aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/Kconfig4
-rw-r--r--sound/pci/ali5451/ali5451.c83
-rw-r--r--sound/pci/azt3328.c1116
-rw-r--r--sound/pci/azt3328.h103
-rw-r--r--sound/pci/ca0106/ca0106_main.c4
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.h2
-rw-r--r--sound/pci/ctxfi/ct20k2reg.h9
-rw-r--r--sound/pci/ctxfi/ctamixer.c34
-rw-r--r--sound/pci/ctxfi/ctatc.c77
-rw-r--r--sound/pci/ctxfi/ctdaio.c34
-rw-r--r--sound/pci/ctxfi/cthw20k1.c22
-rw-r--r--sound/pci/ctxfi/cthw20k2.c73
-rw-r--r--sound/pci/ctxfi/ctmixer.c8
-rw-r--r--sound/pci/ctxfi/ctpcm.c6
-rw-r--r--sound/pci/ctxfi/ctresource.c4
-rw-r--r--sound/pci/ctxfi/ctsrc.c17
-rw-r--r--sound/pci/ctxfi/ctvmem.c6
-rw-r--r--sound/pci/emu10k1/p16v.c2
-rw-r--r--sound/pci/hda/Kconfig27
-rw-r--r--sound/pci/hda/Makefile4
-rw-r--r--sound/pci/hda/hda_beep.c15
-rw-r--r--sound/pci/hda/hda_codec.c90
-rw-r--r--sound/pci/hda/hda_codec.h12
-rw-r--r--sound/pci/hda/hda_eld.c4
-rw-r--r--sound/pci/hda/hda_generic.c18
-rw-r--r--sound/pci/hda/hda_hwdep.c236
-rw-r--r--sound/pci/hda/hda_intel.c206
-rw-r--r--sound/pci/hda/hda_local.h14
-rw-r--r--sound/pci/hda/hda_proc.c7
-rw-r--r--sound/pci/hda/patch_analog.c139
-rw-r--r--sound/pci/hda/patch_atihdmi.c3
-rw-r--r--sound/pci/hda/patch_ca0110.c5
-rw-r--r--sound/pci/hda/patch_cirrus.c1194
-rw-r--r--sound/pci/hda/patch_cmedia.c3
-rw-r--r--sound/pci/hda/patch_conexant.c479
-rw-r--r--sound/pci/hda/patch_intelhdmi.c104
-rw-r--r--sound/pci/hda/patch_nvhdmi.c2
-rw-r--r--sound/pci/hda/patch_realtek.c4293
-rw-r--r--sound/pci/hda/patch_sigmatel.c1283
-rw-r--r--sound/pci/hda/patch_via.c89
-rw-r--r--sound/pci/ice1712/ice1712.h9
-rw-r--r--sound/pci/ice1712/ice1724.c112
-rw-r--r--sound/pci/ice1712/prodigy_hifi.c46
-rw-r--r--sound/pci/oxygen/oxygen_io.c11
-rw-r--r--sound/pci/oxygen/oxygen_lib.c3
-rw-r--r--sound/pci/oxygen/oxygen_pcm.c2
-rw-r--r--sound/pci/oxygen/virtuoso.c2
-rw-r--r--sound/pci/riptide/riptide.c7
-rw-r--r--sound/pci/rme9652/hdsp.c39
-rw-r--r--sound/pci/vx222/vx222_ops.c4
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c20
51 files changed, 6214 insertions, 3872 deletions
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 748f6b7d90b..fb5ee3cc396 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -135,11 +135,11 @@ config SND_AW2
135 135
136 136
137config SND_AZT3328 137config SND_AZT3328
138 tristate "Aztech AZF3328 / PCI168 (EXPERIMENTAL)" 138 tristate "Aztech AZF3328 / PCI168"
139 depends on EXPERIMENTAL
140 select SND_OPL3_LIB 139 select SND_OPL3_LIB
141 select SND_MPU401_UART 140 select SND_MPU401_UART
142 select SND_PCM 141 select SND_PCM
142 select SND_RAWMIDI
143 help 143 help
144 Say Y here to include support for Aztech AZF3328 (PCI168) 144 Say Y here to include support for Aztech AZF3328 (PCI168)
145 soundcards. 145 soundcards.
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index c551006e292..b458d208720 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -310,12 +310,16 @@ static int snd_ali_codec_ready(struct snd_ali *codec,
310 unsigned int res; 310 unsigned int res;
311 311
312 end_time = jiffies + msecs_to_jiffies(250); 312 end_time = jiffies + msecs_to_jiffies(250);
313 do { 313
314 for (;;) {
314 res = snd_ali_5451_peek(codec,port); 315 res = snd_ali_5451_peek(codec,port);
315 if (!(res & 0x8000)) 316 if (!(res & 0x8000))
316 return 0; 317 return 0;
318 if (!time_after_eq(end_time, jiffies))
319 break;
317 schedule_timeout_uninterruptible(1); 320 schedule_timeout_uninterruptible(1);
318 } while (time_after_eq(end_time, jiffies)); 321 }
322
319 snd_ali_5451_poke(codec, port, res & ~0x8000); 323 snd_ali_5451_poke(codec, port, res & ~0x8000);
320 snd_printdd("ali_codec_ready: codec is not ready.\n "); 324 snd_printdd("ali_codec_ready: codec is not ready.\n ");
321 return -EIO; 325 return -EIO;
@@ -327,15 +331,17 @@ static int snd_ali_stimer_ready(struct snd_ali *codec)
327 unsigned long dwChk1,dwChk2; 331 unsigned long dwChk1,dwChk2;
328 332
329 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); 333 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER);
330 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
331
332 end_time = jiffies + msecs_to_jiffies(250); 334 end_time = jiffies + msecs_to_jiffies(250);
333 do { 335
336 for (;;) {
334 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); 337 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
335 if (dwChk2 != dwChk1) 338 if (dwChk2 != dwChk1)
336 return 0; 339 return 0;
340 if (!time_after_eq(end_time, jiffies))
341 break;
337 schedule_timeout_uninterruptible(1); 342 schedule_timeout_uninterruptible(1);
338 } while (time_after_eq(end_time, jiffies)); 343 }
344
339 snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n"); 345 snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n");
340 return -EIO; 346 return -EIO;
341} 347}
@@ -472,45 +478,6 @@ static int snd_ali_reset_5451(struct snd_ali *codec)
472 return 0; 478 return 0;
473} 479}
474 480
475#ifdef CODEC_RESET
476
477static int snd_ali_reset_codec(struct snd_ali *codec)
478{
479 struct pci_dev *pci_dev;
480 unsigned char bVal;
481 unsigned int dwVal;
482 unsigned short wCount, wReg;
483
484 pci_dev = codec->pci_m1533;
485
486 pci_read_config_dword(pci_dev, 0x7c, &dwVal);
487 pci_write_config_dword(pci_dev, 0x7c, dwVal | 0x08000000);
488 udelay(5000);
489 pci_read_config_dword(pci_dev, 0x7c, &dwVal);
490 pci_write_config_dword(pci_dev, 0x7c, dwVal & 0xf7ffffff);
491 udelay(5000);
492
493 bVal = inb(ALI_REG(codec,ALI_SCTRL));
494 bVal |= 0x02;
495 outb(ALI_REG(codec,ALI_SCTRL),bVal);
496 udelay(5000);
497 bVal = inb(ALI_REG(codec,ALI_SCTRL));
498 bVal &= 0xfd;
499 outb(ALI_REG(codec,ALI_SCTRL),bVal);
500 udelay(15000);
501
502 wCount = 200;
503 while (wCount--) {
504 wReg = snd_ali_codec_read(codec->ac97, AC97_POWERDOWN);
505 if ((wReg & 0x000f) == 0x000f)
506 return 0;
507 udelay(5000);
508 }
509 return -1;
510}
511
512#endif
513
514/* 481/*
515 * ALI 5451 Controller 482 * ALI 5451 Controller
516 */ 483 */
@@ -555,22 +522,6 @@ static void snd_ali_disable_address_interrupt(struct snd_ali *codec)
555 outl(gc, ALI_REG(codec, ALI_GC_CIR)); 522 outl(gc, ALI_REG(codec, ALI_GC_CIR));
556} 523}
557 524
558#if 0 /* not used */
559static void snd_ali_enable_voice_irq(struct snd_ali *codec,
560 unsigned int channel)
561{
562 unsigned int mask;
563 struct snd_ali_channel_control *pchregs = &(codec->chregs);
564
565 snd_ali_printk("enable_voice_irq channel=%d\n",channel);
566
567 mask = 1 << (channel & 0x1f);
568 pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten));
569 pchregs->data.ainten |= mask;
570 outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten));
571}
572#endif
573
574static void snd_ali_disable_voice_irq(struct snd_ali *codec, 525static void snd_ali_disable_voice_irq(struct snd_ali *codec,
575 unsigned int channel) 526 unsigned int channel)
576{ 527{
@@ -671,16 +622,6 @@ static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel)
671 } 622 }
672} 623}
673 624
674#if 0 /* not used */
675static void snd_ali_start_voice(struct snd_ali *codec, unsigned int channel)
676{
677 unsigned int mask = 1 << (channel & 0x1f);
678
679 snd_ali_printk("start_voice: channel=%d\n",channel);
680 outl(mask, ALI_REG(codec,codec->chregs.regs.start));
681}
682#endif
683
684static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel) 625static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel)
685{ 626{
686 unsigned int mask = 1 << (channel & 0x1f); 627 unsigned int mask = 1 << (channel & 0x1f);
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index f290bc56178..8451a0169f3 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168). 2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168).
3 * Copyright (C) 2002, 2005 - 2008 by Andreas Mohr <andi AT lisas.de> 3 * Copyright (C) 2002, 2005 - 2009 by Andreas Mohr <andi AT lisas.de>
4 * 4 *
5 * Framework borrowed from Bart Hartgers's als4000.c. 5 * Framework borrowed from Bart Hartgers's als4000.c.
6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801), 6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801),
@@ -10,6 +10,13 @@
10 * PCI168 A/AP, sub ID 8000 10 * PCI168 A/AP, sub ID 8000
11 * Please give me feedback in case you try my driver with one of these!! 11 * Please give me feedback in case you try my driver with one of these!!
12 * 12 *
13 * Keywords: Windows XP Vista 168nt4-125.zip 168win95-125.zip PCI 168 download
14 * (XP/Vista do not support this card at all but every Linux distribution
15 * has very good support out of the box;
16 * just to make sure that the right people hit this and get to know that,
17 * despite the high level of Internet ignorance - as usual :-P -
18 * about very good support for this card - on Linux!)
19 *
13 * GPL LICENSE 20 * GPL LICENSE
14 * This program is free software; you can redistribute it and/or modify 21 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by 22 * it under the terms of the GNU General Public License as published by
@@ -71,10 +78,11 @@
71 * - built-in General DirectX timer having a 20 bits counter 78 * - built-in General DirectX timer having a 20 bits counter
72 * with 1us resolution (see below!) 79 * with 1us resolution (see below!)
73 * - I2S serial output port for external DAC 80 * - I2S serial output port for external DAC
81 * [FIXME: 3.3V or 5V level? maximum rate is 66.2kHz right?]
74 * - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI 82 * - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI
75 * - supports hardware volume control 83 * - supports hardware volume control
76 * - single chip low cost solution (128 pin QFP) 84 * - single chip low cost solution (128 pin QFP)
77 * - supports programmable Sub-vendor and Sub-system ID 85 * - supports programmable Sub-vendor and Sub-system ID [24C02 SEEPROM chip]
78 * required for Microsoft's logo compliance (FIXME: where?) 86 * required for Microsoft's logo compliance (FIXME: where?)
79 * At least the Trident 4D Wave DX has one bit somewhere 87 * At least the Trident 4D Wave DX has one bit somewhere
80 * to enable writes to PCI subsystem VID registers, that should be it. 88 * to enable writes to PCI subsystem VID registers, that should be it.
@@ -82,6 +90,7 @@
82 * some custom data starting at 0x80. What kind of config settings 90 * some custom data starting at 0x80. What kind of config settings
83 * are located in our extended PCI space anyway?? 91 * are located in our extended PCI space anyway??
84 * - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms 92 * - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms
93 * [TDA1517P chip]
85 * 94 *
86 * Note that this driver now is actually *better* than the Windows driver, 95 * Note that this driver now is actually *better* than the Windows driver,
87 * since it additionally supports the card's 1MHz DirectX timer - just try 96 * since it additionally supports the card's 1MHz DirectX timer - just try
@@ -146,10 +155,15 @@
146 * to read the Digital Enhanced Game Port. Not sure whether it is fixable. 155 * to read the Digital Enhanced Game Port. Not sure whether it is fixable.
147 * 156 *
148 * TODO 157 * TODO
158 * - use PCI_VDEVICE
159 * - verify driver status on x86_64
160 * - test multi-card driver operation
161 * - (ab)use 1MHz DirectX timer as kernel clocksource
149 * - test MPU401 MIDI playback etc. 162 * - test MPU401 MIDI playback etc.
150 * - add more power micro-management (disable various units of the card 163 * - add more power micro-management (disable various units of the card
151 * as long as they're unused). However this requires more I/O ports which I 164 * as long as they're unused, to improve audio quality and save power).
152 * haven't figured out yet and which thus might not even exist... 165 * However this requires more I/O ports which I haven't figured out yet
166 * and which thus might not even exist...
153 * The standard suspend/resume functionality could probably make use of 167 * The standard suspend/resume functionality could probably make use of
154 * some improvement, too... 168 * some improvement, too...
155 * - figure out what all unknown port bits are responsible for 169 * - figure out what all unknown port bits are responsible for
@@ -185,25 +199,46 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
185#define SUPPORT_GAMEPORT 1 199#define SUPPORT_GAMEPORT 1
186#endif 200#endif
187 201
202/* === Debug settings ===
203 Further diagnostic functionality than the settings below
204 does not need to be provided, since one can easily write a bash script
205 to dump the card's I/O ports (those listed in lspci -v -v):
206 function dump()
207 {
208 local descr=$1; local addr=$2; local count=$3
209
210 echo "${descr}: ${count} @ ${addr}:"
211 dd if=/dev/port skip=$[${addr}] count=${count} bs=1 2>/dev/null| hexdump -C
212 }
213 and then use something like
214 "dump joy200 0x200 8", "dump mpu388 0x388 4", "dump joy 0xb400 8",
215 "dump codec00 0xa800 32", "dump mixer 0xb800 64", "dump synth 0xbc00 8",
216 possibly within a "while true; do ... sleep 1; done" loop.
217 Tweaking ports could be done using
218 VALSTRING="`printf "%02x" $value`"
219 printf "\x""$VALSTRING"|dd of=/dev/port seek=$[${addr}] bs=1 2>/dev/null
220*/
221
188#define DEBUG_MISC 0 222#define DEBUG_MISC 0
189#define DEBUG_CALLS 0 223#define DEBUG_CALLS 0
190#define DEBUG_MIXER 0 224#define DEBUG_MIXER 0
191#define DEBUG_PLAY_REC 0 225#define DEBUG_CODEC 0
192#define DEBUG_IO 0 226#define DEBUG_IO 0
193#define DEBUG_TIMER 0 227#define DEBUG_TIMER 0
194#define DEBUG_GAME 0 228#define DEBUG_GAME 0
229#define DEBUG_PM 0
195#define MIXER_TESTING 0 230#define MIXER_TESTING 0
196 231
197#if DEBUG_MISC 232#if DEBUG_MISC
198#define snd_azf3328_dbgmisc(format, args...) printk(KERN_ERR format, ##args) 233#define snd_azf3328_dbgmisc(format, args...) printk(KERN_DEBUG format, ##args)
199#else 234#else
200#define snd_azf3328_dbgmisc(format, args...) 235#define snd_azf3328_dbgmisc(format, args...)
201#endif 236#endif
202 237
203#if DEBUG_CALLS 238#if DEBUG_CALLS
204#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args) 239#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
205#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__) 240#define snd_azf3328_dbgcallenter() printk(KERN_DEBUG "--> %s\n", __func__)
206#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__) 241#define snd_azf3328_dbgcallleave() printk(KERN_DEBUG "<-- %s\n", __func__)
207#else 242#else
208#define snd_azf3328_dbgcalls(format, args...) 243#define snd_azf3328_dbgcalls(format, args...)
209#define snd_azf3328_dbgcallenter() 244#define snd_azf3328_dbgcallenter()
@@ -216,10 +251,10 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
216#define snd_azf3328_dbgmixer(format, args...) 251#define snd_azf3328_dbgmixer(format, args...)
217#endif 252#endif
218 253
219#if DEBUG_PLAY_REC 254#if DEBUG_CODEC
220#define snd_azf3328_dbgplay(format, args...) printk(KERN_DEBUG format, ##args) 255#define snd_azf3328_dbgcodec(format, args...) printk(KERN_DEBUG format, ##args)
221#else 256#else
222#define snd_azf3328_dbgplay(format, args...) 257#define snd_azf3328_dbgcodec(format, args...)
223#endif 258#endif
224 259
225#if DEBUG_MISC 260#if DEBUG_MISC
@@ -234,6 +269,12 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
234#define snd_azf3328_dbggame(format, args...) 269#define snd_azf3328_dbggame(format, args...)
235#endif 270#endif
236 271
272#if DEBUG_PM
273#define snd_azf3328_dbgpm(format, args...) printk(KERN_DEBUG format, ##args)
274#else
275#define snd_azf3328_dbgpm(format, args...)
276#endif
277
237static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 278static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
238module_param_array(index, int, NULL, 0444); 279module_param_array(index, int, NULL, 0444);
239MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard."); 280MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard.");
@@ -250,22 +291,23 @@ static int seqtimer_scaling = 128;
250module_param(seqtimer_scaling, int, 0444); 291module_param(seqtimer_scaling, int, 0444);
251MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128."); 292MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128.");
252 293
253struct snd_azf3328_audio_stream { 294struct snd_azf3328_codec_data {
295 unsigned long io_base;
254 struct snd_pcm_substream *substream; 296 struct snd_pcm_substream *substream;
255 int enabled; 297 bool running;
256 int running; 298 const char *name;
257 unsigned long portbase;
258}; 299};
259 300
260enum snd_azf3328_stream_index { 301enum snd_azf3328_codec_type {
261 AZF_PLAYBACK = 0, 302 AZF_CODEC_PLAYBACK = 0,
262 AZF_CAPTURE = 1, 303 AZF_CODEC_CAPTURE = 1,
304 AZF_CODEC_I2S_OUT = 2,
263}; 305};
264 306
265struct snd_azf3328 { 307struct snd_azf3328 {
266 /* often-used fields towards beginning, then grouped */ 308 /* often-used fields towards beginning, then grouped */
267 309
268 unsigned long codec_io; /* usually 0xb000, size 128 */ 310 unsigned long ctrl_io; /* usually 0xb000, size 128 */
269 unsigned long game_io; /* usually 0xb400, size 8 */ 311 unsigned long game_io; /* usually 0xb400, size 8 */
270 unsigned long mpu_io; /* usually 0xb800, size 4 */ 312 unsigned long mpu_io; /* usually 0xb800, size 4 */
271 unsigned long opl3_io; /* usually 0xbc00, size 8 */ 313 unsigned long opl3_io; /* usually 0xbc00, size 8 */
@@ -275,15 +317,17 @@ struct snd_azf3328 {
275 317
276 struct snd_timer *timer; 318 struct snd_timer *timer;
277 319
278 struct snd_pcm *pcm; 320 struct snd_pcm *pcm[3];
279 struct snd_azf3328_audio_stream audio_stream[2]; 321
322 /* playback, recording and I2S out codecs */
323 struct snd_azf3328_codec_data codecs[3];
280 324
281 struct snd_card *card; 325 struct snd_card *card;
282 struct snd_rawmidi *rmidi; 326 struct snd_rawmidi *rmidi;
283 327
284#ifdef SUPPORT_GAMEPORT 328#ifdef SUPPORT_GAMEPORT
285 struct gameport *gameport; 329 struct gameport *gameport;
286 int axes[4]; 330 u16 axes[4];
287#endif 331#endif
288 332
289 struct pci_dev *pci; 333 struct pci_dev *pci;
@@ -293,16 +337,16 @@ struct snd_azf3328 {
293 * If we need to add more registers here, then we might try to fold this 337 * If we need to add more registers here, then we might try to fold this
294 * into some transparent combined shadow register handling with 338 * into some transparent combined shadow register handling with
295 * CONFIG_PM register storage below, but that's slightly difficult. */ 339 * CONFIG_PM register storage below, but that's slightly difficult. */
296 u16 shadow_reg_codec_6AH; 340 u16 shadow_reg_ctrl_6AH;
297 341
298#ifdef CONFIG_PM 342#ifdef CONFIG_PM
299 /* register value containers for power management 343 /* register value containers for power management
300 * Note: not always full I/O range preserved (just like Win driver!) */ 344 * Note: not always full I/O range preserved (similar to Win driver!) */
301 u16 saved_regs_codec[AZF_IO_SIZE_CODEC_PM / 2]; 345 u32 saved_regs_ctrl[AZF_ALIGN(AZF_IO_SIZE_CTRL_PM) / 4];
302 u16 saved_regs_game [AZF_IO_SIZE_GAME_PM / 2]; 346 u32 saved_regs_game[AZF_ALIGN(AZF_IO_SIZE_GAME_PM) / 4];
303 u16 saved_regs_mpu [AZF_IO_SIZE_MPU_PM / 2]; 347 u32 saved_regs_mpu[AZF_ALIGN(AZF_IO_SIZE_MPU_PM) / 4];
304 u16 saved_regs_opl3 [AZF_IO_SIZE_OPL3_PM / 2]; 348 u32 saved_regs_opl3[AZF_ALIGN(AZF_IO_SIZE_OPL3_PM) / 4];
305 u16 saved_regs_mixer[AZF_IO_SIZE_MIXER_PM / 2]; 349 u32 saved_regs_mixer[AZF_ALIGN(AZF_IO_SIZE_MIXER_PM) / 4];
306#endif 350#endif
307}; 351};
308 352
@@ -316,7 +360,7 @@ MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
316 360
317 361
318static int 362static int
319snd_azf3328_io_reg_setb(unsigned reg, u8 mask, int do_set) 363snd_azf3328_io_reg_setb(unsigned reg, u8 mask, bool do_set)
320{ 364{
321 u8 prev = inb(reg), new; 365 u8 prev = inb(reg), new;
322 366
@@ -331,39 +375,72 @@ snd_azf3328_io_reg_setb(unsigned reg, u8 mask, int do_set)
331} 375}
332 376
333static inline void 377static inline void
334snd_azf3328_codec_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value) 378snd_azf3328_codec_outb(const struct snd_azf3328_codec_data *codec,
379 unsigned reg,
380 u8 value
381)
335{ 382{
336 outb(value, chip->codec_io + reg); 383 outb(value, codec->io_base + reg);
337} 384}
338 385
339static inline u8 386static inline u8
340snd_azf3328_codec_inb(const struct snd_azf3328 *chip, unsigned reg) 387snd_azf3328_codec_inb(const struct snd_azf3328_codec_data *codec, unsigned reg)
341{ 388{
342 return inb(chip->codec_io + reg); 389 return inb(codec->io_base + reg);
343} 390}
344 391
345static inline void 392static inline void
346snd_azf3328_codec_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value) 393snd_azf3328_codec_outw(const struct snd_azf3328_codec_data *codec,
394 unsigned reg,
395 u16 value
396)
347{ 397{
348 outw(value, chip->codec_io + reg); 398 outw(value, codec->io_base + reg);
349} 399}
350 400
351static inline u16 401static inline u16
352snd_azf3328_codec_inw(const struct snd_azf3328 *chip, unsigned reg) 402snd_azf3328_codec_inw(const struct snd_azf3328_codec_data *codec, unsigned reg)
353{ 403{
354 return inw(chip->codec_io + reg); 404 return inw(codec->io_base + reg);
355} 405}
356 406
357static inline void 407static inline void
358snd_azf3328_codec_outl(const struct snd_azf3328 *chip, unsigned reg, u32 value) 408snd_azf3328_codec_outl(const struct snd_azf3328_codec_data *codec,
409 unsigned reg,
410 u32 value
411)
359{ 412{
360 outl(value, chip->codec_io + reg); 413 outl(value, codec->io_base + reg);
361} 414}
362 415
363static inline u32 416static inline u32
364snd_azf3328_codec_inl(const struct snd_azf3328 *chip, unsigned reg) 417snd_azf3328_codec_inl(const struct snd_azf3328_codec_data *codec, unsigned reg)
418{
419 return inl(codec->io_base + reg);
420}
421
422static inline void
423snd_azf3328_ctrl_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
424{
425 outb(value, chip->ctrl_io + reg);
426}
427
428static inline u8
429snd_azf3328_ctrl_inb(const struct snd_azf3328 *chip, unsigned reg)
430{
431 return inb(chip->ctrl_io + reg);
432}
433
434static inline void
435snd_azf3328_ctrl_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
436{
437 outw(value, chip->ctrl_io + reg);
438}
439
440static inline void
441snd_azf3328_ctrl_outl(const struct snd_azf3328 *chip, unsigned reg, u32 value)
365{ 442{
366 return inl(chip->codec_io + reg); 443 outl(value, chip->ctrl_io + reg);
367} 444}
368 445
369static inline void 446static inline void
@@ -404,13 +481,13 @@ snd_azf3328_mixer_inw(const struct snd_azf3328 *chip, unsigned reg)
404 481
405#define AZF_MUTE_BIT 0x80 482#define AZF_MUTE_BIT 0x80
406 483
407static int 484static bool
408snd_azf3328_mixer_set_mute(const struct snd_azf3328 *chip, 485snd_azf3328_mixer_set_mute(const struct snd_azf3328 *chip,
409 unsigned reg, int do_mute 486 unsigned reg, bool do_mute
410) 487)
411{ 488{
412 unsigned long portbase = chip->mixer_io + reg + 1; 489 unsigned long portbase = chip->mixer_io + reg + 1;
413 int updated; 490 bool updated;
414 491
415 /* the mute bit is on the *second* (i.e. right) register of a 492 /* the mute bit is on the *second* (i.e. right) register of a
416 * left/right channel setting */ 493 * left/right channel setting */
@@ -569,7 +646,7 @@ snd_azf3328_get_mixer(struct snd_kcontrol *kcontrol,
569{ 646{
570 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol); 647 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
571 struct azf3328_mixer_reg reg; 648 struct azf3328_mixer_reg reg;
572 unsigned int oreg, val; 649 u16 oreg, val;
573 650
574 snd_azf3328_dbgcallenter(); 651 snd_azf3328_dbgcallenter();
575 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 652 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
@@ -600,7 +677,7 @@ snd_azf3328_put_mixer(struct snd_kcontrol *kcontrol,
600{ 677{
601 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol); 678 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
602 struct azf3328_mixer_reg reg; 679 struct azf3328_mixer_reg reg;
603 unsigned int oreg, nreg, val; 680 u16 oreg, nreg, val;
604 681
605 snd_azf3328_dbgcallenter(); 682 snd_azf3328_dbgcallenter();
606 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 683 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
@@ -709,7 +786,7 @@ snd_azf3328_put_mixer_enum(struct snd_kcontrol *kcontrol,
709{ 786{
710 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol); 787 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
711 struct azf3328_mixer_reg reg; 788 struct azf3328_mixer_reg reg;
712 unsigned int oreg, nreg, val; 789 u16 oreg, nreg, val;
713 790
714 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 791 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
715 oreg = snd_azf3328_mixer_inw(chip, reg.reg); 792 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
@@ -867,14 +944,15 @@ snd_azf3328_hw_free(struct snd_pcm_substream *substream)
867 944
868static void 945static void
869snd_azf3328_codec_setfmt(struct snd_azf3328 *chip, 946snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
870 unsigned reg, 947 enum snd_azf3328_codec_type codec_type,
871 enum azf_freq_t bitrate, 948 enum azf_freq_t bitrate,
872 unsigned int format_width, 949 unsigned int format_width,
873 unsigned int channels 950 unsigned int channels
874) 951)
875{ 952{
876 u16 val = 0xff00;
877 unsigned long flags; 953 unsigned long flags;
954 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
955 u16 val = 0xff00;
878 956
879 snd_azf3328_dbgcallenter(); 957 snd_azf3328_dbgcallenter();
880 switch (bitrate) { 958 switch (bitrate) {
@@ -917,7 +995,7 @@ snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
917 spin_lock_irqsave(&chip->reg_lock, flags); 995 spin_lock_irqsave(&chip->reg_lock, flags);
918 996
919 /* set bitrate/format */ 997 /* set bitrate/format */
920 snd_azf3328_codec_outw(chip, reg, val); 998 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_SOUNDFORMAT, val);
921 999
922 /* changing the bitrate/format settings switches off the 1000 /* changing the bitrate/format settings switches off the
923 * audio output with an annoying click in case of 8/16bit format change 1001 * audio output with an annoying click in case of 8/16bit format change
@@ -926,11 +1004,11 @@ snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
926 * (FIXME: yes, it works, but what exactly am I doing here?? :) 1004 * (FIXME: yes, it works, but what exactly am I doing here?? :)
927 * FIXME: does this have some side effects for full-duplex 1005 * FIXME: does this have some side effects for full-duplex
928 * or other dramatic side effects? */ 1006 * or other dramatic side effects? */
929 if (reg == IDX_IO_PLAY_SOUNDFORMAT) /* only do it for playback */ 1007 if (codec_type == AZF_CODEC_PLAYBACK) /* only do it for playback */
930 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, 1008 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
931 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) | 1009 snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS) |
932 DMA_PLAY_SOMETHING1 | 1010 DMA_RUN_SOMETHING1 |
933 DMA_PLAY_SOMETHING2 | 1011 DMA_RUN_SOMETHING2 |
934 SOMETHING_ALMOST_ALWAYS_SET | 1012 SOMETHING_ALMOST_ALWAYS_SET |
935 DMA_EPILOGUE_SOMETHING | 1013 DMA_EPILOGUE_SOMETHING |
936 DMA_SOMETHING_ELSE 1014 DMA_SOMETHING_ELSE
@@ -942,112 +1020,134 @@ snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
942 1020
943static inline void 1021static inline void
944snd_azf3328_codec_setfmt_lowpower(struct snd_azf3328 *chip, 1022snd_azf3328_codec_setfmt_lowpower(struct snd_azf3328 *chip,
945 unsigned reg 1023 enum snd_azf3328_codec_type codec_type
946) 1024)
947{ 1025{
948 /* choose lowest frequency for low power consumption. 1026 /* choose lowest frequency for low power consumption.
949 * While this will cause louder noise due to rather coarse frequency, 1027 * While this will cause louder noise due to rather coarse frequency,
950 * it should never matter since output should always 1028 * it should never matter since output should always
951 * get disabled properly when idle anyway. */ 1029 * get disabled properly when idle anyway. */
952 snd_azf3328_codec_setfmt(chip, reg, AZF_FREQ_4000, 8, 1); 1030 snd_azf3328_codec_setfmt(chip, codec_type, AZF_FREQ_4000, 8, 1);
953} 1031}
954 1032
955static void 1033static void
956snd_azf3328_codec_reg_6AH_update(struct snd_azf3328 *chip, 1034snd_azf3328_ctrl_reg_6AH_update(struct snd_azf3328 *chip,
957 unsigned bitmask, 1035 unsigned bitmask,
958 int enable 1036 bool enable
959) 1037)
960{ 1038{
961 if (enable) 1039 bool do_mask = !enable;
962 chip->shadow_reg_codec_6AH &= ~bitmask; 1040 if (do_mask)
1041 chip->shadow_reg_ctrl_6AH |= bitmask;
963 else 1042 else
964 chip->shadow_reg_codec_6AH |= bitmask; 1043 chip->shadow_reg_ctrl_6AH &= ~bitmask;
965 snd_azf3328_dbgplay("6AH_update mask 0x%04x enable %d: val 0x%04x\n", 1044 snd_azf3328_dbgcodec("6AH_update mask 0x%04x do_mask %d: val 0x%04x\n",
966 bitmask, enable, chip->shadow_reg_codec_6AH); 1045 bitmask, do_mask, chip->shadow_reg_ctrl_6AH);
967 snd_azf3328_codec_outw(chip, IDX_IO_6AH, chip->shadow_reg_codec_6AH); 1046 snd_azf3328_ctrl_outw(chip, IDX_IO_6AH, chip->shadow_reg_ctrl_6AH);
968} 1047}
969 1048
970static inline void 1049static inline void
971snd_azf3328_codec_enable(struct snd_azf3328 *chip, int enable) 1050snd_azf3328_ctrl_enable_codecs(struct snd_azf3328 *chip, bool enable)
972{ 1051{
973 snd_azf3328_dbgplay("codec_enable %d\n", enable); 1052 snd_azf3328_dbgcodec("codec_enable %d\n", enable);
974 /* no idea what exactly is being done here, but I strongly assume it's 1053 /* no idea what exactly is being done here, but I strongly assume it's
975 * PM related */ 1054 * PM related */
976 snd_azf3328_codec_reg_6AH_update( 1055 snd_azf3328_ctrl_reg_6AH_update(
977 chip, IO_6A_PAUSE_PLAYBACK_BIT8, enable 1056 chip, IO_6A_PAUSE_PLAYBACK_BIT8, enable
978 ); 1057 );
979} 1058}
980 1059
981static void 1060static void
982snd_azf3328_codec_activity(struct snd_azf3328 *chip, 1061snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
983 enum snd_azf3328_stream_index stream_type, 1062 enum snd_azf3328_codec_type codec_type,
984 int enable 1063 bool enable
985) 1064)
986{ 1065{
987 int need_change = (chip->audio_stream[stream_type].running != enable); 1066 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1067 bool need_change = (codec->running != enable);
988 1068
989 snd_azf3328_dbgplay( 1069 snd_azf3328_dbgcodec(
990 "codec_activity: type %d, enable %d, need_change %d\n", 1070 "codec_activity: %s codec, enable %d, need_change %d\n",
991 stream_type, enable, need_change 1071 codec->name, enable, need_change
992 ); 1072 );
993 if (need_change) { 1073 if (need_change) {
994 enum snd_azf3328_stream_index other = 1074 static const struct {
995 (stream_type == AZF_PLAYBACK) ? 1075 enum snd_azf3328_codec_type other1;
996 AZF_CAPTURE : AZF_PLAYBACK; 1076 enum snd_azf3328_codec_type other2;
997 /* small check to prevent shutting down the other party 1077 } peer_codecs[3] =
998 * in case it's active */ 1078 { { AZF_CODEC_CAPTURE, AZF_CODEC_I2S_OUT },
999 if ((enable) || !(chip->audio_stream[other].running)) 1079 { AZF_CODEC_PLAYBACK, AZF_CODEC_I2S_OUT },
1000 snd_azf3328_codec_enable(chip, enable); 1080 { AZF_CODEC_PLAYBACK, AZF_CODEC_CAPTURE } };
1081 bool call_function;
1082
1083 if (enable)
1084 /* if enable codec, call enable_codecs func
1085 to enable codec supply... */
1086 call_function = 1;
1087 else {
1088 /* ...otherwise call enable_codecs func
1089 (which globally shuts down operation of codecs)
1090 only in case the other codecs are currently
1091 not active either! */
1092 call_function =
1093 ((!chip->codecs[peer_codecs[codec_type].other1]
1094 .running)
1095 && (!chip->codecs[peer_codecs[codec_type].other2]
1096 .running));
1097 }
1098 if (call_function)
1099 snd_azf3328_ctrl_enable_codecs(chip, enable);
1001 1100
1002 /* ...and adjust clock, too 1101 /* ...and adjust clock, too
1003 * (reduce noise and power consumption) */ 1102 * (reduce noise and power consumption) */
1004 if (!enable) 1103 if (!enable)
1005 snd_azf3328_codec_setfmt_lowpower( 1104 snd_azf3328_codec_setfmt_lowpower(
1006 chip, 1105 chip,
1007 chip->audio_stream[stream_type].portbase 1106 codec_type
1008 + IDX_IO_PLAY_SOUNDFORMAT
1009 ); 1107 );
1108 codec->running = enable;
1010 } 1109 }
1011 chip->audio_stream[stream_type].running = enable;
1012} 1110}
1013 1111
1014static void 1112static void
1015snd_azf3328_setdmaa(struct snd_azf3328 *chip, 1113snd_azf3328_codec_setdmaa(struct snd_azf3328 *chip,
1016 long unsigned int addr, 1114 enum snd_azf3328_codec_type codec_type,
1017 unsigned int count, 1115 unsigned long addr,
1018 unsigned int size, 1116 unsigned int count,
1019 enum snd_azf3328_stream_index stream_type 1117 unsigned int size
1020) 1118)
1021{ 1119{
1120 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1022 snd_azf3328_dbgcallenter(); 1121 snd_azf3328_dbgcallenter();
1023 if (!chip->audio_stream[stream_type].running) { 1122 if (!codec->running) {
1024 /* AZF3328 uses a two buffer pointer DMA playback approach */ 1123 /* AZF3328 uses a two buffer pointer DMA transfer approach */
1025 1124
1026 unsigned long flags, portbase, addr_area2; 1125 unsigned long flags, addr_area2;
1027 1126
1028 /* width 32bit (prevent overflow): */ 1127 /* width 32bit (prevent overflow): */
1029 unsigned long count_areas, count_tmp; 1128 u32 count_areas, lengths;
1030 1129
1031 portbase = chip->audio_stream[stream_type].portbase;
1032 count_areas = size/2; 1130 count_areas = size/2;
1033 addr_area2 = addr+count_areas; 1131 addr_area2 = addr+count_areas;
1034 count_areas--; /* max. index */ 1132 count_areas--; /* max. index */
1035 snd_azf3328_dbgplay("set DMA: buf1 %08lx[%lu], buf2 %08lx[%lu]\n", addr, count_areas, addr_area2, count_areas); 1133 snd_azf3328_dbgcodec("setdma: buffers %08lx[%u] / %08lx[%u]\n",
1134 addr, count_areas, addr_area2, count_areas);
1036 1135
1037 /* build combined I/O buffer length word */ 1136 /* build combined I/O buffer length word */
1038 count_tmp = count_areas; 1137 lengths = (count_areas << 16) | (count_areas);
1039 count_areas |= (count_tmp << 16);
1040 spin_lock_irqsave(&chip->reg_lock, flags); 1138 spin_lock_irqsave(&chip->reg_lock, flags);
1041 outl(addr, portbase + IDX_IO_PLAY_DMA_START_1); 1139 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_1, addr);
1042 outl(addr_area2, portbase + IDX_IO_PLAY_DMA_START_2); 1140 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_2,
1043 outl(count_areas, portbase + IDX_IO_PLAY_DMA_LEN_1); 1141 addr_area2);
1142 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_LENGTHS,
1143 lengths);
1044 spin_unlock_irqrestore(&chip->reg_lock, flags); 1144 spin_unlock_irqrestore(&chip->reg_lock, flags);
1045 } 1145 }
1046 snd_azf3328_dbgcallleave(); 1146 snd_azf3328_dbgcallleave();
1047} 1147}
1048 1148
1049static int 1149static int
1050snd_azf3328_playback_prepare(struct snd_pcm_substream *substream) 1150snd_azf3328_codec_prepare(struct snd_pcm_substream *substream)
1051{ 1151{
1052#if 0 1152#if 0
1053 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1153 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
@@ -1058,157 +1158,161 @@ snd_azf3328_playback_prepare(struct snd_pcm_substream *substream)
1058 1158
1059 snd_azf3328_dbgcallenter(); 1159 snd_azf3328_dbgcallenter();
1060#if 0 1160#if 0
1061 snd_azf3328_codec_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, 1161 snd_azf3328_codec_setfmt(chip, AZF_CODEC_...,
1062 runtime->rate, 1162 runtime->rate,
1063 snd_pcm_format_width(runtime->format), 1163 snd_pcm_format_width(runtime->format),
1064 runtime->channels); 1164 runtime->channels);
1065 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, AZF_PLAYBACK); 1165 snd_azf3328_codec_setdmaa(chip, AZF_CODEC_...,
1166 runtime->dma_addr, count, size);
1066#endif 1167#endif
1067 snd_azf3328_dbgcallleave(); 1168 snd_azf3328_dbgcallleave();
1068 return 0; 1169 return 0;
1069} 1170}
1070 1171
1071static int 1172static int
1072snd_azf3328_capture_prepare(struct snd_pcm_substream *substream) 1173snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1073{ 1174 struct snd_pcm_substream *substream, int cmd)
1074#if 0
1075 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1076 struct snd_pcm_runtime *runtime = substream->runtime;
1077 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1078 unsigned int count = snd_pcm_lib_period_bytes(substream);
1079#endif
1080
1081 snd_azf3328_dbgcallenter();
1082#if 0
1083 snd_azf3328_codec_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
1084 runtime->rate,
1085 snd_pcm_format_width(runtime->format),
1086 runtime->channels);
1087 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, AZF_CAPTURE);
1088#endif
1089 snd_azf3328_dbgcallleave();
1090 return 0;
1091}
1092
1093static int
1094snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
1095{ 1175{
1096 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1176 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1177 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1097 struct snd_pcm_runtime *runtime = substream->runtime; 1178 struct snd_pcm_runtime *runtime = substream->runtime;
1098 int result = 0; 1179 int result = 0;
1099 unsigned int status1; 1180 u16 flags1;
1100 int previously_muted; 1181 bool previously_muted = 0;
1182 bool is_playback_codec = (AZF_CODEC_PLAYBACK == codec_type);
1101 1183
1102 snd_azf3328_dbgcalls("snd_azf3328_playback_trigger cmd %d\n", cmd); 1184 snd_azf3328_dbgcalls("snd_azf3328_codec_trigger cmd %d\n", cmd);
1103 1185
1104 switch (cmd) { 1186 switch (cmd) {
1105 case SNDRV_PCM_TRIGGER_START: 1187 case SNDRV_PCM_TRIGGER_START:
1106 snd_azf3328_dbgplay("START PLAYBACK\n"); 1188 snd_azf3328_dbgcodec("START %s\n", codec->name);
1107 1189
1108 /* mute WaveOut (avoid clicking during setup) */ 1190 if (is_playback_codec) {
1109 previously_muted = 1191 /* mute WaveOut (avoid clicking during setup) */
1110 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1); 1192 previously_muted =
1193 snd_azf3328_mixer_set_mute(
1194 chip, IDX_MIXER_WAVEOUT, 1
1195 );
1196 }
1111 1197
1112 snd_azf3328_codec_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, 1198 snd_azf3328_codec_setfmt(chip, codec_type,
1113 runtime->rate, 1199 runtime->rate,
1114 snd_pcm_format_width(runtime->format), 1200 snd_pcm_format_width(runtime->format),
1115 runtime->channels); 1201 runtime->channels);
1116 1202
1117 spin_lock(&chip->reg_lock); 1203 spin_lock(&chip->reg_lock);
1118 /* first, remember current value: */ 1204 /* first, remember current value: */
1119 status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS); 1205 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
1120 1206
1121 /* stop playback */ 1207 /* stop transfer */
1122 status1 &= ~DMA_RESUME; 1208 flags1 &= ~DMA_RESUME;
1123 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1); 1209 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
1124 1210
1125 /* FIXME: clear interrupts or what??? */ 1211 /* FIXME: clear interrupts or what??? */
1126 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_IRQTYPE, 0xffff); 1212 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_IRQTYPE, 0xffff);
1127 spin_unlock(&chip->reg_lock); 1213 spin_unlock(&chip->reg_lock);
1128 1214
1129 snd_azf3328_setdmaa(chip, runtime->dma_addr, 1215 snd_azf3328_codec_setdmaa(chip, codec_type, runtime->dma_addr,
1130 snd_pcm_lib_period_bytes(substream), 1216 snd_pcm_lib_period_bytes(substream),
1131 snd_pcm_lib_buffer_bytes(substream), 1217 snd_pcm_lib_buffer_bytes(substream)
1132 AZF_PLAYBACK); 1218 );
1133 1219
1134 spin_lock(&chip->reg_lock); 1220 spin_lock(&chip->reg_lock);
1135#ifdef WIN9X 1221#ifdef WIN9X
1136 /* FIXME: enable playback/recording??? */ 1222 /* FIXME: enable playback/recording??? */
1137 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2; 1223 flags1 |= DMA_RUN_SOMETHING1 | DMA_RUN_SOMETHING2;
1138 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1); 1224 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
1139 1225
1140 /* start playback again */ 1226 /* start transfer again */
1141 /* FIXME: what is this value (0x0010)??? */ 1227 /* FIXME: what is this value (0x0010)??? */
1142 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING; 1228 flags1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
1143 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1); 1229 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
1144#else /* NT4 */ 1230#else /* NT4 */
1145 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, 1231 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1146 0x0000); 1232 0x0000);
1147 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, 1233 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1148 DMA_PLAY_SOMETHING1); 1234 DMA_RUN_SOMETHING1);
1149 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, 1235 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1150 DMA_PLAY_SOMETHING1 | 1236 DMA_RUN_SOMETHING1 |
1151 DMA_PLAY_SOMETHING2); 1237 DMA_RUN_SOMETHING2);
1152 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, 1238 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1153 DMA_RESUME | 1239 DMA_RESUME |
1154 SOMETHING_ALMOST_ALWAYS_SET | 1240 SOMETHING_ALMOST_ALWAYS_SET |
1155 DMA_EPILOGUE_SOMETHING | 1241 DMA_EPILOGUE_SOMETHING |
1156 DMA_SOMETHING_ELSE); 1242 DMA_SOMETHING_ELSE);
1157#endif 1243#endif
1158 spin_unlock(&chip->reg_lock); 1244 spin_unlock(&chip->reg_lock);
1159 snd_azf3328_codec_activity(chip, AZF_PLAYBACK, 1); 1245 snd_azf3328_ctrl_codec_activity(chip, codec_type, 1);
1160 1246
1161 /* now unmute WaveOut */ 1247 if (is_playback_codec) {
1162 if (!previously_muted) 1248 /* now unmute WaveOut */
1163 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0); 1249 if (!previously_muted)
1250 snd_azf3328_mixer_set_mute(
1251 chip, IDX_MIXER_WAVEOUT, 0
1252 );
1253 }
1164 1254
1165 snd_azf3328_dbgplay("STARTED PLAYBACK\n"); 1255 snd_azf3328_dbgcodec("STARTED %s\n", codec->name);
1166 break; 1256 break;
1167 case SNDRV_PCM_TRIGGER_RESUME: 1257 case SNDRV_PCM_TRIGGER_RESUME:
1168 snd_azf3328_dbgplay("RESUME PLAYBACK\n"); 1258 snd_azf3328_dbgcodec("RESUME %s\n", codec->name);
1169 /* resume playback if we were active */ 1259 /* resume codec if we were active */
1170 spin_lock(&chip->reg_lock); 1260 spin_lock(&chip->reg_lock);
1171 if (chip->audio_stream[AZF_PLAYBACK].running) 1261 if (codec->running)
1172 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, 1262 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1173 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) | DMA_RESUME); 1263 snd_azf3328_codec_inw(
1264 codec, IDX_IO_CODEC_DMA_FLAGS
1265 ) | DMA_RESUME
1266 );
1174 spin_unlock(&chip->reg_lock); 1267 spin_unlock(&chip->reg_lock);
1175 break; 1268 break;
1176 case SNDRV_PCM_TRIGGER_STOP: 1269 case SNDRV_PCM_TRIGGER_STOP:
1177 snd_azf3328_dbgplay("STOP PLAYBACK\n"); 1270 snd_azf3328_dbgcodec("STOP %s\n", codec->name);
1178 1271
1179 /* mute WaveOut (avoid clicking during setup) */ 1272 if (is_playback_codec) {
1180 previously_muted = 1273 /* mute WaveOut (avoid clicking during setup) */
1181 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1); 1274 previously_muted =
1275 snd_azf3328_mixer_set_mute(
1276 chip, IDX_MIXER_WAVEOUT, 1
1277 );
1278 }
1182 1279
1183 spin_lock(&chip->reg_lock); 1280 spin_lock(&chip->reg_lock);
1184 /* first, remember current value: */ 1281 /* first, remember current value: */
1185 status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS); 1282 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
1186 1283
1187 /* stop playback */ 1284 /* stop transfer */
1188 status1 &= ~DMA_RESUME; 1285 flags1 &= ~DMA_RESUME;
1189 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1); 1286 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
1190 1287
1191 /* hmm, is this really required? we're resetting the same bit 1288 /* hmm, is this really required? we're resetting the same bit
1192 * immediately thereafter... */ 1289 * immediately thereafter... */
1193 status1 |= DMA_PLAY_SOMETHING1; 1290 flags1 |= DMA_RUN_SOMETHING1;
1194 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1); 1291 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
1195 1292
1196 status1 &= ~DMA_PLAY_SOMETHING1; 1293 flags1 &= ~DMA_RUN_SOMETHING1;
1197 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1); 1294 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
1198 spin_unlock(&chip->reg_lock); 1295 spin_unlock(&chip->reg_lock);
1199 snd_azf3328_codec_activity(chip, AZF_PLAYBACK, 0); 1296 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0);
1200 1297
1201 /* now unmute WaveOut */ 1298 if (is_playback_codec) {
1202 if (!previously_muted) 1299 /* now unmute WaveOut */
1203 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0); 1300 if (!previously_muted)
1301 snd_azf3328_mixer_set_mute(
1302 chip, IDX_MIXER_WAVEOUT, 0
1303 );
1304 }
1204 1305
1205 snd_azf3328_dbgplay("STOPPED PLAYBACK\n"); 1306 snd_azf3328_dbgcodec("STOPPED %s\n", codec->name);
1206 break; 1307 break;
1207 case SNDRV_PCM_TRIGGER_SUSPEND: 1308 case SNDRV_PCM_TRIGGER_SUSPEND:
1208 snd_azf3328_dbgplay("SUSPEND PLAYBACK\n"); 1309 snd_azf3328_dbgcodec("SUSPEND %s\n", codec->name);
1209 /* make sure playback is stopped */ 1310 /* make sure codec is stopped */
1210 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, 1311 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1211 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) & ~DMA_RESUME); 1312 snd_azf3328_codec_inw(
1313 codec, IDX_IO_CODEC_DMA_FLAGS
1314 ) & ~DMA_RESUME
1315 );
1212 break; 1316 break;
1213 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1317 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1214 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n"); 1318 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
@@ -1217,7 +1321,7 @@ snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
1217 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n"); 1321 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
1218 break; 1322 break;
1219 default: 1323 default:
1220 printk(KERN_ERR "FIXME: unknown trigger mode!\n"); 1324 snd_printk(KERN_ERR "FIXME: unknown trigger mode!\n");
1221 return -EINVAL; 1325 return -EINVAL;
1222 } 1326 }
1223 1327
@@ -1225,172 +1329,74 @@ snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
1225 return result; 1329 return result;
1226} 1330}
1227 1331
1228/* this is just analogous to playback; I'm not quite sure whether recording
1229 * should actually be triggered like that */
1230static int 1332static int
1231snd_azf3328_capture_trigger(struct snd_pcm_substream *substream, int cmd) 1333snd_azf3328_codec_playback_trigger(struct snd_pcm_substream *substream, int cmd)
1232{ 1334{
1233 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1335 return snd_azf3328_codec_trigger(AZF_CODEC_PLAYBACK, substream, cmd);
1234 struct snd_pcm_runtime *runtime = substream->runtime; 1336}
1235 int result = 0;
1236 unsigned int status1;
1237
1238 snd_azf3328_dbgcalls("snd_azf3328_capture_trigger cmd %d\n", cmd);
1239
1240 switch (cmd) {
1241 case SNDRV_PCM_TRIGGER_START:
1242
1243 snd_azf3328_dbgplay("START CAPTURE\n");
1244
1245 snd_azf3328_codec_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
1246 runtime->rate,
1247 snd_pcm_format_width(runtime->format),
1248 runtime->channels);
1249
1250 spin_lock(&chip->reg_lock);
1251 /* first, remember current value: */
1252 status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
1253
1254 /* stop recording */
1255 status1 &= ~DMA_RESUME;
1256 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1257
1258 /* FIXME: clear interrupts or what??? */
1259 snd_azf3328_codec_outw(chip, IDX_IO_REC_IRQTYPE, 0xffff);
1260 spin_unlock(&chip->reg_lock);
1261
1262 snd_azf3328_setdmaa(chip, runtime->dma_addr,
1263 snd_pcm_lib_period_bytes(substream),
1264 snd_pcm_lib_buffer_bytes(substream),
1265 AZF_CAPTURE);
1266
1267 spin_lock(&chip->reg_lock);
1268#ifdef WIN9X
1269 /* FIXME: enable playback/recording??? */
1270 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
1271 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1272
1273 /* start capture again */
1274 /* FIXME: what is this value (0x0010)??? */
1275 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
1276 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1277#else
1278 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1279 0x0000);
1280 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1281 DMA_PLAY_SOMETHING1);
1282 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1283 DMA_PLAY_SOMETHING1 |
1284 DMA_PLAY_SOMETHING2);
1285 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1286 DMA_RESUME |
1287 SOMETHING_ALMOST_ALWAYS_SET |
1288 DMA_EPILOGUE_SOMETHING |
1289 DMA_SOMETHING_ELSE);
1290#endif
1291 spin_unlock(&chip->reg_lock);
1292 snd_azf3328_codec_activity(chip, AZF_CAPTURE, 1);
1293
1294 snd_azf3328_dbgplay("STARTED CAPTURE\n");
1295 break;
1296 case SNDRV_PCM_TRIGGER_RESUME:
1297 snd_azf3328_dbgplay("RESUME CAPTURE\n");
1298 /* resume recording if we were active */
1299 spin_lock(&chip->reg_lock);
1300 if (chip->audio_stream[AZF_CAPTURE].running)
1301 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1302 snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS) | DMA_RESUME);
1303 spin_unlock(&chip->reg_lock);
1304 break;
1305 case SNDRV_PCM_TRIGGER_STOP:
1306 snd_azf3328_dbgplay("STOP CAPTURE\n");
1307
1308 spin_lock(&chip->reg_lock);
1309 /* first, remember current value: */
1310 status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
1311
1312 /* stop recording */
1313 status1 &= ~DMA_RESUME;
1314 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1315
1316 status1 |= DMA_PLAY_SOMETHING1;
1317 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1318
1319 status1 &= ~DMA_PLAY_SOMETHING1;
1320 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1321 spin_unlock(&chip->reg_lock);
1322 snd_azf3328_codec_activity(chip, AZF_CAPTURE, 0);
1323 1337
1324 snd_azf3328_dbgplay("STOPPED CAPTURE\n"); 1338static int
1325 break; 1339snd_azf3328_codec_capture_trigger(struct snd_pcm_substream *substream, int cmd)
1326 case SNDRV_PCM_TRIGGER_SUSPEND: 1340{
1327 snd_azf3328_dbgplay("SUSPEND CAPTURE\n"); 1341 return snd_azf3328_codec_trigger(AZF_CODEC_CAPTURE, substream, cmd);
1328 /* make sure recording is stopped */ 1342}
1329 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1330 snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS) & ~DMA_RESUME);
1331 break;
1332 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1333 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
1334 break;
1335 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1336 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
1337 break;
1338 default:
1339 printk(KERN_ERR "FIXME: unknown trigger mode!\n");
1340 return -EINVAL;
1341 }
1342 1343
1343 snd_azf3328_dbgcallleave(); 1344static int
1344 return result; 1345snd_azf3328_codec_i2s_out_trigger(struct snd_pcm_substream *substream, int cmd)
1346{
1347 return snd_azf3328_codec_trigger(AZF_CODEC_I2S_OUT, substream, cmd);
1345} 1348}
1346 1349
1347static snd_pcm_uframes_t 1350static snd_pcm_uframes_t
1348snd_azf3328_playback_pointer(struct snd_pcm_substream *substream) 1351snd_azf3328_codec_pointer(struct snd_pcm_substream *substream,
1352 enum snd_azf3328_codec_type codec_type
1353)
1349{ 1354{
1350 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1355 const struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1356 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1351 unsigned long bufptr, result; 1357 unsigned long bufptr, result;
1352 snd_pcm_uframes_t frmres; 1358 snd_pcm_uframes_t frmres;
1353 1359
1354#ifdef QUERY_HARDWARE 1360#ifdef QUERY_HARDWARE
1355 bufptr = snd_azf3328_codec_inl(chip, IDX_IO_PLAY_DMA_START_1); 1361 bufptr = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_START_1);
1356#else 1362#else
1357 bufptr = substream->runtime->dma_addr; 1363 bufptr = substream->runtime->dma_addr;
1358#endif 1364#endif
1359 result = snd_azf3328_codec_inl(chip, IDX_IO_PLAY_DMA_CURRPOS); 1365 result = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_CURRPOS);
1360 1366
1361 /* calculate offset */ 1367 /* calculate offset */
1362 result -= bufptr; 1368 result -= bufptr;
1363 frmres = bytes_to_frames( substream->runtime, result); 1369 frmres = bytes_to_frames( substream->runtime, result);
1364 snd_azf3328_dbgplay("PLAY @ 0x%8lx, frames %8ld\n", result, frmres); 1370 snd_azf3328_dbgcodec("%s @ 0x%8lx, frames %8ld\n",
1371 codec->name, result, frmres);
1365 return frmres; 1372 return frmres;
1366} 1373}
1367 1374
1368static snd_pcm_uframes_t 1375static snd_pcm_uframes_t
1369snd_azf3328_capture_pointer(struct snd_pcm_substream *substream) 1376snd_azf3328_codec_playback_pointer(struct snd_pcm_substream *substream)
1370{ 1377{
1371 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1378 return snd_azf3328_codec_pointer(substream, AZF_CODEC_PLAYBACK);
1372 unsigned long bufptr, result; 1379}
1373 snd_pcm_uframes_t frmres;
1374 1380
1375#ifdef QUERY_HARDWARE 1381static snd_pcm_uframes_t
1376 bufptr = snd_azf3328_codec_inl(chip, IDX_IO_REC_DMA_START_1); 1382snd_azf3328_codec_capture_pointer(struct snd_pcm_substream *substream)
1377#else 1383{
1378 bufptr = substream->runtime->dma_addr; 1384 return snd_azf3328_codec_pointer(substream, AZF_CODEC_CAPTURE);
1379#endif 1385}
1380 result = snd_azf3328_codec_inl(chip, IDX_IO_REC_DMA_CURRPOS);
1381 1386
1382 /* calculate offset */ 1387static snd_pcm_uframes_t
1383 result -= bufptr; 1388snd_azf3328_codec_i2s_out_pointer(struct snd_pcm_substream *substream)
1384 frmres = bytes_to_frames( substream->runtime, result); 1389{
1385 snd_azf3328_dbgplay("REC @ 0x%8lx, frames %8ld\n", result, frmres); 1390 return snd_azf3328_codec_pointer(substream, AZF_CODEC_I2S_OUT);
1386 return frmres;
1387} 1391}
1388 1392
1389/******************************************************************/ 1393/******************************************************************/
1390 1394
1391#ifdef SUPPORT_GAMEPORT 1395#ifdef SUPPORT_GAMEPORT
1392static inline void 1396static inline void
1393snd_azf3328_gameport_irq_enable(struct snd_azf3328 *chip, int enable) 1397snd_azf3328_gameport_irq_enable(struct snd_azf3328 *chip,
1398 bool enable
1399)
1394{ 1400{
1395 snd_azf3328_io_reg_setb( 1401 snd_azf3328_io_reg_setb(
1396 chip->game_io+IDX_GAME_HWCONFIG, 1402 chip->game_io+IDX_GAME_HWCONFIG,
@@ -1400,7 +1406,9 @@ snd_azf3328_gameport_irq_enable(struct snd_azf3328 *chip, int enable)
1400} 1406}
1401 1407
1402static inline void 1408static inline void
1403snd_azf3328_gameport_legacy_address_enable(struct snd_azf3328 *chip, int enable) 1409snd_azf3328_gameport_legacy_address_enable(struct snd_azf3328 *chip,
1410 bool enable
1411)
1404{ 1412{
1405 snd_azf3328_io_reg_setb( 1413 snd_azf3328_io_reg_setb(
1406 chip->game_io+IDX_GAME_HWCONFIG, 1414 chip->game_io+IDX_GAME_HWCONFIG,
@@ -1409,10 +1417,27 @@ snd_azf3328_gameport_legacy_address_enable(struct snd_azf3328 *chip, int enable)
1409 ); 1417 );
1410} 1418}
1411 1419
1420static void
1421snd_azf3328_gameport_set_counter_frequency(struct snd_azf3328 *chip,
1422 unsigned int freq_cfg
1423)
1424{
1425 snd_azf3328_io_reg_setb(
1426 chip->game_io+IDX_GAME_HWCONFIG,
1427 0x02,
1428 (freq_cfg & 1) != 0
1429 );
1430 snd_azf3328_io_reg_setb(
1431 chip->game_io+IDX_GAME_HWCONFIG,
1432 0x04,
1433 (freq_cfg & 2) != 0
1434 );
1435}
1436
1412static inline void 1437static inline void
1413snd_azf3328_gameport_axis_circuit_enable(struct snd_azf3328 *chip, int enable) 1438snd_azf3328_gameport_axis_circuit_enable(struct snd_azf3328 *chip, bool enable)
1414{ 1439{
1415 snd_azf3328_codec_reg_6AH_update( 1440 snd_azf3328_ctrl_reg_6AH_update(
1416 chip, IO_6A_SOMETHING2_GAMEPORT, enable 1441 chip, IO_6A_SOMETHING2_GAMEPORT, enable
1417 ); 1442 );
1418} 1443}
@@ -1447,6 +1472,8 @@ snd_azf3328_gameport_open(struct gameport *gameport, int mode)
1447 break; 1472 break;
1448 } 1473 }
1449 1474
1475 snd_azf3328_gameport_set_counter_frequency(chip,
1476 GAME_HWCFG_ADC_COUNTER_FREQ_STD);
1450 snd_azf3328_gameport_axis_circuit_enable(chip, (res == 0)); 1477 snd_azf3328_gameport_axis_circuit_enable(chip, (res == 0));
1451 1478
1452 return res; 1479 return res;
@@ -1458,6 +1485,8 @@ snd_azf3328_gameport_close(struct gameport *gameport)
1458 struct snd_azf3328 *chip = gameport_get_port_data(gameport); 1485 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1459 1486
1460 snd_azf3328_dbggame("gameport_close\n"); 1487 snd_azf3328_dbggame("gameport_close\n");
1488 snd_azf3328_gameport_set_counter_frequency(chip,
1489 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
1461 snd_azf3328_gameport_axis_circuit_enable(chip, 0); 1490 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
1462} 1491}
1463 1492
@@ -1491,7 +1520,7 @@ snd_azf3328_gameport_cooked_read(struct gameport *gameport,
1491 1520
1492 val = snd_azf3328_game_inb(chip, IDX_GAME_AXES_CONFIG); 1521 val = snd_azf3328_game_inb(chip, IDX_GAME_AXES_CONFIG);
1493 if (val & GAME_AXES_SAMPLING_READY) { 1522 if (val & GAME_AXES_SAMPLING_READY) {
1494 for (i = 0; i < 4; ++i) { 1523 for (i = 0; i < ARRAY_SIZE(chip->axes); ++i) {
1495 /* configure the axis to read */ 1524 /* configure the axis to read */
1496 val = (i << 4) | 0x0f; 1525 val = (i << 4) | 0x0f;
1497 snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val); 1526 snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
@@ -1514,7 +1543,7 @@ snd_azf3328_gameport_cooked_read(struct gameport *gameport,
1514 snd_azf3328_game_outw(chip, IDX_GAME_AXIS_VALUE, 0xffff); 1543 snd_azf3328_game_outw(chip, IDX_GAME_AXIS_VALUE, 0xffff);
1515 spin_unlock_irqrestore(&chip->reg_lock, flags); 1544 spin_unlock_irqrestore(&chip->reg_lock, flags);
1516 1545
1517 for (i = 0; i < 4; i++) { 1546 for (i = 0; i < ARRAY_SIZE(chip->axes); i++) {
1518 axes[i] = chip->axes[i]; 1547 axes[i] = chip->axes[i];
1519 if (axes[i] == 0xffff) 1548 if (axes[i] == 0xffff)
1520 axes[i] = -1; 1549 axes[i] = -1;
@@ -1552,6 +1581,8 @@ snd_azf3328_gameport(struct snd_azf3328 *chip, int dev)
1552 /* DISABLE legacy address: we don't need it! */ 1581 /* DISABLE legacy address: we don't need it! */
1553 snd_azf3328_gameport_legacy_address_enable(chip, 0); 1582 snd_azf3328_gameport_legacy_address_enable(chip, 0);
1554 1583
1584 snd_azf3328_gameport_set_counter_frequency(chip,
1585 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
1555 snd_azf3328_gameport_axis_circuit_enable(chip, 0); 1586 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
1556 1587
1557 gameport_register_port(chip->gameport); 1588 gameport_register_port(chip->gameport);
@@ -1585,40 +1616,77 @@ snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1585static inline void 1616static inline void
1586snd_azf3328_irq_log_unknown_type(u8 which) 1617snd_azf3328_irq_log_unknown_type(u8 which)
1587{ 1618{
1588 snd_azf3328_dbgplay( 1619 snd_azf3328_dbgcodec(
1589 "azt3328: unknown IRQ type (%x) occurred, please report!\n", 1620 "azt3328: unknown IRQ type (%x) occurred, please report!\n",
1590 which 1621 which
1591 ); 1622 );
1592} 1623}
1593 1624
1625static inline void
1626snd_azf3328_codec_interrupt(struct snd_azf3328 *chip, u8 status)
1627{
1628 u8 which;
1629 enum snd_azf3328_codec_type codec_type;
1630 const struct snd_azf3328_codec_data *codec;
1631
1632 for (codec_type = AZF_CODEC_PLAYBACK;
1633 codec_type <= AZF_CODEC_I2S_OUT;
1634 ++codec_type) {
1635
1636 /* skip codec if there's no interrupt for it */
1637 if (!(status & (1 << codec_type)))
1638 continue;
1639
1640 codec = &chip->codecs[codec_type];
1641
1642 spin_lock(&chip->reg_lock);
1643 which = snd_azf3328_codec_inb(codec, IDX_IO_CODEC_IRQTYPE);
1644 /* ack all IRQ types immediately */
1645 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_IRQTYPE, which);
1646 spin_unlock(&chip->reg_lock);
1647
1648 if ((chip->pcm[codec_type]) && (codec->substream)) {
1649 snd_pcm_period_elapsed(codec->substream);
1650 snd_azf3328_dbgcodec("%s period done (#%x), @ %x\n",
1651 codec->name,
1652 which,
1653 snd_azf3328_codec_inl(
1654 codec, IDX_IO_CODEC_DMA_CURRPOS
1655 )
1656 );
1657 } else
1658 printk(KERN_WARNING "azt3328: irq handler problem!\n");
1659 if (which & IRQ_SOMETHING)
1660 snd_azf3328_irq_log_unknown_type(which);
1661 }
1662}
1663
1594static irqreturn_t 1664static irqreturn_t
1595snd_azf3328_interrupt(int irq, void *dev_id) 1665snd_azf3328_interrupt(int irq, void *dev_id)
1596{ 1666{
1597 struct snd_azf3328 *chip = dev_id; 1667 struct snd_azf3328 *chip = dev_id;
1598 u8 status, which; 1668 u8 status;
1599#if DEBUG_PLAY_REC 1669#if DEBUG_CODEC
1600 static unsigned long irq_count; 1670 static unsigned long irq_count;
1601#endif 1671#endif
1602 1672
1603 status = snd_azf3328_codec_inb(chip, IDX_IO_IRQSTATUS); 1673 status = snd_azf3328_ctrl_inb(chip, IDX_IO_IRQSTATUS);
1604 1674
1605 /* fast path out, to ease interrupt sharing */ 1675 /* fast path out, to ease interrupt sharing */
1606 if (!(status & 1676 if (!(status &
1607 (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_GAMEPORT|IRQ_MPU401|IRQ_TIMER) 1677 (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT
1678 |IRQ_GAMEPORT|IRQ_MPU401|IRQ_TIMER)
1608 )) 1679 ))
1609 return IRQ_NONE; /* must be interrupt for another device */ 1680 return IRQ_NONE; /* must be interrupt for another device */
1610 1681
1611 snd_azf3328_dbgplay( 1682 snd_azf3328_dbgcodec(
1612 "irq_count %ld! IDX_IO_PLAY_FLAGS %04x, " 1683 "irq_count %ld! IDX_IO_IRQSTATUS %04x\n",
1613 "IDX_IO_PLAY_IRQTYPE %04x, IDX_IO_IRQSTATUS %04x\n",
1614 irq_count++ /* debug-only */, 1684 irq_count++ /* debug-only */,
1615 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS),
1616 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_IRQTYPE),
1617 status 1685 status
1618 ); 1686 );
1619 1687
1620 if (status & IRQ_TIMER) { 1688 if (status & IRQ_TIMER) {
1621 /* snd_azf3328_dbgplay("timer %ld\n", 1689 /* snd_azf3328_dbgcodec("timer %ld\n",
1622 snd_azf3328_codec_inl(chip, IDX_IO_TIMER_VALUE) 1690 snd_azf3328_codec_inl(chip, IDX_IO_TIMER_VALUE)
1623 & TIMER_VALUE_MASK 1691 & TIMER_VALUE_MASK
1624 ); */ 1692 ); */
@@ -1626,71 +1694,36 @@ snd_azf3328_interrupt(int irq, void *dev_id)
1626 snd_timer_interrupt(chip->timer, chip->timer->sticks); 1694 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1627 /* ACK timer */ 1695 /* ACK timer */
1628 spin_lock(&chip->reg_lock); 1696 spin_lock(&chip->reg_lock);
1629 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07); 1697 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07);
1630 spin_unlock(&chip->reg_lock); 1698 spin_unlock(&chip->reg_lock);
1631 snd_azf3328_dbgplay("azt3328: timer IRQ\n"); 1699 snd_azf3328_dbgcodec("azt3328: timer IRQ\n");
1632 } 1700 }
1633 if (status & IRQ_PLAYBACK) {
1634 spin_lock(&chip->reg_lock);
1635 which = snd_azf3328_codec_inb(chip, IDX_IO_PLAY_IRQTYPE);
1636 /* ack all IRQ types immediately */
1637 snd_azf3328_codec_outb(chip, IDX_IO_PLAY_IRQTYPE, which);
1638 spin_unlock(&chip->reg_lock);
1639 1701
1640 if (chip->pcm && chip->audio_stream[AZF_PLAYBACK].substream) { 1702 if (status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT))
1641 snd_pcm_period_elapsed( 1703 snd_azf3328_codec_interrupt(chip, status);
1642 chip->audio_stream[AZF_PLAYBACK].substream
1643 );
1644 snd_azf3328_dbgplay("PLAY period done (#%x), @ %x\n",
1645 which,
1646 snd_azf3328_codec_inl(
1647 chip, IDX_IO_PLAY_DMA_CURRPOS
1648 )
1649 );
1650 } else
1651 printk(KERN_WARNING "azt3328: irq handler problem!\n");
1652 if (which & IRQ_PLAY_SOMETHING)
1653 snd_azf3328_irq_log_unknown_type(which);
1654 }
1655 if (status & IRQ_RECORDING) {
1656 spin_lock(&chip->reg_lock);
1657 which = snd_azf3328_codec_inb(chip, IDX_IO_REC_IRQTYPE);
1658 /* ack all IRQ types immediately */
1659 snd_azf3328_codec_outb(chip, IDX_IO_REC_IRQTYPE, which);
1660 spin_unlock(&chip->reg_lock);
1661 1704
1662 if (chip->pcm && chip->audio_stream[AZF_CAPTURE].substream) {
1663 snd_pcm_period_elapsed(
1664 chip->audio_stream[AZF_CAPTURE].substream
1665 );
1666 snd_azf3328_dbgplay("REC period done (#%x), @ %x\n",
1667 which,
1668 snd_azf3328_codec_inl(
1669 chip, IDX_IO_REC_DMA_CURRPOS
1670 )
1671 );
1672 } else
1673 printk(KERN_WARNING "azt3328: irq handler problem!\n");
1674 if (which & IRQ_REC_SOMETHING)
1675 snd_azf3328_irq_log_unknown_type(which);
1676 }
1677 if (status & IRQ_GAMEPORT) 1705 if (status & IRQ_GAMEPORT)
1678 snd_azf3328_gameport_interrupt(chip); 1706 snd_azf3328_gameport_interrupt(chip);
1707
1679 /* MPU401 has less critical IRQ requirements 1708 /* MPU401 has less critical IRQ requirements
1680 * than timer and playback/recording, right? */ 1709 * than timer and playback/recording, right? */
1681 if (status & IRQ_MPU401) { 1710 if (status & IRQ_MPU401) {
1682 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); 1711 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
1683 1712
1684 /* hmm, do we have to ack the IRQ here somehow? 1713 /* hmm, do we have to ack the IRQ here somehow?
1685 * If so, then I don't know how... */ 1714 * If so, then I don't know how yet... */
1686 snd_azf3328_dbgplay("azt3328: MPU401 IRQ\n"); 1715 snd_azf3328_dbgcodec("azt3328: MPU401 IRQ\n");
1687 } 1716 }
1688 return IRQ_HANDLED; 1717 return IRQ_HANDLED;
1689} 1718}
1690 1719
1691/*****************************************************************/ 1720/*****************************************************************/
1692 1721
1693static const struct snd_pcm_hardware snd_azf3328_playback = 1722/* as long as we think we have identical snd_pcm_hardware parameters
1723 for playback, capture and i2s out, we can use the same physical struct
1724 since the struct is simply being copied into a member.
1725*/
1726static const struct snd_pcm_hardware snd_azf3328_hardware =
1694{ 1727{
1695 /* FIXME!! Correct? */ 1728 /* FIXME!! Correct? */
1696 .info = SNDRV_PCM_INFO_MMAP | 1729 .info = SNDRV_PCM_INFO_MMAP |
@@ -1718,31 +1751,6 @@ static const struct snd_pcm_hardware snd_azf3328_playback =
1718 .fifo_size = 0, 1751 .fifo_size = 0,
1719}; 1752};
1720 1753
1721static const struct snd_pcm_hardware snd_azf3328_capture =
1722{
1723 /* FIXME */
1724 .info = SNDRV_PCM_INFO_MMAP |
1725 SNDRV_PCM_INFO_INTERLEAVED |
1726 SNDRV_PCM_INFO_MMAP_VALID,
1727 .formats = SNDRV_PCM_FMTBIT_S8 |
1728 SNDRV_PCM_FMTBIT_U8 |
1729 SNDRV_PCM_FMTBIT_S16_LE |
1730 SNDRV_PCM_FMTBIT_U16_LE,
1731 .rates = SNDRV_PCM_RATE_5512 |
1732 SNDRV_PCM_RATE_8000_48000 |
1733 SNDRV_PCM_RATE_KNOT,
1734 .rate_min = AZF_FREQ_4000,
1735 .rate_max = AZF_FREQ_66200,
1736 .channels_min = 1,
1737 .channels_max = 2,
1738 .buffer_bytes_max = 65536,
1739 .period_bytes_min = 64,
1740 .period_bytes_max = 65536,
1741 .periods_min = 1,
1742 .periods_max = 1024,
1743 .fifo_size = 0,
1744};
1745
1746 1754
1747static unsigned int snd_azf3328_fixed_rates[] = { 1755static unsigned int snd_azf3328_fixed_rates[] = {
1748 AZF_FREQ_4000, 1756 AZF_FREQ_4000,
@@ -1770,14 +1778,19 @@ static struct snd_pcm_hw_constraint_list snd_azf3328_hw_constraints_rates = {
1770/*****************************************************************/ 1778/*****************************************************************/
1771 1779
1772static int 1780static int
1773snd_azf3328_playback_open(struct snd_pcm_substream *substream) 1781snd_azf3328_pcm_open(struct snd_pcm_substream *substream,
1782 enum snd_azf3328_codec_type codec_type
1783)
1774{ 1784{
1775 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1785 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1776 struct snd_pcm_runtime *runtime = substream->runtime; 1786 struct snd_pcm_runtime *runtime = substream->runtime;
1777 1787
1778 snd_azf3328_dbgcallenter(); 1788 snd_azf3328_dbgcallenter();
1779 chip->audio_stream[AZF_PLAYBACK].substream = substream; 1789 chip->codecs[codec_type].substream = substream;
1780 runtime->hw = snd_azf3328_playback; 1790
1791 /* same parameters for all our codecs - at least we think so... */
1792 runtime->hw = snd_azf3328_hardware;
1793
1781 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 1794 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1782 &snd_azf3328_hw_constraints_rates); 1795 &snd_azf3328_hw_constraints_rates);
1783 snd_azf3328_dbgcallleave(); 1796 snd_azf3328_dbgcallleave();
@@ -1785,40 +1798,52 @@ snd_azf3328_playback_open(struct snd_pcm_substream *substream)
1785} 1798}
1786 1799
1787static int 1800static int
1801snd_azf3328_playback_open(struct snd_pcm_substream *substream)
1802{
1803 return snd_azf3328_pcm_open(substream, AZF_CODEC_PLAYBACK);
1804}
1805
1806static int
1788snd_azf3328_capture_open(struct snd_pcm_substream *substream) 1807snd_azf3328_capture_open(struct snd_pcm_substream *substream)
1789{ 1808{
1790 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1809 return snd_azf3328_pcm_open(substream, AZF_CODEC_CAPTURE);
1791 struct snd_pcm_runtime *runtime = substream->runtime; 1810}
1792 1811
1793 snd_azf3328_dbgcallenter(); 1812static int
1794 chip->audio_stream[AZF_CAPTURE].substream = substream; 1813snd_azf3328_i2s_out_open(struct snd_pcm_substream *substream)
1795 runtime->hw = snd_azf3328_capture; 1814{
1796 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 1815 return snd_azf3328_pcm_open(substream, AZF_CODEC_I2S_OUT);
1797 &snd_azf3328_hw_constraints_rates);
1798 snd_azf3328_dbgcallleave();
1799 return 0;
1800} 1816}
1801 1817
1802static int 1818static int
1803snd_azf3328_playback_close(struct snd_pcm_substream *substream) 1819snd_azf3328_pcm_close(struct snd_pcm_substream *substream,
1820 enum snd_azf3328_codec_type codec_type
1821)
1804{ 1822{
1805 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1823 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1806 1824
1807 snd_azf3328_dbgcallenter(); 1825 snd_azf3328_dbgcallenter();
1808 chip->audio_stream[AZF_PLAYBACK].substream = NULL; 1826 chip->codecs[codec_type].substream = NULL;
1809 snd_azf3328_dbgcallleave(); 1827 snd_azf3328_dbgcallleave();
1810 return 0; 1828 return 0;
1811} 1829}
1812 1830
1813static int 1831static int
1832snd_azf3328_playback_close(struct snd_pcm_substream *substream)
1833{
1834 return snd_azf3328_pcm_close(substream, AZF_CODEC_PLAYBACK);
1835}
1836
1837static int
1814snd_azf3328_capture_close(struct snd_pcm_substream *substream) 1838snd_azf3328_capture_close(struct snd_pcm_substream *substream)
1815{ 1839{
1816 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1840 return snd_azf3328_pcm_close(substream, AZF_CODEC_CAPTURE);
1841}
1817 1842
1818 snd_azf3328_dbgcallenter(); 1843static int
1819 chip->audio_stream[AZF_CAPTURE].substream = NULL; 1844snd_azf3328_i2s_out_close(struct snd_pcm_substream *substream)
1820 snd_azf3328_dbgcallleave(); 1845{
1821 return 0; 1846 return snd_azf3328_pcm_close(substream, AZF_CODEC_I2S_OUT);
1822} 1847}
1823 1848
1824/******************************************************************/ 1849/******************************************************************/
@@ -1829,9 +1854,9 @@ static struct snd_pcm_ops snd_azf3328_playback_ops = {
1829 .ioctl = snd_pcm_lib_ioctl, 1854 .ioctl = snd_pcm_lib_ioctl,
1830 .hw_params = snd_azf3328_hw_params, 1855 .hw_params = snd_azf3328_hw_params,
1831 .hw_free = snd_azf3328_hw_free, 1856 .hw_free = snd_azf3328_hw_free,
1832 .prepare = snd_azf3328_playback_prepare, 1857 .prepare = snd_azf3328_codec_prepare,
1833 .trigger = snd_azf3328_playback_trigger, 1858 .trigger = snd_azf3328_codec_playback_trigger,
1834 .pointer = snd_azf3328_playback_pointer 1859 .pointer = snd_azf3328_codec_playback_pointer
1835}; 1860};
1836 1861
1837static struct snd_pcm_ops snd_azf3328_capture_ops = { 1862static struct snd_pcm_ops snd_azf3328_capture_ops = {
@@ -1840,30 +1865,67 @@ static struct snd_pcm_ops snd_azf3328_capture_ops = {
1840 .ioctl = snd_pcm_lib_ioctl, 1865 .ioctl = snd_pcm_lib_ioctl,
1841 .hw_params = snd_azf3328_hw_params, 1866 .hw_params = snd_azf3328_hw_params,
1842 .hw_free = snd_azf3328_hw_free, 1867 .hw_free = snd_azf3328_hw_free,
1843 .prepare = snd_azf3328_capture_prepare, 1868 .prepare = snd_azf3328_codec_prepare,
1844 .trigger = snd_azf3328_capture_trigger, 1869 .trigger = snd_azf3328_codec_capture_trigger,
1845 .pointer = snd_azf3328_capture_pointer 1870 .pointer = snd_azf3328_codec_capture_pointer
1871};
1872
1873static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
1874 .open = snd_azf3328_i2s_out_open,
1875 .close = snd_azf3328_i2s_out_close,
1876 .ioctl = snd_pcm_lib_ioctl,
1877 .hw_params = snd_azf3328_hw_params,
1878 .hw_free = snd_azf3328_hw_free,
1879 .prepare = snd_azf3328_codec_prepare,
1880 .trigger = snd_azf3328_codec_i2s_out_trigger,
1881 .pointer = snd_azf3328_codec_i2s_out_pointer
1846}; 1882};
1847 1883
1848static int __devinit 1884static int __devinit
1849snd_azf3328_pcm(struct snd_azf3328 *chip, int device) 1885snd_azf3328_pcm(struct snd_azf3328 *chip)
1850{ 1886{
1887enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */
1888
1851 struct snd_pcm *pcm; 1889 struct snd_pcm *pcm;
1852 int err; 1890 int err;
1853 1891
1854 snd_azf3328_dbgcallenter(); 1892 snd_azf3328_dbgcallenter();
1855 if ((err = snd_pcm_new(chip->card, "AZF3328 DSP", device, 1, 1, &pcm)) < 0) 1893
1894 err = snd_pcm_new(chip->card, "AZF3328 DSP", AZF_PCMDEV_STD,
1895 1, 1, &pcm);
1896 if (err < 0)
1856 return err; 1897 return err;
1857 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_azf3328_playback_ops); 1898 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1858 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_azf3328_capture_ops); 1899 &snd_azf3328_playback_ops);
1900 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1901 &snd_azf3328_capture_ops);
1859 1902
1860 pcm->private_data = chip; 1903 pcm->private_data = chip;
1861 pcm->info_flags = 0; 1904 pcm->info_flags = 0;
1862 strcpy(pcm->name, chip->card->shortname); 1905 strcpy(pcm->name, chip->card->shortname);
1863 chip->pcm = pcm; 1906 /* same pcm object for playback/capture (see snd_pcm_new() above) */
1907 chip->pcm[AZF_CODEC_PLAYBACK] = pcm;
1908 chip->pcm[AZF_CODEC_CAPTURE] = pcm;
1864 1909
1865 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 1910 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1866 snd_dma_pci_data(chip->pci), 64*1024, 64*1024); 1911 snd_dma_pci_data(chip->pci),
1912 64*1024, 64*1024);
1913
1914 err = snd_pcm_new(chip->card, "AZF3328 I2S OUT", AZF_PCMDEV_I2S_OUT,
1915 1, 0, &pcm);
1916 if (err < 0)
1917 return err;
1918 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1919 &snd_azf3328_i2s_out_ops);
1920
1921 pcm->private_data = chip;
1922 pcm->info_flags = 0;
1923 strcpy(pcm->name, chip->card->shortname);
1924 chip->pcm[AZF_CODEC_I2S_OUT] = pcm;
1925
1926 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1927 snd_dma_pci_data(chip->pci),
1928 64*1024, 64*1024);
1867 1929
1868 snd_azf3328_dbgcallleave(); 1930 snd_azf3328_dbgcallleave();
1869 return 0; 1931 return 0;
@@ -1902,7 +1964,7 @@ snd_azf3328_timer_start(struct snd_timer *timer)
1902 snd_azf3328_dbgtimer("setting timer countdown value %d, add COUNTDOWN|IRQ\n", delay); 1964 snd_azf3328_dbgtimer("setting timer countdown value %d, add COUNTDOWN|IRQ\n", delay);
1903 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE; 1965 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE;
1904 spin_lock_irqsave(&chip->reg_lock, flags); 1966 spin_lock_irqsave(&chip->reg_lock, flags);
1905 snd_azf3328_codec_outl(chip, IDX_IO_TIMER_VALUE, delay); 1967 snd_azf3328_ctrl_outl(chip, IDX_IO_TIMER_VALUE, delay);
1906 spin_unlock_irqrestore(&chip->reg_lock, flags); 1968 spin_unlock_irqrestore(&chip->reg_lock, flags);
1907 snd_azf3328_dbgcallleave(); 1969 snd_azf3328_dbgcallleave();
1908 return 0; 1970 return 0;
@@ -1919,7 +1981,7 @@ snd_azf3328_timer_stop(struct snd_timer *timer)
1919 spin_lock_irqsave(&chip->reg_lock, flags); 1981 spin_lock_irqsave(&chip->reg_lock, flags);
1920 /* disable timer countdown and interrupt */ 1982 /* disable timer countdown and interrupt */
1921 /* FIXME: should we write TIMER_IRQ_ACK here? */ 1983 /* FIXME: should we write TIMER_IRQ_ACK here? */
1922 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0); 1984 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0);
1923 spin_unlock_irqrestore(&chip->reg_lock, flags); 1985 spin_unlock_irqrestore(&chip->reg_lock, flags);
1924 snd_azf3328_dbgcallleave(); 1986 snd_azf3328_dbgcallleave();
1925 return 0; 1987 return 0;
@@ -2035,7 +2097,7 @@ snd_azf3328_test_bit(unsigned unsigned reg, int bit)
2035 2097
2036 outb(val, reg); 2098 outb(val, reg);
2037 2099
2038 printk(KERN_ERR "reg %04x bit %d: %02x %02x %02x\n", 2100 printk(KERN_DEBUG "reg %04x bit %d: %02x %02x %02x\n",
2039 reg, bit, val, valoff, valon 2101 reg, bit, val, valoff, valon
2040 ); 2102 );
2041} 2103}
@@ -2048,9 +2110,9 @@ snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
2048 u16 tmp; 2110 u16 tmp;
2049 2111
2050 snd_azf3328_dbgmisc( 2112 snd_azf3328_dbgmisc(
2051 "codec_io 0x%lx, game_io 0x%lx, mpu_io 0x%lx, " 2113 "ctrl_io 0x%lx, game_io 0x%lx, mpu_io 0x%lx, "
2052 "opl3_io 0x%lx, mixer_io 0x%lx, irq %d\n", 2114 "opl3_io 0x%lx, mixer_io 0x%lx, irq %d\n",
2053 chip->codec_io, chip->game_io, chip->mpu_io, 2115 chip->ctrl_io, chip->game_io, chip->mpu_io,
2054 chip->opl3_io, chip->mixer_io, chip->irq 2116 chip->opl3_io, chip->mixer_io, chip->irq
2055 ); 2117 );
2056 2118
@@ -2083,9 +2145,9 @@ snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
2083 inb(0x38c + tmp) 2145 inb(0x38c + tmp)
2084 ); 2146 );
2085 2147
2086 for (tmp = 0; tmp < AZF_IO_SIZE_CODEC; tmp += 2) 2148 for (tmp = 0; tmp < AZF_IO_SIZE_CTRL; tmp += 2)
2087 snd_azf3328_dbgmisc("codec 0x%02x: 0x%04x\n", 2149 snd_azf3328_dbgmisc("ctrl 0x%02x: 0x%04x\n",
2088 tmp, snd_azf3328_codec_inw(chip, tmp) 2150 tmp, snd_azf3328_ctrl_inw(chip, tmp)
2089 ); 2151 );
2090 2152
2091 for (tmp = 0; tmp < AZF_IO_SIZE_MIXER; tmp += 2) 2153 for (tmp = 0; tmp < AZF_IO_SIZE_MIXER; tmp += 2)
@@ -2106,7 +2168,8 @@ snd_azf3328_create(struct snd_card *card,
2106 static struct snd_device_ops ops = { 2168 static struct snd_device_ops ops = {
2107 .dev_free = snd_azf3328_dev_free, 2169 .dev_free = snd_azf3328_dev_free,
2108 }; 2170 };
2109 u16 tmp; 2171 u8 dma_init;
2172 enum snd_azf3328_codec_type codec_type;
2110 2173
2111 *rchip = NULL; 2174 *rchip = NULL;
2112 2175
@@ -2138,14 +2201,21 @@ snd_azf3328_create(struct snd_card *card,
2138 if (err < 0) 2201 if (err < 0)
2139 goto out_err; 2202 goto out_err;
2140 2203
2141 chip->codec_io = pci_resource_start(pci, 0); 2204 chip->ctrl_io = pci_resource_start(pci, 0);
2142 chip->game_io = pci_resource_start(pci, 1); 2205 chip->game_io = pci_resource_start(pci, 1);
2143 chip->mpu_io = pci_resource_start(pci, 2); 2206 chip->mpu_io = pci_resource_start(pci, 2);
2144 chip->opl3_io = pci_resource_start(pci, 3); 2207 chip->opl3_io = pci_resource_start(pci, 3);
2145 chip->mixer_io = pci_resource_start(pci, 4); 2208 chip->mixer_io = pci_resource_start(pci, 4);
2146 2209
2147 chip->audio_stream[AZF_PLAYBACK].portbase = chip->codec_io + 0x00; 2210 chip->codecs[AZF_CODEC_PLAYBACK].io_base =
2148 chip->audio_stream[AZF_CAPTURE].portbase = chip->codec_io + 0x20; 2211 chip->ctrl_io + AZF_IO_OFFS_CODEC_PLAYBACK;
2212 chip->codecs[AZF_CODEC_PLAYBACK].name = "PLAYBACK";
2213 chip->codecs[AZF_CODEC_CAPTURE].io_base =
2214 chip->ctrl_io + AZF_IO_OFFS_CODEC_CAPTURE;
2215 chip->codecs[AZF_CODEC_CAPTURE].name = "CAPTURE";
2216 chip->codecs[AZF_CODEC_I2S_OUT].io_base =
2217 chip->ctrl_io + AZF_IO_OFFS_CODEC_I2S_OUT;
2218 chip->codecs[AZF_CODEC_I2S_OUT].name = "I2S_OUT";
2149 2219
2150 if (request_irq(pci->irq, snd_azf3328_interrupt, 2220 if (request_irq(pci->irq, snd_azf3328_interrupt,
2151 IRQF_SHARED, card->shortname, chip)) { 2221 IRQF_SHARED, card->shortname, chip)) {
@@ -2168,20 +2238,25 @@ snd_azf3328_create(struct snd_card *card,
2168 if (err < 0) 2238 if (err < 0)
2169 goto out_err; 2239 goto out_err;
2170 2240
2171 /* shutdown codecs to save power */ 2241 /* standard codec init stuff */
2172 /* have snd_azf3328_codec_activity() act properly */ 2242 /* default DMA init value */
2173 chip->audio_stream[AZF_PLAYBACK].running = 1; 2243 dma_init = DMA_RUN_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE;
2174 snd_azf3328_codec_activity(chip, AZF_PLAYBACK, 0);
2175 2244
2176 /* standard chip init stuff */ 2245 for (codec_type = AZF_CODEC_PLAYBACK;
2177 /* default IRQ init value */ 2246 codec_type <= AZF_CODEC_I2S_OUT; ++codec_type) {
2178 tmp = DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE; 2247 struct snd_azf3328_codec_data *codec =
2248 &chip->codecs[codec_type];
2179 2249
2180 spin_lock_irq(&chip->reg_lock); 2250 /* shutdown codecs to save power */
2181 snd_azf3328_codec_outb(chip, IDX_IO_PLAY_FLAGS, tmp); 2251 /* have ...ctrl_codec_activity() act properly */
2182 snd_azf3328_codec_outb(chip, IDX_IO_REC_FLAGS, tmp); 2252 codec->running = 1;
2183 snd_azf3328_codec_outb(chip, IDX_IO_SOMETHING_FLAGS, tmp); 2253 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0);
2184 spin_unlock_irq(&chip->reg_lock); 2254
2255 spin_lock_irq(&chip->reg_lock);
2256 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_DMA_FLAGS,
2257 dma_init);
2258 spin_unlock_irq(&chip->reg_lock);
2259 }
2185 2260
2186 snd_card_set_dev(card, &pci->dev); 2261 snd_card_set_dev(card, &pci->dev);
2187 2262
@@ -2229,8 +2304,11 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2229 2304
2230 card->private_data = chip; 2305 card->private_data = chip;
2231 2306
2307 /* chose to use MPU401_HW_AZT2320 ID instead of MPU401_HW_MPU401,
2308 since our hardware ought to be similar, thus use same ID. */
2232 err = snd_mpu401_uart_new( 2309 err = snd_mpu401_uart_new(
2233 card, 0, MPU401_HW_MPU401, chip->mpu_io, MPU401_INFO_INTEGRATED, 2310 card, 0,
2311 MPU401_HW_AZT2320, chip->mpu_io, MPU401_INFO_INTEGRATED,
2234 pci->irq, 0, &chip->rmidi 2312 pci->irq, 0, &chip->rmidi
2235 ); 2313 );
2236 if (err < 0) { 2314 if (err < 0) {
@@ -2244,7 +2322,7 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2244 if (err < 0) 2322 if (err < 0)
2245 goto out_err; 2323 goto out_err;
2246 2324
2247 err = snd_azf3328_pcm(chip, 0); 2325 err = snd_azf3328_pcm(chip);
2248 if (err < 0) 2326 if (err < 0)
2249 goto out_err; 2327 goto out_err;
2250 2328
@@ -2266,14 +2344,14 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2266 opl3->private_data = chip; 2344 opl3->private_data = chip;
2267 2345
2268 sprintf(card->longname, "%s at 0x%lx, irq %i", 2346 sprintf(card->longname, "%s at 0x%lx, irq %i",
2269 card->shortname, chip->codec_io, chip->irq); 2347 card->shortname, chip->ctrl_io, chip->irq);
2270 2348
2271 err = snd_card_register(card); 2349 err = snd_card_register(card);
2272 if (err < 0) 2350 if (err < 0)
2273 goto out_err; 2351 goto out_err;
2274 2352
2275#ifdef MODULE 2353#ifdef MODULE
2276 printk( 2354 printk(KERN_INFO
2277"azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168.\n" 2355"azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168.\n"
2278"azt3328: Hardware was completely undocumented, unfortunately.\n" 2356"azt3328: Hardware was completely undocumented, unfortunately.\n"
2279"azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n" 2357"azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n"
@@ -2308,36 +2386,52 @@ snd_azf3328_remove(struct pci_dev *pci)
2308} 2386}
2309 2387
2310#ifdef CONFIG_PM 2388#ifdef CONFIG_PM
2389static inline void
2390snd_azf3328_suspend_regs(unsigned long io_addr, unsigned count, u32 *saved_regs)
2391{
2392 unsigned reg;
2393
2394 for (reg = 0; reg < count; ++reg) {
2395 *saved_regs = inl(io_addr);
2396 snd_azf3328_dbgpm("suspend: io 0x%04lx: 0x%08x\n",
2397 io_addr, *saved_regs);
2398 ++saved_regs;
2399 io_addr += sizeof(*saved_regs);
2400 }
2401}
2402
2311static int 2403static int
2312snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state) 2404snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state)
2313{ 2405{
2314 struct snd_card *card = pci_get_drvdata(pci); 2406 struct snd_card *card = pci_get_drvdata(pci);
2315 struct snd_azf3328 *chip = card->private_data; 2407 struct snd_azf3328 *chip = card->private_data;
2316 unsigned reg; 2408 u16 *saved_regs_ctrl_u16;
2317 2409
2318 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2410 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2319 2411
2320 snd_pcm_suspend_all(chip->pcm); 2412 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_PLAYBACK]);
2413 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_I2S_OUT]);
2321 2414
2322 for (reg = 0; reg < AZF_IO_SIZE_MIXER_PM / 2; ++reg) 2415 snd_azf3328_suspend_regs(chip->mixer_io,
2323 chip->saved_regs_mixer[reg] = inw(chip->mixer_io + reg * 2); 2416 ARRAY_SIZE(chip->saved_regs_mixer), chip->saved_regs_mixer);
2324 2417
2325 /* make sure to disable master volume etc. to prevent looping sound */ 2418 /* make sure to disable master volume etc. to prevent looping sound */
2326 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); 2419 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
2327 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1); 2420 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
2328 2421
2329 for (reg = 0; reg < AZF_IO_SIZE_CODEC_PM / 2; ++reg) 2422 snd_azf3328_suspend_regs(chip->ctrl_io,
2330 chip->saved_regs_codec[reg] = inw(chip->codec_io + reg * 2); 2423 ARRAY_SIZE(chip->saved_regs_ctrl), chip->saved_regs_ctrl);
2331 2424
2332 /* manually store the one currently relevant write-only reg, too */ 2425 /* manually store the one currently relevant write-only reg, too */
2333 chip->saved_regs_codec[IDX_IO_6AH / 2] = chip->shadow_reg_codec_6AH; 2426 saved_regs_ctrl_u16 = (u16 *)chip->saved_regs_ctrl;
2427 saved_regs_ctrl_u16[IDX_IO_6AH / 2] = chip->shadow_reg_ctrl_6AH;
2334 2428
2335 for (reg = 0; reg < AZF_IO_SIZE_GAME_PM / 2; ++reg) 2429 snd_azf3328_suspend_regs(chip->game_io,
2336 chip->saved_regs_game[reg] = inw(chip->game_io + reg * 2); 2430 ARRAY_SIZE(chip->saved_regs_game), chip->saved_regs_game);
2337 for (reg = 0; reg < AZF_IO_SIZE_MPU_PM / 2; ++reg) 2431 snd_azf3328_suspend_regs(chip->mpu_io,
2338 chip->saved_regs_mpu[reg] = inw(chip->mpu_io + reg * 2); 2432 ARRAY_SIZE(chip->saved_regs_mpu), chip->saved_regs_mpu);
2339 for (reg = 0; reg < AZF_IO_SIZE_OPL3_PM / 2; ++reg) 2433 snd_azf3328_suspend_regs(chip->opl3_io,
2340 chip->saved_regs_opl3[reg] = inw(chip->opl3_io + reg * 2); 2434 ARRAY_SIZE(chip->saved_regs_opl3), chip->saved_regs_opl3);
2341 2435
2342 pci_disable_device(pci); 2436 pci_disable_device(pci);
2343 pci_save_state(pci); 2437 pci_save_state(pci);
@@ -2345,12 +2439,28 @@ snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state)
2345 return 0; 2439 return 0;
2346} 2440}
2347 2441
2442static inline void
2443snd_azf3328_resume_regs(const u32 *saved_regs,
2444 unsigned long io_addr,
2445 unsigned count
2446)
2447{
2448 unsigned reg;
2449
2450 for (reg = 0; reg < count; ++reg) {
2451 outl(*saved_regs, io_addr);
2452 snd_azf3328_dbgpm("resume: io 0x%04lx: 0x%08x --> 0x%08x\n",
2453 io_addr, *saved_regs, inl(io_addr));
2454 ++saved_regs;
2455 io_addr += sizeof(*saved_regs);
2456 }
2457}
2458
2348static int 2459static int
2349snd_azf3328_resume(struct pci_dev *pci) 2460snd_azf3328_resume(struct pci_dev *pci)
2350{ 2461{
2351 struct snd_card *card = pci_get_drvdata(pci); 2462 struct snd_card *card = pci_get_drvdata(pci);
2352 struct snd_azf3328 *chip = card->private_data; 2463 const struct snd_azf3328 *chip = card->private_data;
2353 unsigned reg;
2354 2464
2355 pci_set_power_state(pci, PCI_D0); 2465 pci_set_power_state(pci, PCI_D0);
2356 pci_restore_state(pci); 2466 pci_restore_state(pci);
@@ -2362,16 +2472,24 @@ snd_azf3328_resume(struct pci_dev *pci)
2362 } 2472 }
2363 pci_set_master(pci); 2473 pci_set_master(pci);
2364 2474
2365 for (reg = 0; reg < AZF_IO_SIZE_GAME_PM / 2; ++reg) 2475 snd_azf3328_resume_regs(chip->saved_regs_game, chip->game_io,
2366 outw(chip->saved_regs_game[reg], chip->game_io + reg * 2); 2476 ARRAY_SIZE(chip->saved_regs_game));
2367 for (reg = 0; reg < AZF_IO_SIZE_MPU_PM / 2; ++reg) 2477 snd_azf3328_resume_regs(chip->saved_regs_mpu, chip->mpu_io,
2368 outw(chip->saved_regs_mpu[reg], chip->mpu_io + reg * 2); 2478 ARRAY_SIZE(chip->saved_regs_mpu));
2369 for (reg = 0; reg < AZF_IO_SIZE_OPL3_PM / 2; ++reg) 2479 snd_azf3328_resume_regs(chip->saved_regs_opl3, chip->opl3_io,
2370 outw(chip->saved_regs_opl3[reg], chip->opl3_io + reg * 2); 2480 ARRAY_SIZE(chip->saved_regs_opl3));
2371 for (reg = 0; reg < AZF_IO_SIZE_MIXER_PM / 2; ++reg) 2481
2372 outw(chip->saved_regs_mixer[reg], chip->mixer_io + reg * 2); 2482 snd_azf3328_resume_regs(chip->saved_regs_mixer, chip->mixer_io,
2373 for (reg = 0; reg < AZF_IO_SIZE_CODEC_PM / 2; ++reg) 2483 ARRAY_SIZE(chip->saved_regs_mixer));
2374 outw(chip->saved_regs_codec[reg], chip->codec_io + reg * 2); 2484
2485 /* unfortunately with 32bit transfers, IDX_MIXER_PLAY_MASTER (0x02)
2486 and IDX_MIXER_RESET (offset 0x00) get touched at the same time,
2487 resulting in a mixer reset condition persisting until _after_
2488 master vol was restored. Thus master vol needs an extra restore. */
2489 outw(((u16 *)chip->saved_regs_mixer)[1], chip->mixer_io + 2);
2490
2491 snd_azf3328_resume_regs(chip->saved_regs_ctrl, chip->ctrl_io,
2492 ARRAY_SIZE(chip->saved_regs_ctrl));
2375 2493
2376 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 2494 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2377 return 0; 2495 return 0;
diff --git a/sound/pci/azt3328.h b/sound/pci/azt3328.h
index 974e05122f0..6f46b97650c 100644
--- a/sound/pci/azt3328.h
+++ b/sound/pci/azt3328.h
@@ -6,50 +6,59 @@
6 6
7/*** main I/O area port indices ***/ 7/*** main I/O area port indices ***/
8/* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */ 8/* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */
9#define AZF_IO_SIZE_CODEC 0x80 9#define AZF_IO_SIZE_CTRL 0x80
10#define AZF_IO_SIZE_CODEC_PM 0x70 10#define AZF_IO_SIZE_CTRL_PM 0x70
11 11
12/* the driver initialisation suggests a layout of 4 main areas: 12/* the driver initialisation suggests a layout of 4 areas
13 * from 0x00 (playback), from 0x20 (recording) and from 0x40 (maybe MPU401??). 13 * within the main card control I/O:
14 * from 0x00 (playback codec), from 0x20 (recording codec)
15 * and from 0x40 (most certainly I2S out codec).
14 * And another area from 0x60 to 0x6f (DirectX timer, IRQ management, 16 * And another area from 0x60 to 0x6f (DirectX timer, IRQ management,
15 * power management etc.???). */ 17 * power management etc.???). */
16 18
17/** playback area **/ 19#define AZF_IO_OFFS_CODEC_PLAYBACK 0x00
18#define IDX_IO_PLAY_FLAGS 0x00 /* PU:0x0000 */ 20#define AZF_IO_OFFS_CODEC_CAPTURE 0x20
21#define AZF_IO_OFFS_CODEC_I2S_OUT 0x40
22
23#define IDX_IO_CODEC_DMA_FLAGS 0x00 /* PU:0x0000 */
19 /* able to reactivate output after output muting due to 8/16bit 24 /* able to reactivate output after output muting due to 8/16bit
20 * output change, just like 0x0002. 25 * output change, just like 0x0002.
21 * 0x0001 is the only bit that's able to start the DMA counter */ 26 * 0x0001 is the only bit that's able to start the DMA counter */
22 #define DMA_RESUME 0x0001 /* paused if cleared ? */ 27 #define DMA_RESUME 0x0001 /* paused if cleared? */
23 /* 0x0002 *temporarily* set during DMA stopping. hmm 28 /* 0x0002 *temporarily* set during DMA stopping. hmm
24 * both 0x0002 and 0x0004 set in playback setup. */ 29 * both 0x0002 and 0x0004 set in playback setup. */
25 /* able to reactivate output after output muting due to 8/16bit 30 /* able to reactivate output after output muting due to 8/16bit
26 * output change, just like 0x0001. */ 31 * output change, just like 0x0001. */
27 #define DMA_PLAY_SOMETHING1 0x0002 /* \ alternated (toggled) */ 32 #define DMA_RUN_SOMETHING1 0x0002 /* \ alternated (toggled) */
28 /* 0x0004: NOT able to reactivate output */ 33 /* 0x0004: NOT able to reactivate output */
29 #define DMA_PLAY_SOMETHING2 0x0004 /* / bits */ 34 #define DMA_RUN_SOMETHING2 0x0004 /* / bits */
30 #define SOMETHING_ALMOST_ALWAYS_SET 0x0008 /* ???; can be modified */ 35 #define SOMETHING_ALMOST_ALWAYS_SET 0x0008 /* ???; can be modified */
31 #define DMA_EPILOGUE_SOMETHING 0x0010 36 #define DMA_EPILOGUE_SOMETHING 0x0010
32 #define DMA_SOMETHING_ELSE 0x0020 /* ??? */ 37 #define DMA_SOMETHING_ELSE 0x0020 /* ??? */
33 #define SOMETHING_UNMODIFIABLE 0xffc0 /* unused ? not modifiable */ 38 #define SOMETHING_UNMODIFIABLE 0xffc0 /* unused? not modifiable */
34#define IDX_IO_PLAY_IRQTYPE 0x02 /* PU:0x0001 */ 39#define IDX_IO_CODEC_IRQTYPE 0x02 /* PU:0x0001 */
35 /* write back to flags in case flags are set, in order to ACK IRQ in handler 40 /* write back to flags in case flags are set, in order to ACK IRQ in handler
36 * (bit 1 of port 0x64 indicates interrupt for one of these three types) 41 * (bit 1 of port 0x64 indicates interrupt for one of these three types)
37 * sometimes in this case it just writes 0xffff to globally ACK all IRQs 42 * sometimes in this case it just writes 0xffff to globally ACK all IRQs
38 * settings written are not reflected when reading back, though. 43 * settings written are not reflected when reading back, though.
39 * seems to be IRQ, too (frequently used: port |= 0x07 !), but who knows ? */ 44 * seems to be IRQ, too (frequently used: port |= 0x07 !), but who knows? */
40 #define IRQ_PLAY_SOMETHING 0x0001 /* something & ACK */ 45 #define IRQ_SOMETHING 0x0001 /* something & ACK */
41 #define IRQ_FINISHED_PLAYBUF_1 0x0002 /* 1st dmabuf finished & ACK */ 46 #define IRQ_FINISHED_DMABUF_1 0x0002 /* 1st dmabuf finished & ACK */
42 #define IRQ_FINISHED_PLAYBUF_2 0x0004 /* 2nd dmabuf finished & ACK */ 47 #define IRQ_FINISHED_DMABUF_2 0x0004 /* 2nd dmabuf finished & ACK */
43 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */ 48 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */
44 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */ 49 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */
45 #define IRQMASK_UNMODIFIABLE 0xffe0 /* unused ? not modifiable */ 50 #define IRQMASK_UNMODIFIABLE 0xffe0 /* unused? not modifiable */
46#define IDX_IO_PLAY_DMA_START_1 0x04 /* start address of 1st DMA play area, PU:0x00000000 */ 51 /* start address of 1st DMA transfer area, PU:0x00000000 */
47#define IDX_IO_PLAY_DMA_START_2 0x08 /* start address of 2nd DMA play area, PU:0x00000000 */ 52#define IDX_IO_CODEC_DMA_START_1 0x04
48#define IDX_IO_PLAY_DMA_LEN_1 0x0c /* length of 1st DMA play area, PU:0x0000 */ 53 /* start address of 2nd DMA transfer area, PU:0x00000000 */
49#define IDX_IO_PLAY_DMA_LEN_2 0x0e /* length of 2nd DMA play area, PU:0x0000 */ 54#define IDX_IO_CODEC_DMA_START_2 0x08
50#define IDX_IO_PLAY_DMA_CURRPOS 0x10 /* current DMA position, PU:0x00000000 */ 55 /* both lengths of DMA transfer areas, PU:0x00000000
51#define IDX_IO_PLAY_DMA_CURROFS 0x14 /* offset within current DMA play area, PU:0x0000 */ 56 length1: offset 0x0c, length2: offset 0x0e */
52#define IDX_IO_PLAY_SOUNDFORMAT 0x16 /* PU:0x0010 */ 57#define IDX_IO_CODEC_DMA_LENGTHS 0x0c
58#define IDX_IO_CODEC_DMA_CURRPOS 0x10 /* current DMA position, PU:0x00000000 */
59 /* offset within current DMA transfer area, PU:0x0000 */
60#define IDX_IO_CODEC_DMA_CURROFS 0x14
61#define IDX_IO_CODEC_SOUNDFORMAT 0x16 /* PU:0x0010 */
53 /* all unspecified bits can't be modified */ 62 /* all unspecified bits can't be modified */
54 #define SOUNDFORMAT_FREQUENCY_MASK 0x000f 63 #define SOUNDFORMAT_FREQUENCY_MASK 0x000f
55 #define SOUNDFORMAT_XTAL1 0x00 64 #define SOUNDFORMAT_XTAL1 0x00
@@ -76,6 +85,7 @@
76 #define SOUNDFORMAT_FLAG_16BIT 0x0010 85 #define SOUNDFORMAT_FLAG_16BIT 0x0010
77 #define SOUNDFORMAT_FLAG_2CHANNELS 0x0020 86 #define SOUNDFORMAT_FLAG_2CHANNELS 0x0020
78 87
88
79/* define frequency helpers, for maximum value safety */ 89/* define frequency helpers, for maximum value safety */
80enum azf_freq_t { 90enum azf_freq_t {
81#define AZF_FREQ(rate) AZF_FREQ_##rate = rate 91#define AZF_FREQ(rate) AZF_FREQ_##rate = rate
@@ -96,29 +106,6 @@ enum azf_freq_t {
96#undef AZF_FREQ 106#undef AZF_FREQ
97}; 107};
98 108
99/** recording area (see also: playback bit flag definitions) **/
100#define IDX_IO_REC_FLAGS 0x20 /* ??, PU:0x0000 */
101#define IDX_IO_REC_IRQTYPE 0x22 /* ??, PU:0x0000 */
102 #define IRQ_REC_SOMETHING 0x0001 /* something & ACK */
103 #define IRQ_FINISHED_RECBUF_1 0x0002 /* 1st dmabuf finished & ACK */
104 #define IRQ_FINISHED_RECBUF_2 0x0004 /* 2nd dmabuf finished & ACK */
105 /* hmm, maybe these are just the corresponding *recording* flags ?
106 * but OTOH they are most likely at port 0x22 instead */
107 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */
108 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */
109#define IDX_IO_REC_DMA_START_1 0x24 /* PU:0x00000000 */
110#define IDX_IO_REC_DMA_START_2 0x28 /* PU:0x00000000 */
111#define IDX_IO_REC_DMA_LEN_1 0x2c /* PU:0x0000 */
112#define IDX_IO_REC_DMA_LEN_2 0x2e /* PU:0x0000 */
113#define IDX_IO_REC_DMA_CURRPOS 0x30 /* PU:0x00000000 */
114#define IDX_IO_REC_DMA_CURROFS 0x34 /* PU:0x00000000 */
115#define IDX_IO_REC_SOUNDFORMAT 0x36 /* PU:0x0000 */
116
117/** hmm, what is this I/O area for? MPU401?? or external DAC via I2S?? (after playback, recording, ???, timer) **/
118#define IDX_IO_SOMETHING_FLAGS 0x40 /* gets set to 0x34 just like port 0x0 and 0x20 on card init, PU:0x0000 */
119/* general */
120#define IDX_IO_42H 0x42 /* PU:0x0001 */
121
122/** DirectX timer, main interrupt area (FIXME: and something else?) **/ 109/** DirectX timer, main interrupt area (FIXME: and something else?) **/
123#define IDX_IO_TIMER_VALUE 0x60 /* found this timer area by pure luck :-) */ 110#define IDX_IO_TIMER_VALUE 0x60 /* found this timer area by pure luck :-) */
124 /* timer countdown value; triggers IRQ when timer is finished */ 111 /* timer countdown value; triggers IRQ when timer is finished */
@@ -133,17 +120,19 @@ enum azf_freq_t {
133#define IDX_IO_IRQSTATUS 0x64 120#define IDX_IO_IRQSTATUS 0x64
134 /* some IRQ bit in here might also be used to signal a power-management timer 121 /* some IRQ bit in here might also be used to signal a power-management timer
135 * timeout, to request shutdown of the chip (e.g. AD1815JS has such a thing). 122 * timeout, to request shutdown of the chip (e.g. AD1815JS has such a thing).
136 * Some OPL3 hardware (e.g. in LM4560) has some special timer hardware which 123 * OPL3 hardware contains several timers which confusingly in most cases
137 * can trigger an OPL3 timer IRQ, so maybe there's such a thing as well... */ 124 * are NOT routed to an IRQ, but some designs (e.g. LM4560) DO support that,
125 * so I wouldn't be surprised at all to discover that AZF3328
126 * supports that thing as well... */
138 127
139 #define IRQ_PLAYBACK 0x0001 128 #define IRQ_PLAYBACK 0x0001
140 #define IRQ_RECORDING 0x0002 129 #define IRQ_RECORDING 0x0002
141 #define IRQ_UNKNOWN1 0x0004 /* most probably I2S port */ 130 #define IRQ_I2S_OUT 0x0004 /* this IS I2S, right!? (untested) */
142 #define IRQ_GAMEPORT 0x0008 /* Interrupt of Digital(ly) Enhanced Game Port */ 131 #define IRQ_GAMEPORT 0x0008 /* Interrupt of Digital(ly) Enhanced Game Port */
143 #define IRQ_MPU401 0x0010 132 #define IRQ_MPU401 0x0010
144 #define IRQ_TIMER 0x0020 /* DirectX timer */ 133 #define IRQ_TIMER 0x0020 /* DirectX timer */
145 #define IRQ_UNKNOWN2 0x0040 /* probably unused, or possibly I2S port? */ 134 #define IRQ_UNKNOWN2 0x0040 /* probably unused, or possibly OPL3 timer? */
146 #define IRQ_UNKNOWN3 0x0080 /* probably unused, or possibly I2S port? */ 135 #define IRQ_UNKNOWN3 0x0080 /* probably unused, or possibly OPL3 timer? */
147#define IDX_IO_66H 0x66 /* writing 0xffff returns 0x0000 */ 136#define IDX_IO_66H 0x66 /* writing 0xffff returns 0x0000 */
148 /* this is set to e.g. 0x3ff or 0x300, and writable; 137 /* this is set to e.g. 0x3ff or 0x300, and writable;
149 * maybe some buffer limit, but I couldn't find out more, PU:0x00ff: */ 138 * maybe some buffer limit, but I couldn't find out more, PU:0x00ff: */
@@ -206,7 +195,7 @@ enum azf_freq_t {
206/*** Gameport area port indices ***/ 195/*** Gameport area port indices ***/
207/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */ 196/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */
208#define AZF_IO_SIZE_GAME 0x08 197#define AZF_IO_SIZE_GAME 0x08
209#define AZF_IO_SIZE_GAME_PM 0x06 198#define AZF_IO_SIZE_GAME_PM 0x06
210 199
211enum { 200enum {
212 AZF_GAME_LEGACY_IO_PORT = 0x200 201 AZF_GAME_LEGACY_IO_PORT = 0x200
@@ -272,6 +261,12 @@ enum {
272 * 11 --> 1/200: */ 261 * 11 --> 1/200: */
273 #define GAME_HWCFG_ADC_COUNTER_FREQ_MASK 0x06 262 #define GAME_HWCFG_ADC_COUNTER_FREQ_MASK 0x06
274 263
264 /* FIXME: these values might be reversed... */
265 #define GAME_HWCFG_ADC_COUNTER_FREQ_STD 0
266 #define GAME_HWCFG_ADC_COUNTER_FREQ_1_2 1
267 #define GAME_HWCFG_ADC_COUNTER_FREQ_1_20 2
268 #define GAME_HWCFG_ADC_COUNTER_FREQ_1_200 3
269
275 /* enable gameport legacy I/O address (0x200) 270 /* enable gameport legacy I/O address (0x200)
276 * I was unable to locate any configurability for a different address: */ 271 * I was unable to locate any configurability for a different address: */
277 #define GAME_HWCFG_LEGACY_ADDRESS_ENABLE 0x08 272 #define GAME_HWCFG_LEGACY_ADDRESS_ENABLE 0x08
@@ -281,6 +276,7 @@ enum {
281#define AZF_IO_SIZE_MPU_PM 0x04 276#define AZF_IO_SIZE_MPU_PM 0x04
282 277
283/*** OPL3 synth ***/ 278/*** OPL3 synth ***/
279/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */
284#define AZF_IO_SIZE_OPL3 0x08 280#define AZF_IO_SIZE_OPL3 0x08
285#define AZF_IO_SIZE_OPL3_PM 0x06 281#define AZF_IO_SIZE_OPL3_PM 0x06
286/* hmm, given that a standard OPL3 has 4 registers only, 282/* hmm, given that a standard OPL3 has 4 registers only,
@@ -340,4 +336,7 @@ enum {
340#define SET_CHAN_LEFT 1 336#define SET_CHAN_LEFT 1
341#define SET_CHAN_RIGHT 2 337#define SET_CHAN_RIGHT 2
342 338
339/* helper macro to align I/O port ranges to 32bit I/O width */
340#define AZF_ALIGN(x) (((x) + 3) & (~3))
341
343#endif /* __SOUND_AZT3328_H */ 342#endif /* __SOUND_AZT3328_H */
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index f24bf1ecb36..15e4138bce1 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -325,9 +325,9 @@ static struct snd_pcm_hardware snd_ca0106_capture_hw = {
325 .rate_max = 192000, 325 .rate_max = 192000,
326 .channels_min = 2, 326 .channels_min = 2,
327 .channels_max = 2, 327 .channels_max = 2,
328 .buffer_bytes_max = ((65536 - 64) * 8), 328 .buffer_bytes_max = 65536 - 128,
329 .period_bytes_min = 64, 329 .period_bytes_min = 64,
330 .period_bytes_max = (65536 - 64), 330 .period_bytes_max = 32768 - 64,
331 .periods_min = 2, 331 .periods_min = 2,
332 .periods_max = 2, 332 .periods_max = 2,
333 .fifo_size = 0, 333 .fifo_size = 0,
diff --git a/sound/pci/cs46xx/cs46xx_lib.h b/sound/pci/cs46xx/cs46xx_lib.h
index 4eb55aa3361..b5189495d58 100644
--- a/sound/pci/cs46xx/cs46xx_lib.h
+++ b/sound/pci/cs46xx/cs46xx_lib.h
@@ -35,7 +35,7 @@
35 35
36 36
37#ifdef CONFIG_SND_CS46XX_NEW_DSP 37#ifdef CONFIG_SND_CS46XX_NEW_DSP
38#define CS46XX_MIN_PERIOD_SIZE 1 38#define CS46XX_MIN_PERIOD_SIZE 64
39#define CS46XX_MAX_PERIOD_SIZE 1024*1024 39#define CS46XX_MAX_PERIOD_SIZE 1024*1024
40#else 40#else
41#define CS46XX_MIN_PERIOD_SIZE 2048 41#define CS46XX_MIN_PERIOD_SIZE 2048
diff --git a/sound/pci/ctxfi/ct20k2reg.h b/sound/pci/ctxfi/ct20k2reg.h
index 2d07986f57c..e0394e3996e 100644
--- a/sound/pci/ctxfi/ct20k2reg.h
+++ b/sound/pci/ctxfi/ct20k2reg.h
@@ -11,9 +11,12 @@
11 11
12 12
13/* Timer Registers */ 13/* Timer Registers */
14#define TIMER_TIMR 0x1B7004 14#define WC 0x1b7000
15#define INTERRUPT_GIP 0x1B7010 15#define TIMR 0x1b7004
16#define INTERRUPT_GIE 0x1B7014 16# define TIMR_IE (1<<15)
17# define TIMR_IP (1<<14)
18#define GIP 0x1b7010
19#define GIE 0x1b7014
17 20
18/* I2C Registers */ 21/* I2C Registers */
19#define I2C_IF_ADDRESS 0x1B9000 22#define I2C_IF_ADDRESS 0x1B9000
diff --git a/sound/pci/ctxfi/ctamixer.c b/sound/pci/ctxfi/ctamixer.c
index a1db51b3ead..fee35cfc0c7 100644
--- a/sound/pci/ctxfi/ctamixer.c
+++ b/sound/pci/ctxfi/ctamixer.c
@@ -63,7 +63,7 @@ static int amixer_set_input(struct amixer *amixer, struct rsc *rsc)
63 hw = amixer->rsc.hw; 63 hw = amixer->rsc.hw;
64 hw->amixer_set_mode(amixer->rsc.ctrl_blk, AMIXER_Y_IMMEDIATE); 64 hw->amixer_set_mode(amixer->rsc.ctrl_blk, AMIXER_Y_IMMEDIATE);
65 amixer->input = rsc; 65 amixer->input = rsc;
66 if (NULL == rsc) 66 if (!rsc)
67 hw->amixer_set_x(amixer->rsc.ctrl_blk, BLANK_SLOT); 67 hw->amixer_set_x(amixer->rsc.ctrl_blk, BLANK_SLOT);
68 else 68 else
69 hw->amixer_set_x(amixer->rsc.ctrl_blk, 69 hw->amixer_set_x(amixer->rsc.ctrl_blk,
@@ -99,7 +99,7 @@ static int amixer_set_sum(struct amixer *amixer, struct sum *sum)
99 99
100 hw = amixer->rsc.hw; 100 hw = amixer->rsc.hw;
101 amixer->sum = sum; 101 amixer->sum = sum;
102 if (NULL == sum) { 102 if (!sum) {
103 hw->amixer_set_se(amixer->rsc.ctrl_blk, 0); 103 hw->amixer_set_se(amixer->rsc.ctrl_blk, 0);
104 } else { 104 } else {
105 hw->amixer_set_se(amixer->rsc.ctrl_blk, 1); 105 hw->amixer_set_se(amixer->rsc.ctrl_blk, 1);
@@ -124,20 +124,20 @@ static int amixer_commit_write(struct amixer *amixer)
124 124
125 /* Program master and conjugate resources */ 125 /* Program master and conjugate resources */
126 amixer->rsc.ops->master(&amixer->rsc); 126 amixer->rsc.ops->master(&amixer->rsc);
127 if (NULL != input) 127 if (input)
128 input->ops->master(input); 128 input->ops->master(input);
129 129
130 if (NULL != sum) 130 if (sum)
131 sum->rsc.ops->master(&sum->rsc); 131 sum->rsc.ops->master(&sum->rsc);
132 132
133 for (i = 0; i < amixer->rsc.msr; i++) { 133 for (i = 0; i < amixer->rsc.msr; i++) {
134 hw->amixer_set_dirty_all(amixer->rsc.ctrl_blk); 134 hw->amixer_set_dirty_all(amixer->rsc.ctrl_blk);
135 if (NULL != input) { 135 if (input) {
136 hw->amixer_set_x(amixer->rsc.ctrl_blk, 136 hw->amixer_set_x(amixer->rsc.ctrl_blk,
137 input->ops->output_slot(input)); 137 input->ops->output_slot(input));
138 input->ops->next_conj(input); 138 input->ops->next_conj(input);
139 } 139 }
140 if (NULL != sum) { 140 if (sum) {
141 hw->amixer_set_sadr(amixer->rsc.ctrl_blk, 141 hw->amixer_set_sadr(amixer->rsc.ctrl_blk,
142 sum->rsc.ops->index(&sum->rsc)); 142 sum->rsc.ops->index(&sum->rsc));
143 sum->rsc.ops->next_conj(&sum->rsc); 143 sum->rsc.ops->next_conj(&sum->rsc);
@@ -147,10 +147,10 @@ static int amixer_commit_write(struct amixer *amixer)
147 amixer->rsc.ops->next_conj(&amixer->rsc); 147 amixer->rsc.ops->next_conj(&amixer->rsc);
148 } 148 }
149 amixer->rsc.ops->master(&amixer->rsc); 149 amixer->rsc.ops->master(&amixer->rsc);
150 if (NULL != input) 150 if (input)
151 input->ops->master(input); 151 input->ops->master(input);
152 152
153 if (NULL != sum) 153 if (sum)
154 sum->rsc.ops->master(&sum->rsc); 154 sum->rsc.ops->master(&sum->rsc);
155 155
156 return 0; 156 return 0;
@@ -242,13 +242,12 @@ static int get_amixer_rsc(struct amixer_mgr *mgr,
242 242
243 /* Allocate mem for amixer resource */ 243 /* Allocate mem for amixer resource */
244 amixer = kzalloc(sizeof(*amixer), GFP_KERNEL); 244 amixer = kzalloc(sizeof(*amixer), GFP_KERNEL);
245 if (NULL == amixer) { 245 if (!amixer)
246 err = -ENOMEM; 246 return -ENOMEM;
247 return err;
248 }
249 247
250 /* Check whether there are sufficient 248 /* Check whether there are sufficient
251 * amixer resources to meet request. */ 249 * amixer resources to meet request. */
250 err = 0;
252 spin_lock_irqsave(&mgr->mgr_lock, flags); 251 spin_lock_irqsave(&mgr->mgr_lock, flags);
253 for (i = 0; i < desc->msr; i++) { 252 for (i = 0; i < desc->msr; i++) {
254 err = mgr_get_resource(&mgr->mgr, 1, &idx); 253 err = mgr_get_resource(&mgr->mgr, 1, &idx);
@@ -304,7 +303,7 @@ int amixer_mgr_create(void *hw, struct amixer_mgr **ramixer_mgr)
304 303
305 *ramixer_mgr = NULL; 304 *ramixer_mgr = NULL;
306 amixer_mgr = kzalloc(sizeof(*amixer_mgr), GFP_KERNEL); 305 amixer_mgr = kzalloc(sizeof(*amixer_mgr), GFP_KERNEL);
307 if (NULL == amixer_mgr) 306 if (!amixer_mgr)
308 return -ENOMEM; 307 return -ENOMEM;
309 308
310 err = rsc_mgr_init(&amixer_mgr->mgr, AMIXER, AMIXER_RESOURCE_NUM, hw); 309 err = rsc_mgr_init(&amixer_mgr->mgr, AMIXER, AMIXER_RESOURCE_NUM, hw);
@@ -397,12 +396,11 @@ static int get_sum_rsc(struct sum_mgr *mgr,
397 396
398 /* Allocate mem for sum resource */ 397 /* Allocate mem for sum resource */
399 sum = kzalloc(sizeof(*sum), GFP_KERNEL); 398 sum = kzalloc(sizeof(*sum), GFP_KERNEL);
400 if (NULL == sum) { 399 if (!sum)
401 err = -ENOMEM; 400 return -ENOMEM;
402 return err;
403 }
404 401
405 /* Check whether there are sufficient sum resources to meet request. */ 402 /* Check whether there are sufficient sum resources to meet request. */
403 err = 0;
406 spin_lock_irqsave(&mgr->mgr_lock, flags); 404 spin_lock_irqsave(&mgr->mgr_lock, flags);
407 for (i = 0; i < desc->msr; i++) { 405 for (i = 0; i < desc->msr; i++) {
408 err = mgr_get_resource(&mgr->mgr, 1, &idx); 406 err = mgr_get_resource(&mgr->mgr, 1, &idx);
@@ -458,7 +456,7 @@ int sum_mgr_create(void *hw, struct sum_mgr **rsum_mgr)
458 456
459 *rsum_mgr = NULL; 457 *rsum_mgr = NULL;
460 sum_mgr = kzalloc(sizeof(*sum_mgr), GFP_KERNEL); 458 sum_mgr = kzalloc(sizeof(*sum_mgr), GFP_KERNEL);
461 if (NULL == sum_mgr) 459 if (!sum_mgr)
462 return -ENOMEM; 460 return -ENOMEM;
463 461
464 err = rsc_mgr_init(&sum_mgr->mgr, SUM, SUM_RESOURCE_NUM, hw); 462 err = rsc_mgr_init(&sum_mgr->mgr, SUM, SUM_RESOURCE_NUM, hw);
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index a49c7664730..b1b3a644f73 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -136,7 +136,7 @@ static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
136 struct snd_pcm_runtime *runtime; 136 struct snd_pcm_runtime *runtime;
137 struct ct_vm *vm; 137 struct ct_vm *vm;
138 138
139 if (NULL == apcm->substream) 139 if (!apcm->substream)
140 return 0; 140 return 0;
141 141
142 runtime = apcm->substream->runtime; 142 runtime = apcm->substream->runtime;
@@ -144,7 +144,7 @@ static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
144 144
145 apcm->vm_block = vm->map(vm, apcm->substream, runtime->dma_bytes); 145 apcm->vm_block = vm->map(vm, apcm->substream, runtime->dma_bytes);
146 146
147 if (NULL == apcm->vm_block) 147 if (!apcm->vm_block)
148 return -ENOENT; 148 return -ENOENT;
149 149
150 return 0; 150 return 0;
@@ -154,7 +154,7 @@ static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
154{ 154{
155 struct ct_vm *vm; 155 struct ct_vm *vm;
156 156
157 if (NULL == apcm->vm_block) 157 if (!apcm->vm_block)
158 return; 158 return;
159 159
160 vm = atc->vm; 160 vm = atc->vm;
@@ -231,16 +231,16 @@ atc_get_pitch(unsigned int input_rate, unsigned int output_rate)
231 231
232static int select_rom(unsigned int pitch) 232static int select_rom(unsigned int pitch)
233{ 233{
234 if ((pitch > 0x00428f5c) && (pitch < 0x01b851ec)) { 234 if (pitch > 0x00428f5c && pitch < 0x01b851ec) {
235 /* 0.26 <= pitch <= 1.72 */ 235 /* 0.26 <= pitch <= 1.72 */
236 return 1; 236 return 1;
237 } else if ((0x01d66666 == pitch) || (0x01d66667 == pitch)) { 237 } else if (pitch == 0x01d66666 || pitch == 0x01d66667) {
238 /* pitch == 1.8375 */ 238 /* pitch == 1.8375 */
239 return 2; 239 return 2;
240 } else if (0x02000000 == pitch) { 240 } else if (pitch == 0x02000000) {
241 /* pitch == 2 */ 241 /* pitch == 2 */
242 return 3; 242 return 3;
243 } else if ((pitch >= 0x0) && (pitch <= 0x08000000)) { 243 } else if (pitch >= 0x0 && pitch <= 0x08000000) {
244 /* 0 <= pitch <= 8 */ 244 /* 0 <= pitch <= 8 */
245 return 0; 245 return 0;
246 } else { 246 } else {
@@ -283,7 +283,7 @@ static int atc_pcm_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm)
283 /* Get AMIXER resource */ 283 /* Get AMIXER resource */
284 n_amixer = (n_amixer < 2) ? 2 : n_amixer; 284 n_amixer = (n_amixer < 2) ? 2 : n_amixer;
285 apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); 285 apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL);
286 if (NULL == apcm->amixers) { 286 if (!apcm->amixers) {
287 err = -ENOMEM; 287 err = -ENOMEM;
288 goto error1; 288 goto error1;
289 } 289 }
@@ -311,7 +311,7 @@ static int atc_pcm_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm)
311 INIT_VOL, atc->pcm[i+device*2]); 311 INIT_VOL, atc->pcm[i+device*2]);
312 mutex_unlock(&atc->atc_mutex); 312 mutex_unlock(&atc->atc_mutex);
313 src = src->ops->next_interleave(src); 313 src = src->ops->next_interleave(src);
314 if (NULL == src) 314 if (!src)
315 src = apcm->src; 315 src = apcm->src;
316 } 316 }
317 317
@@ -334,7 +334,7 @@ atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
334 struct srcimp *srcimp; 334 struct srcimp *srcimp;
335 int i; 335 int i;
336 336
337 if (NULL != apcm->srcimps) { 337 if (apcm->srcimps) {
338 for (i = 0; i < apcm->n_srcimp; i++) { 338 for (i = 0; i < apcm->n_srcimp; i++) {
339 srcimp = apcm->srcimps[i]; 339 srcimp = apcm->srcimps[i];
340 srcimp->ops->unmap(srcimp); 340 srcimp->ops->unmap(srcimp);
@@ -345,7 +345,7 @@ atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
345 apcm->srcimps = NULL; 345 apcm->srcimps = NULL;
346 } 346 }
347 347
348 if (NULL != apcm->srccs) { 348 if (apcm->srccs) {
349 for (i = 0; i < apcm->n_srcc; i++) { 349 for (i = 0; i < apcm->n_srcc; i++) {
350 src_mgr->put_src(src_mgr, apcm->srccs[i]); 350 src_mgr->put_src(src_mgr, apcm->srccs[i]);
351 apcm->srccs[i] = NULL; 351 apcm->srccs[i] = NULL;
@@ -354,7 +354,7 @@ atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
354 apcm->srccs = NULL; 354 apcm->srccs = NULL;
355 } 355 }
356 356
357 if (NULL != apcm->amixers) { 357 if (apcm->amixers) {
358 for (i = 0; i < apcm->n_amixer; i++) { 358 for (i = 0; i < apcm->n_amixer; i++) {
359 amixer_mgr->put_amixer(amixer_mgr, apcm->amixers[i]); 359 amixer_mgr->put_amixer(amixer_mgr, apcm->amixers[i]);
360 apcm->amixers[i] = NULL; 360 apcm->amixers[i] = NULL;
@@ -363,17 +363,17 @@ atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
363 apcm->amixers = NULL; 363 apcm->amixers = NULL;
364 } 364 }
365 365
366 if (NULL != apcm->mono) { 366 if (apcm->mono) {
367 sum_mgr->put_sum(sum_mgr, apcm->mono); 367 sum_mgr->put_sum(sum_mgr, apcm->mono);
368 apcm->mono = NULL; 368 apcm->mono = NULL;
369 } 369 }
370 370
371 if (NULL != apcm->src) { 371 if (apcm->src) {
372 src_mgr->put_src(src_mgr, apcm->src); 372 src_mgr->put_src(src_mgr, apcm->src);
373 apcm->src = NULL; 373 apcm->src = NULL;
374 } 374 }
375 375
376 if (NULL != apcm->vm_block) { 376 if (apcm->vm_block) {
377 /* Undo device virtual mem map */ 377 /* Undo device virtual mem map */
378 ct_unmap_audio_buffer(atc, apcm); 378 ct_unmap_audio_buffer(atc, apcm);
379 apcm->vm_block = NULL; 379 apcm->vm_block = NULL;
@@ -419,7 +419,7 @@ static int atc_pcm_stop(struct ct_atc *atc, struct ct_atc_pcm *apcm)
419 src->ops->set_state(src, SRC_STATE_OFF); 419 src->ops->set_state(src, SRC_STATE_OFF);
420 src->ops->commit_write(src); 420 src->ops->commit_write(src);
421 421
422 if (NULL != apcm->srccs) { 422 if (apcm->srccs) {
423 for (i = 0; i < apcm->n_srcc; i++) { 423 for (i = 0; i < apcm->n_srcc; i++) {
424 src = apcm->srccs[i]; 424 src = apcm->srccs[i];
425 src->ops->set_bm(src, 0); 425 src->ops->set_bm(src, 0);
@@ -544,18 +544,18 @@ atc_pcm_capture_get_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
544 544
545 if (n_srcc) { 545 if (n_srcc) {
546 apcm->srccs = kzalloc(sizeof(void *)*n_srcc, GFP_KERNEL); 546 apcm->srccs = kzalloc(sizeof(void *)*n_srcc, GFP_KERNEL);
547 if (NULL == apcm->srccs) 547 if (!apcm->srccs)
548 return -ENOMEM; 548 return -ENOMEM;
549 } 549 }
550 if (n_amixer) { 550 if (n_amixer) {
551 apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); 551 apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL);
552 if (NULL == apcm->amixers) { 552 if (!apcm->amixers) {
553 err = -ENOMEM; 553 err = -ENOMEM;
554 goto error1; 554 goto error1;
555 } 555 }
556 } 556 }
557 apcm->srcimps = kzalloc(sizeof(void *)*n_srcimp, GFP_KERNEL); 557 apcm->srcimps = kzalloc(sizeof(void *)*n_srcimp, GFP_KERNEL);
558 if (NULL == apcm->srcimps) { 558 if (!apcm->srcimps) {
559 err = -ENOMEM; 559 err = -ENOMEM;
560 goto error1; 560 goto error1;
561 } 561 }
@@ -818,7 +818,7 @@ static int spdif_passthru_playback_get_resources(struct ct_atc *atc,
818 /* Get AMIXER resource */ 818 /* Get AMIXER resource */
819 n_amixer = (n_amixer < 2) ? 2 : n_amixer; 819 n_amixer = (n_amixer < 2) ? 2 : n_amixer;
820 apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); 820 apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL);
821 if (NULL == apcm->amixers) { 821 if (!apcm->amixers) {
822 err = -ENOMEM; 822 err = -ENOMEM;
823 goto error1; 823 goto error1;
824 } 824 }
@@ -919,7 +919,7 @@ spdif_passthru_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm)
919 amixer = apcm->amixers[i]; 919 amixer = apcm->amixers[i];
920 amixer->ops->setup(amixer, &src->rsc, INIT_VOL, NULL); 920 amixer->ops->setup(amixer, &src->rsc, INIT_VOL, NULL);
921 src = src->ops->next_interleave(src); 921 src = src->ops->next_interleave(src);
922 if (NULL == src) 922 if (!src)
923 src = apcm->src; 923 src = apcm->src;
924 } 924 }
925 /* Connect to SPDIFOO */ 925 /* Connect to SPDIFOO */
@@ -1121,7 +1121,7 @@ static int atc_release_resources(struct ct_atc *atc)
1121 struct ct_mixer *mixer = NULL; 1121 struct ct_mixer *mixer = NULL;
1122 1122
1123 /* disconnect internal mixer objects */ 1123 /* disconnect internal mixer objects */
1124 if (NULL != atc->mixer) { 1124 if (atc->mixer) {
1125 mixer = atc->mixer; 1125 mixer = atc->mixer;
1126 mixer->set_input_left(mixer, MIX_LINE_IN, NULL); 1126 mixer->set_input_left(mixer, MIX_LINE_IN, NULL);
1127 mixer->set_input_right(mixer, MIX_LINE_IN, NULL); 1127 mixer->set_input_right(mixer, MIX_LINE_IN, NULL);
@@ -1131,7 +1131,7 @@ static int atc_release_resources(struct ct_atc *atc)
1131 mixer->set_input_right(mixer, MIX_SPDIF_IN, NULL); 1131 mixer->set_input_right(mixer, MIX_SPDIF_IN, NULL);
1132 } 1132 }
1133 1133
1134 if (NULL != atc->daios) { 1134 if (atc->daios) {
1135 daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO]; 1135 daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO];
1136 for (i = 0; i < atc->n_daio; i++) { 1136 for (i = 0; i < atc->n_daio; i++) {
1137 daio = atc->daios[i]; 1137 daio = atc->daios[i];
@@ -1149,7 +1149,7 @@ static int atc_release_resources(struct ct_atc *atc)
1149 atc->daios = NULL; 1149 atc->daios = NULL;
1150 } 1150 }
1151 1151
1152 if (NULL != atc->pcm) { 1152 if (atc->pcm) {
1153 sum_mgr = atc->rsc_mgrs[SUM]; 1153 sum_mgr = atc->rsc_mgrs[SUM];
1154 for (i = 0; i < atc->n_pcm; i++) 1154 for (i = 0; i < atc->n_pcm; i++)
1155 sum_mgr->put_sum(sum_mgr, atc->pcm[i]); 1155 sum_mgr->put_sum(sum_mgr, atc->pcm[i]);
@@ -1158,7 +1158,7 @@ static int atc_release_resources(struct ct_atc *atc)
1158 atc->pcm = NULL; 1158 atc->pcm = NULL;
1159 } 1159 }
1160 1160
1161 if (NULL != atc->srcs) { 1161 if (atc->srcs) {
1162 src_mgr = atc->rsc_mgrs[SRC]; 1162 src_mgr = atc->rsc_mgrs[SRC];
1163 for (i = 0; i < atc->n_src; i++) 1163 for (i = 0; i < atc->n_src; i++)
1164 src_mgr->put_src(src_mgr, atc->srcs[i]); 1164 src_mgr->put_src(src_mgr, atc->srcs[i]);
@@ -1167,7 +1167,7 @@ static int atc_release_resources(struct ct_atc *atc)
1167 atc->srcs = NULL; 1167 atc->srcs = NULL;
1168 } 1168 }
1169 1169
1170 if (NULL != atc->srcimps) { 1170 if (atc->srcimps) {
1171 srcimp_mgr = atc->rsc_mgrs[SRCIMP]; 1171 srcimp_mgr = atc->rsc_mgrs[SRCIMP];
1172 for (i = 0; i < atc->n_srcimp; i++) { 1172 for (i = 0; i < atc->n_srcimp; i++) {
1173 srcimp = atc->srcimps[i]; 1173 srcimp = atc->srcimps[i];
@@ -1185,7 +1185,7 @@ static int ct_atc_destroy(struct ct_atc *atc)
1185{ 1185{
1186 int i = 0; 1186 int i = 0;
1187 1187
1188 if (NULL == atc) 1188 if (!atc)
1189 return 0; 1189 return 0;
1190 1190
1191 if (atc->timer) { 1191 if (atc->timer) {
@@ -1196,21 +1196,20 @@ static int ct_atc_destroy(struct ct_atc *atc)
1196 atc_release_resources(atc); 1196 atc_release_resources(atc);
1197 1197
1198 /* Destroy internal mixer objects */ 1198 /* Destroy internal mixer objects */
1199 if (NULL != atc->mixer) 1199 if (atc->mixer)
1200 ct_mixer_destroy(atc->mixer); 1200 ct_mixer_destroy(atc->mixer);
1201 1201
1202 for (i = 0; i < NUM_RSCTYP; i++) { 1202 for (i = 0; i < NUM_RSCTYP; i++) {
1203 if ((NULL != rsc_mgr_funcs[i].destroy) && 1203 if (rsc_mgr_funcs[i].destroy && atc->rsc_mgrs[i])
1204 (NULL != atc->rsc_mgrs[i]))
1205 rsc_mgr_funcs[i].destroy(atc->rsc_mgrs[i]); 1204 rsc_mgr_funcs[i].destroy(atc->rsc_mgrs[i]);
1206 1205
1207 } 1206 }
1208 1207
1209 if (NULL != atc->hw) 1208 if (atc->hw)
1210 destroy_hw_obj((struct hw *)atc->hw); 1209 destroy_hw_obj((struct hw *)atc->hw);
1211 1210
1212 /* Destroy device virtual memory manager object */ 1211 /* Destroy device virtual memory manager object */
1213 if (NULL != atc->vm) { 1212 if (atc->vm) {
1214 ct_vm_destroy(atc->vm); 1213 ct_vm_destroy(atc->vm);
1215 atc->vm = NULL; 1214 atc->vm = NULL;
1216 } 1215 }
@@ -1275,7 +1274,7 @@ int __devinit ct_atc_create_alsa_devs(struct ct_atc *atc)
1275 alsa_dev_funcs[MIXER].public_name = atc->chip_name; 1274 alsa_dev_funcs[MIXER].public_name = atc->chip_name;
1276 1275
1277 for (i = 0; i < NUM_CTALSADEVS; i++) { 1276 for (i = 0; i < NUM_CTALSADEVS; i++) {
1278 if (NULL == alsa_dev_funcs[i].create) 1277 if (!alsa_dev_funcs[i].create)
1279 continue; 1278 continue;
1280 1279
1281 err = alsa_dev_funcs[i].create(atc, i, 1280 err = alsa_dev_funcs[i].create(atc, i,
@@ -1312,7 +1311,7 @@ static int __devinit atc_create_hw_devs(struct ct_atc *atc)
1312 return err; 1311 return err;
1313 1312
1314 for (i = 0; i < NUM_RSCTYP; i++) { 1313 for (i = 0; i < NUM_RSCTYP; i++) {
1315 if (NULL == rsc_mgr_funcs[i].create) 1314 if (!rsc_mgr_funcs[i].create)
1316 continue; 1315 continue;
1317 1316
1318 err = rsc_mgr_funcs[i].create(atc->hw, &atc->rsc_mgrs[i]); 1317 err = rsc_mgr_funcs[i].create(atc->hw, &atc->rsc_mgrs[i]);
@@ -1339,19 +1338,19 @@ static int atc_get_resources(struct ct_atc *atc)
1339 int err, i; 1338 int err, i;
1340 1339
1341 atc->daios = kzalloc(sizeof(void *)*(DAIONUM), GFP_KERNEL); 1340 atc->daios = kzalloc(sizeof(void *)*(DAIONUM), GFP_KERNEL);
1342 if (NULL == atc->daios) 1341 if (!atc->daios)
1343 return -ENOMEM; 1342 return -ENOMEM;
1344 1343
1345 atc->srcs = kzalloc(sizeof(void *)*(2*2), GFP_KERNEL); 1344 atc->srcs = kzalloc(sizeof(void *)*(2*2), GFP_KERNEL);
1346 if (NULL == atc->srcs) 1345 if (!atc->srcs)
1347 return -ENOMEM; 1346 return -ENOMEM;
1348 1347
1349 atc->srcimps = kzalloc(sizeof(void *)*(2*2), GFP_KERNEL); 1348 atc->srcimps = kzalloc(sizeof(void *)*(2*2), GFP_KERNEL);
1350 if (NULL == atc->srcimps) 1349 if (!atc->srcimps)
1351 return -ENOMEM; 1350 return -ENOMEM;
1352 1351
1353 atc->pcm = kzalloc(sizeof(void *)*(2*4), GFP_KERNEL); 1352 atc->pcm = kzalloc(sizeof(void *)*(2*4), GFP_KERNEL);
1354 if (NULL == atc->pcm) 1353 if (!atc->pcm)
1355 return -ENOMEM; 1354 return -ENOMEM;
1356 1355
1357 daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO]; 1356 daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO];
@@ -1648,7 +1647,7 @@ int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
1648 *ratc = NULL; 1647 *ratc = NULL;
1649 1648
1650 atc = kzalloc(sizeof(*atc), GFP_KERNEL); 1649 atc = kzalloc(sizeof(*atc), GFP_KERNEL);
1651 if (NULL == atc) 1650 if (!atc)
1652 return -ENOMEM; 1651 return -ENOMEM;
1653 1652
1654 /* Set operations */ 1653 /* Set operations */
diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c
index 082e35c08c0..af56eb949bd 100644
--- a/sound/pci/ctxfi/ctdaio.c
+++ b/sound/pci/ctxfi/ctdaio.c
@@ -57,9 +57,9 @@ struct daio_rsc_idx idx_20k1[NUM_DAIOTYP] = {
57 57
58struct daio_rsc_idx idx_20k2[NUM_DAIOTYP] = { 58struct daio_rsc_idx idx_20k2[NUM_DAIOTYP] = {
59 [LINEO1] = {.left = 0x40, .right = 0x41}, 59 [LINEO1] = {.left = 0x40, .right = 0x41},
60 [LINEO2] = {.left = 0x70, .right = 0x71}, 60 [LINEO2] = {.left = 0x60, .right = 0x61},
61 [LINEO3] = {.left = 0x50, .right = 0x51}, 61 [LINEO3] = {.left = 0x50, .right = 0x51},
62 [LINEO4] = {.left = 0x60, .right = 0x61}, 62 [LINEO4] = {.left = 0x70, .right = 0x71},
63 [LINEIM] = {.left = 0x45, .right = 0xc5}, 63 [LINEIM] = {.left = 0x45, .right = 0xc5},
64 [SPDIFOO] = {.left = 0x00, .right = 0x01}, 64 [SPDIFOO] = {.left = 0x00, .right = 0x01},
65 [SPDIFIO] = {.left = 0x05, .right = 0x85}, 65 [SPDIFIO] = {.left = 0x05, .right = 0x85},
@@ -173,7 +173,7 @@ static int dao_set_left_input(struct dao *dao, struct rsc *input)
173 int i; 173 int i;
174 174
175 entry = kzalloc((sizeof(*entry) * daio->rscl.msr), GFP_KERNEL); 175 entry = kzalloc((sizeof(*entry) * daio->rscl.msr), GFP_KERNEL);
176 if (NULL == entry) 176 if (!entry)
177 return -ENOMEM; 177 return -ENOMEM;
178 178
179 /* Program master and conjugate resources */ 179 /* Program master and conjugate resources */
@@ -201,7 +201,7 @@ static int dao_set_right_input(struct dao *dao, struct rsc *input)
201 int i; 201 int i;
202 202
203 entry = kzalloc((sizeof(*entry) * daio->rscr.msr), GFP_KERNEL); 203 entry = kzalloc((sizeof(*entry) * daio->rscr.msr), GFP_KERNEL);
204 if (NULL == entry) 204 if (!entry)
205 return -ENOMEM; 205 return -ENOMEM;
206 206
207 /* Program master and conjugate resources */ 207 /* Program master and conjugate resources */
@@ -228,7 +228,7 @@ static int dao_clear_left_input(struct dao *dao)
228 struct daio *daio = &dao->daio; 228 struct daio *daio = &dao->daio;
229 int i; 229 int i;
230 230
231 if (NULL == dao->imappers[0]) 231 if (!dao->imappers[0])
232 return 0; 232 return 0;
233 233
234 entry = dao->imappers[0]; 234 entry = dao->imappers[0];
@@ -252,7 +252,7 @@ static int dao_clear_right_input(struct dao *dao)
252 struct daio *daio = &dao->daio; 252 struct daio *daio = &dao->daio;
253 int i; 253 int i;
254 254
255 if (NULL == dao->imappers[daio->rscl.msr]) 255 if (!dao->imappers[daio->rscl.msr])
256 return 0; 256 return 0;
257 257
258 entry = dao->imappers[daio->rscl.msr]; 258 entry = dao->imappers[daio->rscl.msr];
@@ -408,7 +408,7 @@ static int dao_rsc_init(struct dao *dao,
408 return err; 408 return err;
409 409
410 dao->imappers = kzalloc(sizeof(void *)*desc->msr*2, GFP_KERNEL); 410 dao->imappers = kzalloc(sizeof(void *)*desc->msr*2, GFP_KERNEL);
411 if (NULL == dao->imappers) { 411 if (!dao->imappers) {
412 err = -ENOMEM; 412 err = -ENOMEM;
413 goto error1; 413 goto error1;
414 } 414 }
@@ -442,11 +442,11 @@ error1:
442 442
443static int dao_rsc_uninit(struct dao *dao) 443static int dao_rsc_uninit(struct dao *dao)
444{ 444{
445 if (NULL != dao->imappers) { 445 if (dao->imappers) {
446 if (NULL != dao->imappers[0]) 446 if (dao->imappers[0])
447 dao_clear_left_input(dao); 447 dao_clear_left_input(dao);
448 448
449 if (NULL != dao->imappers[dao->daio.rscl.msr]) 449 if (dao->imappers[dao->daio.rscl.msr])
450 dao_clear_right_input(dao); 450 dao_clear_right_input(dao);
451 451
452 kfree(dao->imappers); 452 kfree(dao->imappers);
@@ -555,7 +555,7 @@ static int get_daio_rsc(struct daio_mgr *mgr,
555 /* Allocate mem for daio resource */ 555 /* Allocate mem for daio resource */
556 if (desc->type <= DAIO_OUT_MAX) { 556 if (desc->type <= DAIO_OUT_MAX) {
557 dao = kzalloc(sizeof(*dao), GFP_KERNEL); 557 dao = kzalloc(sizeof(*dao), GFP_KERNEL);
558 if (NULL == dao) { 558 if (!dao) {
559 err = -ENOMEM; 559 err = -ENOMEM;
560 goto error; 560 goto error;
561 } 561 }
@@ -566,7 +566,7 @@ static int get_daio_rsc(struct daio_mgr *mgr,
566 *rdaio = &dao->daio; 566 *rdaio = &dao->daio;
567 } else { 567 } else {
568 dai = kzalloc(sizeof(*dai), GFP_KERNEL); 568 dai = kzalloc(sizeof(*dai), GFP_KERNEL);
569 if (NULL == dai) { 569 if (!dai) {
570 err = -ENOMEM; 570 err = -ENOMEM;
571 goto error; 571 goto error;
572 } 572 }
@@ -583,9 +583,9 @@ static int get_daio_rsc(struct daio_mgr *mgr,
583 return 0; 583 return 0;
584 584
585error: 585error:
586 if (NULL != dao) 586 if (dao)
587 kfree(dao); 587 kfree(dao);
588 else if (NULL != dai) 588 else if (dai)
589 kfree(dai); 589 kfree(dai);
590 590
591 spin_lock_irqsave(&mgr->mgr_lock, flags); 591 spin_lock_irqsave(&mgr->mgr_lock, flags);
@@ -663,7 +663,7 @@ static int daio_imap_add(struct daio_mgr *mgr, struct imapper *entry)
663 int err; 663 int err;
664 664
665 spin_lock_irqsave(&mgr->imap_lock, flags); 665 spin_lock_irqsave(&mgr->imap_lock, flags);
666 if ((0 == entry->addr) && (mgr->init_imap_added)) { 666 if (!entry->addr && mgr->init_imap_added) {
667 input_mapper_delete(&mgr->imappers, mgr->init_imap, 667 input_mapper_delete(&mgr->imappers, mgr->init_imap,
668 daio_map_op, mgr); 668 daio_map_op, mgr);
669 mgr->init_imap_added = 0; 669 mgr->init_imap_added = 0;
@@ -707,7 +707,7 @@ int daio_mgr_create(void *hw, struct daio_mgr **rdaio_mgr)
707 707
708 *rdaio_mgr = NULL; 708 *rdaio_mgr = NULL;
709 daio_mgr = kzalloc(sizeof(*daio_mgr), GFP_KERNEL); 709 daio_mgr = kzalloc(sizeof(*daio_mgr), GFP_KERNEL);
710 if (NULL == daio_mgr) 710 if (!daio_mgr)
711 return -ENOMEM; 711 return -ENOMEM;
712 712
713 err = rsc_mgr_init(&daio_mgr->mgr, DAIO, DAIO_RESOURCE_NUM, hw); 713 err = rsc_mgr_init(&daio_mgr->mgr, DAIO, DAIO_RESOURCE_NUM, hw);
@@ -718,7 +718,7 @@ int daio_mgr_create(void *hw, struct daio_mgr **rdaio_mgr)
718 spin_lock_init(&daio_mgr->imap_lock); 718 spin_lock_init(&daio_mgr->imap_lock);
719 INIT_LIST_HEAD(&daio_mgr->imappers); 719 INIT_LIST_HEAD(&daio_mgr->imappers);
720 entry = kzalloc(sizeof(*entry), GFP_KERNEL); 720 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
721 if (NULL == entry) { 721 if (!entry) {
722 err = -ENOMEM; 722 err = -ENOMEM;
723 goto error2; 723 goto error2;
724 } 724 }
diff --git a/sound/pci/ctxfi/cthw20k1.c b/sound/pci/ctxfi/cthw20k1.c
index ad3e1d14446..0cf400f879f 100644
--- a/sound/pci/ctxfi/cthw20k1.c
+++ b/sound/pci/ctxfi/cthw20k1.c
@@ -168,7 +168,7 @@ static int src_get_rsc_ctrl_blk(void **rblk)
168 168
169 *rblk = NULL; 169 *rblk = NULL;
170 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 170 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
171 if (NULL == blk) 171 if (!blk)
172 return -ENOMEM; 172 return -ENOMEM;
173 173
174 *rblk = blk; 174 *rblk = blk;
@@ -494,7 +494,7 @@ static int src_mgr_get_ctrl_blk(void **rblk)
494 494
495 *rblk = NULL; 495 *rblk = NULL;
496 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 496 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
497 if (NULL == blk) 497 if (!blk)
498 return -ENOMEM; 498 return -ENOMEM;
499 499
500 *rblk = blk; 500 *rblk = blk;
@@ -515,7 +515,7 @@ static int srcimp_mgr_get_ctrl_blk(void **rblk)
515 515
516 *rblk = NULL; 516 *rblk = NULL;
517 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 517 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
518 if (NULL == blk) 518 if (!blk)
519 return -ENOMEM; 519 return -ENOMEM;
520 520
521 *rblk = blk; 521 *rblk = blk;
@@ -702,7 +702,7 @@ static int amixer_rsc_get_ctrl_blk(void **rblk)
702 702
703 *rblk = NULL; 703 *rblk = NULL;
704 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 704 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
705 if (NULL == blk) 705 if (!blk)
706 return -ENOMEM; 706 return -ENOMEM;
707 707
708 *rblk = blk; 708 *rblk = blk;
@@ -723,7 +723,7 @@ static int amixer_mgr_get_ctrl_blk(void **rblk)
723 723
724 *rblk = NULL; 724 *rblk = NULL;
725 /*blk = kzalloc(sizeof(*blk), GFP_KERNEL); 725 /*blk = kzalloc(sizeof(*blk), GFP_KERNEL);
726 if (NULL == blk) 726 if (!blk)
727 return -ENOMEM; 727 return -ENOMEM;
728 728
729 *rblk = blk;*/ 729 *rblk = blk;*/
@@ -909,7 +909,7 @@ static int dai_get_ctrl_blk(void **rblk)
909 909
910 *rblk = NULL; 910 *rblk = NULL;
911 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 911 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
912 if (NULL == blk) 912 if (!blk)
913 return -ENOMEM; 913 return -ENOMEM;
914 914
915 *rblk = blk; 915 *rblk = blk;
@@ -958,7 +958,7 @@ static int dao_get_ctrl_blk(void **rblk)
958 958
959 *rblk = NULL; 959 *rblk = NULL;
960 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 960 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
961 if (NULL == blk) 961 if (!blk)
962 return -ENOMEM; 962 return -ENOMEM;
963 963
964 *rblk = blk; 964 *rblk = blk;
@@ -1152,7 +1152,7 @@ static int daio_mgr_get_ctrl_blk(struct hw *hw, void **rblk)
1152 1152
1153 *rblk = NULL; 1153 *rblk = NULL;
1154 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 1154 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
1155 if (NULL == blk) 1155 if (!blk)
1156 return -ENOMEM; 1156 return -ENOMEM;
1157 1157
1158 blk->i2sctl = hw_read_20kx(hw, I2SCTL); 1158 blk->i2sctl = hw_read_20kx(hw, I2SCTL);
@@ -1808,7 +1808,7 @@ static int uaa_to_xfi(struct pci_dev *pci)
1808 /* By default, Hendrix card UAA Bar0 should be using memory... */ 1808 /* By default, Hendrix card UAA Bar0 should be using memory... */
1809 io_base = pci_resource_start(pci, 0); 1809 io_base = pci_resource_start(pci, 0);
1810 mem_base = ioremap(io_base, pci_resource_len(pci, 0)); 1810 mem_base = ioremap(io_base, pci_resource_len(pci, 0));
1811 if (NULL == mem_base) 1811 if (!mem_base)
1812 return -ENOENT; 1812 return -ENOENT;
1813 1813
1814 /* Read current mode from Mode Change Register */ 1814 /* Read current mode from Mode Change Register */
@@ -1977,7 +1977,7 @@ static int hw_card_shutdown(struct hw *hw)
1977 1977
1978 hw->irq = -1; 1978 hw->irq = -1;
1979 1979
1980 if (NULL != ((void *)hw->mem_base)) 1980 if (hw->mem_base)
1981 iounmap((void *)hw->mem_base); 1981 iounmap((void *)hw->mem_base);
1982 1982
1983 hw->mem_base = (unsigned long)NULL; 1983 hw->mem_base = (unsigned long)NULL;
@@ -2274,7 +2274,7 @@ int __devinit create_20k1_hw_obj(struct hw **rhw)
2274 2274
2275 *rhw = NULL; 2275 *rhw = NULL;
2276 hw20k1 = kzalloc(sizeof(*hw20k1), GFP_KERNEL); 2276 hw20k1 = kzalloc(sizeof(*hw20k1), GFP_KERNEL);
2277 if (NULL == hw20k1) 2277 if (!hw20k1)
2278 return -ENOMEM; 2278 return -ENOMEM;
2279 2279
2280 spin_lock_init(&hw20k1->reg_20k1_lock); 2280 spin_lock_init(&hw20k1->reg_20k1_lock);
diff --git a/sound/pci/ctxfi/cthw20k2.c b/sound/pci/ctxfi/cthw20k2.c
index dec46d04b04..b6b11bfe757 100644
--- a/sound/pci/ctxfi/cthw20k2.c
+++ b/sound/pci/ctxfi/cthw20k2.c
@@ -166,7 +166,7 @@ static int src_get_rsc_ctrl_blk(void **rblk)
166 166
167 *rblk = NULL; 167 *rblk = NULL;
168 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 168 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
169 if (NULL == blk) 169 if (!blk)
170 return -ENOMEM; 170 return -ENOMEM;
171 171
172 *rblk = blk; 172 *rblk = blk;
@@ -492,7 +492,7 @@ static int src_mgr_get_ctrl_blk(void **rblk)
492 492
493 *rblk = NULL; 493 *rblk = NULL;
494 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 494 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
495 if (NULL == blk) 495 if (!blk)
496 return -ENOMEM; 496 return -ENOMEM;
497 497
498 *rblk = blk; 498 *rblk = blk;
@@ -513,7 +513,7 @@ static int srcimp_mgr_get_ctrl_blk(void **rblk)
513 513
514 *rblk = NULL; 514 *rblk = NULL;
515 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 515 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
516 if (NULL == blk) 516 if (!blk)
517 return -ENOMEM; 517 return -ENOMEM;
518 518
519 *rblk = blk; 519 *rblk = blk;
@@ -702,7 +702,7 @@ static int amixer_rsc_get_ctrl_blk(void **rblk)
702 702
703 *rblk = NULL; 703 *rblk = NULL;
704 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 704 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
705 if (NULL == blk) 705 if (!blk)
706 return -ENOMEM; 706 return -ENOMEM;
707 707
708 *rblk = blk; 708 *rblk = blk;
@@ -891,7 +891,7 @@ static int dai_get_ctrl_blk(void **rblk)
891 891
892 *rblk = NULL; 892 *rblk = NULL;
893 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 893 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
894 if (NULL == blk) 894 if (!blk)
895 return -ENOMEM; 895 return -ENOMEM;
896 896
897 *rblk = blk; 897 *rblk = blk;
@@ -941,7 +941,7 @@ static int dao_get_ctrl_blk(void **rblk)
941 941
942 *rblk = NULL; 942 *rblk = NULL;
943 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 943 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
944 if (NULL == blk) 944 if (!blk)
945 return -ENOMEM; 945 return -ENOMEM;
946 946
947 *rblk = blk; 947 *rblk = blk;
@@ -1092,7 +1092,7 @@ static int daio_mgr_get_ctrl_blk(struct hw *hw, void **rblk)
1092 1092
1093 *rblk = NULL; 1093 *rblk = NULL;
1094 blk = kzalloc(sizeof(*blk), GFP_KERNEL); 1094 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
1095 if (NULL == blk) 1095 if (!blk)
1096 return -ENOMEM; 1096 return -ENOMEM;
1097 1097
1098 for (i = 0; i < 8; i++) { 1098 for (i = 0; i < 8; i++) {
@@ -1112,6 +1112,26 @@ static int daio_mgr_put_ctrl_blk(void *blk)
1112 return 0; 1112 return 0;
1113} 1113}
1114 1114
1115/* Timer interrupt */
1116static int set_timer_irq(struct hw *hw, int enable)
1117{
1118 hw_write_20kx(hw, GIE, enable ? IT_INT : 0);
1119 return 0;
1120}
1121
1122static int set_timer_tick(struct hw *hw, unsigned int ticks)
1123{
1124 if (ticks)
1125 ticks |= TIMR_IE | TIMR_IP;
1126 hw_write_20kx(hw, TIMR, ticks);
1127 return 0;
1128}
1129
1130static unsigned int get_wc(struct hw *hw)
1131{
1132 return hw_read_20kx(hw, WC);
1133}
1134
1115/* Card hardware initialization block */ 1135/* Card hardware initialization block */
1116struct dac_conf { 1136struct dac_conf {
1117 unsigned int msr; /* master sample rate in rsrs */ 1137 unsigned int msr; /* master sample rate in rsrs */
@@ -1841,6 +1861,22 @@ static int hw_have_digit_io_switch(struct hw *hw)
1841 return 0; 1861 return 0;
1842} 1862}
1843 1863
1864static irqreturn_t ct_20k2_interrupt(int irq, void *dev_id)
1865{
1866 struct hw *hw = dev_id;
1867 unsigned int status;
1868
1869 status = hw_read_20kx(hw, GIP);
1870 if (!status)
1871 return IRQ_NONE;
1872
1873 if (hw->irq_callback)
1874 hw->irq_callback(hw->irq_callback_data, status);
1875
1876 hw_write_20kx(hw, GIP, status);
1877 return IRQ_HANDLED;
1878}
1879
1844static int hw_card_start(struct hw *hw) 1880static int hw_card_start(struct hw *hw)
1845{ 1881{
1846 int err = 0; 1882 int err = 0;
@@ -1868,7 +1904,7 @@ static int hw_card_start(struct hw *hw)
1868 hw->io_base = pci_resource_start(hw->pci, 2); 1904 hw->io_base = pci_resource_start(hw->pci, 2);
1869 hw->mem_base = (unsigned long)ioremap(hw->io_base, 1905 hw->mem_base = (unsigned long)ioremap(hw->io_base,
1870 pci_resource_len(hw->pci, 2)); 1906 pci_resource_len(hw->pci, 2));
1871 if (NULL == (void *)hw->mem_base) { 1907 if (!hw->mem_base) {
1872 err = -ENOENT; 1908 err = -ENOENT;
1873 goto error2; 1909 goto error2;
1874 } 1910 }
@@ -1879,12 +1915,15 @@ static int hw_card_start(struct hw *hw)
1879 set_field(&gctl, GCTL_UAA, 0); 1915 set_field(&gctl, GCTL_UAA, 0);
1880 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl); 1916 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1881 1917
1882 /*if ((err = request_irq(pci->irq, ct_atc_interrupt, IRQF_SHARED, 1918 if (hw->irq < 0) {
1883 atc->chip_details->nm_card, hw))) { 1919 err = request_irq(pci->irq, ct_20k2_interrupt, IRQF_SHARED,
1884 goto error3; 1920 "ctxfi", hw);
1921 if (err < 0) {
1922 printk(KERN_ERR "XFi: Cannot get irq %d\n", pci->irq);
1923 goto error2;
1924 }
1925 hw->irq = pci->irq;
1885 } 1926 }
1886 hw->irq = pci->irq;
1887 */
1888 1927
1889 pci_set_master(pci); 1928 pci_set_master(pci);
1890 1929
@@ -1923,7 +1962,7 @@ static int hw_card_shutdown(struct hw *hw)
1923 1962
1924 hw->irq = -1; 1963 hw->irq = -1;
1925 1964
1926 if (NULL != ((void *)hw->mem_base)) 1965 if (hw->mem_base)
1927 iounmap((void *)hw->mem_base); 1966 iounmap((void *)hw->mem_base);
1928 1967
1929 hw->mem_base = (unsigned long)NULL; 1968 hw->mem_base = (unsigned long)NULL;
@@ -1972,7 +2011,7 @@ static int hw_card_init(struct hw *hw, struct card_conf *info)
1972 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl); 2011 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1973 2012
1974 /* Reset all global pending interrupts */ 2013 /* Reset all global pending interrupts */
1975 hw_write_20kx(hw, INTERRUPT_GIE, 0); 2014 hw_write_20kx(hw, GIE, 0);
1976 /* Reset all SRC pending interrupts */ 2015 /* Reset all SRC pending interrupts */
1977 hw_write_20kx(hw, SRC_IP, 0); 2016 hw_write_20kx(hw, SRC_IP, 0);
1978 2017
@@ -2149,6 +2188,10 @@ static struct hw ct20k2_preset __devinitdata = {
2149 .daio_mgr_set_imapnxt = daio_mgr_set_imapnxt, 2188 .daio_mgr_set_imapnxt = daio_mgr_set_imapnxt,
2150 .daio_mgr_set_imapaddr = daio_mgr_set_imapaddr, 2189 .daio_mgr_set_imapaddr = daio_mgr_set_imapaddr,
2151 .daio_mgr_commit_write = daio_mgr_commit_write, 2190 .daio_mgr_commit_write = daio_mgr_commit_write,
2191
2192 .set_timer_irq = set_timer_irq,
2193 .set_timer_tick = set_timer_tick,
2194 .get_wc = get_wc,
2152}; 2195};
2153 2196
2154int __devinit create_20k2_hw_obj(struct hw **rhw) 2197int __devinit create_20k2_hw_obj(struct hw **rhw)
diff --git a/sound/pci/ctxfi/ctmixer.c b/sound/pci/ctxfi/ctmixer.c
index f26d7cd9db9..15c1e7271ea 100644
--- a/sound/pci/ctxfi/ctmixer.c
+++ b/sound/pci/ctxfi/ctmixer.c
@@ -654,7 +654,7 @@ ct_mixer_kcontrol_new(struct ct_mixer *mixer, struct snd_kcontrol_new *new)
654 int err; 654 int err;
655 655
656 kctl = snd_ctl_new1(new, mixer->atc); 656 kctl = snd_ctl_new1(new, mixer->atc);
657 if (NULL == kctl) 657 if (!kctl)
658 return -ENOMEM; 658 return -ENOMEM;
659 659
660 if (SNDRV_CTL_ELEM_IFACE_PCM == kctl->id.iface) 660 if (SNDRV_CTL_ELEM_IFACE_PCM == kctl->id.iface)
@@ -837,17 +837,17 @@ static int ct_mixer_get_mem(struct ct_mixer **rmixer)
837 *rmixer = NULL; 837 *rmixer = NULL;
838 /* Allocate mem for mixer obj */ 838 /* Allocate mem for mixer obj */
839 mixer = kzalloc(sizeof(*mixer), GFP_KERNEL); 839 mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
840 if (NULL == mixer) 840 if (!mixer)
841 return -ENOMEM; 841 return -ENOMEM;
842 842
843 mixer->amixers = kzalloc(sizeof(void *)*(NUM_CT_AMIXERS*CHN_NUM), 843 mixer->amixers = kzalloc(sizeof(void *)*(NUM_CT_AMIXERS*CHN_NUM),
844 GFP_KERNEL); 844 GFP_KERNEL);
845 if (NULL == mixer->amixers) { 845 if (!mixer->amixers) {
846 err = -ENOMEM; 846 err = -ENOMEM;
847 goto error1; 847 goto error1;
848 } 848 }
849 mixer->sums = kzalloc(sizeof(void *)*(NUM_CT_SUMS*CHN_NUM), GFP_KERNEL); 849 mixer->sums = kzalloc(sizeof(void *)*(NUM_CT_SUMS*CHN_NUM), GFP_KERNEL);
850 if (NULL == mixer->sums) { 850 if (!mixer->sums) {
851 err = -ENOMEM; 851 err = -ENOMEM;
852 goto error2; 852 goto error2;
853 } 853 }
diff --git a/sound/pci/ctxfi/ctpcm.c b/sound/pci/ctxfi/ctpcm.c
index 60ea23180ac..d0dc227fbdd 100644
--- a/sound/pci/ctxfi/ctpcm.c
+++ b/sound/pci/ctxfi/ctpcm.c
@@ -97,7 +97,7 @@ static void ct_atc_pcm_interrupt(struct ct_atc_pcm *atc_pcm)
97{ 97{
98 struct ct_atc_pcm *apcm = atc_pcm; 98 struct ct_atc_pcm *apcm = atc_pcm;
99 99
100 if (NULL == apcm->substream) 100 if (!apcm->substream)
101 return; 101 return;
102 102
103 snd_pcm_period_elapsed(apcm->substream); 103 snd_pcm_period_elapsed(apcm->substream);
@@ -123,7 +123,7 @@ static int ct_pcm_playback_open(struct snd_pcm_substream *substream)
123 int err; 123 int err;
124 124
125 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL); 125 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
126 if (NULL == apcm) 126 if (!apcm)
127 return -ENOMEM; 127 return -ENOMEM;
128 128
129 apcm->substream = substream; 129 apcm->substream = substream;
@@ -271,7 +271,7 @@ static int ct_pcm_capture_open(struct snd_pcm_substream *substream)
271 int err; 271 int err;
272 272
273 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL); 273 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
274 if (NULL == apcm) 274 if (!apcm)
275 return -ENOMEM; 275 return -ENOMEM;
276 276
277 apcm->started = 0; 277 apcm->started = 0;
diff --git a/sound/pci/ctxfi/ctresource.c b/sound/pci/ctxfi/ctresource.c
index 889c495bb7d..7dfaf67344d 100644
--- a/sound/pci/ctxfi/ctresource.c
+++ b/sound/pci/ctxfi/ctresource.c
@@ -144,7 +144,7 @@ int rsc_init(struct rsc *rsc, u32 idx, enum RSCTYP type, u32 msr, void *hw)
144 rsc->msr = msr; 144 rsc->msr = msr;
145 rsc->hw = hw; 145 rsc->hw = hw;
146 rsc->ops = &rsc_generic_ops; 146 rsc->ops = &rsc_generic_ops;
147 if (NULL == hw) { 147 if (!hw) {
148 rsc->ctrl_blk = NULL; 148 rsc->ctrl_blk = NULL;
149 return 0; 149 return 0;
150 } 150 }
@@ -216,7 +216,7 @@ int rsc_mgr_init(struct rsc_mgr *mgr, enum RSCTYP type,
216 mgr->type = NUM_RSCTYP; 216 mgr->type = NUM_RSCTYP;
217 217
218 mgr->rscs = kzalloc(((amount + 8 - 1) / 8), GFP_KERNEL); 218 mgr->rscs = kzalloc(((amount + 8 - 1) / 8), GFP_KERNEL);
219 if (NULL == mgr->rscs) 219 if (!mgr->rscs)
220 return -ENOMEM; 220 return -ENOMEM;
221 221
222 switch (type) { 222 switch (type) {
diff --git a/sound/pci/ctxfi/ctsrc.c b/sound/pci/ctxfi/ctsrc.c
index e1c145d8b70..c749fa72088 100644
--- a/sound/pci/ctxfi/ctsrc.c
+++ b/sound/pci/ctxfi/ctsrc.c
@@ -441,7 +441,7 @@ get_src_rsc(struct src_mgr *mgr, const struct src_desc *desc, struct src **rsrc)
441 else 441 else
442 src = kzalloc(sizeof(*src), GFP_KERNEL); 442 src = kzalloc(sizeof(*src), GFP_KERNEL);
443 443
444 if (NULL == src) { 444 if (!src) {
445 err = -ENOMEM; 445 err = -ENOMEM;
446 goto error1; 446 goto error1;
447 } 447 }
@@ -550,7 +550,7 @@ int src_mgr_create(void *hw, struct src_mgr **rsrc_mgr)
550 550
551 *rsrc_mgr = NULL; 551 *rsrc_mgr = NULL;
552 src_mgr = kzalloc(sizeof(*src_mgr), GFP_KERNEL); 552 src_mgr = kzalloc(sizeof(*src_mgr), GFP_KERNEL);
553 if (NULL == src_mgr) 553 if (!src_mgr)
554 return -ENOMEM; 554 return -ENOMEM;
555 555
556 err = rsc_mgr_init(&src_mgr->mgr, SRC, SRC_RESOURCE_NUM, hw); 556 err = rsc_mgr_init(&src_mgr->mgr, SRC, SRC_RESOURCE_NUM, hw);
@@ -679,7 +679,7 @@ static int srcimp_rsc_init(struct srcimp *srcimp,
679 /* Reserve memory for imapper nodes */ 679 /* Reserve memory for imapper nodes */
680 srcimp->imappers = kzalloc(sizeof(struct imapper)*desc->msr, 680 srcimp->imappers = kzalloc(sizeof(struct imapper)*desc->msr,
681 GFP_KERNEL); 681 GFP_KERNEL);
682 if (NULL == srcimp->imappers) { 682 if (!srcimp->imappers) {
683 err = -ENOMEM; 683 err = -ENOMEM;
684 goto error1; 684 goto error1;
685 } 685 }
@@ -724,12 +724,11 @@ static int get_srcimp_rsc(struct srcimp_mgr *mgr,
724 724
725 /* Allocate mem for SRCIMP resource */ 725 /* Allocate mem for SRCIMP resource */
726 srcimp = kzalloc(sizeof(*srcimp), GFP_KERNEL); 726 srcimp = kzalloc(sizeof(*srcimp), GFP_KERNEL);
727 if (NULL == srcimp) { 727 if (!srcimp)
728 err = -ENOMEM; 728 return -ENOMEM;
729 return err;
730 }
731 729
732 /* Check whether there are sufficient SRCIMP resources. */ 730 /* Check whether there are sufficient SRCIMP resources. */
731 err = 0;
733 spin_lock_irqsave(&mgr->mgr_lock, flags); 732 spin_lock_irqsave(&mgr->mgr_lock, flags);
734 for (i = 0; i < desc->msr; i++) { 733 for (i = 0; i < desc->msr; i++) {
735 err = mgr_get_resource(&mgr->mgr, 1, &idx); 734 err = mgr_get_resource(&mgr->mgr, 1, &idx);
@@ -834,7 +833,7 @@ int srcimp_mgr_create(void *hw, struct srcimp_mgr **rsrcimp_mgr)
834 833
835 *rsrcimp_mgr = NULL; 834 *rsrcimp_mgr = NULL;
836 srcimp_mgr = kzalloc(sizeof(*srcimp_mgr), GFP_KERNEL); 835 srcimp_mgr = kzalloc(sizeof(*srcimp_mgr), GFP_KERNEL);
837 if (NULL == srcimp_mgr) 836 if (!srcimp_mgr)
838 return -ENOMEM; 837 return -ENOMEM;
839 838
840 err = rsc_mgr_init(&srcimp_mgr->mgr, SRCIMP, SRCIMP_RESOURCE_NUM, hw); 839 err = rsc_mgr_init(&srcimp_mgr->mgr, SRCIMP, SRCIMP_RESOURCE_NUM, hw);
@@ -845,7 +844,7 @@ int srcimp_mgr_create(void *hw, struct srcimp_mgr **rsrcimp_mgr)
845 spin_lock_init(&srcimp_mgr->imap_lock); 844 spin_lock_init(&srcimp_mgr->imap_lock);
846 INIT_LIST_HEAD(&srcimp_mgr->imappers); 845 INIT_LIST_HEAD(&srcimp_mgr->imappers);
847 entry = kzalloc(sizeof(*entry), GFP_KERNEL); 846 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
848 if (NULL == entry) { 847 if (!entry) {
849 err = -ENOMEM; 848 err = -ENOMEM;
850 goto error2; 849 goto error2;
851 } 850 }
diff --git a/sound/pci/ctxfi/ctvmem.c b/sound/pci/ctxfi/ctvmem.c
index 67665a7e43c..6b78752e950 100644
--- a/sound/pci/ctxfi/ctvmem.c
+++ b/sound/pci/ctxfi/ctvmem.c
@@ -60,7 +60,7 @@ get_vm_block(struct ct_vm *vm, unsigned int size)
60 } 60 }
61 61
62 block = kzalloc(sizeof(*block), GFP_KERNEL); 62 block = kzalloc(sizeof(*block), GFP_KERNEL);
63 if (NULL == block) 63 if (!block)
64 goto out; 64 goto out;
65 65
66 block->addr = entry->addr; 66 block->addr = entry->addr;
@@ -181,7 +181,7 @@ int ct_vm_create(struct ct_vm **rvm)
181 *rvm = NULL; 181 *rvm = NULL;
182 182
183 vm = kzalloc(sizeof(*vm), GFP_KERNEL); 183 vm = kzalloc(sizeof(*vm), GFP_KERNEL);
184 if (NULL == vm) 184 if (!vm)
185 return -ENOMEM; 185 return -ENOMEM;
186 186
187 mutex_init(&vm->lock); 187 mutex_init(&vm->lock);
@@ -189,7 +189,7 @@ int ct_vm_create(struct ct_vm **rvm)
189 /* Allocate page table pages */ 189 /* Allocate page table pages */
190 for (i = 0; i < CT_PTP_NUM; i++) { 190 for (i = 0; i < CT_PTP_NUM; i++) {
191 vm->ptp[i] = kmalloc(PAGE_SIZE, GFP_KERNEL); 191 vm->ptp[i] = kmalloc(PAGE_SIZE, GFP_KERNEL);
192 if (NULL == vm->ptp[i]) 192 if (!vm->ptp[i])
193 break; 193 break;
194 } 194 }
195 if (!i) { 195 if (!i) {
diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
index e617acaf10e..61b8ab39800 100644
--- a/sound/pci/emu10k1/p16v.c
+++ b/sound/pci/emu10k1/p16v.c
@@ -644,7 +644,7 @@ int __devinit snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm *
644 int err; 644 int err;
645 int capture=1; 645 int capture=1;
646 646
647 /* snd_printk("KERN_DEBUG snd_p16v_pcm called. device=%d\n", device); */ 647 /* snd_printk(KERN_DEBUG "snd_p16v_pcm called. device=%d\n", device); */
648 emu->p16v_device_offset = device; 648 emu->p16v_device_offset = device;
649 if (rpcm) 649 if (rpcm)
650 *rpcm = NULL; 650 *rpcm = NULL;
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 04438f1d682..55545e0818b 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -46,6 +46,20 @@ config SND_HDA_INPUT_JACK
46 Say Y here to enable the jack plugging notification via 46 Say Y here to enable the jack plugging notification via
47 input layer. 47 input layer.
48 48
49config SND_HDA_PATCH_LOADER
50 bool "Support initialization patch loading for HD-audio"
51 depends on EXPERIMENTAL
52 select FW_LOADER
53 select SND_HDA_HWDEP
54 select SND_HDA_RECONFIG
55 help
56 Say Y here to allow the HD-audio driver to load a pseudo
57 firmware file ("patch") for overriding the BIOS setup at
58 start up. The "patch" file can be specified via patch module
59 option, such as patch=hda-init.
60
61 This option turns on hwdep and reconfig features automatically.
62
49config SND_HDA_CODEC_REALTEK 63config SND_HDA_CODEC_REALTEK
50 bool "Build Realtek HD-audio codec support" 64 bool "Build Realtek HD-audio codec support"
51 default y 65 default y
@@ -134,6 +148,19 @@ config SND_HDA_ELD
134 def_bool y 148 def_bool y
135 depends on SND_HDA_CODEC_INTELHDMI 149 depends on SND_HDA_CODEC_INTELHDMI
136 150
151config SND_HDA_CODEC_CIRRUS
152 bool "Build Cirrus Logic codec support"
153 depends on SND_HDA_INTEL
154 default y
155 help
156 Say Y here to include Cirrus Logic codec support in
157 snd-hda-intel driver, such as CS4206.
158
159 When the HD-audio driver is built as a module, the codec
160 support code is also built as another module,
161 snd-hda-codec-cirrus.
162 This module is automatically loaded at probing.
163
137config SND_HDA_CODEC_CONEXANT 164config SND_HDA_CODEC_CONEXANT
138 bool "Build Conexant HD-audio codec support" 165 bool "Build Conexant HD-audio codec support"
139 default y 166 default y
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index e3081d4586c..315a1c4f899 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -13,6 +13,7 @@ snd-hda-codec-analog-objs := patch_analog.o
13snd-hda-codec-idt-objs := patch_sigmatel.o 13snd-hda-codec-idt-objs := patch_sigmatel.o
14snd-hda-codec-si3054-objs := patch_si3054.o 14snd-hda-codec-si3054-objs := patch_si3054.o
15snd-hda-codec-atihdmi-objs := patch_atihdmi.o 15snd-hda-codec-atihdmi-objs := patch_atihdmi.o
16snd-hda-codec-cirrus-objs := patch_cirrus.o
16snd-hda-codec-ca0110-objs := patch_ca0110.o 17snd-hda-codec-ca0110-objs := patch_ca0110.o
17snd-hda-codec-conexant-objs := patch_conexant.o 18snd-hda-codec-conexant-objs := patch_conexant.o
18snd-hda-codec-via-objs := patch_via.o 19snd-hda-codec-via-objs := patch_via.o
@@ -41,6 +42,9 @@ endif
41ifdef CONFIG_SND_HDA_CODEC_ATIHDMI 42ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
42obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-atihdmi.o 43obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-atihdmi.o
43endif 44endif
45ifdef CONFIG_SND_HDA_CODEC_CIRRUS
46obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-cirrus.o
47endif
44ifdef CONFIG_SND_HDA_CODEC_CA0110 48ifdef CONFIG_SND_HDA_CODEC_CA0110
45obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-ca0110.o 49obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-ca0110.o
46endif 50endif
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 29272f2e95a..3f51a981e60 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -24,6 +24,7 @@
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <sound/core.h> 25#include <sound/core.h>
26#include "hda_beep.h" 26#include "hda_beep.h"
27#include "hda_local.h"
27 28
28enum { 29enum {
29 DIGBEEP_HZ_STEP = 46875, /* 46.875 Hz */ 30 DIGBEEP_HZ_STEP = 46875, /* 46.875 Hz */
@@ -50,19 +51,22 @@ static void snd_hda_generate_beep(struct work_struct *work)
50 * The tone frequency of beep generator on IDT/STAC codecs is 51 * The tone frequency of beep generator on IDT/STAC codecs is
51 * defined from the 8bit tone parameter, in Hz, 52 * defined from the 8bit tone parameter, in Hz,
52 * freq = 48000 * (257 - tone) / 1024 53 * freq = 48000 * (257 - tone) / 1024
53 * that is from 12kHz to 93.75kHz in step of 46.875 hz 54 * that is from 12kHz to 93.75Hz in steps of 46.875 Hz
54 */ 55 */
55static int beep_linear_tone(struct hda_beep *beep, int hz) 56static int beep_linear_tone(struct hda_beep *beep, int hz)
56{ 57{
58 if (hz <= 0)
59 return 0;
57 hz *= 1000; /* fixed point */ 60 hz *= 1000; /* fixed point */
58 hz = hz - DIGBEEP_HZ_MIN; 61 hz = hz - DIGBEEP_HZ_MIN
62 + DIGBEEP_HZ_STEP / 2; /* round to nearest step */
59 if (hz < 0) 63 if (hz < 0)
60 hz = 0; /* turn off PC beep*/ 64 hz = 0; /* turn off PC beep*/
61 else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN)) 65 else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN))
62 hz = 0xff; 66 hz = 1; /* max frequency */
63 else { 67 else {
64 hz /= DIGBEEP_HZ_STEP; 68 hz /= DIGBEEP_HZ_STEP;
65 hz++; 69 hz = 255 - hz;
66 } 70 }
67 return hz; 71 return hz;
68} 72}
@@ -115,6 +119,9 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
115 struct hda_beep *beep; 119 struct hda_beep *beep;
116 int err; 120 int err;
117 121
122 if (!snd_hda_get_bool_hint(codec, "beep"))
123 return 0; /* disabled explicitly */
124
118 beep = kzalloc(sizeof(*beep), GFP_KERNEL); 125 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
119 if (beep == NULL) 126 if (beep == NULL)
120 return -ENOMEM; 127 return -ENOMEM;
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 462e2cedaa6..af989f660cc 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -44,6 +44,7 @@ struct hda_vendor_id {
44/* codec vendor labels */ 44/* codec vendor labels */
45static struct hda_vendor_id hda_vendor_ids[] = { 45static struct hda_vendor_id hda_vendor_ids[] = {
46 { 0x1002, "ATI" }, 46 { 0x1002, "ATI" },
47 { 0x1013, "Cirrus Logic" },
47 { 0x1057, "Motorola" }, 48 { 0x1057, "Motorola" },
48 { 0x1095, "Silicon Image" }, 49 { 0x1095, "Silicon Image" },
49 { 0x10de, "Nvidia" }, 50 { 0x10de, "Nvidia" },
@@ -150,7 +151,14 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
150{ 151{
151 u32 val; 152 u32 val;
152 153
153 val = (u32)(codec->addr & 0x0f) << 28; 154 if ((codec->addr & ~0xf) || (direct & ~1) || (nid & ~0x7f) ||
155 (verb & ~0xfff) || (parm & ~0xffff)) {
156 printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n",
157 codec->addr, direct, nid, verb, parm);
158 return ~0;
159 }
160
161 val = (u32)codec->addr << 28;
154 val |= (u32)direct << 27; 162 val |= (u32)direct << 27;
155 val |= (u32)nid << 20; 163 val |= (u32)nid << 20;
156 val |= verb << 8; 164 val |= verb << 8;
@@ -167,6 +175,9 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
167 struct hda_bus *bus = codec->bus; 175 struct hda_bus *bus = codec->bus;
168 int err; 176 int err;
169 177
178 if (cmd == ~0)
179 return -1;
180
170 if (res) 181 if (res)
171 *res = -1; 182 *res = -1;
172 again: 183 again:
@@ -174,7 +185,7 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
174 mutex_lock(&bus->cmd_mutex); 185 mutex_lock(&bus->cmd_mutex);
175 err = bus->ops.command(bus, cmd); 186 err = bus->ops.command(bus, cmd);
176 if (!err && res) 187 if (!err && res)
177 *res = bus->ops.get_response(bus); 188 *res = bus->ops.get_response(bus, codec->addr);
178 mutex_unlock(&bus->cmd_mutex); 189 mutex_unlock(&bus->cmd_mutex);
179 snd_hda_power_down(codec); 190 snd_hda_power_down(codec);
180 if (res && *res == -1 && bus->rirb_error) { 191 if (res && *res == -1 && bus->rirb_error) {
@@ -291,11 +302,20 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
291 unsigned int parm; 302 unsigned int parm;
292 int i, conn_len, conns; 303 int i, conn_len, conns;
293 unsigned int shift, num_elems, mask; 304 unsigned int shift, num_elems, mask;
305 unsigned int wcaps;
294 hda_nid_t prev_nid; 306 hda_nid_t prev_nid;
295 307
296 if (snd_BUG_ON(!conn_list || max_conns <= 0)) 308 if (snd_BUG_ON(!conn_list || max_conns <= 0))
297 return -EINVAL; 309 return -EINVAL;
298 310
311 wcaps = get_wcaps(codec, nid);
312 if (!(wcaps & AC_WCAP_CONN_LIST) &&
313 get_wcaps_type(wcaps) != AC_WID_VOL_KNB) {
314 snd_printk(KERN_WARNING "hda_codec: "
315 "connection list not available for 0x%x\n", nid);
316 return -EINVAL;
317 }
318
299 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN); 319 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
300 if (parm & AC_CLIST_LONG) { 320 if (parm & AC_CLIST_LONG) {
301 /* long form */ 321 /* long form */
@@ -316,6 +336,8 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
316 /* single connection */ 336 /* single connection */
317 parm = snd_hda_codec_read(codec, nid, 0, 337 parm = snd_hda_codec_read(codec, nid, 0,
318 AC_VERB_GET_CONNECT_LIST, 0); 338 AC_VERB_GET_CONNECT_LIST, 0);
339 if (parm == -1 && codec->bus->rirb_error)
340 return -EIO;
319 conn_list[0] = parm & mask; 341 conn_list[0] = parm & mask;
320 return 1; 342 return 1;
321 } 343 }
@@ -327,11 +349,20 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
327 int range_val; 349 int range_val;
328 hda_nid_t val, n; 350 hda_nid_t val, n;
329 351
330 if (i % num_elems == 0) 352 if (i % num_elems == 0) {
331 parm = snd_hda_codec_read(codec, nid, 0, 353 parm = snd_hda_codec_read(codec, nid, 0,
332 AC_VERB_GET_CONNECT_LIST, i); 354 AC_VERB_GET_CONNECT_LIST, i);
355 if (parm == -1 && codec->bus->rirb_error)
356 return -EIO;
357 }
333 range_val = !!(parm & (1 << (shift-1))); /* ranges */ 358 range_val = !!(parm & (1 << (shift-1))); /* ranges */
334 val = parm & mask; 359 val = parm & mask;
360 if (val == 0) {
361 snd_printk(KERN_WARNING "hda_codec: "
362 "invalid CONNECT_LIST verb %x[%i]:%x\n",
363 nid, i, parm);
364 return 0;
365 }
335 parm >>= shift; 366 parm >>= shift;
336 if (range_val) { 367 if (range_val) {
337 /* ranges between the previous and this one */ 368 /* ranges between the previous and this one */
@@ -721,8 +752,7 @@ static int read_pin_defaults(struct hda_codec *codec)
721 for (i = 0; i < codec->num_nodes; i++, nid++) { 752 for (i = 0; i < codec->num_nodes; i++, nid++) {
722 struct hda_pincfg *pin; 753 struct hda_pincfg *pin;
723 unsigned int wcaps = get_wcaps(codec, nid); 754 unsigned int wcaps = get_wcaps(codec, nid);
724 unsigned int wid_type = (wcaps & AC_WCAP_TYPE) >> 755 unsigned int wid_type = get_wcaps_type(wcaps);
725 AC_WCAP_TYPE_SHIFT;
726 if (wid_type != AC_WID_PIN) 756 if (wid_type != AC_WID_PIN)
727 continue; 757 continue;
728 pin = snd_array_new(&codec->init_pins); 758 pin = snd_array_new(&codec->init_pins);
@@ -885,7 +915,7 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
885 * Returns 0 if successful, or a negative error code. 915 * Returns 0 if successful, or a negative error code.
886 */ 916 */
887int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 917int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
888 int do_init, struct hda_codec **codecp) 918 struct hda_codec **codecp)
889{ 919{
890 struct hda_codec *codec; 920 struct hda_codec *codec;
891 char component[31]; 921 char component[31];
@@ -978,11 +1008,6 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
978 codec->afg ? codec->afg : codec->mfg, 1008 codec->afg ? codec->afg : codec->mfg,
979 AC_PWRST_D0); 1009 AC_PWRST_D0);
980 1010
981 if (do_init) {
982 err = snd_hda_codec_configure(codec);
983 if (err < 0)
984 goto error;
985 }
986 snd_hda_codec_proc_new(codec); 1011 snd_hda_codec_proc_new(codec);
987 1012
988 snd_hda_create_hwdep(codec); 1013 snd_hda_create_hwdep(codec);
@@ -1036,6 +1061,7 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1036 err = init_unsol_queue(codec->bus); 1061 err = init_unsol_queue(codec->bus);
1037 return err; 1062 return err;
1038} 1063}
1064EXPORT_SYMBOL_HDA(snd_hda_codec_configure);
1039 1065
1040/** 1066/**
1041 * snd_hda_codec_setup_stream - set up the codec for streaming 1067 * snd_hda_codec_setup_stream - set up the codec for streaming
@@ -2350,16 +2376,20 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2350 hda_nid_t nid; 2376 hda_nid_t nid;
2351 int i; 2377 int i;
2352 2378
2353 snd_hda_codec_write(codec, fg, 0, AC_VERB_SET_POWER_STATE, 2379 /* this delay seems necessary to avoid click noise at power-down */
2380 if (power_state == AC_PWRST_D3)
2381 msleep(100);
2382 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
2354 power_state); 2383 power_state);
2355 msleep(10); /* partial workaround for "azx_get_response timeout" */ 2384 /* partial workaround for "azx_get_response timeout" */
2385 if (power_state == AC_PWRST_D0)
2386 msleep(10);
2356 2387
2357 nid = codec->start_nid; 2388 nid = codec->start_nid;
2358 for (i = 0; i < codec->num_nodes; i++, nid++) { 2389 for (i = 0; i < codec->num_nodes; i++, nid++) {
2359 unsigned int wcaps = get_wcaps(codec, nid); 2390 unsigned int wcaps = get_wcaps(codec, nid);
2360 if (wcaps & AC_WCAP_POWER) { 2391 if (wcaps & AC_WCAP_POWER) {
2361 unsigned int wid_type = (wcaps & AC_WCAP_TYPE) >> 2392 unsigned int wid_type = get_wcaps_type(wcaps);
2362 AC_WCAP_TYPE_SHIFT;
2363 if (power_state == AC_PWRST_D3 && 2393 if (power_state == AC_PWRST_D3 &&
2364 wid_type == AC_WID_PIN) { 2394 wid_type == AC_WID_PIN) {
2365 unsigned int pincap; 2395 unsigned int pincap;
@@ -2567,7 +2597,7 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
2567 case 20: 2597 case 20:
2568 case 24: 2598 case 24:
2569 case 32: 2599 case 32:
2570 if (maxbps >= 32) 2600 if (maxbps >= 32 || format == SNDRV_PCM_FORMAT_FLOAT_LE)
2571 val |= 0x40; 2601 val |= 0x40;
2572 else if (maxbps >= 24) 2602 else if (maxbps >= 24)
2573 val |= 0x30; 2603 val |= 0x30;
@@ -2694,11 +2724,12 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2694 bps = 20; 2724 bps = 20;
2695 } 2725 }
2696 } 2726 }
2697 else if (streams == AC_SUPFMT_FLOAT32) { 2727 if (streams & AC_SUPFMT_FLOAT32) {
2698 /* should be exclusive */
2699 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; 2728 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
2700 bps = 32; 2729 if (!bps)
2701 } else if (streams == AC_SUPFMT_AC3) { 2730 bps = 32;
2731 }
2732 if (streams == AC_SUPFMT_AC3) {
2702 /* should be exclusive */ 2733 /* should be exclusive */
2703 /* temporary hack: we have still no proper support 2734 /* temporary hack: we have still no proper support
2704 * for the direct AC3 stream... 2735 * for the direct AC3 stream...
@@ -3096,7 +3127,7 @@ int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
3096 tbl = q; 3127 tbl = q;
3097 3128
3098 if (tbl->value >= 0 && tbl->value < num_configs) { 3129 if (tbl->value >= 0 && tbl->value < num_configs) {
3099#ifdef CONFIG_SND_DEBUG_DETECT 3130#ifdef CONFIG_SND_DEBUG_VERBOSE
3100 char tmp[10]; 3131 char tmp[10];
3101 const char *model = NULL; 3132 const char *model = NULL;
3102 if (models) 3133 if (models)
@@ -3470,10 +3501,16 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3470 } 3501 }
3471 mutex_lock(&codec->spdif_mutex); 3502 mutex_lock(&codec->spdif_mutex);
3472 if (mout->share_spdif) { 3503 if (mout->share_spdif) {
3473 runtime->hw.rates &= mout->spdif_rates; 3504 if ((runtime->hw.rates & mout->spdif_rates) &&
3474 runtime->hw.formats &= mout->spdif_formats; 3505 (runtime->hw.formats & mout->spdif_formats)) {
3475 if (mout->spdif_maxbps < hinfo->maxbps) 3506 runtime->hw.rates &= mout->spdif_rates;
3476 hinfo->maxbps = mout->spdif_maxbps; 3507 runtime->hw.formats &= mout->spdif_formats;
3508 if (mout->spdif_maxbps < hinfo->maxbps)
3509 hinfo->maxbps = mout->spdif_maxbps;
3510 } else {
3511 mout->share_spdif = 0;
3512 /* FIXME: need notify? */
3513 }
3477 } 3514 }
3478 mutex_unlock(&codec->spdif_mutex); 3515 mutex_unlock(&codec->spdif_mutex);
3479 } 3516 }
@@ -3643,8 +3680,7 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3643 end_nid = codec->start_nid + codec->num_nodes; 3680 end_nid = codec->start_nid + codec->num_nodes;
3644 for (nid = codec->start_nid; nid < end_nid; nid++) { 3681 for (nid = codec->start_nid; nid < end_nid; nid++) {
3645 unsigned int wid_caps = get_wcaps(codec, nid); 3682 unsigned int wid_caps = get_wcaps(codec, nid);
3646 unsigned int wid_type = 3683 unsigned int wid_type = get_wcaps_type(wid_caps);
3647 (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3648 unsigned int def_conf; 3684 unsigned int def_conf;
3649 short assoc, loc; 3685 short assoc, loc;
3650 3686
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index cad79efaabc..99552fb5f75 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -568,7 +568,7 @@ struct hda_bus_ops {
568 /* send a single command */ 568 /* send a single command */
569 int (*command)(struct hda_bus *bus, unsigned int cmd); 569 int (*command)(struct hda_bus *bus, unsigned int cmd);
570 /* get a response from the last command */ 570 /* get a response from the last command */
571 unsigned int (*get_response)(struct hda_bus *bus); 571 unsigned int (*get_response)(struct hda_bus *bus, unsigned int addr);
572 /* free the private data */ 572 /* free the private data */
573 void (*private_free)(struct hda_bus *); 573 void (*private_free)(struct hda_bus *);
574 /* attach a PCM stream */ 574 /* attach a PCM stream */
@@ -830,7 +830,8 @@ enum {
830int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp, 830int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp,
831 struct hda_bus **busp); 831 struct hda_bus **busp);
832int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 832int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
833 int do_init, struct hda_codec **codecp); 833 struct hda_codec **codecp);
834int snd_hda_codec_configure(struct hda_codec *codec);
834 835
835/* 836/*
836 * low level functions 837 * low level functions
@@ -938,6 +939,13 @@ static inline void snd_hda_power_down(struct hda_codec *codec) {}
938#define snd_hda_codec_needs_resume(codec) 1 939#define snd_hda_codec_needs_resume(codec) 1
939#endif 940#endif
940 941
942#ifdef CONFIG_SND_HDA_PATCH_LOADER
943/*
944 * patch firmware
945 */
946int snd_hda_load_patch(struct hda_bus *bus, const char *patch);
947#endif
948
941/* 949/*
942 * Codec modularization 950 * Codec modularization
943 */ 951 */
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index fcad5ec3177..9446a5abea1 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -508,7 +508,7 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
508 char name[64]; 508 char name[64];
509 char *sname; 509 char *sname;
510 long long val; 510 long long val;
511 int n; 511 unsigned int n;
512 512
513 while (!snd_info_get_line(buffer, line, sizeof(line))) { 513 while (!snd_info_get_line(buffer, line, sizeof(line))) {
514 if (sscanf(line, "%s %llx", name, &val) != 2) 514 if (sscanf(line, "%s %llx", name, &val) != 2)
@@ -539,7 +539,7 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
539 sname++; 539 sname++;
540 n = 10 * n + name[4] - '0'; 540 n = 10 * n + name[4] - '0';
541 } 541 }
542 if (n < 0 || n > 31) /* double the CEA limit */ 542 if (n >= ELD_MAX_SAD)
543 continue; 543 continue;
544 if (!strcmp(sname, "_coding_type")) 544 if (!strcmp(sname, "_coding_type"))
545 e->sad[n].format = val; 545 e->sad[n].format = val;
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 1d5797a9668..b36f6c5a92d 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -121,11 +121,17 @@ static int add_new_node(struct hda_codec *codec, struct hda_gspec *spec, hda_nid
121 if (node == NULL) 121 if (node == NULL)
122 return -ENOMEM; 122 return -ENOMEM;
123 node->nid = nid; 123 node->nid = nid;
124 nconns = snd_hda_get_connections(codec, nid, conn_list, 124 node->wid_caps = get_wcaps(codec, nid);
125 HDA_MAX_CONNECTIONS); 125 node->type = get_wcaps_type(node->wid_caps);
126 if (nconns < 0) { 126 if (node->wid_caps & AC_WCAP_CONN_LIST) {
127 kfree(node); 127 nconns = snd_hda_get_connections(codec, nid, conn_list,
128 return nconns; 128 HDA_MAX_CONNECTIONS);
129 if (nconns < 0) {
130 kfree(node);
131 return nconns;
132 }
133 } else {
134 nconns = 0;
129 } 135 }
130 if (nconns <= ARRAY_SIZE(node->slist)) 136 if (nconns <= ARRAY_SIZE(node->slist))
131 node->conn_list = node->slist; 137 node->conn_list = node->slist;
@@ -140,8 +146,6 @@ static int add_new_node(struct hda_codec *codec, struct hda_gspec *spec, hda_nid
140 } 146 }
141 memcpy(node->conn_list, conn_list, nconns * sizeof(hda_nid_t)); 147 memcpy(node->conn_list, conn_list, nconns * sizeof(hda_nid_t));
142 node->nconns = nconns; 148 node->nconns = nconns;
143 node->wid_caps = get_wcaps(codec, nid);
144 node->type = (node->wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
145 149
146 if (node->type == AC_WID_PIN) { 150 if (node->type == AC_WID_PIN) {
147 node->pin_caps = snd_hda_query_pin_caps(codec, node->nid); 151 node->pin_caps = snd_hda_query_pin_caps(codec, node->nid);
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index 6812fbe80fa..cc24e6721d7 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -24,6 +24,7 @@
24#include <linux/compat.h> 24#include <linux/compat.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/ctype.h> 26#include <linux/ctype.h>
27#include <linux/firmware.h>
27#include <sound/core.h> 28#include <sound/core.h>
28#include "hda_codec.h" 29#include "hda_codec.h"
29#include "hda_local.h" 30#include "hda_local.h"
@@ -312,12 +313,8 @@ static ssize_t init_verbs_show(struct device *dev,
312 return len; 313 return len;
313} 314}
314 315
315static ssize_t init_verbs_store(struct device *dev, 316static int parse_init_verbs(struct hda_codec *codec, const char *buf)
316 struct device_attribute *attr,
317 const char *buf, size_t count)
318{ 317{
319 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
320 struct hda_codec *codec = hwdep->private_data;
321 struct hda_verb *v; 318 struct hda_verb *v;
322 int nid, verb, param; 319 int nid, verb, param;
323 320
@@ -331,6 +328,18 @@ static ssize_t init_verbs_store(struct device *dev,
331 v->nid = nid; 328 v->nid = nid;
332 v->verb = verb; 329 v->verb = verb;
333 v->param = param; 330 v->param = param;
331 return 0;
332}
333
334static ssize_t init_verbs_store(struct device *dev,
335 struct device_attribute *attr,
336 const char *buf, size_t count)
337{
338 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
339 struct hda_codec *codec = hwdep->private_data;
340 int err = parse_init_verbs(codec, buf);
341 if (err < 0)
342 return err;
334 return count; 343 return count;
335} 344}
336 345
@@ -376,19 +385,15 @@ static void remove_trail_spaces(char *str)
376 385
377#define MAX_HINTS 1024 386#define MAX_HINTS 1024
378 387
379static ssize_t hints_store(struct device *dev, 388static int parse_hints(struct hda_codec *codec, const char *buf)
380 struct device_attribute *attr,
381 const char *buf, size_t count)
382{ 389{
383 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
384 struct hda_codec *codec = hwdep->private_data;
385 char *key, *val; 390 char *key, *val;
386 struct hda_hint *hint; 391 struct hda_hint *hint;
387 392
388 while (isspace(*buf)) 393 while (isspace(*buf))
389 buf++; 394 buf++;
390 if (!*buf || *buf == '#' || *buf == '\n') 395 if (!*buf || *buf == '#' || *buf == '\n')
391 return count; 396 return 0;
392 if (*buf == '=') 397 if (*buf == '=')
393 return -EINVAL; 398 return -EINVAL;
394 key = kstrndup_noeol(buf, 1024); 399 key = kstrndup_noeol(buf, 1024);
@@ -411,7 +416,7 @@ static ssize_t hints_store(struct device *dev,
411 kfree(hint->key); 416 kfree(hint->key);
412 hint->key = key; 417 hint->key = key;
413 hint->val = val; 418 hint->val = val;
414 return count; 419 return 0;
415 } 420 }
416 /* allocate a new hint entry */ 421 /* allocate a new hint entry */
417 if (codec->hints.used >= MAX_HINTS) 422 if (codec->hints.used >= MAX_HINTS)
@@ -424,6 +429,18 @@ static ssize_t hints_store(struct device *dev,
424 } 429 }
425 hint->key = key; 430 hint->key = key;
426 hint->val = val; 431 hint->val = val;
432 return 0;
433}
434
435static ssize_t hints_store(struct device *dev,
436 struct device_attribute *attr,
437 const char *buf, size_t count)
438{
439 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
440 struct hda_codec *codec = hwdep->private_data;
441 int err = parse_hints(codec, buf);
442 if (err < 0)
443 return err;
427 return count; 444 return count;
428} 445}
429 446
@@ -469,20 +486,24 @@ static ssize_t driver_pin_configs_show(struct device *dev,
469 486
470#define MAX_PIN_CONFIGS 32 487#define MAX_PIN_CONFIGS 32
471 488
472static ssize_t user_pin_configs_store(struct device *dev, 489static int parse_user_pin_configs(struct hda_codec *codec, const char *buf)
473 struct device_attribute *attr,
474 const char *buf, size_t count)
475{ 490{
476 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
477 struct hda_codec *codec = hwdep->private_data;
478 int nid, cfg; 491 int nid, cfg;
479 int err;
480 492
481 if (sscanf(buf, "%i %i", &nid, &cfg) != 2) 493 if (sscanf(buf, "%i %i", &nid, &cfg) != 2)
482 return -EINVAL; 494 return -EINVAL;
483 if (!nid) 495 if (!nid)
484 return -EINVAL; 496 return -EINVAL;
485 err = snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg); 497 return snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg);
498}
499
500static ssize_t user_pin_configs_store(struct device *dev,
501 struct device_attribute *attr,
502 const char *buf, size_t count)
503{
504 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
505 struct hda_codec *codec = hwdep->private_data;
506 int err = parse_user_pin_configs(codec, buf);
486 if (err < 0) 507 if (err < 0)
487 return err; 508 return err;
488 return count; 509 return count;
@@ -553,3 +574,180 @@ int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
553EXPORT_SYMBOL_HDA(snd_hda_get_bool_hint); 574EXPORT_SYMBOL_HDA(snd_hda_get_bool_hint);
554 575
555#endif /* CONFIG_SND_HDA_RECONFIG */ 576#endif /* CONFIG_SND_HDA_RECONFIG */
577
578#ifdef CONFIG_SND_HDA_PATCH_LOADER
579
580/* parser mode */
581enum {
582 LINE_MODE_NONE,
583 LINE_MODE_CODEC,
584 LINE_MODE_MODEL,
585 LINE_MODE_PINCFG,
586 LINE_MODE_VERB,
587 LINE_MODE_HINT,
588 NUM_LINE_MODES,
589};
590
591static inline int strmatch(const char *a, const char *b)
592{
593 return strnicmp(a, b, strlen(b)) == 0;
594}
595
596/* parse the contents after the line "[codec]"
597 * accept only the line with three numbers, and assign the current codec
598 */
599static void parse_codec_mode(char *buf, struct hda_bus *bus,
600 struct hda_codec **codecp)
601{
602 unsigned int vendorid, subid, caddr;
603 struct hda_codec *codec;
604
605 *codecp = NULL;
606 if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) {
607 list_for_each_entry(codec, &bus->codec_list, list) {
608 if (codec->addr == caddr) {
609 *codecp = codec;
610 break;
611 }
612 }
613 }
614}
615
616/* parse the contents after the other command tags, [pincfg], [verb],
617 * [hint] and [model]
618 * just pass to the sysfs helper (only when any codec was specified)
619 */
620static void parse_pincfg_mode(char *buf, struct hda_bus *bus,
621 struct hda_codec **codecp)
622{
623 if (!*codecp)
624 return;
625 parse_user_pin_configs(*codecp, buf);
626}
627
628static void parse_verb_mode(char *buf, struct hda_bus *bus,
629 struct hda_codec **codecp)
630{
631 if (!*codecp)
632 return;
633 parse_init_verbs(*codecp, buf);
634}
635
636static void parse_hint_mode(char *buf, struct hda_bus *bus,
637 struct hda_codec **codecp)
638{
639 if (!*codecp)
640 return;
641 parse_hints(*codecp, buf);
642}
643
644static void parse_model_mode(char *buf, struct hda_bus *bus,
645 struct hda_codec **codecp)
646{
647 if (!*codecp)
648 return;
649 kfree((*codecp)->modelname);
650 (*codecp)->modelname = kstrdup(buf, GFP_KERNEL);
651}
652
653struct hda_patch_item {
654 const char *tag;
655 void (*parser)(char *buf, struct hda_bus *bus, struct hda_codec **retc);
656};
657
658static struct hda_patch_item patch_items[NUM_LINE_MODES] = {
659 [LINE_MODE_CODEC] = { "[codec]", parse_codec_mode },
660 [LINE_MODE_MODEL] = { "[model]", parse_model_mode },
661 [LINE_MODE_VERB] = { "[verb]", parse_verb_mode },
662 [LINE_MODE_PINCFG] = { "[pincfg]", parse_pincfg_mode },
663 [LINE_MODE_HINT] = { "[hint]", parse_hint_mode },
664};
665
666/* check the line starting with '[' -- change the parser mode accodingly */
667static int parse_line_mode(char *buf, struct hda_bus *bus)
668{
669 int i;
670 for (i = 0; i < ARRAY_SIZE(patch_items); i++) {
671 if (!patch_items[i].tag)
672 continue;
673 if (strmatch(buf, patch_items[i].tag))
674 return i;
675 }
676 return LINE_MODE_NONE;
677}
678
679/* copy one line from the buffer in fw, and update the fields in fw
680 * return zero if it reaches to the end of the buffer, or non-zero
681 * if successfully copied a line
682 *
683 * the spaces at the beginning and the end of the line are stripped
684 */
685static int get_line_from_fw(char *buf, int size, struct firmware *fw)
686{
687 int len;
688 const char *p = fw->data;
689 while (isspace(*p) && fw->size) {
690 p++;
691 fw->size--;
692 }
693 if (!fw->size)
694 return 0;
695 if (size < fw->size)
696 size = fw->size;
697
698 for (len = 0; len < fw->size; len++) {
699 if (!*p)
700 break;
701 if (*p == '\n') {
702 p++;
703 len++;
704 break;
705 }
706 if (len < size)
707 *buf++ = *p++;
708 }
709 *buf = 0;
710 fw->size -= len;
711 fw->data = p;
712 remove_trail_spaces(buf);
713 return 1;
714}
715
716/*
717 * load a "patch" firmware file and parse it
718 */
719int snd_hda_load_patch(struct hda_bus *bus, const char *patch)
720{
721 int err;
722 const struct firmware *fw;
723 struct firmware tmp;
724 char buf[128];
725 struct hda_codec *codec;
726 int line_mode;
727 struct device *dev = bus->card->dev;
728
729 if (snd_BUG_ON(!dev))
730 return -ENODEV;
731 err = request_firmware(&fw, patch, dev);
732 if (err < 0) {
733 printk(KERN_ERR "hda-codec: Cannot load the patch '%s'\n",
734 patch);
735 return err;
736 }
737
738 tmp = *fw;
739 line_mode = LINE_MODE_NONE;
740 codec = NULL;
741 while (get_line_from_fw(buf, sizeof(buf) - 1, &tmp)) {
742 if (!*buf || *buf == '#' || *buf == '\n')
743 continue;
744 if (*buf == '[')
745 line_mode = parse_line_mode(buf, bus);
746 else if (patch_items[line_mode].parser)
747 patch_items[line_mode].parser(buf, bus, &codec);
748 }
749 release_firmware(fw);
750 return 0;
751}
752EXPORT_SYMBOL_HDA(snd_hda_load_patch);
753#endif /* CONFIG_SND_HDA_PATCH_LOADER */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 4e9ea708027..20a66f85f0a 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -61,6 +61,9 @@ static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
61static int probe_only[SNDRV_CARDS]; 61static int probe_only[SNDRV_CARDS];
62static int single_cmd; 62static int single_cmd;
63static int enable_msi; 63static int enable_msi;
64#ifdef CONFIG_SND_HDA_PATCH_LOADER
65static char *patch[SNDRV_CARDS];
66#endif
64 67
65module_param_array(index, int, NULL, 0444); 68module_param_array(index, int, NULL, 0444);
66MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); 69MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
@@ -84,6 +87,10 @@ MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
84 "(for debugging only)."); 87 "(for debugging only).");
85module_param(enable_msi, int, 0444); 88module_param(enable_msi, int, 0444);
86MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)"); 89MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
90#ifdef CONFIG_SND_HDA_PATCH_LOADER
91module_param_array(patch, charp, NULL, 0444);
92MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
93#endif
87 94
88#ifdef CONFIG_SND_HDA_POWER_SAVE 95#ifdef CONFIG_SND_HDA_POWER_SAVE
89static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; 96static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
@@ -253,7 +260,7 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
253 260
254/* STATESTS int mask: S3,SD2,SD1,SD0 */ 261/* STATESTS int mask: S3,SD2,SD1,SD0 */
255#define AZX_MAX_CODECS 4 262#define AZX_MAX_CODECS 4
256#define STATESTS_INT_MASK 0x0f 263#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
257 264
258/* SD_CTL bits */ 265/* SD_CTL bits */
259#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ 266#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
@@ -361,8 +368,8 @@ struct azx_rb {
361 dma_addr_t addr; /* physical address of CORB/RIRB buffer */ 368 dma_addr_t addr; /* physical address of CORB/RIRB buffer */
362 /* for RIRB */ 369 /* for RIRB */
363 unsigned short rp, wp; /* read/write pointers */ 370 unsigned short rp, wp; /* read/write pointers */
364 int cmds; /* number of pending requests */ 371 int cmds[AZX_MAX_CODECS]; /* number of pending requests */
365 u32 res; /* last read value */ 372 u32 res[AZX_MAX_CODECS]; /* last read value */
366}; 373};
367 374
368struct azx { 375struct azx {
@@ -418,7 +425,7 @@ struct azx {
418 unsigned int probing :1; /* codec probing phase */ 425 unsigned int probing :1; /* codec probing phase */
419 426
420 /* for debugging */ 427 /* for debugging */
421 unsigned int last_cmd; /* last issued command (to sync) */ 428 unsigned int last_cmd[AZX_MAX_CODECS];
422 429
423 /* for pending irqs */ 430 /* for pending irqs */
424 struct work_struct irq_pending_work; 431 struct work_struct irq_pending_work;
@@ -513,6 +520,7 @@ static int azx_alloc_cmd_io(struct azx *chip)
513 520
514static void azx_init_cmd_io(struct azx *chip) 521static void azx_init_cmd_io(struct azx *chip)
515{ 522{
523 spin_lock_irq(&chip->reg_lock);
516 /* CORB set up */ 524 /* CORB set up */
517 chip->corb.addr = chip->rb.addr; 525 chip->corb.addr = chip->rb.addr;
518 chip->corb.buf = (u32 *)chip->rb.area; 526 chip->corb.buf = (u32 *)chip->rb.area;
@@ -531,7 +539,8 @@ static void azx_init_cmd_io(struct azx *chip)
531 /* RIRB set up */ 539 /* RIRB set up */
532 chip->rirb.addr = chip->rb.addr + 2048; 540 chip->rirb.addr = chip->rb.addr + 2048;
533 chip->rirb.buf = (u32 *)(chip->rb.area + 2048); 541 chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
534 chip->rirb.wp = chip->rirb.rp = chip->rirb.cmds = 0; 542 chip->rirb.wp = chip->rirb.rp = 0;
543 memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));
535 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr); 544 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
536 azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr)); 545 azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
537 546
@@ -543,30 +552,60 @@ static void azx_init_cmd_io(struct azx *chip)
543 azx_writew(chip, RINTCNT, 1); 552 azx_writew(chip, RINTCNT, 1);
544 /* enable rirb dma and response irq */ 553 /* enable rirb dma and response irq */
545 azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN); 554 azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
555 spin_unlock_irq(&chip->reg_lock);
546} 556}
547 557
548static void azx_free_cmd_io(struct azx *chip) 558static void azx_free_cmd_io(struct azx *chip)
549{ 559{
560 spin_lock_irq(&chip->reg_lock);
550 /* disable ringbuffer DMAs */ 561 /* disable ringbuffer DMAs */
551 azx_writeb(chip, RIRBCTL, 0); 562 azx_writeb(chip, RIRBCTL, 0);
552 azx_writeb(chip, CORBCTL, 0); 563 azx_writeb(chip, CORBCTL, 0);
564 spin_unlock_irq(&chip->reg_lock);
565}
566
567static unsigned int azx_command_addr(u32 cmd)
568{
569 unsigned int addr = cmd >> 28;
570
571 if (addr >= AZX_MAX_CODECS) {
572 snd_BUG();
573 addr = 0;
574 }
575
576 return addr;
577}
578
579static unsigned int azx_response_addr(u32 res)
580{
581 unsigned int addr = res & 0xf;
582
583 if (addr >= AZX_MAX_CODECS) {
584 snd_BUG();
585 addr = 0;
586 }
587
588 return addr;
553} 589}
554 590
555/* send a command */ 591/* send a command */
556static int azx_corb_send_cmd(struct hda_bus *bus, u32 val) 592static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
557{ 593{
558 struct azx *chip = bus->private_data; 594 struct azx *chip = bus->private_data;
595 unsigned int addr = azx_command_addr(val);
559 unsigned int wp; 596 unsigned int wp;
560 597
598 spin_lock_irq(&chip->reg_lock);
599
561 /* add command to corb */ 600 /* add command to corb */
562 wp = azx_readb(chip, CORBWP); 601 wp = azx_readb(chip, CORBWP);
563 wp++; 602 wp++;
564 wp %= ICH6_MAX_CORB_ENTRIES; 603 wp %= ICH6_MAX_CORB_ENTRIES;
565 604
566 spin_lock_irq(&chip->reg_lock); 605 chip->rirb.cmds[addr]++;
567 chip->rirb.cmds++;
568 chip->corb.buf[wp] = cpu_to_le32(val); 606 chip->corb.buf[wp] = cpu_to_le32(val);
569 azx_writel(chip, CORBWP, wp); 607 azx_writel(chip, CORBWP, wp);
608
570 spin_unlock_irq(&chip->reg_lock); 609 spin_unlock_irq(&chip->reg_lock);
571 610
572 return 0; 611 return 0;
@@ -578,13 +617,14 @@ static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
578static void azx_update_rirb(struct azx *chip) 617static void azx_update_rirb(struct azx *chip)
579{ 618{
580 unsigned int rp, wp; 619 unsigned int rp, wp;
620 unsigned int addr;
581 u32 res, res_ex; 621 u32 res, res_ex;
582 622
583 wp = azx_readb(chip, RIRBWP); 623 wp = azx_readb(chip, RIRBWP);
584 if (wp == chip->rirb.wp) 624 if (wp == chip->rirb.wp)
585 return; 625 return;
586 chip->rirb.wp = wp; 626 chip->rirb.wp = wp;
587 627
588 while (chip->rirb.rp != wp) { 628 while (chip->rirb.rp != wp) {
589 chip->rirb.rp++; 629 chip->rirb.rp++;
590 chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES; 630 chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
@@ -592,18 +632,24 @@ static void azx_update_rirb(struct azx *chip)
592 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */ 632 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
593 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]); 633 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
594 res = le32_to_cpu(chip->rirb.buf[rp]); 634 res = le32_to_cpu(chip->rirb.buf[rp]);
635 addr = azx_response_addr(res_ex);
595 if (res_ex & ICH6_RIRB_EX_UNSOL_EV) 636 if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
596 snd_hda_queue_unsol_event(chip->bus, res, res_ex); 637 snd_hda_queue_unsol_event(chip->bus, res, res_ex);
597 else if (chip->rirb.cmds) { 638 else if (chip->rirb.cmds[addr]) {
598 chip->rirb.res = res; 639 chip->rirb.res[addr] = res;
599 smp_wmb(); 640 smp_wmb();
600 chip->rirb.cmds--; 641 chip->rirb.cmds[addr]--;
601 } 642 } else
643 snd_printk(KERN_ERR SFX "spurious response %#x:%#x, "
644 "last cmd=%#08x\n",
645 res, res_ex,
646 chip->last_cmd[addr]);
602 } 647 }
603} 648}
604 649
605/* receive a response */ 650/* receive a response */
606static unsigned int azx_rirb_get_response(struct hda_bus *bus) 651static unsigned int azx_rirb_get_response(struct hda_bus *bus,
652 unsigned int addr)
607{ 653{
608 struct azx *chip = bus->private_data; 654 struct azx *chip = bus->private_data;
609 unsigned long timeout; 655 unsigned long timeout;
@@ -616,10 +662,10 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus)
616 azx_update_rirb(chip); 662 azx_update_rirb(chip);
617 spin_unlock_irq(&chip->reg_lock); 663 spin_unlock_irq(&chip->reg_lock);
618 } 664 }
619 if (!chip->rirb.cmds) { 665 if (!chip->rirb.cmds[addr]) {
620 smp_rmb(); 666 smp_rmb();
621 bus->rirb_error = 0; 667 bus->rirb_error = 0;
622 return chip->rirb.res; /* the last value */ 668 return chip->rirb.res[addr]; /* the last value */
623 } 669 }
624 if (time_after(jiffies, timeout)) 670 if (time_after(jiffies, timeout))
625 break; 671 break;
@@ -633,7 +679,8 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus)
633 679
634 if (chip->msi) { 680 if (chip->msi) {
635 snd_printk(KERN_WARNING SFX "No response from codec, " 681 snd_printk(KERN_WARNING SFX "No response from codec, "
636 "disabling MSI: last cmd=0x%08x\n", chip->last_cmd); 682 "disabling MSI: last cmd=0x%08x\n",
683 chip->last_cmd[addr]);
637 free_irq(chip->irq, chip); 684 free_irq(chip->irq, chip);
638 chip->irq = -1; 685 chip->irq = -1;
639 pci_disable_msi(chip->pci); 686 pci_disable_msi(chip->pci);
@@ -648,7 +695,7 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus)
648 if (!chip->polling_mode) { 695 if (!chip->polling_mode) {
649 snd_printk(KERN_WARNING SFX "azx_get_response timeout, " 696 snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
650 "switching to polling mode: last cmd=0x%08x\n", 697 "switching to polling mode: last cmd=0x%08x\n",
651 chip->last_cmd); 698 chip->last_cmd[addr]);
652 chip->polling_mode = 1; 699 chip->polling_mode = 1;
653 goto again; 700 goto again;
654 } 701 }
@@ -672,7 +719,7 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus)
672 719
673 snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, " 720 snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "
674 "switching to single_cmd mode: last cmd=0x%08x\n", 721 "switching to single_cmd mode: last cmd=0x%08x\n",
675 chip->last_cmd); 722 chip->last_cmd[addr]);
676 chip->single_cmd = 1; 723 chip->single_cmd = 1;
677 bus->response_reset = 0; 724 bus->response_reset = 0;
678 /* re-initialize CORB/RIRB */ 725 /* re-initialize CORB/RIRB */
@@ -692,7 +739,7 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus)
692 */ 739 */
693 740
694/* receive a response */ 741/* receive a response */
695static int azx_single_wait_for_response(struct azx *chip) 742static int azx_single_wait_for_response(struct azx *chip, unsigned int addr)
696{ 743{
697 int timeout = 50; 744 int timeout = 50;
698 745
@@ -700,7 +747,7 @@ static int azx_single_wait_for_response(struct azx *chip)
700 /* check IRV busy bit */ 747 /* check IRV busy bit */
701 if (azx_readw(chip, IRS) & ICH6_IRS_VALID) { 748 if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {
702 /* reuse rirb.res as the response return value */ 749 /* reuse rirb.res as the response return value */
703 chip->rirb.res = azx_readl(chip, IR); 750 chip->rirb.res[addr] = azx_readl(chip, IR);
704 return 0; 751 return 0;
705 } 752 }
706 udelay(1); 753 udelay(1);
@@ -708,7 +755,7 @@ static int azx_single_wait_for_response(struct azx *chip)
708 if (printk_ratelimit()) 755 if (printk_ratelimit())
709 snd_printd(SFX "get_response timeout: IRS=0x%x\n", 756 snd_printd(SFX "get_response timeout: IRS=0x%x\n",
710 azx_readw(chip, IRS)); 757 azx_readw(chip, IRS));
711 chip->rirb.res = -1; 758 chip->rirb.res[addr] = -1;
712 return -EIO; 759 return -EIO;
713} 760}
714 761
@@ -716,6 +763,7 @@ static int azx_single_wait_for_response(struct azx *chip)
716static int azx_single_send_cmd(struct hda_bus *bus, u32 val) 763static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
717{ 764{
718 struct azx *chip = bus->private_data; 765 struct azx *chip = bus->private_data;
766 unsigned int addr = azx_command_addr(val);
719 int timeout = 50; 767 int timeout = 50;
720 768
721 bus->rirb_error = 0; 769 bus->rirb_error = 0;
@@ -728,7 +776,7 @@ static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
728 azx_writel(chip, IC, val); 776 azx_writel(chip, IC, val);
729 azx_writew(chip, IRS, azx_readw(chip, IRS) | 777 azx_writew(chip, IRS, azx_readw(chip, IRS) |
730 ICH6_IRS_BUSY); 778 ICH6_IRS_BUSY);
731 return azx_single_wait_for_response(chip); 779 return azx_single_wait_for_response(chip, addr);
732 } 780 }
733 udelay(1); 781 udelay(1);
734 } 782 }
@@ -739,10 +787,11 @@ static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
739} 787}
740 788
741/* receive a response */ 789/* receive a response */
742static unsigned int azx_single_get_response(struct hda_bus *bus) 790static unsigned int azx_single_get_response(struct hda_bus *bus,
791 unsigned int addr)
743{ 792{
744 struct azx *chip = bus->private_data; 793 struct azx *chip = bus->private_data;
745 return chip->rirb.res; 794 return chip->rirb.res[addr];
746} 795}
747 796
748/* 797/*
@@ -757,7 +806,7 @@ static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
757{ 806{
758 struct azx *chip = bus->private_data; 807 struct azx *chip = bus->private_data;
759 808
760 chip->last_cmd = val; 809 chip->last_cmd[azx_command_addr(val)] = val;
761 if (chip->single_cmd) 810 if (chip->single_cmd)
762 return azx_single_send_cmd(bus, val); 811 return azx_single_send_cmd(bus, val);
763 else 812 else
@@ -765,13 +814,14 @@ static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
765} 814}
766 815
767/* get a response */ 816/* get a response */
768static unsigned int azx_get_response(struct hda_bus *bus) 817static unsigned int azx_get_response(struct hda_bus *bus,
818 unsigned int addr)
769{ 819{
770 struct azx *chip = bus->private_data; 820 struct azx *chip = bus->private_data;
771 if (chip->single_cmd) 821 if (chip->single_cmd)
772 return azx_single_get_response(bus); 822 return azx_single_get_response(bus, addr);
773 else 823 else
774 return azx_rirb_get_response(bus); 824 return azx_rirb_get_response(bus, addr);
775} 825}
776 826
777#ifdef CONFIG_SND_HDA_POWER_SAVE 827#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -1243,10 +1293,12 @@ static int probe_codec(struct azx *chip, int addr)
1243 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; 1293 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
1244 unsigned int res; 1294 unsigned int res;
1245 1295
1296 mutex_lock(&chip->bus->cmd_mutex);
1246 chip->probing = 1; 1297 chip->probing = 1;
1247 azx_send_cmd(chip->bus, cmd); 1298 azx_send_cmd(chip->bus, cmd);
1248 res = azx_get_response(chip->bus); 1299 res = azx_get_response(chip->bus, addr);
1249 chip->probing = 0; 1300 chip->probing = 0;
1301 mutex_unlock(&chip->bus->cmd_mutex);
1250 if (res == -1) 1302 if (res == -1)
1251 return -EIO; 1303 return -EIO;
1252 snd_printdd(SFX "codec #%d probed OK\n", addr); 1304 snd_printdd(SFX "codec #%d probed OK\n", addr);
@@ -1286,8 +1338,7 @@ static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
1286 [AZX_DRIVER_TERA] = 1, 1338 [AZX_DRIVER_TERA] = 1,
1287}; 1339};
1288 1340
1289static int __devinit azx_codec_create(struct azx *chip, const char *model, 1341static int __devinit azx_codec_create(struct azx *chip, const char *model)
1290 int no_init)
1291{ 1342{
1292 struct hda_bus_template bus_temp; 1343 struct hda_bus_template bus_temp;
1293 int c, codecs, err; 1344 int c, codecs, err;
@@ -1346,7 +1397,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model,
1346 for (c = 0; c < max_slots; c++) { 1397 for (c = 0; c < max_slots; c++) {
1347 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { 1398 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1348 struct hda_codec *codec; 1399 struct hda_codec *codec;
1349 err = snd_hda_codec_new(chip->bus, c, !no_init, &codec); 1400 err = snd_hda_codec_new(chip->bus, c, &codec);
1350 if (err < 0) 1401 if (err < 0)
1351 continue; 1402 continue;
1352 codecs++; 1403 codecs++;
@@ -1356,7 +1407,16 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model,
1356 snd_printk(KERN_ERR SFX "no codecs initialized\n"); 1407 snd_printk(KERN_ERR SFX "no codecs initialized\n");
1357 return -ENXIO; 1408 return -ENXIO;
1358 } 1409 }
1410 return 0;
1411}
1359 1412
1413/* configure each codec instance */
1414static int __devinit azx_codec_configure(struct azx *chip)
1415{
1416 struct hda_codec *codec;
1417 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1418 snd_hda_codec_configure(codec);
1419 }
1360 return 0; 1420 return 0;
1361} 1421}
1362 1422
@@ -1454,6 +1514,18 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1454 mutex_unlock(&chip->open_mutex); 1514 mutex_unlock(&chip->open_mutex);
1455 return err; 1515 return err;
1456 } 1516 }
1517 snd_pcm_limit_hw_rates(runtime);
1518 /* sanity check */
1519 if (snd_BUG_ON(!runtime->hw.channels_min) ||
1520 snd_BUG_ON(!runtime->hw.channels_max) ||
1521 snd_BUG_ON(!runtime->hw.formats) ||
1522 snd_BUG_ON(!runtime->hw.rates)) {
1523 azx_release_device(azx_dev);
1524 hinfo->ops.close(hinfo, apcm->codec, substream);
1525 snd_hda_power_down(apcm->codec);
1526 mutex_unlock(&chip->open_mutex);
1527 return -EINVAL;
1528 }
1457 spin_lock_irqsave(&chip->reg_lock, flags); 1529 spin_lock_irqsave(&chip->reg_lock, flags);
1458 azx_dev->substream = substream; 1530 azx_dev->substream = substream;
1459 azx_dev->running = 0; 1531 azx_dev->running = 0;
@@ -1462,7 +1534,6 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1462 runtime->private_data = azx_dev; 1534 runtime->private_data = azx_dev;
1463 snd_pcm_set_sync(substream); 1535 snd_pcm_set_sync(substream);
1464 mutex_unlock(&chip->open_mutex); 1536 mutex_unlock(&chip->open_mutex);
1465
1466 return 0; 1537 return 0;
1467} 1538}
1468 1539
@@ -2228,6 +2299,30 @@ static void __devinit check_probe_mask(struct azx *chip, int dev)
2228 } 2299 }
2229} 2300}
2230 2301
2302/*
2303 * white-list for enable_msi
2304 */
2305static struct snd_pci_quirk msi_white_list[] __devinitdata = {
2306 SND_PCI_QUIRK(0x103c, 0x3607, "HP Compa CQ40", 1),
2307 {}
2308};
2309
2310static void __devinit check_msi(struct azx *chip)
2311{
2312 const struct snd_pci_quirk *q;
2313
2314 chip->msi = enable_msi;
2315 if (chip->msi)
2316 return;
2317 q = snd_pci_quirk_lookup(chip->pci, msi_white_list);
2318 if (q) {
2319 printk(KERN_INFO
2320 "hda_intel: msi for device %04x:%04x set to %d\n",
2321 q->subvendor, q->subdevice, q->value);
2322 chip->msi = q->value;
2323 }
2324}
2325
2231 2326
2232/* 2327/*
2233 * constructor 2328 * constructor
@@ -2262,7 +2357,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2262 chip->pci = pci; 2357 chip->pci = pci;
2263 chip->irq = -1; 2358 chip->irq = -1;
2264 chip->driver_type = driver_type; 2359 chip->driver_type = driver_type;
2265 chip->msi = enable_msi; 2360 check_msi(chip);
2266 chip->dev_index = dev; 2361 chip->dev_index = dev;
2267 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); 2362 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
2268 2363
@@ -2322,9 +2417,19 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2322 gcap = azx_readw(chip, GCAP); 2417 gcap = azx_readw(chip, GCAP);
2323 snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap); 2418 snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap);
2324 2419
2325 /* ATI chips seems buggy about 64bit DMA addresses */ 2420 /* disable SB600 64bit support for safety */
2326 if (chip->driver_type == AZX_DRIVER_ATI) 2421 if ((chip->driver_type == AZX_DRIVER_ATI) ||
2327 gcap &= ~ICH6_GCAP_64OK; 2422 (chip->driver_type == AZX_DRIVER_ATIHDMI)) {
2423 struct pci_dev *p_smbus;
2424 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
2425 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
2426 NULL);
2427 if (p_smbus) {
2428 if (p_smbus->revision < 0x30)
2429 gcap &= ~ICH6_GCAP_64OK;
2430 pci_dev_put(p_smbus);
2431 }
2432 }
2328 2433
2329 /* allow 64bit DMA address if supported by H/W */ 2434 /* allow 64bit DMA address if supported by H/W */
2330 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64))) 2435 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
@@ -2460,15 +2565,32 @@ static int __devinit azx_probe(struct pci_dev *pci,
2460 return err; 2565 return err;
2461 } 2566 }
2462 2567
2568 /* set this here since it's referred in snd_hda_load_patch() */
2569 snd_card_set_dev(card, &pci->dev);
2570
2463 err = azx_create(card, pci, dev, pci_id->driver_data, &chip); 2571 err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
2464 if (err < 0) 2572 if (err < 0)
2465 goto out_free; 2573 goto out_free;
2466 card->private_data = chip; 2574 card->private_data = chip;
2467 2575
2468 /* create codec instances */ 2576 /* create codec instances */
2469 err = azx_codec_create(chip, model[dev], probe_only[dev]); 2577 err = azx_codec_create(chip, model[dev]);
2470 if (err < 0) 2578 if (err < 0)
2471 goto out_free; 2579 goto out_free;
2580#ifdef CONFIG_SND_HDA_PATCH_LOADER
2581 if (patch[dev]) {
2582 snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n",
2583 patch[dev]);
2584 err = snd_hda_load_patch(chip->bus, patch[dev]);
2585 if (err < 0)
2586 goto out_free;
2587 }
2588#endif
2589 if (!probe_only[dev]) {
2590 err = azx_codec_configure(chip);
2591 if (err < 0)
2592 goto out_free;
2593 }
2472 2594
2473 /* create PCM streams */ 2595 /* create PCM streams */
2474 err = snd_hda_build_pcms(chip->bus); 2596 err = snd_hda_build_pcms(chip->bus);
@@ -2480,8 +2602,6 @@ static int __devinit azx_probe(struct pci_dev *pci,
2480 if (err < 0) 2602 if (err < 0)
2481 goto out_free; 2603 goto out_free;
2482 2604
2483 snd_card_set_dev(card, &pci->dev);
2484
2485 err = snd_card_register(card); 2605 err = snd_card_register(card);
2486 if (err < 0) 2606 if (err < 0)
2487 goto out_free; 2607 goto out_free;
@@ -2583,11 +2703,15 @@ static struct pci_device_id azx_ids[] = {
2583 /* this entry seems still valid -- i.e. without emu20kx chip */ 2703 /* this entry seems still valid -- i.e. without emu20kx chip */
2584 { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_GENERIC }, 2704 { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_GENERIC },
2585#endif 2705#endif
2586 /* AMD Generic, PCI class code and Vendor ID for HD Audio */ 2706 /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
2587 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID), 2707 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
2588 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2708 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2589 .class_mask = 0xffffff, 2709 .class_mask = 0xffffff,
2590 .driver_data = AZX_DRIVER_GENERIC }, 2710 .driver_data = AZX_DRIVER_GENERIC },
2711 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
2712 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2713 .class_mask = 0xffffff,
2714 .driver_data = AZX_DRIVER_GENERIC },
2591 { 0, } 2715 { 0, }
2592}; 2716};
2593MODULE_DEVICE_TABLE(pci, azx_ids); 2717MODULE_DEVICE_TABLE(pci, azx_ids);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 83349013b4d..5f1dcc59002 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -99,7 +99,6 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
99int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 99int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
100 unsigned int *tlv, const char **slaves); 100 unsigned int *tlv, const char **slaves);
101int snd_hda_codec_reset(struct hda_codec *codec); 101int snd_hda_codec_reset(struct hda_codec *codec);
102int snd_hda_codec_configure(struct hda_codec *codec);
103 102
104/* amp value bits */ 103/* amp value bits */
105#define HDA_AMP_MUTE 0x80 104#define HDA_AMP_MUTE 0x80
@@ -408,6 +407,19 @@ static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
408 return codec->wcaps[nid - codec->start_nid]; 407 return codec->wcaps[nid - codec->start_nid];
409} 408}
410 409
410/* get the widget type from widget capability bits */
411#define get_wcaps_type(wcaps) (((wcaps) & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT)
412
413static inline unsigned int get_wcaps_channels(u32 wcaps)
414{
415 unsigned int chans;
416
417 chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
418 chans = ((chans << 1) | 1) + 1;
419
420 return chans;
421}
422
411u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction); 423u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
412int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 424int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
413 unsigned int caps); 425 unsigned int caps);
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 418c5d1bada..95f24e4729f 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -508,17 +508,14 @@ static void print_codec_info(struct snd_info_entry *entry,
508 unsigned int wid_caps = 508 unsigned int wid_caps =
509 snd_hda_param_read(codec, nid, 509 snd_hda_param_read(codec, nid,
510 AC_PAR_AUDIO_WIDGET_CAP); 510 AC_PAR_AUDIO_WIDGET_CAP);
511 unsigned int wid_type = 511 unsigned int wid_type = get_wcaps_type(wid_caps);
512 (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
513 hda_nid_t conn[HDA_MAX_CONNECTIONS]; 512 hda_nid_t conn[HDA_MAX_CONNECTIONS];
514 int conn_len = 0; 513 int conn_len = 0;
515 514
516 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid, 515 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
517 get_wid_type_name(wid_type), wid_caps); 516 get_wid_type_name(wid_type), wid_caps);
518 if (wid_caps & AC_WCAP_STEREO) { 517 if (wid_caps & AC_WCAP_STEREO) {
519 unsigned int chans; 518 unsigned int chans = get_wcaps_channels(wid_caps);
520 chans = (wid_caps & AC_WCAP_CHAN_CNT_EXT) >> 13;
521 chans = ((chans << 1) | 1) + 1;
522 if (chans == 2) 519 if (chans == 2)
523 snd_iprintf(buffer, " Stereo"); 520 snd_iprintf(buffer, " Stereo");
524 else 521 else
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 1988582d1ab..215e72a8711 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -2982,7 +2982,8 @@ static int patch_ad1988(struct hda_codec *codec)
2982 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST, 2982 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2983 ad1988_models, ad1988_cfg_tbl); 2983 ad1988_models, ad1988_cfg_tbl);
2984 if (board_config < 0) { 2984 if (board_config < 0) {
2985 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n"); 2985 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
2986 codec->chip_name);
2986 board_config = AD1988_AUTO; 2987 board_config = AD1988_AUTO;
2987 } 2988 }
2988 2989
@@ -3702,19 +3703,29 @@ static struct hda_amp_list ad1884a_loopbacks[] = {
3702 * Port F: Internal speakers 3703 * Port F: Internal speakers
3703 */ 3704 */
3704 3705
3705static struct hda_input_mux ad1884a_laptop_capture_source = { 3706static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3706 .num_items = 4, 3707 struct snd_ctl_elem_value *ucontrol)
3707 .items = { 3708{
3708 { "Mic", 0x0 }, /* port-B */ 3709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3709 { "Internal Mic", 0x1 }, /* port-C */ 3710 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3710 { "Dock Mic", 0x4 }, /* port-E */ 3711 int mute = (!ucontrol->value.integer.value[0] &&
3711 { "Mix", 0x3 }, 3712 !ucontrol->value.integer.value[1]);
3712 }, 3713 /* toggle GPIO1 according to the mute state */
3713}; 3714 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3715 mute ? 0x02 : 0x0);
3716 return ret;
3717}
3714 3718
3715static struct snd_kcontrol_new ad1884a_laptop_mixers[] = { 3719static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3716 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT), 3720 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3717 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT), 3721 {
3722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3723 .name = "Master Playback Switch",
3724 .info = snd_hda_mixer_amp_switch_info,
3725 .get = snd_hda_mixer_amp_switch_get,
3726 .put = ad1884a_mobile_master_sw_put,
3727 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3728 },
3718 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT), 3729 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3719 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT), 3730 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3720 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 3731 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
@@ -3729,26 +3740,20 @@ static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3729 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT), 3740 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3730 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3741 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3731 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 3742 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3732 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3733 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3734 {
3735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3736 /* The multiple "Capture Source" controls confuse alsamixer
3737 * So call somewhat different..
3738 */
3739 /* .name = "Capture Source", */
3740 .name = "Input Source",
3741 .count = 2,
3742 .info = ad198x_mux_enum_info,
3743 .get = ad198x_mux_enum_get,
3744 .put = ad198x_mux_enum_put,
3745 },
3746 { } /* end */ 3743 { } /* end */
3747}; 3744};
3748 3745
3749static struct snd_kcontrol_new ad1884a_mobile_mixers[] = { 3746static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3750 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT), 3747 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3751 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT), 3748 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3749 {
3750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3751 .name = "Master Playback Switch",
3752 .info = snd_hda_mixer_amp_switch_info,
3753 .get = snd_hda_mixer_amp_switch_get,
3754 .put = ad1884a_mobile_master_sw_put,
3755 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3756 },
3752 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT), 3757 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3753 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 3758 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3754 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT), 3759 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
@@ -3807,6 +3812,63 @@ static int ad1884a_hp_init(struct hda_codec *codec)
3807 return 0; 3812 return 0;
3808} 3813}
3809 3814
3815/* mute internal speaker if HP or docking HP is plugged */
3816static void ad1884a_laptop_automute(struct hda_codec *codec)
3817{
3818 unsigned int present;
3819
3820 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0);
3821 present &= AC_PINSENSE_PRESENCE;
3822 if (!present) {
3823 present = snd_hda_codec_read(codec, 0x12, 0,
3824 AC_VERB_GET_PIN_SENSE, 0);
3825 present &= AC_PINSENSE_PRESENCE;
3826 }
3827 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3828 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3829 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3830 present ? 0x00 : 0x02);
3831}
3832
3833/* switch to external mic if plugged */
3834static void ad1884a_laptop_automic(struct hda_codec *codec)
3835{
3836 unsigned int idx;
3837
3838 if (snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0) &
3839 AC_PINSENSE_PRESENCE)
3840 idx = 0;
3841 else if (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) &
3842 AC_PINSENSE_PRESENCE)
3843 idx = 4;
3844 else
3845 idx = 1;
3846 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
3847}
3848
3849/* unsolicited event for HP jack sensing */
3850static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
3851 unsigned int res)
3852{
3853 switch (res >> 26) {
3854 case AD1884A_HP_EVENT:
3855 ad1884a_laptop_automute(codec);
3856 break;
3857 case AD1884A_MIC_EVENT:
3858 ad1884a_laptop_automic(codec);
3859 break;
3860 }
3861}
3862
3863/* initialize jack-sensing, too */
3864static int ad1884a_laptop_init(struct hda_codec *codec)
3865{
3866 ad198x_init(codec);
3867 ad1884a_laptop_automute(codec);
3868 ad1884a_laptop_automic(codec);
3869 return 0;
3870}
3871
3810/* additional verbs for laptop model */ 3872/* additional verbs for laptop model */
3811static struct hda_verb ad1884a_laptop_verbs[] = { 3873static struct hda_verb ad1884a_laptop_verbs[] = {
3812 /* Port-A (HP) pin - always unmuted */ 3874 /* Port-A (HP) pin - always unmuted */
@@ -3814,18 +3876,28 @@ static struct hda_verb ad1884a_laptop_verbs[] = {
3814 /* Port-F (int speaker) mixer - route only from analog mixer */ 3876 /* Port-F (int speaker) mixer - route only from analog mixer */
3815 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 3877 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3816 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 3878 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3817 /* Port-F pin */ 3879 /* Port-F (int speaker) pin */
3818 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 3880 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3819 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3881 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3882 /* required for compaq 6530s/6531s speaker output */
3883 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3820 /* Port-C pin - internal mic-in */ 3884 /* Port-C pin - internal mic-in */
3821 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 3885 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3822 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */ 3886 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3823 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */ 3887 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3888 /* Port-D (docking line-out) pin - default unmuted */
3889 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3824 /* analog mix */ 3890 /* analog mix */
3825 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 3891 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3826 /* unsolicited event for pin-sense */ 3892 /* unsolicited event for pin-sense */
3827 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT}, 3893 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3894 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3828 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT}, 3895 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3896 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3897 /* allow to touch GPIO1 (for mute control) */
3898 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3899 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3900 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
3829 { } /* end */ 3901 { } /* end */
3830}; 3902};
3831 3903
@@ -3869,6 +3941,10 @@ static struct hda_verb ad1884a_mobile_verbs[] = {
3869 /* unsolicited event for pin-sense */ 3941 /* unsolicited event for pin-sense */
3870 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT}, 3942 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3871 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT}, 3943 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3944 /* allow to touch GPIO1 (for mute control) */
3945 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3946 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3947 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
3872 { } /* end */ 3948 { } /* end */
3873}; 3949};
3874 3950
@@ -3978,8 +4054,10 @@ static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3978 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP), 4054 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
3979 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE), 4055 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3980 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE), 4056 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
4057 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
3981 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP), 4058 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
3982 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP), 4059 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
4060 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
3983 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD), 4061 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3984 {} 4062 {}
3985}; 4063};
@@ -4029,9 +4107,8 @@ static int patch_ad1884a(struct hda_codec *codec)
4029 spec->mixers[0] = ad1884a_laptop_mixers; 4107 spec->mixers[0] = ad1884a_laptop_mixers;
4030 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs; 4108 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4031 spec->multiout.dig_out_nid = 0; 4109 spec->multiout.dig_out_nid = 0;
4032 spec->input_mux = &ad1884a_laptop_capture_source; 4110 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4033 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event; 4111 codec->patch_ops.init = ad1884a_laptop_init;
4034 codec->patch_ops.init = ad1884a_hp_init;
4035 /* set the upper-limit for mixer amp to 0dB for avoiding the 4112 /* set the upper-limit for mixer amp to 0dB for avoiding the
4036 * possible damage by overloading 4113 * possible damage by overloading
4037 */ 4114 */
diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c
index 233e4778bba..fb684f00156 100644
--- a/sound/pci/hda/patch_atihdmi.c
+++ b/sound/pci/hda/patch_atihdmi.c
@@ -141,8 +141,7 @@ static int atihdmi_build_pcms(struct hda_codec *codec)
141 /* FIXME: we must check ELD and change the PCM parameters dynamically 141 /* FIXME: we must check ELD and change the PCM parameters dynamically
142 */ 142 */
143 chans = get_wcaps(codec, CVT_NID); 143 chans = get_wcaps(codec, CVT_NID);
144 chans = (chans & AC_WCAP_CHAN_CNT_EXT) >> 13; 144 chans = get_wcaps_channels(chans);
145 chans = ((chans << 1) | 1) + 1;
146 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans; 145 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
147 146
148 return 0; 147 return 0;
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index 392d108c355..d08353d3bb7 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -459,8 +459,7 @@ static void parse_input(struct hda_codec *codec)
459 nid = codec->start_nid; 459 nid = codec->start_nid;
460 for (i = 0; i < codec->num_nodes; i++, nid++) { 460 for (i = 0; i < codec->num_nodes; i++, nid++) {
461 unsigned int wcaps = get_wcaps(codec, nid); 461 unsigned int wcaps = get_wcaps(codec, nid);
462 unsigned int type = (wcaps & AC_WCAP_TYPE) >> 462 unsigned int type = get_wcaps_type(wcaps);
463 AC_WCAP_TYPE_SHIFT;
464 if (type != AC_WID_AUD_IN) 463 if (type != AC_WID_AUD_IN)
465 continue; 464 continue;
466 if (snd_hda_get_connections(codec, nid, &pin, 1) != 1) 465 if (snd_hda_get_connections(codec, nid, &pin, 1) != 1)
@@ -510,7 +509,7 @@ static int ca0110_parse_auto_config(struct hda_codec *codec)
510} 509}
511 510
512 511
513int patch_ca0110(struct hda_codec *codec) 512static int patch_ca0110(struct hda_codec *codec)
514{ 513{
515 struct ca0110_spec *spec; 514 struct ca0110_spec *spec;
516 int err; 515 int err;
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
new file mode 100644
index 00000000000..8ba306856d3
--- /dev/null
+++ b/sound/pci/hda/patch_cirrus.c
@@ -0,0 +1,1194 @@
1/*
2 * HD audio interface patch for Cirrus Logic CS420x chip
3 *
4 * Copyright (c) 2009 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This driver is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/slab.h>
24#include <linux/pci.h>
25#include <sound/core.h>
26#include "hda_codec.h"
27#include "hda_local.h"
28
29/*
30 */
31
32struct cs_spec {
33 int board_config;
34 struct auto_pin_cfg autocfg;
35 struct hda_multi_out multiout;
36 struct snd_kcontrol *vmaster_sw;
37 struct snd_kcontrol *vmaster_vol;
38
39 hda_nid_t dac_nid[AUTO_CFG_MAX_OUTS];
40 hda_nid_t slave_dig_outs[2];
41
42 unsigned int input_idx[AUTO_PIN_LAST];
43 unsigned int capsrc_idx[AUTO_PIN_LAST];
44 hda_nid_t adc_nid[AUTO_PIN_LAST];
45 unsigned int adc_idx[AUTO_PIN_LAST];
46 unsigned int num_inputs;
47 unsigned int cur_input;
48 unsigned int automic_idx;
49 hda_nid_t cur_adc;
50 unsigned int cur_adc_stream_tag;
51 unsigned int cur_adc_format;
52 hda_nid_t dig_in;
53
54 struct hda_bind_ctls *capture_bind[2];
55
56 unsigned int gpio_mask;
57 unsigned int gpio_dir;
58 unsigned int gpio_data;
59
60 struct hda_pcm pcm_rec[2]; /* PCM information */
61
62 unsigned int hp_detect:1;
63 unsigned int mic_detect:1;
64};
65
66/* available models */
67enum {
68 CS420X_MBP55,
69 CS420X_AUTO,
70 CS420X_MODELS
71};
72
73/* Vendor-specific processing widget */
74#define CS420X_VENDOR_NID 0x11
75#define CS_DIG_OUT1_PIN_NID 0x10
76#define CS_DIG_OUT2_PIN_NID 0x15
77#define CS_DMIC1_PIN_NID 0x12
78#define CS_DMIC2_PIN_NID 0x0e
79
80/* coef indices */
81#define IDX_SPDIF_STAT 0x0000
82#define IDX_SPDIF_CTL 0x0001
83#define IDX_ADC_CFG 0x0002
84/* SZC bitmask, 4 modes below:
85 * 0 = immediate,
86 * 1 = digital immediate, analog zero-cross
87 * 2 = digtail & analog soft-ramp
88 * 3 = digital soft-ramp, analog zero-cross
89 */
90#define CS_COEF_ADC_SZC_MASK (3 << 0)
91#define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
92#define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
93/* PGA mode: 0 = differential, 1 = signle-ended */
94#define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
95#define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
96#define IDX_DAC_CFG 0x0003
97/* SZC bitmask, 4 modes below:
98 * 0 = Immediate
99 * 1 = zero-cross
100 * 2 = soft-ramp
101 * 3 = soft-ramp on zero-cross
102 */
103#define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
104#define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
105#define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
106
107#define IDX_BEEP_CFG 0x0004
108/* 0x0008 - test reg key */
109/* 0x0009 - 0x0014 -> 12 test regs */
110/* 0x0015 - visibility reg */
111
112
113static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
114{
115 snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
116 AC_VERB_SET_COEF_INDEX, idx);
117 return snd_hda_codec_read(codec, CS420X_VENDOR_NID, 0,
118 AC_VERB_GET_PROC_COEF, 0);
119}
120
121static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
122 unsigned int coef)
123{
124 snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
125 AC_VERB_SET_COEF_INDEX, idx);
126 snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
127 AC_VERB_SET_PROC_COEF, coef);
128}
129
130
131#define HP_EVENT 1
132#define MIC_EVENT 2
133
134/*
135 * PCM callbacks
136 */
137static int cs_playback_pcm_open(struct hda_pcm_stream *hinfo,
138 struct hda_codec *codec,
139 struct snd_pcm_substream *substream)
140{
141 struct cs_spec *spec = codec->spec;
142 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
143 hinfo);
144}
145
146static int cs_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
147 struct hda_codec *codec,
148 unsigned int stream_tag,
149 unsigned int format,
150 struct snd_pcm_substream *substream)
151{
152 struct cs_spec *spec = codec->spec;
153 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
154 stream_tag, format, substream);
155}
156
157static int cs_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
158 struct hda_codec *codec,
159 struct snd_pcm_substream *substream)
160{
161 struct cs_spec *spec = codec->spec;
162 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
163}
164
165/*
166 * Digital out
167 */
168static int cs_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
170 struct snd_pcm_substream *substream)
171{
172 struct cs_spec *spec = codec->spec;
173 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
174}
175
176static int cs_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
177 struct hda_codec *codec,
178 struct snd_pcm_substream *substream)
179{
180 struct cs_spec *spec = codec->spec;
181 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
182}
183
184static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
185 struct hda_codec *codec,
186 unsigned int stream_tag,
187 unsigned int format,
188 struct snd_pcm_substream *substream)
189{
190 struct cs_spec *spec = codec->spec;
191 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
192 format, substream);
193}
194
195static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
196 struct hda_codec *codec,
197 struct snd_pcm_substream *substream)
198{
199 struct cs_spec *spec = codec->spec;
200 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
201}
202
203/*
204 * Analog capture
205 */
206static int cs_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
207 struct hda_codec *codec,
208 unsigned int stream_tag,
209 unsigned int format,
210 struct snd_pcm_substream *substream)
211{
212 struct cs_spec *spec = codec->spec;
213 spec->cur_adc = spec->adc_nid[spec->cur_input];
214 spec->cur_adc_stream_tag = stream_tag;
215 spec->cur_adc_format = format;
216 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
217 return 0;
218}
219
220static int cs_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
221 struct hda_codec *codec,
222 struct snd_pcm_substream *substream)
223{
224 struct cs_spec *spec = codec->spec;
225 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
226 spec->cur_adc = 0;
227 return 0;
228}
229
230/*
231 */
232static struct hda_pcm_stream cs_pcm_analog_playback = {
233 .substreams = 1,
234 .channels_min = 2,
235 .channels_max = 2,
236 .ops = {
237 .open = cs_playback_pcm_open,
238 .prepare = cs_playback_pcm_prepare,
239 .cleanup = cs_playback_pcm_cleanup
240 },
241};
242
243static struct hda_pcm_stream cs_pcm_analog_capture = {
244 .substreams = 1,
245 .channels_min = 2,
246 .channels_max = 2,
247 .ops = {
248 .prepare = cs_capture_pcm_prepare,
249 .cleanup = cs_capture_pcm_cleanup
250 },
251};
252
253static struct hda_pcm_stream cs_pcm_digital_playback = {
254 .substreams = 1,
255 .channels_min = 2,
256 .channels_max = 2,
257 .ops = {
258 .open = cs_dig_playback_pcm_open,
259 .close = cs_dig_playback_pcm_close,
260 .prepare = cs_dig_playback_pcm_prepare,
261 .cleanup = cs_dig_playback_pcm_cleanup
262 },
263};
264
265static struct hda_pcm_stream cs_pcm_digital_capture = {
266 .substreams = 1,
267 .channels_min = 2,
268 .channels_max = 2,
269};
270
271static int cs_build_pcms(struct hda_codec *codec)
272{
273 struct cs_spec *spec = codec->spec;
274 struct hda_pcm *info = spec->pcm_rec;
275
276 codec->pcm_info = info;
277 codec->num_pcms = 0;
278
279 info->name = "Cirrus Analog";
280 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cs_pcm_analog_playback;
281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0];
282 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
283 spec->multiout.max_channels;
284 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture;
285 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
286 spec->adc_nid[spec->cur_input];
287 codec->num_pcms++;
288
289 if (!spec->multiout.dig_out_nid && !spec->dig_in)
290 return 0;
291
292 info++;
293 info->name = "Cirrus Digital";
294 info->pcm_type = spec->autocfg.dig_out_type[0];
295 if (!info->pcm_type)
296 info->pcm_type = HDA_PCM_TYPE_SPDIF;
297 if (spec->multiout.dig_out_nid) {
298 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
299 cs_pcm_digital_playback;
300 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
301 spec->multiout.dig_out_nid;
302 }
303 if (spec->dig_in) {
304 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
305 cs_pcm_digital_capture;
306 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
307 }
308 codec->num_pcms++;
309
310 return 0;
311}
312
313/*
314 * parse codec topology
315 */
316
317static hda_nid_t get_dac(struct hda_codec *codec, hda_nid_t pin)
318{
319 hda_nid_t dac;
320 if (!pin)
321 return 0;
322 if (snd_hda_get_connections(codec, pin, &dac, 1) != 1)
323 return 0;
324 return dac;
325}
326
327static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
328{
329 struct cs_spec *spec = codec->spec;
330 struct auto_pin_cfg *cfg = &spec->autocfg;
331 hda_nid_t pin = cfg->input_pins[idx];
332 unsigned int val = snd_hda_query_pin_caps(codec, pin);
333 if (!(val & AC_PINCAP_PRES_DETECT))
334 return 0;
335 val = snd_hda_codec_get_pincfg(codec, pin);
336 return (get_defcfg_connect(val) == AC_JACK_PORT_COMPLEX);
337}
338
339static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
340 unsigned int *idxp)
341{
342 int i;
343 hda_nid_t nid;
344
345 nid = codec->start_nid;
346 for (i = 0; i < codec->num_nodes; i++, nid++) {
347 hda_nid_t pins[2];
348 unsigned int type;
349 int j, nums;
350 type = (get_wcaps(codec, nid) & AC_WCAP_TYPE)
351 >> AC_WCAP_TYPE_SHIFT;
352 if (type != AC_WID_AUD_IN)
353 continue;
354 nums = snd_hda_get_connections(codec, nid, pins,
355 ARRAY_SIZE(pins));
356 if (nums <= 0)
357 continue;
358 for (j = 0; j < nums; j++) {
359 if (pins[j] == pin) {
360 *idxp = j;
361 return nid;
362 }
363 }
364 }
365 return 0;
366}
367
368static int is_active_pin(struct hda_codec *codec, hda_nid_t nid)
369{
370 unsigned int val;
371 val = snd_hda_codec_get_pincfg(codec, nid);
372 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
373}
374
375static int parse_output(struct hda_codec *codec)
376{
377 struct cs_spec *spec = codec->spec;
378 struct auto_pin_cfg *cfg = &spec->autocfg;
379 int i, extra_nids;
380 hda_nid_t dac;
381
382 for (i = 0; i < cfg->line_outs; i++) {
383 dac = get_dac(codec, cfg->line_out_pins[i]);
384 if (!dac)
385 break;
386 spec->dac_nid[i] = dac;
387 }
388 spec->multiout.num_dacs = i;
389 spec->multiout.dac_nids = spec->dac_nid;
390 spec->multiout.max_channels = i * 2;
391
392 /* add HP and speakers */
393 extra_nids = 0;
394 for (i = 0; i < cfg->hp_outs; i++) {
395 dac = get_dac(codec, cfg->hp_pins[i]);
396 if (!dac)
397 break;
398 if (!i)
399 spec->multiout.hp_nid = dac;
400 else
401 spec->multiout.extra_out_nid[extra_nids++] = dac;
402 }
403 for (i = 0; i < cfg->speaker_outs; i++) {
404 dac = get_dac(codec, cfg->speaker_pins[i]);
405 if (!dac)
406 break;
407 spec->multiout.extra_out_nid[extra_nids++] = dac;
408 }
409
410 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
411 cfg->speaker_outs = cfg->line_outs;
412 memcpy(cfg->speaker_pins, cfg->line_out_pins,
413 sizeof(cfg->speaker_pins));
414 cfg->line_outs = 0;
415 }
416
417 return 0;
418}
419
420static int parse_input(struct hda_codec *codec)
421{
422 struct cs_spec *spec = codec->spec;
423 struct auto_pin_cfg *cfg = &spec->autocfg;
424 int i;
425
426 for (i = 0; i < AUTO_PIN_LAST; i++) {
427 hda_nid_t pin = cfg->input_pins[i];
428 if (!pin)
429 continue;
430 spec->input_idx[spec->num_inputs] = i;
431 spec->capsrc_idx[i] = spec->num_inputs++;
432 spec->cur_input = i;
433 spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]);
434 }
435 if (!spec->num_inputs)
436 return 0;
437
438 /* check whether the automatic mic switch is available */
439 if (spec->num_inputs == 2 &&
440 spec->adc_nid[AUTO_PIN_MIC] && spec->adc_nid[AUTO_PIN_FRONT_MIC]) {
441 if (is_ext_mic(codec, cfg->input_pins[AUTO_PIN_FRONT_MIC])) {
442 if (!is_ext_mic(codec, cfg->input_pins[AUTO_PIN_MIC])) {
443 spec->mic_detect = 1;
444 spec->automic_idx = AUTO_PIN_FRONT_MIC;
445 }
446 } else {
447 if (is_ext_mic(codec, cfg->input_pins[AUTO_PIN_MIC])) {
448 spec->mic_detect = 1;
449 spec->automic_idx = AUTO_PIN_MIC;
450 }
451 }
452 }
453 return 0;
454}
455
456
457static int parse_digital_output(struct hda_codec *codec)
458{
459 struct cs_spec *spec = codec->spec;
460 struct auto_pin_cfg *cfg = &spec->autocfg;
461 hda_nid_t nid;
462
463 if (!cfg->dig_outs)
464 return 0;
465 if (snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) < 1)
466 return 0;
467 spec->multiout.dig_out_nid = nid;
468 spec->multiout.share_spdif = 1;
469 if (cfg->dig_outs > 1 &&
470 snd_hda_get_connections(codec, cfg->dig_out_pins[1], &nid, 1) > 0) {
471 spec->slave_dig_outs[0] = nid;
472 codec->slave_dig_outs = spec->slave_dig_outs;
473 }
474 return 0;
475}
476
477static int parse_digital_input(struct hda_codec *codec)
478{
479 struct cs_spec *spec = codec->spec;
480 struct auto_pin_cfg *cfg = &spec->autocfg;
481 int idx;
482
483 if (cfg->dig_in_pin)
484 spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx);
485 return 0;
486}
487
488/*
489 * create mixer controls
490 */
491
492static const char *dir_sfx[2] = { "Playback", "Capture" };
493
494static int add_mute(struct hda_codec *codec, const char *name, int index,
495 unsigned int pval, int dir, struct snd_kcontrol **kctlp)
496{
497 char tmp[44];
498 struct snd_kcontrol_new knew =
499 HDA_CODEC_MUTE_IDX(tmp, index, 0, 0, HDA_OUTPUT);
500 knew.private_value = pval;
501 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]);
502 *kctlp = snd_ctl_new1(&knew, codec);
503 return snd_hda_ctl_add(codec, *kctlp);
504}
505
506static int add_volume(struct hda_codec *codec, const char *name,
507 int index, unsigned int pval, int dir,
508 struct snd_kcontrol **kctlp)
509{
510 char tmp[32];
511 struct snd_kcontrol_new knew =
512 HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT);
513 knew.private_value = pval;
514 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
515 *kctlp = snd_ctl_new1(&knew, codec);
516 return snd_hda_ctl_add(codec, *kctlp);
517}
518
519static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
520{
521 unsigned int caps;
522
523 /* set the upper-limit for mixer amp to 0dB */
524 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
525 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
526 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
527 << AC_AMPCAP_NUM_STEPS_SHIFT;
528 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
529}
530
531static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
532{
533 struct cs_spec *spec = codec->spec;
534 unsigned int tlv[4];
535 int err;
536
537 spec->vmaster_sw =
538 snd_ctl_make_virtual_master("Master Playback Switch", NULL);
539 err = snd_hda_ctl_add(codec, spec->vmaster_sw);
540 if (err < 0)
541 return err;
542
543 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
544 spec->vmaster_vol =
545 snd_ctl_make_virtual_master("Master Playback Volume", tlv);
546 err = snd_hda_ctl_add(codec, spec->vmaster_vol);
547 if (err < 0)
548 return err;
549 return 0;
550}
551
552static int add_output(struct hda_codec *codec, hda_nid_t dac, int idx,
553 int num_ctls, int type)
554{
555 struct cs_spec *spec = codec->spec;
556 const char *name;
557 int err, index;
558 struct snd_kcontrol *kctl;
559 static char *speakers[] = {
560 "Front Speaker", "Surround Speaker", "Bass Speaker"
561 };
562 static char *line_outs[] = {
563 "Front Line-Out", "Surround Line-Out", "Bass Line-Out"
564 };
565
566 fix_volume_caps(codec, dac);
567 if (!spec->vmaster_sw) {
568 err = add_vmaster(codec, dac);
569 if (err < 0)
570 return err;
571 }
572
573 index = 0;
574 switch (type) {
575 case AUTO_PIN_HP_OUT:
576 name = "Headphone";
577 index = idx;
578 break;
579 case AUTO_PIN_SPEAKER_OUT:
580 if (num_ctls > 1)
581 name = speakers[idx];
582 else
583 name = "Speaker";
584 break;
585 default:
586 if (num_ctls > 1)
587 name = line_outs[idx];
588 else
589 name = "Line-Out";
590 break;
591 }
592
593 err = add_mute(codec, name, index,
594 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
595 if (err < 0)
596 return err;
597 err = snd_ctl_add_slave(spec->vmaster_sw, kctl);
598 if (err < 0)
599 return err;
600
601 err = add_volume(codec, name, index,
602 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
603 if (err < 0)
604 return err;
605 err = snd_ctl_add_slave(spec->vmaster_vol, kctl);
606 if (err < 0)
607 return err;
608
609 return 0;
610}
611
612static int build_output(struct hda_codec *codec)
613{
614 struct cs_spec *spec = codec->spec;
615 struct auto_pin_cfg *cfg = &spec->autocfg;
616 int i, err;
617
618 for (i = 0; i < cfg->line_outs; i++) {
619 err = add_output(codec, get_dac(codec, cfg->line_out_pins[i]),
620 i, cfg->line_outs, cfg->line_out_type);
621 if (err < 0)
622 return err;
623 }
624 for (i = 0; i < cfg->hp_outs; i++) {
625 err = add_output(codec, get_dac(codec, cfg->hp_pins[i]),
626 i, cfg->hp_outs, AUTO_PIN_HP_OUT);
627 if (err < 0)
628 return err;
629 }
630 for (i = 0; i < cfg->speaker_outs; i++) {
631 err = add_output(codec, get_dac(codec, cfg->speaker_pins[i]),
632 i, cfg->speaker_outs, AUTO_PIN_SPEAKER_OUT);
633 if (err < 0)
634 return err;
635 }
636 return 0;
637}
638
639/*
640 */
641
642static struct snd_kcontrol_new cs_capture_ctls[] = {
643 HDA_BIND_SW("Capture Switch", 0),
644 HDA_BIND_VOL("Capture Volume", 0),
645};
646
647static int change_cur_input(struct hda_codec *codec, unsigned int idx,
648 int force)
649{
650 struct cs_spec *spec = codec->spec;
651
652 if (spec->cur_input == idx && !force)
653 return 0;
654 if (spec->cur_adc && spec->cur_adc != spec->adc_nid[idx]) {
655 /* stream is running, let's swap the current ADC */
656 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
657 spec->cur_adc = spec->adc_nid[idx];
658 snd_hda_codec_setup_stream(codec, spec->cur_adc,
659 spec->cur_adc_stream_tag, 0,
660 spec->cur_adc_format);
661 }
662 snd_hda_codec_write(codec, spec->cur_adc, 0,
663 AC_VERB_SET_CONNECT_SEL,
664 spec->adc_idx[idx]);
665 spec->cur_input = idx;
666 return 1;
667}
668
669static int cs_capture_source_info(struct snd_kcontrol *kcontrol,
670 struct snd_ctl_elem_info *uinfo)
671{
672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
673 struct cs_spec *spec = codec->spec;
674 unsigned int idx;
675
676 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
677 uinfo->count = 1;
678 uinfo->value.enumerated.items = spec->num_inputs;
679 if (uinfo->value.enumerated.item >= spec->num_inputs)
680 uinfo->value.enumerated.item = spec->num_inputs - 1;
681 idx = spec->input_idx[uinfo->value.enumerated.item];
682 strcpy(uinfo->value.enumerated.name, auto_pin_cfg_labels[idx]);
683 return 0;
684}
685
686static int cs_capture_source_get(struct snd_kcontrol *kcontrol,
687 struct snd_ctl_elem_value *ucontrol)
688{
689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
690 struct cs_spec *spec = codec->spec;
691 ucontrol->value.enumerated.item[0] = spec->capsrc_idx[spec->cur_input];
692 return 0;
693}
694
695static int cs_capture_source_put(struct snd_kcontrol *kcontrol,
696 struct snd_ctl_elem_value *ucontrol)
697{
698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
699 struct cs_spec *spec = codec->spec;
700 unsigned int idx = ucontrol->value.enumerated.item[0];
701
702 if (idx >= spec->num_inputs)
703 return -EINVAL;
704 idx = spec->input_idx[idx];
705 return change_cur_input(codec, idx, 0);
706}
707
708static struct snd_kcontrol_new cs_capture_source = {
709 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
710 .name = "Capture Source",
711 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
712 .info = cs_capture_source_info,
713 .get = cs_capture_source_get,
714 .put = cs_capture_source_put,
715};
716
717static struct hda_bind_ctls *make_bind_capture(struct hda_codec *codec,
718 struct hda_ctl_ops *ops)
719{
720 struct cs_spec *spec = codec->spec;
721 struct hda_bind_ctls *bind;
722 int i, n;
723
724 bind = kzalloc(sizeof(*bind) + sizeof(long) * (spec->num_inputs + 1),
725 GFP_KERNEL);
726 if (!bind)
727 return NULL;
728 bind->ops = ops;
729 n = 0;
730 for (i = 0; i < AUTO_PIN_LAST; i++) {
731 if (!spec->adc_nid[i])
732 continue;
733 bind->values[n++] =
734 HDA_COMPOSE_AMP_VAL(spec->adc_nid[i], 3,
735 spec->adc_idx[i], HDA_INPUT);
736 }
737 return bind;
738}
739
740static int build_input(struct hda_codec *codec)
741{
742 struct cs_spec *spec = codec->spec;
743 int i, err;
744
745 if (!spec->num_inputs)
746 return 0;
747
748 /* make bind-capture */
749 spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw);
750 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
751 for (i = 0; i < 2; i++) {
752 struct snd_kcontrol *kctl;
753 if (!spec->capture_bind[i])
754 return -ENOMEM;
755 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
756 if (!kctl)
757 return -ENOMEM;
758 kctl->private_value = (long)spec->capture_bind[i];
759 err = snd_hda_ctl_add(codec, kctl);
760 if (err < 0)
761 return err;
762 }
763
764 if (spec->num_inputs > 1 && !spec->mic_detect) {
765 err = snd_hda_ctl_add(codec,
766 snd_ctl_new1(&cs_capture_source, codec));
767 if (err < 0)
768 return err;
769 }
770
771 return 0;
772}
773
774/*
775 */
776
777static int build_digital_output(struct hda_codec *codec)
778{
779 struct cs_spec *spec = codec->spec;
780 int err;
781
782 if (!spec->multiout.dig_out_nid)
783 return 0;
784
785 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
786 if (err < 0)
787 return err;
788 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
789 if (err < 0)
790 return err;
791 return 0;
792}
793
794static int build_digital_input(struct hda_codec *codec)
795{
796 struct cs_spec *spec = codec->spec;
797 if (spec->dig_in)
798 return snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
799 return 0;
800}
801
802/*
803 * auto-mute and auto-mic switching
804 */
805
806static void cs_automute(struct hda_codec *codec)
807{
808 struct cs_spec *spec = codec->spec;
809 struct auto_pin_cfg *cfg = &spec->autocfg;
810 unsigned int caps, present, hp_present;
811 hda_nid_t nid;
812 int i;
813
814 hp_present = 0;
815 for (i = 0; i < cfg->hp_outs; i++) {
816 nid = cfg->hp_pins[i];
817 caps = snd_hda_query_pin_caps(codec, nid);
818 if (!(caps & AC_PINCAP_PRES_DETECT))
819 continue;
820 if (caps & AC_PINCAP_TRIG_REQ)
821 snd_hda_codec_read(codec, nid, 0,
822 AC_VERB_SET_PIN_SENSE, 0);
823 present = snd_hda_codec_read(codec, nid, 0,
824 AC_VERB_GET_PIN_SENSE, 0);
825 hp_present |= (present & AC_PINSENSE_PRESENCE) != 0;
826 if (hp_present)
827 break;
828 }
829 for (i = 0; i < cfg->speaker_outs; i++) {
830 nid = cfg->speaker_pins[i];
831 snd_hda_codec_write(codec, nid, 0,
832 AC_VERB_SET_PIN_WIDGET_CONTROL,
833 hp_present ? 0 : PIN_OUT);
834 }
835 if (spec->board_config == CS420X_MBP55) {
836 unsigned int gpio = hp_present ? 0x02 : 0x08;
837 snd_hda_codec_write(codec, 0x01, 0,
838 AC_VERB_SET_GPIO_DATA, gpio);
839 }
840}
841
842static void cs_automic(struct hda_codec *codec)
843{
844 struct cs_spec *spec = codec->spec;
845 struct auto_pin_cfg *cfg = &spec->autocfg;
846 hda_nid_t nid;
847 unsigned int caps, present;
848
849 nid = cfg->input_pins[spec->automic_idx];
850 caps = snd_hda_query_pin_caps(codec, nid);
851 if (caps & AC_PINCAP_TRIG_REQ)
852 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
853 present = snd_hda_codec_read(codec, nid, 0,
854 AC_VERB_GET_PIN_SENSE, 0);
855 if (present & AC_PINSENSE_PRESENCE)
856 change_cur_input(codec, spec->automic_idx, 0);
857 else {
858 unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ?
859 AUTO_PIN_FRONT_MIC : AUTO_PIN_MIC;
860 change_cur_input(codec, imic, 0);
861 }
862}
863
864/*
865 */
866
867static void init_output(struct hda_codec *codec)
868{
869 struct cs_spec *spec = codec->spec;
870 struct auto_pin_cfg *cfg = &spec->autocfg;
871 int i;
872
873 /* mute first */
874 for (i = 0; i < spec->multiout.num_dacs; i++)
875 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
876 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
877 if (spec->multiout.hp_nid)
878 snd_hda_codec_write(codec, spec->multiout.hp_nid, 0,
879 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
880 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
881 if (!spec->multiout.extra_out_nid[i])
882 break;
883 snd_hda_codec_write(codec, spec->multiout.extra_out_nid[i], 0,
884 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
885 }
886
887 /* set appropriate pin controls */
888 for (i = 0; i < cfg->line_outs; i++)
889 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
890 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
891 for (i = 0; i < cfg->hp_outs; i++) {
892 hda_nid_t nid = cfg->hp_pins[i];
893 snd_hda_codec_write(codec, nid, 0,
894 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
895 if (!cfg->speaker_outs)
896 continue;
897 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
898 snd_hda_codec_write(codec, nid, 0,
899 AC_VERB_SET_UNSOLICITED_ENABLE,
900 AC_USRSP_EN | HP_EVENT);
901 spec->hp_detect = 1;
902 }
903 }
904 for (i = 0; i < cfg->speaker_outs; i++)
905 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
906 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
907 if (spec->hp_detect)
908 cs_automute(codec);
909}
910
911static void init_input(struct hda_codec *codec)
912{
913 struct cs_spec *spec = codec->spec;
914 struct auto_pin_cfg *cfg = &spec->autocfg;
915 unsigned int coef;
916 int i;
917
918 for (i = 0; i < AUTO_PIN_LAST; i++) {
919 unsigned int ctl;
920 hda_nid_t pin = cfg->input_pins[i];
921 if (!pin || !spec->adc_nid[i])
922 continue;
923 /* set appropriate pin control and mute first */
924 ctl = PIN_IN;
925 if (i <= AUTO_PIN_FRONT_MIC) {
926 unsigned int caps = snd_hda_query_pin_caps(codec, pin);
927 caps >>= AC_PINCAP_VREF_SHIFT;
928 if (caps & AC_PINCAP_VREF_80)
929 ctl = PIN_VREF80;
930 }
931 snd_hda_codec_write(codec, pin, 0,
932 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
933 snd_hda_codec_write(codec, spec->adc_nid[i], 0,
934 AC_VERB_SET_AMP_GAIN_MUTE,
935 AMP_IN_MUTE(spec->adc_idx[i]));
936 if (spec->mic_detect && spec->automic_idx == i)
937 snd_hda_codec_write(codec, pin, 0,
938 AC_VERB_SET_UNSOLICITED_ENABLE,
939 AC_USRSP_EN | MIC_EVENT);
940 }
941 change_cur_input(codec, spec->cur_input, 1);
942 if (spec->mic_detect)
943 cs_automic(codec);
944
945 coef = 0x000a; /* ADC1/2 - Digital and Analog Soft Ramp */
946 if (is_active_pin(codec, CS_DMIC2_PIN_NID))
947 coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */
948 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
949 coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0
950 * No effect if SPDIF_OUT2 is slected in
951 * IDX_SPDIF_CTL.
952 */
953 cs_vendor_coef_set(codec, IDX_ADC_CFG, coef);
954}
955
956static struct hda_verb cs_coef_init_verbs[] = {
957 {0x11, AC_VERB_SET_PROC_STATE, 1},
958 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
959 {0x11, AC_VERB_SET_PROC_COEF,
960 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
961 | 0x0040 /* Mute DACs on FIFO error */
962 | 0x1000 /* Enable DACs High Pass Filter */
963 | 0x0400 /* Disable Coefficient Auto increment */
964 )},
965 /* Beep */
966 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
967 {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */
968
969 {} /* terminator */
970};
971
972/* SPDIF setup */
973static void init_digital(struct hda_codec *codec)
974{
975 unsigned int coef;
976
977 coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
978 coef |= 0x0008; /* Replace with mute on error */
979 if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID))
980 coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
981 * SPDIF_OUT2 is shared with GPIO1 and
982 * DMIC_SDA2.
983 */
984 cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef);
985}
986
987static int cs_init(struct hda_codec *codec)
988{
989 struct cs_spec *spec = codec->spec;
990
991 snd_hda_sequence_write(codec, cs_coef_init_verbs);
992
993 if (spec->gpio_mask) {
994 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
995 spec->gpio_mask);
996 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
997 spec->gpio_dir);
998 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
999 spec->gpio_data);
1000 }
1001
1002 init_output(codec);
1003 init_input(codec);
1004 init_digital(codec);
1005 return 0;
1006}
1007
1008static int cs_build_controls(struct hda_codec *codec)
1009{
1010 int err;
1011
1012 err = build_output(codec);
1013 if (err < 0)
1014 return err;
1015 err = build_input(codec);
1016 if (err < 0)
1017 return err;
1018 err = build_digital_output(codec);
1019 if (err < 0)
1020 return err;
1021 err = build_digital_input(codec);
1022 if (err < 0)
1023 return err;
1024 return cs_init(codec);
1025}
1026
1027static void cs_free(struct hda_codec *codec)
1028{
1029 struct cs_spec *spec = codec->spec;
1030 kfree(spec->capture_bind[0]);
1031 kfree(spec->capture_bind[1]);
1032 kfree(codec->spec);
1033}
1034
1035static void cs_unsol_event(struct hda_codec *codec, unsigned int res)
1036{
1037 switch ((res >> 26) & 0x7f) {
1038 case HP_EVENT:
1039 cs_automute(codec);
1040 break;
1041 case MIC_EVENT:
1042 cs_automic(codec);
1043 break;
1044 }
1045}
1046
1047static struct hda_codec_ops cs_patch_ops = {
1048 .build_controls = cs_build_controls,
1049 .build_pcms = cs_build_pcms,
1050 .init = cs_init,
1051 .free = cs_free,
1052 .unsol_event = cs_unsol_event,
1053};
1054
1055static int cs_parse_auto_config(struct hda_codec *codec)
1056{
1057 struct cs_spec *spec = codec->spec;
1058 int err;
1059
1060 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1061 if (err < 0)
1062 return err;
1063
1064 err = parse_output(codec);
1065 if (err < 0)
1066 return err;
1067 err = parse_input(codec);
1068 if (err < 0)
1069 return err;
1070 err = parse_digital_output(codec);
1071 if (err < 0)
1072 return err;
1073 err = parse_digital_input(codec);
1074 if (err < 0)
1075 return err;
1076 return 0;
1077}
1078
1079static const char *cs420x_models[CS420X_MODELS] = {
1080 [CS420X_MBP55] = "mbp55",
1081 [CS420X_AUTO] = "auto",
1082};
1083
1084
1085static struct snd_pci_quirk cs420x_cfg_tbl[] = {
1086 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
1087 {} /* terminator */
1088};
1089
1090struct cs_pincfg {
1091 hda_nid_t nid;
1092 u32 val;
1093};
1094
1095static struct cs_pincfg mbp55_pincfgs[] = {
1096 { 0x09, 0x012b4030 },
1097 { 0x0a, 0x90100121 },
1098 { 0x0b, 0x90100120 },
1099 { 0x0c, 0x400000f0 },
1100 { 0x0d, 0x90a00110 },
1101 { 0x0e, 0x400000f0 },
1102 { 0x0f, 0x400000f0 },
1103 { 0x10, 0x014be040 },
1104 { 0x12, 0x400000f0 },
1105 { 0x15, 0x400000f0 },
1106 {} /* terminator */
1107};
1108
1109static struct cs_pincfg *cs_pincfgs[CS420X_MODELS] = {
1110 [CS420X_MBP55] = mbp55_pincfgs,
1111};
1112
1113static void fix_pincfg(struct hda_codec *codec, int model)
1114{
1115 const struct cs_pincfg *cfg = cs_pincfgs[model];
1116 if (!cfg)
1117 return;
1118 for (; cfg->nid; cfg++)
1119 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1120}
1121
1122
1123static int patch_cs420x(struct hda_codec *codec)
1124{
1125 struct cs_spec *spec;
1126 int err;
1127
1128 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1129 if (!spec)
1130 return -ENOMEM;
1131 codec->spec = spec;
1132
1133 spec->board_config =
1134 snd_hda_check_board_config(codec, CS420X_MODELS,
1135 cs420x_models, cs420x_cfg_tbl);
1136 if (spec->board_config >= 0)
1137 fix_pincfg(codec, spec->board_config);
1138
1139 switch (spec->board_config) {
1140 case CS420X_MBP55:
1141 /* GPIO1 = headphones */
1142 /* GPIO3 = speakers */
1143 spec->gpio_mask = 0x0a;
1144 spec->gpio_dir = 0x0a;
1145 break;
1146 }
1147
1148 err = cs_parse_auto_config(codec);
1149 if (err < 0)
1150 goto error;
1151
1152 codec->patch_ops = cs_patch_ops;
1153
1154 return 0;
1155
1156 error:
1157 kfree(codec->spec);
1158 codec->spec = NULL;
1159 return err;
1160}
1161
1162
1163/*
1164 * patch entries
1165 */
1166static struct hda_codec_preset snd_hda_preset_cirrus[] = {
1167 { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x },
1168 { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x },
1169 {} /* terminator */
1170};
1171
1172MODULE_ALIAS("snd-hda-codec-id:10134206");
1173MODULE_ALIAS("snd-hda-codec-id:10134207");
1174
1175MODULE_LICENSE("GPL");
1176MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1177
1178static struct hda_codec_preset_list cirrus_list = {
1179 .preset = snd_hda_preset_cirrus,
1180 .owner = THIS_MODULE,
1181};
1182
1183static int __init patch_cirrus_init(void)
1184{
1185 return snd_hda_add_codec_preset(&cirrus_list);
1186}
1187
1188static void __exit patch_cirrus_exit(void)
1189{
1190 snd_hda_delete_codec_preset(&cirrus_list);
1191}
1192
1193module_init(patch_cirrus_init)
1194module_exit(patch_cirrus_exit)
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index c921264bbd7..780e1a72114 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -635,7 +635,8 @@ static int patch_cmi9880(struct hda_codec *codec)
635 cmi9880_models, 635 cmi9880_models,
636 cmi9880_cfg_tbl); 636 cmi9880_cfg_tbl);
637 if (spec->board_config < 0) { 637 if (spec->board_config < 0) {
638 snd_printdd(KERN_INFO "hda_codec: Unknown model for CMI9880\n"); 638 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
639 codec->chip_name);
639 spec->board_config = CMI_AUTO; /* try everything */ 640 spec->board_config = CMI_AUTO; /* try everything */
640 } 641 }
641 642
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index ac868c59f9e..9d899eda44d 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -108,6 +108,8 @@ struct conexant_spec {
108 struct hda_input_mux private_imux; 108 struct hda_input_mux private_imux;
109 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 109 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
110 110
111 unsigned int dell_automute;
112 unsigned int port_d_mode;
111}; 113};
112 114
113static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 115static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
@@ -1908,6 +1910,480 @@ static int patch_cxt5051(struct hda_codec *codec)
1908 return 0; 1910 return 0;
1909} 1911}
1910 1912
1913/* Conexant 5066 specific */
1914
1915static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1916static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1917static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1918#define CXT5066_SPDIF_OUT 0x21
1919
1920static struct hda_channel_mode cxt5066_modes[1] = {
1921 { 2, NULL },
1922};
1923
1924static void cxt5066_update_speaker(struct hda_codec *codec)
1925{
1926 struct conexant_spec *spec = codec->spec;
1927 unsigned int pinctl;
1928
1929 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
1930 spec->hp_present);
1931
1932 /* Port A (HP) */
1933 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
1934 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1935 pinctl);
1936
1937 /* Port D (HP/LO) */
1938 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
1939 ? spec->port_d_mode : 0;
1940 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1941 pinctl);
1942
1943 /* CLASS_D AMP */
1944 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1945 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1946 pinctl);
1947
1948 if (spec->dell_automute) {
1949 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
1950 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
1951 ? PIN_OUT : 0;
1952 snd_hda_codec_write(codec, 0x1c, 0,
1953 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
1954 }
1955}
1956
1957/* turn on/off EAPD (+ mute HP) as a master switch */
1958static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1959 struct snd_ctl_elem_value *ucontrol)
1960{
1961 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1962
1963 if (!cxt_eapd_put(kcontrol, ucontrol))
1964 return 0;
1965
1966 cxt5066_update_speaker(codec);
1967 return 1;
1968}
1969
1970/* toggle input of built-in and mic jack appropriately */
1971static void cxt5066_automic(struct hda_codec *codec)
1972{
1973 static struct hda_verb ext_mic_present[] = {
1974 /* enable external mic, port B */
1975 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1976
1977 /* switch to external mic input */
1978 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
1979
1980 /* disable internal mic, port C */
1981 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1982 {}
1983 };
1984 static struct hda_verb ext_mic_absent[] = {
1985 /* enable internal mic, port C */
1986 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1987
1988 /* switch to internal mic input */
1989 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
1990
1991 /* disable external mic, port B */
1992 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1993 {}
1994 };
1995 unsigned int present;
1996
1997 present = snd_hda_codec_read(codec, 0x1a, 0,
1998 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1999 if (present) {
2000 snd_printdd("CXT5066: external microphone detected\n");
2001 snd_hda_sequence_write(codec, ext_mic_present);
2002 } else {
2003 snd_printdd("CXT5066: external microphone absent\n");
2004 snd_hda_sequence_write(codec, ext_mic_absent);
2005 }
2006}
2007
2008/* mute internal speaker if HP is plugged */
2009static void cxt5066_hp_automute(struct hda_codec *codec)
2010{
2011 struct conexant_spec *spec = codec->spec;
2012 unsigned int portA, portD;
2013
2014 /* Port A */
2015 portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0)
2016 & AC_PINSENSE_PRESENCE;
2017
2018 /* Port D */
2019 portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0)
2020 & AC_PINSENSE_PRESENCE) << 1;
2021
2022 spec->hp_present = !!(portA | portD);
2023 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2024 portA, portD, spec->hp_present);
2025 cxt5066_update_speaker(codec);
2026}
2027
2028/* unsolicited event for jack sensing */
2029static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2030{
2031 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2032 switch (res >> 26) {
2033 case CONEXANT_HP_EVENT:
2034 cxt5066_hp_automute(codec);
2035 break;
2036 case CONEXANT_MIC_EVENT:
2037 cxt5066_automic(codec);
2038 break;
2039 }
2040}
2041
2042static const struct hda_input_mux cxt5066_analog_mic_boost = {
2043 .num_items = 5,
2044 .items = {
2045 { "0dB", 0 },
2046 { "10dB", 1 },
2047 { "20dB", 2 },
2048 { "30dB", 3 },
2049 { "40dB", 4 },
2050 },
2051};
2052
2053static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2054 struct snd_ctl_elem_info *uinfo)
2055{
2056 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2057}
2058
2059static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2060 struct snd_ctl_elem_value *ucontrol)
2061{
2062 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2063 int val;
2064
2065 val = snd_hda_codec_read(codec, 0x17, 0,
2066 AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT);
2067
2068 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2069 return 0;
2070}
2071
2072static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2073 struct snd_ctl_elem_value *ucontrol)
2074{
2075 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2076 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2077 unsigned int idx;
2078
2079 if (!imux->num_items)
2080 return 0;
2081 idx = ucontrol->value.enumerated.item[0];
2082 if (idx >= imux->num_items)
2083 idx = imux->num_items - 1;
2084
2085 snd_hda_codec_write_cache(codec, 0x17, 0,
2086 AC_VERB_SET_AMP_GAIN_MUTE,
2087 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2088 imux->items[idx].index);
2089
2090 return 1;
2091}
2092
2093static struct hda_input_mux cxt5066_capture_source = {
2094 .num_items = 4,
2095 .items = {
2096 { "Mic B", 0 },
2097 { "Mic C", 1 },
2098 { "Mic E", 2 },
2099 { "Mic F", 3 },
2100 },
2101};
2102
2103static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2104 .ops = &snd_hda_bind_vol,
2105 .values = {
2106 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2107 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2108 0
2109 },
2110};
2111
2112static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2113 .ops = &snd_hda_bind_sw,
2114 .values = {
2115 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2116 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2117 0
2118 },
2119};
2120
2121static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2122 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2123 {}
2124};
2125
2126static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2127 {
2128 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2129 .name = "Master Playback Volume",
2130 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2131 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2132 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2133 .info = snd_hda_mixer_amp_volume_info,
2134 .get = snd_hda_mixer_amp_volume_get,
2135 .put = snd_hda_mixer_amp_volume_put,
2136 .tlv = { .c = snd_hda_mixer_amp_tlv },
2137 /* offset by 28 volume steps to limit minimum gain to -46dB */
2138 .private_value =
2139 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2140 },
2141 {}
2142};
2143
2144static struct snd_kcontrol_new cxt5066_mixers[] = {
2145 {
2146 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2147 .name = "Master Playback Switch",
2148 .info = cxt_eapd_info,
2149 .get = cxt_eapd_get,
2150 .put = cxt5066_hp_master_sw_put,
2151 .private_value = 0x1d,
2152 },
2153
2154 {
2155 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2156 .name = "Analog Mic Boost Capture Enum",
2157 .info = cxt5066_mic_boost_mux_enum_info,
2158 .get = cxt5066_mic_boost_mux_enum_get,
2159 .put = cxt5066_mic_boost_mux_enum_put,
2160 },
2161
2162 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2163 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2164 {}
2165};
2166
2167static struct hda_verb cxt5066_init_verbs[] = {
2168 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2169 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2170 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2171 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2172
2173 /* Speakers */
2174 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2175 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2176
2177 /* HP, Amp */
2178 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2179 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2180
2181 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2182 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2183
2184 /* DAC1 */
2185 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2186
2187 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2188 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2189 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2190 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2191 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2192 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2193
2194 /* no digital microphone support yet */
2195 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2196
2197 /* Audio input selector */
2198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2199
2200 /* SPDIF route: PCM */
2201 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2202 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2203
2204 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2205 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2206
2207 /* EAPD */
2208 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2209
2210 /* not handling these yet */
2211 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2212 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2213 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2214 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2215 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2216 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2217 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2218 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2219 { } /* end */
2220};
2221
2222static struct hda_verb cxt5066_init_verbs_olpc[] = {
2223 /* Port A: headphones */
2224 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2225 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2226
2227 /* Port B: external microphone */
2228 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2229
2230 /* Port C: internal microphone */
2231 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2232
2233 /* Port D: unused */
2234 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2235
2236 /* Port E: unused, but has primary EAPD */
2237 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2239
2240 /* Port F: unused */
2241 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2242
2243 /* Port G: internal speakers */
2244 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2245 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2246
2247 /* DAC1 */
2248 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2249
2250 /* DAC2: unused */
2251 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2252
2253 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2254 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2255 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2256 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2257 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2258 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2259 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2260 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2261 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2262 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2263 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2264 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2265
2266 /* Disable digital microphone port */
2267 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2268
2269 /* Audio input selectors */
2270 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2271 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2272
2273 /* Disable SPDIF */
2274 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2275 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2276
2277 /* enable unsolicited events for Port A and B */
2278 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2279 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2280 { } /* end */
2281};
2282
2283static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2284 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2285 { } /* end */
2286};
2287
2288/* initialize jack-sensing, too */
2289static int cxt5066_init(struct hda_codec *codec)
2290{
2291 snd_printdd("CXT5066: init\n");
2292 conexant_init(codec);
2293 if (codec->patch_ops.unsol_event) {
2294 cxt5066_hp_automute(codec);
2295 cxt5066_automic(codec);
2296 }
2297 return 0;
2298}
2299
2300enum {
2301 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2302 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2303 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2304 CXT5066_MODELS
2305};
2306
2307static const char *cxt5066_models[CXT5066_MODELS] = {
2308 [CXT5066_LAPTOP] = "laptop",
2309 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2310 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2311};
2312
2313static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2314 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2315 CXT5066_LAPTOP),
2316 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2317 CXT5066_DELL_LAPTOP),
2318 {}
2319};
2320
2321static int patch_cxt5066(struct hda_codec *codec)
2322{
2323 struct conexant_spec *spec;
2324 int board_config;
2325
2326 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2327 if (!spec)
2328 return -ENOMEM;
2329 codec->spec = spec;
2330
2331 codec->patch_ops = conexant_patch_ops;
2332 codec->patch_ops.init = cxt5066_init;
2333
2334 spec->dell_automute = 0;
2335 spec->multiout.max_channels = 2;
2336 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2337 spec->multiout.dac_nids = cxt5066_dac_nids;
2338 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2339 spec->num_adc_nids = 1;
2340 spec->adc_nids = cxt5066_adc_nids;
2341 spec->capsrc_nids = cxt5066_capsrc_nids;
2342 spec->input_mux = &cxt5066_capture_source;
2343
2344 spec->port_d_mode = PIN_HP;
2345
2346 spec->num_init_verbs = 1;
2347 spec->init_verbs[0] = cxt5066_init_verbs;
2348 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2349 spec->channel_mode = cxt5066_modes;
2350 spec->cur_adc = 0;
2351 spec->cur_adc_idx = 0;
2352
2353 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2354 cxt5066_models, cxt5066_cfg_tbl);
2355 switch (board_config) {
2356 default:
2357 case CXT5066_LAPTOP:
2358 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2359 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2360 break;
2361 case CXT5066_DELL_LAPTOP:
2362 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2363 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2364
2365 spec->port_d_mode = PIN_OUT;
2366 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2367 spec->num_init_verbs++;
2368 spec->dell_automute = 1;
2369 break;
2370 case CXT5066_OLPC_XO_1_5:
2371 codec->patch_ops.unsol_event = cxt5066_unsol_event;
2372 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2373 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2374 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2375 spec->port_d_mode = 0;
2376
2377 /* no S/PDIF out */
2378 spec->multiout.dig_out_nid = 0;
2379
2380 /* input source automatically selected */
2381 spec->input_mux = NULL;
2382 break;
2383 }
2384
2385 return 0;
2386}
1911 2387
1912/* 2388/*
1913 */ 2389 */
@@ -1919,12 +2395,15 @@ static struct hda_codec_preset snd_hda_preset_conexant[] = {
1919 .patch = patch_cxt5047 }, 2395 .patch = patch_cxt5047 },
1920 { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 2396 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1921 .patch = patch_cxt5051 }, 2397 .patch = patch_cxt5051 },
2398 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2399 .patch = patch_cxt5066 },
1922 {} /* terminator */ 2400 {} /* terminator */
1923}; 2401};
1924 2402
1925MODULE_ALIAS("snd-hda-codec-id:14f15045"); 2403MODULE_ALIAS("snd-hda-codec-id:14f15045");
1926MODULE_ALIAS("snd-hda-codec-id:14f15047"); 2404MODULE_ALIAS("snd-hda-codec-id:14f15047");
1927MODULE_ALIAS("snd-hda-codec-id:14f15051"); 2405MODULE_ALIAS("snd-hda-codec-id:14f15051");
2406MODULE_ALIAS("snd-hda-codec-id:14f15066");
1928 2407
1929MODULE_LICENSE("GPL"); 2408MODULE_LICENSE("GPL");
1930MODULE_DESCRIPTION("Conexant HD-audio codec"); 2409MODULE_DESCRIPTION("Conexant HD-audio codec");
diff --git a/sound/pci/hda/patch_intelhdmi.c b/sound/pci/hda/patch_intelhdmi.c
index fcc77fec448..01a18ed475a 100644
--- a/sound/pci/hda/patch_intelhdmi.c
+++ b/sound/pci/hda/patch_intelhdmi.c
@@ -33,8 +33,8 @@
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35 35
36#define CVT_NID 0x02 /* audio converter */ 36static hda_nid_t cvt_nid; /* audio converter */
37#define PIN_NID 0x03 /* HDMI output pin */ 37static hda_nid_t pin_nid; /* HDMI output pin */
38 38
39#define INTEL_HDMI_EVENT_TAG 0x08 39#define INTEL_HDMI_EVENT_TAG 0x08
40 40
@@ -44,30 +44,6 @@ struct intel_hdmi_spec {
44 struct hdmi_eld sink_eld; 44 struct hdmi_eld sink_eld;
45}; 45};
46 46
47static struct hda_verb pinout_enable_verb[] = {
48 {PIN_NID, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
49 {} /* terminator */
50};
51
52static struct hda_verb unsolicited_response_verb[] = {
53 {PIN_NID, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN |
54 INTEL_HDMI_EVENT_TAG},
55 {}
56};
57
58static struct hda_verb def_chan_map[] = {
59 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x00},
60 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x11},
61 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x22},
62 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x33},
63 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x44},
64 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x55},
65 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x66},
66 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x77},
67 {}
68};
69
70
71struct hdmi_audio_infoframe { 47struct hdmi_audio_infoframe {
72 u8 type; /* 0x84 */ 48 u8 type; /* 0x84 */
73 u8 ver; /* 0x01 */ 49 u8 ver; /* 0x01 */
@@ -244,11 +220,12 @@ static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t nid,
244static void hdmi_enable_output(struct hda_codec *codec) 220static void hdmi_enable_output(struct hda_codec *codec)
245{ 221{
246 /* Unmute */ 222 /* Unmute */
247 if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP) 223 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
248 snd_hda_codec_write(codec, PIN_NID, 0, 224 snd_hda_codec_write(codec, pin_nid, 0,
249 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 225 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
250 /* Enable pin out */ 226 /* Enable pin out */
251 snd_hda_sequence_write(codec, pinout_enable_verb); 227 snd_hda_codec_write(codec, pin_nid, 0,
228 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
252} 229}
253 230
254/* 231/*
@@ -256,8 +233,8 @@ static void hdmi_enable_output(struct hda_codec *codec)
256 */ 233 */
257static void hdmi_start_infoframe_trans(struct hda_codec *codec) 234static void hdmi_start_infoframe_trans(struct hda_codec *codec)
258{ 235{
259 hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0); 236 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
260 snd_hda_codec_write(codec, PIN_NID, 0, AC_VERB_SET_HDMI_DIP_XMIT, 237 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
261 AC_DIPXMIT_BEST); 238 AC_DIPXMIT_BEST);
262} 239}
263 240
@@ -266,20 +243,20 @@ static void hdmi_start_infoframe_trans(struct hda_codec *codec)
266 */ 243 */
267static void hdmi_stop_infoframe_trans(struct hda_codec *codec) 244static void hdmi_stop_infoframe_trans(struct hda_codec *codec)
268{ 245{
269 hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0); 246 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
270 snd_hda_codec_write(codec, PIN_NID, 0, AC_VERB_SET_HDMI_DIP_XMIT, 247 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
271 AC_DIPXMIT_DISABLE); 248 AC_DIPXMIT_DISABLE);
272} 249}
273 250
274static int hdmi_get_channel_count(struct hda_codec *codec) 251static int hdmi_get_channel_count(struct hda_codec *codec)
275{ 252{
276 return 1 + snd_hda_codec_read(codec, CVT_NID, 0, 253 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
277 AC_VERB_GET_CVT_CHAN_COUNT, 0); 254 AC_VERB_GET_CVT_CHAN_COUNT, 0);
278} 255}
279 256
280static void hdmi_set_channel_count(struct hda_codec *codec, int chs) 257static void hdmi_set_channel_count(struct hda_codec *codec, int chs)
281{ 258{
282 snd_hda_codec_write(codec, CVT_NID, 0, 259 snd_hda_codec_write(codec, cvt_nid, 0,
283 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); 260 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
284 261
285 if (chs != hdmi_get_channel_count(codec)) 262 if (chs != hdmi_get_channel_count(codec))
@@ -294,7 +271,7 @@ static void hdmi_debug_channel_mapping(struct hda_codec *codec)
294 int slot; 271 int slot;
295 272
296 for (i = 0; i < 8; i++) { 273 for (i = 0; i < 8; i++) {
297 slot = snd_hda_codec_read(codec, CVT_NID, 0, 274 slot = snd_hda_codec_read(codec, cvt_nid, 0,
298 AC_VERB_GET_HDMI_CHAN_SLOT, i); 275 AC_VERB_GET_HDMI_CHAN_SLOT, i);
299 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", 276 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
300 slot >> 4, slot & 0x7); 277 slot >> 4, slot & 0x7);
@@ -307,7 +284,7 @@ static void hdmi_parse_eld(struct hda_codec *codec)
307 struct intel_hdmi_spec *spec = codec->spec; 284 struct intel_hdmi_spec *spec = codec->spec;
308 struct hdmi_eld *eld = &spec->sink_eld; 285 struct hdmi_eld *eld = &spec->sink_eld;
309 286
310 if (!snd_hdmi_get_eld(eld, codec, PIN_NID)) 287 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
311 snd_hdmi_show_eld(eld); 288 snd_hdmi_show_eld(eld);
312} 289}
313 290
@@ -322,11 +299,11 @@ static void hdmi_debug_dip_size(struct hda_codec *codec)
322 int i; 299 int i;
323 int size; 300 int size;
324 301
325 size = snd_hdmi_get_eld_size(codec, PIN_NID); 302 size = snd_hdmi_get_eld_size(codec, pin_nid);
326 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size); 303 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
327 304
328 for (i = 0; i < 8; i++) { 305 for (i = 0; i < 8; i++) {
329 size = snd_hda_codec_read(codec, PIN_NID, 0, 306 size = snd_hda_codec_read(codec, pin_nid, 0,
330 AC_VERB_GET_HDMI_DIP_SIZE, i); 307 AC_VERB_GET_HDMI_DIP_SIZE, i);
331 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size); 308 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
332 } 309 }
@@ -340,15 +317,15 @@ static void hdmi_clear_dip_buffers(struct hda_codec *codec)
340 int size; 317 int size;
341 int pi, bi; 318 int pi, bi;
342 for (i = 0; i < 8; i++) { 319 for (i = 0; i < 8; i++) {
343 size = snd_hda_codec_read(codec, PIN_NID, 0, 320 size = snd_hda_codec_read(codec, pin_nid, 0,
344 AC_VERB_GET_HDMI_DIP_SIZE, i); 321 AC_VERB_GET_HDMI_DIP_SIZE, i);
345 if (size == 0) 322 if (size == 0)
346 continue; 323 continue;
347 324
348 hdmi_set_dip_index(codec, PIN_NID, i, 0x0); 325 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
349 for (j = 1; j < 1000; j++) { 326 for (j = 1; j < 1000; j++) {
350 hdmi_write_dip_byte(codec, PIN_NID, 0x0); 327 hdmi_write_dip_byte(codec, pin_nid, 0x0);
351 hdmi_get_dip_index(codec, PIN_NID, &pi, &bi); 328 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
352 if (pi != i) 329 if (pi != i)
353 snd_printd(KERN_INFO "dip index %d: %d != %d\n", 330 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
354 bi, pi, i); 331 bi, pi, i);
@@ -376,9 +353,9 @@ static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
376 sum += params[i]; 353 sum += params[i];
377 ai->checksum = - sum; 354 ai->checksum = - sum;
378 355
379 hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0); 356 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
380 for (i = 0; i < sizeof(ai); i++) 357 for (i = 0; i < sizeof(ai); i++)
381 hdmi_write_dip_byte(codec, PIN_NID, params[i]); 358 hdmi_write_dip_byte(codec, pin_nid, params[i]);
382} 359}
383 360
384/* 361/*
@@ -465,6 +442,8 @@ static int hdmi_setup_channel_allocation(struct hda_codec *codec,
465static void hdmi_setup_channel_mapping(struct hda_codec *codec, 442static void hdmi_setup_channel_mapping(struct hda_codec *codec,
466 struct hdmi_audio_infoframe *ai) 443 struct hdmi_audio_infoframe *ai)
467{ 444{
445 int i;
446
468 if (!ai->CA) 447 if (!ai->CA)
469 return; 448 return;
470 449
@@ -473,7 +452,11 @@ static void hdmi_setup_channel_mapping(struct hda_codec *codec,
473 * ALSA sequence is front/surr/clfe/side? 452 * ALSA sequence is front/surr/clfe/side?
474 */ 453 */
475 454
476 snd_hda_sequence_write(codec, def_chan_map); 455 for (i = 0; i < 8; i++)
456 snd_hda_codec_write(codec, cvt_nid, 0,
457 AC_VERB_SET_HDMI_CHAN_SLOT,
458 (i << 4) | i);
459
477 hdmi_debug_channel_mapping(codec); 460 hdmi_debug_channel_mapping(codec);
478} 461}
479 462
@@ -597,7 +580,6 @@ static struct hda_pcm_stream intel_hdmi_pcm_playback = {
597 .substreams = 1, 580 .substreams = 1,
598 .channels_min = 2, 581 .channels_min = 2,
599 .channels_max = 8, 582 .channels_max = 8,
600 .nid = CVT_NID, /* NID to query formats and rates and setup streams */
601 .ops = { 583 .ops = {
602 .open = intel_hdmi_playback_pcm_open, 584 .open = intel_hdmi_playback_pcm_open,
603 .close = intel_hdmi_playback_pcm_close, 585 .close = intel_hdmi_playback_pcm_close,
@@ -613,6 +595,9 @@ static int intel_hdmi_build_pcms(struct hda_codec *codec)
613 codec->num_pcms = 1; 595 codec->num_pcms = 1;
614 codec->pcm_info = info; 596 codec->pcm_info = info;
615 597
598 /* NID to query formats and rates and setup streams */
599 intel_hdmi_pcm_playback.nid = cvt_nid;
600
616 info->name = "INTEL HDMI"; 601 info->name = "INTEL HDMI";
617 info->pcm_type = HDA_PCM_TYPE_HDMI; 602 info->pcm_type = HDA_PCM_TYPE_HDMI;
618 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = intel_hdmi_pcm_playback; 603 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = intel_hdmi_pcm_playback;
@@ -636,8 +621,9 @@ static int intel_hdmi_init(struct hda_codec *codec)
636{ 621{
637 hdmi_enable_output(codec); 622 hdmi_enable_output(codec);
638 623
639 snd_hda_sequence_write(codec, unsolicited_response_verb); 624 snd_hda_codec_write(codec, pin_nid, 0,
640 625 AC_VERB_SET_UNSOLICITED_ENABLE,
626 AC_USRSP_EN | INTEL_HDMI_EVENT_TAG);
641 return 0; 627 return 0;
642} 628}
643 629
@@ -657,7 +643,7 @@ static struct hda_codec_ops intel_hdmi_patch_ops = {
657 .unsol_event = intel_hdmi_unsol_event, 643 .unsol_event = intel_hdmi_unsol_event,
658}; 644};
659 645
660static int patch_intel_hdmi(struct hda_codec *codec) 646static int do_patch_intel_hdmi(struct hda_codec *codec)
661{ 647{
662 struct intel_hdmi_spec *spec; 648 struct intel_hdmi_spec *spec;
663 649
@@ -667,7 +653,7 @@ static int patch_intel_hdmi(struct hda_codec *codec)
667 653
668 spec->multiout.num_dacs = 0; /* no analog */ 654 spec->multiout.num_dacs = 0; /* no analog */
669 spec->multiout.max_channels = 8; 655 spec->multiout.max_channels = 8;
670 spec->multiout.dig_out_nid = CVT_NID; 656 spec->multiout.dig_out_nid = cvt_nid;
671 657
672 codec->spec = spec; 658 codec->spec = spec;
673 codec->patch_ops = intel_hdmi_patch_ops; 659 codec->patch_ops = intel_hdmi_patch_ops;
@@ -679,12 +665,27 @@ static int patch_intel_hdmi(struct hda_codec *codec)
679 return 0; 665 return 0;
680} 666}
681 667
668static int patch_intel_hdmi(struct hda_codec *codec)
669{
670 cvt_nid = 0x02;
671 pin_nid = 0x03;
672 return do_patch_intel_hdmi(codec);
673}
674
675static int patch_intel_hdmi_ibexpeak(struct hda_codec *codec)
676{
677 cvt_nid = 0x02;
678 pin_nid = 0x04;
679 return do_patch_intel_hdmi(codec);
680}
681
682static struct hda_codec_preset snd_hda_preset_intelhdmi[] = { 682static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
683 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi }, 683 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi },
684 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi }, 684 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi },
685 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi }, 685 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi },
686 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi }, 686 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi },
687 { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi }, 687 { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi },
688 { .id = 0x80860054, .name = "Q57 DEVIBX", .patch = patch_intel_hdmi_ibexpeak },
688 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi }, 689 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
689 {} /* terminator */ 690 {} /* terminator */
690}; 691};
@@ -694,6 +695,7 @@ MODULE_ALIAS("snd-hda-codec-id:80862801");
694MODULE_ALIAS("snd-hda-codec-id:80862802"); 695MODULE_ALIAS("snd-hda-codec-id:80862802");
695MODULE_ALIAS("snd-hda-codec-id:80862803"); 696MODULE_ALIAS("snd-hda-codec-id:80862803");
696MODULE_ALIAS("snd-hda-codec-id:80862804"); 697MODULE_ALIAS("snd-hda-codec-id:80862804");
698MODULE_ALIAS("snd-hda-codec-id:80860054");
697MODULE_ALIAS("snd-hda-codec-id:10951392"); 699MODULE_ALIAS("snd-hda-codec-id:10951392");
698 700
699MODULE_LICENSE("GPL"); 701MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/patch_nvhdmi.c b/sound/pci/hda/patch_nvhdmi.c
index f5792e2eea8..c8435c9a97f 100644
--- a/sound/pci/hda/patch_nvhdmi.c
+++ b/sound/pci/hda/patch_nvhdmi.c
@@ -377,6 +377,7 @@ static int patch_nvhdmi_2ch(struct hda_codec *codec)
377 */ 377 */
378static struct hda_codec_preset snd_hda_preset_nvhdmi[] = { 378static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
379 { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 379 { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
380 { .id = 0x10de0003, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
380 { .id = 0x10de0006, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 381 { .id = 0x10de0006, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
381 { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi_8ch }, 382 { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi_8ch },
382 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch }, 383 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
@@ -385,6 +386,7 @@ static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
385}; 386};
386 387
387MODULE_ALIAS("snd-hda-codec-id:10de0002"); 388MODULE_ALIAS("snd-hda-codec-id:10de0002");
389MODULE_ALIAS("snd-hda-codec-id:10de0003");
388MODULE_ALIAS("snd-hda-codec-id:10de0006"); 390MODULE_ALIAS("snd-hda-codec-id:10de0006");
389MODULE_ALIAS("snd-hda-codec-id:10de0007"); 391MODULE_ALIAS("snd-hda-codec-id:10de0007");
390MODULE_ALIAS("snd-hda-codec-id:10de0067"); 392MODULE_ALIAS("snd-hda-codec-id:10de0067");
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 3a8e58c483d..12960581956 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -208,12 +208,6 @@ enum {
208 ALC885_MBP3, 208 ALC885_MBP3,
209 ALC885_MB5, 209 ALC885_MB5,
210 ALC885_IMAC24, 210 ALC885_IMAC24,
211 ALC882_AUTO,
212 ALC882_MODEL_LAST,
213};
214
215/* ALC883 models */
216enum {
217 ALC883_3ST_2ch_DIG, 211 ALC883_3ST_2ch_DIG,
218 ALC883_3ST_6ch_DIG, 212 ALC883_3ST_6ch_DIG,
219 ALC883_3ST_6ch, 213 ALC883_3ST_6ch,
@@ -226,6 +220,7 @@ enum {
226 ALC888_ACER_ASPIRE_4930G, 220 ALC888_ACER_ASPIRE_4930G,
227 ALC888_ACER_ASPIRE_6530G, 221 ALC888_ACER_ASPIRE_6530G,
228 ALC888_ACER_ASPIRE_8930G, 222 ALC888_ACER_ASPIRE_8930G,
223 ALC888_ACER_ASPIRE_7730G,
229 ALC883_MEDION, 224 ALC883_MEDION,
230 ALC883_MEDION_MD2, 225 ALC883_MEDION_MD2,
231 ALC883_LAPTOP_EAPD, 226 ALC883_LAPTOP_EAPD,
@@ -237,17 +232,20 @@ enum {
237 ALC888_3ST_HP, 232 ALC888_3ST_HP,
238 ALC888_6ST_DELL, 233 ALC888_6ST_DELL,
239 ALC883_MITAC, 234 ALC883_MITAC,
235 ALC883_CLEVO_M540R,
240 ALC883_CLEVO_M720, 236 ALC883_CLEVO_M720,
241 ALC883_FUJITSU_PI2515, 237 ALC883_FUJITSU_PI2515,
242 ALC888_FUJITSU_XA3530, 238 ALC888_FUJITSU_XA3530,
243 ALC883_3ST_6ch_INTEL, 239 ALC883_3ST_6ch_INTEL,
240 ALC889A_INTEL,
241 ALC889_INTEL,
244 ALC888_ASUS_M90V, 242 ALC888_ASUS_M90V,
245 ALC888_ASUS_EEE1601, 243 ALC888_ASUS_EEE1601,
246 ALC889A_MB31, 244 ALC889A_MB31,
247 ALC1200_ASUS_P5Q, 245 ALC1200_ASUS_P5Q,
248 ALC883_SONY_VAIO_TT, 246 ALC883_SONY_VAIO_TT,
249 ALC883_AUTO, 247 ALC882_AUTO,
250 ALC883_MODEL_LAST, 248 ALC882_MODEL_LAST,
251}; 249};
252 250
253/* for GPIO Poll */ 251/* for GPIO Poll */
@@ -262,6 +260,14 @@ enum {
262 ALC_INIT_GPIO3, 260 ALC_INIT_GPIO3,
263}; 261};
264 262
263struct alc_mic_route {
264 hda_nid_t pin;
265 unsigned char mux_idx;
266 unsigned char amix_idx;
267};
268
269#define MUX_IDX_UNDEF ((unsigned char)-1)
270
265struct alc_spec { 271struct alc_spec {
266 /* codec parameterization */ 272 /* codec parameterization */
267 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ 273 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
@@ -275,13 +281,13 @@ struct alc_spec {
275 */ 281 */
276 unsigned int num_init_verbs; 282 unsigned int num_init_verbs;
277 283
278 char stream_name_analog[16]; /* analog PCM stream */ 284 char stream_name_analog[32]; /* analog PCM stream */
279 struct hda_pcm_stream *stream_analog_playback; 285 struct hda_pcm_stream *stream_analog_playback;
280 struct hda_pcm_stream *stream_analog_capture; 286 struct hda_pcm_stream *stream_analog_capture;
281 struct hda_pcm_stream *stream_analog_alt_playback; 287 struct hda_pcm_stream *stream_analog_alt_playback;
282 struct hda_pcm_stream *stream_analog_alt_capture; 288 struct hda_pcm_stream *stream_analog_alt_capture;
283 289
284 char stream_name_digital[16]; /* digital PCM stream */ 290 char stream_name_digital[32]; /* digital PCM stream */
285 struct hda_pcm_stream *stream_digital_playback; 291 struct hda_pcm_stream *stream_digital_playback;
286 struct hda_pcm_stream *stream_digital_capture; 292 struct hda_pcm_stream *stream_digital_capture;
287 293
@@ -304,6 +310,8 @@ struct alc_spec {
304 unsigned int num_mux_defs; 310 unsigned int num_mux_defs;
305 const struct hda_input_mux *input_mux; 311 const struct hda_input_mux *input_mux;
306 unsigned int cur_mux[3]; 312 unsigned int cur_mux[3];
313 struct alc_mic_route ext_mic;
314 struct alc_mic_route int_mic;
307 315
308 /* channel model */ 316 /* channel model */
309 const struct hda_channel_mode *channel_mode; 317 const struct hda_channel_mode *channel_mode;
@@ -320,6 +328,8 @@ struct alc_spec {
320 struct snd_array kctls; 328 struct snd_array kctls;
321 struct hda_input_mux private_imux[3]; 329 struct hda_input_mux private_imux[3];
322 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 330 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
331 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
332 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
323 333
324 /* hooks */ 334 /* hooks */
325 void (*init_hook)(struct hda_codec *codec); 335 void (*init_hook)(struct hda_codec *codec);
@@ -329,6 +339,7 @@ struct alc_spec {
329 unsigned int sense_updated: 1; 339 unsigned int sense_updated: 1;
330 unsigned int jack_present: 1; 340 unsigned int jack_present: 1;
331 unsigned int master_sw: 1; 341 unsigned int master_sw: 1;
342 unsigned int auto_mic:1;
332 343
333 /* other flags */ 344 /* other flags */
334 unsigned int no_analog :1; /* digital I/O only */ 345 unsigned int no_analog :1; /* digital I/O only */
@@ -370,6 +381,7 @@ struct alc_config_preset {
370 unsigned int num_mux_defs; 381 unsigned int num_mux_defs;
371 const struct hda_input_mux *input_mux; 382 const struct hda_input_mux *input_mux;
372 void (*unsol_event)(struct hda_codec *, unsigned int); 383 void (*unsol_event)(struct hda_codec *, unsigned int);
384 void (*setup)(struct hda_codec *);
373 void (*init_hook)(struct hda_codec *); 385 void (*init_hook)(struct hda_codec *);
374#ifdef CONFIG_SND_HDA_POWER_SAVE 386#ifdef CONFIG_SND_HDA_POWER_SAVE
375 struct hda_amp_list *loopbacks; 387 struct hda_amp_list *loopbacks;
@@ -417,7 +429,7 @@ static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
417 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; 429 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
418 imux = &spec->input_mux[mux_idx]; 430 imux = &spec->input_mux[mux_idx];
419 431
420 type = (get_wcaps(codec, nid) & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 432 type = get_wcaps_type(get_wcaps(codec, nid));
421 if (type == AC_WID_AUD_MIX) { 433 if (type == AC_WID_AUD_MIX) {
422 /* Matrix-mixer style (e.g. ALC882) */ 434 /* Matrix-mixer style (e.g. ALC882) */
423 unsigned int *cur_val = &spec->cur_mux[adc_idx]; 435 unsigned int *cur_val = &spec->cur_mux[adc_idx];
@@ -559,7 +571,7 @@ static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
559 571
560 /* Find enumerated value for current pinctl setting */ 572 /* Find enumerated value for current pinctl setting */
561 i = alc_pin_mode_min(dir); 573 i = alc_pin_mode_min(dir);
562 while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir)) 574 while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
563 i++; 575 i++;
564 *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir); 576 *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
565 return 0; 577 return 0;
@@ -842,9 +854,10 @@ static void print_realtek_coef(struct snd_info_buffer *buffer,
842/* 854/*
843 * set up from the preset table 855 * set up from the preset table
844 */ 856 */
845static void setup_preset(struct alc_spec *spec, 857static void setup_preset(struct hda_codec *codec,
846 const struct alc_config_preset *preset) 858 const struct alc_config_preset *preset)
847{ 859{
860 struct alc_spec *spec = codec->spec;
848 int i; 861 int i;
849 862
850 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++) 863 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
@@ -886,6 +899,9 @@ static void setup_preset(struct alc_spec *spec,
886#ifdef CONFIG_SND_HDA_POWER_SAVE 899#ifdef CONFIG_SND_HDA_POWER_SAVE
887 spec->loopback.amplist = preset->loopbacks; 900 spec->loopback.amplist = preset->loopbacks;
888#endif 901#endif
902
903 if (preset->setup)
904 preset->setup(codec);
889} 905}
890 906
891/* Enable GPIO mask and set output */ 907/* Enable GPIO mask and set output */
@@ -965,30 +981,64 @@ static void alc_automute_pin(struct hda_codec *codec)
965 } 981 }
966} 982}
967 983
968#if 0 /* it's broken in some cases -- temporarily disabled */ 984static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
985 hda_nid_t nid)
986{
987 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
988 int i, nums;
989
990 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
991 for (i = 0; i < nums; i++)
992 if (conn[i] == nid)
993 return i;
994 return -1;
995}
996
969static void alc_mic_automute(struct hda_codec *codec) 997static void alc_mic_automute(struct hda_codec *codec)
970{ 998{
971 struct alc_spec *spec = codec->spec; 999 struct alc_spec *spec = codec->spec;
972 unsigned int present; 1000 struct alc_mic_route *dead, *alive;
973 unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC]; 1001 unsigned int present, type;
974 unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC]; 1002 hda_nid_t cap_nid;
975 unsigned int mix_nid = spec->capsrc_nids[0]; 1003
976 unsigned int capsrc_idx_mic, capsrc_idx_fmic; 1004 if (!spec->auto_mic)
977 1005 return;
978 capsrc_idx_mic = mic_nid - 0x18; 1006 if (!spec->int_mic.pin || !spec->ext_mic.pin)
979 capsrc_idx_fmic = fmic_nid - 0x18; 1007 return;
980 present = snd_hda_codec_read(codec, mic_nid, 0, 1008 if (snd_BUG_ON(!spec->adc_nids))
981 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1009 return;
982 snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 1010
983 0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80)); 1011 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
984 snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 1012
985 0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0)); 1013 present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0,
986 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic, 1014 AC_VERB_GET_PIN_SENSE, 0);
987 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 1015 present &= AC_PINSENSE_PRESENCE;
1016 if (present) {
1017 alive = &spec->ext_mic;
1018 dead = &spec->int_mic;
1019 } else {
1020 alive = &spec->int_mic;
1021 dead = &spec->ext_mic;
1022 }
1023
1024 type = get_wcaps_type(get_wcaps(codec, cap_nid));
1025 if (type == AC_WID_AUD_MIX) {
1026 /* Matrix-mixer style (e.g. ALC882) */
1027 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1028 alive->mux_idx,
1029 HDA_AMP_MUTE, 0);
1030 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1031 dead->mux_idx,
1032 HDA_AMP_MUTE, HDA_AMP_MUTE);
1033 } else {
1034 /* MUX style (e.g. ALC880) */
1035 snd_hda_codec_write_cache(codec, cap_nid, 0,
1036 AC_VERB_SET_CONNECT_SEL,
1037 alive->mux_idx);
1038 }
1039
1040 /* FIXME: analog mixer */
988} 1041}
989#else
990#define alc_mic_automute(codec) do {} while(0) /* NOP */
991#endif /* disabled */
992 1042
993/* unsolicited event for HP jack sensing */ 1043/* unsolicited event for HP jack sensing */
994static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) 1044static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
@@ -1031,6 +1081,16 @@ static void alc888_coef_init(struct hda_codec *codec)
1031 AC_VERB_SET_PROC_COEF, 0x3030); 1081 AC_VERB_SET_PROC_COEF, 0x3030);
1032} 1082}
1033 1083
1084static void alc889_coef_init(struct hda_codec *codec)
1085{
1086 unsigned int tmp;
1087
1088 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1089 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1090 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1091 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1092}
1093
1034static void alc_auto_init_amp(struct hda_codec *codec, int type) 1094static void alc_auto_init_amp(struct hda_codec *codec, int type)
1035{ 1095{
1036 unsigned int tmp; 1096 unsigned int tmp;
@@ -1088,15 +1148,7 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
1088 case 0x10ec0885: 1148 case 0x10ec0885:
1089 case 0x10ec0887: 1149 case 0x10ec0887:
1090 case 0x10ec0889: 1150 case 0x10ec0889:
1091 snd_hda_codec_write(codec, 0x20, 0, 1151 alc889_coef_init(codec);
1092 AC_VERB_SET_COEF_INDEX, 7);
1093 tmp = snd_hda_codec_read(codec, 0x20, 0,
1094 AC_VERB_GET_PROC_COEF, 0);
1095 snd_hda_codec_write(codec, 0x20, 0,
1096 AC_VERB_SET_COEF_INDEX, 7);
1097 snd_hda_codec_write(codec, 0x20, 0,
1098 AC_VERB_SET_PROC_COEF,
1099 tmp | 0x2010);
1100 break; 1152 break;
1101 case 0x10ec0888: 1153 case 0x10ec0888:
1102 alc888_coef_init(codec); 1154 alc888_coef_init(codec);
@@ -1142,6 +1194,55 @@ static void alc_init_auto_hp(struct hda_codec *codec)
1142 spec->unsol_event = alc_sku_unsol_event; 1194 spec->unsol_event = alc_sku_unsol_event;
1143} 1195}
1144 1196
1197static void alc_init_auto_mic(struct hda_codec *codec)
1198{
1199 struct alc_spec *spec = codec->spec;
1200 struct auto_pin_cfg *cfg = &spec->autocfg;
1201 hda_nid_t fixed, ext;
1202 int i;
1203
1204 /* there must be only two mic inputs exclusively */
1205 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
1206 if (cfg->input_pins[i])
1207 return;
1208
1209 fixed = ext = 0;
1210 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
1211 hda_nid_t nid = cfg->input_pins[i];
1212 unsigned int defcfg;
1213 if (!nid)
1214 return;
1215 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1216 switch (get_defcfg_connect(defcfg)) {
1217 case AC_JACK_PORT_FIXED:
1218 if (fixed)
1219 return; /* already occupied */
1220 fixed = nid;
1221 break;
1222 case AC_JACK_PORT_COMPLEX:
1223 if (ext)
1224 return; /* already occupied */
1225 ext = nid;
1226 break;
1227 default:
1228 return; /* invalid entry */
1229 }
1230 }
1231 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1232 return; /* no unsol support */
1233 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1234 ext, fixed);
1235 spec->ext_mic.pin = ext;
1236 spec->int_mic.pin = fixed;
1237 spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1238 spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1239 spec->auto_mic = 1;
1240 snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1241 AC_VERB_SET_UNSOLICITED_ENABLE,
1242 AC_USRSP_EN | ALC880_MIC_EVENT);
1243 spec->unsol_event = alc_sku_unsol_event;
1244}
1245
1145/* check subsystem ID and set up device-specific initialization; 1246/* check subsystem ID and set up device-specific initialization;
1146 * return 1 if initialized, 0 if invalid SSID 1247 * return 1 if initialized, 0 if invalid SSID
1147 */ 1248 */
@@ -1243,6 +1344,7 @@ do_sku:
1243 } 1344 }
1244 1345
1245 alc_init_auto_hp(codec); 1346 alc_init_auto_hp(codec);
1347 alc_init_auto_mic(codec);
1246 return 1; 1348 return 1;
1247} 1349}
1248 1350
@@ -1255,6 +1357,7 @@ static void alc_ssid_check(struct hda_codec *codec,
1255 "Enable default setup for auto mode as fallback\n"); 1357 "Enable default setup for auto mode as fallback\n");
1256 spec->init_amp = ALC_INIT_DEFAULT; 1358 spec->init_amp = ALC_INIT_DEFAULT;
1257 alc_init_auto_hp(codec); 1359 alc_init_auto_hp(codec);
1360 alc_init_auto_mic(codec);
1258 } 1361 }
1259} 1362}
1260 1363
@@ -1436,7 +1539,25 @@ static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1436 alc_automute_amp(codec); 1539 alc_automute_amp(codec);
1437} 1540}
1438 1541
1439static void alc888_fujitsu_xa3530_init_hook(struct hda_codec *codec) 1542static void alc889_automute_setup(struct hda_codec *codec)
1543{
1544 struct alc_spec *spec = codec->spec;
1545
1546 spec->autocfg.hp_pins[0] = 0x15;
1547 spec->autocfg.speaker_pins[0] = 0x14;
1548 spec->autocfg.speaker_pins[1] = 0x16;
1549 spec->autocfg.speaker_pins[2] = 0x17;
1550 spec->autocfg.speaker_pins[3] = 0x19;
1551 spec->autocfg.speaker_pins[4] = 0x1a;
1552}
1553
1554static void alc889_intel_init_hook(struct hda_codec *codec)
1555{
1556 alc889_coef_init(codec);
1557 alc_automute_amp(codec);
1558}
1559
1560static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1440{ 1561{
1441 struct alc_spec *spec = codec->spec; 1562 struct alc_spec *spec = codec->spec;
1442 1563
@@ -1444,7 +1565,6 @@ static void alc888_fujitsu_xa3530_init_hook(struct hda_codec *codec)
1444 spec->autocfg.hp_pins[1] = 0x1b; /* hp */ 1565 spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1445 spec->autocfg.speaker_pins[0] = 0x14; /* speaker */ 1566 spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1446 spec->autocfg.speaker_pins[1] = 0x15; /* bass */ 1567 spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1447 alc_automute_amp(codec);
1448} 1568}
1449 1569
1450/* 1570/*
@@ -1643,16 +1763,15 @@ static struct snd_kcontrol_new alc888_base_mixer[] = {
1643 { } /* end */ 1763 { } /* end */
1644}; 1764};
1645 1765
1646static void alc888_acer_aspire_4930g_init_hook(struct hda_codec *codec) 1766static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1647{ 1767{
1648 struct alc_spec *spec = codec->spec; 1768 struct alc_spec *spec = codec->spec;
1649 1769
1650 spec->autocfg.hp_pins[0] = 0x15; 1770 spec->autocfg.hp_pins[0] = 0x15;
1651 spec->autocfg.speaker_pins[0] = 0x14; 1771 spec->autocfg.speaker_pins[0] = 0x14;
1652 alc_automute_amp(codec);
1653} 1772}
1654 1773
1655static void alc888_acer_aspire_6530g_init_hook(struct hda_codec *codec) 1774static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1656{ 1775{
1657 struct alc_spec *spec = codec->spec; 1776 struct alc_spec *spec = codec->spec;
1658 1777
@@ -1660,10 +1779,9 @@ static void alc888_acer_aspire_6530g_init_hook(struct hda_codec *codec)
1660 spec->autocfg.speaker_pins[0] = 0x14; 1779 spec->autocfg.speaker_pins[0] = 0x14;
1661 spec->autocfg.speaker_pins[1] = 0x16; 1780 spec->autocfg.speaker_pins[1] = 0x16;
1662 spec->autocfg.speaker_pins[2] = 0x17; 1781 spec->autocfg.speaker_pins[2] = 0x17;
1663 alc_automute_amp(codec);
1664} 1782}
1665 1783
1666static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec) 1784static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1667{ 1785{
1668 struct alc_spec *spec = codec->spec; 1786 struct alc_spec *spec = codec->spec;
1669 1787
@@ -1671,7 +1789,6 @@ static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec)
1671 spec->autocfg.speaker_pins[0] = 0x14; 1789 spec->autocfg.speaker_pins[0] = 0x14;
1672 spec->autocfg.speaker_pins[1] = 0x16; 1790 spec->autocfg.speaker_pins[1] = 0x16;
1673 spec->autocfg.speaker_pins[2] = 0x1b; 1791 spec->autocfg.speaker_pins[2] = 0x1b;
1674 alc_automute_amp(codec);
1675} 1792}
1676 1793
1677/* 1794/*
@@ -2651,13 +2768,17 @@ static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2651 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); 2768 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2652} 2769}
2653 2770
2654static void alc880_uniwill_init_hook(struct hda_codec *codec) 2771static void alc880_uniwill_setup(struct hda_codec *codec)
2655{ 2772{
2656 struct alc_spec *spec = codec->spec; 2773 struct alc_spec *spec = codec->spec;
2657 2774
2658 spec->autocfg.hp_pins[0] = 0x14; 2775 spec->autocfg.hp_pins[0] = 0x14;
2659 spec->autocfg.speaker_pins[0] = 0x15; 2776 spec->autocfg.speaker_pins[0] = 0x15;
2660 spec->autocfg.speaker_pins[0] = 0x16; 2777 spec->autocfg.speaker_pins[0] = 0x16;
2778}
2779
2780static void alc880_uniwill_init_hook(struct hda_codec *codec)
2781{
2661 alc_automute_amp(codec); 2782 alc_automute_amp(codec);
2662 alc880_uniwill_mic_automute(codec); 2783 alc880_uniwill_mic_automute(codec);
2663} 2784}
@@ -2678,13 +2799,12 @@ static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2678 } 2799 }
2679} 2800}
2680 2801
2681static void alc880_uniwill_p53_init_hook(struct hda_codec *codec) 2802static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2682{ 2803{
2683 struct alc_spec *spec = codec->spec; 2804 struct alc_spec *spec = codec->spec;
2684 2805
2685 spec->autocfg.hp_pins[0] = 0x14; 2806 spec->autocfg.hp_pins[0] = 0x14;
2686 spec->autocfg.speaker_pins[0] = 0x15; 2807 spec->autocfg.speaker_pins[0] = 0x15;
2687 alc_automute_amp(codec);
2688} 2808}
2689 2809
2690static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec) 2810static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
@@ -2947,13 +3067,12 @@ static struct hda_verb alc880_lg_init_verbs[] = {
2947}; 3067};
2948 3068
2949/* toggle speaker-output according to the hp-jack state */ 3069/* toggle speaker-output according to the hp-jack state */
2950static void alc880_lg_init_hook(struct hda_codec *codec) 3070static void alc880_lg_setup(struct hda_codec *codec)
2951{ 3071{
2952 struct alc_spec *spec = codec->spec; 3072 struct alc_spec *spec = codec->spec;
2953 3073
2954 spec->autocfg.hp_pins[0] = 0x1b; 3074 spec->autocfg.hp_pins[0] = 0x1b;
2955 spec->autocfg.speaker_pins[0] = 0x17; 3075 spec->autocfg.speaker_pins[0] = 0x17;
2956 alc_automute_amp(codec);
2957} 3076}
2958 3077
2959/* 3078/*
@@ -3032,13 +3151,12 @@ static struct hda_verb alc880_lg_lw_init_verbs[] = {
3032}; 3151};
3033 3152
3034/* toggle speaker-output according to the hp-jack state */ 3153/* toggle speaker-output according to the hp-jack state */
3035static void alc880_lg_lw_init_hook(struct hda_codec *codec) 3154static void alc880_lg_lw_setup(struct hda_codec *codec)
3036{ 3155{
3037 struct alc_spec *spec = codec->spec; 3156 struct alc_spec *spec = codec->spec;
3038 3157
3039 spec->autocfg.hp_pins[0] = 0x1b; 3158 spec->autocfg.hp_pins[0] = 0x1b;
3040 spec->autocfg.speaker_pins[0] = 0x14; 3159 spec->autocfg.speaker_pins[0] = 0x14;
3041 alc_automute_amp(codec);
3042} 3160}
3043 3161
3044static struct snd_kcontrol_new alc880_medion_rim_mixer[] = { 3162static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
@@ -3104,13 +3222,12 @@ static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3104 alc880_medion_rim_automute(codec); 3222 alc880_medion_rim_automute(codec);
3105} 3223}
3106 3224
3107static void alc880_medion_rim_init_hook(struct hda_codec *codec) 3225static void alc880_medion_rim_setup(struct hda_codec *codec)
3108{ 3226{
3109 struct alc_spec *spec = codec->spec; 3227 struct alc_spec *spec = codec->spec;
3110 3228
3111 spec->autocfg.hp_pins[0] = 0x14; 3229 spec->autocfg.hp_pins[0] = 0x14;
3112 spec->autocfg.speaker_pins[0] = 0x1b; 3230 spec->autocfg.speaker_pins[0] = 0x1b;
3113 alc880_medion_rim_automute(codec);
3114} 3231}
3115 3232
3116#ifdef CONFIG_SND_HDA_POWER_SAVE 3233#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -3977,7 +4094,8 @@ static struct alc_config_preset alc880_presets[] = {
3977 .channel_mode = alc880_2_jack_modes, 4094 .channel_mode = alc880_2_jack_modes,
3978 .input_mux = &alc880_f1734_capture_source, 4095 .input_mux = &alc880_f1734_capture_source,
3979 .unsol_event = alc880_uniwill_p53_unsol_event, 4096 .unsol_event = alc880_uniwill_p53_unsol_event,
3980 .init_hook = alc880_uniwill_p53_init_hook, 4097 .setup = alc880_uniwill_p53_setup,
4098 .init_hook = alc_automute_amp,
3981 }, 4099 },
3982 [ALC880_ASUS] = { 4100 [ALC880_ASUS] = {
3983 .mixers = { alc880_asus_mixer }, 4101 .mixers = { alc880_asus_mixer },
@@ -4054,6 +4172,7 @@ static struct alc_config_preset alc880_presets[] = {
4054 .need_dac_fix = 1, 4172 .need_dac_fix = 1,
4055 .input_mux = &alc880_capture_source, 4173 .input_mux = &alc880_capture_source,
4056 .unsol_event = alc880_uniwill_unsol_event, 4174 .unsol_event = alc880_uniwill_unsol_event,
4175 .setup = alc880_uniwill_setup,
4057 .init_hook = alc880_uniwill_init_hook, 4176 .init_hook = alc880_uniwill_init_hook,
4058 }, 4177 },
4059 [ALC880_UNIWILL_P53] = { 4178 [ALC880_UNIWILL_P53] = {
@@ -4066,7 +4185,8 @@ static struct alc_config_preset alc880_presets[] = {
4066 .channel_mode = alc880_threestack_modes, 4185 .channel_mode = alc880_threestack_modes,
4067 .input_mux = &alc880_capture_source, 4186 .input_mux = &alc880_capture_source,
4068 .unsol_event = alc880_uniwill_p53_unsol_event, 4187 .unsol_event = alc880_uniwill_p53_unsol_event,
4069 .init_hook = alc880_uniwill_p53_init_hook, 4188 .setup = alc880_uniwill_p53_setup,
4189 .init_hook = alc_automute_amp,
4070 }, 4190 },
4071 [ALC880_FUJITSU] = { 4191 [ALC880_FUJITSU] = {
4072 .mixers = { alc880_fujitsu_mixer }, 4192 .mixers = { alc880_fujitsu_mixer },
@@ -4080,7 +4200,8 @@ static struct alc_config_preset alc880_presets[] = {
4080 .channel_mode = alc880_2_jack_modes, 4200 .channel_mode = alc880_2_jack_modes,
4081 .input_mux = &alc880_capture_source, 4201 .input_mux = &alc880_capture_source,
4082 .unsol_event = alc880_uniwill_p53_unsol_event, 4202 .unsol_event = alc880_uniwill_p53_unsol_event,
4083 .init_hook = alc880_uniwill_p53_init_hook, 4203 .setup = alc880_uniwill_p53_setup,
4204 .init_hook = alc_automute_amp,
4084 }, 4205 },
4085 [ALC880_CLEVO] = { 4206 [ALC880_CLEVO] = {
4086 .mixers = { alc880_three_stack_mixer }, 4207 .mixers = { alc880_three_stack_mixer },
@@ -4106,7 +4227,8 @@ static struct alc_config_preset alc880_presets[] = {
4106 .need_dac_fix = 1, 4227 .need_dac_fix = 1,
4107 .input_mux = &alc880_lg_capture_source, 4228 .input_mux = &alc880_lg_capture_source,
4108 .unsol_event = alc_automute_amp_unsol_event, 4229 .unsol_event = alc_automute_amp_unsol_event,
4109 .init_hook = alc880_lg_init_hook, 4230 .setup = alc880_lg_setup,
4231 .init_hook = alc_automute_amp,
4110#ifdef CONFIG_SND_HDA_POWER_SAVE 4232#ifdef CONFIG_SND_HDA_POWER_SAVE
4111 .loopbacks = alc880_lg_loopbacks, 4233 .loopbacks = alc880_lg_loopbacks,
4112#endif 4234#endif
@@ -4122,7 +4244,8 @@ static struct alc_config_preset alc880_presets[] = {
4122 .channel_mode = alc880_lg_lw_modes, 4244 .channel_mode = alc880_lg_lw_modes,
4123 .input_mux = &alc880_lg_lw_capture_source, 4245 .input_mux = &alc880_lg_lw_capture_source,
4124 .unsol_event = alc_automute_amp_unsol_event, 4246 .unsol_event = alc_automute_amp_unsol_event,
4125 .init_hook = alc880_lg_lw_init_hook, 4247 .setup = alc880_lg_lw_setup,
4248 .init_hook = alc_automute_amp,
4126 }, 4249 },
4127 [ALC880_MEDION_RIM] = { 4250 [ALC880_MEDION_RIM] = {
4128 .mixers = { alc880_medion_rim_mixer }, 4251 .mixers = { alc880_medion_rim_mixer },
@@ -4136,7 +4259,8 @@ static struct alc_config_preset alc880_presets[] = {
4136 .channel_mode = alc880_2_jack_modes, 4259 .channel_mode = alc880_2_jack_modes,
4137 .input_mux = &alc880_medion_rim_capture_source, 4260 .input_mux = &alc880_medion_rim_capture_source,
4138 .unsol_event = alc880_medion_rim_unsol_event, 4261 .unsol_event = alc880_medion_rim_unsol_event,
4139 .init_hook = alc880_medion_rim_init_hook, 4262 .setup = alc880_medion_rim_setup,
4263 .init_hook = alc880_medion_rim_automute,
4140 }, 4264 },
4141#ifdef CONFIG_SND_DEBUG 4265#ifdef CONFIG_SND_DEBUG
4142 [ALC880_TEST] = { 4266 [ALC880_TEST] = {
@@ -4189,8 +4313,6 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
4189#define alc880_fixed_pin_idx(nid) ((nid) - 0x14) 4313#define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
4190#define alc880_is_multi_pin(nid) ((nid) >= 0x18) 4314#define alc880_is_multi_pin(nid) ((nid) >= 0x18)
4191#define alc880_multi_pin_idx(nid) ((nid) - 0x18) 4315#define alc880_multi_pin_idx(nid) ((nid) - 0x18)
4192#define alc880_is_input_pin(nid) ((nid) >= 0x18)
4193#define alc880_input_pin_idx(nid) ((nid) - 0x18)
4194#define alc880_idx_to_dac(nid) ((nid) + 0x02) 4316#define alc880_idx_to_dac(nid) ((nid) + 0x02)
4195#define alc880_dac_to_idx(nid) ((nid) - 0x02) 4317#define alc880_dac_to_idx(nid) ((nid) - 0x02)
4196#define alc880_idx_to_mixer(nid) ((nid) + 0x0c) 4318#define alc880_idx_to_mixer(nid) ((nid) + 0x0c)
@@ -4278,13 +4400,19 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4278 if (err < 0) 4400 if (err < 0)
4279 return err; 4401 return err;
4280 } else { 4402 } else {
4281 sprintf(name, "%s Playback Volume", chname[i]); 4403 const char *pfx;
4404 if (cfg->line_outs == 1 &&
4405 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4406 pfx = "Speaker";
4407 else
4408 pfx = chname[i];
4409 sprintf(name, "%s Playback Volume", pfx);
4282 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 4410 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4283 HDA_COMPOSE_AMP_VAL(nid, 3, 0, 4411 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4284 HDA_OUTPUT)); 4412 HDA_OUTPUT));
4285 if (err < 0) 4413 if (err < 0)
4286 return err; 4414 return err;
4287 sprintf(name, "%s Playback Switch", chname[i]); 4415 sprintf(name, "%s Playback Switch", pfx);
4288 err = add_control(spec, ALC_CTL_BIND_MUTE, name, 4416 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4289 HDA_COMPOSE_AMP_VAL(nid, 3, 2, 4417 HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4290 HDA_INPUT)); 4418 HDA_INPUT));
@@ -4358,31 +4486,61 @@ static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4358 return 0; 4486 return 0;
4359} 4487}
4360 4488
4489static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
4490{
4491 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
4492 return (pincap & AC_PINCAP_IN) != 0;
4493}
4494
4361/* create playback/capture controls for input pins */ 4495/* create playback/capture controls for input pins */
4362static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec, 4496static int alc_auto_create_input_ctls(struct hda_codec *codec,
4363 const struct auto_pin_cfg *cfg) 4497 const struct auto_pin_cfg *cfg,
4498 hda_nid_t mixer,
4499 hda_nid_t cap1, hda_nid_t cap2)
4364{ 4500{
4501 struct alc_spec *spec = codec->spec;
4365 struct hda_input_mux *imux = &spec->private_imux[0]; 4502 struct hda_input_mux *imux = &spec->private_imux[0];
4366 int i, err, idx; 4503 int i, err, idx;
4367 4504
4368 for (i = 0; i < AUTO_PIN_LAST; i++) { 4505 for (i = 0; i < AUTO_PIN_LAST; i++) {
4369 if (alc880_is_input_pin(cfg->input_pins[i])) { 4506 hda_nid_t pin;
4370 idx = alc880_input_pin_idx(cfg->input_pins[i]); 4507
4371 err = new_analog_input(spec, cfg->input_pins[i], 4508 pin = cfg->input_pins[i];
4372 auto_pin_cfg_labels[i], 4509 if (!alc_is_input_pin(codec, pin))
4373 idx, 0x0b); 4510 continue;
4374 if (err < 0) 4511
4375 return err; 4512 if (mixer) {
4513 idx = get_connection_index(codec, mixer, pin);
4514 if (idx >= 0) {
4515 err = new_analog_input(spec, pin,
4516 auto_pin_cfg_labels[i],
4517 idx, mixer);
4518 if (err < 0)
4519 return err;
4520 }
4521 }
4522
4523 if (!cap1)
4524 continue;
4525 idx = get_connection_index(codec, cap1, pin);
4526 if (idx < 0 && cap2)
4527 idx = get_connection_index(codec, cap2, pin);
4528 if (idx >= 0) {
4376 imux->items[imux->num_items].label = 4529 imux->items[imux->num_items].label =
4377 auto_pin_cfg_labels[i]; 4530 auto_pin_cfg_labels[i];
4378 imux->items[imux->num_items].index = 4531 imux->items[imux->num_items].index = idx;
4379 alc880_input_pin_idx(cfg->input_pins[i]);
4380 imux->num_items++; 4532 imux->num_items++;
4381 } 4533 }
4382 } 4534 }
4383 return 0; 4535 return 0;
4384} 4536}
4385 4537
4538static int alc880_auto_create_input_ctls(struct hda_codec *codec,
4539 const struct auto_pin_cfg *cfg)
4540{
4541 return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
4542}
4543
4386static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, 4544static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4387 unsigned int pin_type) 4545 unsigned int pin_type)
4388{ 4546{
@@ -4448,7 +4606,7 @@ static void alc880_auto_init_analog_input(struct hda_codec *codec)
4448 4606
4449 for (i = 0; i < AUTO_PIN_LAST; i++) { 4607 for (i = 0; i < AUTO_PIN_LAST; i++) {
4450 hda_nid_t nid = spec->autocfg.input_pins[i]; 4608 hda_nid_t nid = spec->autocfg.input_pins[i];
4451 if (alc880_is_input_pin(nid)) { 4609 if (alc_is_input_pin(codec, nid)) {
4452 alc_set_input_pin(codec, nid, i); 4610 alc_set_input_pin(codec, nid, i);
4453 if (nid != ALC880_PIN_CD_NID && 4611 if (nid != ALC880_PIN_CD_NID &&
4454 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 4612 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -4491,7 +4649,7 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
4491 "Headphone"); 4649 "Headphone");
4492 if (err < 0) 4650 if (err < 0)
4493 return err; 4651 return err;
4494 err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg); 4652 err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4495 if (err < 0) 4653 if (err < 0)
4496 return err; 4654 return err;
4497 4655
@@ -4541,8 +4699,42 @@ static void alc880_auto_init(struct hda_codec *codec)
4541 alc_inithook(codec); 4699 alc_inithook(codec);
4542} 4700}
4543 4701
4544static void set_capture_mixer(struct alc_spec *spec) 4702/* check the ADC/MUX contains all input pins; some ADC/MUX contains only
4703 * one of two digital mic pins, e.g. on ALC272
4704 */
4705static void fixup_automic_adc(struct hda_codec *codec)
4706{
4707 struct alc_spec *spec = codec->spec;
4708 int i;
4709
4710 for (i = 0; i < spec->num_adc_nids; i++) {
4711 hda_nid_t cap = spec->capsrc_nids ?
4712 spec->capsrc_nids[i] : spec->adc_nids[i];
4713 int iidx, eidx;
4714
4715 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
4716 if (iidx < 0)
4717 continue;
4718 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
4719 if (eidx < 0)
4720 continue;
4721 spec->int_mic.mux_idx = iidx;
4722 spec->ext_mic.mux_idx = eidx;
4723 if (spec->capsrc_nids)
4724 spec->capsrc_nids += i;
4725 spec->adc_nids += i;
4726 spec->num_adc_nids = 1;
4727 return;
4728 }
4729 snd_printd(KERN_INFO "hda_codec: %s: "
4730 "No ADC/MUX containing both 0x%x and 0x%x pins\n",
4731 codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
4732 spec->auto_mic = 0; /* disable auto-mic to be sure */
4733}
4734
4735static void set_capture_mixer(struct hda_codec *codec)
4545{ 4736{
4737 struct alc_spec *spec = codec->spec;
4546 static struct snd_kcontrol_new *caps[2][3] = { 4738 static struct snd_kcontrol_new *caps[2][3] = {
4547 { alc_capture_mixer_nosrc1, 4739 { alc_capture_mixer_nosrc1,
4548 alc_capture_mixer_nosrc2, 4740 alc_capture_mixer_nosrc2,
@@ -4553,7 +4745,10 @@ static void set_capture_mixer(struct alc_spec *spec)
4553 }; 4745 };
4554 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) { 4746 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4555 int mux; 4747 int mux;
4556 if (spec->input_mux && spec->input_mux->num_items > 1) 4748 if (spec->auto_mic) {
4749 mux = 0;
4750 fixup_automic_adc(codec);
4751 } else if (spec->input_mux && spec->input_mux->num_items > 1)
4557 mux = 1; 4752 mux = 1;
4558 else 4753 else
4559 mux = 0; 4754 mux = 0;
@@ -4584,8 +4779,8 @@ static int patch_alc880(struct hda_codec *codec)
4584 alc880_models, 4779 alc880_models,
4585 alc880_cfg_tbl); 4780 alc880_cfg_tbl);
4586 if (board_config < 0) { 4781 if (board_config < 0) {
4587 printk(KERN_INFO "hda_codec: Unknown model for %s, " 4782 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4588 "trying auto-probe from BIOS...\n", codec->chip_name); 4783 codec->chip_name);
4589 board_config = ALC880_AUTO; 4784 board_config = ALC880_AUTO;
4590 } 4785 }
4591 4786
@@ -4610,7 +4805,7 @@ static int patch_alc880(struct hda_codec *codec)
4610 } 4805 }
4611 4806
4612 if (board_config != ALC880_AUTO) 4807 if (board_config != ALC880_AUTO)
4613 setup_preset(spec, &alc880_presets[board_config]); 4808 setup_preset(codec, &alc880_presets[board_config]);
4614 4809
4615 spec->stream_analog_playback = &alc880_pcm_analog_playback; 4810 spec->stream_analog_playback = &alc880_pcm_analog_playback;
4616 spec->stream_analog_capture = &alc880_pcm_analog_capture; 4811 spec->stream_analog_capture = &alc880_pcm_analog_capture;
@@ -4623,7 +4818,7 @@ static int patch_alc880(struct hda_codec *codec)
4623 /* check whether NID 0x07 is valid */ 4818 /* check whether NID 0x07 is valid */
4624 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]); 4819 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4625 /* get type */ 4820 /* get type */
4626 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 4821 wcap = get_wcaps_type(wcap);
4627 if (wcap != AC_WID_AUD_IN) { 4822 if (wcap != AC_WID_AUD_IN) {
4628 spec->adc_nids = alc880_adc_nids_alt; 4823 spec->adc_nids = alc880_adc_nids_alt;
4629 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt); 4824 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
@@ -4632,7 +4827,7 @@ static int patch_alc880(struct hda_codec *codec)
4632 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids); 4827 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4633 } 4828 }
4634 } 4829 }
4635 set_capture_mixer(spec); 4830 set_capture_mixer(codec);
4636 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 4831 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4637 4832
4638 spec->vmaster_nid = 0x0c; 4833 spec->vmaster_nid = 0x0c;
@@ -5824,7 +6019,14 @@ static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5824 6019
5825 nid = cfg->line_out_pins[0]; 6020 nid = cfg->line_out_pins[0];
5826 if (nid) { 6021 if (nid) {
5827 err = alc260_add_playback_controls(spec, nid, "Front", &vols); 6022 const char *pfx;
6023 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
6024 pfx = "Master";
6025 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
6026 pfx = "Speaker";
6027 else
6028 pfx = "Front";
6029 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
5828 if (err < 0) 6030 if (err < 0)
5829 return err; 6031 return err;
5830 } 6032 }
@@ -5847,39 +6049,10 @@ static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5847} 6049}
5848 6050
5849/* create playback/capture controls for input pins */ 6051/* create playback/capture controls for input pins */
5850static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec, 6052static int alc260_auto_create_input_ctls(struct hda_codec *codec,
5851 const struct auto_pin_cfg *cfg) 6053 const struct auto_pin_cfg *cfg)
5852{ 6054{
5853 struct hda_input_mux *imux = &spec->private_imux[0]; 6055 return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
5854 int i, err, idx;
5855
5856 for (i = 0; i < AUTO_PIN_LAST; i++) {
5857 if (cfg->input_pins[i] >= 0x12) {
5858 idx = cfg->input_pins[i] - 0x12;
5859 err = new_analog_input(spec, cfg->input_pins[i],
5860 auto_pin_cfg_labels[i], idx,
5861 0x07);
5862 if (err < 0)
5863 return err;
5864 imux->items[imux->num_items].label =
5865 auto_pin_cfg_labels[i];
5866 imux->items[imux->num_items].index = idx;
5867 imux->num_items++;
5868 }
5869 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5870 idx = cfg->input_pins[i] - 0x09;
5871 err = new_analog_input(spec, cfg->input_pins[i],
5872 auto_pin_cfg_labels[i], idx,
5873 0x07);
5874 if (err < 0)
5875 return err;
5876 imux->items[imux->num_items].label =
5877 auto_pin_cfg_labels[i];
5878 imux->items[imux->num_items].index = idx;
5879 imux->num_items++;
5880 }
5881 }
5882 return 0;
5883} 6056}
5884 6057
5885static void alc260_auto_set_output_and_unmute(struct hda_codec *codec, 6058static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
@@ -5993,7 +6166,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
5993 return err; 6166 return err;
5994 if (!spec->kctls.list) 6167 if (!spec->kctls.list)
5995 return 0; /* can't find valid BIOS pin config */ 6168 return 0; /* can't find valid BIOS pin config */
5996 err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg); 6169 err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
5997 if (err < 0) 6170 if (err < 0)
5998 return err; 6171 return err;
5999 6172
@@ -6228,8 +6401,7 @@ static int patch_alc260(struct hda_codec *codec)
6228 alc260_models, 6401 alc260_models,
6229 alc260_cfg_tbl); 6402 alc260_cfg_tbl);
6230 if (board_config < 0) { 6403 if (board_config < 0) {
6231 snd_printd(KERN_INFO "hda_codec: Unknown model for %s, " 6404 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6232 "trying auto-probe from BIOS...\n",
6233 codec->chip_name); 6405 codec->chip_name);
6234 board_config = ALC260_AUTO; 6406 board_config = ALC260_AUTO;
6235 } 6407 }
@@ -6255,7 +6427,7 @@ static int patch_alc260(struct hda_codec *codec)
6255 } 6427 }
6256 6428
6257 if (board_config != ALC260_AUTO) 6429 if (board_config != ALC260_AUTO)
6258 setup_preset(spec, &alc260_presets[board_config]); 6430 setup_preset(codec, &alc260_presets[board_config]);
6259 6431
6260 spec->stream_analog_playback = &alc260_pcm_analog_playback; 6432 spec->stream_analog_playback = &alc260_pcm_analog_playback;
6261 spec->stream_analog_capture = &alc260_pcm_analog_capture; 6433 spec->stream_analog_capture = &alc260_pcm_analog_capture;
@@ -6266,7 +6438,7 @@ static int patch_alc260(struct hda_codec *codec)
6266 if (!spec->adc_nids && spec->input_mux) { 6438 if (!spec->adc_nids && spec->input_mux) {
6267 /* check whether NID 0x04 is valid */ 6439 /* check whether NID 0x04 is valid */
6268 unsigned int wcap = get_wcaps(codec, 0x04); 6440 unsigned int wcap = get_wcaps(codec, 0x04);
6269 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 6441 wcap = get_wcaps_type(wcap);
6270 /* get type */ 6442 /* get type */
6271 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) { 6443 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6272 spec->adc_nids = alc260_adc_nids_alt; 6444 spec->adc_nids = alc260_adc_nids_alt;
@@ -6276,7 +6448,7 @@ static int patch_alc260(struct hda_codec *codec)
6276 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids); 6448 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6277 } 6449 }
6278 } 6450 }
6279 set_capture_mixer(spec); 6451 set_capture_mixer(codec);
6280 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); 6452 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6281 6453
6282 spec->vmaster_nid = 0x08; 6454 spec->vmaster_nid = 0x08;
@@ -6295,7 +6467,7 @@ static int patch_alc260(struct hda_codec *codec)
6295 6467
6296 6468
6297/* 6469/*
6298 * ALC882 support 6470 * ALC882/883/885/888/889 support
6299 * 6471 *
6300 * ALC882 is almost identical with ALC880 but has cleaner and more flexible 6472 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6301 * configuration. Each pin widget can choose any input DACs and a mixer. 6473 * configuration. Each pin widget can choose any input DACs and a mixer.
@@ -6307,22 +6479,35 @@ static int patch_alc260(struct hda_codec *codec)
6307 */ 6479 */
6308#define ALC882_DIGOUT_NID 0x06 6480#define ALC882_DIGOUT_NID 0x06
6309#define ALC882_DIGIN_NID 0x0a 6481#define ALC882_DIGIN_NID 0x0a
6482#define ALC883_DIGOUT_NID ALC882_DIGOUT_NID
6483#define ALC883_DIGIN_NID ALC882_DIGIN_NID
6484#define ALC1200_DIGOUT_NID 0x10
6485
6310 6486
6311static struct hda_channel_mode alc882_ch_modes[1] = { 6487static struct hda_channel_mode alc882_ch_modes[1] = {
6312 { 8, NULL } 6488 { 8, NULL }
6313}; 6489};
6314 6490
6491/* DACs */
6315static hda_nid_t alc882_dac_nids[4] = { 6492static hda_nid_t alc882_dac_nids[4] = {
6316 /* front, rear, clfe, rear_surr */ 6493 /* front, rear, clfe, rear_surr */
6317 0x02, 0x03, 0x04, 0x05 6494 0x02, 0x03, 0x04, 0x05
6318}; 6495};
6496#define alc883_dac_nids alc882_dac_nids
6319 6497
6320/* identical with ALC880 */ 6498/* ADCs */
6321#define alc882_adc_nids alc880_adc_nids 6499#define alc882_adc_nids alc880_adc_nids
6322#define alc882_adc_nids_alt alc880_adc_nids_alt 6500#define alc882_adc_nids_alt alc880_adc_nids_alt
6501#define alc883_adc_nids alc882_adc_nids_alt
6502static hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
6503static hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
6504#define alc889_adc_nids alc880_adc_nids
6323 6505
6324static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 }; 6506static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6325static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 }; 6507static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6508#define alc883_capsrc_nids alc882_capsrc_nids_alt
6509static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
6510#define alc889_capsrc_nids alc882_capsrc_nids
6326 6511
6327/* input MUX */ 6512/* input MUX */
6328/* FIXME: should be a matrix-type input source selection */ 6513/* FIXME: should be a matrix-type input source selection */
@@ -6337,6 +6522,17 @@ static struct hda_input_mux alc882_capture_source = {
6337 }, 6522 },
6338}; 6523};
6339 6524
6525#define alc883_capture_source alc882_capture_source
6526
6527static struct hda_input_mux alc889_capture_source = {
6528 .num_items = 3,
6529 .items = {
6530 { "Front Mic", 0x0 },
6531 { "Mic", 0x3 },
6532 { "Line", 0x2 },
6533 },
6534};
6535
6340static struct hda_input_mux mb5_capture_source = { 6536static struct hda_input_mux mb5_capture_source = {
6341 .num_items = 3, 6537 .num_items = 3,
6342 .items = { 6538 .items = {
@@ -6346,6 +6542,77 @@ static struct hda_input_mux mb5_capture_source = {
6346 }, 6542 },
6347}; 6543};
6348 6544
6545static struct hda_input_mux alc883_3stack_6ch_intel = {
6546 .num_items = 4,
6547 .items = {
6548 { "Mic", 0x1 },
6549 { "Front Mic", 0x0 },
6550 { "Line", 0x2 },
6551 { "CD", 0x4 },
6552 },
6553};
6554
6555static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6556 .num_items = 2,
6557 .items = {
6558 { "Mic", 0x1 },
6559 { "Line", 0x2 },
6560 },
6561};
6562
6563static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6564 .num_items = 4,
6565 .items = {
6566 { "Mic", 0x0 },
6567 { "iMic", 0x1 },
6568 { "Line", 0x2 },
6569 { "CD", 0x4 },
6570 },
6571};
6572
6573static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6574 .num_items = 2,
6575 .items = {
6576 { "Mic", 0x0 },
6577 { "Int Mic", 0x1 },
6578 },
6579};
6580
6581static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6582 .num_items = 3,
6583 .items = {
6584 { "Mic", 0x0 },
6585 { "Front Mic", 0x1 },
6586 { "Line", 0x4 },
6587 },
6588};
6589
6590static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6591 .num_items = 2,
6592 .items = {
6593 { "Mic", 0x0 },
6594 { "Line", 0x2 },
6595 },
6596};
6597
6598static struct hda_input_mux alc889A_mb31_capture_source = {
6599 .num_items = 2,
6600 .items = {
6601 { "Mic", 0x0 },
6602 /* Front Mic (0x01) unused */
6603 { "Line", 0x2 },
6604 /* Line 2 (0x03) unused */
6605 /* CD (0x04) unsused? */
6606 },
6607};
6608
6609/*
6610 * 2ch mode
6611 */
6612static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6613 { 2, NULL }
6614};
6615
6349/* 6616/*
6350 * 2ch mode 6617 * 2ch mode
6351 */ 6618 */
@@ -6358,6 +6625,18 @@ static struct hda_verb alc882_3ST_ch2_init[] = {
6358}; 6625};
6359 6626
6360/* 6627/*
6628 * 4ch mode
6629 */
6630static struct hda_verb alc882_3ST_ch4_init[] = {
6631 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6632 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6633 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6634 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6635 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6636 { } /* end */
6637};
6638
6639/*
6361 * 6ch mode 6640 * 6ch mode
6362 */ 6641 */
6363static struct hda_verb alc882_3ST_ch6_init[] = { 6642static struct hda_verb alc882_3ST_ch6_init[] = {
@@ -6370,11 +6649,60 @@ static struct hda_verb alc882_3ST_ch6_init[] = {
6370 { } /* end */ 6649 { } /* end */
6371}; 6650};
6372 6651
6373static struct hda_channel_mode alc882_3ST_6ch_modes[2] = { 6652static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6374 { 2, alc882_3ST_ch2_init }, 6653 { 2, alc882_3ST_ch2_init },
6654 { 4, alc882_3ST_ch4_init },
6375 { 6, alc882_3ST_ch6_init }, 6655 { 6, alc882_3ST_ch6_init },
6376}; 6656};
6377 6657
6658#define alc883_3ST_6ch_modes alc882_3ST_6ch_modes
6659
6660/*
6661 * 2ch mode
6662 */
6663static struct hda_verb alc883_3ST_ch2_clevo_init[] = {
6664 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
6665 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6666 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6667 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6668 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6669 { } /* end */
6670};
6671
6672/*
6673 * 4ch mode
6674 */
6675static struct hda_verb alc883_3ST_ch4_clevo_init[] = {
6676 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6677 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6678 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6679 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6680 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6681 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6682 { } /* end */
6683};
6684
6685/*
6686 * 6ch mode
6687 */
6688static struct hda_verb alc883_3ST_ch6_clevo_init[] = {
6689 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6690 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6691 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6692 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6693 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6694 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6695 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6696 { } /* end */
6697};
6698
6699static struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
6700 { 2, alc883_3ST_ch2_clevo_init },
6701 { 4, alc883_3ST_ch4_clevo_init },
6702 { 6, alc883_3ST_ch6_clevo_init },
6703};
6704
6705
6378/* 6706/*
6379 * 6ch mode 6707 * 6ch mode
6380 */ 6708 */
@@ -6417,9 +6745,9 @@ static struct hda_verb alc885_mbp_ch2_init[] = {
6417}; 6745};
6418 6746
6419/* 6747/*
6420 * 6ch mode 6748 * 4ch mode
6421 */ 6749 */
6422static struct hda_verb alc885_mbp_ch6_init[] = { 6750static struct hda_verb alc885_mbp_ch4_init[] = {
6423 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, 6751 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6424 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 6752 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6425 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 }, 6753 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
@@ -6428,9 +6756,9 @@ static struct hda_verb alc885_mbp_ch6_init[] = {
6428 { } /* end */ 6756 { } /* end */
6429}; 6757};
6430 6758
6431static struct hda_channel_mode alc885_mbp_6ch_modes[2] = { 6759static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
6432 { 2, alc885_mbp_ch2_init }, 6760 { 2, alc885_mbp_ch2_init },
6433 { 6, alc885_mbp_ch6_init }, 6761 { 4, alc885_mbp_ch4_init },
6434}; 6762};
6435 6763
6436/* 6764/*
@@ -6462,6 +6790,189 @@ static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6462 { 6, alc885_mb5_ch6_init }, 6790 { 6, alc885_mb5_ch6_init },
6463}; 6791};
6464 6792
6793
6794/*
6795 * 2ch mode
6796 */
6797static struct hda_verb alc883_4ST_ch2_init[] = {
6798 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6799 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6800 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6801 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6802 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6803 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6804 { } /* end */
6805};
6806
6807/*
6808 * 4ch mode
6809 */
6810static struct hda_verb alc883_4ST_ch4_init[] = {
6811 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6812 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6813 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6814 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6815 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6816 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6817 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6818 { } /* end */
6819};
6820
6821/*
6822 * 6ch mode
6823 */
6824static struct hda_verb alc883_4ST_ch6_init[] = {
6825 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6826 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6827 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6828 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6829 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6830 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6831 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6832 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6833 { } /* end */
6834};
6835
6836/*
6837 * 8ch mode
6838 */
6839static struct hda_verb alc883_4ST_ch8_init[] = {
6840 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6841 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6842 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6843 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6844 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6845 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6846 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6847 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6848 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6849 { } /* end */
6850};
6851
6852static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
6853 { 2, alc883_4ST_ch2_init },
6854 { 4, alc883_4ST_ch4_init },
6855 { 6, alc883_4ST_ch6_init },
6856 { 8, alc883_4ST_ch8_init },
6857};
6858
6859
6860/*
6861 * 2ch mode
6862 */
6863static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6864 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6865 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6866 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6867 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6868 { } /* end */
6869};
6870
6871/*
6872 * 4ch mode
6873 */
6874static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6875 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6876 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6877 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6878 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6879 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6880 { } /* end */
6881};
6882
6883/*
6884 * 6ch mode
6885 */
6886static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6887 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6888 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6889 { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6890 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6891 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6892 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6893 { } /* end */
6894};
6895
6896static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6897 { 2, alc883_3ST_ch2_intel_init },
6898 { 4, alc883_3ST_ch4_intel_init },
6899 { 6, alc883_3ST_ch6_intel_init },
6900};
6901
6902/*
6903 * 2ch mode
6904 */
6905static struct hda_verb alc889_ch2_intel_init[] = {
6906 { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6907 { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
6908 { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
6909 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
6910 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6911 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6912 { } /* end */
6913};
6914
6915/*
6916 * 6ch mode
6917 */
6918static struct hda_verb alc889_ch6_intel_init[] = {
6919 { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6920 { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6921 { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6922 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6923 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6924 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6925 { } /* end */
6926};
6927
6928/*
6929 * 8ch mode
6930 */
6931static struct hda_verb alc889_ch8_intel_init[] = {
6932 { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6933 { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6934 { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6935 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6936 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
6937 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6938 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6939 { } /* end */
6940};
6941
6942static struct hda_channel_mode alc889_8ch_intel_modes[3] = {
6943 { 2, alc889_ch2_intel_init },
6944 { 6, alc889_ch6_intel_init },
6945 { 8, alc889_ch8_intel_init },
6946};
6947
6948/*
6949 * 6ch mode
6950 */
6951static struct hda_verb alc883_sixstack_ch6_init[] = {
6952 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6953 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6954 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6955 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6956 { } /* end */
6957};
6958
6959/*
6960 * 8ch mode
6961 */
6962static struct hda_verb alc883_sixstack_ch8_init[] = {
6963 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6964 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6965 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6966 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6967 { } /* end */
6968};
6969
6970static struct hda_channel_mode alc883_sixstack_modes[2] = {
6971 { 6, alc883_sixstack_ch6_init },
6972 { 8, alc883_sixstack_ch8_init },
6973};
6974
6975
6465/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17 6976/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6466 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b 6977 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6467 */ 6978 */
@@ -6491,10 +7002,11 @@ static struct snd_kcontrol_new alc882_base_mixer[] = {
6491}; 7002};
6492 7003
6493static struct snd_kcontrol_new alc885_mbp3_mixer[] = { 7004static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6494 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT), 7005 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6495 HDA_BIND_MUTE ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT), 7006 HDA_BIND_MUTE ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
6496 HDA_CODEC_MUTE ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT), 7007 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
6497 HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT), 7008 HDA_BIND_MUTE ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
7009 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6498 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 7010 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6499 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 7011 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6500 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT), 7012 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
@@ -6597,7 +7109,7 @@ static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6597 { } /* end */ 7109 { } /* end */
6598}; 7110};
6599 7111
6600static struct hda_verb alc882_init_verbs[] = { 7112static struct hda_verb alc882_base_init_verbs[] = {
6601 /* Front mixer: unmute input/output amp left and right (volume = 0) */ 7113 /* Front mixer: unmute input/output amp left and right (volume = 0) */
6602 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 7114 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6603 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7115 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
@@ -6615,6 +7127,13 @@ static struct hda_verb alc882_init_verbs[] = {
6615 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7127 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6616 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 7128 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6617 7129
7130 /* mute analog input loopbacks */
7131 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7132 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7133 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7134 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7135 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7136
6618 /* Front Pin: output 0 (0x0c) */ 7137 /* Front Pin: output 0 (0x0c) */
6619 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7138 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6620 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 7139 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -6649,11 +7168,6 @@ static struct hda_verb alc882_init_verbs[] = {
6649 7168
6650 /* FIXME: use matrix-type input source selection */ 7169 /* FIXME: use matrix-type input source selection */
6651 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */ 7170 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6652 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6653 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6654 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6655 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6656 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6657 /* Input mixer2 */ 7171 /* Input mixer2 */
6658 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7172 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6659 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 7173 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
@@ -6664,9 +7178,6 @@ static struct hda_verb alc882_init_verbs[] = {
6664 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 7178 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6665 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 7179 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6666 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 7180 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6667 /* ADC1: mute amp left and right */
6668 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6669 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6670 /* ADC2: mute amp left and right */ 7181 /* ADC2: mute amp left and right */
6671 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7182 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6672 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, 7183 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -6677,6 +7188,18 @@ static struct hda_verb alc882_init_verbs[] = {
6677 { } 7188 { }
6678}; 7189};
6679 7190
7191static struct hda_verb alc882_adc1_init_verbs[] = {
7192 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7193 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7194 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7195 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7196 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7197 /* ADC1: mute amp left and right */
7198 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7199 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7200 { }
7201};
7202
6680static struct hda_verb alc882_eapd_verbs[] = { 7203static struct hda_verb alc882_eapd_verbs[] = {
6681 /* change to EAPD mode */ 7204 /* change to EAPD mode */
6682 {0x20, AC_VERB_SET_COEF_INDEX, 0x07}, 7205 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
@@ -6684,6 +7207,110 @@ static struct hda_verb alc882_eapd_verbs[] = {
6684 { } 7207 { }
6685}; 7208};
6686 7209
7210static struct hda_verb alc889_eapd_verbs[] = {
7211 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
7212 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
7213 { }
7214};
7215
7216static struct hda_verb alc_hp15_unsol_verbs[] = {
7217 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7218 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7219 {}
7220};
7221
7222static struct hda_verb alc885_init_verbs[] = {
7223 /* Front mixer: unmute input/output amp left and right (volume = 0) */
7224 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7225 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7226 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7227 /* Rear mixer */
7228 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7229 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7230 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7231 /* CLFE mixer */
7232 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7233 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7234 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7235 /* Side mixer */
7236 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7237 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7238 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7239
7240 /* mute analog input loopbacks */
7241 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7242 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7243 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7244
7245 /* Front HP Pin: output 0 (0x0c) */
7246 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7247 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7248 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7249 /* Front Pin: output 0 (0x0c) */
7250 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7251 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7252 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7253 /* Rear Pin: output 1 (0x0d) */
7254 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7255 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7256 {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
7257 /* CLFE Pin: output 2 (0x0e) */
7258 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7259 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7260 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7261 /* Side Pin: output 3 (0x0f) */
7262 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7263 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7264 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7265 /* Mic (rear) pin: input vref at 80% */
7266 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7267 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7268 /* Front Mic pin: input vref at 80% */
7269 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7270 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7271 /* Line In pin: input */
7272 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7273 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7274
7275 /* Mixer elements: 0x18, , 0x1a, 0x1b */
7276 /* Input mixer1 */
7277 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7278 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7279 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7280 /* Input mixer2 */
7281 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7282 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7283 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7284 /* Input mixer3 */
7285 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7286 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7287 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7288 /* ADC2: mute amp left and right */
7289 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7290 /* ADC3: mute amp left and right */
7291 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7292
7293 { }
7294};
7295
7296static struct hda_verb alc885_init_input_verbs[] = {
7297 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7298 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7299 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7300 { }
7301};
7302
7303
7304/* Unmute Selector 24h and set the default input to front mic */
7305static struct hda_verb alc889_init_input_verbs[] = {
7306 {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
7307 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7308 { }
7309};
7310
7311
7312#define alc883_init_verbs alc882_base_init_verbs
7313
6687/* Mac Pro test */ 7314/* Mac Pro test */
6688static struct snd_kcontrol_new alc882_macpro_mixer[] = { 7315static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6689 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7316 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -6808,14 +7435,18 @@ static struct hda_verb alc885_mbp3_init_verbs[] = {
6808 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 7435 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6809 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7436 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6810 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 7437 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7438 /* HP mixer */
7439 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7440 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7441 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6811 /* Front Pin: output 0 (0x0c) */ 7442 /* Front Pin: output 0 (0x0c) */
6812 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7443 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6813 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 7444 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6814 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, 7445 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6815 /* HP Pin: output 0 (0x0d) */ 7446 /* HP Pin: output 0 (0x0e) */
6816 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4}, 7447 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6817 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 7448 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6818 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 7449 {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
6819 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 7450 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6820 /* Mic (rear) pin: input vref at 80% */ 7451 /* Mic (rear) pin: input vref at 80% */
6821 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 7452 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
@@ -6887,23 +7518,21 @@ static struct hda_verb alc885_imac24_init_verbs[] = {
6887}; 7518};
6888 7519
6889/* Toggle speaker-output according to the hp-jack state */ 7520/* Toggle speaker-output according to the hp-jack state */
6890static void alc885_imac24_automute_init_hook(struct hda_codec *codec) 7521static void alc885_imac24_setup(struct hda_codec *codec)
6891{ 7522{
6892 struct alc_spec *spec = codec->spec; 7523 struct alc_spec *spec = codec->spec;
6893 7524
6894 spec->autocfg.hp_pins[0] = 0x14; 7525 spec->autocfg.hp_pins[0] = 0x14;
6895 spec->autocfg.speaker_pins[0] = 0x18; 7526 spec->autocfg.speaker_pins[0] = 0x18;
6896 spec->autocfg.speaker_pins[1] = 0x1a; 7527 spec->autocfg.speaker_pins[1] = 0x1a;
6897 alc_automute_amp(codec);
6898} 7528}
6899 7529
6900static void alc885_mbp3_init_hook(struct hda_codec *codec) 7530static void alc885_mbp3_setup(struct hda_codec *codec)
6901{ 7531{
6902 struct alc_spec *spec = codec->spec; 7532 struct alc_spec *spec = codec->spec;
6903 7533
6904 spec->autocfg.hp_pins[0] = 0x15; 7534 spec->autocfg.hp_pins[0] = 0x15;
6905 spec->autocfg.speaker_pins[0] = 0x14; 7535 spec->autocfg.speaker_pins[0] = 0x14;
6906 alc_automute_amp(codec);
6907} 7536}
6908 7537
6909 7538
@@ -6919,9 +7548,6 @@ static struct hda_verb alc882_targa_verbs[] = {
6919 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */ 7548 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6920 7549
6921 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 7550 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6922 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6923 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6924 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6925 { } /* end */ 7551 { } /* end */
6926}; 7552};
6927 7553
@@ -6934,13 +7560,12 @@ static void alc882_targa_automute(struct hda_codec *codec)
6934 spec->jack_present ? 1 : 3); 7560 spec->jack_present ? 1 : 3);
6935} 7561}
6936 7562
6937static void alc882_targa_init_hook(struct hda_codec *codec) 7563static void alc882_targa_setup(struct hda_codec *codec)
6938{ 7564{
6939 struct alc_spec *spec = codec->spec; 7565 struct alc_spec *spec = codec->spec;
6940 7566
6941 spec->autocfg.hp_pins[0] = 0x14; 7567 spec->autocfg.hp_pins[0] = 0x14;
6942 spec->autocfg.speaker_pins[0] = 0x1b; 7568 spec->autocfg.speaker_pins[0] = 0x1b;
6943 alc882_targa_automute(codec);
6944} 7569}
6945 7570
6946static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res) 7571static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
@@ -7028,18 +7653,16 @@ static void alc885_macpro_init_hook(struct hda_codec *codec)
7028static void alc885_imac24_init_hook(struct hda_codec *codec) 7653static void alc885_imac24_init_hook(struct hda_codec *codec)
7029{ 7654{
7030 alc885_macpro_init_hook(codec); 7655 alc885_macpro_init_hook(codec);
7031 alc885_imac24_automute_init_hook(codec); 7656 alc_automute_amp(codec);
7032} 7657}
7033 7658
7034/* 7659/*
7035 * generic initialization of ADC, input mixers and output mixers 7660 * generic initialization of ADC, input mixers and output mixers
7036 */ 7661 */
7037static struct hda_verb alc882_auto_init_verbs[] = { 7662static struct hda_verb alc883_auto_init_verbs[] = {
7038 /* 7663 /*
7039 * Unmute ADC0-2 and set the default input to mic-in 7664 * Unmute ADC0-2 and set the default input to mic-in
7040 */ 7665 */
7041 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7042 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7043 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, 7666 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7044 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7667 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7045 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00}, 7668 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -7080,11 +7703,6 @@ static struct hda_verb alc882_auto_init_verbs[] = {
7080 7703
7081 /* FIXME: use matrix-type input source selection */ 7704 /* FIXME: use matrix-type input source selection */
7082 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */ 7705 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7083 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7084 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7085 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7086 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7087 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7088 /* Input mixer2 */ 7706 /* Input mixer2 */
7089 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, 7707 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7090 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))}, 7708 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
@@ -7099,819 +7717,6 @@ static struct hda_verb alc882_auto_init_verbs[] = {
7099 { } 7717 { }
7100}; 7718};
7101 7719
7102#ifdef CONFIG_SND_HDA_POWER_SAVE
7103#define alc882_loopbacks alc880_loopbacks
7104#endif
7105
7106/* pcm configuration: identical with ALC880 */
7107#define alc882_pcm_analog_playback alc880_pcm_analog_playback
7108#define alc882_pcm_analog_capture alc880_pcm_analog_capture
7109#define alc882_pcm_digital_playback alc880_pcm_digital_playback
7110#define alc882_pcm_digital_capture alc880_pcm_digital_capture
7111
7112/*
7113 * configuration and preset
7114 */
7115static const char *alc882_models[ALC882_MODEL_LAST] = {
7116 [ALC882_3ST_DIG] = "3stack-dig",
7117 [ALC882_6ST_DIG] = "6stack-dig",
7118 [ALC882_ARIMA] = "arima",
7119 [ALC882_W2JC] = "w2jc",
7120 [ALC882_TARGA] = "targa",
7121 [ALC882_ASUS_A7J] = "asus-a7j",
7122 [ALC882_ASUS_A7M] = "asus-a7m",
7123 [ALC885_MACPRO] = "macpro",
7124 [ALC885_MB5] = "mb5",
7125 [ALC885_MBP3] = "mbp3",
7126 [ALC885_IMAC24] = "imac24",
7127 [ALC882_AUTO] = "auto",
7128};
7129
7130static struct snd_pci_quirk alc882_cfg_tbl[] = {
7131 SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
7132 SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
7133 SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
7134 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
7135 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
7136 SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
7137 SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
7138 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
7139 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
7140 SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8 */
7141 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
7142 SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
7143 {}
7144};
7145
7146static struct alc_config_preset alc882_presets[] = {
7147 [ALC882_3ST_DIG] = {
7148 .mixers = { alc882_base_mixer },
7149 .init_verbs = { alc882_init_verbs },
7150 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7151 .dac_nids = alc882_dac_nids,
7152 .dig_out_nid = ALC882_DIGOUT_NID,
7153 .dig_in_nid = ALC882_DIGIN_NID,
7154 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7155 .channel_mode = alc882_ch_modes,
7156 .need_dac_fix = 1,
7157 .input_mux = &alc882_capture_source,
7158 },
7159 [ALC882_6ST_DIG] = {
7160 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7161 .init_verbs = { alc882_init_verbs },
7162 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7163 .dac_nids = alc882_dac_nids,
7164 .dig_out_nid = ALC882_DIGOUT_NID,
7165 .dig_in_nid = ALC882_DIGIN_NID,
7166 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7167 .channel_mode = alc882_sixstack_modes,
7168 .input_mux = &alc882_capture_source,
7169 },
7170 [ALC882_ARIMA] = {
7171 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7172 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
7173 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7174 .dac_nids = alc882_dac_nids,
7175 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7176 .channel_mode = alc882_sixstack_modes,
7177 .input_mux = &alc882_capture_source,
7178 },
7179 [ALC882_W2JC] = {
7180 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
7181 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7182 alc880_gpio1_init_verbs },
7183 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7184 .dac_nids = alc882_dac_nids,
7185 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7186 .channel_mode = alc880_threestack_modes,
7187 .need_dac_fix = 1,
7188 .input_mux = &alc882_capture_source,
7189 .dig_out_nid = ALC882_DIGOUT_NID,
7190 },
7191 [ALC885_MBP3] = {
7192 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
7193 .init_verbs = { alc885_mbp3_init_verbs,
7194 alc880_gpio1_init_verbs },
7195 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7196 .dac_nids = alc882_dac_nids,
7197 .channel_mode = alc885_mbp_6ch_modes,
7198 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
7199 .input_mux = &alc882_capture_source,
7200 .dig_out_nid = ALC882_DIGOUT_NID,
7201 .dig_in_nid = ALC882_DIGIN_NID,
7202 .unsol_event = alc_automute_amp_unsol_event,
7203 .init_hook = alc885_mbp3_init_hook,
7204 },
7205 [ALC885_MB5] = {
7206 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
7207 .init_verbs = { alc885_mb5_init_verbs,
7208 alc880_gpio1_init_verbs },
7209 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7210 .dac_nids = alc882_dac_nids,
7211 .channel_mode = alc885_mb5_6ch_modes,
7212 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
7213 .input_mux = &mb5_capture_source,
7214 .dig_out_nid = ALC882_DIGOUT_NID,
7215 .dig_in_nid = ALC882_DIGIN_NID,
7216 },
7217 [ALC885_MACPRO] = {
7218 .mixers = { alc882_macpro_mixer },
7219 .init_verbs = { alc882_macpro_init_verbs },
7220 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7221 .dac_nids = alc882_dac_nids,
7222 .dig_out_nid = ALC882_DIGOUT_NID,
7223 .dig_in_nid = ALC882_DIGIN_NID,
7224 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7225 .channel_mode = alc882_ch_modes,
7226 .input_mux = &alc882_capture_source,
7227 .init_hook = alc885_macpro_init_hook,
7228 },
7229 [ALC885_IMAC24] = {
7230 .mixers = { alc885_imac24_mixer },
7231 .init_verbs = { alc885_imac24_init_verbs },
7232 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7233 .dac_nids = alc882_dac_nids,
7234 .dig_out_nid = ALC882_DIGOUT_NID,
7235 .dig_in_nid = ALC882_DIGIN_NID,
7236 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7237 .channel_mode = alc882_ch_modes,
7238 .input_mux = &alc882_capture_source,
7239 .unsol_event = alc_automute_amp_unsol_event,
7240 .init_hook = alc885_imac24_init_hook,
7241 },
7242 [ALC882_TARGA] = {
7243 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
7244 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
7245 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7246 .dac_nids = alc882_dac_nids,
7247 .dig_out_nid = ALC882_DIGOUT_NID,
7248 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7249 .adc_nids = alc882_adc_nids,
7250 .capsrc_nids = alc882_capsrc_nids,
7251 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7252 .channel_mode = alc882_3ST_6ch_modes,
7253 .need_dac_fix = 1,
7254 .input_mux = &alc882_capture_source,
7255 .unsol_event = alc882_targa_unsol_event,
7256 .init_hook = alc882_targa_init_hook,
7257 },
7258 [ALC882_ASUS_A7J] = {
7259 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
7260 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
7261 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7262 .dac_nids = alc882_dac_nids,
7263 .dig_out_nid = ALC882_DIGOUT_NID,
7264 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7265 .adc_nids = alc882_adc_nids,
7266 .capsrc_nids = alc882_capsrc_nids,
7267 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7268 .channel_mode = alc882_3ST_6ch_modes,
7269 .need_dac_fix = 1,
7270 .input_mux = &alc882_capture_source,
7271 },
7272 [ALC882_ASUS_A7M] = {
7273 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
7274 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7275 alc880_gpio1_init_verbs,
7276 alc882_asus_a7m_verbs },
7277 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7278 .dac_nids = alc882_dac_nids,
7279 .dig_out_nid = ALC882_DIGOUT_NID,
7280 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7281 .channel_mode = alc880_threestack_modes,
7282 .need_dac_fix = 1,
7283 .input_mux = &alc882_capture_source,
7284 },
7285};
7286
7287
7288/*
7289 * Pin config fixes
7290 */
7291enum {
7292 PINFIX_ABIT_AW9D_MAX
7293};
7294
7295static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
7296 { 0x15, 0x01080104 }, /* side */
7297 { 0x16, 0x01011012 }, /* rear */
7298 { 0x17, 0x01016011 }, /* clfe */
7299 { }
7300};
7301
7302static const struct alc_pincfg *alc882_pin_fixes[] = {
7303 [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
7304};
7305
7306static struct snd_pci_quirk alc882_pinfix_tbl[] = {
7307 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
7308 {}
7309};
7310
7311/*
7312 * BIOS auto configuration
7313 */
7314static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
7315 hda_nid_t nid, int pin_type,
7316 int dac_idx)
7317{
7318 /* set as output */
7319 struct alc_spec *spec = codec->spec;
7320 int idx;
7321
7322 alc_set_pin_output(codec, nid, pin_type);
7323 if (spec->multiout.dac_nids[dac_idx] == 0x25)
7324 idx = 4;
7325 else
7326 idx = spec->multiout.dac_nids[dac_idx] - 2;
7327 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7328
7329}
7330
7331static void alc882_auto_init_multi_out(struct hda_codec *codec)
7332{
7333 struct alc_spec *spec = codec->spec;
7334 int i;
7335
7336 for (i = 0; i <= HDA_SIDE; i++) {
7337 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7338 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7339 if (nid)
7340 alc882_auto_set_output_and_unmute(codec, nid, pin_type,
7341 i);
7342 }
7343}
7344
7345static void alc882_auto_init_hp_out(struct hda_codec *codec)
7346{
7347 struct alc_spec *spec = codec->spec;
7348 hda_nid_t pin;
7349
7350 pin = spec->autocfg.hp_pins[0];
7351 if (pin) /* connect to front */
7352 /* use dac 0 */
7353 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7354 pin = spec->autocfg.speaker_pins[0];
7355 if (pin)
7356 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7357}
7358
7359#define alc882_is_input_pin(nid) alc880_is_input_pin(nid)
7360#define ALC882_PIN_CD_NID ALC880_PIN_CD_NID
7361
7362static void alc882_auto_init_analog_input(struct hda_codec *codec)
7363{
7364 struct alc_spec *spec = codec->spec;
7365 int i;
7366
7367 for (i = 0; i < AUTO_PIN_LAST; i++) {
7368 hda_nid_t nid = spec->autocfg.input_pins[i];
7369 if (!nid)
7370 continue;
7371 alc_set_input_pin(codec, nid, AUTO_PIN_FRONT_MIC /*i*/);
7372 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
7373 snd_hda_codec_write(codec, nid, 0,
7374 AC_VERB_SET_AMP_GAIN_MUTE,
7375 AMP_OUT_MUTE);
7376 }
7377}
7378
7379static void alc882_auto_init_input_src(struct hda_codec *codec)
7380{
7381 struct alc_spec *spec = codec->spec;
7382 int c;
7383
7384 for (c = 0; c < spec->num_adc_nids; c++) {
7385 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
7386 hda_nid_t nid = spec->capsrc_nids[c];
7387 unsigned int mux_idx;
7388 const struct hda_input_mux *imux;
7389 int conns, mute, idx, item;
7390
7391 conns = snd_hda_get_connections(codec, nid, conn_list,
7392 ARRAY_SIZE(conn_list));
7393 if (conns < 0)
7394 continue;
7395 mux_idx = c >= spec->num_mux_defs ? 0 : c;
7396 imux = &spec->input_mux[mux_idx];
7397 for (idx = 0; idx < conns; idx++) {
7398 /* if the current connection is the selected one,
7399 * unmute it as default - otherwise mute it
7400 */
7401 mute = AMP_IN_MUTE(idx);
7402 for (item = 0; item < imux->num_items; item++) {
7403 if (imux->items[item].index == idx) {
7404 if (spec->cur_mux[c] == item)
7405 mute = AMP_IN_UNMUTE(idx);
7406 break;
7407 }
7408 }
7409 /* check if we have a selector or mixer
7410 * we could check for the widget type instead, but
7411 * just check for Amp-In presence (in case of mixer
7412 * without amp-in there is something wrong, this
7413 * function shouldn't be used or capsrc nid is wrong)
7414 */
7415 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
7416 snd_hda_codec_write(codec, nid, 0,
7417 AC_VERB_SET_AMP_GAIN_MUTE,
7418 mute);
7419 else if (mute != AMP_IN_MUTE(idx))
7420 snd_hda_codec_write(codec, nid, 0,
7421 AC_VERB_SET_CONNECT_SEL,
7422 idx);
7423 }
7424 }
7425}
7426
7427/* add mic boosts if needed */
7428static int alc_auto_add_mic_boost(struct hda_codec *codec)
7429{
7430 struct alc_spec *spec = codec->spec;
7431 int err;
7432 hda_nid_t nid;
7433
7434 nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
7435 if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7436 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7437 "Mic Boost",
7438 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7439 if (err < 0)
7440 return err;
7441 }
7442 nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
7443 if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7444 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7445 "Front Mic Boost",
7446 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7447 if (err < 0)
7448 return err;
7449 }
7450 return 0;
7451}
7452
7453/* almost identical with ALC880 parser... */
7454static int alc882_parse_auto_config(struct hda_codec *codec)
7455{
7456 struct alc_spec *spec = codec->spec;
7457 int err = alc880_parse_auto_config(codec);
7458
7459 if (err < 0)
7460 return err;
7461 else if (!err)
7462 return 0; /* no config found */
7463
7464 err = alc_auto_add_mic_boost(codec);
7465 if (err < 0)
7466 return err;
7467
7468 /* hack - override the init verbs */
7469 spec->init_verbs[0] = alc882_auto_init_verbs;
7470
7471 return 1; /* config found */
7472}
7473
7474/* additional initialization for auto-configuration model */
7475static void alc882_auto_init(struct hda_codec *codec)
7476{
7477 struct alc_spec *spec = codec->spec;
7478 alc882_auto_init_multi_out(codec);
7479 alc882_auto_init_hp_out(codec);
7480 alc882_auto_init_analog_input(codec);
7481 alc882_auto_init_input_src(codec);
7482 if (spec->unsol_event)
7483 alc_inithook(codec);
7484}
7485
7486static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7487
7488static int patch_alc882(struct hda_codec *codec)
7489{
7490 struct alc_spec *spec;
7491 int err, board_config;
7492
7493 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7494 if (spec == NULL)
7495 return -ENOMEM;
7496
7497 codec->spec = spec;
7498
7499 board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7500 alc882_models,
7501 alc882_cfg_tbl);
7502
7503 if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7504 /* Pick up systems that don't supply PCI SSID */
7505 switch (codec->subsystem_id) {
7506 case 0x106b0c00: /* Mac Pro */
7507 board_config = ALC885_MACPRO;
7508 break;
7509 case 0x106b1000: /* iMac 24 */
7510 case 0x106b2800: /* AppleTV */
7511 case 0x106b3e00: /* iMac 24 Aluminium */
7512 board_config = ALC885_IMAC24;
7513 break;
7514 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
7515 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7516 case 0x106b00a4: /* MacbookPro4,1 */
7517 case 0x106b2c00: /* Macbook Pro rev3 */
7518 /* Macbook 3.1 (0x106b3600) is handled by patch_alc883() */
7519 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7520 board_config = ALC885_MBP3;
7521 break;
7522 case 0x106b3f00: /* Macbook 5,1 */
7523 case 0x106b4000: /* Macbook Pro 5,1 - FIXME: HP jack sense
7524 * seems not working, so apparently
7525 * no perfect solution yet
7526 */
7527 board_config = ALC885_MB5;
7528 break;
7529 default:
7530 /* ALC889A is handled better as ALC888-compatible */
7531 if (codec->revision_id == 0x100101 ||
7532 codec->revision_id == 0x100103) {
7533 alc_free(codec);
7534 return patch_alc883(codec);
7535 }
7536 printk(KERN_INFO "hda_codec: Unknown model for %s, "
7537 "trying auto-probe from BIOS...\n",
7538 codec->chip_name);
7539 board_config = ALC882_AUTO;
7540 }
7541 }
7542
7543 alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7544
7545 if (board_config == ALC882_AUTO) {
7546 /* automatic parse from the BIOS config */
7547 err = alc882_parse_auto_config(codec);
7548 if (err < 0) {
7549 alc_free(codec);
7550 return err;
7551 } else if (!err) {
7552 printk(KERN_INFO
7553 "hda_codec: Cannot set up configuration "
7554 "from BIOS. Using base mode...\n");
7555 board_config = ALC882_3ST_DIG;
7556 }
7557 }
7558
7559 err = snd_hda_attach_beep_device(codec, 0x1);
7560 if (err < 0) {
7561 alc_free(codec);
7562 return err;
7563 }
7564
7565 if (board_config != ALC882_AUTO)
7566 setup_preset(spec, &alc882_presets[board_config]);
7567
7568 spec->stream_analog_playback = &alc882_pcm_analog_playback;
7569 spec->stream_analog_capture = &alc882_pcm_analog_capture;
7570 /* FIXME: setup DAC5 */
7571 /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7572 spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7573
7574 spec->stream_digital_playback = &alc882_pcm_digital_playback;
7575 spec->stream_digital_capture = &alc882_pcm_digital_capture;
7576
7577 if (!spec->adc_nids && spec->input_mux) {
7578 /* check whether NID 0x07 is valid */
7579 unsigned int wcap = get_wcaps(codec, 0x07);
7580 /* get type */
7581 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7582 if (wcap != AC_WID_AUD_IN) {
7583 spec->adc_nids = alc882_adc_nids_alt;
7584 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7585 spec->capsrc_nids = alc882_capsrc_nids_alt;
7586 } else {
7587 spec->adc_nids = alc882_adc_nids;
7588 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7589 spec->capsrc_nids = alc882_capsrc_nids;
7590 }
7591 }
7592 set_capture_mixer(spec);
7593 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7594
7595 spec->vmaster_nid = 0x0c;
7596
7597 codec->patch_ops = alc_patch_ops;
7598 if (board_config == ALC882_AUTO)
7599 spec->init_hook = alc882_auto_init;
7600#ifdef CONFIG_SND_HDA_POWER_SAVE
7601 if (!spec->loopback.amplist)
7602 spec->loopback.amplist = alc882_loopbacks;
7603#endif
7604 codec->proc_widget_hook = print_realtek_coef;
7605
7606 return 0;
7607}
7608
7609/*
7610 * ALC883 support
7611 *
7612 * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7613 * configuration. Each pin widget can choose any input DACs and a mixer.
7614 * Each ADC is connected from a mixer of all inputs. This makes possible
7615 * 6-channel independent captures.
7616 *
7617 * In addition, an independent DAC for the multi-playback (not used in this
7618 * driver yet).
7619 */
7620#define ALC883_DIGOUT_NID 0x06
7621#define ALC883_DIGIN_NID 0x0a
7622
7623#define ALC1200_DIGOUT_NID 0x10
7624
7625static hda_nid_t alc883_dac_nids[4] = {
7626 /* front, rear, clfe, rear_surr */
7627 0x02, 0x03, 0x04, 0x05
7628};
7629
7630static hda_nid_t alc883_adc_nids[2] = {
7631 /* ADC1-2 */
7632 0x08, 0x09,
7633};
7634
7635static hda_nid_t alc883_adc_nids_alt[1] = {
7636 /* ADC1 */
7637 0x08,
7638};
7639
7640static hda_nid_t alc883_adc_nids_rev[2] = {
7641 /* ADC2-1 */
7642 0x09, 0x08
7643};
7644
7645#define alc889_adc_nids alc880_adc_nids
7646
7647static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7648
7649static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7650
7651#define alc889_capsrc_nids alc882_capsrc_nids
7652
7653/* input MUX */
7654/* FIXME: should be a matrix-type input source selection */
7655
7656static struct hda_input_mux alc883_capture_source = {
7657 .num_items = 4,
7658 .items = {
7659 { "Mic", 0x0 },
7660 { "Front Mic", 0x1 },
7661 { "Line", 0x2 },
7662 { "CD", 0x4 },
7663 },
7664};
7665
7666static struct hda_input_mux alc883_3stack_6ch_intel = {
7667 .num_items = 4,
7668 .items = {
7669 { "Mic", 0x1 },
7670 { "Front Mic", 0x0 },
7671 { "Line", 0x2 },
7672 { "CD", 0x4 },
7673 },
7674};
7675
7676static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7677 .num_items = 2,
7678 .items = {
7679 { "Mic", 0x1 },
7680 { "Line", 0x2 },
7681 },
7682};
7683
7684static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7685 .num_items = 4,
7686 .items = {
7687 { "Mic", 0x0 },
7688 { "iMic", 0x1 },
7689 { "Line", 0x2 },
7690 { "CD", 0x4 },
7691 },
7692};
7693
7694static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7695 .num_items = 2,
7696 .items = {
7697 { "Mic", 0x0 },
7698 { "Int Mic", 0x1 },
7699 },
7700};
7701
7702static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7703 .num_items = 3,
7704 .items = {
7705 { "Mic", 0x0 },
7706 { "Front Mic", 0x1 },
7707 { "Line", 0x4 },
7708 },
7709};
7710
7711static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7712 .num_items = 2,
7713 .items = {
7714 { "Mic", 0x0 },
7715 { "Line", 0x2 },
7716 },
7717};
7718
7719static struct hda_input_mux alc889A_mb31_capture_source = {
7720 .num_items = 2,
7721 .items = {
7722 { "Mic", 0x0 },
7723 /* Front Mic (0x01) unused */
7724 { "Line", 0x2 },
7725 /* Line 2 (0x03) unused */
7726 /* CD (0x04) unsused? */
7727 },
7728};
7729
7730/*
7731 * 2ch mode
7732 */
7733static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7734 { 2, NULL }
7735};
7736
7737/*
7738 * 2ch mode
7739 */
7740static struct hda_verb alc883_3ST_ch2_init[] = {
7741 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7742 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7743 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7744 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7745 { } /* end */
7746};
7747
7748/*
7749 * 4ch mode
7750 */
7751static struct hda_verb alc883_3ST_ch4_init[] = {
7752 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7753 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7754 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7755 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7756 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7757 { } /* end */
7758};
7759
7760/*
7761 * 6ch mode
7762 */
7763static struct hda_verb alc883_3ST_ch6_init[] = {
7764 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7765 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7766 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7767 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7768 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7769 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7770 { } /* end */
7771};
7772
7773static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7774 { 2, alc883_3ST_ch2_init },
7775 { 4, alc883_3ST_ch4_init },
7776 { 6, alc883_3ST_ch6_init },
7777};
7778
7779
7780/*
7781 * 2ch mode
7782 */
7783static struct hda_verb alc883_4ST_ch2_init[] = {
7784 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7785 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7786 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7787 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7788 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7789 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7790 { } /* end */
7791};
7792
7793/*
7794 * 4ch mode
7795 */
7796static struct hda_verb alc883_4ST_ch4_init[] = {
7797 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7798 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7799 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7800 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7801 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7802 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7803 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7804 { } /* end */
7805};
7806
7807/*
7808 * 6ch mode
7809 */
7810static struct hda_verb alc883_4ST_ch6_init[] = {
7811 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7812 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7813 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7814 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7815 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7816 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7817 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7818 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7819 { } /* end */
7820};
7821
7822/*
7823 * 8ch mode
7824 */
7825static struct hda_verb alc883_4ST_ch8_init[] = {
7826 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7827 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7828 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
7829 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7830 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7831 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7832 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7833 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7834 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7835 { } /* end */
7836};
7837
7838static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
7839 { 2, alc883_4ST_ch2_init },
7840 { 4, alc883_4ST_ch4_init },
7841 { 6, alc883_4ST_ch6_init },
7842 { 8, alc883_4ST_ch8_init },
7843};
7844
7845
7846/*
7847 * 2ch mode
7848 */
7849static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7850 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7851 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7852 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7853 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7854 { } /* end */
7855};
7856
7857/*
7858 * 4ch mode
7859 */
7860static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7861 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7862 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7863 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7864 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7865 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7866 { } /* end */
7867};
7868
7869/*
7870 * 6ch mode
7871 */
7872static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7873 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7874 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7875 { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7876 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7877 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7878 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7879 { } /* end */
7880};
7881
7882static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7883 { 2, alc883_3ST_ch2_intel_init },
7884 { 4, alc883_3ST_ch4_intel_init },
7885 { 6, alc883_3ST_ch6_intel_init },
7886};
7887
7888/*
7889 * 6ch mode
7890 */
7891static struct hda_verb alc883_sixstack_ch6_init[] = {
7892 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7893 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7894 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7895 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7896 { } /* end */
7897};
7898
7899/*
7900 * 8ch mode
7901 */
7902static struct hda_verb alc883_sixstack_ch8_init[] = {
7903 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7904 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7905 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7906 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7907 { } /* end */
7908};
7909
7910static struct hda_channel_mode alc883_sixstack_modes[2] = {
7911 { 6, alc883_sixstack_ch6_init },
7912 { 8, alc883_sixstack_ch8_init },
7913};
7914
7915/* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */ 7720/* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7916static struct hda_verb alc889A_mb31_ch2_init[] = { 7721static struct hda_verb alc889A_mb31_ch2_init[] = {
7917 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP as front */ 7722 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP as front */
@@ -7962,34 +7767,7 @@ static struct hda_verb alc883_medion_eapd_verbs[] = {
7962 { } 7767 { }
7963}; 7768};
7964 7769
7965/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17 7770#define alc883_base_mixer alc882_base_mixer
7966 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7967 */
7968
7969static struct snd_kcontrol_new alc883_base_mixer[] = {
7970 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7971 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7972 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7973 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7974 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7975 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7976 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7977 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7978 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7979 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7980 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7981 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7982 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7983 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7984 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7985 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7986 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7987 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7988 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7989 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7990 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7991 { } /* end */
7992};
7993 7771
7994static struct snd_kcontrol_new alc883_mitac_mixer[] = { 7772static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7995 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7773 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -8100,6 +7878,30 @@ static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
8100 { } /* end */ 7878 { } /* end */
8101}; 7879};
8102 7880
7881static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
7882 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7883 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7884 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7885 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7886 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7887 HDA_OUTPUT),
7888 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7889 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7890 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7891 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7892 HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
7893 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7894 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7895 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7896 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
7897 HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT),
7898 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
7899 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7900 HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7901 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7902 { } /* end */
7903};
7904
8103static struct snd_kcontrol_new alc883_fivestack_mixer[] = { 7905static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8104 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7906 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8105 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 7907 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -8125,8 +7927,9 @@ static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8125 7927
8126static struct snd_kcontrol_new alc883_targa_mixer[] = { 7928static struct snd_kcontrol_new alc883_targa_mixer[] = {
8127 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7929 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7930 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8128 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT), 7931 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8129 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 7932 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8130 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 7933 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8131 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 7934 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8132 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 7935 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
@@ -8145,8 +7948,9 @@ static struct snd_kcontrol_new alc883_targa_mixer[] = {
8145 7948
8146static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = { 7949static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
8147 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7950 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7951 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8148 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT), 7952 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8149 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 7953 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8150 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 7954 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8151 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 7955 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8152 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 7956 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
@@ -8158,6 +7962,15 @@ static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
8158 { } /* end */ 7962 { } /* end */
8159}; 7963};
8160 7964
7965static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
7966 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7967 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7968 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7969 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7970 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7971 { } /* end */
7972};
7973
8161static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = { 7974static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
8162 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7975 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8163 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 7976 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -8340,93 +8153,14 @@ static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8340 { } /* end */ 8153 { } /* end */
8341}; 8154};
8342 8155
8343static struct hda_verb alc883_init_verbs[] = {
8344 /* ADC1: mute amp left and right */
8345 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8346 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8347 /* ADC2: mute amp left and right */
8348 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8349 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8350 /* Front mixer: unmute input/output amp left and right (volume = 0) */
8351 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8352 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8353 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8354 /* Rear mixer */
8355 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8356 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8357 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8358 /* CLFE mixer */
8359 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8360 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8361 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8362 /* Side mixer */
8363 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8364 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8365 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8366
8367 /* mute analog input loopbacks */
8368 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8369 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8370 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8371 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8372 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8373
8374 /* Front Pin: output 0 (0x0c) */
8375 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8376 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8377 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8378 /* Rear Pin: output 1 (0x0d) */
8379 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8380 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8381 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8382 /* CLFE Pin: output 2 (0x0e) */
8383 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8384 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8385 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8386 /* Side Pin: output 3 (0x0f) */
8387 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8388 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8389 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8390 /* Mic (rear) pin: input vref at 80% */
8391 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8392 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8393 /* Front Mic pin: input vref at 80% */
8394 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8395 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8396 /* Line In pin: input */
8397 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8398 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8399 /* Line-2 In: Headphone output (output 0 - 0x0c) */
8400 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8401 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8402 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8403 /* CD pin widget for input */
8404 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8405
8406 /* FIXME: use matrix-type input source selection */
8407 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8408 /* Input mixer2 */
8409 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8410 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8411 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8412 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8413 /* Input mixer3 */
8414 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8415 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8416 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8417 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8418 { }
8419};
8420
8421/* toggle speaker-output according to the hp-jack state */ 8156/* toggle speaker-output according to the hp-jack state */
8422static void alc883_mitac_init_hook(struct hda_codec *codec) 8157static void alc883_mitac_setup(struct hda_codec *codec)
8423{ 8158{
8424 struct alc_spec *spec = codec->spec; 8159 struct alc_spec *spec = codec->spec;
8425 8160
8426 spec->autocfg.hp_pins[0] = 0x15; 8161 spec->autocfg.hp_pins[0] = 0x15;
8427 spec->autocfg.speaker_pins[0] = 0x14; 8162 spec->autocfg.speaker_pins[0] = 0x14;
8428 spec->autocfg.speaker_pins[1] = 0x17; 8163 spec->autocfg.speaker_pins[1] = 0x17;
8429 alc_automute_amp(codec);
8430} 8164}
8431 8165
8432/* auto-toggle front mic */ 8166/* auto-toggle front mic */
@@ -8458,6 +8192,22 @@ static struct hda_verb alc883_mitac_verbs[] = {
8458 { } /* end */ 8192 { } /* end */
8459}; 8193};
8460 8194
8195static struct hda_verb alc883_clevo_m540r_verbs[] = {
8196 /* HP */
8197 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8198 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8199 /* Int speaker */
8200 /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
8201
8202 /* enable unsolicited event */
8203 /*
8204 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8205 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8206 */
8207
8208 { } /* end */
8209};
8210
8461static struct hda_verb alc883_clevo_m720_verbs[] = { 8211static struct hda_verb alc883_clevo_m720_verbs[] = {
8462 /* HP */ 8212 /* HP */
8463 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 8213 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -8581,7 +8331,7 @@ static struct hda_verb alc883_vaiott_verbs[] = {
8581 { } /* end */ 8331 { } /* end */
8582}; 8332};
8583 8333
8584static void alc888_3st_hp_init_hook(struct hda_codec *codec) 8334static void alc888_3st_hp_setup(struct hda_codec *codec)
8585{ 8335{
8586 struct alc_spec *spec = codec->spec; 8336 struct alc_spec *spec = codec->spec;
8587 8337
@@ -8589,7 +8339,6 @@ static void alc888_3st_hp_init_hook(struct hda_codec *codec)
8589 spec->autocfg.speaker_pins[0] = 0x14; 8339 spec->autocfg.speaker_pins[0] = 0x14;
8590 spec->autocfg.speaker_pins[1] = 0x16; 8340 spec->autocfg.speaker_pins[1] = 0x16;
8591 spec->autocfg.speaker_pins[2] = 0x18; 8341 spec->autocfg.speaker_pins[2] = 0x18;
8592 alc_automute_amp(codec);
8593} 8342}
8594 8343
8595static struct hda_verb alc888_3st_hp_verbs[] = { 8344static struct hda_verb alc888_3st_hp_verbs[] = {
@@ -8686,13 +8435,12 @@ static struct hda_verb alc883_medion_md2_verbs[] = {
8686}; 8435};
8687 8436
8688/* toggle speaker-output according to the hp-jack state */ 8437/* toggle speaker-output according to the hp-jack state */
8689static void alc883_medion_md2_init_hook(struct hda_codec *codec) 8438static void alc883_medion_md2_setup(struct hda_codec *codec)
8690{ 8439{
8691 struct alc_spec *spec = codec->spec; 8440 struct alc_spec *spec = codec->spec;
8692 8441
8693 spec->autocfg.hp_pins[0] = 0x14; 8442 spec->autocfg.hp_pins[0] = 0x14;
8694 spec->autocfg.speaker_pins[0] = 0x15; 8443 spec->autocfg.speaker_pins[0] = 0x15;
8695 alc_automute_amp(codec);
8696} 8444}
8697 8445
8698/* toggle speaker-output according to the hp-jack state */ 8446/* toggle speaker-output according to the hp-jack state */
@@ -8709,12 +8457,16 @@ static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8709 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8457 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8710} 8458}
8711 8459
8712static void alc883_clevo_m720_init_hook(struct hda_codec *codec) 8460static void alc883_clevo_m720_setup(struct hda_codec *codec)
8713{ 8461{
8714 struct alc_spec *spec = codec->spec; 8462 struct alc_spec *spec = codec->spec;
8715 8463
8716 spec->autocfg.hp_pins[0] = 0x15; 8464 spec->autocfg.hp_pins[0] = 0x15;
8717 spec->autocfg.speaker_pins[0] = 0x14; 8465 spec->autocfg.speaker_pins[0] = 0x14;
8466}
8467
8468static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8469{
8718 alc_automute_amp(codec); 8470 alc_automute_amp(codec);
8719 alc883_clevo_m720_mic_automute(codec); 8471 alc883_clevo_m720_mic_automute(codec);
8720} 8472}
@@ -8733,22 +8485,20 @@ static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8733} 8485}
8734 8486
8735/* toggle speaker-output according to the hp-jack state */ 8487/* toggle speaker-output according to the hp-jack state */
8736static void alc883_2ch_fujitsu_pi2515_init_hook(struct hda_codec *codec) 8488static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8737{ 8489{
8738 struct alc_spec *spec = codec->spec; 8490 struct alc_spec *spec = codec->spec;
8739 8491
8740 spec->autocfg.hp_pins[0] = 0x14; 8492 spec->autocfg.hp_pins[0] = 0x14;
8741 spec->autocfg.speaker_pins[0] = 0x15; 8493 spec->autocfg.speaker_pins[0] = 0x15;
8742 alc_automute_amp(codec);
8743} 8494}
8744 8495
8745static void alc883_haier_w66_init_hook(struct hda_codec *codec) 8496static void alc883_haier_w66_setup(struct hda_codec *codec)
8746{ 8497{
8747 struct alc_spec *spec = codec->spec; 8498 struct alc_spec *spec = codec->spec;
8748 8499
8749 spec->autocfg.hp_pins[0] = 0x1b; 8500 spec->autocfg.hp_pins[0] = 0x1b;
8750 spec->autocfg.speaker_pins[0] = 0x14; 8501 spec->autocfg.speaker_pins[0] = 0x14;
8751 alc_automute_amp(codec);
8752} 8502}
8753 8503
8754static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec) 8504static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
@@ -8787,14 +8537,13 @@ static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8787} 8537}
8788 8538
8789/* toggle speaker-output according to the hp-jack state */ 8539/* toggle speaker-output according to the hp-jack state */
8790static void alc883_acer_aspire_init_hook(struct hda_codec *codec) 8540static void alc883_acer_aspire_setup(struct hda_codec *codec)
8791{ 8541{
8792 struct alc_spec *spec = codec->spec; 8542 struct alc_spec *spec = codec->spec;
8793 8543
8794 spec->autocfg.hp_pins[0] = 0x14; 8544 spec->autocfg.hp_pins[0] = 0x14;
8795 spec->autocfg.speaker_pins[0] = 0x15; 8545 spec->autocfg.speaker_pins[0] = 0x15;
8796 spec->autocfg.speaker_pins[1] = 0x16; 8546 spec->autocfg.speaker_pins[1] = 0x16;
8797 alc_automute_amp(codec);
8798} 8547}
8799 8548
8800static struct hda_verb alc883_acer_eapd_verbs[] = { 8549static struct hda_verb alc883_acer_eapd_verbs[] = {
@@ -8815,7 +8564,14 @@ static struct hda_verb alc883_acer_eapd_verbs[] = {
8815 { } 8564 { }
8816}; 8565};
8817 8566
8818static void alc888_6st_dell_init_hook(struct hda_codec *codec) 8567static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
8568 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8569 {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8570 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8571 { } /* end */
8572};
8573
8574static void alc888_6st_dell_setup(struct hda_codec *codec)
8819{ 8575{
8820 struct alc_spec *spec = codec->spec; 8576 struct alc_spec *spec = codec->spec;
8821 8577
@@ -8824,10 +8580,9 @@ static void alc888_6st_dell_init_hook(struct hda_codec *codec)
8824 spec->autocfg.speaker_pins[1] = 0x15; 8580 spec->autocfg.speaker_pins[1] = 0x15;
8825 spec->autocfg.speaker_pins[2] = 0x16; 8581 spec->autocfg.speaker_pins[2] = 0x16;
8826 spec->autocfg.speaker_pins[3] = 0x17; 8582 spec->autocfg.speaker_pins[3] = 0x17;
8827 alc_automute_amp(codec);
8828} 8583}
8829 8584
8830static void alc888_lenovo_sky_init_hook(struct hda_codec *codec) 8585static void alc888_lenovo_sky_setup(struct hda_codec *codec)
8831{ 8586{
8832 struct alc_spec *spec = codec->spec; 8587 struct alc_spec *spec = codec->spec;
8833 8588
@@ -8837,82 +8592,17 @@ static void alc888_lenovo_sky_init_hook(struct hda_codec *codec)
8837 spec->autocfg.speaker_pins[2] = 0x16; 8592 spec->autocfg.speaker_pins[2] = 0x16;
8838 spec->autocfg.speaker_pins[3] = 0x17; 8593 spec->autocfg.speaker_pins[3] = 0x17;
8839 spec->autocfg.speaker_pins[4] = 0x1a; 8594 spec->autocfg.speaker_pins[4] = 0x1a;
8840 alc_automute_amp(codec);
8841} 8595}
8842 8596
8843static void alc883_vaiott_init_hook(struct hda_codec *codec) 8597static void alc883_vaiott_setup(struct hda_codec *codec)
8844{ 8598{
8845 struct alc_spec *spec = codec->spec; 8599 struct alc_spec *spec = codec->spec;
8846 8600
8847 spec->autocfg.hp_pins[0] = 0x15; 8601 spec->autocfg.hp_pins[0] = 0x15;
8848 spec->autocfg.speaker_pins[0] = 0x14; 8602 spec->autocfg.speaker_pins[0] = 0x14;
8849 spec->autocfg.speaker_pins[1] = 0x17; 8603 spec->autocfg.speaker_pins[1] = 0x17;
8850 alc_automute_amp(codec);
8851} 8604}
8852 8605
8853/*
8854 * generic initialization of ADC, input mixers and output mixers
8855 */
8856static struct hda_verb alc883_auto_init_verbs[] = {
8857 /*
8858 * Unmute ADC0-2 and set the default input to mic-in
8859 */
8860 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8861 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8862 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8863 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8864
8865 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8866 * mixer widget
8867 * Note: PASD motherboards uses the Line In 2 as the input for
8868 * front panel mic (mic 2)
8869 */
8870 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8871 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8872 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8873 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8874 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8875 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8876
8877 /*
8878 * Set up output mixers (0x0c - 0x0f)
8879 */
8880 /* set vol=0 to output mixers */
8881 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8882 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8883 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8884 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8885 /* set up input amps for analog loopback */
8886 /* Amp Indices: DAC = 0, mixer = 1 */
8887 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8888 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8889 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8890 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8891 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8892 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8893 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8894 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8895 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8896 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8897
8898 /* FIXME: use matrix-type input source selection */
8899 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8900 /* Input mixer1 */
8901 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8902 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8903 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8904 /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8905 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8906 /* Input mixer2 */
8907 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8908 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8909 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8910 /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8911 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8912
8913 { }
8914};
8915
8916static struct hda_verb alc888_asus_m90v_verbs[] = { 8606static struct hda_verb alc888_asus_m90v_verbs[] = {
8917 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8607 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8918 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8608 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
@@ -8923,19 +8613,7 @@ static struct hda_verb alc888_asus_m90v_verbs[] = {
8923 { } /* end */ 8613 { } /* end */
8924}; 8614};
8925 8615
8926static void alc883_nb_mic_automute(struct hda_codec *codec) 8616static void alc883_mode2_setup(struct hda_codec *codec)
8927{
8928 unsigned int present;
8929
8930 present = snd_hda_codec_read(codec, 0x18, 0,
8931 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8932 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8933 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8934 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8935 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8936}
8937
8938static void alc883_M90V_init_hook(struct hda_codec *codec)
8939{ 8617{
8940 struct alc_spec *spec = codec->spec; 8618 struct alc_spec *spec = codec->spec;
8941 8619
@@ -8943,26 +8621,11 @@ static void alc883_M90V_init_hook(struct hda_codec *codec)
8943 spec->autocfg.speaker_pins[0] = 0x14; 8621 spec->autocfg.speaker_pins[0] = 0x14;
8944 spec->autocfg.speaker_pins[1] = 0x15; 8622 spec->autocfg.speaker_pins[1] = 0x15;
8945 spec->autocfg.speaker_pins[2] = 0x16; 8623 spec->autocfg.speaker_pins[2] = 0x16;
8946 alc_automute_pin(codec); 8624 spec->ext_mic.pin = 0x18;
8947} 8625 spec->int_mic.pin = 0x19;
8948 8626 spec->ext_mic.mux_idx = 0;
8949static void alc883_mode2_unsol_event(struct hda_codec *codec, 8627 spec->int_mic.mux_idx = 1;
8950 unsigned int res) 8628 spec->auto_mic = 1;
8951{
8952 switch (res >> 26) {
8953 case ALC880_MIC_EVENT:
8954 alc883_nb_mic_automute(codec);
8955 break;
8956 default:
8957 alc_sku_unsol_event(codec, res);
8958 break;
8959 }
8960}
8961
8962static void alc883_mode2_inithook(struct hda_codec *codec)
8963{
8964 alc883_M90V_init_hook(codec);
8965 alc883_nb_mic_automute(codec);
8966} 8629}
8967 8630
8968static struct hda_verb alc888_asus_eee1601_verbs[] = { 8631static struct hda_verb alc888_asus_eee1601_verbs[] = {
@@ -9023,25 +8686,44 @@ static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
9023 alc889A_mb31_automute(codec); 8686 alc889A_mb31_automute(codec);
9024} 8687}
9025 8688
8689
9026#ifdef CONFIG_SND_HDA_POWER_SAVE 8690#ifdef CONFIG_SND_HDA_POWER_SAVE
9027#define alc883_loopbacks alc880_loopbacks 8691#define alc882_loopbacks alc880_loopbacks
9028#endif 8692#endif
9029 8693
9030/* pcm configuration: identical with ALC880 */ 8694/* pcm configuration: identical with ALC880 */
9031#define alc883_pcm_analog_playback alc880_pcm_analog_playback 8695#define alc882_pcm_analog_playback alc880_pcm_analog_playback
9032#define alc883_pcm_analog_capture alc880_pcm_analog_capture 8696#define alc882_pcm_analog_capture alc880_pcm_analog_capture
9033#define alc883_pcm_analog_alt_capture alc880_pcm_analog_alt_capture 8697#define alc882_pcm_digital_playback alc880_pcm_digital_playback
9034#define alc883_pcm_digital_playback alc880_pcm_digital_playback 8698#define alc882_pcm_digital_capture alc880_pcm_digital_capture
9035#define alc883_pcm_digital_capture alc880_pcm_digital_capture 8699
8700static hda_nid_t alc883_slave_dig_outs[] = {
8701 ALC1200_DIGOUT_NID, 0,
8702};
8703
8704static hda_nid_t alc1200_slave_dig_outs[] = {
8705 ALC883_DIGOUT_NID, 0,
8706};
9036 8707
9037/* 8708/*
9038 * configuration and preset 8709 * configuration and preset
9039 */ 8710 */
9040static const char *alc883_models[ALC883_MODEL_LAST] = { 8711static const char *alc882_models[ALC882_MODEL_LAST] = {
9041 [ALC883_3ST_2ch_DIG] = "3stack-dig", 8712 [ALC882_3ST_DIG] = "3stack-dig",
8713 [ALC882_6ST_DIG] = "6stack-dig",
8714 [ALC882_ARIMA] = "arima",
8715 [ALC882_W2JC] = "w2jc",
8716 [ALC882_TARGA] = "targa",
8717 [ALC882_ASUS_A7J] = "asus-a7j",
8718 [ALC882_ASUS_A7M] = "asus-a7m",
8719 [ALC885_MACPRO] = "macpro",
8720 [ALC885_MB5] = "mb5",
8721 [ALC885_MBP3] = "mbp3",
8722 [ALC885_IMAC24] = "imac24",
8723 [ALC883_3ST_2ch_DIG] = "3stack-2ch-dig",
9042 [ALC883_3ST_6ch_DIG] = "3stack-6ch-dig", 8724 [ALC883_3ST_6ch_DIG] = "3stack-6ch-dig",
9043 [ALC883_3ST_6ch] = "3stack-6ch", 8725 [ALC883_3ST_6ch] = "3stack-6ch",
9044 [ALC883_6ST_DIG] = "6stack-dig", 8726 [ALC883_6ST_DIG] = "alc883-6stack-dig",
9045 [ALC883_TARGA_DIG] = "targa-dig", 8727 [ALC883_TARGA_DIG] = "targa-dig",
9046 [ALC883_TARGA_2ch_DIG] = "targa-2ch-dig", 8728 [ALC883_TARGA_2ch_DIG] = "targa-2ch-dig",
9047 [ALC883_TARGA_8ch_DIG] = "targa-8ch-dig", 8729 [ALC883_TARGA_8ch_DIG] = "targa-8ch-dig",
@@ -9050,6 +8732,7 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
9050 [ALC888_ACER_ASPIRE_4930G] = "acer-aspire-4930g", 8732 [ALC888_ACER_ASPIRE_4930G] = "acer-aspire-4930g",
9051 [ALC888_ACER_ASPIRE_6530G] = "acer-aspire-6530g", 8733 [ALC888_ACER_ASPIRE_6530G] = "acer-aspire-6530g",
9052 [ALC888_ACER_ASPIRE_8930G] = "acer-aspire-8930g", 8734 [ALC888_ACER_ASPIRE_8930G] = "acer-aspire-8930g",
8735 [ALC888_ACER_ASPIRE_7730G] = "acer-aspire-7730g",
9053 [ALC883_MEDION] = "medion", 8736 [ALC883_MEDION] = "medion",
9054 [ALC883_MEDION_MD2] = "medion-md2", 8737 [ALC883_MEDION_MD2] = "medion-md2",
9055 [ALC883_LAPTOP_EAPD] = "laptop-eapd", 8738 [ALC883_LAPTOP_EAPD] = "laptop-eapd",
@@ -9061,18 +8744,22 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
9061 [ALC888_3ST_HP] = "3stack-hp", 8744 [ALC888_3ST_HP] = "3stack-hp",
9062 [ALC888_6ST_DELL] = "6stack-dell", 8745 [ALC888_6ST_DELL] = "6stack-dell",
9063 [ALC883_MITAC] = "mitac", 8746 [ALC883_MITAC] = "mitac",
8747 [ALC883_CLEVO_M540R] = "clevo-m540r",
9064 [ALC883_CLEVO_M720] = "clevo-m720", 8748 [ALC883_CLEVO_M720] = "clevo-m720",
9065 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515", 8749 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
9066 [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530", 8750 [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
9067 [ALC883_3ST_6ch_INTEL] = "3stack-6ch-intel", 8751 [ALC883_3ST_6ch_INTEL] = "3stack-6ch-intel",
8752 [ALC889A_INTEL] = "intel-alc889a",
8753 [ALC889_INTEL] = "intel-x58",
9068 [ALC1200_ASUS_P5Q] = "asus-p5q", 8754 [ALC1200_ASUS_P5Q] = "asus-p5q",
9069 [ALC889A_MB31] = "mb31", 8755 [ALC889A_MB31] = "mb31",
9070 [ALC883_SONY_VAIO_TT] = "sony-vaio-tt", 8756 [ALC883_SONY_VAIO_TT] = "sony-vaio-tt",
9071 [ALC883_AUTO] = "auto", 8757 [ALC882_AUTO] = "auto",
9072}; 8758};
9073 8759
9074static struct snd_pci_quirk alc883_cfg_tbl[] = { 8760static struct snd_pci_quirk alc882_cfg_tbl[] = {
9075 SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG), 8761 SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
8762
9076 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE), 8763 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
9077 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE), 8764 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
9078 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE), 8765 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
@@ -9087,40 +8774,56 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9087 ALC888_ACER_ASPIRE_8930G), 8774 ALC888_ACER_ASPIRE_8930G),
9088 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G", 8775 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
9089 ALC888_ACER_ASPIRE_8930G), 8776 ALC888_ACER_ASPIRE_8930G),
9090 SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO), 8777 SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
9091 SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO), 8778 SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
9092 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G", 8779 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
9093 ALC888_ACER_ASPIRE_6530G), 8780 ALC888_ACER_ASPIRE_6530G),
9094 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G", 8781 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
9095 ALC888_ACER_ASPIRE_6530G), 8782 ALC888_ACER_ASPIRE_6530G),
8783 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
8784 ALC888_ACER_ASPIRE_7730G),
9096 /* default Acer -- disabled as it causes more problems. 8785 /* default Acer -- disabled as it causes more problems.
9097 * model=auto should work fine now 8786 * model=auto should work fine now
9098 */ 8787 */
9099 /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */ 8788 /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
8789
9100 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL), 8790 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8791
9101 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), 8792 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
9102 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP), 8793 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
9103 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP), 8794 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
9104 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG), 8795 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
9105 SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP), 8796 SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
9106 SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP), 8797 SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8798
8799 SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
8800 SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
8801 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
9107 SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V), 8802 SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8803 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
8804 SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
8805 SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
9108 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG), 8806 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
9109 SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG), 8807 SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
9110 SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q), 8808 SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
9111 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601), 8809 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8810
8811 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
9112 SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG), 8812 SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
9113 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG), 8813 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
9114 SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC), 8814 SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
9115 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC), 8815 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
9116 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD), 8816 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
9117 SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL), 8817 SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
9118 SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch), 8818 SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
9119 SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG), 8819 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
8820
9120 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG), 8821 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
9121 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG), 8822 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
9122 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG), 8823 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8824 SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8 */
9123 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG), 8825 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8826 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
9124 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG), 8827 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
9125 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG), 8828 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
9126 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG), 8829 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
@@ -9129,6 +8832,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9129 SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG), 8832 SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
9130 SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG), 8833 SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
9131 SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG), 8834 SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8835 SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
9132 SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG), 8836 SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
9133 SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG), 8837 SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
9134 SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG), 8838 SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
@@ -9142,11 +8846,15 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9142 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG), 8846 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
9143 SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG), 8847 SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
9144 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG), 8848 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8849 SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
8850
9145 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG), 8851 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
9146 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720), 8852 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
9147 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720), 8853 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8854 SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
9148 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD), 8855 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
9149 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch), 8856 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8857 /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
9150 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION), 8858 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
9151 SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx", 8859 SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
9152 ALC883_FUJITSU_PI2515), 8860 ALC883_FUJITSU_PI2515),
@@ -9161,24 +8869,186 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9161 SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG), 8869 SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
9162 SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG), 8870 SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
9163 SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66), 8871 SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8872
9164 SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL), 8873 SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
9165 SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL), 8874 SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
9166 SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC), 8875 SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
9167 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL), 8876 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
8877 SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
8878 SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
9168 SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch), 8879 SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
9169 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
9170 {}
9171};
9172 8880
9173static hda_nid_t alc883_slave_dig_outs[] = { 8881 {}
9174 ALC1200_DIGOUT_NID, 0,
9175}; 8882};
9176 8883
9177static hda_nid_t alc1200_slave_dig_outs[] = { 8884/* codec SSID table for Intel Mac */
9178 ALC883_DIGOUT_NID, 0, 8885static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8886 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
8887 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
8888 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
8889 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
8890 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
8891 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
8892 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
8893 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8894 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8895 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
8896 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8897 /* FIXME: HP jack sense seems not working for MBP 5,1, so apparently
8898 * no perfect solution yet
8899 */
8900 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
8901 {} /* terminator */
9179}; 8902};
9180 8903
9181static struct alc_config_preset alc883_presets[] = { 8904static struct alc_config_preset alc882_presets[] = {
8905 [ALC882_3ST_DIG] = {
8906 .mixers = { alc882_base_mixer },
8907 .init_verbs = { alc882_base_init_verbs,
8908 alc882_adc1_init_verbs },
8909 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8910 .dac_nids = alc882_dac_nids,
8911 .dig_out_nid = ALC882_DIGOUT_NID,
8912 .dig_in_nid = ALC882_DIGIN_NID,
8913 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8914 .channel_mode = alc882_ch_modes,
8915 .need_dac_fix = 1,
8916 .input_mux = &alc882_capture_source,
8917 },
8918 [ALC882_6ST_DIG] = {
8919 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8920 .init_verbs = { alc882_base_init_verbs,
8921 alc882_adc1_init_verbs },
8922 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8923 .dac_nids = alc882_dac_nids,
8924 .dig_out_nid = ALC882_DIGOUT_NID,
8925 .dig_in_nid = ALC882_DIGIN_NID,
8926 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8927 .channel_mode = alc882_sixstack_modes,
8928 .input_mux = &alc882_capture_source,
8929 },
8930 [ALC882_ARIMA] = {
8931 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8932 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8933 alc882_eapd_verbs },
8934 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8935 .dac_nids = alc882_dac_nids,
8936 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8937 .channel_mode = alc882_sixstack_modes,
8938 .input_mux = &alc882_capture_source,
8939 },
8940 [ALC882_W2JC] = {
8941 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
8942 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8943 alc882_eapd_verbs, alc880_gpio1_init_verbs },
8944 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8945 .dac_nids = alc882_dac_nids,
8946 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
8947 .channel_mode = alc880_threestack_modes,
8948 .need_dac_fix = 1,
8949 .input_mux = &alc882_capture_source,
8950 .dig_out_nid = ALC882_DIGOUT_NID,
8951 },
8952 [ALC885_MBP3] = {
8953 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
8954 .init_verbs = { alc885_mbp3_init_verbs,
8955 alc880_gpio1_init_verbs },
8956 .num_dacs = 2,
8957 .dac_nids = alc882_dac_nids,
8958 .hp_nid = 0x04,
8959 .channel_mode = alc885_mbp_4ch_modes,
8960 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
8961 .input_mux = &alc882_capture_source,
8962 .dig_out_nid = ALC882_DIGOUT_NID,
8963 .dig_in_nid = ALC882_DIGIN_NID,
8964 .unsol_event = alc_automute_amp_unsol_event,
8965 .setup = alc885_mbp3_setup,
8966 .init_hook = alc_automute_amp,
8967 },
8968 [ALC885_MB5] = {
8969 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
8970 .init_verbs = { alc885_mb5_init_verbs,
8971 alc880_gpio1_init_verbs },
8972 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8973 .dac_nids = alc882_dac_nids,
8974 .channel_mode = alc885_mb5_6ch_modes,
8975 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
8976 .input_mux = &mb5_capture_source,
8977 .dig_out_nid = ALC882_DIGOUT_NID,
8978 .dig_in_nid = ALC882_DIGIN_NID,
8979 },
8980 [ALC885_MACPRO] = {
8981 .mixers = { alc882_macpro_mixer },
8982 .init_verbs = { alc882_macpro_init_verbs },
8983 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8984 .dac_nids = alc882_dac_nids,
8985 .dig_out_nid = ALC882_DIGOUT_NID,
8986 .dig_in_nid = ALC882_DIGIN_NID,
8987 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8988 .channel_mode = alc882_ch_modes,
8989 .input_mux = &alc882_capture_source,
8990 .init_hook = alc885_macpro_init_hook,
8991 },
8992 [ALC885_IMAC24] = {
8993 .mixers = { alc885_imac24_mixer },
8994 .init_verbs = { alc885_imac24_init_verbs },
8995 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8996 .dac_nids = alc882_dac_nids,
8997 .dig_out_nid = ALC882_DIGOUT_NID,
8998 .dig_in_nid = ALC882_DIGIN_NID,
8999 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9000 .channel_mode = alc882_ch_modes,
9001 .input_mux = &alc882_capture_source,
9002 .unsol_event = alc_automute_amp_unsol_event,
9003 .setup = alc885_imac24_setup,
9004 .init_hook = alc885_imac24_init_hook,
9005 },
9006 [ALC882_TARGA] = {
9007 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9008 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9009 alc880_gpio3_init_verbs, alc882_targa_verbs},
9010 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9011 .dac_nids = alc882_dac_nids,
9012 .dig_out_nid = ALC882_DIGOUT_NID,
9013 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9014 .adc_nids = alc882_adc_nids,
9015 .capsrc_nids = alc882_capsrc_nids,
9016 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9017 .channel_mode = alc882_3ST_6ch_modes,
9018 .need_dac_fix = 1,
9019 .input_mux = &alc882_capture_source,
9020 .unsol_event = alc882_targa_unsol_event,
9021 .setup = alc882_targa_setup,
9022 .init_hook = alc882_targa_automute,
9023 },
9024 [ALC882_ASUS_A7J] = {
9025 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
9026 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9027 alc882_asus_a7j_verbs},
9028 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9029 .dac_nids = alc882_dac_nids,
9030 .dig_out_nid = ALC882_DIGOUT_NID,
9031 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9032 .adc_nids = alc882_adc_nids,
9033 .capsrc_nids = alc882_capsrc_nids,
9034 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9035 .channel_mode = alc882_3ST_6ch_modes,
9036 .need_dac_fix = 1,
9037 .input_mux = &alc882_capture_source,
9038 },
9039 [ALC882_ASUS_A7M] = {
9040 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
9041 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9042 alc882_eapd_verbs, alc880_gpio1_init_verbs,
9043 alc882_asus_a7m_verbs },
9044 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9045 .dac_nids = alc882_dac_nids,
9046 .dig_out_nid = ALC882_DIGOUT_NID,
9047 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
9048 .channel_mode = alc880_threestack_modes,
9049 .need_dac_fix = 1,
9050 .input_mux = &alc882_capture_source,
9051 },
9182 [ALC883_3ST_2ch_DIG] = { 9052 [ALC883_3ST_2ch_DIG] = {
9183 .mixers = { alc883_3ST_2ch_mixer }, 9053 .mixers = { alc883_3ST_2ch_mixer },
9184 .init_verbs = { alc883_init_verbs }, 9054 .init_verbs = { alc883_init_verbs },
@@ -9225,6 +9095,46 @@ static struct alc_config_preset alc883_presets[] = {
9225 .need_dac_fix = 1, 9095 .need_dac_fix = 1,
9226 .input_mux = &alc883_3stack_6ch_intel, 9096 .input_mux = &alc883_3stack_6ch_intel,
9227 }, 9097 },
9098 [ALC889A_INTEL] = {
9099 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9100 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
9101 alc_hp15_unsol_verbs },
9102 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9103 .dac_nids = alc883_dac_nids,
9104 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9105 .adc_nids = alc889_adc_nids,
9106 .dig_out_nid = ALC883_DIGOUT_NID,
9107 .dig_in_nid = ALC883_DIGIN_NID,
9108 .slave_dig_outs = alc883_slave_dig_outs,
9109 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9110 .channel_mode = alc889_8ch_intel_modes,
9111 .capsrc_nids = alc889_capsrc_nids,
9112 .input_mux = &alc889_capture_source,
9113 .setup = alc889_automute_setup,
9114 .init_hook = alc_automute_amp,
9115 .unsol_event = alc_automute_amp_unsol_event,
9116 .need_dac_fix = 1,
9117 },
9118 [ALC889_INTEL] = {
9119 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9120 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
9121 alc889_eapd_verbs, alc_hp15_unsol_verbs},
9122 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9123 .dac_nids = alc883_dac_nids,
9124 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9125 .adc_nids = alc889_adc_nids,
9126 .dig_out_nid = ALC883_DIGOUT_NID,
9127 .dig_in_nid = ALC883_DIGIN_NID,
9128 .slave_dig_outs = alc883_slave_dig_outs,
9129 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9130 .channel_mode = alc889_8ch_intel_modes,
9131 .capsrc_nids = alc889_capsrc_nids,
9132 .input_mux = &alc889_capture_source,
9133 .setup = alc889_automute_setup,
9134 .init_hook = alc889_intel_init_hook,
9135 .unsol_event = alc_automute_amp_unsol_event,
9136 .need_dac_fix = 1,
9137 },
9228 [ALC883_6ST_DIG] = { 9138 [ALC883_6ST_DIG] = {
9229 .mixers = { alc883_base_mixer, alc883_chmode_mixer }, 9139 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9230 .init_verbs = { alc883_init_verbs }, 9140 .init_verbs = { alc883_init_verbs },
@@ -9238,7 +9148,8 @@ static struct alc_config_preset alc883_presets[] = {
9238 }, 9148 },
9239 [ALC883_TARGA_DIG] = { 9149 [ALC883_TARGA_DIG] = {
9240 .mixers = { alc883_targa_mixer, alc883_chmode_mixer }, 9150 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9241 .init_verbs = { alc883_init_verbs, alc883_targa_verbs}, 9151 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9152 alc883_targa_verbs},
9242 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9153 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9243 .dac_nids = alc883_dac_nids, 9154 .dac_nids = alc883_dac_nids,
9244 .dig_out_nid = ALC883_DIGOUT_NID, 9155 .dig_out_nid = ALC883_DIGOUT_NID,
@@ -9247,11 +9158,13 @@ static struct alc_config_preset alc883_presets[] = {
9247 .need_dac_fix = 1, 9158 .need_dac_fix = 1,
9248 .input_mux = &alc883_capture_source, 9159 .input_mux = &alc883_capture_source,
9249 .unsol_event = alc883_targa_unsol_event, 9160 .unsol_event = alc883_targa_unsol_event,
9250 .init_hook = alc883_targa_init_hook, 9161 .setup = alc882_targa_setup,
9162 .init_hook = alc882_targa_automute,
9251 }, 9163 },
9252 [ALC883_TARGA_2ch_DIG] = { 9164 [ALC883_TARGA_2ch_DIG] = {
9253 .mixers = { alc883_targa_2ch_mixer}, 9165 .mixers = { alc883_targa_2ch_mixer},
9254 .init_verbs = { alc883_init_verbs, alc883_targa_verbs}, 9166 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9167 alc883_targa_verbs},
9255 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9168 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9256 .dac_nids = alc883_dac_nids, 9169 .dac_nids = alc883_dac_nids,
9257 .adc_nids = alc883_adc_nids_alt, 9170 .adc_nids = alc883_adc_nids_alt,
@@ -9261,10 +9174,12 @@ static struct alc_config_preset alc883_presets[] = {
9261 .channel_mode = alc883_3ST_2ch_modes, 9174 .channel_mode = alc883_3ST_2ch_modes,
9262 .input_mux = &alc883_capture_source, 9175 .input_mux = &alc883_capture_source,
9263 .unsol_event = alc883_targa_unsol_event, 9176 .unsol_event = alc883_targa_unsol_event,
9264 .init_hook = alc883_targa_init_hook, 9177 .setup = alc882_targa_setup,
9178 .init_hook = alc882_targa_automute,
9265 }, 9179 },
9266 [ALC883_TARGA_8ch_DIG] = { 9180 [ALC883_TARGA_8ch_DIG] = {
9267 .mixers = { alc883_base_mixer, alc883_chmode_mixer }, 9181 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
9182 alc883_chmode_mixer },
9268 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs, 9183 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9269 alc883_targa_verbs }, 9184 alc883_targa_verbs },
9270 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9185 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
@@ -9279,7 +9194,8 @@ static struct alc_config_preset alc883_presets[] = {
9279 .need_dac_fix = 1, 9194 .need_dac_fix = 1,
9280 .input_mux = &alc883_capture_source, 9195 .input_mux = &alc883_capture_source,
9281 .unsol_event = alc883_targa_unsol_event, 9196 .unsol_event = alc883_targa_unsol_event,
9282 .init_hook = alc883_targa_init_hook, 9197 .setup = alc882_targa_setup,
9198 .init_hook = alc882_targa_automute,
9283 }, 9199 },
9284 [ALC883_ACER] = { 9200 [ALC883_ACER] = {
9285 .mixers = { alc883_base_mixer }, 9201 .mixers = { alc883_base_mixer },
@@ -9305,7 +9221,8 @@ static struct alc_config_preset alc883_presets[] = {
9305 .channel_mode = alc883_3ST_2ch_modes, 9221 .channel_mode = alc883_3ST_2ch_modes,
9306 .input_mux = &alc883_capture_source, 9222 .input_mux = &alc883_capture_source,
9307 .unsol_event = alc_automute_amp_unsol_event, 9223 .unsol_event = alc_automute_amp_unsol_event,
9308 .init_hook = alc883_acer_aspire_init_hook, 9224 .setup = alc883_acer_aspire_setup,
9225 .init_hook = alc_automute_amp,
9309 }, 9226 },
9310 [ALC888_ACER_ASPIRE_4930G] = { 9227 [ALC888_ACER_ASPIRE_4930G] = {
9311 .mixers = { alc888_base_mixer, 9228 .mixers = { alc888_base_mixer,
@@ -9325,7 +9242,8 @@ static struct alc_config_preset alc883_presets[] = {
9325 ARRAY_SIZE(alc888_2_capture_sources), 9242 ARRAY_SIZE(alc888_2_capture_sources),
9326 .input_mux = alc888_2_capture_sources, 9243 .input_mux = alc888_2_capture_sources,
9327 .unsol_event = alc_automute_amp_unsol_event, 9244 .unsol_event = alc_automute_amp_unsol_event,
9328 .init_hook = alc888_acer_aspire_4930g_init_hook, 9245 .setup = alc888_acer_aspire_4930g_setup,
9246 .init_hook = alc_automute_amp,
9329 }, 9247 },
9330 [ALC888_ACER_ASPIRE_6530G] = { 9248 [ALC888_ACER_ASPIRE_6530G] = {
9331 .mixers = { alc888_acer_aspire_6530_mixer }, 9249 .mixers = { alc888_acer_aspire_6530_mixer },
@@ -9343,7 +9261,8 @@ static struct alc_config_preset alc883_presets[] = {
9343 ARRAY_SIZE(alc888_2_capture_sources), 9261 ARRAY_SIZE(alc888_2_capture_sources),
9344 .input_mux = alc888_acer_aspire_6530_sources, 9262 .input_mux = alc888_acer_aspire_6530_sources,
9345 .unsol_event = alc_automute_amp_unsol_event, 9263 .unsol_event = alc_automute_amp_unsol_event,
9346 .init_hook = alc888_acer_aspire_6530g_init_hook, 9264 .setup = alc888_acer_aspire_6530g_setup,
9265 .init_hook = alc_automute_amp,
9347 }, 9266 },
9348 [ALC888_ACER_ASPIRE_8930G] = { 9267 [ALC888_ACER_ASPIRE_8930G] = {
9349 .mixers = { alc888_base_mixer, 9268 .mixers = { alc888_base_mixer,
@@ -9364,7 +9283,28 @@ static struct alc_config_preset alc883_presets[] = {
9364 ARRAY_SIZE(alc889_capture_sources), 9283 ARRAY_SIZE(alc889_capture_sources),
9365 .input_mux = alc889_capture_sources, 9284 .input_mux = alc889_capture_sources,
9366 .unsol_event = alc_automute_amp_unsol_event, 9285 .unsol_event = alc_automute_amp_unsol_event,
9367 .init_hook = alc889_acer_aspire_8930g_init_hook, 9286 .setup = alc889_acer_aspire_8930g_setup,
9287 .init_hook = alc_automute_amp,
9288 },
9289 [ALC888_ACER_ASPIRE_7730G] = {
9290 .mixers = { alc883_3ST_6ch_mixer,
9291 alc883_chmode_mixer },
9292 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9293 alc888_acer_aspire_7730G_verbs },
9294 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9295 .dac_nids = alc883_dac_nids,
9296 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9297 .adc_nids = alc883_adc_nids_rev,
9298 .capsrc_nids = alc883_capsrc_nids_rev,
9299 .dig_out_nid = ALC883_DIGOUT_NID,
9300 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9301 .channel_mode = alc883_3ST_6ch_modes,
9302 .need_dac_fix = 1,
9303 .const_channel_count = 6,
9304 .input_mux = &alc883_capture_source,
9305 .unsol_event = alc_automute_amp_unsol_event,
9306 .setup = alc888_acer_aspire_6530g_setup,
9307 .init_hook = alc_automute_amp,
9368 }, 9308 },
9369 [ALC883_MEDION] = { 9309 [ALC883_MEDION] = {
9370 .mixers = { alc883_fivestack_mixer, 9310 .mixers = { alc883_fivestack_mixer,
@@ -9389,7 +9329,8 @@ static struct alc_config_preset alc883_presets[] = {
9389 .channel_mode = alc883_3ST_2ch_modes, 9329 .channel_mode = alc883_3ST_2ch_modes,
9390 .input_mux = &alc883_capture_source, 9330 .input_mux = &alc883_capture_source,
9391 .unsol_event = alc_automute_amp_unsol_event, 9331 .unsol_event = alc_automute_amp_unsol_event,
9392 .init_hook = alc883_medion_md2_init_hook, 9332 .setup = alc883_medion_md2_setup,
9333 .init_hook = alc_automute_amp,
9393 }, 9334 },
9394 [ALC883_LAPTOP_EAPD] = { 9335 [ALC883_LAPTOP_EAPD] = {
9395 .mixers = { alc883_base_mixer }, 9336 .mixers = { alc883_base_mixer },
@@ -9400,6 +9341,21 @@ static struct alc_config_preset alc883_presets[] = {
9400 .channel_mode = alc883_3ST_2ch_modes, 9341 .channel_mode = alc883_3ST_2ch_modes,
9401 .input_mux = &alc883_capture_source, 9342 .input_mux = &alc883_capture_source,
9402 }, 9343 },
9344 [ALC883_CLEVO_M540R] = {
9345 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9346 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
9347 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9348 .dac_nids = alc883_dac_nids,
9349 .dig_out_nid = ALC883_DIGOUT_NID,
9350 .dig_in_nid = ALC883_DIGIN_NID,
9351 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
9352 .channel_mode = alc883_3ST_6ch_clevo_modes,
9353 .need_dac_fix = 1,
9354 .input_mux = &alc883_capture_source,
9355 /* This machine has the hardware HP auto-muting, thus
9356 * we need no software mute via unsol event
9357 */
9358 },
9403 [ALC883_CLEVO_M720] = { 9359 [ALC883_CLEVO_M720] = {
9404 .mixers = { alc883_clevo_m720_mixer }, 9360 .mixers = { alc883_clevo_m720_mixer },
9405 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs }, 9361 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
@@ -9410,6 +9366,7 @@ static struct alc_config_preset alc883_presets[] = {
9410 .channel_mode = alc883_3ST_2ch_modes, 9366 .channel_mode = alc883_3ST_2ch_modes,
9411 .input_mux = &alc883_capture_source, 9367 .input_mux = &alc883_capture_source,
9412 .unsol_event = alc883_clevo_m720_unsol_event, 9368 .unsol_event = alc883_clevo_m720_unsol_event,
9369 .setup = alc883_clevo_m720_setup,
9413 .init_hook = alc883_clevo_m720_init_hook, 9370 .init_hook = alc883_clevo_m720_init_hook,
9414 }, 9371 },
9415 [ALC883_LENOVO_101E_2ch] = { 9372 [ALC883_LENOVO_101E_2ch] = {
@@ -9435,7 +9392,8 @@ static struct alc_config_preset alc883_presets[] = {
9435 .need_dac_fix = 1, 9392 .need_dac_fix = 1,
9436 .input_mux = &alc883_lenovo_nb0763_capture_source, 9393 .input_mux = &alc883_lenovo_nb0763_capture_source,
9437 .unsol_event = alc_automute_amp_unsol_event, 9394 .unsol_event = alc_automute_amp_unsol_event,
9438 .init_hook = alc883_medion_md2_init_hook, 9395 .setup = alc883_medion_md2_setup,
9396 .init_hook = alc_automute_amp,
9439 }, 9397 },
9440 [ALC888_LENOVO_MS7195_DIG] = { 9398 [ALC888_LENOVO_MS7195_DIG] = {
9441 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer }, 9399 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
@@ -9460,7 +9418,8 @@ static struct alc_config_preset alc883_presets[] = {
9460 .channel_mode = alc883_3ST_2ch_modes, 9418 .channel_mode = alc883_3ST_2ch_modes,
9461 .input_mux = &alc883_capture_source, 9419 .input_mux = &alc883_capture_source,
9462 .unsol_event = alc_automute_amp_unsol_event, 9420 .unsol_event = alc_automute_amp_unsol_event,
9463 .init_hook = alc883_haier_w66_init_hook, 9421 .setup = alc883_haier_w66_setup,
9422 .init_hook = alc_automute_amp,
9464 }, 9423 },
9465 [ALC888_3ST_HP] = { 9424 [ALC888_3ST_HP] = {
9466 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer }, 9425 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
@@ -9472,7 +9431,8 @@ static struct alc_config_preset alc883_presets[] = {
9472 .need_dac_fix = 1, 9431 .need_dac_fix = 1,
9473 .input_mux = &alc883_capture_source, 9432 .input_mux = &alc883_capture_source,
9474 .unsol_event = alc_automute_amp_unsol_event, 9433 .unsol_event = alc_automute_amp_unsol_event,
9475 .init_hook = alc888_3st_hp_init_hook, 9434 .setup = alc888_3st_hp_setup,
9435 .init_hook = alc_automute_amp,
9476 }, 9436 },
9477 [ALC888_6ST_DELL] = { 9437 [ALC888_6ST_DELL] = {
9478 .mixers = { alc883_base_mixer, alc883_chmode_mixer }, 9438 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
@@ -9485,7 +9445,8 @@ static struct alc_config_preset alc883_presets[] = {
9485 .channel_mode = alc883_sixstack_modes, 9445 .channel_mode = alc883_sixstack_modes,
9486 .input_mux = &alc883_capture_source, 9446 .input_mux = &alc883_capture_source,
9487 .unsol_event = alc_automute_amp_unsol_event, 9447 .unsol_event = alc_automute_amp_unsol_event,
9488 .init_hook = alc888_6st_dell_init_hook, 9448 .setup = alc888_6st_dell_setup,
9449 .init_hook = alc_automute_amp,
9489 }, 9450 },
9490 [ALC883_MITAC] = { 9451 [ALC883_MITAC] = {
9491 .mixers = { alc883_mitac_mixer }, 9452 .mixers = { alc883_mitac_mixer },
@@ -9496,7 +9457,8 @@ static struct alc_config_preset alc883_presets[] = {
9496 .channel_mode = alc883_3ST_2ch_modes, 9457 .channel_mode = alc883_3ST_2ch_modes,
9497 .input_mux = &alc883_capture_source, 9458 .input_mux = &alc883_capture_source,
9498 .unsol_event = alc_automute_amp_unsol_event, 9459 .unsol_event = alc_automute_amp_unsol_event,
9499 .init_hook = alc883_mitac_init_hook, 9460 .setup = alc883_mitac_setup,
9461 .init_hook = alc_automute_amp,
9500 }, 9462 },
9501 [ALC883_FUJITSU_PI2515] = { 9463 [ALC883_FUJITSU_PI2515] = {
9502 .mixers = { alc883_2ch_fujitsu_pi2515_mixer }, 9464 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
@@ -9509,7 +9471,8 @@ static struct alc_config_preset alc883_presets[] = {
9509 .channel_mode = alc883_3ST_2ch_modes, 9471 .channel_mode = alc883_3ST_2ch_modes,
9510 .input_mux = &alc883_fujitsu_pi2515_capture_source, 9472 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9511 .unsol_event = alc_automute_amp_unsol_event, 9473 .unsol_event = alc_automute_amp_unsol_event,
9512 .init_hook = alc883_2ch_fujitsu_pi2515_init_hook, 9474 .setup = alc883_2ch_fujitsu_pi2515_setup,
9475 .init_hook = alc_automute_amp,
9513 }, 9476 },
9514 [ALC888_FUJITSU_XA3530] = { 9477 [ALC888_FUJITSU_XA3530] = {
9515 .mixers = { alc888_base_mixer, alc883_chmode_mixer }, 9478 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
@@ -9527,7 +9490,8 @@ static struct alc_config_preset alc883_presets[] = {
9527 ARRAY_SIZE(alc888_2_capture_sources), 9490 ARRAY_SIZE(alc888_2_capture_sources),
9528 .input_mux = alc888_2_capture_sources, 9491 .input_mux = alc888_2_capture_sources,
9529 .unsol_event = alc_automute_amp_unsol_event, 9492 .unsol_event = alc_automute_amp_unsol_event,
9530 .init_hook = alc888_fujitsu_xa3530_init_hook, 9493 .setup = alc888_fujitsu_xa3530_setup,
9494 .init_hook = alc_automute_amp,
9531 }, 9495 },
9532 [ALC888_LENOVO_SKY] = { 9496 [ALC888_LENOVO_SKY] = {
9533 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer }, 9497 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
@@ -9540,7 +9504,8 @@ static struct alc_config_preset alc883_presets[] = {
9540 .need_dac_fix = 1, 9504 .need_dac_fix = 1,
9541 .input_mux = &alc883_lenovo_sky_capture_source, 9505 .input_mux = &alc883_lenovo_sky_capture_source,
9542 .unsol_event = alc_automute_amp_unsol_event, 9506 .unsol_event = alc_automute_amp_unsol_event,
9543 .init_hook = alc888_lenovo_sky_init_hook, 9507 .setup = alc888_lenovo_sky_setup,
9508 .init_hook = alc_automute_amp,
9544 }, 9509 },
9545 [ALC888_ASUS_M90V] = { 9510 [ALC888_ASUS_M90V] = {
9546 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer }, 9511 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
@@ -9553,8 +9518,9 @@ static struct alc_config_preset alc883_presets[] = {
9553 .channel_mode = alc883_3ST_6ch_modes, 9518 .channel_mode = alc883_3ST_6ch_modes,
9554 .need_dac_fix = 1, 9519 .need_dac_fix = 1,
9555 .input_mux = &alc883_fujitsu_pi2515_capture_source, 9520 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9556 .unsol_event = alc883_mode2_unsol_event, 9521 .unsol_event = alc_sku_unsol_event,
9557 .init_hook = alc883_mode2_inithook, 9522 .setup = alc883_mode2_setup,
9523 .init_hook = alc_inithook,
9558 }, 9524 },
9559 [ALC888_ASUS_EEE1601] = { 9525 [ALC888_ASUS_EEE1601] = {
9560 .mixers = { alc883_asus_eee1601_mixer }, 9526 .mixers = { alc883_asus_eee1601_mixer },
@@ -9607,15 +9573,45 @@ static struct alc_config_preset alc883_presets[] = {
9607 .channel_mode = alc883_3ST_2ch_modes, 9573 .channel_mode = alc883_3ST_2ch_modes,
9608 .input_mux = &alc883_capture_source, 9574 .input_mux = &alc883_capture_source,
9609 .unsol_event = alc_automute_amp_unsol_event, 9575 .unsol_event = alc_automute_amp_unsol_event,
9610 .init_hook = alc883_vaiott_init_hook, 9576 .setup = alc883_vaiott_setup,
9577 .init_hook = alc_automute_amp,
9611 }, 9578 },
9612}; 9579};
9613 9580
9614 9581
9615/* 9582/*
9583 * Pin config fixes
9584 */
9585enum {
9586 PINFIX_ABIT_AW9D_MAX
9587};
9588
9589static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
9590 { 0x15, 0x01080104 }, /* side */
9591 { 0x16, 0x01011012 }, /* rear */
9592 { 0x17, 0x01016011 }, /* clfe */
9593 { }
9594};
9595
9596static const struct alc_pincfg *alc882_pin_fixes[] = {
9597 [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
9598};
9599
9600static struct snd_pci_quirk alc882_pinfix_tbl[] = {
9601 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
9602 {}
9603};
9604
9605/*
9616 * BIOS auto configuration 9606 * BIOS auto configuration
9617 */ 9607 */
9618static void alc883_auto_set_output_and_unmute(struct hda_codec *codec, 9608static int alc882_auto_create_input_ctls(struct hda_codec *codec,
9609 const struct auto_pin_cfg *cfg)
9610{
9611 return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
9612}
9613
9614static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
9619 hda_nid_t nid, int pin_type, 9615 hda_nid_t nid, int pin_type,
9620 int dac_idx) 9616 int dac_idx)
9621{ 9617{
@@ -9632,7 +9628,7 @@ static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
9632 9628
9633} 9629}
9634 9630
9635static void alc883_auto_init_multi_out(struct hda_codec *codec) 9631static void alc882_auto_init_multi_out(struct hda_codec *codec)
9636{ 9632{
9637 struct alc_spec *spec = codec->spec; 9633 struct alc_spec *spec = codec->spec;
9638 int i; 9634 int i;
@@ -9641,12 +9637,12 @@ static void alc883_auto_init_multi_out(struct hda_codec *codec)
9641 hda_nid_t nid = spec->autocfg.line_out_pins[i]; 9637 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9642 int pin_type = get_pin_type(spec->autocfg.line_out_type); 9638 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9643 if (nid) 9639 if (nid)
9644 alc883_auto_set_output_and_unmute(codec, nid, pin_type, 9640 alc882_auto_set_output_and_unmute(codec, nid, pin_type,
9645 i); 9641 i);
9646 } 9642 }
9647} 9643}
9648 9644
9649static void alc883_auto_init_hp_out(struct hda_codec *codec) 9645static void alc882_auto_init_hp_out(struct hda_codec *codec)
9650{ 9646{
9651 struct alc_spec *spec = codec->spec; 9647 struct alc_spec *spec = codec->spec;
9652 hda_nid_t pin; 9648 hda_nid_t pin;
@@ -9654,91 +9650,191 @@ static void alc883_auto_init_hp_out(struct hda_codec *codec)
9654 pin = spec->autocfg.hp_pins[0]; 9650 pin = spec->autocfg.hp_pins[0];
9655 if (pin) /* connect to front */ 9651 if (pin) /* connect to front */
9656 /* use dac 0 */ 9652 /* use dac 0 */
9657 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 9653 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9658 pin = spec->autocfg.speaker_pins[0]; 9654 pin = spec->autocfg.speaker_pins[0];
9659 if (pin) 9655 if (pin)
9660 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); 9656 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9661} 9657}
9662 9658
9663#define alc883_is_input_pin(nid) alc880_is_input_pin(nid) 9659static void alc882_auto_init_analog_input(struct hda_codec *codec)
9664#define ALC883_PIN_CD_NID ALC880_PIN_CD_NID
9665
9666static void alc883_auto_init_analog_input(struct hda_codec *codec)
9667{ 9660{
9668 struct alc_spec *spec = codec->spec; 9661 struct alc_spec *spec = codec->spec;
9669 int i; 9662 int i;
9670 9663
9671 for (i = 0; i < AUTO_PIN_LAST; i++) { 9664 for (i = 0; i < AUTO_PIN_LAST; i++) {
9672 hda_nid_t nid = spec->autocfg.input_pins[i]; 9665 hda_nid_t nid = spec->autocfg.input_pins[i];
9673 if (alc883_is_input_pin(nid)) { 9666 if (!nid)
9674 alc_set_input_pin(codec, nid, i); 9667 continue;
9675 if (nid != ALC883_PIN_CD_NID && 9668 alc_set_input_pin(codec, nid, i);
9676 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 9669 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
9670 snd_hda_codec_write(codec, nid, 0,
9671 AC_VERB_SET_AMP_GAIN_MUTE,
9672 AMP_OUT_MUTE);
9673 }
9674}
9675
9676static void alc882_auto_init_input_src(struct hda_codec *codec)
9677{
9678 struct alc_spec *spec = codec->spec;
9679 int c;
9680
9681 for (c = 0; c < spec->num_adc_nids; c++) {
9682 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
9683 hda_nid_t nid = spec->capsrc_nids[c];
9684 unsigned int mux_idx;
9685 const struct hda_input_mux *imux;
9686 int conns, mute, idx, item;
9687
9688 conns = snd_hda_get_connections(codec, nid, conn_list,
9689 ARRAY_SIZE(conn_list));
9690 if (conns < 0)
9691 continue;
9692 mux_idx = c >= spec->num_mux_defs ? 0 : c;
9693 imux = &spec->input_mux[mux_idx];
9694 for (idx = 0; idx < conns; idx++) {
9695 /* if the current connection is the selected one,
9696 * unmute it as default - otherwise mute it
9697 */
9698 mute = AMP_IN_MUTE(idx);
9699 for (item = 0; item < imux->num_items; item++) {
9700 if (imux->items[item].index == idx) {
9701 if (spec->cur_mux[c] == item)
9702 mute = AMP_IN_UNMUTE(idx);
9703 break;
9704 }
9705 }
9706 /* check if we have a selector or mixer
9707 * we could check for the widget type instead, but
9708 * just check for Amp-In presence (in case of mixer
9709 * without amp-in there is something wrong, this
9710 * function shouldn't be used or capsrc nid is wrong)
9711 */
9712 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
9677 snd_hda_codec_write(codec, nid, 0, 9713 snd_hda_codec_write(codec, nid, 0,
9678 AC_VERB_SET_AMP_GAIN_MUTE, 9714 AC_VERB_SET_AMP_GAIN_MUTE,
9679 AMP_OUT_MUTE); 9715 mute);
9716 else if (mute != AMP_IN_MUTE(idx))
9717 snd_hda_codec_write(codec, nid, 0,
9718 AC_VERB_SET_CONNECT_SEL,
9719 idx);
9680 } 9720 }
9681 } 9721 }
9682} 9722}
9683 9723
9684#define alc883_auto_init_input_src alc882_auto_init_input_src 9724/* add mic boosts if needed */
9725static int alc_auto_add_mic_boost(struct hda_codec *codec)
9726{
9727 struct alc_spec *spec = codec->spec;
9728 int err;
9729 hda_nid_t nid;
9730
9731 nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
9732 if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9733 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9734 "Mic Boost",
9735 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9736 if (err < 0)
9737 return err;
9738 }
9739 nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
9740 if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9741 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9742 "Front Mic Boost",
9743 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9744 if (err < 0)
9745 return err;
9746 }
9747 return 0;
9748}
9685 9749
9686/* almost identical with ALC880 parser... */ 9750/* almost identical with ALC880 parser... */
9687static int alc883_parse_auto_config(struct hda_codec *codec) 9751static int alc882_parse_auto_config(struct hda_codec *codec)
9688{ 9752{
9689 struct alc_spec *spec = codec->spec; 9753 struct alc_spec *spec = codec->spec;
9690 int err = alc880_parse_auto_config(codec); 9754 static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
9691 struct auto_pin_cfg *cfg = &spec->autocfg; 9755 int i, err;
9692 int i;
9693 9756
9757 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9758 alc882_ignore);
9694 if (err < 0) 9759 if (err < 0)
9695 return err; 9760 return err;
9696 else if (!err) 9761 if (!spec->autocfg.line_outs)
9697 return 0; /* no config found */ 9762 return 0; /* can't find valid BIOS pin config */
9698 9763
9699 err = alc_auto_add_mic_boost(codec); 9764 err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
9765 if (err < 0)
9766 return err;
9767 err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
9768 if (err < 0)
9769 return err;
9770 err = alc880_auto_create_extra_out(spec,
9771 spec->autocfg.speaker_pins[0],
9772 "Speaker");
9773 if (err < 0)
9774 return err;
9775 err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
9776 "Headphone");
9777 if (err < 0)
9778 return err;
9779 err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
9700 if (err < 0) 9780 if (err < 0)
9701 return err; 9781 return err;
9702 9782
9703 /* hack - override the init verbs */ 9783 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9704 spec->init_verbs[0] = alc883_auto_init_verbs;
9705 9784
9706 /* setup input_mux for ALC889 */ 9785 /* check multiple SPDIF-out (for recent codecs) */
9707 if (codec->vendor_id == 0x10ec0889) { 9786 for (i = 0; i < spec->autocfg.dig_outs; i++) {
9708 /* digital-mic input pin is excluded in alc880_auto_create..() 9787 hda_nid_t dig_nid;
9709 * because it's under 0x18 9788 err = snd_hda_get_connections(codec,
9710 */ 9789 spec->autocfg.dig_out_pins[i],
9711 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 || 9790 &dig_nid, 1);
9712 cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) { 9791 if (err < 0)
9713 struct hda_input_mux *imux = &spec->private_imux[0]; 9792 continue;
9714 for (i = 1; i < 3; i++) 9793 if (!i)
9715 memcpy(&spec->private_imux[i], 9794 spec->multiout.dig_out_nid = dig_nid;
9716 &spec->private_imux[0], 9795 else {
9717 sizeof(spec->private_imux[0])); 9796 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9718 imux->items[imux->num_items].label = "Int DMic"; 9797 spec->slave_dig_outs[i - 1] = dig_nid;
9719 imux->items[imux->num_items].index = 0x0b; 9798 if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
9720 imux->num_items++; 9799 break;
9721 spec->num_mux_defs = 3;
9722 spec->input_mux = spec->private_imux;
9723 } 9800 }
9724 } 9801 }
9802 if (spec->autocfg.dig_in_pin)
9803 spec->dig_in_nid = ALC880_DIGIN_NID;
9804
9805 if (spec->kctls.list)
9806 add_mixer(spec, spec->kctls.list);
9807
9808 add_verb(spec, alc883_auto_init_verbs);
9809 /* if ADC 0x07 is available, initialize it, too */
9810 if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
9811 add_verb(spec, alc882_adc1_init_verbs);
9812
9813 spec->num_mux_defs = 1;
9814 spec->input_mux = &spec->private_imux[0];
9815
9816 alc_ssid_check(codec, 0x15, 0x1b, 0x14);
9817
9818 err = alc_auto_add_mic_boost(codec);
9819 if (err < 0)
9820 return err;
9725 9821
9726 return 1; /* config found */ 9822 return 1; /* config found */
9727} 9823}
9728 9824
9729/* additional initialization for auto-configuration model */ 9825/* additional initialization for auto-configuration model */
9730static void alc883_auto_init(struct hda_codec *codec) 9826static void alc882_auto_init(struct hda_codec *codec)
9731{ 9827{
9732 struct alc_spec *spec = codec->spec; 9828 struct alc_spec *spec = codec->spec;
9733 alc883_auto_init_multi_out(codec); 9829 alc882_auto_init_multi_out(codec);
9734 alc883_auto_init_hp_out(codec); 9830 alc882_auto_init_hp_out(codec);
9735 alc883_auto_init_analog_input(codec); 9831 alc882_auto_init_analog_input(codec);
9736 alc883_auto_init_input_src(codec); 9832 alc882_auto_init_input_src(codec);
9737 if (spec->unsol_event) 9833 if (spec->unsol_event)
9738 alc_inithook(codec); 9834 alc_inithook(codec);
9739} 9835}
9740 9836
9741static int patch_alc883(struct hda_codec *codec) 9837static int patch_alc882(struct hda_codec *codec)
9742{ 9838{
9743 struct alc_spec *spec; 9839 struct alc_spec *spec;
9744 int err, board_config; 9840 int err, board_config;
@@ -9749,28 +9845,35 @@ static int patch_alc883(struct hda_codec *codec)
9749 9845
9750 codec->spec = spec; 9846 codec->spec = spec;
9751 9847
9752 alc_fix_pll_init(codec, 0x20, 0x0a, 10); 9848 switch (codec->vendor_id) {
9849 case 0x10ec0882:
9850 case 0x10ec0885:
9851 break;
9852 default:
9853 /* ALC883 and variants */
9854 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9855 break;
9856 }
9753 9857
9754 board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST, 9858 board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
9755 alc883_models, 9859 alc882_models,
9756 alc883_cfg_tbl); 9860 alc882_cfg_tbl);
9757 if (board_config < 0 || board_config >= ALC883_MODEL_LAST) { 9861
9758 /* Pick up systems that don't supply PCI SSID */ 9862 if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
9759 switch (codec->subsystem_id) { 9863 board_config = snd_hda_check_board_codec_sid_config(codec,
9760 case 0x106b3600: /* Macbook 3.1 */ 9864 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
9761 board_config = ALC889A_MB31; 9865
9762 break; 9866 if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9763 default: 9867 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
9764 printk(KERN_INFO 9868 codec->chip_name);
9765 "hda_codec: Unknown model for %s, trying " 9869 board_config = ALC882_AUTO;
9766 "auto-probe from BIOS...\n", codec->chip_name);
9767 board_config = ALC883_AUTO;
9768 }
9769 } 9870 }
9770 9871
9771 if (board_config == ALC883_AUTO) { 9872 alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
9873
9874 if (board_config == ALC882_AUTO) {
9772 /* automatic parse from the BIOS config */ 9875 /* automatic parse from the BIOS config */
9773 err = alc883_parse_auto_config(codec); 9876 err = alc882_parse_auto_config(codec);
9774 if (err < 0) { 9877 if (err < 0) {
9775 alc_free(codec); 9878 alc_free(codec);
9776 return err; 9879 return err;
@@ -9778,7 +9881,7 @@ static int patch_alc883(struct hda_codec *codec)
9778 printk(KERN_INFO 9881 printk(KERN_INFO
9779 "hda_codec: Cannot set up configuration " 9882 "hda_codec: Cannot set up configuration "
9780 "from BIOS. Using base mode...\n"); 9883 "from BIOS. Using base mode...\n");
9781 board_config = ALC883_3ST_2ch_DIG; 9884 board_config = ALC882_3ST_DIG;
9782 } 9885 }
9783 } 9886 }
9784 9887
@@ -9788,63 +9891,61 @@ static int patch_alc883(struct hda_codec *codec)
9788 return err; 9891 return err;
9789 } 9892 }
9790 9893
9791 if (board_config != ALC883_AUTO) 9894 if (board_config != ALC882_AUTO)
9792 setup_preset(spec, &alc883_presets[board_config]); 9895 setup_preset(codec, &alc882_presets[board_config]);
9793 9896
9794 switch (codec->vendor_id) { 9897 spec->stream_analog_playback = &alc882_pcm_analog_playback;
9795 case 0x10ec0888: 9898 spec->stream_analog_capture = &alc882_pcm_analog_capture;
9796 if (!spec->num_adc_nids) { 9899 /* FIXME: setup DAC5 */
9797 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids); 9900 /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
9798 spec->adc_nids = alc883_adc_nids; 9901 spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
9799 } 9902
9800 if (!spec->capsrc_nids) 9903 spec->stream_digital_playback = &alc882_pcm_digital_playback;
9801 spec->capsrc_nids = alc883_capsrc_nids; 9904 spec->stream_digital_capture = &alc882_pcm_digital_capture;
9905
9906 if (codec->vendor_id == 0x10ec0888)
9802 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */ 9907 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9803 break; 9908
9804 case 0x10ec0889: 9909 if (!spec->adc_nids && spec->input_mux) {
9805 if (!spec->num_adc_nids) { 9910 int i;
9806 spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids); 9911 spec->num_adc_nids = 0;
9807 spec->adc_nids = alc889_adc_nids; 9912 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
9808 } 9913 hda_nid_t cap;
9809 if (!spec->capsrc_nids) 9914 hda_nid_t nid = alc882_adc_nids[i];
9810 spec->capsrc_nids = alc889_capsrc_nids; 9915 unsigned int wcap = get_wcaps(codec, nid);
9811 break; 9916 /* get type */
9812 default: 9917 wcap = get_wcaps_type(wcap);
9813 if (!spec->num_adc_nids) { 9918 if (wcap != AC_WID_AUD_IN)
9814 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids); 9919 continue;
9815 spec->adc_nids = alc883_adc_nids; 9920 spec->private_adc_nids[spec->num_adc_nids] = nid;
9921 err = snd_hda_get_connections(codec, nid, &cap, 1);
9922 if (err < 0)
9923 continue;
9924 spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9925 spec->num_adc_nids++;
9816 } 9926 }
9817 if (!spec->capsrc_nids) 9927 spec->adc_nids = spec->private_adc_nids;
9818 spec->capsrc_nids = alc883_capsrc_nids; 9928 spec->capsrc_nids = spec->private_capsrc_nids;
9819 break;
9820 } 9929 }
9821 9930
9822 spec->stream_analog_playback = &alc883_pcm_analog_playback; 9931 set_capture_mixer(codec);
9823 spec->stream_analog_capture = &alc883_pcm_analog_capture;
9824 spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9825
9826 spec->stream_digital_playback = &alc883_pcm_digital_playback;
9827 spec->stream_digital_capture = &alc883_pcm_digital_capture;
9828
9829 if (!spec->cap_mixer)
9830 set_capture_mixer(spec);
9831 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 9932 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9832 9933
9833 spec->vmaster_nid = 0x0c; 9934 spec->vmaster_nid = 0x0c;
9834 9935
9835 codec->patch_ops = alc_patch_ops; 9936 codec->patch_ops = alc_patch_ops;
9836 if (board_config == ALC883_AUTO) 9937 if (board_config == ALC882_AUTO)
9837 spec->init_hook = alc883_auto_init; 9938 spec->init_hook = alc882_auto_init;
9838
9839#ifdef CONFIG_SND_HDA_POWER_SAVE 9939#ifdef CONFIG_SND_HDA_POWER_SAVE
9840 if (!spec->loopback.amplist) 9940 if (!spec->loopback.amplist)
9841 spec->loopback.amplist = alc883_loopbacks; 9941 spec->loopback.amplist = alc882_loopbacks;
9842#endif 9942#endif
9843 codec->proc_widget_hook = print_realtek_coef; 9943 codec->proc_widget_hook = print_realtek_coef;
9844 9944
9845 return 0; 9945 return 0;
9846} 9946}
9847 9947
9948
9848/* 9949/*
9849 * ALC262 support 9950 * ALC262 support
9850 */ 9951 */
@@ -10020,13 +10121,12 @@ static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10020}; 10121};
10021 10122
10022/* mute/unmute internal speaker according to the hp jack and mute state */ 10123/* mute/unmute internal speaker according to the hp jack and mute state */
10023static void alc262_hp_t5735_init_hook(struct hda_codec *codec) 10124static void alc262_hp_t5735_setup(struct hda_codec *codec)
10024{ 10125{
10025 struct alc_spec *spec = codec->spec; 10126 struct alc_spec *spec = codec->spec;
10026 10127
10027 spec->autocfg.hp_pins[0] = 0x15; 10128 spec->autocfg.hp_pins[0] = 0x15;
10028 spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */ 10129 spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10029 alc_automute_amp(codec);
10030} 10130}
10031 10131
10032static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = { 10132static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
@@ -10183,22 +10283,20 @@ static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10183 alc262_hippo_automute(codec); 10283 alc262_hippo_automute(codec);
10184} 10284}
10185 10285
10186static void alc262_hippo_init_hook(struct hda_codec *codec) 10286static void alc262_hippo_setup(struct hda_codec *codec)
10187{ 10287{
10188 struct alc_spec *spec = codec->spec; 10288 struct alc_spec *spec = codec->spec;
10189 10289
10190 spec->autocfg.hp_pins[0] = 0x15; 10290 spec->autocfg.hp_pins[0] = 0x15;
10191 spec->autocfg.speaker_pins[0] = 0x14; 10291 spec->autocfg.speaker_pins[0] = 0x14;
10192 alc262_hippo_automute(codec);
10193} 10292}
10194 10293
10195static void alc262_hippo1_init_hook(struct hda_codec *codec) 10294static void alc262_hippo1_setup(struct hda_codec *codec)
10196{ 10295{
10197 struct alc_spec *spec = codec->spec; 10296 struct alc_spec *spec = codec->spec;
10198 10297
10199 spec->autocfg.hp_pins[0] = 0x1b; 10298 spec->autocfg.hp_pins[0] = 0x1b;
10200 spec->autocfg.speaker_pins[0] = 0x14; 10299 spec->autocfg.speaker_pins[0] = 0x14;
10201 alc262_hippo_automute(codec);
10202} 10300}
10203 10301
10204 10302
@@ -10255,13 +10353,12 @@ static struct hda_verb alc262_tyan_verbs[] = {
10255}; 10353};
10256 10354
10257/* unsolicited event for HP jack sensing */ 10355/* unsolicited event for HP jack sensing */
10258static void alc262_tyan_init_hook(struct hda_codec *codec) 10356static void alc262_tyan_setup(struct hda_codec *codec)
10259{ 10357{
10260 struct alc_spec *spec = codec->spec; 10358 struct alc_spec *spec = codec->spec;
10261 10359
10262 spec->autocfg.hp_pins[0] = 0x1b; 10360 spec->autocfg.hp_pins[0] = 0x1b;
10263 spec->autocfg.speaker_pins[0] = 0x15; 10361 spec->autocfg.speaker_pins[0] = 0x15;
10264 alc_automute_amp(codec);
10265} 10362}
10266 10363
10267 10364
@@ -10353,12 +10450,6 @@ static struct hda_verb alc262_eapd_verbs[] = {
10353 { } 10450 { }
10354}; 10451};
10355 10452
10356static struct hda_verb alc262_hippo_unsol_verbs[] = {
10357 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10358 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10359 {}
10360};
10361
10362static struct hda_verb alc262_hippo1_unsol_verbs[] = { 10453static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10363 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0}, 10454 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10364 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 10455 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -10379,14 +10470,6 @@ static struct hda_verb alc262_sony_unsol_verbs[] = {
10379 {} 10470 {}
10380}; 10471};
10381 10472
10382static struct hda_input_mux alc262_dmic_capture_source = {
10383 .num_items = 2,
10384 .items = {
10385 { "Int DMic", 0x9 },
10386 { "Mic", 0x0 },
10387 },
10388};
10389
10390static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = { 10473static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10391 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 10474 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10392 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), 10475 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
@@ -10408,35 +10491,17 @@ static struct hda_verb alc262_toshiba_s06_verbs[] = {
10408 {} 10491 {}
10409}; 10492};
10410 10493
10411static void alc262_dmic_automute(struct hda_codec *codec) 10494static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10412{
10413 unsigned int present;
10414
10415 present = snd_hda_codec_read(codec, 0x18, 0,
10416 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10417 snd_hda_codec_write(codec, 0x22, 0,
10418 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
10419}
10420
10421
10422/* unsolicited event for HP jack sensing */
10423static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
10424 unsigned int res)
10425{
10426 if ((res >> 26) == ALC880_MIC_EVENT)
10427 alc262_dmic_automute(codec);
10428 else
10429 alc_sku_unsol_event(codec, res);
10430}
10431
10432static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
10433{ 10495{
10434 struct alc_spec *spec = codec->spec; 10496 struct alc_spec *spec = codec->spec;
10435 10497
10436 spec->autocfg.hp_pins[0] = 0x15; 10498 spec->autocfg.hp_pins[0] = 0x15;
10437 spec->autocfg.speaker_pins[0] = 0x14; 10499 spec->autocfg.speaker_pins[0] = 0x14;
10438 alc_automute_pin(codec); 10500 spec->ext_mic.pin = 0x18;
10439 alc262_dmic_automute(codec); 10501 spec->ext_mic.mux_idx = 0;
10502 spec->int_mic.pin = 0x12;
10503 spec->int_mic.mux_idx = 9;
10504 spec->auto_mic = 1;
10440} 10505}
10441 10506
10442/* 10507/*
@@ -10625,6 +10690,18 @@ static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10625 alc262_lenovo_3000_automute(codec, 1); 10690 alc262_lenovo_3000_automute(codec, 1);
10626} 10691}
10627 10692
10693static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
10694 int dir, int idx, long *valp)
10695{
10696 int i, change = 0;
10697
10698 for (i = 0; i < 2; i++, valp++)
10699 change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
10700 HDA_AMP_MUTE,
10701 *valp ? 0 : HDA_AMP_MUTE);
10702 return change;
10703}
10704
10628/* bind hp and internal speaker mute (with plug check) */ 10705/* bind hp and internal speaker mute (with plug check) */
10629static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol, 10706static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10630 struct snd_ctl_elem_value *ucontrol) 10707 struct snd_ctl_elem_value *ucontrol)
@@ -10633,13 +10710,8 @@ static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10633 long *valp = ucontrol->value.integer.value; 10710 long *valp = ucontrol->value.integer.value;
10634 int change; 10711 int change;
10635 10712
10636 change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 10713 change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10637 HDA_AMP_MUTE, 10714 change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10638 valp ? 0 : HDA_AMP_MUTE);
10639 change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10640 HDA_AMP_MUTE,
10641 valp ? 0 : HDA_AMP_MUTE);
10642
10643 if (change) 10715 if (change)
10644 alc262_fujitsu_automute(codec, 0); 10716 alc262_fujitsu_automute(codec, 0);
10645 return change; 10717 return change;
@@ -10674,10 +10746,7 @@ static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10674 long *valp = ucontrol->value.integer.value; 10746 long *valp = ucontrol->value.integer.value;
10675 int change; 10747 int change;
10676 10748
10677 change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0, 10749 change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10678 HDA_AMP_MUTE,
10679 valp ? 0 : HDA_AMP_MUTE);
10680
10681 if (change) 10750 if (change)
10682 alc262_lenovo_3000_automute(codec, 0); 10751 alc262_lenovo_3000_automute(codec, 0);
10683 return change; 10752 return change;
@@ -10850,104 +10919,111 @@ static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10850 { } /* end */ 10919 { } /* end */
10851}; 10920};
10852 10921
10922/* We use two mixers depending on the output pin; 0x16 is a mono output
10923 * and thus it's bound with a different mixer.
10924 * This function returns which mixer amp should be used.
10925 */
10926static int alc262_check_volbit(hda_nid_t nid)
10927{
10928 if (!nid)
10929 return 0;
10930 else if (nid == 0x16)
10931 return 2;
10932 else
10933 return 1;
10934}
10935
10936static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10937 const char *pfx, int *vbits)
10938{
10939 char name[32];
10940 unsigned long val;
10941 int vbit;
10942
10943 vbit = alc262_check_volbit(nid);
10944 if (!vbit)
10945 return 0;
10946 if (*vbits & vbit) /* a volume control for this mixer already there */
10947 return 0;
10948 *vbits |= vbit;
10949 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
10950 if (vbit == 2)
10951 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10952 else
10953 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10954 return add_control(spec, ALC_CTL_WIDGET_VOL, name, val);
10955}
10956
10957static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10958 const char *pfx)
10959{
10960 char name[32];
10961 unsigned long val;
10962
10963 if (!nid)
10964 return 0;
10965 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
10966 if (nid == 0x16)
10967 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10968 else
10969 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10970 return add_control(spec, ALC_CTL_WIDGET_MUTE, name, val);
10971}
10972
10853/* add playback controls from the parsed DAC table */ 10973/* add playback controls from the parsed DAC table */
10854static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, 10974static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10855 const struct auto_pin_cfg *cfg) 10975 const struct auto_pin_cfg *cfg)
10856{ 10976{
10857 hda_nid_t nid; 10977 const char *pfx;
10978 int vbits;
10858 int err; 10979 int err;
10859 10980
10860 spec->multiout.num_dacs = 1; /* only use one dac */ 10981 spec->multiout.num_dacs = 1; /* only use one dac */
10861 spec->multiout.dac_nids = spec->private_dac_nids; 10982 spec->multiout.dac_nids = spec->private_dac_nids;
10862 spec->multiout.dac_nids[0] = 2; 10983 spec->multiout.dac_nids[0] = 2;
10863 10984
10864 nid = cfg->line_out_pins[0]; 10985 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
10865 if (nid) { 10986 pfx = "Master";
10866 err = add_control(spec, ALC_CTL_WIDGET_VOL, 10987 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
10867 "Front Playback Volume", 10988 pfx = "Speaker";
10868 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT)); 10989 else
10869 if (err < 0) 10990 pfx = "Front";
10870 return err; 10991 err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
10871 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 10992 if (err < 0)
10872 "Front Playback Switch", 10993 return err;
10873 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT)); 10994 err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
10874 if (err < 0) 10995 if (err < 0)
10875 return err; 10996 return err;
10876 } 10997 err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
10877 10998 if (err < 0)
10878 nid = cfg->speaker_pins[0]; 10999 return err;
10879 if (nid) {
10880 if (nid == 0x16) {
10881 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10882 "Speaker Playback Volume",
10883 HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10884 HDA_OUTPUT));
10885 if (err < 0)
10886 return err;
10887 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10888 "Speaker Playback Switch",
10889 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10890 HDA_OUTPUT));
10891 if (err < 0)
10892 return err;
10893 } else {
10894 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10895 "Speaker Playback Switch",
10896 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10897 HDA_OUTPUT));
10898 if (err < 0)
10899 return err;
10900 }
10901 }
10902 nid = cfg->hp_pins[0];
10903 if (nid) {
10904 /* spec->multiout.hp_nid = 2; */
10905 if (nid == 0x16) {
10906 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10907 "Headphone Playback Volume",
10908 HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10909 HDA_OUTPUT));
10910 if (err < 0)
10911 return err;
10912 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10913 "Headphone Playback Switch",
10914 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10915 HDA_OUTPUT));
10916 if (err < 0)
10917 return err;
10918 } else {
10919 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10920 "Headphone Playback Switch",
10921 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10922 HDA_OUTPUT));
10923 if (err < 0)
10924 return err;
10925 }
10926 }
10927 return 0;
10928}
10929
10930static int alc262_auto_create_analog_input_ctls(struct alc_spec *spec,
10931 const struct auto_pin_cfg *cfg)
10932{
10933 int err;
10934 11000
10935 err = alc880_auto_create_analog_input_ctls(spec, cfg); 11001 vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
11002 alc262_check_volbit(cfg->speaker_pins[0]) |
11003 alc262_check_volbit(cfg->hp_pins[0]);
11004 if (vbits == 1 || vbits == 2)
11005 pfx = "Master"; /* only one mixer is used */
11006 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11007 pfx = "Speaker";
11008 else
11009 pfx = "Front";
11010 vbits = 0;
11011 err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[0], pfx, &vbits);
11012 if (err < 0)
11013 return err;
11014 err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[0], "Speaker",
11015 &vbits);
11016 if (err < 0)
11017 return err;
11018 err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[0], "Headphone",
11019 &vbits);
10936 if (err < 0) 11020 if (err < 0)
10937 return err; 11021 return err;
10938 /* digital-mic input pin is excluded in alc880_auto_create..()
10939 * because it's under 0x18
10940 */
10941 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
10942 cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
10943 struct hda_input_mux *imux = &spec->private_imux[0];
10944 imux->items[imux->num_items].label = "Int Mic";
10945 imux->items[imux->num_items].index = 0x09;
10946 imux->num_items++;
10947 }
10948 return 0; 11022 return 0;
10949} 11023}
10950 11024
11025#define alc262_auto_create_input_ctls \
11026 alc880_auto_create_input_ctls
10951 11027
10952/* 11028/*
10953 * generic initialization of ADC, input mixers and output mixers 11029 * generic initialization of ADC, input mixers and output mixers
@@ -11265,7 +11341,7 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
11265 err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg); 11341 err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11266 if (err < 0) 11342 if (err < 0)
11267 return err; 11343 return err;
11268 err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg); 11344 err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11269 if (err < 0) 11345 if (err < 0)
11270 return err; 11346 return err;
11271 11347
@@ -11396,7 +11472,7 @@ static struct alc_config_preset alc262_presets[] = {
11396 }, 11472 },
11397 [ALC262_HIPPO] = { 11473 [ALC262_HIPPO] = {
11398 .mixers = { alc262_hippo_mixer }, 11474 .mixers = { alc262_hippo_mixer },
11399 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs}, 11475 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11400 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 11476 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11401 .dac_nids = alc262_dac_nids, 11477 .dac_nids = alc262_dac_nids,
11402 .hp_nid = 0x03, 11478 .hp_nid = 0x03,
@@ -11405,7 +11481,8 @@ static struct alc_config_preset alc262_presets[] = {
11405 .channel_mode = alc262_modes, 11481 .channel_mode = alc262_modes,
11406 .input_mux = &alc262_capture_source, 11482 .input_mux = &alc262_capture_source,
11407 .unsol_event = alc262_hippo_unsol_event, 11483 .unsol_event = alc262_hippo_unsol_event,
11408 .init_hook = alc262_hippo_init_hook, 11484 .setup = alc262_hippo_setup,
11485 .init_hook = alc262_hippo_automute,
11409 }, 11486 },
11410 [ALC262_HIPPO_1] = { 11487 [ALC262_HIPPO_1] = {
11411 .mixers = { alc262_hippo1_mixer }, 11488 .mixers = { alc262_hippo1_mixer },
@@ -11418,7 +11495,8 @@ static struct alc_config_preset alc262_presets[] = {
11418 .channel_mode = alc262_modes, 11495 .channel_mode = alc262_modes,
11419 .input_mux = &alc262_capture_source, 11496 .input_mux = &alc262_capture_source,
11420 .unsol_event = alc262_hippo_unsol_event, 11497 .unsol_event = alc262_hippo_unsol_event,
11421 .init_hook = alc262_hippo1_init_hook, 11498 .setup = alc262_hippo1_setup,
11499 .init_hook = alc262_hippo_automute,
11422 }, 11500 },
11423 [ALC262_FUJITSU] = { 11501 [ALC262_FUJITSU] = {
11424 .mixers = { alc262_fujitsu_mixer }, 11502 .mixers = { alc262_fujitsu_mixer },
@@ -11481,7 +11559,8 @@ static struct alc_config_preset alc262_presets[] = {
11481 .channel_mode = alc262_modes, 11559 .channel_mode = alc262_modes,
11482 .input_mux = &alc262_capture_source, 11560 .input_mux = &alc262_capture_source,
11483 .unsol_event = alc_automute_amp_unsol_event, 11561 .unsol_event = alc_automute_amp_unsol_event,
11484 .init_hook = alc262_hp_t5735_init_hook, 11562 .setup = alc262_hp_t5735_setup,
11563 .init_hook = alc_automute_amp,
11485 }, 11564 },
11486 [ALC262_HP_RP5700] = { 11565 [ALC262_HP_RP5700] = {
11487 .mixers = { alc262_hp_rp5700_mixer }, 11566 .mixers = { alc262_hp_rp5700_mixer },
@@ -11512,11 +11591,13 @@ static struct alc_config_preset alc262_presets[] = {
11512 .channel_mode = alc262_modes, 11591 .channel_mode = alc262_modes,
11513 .input_mux = &alc262_capture_source, 11592 .input_mux = &alc262_capture_source,
11514 .unsol_event = alc262_hippo_unsol_event, 11593 .unsol_event = alc262_hippo_unsol_event,
11515 .init_hook = alc262_hippo_init_hook, 11594 .setup = alc262_hippo_setup,
11595 .init_hook = alc262_hippo_automute,
11516 }, 11596 },
11517 [ALC262_BENQ_T31] = { 11597 [ALC262_BENQ_T31] = {
11518 .mixers = { alc262_benq_t31_mixer }, 11598 .mixers = { alc262_benq_t31_mixer },
11519 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs }, 11599 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
11600 alc_hp15_unsol_verbs },
11520 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 11601 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11521 .dac_nids = alc262_dac_nids, 11602 .dac_nids = alc262_dac_nids,
11522 .hp_nid = 0x03, 11603 .hp_nid = 0x03,
@@ -11524,7 +11605,8 @@ static struct alc_config_preset alc262_presets[] = {
11524 .channel_mode = alc262_modes, 11605 .channel_mode = alc262_modes,
11525 .input_mux = &alc262_capture_source, 11606 .input_mux = &alc262_capture_source,
11526 .unsol_event = alc262_hippo_unsol_event, 11607 .unsol_event = alc262_hippo_unsol_event,
11527 .init_hook = alc262_hippo_init_hook, 11608 .setup = alc262_hippo_setup,
11609 .init_hook = alc262_hippo_automute,
11528 }, 11610 },
11529 [ALC262_ULTRA] = { 11611 [ALC262_ULTRA] = {
11530 .mixers = { alc262_ultra_mixer }, 11612 .mixers = { alc262_ultra_mixer },
@@ -11576,9 +11658,9 @@ static struct alc_config_preset alc262_presets[] = {
11576 .dig_out_nid = ALC262_DIGOUT_NID, 11658 .dig_out_nid = ALC262_DIGOUT_NID,
11577 .num_channel_mode = ARRAY_SIZE(alc262_modes), 11659 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11578 .channel_mode = alc262_modes, 11660 .channel_mode = alc262_modes,
11579 .input_mux = &alc262_dmic_capture_source, 11661 .unsol_event = alc_sku_unsol_event,
11580 .unsol_event = alc262_toshiba_s06_unsol_event, 11662 .setup = alc262_toshiba_s06_setup,
11581 .init_hook = alc262_toshiba_s06_init_hook, 11663 .init_hook = alc_inithook,
11582 }, 11664 },
11583 [ALC262_TOSHIBA_RX1] = { 11665 [ALC262_TOSHIBA_RX1] = {
11584 .mixers = { alc262_toshiba_rx1_mixer }, 11666 .mixers = { alc262_toshiba_rx1_mixer },
@@ -11590,7 +11672,8 @@ static struct alc_config_preset alc262_presets[] = {
11590 .channel_mode = alc262_modes, 11672 .channel_mode = alc262_modes,
11591 .input_mux = &alc262_capture_source, 11673 .input_mux = &alc262_capture_source,
11592 .unsol_event = alc262_hippo_unsol_event, 11674 .unsol_event = alc262_hippo_unsol_event,
11593 .init_hook = alc262_hippo_init_hook, 11675 .setup = alc262_hippo_setup,
11676 .init_hook = alc262_hippo_automute,
11594 }, 11677 },
11595 [ALC262_TYAN] = { 11678 [ALC262_TYAN] = {
11596 .mixers = { alc262_tyan_mixer }, 11679 .mixers = { alc262_tyan_mixer },
@@ -11603,7 +11686,8 @@ static struct alc_config_preset alc262_presets[] = {
11603 .channel_mode = alc262_modes, 11686 .channel_mode = alc262_modes,
11604 .input_mux = &alc262_capture_source, 11687 .input_mux = &alc262_capture_source,
11605 .unsol_event = alc_automute_amp_unsol_event, 11688 .unsol_event = alc_automute_amp_unsol_event,
11606 .init_hook = alc262_tyan_init_hook, 11689 .setup = alc262_tyan_setup,
11690 .init_hook = alc_automute_amp,
11607 }, 11691 },
11608}; 11692};
11609 11693
@@ -11638,8 +11722,8 @@ static int patch_alc262(struct hda_codec *codec)
11638 alc262_cfg_tbl); 11722 alc262_cfg_tbl);
11639 11723
11640 if (board_config < 0) { 11724 if (board_config < 0) {
11641 printk(KERN_INFO "hda_codec: Unknown model for %s, " 11725 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11642 "trying auto-probe from BIOS...\n", codec->chip_name); 11726 codec->chip_name);
11643 board_config = ALC262_AUTO; 11727 board_config = ALC262_AUTO;
11644 } 11728 }
11645 11729
@@ -11666,7 +11750,7 @@ static int patch_alc262(struct hda_codec *codec)
11666 } 11750 }
11667 11751
11668 if (board_config != ALC262_AUTO) 11752 if (board_config != ALC262_AUTO)
11669 setup_preset(spec, &alc262_presets[board_config]); 11753 setup_preset(codec, &alc262_presets[board_config]);
11670 11754
11671 spec->stream_analog_playback = &alc262_pcm_analog_playback; 11755 spec->stream_analog_playback = &alc262_pcm_analog_playback;
11672 spec->stream_analog_capture = &alc262_pcm_analog_capture; 11756 spec->stream_analog_capture = &alc262_pcm_analog_capture;
@@ -11692,7 +11776,7 @@ static int patch_alc262(struct hda_codec *codec)
11692 unsigned int wcap = get_wcaps(codec, 0x07); 11776 unsigned int wcap = get_wcaps(codec, 0x07);
11693 11777
11694 /* get type */ 11778 /* get type */
11695 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 11779 wcap = get_wcaps_type(wcap);
11696 if (wcap != AC_WID_AUD_IN) { 11780 if (wcap != AC_WID_AUD_IN) {
11697 spec->adc_nids = alc262_adc_nids_alt; 11781 spec->adc_nids = alc262_adc_nids_alt;
11698 spec->num_adc_nids = 11782 spec->num_adc_nids =
@@ -11707,7 +11791,7 @@ static int patch_alc262(struct hda_codec *codec)
11707 } 11791 }
11708 } 11792 }
11709 if (!spec->cap_mixer && !spec->no_analog) 11793 if (!spec->cap_mixer && !spec->no_analog)
11710 set_capture_mixer(spec); 11794 set_capture_mixer(codec);
11711 if (!spec->no_analog) 11795 if (!spec->no_analog)
11712 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 11796 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11713 11797
@@ -11799,14 +11883,6 @@ static struct hda_verb alc268_toshiba_verbs[] = {
11799 { } /* end */ 11883 { } /* end */
11800}; 11884};
11801 11885
11802static struct hda_input_mux alc268_acer_lc_capture_source = {
11803 .num_items = 2,
11804 .items = {
11805 { "i-Mic", 0x6 },
11806 { "E-Mic", 0x0 },
11807 },
11808};
11809
11810/* Acer specific */ 11886/* Acer specific */
11811/* bind volumes of both NID 0x02 and 0x03 */ 11887/* bind volumes of both NID 0x02 and 0x03 */
11812static struct hda_bind_ctls alc268_acer_bind_master_vol = { 11888static struct hda_bind_ctls alc268_acer_bind_master_vol = {
@@ -11848,12 +11924,7 @@ static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11848 long *valp = ucontrol->value.integer.value; 11924 long *valp = ucontrol->value.integer.value;
11849 int change; 11925 int change;
11850 11926
11851 change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0, 11927 change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
11852 HDA_AMP_MUTE,
11853 valp[0] ? 0 : HDA_AMP_MUTE);
11854 change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11855 HDA_AMP_MUTE,
11856 valp[1] ? 0 : HDA_AMP_MUTE);
11857 if (change) 11928 if (change)
11858 alc268_acer_automute(codec, 0); 11929 alc268_acer_automute(codec, 0);
11859 return change; 11930 return change;
@@ -11930,7 +12001,8 @@ static struct hda_verb alc268_acer_verbs[] = {
11930 12001
11931/* unsolicited event for HP jack sensing */ 12002/* unsolicited event for HP jack sensing */
11932#define alc268_toshiba_unsol_event alc262_hippo_unsol_event 12003#define alc268_toshiba_unsol_event alc262_hippo_unsol_event
11933#define alc268_toshiba_init_hook alc262_hippo_init_hook 12004#define alc268_toshiba_setup alc262_hippo_setup
12005#define alc268_toshiba_automute alc262_hippo_automute
11934 12006
11935static void alc268_acer_unsol_event(struct hda_codec *codec, 12007static void alc268_acer_unsol_event(struct hda_codec *codec,
11936 unsigned int res) 12008 unsigned int res)
@@ -11960,30 +12032,33 @@ static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11960 AMP_IN_MUTE(0), bits); 12032 AMP_IN_MUTE(0), bits);
11961} 12033}
11962 12034
11963
11964static void alc268_acer_mic_automute(struct hda_codec *codec)
11965{
11966 unsigned int present;
11967
11968 present = snd_hda_codec_read(codec, 0x18, 0,
11969 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11970 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11971 present ? 0x0 : 0x6);
11972}
11973
11974static void alc268_acer_lc_unsol_event(struct hda_codec *codec, 12035static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11975 unsigned int res) 12036 unsigned int res)
11976{ 12037{
11977 if ((res >> 26) == ALC880_HP_EVENT) 12038 switch (res >> 26) {
12039 case ALC880_HP_EVENT:
11978 alc268_aspire_one_speaker_automute(codec); 12040 alc268_aspire_one_speaker_automute(codec);
11979 if ((res >> 26) == ALC880_MIC_EVENT) 12041 break;
11980 alc268_acer_mic_automute(codec); 12042 case ALC880_MIC_EVENT:
12043 alc_mic_automute(codec);
12044 break;
12045 }
12046}
12047
12048static void alc268_acer_lc_setup(struct hda_codec *codec)
12049{
12050 struct alc_spec *spec = codec->spec;
12051 spec->ext_mic.pin = 0x18;
12052 spec->ext_mic.mux_idx = 0;
12053 spec->int_mic.pin = 0x12;
12054 spec->int_mic.mux_idx = 6;
12055 spec->auto_mic = 1;
11981} 12056}
11982 12057
11983static void alc268_acer_lc_init_hook(struct hda_codec *codec) 12058static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11984{ 12059{
11985 alc268_aspire_one_speaker_automute(codec); 12060 alc268_aspire_one_speaker_automute(codec);
11986 alc268_acer_mic_automute(codec); 12061 alc_mic_automute(codec);
11987} 12062}
11988 12063
11989static struct snd_kcontrol_new alc268_dell_mixer[] = { 12064static struct snd_kcontrol_new alc268_dell_mixer[] = {
@@ -12001,17 +12076,22 @@ static struct hda_verb alc268_dell_verbs[] = {
12001 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 12076 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12002 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 12077 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12003 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 12078 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12079 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12004 { } 12080 { }
12005}; 12081};
12006 12082
12007/* mute/unmute internal speaker according to the hp jack and mute state */ 12083/* mute/unmute internal speaker according to the hp jack and mute state */
12008static void alc268_dell_init_hook(struct hda_codec *codec) 12084static void alc268_dell_setup(struct hda_codec *codec)
12009{ 12085{
12010 struct alc_spec *spec = codec->spec; 12086 struct alc_spec *spec = codec->spec;
12011 12087
12012 spec->autocfg.hp_pins[0] = 0x15; 12088 spec->autocfg.hp_pins[0] = 0x15;
12013 spec->autocfg.speaker_pins[0] = 0x14; 12089 spec->autocfg.speaker_pins[0] = 0x14;
12014 alc_automute_pin(codec); 12090 spec->ext_mic.pin = 0x18;
12091 spec->ext_mic.mux_idx = 0;
12092 spec->int_mic.pin = 0x19;
12093 spec->int_mic.mux_idx = 1;
12094 spec->auto_mic = 1;
12015} 12095}
12016 12096
12017static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = { 12097static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
@@ -12032,38 +12112,16 @@ static struct hda_verb alc267_quanta_il1_verbs[] = {
12032 { } 12112 { }
12033}; 12113};
12034 12114
12035static void alc267_quanta_il1_mic_automute(struct hda_codec *codec) 12115static void alc267_quanta_il1_setup(struct hda_codec *codec)
12036{
12037 unsigned int present;
12038
12039 present = snd_hda_codec_read(codec, 0x18, 0,
12040 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12041 snd_hda_codec_write(codec, 0x23, 0,
12042 AC_VERB_SET_CONNECT_SEL,
12043 present ? 0x00 : 0x01);
12044}
12045
12046static void alc267_quanta_il1_init_hook(struct hda_codec *codec)
12047{ 12116{
12048 struct alc_spec *spec = codec->spec; 12117 struct alc_spec *spec = codec->spec;
12049
12050 spec->autocfg.hp_pins[0] = 0x15; 12118 spec->autocfg.hp_pins[0] = 0x15;
12051 spec->autocfg.speaker_pins[0] = 0x14; 12119 spec->autocfg.speaker_pins[0] = 0x14;
12052 alc_automute_pin(codec); 12120 spec->ext_mic.pin = 0x18;
12053 alc267_quanta_il1_mic_automute(codec); 12121 spec->ext_mic.mux_idx = 0;
12054} 12122 spec->int_mic.pin = 0x19;
12055 12123 spec->int_mic.mux_idx = 1;
12056static void alc267_quanta_il1_unsol_event(struct hda_codec *codec, 12124 spec->auto_mic = 1;
12057 unsigned int res)
12058{
12059 switch (res >> 26) {
12060 case ALC880_MIC_EVENT:
12061 alc267_quanta_il1_mic_automute(codec);
12062 break;
12063 default:
12064 alc_sku_unsol_event(codec, res);
12065 break;
12066 }
12067} 12125}
12068 12126
12069/* 12127/*
@@ -12143,21 +12201,16 @@ static struct hda_verb alc268_volume_init_verbs[] = {
12143 { } 12201 { }
12144}; 12202};
12145 12203
12204static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
12205 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12206 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12207 { } /* end */
12208};
12209
12146static struct snd_kcontrol_new alc268_capture_alt_mixer[] = { 12210static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12147 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT), 12211 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12148 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT), 12212 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12149 { 12213 _DEFINE_CAPSRC(1),
12150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12151 /* The multiple "Capture Source" controls confuse alsamixer
12152 * So call somewhat different..
12153 */
12154 /* .name = "Capture Source", */
12155 .name = "Input Source",
12156 .count = 1,
12157 .info = alc_mux_enum_info,
12158 .get = alc_mux_enum_get,
12159 .put = alc_mux_enum_put,
12160 },
12161 { } /* end */ 12214 { } /* end */
12162}; 12215};
12163 12216
@@ -12166,18 +12219,7 @@ static struct snd_kcontrol_new alc268_capture_mixer[] = {
12166 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT), 12219 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12167 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT), 12220 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12168 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT), 12221 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12169 { 12222 _DEFINE_CAPSRC(2),
12170 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12171 /* The multiple "Capture Source" controls confuse alsamixer
12172 * So call somewhat different..
12173 */
12174 /* .name = "Capture Source", */
12175 .name = "Input Source",
12176 .count = 2,
12177 .info = alc_mux_enum_info,
12178 .get = alc_mux_enum_get,
12179 .put = alc_mux_enum_put,
12180 },
12181 { } /* end */ 12223 { } /* end */
12182}; 12224};
12183 12225
@@ -12264,26 +12306,38 @@ static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12264 const char *ctlname, int idx) 12306 const char *ctlname, int idx)
12265{ 12307{
12266 char name[32]; 12308 char name[32];
12309 hda_nid_t dac;
12267 int err; 12310 int err;
12268 12311
12269 sprintf(name, "%s Playback Volume", ctlname); 12312 sprintf(name, "%s Playback Volume", ctlname);
12270 if (nid == 0x14) { 12313 switch (nid) {
12271 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 12314 case 0x14:
12272 HDA_COMPOSE_AMP_VAL(0x02, 3, idx, 12315 case 0x16:
12273 HDA_OUTPUT)); 12316 dac = 0x02;
12274 if (err < 0) 12317 break;
12275 return err; 12318 case 0x15:
12276 } else if (nid == 0x15) { 12319 dac = 0x03;
12320 break;
12321 default:
12322 return 0;
12323 }
12324 if (spec->multiout.dac_nids[0] != dac &&
12325 spec->multiout.dac_nids[1] != dac) {
12277 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 12326 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12278 HDA_COMPOSE_AMP_VAL(0x03, 3, idx, 12327 HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12279 HDA_OUTPUT)); 12328 HDA_OUTPUT));
12280 if (err < 0) 12329 if (err < 0)
12281 return err; 12330 return err;
12282 } else 12331 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12283 return -1; 12332 }
12333
12284 sprintf(name, "%s Playback Switch", ctlname); 12334 sprintf(name, "%s Playback Switch", ctlname);
12285 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 12335 if (nid != 0x16)
12336 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12286 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT)); 12337 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12338 else /* mono */
12339 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12340 HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12287 if (err < 0) 12341 if (err < 0)
12288 return err; 12342 return err;
12289 return 0; 12343 return 0;
@@ -12296,14 +12350,19 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12296 hda_nid_t nid; 12350 hda_nid_t nid;
12297 int err; 12351 int err;
12298 12352
12299 spec->multiout.num_dacs = 2; /* only use one dac */
12300 spec->multiout.dac_nids = spec->private_dac_nids; 12353 spec->multiout.dac_nids = spec->private_dac_nids;
12301 spec->multiout.dac_nids[0] = 2;
12302 spec->multiout.dac_nids[1] = 3;
12303 12354
12304 nid = cfg->line_out_pins[0]; 12355 nid = cfg->line_out_pins[0];
12305 if (nid) 12356 if (nid) {
12306 alc268_new_analog_output(spec, nid, "Front", 0); 12357 const char *name;
12358 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
12359 name = "Speaker";
12360 else
12361 name = "Front";
12362 err = alc268_new_analog_output(spec, nid, name, 0);
12363 if (err < 0)
12364 return err;
12365 }
12307 12366
12308 nid = cfg->speaker_pins[0]; 12367 nid = cfg->speaker_pins[0];
12309 if (nid == 0x1d) { 12368 if (nid == 0x1d) {
@@ -12312,16 +12371,23 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12312 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); 12371 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12313 if (err < 0) 12372 if (err < 0)
12314 return err; 12373 return err;
12374 } else {
12375 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
12376 if (err < 0)
12377 return err;
12315 } 12378 }
12316 nid = cfg->hp_pins[0]; 12379 nid = cfg->hp_pins[0];
12317 if (nid) 12380 if (nid) {
12318 alc268_new_analog_output(spec, nid, "Headphone", 0); 12381 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
12382 if (err < 0)
12383 return err;
12384 }
12319 12385
12320 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2]; 12386 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12321 if (nid == 0x16) { 12387 if (nid == 0x16) {
12322 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 12388 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12323 "Mono Playback Switch", 12389 "Mono Playback Switch",
12324 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT)); 12390 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12325 if (err < 0) 12391 if (err < 0)
12326 return err; 12392 return err;
12327 } 12393 }
@@ -12329,38 +12395,46 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12329} 12395}
12330 12396
12331/* create playback/capture controls for input pins */ 12397/* create playback/capture controls for input pins */
12332static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec, 12398static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12333 const struct auto_pin_cfg *cfg) 12399 const struct auto_pin_cfg *cfg)
12334{ 12400{
12335 struct hda_input_mux *imux = &spec->private_imux[0]; 12401 return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12336 int i, idx1; 12402}
12337 12403
12338 for (i = 0; i < AUTO_PIN_LAST; i++) { 12404static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
12339 switch(cfg->input_pins[i]) { 12405 hda_nid_t nid, int pin_type)
12340 case 0x18: 12406{
12341 idx1 = 0; /* Mic 1 */ 12407 int idx;
12342 break; 12408
12343 case 0x19: 12409 alc_set_pin_output(codec, nid, pin_type);
12344 idx1 = 1; /* Mic 2 */ 12410 if (nid == 0x14 || nid == 0x16)
12345 break; 12411 idx = 0;
12346 case 0x1a: 12412 else
12347 idx1 = 2; /* Line In */ 12413 idx = 1;
12348 break; 12414 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
12349 case 0x1c: 12415}
12350 idx1 = 3; /* CD */ 12416
12351 break; 12417static void alc268_auto_init_multi_out(struct hda_codec *codec)
12352 case 0x12: 12418{
12353 case 0x13: 12419 struct alc_spec *spec = codec->spec;
12354 idx1 = 6; /* digital mics */ 12420 hda_nid_t nid = spec->autocfg.line_out_pins[0];
12355 break; 12421 if (nid) {
12356 default: 12422 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12357 continue; 12423 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
12358 }
12359 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12360 imux->items[imux->num_items].index = idx1;
12361 imux->num_items++;
12362 } 12424 }
12363 return 0; 12425}
12426
12427static void alc268_auto_init_hp_out(struct hda_codec *codec)
12428{
12429 struct alc_spec *spec = codec->spec;
12430 hda_nid_t pin;
12431
12432 pin = spec->autocfg.hp_pins[0];
12433 if (pin)
12434 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
12435 pin = spec->autocfg.speaker_pins[0];
12436 if (pin)
12437 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
12364} 12438}
12365 12439
12366static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec) 12440static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
@@ -12371,9 +12445,10 @@ static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12371 hda_nid_t line_nid = spec->autocfg.line_out_pins[0]; 12445 hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12372 unsigned int dac_vol1, dac_vol2; 12446 unsigned int dac_vol1, dac_vol2;
12373 12447
12374 if (speaker_nid) { 12448 if (line_nid == 0x1d || speaker_nid == 0x1d) {
12375 snd_hda_codec_write(codec, speaker_nid, 0, 12449 snd_hda_codec_write(codec, speaker_nid, 0,
12376 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 12450 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12451 /* mute mixer inputs from 0x1d */
12377 snd_hda_codec_write(codec, 0x0f, 0, 12452 snd_hda_codec_write(codec, 0x0f, 0,
12378 AC_VERB_SET_AMP_GAIN_MUTE, 12453 AC_VERB_SET_AMP_GAIN_MUTE,
12379 AMP_IN_UNMUTE(1)); 12454 AMP_IN_UNMUTE(1));
@@ -12381,6 +12456,7 @@ static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12381 AC_VERB_SET_AMP_GAIN_MUTE, 12456 AC_VERB_SET_AMP_GAIN_MUTE,
12382 AMP_IN_UNMUTE(1)); 12457 AMP_IN_UNMUTE(1));
12383 } else { 12458 } else {
12459 /* unmute mixer inputs from 0x1d */
12384 snd_hda_codec_write(codec, 0x0f, 0, 12460 snd_hda_codec_write(codec, 0x0f, 0,
12385 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)); 12461 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12386 snd_hda_codec_write(codec, 0x10, 0, 12462 snd_hda_codec_write(codec, 0x10, 0,
@@ -12437,7 +12513,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
12437 err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg); 12513 err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12438 if (err < 0) 12514 if (err < 0)
12439 return err; 12515 return err;
12440 err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg); 12516 err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
12441 if (err < 0) 12517 if (err < 0)
12442 return err; 12518 return err;
12443 12519
@@ -12456,7 +12532,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
12456 add_mixer(spec, alc268_beep_mixer); 12532 add_mixer(spec, alc268_beep_mixer);
12457 12533
12458 add_verb(spec, alc268_volume_init_verbs); 12534 add_verb(spec, alc268_volume_init_verbs);
12459 spec->num_mux_defs = 1; 12535 spec->num_mux_defs = 2;
12460 spec->input_mux = &spec->private_imux[0]; 12536 spec->input_mux = &spec->private_imux[0];
12461 12537
12462 err = alc_auto_add_mic_boost(codec); 12538 err = alc_auto_add_mic_boost(codec);
@@ -12468,8 +12544,6 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
12468 return 1; 12544 return 1;
12469} 12545}
12470 12546
12471#define alc268_auto_init_multi_out alc882_auto_init_multi_out
12472#define alc268_auto_init_hp_out alc882_auto_init_hp_out
12473#define alc268_auto_init_analog_input alc882_auto_init_analog_input 12547#define alc268_auto_init_analog_input alc882_auto_init_analog_input
12474 12548
12475/* init callback for auto-configuration model -- overriding the default init */ 12549/* init callback for auto-configuration model -- overriding the default init */
@@ -12512,12 +12586,13 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
12512 ALC268_ACER_ASPIRE_ONE), 12586 ALC268_ACER_ASPIRE_ONE),
12513 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL), 12587 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12514 SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL), 12588 SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
12589 /* almost compatible with toshiba but with optional digital outs;
12590 * auto-probing seems working fine
12591 */
12515 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series", 12592 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12516 ALC268_TOSHIBA), 12593 ALC268_AUTO),
12517 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST), 12594 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12518 SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO), 12595 SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12519 SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12520 ALC268_TOSHIBA),
12521 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA), 12596 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12522 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER), 12597 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12523 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1), 12598 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
@@ -12525,9 +12600,19 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
12525 {} 12600 {}
12526}; 12601};
12527 12602
12603/* Toshiba laptops have no unique PCI SSID but only codec SSID */
12604static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
12605 SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
12606 SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
12607 SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12608 ALC268_TOSHIBA),
12609 {}
12610};
12611
12528static struct alc_config_preset alc268_presets[] = { 12612static struct alc_config_preset alc268_presets[] = {
12529 [ALC267_QUANTA_IL1] = { 12613 [ALC267_QUANTA_IL1] = {
12530 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer }, 12614 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
12615 alc268_capture_nosrc_mixer },
12531 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12616 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12532 alc267_quanta_il1_verbs }, 12617 alc267_quanta_il1_verbs },
12533 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 12618 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -12537,9 +12622,9 @@ static struct alc_config_preset alc268_presets[] = {
12537 .hp_nid = 0x03, 12622 .hp_nid = 0x03,
12538 .num_channel_mode = ARRAY_SIZE(alc268_modes), 12623 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12539 .channel_mode = alc268_modes, 12624 .channel_mode = alc268_modes,
12540 .input_mux = &alc268_capture_source, 12625 .unsol_event = alc_sku_unsol_event,
12541 .unsol_event = alc267_quanta_il1_unsol_event, 12626 .setup = alc267_quanta_il1_setup,
12542 .init_hook = alc267_quanta_il1_init_hook, 12627 .init_hook = alc_inithook,
12543 }, 12628 },
12544 [ALC268_3ST] = { 12629 [ALC268_3ST] = {
12545 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer, 12630 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
@@ -12571,10 +12656,11 @@ static struct alc_config_preset alc268_presets[] = {
12571 .channel_mode = alc268_modes, 12656 .channel_mode = alc268_modes,
12572 .input_mux = &alc268_capture_source, 12657 .input_mux = &alc268_capture_source,
12573 .unsol_event = alc268_toshiba_unsol_event, 12658 .unsol_event = alc268_toshiba_unsol_event,
12574 .init_hook = alc268_toshiba_init_hook, 12659 .setup = alc268_toshiba_setup,
12660 .init_hook = alc268_toshiba_automute,
12575 }, 12661 },
12576 [ALC268_ACER] = { 12662 [ALC268_ACER] = {
12577 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer, 12663 .mixers = { alc268_acer_mixer, alc268_capture_nosrc_mixer,
12578 alc268_beep_mixer }, 12664 alc268_beep_mixer },
12579 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12665 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12580 alc268_acer_verbs }, 12666 alc268_acer_verbs },
@@ -12610,7 +12696,7 @@ static struct alc_config_preset alc268_presets[] = {
12610 [ALC268_ACER_ASPIRE_ONE] = { 12696 [ALC268_ACER_ASPIRE_ONE] = {
12611 .mixers = { alc268_acer_aspire_one_mixer, 12697 .mixers = { alc268_acer_aspire_one_mixer,
12612 alc268_beep_mixer, 12698 alc268_beep_mixer,
12613 alc268_capture_alt_mixer }, 12699 alc268_capture_nosrc_mixer },
12614 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12700 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12615 alc268_acer_aspire_one_verbs }, 12701 alc268_acer_aspire_one_verbs },
12616 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 12702 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -12621,22 +12707,26 @@ static struct alc_config_preset alc268_presets[] = {
12621 .hp_nid = 0x03, 12707 .hp_nid = 0x03,
12622 .num_channel_mode = ARRAY_SIZE(alc268_modes), 12708 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12623 .channel_mode = alc268_modes, 12709 .channel_mode = alc268_modes,
12624 .input_mux = &alc268_acer_lc_capture_source,
12625 .unsol_event = alc268_acer_lc_unsol_event, 12710 .unsol_event = alc268_acer_lc_unsol_event,
12711 .setup = alc268_acer_lc_setup,
12626 .init_hook = alc268_acer_lc_init_hook, 12712 .init_hook = alc268_acer_lc_init_hook,
12627 }, 12713 },
12628 [ALC268_DELL] = { 12714 [ALC268_DELL] = {
12629 .mixers = { alc268_dell_mixer, alc268_beep_mixer }, 12715 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
12716 alc268_capture_nosrc_mixer },
12630 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12717 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12631 alc268_dell_verbs }, 12718 alc268_dell_verbs },
12632 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 12719 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12633 .dac_nids = alc268_dac_nids, 12720 .dac_nids = alc268_dac_nids,
12721 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12722 .adc_nids = alc268_adc_nids_alt,
12723 .capsrc_nids = alc268_capsrc_nids,
12634 .hp_nid = 0x02, 12724 .hp_nid = 0x02,
12635 .num_channel_mode = ARRAY_SIZE(alc268_modes), 12725 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12636 .channel_mode = alc268_modes, 12726 .channel_mode = alc268_modes,
12637 .unsol_event = alc_sku_unsol_event, 12727 .unsol_event = alc_sku_unsol_event,
12638 .init_hook = alc268_dell_init_hook, 12728 .setup = alc268_dell_setup,
12639 .input_mux = &alc268_capture_source, 12729 .init_hook = alc_inithook,
12640 }, 12730 },
12641 [ALC268_ZEPTO] = { 12731 [ALC268_ZEPTO] = {
12642 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer, 12732 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
@@ -12653,8 +12743,8 @@ static struct alc_config_preset alc268_presets[] = {
12653 .num_channel_mode = ARRAY_SIZE(alc268_modes), 12743 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12654 .channel_mode = alc268_modes, 12744 .channel_mode = alc268_modes,
12655 .input_mux = &alc268_capture_source, 12745 .input_mux = &alc268_capture_source,
12656 .unsol_event = alc268_toshiba_unsol_event, 12746 .setup = alc268_toshiba_setup,
12657 .init_hook = alc268_toshiba_init_hook 12747 .init_hook = alc268_toshiba_automute,
12658 }, 12748 },
12659#ifdef CONFIG_SND_DEBUG 12749#ifdef CONFIG_SND_DEBUG
12660 [ALC268_TEST] = { 12750 [ALC268_TEST] = {
@@ -12691,9 +12781,13 @@ static int patch_alc268(struct hda_codec *codec)
12691 alc268_models, 12781 alc268_models,
12692 alc268_cfg_tbl); 12782 alc268_cfg_tbl);
12693 12783
12784 if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
12785 board_config = snd_hda_check_board_codec_sid_config(codec,
12786 ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
12787
12694 if (board_config < 0 || board_config >= ALC268_MODEL_LAST) { 12788 if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12695 printk(KERN_INFO "hda_codec: Unknown model for %s, " 12789 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12696 "trying auto-probe from BIOS...\n", codec->chip_name); 12790 codec->chip_name);
12697 board_config = ALC268_AUTO; 12791 board_config = ALC268_AUTO;
12698 } 12792 }
12699 12793
@@ -12712,7 +12806,7 @@ static int patch_alc268(struct hda_codec *codec)
12712 } 12806 }
12713 12807
12714 if (board_config != ALC268_AUTO) 12808 if (board_config != ALC268_AUTO)
12715 setup_preset(spec, &alc268_presets[board_config]); 12809 setup_preset(codec, &alc268_presets[board_config]);
12716 12810
12717 spec->stream_analog_playback = &alc268_pcm_analog_playback; 12811 spec->stream_analog_playback = &alc268_pcm_analog_playback;
12718 spec->stream_analog_capture = &alc268_pcm_analog_capture; 12812 spec->stream_analog_capture = &alc268_pcm_analog_capture;
@@ -12749,11 +12843,15 @@ static int patch_alc268(struct hda_codec *codec)
12749 int i; 12843 int i;
12750 12844
12751 /* get type */ 12845 /* get type */
12752 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 12846 wcap = get_wcaps_type(wcap);
12753 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) { 12847 if (spec->auto_mic ||
12848 wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12754 spec->adc_nids = alc268_adc_nids_alt; 12849 spec->adc_nids = alc268_adc_nids_alt;
12755 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt); 12850 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12756 add_mixer(spec, alc268_capture_alt_mixer); 12851 if (spec->auto_mic || spec->input_mux->num_items == 1)
12852 add_mixer(spec, alc268_capture_nosrc_mixer);
12853 else
12854 add_mixer(spec, alc268_capture_alt_mixer);
12757 } else { 12855 } else {
12758 spec->adc_nids = alc268_adc_nids; 12856 spec->adc_nids = alc268_adc_nids;
12759 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids); 12857 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
@@ -12764,6 +12862,8 @@ static int patch_alc268(struct hda_codec *codec)
12764 for (i = 0; i < spec->num_adc_nids; i++) 12862 for (i = 0; i < spec->num_adc_nids; i++)
12765 snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i], 12863 snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12766 0, AC_VERB_SET_CONNECT_SEL, 12864 0, AC_VERB_SET_CONNECT_SEL,
12865 i < spec->num_mux_defs ?
12866 spec->input_mux[i].items[0].index :
12767 spec->input_mux->items[0].index); 12867 spec->input_mux->items[0].index);
12768 } 12868 }
12769 12869
@@ -12798,22 +12898,6 @@ static hda_nid_t alc269_capsrc_nids[1] = {
12798 * not a mux! 12898 * not a mux!
12799 */ 12899 */
12800 12900
12801static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12802 .num_items = 2,
12803 .items = {
12804 { "i-Mic", 0x5 },
12805 { "e-Mic", 0x0 },
12806 },
12807};
12808
12809static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12810 .num_items = 2,
12811 .items = {
12812 { "i-Mic", 0x1 },
12813 { "e-Mic", 0x0 },
12814 },
12815};
12816
12817#define alc269_modes alc260_modes 12901#define alc269_modes alc260_modes
12818#define alc269_capture_source alc880_lg_lw_capture_source 12902#define alc269_capture_source alc880_lg_lw_capture_source
12819 12903
@@ -12876,20 +12960,11 @@ static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12876 { } 12960 { }
12877}; 12961};
12878 12962
12879/* bind volumes of both NID 0x0c and 0x0d */
12880static struct hda_bind_ctls alc269_epc_bind_vol = {
12881 .ops = &snd_hda_bind_vol,
12882 .values = {
12883 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12884 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12885 0
12886 },
12887};
12888
12889static struct snd_kcontrol_new alc269_eeepc_mixer[] = { 12963static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12890 HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), 12964 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12891 HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol), 12965 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12892 HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT), 12966 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12967 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12893 { } /* end */ 12968 { } /* end */
12894}; 12969};
12895 12970
@@ -12902,12 +12977,7 @@ static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12902}; 12977};
12903 12978
12904/* FSC amilo */ 12979/* FSC amilo */
12905static struct snd_kcontrol_new alc269_fujitsu_mixer[] = { 12980#define alc269_fujitsu_mixer alc269_eeepc_mixer
12906 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12907 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12908 HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12909 { } /* end */
12910};
12911 12981
12912static struct hda_verb alc269_quanta_fl1_verbs[] = { 12982static struct hda_verb alc269_quanta_fl1_verbs[] = {
12913 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 12983 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
@@ -12989,16 +13059,6 @@ static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12989 AC_VERB_SET_PROC_COEF, 0x480); 13059 AC_VERB_SET_PROC_COEF, 0x480);
12990} 13060}
12991 13061
12992static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12993{
12994 unsigned int present;
12995
12996 present = snd_hda_codec_read(codec, 0x18, 0,
12997 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12998 snd_hda_codec_write(codec, 0x23, 0,
12999 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
13000}
13001
13002static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec) 13062static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13003{ 13063{
13004 unsigned int present_laptop; 13064 unsigned int present_laptop;
@@ -13025,10 +13085,14 @@ static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13025static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec, 13085static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13026 unsigned int res) 13086 unsigned int res)
13027{ 13087{
13028 if ((res >> 26) == ALC880_HP_EVENT) 13088 switch (res >> 26) {
13089 case ALC880_HP_EVENT:
13029 alc269_quanta_fl1_speaker_automute(codec); 13090 alc269_quanta_fl1_speaker_automute(codec);
13030 if ((res >> 26) == ALC880_MIC_EVENT) 13091 break;
13031 alc269_quanta_fl1_mic_automute(codec); 13092 case ALC880_MIC_EVENT:
13093 alc_mic_automute(codec);
13094 break;
13095 }
13032} 13096}
13033 13097
13034static void alc269_lifebook_unsol_event(struct hda_codec *codec, 13098static void alc269_lifebook_unsol_event(struct hda_codec *codec,
@@ -13040,10 +13104,20 @@ static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13040 alc269_lifebook_mic_autoswitch(codec); 13104 alc269_lifebook_mic_autoswitch(codec);
13041} 13105}
13042 13106
13107static void alc269_quanta_fl1_setup(struct hda_codec *codec)
13108{
13109 struct alc_spec *spec = codec->spec;
13110 spec->ext_mic.pin = 0x18;
13111 spec->ext_mic.mux_idx = 0;
13112 spec->int_mic.pin = 0x19;
13113 spec->int_mic.mux_idx = 1;
13114 spec->auto_mic = 1;
13115}
13116
13043static void alc269_quanta_fl1_init_hook(struct hda_codec *codec) 13117static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13044{ 13118{
13045 alc269_quanta_fl1_speaker_automute(codec); 13119 alc269_quanta_fl1_speaker_automute(codec);
13046 alc269_quanta_fl1_mic_automute(codec); 13120 alc_mic_automute(codec);
13047} 13121}
13048 13122
13049static void alc269_lifebook_init_hook(struct hda_codec *codec) 13123static void alc269_lifebook_init_hook(struct hda_codec *codec)
@@ -13088,60 +13162,44 @@ static void alc269_speaker_automute(struct hda_codec *codec)
13088 AMP_IN_MUTE(0), bits); 13162 AMP_IN_MUTE(0), bits);
13089} 13163}
13090 13164
13091static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
13092{
13093 unsigned int present;
13094
13095 present = snd_hda_codec_read(codec, 0x18, 0,
13096 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13097 snd_hda_codec_write(codec, 0x23, 0,
13098 AC_VERB_SET_CONNECT_SEL, (present ? 0 : 5));
13099}
13100
13101static void alc269_eeepc_amic_automute(struct hda_codec *codec)
13102{
13103 unsigned int present;
13104
13105 present = snd_hda_codec_read(codec, 0x18, 0,
13106 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13107 snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13108 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13109 snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13110 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13111}
13112
13113/* unsolicited event for HP jack sensing */ 13165/* unsolicited event for HP jack sensing */
13114static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec, 13166static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13115 unsigned int res) 13167 unsigned int res)
13116{ 13168{
13117 if ((res >> 26) == ALC880_HP_EVENT) 13169 switch (res >> 26) {
13170 case ALC880_HP_EVENT:
13118 alc269_speaker_automute(codec); 13171 alc269_speaker_automute(codec);
13119 13172 break;
13120 if ((res >> 26) == ALC880_MIC_EVENT) 13173 case ALC880_MIC_EVENT:
13121 alc269_eeepc_dmic_automute(codec); 13174 alc_mic_automute(codec);
13175 break;
13176 }
13122} 13177}
13123 13178
13124static void alc269_eeepc_dmic_inithook(struct hda_codec *codec) 13179static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13125{ 13180{
13126 alc269_speaker_automute(codec); 13181 struct alc_spec *spec = codec->spec;
13127 alc269_eeepc_dmic_automute(codec); 13182 spec->ext_mic.pin = 0x18;
13183 spec->ext_mic.mux_idx = 0;
13184 spec->int_mic.pin = 0x12;
13185 spec->int_mic.mux_idx = 5;
13186 spec->auto_mic = 1;
13128} 13187}
13129 13188
13130/* unsolicited event for HP jack sensing */ 13189static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13131static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
13132 unsigned int res)
13133{ 13190{
13134 if ((res >> 26) == ALC880_HP_EVENT) 13191 struct alc_spec *spec = codec->spec;
13135 alc269_speaker_automute(codec); 13192 spec->ext_mic.pin = 0x18;
13136 13193 spec->ext_mic.mux_idx = 0;
13137 if ((res >> 26) == ALC880_MIC_EVENT) 13194 spec->int_mic.pin = 0x19;
13138 alc269_eeepc_amic_automute(codec); 13195 spec->int_mic.mux_idx = 1;
13196 spec->auto_mic = 1;
13139} 13197}
13140 13198
13141static void alc269_eeepc_amic_inithook(struct hda_codec *codec) 13199static void alc269_eeepc_inithook(struct hda_codec *codec)
13142{ 13200{
13143 alc269_speaker_automute(codec); 13201 alc269_speaker_automute(codec);
13144 alc269_eeepc_amic_automute(codec); 13202 alc_mic_automute(codec);
13145} 13203}
13146 13204
13147/* 13205/*
@@ -13214,89 +13272,10 @@ static struct hda_verb alc269_init_verbs[] = {
13214 { } 13272 { }
13215}; 13273};
13216 13274
13217/* add playback controls from the parsed DAC table */ 13275#define alc269_auto_create_multi_out_ctls \
13218static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec, 13276 alc268_auto_create_multi_out_ctls
13219 const struct auto_pin_cfg *cfg) 13277#define alc269_auto_create_input_ctls \
13220{ 13278 alc268_auto_create_input_ctls
13221 hda_nid_t nid;
13222 int err;
13223
13224 spec->multiout.num_dacs = 1; /* only use one dac */
13225 spec->multiout.dac_nids = spec->private_dac_nids;
13226 spec->multiout.dac_nids[0] = 2;
13227
13228 nid = cfg->line_out_pins[0];
13229 if (nid) {
13230 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13231 "Front Playback Volume",
13232 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
13233 if (err < 0)
13234 return err;
13235 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13236 "Front Playback Switch",
13237 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13238 if (err < 0)
13239 return err;
13240 }
13241
13242 nid = cfg->speaker_pins[0];
13243 if (nid) {
13244 if (!cfg->line_out_pins[0]) {
13245 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13246 "Speaker Playback Volume",
13247 HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13248 HDA_OUTPUT));
13249 if (err < 0)
13250 return err;
13251 }
13252 if (nid == 0x16) {
13253 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13254 "Speaker Playback Switch",
13255 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13256 HDA_OUTPUT));
13257 if (err < 0)
13258 return err;
13259 } else {
13260 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13261 "Speaker Playback Switch",
13262 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13263 HDA_OUTPUT));
13264 if (err < 0)
13265 return err;
13266 }
13267 }
13268 nid = cfg->hp_pins[0];
13269 if (nid) {
13270 /* spec->multiout.hp_nid = 2; */
13271 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
13272 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13273 "Headphone Playback Volume",
13274 HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13275 HDA_OUTPUT));
13276 if (err < 0)
13277 return err;
13278 }
13279 if (nid == 0x16) {
13280 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13281 "Headphone Playback Switch",
13282 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13283 HDA_OUTPUT));
13284 if (err < 0)
13285 return err;
13286 } else {
13287 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13288 "Headphone Playback Switch",
13289 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13290 HDA_OUTPUT));
13291 if (err < 0)
13292 return err;
13293 }
13294 }
13295 return 0;
13296}
13297
13298#define alc269_auto_create_analog_input_ctls \
13299 alc262_auto_create_analog_input_ctls
13300 13279
13301#ifdef CONFIG_SND_HDA_POWER_SAVE 13280#ifdef CONFIG_SND_HDA_POWER_SAVE
13302#define alc269_loopbacks alc880_loopbacks 13281#define alc269_loopbacks alc880_loopbacks
@@ -13346,7 +13325,7 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
13346 err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg); 13325 err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13347 if (err < 0) 13326 if (err < 0)
13348 return err; 13327 return err;
13349 err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg); 13328 err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13350 if (err < 0) 13329 if (err < 0)
13351 return err; 13330 return err;
13352 13331
@@ -13371,15 +13350,15 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
13371 return err; 13350 return err;
13372 13351
13373 if (!spec->cap_mixer && !spec->no_analog) 13352 if (!spec->cap_mixer && !spec->no_analog)
13374 set_capture_mixer(spec); 13353 set_capture_mixer(codec);
13375 13354
13376 alc_ssid_check(codec, 0x15, 0x1b, 0x14); 13355 alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13377 13356
13378 return 1; 13357 return 1;
13379} 13358}
13380 13359
13381#define alc269_auto_init_multi_out alc882_auto_init_multi_out 13360#define alc269_auto_init_multi_out alc268_auto_init_multi_out
13382#define alc269_auto_init_hp_out alc882_auto_init_hp_out 13361#define alc269_auto_init_hp_out alc268_auto_init_hp_out
13383#define alc269_auto_init_analog_input alc882_auto_init_analog_input 13362#define alc269_auto_init_analog_input alc882_auto_init_analog_input
13384 13363
13385 13364
@@ -13403,7 +13382,8 @@ static const char *alc269_models[ALC269_MODEL_LAST] = {
13403 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703", 13382 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703",
13404 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901", 13383 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901",
13405 [ALC269_FUJITSU] = "fujitsu", 13384 [ALC269_FUJITSU] = "fujitsu",
13406 [ALC269_LIFEBOOK] = "lifebook" 13385 [ALC269_LIFEBOOK] = "lifebook",
13386 [ALC269_AUTO] = "auto",
13407}; 13387};
13408 13388
13409static struct snd_pci_quirk alc269_cfg_tbl[] = { 13389static struct snd_pci_quirk alc269_cfg_tbl[] = {
@@ -13447,6 +13427,7 @@ static struct alc_config_preset alc269_presets[] = {
13447 .channel_mode = alc269_modes, 13427 .channel_mode = alc269_modes,
13448 .input_mux = &alc269_capture_source, 13428 .input_mux = &alc269_capture_source,
13449 .unsol_event = alc269_quanta_fl1_unsol_event, 13429 .unsol_event = alc269_quanta_fl1_unsol_event,
13430 .setup = alc269_quanta_fl1_setup,
13450 .init_hook = alc269_quanta_fl1_init_hook, 13431 .init_hook = alc269_quanta_fl1_init_hook,
13451 }, 13432 },
13452 [ALC269_ASUS_EEEPC_P703] = { 13433 [ALC269_ASUS_EEEPC_P703] = {
@@ -13459,9 +13440,9 @@ static struct alc_config_preset alc269_presets[] = {
13459 .hp_nid = 0x03, 13440 .hp_nid = 0x03,
13460 .num_channel_mode = ARRAY_SIZE(alc269_modes), 13441 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13461 .channel_mode = alc269_modes, 13442 .channel_mode = alc269_modes,
13462 .input_mux = &alc269_eeepc_amic_capture_source, 13443 .unsol_event = alc269_eeepc_unsol_event,
13463 .unsol_event = alc269_eeepc_amic_unsol_event, 13444 .setup = alc269_eeepc_amic_setup,
13464 .init_hook = alc269_eeepc_amic_inithook, 13445 .init_hook = alc269_eeepc_inithook,
13465 }, 13446 },
13466 [ALC269_ASUS_EEEPC_P901] = { 13447 [ALC269_ASUS_EEEPC_P901] = {
13467 .mixers = { alc269_eeepc_mixer }, 13448 .mixers = { alc269_eeepc_mixer },
@@ -13473,9 +13454,9 @@ static struct alc_config_preset alc269_presets[] = {
13473 .hp_nid = 0x03, 13454 .hp_nid = 0x03,
13474 .num_channel_mode = ARRAY_SIZE(alc269_modes), 13455 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13475 .channel_mode = alc269_modes, 13456 .channel_mode = alc269_modes,
13476 .input_mux = &alc269_eeepc_dmic_capture_source, 13457 .unsol_event = alc269_eeepc_unsol_event,
13477 .unsol_event = alc269_eeepc_dmic_unsol_event, 13458 .setup = alc269_eeepc_dmic_setup,
13478 .init_hook = alc269_eeepc_dmic_inithook, 13459 .init_hook = alc269_eeepc_inithook,
13479 }, 13460 },
13480 [ALC269_FUJITSU] = { 13461 [ALC269_FUJITSU] = {
13481 .mixers = { alc269_fujitsu_mixer }, 13462 .mixers = { alc269_fujitsu_mixer },
@@ -13487,9 +13468,9 @@ static struct alc_config_preset alc269_presets[] = {
13487 .hp_nid = 0x03, 13468 .hp_nid = 0x03,
13488 .num_channel_mode = ARRAY_SIZE(alc269_modes), 13469 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13489 .channel_mode = alc269_modes, 13470 .channel_mode = alc269_modes,
13490 .input_mux = &alc269_eeepc_dmic_capture_source, 13471 .unsol_event = alc269_eeepc_unsol_event,
13491 .unsol_event = alc269_eeepc_dmic_unsol_event, 13472 .setup = alc269_eeepc_dmic_setup,
13492 .init_hook = alc269_eeepc_dmic_inithook, 13473 .init_hook = alc269_eeepc_inithook,
13493 }, 13474 },
13494 [ALC269_LIFEBOOK] = { 13475 [ALC269_LIFEBOOK] = {
13495 .mixers = { alc269_lifebook_mixer }, 13476 .mixers = { alc269_lifebook_mixer },
@@ -13524,8 +13505,8 @@ static int patch_alc269(struct hda_codec *codec)
13524 alc269_cfg_tbl); 13505 alc269_cfg_tbl);
13525 13506
13526 if (board_config < 0) { 13507 if (board_config < 0) {
13527 printk(KERN_INFO "hda_codec: Unknown model for %s, " 13508 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13528 "trying auto-probe from BIOS...\n", codec->chip_name); 13509 codec->chip_name);
13529 board_config = ALC269_AUTO; 13510 board_config = ALC269_AUTO;
13530 } 13511 }
13531 13512
@@ -13550,7 +13531,7 @@ static int patch_alc269(struct hda_codec *codec)
13550 } 13531 }
13551 13532
13552 if (board_config != ALC269_AUTO) 13533 if (board_config != ALC269_AUTO)
13553 setup_preset(spec, &alc269_presets[board_config]); 13534 setup_preset(codec, &alc269_presets[board_config]);
13554 13535
13555 if (codec->subsystem_id == 0x17aa3bf8) { 13536 if (codec->subsystem_id == 0x17aa3bf8) {
13556 /* Due to a hardware problem on Lenovo Ideadpad, we need to 13537 /* Due to a hardware problem on Lenovo Ideadpad, we need to
@@ -13569,9 +13550,11 @@ static int patch_alc269(struct hda_codec *codec)
13569 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids); 13550 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13570 spec->capsrc_nids = alc269_capsrc_nids; 13551 spec->capsrc_nids = alc269_capsrc_nids;
13571 if (!spec->cap_mixer) 13552 if (!spec->cap_mixer)
13572 set_capture_mixer(spec); 13553 set_capture_mixer(codec);
13573 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); 13554 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13574 13555
13556 spec->vmaster_nid = 0x02;
13557
13575 codec->patch_ops = alc_patch_ops; 13558 codec->patch_ops = alc_patch_ops;
13576 if (board_config == ALC269_AUTO) 13559 if (board_config == ALC269_AUTO)
13577 spec->init_hook = alc269_auto_init; 13560 spec->init_hook = alc269_auto_init;
@@ -14117,23 +14100,23 @@ static struct hda_verb alc861_auto_init_verbs[] = {
14117 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 14100 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14118 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, 14101 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14119 14102
14120 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 14103 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14121 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 14104 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14122 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 14105 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14123 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 14106 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14124 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 14107 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14125 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 14108 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14126 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 14109 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14127 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 14110 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14128 14111
14129 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 14112 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14130 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 14113 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14131 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 14114 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14132 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, 14115 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14133 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 14116 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14134 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 14117 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14135 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 14118 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14136 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, 14119 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14137 14120
14138 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, /* set Mic 1 */ 14121 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, /* set Mic 1 */
14139 14122
@@ -14205,64 +14188,96 @@ static struct hda_input_mux alc861_capture_source = {
14205 }, 14188 },
14206}; 14189};
14207 14190
14191static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
14192{
14193 struct alc_spec *spec = codec->spec;
14194 hda_nid_t mix, srcs[5];
14195 int i, j, num;
14196
14197 if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
14198 return 0;
14199 num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14200 if (num < 0)
14201 return 0;
14202 for (i = 0; i < num; i++) {
14203 unsigned int type;
14204 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
14205 if (type != AC_WID_AUD_OUT)
14206 continue;
14207 for (j = 0; j < spec->multiout.num_dacs; j++)
14208 if (spec->multiout.dac_nids[j] == srcs[i])
14209 break;
14210 if (j >= spec->multiout.num_dacs)
14211 return srcs[i];
14212 }
14213 return 0;
14214}
14215
14208/* fill in the dac_nids table from the parsed pin configuration */ 14216/* fill in the dac_nids table from the parsed pin configuration */
14209static int alc861_auto_fill_dac_nids(struct alc_spec *spec, 14217static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14210 const struct auto_pin_cfg *cfg) 14218 const struct auto_pin_cfg *cfg)
14211{ 14219{
14220 struct alc_spec *spec = codec->spec;
14212 int i; 14221 int i;
14213 hda_nid_t nid; 14222 hda_nid_t nid, dac;
14214 14223
14215 spec->multiout.dac_nids = spec->private_dac_nids; 14224 spec->multiout.dac_nids = spec->private_dac_nids;
14216 for (i = 0; i < cfg->line_outs; i++) { 14225 for (i = 0; i < cfg->line_outs; i++) {
14217 nid = cfg->line_out_pins[i]; 14226 nid = cfg->line_out_pins[i];
14218 if (nid) { 14227 dac = alc861_look_for_dac(codec, nid);
14219 if (i >= ARRAY_SIZE(alc861_dac_nids)) 14228 if (!dac)
14220 continue; 14229 continue;
14221 spec->multiout.dac_nids[i] = alc861_dac_nids[i]; 14230 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14222 }
14223 } 14231 }
14224 spec->multiout.num_dacs = cfg->line_outs;
14225 return 0; 14232 return 0;
14226} 14233}
14227 14234
14235static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14236 hda_nid_t nid, unsigned int chs)
14237{
14238 char name[32];
14239 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
14240 return add_control(codec->spec, ALC_CTL_WIDGET_MUTE, name,
14241 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14242}
14243
14228/* add playback controls from the parsed DAC table */ 14244/* add playback controls from the parsed DAC table */
14229static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec, 14245static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14230 const struct auto_pin_cfg *cfg) 14246 const struct auto_pin_cfg *cfg)
14231{ 14247{
14232 char name[32]; 14248 struct alc_spec *spec = codec->spec;
14233 static const char *chname[4] = { 14249 static const char *chname[4] = {
14234 "Front", "Surround", NULL /*CLFE*/, "Side" 14250 "Front", "Surround", NULL /*CLFE*/, "Side"
14235 }; 14251 };
14236 hda_nid_t nid; 14252 hda_nid_t nid;
14237 int i, idx, err; 14253 int i, err;
14254
14255 if (cfg->line_outs == 1) {
14256 const char *pfx = NULL;
14257 if (!cfg->hp_outs)
14258 pfx = "Master";
14259 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
14260 pfx = "Speaker";
14261 if (pfx) {
14262 nid = spec->multiout.dac_nids[0];
14263 return alc861_create_out_sw(codec, pfx, nid, 3);
14264 }
14265 }
14238 14266
14239 for (i = 0; i < cfg->line_outs; i++) { 14267 for (i = 0; i < cfg->line_outs; i++) {
14240 nid = spec->multiout.dac_nids[i]; 14268 nid = spec->multiout.dac_nids[i];
14241 if (!nid) 14269 if (!nid)
14242 continue; 14270 continue;
14243 if (nid == 0x05) { 14271 if (i == 2) {
14244 /* Center/LFE */ 14272 /* Center/LFE */
14245 err = add_control(spec, ALC_CTL_BIND_MUTE, 14273 err = alc861_create_out_sw(codec, "Center", nid, 1);
14246 "Center Playback Switch",
14247 HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14248 HDA_OUTPUT));
14249 if (err < 0) 14274 if (err < 0)
14250 return err; 14275 return err;
14251 err = add_control(spec, ALC_CTL_BIND_MUTE, 14276 err = alc861_create_out_sw(codec, "LFE", nid, 2);
14252 "LFE Playback Switch",
14253 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14254 HDA_OUTPUT));
14255 if (err < 0) 14277 if (err < 0)
14256 return err; 14278 return err;
14257 } else { 14279 } else {
14258 for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1; 14280 err = alc861_create_out_sw(codec, chname[i], nid, 3);
14259 idx++)
14260 if (nid == alc861_dac_nids[idx])
14261 break;
14262 sprintf(name, "%s Playback Switch", chname[idx]);
14263 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14264 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14265 HDA_OUTPUT));
14266 if (err < 0) 14281 if (err < 0)
14267 return err; 14282 return err;
14268 } 14283 }
@@ -14270,8 +14285,9 @@ static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
14270 return 0; 14285 return 0;
14271} 14286}
14272 14287
14273static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin) 14288static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
14274{ 14289{
14290 struct alc_spec *spec = codec->spec;
14275 int err; 14291 int err;
14276 hda_nid_t nid; 14292 hda_nid_t nid;
14277 14293
@@ -14279,70 +14295,49 @@ static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
14279 return 0; 14295 return 0;
14280 14296
14281 if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) { 14297 if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14282 nid = 0x03; 14298 nid = alc861_look_for_dac(codec, pin);
14283 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 14299 if (nid) {
14284 "Headphone Playback Switch", 14300 err = alc861_create_out_sw(codec, "Headphone", nid, 3);
14285 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT)); 14301 if (err < 0)
14286 if (err < 0) 14302 return err;
14287 return err; 14303 spec->multiout.hp_nid = nid;
14288 spec->multiout.hp_nid = nid; 14304 }
14289 } 14305 }
14290 return 0; 14306 return 0;
14291} 14307}
14292 14308
14293/* create playback/capture controls for input pins */ 14309/* create playback/capture controls for input pins */
14294static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec, 14310static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14295 const struct auto_pin_cfg *cfg) 14311 const struct auto_pin_cfg *cfg)
14296{ 14312{
14297 struct hda_input_mux *imux = &spec->private_imux[0]; 14313 return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14298 int i, err, idx, idx1;
14299
14300 for (i = 0; i < AUTO_PIN_LAST; i++) {
14301 switch (cfg->input_pins[i]) {
14302 case 0x0c:
14303 idx1 = 1;
14304 idx = 2; /* Line In */
14305 break;
14306 case 0x0f:
14307 idx1 = 2;
14308 idx = 2; /* Line In */
14309 break;
14310 case 0x0d:
14311 idx1 = 0;
14312 idx = 1; /* Mic In */
14313 break;
14314 case 0x10:
14315 idx1 = 3;
14316 idx = 1; /* Mic In */
14317 break;
14318 case 0x11:
14319 idx1 = 4;
14320 idx = 0; /* CD */
14321 break;
14322 default:
14323 continue;
14324 }
14325
14326 err = new_analog_input(spec, cfg->input_pins[i],
14327 auto_pin_cfg_labels[i], idx, 0x15);
14328 if (err < 0)
14329 return err;
14330
14331 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
14332 imux->items[imux->num_items].index = idx1;
14333 imux->num_items++;
14334 }
14335 return 0;
14336} 14314}
14337 14315
14338static void alc861_auto_set_output_and_unmute(struct hda_codec *codec, 14316static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14339 hda_nid_t nid, 14317 hda_nid_t nid,
14340 int pin_type, int dac_idx) 14318 int pin_type, hda_nid_t dac)
14341{ 14319{
14320 hda_nid_t mix, srcs[5];
14321 int i, num;
14322
14342 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 14323 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14343 pin_type); 14324 pin_type);
14344 snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE, 14325 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14345 AMP_OUT_UNMUTE); 14326 AMP_OUT_UNMUTE);
14327 if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
14328 return;
14329 num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14330 if (num < 0)
14331 return;
14332 for (i = 0; i < num; i++) {
14333 unsigned int mute;
14334 if (srcs[i] == dac || srcs[i] == 0x15)
14335 mute = AMP_IN_UNMUTE(i);
14336 else
14337 mute = AMP_IN_MUTE(i);
14338 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14339 mute);
14340 }
14346} 14341}
14347 14342
14348static void alc861_auto_init_multi_out(struct hda_codec *codec) 14343static void alc861_auto_init_multi_out(struct hda_codec *codec)
@@ -14365,12 +14360,13 @@ static void alc861_auto_init_hp_out(struct hda_codec *codec)
14365 hda_nid_t pin; 14360 hda_nid_t pin;
14366 14361
14367 pin = spec->autocfg.hp_pins[0]; 14362 pin = spec->autocfg.hp_pins[0];
14368 if (pin) /* connect to front */ 14363 if (pin)
14369 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP, 14364 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
14370 spec->multiout.dac_nids[0]); 14365 spec->multiout.hp_nid);
14371 pin = spec->autocfg.speaker_pins[0]; 14366 pin = spec->autocfg.speaker_pins[0];
14372 if (pin) 14367 if (pin)
14373 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); 14368 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT,
14369 spec->multiout.dac_nids[0]);
14374} 14370}
14375 14371
14376static void alc861_auto_init_analog_input(struct hda_codec *codec) 14372static void alc861_auto_init_analog_input(struct hda_codec *codec)
@@ -14402,16 +14398,16 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
14402 if (!spec->autocfg.line_outs) 14398 if (!spec->autocfg.line_outs)
14403 return 0; /* can't find valid BIOS pin config */ 14399 return 0; /* can't find valid BIOS pin config */
14404 14400
14405 err = alc861_auto_fill_dac_nids(spec, &spec->autocfg); 14401 err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
14406 if (err < 0) 14402 if (err < 0)
14407 return err; 14403 return err;
14408 err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg); 14404 err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
14409 if (err < 0) 14405 if (err < 0)
14410 return err; 14406 return err;
14411 err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); 14407 err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
14412 if (err < 0) 14408 if (err < 0)
14413 return err; 14409 return err;
14414 err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg); 14410 err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
14415 if (err < 0) 14411 if (err < 0)
14416 return err; 14412 return err;
14417 14413
@@ -14430,7 +14426,7 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
14430 14426
14431 spec->adc_nids = alc861_adc_nids; 14427 spec->adc_nids = alc861_adc_nids;
14432 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids); 14428 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14433 set_capture_mixer(spec); 14429 set_capture_mixer(codec);
14434 14430
14435 alc_ssid_check(codec, 0x0e, 0x0f, 0x0b); 14431 alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14436 14432
@@ -14623,8 +14619,8 @@ static int patch_alc861(struct hda_codec *codec)
14623 alc861_cfg_tbl); 14619 alc861_cfg_tbl);
14624 14620
14625 if (board_config < 0) { 14621 if (board_config < 0) {
14626 printk(KERN_INFO "hda_codec: Unknown model for %s, " 14622 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14627 "trying auto-probe from BIOS...\n", codec->chip_name); 14623 codec->chip_name);
14628 board_config = ALC861_AUTO; 14624 board_config = ALC861_AUTO;
14629 } 14625 }
14630 14626
@@ -14649,7 +14645,7 @@ static int patch_alc861(struct hda_codec *codec)
14649 } 14645 }
14650 14646
14651 if (board_config != ALC861_AUTO) 14647 if (board_config != ALC861_AUTO)
14652 setup_preset(spec, &alc861_presets[board_config]); 14648 setup_preset(codec, &alc861_presets[board_config]);
14653 14649
14654 spec->stream_analog_playback = &alc861_pcm_analog_playback; 14650 spec->stream_analog_playback = &alc861_pcm_analog_playback;
14655 spec->stream_analog_capture = &alc861_pcm_analog_capture; 14651 spec->stream_analog_capture = &alc861_pcm_analog_capture;
@@ -15052,12 +15048,15 @@ static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15052 HDA_AMP_MUTE, bits); 15048 HDA_AMP_MUTE, bits);
15053} 15049}
15054 15050
15055static void alc861vd_lenovo_init_hook(struct hda_codec *codec) 15051static void alc861vd_lenovo_setup(struct hda_codec *codec)
15056{ 15052{
15057 struct alc_spec *spec = codec->spec; 15053 struct alc_spec *spec = codec->spec;
15058
15059 spec->autocfg.hp_pins[0] = 0x1b; 15054 spec->autocfg.hp_pins[0] = 0x1b;
15060 spec->autocfg.speaker_pins[0] = 0x14; 15055 spec->autocfg.speaker_pins[0] = 0x14;
15056}
15057
15058static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15059{
15061 alc_automute_amp(codec); 15060 alc_automute_amp(codec);
15062 alc861vd_lenovo_mic_automute(codec); 15061 alc861vd_lenovo_mic_automute(codec);
15063} 15062}
@@ -15121,13 +15120,12 @@ static struct hda_verb alc861vd_dallas_verbs[] = {
15121}; 15120};
15122 15121
15123/* toggle speaker-output according to the hp-jack state */ 15122/* toggle speaker-output according to the hp-jack state */
15124static void alc861vd_dallas_init_hook(struct hda_codec *codec) 15123static void alc861vd_dallas_setup(struct hda_codec *codec)
15125{ 15124{
15126 struct alc_spec *spec = codec->spec; 15125 struct alc_spec *spec = codec->spec;
15127 15126
15128 spec->autocfg.hp_pins[0] = 0x15; 15127 spec->autocfg.hp_pins[0] = 0x15;
15129 spec->autocfg.speaker_pins[0] = 0x14; 15128 spec->autocfg.speaker_pins[0] = 0x14;
15130 alc_automute_amp(codec);
15131} 15129}
15132 15130
15133#ifdef CONFIG_SND_HDA_POWER_SAVE 15131#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -15166,7 +15164,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15166 SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST), 15164 SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15167 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO), 15165 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15168 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/ 15166 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15169 SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS), 15167 SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15170 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO), 15168 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15171 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS), 15169 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15172 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG), 15170 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
@@ -15241,6 +15239,7 @@ static struct alc_config_preset alc861vd_presets[] = {
15241 .channel_mode = alc861vd_3stack_2ch_modes, 15239 .channel_mode = alc861vd_3stack_2ch_modes,
15242 .input_mux = &alc861vd_capture_source, 15240 .input_mux = &alc861vd_capture_source,
15243 .unsol_event = alc861vd_lenovo_unsol_event, 15241 .unsol_event = alc861vd_lenovo_unsol_event,
15242 .setup = alc861vd_lenovo_setup,
15244 .init_hook = alc861vd_lenovo_init_hook, 15243 .init_hook = alc861vd_lenovo_init_hook,
15245 }, 15244 },
15246 [ALC861VD_DALLAS] = { 15245 [ALC861VD_DALLAS] = {
@@ -15252,7 +15251,8 @@ static struct alc_config_preset alc861vd_presets[] = {
15252 .channel_mode = alc861vd_3stack_2ch_modes, 15251 .channel_mode = alc861vd_3stack_2ch_modes,
15253 .input_mux = &alc861vd_dallas_capture_source, 15252 .input_mux = &alc861vd_dallas_capture_source,
15254 .unsol_event = alc_automute_amp_unsol_event, 15253 .unsol_event = alc_automute_amp_unsol_event,
15255 .init_hook = alc861vd_dallas_init_hook, 15254 .setup = alc861vd_dallas_setup,
15255 .init_hook = alc_automute_amp,
15256 }, 15256 },
15257 [ALC861VD_HP] = { 15257 [ALC861VD_HP] = {
15258 .mixers = { alc861vd_hp_mixer }, 15258 .mixers = { alc861vd_hp_mixer },
@@ -15264,7 +15264,8 @@ static struct alc_config_preset alc861vd_presets[] = {
15264 .channel_mode = alc861vd_3stack_2ch_modes, 15264 .channel_mode = alc861vd_3stack_2ch_modes,
15265 .input_mux = &alc861vd_hp_capture_source, 15265 .input_mux = &alc861vd_hp_capture_source,
15266 .unsol_event = alc_automute_amp_unsol_event, 15266 .unsol_event = alc_automute_amp_unsol_event,
15267 .init_hook = alc861vd_dallas_init_hook, 15267 .setup = alc861vd_dallas_setup,
15268 .init_hook = alc_automute_amp,
15268 }, 15269 },
15269 [ALC660VD_ASUS_V1S] = { 15270 [ALC660VD_ASUS_V1S] = {
15270 .mixers = { alc861vd_lenovo_mixer }, 15271 .mixers = { alc861vd_lenovo_mixer },
@@ -15279,6 +15280,7 @@ static struct alc_config_preset alc861vd_presets[] = {
15279 .channel_mode = alc861vd_3stack_2ch_modes, 15280 .channel_mode = alc861vd_3stack_2ch_modes,
15280 .input_mux = &alc861vd_capture_source, 15281 .input_mux = &alc861vd_capture_source,
15281 .unsol_event = alc861vd_lenovo_unsol_event, 15282 .unsol_event = alc861vd_lenovo_unsol_event,
15283 .setup = alc861vd_lenovo_setup,
15282 .init_hook = alc861vd_lenovo_init_hook, 15284 .init_hook = alc861vd_lenovo_init_hook,
15283 }, 15285 },
15284}; 15286};
@@ -15286,6 +15288,13 @@ static struct alc_config_preset alc861vd_presets[] = {
15286/* 15288/*
15287 * BIOS auto configuration 15289 * BIOS auto configuration
15288 */ 15290 */
15291static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
15292 const struct auto_pin_cfg *cfg)
15293{
15294 return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
15295}
15296
15297
15289static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec, 15298static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15290 hda_nid_t nid, int pin_type, int dac_idx) 15299 hda_nid_t nid, int pin_type, int dac_idx)
15291{ 15300{
@@ -15320,7 +15329,6 @@ static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15320 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); 15329 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15321} 15330}
15322 15331
15323#define alc861vd_is_input_pin(nid) alc880_is_input_pin(nid)
15324#define ALC861VD_PIN_CD_NID ALC880_PIN_CD_NID 15332#define ALC861VD_PIN_CD_NID ALC880_PIN_CD_NID
15325 15333
15326static void alc861vd_auto_init_analog_input(struct hda_codec *codec) 15334static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
@@ -15330,7 +15338,7 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15330 15338
15331 for (i = 0; i < AUTO_PIN_LAST; i++) { 15339 for (i = 0; i < AUTO_PIN_LAST; i++) {
15332 hda_nid_t nid = spec->autocfg.input_pins[i]; 15340 hda_nid_t nid = spec->autocfg.input_pins[i];
15333 if (alc861vd_is_input_pin(nid)) { 15341 if (alc_is_input_pin(codec, nid)) {
15334 alc_set_input_pin(codec, nid, i); 15342 alc_set_input_pin(codec, nid, i);
15335 if (nid != ALC861VD_PIN_CD_NID && 15343 if (nid != ALC861VD_PIN_CD_NID &&
15336 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 15344 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -15394,13 +15402,25 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15394 if (err < 0) 15402 if (err < 0)
15395 return err; 15403 return err;
15396 } else { 15404 } else {
15397 sprintf(name, "%s Playback Volume", chname[i]); 15405 const char *pfx;
15406 if (cfg->line_outs == 1 &&
15407 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
15408 if (!cfg->hp_pins)
15409 pfx = "Speaker";
15410 else
15411 pfx = "PCM";
15412 } else
15413 pfx = chname[i];
15414 sprintf(name, "%s Playback Volume", pfx);
15398 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 15415 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15399 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, 15416 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15400 HDA_OUTPUT)); 15417 HDA_OUTPUT));
15401 if (err < 0) 15418 if (err < 0)
15402 return err; 15419 return err;
15403 sprintf(name, "%s Playback Switch", chname[i]); 15420 if (cfg->line_outs == 1 &&
15421 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15422 pfx = "Speaker";
15423 sprintf(name, "%s Playback Switch", pfx);
15404 err = add_control(spec, ALC_CTL_BIND_MUTE, name, 15424 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15405 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, 15425 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15406 HDA_INPUT)); 15426 HDA_INPUT));
@@ -15493,7 +15513,7 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
15493 "Headphone"); 15513 "Headphone");
15494 if (err < 0) 15514 if (err < 0)
15495 return err; 15515 return err;
15496 err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg); 15516 err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
15497 if (err < 0) 15517 if (err < 0)
15498 return err; 15518 return err;
15499 15519
@@ -15547,8 +15567,8 @@ static int patch_alc861vd(struct hda_codec *codec)
15547 alc861vd_cfg_tbl); 15567 alc861vd_cfg_tbl);
15548 15568
15549 if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) { 15569 if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15550 printk(KERN_INFO "hda_codec: Unknown model for %s, " 15570 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15551 "trying auto-probe from BIOS...\n", codec->chip_name); 15571 codec->chip_name);
15552 board_config = ALC861VD_AUTO; 15572 board_config = ALC861VD_AUTO;
15553 } 15573 }
15554 15574
@@ -15573,7 +15593,7 @@ static int patch_alc861vd(struct hda_codec *codec)
15573 } 15593 }
15574 15594
15575 if (board_config != ALC861VD_AUTO) 15595 if (board_config != ALC861VD_AUTO)
15576 setup_preset(spec, &alc861vd_presets[board_config]); 15596 setup_preset(codec, &alc861vd_presets[board_config]);
15577 15597
15578 if (codec->vendor_id == 0x10ec0660) { 15598 if (codec->vendor_id == 0x10ec0660) {
15579 /* always turn on EAPD */ 15599 /* always turn on EAPD */
@@ -15586,11 +15606,14 @@ static int patch_alc861vd(struct hda_codec *codec)
15586 spec->stream_digital_playback = &alc861vd_pcm_digital_playback; 15606 spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15587 spec->stream_digital_capture = &alc861vd_pcm_digital_capture; 15607 spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15588 15608
15589 spec->adc_nids = alc861vd_adc_nids; 15609 if (!spec->adc_nids) {
15590 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids); 15610 spec->adc_nids = alc861vd_adc_nids;
15591 spec->capsrc_nids = alc861vd_capsrc_nids; 15611 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15612 }
15613 if (!spec->capsrc_nids)
15614 spec->capsrc_nids = alc861vd_capsrc_nids;
15592 15615
15593 set_capture_mixer(spec); 15616 set_capture_mixer(codec);
15594 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 15617 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15595 15618
15596 spec->vmaster_nid = 0x02; 15619 spec->vmaster_nid = 0x02;
@@ -15631,9 +15654,9 @@ static hda_nid_t alc272_dac_nids[2] = {
15631 0x02, 0x03 15654 0x02, 0x03
15632}; 15655};
15633 15656
15634static hda_nid_t alc662_adc_nids[1] = { 15657static hda_nid_t alc662_adc_nids[2] = {
15635 /* ADC1-2 */ 15658 /* ADC1-2 */
15636 0x09, 15659 0x09, 0x08
15637}; 15660};
15638 15661
15639static hda_nid_t alc272_adc_nids[1] = { 15662static hda_nid_t alc272_adc_nids[1] = {
@@ -15641,7 +15664,7 @@ static hda_nid_t alc272_adc_nids[1] = {
15641 0x08, 15664 0x08,
15642}; 15665};
15643 15666
15644static hda_nid_t alc662_capsrc_nids[1] = { 0x22 }; 15667static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
15645static hda_nid_t alc272_capsrc_nids[1] = { 0x23 }; 15668static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15646 15669
15647 15670
@@ -15665,14 +15688,6 @@ static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15665 }, 15688 },
15666}; 15689};
15667 15690
15668static struct hda_input_mux alc662_eeepc_capture_source = {
15669 .num_items = 2,
15670 .items = {
15671 { "i-Mic", 0x1 },
15672 { "e-Mic", 0x0 },
15673 },
15674};
15675
15676static struct hda_input_mux alc663_capture_source = { 15691static struct hda_input_mux alc663_capture_source = {
15677 .num_items = 3, 15692 .num_items = 3,
15678 .items = { 15693 .items = {
@@ -15682,23 +15697,7 @@ static struct hda_input_mux alc663_capture_source = {
15682 }, 15697 },
15683}; 15698};
15684 15699
15685static struct hda_input_mux alc663_m51va_capture_source = { 15700#if 0 /* set to 1 for testing other input sources below */
15686 .num_items = 2,
15687 .items = {
15688 { "Ext-Mic", 0x0 },
15689 { "D-Mic", 0x9 },
15690 },
15691};
15692
15693#if 1 /* set to 0 for testing other input sources below */
15694static struct hda_input_mux alc272_nc10_capture_source = {
15695 .num_items = 2,
15696 .items = {
15697 { "Autoselect Mic", 0x0 },
15698 { "Internal Mic", 0x1 },
15699 },
15700};
15701#else
15702static struct hda_input_mux alc272_nc10_capture_source = { 15701static struct hda_input_mux alc272_nc10_capture_source = {
15703 .num_items = 16, 15702 .num_items = 16,
15704 .items = { 15703 .items = {
@@ -16367,47 +16366,44 @@ static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16367 alc662_lenovo_101e_ispeaker_automute(codec); 16366 alc662_lenovo_101e_ispeaker_automute(codec);
16368} 16367}
16369 16368
16370static void alc662_eeepc_mic_automute(struct hda_codec *codec)
16371{
16372 unsigned int present;
16373
16374 present = snd_hda_codec_read(codec, 0x18, 0,
16375 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16376 snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16377 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16378 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16379 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16380 snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16381 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16382 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16383 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16384}
16385
16386/* unsolicited event for HP jack sensing */ 16369/* unsolicited event for HP jack sensing */
16387static void alc662_eeepc_unsol_event(struct hda_codec *codec, 16370static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16388 unsigned int res) 16371 unsigned int res)
16389{ 16372{
16390 if ((res >> 26) == ALC880_MIC_EVENT) 16373 if ((res >> 26) == ALC880_MIC_EVENT)
16391 alc662_eeepc_mic_automute(codec); 16374 alc_mic_automute(codec);
16392 else 16375 else
16393 alc262_hippo_unsol_event(codec, res); 16376 alc262_hippo_unsol_event(codec, res);
16394} 16377}
16395 16378
16379static void alc662_eeepc_setup(struct hda_codec *codec)
16380{
16381 struct alc_spec *spec = codec->spec;
16382
16383 alc262_hippo1_setup(codec);
16384 spec->ext_mic.pin = 0x18;
16385 spec->ext_mic.mux_idx = 0;
16386 spec->int_mic.pin = 0x19;
16387 spec->int_mic.mux_idx = 1;
16388 spec->auto_mic = 1;
16389}
16390
16396static void alc662_eeepc_inithook(struct hda_codec *codec) 16391static void alc662_eeepc_inithook(struct hda_codec *codec)
16397{ 16392{
16398 alc262_hippo1_init_hook(codec); 16393 alc262_hippo_automute(codec);
16399 alc662_eeepc_mic_automute(codec); 16394 alc_mic_automute(codec);
16400} 16395}
16401 16396
16402static void alc662_eeepc_ep20_inithook(struct hda_codec *codec) 16397static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
16403{ 16398{
16404 struct alc_spec *spec = codec->spec; 16399 struct alc_spec *spec = codec->spec;
16405 16400
16406 spec->autocfg.hp_pins[0] = 0x14; 16401 spec->autocfg.hp_pins[0] = 0x14;
16407 spec->autocfg.speaker_pins[0] = 0x1b; 16402 spec->autocfg.speaker_pins[0] = 0x1b;
16408 alc262_hippo_master_update(codec);
16409} 16403}
16410 16404
16405#define alc662_eeepc_ep20_inithook alc262_hippo_master_update
16406
16411static void alc663_m51va_speaker_automute(struct hda_codec *codec) 16407static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16412{ 16408{
16413 unsigned int present; 16409 unsigned int present;
@@ -16518,23 +16514,6 @@ static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16518 } 16514 }
16519} 16515}
16520 16516
16521static void alc663_m51va_mic_automute(struct hda_codec *codec)
16522{
16523 unsigned int present;
16524
16525 present = snd_hda_codec_read(codec, 0x18, 0,
16526 AC_VERB_GET_PIN_SENSE, 0)
16527 & AC_PINSENSE_PRESENCE;
16528 snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16529 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16530 snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16531 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16532 snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16533 0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16534 snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16535 0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16536}
16537
16538static void alc663_m51va_unsol_event(struct hda_codec *codec, 16517static void alc663_m51va_unsol_event(struct hda_codec *codec,
16539 unsigned int res) 16518 unsigned int res)
16540{ 16519{
@@ -16543,36 +16522,32 @@ static void alc663_m51va_unsol_event(struct hda_codec *codec,
16543 alc663_m51va_speaker_automute(codec); 16522 alc663_m51va_speaker_automute(codec);
16544 break; 16523 break;
16545 case ALC880_MIC_EVENT: 16524 case ALC880_MIC_EVENT:
16546 alc663_m51va_mic_automute(codec); 16525 alc_mic_automute(codec);
16547 break; 16526 break;
16548 } 16527 }
16549} 16528}
16550 16529
16530static void alc663_m51va_setup(struct hda_codec *codec)
16531{
16532 struct alc_spec *spec = codec->spec;
16533 spec->ext_mic.pin = 0x18;
16534 spec->ext_mic.mux_idx = 0;
16535 spec->int_mic.pin = 0x12;
16536 spec->int_mic.mux_idx = 1;
16537 spec->auto_mic = 1;
16538}
16539
16551static void alc663_m51va_inithook(struct hda_codec *codec) 16540static void alc663_m51va_inithook(struct hda_codec *codec)
16552{ 16541{
16553 alc663_m51va_speaker_automute(codec); 16542 alc663_m51va_speaker_automute(codec);
16554 alc663_m51va_mic_automute(codec); 16543 alc_mic_automute(codec);
16555} 16544}
16556 16545
16557/* ***************** Mode1 ******************************/ 16546/* ***************** Mode1 ******************************/
16558static void alc663_mode1_unsol_event(struct hda_codec *codec, 16547#define alc663_mode1_unsol_event alc663_m51va_unsol_event
16559 unsigned int res) 16548#define alc663_mode1_setup alc663_m51va_setup
16560{ 16549#define alc663_mode1_inithook alc663_m51va_inithook
16561 switch (res >> 26) {
16562 case ALC880_HP_EVENT:
16563 alc663_m51va_speaker_automute(codec);
16564 break;
16565 case ALC880_MIC_EVENT:
16566 alc662_eeepc_mic_automute(codec);
16567 break;
16568 }
16569}
16570 16550
16571static void alc663_mode1_inithook(struct hda_codec *codec)
16572{
16573 alc663_m51va_speaker_automute(codec);
16574 alc662_eeepc_mic_automute(codec);
16575}
16576/* ***************** Mode2 ******************************/ 16551/* ***************** Mode2 ******************************/
16577static void alc662_mode2_unsol_event(struct hda_codec *codec, 16552static void alc662_mode2_unsol_event(struct hda_codec *codec,
16578 unsigned int res) 16553 unsigned int res)
@@ -16582,15 +16557,17 @@ static void alc662_mode2_unsol_event(struct hda_codec *codec,
16582 alc662_f5z_speaker_automute(codec); 16557 alc662_f5z_speaker_automute(codec);
16583 break; 16558 break;
16584 case ALC880_MIC_EVENT: 16559 case ALC880_MIC_EVENT:
16585 alc662_eeepc_mic_automute(codec); 16560 alc_mic_automute(codec);
16586 break; 16561 break;
16587 } 16562 }
16588} 16563}
16589 16564
16565#define alc662_mode2_setup alc663_m51va_setup
16566
16590static void alc662_mode2_inithook(struct hda_codec *codec) 16567static void alc662_mode2_inithook(struct hda_codec *codec)
16591{ 16568{
16592 alc662_f5z_speaker_automute(codec); 16569 alc662_f5z_speaker_automute(codec);
16593 alc662_eeepc_mic_automute(codec); 16570 alc_mic_automute(codec);
16594} 16571}
16595/* ***************** Mode3 ******************************/ 16572/* ***************** Mode3 ******************************/
16596static void alc663_mode3_unsol_event(struct hda_codec *codec, 16573static void alc663_mode3_unsol_event(struct hda_codec *codec,
@@ -16601,15 +16578,17 @@ static void alc663_mode3_unsol_event(struct hda_codec *codec,
16601 alc663_two_hp_m1_speaker_automute(codec); 16578 alc663_two_hp_m1_speaker_automute(codec);
16602 break; 16579 break;
16603 case ALC880_MIC_EVENT: 16580 case ALC880_MIC_EVENT:
16604 alc662_eeepc_mic_automute(codec); 16581 alc_mic_automute(codec);
16605 break; 16582 break;
16606 } 16583 }
16607} 16584}
16608 16585
16586#define alc663_mode3_setup alc663_m51va_setup
16587
16609static void alc663_mode3_inithook(struct hda_codec *codec) 16588static void alc663_mode3_inithook(struct hda_codec *codec)
16610{ 16589{
16611 alc663_two_hp_m1_speaker_automute(codec); 16590 alc663_two_hp_m1_speaker_automute(codec);
16612 alc662_eeepc_mic_automute(codec); 16591 alc_mic_automute(codec);
16613} 16592}
16614/* ***************** Mode4 ******************************/ 16593/* ***************** Mode4 ******************************/
16615static void alc663_mode4_unsol_event(struct hda_codec *codec, 16594static void alc663_mode4_unsol_event(struct hda_codec *codec,
@@ -16620,15 +16599,17 @@ static void alc663_mode4_unsol_event(struct hda_codec *codec,
16620 alc663_21jd_two_speaker_automute(codec); 16599 alc663_21jd_two_speaker_automute(codec);
16621 break; 16600 break;
16622 case ALC880_MIC_EVENT: 16601 case ALC880_MIC_EVENT:
16623 alc662_eeepc_mic_automute(codec); 16602 alc_mic_automute(codec);
16624 break; 16603 break;
16625 } 16604 }
16626} 16605}
16627 16606
16607#define alc663_mode4_setup alc663_m51va_setup
16608
16628static void alc663_mode4_inithook(struct hda_codec *codec) 16609static void alc663_mode4_inithook(struct hda_codec *codec)
16629{ 16610{
16630 alc663_21jd_two_speaker_automute(codec); 16611 alc663_21jd_two_speaker_automute(codec);
16631 alc662_eeepc_mic_automute(codec); 16612 alc_mic_automute(codec);
16632} 16613}
16633/* ***************** Mode5 ******************************/ 16614/* ***************** Mode5 ******************************/
16634static void alc663_mode5_unsol_event(struct hda_codec *codec, 16615static void alc663_mode5_unsol_event(struct hda_codec *codec,
@@ -16639,15 +16620,17 @@ static void alc663_mode5_unsol_event(struct hda_codec *codec,
16639 alc663_15jd_two_speaker_automute(codec); 16620 alc663_15jd_two_speaker_automute(codec);
16640 break; 16621 break;
16641 case ALC880_MIC_EVENT: 16622 case ALC880_MIC_EVENT:
16642 alc662_eeepc_mic_automute(codec); 16623 alc_mic_automute(codec);
16643 break; 16624 break;
16644 } 16625 }
16645} 16626}
16646 16627
16628#define alc663_mode5_setup alc663_m51va_setup
16629
16647static void alc663_mode5_inithook(struct hda_codec *codec) 16630static void alc663_mode5_inithook(struct hda_codec *codec)
16648{ 16631{
16649 alc663_15jd_two_speaker_automute(codec); 16632 alc663_15jd_two_speaker_automute(codec);
16650 alc662_eeepc_mic_automute(codec); 16633 alc_mic_automute(codec);
16651} 16634}
16652/* ***************** Mode6 ******************************/ 16635/* ***************** Mode6 ******************************/
16653static void alc663_mode6_unsol_event(struct hda_codec *codec, 16636static void alc663_mode6_unsol_event(struct hda_codec *codec,
@@ -16658,15 +16641,17 @@ static void alc663_mode6_unsol_event(struct hda_codec *codec,
16658 alc663_two_hp_m2_speaker_automute(codec); 16641 alc663_two_hp_m2_speaker_automute(codec);
16659 break; 16642 break;
16660 case ALC880_MIC_EVENT: 16643 case ALC880_MIC_EVENT:
16661 alc662_eeepc_mic_automute(codec); 16644 alc_mic_automute(codec);
16662 break; 16645 break;
16663 } 16646 }
16664} 16647}
16665 16648
16649#define alc663_mode6_setup alc663_m51va_setup
16650
16666static void alc663_mode6_inithook(struct hda_codec *codec) 16651static void alc663_mode6_inithook(struct hda_codec *codec)
16667{ 16652{
16668 alc663_two_hp_m2_speaker_automute(codec); 16653 alc663_two_hp_m2_speaker_automute(codec);
16669 alc662_eeepc_mic_automute(codec); 16654 alc_mic_automute(codec);
16670} 16655}
16671 16656
16672static void alc663_g71v_hp_automute(struct hda_codec *codec) 16657static void alc663_g71v_hp_automute(struct hda_codec *codec)
@@ -16708,16 +16693,18 @@ static void alc663_g71v_unsol_event(struct hda_codec *codec,
16708 alc663_g71v_front_automute(codec); 16693 alc663_g71v_front_automute(codec);
16709 break; 16694 break;
16710 case ALC880_MIC_EVENT: 16695 case ALC880_MIC_EVENT:
16711 alc662_eeepc_mic_automute(codec); 16696 alc_mic_automute(codec);
16712 break; 16697 break;
16713 } 16698 }
16714} 16699}
16715 16700
16701#define alc663_g71v_setup alc663_m51va_setup
16702
16716static void alc663_g71v_inithook(struct hda_codec *codec) 16703static void alc663_g71v_inithook(struct hda_codec *codec)
16717{ 16704{
16718 alc663_g71v_front_automute(codec); 16705 alc663_g71v_front_automute(codec);
16719 alc663_g71v_hp_automute(codec); 16706 alc663_g71v_hp_automute(codec);
16720 alc662_eeepc_mic_automute(codec); 16707 alc_mic_automute(codec);
16721} 16708}
16722 16709
16723static void alc663_g50v_unsol_event(struct hda_codec *codec, 16710static void alc663_g50v_unsol_event(struct hda_codec *codec,
@@ -16728,15 +16715,17 @@ static void alc663_g50v_unsol_event(struct hda_codec *codec,
16728 alc663_m51va_speaker_automute(codec); 16715 alc663_m51va_speaker_automute(codec);
16729 break; 16716 break;
16730 case ALC880_MIC_EVENT: 16717 case ALC880_MIC_EVENT:
16731 alc662_eeepc_mic_automute(codec); 16718 alc_mic_automute(codec);
16732 break; 16719 break;
16733 } 16720 }
16734} 16721}
16735 16722
16723#define alc663_g50v_setup alc663_m51va_setup
16724
16736static void alc663_g50v_inithook(struct hda_codec *codec) 16725static void alc663_g50v_inithook(struct hda_codec *codec)
16737{ 16726{
16738 alc663_m51va_speaker_automute(codec); 16727 alc663_m51va_speaker_automute(codec);
16739 alc662_eeepc_mic_automute(codec); 16728 alc_mic_automute(codec);
16740} 16729}
16741 16730
16742static struct snd_kcontrol_new alc662_ecs_mixer[] = { 16731static struct snd_kcontrol_new alc662_ecs_mixer[] = {
@@ -16940,8 +16929,8 @@ static struct alc_config_preset alc662_presets[] = {
16940 .dac_nids = alc662_dac_nids, 16929 .dac_nids = alc662_dac_nids,
16941 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16930 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16942 .channel_mode = alc662_3ST_2ch_modes, 16931 .channel_mode = alc662_3ST_2ch_modes,
16943 .input_mux = &alc662_eeepc_capture_source,
16944 .unsol_event = alc662_eeepc_unsol_event, 16932 .unsol_event = alc662_eeepc_unsol_event,
16933 .setup = alc662_eeepc_setup,
16945 .init_hook = alc662_eeepc_inithook, 16934 .init_hook = alc662_eeepc_inithook,
16946 }, 16935 },
16947 [ALC662_ASUS_EEEPC_EP20] = { 16936 [ALC662_ASUS_EEEPC_EP20] = {
@@ -16955,6 +16944,7 @@ static struct alc_config_preset alc662_presets[] = {
16955 .channel_mode = alc662_3ST_6ch_modes, 16944 .channel_mode = alc662_3ST_6ch_modes,
16956 .input_mux = &alc662_lenovo_101e_capture_source, 16945 .input_mux = &alc662_lenovo_101e_capture_source,
16957 .unsol_event = alc662_eeepc_unsol_event, 16946 .unsol_event = alc662_eeepc_unsol_event,
16947 .setup = alc662_eeepc_ep20_setup,
16958 .init_hook = alc662_eeepc_ep20_inithook, 16948 .init_hook = alc662_eeepc_ep20_inithook,
16959 }, 16949 },
16960 [ALC662_ECS] = { 16950 [ALC662_ECS] = {
@@ -16965,8 +16955,8 @@ static struct alc_config_preset alc662_presets[] = {
16965 .dac_nids = alc662_dac_nids, 16955 .dac_nids = alc662_dac_nids,
16966 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16956 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16967 .channel_mode = alc662_3ST_2ch_modes, 16957 .channel_mode = alc662_3ST_2ch_modes,
16968 .input_mux = &alc662_eeepc_capture_source,
16969 .unsol_event = alc662_eeepc_unsol_event, 16958 .unsol_event = alc662_eeepc_unsol_event,
16959 .setup = alc662_eeepc_setup,
16970 .init_hook = alc662_eeepc_inithook, 16960 .init_hook = alc662_eeepc_inithook,
16971 }, 16961 },
16972 [ALC663_ASUS_M51VA] = { 16962 [ALC663_ASUS_M51VA] = {
@@ -16977,8 +16967,8 @@ static struct alc_config_preset alc662_presets[] = {
16977 .dig_out_nid = ALC662_DIGOUT_NID, 16967 .dig_out_nid = ALC662_DIGOUT_NID,
16978 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16968 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16979 .channel_mode = alc662_3ST_2ch_modes, 16969 .channel_mode = alc662_3ST_2ch_modes,
16980 .input_mux = &alc663_m51va_capture_source,
16981 .unsol_event = alc663_m51va_unsol_event, 16970 .unsol_event = alc663_m51va_unsol_event,
16971 .setup = alc663_m51va_setup,
16982 .init_hook = alc663_m51va_inithook, 16972 .init_hook = alc663_m51va_inithook,
16983 }, 16973 },
16984 [ALC663_ASUS_G71V] = { 16974 [ALC663_ASUS_G71V] = {
@@ -16989,8 +16979,8 @@ static struct alc_config_preset alc662_presets[] = {
16989 .dig_out_nid = ALC662_DIGOUT_NID, 16979 .dig_out_nid = ALC662_DIGOUT_NID,
16990 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16980 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16991 .channel_mode = alc662_3ST_2ch_modes, 16981 .channel_mode = alc662_3ST_2ch_modes,
16992 .input_mux = &alc662_eeepc_capture_source,
16993 .unsol_event = alc663_g71v_unsol_event, 16982 .unsol_event = alc663_g71v_unsol_event,
16983 .setup = alc663_g71v_setup,
16994 .init_hook = alc663_g71v_inithook, 16984 .init_hook = alc663_g71v_inithook,
16995 }, 16985 },
16996 [ALC663_ASUS_H13] = { 16986 [ALC663_ASUS_H13] = {
@@ -17000,7 +16990,6 @@ static struct alc_config_preset alc662_presets[] = {
17000 .dac_nids = alc662_dac_nids, 16990 .dac_nids = alc662_dac_nids,
17001 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16991 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17002 .channel_mode = alc662_3ST_2ch_modes, 16992 .channel_mode = alc662_3ST_2ch_modes,
17003 .input_mux = &alc663_m51va_capture_source,
17004 .unsol_event = alc663_m51va_unsol_event, 16993 .unsol_event = alc663_m51va_unsol_event,
17005 .init_hook = alc663_m51va_inithook, 16994 .init_hook = alc663_m51va_inithook,
17006 }, 16995 },
@@ -17014,6 +17003,7 @@ static struct alc_config_preset alc662_presets[] = {
17014 .channel_mode = alc662_3ST_6ch_modes, 17003 .channel_mode = alc662_3ST_6ch_modes,
17015 .input_mux = &alc663_capture_source, 17004 .input_mux = &alc663_capture_source,
17016 .unsol_event = alc663_g50v_unsol_event, 17005 .unsol_event = alc663_g50v_unsol_event,
17006 .setup = alc663_g50v_setup,
17017 .init_hook = alc663_g50v_inithook, 17007 .init_hook = alc663_g50v_inithook,
17018 }, 17008 },
17019 [ALC663_ASUS_MODE1] = { 17009 [ALC663_ASUS_MODE1] = {
@@ -17027,8 +17017,8 @@ static struct alc_config_preset alc662_presets[] = {
17027 .dig_out_nid = ALC662_DIGOUT_NID, 17017 .dig_out_nid = ALC662_DIGOUT_NID,
17028 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17018 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17029 .channel_mode = alc662_3ST_2ch_modes, 17019 .channel_mode = alc662_3ST_2ch_modes,
17030 .input_mux = &alc662_eeepc_capture_source,
17031 .unsol_event = alc663_mode1_unsol_event, 17020 .unsol_event = alc663_mode1_unsol_event,
17021 .setup = alc663_mode1_setup,
17032 .init_hook = alc663_mode1_inithook, 17022 .init_hook = alc663_mode1_inithook,
17033 }, 17023 },
17034 [ALC662_ASUS_MODE2] = { 17024 [ALC662_ASUS_MODE2] = {
@@ -17041,8 +17031,8 @@ static struct alc_config_preset alc662_presets[] = {
17041 .dig_out_nid = ALC662_DIGOUT_NID, 17031 .dig_out_nid = ALC662_DIGOUT_NID,
17042 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17032 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17043 .channel_mode = alc662_3ST_2ch_modes, 17033 .channel_mode = alc662_3ST_2ch_modes,
17044 .input_mux = &alc662_eeepc_capture_source,
17045 .unsol_event = alc662_mode2_unsol_event, 17034 .unsol_event = alc662_mode2_unsol_event,
17035 .setup = alc662_mode2_setup,
17046 .init_hook = alc662_mode2_inithook, 17036 .init_hook = alc662_mode2_inithook,
17047 }, 17037 },
17048 [ALC663_ASUS_MODE3] = { 17038 [ALC663_ASUS_MODE3] = {
@@ -17056,8 +17046,8 @@ static struct alc_config_preset alc662_presets[] = {
17056 .dig_out_nid = ALC662_DIGOUT_NID, 17046 .dig_out_nid = ALC662_DIGOUT_NID,
17057 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17047 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17058 .channel_mode = alc662_3ST_2ch_modes, 17048 .channel_mode = alc662_3ST_2ch_modes,
17059 .input_mux = &alc662_eeepc_capture_source,
17060 .unsol_event = alc663_mode3_unsol_event, 17049 .unsol_event = alc663_mode3_unsol_event,
17050 .setup = alc663_mode3_setup,
17061 .init_hook = alc663_mode3_inithook, 17051 .init_hook = alc663_mode3_inithook,
17062 }, 17052 },
17063 [ALC663_ASUS_MODE4] = { 17053 [ALC663_ASUS_MODE4] = {
@@ -17071,8 +17061,8 @@ static struct alc_config_preset alc662_presets[] = {
17071 .dig_out_nid = ALC662_DIGOUT_NID, 17061 .dig_out_nid = ALC662_DIGOUT_NID,
17072 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17062 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17073 .channel_mode = alc662_3ST_2ch_modes, 17063 .channel_mode = alc662_3ST_2ch_modes,
17074 .input_mux = &alc662_eeepc_capture_source,
17075 .unsol_event = alc663_mode4_unsol_event, 17064 .unsol_event = alc663_mode4_unsol_event,
17065 .setup = alc663_mode4_setup,
17076 .init_hook = alc663_mode4_inithook, 17066 .init_hook = alc663_mode4_inithook,
17077 }, 17067 },
17078 [ALC663_ASUS_MODE5] = { 17068 [ALC663_ASUS_MODE5] = {
@@ -17086,8 +17076,8 @@ static struct alc_config_preset alc662_presets[] = {
17086 .dig_out_nid = ALC662_DIGOUT_NID, 17076 .dig_out_nid = ALC662_DIGOUT_NID,
17087 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17077 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17088 .channel_mode = alc662_3ST_2ch_modes, 17078 .channel_mode = alc662_3ST_2ch_modes,
17089 .input_mux = &alc662_eeepc_capture_source,
17090 .unsol_event = alc663_mode5_unsol_event, 17079 .unsol_event = alc663_mode5_unsol_event,
17080 .setup = alc663_mode5_setup,
17091 .init_hook = alc663_mode5_inithook, 17081 .init_hook = alc663_mode5_inithook,
17092 }, 17082 },
17093 [ALC663_ASUS_MODE6] = { 17083 [ALC663_ASUS_MODE6] = {
@@ -17101,8 +17091,8 @@ static struct alc_config_preset alc662_presets[] = {
17101 .dig_out_nid = ALC662_DIGOUT_NID, 17091 .dig_out_nid = ALC662_DIGOUT_NID,
17102 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17092 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17103 .channel_mode = alc662_3ST_2ch_modes, 17093 .channel_mode = alc662_3ST_2ch_modes,
17104 .input_mux = &alc662_eeepc_capture_source,
17105 .unsol_event = alc663_mode6_unsol_event, 17094 .unsol_event = alc663_mode6_unsol_event,
17095 .setup = alc663_mode6_setup,
17106 .init_hook = alc663_mode6_inithook, 17096 .init_hook = alc663_mode6_inithook,
17107 }, 17097 },
17108 [ALC272_DELL] = { 17098 [ALC272_DELL] = {
@@ -17116,8 +17106,8 @@ static struct alc_config_preset alc662_presets[] = {
17116 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids), 17106 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17117 .capsrc_nids = alc272_capsrc_nids, 17107 .capsrc_nids = alc272_capsrc_nids,
17118 .channel_mode = alc662_3ST_2ch_modes, 17108 .channel_mode = alc662_3ST_2ch_modes,
17119 .input_mux = &alc663_m51va_capture_source,
17120 .unsol_event = alc663_m51va_unsol_event, 17109 .unsol_event = alc663_m51va_unsol_event,
17110 .setup = alc663_m51va_setup,
17121 .init_hook = alc663_m51va_inithook, 17111 .init_hook = alc663_m51va_inithook,
17122 }, 17112 },
17123 [ALC272_DELL_ZM1] = { 17113 [ALC272_DELL_ZM1] = {
@@ -17128,11 +17118,11 @@ static struct alc_config_preset alc662_presets[] = {
17128 .dac_nids = alc662_dac_nids, 17118 .dac_nids = alc662_dac_nids,
17129 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17119 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17130 .adc_nids = alc662_adc_nids, 17120 .adc_nids = alc662_adc_nids,
17131 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids), 17121 .num_adc_nids = 1,
17132 .capsrc_nids = alc662_capsrc_nids, 17122 .capsrc_nids = alc662_capsrc_nids,
17133 .channel_mode = alc662_3ST_2ch_modes, 17123 .channel_mode = alc662_3ST_2ch_modes,
17134 .input_mux = &alc663_m51va_capture_source,
17135 .unsol_event = alc663_m51va_unsol_event, 17124 .unsol_event = alc663_m51va_unsol_event,
17125 .setup = alc663_m51va_setup,
17136 .init_hook = alc663_m51va_inithook, 17126 .init_hook = alc663_m51va_inithook,
17137 }, 17127 },
17138 [ALC272_SAMSUNG_NC10] = { 17128 [ALC272_SAMSUNG_NC10] = {
@@ -17143,8 +17133,9 @@ static struct alc_config_preset alc662_presets[] = {
17143 .dac_nids = alc272_dac_nids, 17133 .dac_nids = alc272_dac_nids,
17144 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17134 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17145 .channel_mode = alc662_3ST_2ch_modes, 17135 .channel_mode = alc662_3ST_2ch_modes,
17146 .input_mux = &alc272_nc10_capture_source, 17136 /*.input_mux = &alc272_nc10_capture_source,*/
17147 .unsol_event = alc663_mode4_unsol_event, 17137 .unsol_event = alc663_mode4_unsol_event,
17138 .setup = alc663_mode4_setup,
17148 .init_hook = alc663_mode4_inithook, 17139 .init_hook = alc663_mode4_inithook,
17149 }, 17140 },
17150}; 17141};
@@ -17196,13 +17187,25 @@ static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
17196 if (err < 0) 17187 if (err < 0)
17197 return err; 17188 return err;
17198 } else { 17189 } else {
17199 sprintf(name, "%s Playback Volume", chname[i]); 17190 const char *pfx;
17191 if (cfg->line_outs == 1 &&
17192 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
17193 if (!cfg->hp_pins)
17194 pfx = "Speaker";
17195 else
17196 pfx = "PCM";
17197 } else
17198 pfx = chname[i];
17199 sprintf(name, "%s Playback Volume", pfx);
17200 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 17200 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
17201 HDA_COMPOSE_AMP_VAL(nid, 3, 0, 17201 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
17202 HDA_OUTPUT)); 17202 HDA_OUTPUT));
17203 if (err < 0) 17203 if (err < 0)
17204 return err; 17204 return err;
17205 sprintf(name, "%s Playback Switch", chname[i]); 17205 if (cfg->line_outs == 1 &&
17206 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
17207 pfx = "Speaker";
17208 sprintf(name, "%s Playback Switch", pfx);
17206 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 17209 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17207 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i), 17210 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
17208 3, 0, HDA_INPUT)); 17211 3, 0, HDA_INPUT));
@@ -17264,62 +17267,9 @@ static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
17264 return 0; 17267 return 0;
17265} 17268}
17266 17269
17267/* return the index of the src widget from the connection list of the nid.
17268 * return -1 if not found
17269 */
17270static int alc662_input_pin_idx(struct hda_codec *codec, hda_nid_t nid,
17271 hda_nid_t src)
17272{
17273 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
17274 int i, conns;
17275
17276 conns = snd_hda_get_connections(codec, nid, conn_list,
17277 ARRAY_SIZE(conn_list));
17278 if (conns < 0)
17279 return -1;
17280 for (i = 0; i < conns; i++)
17281 if (conn_list[i] == src)
17282 return i;
17283 return -1;
17284}
17285
17286static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
17287{
17288 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
17289 return (pincap & AC_PINCAP_IN) != 0;
17290}
17291
17292/* create playback/capture controls for input pins */ 17270/* create playback/capture controls for input pins */
17293static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec, 17271#define alc662_auto_create_input_ctls \
17294 const struct auto_pin_cfg *cfg) 17272 alc880_auto_create_input_ctls
17295{
17296 struct alc_spec *spec = codec->spec;
17297 struct hda_input_mux *imux = &spec->private_imux[0];
17298 int i, err, idx;
17299
17300 for (i = 0; i < AUTO_PIN_LAST; i++) {
17301 if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
17302 idx = alc662_input_pin_idx(codec, 0x0b,
17303 cfg->input_pins[i]);
17304 if (idx >= 0) {
17305 err = new_analog_input(spec, cfg->input_pins[i],
17306 auto_pin_cfg_labels[i],
17307 idx, 0x0b);
17308 if (err < 0)
17309 return err;
17310 }
17311 idx = alc662_input_pin_idx(codec, 0x22,
17312 cfg->input_pins[i]);
17313 if (idx >= 0) {
17314 imux->items[imux->num_items].label =
17315 auto_pin_cfg_labels[i];
17316 imux->items[imux->num_items].index = idx;
17317 imux->num_items++;
17318 }
17319 }
17320 }
17321 return 0;
17322}
17323 17273
17324static void alc662_auto_set_output_and_unmute(struct hda_codec *codec, 17274static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17325 hda_nid_t nid, int pin_type, 17275 hda_nid_t nid, int pin_type,
@@ -17373,7 +17323,7 @@ static void alc662_auto_init_analog_input(struct hda_codec *codec)
17373 17323
17374 for (i = 0; i < AUTO_PIN_LAST; i++) { 17324 for (i = 0; i < AUTO_PIN_LAST; i++) {
17375 hda_nid_t nid = spec->autocfg.input_pins[i]; 17325 hda_nid_t nid = spec->autocfg.input_pins[i];
17376 if (alc662_is_input_pin(codec, nid)) { 17326 if (alc_is_input_pin(codec, nid)) {
17377 alc_set_input_pin(codec, nid, i); 17327 alc_set_input_pin(codec, nid, i);
17378 if (nid != ALC662_PIN_CD_NID && 17328 if (nid != ALC662_PIN_CD_NID &&
17379 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 17329 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -17414,7 +17364,7 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
17414 "Headphone"); 17364 "Headphone");
17415 if (err < 0) 17365 if (err < 0)
17416 return err; 17366 return err;
17417 err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg); 17367 err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
17418 if (err < 0) 17368 if (err < 0)
17419 return err; 17369 return err;
17420 17370
@@ -17471,8 +17421,8 @@ static int patch_alc662(struct hda_codec *codec)
17471 alc662_models, 17421 alc662_models,
17472 alc662_cfg_tbl); 17422 alc662_cfg_tbl);
17473 if (board_config < 0) { 17423 if (board_config < 0) {
17474 printk(KERN_INFO "hda_codec: Unknown model for %s, " 17424 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17475 "trying auto-probe from BIOS...\n", codec->chip_name); 17425 codec->chip_name);
17476 board_config = ALC662_AUTO; 17426 board_config = ALC662_AUTO;
17477 } 17427 }
17478 17428
@@ -17497,7 +17447,7 @@ static int patch_alc662(struct hda_codec *codec)
17497 } 17447 }
17498 17448
17499 if (board_config != ALC662_AUTO) 17449 if (board_config != ALC662_AUTO)
17500 setup_preset(spec, &alc662_presets[board_config]); 17450 setup_preset(codec, &alc662_presets[board_config]);
17501 17451
17502 spec->stream_analog_playback = &alc662_pcm_analog_playback; 17452 spec->stream_analog_playback = &alc662_pcm_analog_playback;
17503 spec->stream_analog_capture = &alc662_pcm_analog_capture; 17453 spec->stream_analog_capture = &alc662_pcm_analog_capture;
@@ -17505,12 +17455,15 @@ static int patch_alc662(struct hda_codec *codec)
17505 spec->stream_digital_playback = &alc662_pcm_digital_playback; 17455 spec->stream_digital_playback = &alc662_pcm_digital_playback;
17506 spec->stream_digital_capture = &alc662_pcm_digital_capture; 17456 spec->stream_digital_capture = &alc662_pcm_digital_capture;
17507 17457
17508 spec->adc_nids = alc662_adc_nids; 17458 if (!spec->adc_nids) {
17509 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids); 17459 spec->adc_nids = alc662_adc_nids;
17510 spec->capsrc_nids = alc662_capsrc_nids; 17460 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17461 }
17462 if (!spec->capsrc_nids)
17463 spec->capsrc_nids = alc662_capsrc_nids;
17511 17464
17512 if (!spec->cap_mixer) 17465 if (!spec->cap_mixer)
17513 set_capture_mixer(spec); 17466 set_capture_mixer(codec);
17514 if (codec->vendor_id == 0x10ec0662) 17467 if (codec->vendor_id == 0x10ec0662)
17515 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 17468 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17516 else 17469 else
@@ -17546,23 +17499,23 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
17546 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, 17499 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17547 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, 17500 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17548 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", 17501 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17549 .patch = patch_alc883 }, 17502 .patch = patch_alc882 },
17550 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", 17503 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17551 .patch = patch_alc662 }, 17504 .patch = patch_alc662 },
17552 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, 17505 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17553 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, 17506 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17554 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, 17507 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17555 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 }, 17508 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
17556 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", 17509 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17557 .patch = patch_alc882 }, /* should be patch_alc883() in future */ 17510 .patch = patch_alc882 },
17558 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", 17511 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17559 .patch = patch_alc882 }, /* should be patch_alc883() in future */ 17512 .patch = patch_alc882 },
17560 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, 17513 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17561 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 }, 17514 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17562 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", 17515 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17563 .patch = patch_alc883 }, 17516 .patch = patch_alc882 },
17564 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 }, 17517 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
17565 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 }, 17518 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17566 {} /* terminator */ 17519 {} /* terminator */
17567}; 17520};
17568 17521
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 14f3c3e0f62..826137ec300 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -40,6 +40,8 @@ enum {
40 STAC_INSERT_EVENT, 40 STAC_INSERT_EVENT,
41 STAC_PWR_EVENT, 41 STAC_PWR_EVENT,
42 STAC_HP_EVENT, 42 STAC_HP_EVENT,
43 STAC_LO_EVENT,
44 STAC_MIC_EVENT,
43}; 45};
44 46
45enum { 47enum {
@@ -76,10 +78,12 @@ enum {
76 STAC_92HD73XX_AUTO, 78 STAC_92HD73XX_AUTO,
77 STAC_92HD73XX_NO_JD, /* no jack-detection */ 79 STAC_92HD73XX_NO_JD, /* no jack-detection */
78 STAC_92HD73XX_REF, 80 STAC_92HD73XX_REF,
81 STAC_92HD73XX_INTEL,
79 STAC_DELL_M6_AMIC, 82 STAC_DELL_M6_AMIC,
80 STAC_DELL_M6_DMIC, 83 STAC_DELL_M6_DMIC,
81 STAC_DELL_M6_BOTH, 84 STAC_DELL_M6_BOTH,
82 STAC_DELL_EQ, 85 STAC_DELL_EQ,
86 STAC_ALIENWARE_M17X,
83 STAC_92HD73XX_MODELS 87 STAC_92HD73XX_MODELS
84}; 88};
85 89
@@ -176,6 +180,12 @@ struct sigmatel_jack {
176 struct snd_jack *jack; 180 struct snd_jack *jack;
177}; 181};
178 182
183struct sigmatel_mic_route {
184 hda_nid_t pin;
185 unsigned char mux_idx;
186 unsigned char dmux_idx;
187};
188
179struct sigmatel_spec { 189struct sigmatel_spec {
180 struct snd_kcontrol_new *mixers[4]; 190 struct snd_kcontrol_new *mixers[4];
181 unsigned int num_mixers; 191 unsigned int num_mixers;
@@ -187,6 +197,7 @@ struct sigmatel_spec {
187 unsigned int hp_detect: 1; 197 unsigned int hp_detect: 1;
188 unsigned int spdif_mute: 1; 198 unsigned int spdif_mute: 1;
189 unsigned int check_volume_offset:1; 199 unsigned int check_volume_offset:1;
200 unsigned int auto_mic:1;
190 201
191 /* gpio lines */ 202 /* gpio lines */
192 unsigned int eapd_mask; 203 unsigned int eapd_mask;
@@ -218,7 +229,6 @@ struct sigmatel_spec {
218 229
219 /* playback */ 230 /* playback */
220 struct hda_input_mux *mono_mux; 231 struct hda_input_mux *mono_mux;
221 struct hda_input_mux *amp_mux;
222 unsigned int cur_mmux; 232 unsigned int cur_mmux;
223 struct hda_multi_out multiout; 233 struct hda_multi_out multiout;
224 hda_nid_t dac_nids[5]; 234 hda_nid_t dac_nids[5];
@@ -238,6 +248,15 @@ struct sigmatel_spec {
238 unsigned int num_dmuxes; 248 unsigned int num_dmuxes;
239 hda_nid_t *smux_nids; 249 hda_nid_t *smux_nids;
240 unsigned int num_smuxes; 250 unsigned int num_smuxes;
251 unsigned int num_analog_muxes;
252
253 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
254 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
255 unsigned int num_caps; /* number of capture volume/switch elements */
256
257 struct sigmatel_mic_route ext_mic;
258 struct sigmatel_mic_route int_mic;
259
241 const char **spdif_labels; 260 const char **spdif_labels;
242 261
243 hda_nid_t dig_in_nid; 262 hda_nid_t dig_in_nid;
@@ -262,7 +281,6 @@ struct sigmatel_spec {
262 unsigned int cur_smux[2]; 281 unsigned int cur_smux[2];
263 unsigned int cur_amux; 282 unsigned int cur_amux;
264 hda_nid_t *amp_nids; 283 hda_nid_t *amp_nids;
265 unsigned int num_amps;
266 unsigned int powerdown_adcs; 284 unsigned int powerdown_adcs;
267 285
268 /* i/o switches */ 286 /* i/o switches */
@@ -281,7 +299,6 @@ struct sigmatel_spec {
281 struct hda_input_mux private_dimux; 299 struct hda_input_mux private_dimux;
282 struct hda_input_mux private_imux; 300 struct hda_input_mux private_imux;
283 struct hda_input_mux private_smux; 301 struct hda_input_mux private_smux;
284 struct hda_input_mux private_amp_mux;
285 struct hda_input_mux private_mono_mux; 302 struct hda_input_mux private_mono_mux;
286}; 303};
287 304
@@ -310,11 +327,6 @@ static hda_nid_t stac92hd73xx_adc_nids[2] = {
310 0x1a, 0x1b 327 0x1a, 0x1b
311}; 328};
312 329
313#define DELL_M6_AMP 2
314static hda_nid_t stac92hd73xx_amp_nids[3] = {
315 0x0b, 0x0c, 0x0e
316};
317
318#define STAC92HD73XX_NUM_DMICS 2 330#define STAC92HD73XX_NUM_DMICS 2
319static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = { 331static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
320 0x13, 0x14, 0 332 0x13, 0x14, 0
@@ -322,8 +334,8 @@ static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
322 334
323#define STAC92HD73_DAC_COUNT 5 335#define STAC92HD73_DAC_COUNT 5
324 336
325static hda_nid_t stac92hd73xx_mux_nids[4] = { 337static hda_nid_t stac92hd73xx_mux_nids[2] = {
326 0x28, 0x29, 0x2a, 0x2b, 338 0x20, 0x21,
327}; 339};
328 340
329static hda_nid_t stac92hd73xx_dmux_nids[2] = { 341static hda_nid_t stac92hd73xx_dmux_nids[2] = {
@@ -334,14 +346,16 @@ static hda_nid_t stac92hd73xx_smux_nids[2] = {
334 0x22, 0x23, 346 0x22, 0x23,
335}; 347};
336 348
337#define STAC92HD83XXX_NUM_DMICS 2 349#define STAC92HD73XX_NUM_CAPS 2
338static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = { 350static unsigned long stac92hd73xx_capvols[] = {
339 0x11, 0x12, 0 351 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
352 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
340}; 353};
354#define stac92hd73xx_capsws stac92hd73xx_capvols
341 355
342#define STAC92HD83_DAC_COUNT 3 356#define STAC92HD83_DAC_COUNT 3
343 357
344static hda_nid_t stac92hd83xxx_dmux_nids[2] = { 358static hda_nid_t stac92hd83xxx_mux_nids[2] = {
345 0x17, 0x18, 359 0x17, 0x18,
346}; 360};
347 361
@@ -361,9 +375,12 @@ static unsigned int stac92hd83xxx_pwr_mapping[4] = {
361 0x03, 0x0c, 0x20, 0x40, 375 0x03, 0x0c, 0x20, 0x40,
362}; 376};
363 377
364static hda_nid_t stac92hd83xxx_amp_nids[1] = { 378#define STAC92HD83XXX_NUM_CAPS 2
365 0xc, 379static unsigned long stac92hd83xxx_capvols[] = {
380 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
381 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
366}; 382};
383#define stac92hd83xxx_capsws stac92hd83xxx_capvols
367 384
368static hda_nid_t stac92hd71bxx_pwr_nids[3] = { 385static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
369 0x0a, 0x0d, 0x0f 386 0x0a, 0x0d, 0x0f
@@ -394,6 +411,13 @@ static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
394 0x22, 0 411 0x22, 0
395}; 412};
396 413
414#define STAC92HD71BXX_NUM_CAPS 2
415static unsigned long stac92hd71bxx_capvols[] = {
416 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
417 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
418};
419#define stac92hd71bxx_capsws stac92hd71bxx_capvols
420
397static hda_nid_t stac925x_adc_nids[1] = { 421static hda_nid_t stac925x_adc_nids[1] = {
398 0x03, 422 0x03,
399}; 423};
@@ -415,6 +439,13 @@ static hda_nid_t stac925x_dmux_nids[1] = {
415 0x14, 439 0x14,
416}; 440};
417 441
442static unsigned long stac925x_capvols[] = {
443 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
444};
445static unsigned long stac925x_capsws[] = {
446 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
447};
448
418static hda_nid_t stac922x_adc_nids[2] = { 449static hda_nid_t stac922x_adc_nids[2] = {
419 0x06, 0x07, 450 0x06, 0x07,
420}; 451};
@@ -423,6 +454,13 @@ static hda_nid_t stac922x_mux_nids[2] = {
423 0x12, 0x13, 454 0x12, 0x13,
424}; 455};
425 456
457#define STAC922X_NUM_CAPS 2
458static unsigned long stac922x_capvols[] = {
459 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
460 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
461};
462#define stac922x_capsws stac922x_capvols
463
426static hda_nid_t stac927x_slave_dig_outs[2] = { 464static hda_nid_t stac927x_slave_dig_outs[2] = {
427 0x1f, 0, 465 0x1f, 0,
428}; 466};
@@ -452,6 +490,18 @@ static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
452 0x13, 0x14, 0 490 0x13, 0x14, 0
453}; 491};
454 492
493#define STAC927X_NUM_CAPS 3
494static unsigned long stac927x_capvols[] = {
495 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
496 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
497 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
498};
499static unsigned long stac927x_capsws[] = {
500 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
501 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
502 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
503};
504
455static const char *stac927x_spdif_labels[5] = { 505static const char *stac927x_spdif_labels[5] = {
456 "Digital Playback", "ADAT", "Analog Mux 1", 506 "Digital Playback", "ADAT", "Analog Mux 1",
457 "Analog Mux 2", "Analog Mux 3" 507 "Analog Mux 2", "Analog Mux 3"
@@ -478,6 +528,16 @@ static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
478 0x17, 0x18, 0 528 0x17, 0x18, 0
479}; 529};
480 530
531#define STAC9205_NUM_CAPS 2
532static unsigned long stac9205_capvols[] = {
533 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
534 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
535};
536static unsigned long stac9205_capsws[] = {
537 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
538 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
539};
540
481static hda_nid_t stac9200_pin_nids[8] = { 541static hda_nid_t stac9200_pin_nids[8] = {
482 0x08, 0x09, 0x0d, 0x0e, 542 0x08, 0x09, 0x0d, 0x0e,
483 0x0f, 0x10, 0x11, 0x12, 543 0x0f, 0x10, 0x11, 0x12,
@@ -528,34 +588,6 @@ static hda_nid_t stac9205_pin_nids[12] = {
528 0x21, 0x22, 588 0x21, 0x22,
529}; 589};
530 590
531#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
532
533static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
534 struct snd_ctl_elem_value *ucontrol)
535{
536 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
537 struct sigmatel_spec *spec = codec->spec;
538 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
539
540 kcontrol->private_value ^= get_amp_nid(kcontrol);
541 kcontrol->private_value |= nid;
542
543 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
544}
545
546static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol)
548{
549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
550 struct sigmatel_spec *spec = codec->spec;
551 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
552
553 kcontrol->private_value ^= get_amp_nid(kcontrol);
554 kcontrol->private_value |= nid;
555
556 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
557}
558
559static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol, 591static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
560 struct snd_ctl_elem_info *uinfo) 592 struct snd_ctl_elem_info *uinfo)
561{ 593{
@@ -692,9 +724,35 @@ static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
692 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
693 struct sigmatel_spec *spec = codec->spec; 725 struct sigmatel_spec *spec = codec->spec;
694 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 726 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
695 727 const struct hda_input_mux *imux = spec->input_mux;
696 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 728 unsigned int idx, prev_idx;
697 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]); 729
730 idx = ucontrol->value.enumerated.item[0];
731 if (idx >= imux->num_items)
732 idx = imux->num_items - 1;
733 prev_idx = spec->cur_mux[adc_idx];
734 if (prev_idx == idx)
735 return 0;
736 if (idx < spec->num_analog_muxes) {
737 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
738 AC_VERB_SET_CONNECT_SEL,
739 imux->items[idx].index);
740 if (prev_idx >= spec->num_analog_muxes) {
741 imux = spec->dinput_mux;
742 /* 0 = analog */
743 snd_hda_codec_write_cache(codec,
744 spec->dmux_nids[adc_idx], 0,
745 AC_VERB_SET_CONNECT_SEL,
746 imux->items[0].index);
747 }
748 } else {
749 imux = spec->dinput_mux;
750 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
751 AC_VERB_SET_CONNECT_SEL,
752 imux->items[idx - 1].index);
753 }
754 spec->cur_mux[adc_idx] = idx;
755 return 1;
698} 756}
699 757
700static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol, 758static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
@@ -725,41 +783,6 @@ static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
725 spec->mono_nid, &spec->cur_mmux); 783 spec->mono_nid, &spec->cur_mmux);
726} 784}
727 785
728static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_info *uinfo)
730{
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 struct sigmatel_spec *spec = codec->spec;
733 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
734}
735
736static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
737 struct snd_ctl_elem_value *ucontrol)
738{
739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
740 struct sigmatel_spec *spec = codec->spec;
741
742 ucontrol->value.enumerated.item[0] = spec->cur_amux;
743 return 0;
744}
745
746static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
747 struct snd_ctl_elem_value *ucontrol)
748{
749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
750 struct sigmatel_spec *spec = codec->spec;
751 struct snd_kcontrol *ctl =
752 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
753 if (!ctl)
754 return -EINVAL;
755
756 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
757 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
758
759 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
760 0, &spec->cur_amux);
761}
762
763#define stac92xx_aloopback_info snd_ctl_boolean_mono_info 786#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
764 787
765static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol, 788static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
@@ -827,92 +850,20 @@ static struct hda_verb stac9200_eapd_init[] = {
827 {} 850 {}
828}; 851};
829 852
830static struct hda_verb stac92hd73xx_6ch_core_init[] = {
831 /* set master volume and direct control */
832 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
833 /* setup adcs to point to mixer */
834 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
835 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
836 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
837 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
838 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
839 /* setup import muxs */
840 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
841 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
842 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
843 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
844 {}
845};
846
847static struct hda_verb dell_eq_core_init[] = { 853static struct hda_verb dell_eq_core_init[] = {
848 /* set master volume to max value without distortion 854 /* set master volume to max value without distortion
849 * and direct control */ 855 * and direct control */
850 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec}, 856 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
851 /* setup adcs to point to mixer */
852 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
853 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
854 /* setup import muxs */
855 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
856 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
857 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
858 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
859 {}
860};
861
862static struct hda_verb dell_m6_core_init[] = {
863 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
864 /* setup adcs to point to mixer */
865 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
866 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
867 /* setup import muxs */
868 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
869 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
870 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
871 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
872 {}
873};
874
875static struct hda_verb stac92hd73xx_8ch_core_init[] = {
876 /* set master volume and direct control */
877 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
878 /* setup adcs to point to mixer */
879 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
880 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
881 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
882 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
883 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884 /* setup import muxs */
885 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
886 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
887 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
888 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
889 {} 857 {}
890}; 858};
891 859
892static struct hda_verb stac92hd73xx_10ch_core_init[] = { 860static struct hda_verb stac92hd73xx_core_init[] = {
893 /* set master volume and direct control */ 861 /* set master volume and direct control */
894 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 862 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
895 /* dac3 is connected to import3 mux */
896 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
897 /* setup adcs to point to mixer */
898 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
899 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
900 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
901 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
902 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
903 /* setup import muxs */
904 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
905 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
906 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
907 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
908 {} 863 {}
909}; 864};
910 865
911static struct hda_verb stac92hd83xxx_core_init[] = { 866static struct hda_verb stac92hd83xxx_core_init[] = {
912 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
913 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
914 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
915
916 /* power state controls amps */ 867 /* power state controls amps */
917 { 0x01, AC_VERB_SET_EAPD, 1 << 2}, 868 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
918 {} 869 {}
@@ -924,19 +875,6 @@ static struct hda_verb stac92hd71bxx_core_init[] = {
924 {} 875 {}
925}; 876};
926 877
927#define HD_DISABLE_PORTF 1
928static struct hda_verb stac92hd71bxx_analog_core_init[] = {
929 /* start of config #1 */
930
931 /* connect port 0f to audio mixer */
932 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
933 /* start of config #2 */
934
935 /* set master volume and direct control */
936 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
937 {}
938};
939
940static struct hda_verb stac92hd71bxx_unmute_core_init[] = { 878static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
941 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */ 879 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
942 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 880 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -995,31 +933,6 @@ static struct hda_verb stac9205_core_init[] = {
995 .put = stac92xx_mono_mux_enum_put, \ 933 .put = stac92xx_mono_mux_enum_put, \
996 } 934 }
997 935
998#define STAC_AMP_MUX \
999 { \
1000 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1001 .name = "Amp Selector Capture Switch", \
1002 .count = 1, \
1003 .info = stac92xx_amp_mux_enum_info, \
1004 .get = stac92xx_amp_mux_enum_get, \
1005 .put = stac92xx_amp_mux_enum_put, \
1006 }
1007
1008#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1009 { \
1010 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1011 .name = xname, \
1012 .index = 0, \
1013 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1014 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1015 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1016 .info = stac92xx_amp_volume_info, \
1017 .get = stac92xx_amp_volume_get, \
1018 .put = stac92xx_amp_volume_put, \
1019 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1020 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1021 }
1022
1023#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \ 936#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
1024 { \ 937 { \
1025 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -1050,34 +963,6 @@ static struct snd_kcontrol_new stac9200_mixer[] = {
1050 { } /* end */ 963 { } /* end */
1051}; 964};
1052 965
1053#define DELL_M6_MIXER 6
1054static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1055 /* start of config #1 */
1056 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1057 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1058
1059 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1060 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1061
1062 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1063 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1064
1065 /* start of config #2 */
1066 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1067 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1068
1069 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1070 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1071
1072 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1073 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1074
1075 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1076 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1077
1078 { } /* end */
1079};
1080
1081static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = { 966static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1082 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3), 967 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1083 {} 968 {}
@@ -1093,134 +978,14 @@ static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1093 {} 978 {}
1094}; 979};
1095 980
1096static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1097 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1098 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1099
1100 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1101 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1102
1103 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1104 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1105
1106 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1107 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1108
1109 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1110 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1111
1112 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1113 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1114
1115 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1116 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1117 { } /* end */
1118};
1119
1120static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1121 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1122 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1123
1124 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1125 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1126
1127 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1128 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1129
1130 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1131 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1132
1133 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1134 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1135
1136 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1137 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1138
1139 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1140 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1141 { } /* end */
1142};
1143
1144
1145static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1146 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1147 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1148
1149 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1150 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1151
1152 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1153 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
1154
1155 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1156 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
1157
1158 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1159 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
1160
1161 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1162 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
1163
1164 /*
1165 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1166 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
1167 */
1168 { } /* end */
1169};
1170
1171static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1172 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1173 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1174
1175 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1176 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1177 /* analog pc-beep replaced with digital beep support */
1178 /*
1179 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1180 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
1181 */
1182
1183 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1184 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
1185
1186 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1187 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
1188
1189 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1190 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1191
1192 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1193 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
1194 { } /* end */
1195};
1196 981
1197static struct snd_kcontrol_new stac92hd71bxx_loopback[] = { 982static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1198 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2) 983 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1199}; 984};
1200 985
1201static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
1202 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1203 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1204
1205 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1206 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1207 { } /* end */
1208};
1209
1210static struct snd_kcontrol_new stac925x_mixer[] = { 986static struct snd_kcontrol_new stac925x_mixer[] = {
1211 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT), 987 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1212 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT), 988 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1213 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
1214 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
1215 { } /* end */
1216};
1217
1218static struct snd_kcontrol_new stac9205_mixer[] = {
1219 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1220 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
1221
1222 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1223 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
1224 { } /* end */ 989 { } /* end */
1225}; 990};
1226 991
@@ -1229,29 +994,6 @@ static struct snd_kcontrol_new stac9205_loopback[] = {
1229 {} 994 {}
1230}; 995};
1231 996
1232/* This needs to be generated dynamically based on sequence */
1233static struct snd_kcontrol_new stac922x_mixer[] = {
1234 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1235 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
1236
1237 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1238 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
1239 { } /* end */
1240};
1241
1242
1243static struct snd_kcontrol_new stac927x_mixer[] = {
1244 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1245 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
1246
1247 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1248 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
1249
1250 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1251 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
1252 { } /* end */
1253};
1254
1255static struct snd_kcontrol_new stac927x_loopback[] = { 997static struct snd_kcontrol_new stac927x_loopback[] = {
1256 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1), 998 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1257 {} 999 {}
@@ -1309,16 +1051,19 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1309 int err; 1051 int err;
1310 int i; 1052 int i;
1311 1053
1312 err = snd_hda_add_new_ctls(codec, spec->mixer); 1054 if (spec->mixer) {
1313 if (err < 0) 1055 err = snd_hda_add_new_ctls(codec, spec->mixer);
1314 return err; 1056 if (err < 0)
1057 return err;
1058 }
1315 1059
1316 for (i = 0; i < spec->num_mixers; i++) { 1060 for (i = 0; i < spec->num_mixers; i++) {
1317 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 1061 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1318 if (err < 0) 1062 if (err < 0)
1319 return err; 1063 return err;
1320 } 1064 }
1321 if (spec->num_dmuxes > 0) { 1065 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1066 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1322 stac_dmux_mixer.count = spec->num_dmuxes; 1067 stac_dmux_mixer.count = spec->num_dmuxes;
1323 err = snd_hda_ctl_add(codec, 1068 err = snd_hda_ctl_add(codec,
1324 snd_ctl_new1(&stac_dmux_mixer, codec)); 1069 snd_ctl_new1(&stac_dmux_mixer, codec));
@@ -1590,8 +1335,6 @@ static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1590 /* SigmaTel reference board */ 1335 /* SigmaTel reference board */
1591 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1336 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1592 "DFI LanParty", STAC_REF), 1337 "DFI LanParty", STAC_REF),
1593 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
1594 "SigmaTel",STAC_9205_REF),
1595 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, 1338 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1596 "DFI LanParty", STAC_REF), 1339 "DFI LanParty", STAC_REF),
1597 /* Dell laptops have BIOS problem */ 1340 /* Dell laptops have BIOS problem */
@@ -1767,22 +1510,32 @@ static unsigned int dell_m6_pin_configs[13] = {
1767 0x4f0000f0, 1510 0x4f0000f0,
1768}; 1511};
1769 1512
1513static unsigned int alienware_m17x_pin_configs[13] = {
1514 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1515 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1516 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1517 0x904601b0,
1518};
1519
1770static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = { 1520static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1771 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs, 1521 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1772 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs, 1522 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1773 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs, 1523 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1774 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs, 1524 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1775 [STAC_DELL_EQ] = dell_m6_pin_configs, 1525 [STAC_DELL_EQ] = dell_m6_pin_configs,
1526 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
1776}; 1527};
1777 1528
1778static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = { 1529static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1779 [STAC_92HD73XX_AUTO] = "auto", 1530 [STAC_92HD73XX_AUTO] = "auto",
1780 [STAC_92HD73XX_NO_JD] = "no-jd", 1531 [STAC_92HD73XX_NO_JD] = "no-jd",
1781 [STAC_92HD73XX_REF] = "ref", 1532 [STAC_92HD73XX_REF] = "ref",
1533 [STAC_92HD73XX_INTEL] = "intel",
1782 [STAC_DELL_M6_AMIC] = "dell-m6-amic", 1534 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1783 [STAC_DELL_M6_DMIC] = "dell-m6-dmic", 1535 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1784 [STAC_DELL_M6_BOTH] = "dell-m6", 1536 [STAC_DELL_M6_BOTH] = "dell-m6",
1785 [STAC_DELL_EQ] = "dell-eq", 1537 [STAC_DELL_EQ] = "dell-eq",
1538 [STAC_ALIENWARE_M17X] = "alienware",
1786}; 1539};
1787 1540
1788static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = { 1541static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
@@ -1791,6 +1544,10 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1791 "DFI LanParty", STAC_92HD73XX_REF), 1544 "DFI LanParty", STAC_92HD73XX_REF),
1792 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, 1545 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1793 "DFI LanParty", STAC_92HD73XX_REF), 1546 "DFI LanParty", STAC_92HD73XX_REF),
1547 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1548 "Intel DG45ID", STAC_92HD73XX_INTEL),
1549 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1550 "Intel DG45FC", STAC_92HD73XX_INTEL),
1794 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254, 1551 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1795 "Dell Studio 1535", STAC_DELL_M6_DMIC), 1552 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1796 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255, 1553 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
@@ -1811,6 +1568,14 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1811 "Dell Studio 1537", STAC_DELL_M6_DMIC), 1568 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1812 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0, 1569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1813 "Dell Studio 17", STAC_DELL_M6_DMIC), 1570 "Dell Studio 17", STAC_DELL_M6_DMIC),
1571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1572 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1573 {} /* terminator */
1574};
1575
1576static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1577 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1578 "Alienware M17x", STAC_ALIENWARE_M17X),
1814 {} /* terminator */ 1579 {} /* terminator */
1815}; 1580};
1816 1581
@@ -1821,8 +1586,8 @@ static unsigned int ref92hd83xxx_pin_configs[10] = {
1821}; 1586};
1822 1587
1823static unsigned int dell_s14_pin_configs[10] = { 1588static unsigned int dell_s14_pin_configs[10] = {
1824 0x02214030, 0x02211010, 0x02a19020, 0x01014050, 1589 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1825 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160, 1590 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
1826 0x40f000f0, 0x40f000f0, 1591 0x40f000f0, 0x40f000f0,
1827}; 1592};
1828 1593
@@ -1921,6 +1686,10 @@ static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1921 "HP mini 1000", STAC_HP_M4), 1686 "HP mini 1000", STAC_HP_M4),
1922 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b, 1687 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1923 "HP HDX", STAC_HP_HDX), /* HDX16 */ 1688 "HP HDX", STAC_HP_HDX), /* HDX16 */
1689 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1690 "HP dv6", STAC_HP_DV5),
1691 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1692 "HP", STAC_HP_DV5),
1924 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233, 1693 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1925 "unknown Dell", STAC_DELL_M4_1), 1694 "unknown Dell", STAC_DELL_M4_1),
1926 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234, 1695 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
@@ -2266,7 +2035,7 @@ static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2266 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS), 2035 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2267 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS), 2036 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2268 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS), 2037 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2269 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST), 2038 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2270 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS), 2039 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2271 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS), 2040 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2272 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS), 2041 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
@@ -2344,6 +2113,8 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2344 /* SigmaTel reference board */ 2113 /* SigmaTel reference board */
2345 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2346 "DFI LanParty", STAC_9205_REF), 2115 "DFI LanParty", STAC_9205_REF),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2117 "SigmaTel", STAC_9205_REF),
2347 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, 2118 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2348 "DFI LanParty", STAC_9205_REF), 2119 "DFI LanParty", STAC_9205_REF),
2349 /* Dell */ 2120 /* Dell */
@@ -2378,6 +2149,7 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2378 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228, 2149 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2379 "Dell Vostro 1500", STAC_9205_DELL_M42), 2150 "Dell Vostro 1500", STAC_9205_DELL_M42),
2380 /* Gateway */ 2151 /* Gateway */
2152 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2381 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD), 2153 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2382 {} /* terminator */ 2154 {} /* terminator */
2383}; 2155};
@@ -2633,8 +2405,7 @@ static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2633 return 0; 2405 return 0;
2634} 2406}
2635 2407
2636static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid, 2408static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2637 unsigned char type);
2638 2409
2639static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol, 2410static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2640 struct snd_ctl_elem_value *ucontrol) 2411 struct snd_ctl_elem_value *ucontrol)
@@ -2648,7 +2419,7 @@ static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2648 /* check to be sure that the ports are upto date with 2419 /* check to be sure that the ports are upto date with
2649 * switch changes 2420 * switch changes
2650 */ 2421 */
2651 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT); 2422 stac_issue_unsol_event(codec, nid);
2652 2423
2653 return 1; 2424 return 1;
2654} 2425}
@@ -2781,7 +2552,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
2781 * appropriately according to the pin direction 2552 * appropriately according to the pin direction
2782 */ 2553 */
2783 if (spec->hp_detect) 2554 if (spec->hp_detect)
2784 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT); 2555 stac_issue_unsol_event(codec, nid);
2785 2556
2786 return 1; 2557 return 1;
2787} 2558}
@@ -2850,8 +2621,6 @@ enum {
2850 STAC_CTL_WIDGET_VOL, 2621 STAC_CTL_WIDGET_VOL,
2851 STAC_CTL_WIDGET_MUTE, 2622 STAC_CTL_WIDGET_MUTE,
2852 STAC_CTL_WIDGET_MONO_MUX, 2623 STAC_CTL_WIDGET_MONO_MUX,
2853 STAC_CTL_WIDGET_AMP_MUX,
2854 STAC_CTL_WIDGET_AMP_VOL,
2855 STAC_CTL_WIDGET_HP_SWITCH, 2624 STAC_CTL_WIDGET_HP_SWITCH,
2856 STAC_CTL_WIDGET_IO_SWITCH, 2625 STAC_CTL_WIDGET_IO_SWITCH,
2857 STAC_CTL_WIDGET_CLFE_SWITCH, 2626 STAC_CTL_WIDGET_CLFE_SWITCH,
@@ -2862,8 +2631,6 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2862 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2631 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2863 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2632 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2864 STAC_MONO_MUX, 2633 STAC_MONO_MUX,
2865 STAC_AMP_MUX,
2866 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2867 STAC_CODEC_HP_SWITCH(NULL), 2634 STAC_CODEC_HP_SWITCH(NULL),
2868 STAC_CODEC_IO_SWITCH(NULL, 0), 2635 STAC_CODEC_IO_SWITCH(NULL, 0),
2869 STAC_CODEC_CLFE_SWITCH(NULL, 0), 2636 STAC_CODEC_CLFE_SWITCH(NULL, 0),
@@ -2964,6 +2731,8 @@ static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2964 struct snd_kcontrol_new *knew; 2731 struct snd_kcontrol_new *knew;
2965 struct hda_input_mux *imux = &spec->private_imux; 2732 struct hda_input_mux *imux = &spec->private_imux;
2966 2733
2734 if (spec->auto_mic)
2735 return 0; /* no need for input source */
2967 if (!spec->num_adcs || imux->num_items <= 1) 2736 if (!spec->num_adcs || imux->num_items <= 1)
2968 return 0; /* no need for input source control */ 2737 return 0; /* no need for input source control */
2969 knew = stac_control_new(spec, &stac_input_src_temp, 2738 knew = stac_control_new(spec, &stac_input_src_temp,
@@ -3057,7 +2826,7 @@ static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3057 HDA_MAX_CONNECTIONS); 2826 HDA_MAX_CONNECTIONS);
3058 for (j = 0; j < conn_len; j++) { 2827 for (j = 0; j < conn_len; j++) {
3059 wcaps = get_wcaps(codec, conn[j]); 2828 wcaps = get_wcaps(codec, conn[j]);
3060 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 2829 wtype = get_wcaps_type(wcaps);
3061 /* we check only analog outputs */ 2830 /* we check only analog outputs */
3062 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL)) 2831 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3063 continue; 2832 continue;
@@ -3316,6 +3085,21 @@ static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3316 return 0; 3085 return 0;
3317} 3086}
3318 3087
3088static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3089 unsigned long sw, int idx)
3090{
3091 int err;
3092 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3093 "Capture Volume", vol);
3094 if (err < 0)
3095 return err;
3096 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3097 "Capture Switch", sw);
3098 if (err < 0)
3099 return err;
3100 return 0;
3101}
3102
3319/* add playback controls from the parsed DAC table */ 3103/* add playback controls from the parsed DAC table */
3320static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec, 3104static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3321 const struct auto_pin_cfg *cfg) 3105 const struct auto_pin_cfg *cfg)
@@ -3389,7 +3173,7 @@ static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3389 spec->mono_nid, 3173 spec->mono_nid,
3390 con_lst, 3174 con_lst,
3391 HDA_MAX_NUM_INPUTS); 3175 HDA_MAX_NUM_INPUTS);
3392 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels)) 3176 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3393 return -EINVAL; 3177 return -EINVAL;
3394 3178
3395 for (i = 0; i < num_cons; i++) { 3179 for (i = 0; i < num_cons; i++) {
@@ -3403,37 +3187,6 @@ static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3403 "Mono Mux", spec->mono_nid); 3187 "Mono Mux", spec->mono_nid);
3404} 3188}
3405 3189
3406/* labels for amp mux outputs */
3407static const char *stac92xx_amp_labels[3] = {
3408 "Front Microphone", "Microphone", "Line In",
3409};
3410
3411/* create amp out controls mux on capable codecs */
3412static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3413{
3414 struct sigmatel_spec *spec = codec->spec;
3415 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3416 int i, err;
3417
3418 for (i = 0; i < spec->num_amps; i++) {
3419 amp_mux->items[amp_mux->num_items].label =
3420 stac92xx_amp_labels[i];
3421 amp_mux->items[amp_mux->num_items].index = i;
3422 amp_mux->num_items++;
3423 }
3424
3425 if (spec->num_amps > 1) {
3426 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3427 "Amp Selector Capture Switch", 0);
3428 if (err < 0)
3429 return err;
3430 }
3431 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3432 "Amp Capture Volume",
3433 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3434}
3435
3436
3437/* create PC beep volume controls */ 3190/* create PC beep volume controls */
3438static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec, 3191static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3439 hda_nid_t nid) 3192 hda_nid_t nid)
@@ -3502,19 +3255,33 @@ static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3502static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec) 3255static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3503{ 3256{
3504 struct sigmatel_spec *spec = codec->spec; 3257 struct sigmatel_spec *spec = codec->spec;
3505 int wcaps, nid, i, err = 0; 3258 int i, j, err = 0;
3506 3259
3507 for (i = 0; i < spec->num_muxes; i++) { 3260 for (i = 0; i < spec->num_muxes; i++) {
3261 hda_nid_t nid;
3262 unsigned int wcaps;
3263 unsigned long val;
3264
3508 nid = spec->mux_nids[i]; 3265 nid = spec->mux_nids[i];
3509 wcaps = get_wcaps(codec, nid); 3266 wcaps = get_wcaps(codec, nid);
3267 if (!(wcaps & AC_WCAP_OUT_AMP))
3268 continue;
3510 3269
3511 if (wcaps & AC_WCAP_OUT_AMP) { 3270 /* check whether already the same control was created as
3512 err = stac92xx_add_control_idx(spec, 3271 * normal Capture Volume.
3513 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume", 3272 */
3514 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT)); 3273 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3515 if (err < 0) 3274 for (j = 0; j < spec->num_caps; j++) {
3516 return err; 3275 if (spec->capvols[j] == val)
3276 break;
3517 } 3277 }
3278 if (j < spec->num_caps)
3279 continue;
3280
3281 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3282 "Mux Capture Volume", val);
3283 if (err < 0)
3284 return err;
3518 } 3285 }
3519 return 0; 3286 return 0;
3520}; 3287};
@@ -3535,7 +3302,7 @@ static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3535 spec->smux_nids[0], 3302 spec->smux_nids[0],
3536 con_lst, 3303 con_lst,
3537 HDA_MAX_NUM_INPUTS); 3304 HDA_MAX_NUM_INPUTS);
3538 if (!num_cons) 3305 if (num_cons <= 0)
3539 return -EINVAL; 3306 return -EINVAL;
3540 3307
3541 if (!labels) 3308 if (!labels)
@@ -3556,101 +3323,231 @@ static const char *stac92xx_dmic_labels[5] = {
3556 "Digital Mic 3", "Digital Mic 4" 3323 "Digital Mic 3", "Digital Mic 4"
3557}; 3324};
3558 3325
3326static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3327 hda_nid_t nid)
3328{
3329 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3330 int i, nums;
3331
3332 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3333 for (i = 0; i < nums; i++)
3334 if (conn[i] == nid)
3335 return i;
3336 return -1;
3337}
3338
3339/* create a volume assigned to the given pin (only if supported) */
3340/* return 1 if the volume control is created */
3341static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3342 const char *label, int direction)
3343{
3344 unsigned int caps, nums;
3345 char name[32];
3346 int err;
3347
3348 if (direction == HDA_OUTPUT)
3349 caps = AC_WCAP_OUT_AMP;
3350 else
3351 caps = AC_WCAP_IN_AMP;
3352 if (!(get_wcaps(codec, nid) & caps))
3353 return 0;
3354 caps = query_amp_caps(codec, nid, direction);
3355 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3356 if (!nums)
3357 return 0;
3358 snprintf(name, sizeof(name), "%s Capture Volume", label);
3359 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3360 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3361 if (err < 0)
3362 return err;
3363 return 1;
3364}
3365
3559/* create playback/capture controls for input pins on dmic capable codecs */ 3366/* create playback/capture controls for input pins on dmic capable codecs */
3560static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec, 3367static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3561 const struct auto_pin_cfg *cfg) 3368 const struct auto_pin_cfg *cfg)
3562{ 3369{
3563 struct sigmatel_spec *spec = codec->spec; 3370 struct sigmatel_spec *spec = codec->spec;
3371 struct hda_input_mux *imux = &spec->private_imux;
3564 struct hda_input_mux *dimux = &spec->private_dimux; 3372 struct hda_input_mux *dimux = &spec->private_dimux;
3565 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS]; 3373 int err, i, active_mics;
3566 int err, i, j; 3374 unsigned int def_conf;
3567 char name[32];
3568 3375
3569 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0]; 3376 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3570 dimux->items[dimux->num_items].index = 0; 3377 dimux->items[dimux->num_items].index = 0;
3571 dimux->num_items++; 3378 dimux->num_items++;
3572 3379
3380 active_mics = 0;
3381 for (i = 0; i < spec->num_dmics; i++) {
3382 /* check the validity: sometimes it's a dead vendor-spec node */
3383 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3384 != AC_WID_PIN)
3385 continue;
3386 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3387 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3388 active_mics++;
3389 }
3390
3573 for (i = 0; i < spec->num_dmics; i++) { 3391 for (i = 0; i < spec->num_dmics; i++) {
3574 hda_nid_t nid; 3392 hda_nid_t nid;
3575 int index; 3393 int index;
3576 int num_cons; 3394 const char *label;
3577 unsigned int wcaps;
3578 unsigned int def_conf;
3579 3395
3580 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]); 3396 nid = spec->dmic_nids[i];
3397 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3398 continue;
3399 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3581 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) 3400 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3582 continue; 3401 continue;
3583 3402
3584 nid = spec->dmic_nids[i]; 3403 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3585 num_cons = snd_hda_get_connections(codec, 3404 if (index < 0)
3586 spec->dmux_nids[0], 3405 continue;
3587 con_lst,
3588 HDA_MAX_NUM_INPUTS);
3589 for (j = 0; j < num_cons; j++)
3590 if (con_lst[j] == nid) {
3591 index = j;
3592 goto found;
3593 }
3594 continue;
3595found:
3596 wcaps = get_wcaps(codec, nid) &
3597 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3598 3406
3599 if (wcaps) { 3407 if (active_mics == 1)
3600 sprintf(name, "%s Capture Volume", 3408 label = "Digital Mic";
3601 stac92xx_dmic_labels[dimux->num_items]); 3409 else
3410 label = stac92xx_dmic_labels[dimux->num_items];
3602 3411
3603 err = stac92xx_add_control(spec, 3412 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
3604 STAC_CTL_WIDGET_VOL, 3413 if (err < 0)
3605 name, 3414 return err;
3606 HDA_COMPOSE_AMP_VAL(nid, 3, 0, 3415 if (!err) {
3607 (wcaps & AC_WCAP_OUT_AMP) ? 3416 err = create_elem_capture_vol(codec, nid, label,
3608 HDA_OUTPUT : HDA_INPUT)); 3417 HDA_OUTPUT);
3609 if (err < 0) 3418 if (err < 0)
3610 return err; 3419 return err;
3611 } 3420 }
3612 3421
3613 dimux->items[dimux->num_items].label = 3422 dimux->items[dimux->num_items].label = label;
3614 stac92xx_dmic_labels[dimux->num_items];
3615 dimux->items[dimux->num_items].index = index; 3423 dimux->items[dimux->num_items].index = index;
3616 dimux->num_items++; 3424 dimux->num_items++;
3425 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3426 imux->items[imux->num_items].label = label;
3427 imux->items[imux->num_items].index = index;
3428 imux->num_items++;
3429 }
3617 } 3430 }
3618 3431
3619 return 0; 3432 return 0;
3620} 3433}
3621 3434
3435static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3436 hda_nid_t *fixed, hda_nid_t *ext)
3437{
3438 unsigned int cfg;
3439
3440 if (!nid)
3441 return 0;
3442 cfg = snd_hda_codec_get_pincfg(codec, nid);
3443 switch (get_defcfg_connect(cfg)) {
3444 case AC_JACK_PORT_FIXED:
3445 if (*fixed)
3446 return 1; /* already occupied */
3447 *fixed = nid;
3448 break;
3449 case AC_JACK_PORT_COMPLEX:
3450 if (*ext)
3451 return 1; /* already occupied */
3452 *ext = nid;
3453 break;
3454 }
3455 return 0;
3456}
3457
3458static int set_mic_route(struct hda_codec *codec,
3459 struct sigmatel_mic_route *mic,
3460 hda_nid_t pin)
3461{
3462 struct sigmatel_spec *spec = codec->spec;
3463 struct auto_pin_cfg *cfg = &spec->autocfg;
3464 int i;
3465
3466 mic->pin = pin;
3467 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3468 if (pin == cfg->input_pins[i])
3469 break;
3470 if (i <= AUTO_PIN_FRONT_MIC) {
3471 /* analog pin */
3472 mic->dmux_idx = 0;
3473 i = get_connection_index(codec, spec->mux_nids[0], pin);
3474 if (i < 0)
3475 return -1;
3476 mic->mux_idx = i;
3477 } else if (spec->dmux_nids) {
3478 /* digital pin */
3479 mic->mux_idx = 0;
3480 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3481 if (i < 0)
3482 return -1;
3483 mic->dmux_idx = i;
3484 }
3485 return 0;
3486}
3487
3488/* return non-zero if the device is for automatic mic switch */
3489static int stac_check_auto_mic(struct hda_codec *codec)
3490{
3491 struct sigmatel_spec *spec = codec->spec;
3492 struct auto_pin_cfg *cfg = &spec->autocfg;
3493 hda_nid_t fixed, ext;
3494 int i;
3495
3496 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3497 if (cfg->input_pins[i])
3498 return 0; /* must be exclusively mics */
3499 }
3500 fixed = ext = 0;
3501 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3502 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3503 return 0;
3504 for (i = 0; i < spec->num_dmics; i++)
3505 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3506 return 0;
3507 if (!fixed || !ext)
3508 return 0;
3509 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3510 return 0; /* no unsol support */
3511 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3512 set_mic_route(codec, &spec->int_mic, fixed))
3513 return 0; /* something is wrong */
3514 return 1;
3515}
3516
3622/* create playback/capture controls for input pins */ 3517/* create playback/capture controls for input pins */
3623static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) 3518static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3624{ 3519{
3625 struct sigmatel_spec *spec = codec->spec; 3520 struct sigmatel_spec *spec = codec->spec;
3626 struct hda_input_mux *imux = &spec->private_imux; 3521 struct hda_input_mux *imux = &spec->private_imux;
3627 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS]; 3522 int i, j;
3628 int i, j, k;
3629 3523
3630 for (i = 0; i < AUTO_PIN_LAST; i++) { 3524 for (i = 0; i < AUTO_PIN_LAST; i++) {
3631 int index; 3525 hda_nid_t nid = cfg->input_pins[i];
3526 int index, err;
3632 3527
3633 if (!cfg->input_pins[i]) 3528 if (!nid)
3634 continue; 3529 continue;
3635 index = -1; 3530 index = -1;
3636 for (j = 0; j < spec->num_muxes; j++) { 3531 for (j = 0; j < spec->num_muxes; j++) {
3637 int num_cons; 3532 index = get_connection_index(codec, spec->mux_nids[j],
3638 num_cons = snd_hda_get_connections(codec, 3533 nid);
3639 spec->mux_nids[j], 3534 if (index >= 0)
3640 con_lst, 3535 break;
3641 HDA_MAX_NUM_INPUTS);
3642 for (k = 0; k < num_cons; k++)
3643 if (con_lst[k] == cfg->input_pins[i]) {
3644 index = k;
3645 goto found;
3646 }
3647 } 3536 }
3648 continue; 3537 if (index < 0)
3649 found: 3538 continue;
3539
3540 err = create_elem_capture_vol(codec, nid,
3541 auto_pin_cfg_labels[i],
3542 HDA_INPUT);
3543 if (err < 0)
3544 return err;
3545
3650 imux->items[imux->num_items].label = auto_pin_cfg_labels[i]; 3546 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3651 imux->items[imux->num_items].index = index; 3547 imux->items[imux->num_items].index = index;
3652 imux->num_items++; 3548 imux->num_items++;
3653 } 3549 }
3550 spec->num_analog_muxes = imux->num_items;
3654 3551
3655 if (imux->num_items) { 3552 if (imux->num_items) {
3656 /* 3553 /*
@@ -3702,7 +3599,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3702{ 3599{
3703 struct sigmatel_spec *spec = codec->spec; 3600 struct sigmatel_spec *spec = codec->spec;
3704 int hp_swap = 0; 3601 int hp_swap = 0;
3705 int err; 3602 int i, err;
3706 3603
3707 if ((err = snd_hda_parse_pin_def_config(codec, 3604 if ((err = snd_hda_parse_pin_def_config(codec,
3708 &spec->autocfg, 3605 &spec->autocfg,
@@ -3742,11 +3639,10 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3742 if (snd_hda_get_connections(codec, 3639 if (snd_hda_get_connections(codec,
3743 spec->autocfg.mono_out_pin, conn_list, 1) && 3640 spec->autocfg.mono_out_pin, conn_list, 1) &&
3744 snd_hda_get_connections(codec, conn_list[0], 3641 snd_hda_get_connections(codec, conn_list[0],
3745 conn_list, 1)) { 3642 conn_list, 1) > 0) {
3746 3643
3747 int wcaps = get_wcaps(codec, conn_list[0]); 3644 int wcaps = get_wcaps(codec, conn_list[0]);
3748 int wid_type = (wcaps & AC_WCAP_TYPE) 3645 int wid_type = get_wcaps_type(wcaps);
3749 >> AC_WCAP_TYPE_SHIFT;
3750 /* LR swap check, some stac925x have a mux that 3646 /* LR swap check, some stac925x have a mux that
3751 * changes the DACs output path instead of the 3647 * changes the DACs output path instead of the
3752 * mono-mux path. 3648 * mono-mux path.
@@ -3837,6 +3733,21 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3837 spec->autocfg.line_outs = 0; 3733 spec->autocfg.line_outs = 0;
3838 } 3734 }
3839 3735
3736 if (stac_check_auto_mic(codec)) {
3737 spec->auto_mic = 1;
3738 /* only one capture for auto-mic */
3739 spec->num_adcs = 1;
3740 spec->num_caps = 1;
3741 spec->num_muxes = 1;
3742 }
3743
3744 for (i = 0; i < spec->num_caps; i++) {
3745 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3746 spec->capsws[i], i);
3747 if (err < 0)
3748 return err;
3749 }
3750
3840 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg); 3751 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3841 if (err < 0) 3752 if (err < 0)
3842 return err; 3753 return err;
@@ -3846,11 +3757,6 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3846 if (err < 0) 3757 if (err < 0)
3847 return err; 3758 return err;
3848 } 3759 }
3849 if (spec->num_amps > 0) {
3850 err = stac92xx_auto_create_amp_output_ctls(codec);
3851 if (err < 0)
3852 return err;
3853 }
3854 if (spec->num_dmics > 0 && !spec->dinput_mux) 3760 if (spec->num_dmics > 0 && !spec->dinput_mux)
3855 if ((err = stac92xx_auto_create_dmic_input_ctls(codec, 3761 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3856 &spec->autocfg)) < 0) 3762 &spec->autocfg)) < 0)
@@ -3887,7 +3793,6 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3887 spec->dinput_mux = &spec->private_dimux; 3793 spec->dinput_mux = &spec->private_dimux;
3888 spec->sinput_mux = &spec->private_smux; 3794 spec->sinput_mux = &spec->private_smux;
3889 spec->mono_mux = &spec->private_mono_mux; 3795 spec->mono_mux = &spec->private_mono_mux;
3890 spec->amp_mux = &spec->private_amp_mux;
3891 return 1; 3796 return 1;
3892} 3797}
3893 3798
@@ -4065,7 +3970,7 @@ static int stac92xx_add_jack(struct hda_codec *codec,
4065 jack->nid = nid; 3970 jack->nid = nid;
4066 jack->type = type; 3971 jack->type = type;
4067 3972
4068 sprintf(name, "%s at %s %s Jack", 3973 snprintf(name, sizeof(name), "%s at %s %s Jack",
4069 snd_hda_get_jack_type(def_conf), 3974 snd_hda_get_jack_type(def_conf),
4070 snd_hda_get_jack_connectivity(def_conf), 3975 snd_hda_get_jack_connectivity(def_conf),
4071 snd_hda_get_jack_location(def_conf)); 3976 snd_hda_get_jack_location(def_conf));
@@ -4099,14 +4004,14 @@ static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4099} 4004}
4100 4005
4101static struct sigmatel_event *stac_get_event(struct hda_codec *codec, 4006static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4102 hda_nid_t nid, unsigned char type) 4007 hda_nid_t nid)
4103{ 4008{
4104 struct sigmatel_spec *spec = codec->spec; 4009 struct sigmatel_spec *spec = codec->spec;
4105 struct sigmatel_event *event = spec->events.list; 4010 struct sigmatel_event *event = spec->events.list;
4106 int i; 4011 int i;
4107 4012
4108 for (i = 0; i < spec->events.used; i++, event++) { 4013 for (i = 0; i < spec->events.used; i++, event++) {
4109 if (event->nid == nid && event->type == type) 4014 if (event->nid == nid)
4110 return event; 4015 return event;
4111 } 4016 }
4112 return NULL; 4017 return NULL;
@@ -4126,24 +4031,32 @@ static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4126 return NULL; 4031 return NULL;
4127} 4032}
4128 4033
4129static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid, 4034/* check if given nid is a valid pin and no other events are assigned
4130 unsigned int type) 4035 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4036 * Otherwise, returns zero.
4037 */
4038static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4039 unsigned int type)
4131{ 4040{
4132 struct sigmatel_event *event; 4041 struct sigmatel_event *event;
4133 int tag; 4042 int tag;
4134 4043
4135 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)) 4044 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4136 return; 4045 return 0;
4137 event = stac_get_event(codec, nid, type); 4046 event = stac_get_event(codec, nid);
4138 if (event) 4047 if (event) {
4048 if (event->type != type)
4049 return 0;
4139 tag = event->tag; 4050 tag = event->tag;
4140 else 4051 } else {
4141 tag = stac_add_event(codec->spec, nid, type, 0); 4052 tag = stac_add_event(codec->spec, nid, type, 0);
4142 if (tag < 0) 4053 if (tag < 0)
4143 return; 4054 return 0;
4055 }
4144 snd_hda_codec_write_cache(codec, nid, 0, 4056 snd_hda_codec_write_cache(codec, nid, 0,
4145 AC_VERB_SET_UNSOLICITED_ENABLE, 4057 AC_VERB_SET_UNSOLICITED_ENABLE,
4146 AC_USRSP_EN | tag); 4058 AC_USRSP_EN | tag);
4059 return 1;
4147} 4060}
4148 4061
4149static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid) 4062static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
@@ -4236,20 +4149,39 @@ static int stac92xx_init(struct hda_codec *codec)
4236 hda_nid_t nid = cfg->hp_pins[i]; 4149 hda_nid_t nid = cfg->hp_pins[i];
4237 enable_pin_detect(codec, nid, STAC_HP_EVENT); 4150 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4238 } 4151 }
4152 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4153 cfg->speaker_outs > 0) {
4154 /* enable pin-detect for line-outs as well */
4155 for (i = 0; i < cfg->line_outs; i++) {
4156 hda_nid_t nid = cfg->line_out_pins[i];
4157 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4158 }
4159 }
4160
4239 /* force to enable the first line-out; the others are set up 4161 /* force to enable the first line-out; the others are set up
4240 * in unsol_event 4162 * in unsol_event
4241 */ 4163 */
4242 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0], 4164 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4243 AC_PINCTL_OUT_EN); 4165 AC_PINCTL_OUT_EN);
4244 /* fake event to set up pins */ 4166 /* fake event to set up pins */
4245 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0], 4167 if (cfg->hp_pins[0])
4246 STAC_HP_EVENT); 4168 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4169 else if (cfg->line_out_pins[0])
4170 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4247 } else { 4171 } else {
4248 stac92xx_auto_init_multi_out(codec); 4172 stac92xx_auto_init_multi_out(codec);
4249 stac92xx_auto_init_hp_out(codec); 4173 stac92xx_auto_init_hp_out(codec);
4250 for (i = 0; i < cfg->hp_outs; i++) 4174 for (i = 0; i < cfg->hp_outs; i++)
4251 stac_toggle_power_map(codec, cfg->hp_pins[i], 1); 4175 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4252 } 4176 }
4177 if (spec->auto_mic) {
4178 /* initialize connection to analog input */
4179 if (spec->dmux_nids)
4180 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4181 AC_VERB_SET_CONNECT_SEL, 0);
4182 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4183 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4184 }
4253 for (i = 0; i < AUTO_PIN_LAST; i++) { 4185 for (i = 0; i < AUTO_PIN_LAST; i++) {
4254 hda_nid_t nid = cfg->input_pins[i]; 4186 hda_nid_t nid = cfg->input_pins[i];
4255 if (nid) { 4187 if (nid) {
@@ -4276,10 +4208,9 @@ static int stac92xx_init(struct hda_codec *codec)
4276 } 4208 }
4277 conf = snd_hda_codec_get_pincfg(codec, nid); 4209 conf = snd_hda_codec_get_pincfg(codec, nid);
4278 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) { 4210 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4279 enable_pin_detect(codec, nid, 4211 if (enable_pin_detect(codec, nid,
4280 STAC_INSERT_EVENT); 4212 STAC_INSERT_EVENT))
4281 stac_issue_unsol_event(codec, nid, 4213 stac_issue_unsol_event(codec, nid);
4282 STAC_INSERT_EVENT);
4283 } 4214 }
4284 } 4215 }
4285 } 4216 }
@@ -4324,10 +4255,8 @@ static int stac92xx_init(struct hda_codec *codec)
4324 stac_toggle_power_map(codec, nid, 1); 4255 stac_toggle_power_map(codec, nid, 1);
4325 continue; 4256 continue;
4326 } 4257 }
4327 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) { 4258 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4328 enable_pin_detect(codec, nid, STAC_PWR_EVENT); 4259 stac_issue_unsol_event(codec, nid);
4329 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
4330 }
4331 } 4260 }
4332 if (spec->dac_list) 4261 if (spec->dac_list)
4333 stac92xx_power_down(codec); 4262 stac92xx_power_down(codec);
@@ -4431,6 +4360,48 @@ static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4431 return 0; 4360 return 0;
4432} 4361}
4433 4362
4363static void stac92xx_line_out_detect(struct hda_codec *codec,
4364 int presence)
4365{
4366 struct sigmatel_spec *spec = codec->spec;
4367 struct auto_pin_cfg *cfg = &spec->autocfg;
4368 int i;
4369
4370 for (i = 0; i < cfg->line_outs; i++) {
4371 if (presence)
4372 break;
4373 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4374 if (presence) {
4375 unsigned int pinctl;
4376 pinctl = snd_hda_codec_read(codec,
4377 cfg->line_out_pins[i], 0,
4378 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4379 if (pinctl & AC_PINCTL_IN_EN)
4380 presence = 0; /* mic- or line-input */
4381 }
4382 }
4383
4384 if (presence) {
4385 /* disable speakers */
4386 for (i = 0; i < cfg->speaker_outs; i++)
4387 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4388 AC_PINCTL_OUT_EN);
4389 if (spec->eapd_mask && spec->eapd_switch)
4390 stac_gpio_set(codec, spec->gpio_mask,
4391 spec->gpio_dir, spec->gpio_data &
4392 ~spec->eapd_mask);
4393 } else {
4394 /* enable speakers */
4395 for (i = 0; i < cfg->speaker_outs; i++)
4396 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4397 AC_PINCTL_OUT_EN);
4398 if (spec->eapd_mask && spec->eapd_switch)
4399 stac_gpio_set(codec, spec->gpio_mask,
4400 spec->gpio_dir, spec->gpio_data |
4401 spec->eapd_mask);
4402 }
4403}
4404
4434/* return non-zero if the hp-pin of the given array index isn't 4405/* return non-zero if the hp-pin of the given array index isn't
4435 * a jack-detection target 4406 * a jack-detection target
4436 */ 4407 */
@@ -4483,13 +4454,6 @@ static void stac92xx_hp_detect(struct hda_codec *codec)
4483 for (i = 0; i < cfg->line_outs; i++) 4454 for (i = 0; i < cfg->line_outs; i++)
4484 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i], 4455 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4485 AC_PINCTL_OUT_EN); 4456 AC_PINCTL_OUT_EN);
4486 for (i = 0; i < cfg->speaker_outs; i++)
4487 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4488 AC_PINCTL_OUT_EN);
4489 if (spec->eapd_mask && spec->eapd_switch)
4490 stac_gpio_set(codec, spec->gpio_mask,
4491 spec->gpio_dir, spec->gpio_data &
4492 ~spec->eapd_mask);
4493 } else { 4457 } else {
4494 /* enable lineouts */ 4458 /* enable lineouts */
4495 if (spec->hp_switch) 4459 if (spec->hp_switch)
@@ -4498,14 +4462,8 @@ static void stac92xx_hp_detect(struct hda_codec *codec)
4498 for (i = 0; i < cfg->line_outs; i++) 4462 for (i = 0; i < cfg->line_outs; i++)
4499 stac92xx_set_pinctl(codec, cfg->line_out_pins[i], 4463 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4500 AC_PINCTL_OUT_EN); 4464 AC_PINCTL_OUT_EN);
4501 for (i = 0; i < cfg->speaker_outs; i++)
4502 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4503 AC_PINCTL_OUT_EN);
4504 if (spec->eapd_mask && spec->eapd_switch)
4505 stac_gpio_set(codec, spec->gpio_mask,
4506 spec->gpio_dir, spec->gpio_data |
4507 spec->eapd_mask);
4508 } 4465 }
4466 stac92xx_line_out_detect(codec, presence);
4509 /* toggle hp outs */ 4467 /* toggle hp outs */
4510 for (i = 0; i < cfg->hp_outs; i++) { 4468 for (i = 0; i < cfg->hp_outs; i++) {
4511 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN; 4469 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
@@ -4590,10 +4548,28 @@ static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4590 } 4548 }
4591} 4549}
4592 4550
4593static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid, 4551static void stac92xx_mic_detect(struct hda_codec *codec)
4594 unsigned char type) 4552{
4553 struct sigmatel_spec *spec = codec->spec;
4554 struct sigmatel_mic_route *mic;
4555
4556 if (get_pin_presence(codec, spec->ext_mic.pin))
4557 mic = &spec->ext_mic;
4558 else
4559 mic = &spec->int_mic;
4560 if (mic->dmux_idx)
4561 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4562 AC_VERB_SET_CONNECT_SEL,
4563 mic->dmux_idx);
4564 else
4565 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4566 AC_VERB_SET_CONNECT_SEL,
4567 mic->mux_idx);
4568}
4569
4570static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4595{ 4571{
4596 struct sigmatel_event *event = stac_get_event(codec, nid, type); 4572 struct sigmatel_event *event = stac_get_event(codec, nid);
4597 if (!event) 4573 if (!event)
4598 return; 4574 return;
4599 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26); 4575 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
@@ -4612,8 +4588,18 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4612 4588
4613 switch (event->type) { 4589 switch (event->type) {
4614 case STAC_HP_EVENT: 4590 case STAC_HP_EVENT:
4591 case STAC_LO_EVENT:
4615 stac92xx_hp_detect(codec); 4592 stac92xx_hp_detect(codec);
4616 /* fallthru */ 4593 break;
4594 case STAC_MIC_EVENT:
4595 stac92xx_mic_detect(codec);
4596 break;
4597 }
4598
4599 switch (event->type) {
4600 case STAC_HP_EVENT:
4601 case STAC_LO_EVENT:
4602 case STAC_MIC_EVENT:
4617 case STAC_INSERT_EVENT: 4603 case STAC_INSERT_EVENT:
4618 case STAC_PWR_EVENT: 4604 case STAC_PWR_EVENT:
4619 if (spec->num_pwrs > 0) 4605 if (spec->num_pwrs > 0)
@@ -4703,9 +4689,13 @@ static int stac92xx_resume(struct hda_codec *codec)
4703 snd_hda_codec_resume_amp(codec); 4689 snd_hda_codec_resume_amp(codec);
4704 snd_hda_codec_resume_cache(codec); 4690 snd_hda_codec_resume_cache(codec);
4705 /* fake event to set up pins again to override cached values */ 4691 /* fake event to set up pins again to override cached values */
4706 if (spec->hp_detect) 4692 if (spec->hp_detect) {
4707 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0], 4693 if (spec->autocfg.hp_pins[0])
4708 STAC_HP_EVENT); 4694 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4695 else if (spec->autocfg.line_out_pins[0])
4696 stac_issue_unsol_event(codec,
4697 spec->autocfg.line_out_pins[0]);
4698 }
4709 return 0; 4699 return 0;
4710} 4700}
4711 4701
@@ -4745,6 +4735,19 @@ static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4745static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state) 4735static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4746{ 4736{
4747 struct sigmatel_spec *spec = codec->spec; 4737 struct sigmatel_spec *spec = codec->spec;
4738 int i;
4739 hda_nid_t nid;
4740
4741 /* reset each pin before powering down DAC/ADC to avoid click noise */
4742 nid = codec->start_nid;
4743 for (i = 0; i < codec->num_nodes; i++, nid++) {
4744 unsigned int wcaps = get_wcaps(codec, nid);
4745 unsigned int wid_type = get_wcaps_type(wcaps);
4746 if (wid_type == AC_WID_PIN)
4747 snd_hda_codec_read(codec, nid, 0,
4748 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4749 }
4750
4748 if (spec->eapd_mask) 4751 if (spec->eapd_mask)
4749 stac_gpio_set(codec, spec->gpio_mask, 4752 stac_gpio_set(codec, spec->gpio_mask,
4750 spec->gpio_dir, spec->gpio_data & 4753 spec->gpio_dir, spec->gpio_data &
@@ -4781,7 +4784,8 @@ static int patch_stac9200(struct hda_codec *codec)
4781 stac9200_models, 4784 stac9200_models,
4782 stac9200_cfg_tbl); 4785 stac9200_cfg_tbl);
4783 if (spec->board_config < 0) 4786 if (spec->board_config < 0)
4784 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n"); 4787 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4788 codec->chip_name);
4785 else 4789 else
4786 stac92xx_set_config_regs(codec, 4790 stac92xx_set_config_regs(codec,
4787 stac9200_brd_tbl[spec->board_config]); 4791 stac9200_brd_tbl[spec->board_config]);
@@ -4853,8 +4857,8 @@ static int patch_stac925x(struct hda_codec *codec)
4853 stac925x_cfg_tbl); 4857 stac925x_cfg_tbl);
4854 again: 4858 again:
4855 if (spec->board_config < 0) 4859 if (spec->board_config < 0)
4856 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x," 4860 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4857 "using BIOS defaults\n"); 4861 codec->chip_name);
4858 else 4862 else
4859 stac92xx_set_config_regs(codec, 4863 stac92xx_set_config_regs(codec,
4860 stac925x_brd_tbl[spec->board_config]); 4864 stac925x_brd_tbl[spec->board_config]);
@@ -4884,6 +4888,9 @@ static int patch_stac925x(struct hda_codec *codec)
4884 4888
4885 spec->init = stac925x_core_init; 4889 spec->init = stac925x_core_init;
4886 spec->mixer = stac925x_mixer; 4890 spec->mixer = stac925x_mixer;
4891 spec->num_caps = 1;
4892 spec->capvols = stac925x_capvols;
4893 spec->capsws = stac925x_capsws;
4887 4894
4888 err = stac92xx_parse_auto_config(codec, 0x8, 0x7); 4895 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
4889 if (!err) { 4896 if (!err) {
@@ -4905,16 +4912,6 @@ static int patch_stac925x(struct hda_codec *codec)
4905 return 0; 4912 return 0;
4906} 4913}
4907 4914
4908static struct hda_input_mux stac92hd73xx_dmux = {
4909 .num_items = 4,
4910 .items = {
4911 { "Analog Inputs", 0x0b },
4912 { "Digital Mic 1", 0x09 },
4913 { "Digital Mic 2", 0x0a },
4914 { "CD", 0x08 },
4915 }
4916};
4917
4918static int patch_stac92hd73xx(struct hda_codec *codec) 4915static int patch_stac92hd73xx(struct hda_codec *codec)
4919{ 4916{
4920 struct sigmatel_spec *spec; 4917 struct sigmatel_spec *spec;
@@ -4934,10 +4931,16 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4934 STAC_92HD73XX_MODELS, 4931 STAC_92HD73XX_MODELS,
4935 stac92hd73xx_models, 4932 stac92hd73xx_models,
4936 stac92hd73xx_cfg_tbl); 4933 stac92hd73xx_cfg_tbl);
4934 /* check codec subsystem id if not found */
4935 if (spec->board_config < 0)
4936 spec->board_config =
4937 snd_hda_check_board_codec_sid_config(codec,
4938 STAC_92HD73XX_MODELS, stac92hd73xx_models,
4939 stac92hd73xx_codec_id_cfg_tbl);
4937again: 4940again:
4938 if (spec->board_config < 0) 4941 if (spec->board_config < 0)
4939 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 4942 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4940 " STAC92HD73XX, using BIOS defaults\n"); 4943 codec->chip_name);
4941 else 4944 else
4942 stac92xx_set_config_regs(codec, 4945 stac92xx_set_config_regs(codec,
4943 stac92hd73xx_brd_tbl[spec->board_config]); 4946 stac92hd73xx_brd_tbl[spec->board_config]);
@@ -4950,20 +4953,15 @@ again:
4950 "number of channels defaulting to DAC count\n"); 4953 "number of channels defaulting to DAC count\n");
4951 num_dacs = STAC92HD73_DAC_COUNT; 4954 num_dacs = STAC92HD73_DAC_COUNT;
4952 } 4955 }
4956 spec->init = stac92hd73xx_core_init;
4953 switch (num_dacs) { 4957 switch (num_dacs) {
4954 case 0x3: /* 6 Channel */ 4958 case 0x3: /* 6 Channel */
4955 spec->mixer = stac92hd73xx_6ch_mixer;
4956 spec->init = stac92hd73xx_6ch_core_init;
4957 spec->aloopback_ctl = stac92hd73xx_6ch_loopback; 4959 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
4958 break; 4960 break;
4959 case 0x4: /* 8 Channel */ 4961 case 0x4: /* 8 Channel */
4960 spec->mixer = stac92hd73xx_8ch_mixer;
4961 spec->init = stac92hd73xx_8ch_core_init;
4962 spec->aloopback_ctl = stac92hd73xx_8ch_loopback; 4962 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
4963 break; 4963 break;
4964 case 0x5: /* 10 Channel */ 4964 case 0x5: /* 10 Channel */
4965 spec->mixer = stac92hd73xx_10ch_mixer;
4966 spec->init = stac92hd73xx_10ch_core_init;
4967 spec->aloopback_ctl = stac92hd73xx_10ch_loopback; 4965 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4968 break; 4966 break;
4969 } 4967 }
@@ -4978,14 +4976,14 @@ again:
4978 spec->dmic_nids = stac92hd73xx_dmic_nids; 4976 spec->dmic_nids = stac92hd73xx_dmic_nids;
4979 spec->dmux_nids = stac92hd73xx_dmux_nids; 4977 spec->dmux_nids = stac92hd73xx_dmux_nids;
4980 spec->smux_nids = stac92hd73xx_smux_nids; 4978 spec->smux_nids = stac92hd73xx_smux_nids;
4981 spec->amp_nids = stac92hd73xx_amp_nids;
4982 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
4983 4979
4984 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids); 4980 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4985 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids); 4981 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
4986 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids); 4982 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
4987 memcpy(&spec->private_dimux, &stac92hd73xx_dmux, 4983
4988 sizeof(stac92hd73xx_dmux)); 4984 spec->num_caps = STAC92HD73XX_NUM_CAPS;
4985 spec->capvols = stac92hd73xx_capvols;
4986 spec->capsws = stac92hd73xx_capsws;
4989 4987
4990 switch (spec->board_config) { 4988 switch (spec->board_config) {
4991 case STAC_DELL_EQ: 4989 case STAC_DELL_EQ:
@@ -4995,43 +4993,40 @@ again:
4995 case STAC_DELL_M6_DMIC: 4993 case STAC_DELL_M6_DMIC:
4996 case STAC_DELL_M6_BOTH: 4994 case STAC_DELL_M6_BOTH:
4997 spec->num_smuxes = 0; 4995 spec->num_smuxes = 0;
4998 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4999 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
5000 spec->eapd_switch = 0; 4996 spec->eapd_switch = 0;
5001 spec->num_amps = 1;
5002 4997
5003 if (spec->board_config != STAC_DELL_EQ)
5004 spec->init = dell_m6_core_init;
5005 switch (spec->board_config) { 4998 switch (spec->board_config) {
5006 case STAC_DELL_M6_AMIC: /* Analog Mics */ 4999 case STAC_DELL_M6_AMIC: /* Analog Mics */
5007 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170); 5000 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5008 spec->num_dmics = 0; 5001 spec->num_dmics = 0;
5009 spec->private_dimux.num_items = 1;
5010 break; 5002 break;
5011 case STAC_DELL_M6_DMIC: /* Digital Mics */ 5003 case STAC_DELL_M6_DMIC: /* Digital Mics */
5012 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160); 5004 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5013 spec->num_dmics = 1; 5005 spec->num_dmics = 1;
5014 spec->private_dimux.num_items = 2;
5015 break; 5006 break;
5016 case STAC_DELL_M6_BOTH: /* Both */ 5007 case STAC_DELL_M6_BOTH: /* Both */
5017 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170); 5008 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5018 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160); 5009 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5019 spec->num_dmics = 1; 5010 spec->num_dmics = 1;
5020 spec->private_dimux.num_items = 2;
5021 break; 5011 break;
5022 } 5012 }
5023 break; 5013 break;
5014 case STAC_ALIENWARE_M17X:
5015 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5016 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5017 spec->eapd_switch = 0;
5018 break;
5024 default: 5019 default:
5025 spec->num_dmics = STAC92HD73XX_NUM_DMICS; 5020 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5026 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids); 5021 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5027 spec->eapd_switch = 1; 5022 spec->eapd_switch = 1;
5023 break;
5028 } 5024 }
5029 if (spec->board_config > STAC_92HD73XX_REF) { 5025 if (spec->board_config != STAC_92HD73XX_REF) {
5030 /* GPIO0 High = Enable EAPD */ 5026 /* GPIO0 High = Enable EAPD */
5031 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1; 5027 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5032 spec->gpio_data = 0x01; 5028 spec->gpio_data = 0x01;
5033 } 5029 }
5034 spec->dinput_mux = &spec->private_dimux;
5035 5030
5036 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 5031 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5037 spec->pwr_nids = stac92hd73xx_pwr_nids; 5032 spec->pwr_nids = stac92hd73xx_pwr_nids;
@@ -5063,15 +5058,6 @@ again:
5063 return 0; 5058 return 0;
5064} 5059}
5065 5060
5066static struct hda_input_mux stac92hd83xxx_dmux = {
5067 .num_items = 3,
5068 .items = {
5069 { "Analog Inputs", 0x03 },
5070 { "Digital Mic 1", 0x04 },
5071 { "Digital Mic 2", 0x05 },
5072 }
5073};
5074
5075static int patch_stac92hd83xxx(struct hda_codec *codec) 5061static int patch_stac92hd83xxx(struct hda_codec *codec)
5076{ 5062{
5077 struct sigmatel_spec *spec; 5063 struct sigmatel_spec *spec;
@@ -5086,34 +5072,31 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
5086 5072
5087 codec->spec = spec; 5073 codec->spec = spec;
5088 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs; 5074 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5089 spec->mono_nid = 0x19;
5090 spec->digbeep_nid = 0x21; 5075 spec->digbeep_nid = 0x21;
5091 spec->dmic_nids = stac92hd83xxx_dmic_nids; 5076 spec->mux_nids = stac92hd83xxx_mux_nids;
5092 spec->dmux_nids = stac92hd83xxx_dmux_nids; 5077 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
5093 spec->adc_nids = stac92hd83xxx_adc_nids; 5078 spec->adc_nids = stac92hd83xxx_adc_nids;
5079 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5094 spec->pwr_nids = stac92hd83xxx_pwr_nids; 5080 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5095 spec->amp_nids = stac92hd83xxx_amp_nids;
5096 spec->pwr_mapping = stac92hd83xxx_pwr_mapping; 5081 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5097 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids); 5082 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5098 spec->multiout.dac_nids = spec->dac_nids; 5083 spec->multiout.dac_nids = spec->dac_nids;
5099 5084
5100 spec->init = stac92hd83xxx_core_init; 5085 spec->init = stac92hd83xxx_core_init;
5101 spec->mixer = stac92hd83xxx_mixer;
5102 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids); 5086 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5103 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
5104 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5105 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
5106 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
5107 spec->dinput_mux = &stac92hd83xxx_dmux;
5108 spec->pin_nids = stac92hd83xxx_pin_nids; 5087 spec->pin_nids = stac92hd83xxx_pin_nids;
5088 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5089 spec->capvols = stac92hd83xxx_capvols;
5090 spec->capsws = stac92hd83xxx_capsws;
5091
5109 spec->board_config = snd_hda_check_board_config(codec, 5092 spec->board_config = snd_hda_check_board_config(codec,
5110 STAC_92HD83XXX_MODELS, 5093 STAC_92HD83XXX_MODELS,
5111 stac92hd83xxx_models, 5094 stac92hd83xxx_models,
5112 stac92hd83xxx_cfg_tbl); 5095 stac92hd83xxx_cfg_tbl);
5113again: 5096again:
5114 if (spec->board_config < 0) 5097 if (spec->board_config < 0)
5115 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5098 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5116 " STAC92HD83XXX, using BIOS defaults\n"); 5099 codec->chip_name);
5117 else 5100 else
5118 stac92xx_set_config_regs(codec, 5101 stac92xx_set_config_regs(codec,
5119 stac92hd83xxx_brd_tbl[spec->board_config]); 5102 stac92hd83xxx_brd_tbl[spec->board_config]);
@@ -5155,6 +5138,8 @@ again:
5155 5138
5156 num_dacs = snd_hda_get_connections(codec, nid, 5139 num_dacs = snd_hda_get_connections(codec, nid,
5157 conn, STAC92HD83_DAC_COUNT + 1) - 1; 5140 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5141 if (num_dacs < 0)
5142 num_dacs = STAC92HD83_DAC_COUNT;
5158 5143
5159 /* set port X to select the last DAC 5144 /* set port X to select the last DAC
5160 */ 5145 */
@@ -5168,25 +5153,6 @@ again:
5168 return 0; 5153 return 0;
5169} 5154}
5170 5155
5171static struct hda_input_mux stac92hd71bxx_dmux_nomixer = {
5172 .num_items = 3,
5173 .items = {
5174 { "Analog Inputs", 0x00 },
5175 { "Digital Mic 1", 0x02 },
5176 { "Digital Mic 2", 0x03 },
5177 }
5178};
5179
5180static struct hda_input_mux stac92hd71bxx_dmux_amixer = {
5181 .num_items = 4,
5182 .items = {
5183 { "Analog Inputs", 0x00 },
5184 { "Mixer", 0x01 },
5185 { "Digital Mic 1", 0x02 },
5186 { "Digital Mic 2", 0x03 },
5187 }
5188};
5189
5190/* get the pin connection (fixed, none, etc) */ 5156/* get the pin connection (fixed, none, etc) */
5191static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx) 5157static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5192{ 5158{
@@ -5247,7 +5213,6 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
5247 struct sigmatel_spec *spec; 5213 struct sigmatel_spec *spec;
5248 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init; 5214 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5249 int err = 0; 5215 int err = 0;
5250 unsigned int ndmic_nids = 0;
5251 5216
5252 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5217 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5253 if (spec == NULL) 5218 if (spec == NULL)
@@ -5276,13 +5241,13 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
5276 stac92hd71bxx_cfg_tbl); 5241 stac92hd71bxx_cfg_tbl);
5277again: 5242again:
5278 if (spec->board_config < 0) 5243 if (spec->board_config < 0)
5279 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5244 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5280 " STAC92HD71BXX, using BIOS defaults\n"); 5245 codec->chip_name);
5281 else 5246 else
5282 stac92xx_set_config_regs(codec, 5247 stac92xx_set_config_regs(codec,
5283 stac92hd71bxx_brd_tbl[spec->board_config]); 5248 stac92hd71bxx_brd_tbl[spec->board_config]);
5284 5249
5285 if (spec->board_config > STAC_92HD71BXX_REF) { 5250 if (spec->board_config != STAC_92HD71BXX_REF) {
5286 /* GPIO0 = EAPD */ 5251 /* GPIO0 = EAPD */
5287 spec->gpio_mask = 0x01; 5252 spec->gpio_mask = 0x01;
5288 spec->gpio_dir = 0x01; 5253 spec->gpio_dir = 0x01;
@@ -5292,6 +5257,10 @@ again:
5292 spec->dmic_nids = stac92hd71bxx_dmic_nids; 5257 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5293 spec->dmux_nids = stac92hd71bxx_dmux_nids; 5258 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5294 5259
5260 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5261 spec->capvols = stac92hd71bxx_capvols;
5262 spec->capsws = stac92hd71bxx_capsws;
5263
5295 switch (codec->vendor_id) { 5264 switch (codec->vendor_id) {
5296 case 0x111d76b6: /* 4 Port without Analog Mixer */ 5265 case 0x111d76b6: /* 4 Port without Analog Mixer */
5297 case 0x111d76b7: 5266 case 0x111d76b7:
@@ -5299,24 +5268,13 @@ again:
5299 /* fallthru */ 5268 /* fallthru */
5300 case 0x111d76b4: /* 6 Port without Analog Mixer */ 5269 case 0x111d76b4: /* 6 Port without Analog Mixer */
5301 case 0x111d76b5: 5270 case 0x111d76b5:
5302 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_nomixer,
5303 sizeof(stac92hd71bxx_dmux_nomixer));
5304 spec->mixer = stac92hd71bxx_mixer;
5305 spec->init = stac92hd71bxx_core_init; 5271 spec->init = stac92hd71bxx_core_init;
5306 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs; 5272 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5307 spec->num_dmics = stac92hd71bxx_connected_ports(codec, 5273 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5308 stac92hd71bxx_dmic_nids, 5274 stac92hd71bxx_dmic_nids,
5309 STAC92HD71BXX_NUM_DMICS); 5275 STAC92HD71BXX_NUM_DMICS);
5310 if (spec->num_dmics) {
5311 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5312 spec->dinput_mux = &spec->private_dimux;
5313 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5314 }
5315 break; 5276 break;
5316 case 0x111d7608: /* 5 Port with Analog Mixer */ 5277 case 0x111d7608: /* 5 Port with Analog Mixer */
5317 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5318 sizeof(stac92hd71bxx_dmux_amixer));
5319 spec->private_dimux.num_items--;
5320 switch (spec->board_config) { 5278 switch (spec->board_config) {
5321 case STAC_HP_M4: 5279 case STAC_HP_M4:
5322 /* Enable VREF power saving on GPIO1 detect */ 5280 /* Enable VREF power saving on GPIO1 detect */
@@ -5338,11 +5296,8 @@ again:
5338 5296
5339 /* no output amps */ 5297 /* no output amps */
5340 spec->num_pwrs = 0; 5298 spec->num_pwrs = 0;
5341 spec->mixer = stac92hd71bxx_analog_mixer;
5342 spec->dinput_mux = &spec->private_dimux;
5343
5344 /* disable VSW */ 5299 /* disable VSW */
5345 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF]; 5300 spec->init = stac92hd71bxx_core_init;
5346 unmute_init++; 5301 unmute_init++;
5347 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0); 5302 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5348 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3); 5303 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
@@ -5350,8 +5305,6 @@ again:
5350 spec->num_dmics = stac92hd71bxx_connected_ports(codec, 5305 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5351 stac92hd71bxx_dmic_nids, 5306 stac92hd71bxx_dmic_nids,
5352 STAC92HD71BXX_NUM_DMICS - 1); 5307 STAC92HD71BXX_NUM_DMICS - 1);
5353 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5354 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
5355 break; 5308 break;
5356 case 0x111d7603: /* 6 Port with Analog Mixer */ 5309 case 0x111d7603: /* 6 Port with Analog Mixer */
5357 if ((codec->revision_id & 0xf) == 1) 5310 if ((codec->revision_id & 0xf) == 1)
@@ -5361,17 +5314,12 @@ again:
5361 spec->num_pwrs = 0; 5314 spec->num_pwrs = 0;
5362 /* fallthru */ 5315 /* fallthru */
5363 default: 5316 default:
5364 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer, 5317 spec->init = stac92hd71bxx_core_init;
5365 sizeof(stac92hd71bxx_dmux_amixer));
5366 spec->dinput_mux = &spec->private_dimux;
5367 spec->mixer = stac92hd71bxx_analog_mixer;
5368 spec->init = stac92hd71bxx_analog_core_init;
5369 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs; 5318 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5370 spec->num_dmics = stac92hd71bxx_connected_ports(codec, 5319 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5371 stac92hd71bxx_dmic_nids, 5320 stac92hd71bxx_dmic_nids,
5372 STAC92HD71BXX_NUM_DMICS); 5321 STAC92HD71BXX_NUM_DMICS);
5373 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids); 5322 break;
5374 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5375 } 5323 }
5376 5324
5377 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) 5325 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
@@ -5399,6 +5347,7 @@ again:
5399 5347
5400 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids); 5348 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5401 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids); 5349 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5350 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5402 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e); 5351 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5403 5352
5404 switch (spec->board_config) { 5353 switch (spec->board_config) {
@@ -5431,6 +5380,11 @@ again:
5431 case STAC_HP_DV5: 5380 case STAC_HP_DV5:
5432 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010); 5381 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5433 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN); 5382 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5383 /* HP dv6 gives the headphone pin as a line-out. Thus we
5384 * need to set hp_detect flag here to force to enable HP
5385 * detection.
5386 */
5387 spec->hp_detect = 1;
5434 break; 5388 break;
5435 case STAC_HP_HDX: 5389 case STAC_HP_HDX:
5436 spec->num_dmics = 1; 5390 spec->num_dmics = 1;
@@ -5453,8 +5407,6 @@ again:
5453#endif 5407#endif
5454 5408
5455 spec->multiout.dac_nids = spec->dac_nids; 5409 spec->multiout.dac_nids = spec->dac_nids;
5456 if (spec->dinput_mux)
5457 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
5458 5410
5459 err = stac92xx_parse_auto_config(codec, 0x21, 0); 5411 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5460 if (!err) { 5412 if (!err) {
@@ -5532,8 +5484,8 @@ static int patch_stac922x(struct hda_codec *codec)
5532 5484
5533 again: 5485 again:
5534 if (spec->board_config < 0) 5486 if (spec->board_config < 0)
5535 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, " 5487 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5536 "using BIOS defaults\n"); 5488 codec->chip_name);
5537 else 5489 else
5538 stac92xx_set_config_regs(codec, 5490 stac92xx_set_config_regs(codec,
5539 stac922x_brd_tbl[spec->board_config]); 5491 stac922x_brd_tbl[spec->board_config]);
@@ -5546,7 +5498,10 @@ static int patch_stac922x(struct hda_codec *codec)
5546 spec->num_pwrs = 0; 5498 spec->num_pwrs = 0;
5547 5499
5548 spec->init = stac922x_core_init; 5500 spec->init = stac922x_core_init;
5549 spec->mixer = stac922x_mixer; 5501
5502 spec->num_caps = STAC922X_NUM_CAPS;
5503 spec->capvols = stac922x_capvols;
5504 spec->capsws = stac922x_capsws;
5550 5505
5551 spec->multiout.dac_nids = spec->dac_nids; 5506 spec->multiout.dac_nids = spec->dac_nids;
5552 5507
@@ -5595,8 +5550,8 @@ static int patch_stac927x(struct hda_codec *codec)
5595 stac927x_cfg_tbl); 5550 stac927x_cfg_tbl);
5596 again: 5551 again:
5597 if (spec->board_config < 0) 5552 if (spec->board_config < 0)
5598 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5553 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5599 "STAC927x, using BIOS defaults\n"); 5554 codec->chip_name);
5600 else 5555 else
5601 stac92xx_set_config_regs(codec, 5556 stac92xx_set_config_regs(codec,
5602 stac927x_brd_tbl[spec->board_config]); 5557 stac927x_brd_tbl[spec->board_config]);
@@ -5612,16 +5567,18 @@ static int patch_stac927x(struct hda_codec *codec)
5612 spec->dac_list = stac927x_dac_nids; 5567 spec->dac_list = stac927x_dac_nids;
5613 spec->multiout.dac_nids = spec->dac_nids; 5568 spec->multiout.dac_nids = spec->dac_nids;
5614 5569
5570 if (spec->board_config != STAC_D965_REF) {
5571 /* GPIO0 High = Enable EAPD */
5572 spec->eapd_mask = spec->gpio_mask = 0x01;
5573 spec->gpio_dir = spec->gpio_data = 0x01;
5574 }
5575
5615 switch (spec->board_config) { 5576 switch (spec->board_config) {
5616 case STAC_D965_3ST: 5577 case STAC_D965_3ST:
5617 case STAC_D965_5ST: 5578 case STAC_D965_5ST:
5618 /* GPIO0 High = Enable EAPD */ 5579 /* GPIO0 High = Enable EAPD */
5619 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
5620 spec->gpio_data = 0x01;
5621 spec->num_dmics = 0; 5580 spec->num_dmics = 0;
5622
5623 spec->init = d965_core_init; 5581 spec->init = d965_core_init;
5624 spec->mixer = stac927x_mixer;
5625 break; 5582 break;
5626 case STAC_DELL_BIOS: 5583 case STAC_DELL_BIOS:
5627 switch (codec->subsystem_id) { 5584 switch (codec->subsystem_id) {
@@ -5639,29 +5596,28 @@ static int patch_stac927x(struct hda_codec *codec)
5639 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130); 5596 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5640 /* fallthru */ 5597 /* fallthru */
5641 case STAC_DELL_3ST: 5598 case STAC_DELL_3ST:
5642 /* GPIO2 High = Enable EAPD */ 5599 if (codec->subsystem_id != 0x1028022f) {
5643 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04; 5600 /* GPIO2 High = Enable EAPD */
5644 spec->gpio_data = 0x04; 5601 spec->eapd_mask = spec->gpio_mask = 0x04;
5602 spec->gpio_dir = spec->gpio_data = 0x04;
5603 }
5645 spec->dmic_nids = stac927x_dmic_nids; 5604 spec->dmic_nids = stac927x_dmic_nids;
5646 spec->num_dmics = STAC927X_NUM_DMICS; 5605 spec->num_dmics = STAC927X_NUM_DMICS;
5647 5606
5648 spec->init = d965_core_init; 5607 spec->init = d965_core_init;
5649 spec->mixer = stac927x_mixer;
5650 spec->dmux_nids = stac927x_dmux_nids; 5608 spec->dmux_nids = stac927x_dmux_nids;
5651 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids); 5609 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5652 break; 5610 break;
5653 default: 5611 default:
5654 if (spec->board_config > STAC_D965_REF) {
5655 /* GPIO0 High = Enable EAPD */
5656 spec->eapd_mask = spec->gpio_mask = 0x01;
5657 spec->gpio_dir = spec->gpio_data = 0x01;
5658 }
5659 spec->num_dmics = 0; 5612 spec->num_dmics = 0;
5660
5661 spec->init = stac927x_core_init; 5613 spec->init = stac927x_core_init;
5662 spec->mixer = stac927x_mixer; 5614 break;
5663 } 5615 }
5664 5616
5617 spec->num_caps = STAC927X_NUM_CAPS;
5618 spec->capvols = stac927x_capvols;
5619 spec->capsws = stac927x_capsws;
5620
5665 spec->num_pwrs = 0; 5621 spec->num_pwrs = 0;
5666 spec->aloopback_ctl = stac927x_loopback; 5622 spec->aloopback_ctl = stac927x_loopback;
5667 spec->aloopback_mask = 0x40; 5623 spec->aloopback_mask = 0x40;
@@ -5723,7 +5679,8 @@ static int patch_stac9205(struct hda_codec *codec)
5723 stac9205_cfg_tbl); 5679 stac9205_cfg_tbl);
5724 again: 5680 again:
5725 if (spec->board_config < 0) 5681 if (spec->board_config < 0)
5726 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n"); 5682 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5683 codec->chip_name);
5727 else 5684 else
5728 stac92xx_set_config_regs(codec, 5685 stac92xx_set_config_regs(codec,
5729 stac9205_brd_tbl[spec->board_config]); 5686 stac9205_brd_tbl[spec->board_config]);
@@ -5742,9 +5699,12 @@ static int patch_stac9205(struct hda_codec *codec)
5742 spec->num_pwrs = 0; 5699 spec->num_pwrs = 0;
5743 5700
5744 spec->init = stac9205_core_init; 5701 spec->init = stac9205_core_init;
5745 spec->mixer = stac9205_mixer;
5746 spec->aloopback_ctl = stac9205_loopback; 5702 spec->aloopback_ctl = stac9205_loopback;
5747 5703
5704 spec->num_caps = STAC9205_NUM_CAPS;
5705 spec->capvols = stac9205_capvols;
5706 spec->capsws = stac9205_capsws;
5707
5748 spec->aloopback_mask = 0x40; 5708 spec->aloopback_mask = 0x40;
5749 spec->aloopback_shift = 0; 5709 spec->aloopback_shift = 0;
5750 /* Turn on/off EAPD per HP plugging */ 5710 /* Turn on/off EAPD per HP plugging */
@@ -5819,12 +5779,6 @@ static struct hda_verb stac9872_core_init[] = {
5819 {} 5779 {}
5820}; 5780};
5821 5781
5822static struct snd_kcontrol_new stac9872_mixer[] = {
5823 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5824 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5825 { } /* end */
5826};
5827
5828static hda_nid_t stac9872_pin_nids[] = { 5782static hda_nid_t stac9872_pin_nids[] = {
5829 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 5783 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5830 0x11, 0x13, 0x14, 5784 0x11, 0x13, 0x14,
@@ -5838,6 +5792,11 @@ static hda_nid_t stac9872_mux_nids[] = {
5838 0x15 5792 0x15
5839}; 5793};
5840 5794
5795static unsigned long stac9872_capvols[] = {
5796 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
5797};
5798#define stac9872_capsws stac9872_capvols
5799
5841static unsigned int stac9872_vaio_pin_configs[9] = { 5800static unsigned int stac9872_vaio_pin_configs[9] = {
5842 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030, 5801 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5843 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0, 5802 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
@@ -5854,6 +5813,8 @@ static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5854}; 5813};
5855 5814
5856static struct snd_pci_quirk stac9872_cfg_tbl[] = { 5815static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5816 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
5817 "Sony VAIO F/S", STAC_9872_VAIO),
5857 {} /* terminator */ 5818 {} /* terminator */
5858}; 5819};
5859 5820
@@ -5866,26 +5827,28 @@ static int patch_stac9872(struct hda_codec *codec)
5866 if (spec == NULL) 5827 if (spec == NULL)
5867 return -ENOMEM; 5828 return -ENOMEM;
5868 codec->spec = spec; 5829 codec->spec = spec;
5830 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5831 spec->pin_nids = stac9872_pin_nids;
5869 5832
5870 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS, 5833 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5871 stac9872_models, 5834 stac9872_models,
5872 stac9872_cfg_tbl); 5835 stac9872_cfg_tbl);
5873 if (spec->board_config < 0) 5836 if (spec->board_config < 0)
5874 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9872, " 5837 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5875 "using BIOS defaults\n"); 5838 codec->chip_name);
5876 else 5839 else
5877 stac92xx_set_config_regs(codec, 5840 stac92xx_set_config_regs(codec,
5878 stac9872_brd_tbl[spec->board_config]); 5841 stac9872_brd_tbl[spec->board_config]);
5879 5842
5880 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5881 spec->pin_nids = stac9872_pin_nids;
5882 spec->multiout.dac_nids = spec->dac_nids; 5843 spec->multiout.dac_nids = spec->dac_nids;
5883 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids); 5844 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5884 spec->adc_nids = stac9872_adc_nids; 5845 spec->adc_nids = stac9872_adc_nids;
5885 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids); 5846 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5886 spec->mux_nids = stac9872_mux_nids; 5847 spec->mux_nids = stac9872_mux_nids;
5887 spec->mixer = stac9872_mixer;
5888 spec->init = stac9872_core_init; 5848 spec->init = stac9872_core_init;
5849 spec->num_caps = 1;
5850 spec->capvols = stac9872_capvols;
5851 spec->capsws = stac9872_capsws;
5889 5852
5890 err = stac92xx_parse_auto_config(codec, 0x10, 0x12); 5853 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5891 if (err < 0) { 5854 if (err < 0) {
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 8e004fb6961..ee89db90c9b 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -210,7 +210,9 @@ struct via_spec {
210 /* capture */ 210 /* capture */
211 unsigned int num_adc_nids; 211 unsigned int num_adc_nids;
212 hda_nid_t *adc_nids; 212 hda_nid_t *adc_nids;
213 hda_nid_t mux_nids[3];
213 hda_nid_t dig_in_nid; 214 hda_nid_t dig_in_nid;
215 hda_nid_t dig_in_pin;
214 216
215 /* capture source */ 217 /* capture source */
216 const struct hda_input_mux *input_mux; 218 const struct hda_input_mux *input_mux;
@@ -319,6 +321,9 @@ static void via_auto_set_output_and_unmute(struct hda_codec *codec,
319 pin_type); 321 pin_type);
320 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 322 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
321 AMP_OUT_UNMUTE); 323 AMP_OUT_UNMUTE);
324 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
325 snd_hda_codec_write(codec, nid, 0,
326 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
322} 327}
323 328
324 329
@@ -387,27 +392,12 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
387 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 392 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388 struct via_spec *spec = codec->spec; 393 struct via_spec *spec = codec->spec;
389 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 394 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
390 unsigned int vendor_id = codec->vendor_id; 395
391 396 if (!spec->mux_nids[adc_idx])
392 /* AIW0 lydia 060801 add for correct sw0 input select */ 397 return -EINVAL;
393 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0)) 398 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
394 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 399 spec->mux_nids[adc_idx],
395 0x18, &spec->cur_mux[adc_idx]); 400 &spec->cur_mux[adc_idx]);
396 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
397 IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
398 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
399 0x19, &spec->cur_mux[adc_idx]);
400 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
401 IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
402 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
403 0x17, &spec->cur_mux[adc_idx]);
404 else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
405 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
406 0x13, &spec->cur_mux[adc_idx]);
407 else
408 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
409 spec->adc_nids[adc_idx],
410 &spec->cur_mux[adc_idx]);
411} 401}
412 402
413static int via_independent_hp_info(struct snd_kcontrol *kcontrol, 403static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
@@ -998,25 +988,11 @@ static int via_init(struct hda_codec *codec)
998 988
999 /* Lydia Add for EAPD enable */ 989 /* Lydia Add for EAPD enable */
1000 if (!spec->dig_in_nid) { /* No Digital In connection */ 990 if (!spec->dig_in_nid) { /* No Digital In connection */
1001 if (IS_VT1708_VENDORID(codec->vendor_id)) { 991 if (spec->dig_in_pin) {
1002 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0, 992 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1003 AC_VERB_SET_PIN_WIDGET_CONTROL,
1004 PIN_OUT);
1005 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
1006 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1007 } else if (IS_VT1709_10CH_VENDORID(codec->vendor_id) ||
1008 IS_VT1709_6CH_VENDORID(codec->vendor_id)) {
1009 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
1010 AC_VERB_SET_PIN_WIDGET_CONTROL, 993 AC_VERB_SET_PIN_WIDGET_CONTROL,
1011 PIN_OUT); 994 PIN_OUT);
1012 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0, 995 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1013 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1014 } else if (IS_VT1708B_8CH_VENDORID(codec->vendor_id) ||
1015 IS_VT1708B_4CH_VENDORID(codec->vendor_id)) {
1016 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
1017 AC_VERB_SET_PIN_WIDGET_CONTROL,
1018 PIN_OUT);
1019 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
1020 AC_VERB_SET_EAPD_BTLENABLE, 0x02); 996 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1021 } 997 }
1022 } else /* enable SPDIF-input pin */ 998 } else /* enable SPDIF-input pin */
@@ -1326,6 +1302,7 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1326 1302
1327 if (spec->autocfg.dig_outs) 1303 if (spec->autocfg.dig_outs)
1328 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; 1304 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1305 spec->dig_in_pin = VT1708_DIGIN_PIN;
1329 if (spec->autocfg.dig_in_pin) 1306 if (spec->autocfg.dig_in_pin)
1330 spec->dig_in_nid = VT1708_DIGIN_NID; 1307 spec->dig_in_nid = VT1708_DIGIN_NID;
1331 1308
@@ -1352,6 +1329,33 @@ static int via_auto_init(struct hda_codec *codec)
1352 return 0; 1329 return 0;
1353} 1330}
1354 1331
1332static int get_mux_nids(struct hda_codec *codec)
1333{
1334 struct via_spec *spec = codec->spec;
1335 hda_nid_t nid, conn[8];
1336 unsigned int type;
1337 int i, n;
1338
1339 for (i = 0; i < spec->num_adc_nids; i++) {
1340 nid = spec->adc_nids[i];
1341 while (nid) {
1342 type = get_wcaps_type(get_wcaps(codec, nid));
1343 if (type == AC_WID_PIN)
1344 break;
1345 n = snd_hda_get_connections(codec, nid, conn,
1346 ARRAY_SIZE(conn));
1347 if (n <= 0)
1348 break;
1349 if (n > 1) {
1350 spec->mux_nids[i] = nid;
1351 break;
1352 }
1353 nid = conn[0];
1354 }
1355 }
1356 return 0;
1357}
1358
1355static int patch_vt1708(struct hda_codec *codec) 1359static int patch_vt1708(struct hda_codec *codec)
1356{ 1360{
1357 struct via_spec *spec; 1361 struct via_spec *spec;
@@ -1390,6 +1394,7 @@ static int patch_vt1708(struct hda_codec *codec)
1390 if (!spec->adc_nids && spec->input_mux) { 1394 if (!spec->adc_nids && spec->input_mux) {
1391 spec->adc_nids = vt1708_adc_nids; 1395 spec->adc_nids = vt1708_adc_nids;
1392 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); 1396 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1397 get_mux_nids(codec);
1393 spec->mixers[spec->num_mixers] = vt1708_capture_mixer; 1398 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1394 spec->num_mixers++; 1399 spec->num_mixers++;
1395 } 1400 }
@@ -1799,6 +1804,7 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
1799 1804
1800 if (spec->autocfg.dig_outs) 1805 if (spec->autocfg.dig_outs)
1801 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; 1806 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1807 spec->dig_in_pin = VT1709_DIGIN_PIN;
1802 if (spec->autocfg.dig_in_pin) 1808 if (spec->autocfg.dig_in_pin)
1803 spec->dig_in_nid = VT1709_DIGIN_NID; 1809 spec->dig_in_nid = VT1709_DIGIN_NID;
1804 1810
@@ -1859,6 +1865,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1859 if (!spec->adc_nids && spec->input_mux) { 1865 if (!spec->adc_nids && spec->input_mux) {
1860 spec->adc_nids = vt1709_adc_nids; 1866 spec->adc_nids = vt1709_adc_nids;
1861 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 1867 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1868 get_mux_nids(codec);
1862 spec->mixers[spec->num_mixers] = vt1709_capture_mixer; 1869 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1863 spec->num_mixers++; 1870 spec->num_mixers++;
1864 } 1871 }
@@ -1952,6 +1959,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1952 if (!spec->adc_nids && spec->input_mux) { 1959 if (!spec->adc_nids && spec->input_mux) {
1953 spec->adc_nids = vt1709_adc_nids; 1960 spec->adc_nids = vt1709_adc_nids;
1954 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 1961 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1962 get_mux_nids(codec);
1955 spec->mixers[spec->num_mixers] = vt1709_capture_mixer; 1963 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1956 spec->num_mixers++; 1964 spec->num_mixers++;
1957 } 1965 }
@@ -2344,6 +2352,7 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
2344 2352
2345 if (spec->autocfg.dig_outs) 2353 if (spec->autocfg.dig_outs)
2346 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; 2354 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2355 spec->dig_in_pin = VT1708B_DIGIN_PIN;
2347 if (spec->autocfg.dig_in_pin) 2356 if (spec->autocfg.dig_in_pin)
2348 spec->dig_in_nid = VT1708B_DIGIN_NID; 2357 spec->dig_in_nid = VT1708B_DIGIN_NID;
2349 2358
@@ -2404,6 +2413,7 @@ static int patch_vt1708B_8ch(struct hda_codec *codec)
2404 if (!spec->adc_nids && spec->input_mux) { 2413 if (!spec->adc_nids && spec->input_mux) {
2405 spec->adc_nids = vt1708B_adc_nids; 2414 spec->adc_nids = vt1708B_adc_nids;
2406 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids); 2415 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2416 get_mux_nids(codec);
2407 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; 2417 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2408 spec->num_mixers++; 2418 spec->num_mixers++;
2409 } 2419 }
@@ -2455,6 +2465,7 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
2455 if (!spec->adc_nids && spec->input_mux) { 2465 if (!spec->adc_nids && spec->input_mux) {
2456 spec->adc_nids = vt1708B_adc_nids; 2466 spec->adc_nids = vt1708B_adc_nids;
2457 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids); 2467 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2468 get_mux_nids(codec);
2458 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; 2469 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2459 spec->num_mixers++; 2470 spec->num_mixers++;
2460 } 2471 }
@@ -2889,6 +2900,7 @@ static int patch_vt1708S(struct hda_codec *codec)
2889 if (!spec->adc_nids && spec->input_mux) { 2900 if (!spec->adc_nids && spec->input_mux) {
2890 spec->adc_nids = vt1708S_adc_nids; 2901 spec->adc_nids = vt1708S_adc_nids;
2891 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); 2902 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2903 get_mux_nids(codec);
2892 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; 2904 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2893 spec->num_mixers++; 2905 spec->num_mixers++;
2894 } 2906 }
@@ -3206,6 +3218,7 @@ static int patch_vt1702(struct hda_codec *codec)
3206 if (!spec->adc_nids && spec->input_mux) { 3218 if (!spec->adc_nids && spec->input_mux) {
3207 spec->adc_nids = vt1702_adc_nids; 3219 spec->adc_nids = vt1702_adc_nids;
3208 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids); 3220 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3221 get_mux_nids(codec);
3209 spec->mixers[spec->num_mixers] = vt1702_capture_mixer; 3222 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3210 spec->num_mixers++; 3223 spec->num_mixers++;
3211 } 3224 }
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index adc909ec125..9da2dae64c5 100644
--- a/sound/pci/ice1712/ice1712.h
+++ b/sound/pci/ice1712/ice1712.h
@@ -379,6 +379,15 @@ struct snd_ice1712 {
379 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate); 379 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate);
380 void (*set_spdif_clock)(struct snd_ice1712 *ice); 380 void (*set_spdif_clock)(struct snd_ice1712 *ice);
381 381
382#ifdef CONFIG_PM
383 int (*pm_suspend)(struct snd_ice1712 *);
384 int (*pm_resume)(struct snd_ice1712 *);
385 int pm_suspend_enabled:1;
386 int pm_saved_is_spdif_master:1;
387 unsigned int pm_saved_spdif_ctrl;
388 unsigned char pm_saved_spdif_cfg;
389 unsigned int pm_saved_route;
390#endif
382}; 391};
383 392
384 393
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index cc84a831eb2..af6e0014862 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -560,6 +560,7 @@ static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
560 560
561 case SNDRV_PCM_TRIGGER_START: 561 case SNDRV_PCM_TRIGGER_START:
562 case SNDRV_PCM_TRIGGER_STOP: 562 case SNDRV_PCM_TRIGGER_STOP:
563 case SNDRV_PCM_TRIGGER_SUSPEND:
563 spin_lock(&ice->reg_lock); 564 spin_lock(&ice->reg_lock);
564 old = inb(ICEMT1724(ice, DMA_CONTROL)); 565 old = inb(ICEMT1724(ice, DMA_CONTROL));
565 if (cmd == SNDRV_PCM_TRIGGER_START) 566 if (cmd == SNDRV_PCM_TRIGGER_START)
@@ -570,6 +571,10 @@ static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
570 spin_unlock(&ice->reg_lock); 571 spin_unlock(&ice->reg_lock);
571 break; 572 break;
572 573
574 case SNDRV_PCM_TRIGGER_RESUME:
575 /* apps will have to restart stream */
576 break;
577
573 default: 578 default:
574 return -EINVAL; 579 return -EINVAL;
575 } 580 }
@@ -2262,7 +2267,7 @@ static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2262 2267
2263 2268
2264 2269
2265static void __devinit snd_vt1724_chip_reset(struct snd_ice1712 *ice) 2270static void snd_vt1724_chip_reset(struct snd_ice1712 *ice)
2266{ 2271{
2267 outb(VT1724_RESET , ICEREG1724(ice, CONTROL)); 2272 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
2268 inb(ICEREG1724(ice, CONTROL)); /* pci posting flush */ 2273 inb(ICEREG1724(ice, CONTROL)); /* pci posting flush */
@@ -2272,7 +2277,7 @@ static void __devinit snd_vt1724_chip_reset(struct snd_ice1712 *ice)
2272 msleep(10); 2277 msleep(10);
2273} 2278}
2274 2279
2275static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice) 2280static int snd_vt1724_chip_init(struct snd_ice1712 *ice)
2276{ 2281{
2277 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG)); 2282 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2278 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG)); 2283 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
@@ -2287,6 +2292,14 @@ static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
2287 2292
2288 outb(0, ICEREG1724(ice, POWERDOWN)); 2293 outb(0, ICEREG1724(ice, POWERDOWN));
2289 2294
2295 /* MPU_RX and TX irq masks are cleared later dynamically */
2296 outb(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX , ICEREG1724(ice, IRQMASK));
2297
2298 /* don't handle FIFO overrun/underruns (just yet),
2299 * since they cause machine lockups
2300 */
2301 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2302
2290 return 0; 2303 return 0;
2291} 2304}
2292 2305
@@ -2431,6 +2444,8 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2431 snd_vt1724_proc_init(ice); 2444 snd_vt1724_proc_init(ice);
2432 synchronize_irq(pci->irq); 2445 synchronize_irq(pci->irq);
2433 2446
2447 card->private_data = ice;
2448
2434 err = pci_request_regions(pci, "ICE1724"); 2449 err = pci_request_regions(pci, "ICE1724");
2435 if (err < 0) { 2450 if (err < 0) {
2436 kfree(ice); 2451 kfree(ice);
@@ -2459,14 +2474,6 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2459 return -EIO; 2474 return -EIO;
2460 } 2475 }
2461 2476
2462 /* MPU_RX and TX irq masks are cleared later dynamically */
2463 outb(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX , ICEREG1724(ice, IRQMASK));
2464
2465 /* don't handle FIFO overrun/underruns (just yet),
2466 * since they cause machine lockups
2467 */
2468 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2469
2470 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops); 2477 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops);
2471 if (err < 0) { 2478 if (err < 0) {
2472 snd_vt1724_free(ice); 2479 snd_vt1724_free(ice);
@@ -2650,11 +2657,96 @@ static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2650 pci_set_drvdata(pci, NULL); 2657 pci_set_drvdata(pci, NULL);
2651} 2658}
2652 2659
2660#ifdef CONFIG_PM
2661static int snd_vt1724_suspend(struct pci_dev *pci, pm_message_t state)
2662{
2663 struct snd_card *card = pci_get_drvdata(pci);
2664 struct snd_ice1712 *ice = card->private_data;
2665
2666 if (!ice->pm_suspend_enabled)
2667 return 0;
2668
2669 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2670
2671 snd_pcm_suspend_all(ice->pcm);
2672 snd_pcm_suspend_all(ice->pcm_pro);
2673 snd_pcm_suspend_all(ice->pcm_ds);
2674 snd_ac97_suspend(ice->ac97);
2675
2676 spin_lock_irq(&ice->reg_lock);
2677 ice->pm_saved_is_spdif_master = ice->is_spdif_master(ice);
2678 ice->pm_saved_spdif_ctrl = inw(ICEMT1724(ice, SPDIF_CTRL));
2679 ice->pm_saved_spdif_cfg = inb(ICEREG1724(ice, SPDIF_CFG));
2680 ice->pm_saved_route = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
2681 spin_unlock_irq(&ice->reg_lock);
2682
2683 if (ice->pm_suspend)
2684 ice->pm_suspend(ice);
2685
2686 pci_disable_device(pci);
2687 pci_save_state(pci);
2688 pci_set_power_state(pci, pci_choose_state(pci, state));
2689 return 0;
2690}
2691
2692static int snd_vt1724_resume(struct pci_dev *pci)
2693{
2694 struct snd_card *card = pci_get_drvdata(pci);
2695 struct snd_ice1712 *ice = card->private_data;
2696
2697 if (!ice->pm_suspend_enabled)
2698 return 0;
2699
2700 pci_set_power_state(pci, PCI_D0);
2701 pci_restore_state(pci);
2702
2703 if (pci_enable_device(pci) < 0) {
2704 snd_card_disconnect(card);
2705 return -EIO;
2706 }
2707
2708 pci_set_master(pci);
2709
2710 snd_vt1724_chip_reset(ice);
2711
2712 if (snd_vt1724_chip_init(ice) < 0) {
2713 snd_card_disconnect(card);
2714 return -EIO;
2715 }
2716
2717 if (ice->pm_resume)
2718 ice->pm_resume(ice);
2719
2720 if (ice->pm_saved_is_spdif_master) {
2721 /* switching to external clock via SPDIF */
2722 ice->set_spdif_clock(ice);
2723 } else {
2724 /* internal on-card clock */
2725 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
2726 }
2727
2728 update_spdif_bits(ice, ice->pm_saved_spdif_ctrl);
2729
2730 outb(ice->pm_saved_spdif_cfg, ICEREG1724(ice, SPDIF_CFG));
2731 outl(ice->pm_saved_route, ICEMT1724(ice, ROUTE_PLAYBACK));
2732
2733 if (ice->ac97)
2734 snd_ac97_resume(ice->ac97);
2735
2736 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2737 return 0;
2738}
2739#endif
2740
2653static struct pci_driver driver = { 2741static struct pci_driver driver = {
2654 .name = "ICE1724", 2742 .name = "ICE1724",
2655 .id_table = snd_vt1724_ids, 2743 .id_table = snd_vt1724_ids,
2656 .probe = snd_vt1724_probe, 2744 .probe = snd_vt1724_probe,
2657 .remove = __devexit_p(snd_vt1724_remove), 2745 .remove = __devexit_p(snd_vt1724_remove),
2746#ifdef CONFIG_PM
2747 .suspend = snd_vt1724_suspend,
2748 .resume = snd_vt1724_resume,
2749#endif
2658}; 2750};
2659 2751
2660static int __init alsa_card_ice1724_init(void) 2752static int __init alsa_card_ice1724_init(void)
diff --git a/sound/pci/ice1712/prodigy_hifi.c b/sound/pci/ice1712/prodigy_hifi.c
index 043a93879bd..c75515f5be6 100644
--- a/sound/pci/ice1712/prodigy_hifi.c
+++ b/sound/pci/ice1712/prodigy_hifi.c
@@ -1077,7 +1077,7 @@ static int __devinit prodigy_hifi_init(struct snd_ice1712 *ice)
1077/* 1077/*
1078 * initialize the chip 1078 * initialize the chip
1079 */ 1079 */
1080static int __devinit prodigy_hd2_init(struct snd_ice1712 *ice) 1080static void ak4396_init(struct snd_ice1712 *ice)
1081{ 1081{
1082 static unsigned short ak4396_inits[] = { 1082 static unsigned short ak4396_inits[] = {
1083 AK4396_CTRL1, 0x87, /* I2S Normal Mode, 24 bit */ 1083 AK4396_CTRL1, 0x87, /* I2S Normal Mode, 24 bit */
@@ -1087,9 +1087,37 @@ static int __devinit prodigy_hd2_init(struct snd_ice1712 *ice)
1087 AK4396_RCH_ATT, 0x00, 1087 AK4396_RCH_ATT, 0x00,
1088 }; 1088 };
1089 1089
1090 struct prodigy_hifi_spec *spec;
1091 unsigned int i; 1090 unsigned int i;
1092 1091
1092 /* initialize ak4396 codec */
1093 /* reset codec */
1094 ak4396_write(ice, AK4396_CTRL1, 0x86);
1095 msleep(100);
1096 ak4396_write(ice, AK4396_CTRL1, 0x87);
1097
1098 for (i = 0; i < ARRAY_SIZE(ak4396_inits); i += 2)
1099 ak4396_write(ice, ak4396_inits[i], ak4396_inits[i+1]);
1100}
1101
1102#ifdef CONFIG_PM
1103static int __devinit prodigy_hd2_resume(struct snd_ice1712 *ice)
1104{
1105 /* initialize ak4396 codec and restore previous mixer volumes */
1106 struct prodigy_hifi_spec *spec = ice->spec;
1107 int i;
1108 mutex_lock(&ice->gpio_mutex);
1109 ak4396_init(ice);
1110 for (i = 0; i < 2; i++)
1111 ak4396_write(ice, AK4396_LCH_ATT + i, spec->vol[i] & 0xff);
1112 mutex_unlock(&ice->gpio_mutex);
1113 return 0;
1114}
1115#endif
1116
1117static int __devinit prodigy_hd2_init(struct snd_ice1712 *ice)
1118{
1119 struct prodigy_hifi_spec *spec;
1120
1093 ice->vt1720 = 0; 1121 ice->vt1720 = 0;
1094 ice->vt1724 = 1; 1122 ice->vt1724 = 1;
1095 1123
@@ -1112,14 +1140,12 @@ static int __devinit prodigy_hd2_init(struct snd_ice1712 *ice)
1112 return -ENOMEM; 1140 return -ENOMEM;
1113 ice->spec = spec; 1141 ice->spec = spec;
1114 1142
1115 /* initialize ak4396 codec */ 1143#ifdef CONFIG_PM
1116 /* reset codec */ 1144 ice->pm_resume = &prodigy_hd2_resume;
1117 ak4396_write(ice, AK4396_CTRL1, 0x86); 1145 ice->pm_suspend_enabled = 1;
1118 msleep(100); 1146#endif
1119 ak4396_write(ice, AK4396_CTRL1, 0x87); 1147
1120 1148 ak4396_init(ice);
1121 for (i = 0; i < ARRAY_SIZE(ak4396_inits); i += 2)
1122 ak4396_write(ice, ak4396_inits[i], ak4396_inits[i+1]);
1123 1149
1124 return 0; 1150 return 0;
1125} 1151}
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index c1eb923f2ac..09b2b2a36df 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -215,17 +215,8 @@ EXPORT_SYMBOL(oxygen_write_spi);
215 215
216void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data) 216void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data)
217{ 217{
218 unsigned long timeout;
219
220 /* should not need more than about 300 us */ 218 /* should not need more than about 300 us */
221 timeout = jiffies + msecs_to_jiffies(1); 219 msleep(1);
222 do {
223 if (!(oxygen_read16(chip, OXYGEN_2WIRE_BUS_STATUS)
224 & OXYGEN_2WIRE_BUSY))
225 break;
226 udelay(1);
227 cond_resched();
228 } while (time_after_eq(timeout, jiffies));
229 220
230 oxygen_write8(chip, OXYGEN_2WIRE_MAP, map); 221 oxygen_write8(chip, OXYGEN_2WIRE_MAP, map);
231 oxygen_write8(chip, OXYGEN_2WIRE_DATA, data); 222 oxygen_write8(chip, OXYGEN_2WIRE_DATA, data);
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 312251d3969..9a8936e2074 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -260,6 +260,9 @@ oxygen_search_pci_id(struct oxygen *chip, const struct pci_device_id ids[])
260 * chip didn't if the first EEPROM word was overwritten. 260 * chip didn't if the first EEPROM word was overwritten.
261 */ 261 */
262 subdevice = oxygen_read_eeprom(chip, 2); 262 subdevice = oxygen_read_eeprom(chip, 2);
263 /* use default ID if EEPROM is missing */
264 if (subdevice == 0xffff)
265 subdevice = 0x8788;
263 /* 266 /*
264 * We use only the subsystem device ID for searching because it is 267 * We use only the subsystem device ID for searching because it is
265 * unique even without the subsystem vendor ID, which may have been 268 * unique even without the subsystem vendor ID, which may have been
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index 3b5ca70c9d4..ef2345d82b8 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -469,9 +469,11 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
469 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, 469 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
470 oxygen_rate(hw_params) | 470 oxygen_rate(hw_params) |
471 chip->model.dac_i2s_format | 471 chip->model.dac_i2s_format |
472 oxygen_i2s_mclk(hw_params) |
472 oxygen_i2s_bits(hw_params), 473 oxygen_i2s_bits(hw_params),
473 OXYGEN_I2S_RATE_MASK | 474 OXYGEN_I2S_RATE_MASK |
474 OXYGEN_I2S_FORMAT_MASK | 475 OXYGEN_I2S_FORMAT_MASK |
476 OXYGEN_I2S_MCLK_MASK |
475 OXYGEN_I2S_BITS_MASK); 477 OXYGEN_I2S_BITS_MASK);
476 oxygen_update_dac_routing(chip); 478 oxygen_update_dac_routing(chip);
477 oxygen_update_spdif_source(chip); 479 oxygen_update_spdif_source(chip);
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index bf971f7cfdc..6ebcb6bdd71 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -635,6 +635,8 @@ static void xonar_d2_resume(struct oxygen *chip)
635 635
636static void xonar_d1_resume(struct oxygen *chip) 636static void xonar_d1_resume(struct oxygen *chip)
637{ 637{
638 oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
639 msleep(1);
638 cs43xx_init(chip); 640 cs43xx_init(chip);
639 xonar_enable_output(chip); 641 xonar_enable_output(chip);
640} 642}
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 235a71e5ac8..b5ca02e2038 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -2197,9 +2197,12 @@ static int __init alsa_card_riptide_init(void)
2197 if (err < 0) 2197 if (err < 0)
2198 return err; 2198 return err;
2199#if defined(SUPPORT_JOYSTICK) 2199#if defined(SUPPORT_JOYSTICK)
2200 pci_register_driver(&joystick_driver); 2200 err = pci_register_driver(&joystick_driver);
2201 /* On failure unregister formerly registered audio driver */
2202 if (err < 0)
2203 pci_unregister_driver(&driver);
2201#endif 2204#endif
2202 return 0; 2205 return err;
2203} 2206}
2204 2207
2205static void __exit alsa_card_riptide_exit(void) 2208static void __exit alsa_card_riptide_exit(void)
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 3da5c029f93..7bb827c7d80 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -3294,15 +3294,33 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3294 char *clock_source; 3294 char *clock_source;
3295 int x; 3295 int x;
3296 3296
3297 if (hdsp_check_for_iobox (hdsp)) { 3297 status = hdsp_read(hdsp, HDSP_statusRegister);
3298 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n"); 3298 status2 = hdsp_read(hdsp, HDSP_status2Register);
3299
3300 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name,
3301 hdsp->card->number + 1);
3302 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3303 hdsp->capture_buffer, hdsp->playback_buffer);
3304 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3305 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3306 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3307 snd_iprintf(buffer, "Control2 register: 0x%x\n",
3308 hdsp->control2_register);
3309 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3310 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3311
3312 if (hdsp_check_for_iobox(hdsp)) {
3313 snd_iprintf(buffer, "No I/O box connected.\n"
3314 "Please connect one and upload firmware.\n");
3299 return; 3315 return;
3300 } 3316 }
3301 3317
3302 if (hdsp_check_for_firmware(hdsp, 0)) { 3318 if (hdsp_check_for_firmware(hdsp, 0)) {
3303 if (hdsp->state & HDSP_FirmwareCached) { 3319 if (hdsp->state & HDSP_FirmwareCached) {
3304 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) { 3320 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3305 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n"); 3321 snd_iprintf(buffer, "Firmware loading from "
3322 "cache failed, "
3323 "please upload manually.\n");
3306 return; 3324 return;
3307 } 3325 }
3308 } else { 3326 } else {
@@ -3319,18 +3337,6 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3319 } 3337 }
3320 } 3338 }
3321 3339
3322 status = hdsp_read(hdsp, HDSP_statusRegister);
3323 status2 = hdsp_read(hdsp, HDSP_status2Register);
3324
3325 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3326 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3327 hdsp->capture_buffer, hdsp->playback_buffer);
3328 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3329 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3330 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3331 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
3332 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3333 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3334 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff); 3340 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3335 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0)); 3341 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3336 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0)); 3342 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
@@ -3351,7 +3357,6 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3351 3357
3352 snd_iprintf(buffer, "\n"); 3358 snd_iprintf(buffer, "\n");
3353 3359
3354
3355 switch (hdsp_clock_source(hdsp)) { 3360 switch (hdsp_clock_source(hdsp)) {
3356 case HDSP_CLOCK_SOURCE_AUTOSYNC: 3361 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3357 clock_source = "AutoSync"; 3362 clock_source = "AutoSync";
diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c
index 6416d3f0c7b..a69e774d0b1 100644
--- a/sound/pci/vx222/vx222_ops.c
+++ b/sound/pci/vx222/vx222_ops.c
@@ -885,10 +885,10 @@ static int vx_input_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
885 struct vx_core *_chip = snd_kcontrol_chip(kcontrol); 885 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
886 struct snd_vx222 *chip = (struct snd_vx222 *)_chip; 886 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
887 if (ucontrol->value.integer.value[0] < 0 || 887 if (ucontrol->value.integer.value[0] < 0 ||
888 ucontrol->value.integer.value[0] < MIC_LEVEL_MAX) 888 ucontrol->value.integer.value[0] > MIC_LEVEL_MAX)
889 return -EINVAL; 889 return -EINVAL;
890 if (ucontrol->value.integer.value[1] < 0 || 890 if (ucontrol->value.integer.value[1] < 0 ||
891 ucontrol->value.integer.value[1] < MIC_LEVEL_MAX) 891 ucontrol->value.integer.value[1] > MIC_LEVEL_MAX)
892 return -EINVAL; 892 return -EINVAL;
893 mutex_lock(&_chip->mixer_mutex); 893 mutex_lock(&_chip->mixer_mutex);
894 if (chip->input_level[0] != ucontrol->value.integer.value[0] || 894 if (chip->input_level[0] != ucontrol->value.integer.value[0] ||
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 2f0925236a1..5518371db13 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -834,7 +834,7 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
834 status = snd_ymfpci_readw(chip, YDSXGR_INTFLAG); 834 status = snd_ymfpci_readw(chip, YDSXGR_INTFLAG);
835 if (status & 1) { 835 if (status & 1) {
836 if (chip->timer) 836 if (chip->timer)
837 snd_timer_interrupt(chip->timer, chip->timer->sticks); 837 snd_timer_interrupt(chip->timer, chip->timer_ticks);
838 } 838 }
839 snd_ymfpci_writew(chip, YDSXGR_INTFLAG, status); 839 snd_ymfpci_writew(chip, YDSXGR_INTFLAG, status);
840 840
@@ -1885,8 +1885,18 @@ static int snd_ymfpci_timer_start(struct snd_timer *timer)
1885 unsigned int count; 1885 unsigned int count;
1886 1886
1887 chip = snd_timer_chip(timer); 1887 chip = snd_timer_chip(timer);
1888 count = (timer->sticks << 1) - 1;
1889 spin_lock_irqsave(&chip->reg_lock, flags); 1888 spin_lock_irqsave(&chip->reg_lock, flags);
1889 if (timer->sticks > 1) {
1890 chip->timer_ticks = timer->sticks;
1891 count = timer->sticks - 1;
1892 } else {
1893 /*
1894 * Divisor 1 is not allowed; fake it by using divisor 2 and
1895 * counting two ticks for each interrupt.
1896 */
1897 chip->timer_ticks = 2;
1898 count = 2 - 1;
1899 }
1890 snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count); 1900 snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count);
1891 snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03); 1901 snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03);
1892 spin_unlock_irqrestore(&chip->reg_lock, flags); 1902 spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -1909,14 +1919,14 @@ static int snd_ymfpci_timer_precise_resolution(struct snd_timer *timer,
1909 unsigned long *num, unsigned long *den) 1919 unsigned long *num, unsigned long *den)
1910{ 1920{
1911 *num = 1; 1921 *num = 1;
1912 *den = 48000; 1922 *den = 96000;
1913 return 0; 1923 return 0;
1914} 1924}
1915 1925
1916static struct snd_timer_hardware snd_ymfpci_timer_hw = { 1926static struct snd_timer_hardware snd_ymfpci_timer_hw = {
1917 .flags = SNDRV_TIMER_HW_AUTO, 1927 .flags = SNDRV_TIMER_HW_AUTO,
1918 .resolution = 20833, /* 1/fs = 20.8333...us */ 1928 .resolution = 10417, /* 1 / 96 kHz = 10.41666...us */
1919 .ticks = 0x8000, 1929 .ticks = 0x10000,
1920 .start = snd_ymfpci_timer_start, 1930 .start = snd_ymfpci_timer_start,
1921 .stop = snd_ymfpci_timer_stop, 1931 .stop = snd_ymfpci_timer_stop,
1922 .precise_resolution = snd_ymfpci_timer_precise_resolution, 1932 .precise_resolution = snd_ymfpci_timer_precise_resolution,