aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2009-10-06 11:01:27 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2009-10-06 11:01:27 -0400
commit907bc6c7fc7071b00083fc11e510e47dd93df45d (patch)
tree0697a608561522c00da9e1814974a2eb051bb96d /sound
parentd2b247a8be57647d1745535acd58169fbcbe431a (diff)
parent2a0f5cb32772e9a9560209e241a80bfbbc31dbc3 (diff)
Merge branch 'for-2.6.32' into for-2.6.33
Diffstat (limited to 'sound')
-rw-r--r--sound/Kconfig28
-rw-r--r--sound/aoa/codecs/tas.c9
-rw-r--r--sound/aoa/core/gpio-pmf.c4
-rw-r--r--sound/arm/pxa2xx-ac97.c20
-rw-r--r--sound/core/Kconfig4
-rw-r--r--sound/core/Makefile2
-rw-r--r--sound/core/control.c34
-rw-r--r--sound/core/info.c8
-rw-r--r--sound/core/init.c8
-rw-r--r--sound/core/memalloc.c4
-rw-r--r--sound/core/misc.c75
-rw-r--r--sound/core/oss/mixer_oss.c3
-rw-r--r--sound/core/oss/pcm_oss.c12
-rw-r--r--sound/core/pcm.c26
-rw-r--r--sound/core/pcm_lib.c87
-rw-r--r--sound/core/pcm_memory.c2
-rw-r--r--sound/core/pcm_native.c121
-rw-r--r--sound/core/rawmidi.c2
-rw-r--r--sound/core/seq/Makefile7
-rw-r--r--sound/core/seq/oss/seq_oss_midi.c14
-rw-r--r--sound/core/seq/seq_midi.c7
-rw-r--r--sound/core/vmaster.c8
-rw-r--r--sound/drivers/dummy.c700
-rw-r--r--sound/isa/cmi8330.c88
-rw-r--r--sound/isa/gus/gus_pcm.c4
-rw-r--r--sound/mips/hal2.c2
-rw-r--r--sound/mips/sgio2audio.c2
-rw-r--r--sound/oss/aedsp16.c9
-rw-r--r--sound/oss/kahlua.c2
-rw-r--r--sound/oss/midibuf.c7
-rw-r--r--sound/oss/mpu401.c18
-rw-r--r--sound/oss/swarm_cs4297a.c3
-rw-r--r--sound/oss/sys_timer.c3
-rw-r--r--sound/oss/vwsnd.c6
-rw-r--r--sound/pci/Kconfig4
-rw-r--r--sound/pci/ali5451/ali5451.c83
-rw-r--r--sound/pci/atiixp.c8
-rw-r--r--sound/pci/atiixp_modem.c4
-rw-r--r--sound/pci/au88x0/au8810.c3
-rw-r--r--sound/pci/au88x0/au8820.c3
-rw-r--r--sound/pci/au88x0/au8830.c3
-rw-r--r--sound/pci/azt3328.c1116
-rw-r--r--sound/pci/azt3328.h103
-rw-r--r--sound/pci/ca0106/ca0106_main.c6
-rw-r--r--sound/pci/cmipci.c10
-rw-r--r--sound/pci/cs4281.c2
-rw-r--r--sound/pci/cs46xx/cs46xx.c6
-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.c81
-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/echoaudio/echoaudio.c30
-rw-r--r--sound/pci/echoaudio/mia.c1
-rw-r--r--sound/pci/emu10k1/emu10k1.c6
-rw-r--r--sound/pci/emu10k1/emu10k1x.c2
-rw-r--r--sound/pci/emu10k1/p16v.c2
-rw-r--r--sound/pci/ens1370.c8
-rw-r--r--sound/pci/es1938.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.c207
-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.c406
-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.c491
-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.c4567
-rw-r--r--sound/pci/hda/patch_sigmatel.c1291
-rw-r--r--sound/pci/hda/patch_via.c89
-rw-r--r--sound/pci/ice1712/ice1712.c2
-rw-r--r--sound/pci/ice1712/ice1712.h9
-rw-r--r--sound/pci/ice1712/ice1724.c114
-rw-r--r--sound/pci/ice1712/prodigy_hifi.c46
-rw-r--r--sound/pci/intel8x0.c58
-rw-r--r--sound/pci/intel8x0m.c34
-rw-r--r--sound/pci/lx6464es/lx6464es.c7
-rw-r--r--sound/pci/lx6464es/lx6464es.h2
-rw-r--r--sound/pci/lx6464es/lx_core.c98
-rw-r--r--sound/pci/mixart/mixart.c2
-rw-r--r--sound/pci/nm256/nm256.c6
-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_mixer.c28
-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/rme32.c9
-rw-r--r--sound/pci/rme96.c12
-rw-r--r--sound/pci/rme9652/hdsp.c39
-rw-r--r--sound/pci/sonicvibes.c2
-rw-r--r--sound/pci/via82xx.c4
-rw-r--r--sound/pci/via82xx_modem.c2
-rw-r--r--sound/pci/vx222/vx222_ops.c4
-rw-r--r--sound/pci/ymfpci/ymfpci.c12
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c20
-rw-r--r--sound/ppc/keywest.c14
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c36
-rw-r--r--sound/soc/codecs/wm8988.c4
-rw-r--r--sound/soc/codecs/wm9081.c2
-rw-r--r--sound/soc/davinci/davinci-pcm.c6
-rw-r--r--sound/soc/fsl/efika-audio-fabric.c2
-rw-r--r--sound/soc/fsl/pcm030-audio-fabric.c2
-rw-r--r--sound/soc/pxa/pxa-ssp.c2
-rw-r--r--sound/soc/s3c24xx/s3c24xx-ac97.h6
-rw-r--r--sound/soc/s3c24xx/s3c24xx_uda134x.c2
-rw-r--r--sound/sound_core.c109
-rw-r--r--sound/usb/Kconfig1
-rw-r--r--sound/usb/caiaq/audio.c1
-rw-r--r--sound/usb/caiaq/device.c16
-rw-r--r--sound/usb/caiaq/device.h1
-rw-r--r--sound/usb/usbaudio.c20
-rw-r--r--sound/usb/usbmidi.c290
-rw-r--r--sound/usb/usbmixer.c121
-rw-r--r--sound/usb/usx2y/us122l.c4
-rw-r--r--sound/usb/usx2y/usX2Yhwdep.c2
-rw-r--r--sound/usb/usx2y/usbusx2y.c2
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c7
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c2
137 files changed, 8136 insertions, 4867 deletions
diff --git a/sound/Kconfig b/sound/Kconfig
index 1eceb85287c5..439e15c8faa3 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -32,6 +32,34 @@ config SOUND_OSS_CORE
32 bool 32 bool
33 default n 33 default n
34 34
35config SOUND_OSS_CORE_PRECLAIM
36 bool "Preclaim OSS device numbers"
37 depends on SOUND_OSS_CORE
38 default y
39 help
40 With this option enabled, the kernel will claim all OSS device
41 numbers if any OSS support (native or emulation) is enabled
42 whether the respective module is loaded or not and try to load the
43 appropriate module using sound-slot/service-* and char-major-*
44 module aliases when one of the device numbers is opened. With
45 this option disabled, kernel will only claim actually in-use
46 device numbers and opening a missing device will generate only the
47 standard char-major-* aliases.
48
49 The only visible difference is use of additional module aliases
50 and whether OSS sound devices appear multiple times in
51 /proc/devices. sound-slot/service-* module aliases are scheduled
52 to be removed (ie. PRECLAIM won't be available) and this option is
53 to make the transition easier. This option can be overridden
54 during boot using the kernel parameter soundcore.preclaim_oss.
55
56 Disabling this allows alternative OSS implementations.
57
58 Please read Documentation/feature-removal-schedule.txt for
59 details.
60
61 If unusre, say Y.
62
35source "sound/oss/dmasound/Kconfig" 63source "sound/oss/dmasound/Kconfig"
36 64
37if !M68K 65if !M68K
diff --git a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c
index f0ebc971c686..1dd66ddffcaf 100644
--- a/sound/aoa/codecs/tas.c
+++ b/sound/aoa/codecs/tas.c
@@ -897,6 +897,15 @@ static int tas_create(struct i2c_adapter *adapter,
897 client = i2c_new_device(adapter, &info); 897 client = i2c_new_device(adapter, &info);
898 if (!client) 898 if (!client)
899 return -ENODEV; 899 return -ENODEV;
900 /*
901 * We know the driver is already loaded, so the device should be
902 * already bound. If not it means binding failed, and then there
903 * is no point in keeping the device instantiated.
904 */
905 if (!client->driver) {
906 i2c_unregister_device(client);
907 return -ENODEV;
908 }
900 909
901 /* 910 /*
902 * Let i2c-core delete that device on driver removal. 911 * Let i2c-core delete that device on driver removal.
diff --git a/sound/aoa/core/gpio-pmf.c b/sound/aoa/core/gpio-pmf.c
index 5ca2220eac7d..1dd0c28d1fb7 100644
--- a/sound/aoa/core/gpio-pmf.c
+++ b/sound/aoa/core/gpio-pmf.c
@@ -182,6 +182,10 @@ static int pmf_set_notify(struct gpio_runtime *rt,
182 if (!old && notify) { 182 if (!old && notify) {
183 irq_client = kzalloc(sizeof(struct pmf_irq_client), 183 irq_client = kzalloc(sizeof(struct pmf_irq_client),
184 GFP_KERNEL); 184 GFP_KERNEL);
185 if (!irq_client) {
186 err = -ENOMEM;
187 goto out_unlock;
188 }
185 irq_client->data = notif; 189 irq_client->data = notif;
186 irq_client->handler = pmf_handle_notify_irq; 190 irq_client->handler = pmf_handle_notify_irq;
187 irq_client->owner = THIS_MODULE; 191 irq_client->owner = THIS_MODULE;
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index 4e34d19ddbc0..b4b48afb6de6 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -137,9 +137,9 @@ static int pxa2xx_ac97_do_resume(struct snd_card *card)
137 return 0; 137 return 0;
138} 138}
139 139
140static int pxa2xx_ac97_suspend(struct platform_device *dev, pm_message_t state) 140static int pxa2xx_ac97_suspend(struct device *dev)
141{ 141{
142 struct snd_card *card = platform_get_drvdata(dev); 142 struct snd_card *card = dev_get_drvdata(dev);
143 int ret = 0; 143 int ret = 0;
144 144
145 if (card) 145 if (card)
@@ -148,9 +148,9 @@ static int pxa2xx_ac97_suspend(struct platform_device *dev, pm_message_t state)
148 return ret; 148 return ret;
149} 149}
150 150
151static int pxa2xx_ac97_resume(struct platform_device *dev) 151static int pxa2xx_ac97_resume(struct device *dev)
152{ 152{
153 struct snd_card *card = platform_get_drvdata(dev); 153 struct snd_card *card = dev_get_drvdata(dev);
154 int ret = 0; 154 int ret = 0;
155 155
156 if (card) 156 if (card)
@@ -159,9 +159,10 @@ static int pxa2xx_ac97_resume(struct platform_device *dev)
159 return ret; 159 return ret;
160} 160}
161 161
162#else 162static struct dev_pm_ops pxa2xx_ac97_pm_ops = {
163#define pxa2xx_ac97_suspend NULL 163 .suspend = pxa2xx_ac97_suspend,
164#define pxa2xx_ac97_resume NULL 164 .resume = pxa2xx_ac97_resume,
165};
165#endif 166#endif
166 167
167static int __devinit pxa2xx_ac97_probe(struct platform_device *dev) 168static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
@@ -241,11 +242,12 @@ static int __devexit pxa2xx_ac97_remove(struct platform_device *dev)
241static struct platform_driver pxa2xx_ac97_driver = { 242static struct platform_driver pxa2xx_ac97_driver = {
242 .probe = pxa2xx_ac97_probe, 243 .probe = pxa2xx_ac97_probe,
243 .remove = __devexit_p(pxa2xx_ac97_remove), 244 .remove = __devexit_p(pxa2xx_ac97_remove),
244 .suspend = pxa2xx_ac97_suspend,
245 .resume = pxa2xx_ac97_resume,
246 .driver = { 245 .driver = {
247 .name = "pxa2xx-ac97", 246 .name = "pxa2xx-ac97",
248 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
248#ifdef CONFIG_PM
249 .pm = &pxa2xx_ac97_pm_ops,
250#endif
249 }, 251 },
250}; 252};
251 253
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 6061fb5f4e1c..c15682a2f9db 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -206,4 +206,8 @@ config SND_PCM_XRUN_DEBUG
206config SND_VMASTER 206config SND_VMASTER
207 bool 207 bool
208 208
209config SND_DMA_SGBUF
210 def_bool y
211 depends on X86
212
209source "sound/core/seq/Kconfig" 213source "sound/core/seq/Kconfig"
diff --git a/sound/core/Makefile b/sound/core/Makefile
index 4229052e7b91..350a08d277f4 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -13,7 +13,7 @@ snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \
13 pcm_memory.o 13 pcm_memory.o
14 14
15snd-page-alloc-y := memalloc.o 15snd-page-alloc-y := memalloc.o
16snd-page-alloc-$(CONFIG_HAS_DMA) += sgbuf.o 16snd-page-alloc-$(CONFIG_SND_DMA_SGBUF) += sgbuf.o
17 17
18snd-rawmidi-objs := rawmidi.o 18snd-rawmidi-objs := rawmidi.o
19snd-timer-objs := timer.o 19snd-timer-objs := timer.o
diff --git a/sound/core/control.c b/sound/core/control.c
index 17b8d47a5cd0..a8b7fabe645e 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -414,7 +414,7 @@ int snd_ctl_remove_id(struct snd_card *card, struct snd_ctl_elem_id *id)
414EXPORT_SYMBOL(snd_ctl_remove_id); 414EXPORT_SYMBOL(snd_ctl_remove_id);
415 415
416/** 416/**
417 * snd_ctl_remove_unlocked_id - remove the unlocked control of the given id and release it 417 * snd_ctl_remove_user_ctl - remove and release the unlocked user control
418 * @file: active control handle 418 * @file: active control handle
419 * @id: the control id to remove 419 * @id: the control id to remove
420 * 420 *
@@ -423,8 +423,8 @@ EXPORT_SYMBOL(snd_ctl_remove_id);
423 * 423 *
424 * Returns 0 if successful, or a negative error code on failure. 424 * Returns 0 if successful, or a negative error code on failure.
425 */ 425 */
426static int snd_ctl_remove_unlocked_id(struct snd_ctl_file * file, 426static int snd_ctl_remove_user_ctl(struct snd_ctl_file * file,
427 struct snd_ctl_elem_id *id) 427 struct snd_ctl_elem_id *id)
428{ 428{
429 struct snd_card *card = file->card; 429 struct snd_card *card = file->card;
430 struct snd_kcontrol *kctl; 430 struct snd_kcontrol *kctl;
@@ -433,15 +433,23 @@ static int snd_ctl_remove_unlocked_id(struct snd_ctl_file * file,
433 down_write(&card->controls_rwsem); 433 down_write(&card->controls_rwsem);
434 kctl = snd_ctl_find_id(card, id); 434 kctl = snd_ctl_find_id(card, id);
435 if (kctl == NULL) { 435 if (kctl == NULL) {
436 up_write(&card->controls_rwsem); 436 ret = -ENOENT;
437 return -ENOENT; 437 goto error;
438 }
439 if (!(kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_USER)) {
440 ret = -EINVAL;
441 goto error;
438 } 442 }
439 for (idx = 0; idx < kctl->count; idx++) 443 for (idx = 0; idx < kctl->count; idx++)
440 if (kctl->vd[idx].owner != NULL && kctl->vd[idx].owner != file) { 444 if (kctl->vd[idx].owner != NULL && kctl->vd[idx].owner != file) {
441 up_write(&card->controls_rwsem); 445 ret = -EBUSY;
442 return -EBUSY; 446 goto error;
443 } 447 }
444 ret = snd_ctl_remove(card, kctl); 448 ret = snd_ctl_remove(card, kctl);
449 if (ret < 0)
450 goto error;
451 card->user_ctl_count--;
452error:
445 up_write(&card->controls_rwsem); 453 up_write(&card->controls_rwsem);
446 return ret; 454 return ret;
447} 455}
@@ -951,7 +959,7 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
951 959
952 if (card->user_ctl_count >= MAX_USER_CONTROLS) 960 if (card->user_ctl_count >= MAX_USER_CONTROLS)
953 return -ENOMEM; 961 return -ENOMEM;
954 if (info->count > 1024) 962 if (info->count < 1)
955 return -EINVAL; 963 return -EINVAL;
956 access = info->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE : 964 access = info->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
957 (info->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE| 965 (info->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE|
@@ -1052,18 +1060,10 @@ static int snd_ctl_elem_remove(struct snd_ctl_file *file,
1052 struct snd_ctl_elem_id __user *_id) 1060 struct snd_ctl_elem_id __user *_id)
1053{ 1061{
1054 struct snd_ctl_elem_id id; 1062 struct snd_ctl_elem_id id;
1055 int err;
1056 1063
1057 if (copy_from_user(&id, _id, sizeof(id))) 1064 if (copy_from_user(&id, _id, sizeof(id)))
1058 return -EFAULT; 1065 return -EFAULT;
1059 err = snd_ctl_remove_unlocked_id(file, &id); 1066 return snd_ctl_remove_user_ctl(file, &id);
1060 if (! err) {
1061 struct snd_card *card = file->card;
1062 down_write(&card->controls_rwsem);
1063 card->user_ctl_count--;
1064 up_write(&card->controls_rwsem);
1065 }
1066 return err;
1067} 1067}
1068 1068
1069static int snd_ctl_subscribe_events(struct snd_ctl_file *file, int __user *ptr) 1069static int snd_ctl_subscribe_events(struct snd_ctl_file *file, int __user *ptr)
diff --git a/sound/core/info.c b/sound/core/info.c
index 35df614f6c55..d749a0d394a7 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -88,12 +88,10 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,
88 char *nbuf; 88 char *nbuf;
89 89
90 nsize = PAGE_ALIGN(nsize); 90 nsize = PAGE_ALIGN(nsize);
91 nbuf = kmalloc(nsize, GFP_KERNEL); 91 nbuf = krealloc(buffer->buffer, nsize, GFP_KERNEL);
92 if (! nbuf) 92 if (! nbuf)
93 return -ENOMEM; 93 return -ENOMEM;
94 94
95 memcpy(nbuf, buffer->buffer, buffer->len);
96 kfree(buffer->buffer);
97 buffer->buffer = nbuf; 95 buffer->buffer = nbuf;
98 buffer->len = nsize; 96 buffer->len = nsize;
99 return 0; 97 return 0;
@@ -108,7 +106,7 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,
108 * 106 *
109 * Returns the size of output string. 107 * Returns the size of output string.
110 */ 108 */
111int snd_iprintf(struct snd_info_buffer *buffer, char *fmt,...) 109int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...)
112{ 110{
113 va_list args; 111 va_list args;
114 int len, res; 112 int len, res;
@@ -727,7 +725,7 @@ EXPORT_SYMBOL(snd_info_get_line);
727 * Returns the updated pointer of the original string so that 725 * Returns the updated pointer of the original string so that
728 * it can be used for the next call. 726 * it can be used for the next call.
729 */ 727 */
730char *snd_info_get_str(char *dest, char *src, int len) 728const char *snd_info_get_str(char *dest, const char *src, int len)
731{ 729{
732 int c; 730 int c;
733 731
diff --git a/sound/core/init.c b/sound/core/init.c
index d5d40d78c409..ec4a50ce5656 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -31,6 +31,14 @@
31#include <sound/control.h> 31#include <sound/control.h>
32#include <sound/info.h> 32#include <sound/info.h>
33 33
34/* monitor files for graceful shutdown (hotplug) */
35struct snd_monitor_file {
36 struct file *file;
37 const struct file_operations *disconnected_f_op;
38 struct list_head shutdown_list; /* still need to shutdown */
39 struct list_head list; /* link of monitor files */
40};
41
34static DEFINE_SPINLOCK(shutdown_lock); 42static DEFINE_SPINLOCK(shutdown_lock);
35static LIST_HEAD(shutdown_files); 43static LIST_HEAD(shutdown_files);
36 44
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 1b3534d67686..9e92441f9b78 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -199,6 +199,8 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
199 case SNDRV_DMA_TYPE_DEV: 199 case SNDRV_DMA_TYPE_DEV:
200 dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr); 200 dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
201 break; 201 break;
202#endif
203#ifdef CONFIG_SND_DMA_SGBUF
202 case SNDRV_DMA_TYPE_DEV_SG: 204 case SNDRV_DMA_TYPE_DEV_SG:
203 snd_malloc_sgbuf_pages(device, size, dmab, NULL); 205 snd_malloc_sgbuf_pages(device, size, dmab, NULL);
204 break; 206 break;
@@ -269,6 +271,8 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
269 case SNDRV_DMA_TYPE_DEV: 271 case SNDRV_DMA_TYPE_DEV:
270 snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); 272 snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
271 break; 273 break;
274#endif
275#ifdef CONFIG_SND_DMA_SGBUF
272 case SNDRV_DMA_TYPE_DEV_SG: 276 case SNDRV_DMA_TYPE_DEV_SG:
273 snd_free_sgbuf_pages(dmab); 277 snd_free_sgbuf_pages(dmab);
274 break; 278 break;
diff --git a/sound/core/misc.c b/sound/core/misc.c
index a9710e0c97af..23a032c6d487 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -24,6 +24,20 @@
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <sound/core.h> 25#include <sound/core.h>
26 26
27#ifdef CONFIG_SND_DEBUG
28
29#ifdef CONFIG_SND_DEBUG_VERBOSE
30#define DEFAULT_DEBUG_LEVEL 2
31#else
32#define DEFAULT_DEBUG_LEVEL 1
33#endif
34
35static int debug = DEFAULT_DEBUG_LEVEL;
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "Debug level (0 = disable)");
38
39#endif /* CONFIG_SND_DEBUG */
40
27void release_and_free_resource(struct resource *res) 41void release_and_free_resource(struct resource *res)
28{ 42{
29 if (res) { 43 if (res) {
@@ -35,46 +49,53 @@ void release_and_free_resource(struct resource *res)
35EXPORT_SYMBOL(release_and_free_resource); 49EXPORT_SYMBOL(release_and_free_resource);
36 50
37#ifdef CONFIG_SND_VERBOSE_PRINTK 51#ifdef CONFIG_SND_VERBOSE_PRINTK
38void snd_verbose_printk(const char *file, int line, const char *format, ...) 52/* strip the leading path if the given path is absolute */
53static const char *sanity_file_name(const char *path)
39{ 54{
40 va_list args; 55 if (*path == '/')
41 56 return strrchr(path, '/') + 1;
42 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') { 57 else
43 char tmp[] = "<0>"; 58 return path;
59}
60
61/* print file and line with a certain printk prefix */
62static int print_snd_pfx(unsigned int level, const char *path, int line,
63 const char *format)
64{
65 const char *file = sanity_file_name(path);
66 char tmp[] = "<0>";
67 const char *pfx = level ? KERN_DEBUG : KERN_DEFAULT;
68 int ret = 0;
69
70 if (format[0] == '<' && format[2] == '>') {
44 tmp[1] = format[1]; 71 tmp[1] = format[1];
45 printk("%sALSA %s:%d: ", tmp, file, line); 72 pfx = tmp;
46 format += 3; 73 ret = 1;
47 } else {
48 printk("ALSA %s:%d: ", file, line);
49 } 74 }
50 va_start(args, format); 75 printk("%sALSA %s:%d: ", pfx, file, line);
51 vprintk(format, args); 76 return ret;
52 va_end(args);
53} 77}
54 78#else
55EXPORT_SYMBOL(snd_verbose_printk); 79#define print_snd_pfx(level, path, line, format) 0
56#endif 80#endif
57 81
58#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK) 82#if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
59void snd_verbose_printd(const char *file, int line, const char *format, ...) 83void __snd_printk(unsigned int level, const char *path, int line,
84 const char *format, ...)
60{ 85{
61 va_list args; 86 va_list args;
62 87
63 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') { 88#ifdef CONFIG_SND_DEBUG
64 char tmp[] = "<0>"; 89 if (debug < level)
65 tmp[1] = format[1]; 90 return;
66 printk("%sALSA %s:%d: ", tmp, file, line); 91#endif
67 format += 3;
68 } else {
69 printk(KERN_DEBUG "ALSA %s:%d: ", file, line);
70 }
71 va_start(args, format); 92 va_start(args, format);
93 if (print_snd_pfx(level, path, line, format))
94 format += 3; /* skip the printk level-prefix */
72 vprintk(format, args); 95 vprintk(format, args);
73 va_end(args); 96 va_end(args);
74
75} 97}
76 98EXPORT_SYMBOL_GPL(__snd_printk);
77EXPORT_SYMBOL(snd_verbose_printd);
78#endif 99#endif
79 100
80#ifdef CONFIG_PCI 101#ifdef CONFIG_PCI
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 5dcd8a526970..772423889eb3 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1154,7 +1154,8 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
1154 struct snd_info_buffer *buffer) 1154 struct snd_info_buffer *buffer)
1155{ 1155{
1156 struct snd_mixer_oss *mixer = entry->private_data; 1156 struct snd_mixer_oss *mixer = entry->private_data;
1157 char line[128], str[32], idxstr[16], *cptr; 1157 char line[128], str[32], idxstr[16];
1158 const char *cptr;
1158 int ch, idx; 1159 int ch, idx;
1159 struct snd_mixer_oss_assign_table *tbl; 1160 struct snd_mixer_oss_assign_table *tbl;
1160 struct slot *slot; 1161 struct slot *slot;
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index dbe406b82591..d9c96353121a 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -1043,10 +1043,15 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
1043 runtime->oss.channels = params_channels(params); 1043 runtime->oss.channels = params_channels(params);
1044 runtime->oss.rate = params_rate(params); 1044 runtime->oss.rate = params_rate(params);
1045 1045
1046 runtime->oss.params = 0;
1047 runtime->oss.prepare = 1;
1048 vfree(runtime->oss.buffer); 1046 vfree(runtime->oss.buffer);
1049 runtime->oss.buffer = vmalloc(runtime->oss.period_bytes); 1047 runtime->oss.buffer = vmalloc(runtime->oss.period_bytes);
1048 if (!runtime->oss.buffer) {
1049 err = -ENOMEM;
1050 goto failure;
1051 }
1052
1053 runtime->oss.params = 0;
1054 runtime->oss.prepare = 1;
1050 runtime->oss.buffer_used = 0; 1055 runtime->oss.buffer_used = 0;
1051 if (runtime->dma_area) 1056 if (runtime->dma_area)
1052 snd_pcm_format_set_silence(runtime->format, runtime->dma_area, bytes_to_samples(runtime, runtime->dma_bytes)); 1057 snd_pcm_format_set_silence(runtime->format, runtime->dma_area, bytes_to_samples(runtime, runtime->dma_bytes));
@@ -2836,7 +2841,8 @@ static void snd_pcm_oss_proc_write(struct snd_info_entry *entry,
2836 struct snd_info_buffer *buffer) 2841 struct snd_info_buffer *buffer)
2837{ 2842{
2838 struct snd_pcm_str *pstr = entry->private_data; 2843 struct snd_pcm_str *pstr = entry->private_data;
2839 char line[128], str[32], task_name[32], *ptr; 2844 char line[128], str[32], task_name[32];
2845 const char *ptr;
2840 int idx1; 2846 int idx1;
2841 struct snd_pcm_oss_setup *setup, *setup1, template; 2847 struct snd_pcm_oss_setup *setup, *setup1, template;
2842 2848
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 145931a9ff30..0c1440121c22 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -162,18 +162,7 @@ static int snd_pcm_control_ioctl(struct snd_card *card,
162 return -ENOIOCTLCMD; 162 return -ENOIOCTLCMD;
163} 163}
164 164
165#ifdef CONFIG_SND_VERBOSE_PROCFS
166
167#define STATE(v) [SNDRV_PCM_STATE_##v] = #v
168#define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v
169#define READY(v) [SNDRV_PCM_READY_##v] = #v
170#define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v
171#define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v
172#define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v
173#define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v
174#define START(v) [SNDRV_PCM_START_##v] = #v
175#define FORMAT(v) [SNDRV_PCM_FORMAT_##v] = #v 165#define FORMAT(v) [SNDRV_PCM_FORMAT_##v] = #v
176#define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v
177 166
178static char *snd_pcm_format_names[] = { 167static char *snd_pcm_format_names[] = {
179 FORMAT(S8), 168 FORMAT(S8),
@@ -216,10 +205,23 @@ static char *snd_pcm_format_names[] = {
216 FORMAT(U18_3BE), 205 FORMAT(U18_3BE),
217}; 206};
218 207
219static const char *snd_pcm_format_name(snd_pcm_format_t format) 208const char *snd_pcm_format_name(snd_pcm_format_t format)
220{ 209{
221 return snd_pcm_format_names[format]; 210 return snd_pcm_format_names[format];
222} 211}
212EXPORT_SYMBOL_GPL(snd_pcm_format_name);
213
214#ifdef CONFIG_SND_VERBOSE_PROCFS
215
216#define STATE(v) [SNDRV_PCM_STATE_##v] = #v
217#define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v
218#define READY(v) [SNDRV_PCM_READY_##v] = #v
219#define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v
220#define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v
221#define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v
222#define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v
223#define START(v) [SNDRV_PCM_START_##v] = #v
224#define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v
223 225
224static char *snd_pcm_stream_names[] = { 226static char *snd_pcm_stream_names[] = {
225 STREAM(PLAYBACK), 227 STREAM(PLAYBACK),
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 333e4dd29450..30f410832a25 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -197,12 +197,16 @@ static int snd_pcm_update_hw_ptr_post(struct snd_pcm_substream *substream,
197 avail = snd_pcm_capture_avail(runtime); 197 avail = snd_pcm_capture_avail(runtime);
198 if (avail > runtime->avail_max) 198 if (avail > runtime->avail_max)
199 runtime->avail_max = avail; 199 runtime->avail_max = avail;
200 if (avail >= runtime->stop_threshold) { 200 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
201 if (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING) 201 if (avail >= runtime->buffer_size) {
202 snd_pcm_drain_done(substream); 202 snd_pcm_drain_done(substream);
203 else 203 return -EPIPE;
204 }
205 } else {
206 if (avail >= runtime->stop_threshold) {
204 xrun(substream); 207 xrun(substream);
205 return -EPIPE; 208 return -EPIPE;
209 }
206 } 210 }
207 if (avail >= runtime->control->avail_min) 211 if (avail >= runtime->control->avail_min)
208 wake_up(&runtime->sleep); 212 wake_up(&runtime->sleep);
@@ -233,6 +237,18 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
233 xrun(substream); 237 xrun(substream);
234 return -EPIPE; 238 return -EPIPE;
235 } 239 }
240 if (xrun_debug(substream, 8)) {
241 char name[16];
242 pcm_debug_name(substream, name, sizeof(name));
243 snd_printd("period_update: %s: pos=0x%x/0x%x/0x%x, "
244 "hwptr=0x%lx, hw_base=0x%lx, hw_intr=0x%lx\n",
245 name, (unsigned int)pos,
246 (unsigned int)runtime->period_size,
247 (unsigned int)runtime->buffer_size,
248 (unsigned long)old_hw_ptr,
249 (unsigned long)runtime->hw_ptr_base,
250 (unsigned long)runtime->hw_ptr_interrupt);
251 }
236 hw_base = runtime->hw_ptr_base; 252 hw_base = runtime->hw_ptr_base;
237 new_hw_ptr = hw_base + pos; 253 new_hw_ptr = hw_base + pos;
238 hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size; 254 hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size;
@@ -244,18 +260,27 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
244 delta = new_hw_ptr - hw_ptr_interrupt; 260 delta = new_hw_ptr - hw_ptr_interrupt;
245 } 261 }
246 if (delta < 0) { 262 if (delta < 0) {
247 delta += runtime->buffer_size; 263 if (runtime->periods == 1 || new_hw_ptr < old_hw_ptr)
264 delta += runtime->buffer_size;
248 if (delta < 0) { 265 if (delta < 0) {
249 hw_ptr_error(substream, 266 hw_ptr_error(substream,
250 "Unexpected hw_pointer value " 267 "Unexpected hw_pointer value "
251 "(stream=%i, pos=%ld, intr_ptr=%ld)\n", 268 "(stream=%i, pos=%ld, intr_ptr=%ld)\n",
252 substream->stream, (long)pos, 269 substream->stream, (long)pos,
253 (long)hw_ptr_interrupt); 270 (long)hw_ptr_interrupt);
271#if 1
272 /* simply skipping the hwptr update seems more
273 * robust in some cases, e.g. on VMware with
274 * inaccurate timer source
275 */
276 return 0; /* skip this update */
277#else
254 /* rebase to interrupt position */ 278 /* rebase to interrupt position */
255 hw_base = new_hw_ptr = hw_ptr_interrupt; 279 hw_base = new_hw_ptr = hw_ptr_interrupt;
256 /* align hw_base to buffer_size */ 280 /* align hw_base to buffer_size */
257 hw_base -= hw_base % runtime->buffer_size; 281 hw_base -= hw_base % runtime->buffer_size;
258 delta = 0; 282 delta = 0;
283#endif
259 } else { 284 } else {
260 hw_base += runtime->buffer_size; 285 hw_base += runtime->buffer_size;
261 if (hw_base >= runtime->boundary) 286 if (hw_base >= runtime->boundary)
@@ -344,6 +369,19 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
344 xrun(substream); 369 xrun(substream);
345 return -EPIPE; 370 return -EPIPE;
346 } 371 }
372 if (xrun_debug(substream, 16)) {
373 char name[16];
374 pcm_debug_name(substream, name, sizeof(name));
375 snd_printd("hw_update: %s: pos=0x%x/0x%x/0x%x, "
376 "hwptr=0x%lx, hw_base=0x%lx, hw_intr=0x%lx\n",
377 name, (unsigned int)pos,
378 (unsigned int)runtime->period_size,
379 (unsigned int)runtime->buffer_size,
380 (unsigned long)old_hw_ptr,
381 (unsigned long)runtime->hw_ptr_base,
382 (unsigned long)runtime->hw_ptr_interrupt);
383 }
384
347 hw_base = runtime->hw_ptr_base; 385 hw_base = runtime->hw_ptr_base;
348 new_hw_ptr = hw_base + pos; 386 new_hw_ptr = hw_base + pos;
349 387
@@ -909,47 +947,24 @@ static int snd_interval_ratden(struct snd_interval *i,
909int snd_interval_list(struct snd_interval *i, unsigned int count, unsigned int *list, unsigned int mask) 947int snd_interval_list(struct snd_interval *i, unsigned int count, unsigned int *list, unsigned int mask)
910{ 948{
911 unsigned int k; 949 unsigned int k;
912 int changed = 0; 950 struct snd_interval list_range;
913 951
914 if (!count) { 952 if (!count) {
915 i->empty = 1; 953 i->empty = 1;
916 return -EINVAL; 954 return -EINVAL;
917 } 955 }
956 snd_interval_any(&list_range);
957 list_range.min = UINT_MAX;
958 list_range.max = 0;
918 for (k = 0; k < count; k++) { 959 for (k = 0; k < count; k++) {
919 if (mask && !(mask & (1 << k))) 960 if (mask && !(mask & (1 << k)))
920 continue; 961 continue;
921 if (i->min == list[k] && !i->openmin) 962 if (!snd_interval_test(i, list[k]))
922 goto _l1;
923 if (i->min < list[k]) {
924 i->min = list[k];
925 i->openmin = 0;
926 changed = 1;
927 goto _l1;
928 }
929 }
930 i->empty = 1;
931 return -EINVAL;
932 _l1:
933 for (k = count; k-- > 0;) {
934 if (mask && !(mask & (1 << k)))
935 continue; 963 continue;
936 if (i->max == list[k] && !i->openmax) 964 list_range.min = min(list_range.min, list[k]);
937 goto _l2; 965 list_range.max = max(list_range.max, list[k]);
938 if (i->max > list[k]) {
939 i->max = list[k];
940 i->openmax = 0;
941 changed = 1;
942 goto _l2;
943 }
944 } 966 }
945 i->empty = 1; 967 return snd_interval_refine(i, &list_range);
946 return -EINVAL;
947 _l2:
948 if (snd_interval_checkempty(i)) {
949 i->empty = 1;
950 return -EINVAL;
951 }
952 return changed;
953} 968}
954 969
955EXPORT_SYMBOL(snd_interval_list); 970EXPORT_SYMBOL(snd_interval_list);
diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c
index a6d42808828c..caa7796bc2f5 100644
--- a/sound/core/pcm_memory.c
+++ b/sound/core/pcm_memory.c
@@ -304,6 +304,7 @@ int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
304 304
305EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages_for_all); 305EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages_for_all);
306 306
307#ifdef CONFIG_SND_DMA_SGBUF
307/** 308/**
308 * snd_pcm_sgbuf_ops_page - get the page struct at the given offset 309 * snd_pcm_sgbuf_ops_page - get the page struct at the given offset
309 * @substream: the pcm substream instance 310 * @substream: the pcm substream instance
@@ -349,6 +350,7 @@ unsigned int snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
349 return size; 350 return size;
350} 351}
351EXPORT_SYMBOL(snd_pcm_sgbuf_get_chunk_size); 352EXPORT_SYMBOL(snd_pcm_sgbuf_get_chunk_size);
353#endif /* CONFIG_SND_DMA_SGBUF */
352 354
353/** 355/**
354 * snd_pcm_lib_malloc_pages - allocate the DMA buffer 356 * snd_pcm_lib_malloc_pages - allocate the DMA buffer
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index ac2150e0670d..ab73edf2c89a 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1343,8 +1343,6 @@ static int snd_pcm_prepare(struct snd_pcm_substream *substream,
1343 1343
1344static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, int state) 1344static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, int state)
1345{ 1345{
1346 if (substream->f_flags & O_NONBLOCK)
1347 return -EAGAIN;
1348 substream->runtime->trigger_master = substream; 1346 substream->runtime->trigger_master = substream;
1349 return 0; 1347 return 0;
1350} 1348}
@@ -1389,12 +1387,6 @@ static struct action_ops snd_pcm_action_drain_init = {
1389 .post_action = snd_pcm_post_drain_init 1387 .post_action = snd_pcm_post_drain_init
1390}; 1388};
1391 1389
1392struct drain_rec {
1393 struct snd_pcm_substream *substream;
1394 wait_queue_t wait;
1395 snd_pcm_uframes_t stop_threshold;
1396};
1397
1398static int snd_pcm_drop(struct snd_pcm_substream *substream); 1390static int snd_pcm_drop(struct snd_pcm_substream *substream);
1399 1391
1400/* 1392/*
@@ -1404,14 +1396,15 @@ static int snd_pcm_drop(struct snd_pcm_substream *substream);
1404 * After this call, all streams are supposed to be either SETUP or DRAINING 1396 * After this call, all streams are supposed to be either SETUP or DRAINING
1405 * (capture only) state. 1397 * (capture only) state.
1406 */ 1398 */
1407static int snd_pcm_drain(struct snd_pcm_substream *substream) 1399static int snd_pcm_drain(struct snd_pcm_substream *substream,
1400 struct file *file)
1408{ 1401{
1409 struct snd_card *card; 1402 struct snd_card *card;
1410 struct snd_pcm_runtime *runtime; 1403 struct snd_pcm_runtime *runtime;
1411 struct snd_pcm_substream *s; 1404 struct snd_pcm_substream *s;
1405 wait_queue_t wait;
1412 int result = 0; 1406 int result = 0;
1413 int i, num_drecs; 1407 int nonblock = 0;
1414 struct drain_rec *drec, drec_tmp, *d;
1415 1408
1416 card = substream->pcm->card; 1409 card = substream->pcm->card;
1417 runtime = substream->runtime; 1410 runtime = substream->runtime;
@@ -1428,70 +1421,59 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream)
1428 } 1421 }
1429 } 1422 }
1430 1423
1431 /* allocate temporary record for drain sync */ 1424 if (file) {
1432 down_read(&snd_pcm_link_rwsem); 1425 if (file->f_flags & O_NONBLOCK)
1433 if (snd_pcm_stream_linked(substream)) { 1426 nonblock = 1;
1434 drec = kmalloc(substream->group->count * sizeof(*drec), GFP_KERNEL); 1427 } else if (substream->f_flags & O_NONBLOCK)
1435 if (! drec) { 1428 nonblock = 1;
1436 up_read(&snd_pcm_link_rwsem);
1437 snd_power_unlock(card);
1438 return -ENOMEM;
1439 }
1440 } else
1441 drec = &drec_tmp;
1442
1443 /* count only playback streams */
1444 num_drecs = 0;
1445 snd_pcm_group_for_each_entry(s, substream) {
1446 runtime = s->runtime;
1447 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1448 d = &drec[num_drecs++];
1449 d->substream = s;
1450 init_waitqueue_entry(&d->wait, current);
1451 add_wait_queue(&runtime->sleep, &d->wait);
1452 /* stop_threshold fixup to avoid endless loop when
1453 * stop_threshold > buffer_size
1454 */
1455 d->stop_threshold = runtime->stop_threshold;
1456 if (runtime->stop_threshold > runtime->buffer_size)
1457 runtime->stop_threshold = runtime->buffer_size;
1458 }
1459 }
1460 up_read(&snd_pcm_link_rwsem);
1461 1429
1430 down_read(&snd_pcm_link_rwsem);
1462 snd_pcm_stream_lock_irq(substream); 1431 snd_pcm_stream_lock_irq(substream);
1463 /* resume pause */ 1432 /* resume pause */
1464 if (substream->runtime->status->state == SNDRV_PCM_STATE_PAUSED) 1433 if (runtime->status->state == SNDRV_PCM_STATE_PAUSED)
1465 snd_pcm_pause(substream, 0); 1434 snd_pcm_pause(substream, 0);
1466 1435
1467 /* pre-start/stop - all running streams are changed to DRAINING state */ 1436 /* pre-start/stop - all running streams are changed to DRAINING state */
1468 result = snd_pcm_action(&snd_pcm_action_drain_init, substream, 0); 1437 result = snd_pcm_action(&snd_pcm_action_drain_init, substream, 0);
1469 if (result < 0) { 1438 if (result < 0)
1470 snd_pcm_stream_unlock_irq(substream); 1439 goto unlock;
1471 goto _error; 1440 /* in non-blocking, we don't wait in ioctl but let caller poll */
1441 if (nonblock) {
1442 result = -EAGAIN;
1443 goto unlock;
1472 } 1444 }
1473 1445
1474 for (;;) { 1446 for (;;) {
1475 long tout; 1447 long tout;
1448 struct snd_pcm_runtime *to_check;
1476 if (signal_pending(current)) { 1449 if (signal_pending(current)) {
1477 result = -ERESTARTSYS; 1450 result = -ERESTARTSYS;
1478 break; 1451 break;
1479 } 1452 }
1480 /* all finished? */ 1453 /* find a substream to drain */
1481 for (i = 0; i < num_drecs; i++) { 1454 to_check = NULL;
1482 runtime = drec[i].substream->runtime; 1455 snd_pcm_group_for_each_entry(s, substream) {
1483 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) 1456 if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
1457 continue;
1458 runtime = s->runtime;
1459 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
1460 to_check = runtime;
1484 break; 1461 break;
1462 }
1485 } 1463 }
1486 if (i == num_drecs) 1464 if (!to_check)
1487 break; /* yes, all drained */ 1465 break; /* all drained */
1488 1466 init_waitqueue_entry(&wait, current);
1467 add_wait_queue(&to_check->sleep, &wait);
1489 set_current_state(TASK_INTERRUPTIBLE); 1468 set_current_state(TASK_INTERRUPTIBLE);
1490 snd_pcm_stream_unlock_irq(substream); 1469 snd_pcm_stream_unlock_irq(substream);
1470 up_read(&snd_pcm_link_rwsem);
1491 snd_power_unlock(card); 1471 snd_power_unlock(card);
1492 tout = schedule_timeout(10 * HZ); 1472 tout = schedule_timeout(10 * HZ);
1493 snd_power_lock(card); 1473 snd_power_lock(card);
1474 down_read(&snd_pcm_link_rwsem);
1494 snd_pcm_stream_lock_irq(substream); 1475 snd_pcm_stream_lock_irq(substream);
1476 remove_wait_queue(&to_check->sleep, &wait);
1495 if (tout == 0) { 1477 if (tout == 0) {
1496 if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) 1478 if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED)
1497 result = -ESTRPIPE; 1479 result = -ESTRPIPE;
@@ -1504,18 +1486,9 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream)
1504 } 1486 }
1505 } 1487 }
1506 1488
1489 unlock:
1507 snd_pcm_stream_unlock_irq(substream); 1490 snd_pcm_stream_unlock_irq(substream);
1508 1491 up_read(&snd_pcm_link_rwsem);
1509 _error:
1510 for (i = 0; i < num_drecs; i++) {
1511 d = &drec[i];
1512 runtime = d->substream->runtime;
1513 remove_wait_queue(&runtime->sleep, &d->wait);
1514 runtime->stop_threshold = d->stop_threshold;
1515 }
1516
1517 if (drec != &drec_tmp)
1518 kfree(drec);
1519 snd_power_unlock(card); 1492 snd_power_unlock(card);
1520 1493
1521 return result; 1494 return result;
@@ -2208,6 +2181,9 @@ static snd_pcm_sframes_t snd_pcm_playback_rewind(struct snd_pcm_substream *subst
2208 case SNDRV_PCM_STATE_XRUN: 2181 case SNDRV_PCM_STATE_XRUN:
2209 ret = -EPIPE; 2182 ret = -EPIPE;
2210 goto __end; 2183 goto __end;
2184 case SNDRV_PCM_STATE_SUSPENDED:
2185 ret = -ESTRPIPE;
2186 goto __end;
2211 default: 2187 default:
2212 ret = -EBADFD; 2188 ret = -EBADFD;
2213 goto __end; 2189 goto __end;
@@ -2253,6 +2229,9 @@ static snd_pcm_sframes_t snd_pcm_capture_rewind(struct snd_pcm_substream *substr
2253 case SNDRV_PCM_STATE_XRUN: 2229 case SNDRV_PCM_STATE_XRUN:
2254 ret = -EPIPE; 2230 ret = -EPIPE;
2255 goto __end; 2231 goto __end;
2232 case SNDRV_PCM_STATE_SUSPENDED:
2233 ret = -ESTRPIPE;
2234 goto __end;
2256 default: 2235 default:
2257 ret = -EBADFD; 2236 ret = -EBADFD;
2258 goto __end; 2237 goto __end;
@@ -2299,6 +2278,9 @@ static snd_pcm_sframes_t snd_pcm_playback_forward(struct snd_pcm_substream *subs
2299 case SNDRV_PCM_STATE_XRUN: 2278 case SNDRV_PCM_STATE_XRUN:
2300 ret = -EPIPE; 2279 ret = -EPIPE;
2301 goto __end; 2280 goto __end;
2281 case SNDRV_PCM_STATE_SUSPENDED:
2282 ret = -ESTRPIPE;
2283 goto __end;
2302 default: 2284 default:
2303 ret = -EBADFD; 2285 ret = -EBADFD;
2304 goto __end; 2286 goto __end;
@@ -2345,6 +2327,9 @@ static snd_pcm_sframes_t snd_pcm_capture_forward(struct snd_pcm_substream *subst
2345 case SNDRV_PCM_STATE_XRUN: 2327 case SNDRV_PCM_STATE_XRUN:
2346 ret = -EPIPE; 2328 ret = -EPIPE;
2347 goto __end; 2329 goto __end;
2330 case SNDRV_PCM_STATE_SUSPENDED:
2331 ret = -ESTRPIPE;
2332 goto __end;
2348 default: 2333 default:
2349 ret = -EBADFD; 2334 ret = -EBADFD;
2350 goto __end; 2335 goto __end;
@@ -2544,7 +2529,7 @@ static int snd_pcm_common_ioctl1(struct file *file,
2544 return snd_pcm_hw_params_old_user(substream, arg); 2529 return snd_pcm_hw_params_old_user(substream, arg);
2545#endif 2530#endif
2546 case SNDRV_PCM_IOCTL_DRAIN: 2531 case SNDRV_PCM_IOCTL_DRAIN:
2547 return snd_pcm_drain(substream); 2532 return snd_pcm_drain(substream, file);
2548 case SNDRV_PCM_IOCTL_DROP: 2533 case SNDRV_PCM_IOCTL_DROP:
2549 return snd_pcm_drop(substream); 2534 return snd_pcm_drop(substream);
2550 case SNDRV_PCM_IOCTL_PAUSE: 2535 case SNDRV_PCM_IOCTL_PAUSE:
@@ -3000,7 +2985,7 @@ static int snd_pcm_mmap_status_fault(struct vm_area_struct *area,
3000 return 0; 2985 return 0;
3001} 2986}
3002 2987
3003static struct vm_operations_struct snd_pcm_vm_ops_status = 2988static const struct vm_operations_struct snd_pcm_vm_ops_status =
3004{ 2989{
3005 .fault = snd_pcm_mmap_status_fault, 2990 .fault = snd_pcm_mmap_status_fault,
3006}; 2991};
@@ -3039,7 +3024,7 @@ static int snd_pcm_mmap_control_fault(struct vm_area_struct *area,
3039 return 0; 3024 return 0;
3040} 3025}
3041 3026
3042static struct vm_operations_struct snd_pcm_vm_ops_control = 3027static const struct vm_operations_struct snd_pcm_vm_ops_control =
3043{ 3028{
3044 .fault = snd_pcm_mmap_control_fault, 3029 .fault = snd_pcm_mmap_control_fault,
3045}; 3030};
@@ -3109,7 +3094,7 @@ static int snd_pcm_mmap_data_fault(struct vm_area_struct *area,
3109 return 0; 3094 return 0;
3110} 3095}
3111 3096
3112static struct vm_operations_struct snd_pcm_vm_ops_data = 3097static const struct vm_operations_struct snd_pcm_vm_ops_data =
3113{ 3098{
3114 .open = snd_pcm_mmap_data_open, 3099 .open = snd_pcm_mmap_data_open,
3115 .close = snd_pcm_mmap_data_close, 3100 .close = snd_pcm_mmap_data_close,
@@ -3133,7 +3118,7 @@ static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
3133 * mmap the DMA buffer on I/O memory area 3118 * mmap the DMA buffer on I/O memory area
3134 */ 3119 */
3135#if SNDRV_PCM_INFO_MMAP_IOMEM 3120#if SNDRV_PCM_INFO_MMAP_IOMEM
3136static struct vm_operations_struct snd_pcm_vm_ops_data_mmio = 3121static const struct vm_operations_struct snd_pcm_vm_ops_data_mmio =
3137{ 3122{
3138 .open = snd_pcm_mmap_data_open, 3123 .open = snd_pcm_mmap_data_open,
3139 .close = snd_pcm_mmap_data_close, 3124 .close = snd_pcm_mmap_data_close,
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 473247c8e6d3..c0adc14c91f0 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -274,7 +274,7 @@ static int open_substream(struct snd_rawmidi *rmidi,
274 return err; 274 return err;
275 substream->opened = 1; 275 substream->opened = 1;
276 if (substream->use_count++ == 0) 276 if (substream->use_count++ == 0)
277 substream->active_sensing = 1; 277 substream->active_sensing = 0;
278 if (mode & SNDRV_RAWMIDI_LFLG_APPEND) 278 if (mode & SNDRV_RAWMIDI_LFLG_APPEND)
279 substream->append = 1; 279 substream->append = 1;
280 rmidi->streams[substream->stream].substream_opened++; 280 rmidi->streams[substream->stream].substream_opened++;
diff --git a/sound/core/seq/Makefile b/sound/core/seq/Makefile
index 1bcb360330e5..941f64a853eb 100644
--- a/sound/core/seq/Makefile
+++ b/sound/core/seq/Makefile
@@ -3,10 +3,6 @@
3# Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz> 3# Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz>
4# 4#
5 5
6ifeq ($(CONFIG_SND_SEQUENCER_OSS),y)
7 obj-$(CONFIG_SND_SEQUENCER) += oss/
8endif
9
10snd-seq-device-objs := seq_device.o 6snd-seq-device-objs := seq_device.o
11snd-seq-objs := seq.o seq_lock.o seq_clientmgr.o seq_memory.o seq_queue.o \ 7snd-seq-objs := seq.o seq_lock.o seq_clientmgr.o seq_memory.o seq_queue.o \
12 seq_fifo.o seq_prioq.o seq_timer.o \ 8 seq_fifo.o seq_prioq.o seq_timer.o \
@@ -19,7 +15,8 @@ snd-seq-virmidi-objs := seq_virmidi.o
19 15
20obj-$(CONFIG_SND_SEQUENCER) += snd-seq.o snd-seq-device.o 16obj-$(CONFIG_SND_SEQUENCER) += snd-seq.o snd-seq-device.o
21ifeq ($(CONFIG_SND_SEQUENCER_OSS),y) 17ifeq ($(CONFIG_SND_SEQUENCER_OSS),y)
22obj-$(CONFIG_SND_SEQUENCER) += snd-seq-midi-event.o 18 obj-$(CONFIG_SND_SEQUENCER) += snd-seq-midi-event.o
19 obj-$(CONFIG_SND_SEQUENCER) += oss/
23endif 20endif
24obj-$(CONFIG_SND_SEQ_DUMMY) += snd-seq-dummy.o 21obj-$(CONFIG_SND_SEQ_DUMMY) += snd-seq-dummy.o
25 22
diff --git a/sound/core/seq/oss/seq_oss_midi.c b/sound/core/seq/oss/seq_oss_midi.c
index 0a711d2d04f0..9dfb2f77be60 100644
--- a/sound/core/seq/oss/seq_oss_midi.c
+++ b/sound/core/seq/oss/seq_oss_midi.c
@@ -20,6 +20,7 @@
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23#include <sound/asoundef.h>
23#include "seq_oss_midi.h" 24#include "seq_oss_midi.h"
24#include "seq_oss_readq.h" 25#include "seq_oss_readq.h"
25#include "seq_oss_timer.h" 26#include "seq_oss_timer.h"
@@ -476,19 +477,20 @@ snd_seq_oss_midi_reset(struct seq_oss_devinfo *dp, int dev)
476 ev.source.port = dp->port; 477 ev.source.port = dp->port;
477 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_SYNTH) { 478 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_SYNTH) {
478 ev.type = SNDRV_SEQ_EVENT_SENSING; 479 ev.type = SNDRV_SEQ_EVENT_SENSING;
479 snd_seq_oss_dispatch(dp, &ev, 0, 0); /* active sensing */ 480 snd_seq_oss_dispatch(dp, &ev, 0, 0);
480 } 481 }
481 for (c = 0; c < 16; c++) { 482 for (c = 0; c < 16; c++) {
482 ev.type = SNDRV_SEQ_EVENT_CONTROLLER; 483 ev.type = SNDRV_SEQ_EVENT_CONTROLLER;
483 ev.data.control.channel = c; 484 ev.data.control.channel = c;
484 ev.data.control.param = 123; 485 ev.data.control.param = MIDI_CTL_ALL_NOTES_OFF;
485 snd_seq_oss_dispatch(dp, &ev, 0, 0); /* all notes off */ 486 snd_seq_oss_dispatch(dp, &ev, 0, 0);
486 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_MUSIC) { 487 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_MUSIC) {
487 ev.data.control.param = 121; 488 ev.data.control.param =
488 snd_seq_oss_dispatch(dp, &ev, 0, 0); /* reset all controllers */ 489 MIDI_CTL_RESET_CONTROLLERS;
490 snd_seq_oss_dispatch(dp, &ev, 0, 0);
489 ev.type = SNDRV_SEQ_EVENT_PITCHBEND; 491 ev.type = SNDRV_SEQ_EVENT_PITCHBEND;
490 ev.data.control.value = 0; 492 ev.data.control.value = 0;
491 snd_seq_oss_dispatch(dp, &ev, 0, 0); /* bender off */ 493 snd_seq_oss_dispatch(dp, &ev, 0, 0);
492 } 494 }
493 } 495 }
494 } 496 }
diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
index 4d26146a62cc..ebaf1b541dcd 100644
--- a/sound/core/seq/seq_midi.c
+++ b/sound/core/seq/seq_midi.c
@@ -120,7 +120,8 @@ static int dump_midi(struct snd_rawmidi_substream *substream, const char *buf, i
120 return -EINVAL; 120 return -EINVAL;
121 runtime = substream->runtime; 121 runtime = substream->runtime;
122 if ((tmp = runtime->avail) < count) { 122 if ((tmp = runtime->avail) < count) {
123 snd_printd("warning, output event was lost (count = %i, available = %i)\n", count, tmp); 123 if (printk_ratelimit())
124 snd_printk(KERN_ERR "MIDI output buffer overrun\n");
124 return -ENOMEM; 125 return -ENOMEM;
125 } 126 }
126 if (snd_rawmidi_kernel_write(substream, buf, count) < count) 127 if (snd_rawmidi_kernel_write(substream, buf, count) < count)
@@ -236,6 +237,7 @@ static int midisynth_use(void *private_data, struct snd_seq_port_subscribe *info
236 memset(&params, 0, sizeof(params)); 237 memset(&params, 0, sizeof(params));
237 params.avail_min = 1; 238 params.avail_min = 1;
238 params.buffer_size = output_buffer_size; 239 params.buffer_size = output_buffer_size;
240 params.no_active_sensing = 1;
239 if ((err = snd_rawmidi_output_params(msynth->output_rfile.output, &params)) < 0) { 241 if ((err = snd_rawmidi_output_params(msynth->output_rfile.output, &params)) < 0) {
240 snd_rawmidi_kernel_release(&msynth->output_rfile); 242 snd_rawmidi_kernel_release(&msynth->output_rfile);
241 return err; 243 return err;
@@ -248,12 +250,9 @@ static int midisynth_use(void *private_data, struct snd_seq_port_subscribe *info
248static int midisynth_unuse(void *private_data, struct snd_seq_port_subscribe *info) 250static int midisynth_unuse(void *private_data, struct snd_seq_port_subscribe *info)
249{ 251{
250 struct seq_midisynth *msynth = private_data; 252 struct seq_midisynth *msynth = private_data;
251 unsigned char buf = 0xff; /* MIDI reset */
252 253
253 if (snd_BUG_ON(!msynth->output_rfile.output)) 254 if (snd_BUG_ON(!msynth->output_rfile.output))
254 return -EINVAL; 255 return -EINVAL;
255 /* sending single MIDI reset message to shut the device up */
256 snd_rawmidi_kernel_write(msynth->output_rfile.output, &buf, 1);
257 snd_rawmidi_drain_output(msynth->output_rfile.output); 256 snd_rawmidi_drain_output(msynth->output_rfile.output);
258 return snd_rawmidi_kernel_release(&msynth->output_rfile); 257 return snd_rawmidi_kernel_release(&msynth->output_rfile);
259} 258}
diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
index 257624bd1997..3b9b550109cb 100644
--- a/sound/core/vmaster.c
+++ b/sound/core/vmaster.c
@@ -353,7 +353,8 @@ static void master_free(struct snd_kcontrol *kcontrol)
353 * 353 *
354 * The optional argument @tlv can be used to specify the TLV information 354 * The optional argument @tlv can be used to specify the TLV information
355 * for dB scale of the master control. It should be a single element 355 * for dB scale of the master control. It should be a single element
356 * with #SNDRV_CTL_TLVT_DB_SCALE type, and should be the max 0dB. 356 * with #SNDRV_CTL_TLVT_DB_SCALE, #SNDRV_CTL_TLV_DB_MINMAX or
357 * #SNDRV_CTL_TLVT_DB_MINMAX_MUTE type, and should be the max 0dB.
357 */ 358 */
358struct snd_kcontrol *snd_ctl_make_virtual_master(char *name, 359struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
359 const unsigned int *tlv) 360 const unsigned int *tlv)
@@ -384,7 +385,10 @@ struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
384 kctl->private_free = master_free; 385 kctl->private_free = master_free;
385 386
386 /* additional (constant) TLV read */ 387 /* additional (constant) TLV read */
387 if (tlv && tlv[0] == SNDRV_CTL_TLVT_DB_SCALE) { 388 if (tlv &&
389 (tlv[0] == SNDRV_CTL_TLVT_DB_SCALE ||
390 tlv[0] == SNDRV_CTL_TLVT_DB_MINMAX ||
391 tlv[0] == SNDRV_CTL_TLVT_DB_MINMAX_MUTE)) {
388 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; 392 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
389 memcpy(master->tlv, tlv, sizeof(master->tlv)); 393 memcpy(master->tlv, tlv, sizeof(master->tlv));
390 kctl->tlv.p = master->tlv; 394 kctl->tlv.p = master->tlv;
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 54239d2e0997..6ba066c41d2e 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -25,12 +25,15 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/time.h> 26#include <linux/time.h>
27#include <linux/wait.h> 27#include <linux/wait.h>
28#include <linux/hrtimer.h>
29#include <linux/math64.h>
28#include <linux/moduleparam.h> 30#include <linux/moduleparam.h>
29#include <sound/core.h> 31#include <sound/core.h>
30#include <sound/control.h> 32#include <sound/control.h>
31#include <sound/tlv.h> 33#include <sound/tlv.h>
32#include <sound/pcm.h> 34#include <sound/pcm.h>
33#include <sound/rawmidi.h> 35#include <sound/rawmidi.h>
36#include <sound/info.h>
34#include <sound/initval.h> 37#include <sound/initval.h>
35 38
36MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 39MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
@@ -39,7 +42,7 @@ MODULE_LICENSE("GPL");
39MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}"); 42MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}");
40 43
41#define MAX_PCM_DEVICES 4 44#define MAX_PCM_DEVICES 4
42#define MAX_PCM_SUBSTREAMS 16 45#define MAX_PCM_SUBSTREAMS 128
43#define MAX_MIDI_DEVICES 2 46#define MAX_MIDI_DEVICES 2
44 47
45#if 0 /* emu10k1 emulation */ 48#if 0 /* emu10k1 emulation */
@@ -148,6 +151,10 @@ static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
148static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 151static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
149static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; 152static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8};
150//static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; 153//static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
154#ifdef CONFIG_HIGH_RES_TIMERS
155static int hrtimer = 1;
156#endif
157static int fake_buffer = 1;
151 158
152module_param_array(index, int, NULL, 0444); 159module_param_array(index, int, NULL, 0444);
153MODULE_PARM_DESC(index, "Index value for dummy soundcard."); 160MODULE_PARM_DESC(index, "Index value for dummy soundcard.");
@@ -161,6 +168,12 @@ module_param_array(pcm_substreams, int, NULL, 0444);
161MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver."); 168MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver.");
162//module_param_array(midi_devs, int, NULL, 0444); 169//module_param_array(midi_devs, int, NULL, 0444);
163//MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver."); 170//MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
171module_param(fake_buffer, bool, 0444);
172MODULE_PARM_DESC(fake_buffer, "Fake buffer allocations.");
173#ifdef CONFIG_HIGH_RES_TIMERS
174module_param(hrtimer, bool, 0644);
175MODULE_PARM_DESC(hrtimer, "Use hrtimer as the timer source.");
176#endif
164 177
165static struct platform_device *devices[SNDRV_CARDS]; 178static struct platform_device *devices[SNDRV_CARDS];
166 179
@@ -171,137 +184,324 @@ static struct platform_device *devices[SNDRV_CARDS];
171#define MIXER_ADDR_CD 4 184#define MIXER_ADDR_CD 4
172#define MIXER_ADDR_LAST 4 185#define MIXER_ADDR_LAST 4
173 186
187struct dummy_timer_ops {
188 int (*create)(struct snd_pcm_substream *);
189 void (*free)(struct snd_pcm_substream *);
190 int (*prepare)(struct snd_pcm_substream *);
191 int (*start)(struct snd_pcm_substream *);
192 int (*stop)(struct snd_pcm_substream *);
193 snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *);
194};
195
174struct snd_dummy { 196struct snd_dummy {
175 struct snd_card *card; 197 struct snd_card *card;
176 struct snd_pcm *pcm; 198 struct snd_pcm *pcm;
177 spinlock_t mixer_lock; 199 spinlock_t mixer_lock;
178 int mixer_volume[MIXER_ADDR_LAST+1][2]; 200 int mixer_volume[MIXER_ADDR_LAST+1][2];
179 int capture_source[MIXER_ADDR_LAST+1][2]; 201 int capture_source[MIXER_ADDR_LAST+1][2];
202 const struct dummy_timer_ops *timer_ops;
180}; 203};
181 204
182struct snd_dummy_pcm { 205/*
183 struct snd_dummy *dummy; 206 * system timer interface
207 */
208
209struct dummy_systimer_pcm {
184 spinlock_t lock; 210 spinlock_t lock;
185 struct timer_list timer; 211 struct timer_list timer;
186 unsigned int pcm_buffer_size; 212 unsigned long base_time;
187 unsigned int pcm_period_size; 213 unsigned int frac_pos; /* fractional sample position (based HZ) */
188 unsigned int pcm_bps; /* bytes per second */ 214 unsigned int frac_period_rest;
189 unsigned int pcm_hz; /* HZ */ 215 unsigned int frac_buffer_size; /* buffer_size * HZ */
190 unsigned int pcm_irq_pos; /* IRQ position */ 216 unsigned int frac_period_size; /* period_size * HZ */
191 unsigned int pcm_buf_pos; /* position in buffer */ 217 unsigned int rate;
218 int elapsed;
192 struct snd_pcm_substream *substream; 219 struct snd_pcm_substream *substream;
193}; 220};
194 221
195 222static void dummy_systimer_rearm(struct dummy_systimer_pcm *dpcm)
196static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm)
197{ 223{
198 dpcm->timer.expires = 1 + jiffies; 224 dpcm->timer.expires = jiffies +
225 (dpcm->frac_period_rest + dpcm->rate - 1) / dpcm->rate;
199 add_timer(&dpcm->timer); 226 add_timer(&dpcm->timer);
200} 227}
201 228
202static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm) 229static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm)
203{ 230{
204 del_timer(&dpcm->timer); 231 unsigned long delta;
232
233 delta = jiffies - dpcm->base_time;
234 if (!delta)
235 return;
236 dpcm->base_time += delta;
237 delta *= dpcm->rate;
238 dpcm->frac_pos += delta;
239 while (dpcm->frac_pos >= dpcm->frac_buffer_size)
240 dpcm->frac_pos -= dpcm->frac_buffer_size;
241 while (dpcm->frac_period_rest <= delta) {
242 dpcm->elapsed++;
243 dpcm->frac_period_rest += dpcm->frac_period_size;
244 }
245 dpcm->frac_period_rest -= delta;
205} 246}
206 247
207static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 248static int dummy_systimer_start(struct snd_pcm_substream *substream)
208{ 249{
209 struct snd_pcm_runtime *runtime = substream->runtime; 250 struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
210 struct snd_dummy_pcm *dpcm = runtime->private_data; 251 spin_lock(&dpcm->lock);
211 int err = 0; 252 dpcm->base_time = jiffies;
253 dummy_systimer_rearm(dpcm);
254 spin_unlock(&dpcm->lock);
255 return 0;
256}
212 257
258static int dummy_systimer_stop(struct snd_pcm_substream *substream)
259{
260 struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
213 spin_lock(&dpcm->lock); 261 spin_lock(&dpcm->lock);
214 switch (cmd) { 262 del_timer(&dpcm->timer);
215 case SNDRV_PCM_TRIGGER_START:
216 case SNDRV_PCM_TRIGGER_RESUME:
217 snd_card_dummy_pcm_timer_start(dpcm);
218 break;
219 case SNDRV_PCM_TRIGGER_STOP:
220 case SNDRV_PCM_TRIGGER_SUSPEND:
221 snd_card_dummy_pcm_timer_stop(dpcm);
222 break;
223 default:
224 err = -EINVAL;
225 break;
226 }
227 spin_unlock(&dpcm->lock); 263 spin_unlock(&dpcm->lock);
228 return 0; 264 return 0;
229} 265}
230 266
231static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) 267static int dummy_systimer_prepare(struct snd_pcm_substream *substream)
232{ 268{
233 struct snd_pcm_runtime *runtime = substream->runtime; 269 struct snd_pcm_runtime *runtime = substream->runtime;
234 struct snd_dummy_pcm *dpcm = runtime->private_data; 270 struct dummy_systimer_pcm *dpcm = runtime->private_data;
235 int bps;
236
237 bps = snd_pcm_format_width(runtime->format) * runtime->rate *
238 runtime->channels / 8;
239
240 if (bps <= 0)
241 return -EINVAL;
242
243 dpcm->pcm_bps = bps;
244 dpcm->pcm_hz = HZ;
245 dpcm->pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream);
246 dpcm->pcm_period_size = snd_pcm_lib_period_bytes(substream);
247 dpcm->pcm_irq_pos = 0;
248 dpcm->pcm_buf_pos = 0;
249 271
250 snd_pcm_format_set_silence(runtime->format, runtime->dma_area, 272 dpcm->frac_pos = 0;
251 bytes_to_samples(runtime, runtime->dma_bytes)); 273 dpcm->rate = runtime->rate;
274 dpcm->frac_buffer_size = runtime->buffer_size * HZ;
275 dpcm->frac_period_size = runtime->period_size * HZ;
276 dpcm->frac_period_rest = dpcm->frac_period_size;
277 dpcm->elapsed = 0;
252 278
253 return 0; 279 return 0;
254} 280}
255 281
256static void snd_card_dummy_pcm_timer_function(unsigned long data) 282static void dummy_systimer_callback(unsigned long data)
257{ 283{
258 struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data; 284 struct dummy_systimer_pcm *dpcm = (struct dummy_systimer_pcm *)data;
259 unsigned long flags; 285 unsigned long flags;
286 int elapsed = 0;
260 287
261 spin_lock_irqsave(&dpcm->lock, flags); 288 spin_lock_irqsave(&dpcm->lock, flags);
262 dpcm->timer.expires = 1 + jiffies; 289 dummy_systimer_update(dpcm);
263 add_timer(&dpcm->timer); 290 dummy_systimer_rearm(dpcm);
264 dpcm->pcm_irq_pos += dpcm->pcm_bps; 291 elapsed = dpcm->elapsed;
265 dpcm->pcm_buf_pos += dpcm->pcm_bps; 292 dpcm->elapsed = 0;
266 dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz; 293 spin_unlock_irqrestore(&dpcm->lock, flags);
267 if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) { 294 if (elapsed)
268 dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz; 295 snd_pcm_period_elapsed(dpcm->substream);
269 spin_unlock_irqrestore(&dpcm->lock, flags); 296}
297
298static snd_pcm_uframes_t
299dummy_systimer_pointer(struct snd_pcm_substream *substream)
300{
301 struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
302 snd_pcm_uframes_t pos;
303
304 spin_lock(&dpcm->lock);
305 dummy_systimer_update(dpcm);
306 pos = dpcm->frac_pos / HZ;
307 spin_unlock(&dpcm->lock);
308 return pos;
309}
310
311static int dummy_systimer_create(struct snd_pcm_substream *substream)
312{
313 struct dummy_systimer_pcm *dpcm;
314
315 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
316 if (!dpcm)
317 return -ENOMEM;
318 substream->runtime->private_data = dpcm;
319 init_timer(&dpcm->timer);
320 dpcm->timer.data = (unsigned long) dpcm;
321 dpcm->timer.function = dummy_systimer_callback;
322 spin_lock_init(&dpcm->lock);
323 dpcm->substream = substream;
324 return 0;
325}
326
327static void dummy_systimer_free(struct snd_pcm_substream *substream)
328{
329 kfree(substream->runtime->private_data);
330}
331
332static struct dummy_timer_ops dummy_systimer_ops = {
333 .create = dummy_systimer_create,
334 .free = dummy_systimer_free,
335 .prepare = dummy_systimer_prepare,
336 .start = dummy_systimer_start,
337 .stop = dummy_systimer_stop,
338 .pointer = dummy_systimer_pointer,
339};
340
341#ifdef CONFIG_HIGH_RES_TIMERS
342/*
343 * hrtimer interface
344 */
345
346struct dummy_hrtimer_pcm {
347 ktime_t base_time;
348 ktime_t period_time;
349 atomic_t running;
350 struct hrtimer timer;
351 struct tasklet_struct tasklet;
352 struct snd_pcm_substream *substream;
353};
354
355static void dummy_hrtimer_pcm_elapsed(unsigned long priv)
356{
357 struct dummy_hrtimer_pcm *dpcm = (struct dummy_hrtimer_pcm *)priv;
358 if (atomic_read(&dpcm->running))
270 snd_pcm_period_elapsed(dpcm->substream); 359 snd_pcm_period_elapsed(dpcm->substream);
271 } else
272 spin_unlock_irqrestore(&dpcm->lock, flags);
273} 360}
274 361
275static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream) 362static enum hrtimer_restart dummy_hrtimer_callback(struct hrtimer *timer)
363{
364 struct dummy_hrtimer_pcm *dpcm;
365
366 dpcm = container_of(timer, struct dummy_hrtimer_pcm, timer);
367 if (!atomic_read(&dpcm->running))
368 return HRTIMER_NORESTART;
369 tasklet_schedule(&dpcm->tasklet);
370 hrtimer_forward_now(timer, dpcm->period_time);
371 return HRTIMER_RESTART;
372}
373
374static int dummy_hrtimer_start(struct snd_pcm_substream *substream)
375{
376 struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
377
378 dpcm->base_time = hrtimer_cb_get_time(&dpcm->timer);
379 hrtimer_start(&dpcm->timer, dpcm->period_time, HRTIMER_MODE_REL);
380 atomic_set(&dpcm->running, 1);
381 return 0;
382}
383
384static int dummy_hrtimer_stop(struct snd_pcm_substream *substream)
385{
386 struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
387
388 atomic_set(&dpcm->running, 0);
389 hrtimer_cancel(&dpcm->timer);
390 return 0;
391}
392
393static inline void dummy_hrtimer_sync(struct dummy_hrtimer_pcm *dpcm)
394{
395 tasklet_kill(&dpcm->tasklet);
396}
397
398static snd_pcm_uframes_t
399dummy_hrtimer_pointer(struct snd_pcm_substream *substream)
276{ 400{
277 struct snd_pcm_runtime *runtime = substream->runtime; 401 struct snd_pcm_runtime *runtime = substream->runtime;
278 struct snd_dummy_pcm *dpcm = runtime->private_data; 402 struct dummy_hrtimer_pcm *dpcm = runtime->private_data;
403 u64 delta;
404 u32 pos;
405
406 delta = ktime_us_delta(hrtimer_cb_get_time(&dpcm->timer),
407 dpcm->base_time);
408 delta = div_u64(delta * runtime->rate + 999999, 1000000);
409 div_u64_rem(delta, runtime->buffer_size, &pos);
410 return pos;
411}
279 412
280 return bytes_to_frames(runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz); 413static int dummy_hrtimer_prepare(struct snd_pcm_substream *substream)
414{
415 struct snd_pcm_runtime *runtime = substream->runtime;
416 struct dummy_hrtimer_pcm *dpcm = runtime->private_data;
417 unsigned int period, rate;
418 long sec;
419 unsigned long nsecs;
420
421 dummy_hrtimer_sync(dpcm);
422 period = runtime->period_size;
423 rate = runtime->rate;
424 sec = period / rate;
425 period %= rate;
426 nsecs = div_u64((u64)period * 1000000000UL + rate - 1, rate);
427 dpcm->period_time = ktime_set(sec, nsecs);
428
429 return 0;
281} 430}
282 431
283static struct snd_pcm_hardware snd_card_dummy_playback = 432static int dummy_hrtimer_create(struct snd_pcm_substream *substream)
284{ 433{
285 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 434 struct dummy_hrtimer_pcm *dpcm;
286 SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), 435
287 .formats = USE_FORMATS, 436 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
288 .rates = USE_RATE, 437 if (!dpcm)
289 .rate_min = USE_RATE_MIN, 438 return -ENOMEM;
290 .rate_max = USE_RATE_MAX, 439 substream->runtime->private_data = dpcm;
291 .channels_min = USE_CHANNELS_MIN, 440 hrtimer_init(&dpcm->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
292 .channels_max = USE_CHANNELS_MAX, 441 dpcm->timer.function = dummy_hrtimer_callback;
293 .buffer_bytes_max = MAX_BUFFER_SIZE, 442 dpcm->substream = substream;
294 .period_bytes_min = 64, 443 atomic_set(&dpcm->running, 0);
295 .period_bytes_max = MAX_PERIOD_SIZE, 444 tasklet_init(&dpcm->tasklet, dummy_hrtimer_pcm_elapsed,
296 .periods_min = USE_PERIODS_MIN, 445 (unsigned long)dpcm);
297 .periods_max = USE_PERIODS_MAX, 446 return 0;
298 .fifo_size = 0, 447}
448
449static void dummy_hrtimer_free(struct snd_pcm_substream *substream)
450{
451 struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
452 dummy_hrtimer_sync(dpcm);
453 kfree(dpcm);
454}
455
456static struct dummy_timer_ops dummy_hrtimer_ops = {
457 .create = dummy_hrtimer_create,
458 .free = dummy_hrtimer_free,
459 .prepare = dummy_hrtimer_prepare,
460 .start = dummy_hrtimer_start,
461 .stop = dummy_hrtimer_stop,
462 .pointer = dummy_hrtimer_pointer,
299}; 463};
300 464
301static struct snd_pcm_hardware snd_card_dummy_capture = 465#endif /* CONFIG_HIGH_RES_TIMERS */
466
467/*
468 * PCM interface
469 */
470
471static int dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
302{ 472{
303 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 473 struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
304 SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), 474
475 switch (cmd) {
476 case SNDRV_PCM_TRIGGER_START:
477 case SNDRV_PCM_TRIGGER_RESUME:
478 return dummy->timer_ops->start(substream);
479 case SNDRV_PCM_TRIGGER_STOP:
480 case SNDRV_PCM_TRIGGER_SUSPEND:
481 return dummy->timer_ops->stop(substream);
482 }
483 return -EINVAL;
484}
485
486static int dummy_pcm_prepare(struct snd_pcm_substream *substream)
487{
488 struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
489
490 return dummy->timer_ops->prepare(substream);
491}
492
493static snd_pcm_uframes_t dummy_pcm_pointer(struct snd_pcm_substream *substream)
494{
495 struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
496
497 return dummy->timer_ops->pointer(substream);
498}
499
500static struct snd_pcm_hardware dummy_pcm_hardware = {
501 .info = (SNDRV_PCM_INFO_MMAP |
502 SNDRV_PCM_INFO_INTERLEAVED |
503 SNDRV_PCM_INFO_RESUME |
504 SNDRV_PCM_INFO_MMAP_VALID),
305 .formats = USE_FORMATS, 505 .formats = USE_FORMATS,
306 .rates = USE_RATE, 506 .rates = USE_RATE,
307 .rate_min = USE_RATE_MIN, 507 .rate_min = USE_RATE_MIN,
@@ -316,123 +516,152 @@ static struct snd_pcm_hardware snd_card_dummy_capture =
316 .fifo_size = 0, 516 .fifo_size = 0,
317}; 517};
318 518
319static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime) 519static int dummy_pcm_hw_params(struct snd_pcm_substream *substream,
320{ 520 struct snd_pcm_hw_params *hw_params)
321 kfree(runtime->private_data);
322}
323
324static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream,
325 struct snd_pcm_hw_params *hw_params)
326{ 521{
327 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 522 if (fake_buffer) {
523 /* runtime->dma_bytes has to be set manually to allow mmap */
524 substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
525 return 0;
526 }
527 return snd_pcm_lib_malloc_pages(substream,
528 params_buffer_bytes(hw_params));
328} 529}
329 530
330static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream) 531static int dummy_pcm_hw_free(struct snd_pcm_substream *substream)
331{ 532{
533 if (fake_buffer)
534 return 0;
332 return snd_pcm_lib_free_pages(substream); 535 return snd_pcm_lib_free_pages(substream);
333} 536}
334 537
335static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream) 538static int dummy_pcm_open(struct snd_pcm_substream *substream)
336{
337 struct snd_dummy_pcm *dpcm;
338
339 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
340 if (! dpcm)
341 return dpcm;
342 init_timer(&dpcm->timer);
343 dpcm->timer.data = (unsigned long) dpcm;
344 dpcm->timer.function = snd_card_dummy_pcm_timer_function;
345 spin_lock_init(&dpcm->lock);
346 dpcm->substream = substream;
347 return dpcm;
348}
349
350static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream)
351{ 539{
540 struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
352 struct snd_pcm_runtime *runtime = substream->runtime; 541 struct snd_pcm_runtime *runtime = substream->runtime;
353 struct snd_dummy_pcm *dpcm;
354 int err; 542 int err;
355 543
356 if ((dpcm = new_pcm_stream(substream)) == NULL) 544 dummy->timer_ops = &dummy_systimer_ops;
357 return -ENOMEM; 545#ifdef CONFIG_HIGH_RES_TIMERS
358 runtime->private_data = dpcm; 546 if (hrtimer)
359 /* makes the infrastructure responsible for freeing dpcm */ 547 dummy->timer_ops = &dummy_hrtimer_ops;
360 runtime->private_free = snd_card_dummy_runtime_free; 548#endif
361 runtime->hw = snd_card_dummy_playback; 549
550 err = dummy->timer_ops->create(substream);
551 if (err < 0)
552 return err;
553
554 runtime->hw = dummy_pcm_hardware;
362 if (substream->pcm->device & 1) { 555 if (substream->pcm->device & 1) {
363 runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 556 runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED;
364 runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 557 runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
365 } 558 }
366 if (substream->pcm->device & 2) 559 if (substream->pcm->device & 2)
367 runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); 560 runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP |
368 err = add_playback_constraints(runtime); 561 SNDRV_PCM_INFO_MMAP_VALID);
369 if (err < 0) 562
563 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
564 err = add_playback_constraints(substream->runtime);
565 else
566 err = add_capture_constraints(substream->runtime);
567 if (err < 0) {
568 dummy->timer_ops->free(substream);
370 return err; 569 return err;
371 570 }
372 return 0; 571 return 0;
373} 572}
374 573
375static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream) 574static int dummy_pcm_close(struct snd_pcm_substream *substream)
376{ 575{
377 struct snd_pcm_runtime *runtime = substream->runtime; 576 struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
378 struct snd_dummy_pcm *dpcm; 577 dummy->timer_ops->free(substream);
379 int err; 578 return 0;
579}
380 580
381 if ((dpcm = new_pcm_stream(substream)) == NULL) 581/*
382 return -ENOMEM; 582 * dummy buffer handling
383 runtime->private_data = dpcm; 583 */
384 /* makes the infrastructure responsible for freeing dpcm */ 584
385 runtime->private_free = snd_card_dummy_runtime_free; 585static void *dummy_page[2];
386 runtime->hw = snd_card_dummy_capture; 586
387 if (substream->pcm->device == 1) { 587static void free_fake_buffer(void)
388 runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 588{
389 runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 589 if (fake_buffer) {
590 int i;
591 for (i = 0; i < 2; i++)
592 if (dummy_page[i]) {
593 free_page((unsigned long)dummy_page[i]);
594 dummy_page[i] = NULL;
595 }
390 } 596 }
391 if (substream->pcm->device & 2) 597}
392 runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
393 err = add_capture_constraints(runtime);
394 if (err < 0)
395 return err;
396 598
599static int alloc_fake_buffer(void)
600{
601 int i;
602
603 if (!fake_buffer)
604 return 0;
605 for (i = 0; i < 2; i++) {
606 dummy_page[i] = (void *)get_zeroed_page(GFP_KERNEL);
607 if (!dummy_page[i]) {
608 free_fake_buffer();
609 return -ENOMEM;
610 }
611 }
397 return 0; 612 return 0;
398} 613}
399 614
400static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream) 615static int dummy_pcm_copy(struct snd_pcm_substream *substream,
616 int channel, snd_pcm_uframes_t pos,
617 void __user *dst, snd_pcm_uframes_t count)
401{ 618{
402 return 0; 619 return 0; /* do nothing */
403} 620}
404 621
405static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream) 622static int dummy_pcm_silence(struct snd_pcm_substream *substream,
623 int channel, snd_pcm_uframes_t pos,
624 snd_pcm_uframes_t count)
406{ 625{
407 return 0; 626 return 0; /* do nothing */
627}
628
629static struct page *dummy_pcm_page(struct snd_pcm_substream *substream,
630 unsigned long offset)
631{
632 return virt_to_page(dummy_page[substream->stream]); /* the same page */
408} 633}
409 634
410static struct snd_pcm_ops snd_card_dummy_playback_ops = { 635static struct snd_pcm_ops dummy_pcm_ops = {
411 .open = snd_card_dummy_playback_open, 636 .open = dummy_pcm_open,
412 .close = snd_card_dummy_playback_close, 637 .close = dummy_pcm_close,
413 .ioctl = snd_pcm_lib_ioctl, 638 .ioctl = snd_pcm_lib_ioctl,
414 .hw_params = snd_card_dummy_hw_params, 639 .hw_params = dummy_pcm_hw_params,
415 .hw_free = snd_card_dummy_hw_free, 640 .hw_free = dummy_pcm_hw_free,
416 .prepare = snd_card_dummy_pcm_prepare, 641 .prepare = dummy_pcm_prepare,
417 .trigger = snd_card_dummy_pcm_trigger, 642 .trigger = dummy_pcm_trigger,
418 .pointer = snd_card_dummy_pcm_pointer, 643 .pointer = dummy_pcm_pointer,
419}; 644};
420 645
421static struct snd_pcm_ops snd_card_dummy_capture_ops = { 646static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
422 .open = snd_card_dummy_capture_open, 647 .open = dummy_pcm_open,
423 .close = snd_card_dummy_capture_close, 648 .close = dummy_pcm_close,
424 .ioctl = snd_pcm_lib_ioctl, 649 .ioctl = snd_pcm_lib_ioctl,
425 .hw_params = snd_card_dummy_hw_params, 650 .hw_params = dummy_pcm_hw_params,
426 .hw_free = snd_card_dummy_hw_free, 651 .hw_free = dummy_pcm_hw_free,
427 .prepare = snd_card_dummy_pcm_prepare, 652 .prepare = dummy_pcm_prepare,
428 .trigger = snd_card_dummy_pcm_trigger, 653 .trigger = dummy_pcm_trigger,
429 .pointer = snd_card_dummy_pcm_pointer, 654 .pointer = dummy_pcm_pointer,
655 .copy = dummy_pcm_copy,
656 .silence = dummy_pcm_silence,
657 .page = dummy_pcm_page,
430}; 658};
431 659
432static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device, 660static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
433 int substreams) 661 int substreams)
434{ 662{
435 struct snd_pcm *pcm; 663 struct snd_pcm *pcm;
664 struct snd_pcm_ops *ops;
436 int err; 665 int err;
437 666
438 err = snd_pcm_new(dummy->card, "Dummy PCM", device, 667 err = snd_pcm_new(dummy->card, "Dummy PCM", device,
@@ -440,17 +669,28 @@ static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
440 if (err < 0) 669 if (err < 0)
441 return err; 670 return err;
442 dummy->pcm = pcm; 671 dummy->pcm = pcm;
443 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops); 672 if (fake_buffer)
444 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops); 673 ops = &dummy_pcm_ops_no_buf;
674 else
675 ops = &dummy_pcm_ops;
676 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, ops);
677 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, ops);
445 pcm->private_data = dummy; 678 pcm->private_data = dummy;
446 pcm->info_flags = 0; 679 pcm->info_flags = 0;
447 strcpy(pcm->name, "Dummy PCM"); 680 strcpy(pcm->name, "Dummy PCM");
448 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, 681 if (!fake_buffer) {
449 snd_dma_continuous_data(GFP_KERNEL), 682 snd_pcm_lib_preallocate_pages_for_all(pcm,
450 0, 64*1024); 683 SNDRV_DMA_TYPE_CONTINUOUS,
684 snd_dma_continuous_data(GFP_KERNEL),
685 0, 64*1024);
686 }
451 return 0; 687 return 0;
452} 688}
453 689
690/*
691 * mixer interface
692 */
693
454#define DUMMY_VOLUME(xname, xindex, addr) \ 694#define DUMMY_VOLUME(xname, xindex, addr) \
455{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 695{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
456 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ 696 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
@@ -581,6 +821,131 @@ static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
581 return 0; 821 return 0;
582} 822}
583 823
824#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_PROC_FS)
825/*
826 * proc interface
827 */
828static void print_formats(struct snd_info_buffer *buffer)
829{
830 int i;
831
832 for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) {
833 if (dummy_pcm_hardware.formats & (1ULL << i))
834 snd_iprintf(buffer, " %s", snd_pcm_format_name(i));
835 }
836}
837
838static void print_rates(struct snd_info_buffer *buffer)
839{
840 static int rates[] = {
841 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000,
842 64000, 88200, 96000, 176400, 192000,
843 };
844 int i;
845
846 if (dummy_pcm_hardware.rates & SNDRV_PCM_RATE_CONTINUOUS)
847 snd_iprintf(buffer, " continuous");
848 if (dummy_pcm_hardware.rates & SNDRV_PCM_RATE_KNOT)
849 snd_iprintf(buffer, " knot");
850 for (i = 0; i < ARRAY_SIZE(rates); i++)
851 if (dummy_pcm_hardware.rates & (1 << i))
852 snd_iprintf(buffer, " %d", rates[i]);
853}
854
855#define get_dummy_int_ptr(ofs) \
856 (unsigned int *)((char *)&dummy_pcm_hardware + (ofs))
857#define get_dummy_ll_ptr(ofs) \
858 (unsigned long long *)((char *)&dummy_pcm_hardware + (ofs))
859
860struct dummy_hw_field {
861 const char *name;
862 const char *format;
863 unsigned int offset;
864 unsigned int size;
865};
866#define FIELD_ENTRY(item, fmt) { \
867 .name = #item, \
868 .format = fmt, \
869 .offset = offsetof(struct snd_pcm_hardware, item), \
870 .size = sizeof(dummy_pcm_hardware.item) }
871
872static struct dummy_hw_field fields[] = {
873 FIELD_ENTRY(formats, "%#llx"),
874 FIELD_ENTRY(rates, "%#x"),
875 FIELD_ENTRY(rate_min, "%d"),
876 FIELD_ENTRY(rate_max, "%d"),
877 FIELD_ENTRY(channels_min, "%d"),
878 FIELD_ENTRY(channels_max, "%d"),
879 FIELD_ENTRY(buffer_bytes_max, "%ld"),
880 FIELD_ENTRY(period_bytes_min, "%ld"),
881 FIELD_ENTRY(period_bytes_max, "%ld"),
882 FIELD_ENTRY(periods_min, "%d"),
883 FIELD_ENTRY(periods_max, "%d"),
884};
885
886static void dummy_proc_read(struct snd_info_entry *entry,
887 struct snd_info_buffer *buffer)
888{
889 int i;
890
891 for (i = 0; i < ARRAY_SIZE(fields); i++) {
892 snd_iprintf(buffer, "%s ", fields[i].name);
893 if (fields[i].size == sizeof(int))
894 snd_iprintf(buffer, fields[i].format,
895 *get_dummy_int_ptr(fields[i].offset));
896 else
897 snd_iprintf(buffer, fields[i].format,
898 *get_dummy_ll_ptr(fields[i].offset));
899 if (!strcmp(fields[i].name, "formats"))
900 print_formats(buffer);
901 else if (!strcmp(fields[i].name, "rates"))
902 print_rates(buffer);
903 snd_iprintf(buffer, "\n");
904 }
905}
906
907static void dummy_proc_write(struct snd_info_entry *entry,
908 struct snd_info_buffer *buffer)
909{
910 char line[64];
911
912 while (!snd_info_get_line(buffer, line, sizeof(line))) {
913 char item[20];
914 const char *ptr;
915 unsigned long long val;
916 int i;
917
918 ptr = snd_info_get_str(item, line, sizeof(item));
919 for (i = 0; i < ARRAY_SIZE(fields); i++) {
920 if (!strcmp(item, fields[i].name))
921 break;
922 }
923 if (i >= ARRAY_SIZE(fields))
924 continue;
925 snd_info_get_str(item, ptr, sizeof(item));
926 if (strict_strtoull(item, 0, &val))
927 continue;
928 if (fields[i].size == sizeof(int))
929 *get_dummy_int_ptr(fields[i].offset) = val;
930 else
931 *get_dummy_ll_ptr(fields[i].offset) = val;
932 }
933}
934
935static void __devinit dummy_proc_init(struct snd_dummy *chip)
936{
937 struct snd_info_entry *entry;
938
939 if (!snd_card_proc_new(chip->card, "dummy_pcm", &entry)) {
940 snd_info_set_text_ops(entry, chip, dummy_proc_read);
941 entry->c.text.write = dummy_proc_write;
942 entry->mode |= S_IWUSR;
943 }
944}
945#else
946#define dummy_proc_init(x)
947#endif /* CONFIG_SND_DEBUG && CONFIG_PROC_FS */
948
584static int __devinit snd_dummy_probe(struct platform_device *devptr) 949static int __devinit snd_dummy_probe(struct platform_device *devptr)
585{ 950{
586 struct snd_card *card; 951 struct snd_card *card;
@@ -610,6 +975,8 @@ static int __devinit snd_dummy_probe(struct platform_device *devptr)
610 strcpy(card->shortname, "Dummy"); 975 strcpy(card->shortname, "Dummy");
611 sprintf(card->longname, "Dummy %i", dev + 1); 976 sprintf(card->longname, "Dummy %i", dev + 1);
612 977
978 dummy_proc_init(dummy);
979
613 snd_card_set_dev(card, &devptr->dev); 980 snd_card_set_dev(card, &devptr->dev);
614 981
615 err = snd_card_register(card); 982 err = snd_card_register(card);
@@ -670,6 +1037,7 @@ static void snd_dummy_unregister_all(void)
670 for (i = 0; i < ARRAY_SIZE(devices); ++i) 1037 for (i = 0; i < ARRAY_SIZE(devices); ++i)
671 platform_device_unregister(devices[i]); 1038 platform_device_unregister(devices[i]);
672 platform_driver_unregister(&snd_dummy_driver); 1039 platform_driver_unregister(&snd_dummy_driver);
1040 free_fake_buffer();
673} 1041}
674 1042
675static int __init alsa_card_dummy_init(void) 1043static int __init alsa_card_dummy_init(void)
@@ -680,6 +1048,12 @@ static int __init alsa_card_dummy_init(void)
680 if (err < 0) 1048 if (err < 0)
681 return err; 1049 return err;
682 1050
1051 err = alloc_fake_buffer();
1052 if (err < 0) {
1053 platform_driver_unregister(&snd_dummy_driver);
1054 return err;
1055 }
1056
683 cards = 0; 1057 cards = 0;
684 for (i = 0; i < SNDRV_CARDS; i++) { 1058 for (i = 0; i < SNDRV_CARDS; i++) {
685 struct platform_device *device; 1059 struct platform_device *device;
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
index de83608719ea..02f79d252718 100644
--- a/sound/isa/cmi8330.c
+++ b/sound/isa/cmi8330.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Driver for C-Media's CMI8330 soundcards. 2 * Driver for C-Media's CMI8330 and CMI8329 soundcards.
3 * Copyright (c) by George Talusan <gstalusan@uwaterloo.ca> 3 * Copyright (c) by George Talusan <gstalusan@uwaterloo.ca>
4 * http://www.undergrad.math.uwaterloo.ca/~gstalusa 4 * http://www.undergrad.math.uwaterloo.ca/~gstalusa
5 * 5 *
@@ -35,7 +35,7 @@
35 * 35 *
36 * This card has two mixers and two PCM devices. I've cheesed it such 36 * This card has two mixers and two PCM devices. I've cheesed it such
37 * that recording and playback can be done through the same device. 37 * that recording and playback can be done through the same device.
38 * The driver "magically" routes the capturing to the CMI8330 codec, 38 * The driver "magically" routes the capturing to the AD1848 codec,
39 * and playback to the SB16 codec. This allows for full-duplex mode 39 * and playback to the SB16 codec. This allows for full-duplex mode
40 * to some extent. 40 * to some extent.
41 * The utilities in alsa-utils are aware of both devices, so passing 41 * The utilities in alsa-utils are aware of both devices, so passing
@@ -64,7 +64,7 @@
64/* 64/*
65 */ 65 */
66MODULE_AUTHOR("George Talusan <gstalusan@uwaterloo.ca>"); 66MODULE_AUTHOR("George Talusan <gstalusan@uwaterloo.ca>");
67MODULE_DESCRIPTION("C-Media CMI8330"); 67MODULE_DESCRIPTION("C-Media CMI8330/CMI8329");
68MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
69MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8330,isapnp:{CMI0001,@@@0001,@X@0001}}}"); 69MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8330,isapnp:{CMI0001,@@@0001,@X@0001}}}");
70 70
@@ -86,38 +86,38 @@ static long mpuport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
86static int mpuirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; 86static int mpuirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
87 87
88module_param_array(index, int, NULL, 0444); 88module_param_array(index, int, NULL, 0444);
89MODULE_PARM_DESC(index, "Index value for CMI8330 soundcard."); 89MODULE_PARM_DESC(index, "Index value for CMI8330/CMI8329 soundcard.");
90module_param_array(id, charp, NULL, 0444); 90module_param_array(id, charp, NULL, 0444);
91MODULE_PARM_DESC(id, "ID string for CMI8330 soundcard."); 91MODULE_PARM_DESC(id, "ID string for CMI8330/CMI8329 soundcard.");
92module_param_array(enable, bool, NULL, 0444); 92module_param_array(enable, bool, NULL, 0444);
93MODULE_PARM_DESC(enable, "Enable CMI8330 soundcard."); 93MODULE_PARM_DESC(enable, "Enable CMI8330/CMI8329 soundcard.");
94#ifdef CONFIG_PNP 94#ifdef CONFIG_PNP
95module_param_array(isapnp, bool, NULL, 0444); 95module_param_array(isapnp, bool, NULL, 0444);
96MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard."); 96MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
97#endif 97#endif
98 98
99module_param_array(sbport, long, NULL, 0444); 99module_param_array(sbport, long, NULL, 0444);
100MODULE_PARM_DESC(sbport, "Port # for CMI8330 SB driver."); 100MODULE_PARM_DESC(sbport, "Port # for CMI8330/CMI8329 SB driver.");
101module_param_array(sbirq, int, NULL, 0444); 101module_param_array(sbirq, int, NULL, 0444);
102MODULE_PARM_DESC(sbirq, "IRQ # for CMI8330 SB driver."); 102MODULE_PARM_DESC(sbirq, "IRQ # for CMI8330/CMI8329 SB driver.");
103module_param_array(sbdma8, int, NULL, 0444); 103module_param_array(sbdma8, int, NULL, 0444);
104MODULE_PARM_DESC(sbdma8, "DMA8 for CMI8330 SB driver."); 104MODULE_PARM_DESC(sbdma8, "DMA8 for CMI8330/CMI8329 SB driver.");
105module_param_array(sbdma16, int, NULL, 0444); 105module_param_array(sbdma16, int, NULL, 0444);
106MODULE_PARM_DESC(sbdma16, "DMA16 for CMI8330 SB driver."); 106MODULE_PARM_DESC(sbdma16, "DMA16 for CMI8330/CMI8329 SB driver.");
107 107
108module_param_array(wssport, long, NULL, 0444); 108module_param_array(wssport, long, NULL, 0444);
109MODULE_PARM_DESC(wssport, "Port # for CMI8330 WSS driver."); 109MODULE_PARM_DESC(wssport, "Port # for CMI8330/CMI8329 WSS driver.");
110module_param_array(wssirq, int, NULL, 0444); 110module_param_array(wssirq, int, NULL, 0444);
111MODULE_PARM_DESC(wssirq, "IRQ # for CMI8330 WSS driver."); 111MODULE_PARM_DESC(wssirq, "IRQ # for CMI8330/CMI8329 WSS driver.");
112module_param_array(wssdma, int, NULL, 0444); 112module_param_array(wssdma, int, NULL, 0444);
113MODULE_PARM_DESC(wssdma, "DMA for CMI8330 WSS driver."); 113MODULE_PARM_DESC(wssdma, "DMA for CMI8330/CMI8329 WSS driver.");
114 114
115module_param_array(fmport, long, NULL, 0444); 115module_param_array(fmport, long, NULL, 0444);
116MODULE_PARM_DESC(fmport, "FM port # for CMI8330 driver."); 116MODULE_PARM_DESC(fmport, "FM port # for CMI8330/CMI8329 driver.");
117module_param_array(mpuport, long, NULL, 0444); 117module_param_array(mpuport, long, NULL, 0444);
118MODULE_PARM_DESC(mpuport, "MPU-401 port # for CMI8330 driver."); 118MODULE_PARM_DESC(mpuport, "MPU-401 port # for CMI8330/CMI8329 driver.");
119module_param_array(mpuirq, int, NULL, 0444); 119module_param_array(mpuirq, int, NULL, 0444);
120MODULE_PARM_DESC(mpuirq, "IRQ # for CMI8330 MPU-401 port."); 120MODULE_PARM_DESC(mpuirq, "IRQ # for CMI8330/CMI8329 MPU-401 port.");
121#ifdef CONFIG_PNP 121#ifdef CONFIG_PNP
122static int isa_registered; 122static int isa_registered;
123static int pnp_registered; 123static int pnp_registered;
@@ -156,6 +156,11 @@ static unsigned char snd_cmi8330_image[((CMI8330_CDINGAIN)-16) + 1] =
156 156
157typedef int (*snd_pcm_open_callback_t)(struct snd_pcm_substream *); 157typedef int (*snd_pcm_open_callback_t)(struct snd_pcm_substream *);
158 158
159enum card_type {
160 CMI8330,
161 CMI8329
162};
163
159struct snd_cmi8330 { 164struct snd_cmi8330 {
160#ifdef CONFIG_PNP 165#ifdef CONFIG_PNP
161 struct pnp_dev *cap; 166 struct pnp_dev *cap;
@@ -172,11 +177,14 @@ struct snd_cmi8330 {
172 snd_pcm_open_callback_t open; 177 snd_pcm_open_callback_t open;
173 void *private_data; /* sb or wss */ 178 void *private_data; /* sb or wss */
174 } streams[2]; 179 } streams[2];
180
181 enum card_type type;
175}; 182};
176 183
177#ifdef CONFIG_PNP 184#ifdef CONFIG_PNP
178 185
179static struct pnp_card_device_id snd_cmi8330_pnpids[] = { 186static struct pnp_card_device_id snd_cmi8330_pnpids[] = {
187 { .id = "CMI0001", .devs = { { "@X@0001" }, { "@@@0001" }, { "@H@0001" }, { "A@@0001" } } },
180 { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } }, 188 { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
181 { .id = "" } 189 { .id = "" }
182}; 190};
@@ -304,7 +312,7 @@ static int __devinit snd_cmi8330_mixer(struct snd_card *card, struct snd_cmi8330
304 unsigned int idx; 312 unsigned int idx;
305 int err; 313 int err;
306 314
307 strcpy(card->mixername, "CMI8330/C3D"); 315 strcpy(card->mixername, (acard->type == CMI8329) ? "CMI8329" : "CMI8330/C3D");
308 316
309 for (idx = 0; idx < ARRAY_SIZE(snd_cmi8330_controls); idx++) { 317 for (idx = 0; idx < ARRAY_SIZE(snd_cmi8330_controls); idx++) {
310 err = snd_ctl_add(card, 318 err = snd_ctl_add(card,
@@ -329,6 +337,9 @@ static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
329 struct pnp_dev *pdev; 337 struct pnp_dev *pdev;
330 int err; 338 int err;
331 339
340 /* CMI8329 has a device with ID A@@0001, CMI8330 does not */
341 acard->type = (id->devs[3].id[0]) ? CMI8329 : CMI8330;
342
332 acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL); 343 acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL);
333 if (acard->cap == NULL) 344 if (acard->cap == NULL)
334 return -EBUSY; 345 return -EBUSY;
@@ -338,45 +349,52 @@ static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
338 return -EBUSY; 349 return -EBUSY;
339 350
340 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL); 351 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
341 if (acard->play == NULL) 352 if (acard->mpu == NULL)
342 return -EBUSY; 353 return -EBUSY;
343 354
344 pdev = acard->cap; 355 pdev = acard->cap;
345 356
346 err = pnp_activate_dev(pdev); 357 err = pnp_activate_dev(pdev);
347 if (err < 0) { 358 if (err < 0) {
348 snd_printk(KERN_ERR "CMI8330/C3D PnP configure failure\n"); 359 snd_printk(KERN_ERR "AD1848 PnP configure failure\n");
349 return -EBUSY; 360 return -EBUSY;
350 } 361 }
351 wssport[dev] = pnp_port_start(pdev, 0); 362 wssport[dev] = pnp_port_start(pdev, 0);
352 wssdma[dev] = pnp_dma(pdev, 0); 363 wssdma[dev] = pnp_dma(pdev, 0);
353 wssirq[dev] = pnp_irq(pdev, 0); 364 wssirq[dev] = pnp_irq(pdev, 0);
354 fmport[dev] = pnp_port_start(pdev, 1); 365 if (pnp_port_start(pdev, 1))
366 fmport[dev] = pnp_port_start(pdev, 1);
355 367
356 /* allocate SB16 resources */ 368 /* allocate SB16 resources */
357 pdev = acard->play; 369 pdev = acard->play;
358 370
359 err = pnp_activate_dev(pdev); 371 err = pnp_activate_dev(pdev);
360 if (err < 0) { 372 if (err < 0) {
361 snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP configure failure\n"); 373 snd_printk(KERN_ERR "SB16 PnP configure failure\n");
362 return -EBUSY; 374 return -EBUSY;
363 } 375 }
364 sbport[dev] = pnp_port_start(pdev, 0); 376 sbport[dev] = pnp_port_start(pdev, 0);
365 sbdma8[dev] = pnp_dma(pdev, 0); 377 sbdma8[dev] = pnp_dma(pdev, 0);
366 sbdma16[dev] = pnp_dma(pdev, 1); 378 sbdma16[dev] = pnp_dma(pdev, 1);
367 sbirq[dev] = pnp_irq(pdev, 0); 379 sbirq[dev] = pnp_irq(pdev, 0);
380 /* On CMI8239, the OPL3 port might be present in SB16 PnP resources */
381 if (fmport[dev] == SNDRV_AUTO_PORT) {
382 if (pnp_port_start(pdev, 1))
383 fmport[dev] = pnp_port_start(pdev, 1);
384 else
385 fmport[dev] = 0x388; /* Or hardwired */
386 }
368 387
369 /* allocate MPU-401 resources */ 388 /* allocate MPU-401 resources */
370 pdev = acard->mpu; 389 pdev = acard->mpu;
371 390
372 err = pnp_activate_dev(pdev); 391 err = pnp_activate_dev(pdev);
373 if (err < 0) { 392 if (err < 0)
374 snd_printk(KERN_ERR 393 snd_printk(KERN_ERR "MPU-401 PnP configure failure: will be disabled\n");
375 "CMI8330/C3D (MPU-401) PnP configure failure\n"); 394 else {
376 return -EBUSY; 395 mpuport[dev] = pnp_port_start(pdev, 0);
396 mpuirq[dev] = pnp_irq(pdev, 0);
377 } 397 }
378 mpuport[dev] = pnp_port_start(pdev, 0);
379 mpuirq[dev] = pnp_irq(pdev, 0);
380 return 0; 398 return 0;
381} 399}
382#endif 400#endif
@@ -430,9 +448,9 @@ static int __devinit snd_cmi8330_pcm(struct snd_card *card, struct snd_cmi8330 *
430 snd_cmi8330_capture_open 448 snd_cmi8330_capture_open
431 }; 449 };
432 450
433 if ((err = snd_pcm_new(card, "CMI8330", 0, 1, 1, &pcm)) < 0) 451 if ((err = snd_pcm_new(card, (chip->type == CMI8329) ? "CMI8329" : "CMI8330", 0, 1, 1, &pcm)) < 0)
434 return err; 452 return err;
435 strcpy(pcm->name, "CMI8330"); 453 strcpy(pcm->name, (chip->type == CMI8329) ? "CMI8329" : "CMI8330");
436 pcm->private_data = chip; 454 pcm->private_data = chip;
437 455
438 /* SB16 */ 456 /* SB16 */
@@ -527,11 +545,11 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev)
527 wssdma[dev], -1, 545 wssdma[dev], -1,
528 WSS_HW_DETECT, 0, &acard->wss); 546 WSS_HW_DETECT, 0, &acard->wss);
529 if (err < 0) { 547 if (err < 0) {
530 snd_printk(KERN_ERR PFX "(CMI8330) device busy??\n"); 548 snd_printk(KERN_ERR PFX "AD1848 device busy??\n");
531 return err; 549 return err;
532 } 550 }
533 if (acard->wss->hardware != WSS_HW_CMI8330) { 551 if (acard->wss->hardware != WSS_HW_CMI8330) {
534 snd_printk(KERN_ERR PFX "(CMI8330) not found during probe\n"); 552 snd_printk(KERN_ERR PFX "AD1848 not found during probe\n");
535 return -ENODEV; 553 return -ENODEV;
536 } 554 }
537 555
@@ -541,11 +559,11 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev)
541 sbdma8[dev], 559 sbdma8[dev],
542 sbdma16[dev], 560 sbdma16[dev],
543 SB_HW_AUTO, &acard->sb)) < 0) { 561 SB_HW_AUTO, &acard->sb)) < 0) {
544 snd_printk(KERN_ERR PFX "(SB16) device busy??\n"); 562 snd_printk(KERN_ERR PFX "SB16 device busy??\n");
545 return err; 563 return err;
546 } 564 }
547 if (acard->sb->hardware != SB_HW_16) { 565 if (acard->sb->hardware != SB_HW_16) {
548 snd_printk(KERN_ERR PFX "(SB16) not found during probe\n"); 566 snd_printk(KERN_ERR PFX "SB16 not found during probe\n");
549 return err; 567 return err;
550 } 568 }
551 569
@@ -585,8 +603,8 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev)
585 mpuport[dev]); 603 mpuport[dev]);
586 } 604 }
587 605
588 strcpy(card->driver, "CMI8330/C3D"); 606 strcpy(card->driver, (acard->type == CMI8329) ? "CMI8329" : "CMI8330/C3D");
589 strcpy(card->shortname, "C-Media CMI8330/C3D"); 607 strcpy(card->shortname, (acard->type == CMI8329) ? "C-Media CMI8329" : "C-Media CMI8330/C3D");
590 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", 608 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
591 card->shortname, 609 card->shortname,
592 acard->wss->port, 610 acard->wss->port,
diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c
index edb11eefdfe3..2dcf45bf7293 100644
--- a/sound/isa/gus/gus_pcm.c
+++ b/sound/isa/gus/gus_pcm.c
@@ -795,13 +795,13 @@ static int snd_gf1_pcm_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
795 if (!(pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE)) 795 if (!(pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE))
796 continue; 796 continue;
797 /* load real volume - better precision */ 797 /* load real volume - better precision */
798 spin_lock_irqsave(&gus->reg_lock, flags); 798 spin_lock(&gus->reg_lock);
799 snd_gf1_select_voice(gus, pvoice->number); 799 snd_gf1_select_voice(gus, pvoice->number);
800 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); 800 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
801 vol = pvoice == pcmp->pvoices[0] ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right; 801 vol = pvoice == pcmp->pvoices[0] ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right;
802 snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, vol); 802 snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, vol);
803 pcmp->final_volume = 1; 803 pcmp->final_volume = 1;
804 spin_unlock_irqrestore(&gus->reg_lock, flags); 804 spin_unlock(&gus->reg_lock);
805 } 805 }
806 spin_unlock_irqrestore(&gus->voice_alloc, flags); 806 spin_unlock_irqrestore(&gus->voice_alloc, flags);
807 return change; 807 return change;
diff --git a/sound/mips/hal2.c b/sound/mips/hal2.c
index c52691c2fc46..9a88cdfd952a 100644
--- a/sound/mips/hal2.c
+++ b/sound/mips/hal2.c
@@ -915,7 +915,7 @@ static int __devinit hal2_probe(struct platform_device *pdev)
915 return 0; 915 return 0;
916} 916}
917 917
918static int __exit hal2_remove(struct platform_device *pdev) 918static int __devexit hal2_remove(struct platform_device *pdev)
919{ 919{
920 struct snd_card *card = platform_get_drvdata(pdev); 920 struct snd_card *card = platform_get_drvdata(pdev);
921 921
diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index e497525bc11b..8691f4cf6191 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -973,7 +973,7 @@ static int __devinit snd_sgio2audio_probe(struct platform_device *pdev)
973 return 0; 973 return 0;
974} 974}
975 975
976static int __exit snd_sgio2audio_remove(struct platform_device *pdev) 976static int __devexit snd_sgio2audio_remove(struct platform_device *pdev)
977{ 977{
978 struct snd_card *card = platform_get_drvdata(pdev); 978 struct snd_card *card = platform_get_drvdata(pdev);
979 979
diff --git a/sound/oss/aedsp16.c b/sound/oss/aedsp16.c
index 3ee9900ffd7b..35b5912cf3f8 100644
--- a/sound/oss/aedsp16.c
+++ b/sound/oss/aedsp16.c
@@ -325,8 +325,9 @@
325/* 325/*
326 * Size of character arrays that store name and version of sound card 326 * Size of character arrays that store name and version of sound card
327 */ 327 */
328#define CARDNAMELEN 15 /* Size of the card's name in chars */ 328#define CARDNAMELEN 15 /* Size of the card's name in chars */
329#define CARDVERLEN 2 /* Size of the card's version in chars */ 329#define CARDVERLEN 10 /* Size of the card's version in chars */
330#define CARDVERDIGITS 2 /* Number of digits in the version */
330 331
331#if defined(CONFIG_SC6600) 332#if defined(CONFIG_SC6600)
332/* 333/*
@@ -410,7 +411,7 @@
410 411
411static int soft_cfg __initdata = 0; /* bitmapped config */ 412static int soft_cfg __initdata = 0; /* bitmapped config */
412static int soft_cfg_mss __initdata = 0; /* bitmapped mss config */ 413static int soft_cfg_mss __initdata = 0; /* bitmapped mss config */
413static int ver[CARDVERLEN] __initdata = {0, 0}; /* DSP Ver: 414static int ver[CARDVERDIGITS] __initdata = {0, 0}; /* DSP Ver:
414 hi->ver[0] lo->ver[1] */ 415 hi->ver[0] lo->ver[1] */
415 416
416#if defined(CONFIG_SC6600) 417#if defined(CONFIG_SC6600)
@@ -957,7 +958,7 @@ static int __init aedsp16_dsp_version(int port)
957 * string is finished. 958 * string is finished.
958 */ 959 */
959 ver[len++] = ret; 960 ver[len++] = ret;
960 } while (len < CARDVERLEN); 961 } while (len < CARDVERDIGITS);
961 sprintf(DSPVersion, "%d.%d", ver[0], ver[1]); 962 sprintf(DSPVersion, "%d.%d", ver[0], ver[1]);
962 963
963 DBG(("success.\n")); 964 DBG(("success.\n"));
diff --git a/sound/oss/kahlua.c b/sound/oss/kahlua.c
index c180598f1710..89466b056be7 100644
--- a/sound/oss/kahlua.c
+++ b/sound/oss/kahlua.c
@@ -199,7 +199,7 @@ MODULE_LICENSE("GPL");
199 */ 199 */
200 200
201static struct pci_device_id id_tbl[] = { 201static struct pci_device_id id_tbl[] = {
202 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 202 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO), 0 },
203 { } 203 { }
204}; 204};
205 205
diff --git a/sound/oss/midibuf.c b/sound/oss/midibuf.c
index a40be0cf1d97..782b3b84dac6 100644
--- a/sound/oss/midibuf.c
+++ b/sound/oss/midibuf.c
@@ -127,15 +127,16 @@ static void midi_poll(unsigned long dummy)
127 for (dev = 0; dev < num_midis; dev++) 127 for (dev = 0; dev < num_midis; dev++)
128 if (midi_devs[dev] != NULL && midi_out_buf[dev] != NULL) 128 if (midi_devs[dev] != NULL && midi_out_buf[dev] != NULL)
129 { 129 {
130 int ok = 1; 130 while (DATA_AVAIL(midi_out_buf[dev]))
131
132 while (DATA_AVAIL(midi_out_buf[dev]) && ok)
133 { 131 {
132 int ok;
134 int c = midi_out_buf[dev]->queue[midi_out_buf[dev]->head]; 133 int c = midi_out_buf[dev]->queue[midi_out_buf[dev]->head];
135 134
136 spin_unlock_irqrestore(&lock,flags);/* Give some time to others */ 135 spin_unlock_irqrestore(&lock,flags);/* Give some time to others */
137 ok = midi_devs[dev]->outputc(dev, c); 136 ok = midi_devs[dev]->outputc(dev, c);
138 spin_lock_irqsave(&lock, flags); 137 spin_lock_irqsave(&lock, flags);
138 if (!ok)
139 break;
139 midi_out_buf[dev]->head = (midi_out_buf[dev]->head + 1) % MAX_QUEUE_SIZE; 140 midi_out_buf[dev]->head = (midi_out_buf[dev]->head + 1) % MAX_QUEUE_SIZE;
140 midi_out_buf[dev]->len--; 141 midi_out_buf[dev]->len--;
141 } 142 }
diff --git a/sound/oss/mpu401.c b/sound/oss/mpu401.c
index 6c0a770ed054..734b8f9e2f78 100644
--- a/sound/oss/mpu401.c
+++ b/sound/oss/mpu401.c
@@ -926,31 +926,21 @@ static struct midi_operations mpu401_midi_operations[MAX_MIDI_DEV];
926static void mpu401_chk_version(int n, struct mpu_config *devc) 926static void mpu401_chk_version(int n, struct mpu_config *devc)
927{ 927{
928 int tmp; 928 int tmp;
929 unsigned long flags;
930 929
931 devc->version = devc->revision = 0; 930 devc->version = devc->revision = 0;
932 931
933 spin_lock_irqsave(&devc->lock,flags); 932 tmp = mpu_cmd(n, 0xAC, 0);
934 if ((tmp = mpu_cmd(n, 0xAC, 0)) < 0) 933 if (tmp < 0)
935 {
936 spin_unlock_irqrestore(&devc->lock,flags);
937 return; 934 return;
938 }
939 if ((tmp & 0xf0) > 0x20) /* Why it's larger than 2.x ??? */ 935 if ((tmp & 0xf0) > 0x20) /* Why it's larger than 2.x ??? */
940 {
941 spin_unlock_irqrestore(&devc->lock,flags);
942 return; 936 return;
943 }
944 devc->version = tmp; 937 devc->version = tmp;
945 938
946 if ((tmp = mpu_cmd(n, 0xAD, 0)) < 0) 939 if ((tmp = mpu_cmd(n, 0xAD, 0)) < 0) {
947 {
948 devc->version = 0; 940 devc->version = 0;
949 spin_unlock_irqrestore(&devc->lock,flags);
950 return; 941 return;
951 } 942 }
952 devc->revision = tmp; 943 devc->revision = tmp;
953 spin_unlock_irqrestore(&devc->lock,flags);
954} 944}
955 945
956int attach_mpu401(struct address_info *hw_config, struct module *owner) 946int attach_mpu401(struct address_info *hw_config, struct module *owner)
@@ -1084,7 +1074,7 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner)
1084 sprintf(mpu_synth_info[m].name, "%s (MPU401)", hw_config->name); 1074 sprintf(mpu_synth_info[m].name, "%s (MPU401)", hw_config->name);
1085 else 1075 else
1086 sprintf(mpu_synth_info[m].name, 1076 sprintf(mpu_synth_info[m].name,
1087 "MPU-401 %d.%d%c Midi interface #%d", 1077 "MPU-401 %d.%d%c MIDI #%d",
1088 (int) (devc->version & 0xf0) >> 4, 1078 (int) (devc->version & 0xf0) >> 4,
1089 devc->version & 0x0f, 1079 devc->version & 0x0f,
1090 revision_char, 1080 revision_char,
diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
index 1edab7b4ea83..3136c88eacdf 100644
--- a/sound/oss/swarm_cs4297a.c
+++ b/sound/oss/swarm_cs4297a.c
@@ -110,9 +110,6 @@ static void start_adc(struct cs4297a_state *s);
110// rather than 64k as some of the games work more responsively. 110// rather than 64k as some of the games work more responsively.
111// log base 2( buff sz = 32k). 111// log base 2( buff sz = 32k).
112 112
113//static unsigned long defaultorder = 3;
114//MODULE_PARM(defaultorder, "i");
115
116// 113//
117// Turn on/off debugging compilation by commenting out "#define CSDEBUG" 114// Turn on/off debugging compilation by commenting out "#define CSDEBUG"
118// 115//
diff --git a/sound/oss/sys_timer.c b/sound/oss/sys_timer.c
index 107534477a2f..8db6aefe15e4 100644
--- a/sound/oss/sys_timer.c
+++ b/sound/oss/sys_timer.c
@@ -100,9 +100,6 @@ def_tmr_open(int dev, int mode)
100 curr_tempo = 60; 100 curr_tempo = 60;
101 curr_timebase = 100; 101 curr_timebase = 100;
102 opened = 1; 102 opened = 1;
103
104 ;
105
106 { 103 {
107 def_tmr.expires = (1) + jiffies; 104 def_tmr.expires = (1) + jiffies;
108 add_timer(&def_tmr); 105 add_timer(&def_tmr);
diff --git a/sound/oss/vwsnd.c b/sound/oss/vwsnd.c
index 187f72750e8f..6713110bdc75 100644
--- a/sound/oss/vwsnd.c
+++ b/sound/oss/vwsnd.c
@@ -628,7 +628,7 @@ static void li_setup_dma(dma_chan_t *chan,
628 ASSERT(!(buffer_paddr & 0xFF)); 628 ASSERT(!(buffer_paddr & 0xFF));
629 chan->baseval = (buffer_paddr >> 8) | 1 << (37 - 8); 629 chan->baseval = (buffer_paddr >> 8) | 1 << (37 - 8);
630 630
631 chan->cfgval = (!LI_CCFG_LOCK | 631 chan->cfgval = ((chan->cfgval & ~LI_CCFG_LOCK) |
632 SHIFT_FIELD(desc->ad1843_slot, LI_CCFG_SLOT) | 632 SHIFT_FIELD(desc->ad1843_slot, LI_CCFG_SLOT) |
633 desc->direction | 633 desc->direction |
634 mode | 634 mode |
@@ -638,9 +638,9 @@ static void li_setup_dma(dma_chan_t *chan,
638 tmask = 13 - fragshift; /* See Lithium DMA Notes above. */ 638 tmask = 13 - fragshift; /* See Lithium DMA Notes above. */
639 ASSERT(size >= 2 && size <= 7); 639 ASSERT(size >= 2 && size <= 7);
640 ASSERT(tmask >= 1 && tmask <= 7); 640 ASSERT(tmask >= 1 && tmask <= 7);
641 chan->ctlval = (!LI_CCTL_RESET | 641 chan->ctlval = ((chan->ctlval & ~LI_CCTL_RESET) |
642 SHIFT_FIELD(size, LI_CCTL_SIZE) | 642 SHIFT_FIELD(size, LI_CCTL_SIZE) |
643 !LI_CCTL_DMA_ENABLE | 643 (chan->ctlval & ~LI_CCTL_DMA_ENABLE) |
644 SHIFT_FIELD(tmask, LI_CCTL_TMASK) | 644 SHIFT_FIELD(tmask, LI_CCTL_TMASK) |
645 SHIFT_FIELD(0, LI_CCTL_TPTR)); 645 SHIFT_FIELD(0, LI_CCTL_TPTR));
646 646
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 748f6b7d90b7..fb5ee3cc3968 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 c551006e2920..b458d208720b 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/atiixp.c b/sound/pci/atiixp.c
index 71515ddb4593..d6752dff2a44 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -287,10 +287,10 @@ struct atiixp {
287/* 287/*
288 */ 288 */
289static struct pci_device_id snd_atiixp_ids[] = { 289static struct pci_device_id snd_atiixp_ids[] = {
290 { 0x1002, 0x4341, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB200 */ 290 { PCI_VDEVICE(ATI, 0x4341), 0 }, /* SB200 */
291 { 0x1002, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB300 */ 291 { PCI_VDEVICE(ATI, 0x4361), 0 }, /* SB300 */
292 { 0x1002, 0x4370, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB400 */ 292 { PCI_VDEVICE(ATI, 0x4370), 0 }, /* SB400 */
293 { 0x1002, 0x4382, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB600 */ 293 { PCI_VDEVICE(ATI, 0x4382), 0 }, /* SB600 */
294 { 0, } 294 { 0, }
295}; 295};
296 296
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index c3136cccc559..e7e147bf8eb2 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -262,8 +262,8 @@ struct atiixp_modem {
262/* 262/*
263 */ 263 */
264static struct pci_device_id snd_atiixp_ids[] = { 264static struct pci_device_id snd_atiixp_ids[] = {
265 { 0x1002, 0x434d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB200 */ 265 { PCI_VDEVICE(ATI, 0x434d), 0 }, /* SB200 */
266 { 0x1002, 0x4378, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB400 */ 266 { PCI_VDEVICE(ATI, 0x4378), 0 }, /* SB400 */
267 { 0, } 267 { 0, }
268}; 268};
269 269
diff --git a/sound/pci/au88x0/au8810.c b/sound/pci/au88x0/au8810.c
index fce22c7af0ea..c0e8c6b295cb 100644
--- a/sound/pci/au88x0/au8810.c
+++ b/sound/pci/au88x0/au8810.c
@@ -1,8 +1,7 @@
1#include "au8810.h" 1#include "au8810.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static struct pci_device_id snd_vortex_ids[] = {
4 {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_ADVANTAGE, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_ADVANTAGE), 1,},
5 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1,},
6 {0,} 5 {0,}
7}; 6};
8 7
diff --git a/sound/pci/au88x0/au8820.c b/sound/pci/au88x0/au8820.c
index d1fbcce07257..a6527330df58 100644
--- a/sound/pci/au88x0/au8820.c
+++ b/sound/pci/au88x0/au8820.c
@@ -1,8 +1,7 @@
1#include "au8820.h" 1#include "au8820.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static struct pci_device_id snd_vortex_ids[] = {
4 {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_1, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_1), 0,},
5 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
6 {0,} 5 {0,}
7}; 6};
8 7
diff --git a/sound/pci/au88x0/au8830.c b/sound/pci/au88x0/au8830.c
index d4f2717c14fb..6c702ad4352a 100644
--- a/sound/pci/au88x0/au8830.c
+++ b/sound/pci/au88x0/au8830.c
@@ -1,8 +1,7 @@
1#include "au8830.h" 1#include "au8830.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static struct pci_device_id snd_vortex_ids[] = {
4 {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_2, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_2), 0,},
5 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
6 {0,} 5 {0,}
7}; 6};
8 7
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index f290bc56178f..8451a0169f32 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 974e05122f00..6f46b97650cc 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 57b992a5c057..15e4138bce17 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,
@@ -1876,7 +1876,7 @@ static int snd_ca0106_resume(struct pci_dev *pci)
1876 1876
1877// PCI IDs 1877// PCI IDs
1878static struct pci_device_id snd_ca0106_ids[] = { 1878static struct pci_device_id snd_ca0106_ids[] = {
1879 { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */ 1879 { PCI_VDEVICE(CREATIVE, 0x0007), 0 }, /* Audigy LS or Live 24bit */
1880 { 0, } 1880 { 0, }
1881}; 1881};
1882MODULE_DEVICE_TABLE(pci, snd_ca0106_ids); 1882MODULE_DEVICE_TABLE(pci, snd_ca0106_ids);
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 449fe02f666e..ddcd4a9fd7e6 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2797,11 +2797,11 @@ static inline void snd_cmipci_proc_init(struct cmipci *cm) {}
2797 2797
2798 2798
2799static struct pci_device_id snd_cmipci_ids[] = { 2799static struct pci_device_id snd_cmipci_ids[] = {
2800 {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2800 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A), 0},
2801 {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2801 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B), 0},
2802 {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2802 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738), 0},
2803 {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2803 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738B), 0},
2804 {PCI_VENDOR_ID_AL, PCI_DEVICE_ID_CMEDIA_CM8738, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2804 {PCI_VDEVICE(AL, PCI_DEVICE_ID_CMEDIA_CM8738), 0},
2805 {0,}, 2805 {0,},
2806}; 2806};
2807 2807
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index f6286f84a221..e2e0359bb056 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -495,7 +495,7 @@ struct cs4281 {
495static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id); 495static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id);
496 496
497static struct pci_device_id snd_cs4281_ids[] = { 497static struct pci_device_id snd_cs4281_ids[] = {
498 { 0x1013, 0x6005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CS4281 */ 498 { PCI_VDEVICE(CIRRUS, 0x6005), 0, }, /* CS4281 */
499 { 0, } 499 { 0, }
500}; 500};
501 501
diff --git a/sound/pci/cs46xx/cs46xx.c b/sound/pci/cs46xx/cs46xx.c
index c9b3e3d48cbc..033aec430117 100644
--- a/sound/pci/cs46xx/cs46xx.c
+++ b/sound/pci/cs46xx/cs46xx.c
@@ -65,9 +65,9 @@ module_param_array(mmap_valid, bool, NULL, 0444);
65MODULE_PARM_DESC(mmap_valid, "Support OSS mmap."); 65MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
66 66
67static struct pci_device_id snd_cs46xx_ids[] = { 67static struct pci_device_id snd_cs46xx_ids[] = {
68 { 0x1013, 0x6001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CS4280 */ 68 { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */
69 { 0x1013, 0x6003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CS4612 */ 69 { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */
70 { 0x1013, 0x6004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CS4615 */ 70 { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */
71 { 0, } 71 { 0, }
72}; 72};
73 73
diff --git a/sound/pci/cs46xx/cs46xx_lib.h b/sound/pci/cs46xx/cs46xx_lib.h
index 4eb55aa33612..b5189495d58a 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 2d07986f57cc..e0394e3996e8 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 a1db51b3ead8..fee35cfc0c7f 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 a49c76647307..75454648d50c 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 */
@@ -1037,7 +1037,7 @@ static int atc_line_front_unmute(struct ct_atc *atc, unsigned char state)
1037 1037
1038static int atc_line_surround_unmute(struct ct_atc *atc, unsigned char state) 1038static int atc_line_surround_unmute(struct ct_atc *atc, unsigned char state)
1039{ 1039{
1040 return atc_daio_unmute(atc, state, LINEO4); 1040 return atc_daio_unmute(atc, state, LINEO2);
1041} 1041}
1042 1042
1043static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state) 1043static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state)
@@ -1047,7 +1047,7 @@ static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state)
1047 1047
1048static int atc_line_rear_unmute(struct ct_atc *atc, unsigned char state) 1048static int atc_line_rear_unmute(struct ct_atc *atc, unsigned char state)
1049{ 1049{
1050 return atc_daio_unmute(atc, state, LINEO2); 1050 return atc_daio_unmute(atc, state, LINEO4);
1051} 1051}
1052 1052
1053static int atc_line_in_unmute(struct ct_atc *atc, unsigned char state) 1053static int atc_line_in_unmute(struct ct_atc *atc, unsigned char state)
@@ -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 082e35c08c02..af56eb949bde 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 ad3e1d144464..0cf400f879f9 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 dec46d04b041..b6b11bfe7574 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 f26d7cd9db9f..15c1e7271ea8 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 60ea23180acb..d0dc227fbdd3 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 889c495bb7d1..7dfaf67344d4 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 e1c145d8b702..c749fa720889 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 67665a7e43c6..6b78752e9503 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/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index da2065cd2c0d..1305f7ca02c3 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -950,7 +950,7 @@ static int __devinit snd_echo_new_pcm(struct echoaudio *chip)
950 Control interface 950 Control interface
951******************************************************************************/ 951******************************************************************************/
952 952
953#ifndef ECHOCARD_HAS_VMIXER 953#if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
954 954
955/******************* PCM output volume *******************/ 955/******************* PCM output volume *******************/
956static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol, 956static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
@@ -1003,6 +1003,19 @@ static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
1003 return changed; 1003 return changed;
1004} 1004}
1005 1005
1006#ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1007/* On the Mia this one controls the line-out volume */
1008static struct snd_kcontrol_new snd_echo_line_output_gain __devinitdata = {
1009 .name = "Line Playback Volume",
1010 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1011 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1012 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1013 .info = snd_echo_output_gain_info,
1014 .get = snd_echo_output_gain_get,
1015 .put = snd_echo_output_gain_put,
1016 .tlv = {.p = db_scale_output_gain},
1017};
1018#else
1006static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = { 1019static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1007 .name = "PCM Playback Volume", 1020 .name = "PCM Playback Volume",
1008 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1021 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -1012,9 +1025,10 @@ static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1012 .put = snd_echo_output_gain_put, 1025 .put = snd_echo_output_gain_put,
1013 .tlv = {.p = db_scale_output_gain}, 1026 .tlv = {.p = db_scale_output_gain},
1014}; 1027};
1015
1016#endif 1028#endif
1017 1029
1030#endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1031
1018 1032
1019 1033
1020#ifdef ECHOCARD_HAS_INPUT_GAIN 1034#ifdef ECHOCARD_HAS_INPUT_GAIN
@@ -2030,10 +2044,18 @@ static int __devinit snd_echo_probe(struct pci_dev *pci,
2030 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip); 2044 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2031 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0) 2045 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2032 goto ctl_error; 2046 goto ctl_error;
2033#else 2047#ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2034 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_pcm_output_gain, chip))) < 0) 2048 err = snd_ctl_add(chip->card,
2049 snd_ctl_new1(&snd_echo_line_output_gain, chip));
2050 if (err < 0)
2035 goto ctl_error; 2051 goto ctl_error;
2036#endif 2052#endif
2053#else /* ECHOCARD_HAS_VMIXER */
2054 err = snd_ctl_add(chip->card,
2055 snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
2056 if (err < 0)
2057 goto ctl_error;
2058#endif /* ECHOCARD_HAS_VMIXER */
2037 2059
2038#ifdef ECHOCARD_HAS_INPUT_GAIN 2060#ifdef ECHOCARD_HAS_INPUT_GAIN
2039 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0) 2061 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
diff --git a/sound/pci/echoaudio/mia.c b/sound/pci/echoaudio/mia.c
index f3b9b45c9c1b..f05c8c097aa8 100644
--- a/sound/pci/echoaudio/mia.c
+++ b/sound/pci/echoaudio/mia.c
@@ -29,6 +29,7 @@
29#define ECHOCARD_HAS_ADAT FALSE 29#define ECHOCARD_HAS_ADAT FALSE
30#define ECHOCARD_HAS_STEREO_BIG_ENDIAN32 30#define ECHOCARD_HAS_STEREO_BIG_ENDIAN32
31#define ECHOCARD_HAS_MIDI 31#define ECHOCARD_HAS_MIDI
32#define ECHOCARD_HAS_LINE_OUT_GAIN
32 33
33/* Pipe indexes */ 34/* Pipe indexes */
34#define PX_ANALOG_OUT 0 /* 8 */ 35#define PX_ANALOG_OUT 0 /* 8 */
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index c7f3b994101c..168af67d938e 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -77,9 +77,9 @@ MODULE_PARM_DESC(subsystem, "Force card subsystem model.");
77 * Class 0401: 1102:0008 (rev 00) Subsystem: 1102:1001 -> Audigy2 Value Model:SB0400 77 * Class 0401: 1102:0008 (rev 00) Subsystem: 1102:1001 -> Audigy2 Value Model:SB0400
78 */ 78 */
79static struct pci_device_id snd_emu10k1_ids[] = { 79static struct pci_device_id snd_emu10k1_ids[] = {
80 { 0x1102, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* EMU10K1 */ 80 { PCI_VDEVICE(CREATIVE, 0x0002), 0 }, /* EMU10K1 */
81 { 0x1102, 0x0004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, /* Audigy */ 81 { PCI_VDEVICE(CREATIVE, 0x0004), 1 }, /* Audigy */
82 { 0x1102, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, /* Audigy 2 Value SB0400 */ 82 { PCI_VDEVICE(CREATIVE, 0x0008), 1 }, /* Audigy 2 Value SB0400 */
83 { 0, } 83 { 0, }
84}; 84};
85 85
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 4d3ad793e98f..36e08bd2b3cc 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -1607,7 +1607,7 @@ static void __devexit snd_emu10k1x_remove(struct pci_dev *pci)
1607 1607
1608// PCI IDs 1608// PCI IDs
1609static struct pci_device_id snd_emu10k1x_ids[] = { 1609static struct pci_device_id snd_emu10k1x_ids[] = {
1610 { 0x1102, 0x0006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Dell OEM version (EMU10K1) */ 1610 { PCI_VDEVICE(CREATIVE, 0x0006), 0 }, /* Dell OEM version (EMU10K1) */
1611 { 0, } 1611 { 0, }
1612}; 1612};
1613MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids); 1613MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids);
diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
index e617acaf10e3..61b8ab39800f 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/ens1370.c b/sound/pci/ens1370.c
index 18f4d1e98c46..2b82c5c723e1 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -445,12 +445,12 @@ static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id);
445 445
446static struct pci_device_id snd_audiopci_ids[] = { 446static struct pci_device_id snd_audiopci_ids[] = {
447#ifdef CHIP1370 447#ifdef CHIP1370
448 { 0x1274, 0x5000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1370 */ 448 { PCI_VDEVICE(ENSONIQ, 0x5000), 0, }, /* ES1370 */
449#endif 449#endif
450#ifdef CHIP1371 450#ifdef CHIP1371
451 { 0x1274, 0x1371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1371 */ 451 { PCI_VDEVICE(ENSONIQ, 0x1371), 0, }, /* ES1371 */
452 { 0x1274, 0x5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1373 - CT5880 */ 452 { PCI_VDEVICE(ENSONIQ, 0x5880), 0, }, /* ES1373 - CT5880 */
453 { 0x1102, 0x8938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ectiva EV1938 */ 453 { PCI_VDEVICE(ECTIVA, 0x8938), 0, }, /* Ectiva EV1938 */
454#endif 454#endif
455 { 0, } 455 { 0, }
456}; 456};
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index fbd2ac09aa34..820318ee62c1 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -244,7 +244,7 @@ struct es1938 {
244static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id); 244static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id);
245 245
246static struct pci_device_id snd_es1938_ids[] = { 246static struct pci_device_id snd_es1938_ids[] = {
247 { 0x125d, 0x1969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Solo-1 */ 247 { PCI_VDEVICE(ESS, 0x1969), 0, }, /* Solo-1 */
248 { 0, } 248 { 0, }
249}; 249};
250 250
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 04438f1d682d..55545e0818b5 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 e3081d4586cc..315a1c4f8998 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 29272f2e95a0..3f51a981e604 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 462e2cedaa6a..af989f660cca 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 cad79efaabc9..99552fb5f756 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 fcad5ec31773..9446a5abea13 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 1d5797a96682..b36f6c5a92df 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 6812fbe80fa4..cc24e6721d74 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 4e9ea7080270..c9ad182e1b4b 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,31 @@ 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, 0x30f7, "HP Pavilion dv4t-1300", 1),
2307 SND_PCI_QUIRK(0x103c, 0x3607, "HP Compa CQ40", 1),
2308 {}
2309};
2310
2311static void __devinit check_msi(struct azx *chip)
2312{
2313 const struct snd_pci_quirk *q;
2314
2315 chip->msi = enable_msi;
2316 if (chip->msi)
2317 return;
2318 q = snd_pci_quirk_lookup(chip->pci, msi_white_list);
2319 if (q) {
2320 printk(KERN_INFO
2321 "hda_intel: msi for device %04x:%04x set to %d\n",
2322 q->subvendor, q->subdevice, q->value);
2323 chip->msi = q->value;
2324 }
2325}
2326
2231 2327
2232/* 2328/*
2233 * constructor 2329 * constructor
@@ -2262,7 +2358,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2262 chip->pci = pci; 2358 chip->pci = pci;
2263 chip->irq = -1; 2359 chip->irq = -1;
2264 chip->driver_type = driver_type; 2360 chip->driver_type = driver_type;
2265 chip->msi = enable_msi; 2361 check_msi(chip);
2266 chip->dev_index = dev; 2362 chip->dev_index = dev;
2267 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); 2363 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
2268 2364
@@ -2322,9 +2418,19 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2322 gcap = azx_readw(chip, GCAP); 2418 gcap = azx_readw(chip, GCAP);
2323 snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap); 2419 snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap);
2324 2420
2325 /* ATI chips seems buggy about 64bit DMA addresses */ 2421 /* disable SB600 64bit support for safety */
2326 if (chip->driver_type == AZX_DRIVER_ATI) 2422 if ((chip->driver_type == AZX_DRIVER_ATI) ||
2327 gcap &= ~ICH6_GCAP_64OK; 2423 (chip->driver_type == AZX_DRIVER_ATIHDMI)) {
2424 struct pci_dev *p_smbus;
2425 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
2426 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
2427 NULL);
2428 if (p_smbus) {
2429 if (p_smbus->revision < 0x30)
2430 gcap &= ~ICH6_GCAP_64OK;
2431 pci_dev_put(p_smbus);
2432 }
2433 }
2328 2434
2329 /* allow 64bit DMA address if supported by H/W */ 2435 /* allow 64bit DMA address if supported by H/W */
2330 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64))) 2436 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
@@ -2460,15 +2566,32 @@ static int __devinit azx_probe(struct pci_dev *pci,
2460 return err; 2566 return err;
2461 } 2567 }
2462 2568
2569 /* set this here since it's referred in snd_hda_load_patch() */
2570 snd_card_set_dev(card, &pci->dev);
2571
2463 err = azx_create(card, pci, dev, pci_id->driver_data, &chip); 2572 err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
2464 if (err < 0) 2573 if (err < 0)
2465 goto out_free; 2574 goto out_free;
2466 card->private_data = chip; 2575 card->private_data = chip;
2467 2576
2468 /* create codec instances */ 2577 /* create codec instances */
2469 err = azx_codec_create(chip, model[dev], probe_only[dev]); 2578 err = azx_codec_create(chip, model[dev]);
2470 if (err < 0) 2579 if (err < 0)
2471 goto out_free; 2580 goto out_free;
2581#ifdef CONFIG_SND_HDA_PATCH_LOADER
2582 if (patch[dev]) {
2583 snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n",
2584 patch[dev]);
2585 err = snd_hda_load_patch(chip->bus, patch[dev]);
2586 if (err < 0)
2587 goto out_free;
2588 }
2589#endif
2590 if (!probe_only[dev]) {
2591 err = azx_codec_configure(chip);
2592 if (err < 0)
2593 goto out_free;
2594 }
2472 2595
2473 /* create PCM streams */ 2596 /* create PCM streams */
2474 err = snd_hda_build_pcms(chip->bus); 2597 err = snd_hda_build_pcms(chip->bus);
@@ -2480,8 +2603,6 @@ static int __devinit azx_probe(struct pci_dev *pci,
2480 if (err < 0) 2603 if (err < 0)
2481 goto out_free; 2604 goto out_free;
2482 2605
2483 snd_card_set_dev(card, &pci->dev);
2484
2485 err = snd_card_register(card); 2606 err = snd_card_register(card);
2486 if (err < 0) 2607 if (err < 0)
2487 goto out_free; 2608 goto out_free;
@@ -2583,11 +2704,15 @@ static struct pci_device_id azx_ids[] = {
2583 /* this entry seems still valid -- i.e. without emu20kx chip */ 2704 /* this entry seems still valid -- i.e. without emu20kx chip */
2584 { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_GENERIC }, 2705 { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_GENERIC },
2585#endif 2706#endif
2586 /* AMD Generic, PCI class code and Vendor ID for HD Audio */ 2707 /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
2587 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID), 2708 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
2588 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2709 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2589 .class_mask = 0xffffff, 2710 .class_mask = 0xffffff,
2590 .driver_data = AZX_DRIVER_GENERIC }, 2711 .driver_data = AZX_DRIVER_GENERIC },
2712 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
2713 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2714 .class_mask = 0xffffff,
2715 .driver_data = AZX_DRIVER_GENERIC },
2591 { 0, } 2716 { 0, }
2592}; 2717};
2593MODULE_DEVICE_TABLE(pci, azx_ids); 2718MODULE_DEVICE_TABLE(pci, azx_ids);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 83349013b4df..5f1dcc59002b 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 418c5d1badaa..95f24e4729f8 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 84cc49ca9148..2d603f6aba63 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -72,6 +72,7 @@ struct ad198x_spec {
72 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 72 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
73 73
74 unsigned int jack_present :1; 74 unsigned int jack_present :1;
75 unsigned int inv_jack_detect:1;
75 76
76#ifdef CONFIG_SND_HDA_POWER_SAVE 77#ifdef CONFIG_SND_HDA_POWER_SAVE
77 struct hda_loopback_check loopback; 78 struct hda_loopback_check loopback;
@@ -669,39 +670,13 @@ static struct hda_input_mux ad1986a_automic_capture_source = {
669 }, 670 },
670}; 671};
671 672
672static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = { 673static struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
673 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol), 674 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
674 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw), 675 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
675 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
676 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
677 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
678 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
679 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
680 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
681 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
682 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
683 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
684 {
685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
686 .name = "Capture Source",
687 .info = ad198x_mux_enum_info,
688 .get = ad198x_mux_enum_get,
689 .put = ad198x_mux_enum_put,
690 },
691 {
692 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
693 .name = "External Amplifier",
694 .info = ad198x_eapd_info,
695 .get = ad198x_eapd_get,
696 .put = ad198x_eapd_put,
697 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
698 },
699 { } /* end */ 676 { } /* end */
700}; 677};
701 678
702static struct snd_kcontrol_new ad1986a_samsung_mixers[] = { 679static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
703 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
704 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
705 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT), 680 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
706 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), 681 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
707 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 682 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
@@ -727,6 +702,12 @@ static struct snd_kcontrol_new ad1986a_samsung_mixers[] = {
727 { } /* end */ 702 { } /* end */
728}; 703};
729 704
705static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
706 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
707 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
708 { } /* end */
709};
710
730/* re-connect the mic boost input according to the jack sensing */ 711/* re-connect the mic boost input according to the jack sensing */
731static void ad1986a_automic(struct hda_codec *codec) 712static void ad1986a_automic(struct hda_codec *codec)
732{ 713{
@@ -776,8 +757,9 @@ static void ad1986a_hp_automute(struct hda_codec *codec)
776 unsigned int present; 757 unsigned int present;
777 758
778 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0); 759 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
779 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */ 760 spec->jack_present = !!(present & 0x80000000);
780 spec->jack_present = !(present & 0x80000000); 761 if (spec->inv_jack_detect)
762 spec->jack_present = !spec->jack_present;
781 ad1986a_update_hp(codec); 763 ad1986a_update_hp(codec);
782} 764}
783 765
@@ -816,7 +798,7 @@ static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
816 return change; 798 return change;
817} 799}
818 800
819static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = { 801static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
820 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol), 802 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
821 { 803 {
822 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -826,33 +808,10 @@ static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
826 .put = ad1986a_hp_master_sw_put, 808 .put = ad1986a_hp_master_sw_put,
827 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT), 809 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
828 }, 810 },
829 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
830 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
831 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
832 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
833 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
834 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
835 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
836 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
837 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
838 {
839 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
840 .name = "Capture Source",
841 .info = ad198x_mux_enum_info,
842 .get = ad198x_mux_enum_get,
843 .put = ad198x_mux_enum_put,
844 },
845 {
846 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
847 .name = "External Amplifier",
848 .info = ad198x_eapd_info,
849 .get = ad198x_eapd_get,
850 .put = ad198x_eapd_put,
851 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
852 },
853 { } /* end */ 811 { } /* end */
854}; 812};
855 813
814
856/* 815/*
857 * initialization verbs 816 * initialization verbs
858 */ 817 */
@@ -981,6 +940,27 @@ static struct hda_verb ad1986a_hp_init_verbs[] = {
981 {} 940 {}
982}; 941};
983 942
943static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
944 unsigned int res)
945{
946 switch (res >> 26) {
947 case AD1986A_HP_EVENT:
948 ad1986a_hp_automute(codec);
949 break;
950 case AD1986A_MIC_EVENT:
951 ad1986a_automic(codec);
952 break;
953 }
954}
955
956static int ad1986a_samsung_p50_init(struct hda_codec *codec)
957{
958 ad198x_init(codec);
959 ad1986a_hp_automute(codec);
960 ad1986a_automic(codec);
961 return 0;
962}
963
984 964
985/* models */ 965/* models */
986enum { 966enum {
@@ -991,6 +971,7 @@ enum {
991 AD1986A_LAPTOP_AUTOMUTE, 971 AD1986A_LAPTOP_AUTOMUTE,
992 AD1986A_ULTRA, 972 AD1986A_ULTRA,
993 AD1986A_SAMSUNG, 973 AD1986A_SAMSUNG,
974 AD1986A_SAMSUNG_P50,
994 AD1986A_MODELS 975 AD1986A_MODELS
995}; 976};
996 977
@@ -1002,6 +983,7 @@ static const char *ad1986a_models[AD1986A_MODELS] = {
1002 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute", 983 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
1003 [AD1986A_ULTRA] = "ultra", 984 [AD1986A_ULTRA] = "ultra",
1004 [AD1986A_SAMSUNG] = "samsung", 985 [AD1986A_SAMSUNG] = "samsung",
986 [AD1986A_SAMSUNG_P50] = "samsung-p50",
1005}; 987};
1006 988
1007static struct snd_pci_quirk ad1986a_cfg_tbl[] = { 989static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
@@ -1024,6 +1006,7 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1024 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD), 1006 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
1025 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK), 1007 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
1026 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP), 1008 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
1009 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
1027 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA), 1010 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
1028 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG), 1011 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
1029 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK), 1012 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
@@ -1111,7 +1094,10 @@ static int patch_ad1986a(struct hda_codec *codec)
1111 spec->multiout.dac_nids = ad1986a_laptop_dac_nids; 1094 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1112 break; 1095 break;
1113 case AD1986A_LAPTOP_EAPD: 1096 case AD1986A_LAPTOP_EAPD:
1114 spec->mixers[0] = ad1986a_laptop_eapd_mixers; 1097 spec->num_mixers = 3;
1098 spec->mixers[0] = ad1986a_laptop_master_mixers;
1099 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1100 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1115 spec->num_init_verbs = 2; 1101 spec->num_init_verbs = 2;
1116 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1102 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1117 spec->multiout.max_channels = 2; 1103 spec->multiout.max_channels = 2;
@@ -1122,7 +1108,9 @@ static int patch_ad1986a(struct hda_codec *codec)
1122 spec->input_mux = &ad1986a_laptop_eapd_capture_source; 1108 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1123 break; 1109 break;
1124 case AD1986A_SAMSUNG: 1110 case AD1986A_SAMSUNG:
1125 spec->mixers[0] = ad1986a_samsung_mixers; 1111 spec->num_mixers = 2;
1112 spec->mixers[0] = ad1986a_laptop_master_mixers;
1113 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1126 spec->num_init_verbs = 3; 1114 spec->num_init_verbs = 3;
1127 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1115 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1128 spec->init_verbs[2] = ad1986a_automic_verbs; 1116 spec->init_verbs[2] = ad1986a_automic_verbs;
@@ -1135,8 +1123,28 @@ static int patch_ad1986a(struct hda_codec *codec)
1135 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event; 1123 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1136 codec->patch_ops.init = ad1986a_automic_init; 1124 codec->patch_ops.init = ad1986a_automic_init;
1137 break; 1125 break;
1126 case AD1986A_SAMSUNG_P50:
1127 spec->num_mixers = 2;
1128 spec->mixers[0] = ad1986a_automute_master_mixers;
1129 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1130 spec->num_init_verbs = 4;
1131 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1132 spec->init_verbs[2] = ad1986a_automic_verbs;
1133 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1134 spec->multiout.max_channels = 2;
1135 spec->multiout.num_dacs = 1;
1136 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1137 if (!is_jack_available(codec, 0x25))
1138 spec->multiout.dig_out_nid = 0;
1139 spec->input_mux = &ad1986a_automic_capture_source;
1140 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1141 codec->patch_ops.init = ad1986a_samsung_p50_init;
1142 break;
1138 case AD1986A_LAPTOP_AUTOMUTE: 1143 case AD1986A_LAPTOP_AUTOMUTE:
1139 spec->mixers[0] = ad1986a_laptop_automute_mixers; 1144 spec->num_mixers = 3;
1145 spec->mixers[0] = ad1986a_automute_master_mixers;
1146 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1147 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1140 spec->num_init_verbs = 3; 1148 spec->num_init_verbs = 3;
1141 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1149 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1142 spec->init_verbs[2] = ad1986a_hp_init_verbs; 1150 spec->init_verbs[2] = ad1986a_hp_init_verbs;
@@ -1148,6 +1156,10 @@ static int patch_ad1986a(struct hda_codec *codec)
1148 spec->input_mux = &ad1986a_laptop_eapd_capture_source; 1156 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1149 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event; 1157 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1150 codec->patch_ops.init = ad1986a_hp_init; 1158 codec->patch_ops.init = ad1986a_hp_init;
1159 /* Lenovo N100 seems to report the reversed bit
1160 * for HP jack-sensing
1161 */
1162 spec->inv_jack_detect = 1;
1151 break; 1163 break;
1152 case AD1986A_ULTRA: 1164 case AD1986A_ULTRA:
1153 spec->mixers[0] = ad1986a_laptop_eapd_mixers; 1165 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
@@ -2970,7 +2982,8 @@ static int patch_ad1988(struct hda_codec *codec)
2970 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST, 2982 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2971 ad1988_models, ad1988_cfg_tbl); 2983 ad1988_models, ad1988_cfg_tbl);
2972 if (board_config < 0) { 2984 if (board_config < 0) {
2973 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);
2974 board_config = AD1988_AUTO; 2987 board_config = AD1988_AUTO;
2975 } 2988 }
2976 2989
@@ -3690,19 +3703,29 @@ static struct hda_amp_list ad1884a_loopbacks[] = {
3690 * Port F: Internal speakers 3703 * Port F: Internal speakers
3691 */ 3704 */
3692 3705
3693static struct hda_input_mux ad1884a_laptop_capture_source = { 3706static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3694 .num_items = 4, 3707 struct snd_ctl_elem_value *ucontrol)
3695 .items = { 3708{
3696 { "Mic", 0x0 }, /* port-B */ 3709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3697 { "Internal Mic", 0x1 }, /* port-C */ 3710 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3698 { "Dock Mic", 0x4 }, /* port-E */ 3711 int mute = (!ucontrol->value.integer.value[0] &&
3699 { "Mix", 0x3 }, 3712 !ucontrol->value.integer.value[1]);
3700 }, 3713 /* toggle GPIO1 according to the mute state */
3701}; 3714 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3715 mute ? 0x02 : 0x0);
3716 return ret;
3717}
3702 3718
3703static struct snd_kcontrol_new ad1884a_laptop_mixers[] = { 3719static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3704 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT), 3720 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3705 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 },
3706 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT), 3729 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3707 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT), 3730 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3708 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 3731 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
@@ -3717,26 +3740,20 @@ static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3717 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT), 3740 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3718 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3741 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3719 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 3742 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3720 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3721 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3722 {
3723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3724 /* The multiple "Capture Source" controls confuse alsamixer
3725 * So call somewhat different..
3726 */
3727 /* .name = "Capture Source", */
3728 .name = "Input Source",
3729 .count = 2,
3730 .info = ad198x_mux_enum_info,
3731 .get = ad198x_mux_enum_get,
3732 .put = ad198x_mux_enum_put,
3733 },
3734 { } /* end */ 3743 { } /* end */
3735}; 3744};
3736 3745
3737static struct snd_kcontrol_new ad1884a_mobile_mixers[] = { 3746static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3738 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT), 3747 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3739 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 },
3740 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT), 3757 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3741 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 3758 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3742 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT), 3759 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
@@ -3795,6 +3812,63 @@ static int ad1884a_hp_init(struct hda_codec *codec)
3795 return 0; 3812 return 0;
3796} 3813}
3797 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
3798/* additional verbs for laptop model */ 3872/* additional verbs for laptop model */
3799static struct hda_verb ad1884a_laptop_verbs[] = { 3873static struct hda_verb ad1884a_laptop_verbs[] = {
3800 /* Port-A (HP) pin - always unmuted */ 3874 /* Port-A (HP) pin - always unmuted */
@@ -3802,18 +3876,28 @@ static struct hda_verb ad1884a_laptop_verbs[] = {
3802 /* Port-F (int speaker) mixer - route only from analog mixer */ 3876 /* Port-F (int speaker) mixer - route only from analog mixer */
3803 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 3877 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3804 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 3878 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3805 /* Port-F pin */ 3879 /* Port-F (int speaker) pin */
3806 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 3880 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3807 {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},
3808 /* Port-C pin - internal mic-in */ 3884 /* Port-C pin - internal mic-in */
3809 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 3885 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3810 {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 */
3811 {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},
3812 /* analog mix */ 3890 /* analog mix */
3813 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 3891 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3814 /* unsolicited event for pin-sense */ 3892 /* unsolicited event for pin-sense */
3815 {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},
3816 {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 */
3817 { } /* end */ 3901 { } /* end */
3818}; 3902};
3819 3903
@@ -3857,6 +3941,10 @@ static struct hda_verb ad1884a_mobile_verbs[] = {
3857 /* unsolicited event for pin-sense */ 3941 /* unsolicited event for pin-sense */
3858 {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},
3859 {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 */
3860 { } /* end */ 3948 { } /* end */
3861}; 3949};
3862 3950
@@ -3944,6 +4032,127 @@ static int ad1984a_thinkpad_init(struct hda_codec *codec)
3944} 4032}
3945 4033
3946/* 4034/*
4035 * HP Touchsmart
4036 * port-A (0x11) - front hp-out
4037 * port-B (0x14) - unused
4038 * port-C (0x15) - unused
4039 * port-D (0x12) - rear line out
4040 * port-E (0x1c) - front mic-in
4041 * port-F (0x16) - Internal speakers
4042 * digital-mic (0x17) - Internal mic
4043 */
4044
4045static struct hda_verb ad1984a_touchsmart_verbs[] = {
4046 /* DACs; unmute as default */
4047 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4048 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4049 /* Port-A (HP) mixer - route only from analog mixer */
4050 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4051 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4052 /* Port-A pin */
4053 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4054 /* Port-A (HP) pin - always unmuted */
4055 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4056 /* Port-E (int speaker) mixer - route only from analog mixer */
4057 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4058 /* Port-E pin */
4059 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4060 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4061 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4062 /* Port-F (int speaker) mixer - route only from analog mixer */
4063 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4064 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4065 /* Port-F pin */
4066 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4067 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4068 /* Analog mixer; mute as default */
4069 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4070 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4071 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4072 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4073 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4074 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4075 /* Analog Mix output amp */
4076 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4077 /* capture sources */
4078 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4079 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4080 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4081 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4082 /* unsolicited event for pin-sense */
4083 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4084 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4085 /* allow to touch GPIO1 (for mute control) */
4086 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4087 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4088 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4089 /* internal mic - dmic */
4090 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4091 /* set magic COEFs for dmic */
4092 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4093 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4094 { } /* end */
4095};
4096
4097static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4098 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4099/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4100 {
4101 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4102 .name = "Master Playback Switch",
4103 .info = snd_hda_mixer_amp_switch_info,
4104 .get = snd_hda_mixer_amp_switch_get,
4105 .put = ad1884a_mobile_master_sw_put,
4106 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4107 },
4108 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4109 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4110 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4111 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4112 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
4113 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4114 { } /* end */
4115};
4116
4117/* switch to external mic if plugged */
4118static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4119{
4120 if (snd_hda_codec_read(codec, 0x1c, 0,
4121 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000) {
4122 snd_hda_codec_write(codec, 0x0c, 0,
4123 AC_VERB_SET_CONNECT_SEL, 0x4);
4124 } else {
4125 snd_hda_codec_write(codec, 0x0c, 0,
4126 AC_VERB_SET_CONNECT_SEL, 0x5);
4127 }
4128}
4129
4130
4131/* unsolicited event for HP jack sensing */
4132static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4133 unsigned int res)
4134{
4135 switch (res >> 26) {
4136 case AD1884A_HP_EVENT:
4137 ad1884a_hp_automute(codec);
4138 break;
4139 case AD1884A_MIC_EVENT:
4140 ad1984a_touchsmart_automic(codec);
4141 break;
4142 }
4143}
4144
4145/* initialize jack-sensing, too */
4146static int ad1984a_touchsmart_init(struct hda_codec *codec)
4147{
4148 ad198x_init(codec);
4149 ad1884a_hp_automute(codec);
4150 ad1984a_touchsmart_automic(codec);
4151 return 0;
4152}
4153
4154
4155/*
3947 */ 4156 */
3948 4157
3949enum { 4158enum {
@@ -3951,6 +4160,7 @@ enum {
3951 AD1884A_LAPTOP, 4160 AD1884A_LAPTOP,
3952 AD1884A_MOBILE, 4161 AD1884A_MOBILE,
3953 AD1884A_THINKPAD, 4162 AD1884A_THINKPAD,
4163 AD1984A_TOUCHSMART,
3954 AD1884A_MODELS 4164 AD1884A_MODELS
3955}; 4165};
3956 4166
@@ -3959,6 +4169,7 @@ static const char *ad1884a_models[AD1884A_MODELS] = {
3959 [AD1884A_LAPTOP] = "laptop", 4169 [AD1884A_LAPTOP] = "laptop",
3960 [AD1884A_MOBILE] = "mobile", 4170 [AD1884A_MOBILE] = "mobile",
3961 [AD1884A_THINKPAD] = "thinkpad", 4171 [AD1884A_THINKPAD] = "thinkpad",
4172 [AD1984A_TOUCHSMART] = "touchsmart",
3962}; 4173};
3963 4174
3964static struct snd_pci_quirk ad1884a_cfg_tbl[] = { 4175static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
@@ -3966,9 +4177,12 @@ static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3966 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP), 4177 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
3967 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE), 4178 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3968 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE), 4179 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
4180 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
3969 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP), 4181 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
3970 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP), 4182 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
4183 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
3971 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD), 4184 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
4185 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
3972 {} 4186 {}
3973}; 4187};
3974 4188
@@ -4017,9 +4231,8 @@ static int patch_ad1884a(struct hda_codec *codec)
4017 spec->mixers[0] = ad1884a_laptop_mixers; 4231 spec->mixers[0] = ad1884a_laptop_mixers;
4018 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs; 4232 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4019 spec->multiout.dig_out_nid = 0; 4233 spec->multiout.dig_out_nid = 0;
4020 spec->input_mux = &ad1884a_laptop_capture_source; 4234 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4021 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event; 4235 codec->patch_ops.init = ad1884a_laptop_init;
4022 codec->patch_ops.init = ad1884a_hp_init;
4023 /* set the upper-limit for mixer amp to 0dB for avoiding the 4236 /* set the upper-limit for mixer amp to 0dB for avoiding the
4024 * possible damage by overloading 4237 * possible damage by overloading
4025 */ 4238 */
@@ -4053,6 +4266,21 @@ static int patch_ad1884a(struct hda_codec *codec)
4053 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event; 4266 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4054 codec->patch_ops.init = ad1984a_thinkpad_init; 4267 codec->patch_ops.init = ad1984a_thinkpad_init;
4055 break; 4268 break;
4269 case AD1984A_TOUCHSMART:
4270 spec->mixers[0] = ad1984a_touchsmart_mixers;
4271 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4272 spec->multiout.dig_out_nid = 0;
4273 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4274 codec->patch_ops.init = ad1984a_touchsmart_init;
4275 /* set the upper-limit for mixer amp to 0dB for avoiding the
4276 * possible damage by overloading
4277 */
4278 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4279 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4280 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4281 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4282 (1 << AC_AMPCAP_MUTE_SHIFT));
4283 break;
4056 } 4284 }
4057 4285
4058 return 0; 4286 return 0;
diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c
index 233e4778bba9..fb684f00156b 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 392d108c3558..d08353d3bb7f 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 000000000000..8ba306856d38
--- /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 c921264bbd71..780e1a72114a 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 ac868c59f9e3..3fbbc8c01e70 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,
@@ -680,11 +682,13 @@ static struct hda_input_mux cxt5045_capture_source = {
680}; 682};
681 683
682static struct hda_input_mux cxt5045_capture_source_benq = { 684static struct hda_input_mux cxt5045_capture_source_benq = {
683 .num_items = 3, 685 .num_items = 5,
684 .items = { 686 .items = {
685 { "IntMic", 0x1 }, 687 { "IntMic", 0x1 },
686 { "ExtMic", 0x2 }, 688 { "ExtMic", 0x2 },
687 { "LineIn", 0x3 }, 689 { "LineIn", 0x3 },
690 { "CD", 0x4 },
691 { "Mixer", 0x0 },
688 } 692 }
689}; 693};
690 694
@@ -809,11 +813,19 @@ static struct snd_kcontrol_new cxt5045_mixers[] = {
809}; 813};
810 814
811static struct snd_kcontrol_new cxt5045_benq_mixers[] = { 815static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
816 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
817 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
818 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
819 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
820
812 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 821 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
813 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 822 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
814 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 823 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
815 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 824 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
816 825
826 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
827 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
828
817 {} 829 {}
818}; 830};
819 831
@@ -1908,6 +1920,480 @@ static int patch_cxt5051(struct hda_codec *codec)
1908 return 0; 1920 return 0;
1909} 1921}
1910 1922
1923/* Conexant 5066 specific */
1924
1925static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1926static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1927static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1928#define CXT5066_SPDIF_OUT 0x21
1929
1930static struct hda_channel_mode cxt5066_modes[1] = {
1931 { 2, NULL },
1932};
1933
1934static void cxt5066_update_speaker(struct hda_codec *codec)
1935{
1936 struct conexant_spec *spec = codec->spec;
1937 unsigned int pinctl;
1938
1939 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
1940 spec->hp_present);
1941
1942 /* Port A (HP) */
1943 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
1944 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1945 pinctl);
1946
1947 /* Port D (HP/LO) */
1948 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
1949 ? spec->port_d_mode : 0;
1950 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1951 pinctl);
1952
1953 /* CLASS_D AMP */
1954 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1955 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1956 pinctl);
1957
1958 if (spec->dell_automute) {
1959 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
1960 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
1961 ? PIN_OUT : 0;
1962 snd_hda_codec_write(codec, 0x1c, 0,
1963 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
1964 }
1965}
1966
1967/* turn on/off EAPD (+ mute HP) as a master switch */
1968static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1969 struct snd_ctl_elem_value *ucontrol)
1970{
1971 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1972
1973 if (!cxt_eapd_put(kcontrol, ucontrol))
1974 return 0;
1975
1976 cxt5066_update_speaker(codec);
1977 return 1;
1978}
1979
1980/* toggle input of built-in and mic jack appropriately */
1981static void cxt5066_automic(struct hda_codec *codec)
1982{
1983 static struct hda_verb ext_mic_present[] = {
1984 /* enable external mic, port B */
1985 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1986
1987 /* switch to external mic input */
1988 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
1989
1990 /* disable internal mic, port C */
1991 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1992 {}
1993 };
1994 static struct hda_verb ext_mic_absent[] = {
1995 /* enable internal mic, port C */
1996 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1997
1998 /* switch to internal mic input */
1999 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2000
2001 /* disable external mic, port B */
2002 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2003 {}
2004 };
2005 unsigned int present;
2006
2007 present = snd_hda_codec_read(codec, 0x1a, 0,
2008 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2009 if (present) {
2010 snd_printdd("CXT5066: external microphone detected\n");
2011 snd_hda_sequence_write(codec, ext_mic_present);
2012 } else {
2013 snd_printdd("CXT5066: external microphone absent\n");
2014 snd_hda_sequence_write(codec, ext_mic_absent);
2015 }
2016}
2017
2018/* mute internal speaker if HP is plugged */
2019static void cxt5066_hp_automute(struct hda_codec *codec)
2020{
2021 struct conexant_spec *spec = codec->spec;
2022 unsigned int portA, portD;
2023
2024 /* Port A */
2025 portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0)
2026 & AC_PINSENSE_PRESENCE;
2027
2028 /* Port D */
2029 portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0)
2030 & AC_PINSENSE_PRESENCE) << 1;
2031
2032 spec->hp_present = !!(portA | portD);
2033 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2034 portA, portD, spec->hp_present);
2035 cxt5066_update_speaker(codec);
2036}
2037
2038/* unsolicited event for jack sensing */
2039static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2040{
2041 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2042 switch (res >> 26) {
2043 case CONEXANT_HP_EVENT:
2044 cxt5066_hp_automute(codec);
2045 break;
2046 case CONEXANT_MIC_EVENT:
2047 cxt5066_automic(codec);
2048 break;
2049 }
2050}
2051
2052static const struct hda_input_mux cxt5066_analog_mic_boost = {
2053 .num_items = 5,
2054 .items = {
2055 { "0dB", 0 },
2056 { "10dB", 1 },
2057 { "20dB", 2 },
2058 { "30dB", 3 },
2059 { "40dB", 4 },
2060 },
2061};
2062
2063static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2064 struct snd_ctl_elem_info *uinfo)
2065{
2066 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2067}
2068
2069static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2070 struct snd_ctl_elem_value *ucontrol)
2071{
2072 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2073 int val;
2074
2075 val = snd_hda_codec_read(codec, 0x17, 0,
2076 AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT);
2077
2078 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2079 return 0;
2080}
2081
2082static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2083 struct snd_ctl_elem_value *ucontrol)
2084{
2085 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2086 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2087 unsigned int idx;
2088
2089 if (!imux->num_items)
2090 return 0;
2091 idx = ucontrol->value.enumerated.item[0];
2092 if (idx >= imux->num_items)
2093 idx = imux->num_items - 1;
2094
2095 snd_hda_codec_write_cache(codec, 0x17, 0,
2096 AC_VERB_SET_AMP_GAIN_MUTE,
2097 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2098 imux->items[idx].index);
2099
2100 return 1;
2101}
2102
2103static struct hda_input_mux cxt5066_capture_source = {
2104 .num_items = 4,
2105 .items = {
2106 { "Mic B", 0 },
2107 { "Mic C", 1 },
2108 { "Mic E", 2 },
2109 { "Mic F", 3 },
2110 },
2111};
2112
2113static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2114 .ops = &snd_hda_bind_vol,
2115 .values = {
2116 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2117 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2118 0
2119 },
2120};
2121
2122static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2123 .ops = &snd_hda_bind_sw,
2124 .values = {
2125 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2126 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2127 0
2128 },
2129};
2130
2131static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2132 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2133 {}
2134};
2135
2136static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2137 {
2138 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2139 .name = "Master Playback Volume",
2140 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2141 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2142 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2143 .info = snd_hda_mixer_amp_volume_info,
2144 .get = snd_hda_mixer_amp_volume_get,
2145 .put = snd_hda_mixer_amp_volume_put,
2146 .tlv = { .c = snd_hda_mixer_amp_tlv },
2147 /* offset by 28 volume steps to limit minimum gain to -46dB */
2148 .private_value =
2149 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2150 },
2151 {}
2152};
2153
2154static struct snd_kcontrol_new cxt5066_mixers[] = {
2155 {
2156 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2157 .name = "Master Playback Switch",
2158 .info = cxt_eapd_info,
2159 .get = cxt_eapd_get,
2160 .put = cxt5066_hp_master_sw_put,
2161 .private_value = 0x1d,
2162 },
2163
2164 {
2165 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2166 .name = "Analog Mic Boost Capture Enum",
2167 .info = cxt5066_mic_boost_mux_enum_info,
2168 .get = cxt5066_mic_boost_mux_enum_get,
2169 .put = cxt5066_mic_boost_mux_enum_put,
2170 },
2171
2172 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2173 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2174 {}
2175};
2176
2177static struct hda_verb cxt5066_init_verbs[] = {
2178 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2179 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2180 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2181 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2182
2183 /* Speakers */
2184 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2185 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2186
2187 /* HP, Amp */
2188 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2189 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2190
2191 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2192 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2193
2194 /* DAC1 */
2195 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2196
2197 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2198 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2199 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2200 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2201 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2202 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2203
2204 /* no digital microphone support yet */
2205 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2206
2207 /* Audio input selector */
2208 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2209
2210 /* SPDIF route: PCM */
2211 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2212 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2213
2214 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2215 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2216
2217 /* EAPD */
2218 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2219
2220 /* not handling these yet */
2221 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2222 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2223 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2224 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2225 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2226 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2227 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2228 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2229 { } /* end */
2230};
2231
2232static struct hda_verb cxt5066_init_verbs_olpc[] = {
2233 /* Port A: headphones */
2234 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2235 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2236
2237 /* Port B: external microphone */
2238 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2239
2240 /* Port C: internal microphone */
2241 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2242
2243 /* Port D: unused */
2244 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2245
2246 /* Port E: unused, but has primary EAPD */
2247 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2248 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2249
2250 /* Port F: unused */
2251 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2252
2253 /* Port G: internal speakers */
2254 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2255 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2256
2257 /* DAC1 */
2258 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2259
2260 /* DAC2: unused */
2261 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2262
2263 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2264 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2265 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2266 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2267 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2268 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2269 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2270 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2271 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2272 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2273 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2274 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2275
2276 /* Disable digital microphone port */
2277 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2278
2279 /* Audio input selectors */
2280 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2281 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2282
2283 /* Disable SPDIF */
2284 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2285 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2286
2287 /* enable unsolicited events for Port A and B */
2288 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2289 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2290 { } /* end */
2291};
2292
2293static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2294 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2295 { } /* end */
2296};
2297
2298/* initialize jack-sensing, too */
2299static int cxt5066_init(struct hda_codec *codec)
2300{
2301 snd_printdd("CXT5066: init\n");
2302 conexant_init(codec);
2303 if (codec->patch_ops.unsol_event) {
2304 cxt5066_hp_automute(codec);
2305 cxt5066_automic(codec);
2306 }
2307 return 0;
2308}
2309
2310enum {
2311 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2312 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2313 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2314 CXT5066_MODELS
2315};
2316
2317static const char *cxt5066_models[CXT5066_MODELS] = {
2318 [CXT5066_LAPTOP] = "laptop",
2319 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2320 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2321};
2322
2323static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2324 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2325 CXT5066_LAPTOP),
2326 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2327 CXT5066_DELL_LAPTOP),
2328 {}
2329};
2330
2331static int patch_cxt5066(struct hda_codec *codec)
2332{
2333 struct conexant_spec *spec;
2334 int board_config;
2335
2336 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2337 if (!spec)
2338 return -ENOMEM;
2339 codec->spec = spec;
2340
2341 codec->patch_ops = conexant_patch_ops;
2342 codec->patch_ops.init = cxt5066_init;
2343
2344 spec->dell_automute = 0;
2345 spec->multiout.max_channels = 2;
2346 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2347 spec->multiout.dac_nids = cxt5066_dac_nids;
2348 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2349 spec->num_adc_nids = 1;
2350 spec->adc_nids = cxt5066_adc_nids;
2351 spec->capsrc_nids = cxt5066_capsrc_nids;
2352 spec->input_mux = &cxt5066_capture_source;
2353
2354 spec->port_d_mode = PIN_HP;
2355
2356 spec->num_init_verbs = 1;
2357 spec->init_verbs[0] = cxt5066_init_verbs;
2358 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2359 spec->channel_mode = cxt5066_modes;
2360 spec->cur_adc = 0;
2361 spec->cur_adc_idx = 0;
2362
2363 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2364 cxt5066_models, cxt5066_cfg_tbl);
2365 switch (board_config) {
2366 default:
2367 case CXT5066_LAPTOP:
2368 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2369 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2370 break;
2371 case CXT5066_DELL_LAPTOP:
2372 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2373 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2374
2375 spec->port_d_mode = PIN_OUT;
2376 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2377 spec->num_init_verbs++;
2378 spec->dell_automute = 1;
2379 break;
2380 case CXT5066_OLPC_XO_1_5:
2381 codec->patch_ops.unsol_event = cxt5066_unsol_event;
2382 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2383 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2384 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2385 spec->port_d_mode = 0;
2386
2387 /* no S/PDIF out */
2388 spec->multiout.dig_out_nid = 0;
2389
2390 /* input source automatically selected */
2391 spec->input_mux = NULL;
2392 break;
2393 }
2394
2395 return 0;
2396}
1911 2397
1912/* 2398/*
1913 */ 2399 */
@@ -1919,12 +2405,15 @@ static struct hda_codec_preset snd_hda_preset_conexant[] = {
1919 .patch = patch_cxt5047 }, 2405 .patch = patch_cxt5047 },
1920 { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 2406 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1921 .patch = patch_cxt5051 }, 2407 .patch = patch_cxt5051 },
2408 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2409 .patch = patch_cxt5066 },
1922 {} /* terminator */ 2410 {} /* terminator */
1923}; 2411};
1924 2412
1925MODULE_ALIAS("snd-hda-codec-id:14f15045"); 2413MODULE_ALIAS("snd-hda-codec-id:14f15045");
1926MODULE_ALIAS("snd-hda-codec-id:14f15047"); 2414MODULE_ALIAS("snd-hda-codec-id:14f15047");
1927MODULE_ALIAS("snd-hda-codec-id:14f15051"); 2415MODULE_ALIAS("snd-hda-codec-id:14f15051");
2416MODULE_ALIAS("snd-hda-codec-id:14f15066");
1928 2417
1929MODULE_LICENSE("GPL"); 2418MODULE_LICENSE("GPL");
1930MODULE_DESCRIPTION("Conexant HD-audio codec"); 2419MODULE_DESCRIPTION("Conexant HD-audio codec");
diff --git a/sound/pci/hda/patch_intelhdmi.c b/sound/pci/hda/patch_intelhdmi.c
index fcc77fec4487..01a18ed475ac 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 f5792e2eea82..c8435c9a97f9 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 334533197425..7810d3dcad83 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 */
@@ -945,12 +961,13 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
945static void alc_automute_pin(struct hda_codec *codec) 961static void alc_automute_pin(struct hda_codec *codec)
946{ 962{
947 struct alc_spec *spec = codec->spec; 963 struct alc_spec *spec = codec->spec;
948 unsigned int present; 964 unsigned int present, pincap;
949 unsigned int nid = spec->autocfg.hp_pins[0]; 965 unsigned int nid = spec->autocfg.hp_pins[0];
950 int i; 966 int i;
951 967
952 /* need to execute and sync at first */ 968 pincap = snd_hda_query_pin_caps(codec, nid);
953 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0); 969 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
970 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
954 present = snd_hda_codec_read(codec, nid, 0, 971 present = snd_hda_codec_read(codec, nid, 0,
955 AC_VERB_GET_PIN_SENSE, 0); 972 AC_VERB_GET_PIN_SENSE, 0);
956 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0; 973 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
@@ -964,30 +981,64 @@ static void alc_automute_pin(struct hda_codec *codec)
964 } 981 }
965} 982}
966 983
967#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
968static void alc_mic_automute(struct hda_codec *codec) 997static void alc_mic_automute(struct hda_codec *codec)
969{ 998{
970 struct alc_spec *spec = codec->spec; 999 struct alc_spec *spec = codec->spec;
971 unsigned int present; 1000 struct alc_mic_route *dead, *alive;
972 unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC]; 1001 unsigned int present, type;
973 unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC]; 1002 hda_nid_t cap_nid;
974 unsigned int mix_nid = spec->capsrc_nids[0]; 1003
975 unsigned int capsrc_idx_mic, capsrc_idx_fmic; 1004 if (!spec->auto_mic)
976 1005 return;
977 capsrc_idx_mic = mic_nid - 0x18; 1006 if (!spec->int_mic.pin || !spec->ext_mic.pin)
978 capsrc_idx_fmic = fmic_nid - 0x18; 1007 return;
979 present = snd_hda_codec_read(codec, mic_nid, 0, 1008 if (snd_BUG_ON(!spec->adc_nids))
980 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1009 return;
981 snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 1010
982 0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80)); 1011 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
983 snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 1012
984 0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0)); 1013 present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0,
985 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic, 1014 AC_VERB_GET_PIN_SENSE, 0);
986 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 */
987} 1041}
988#else
989#define alc_mic_automute(codec) do {} while(0) /* NOP */
990#endif /* disabled */
991 1042
992/* unsolicited event for HP jack sensing */ 1043/* unsolicited event for HP jack sensing */
993static 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)
@@ -1030,6 +1081,16 @@ static void alc888_coef_init(struct hda_codec *codec)
1030 AC_VERB_SET_PROC_COEF, 0x3030); 1081 AC_VERB_SET_PROC_COEF, 0x3030);
1031} 1082}
1032 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
1033static void alc_auto_init_amp(struct hda_codec *codec, int type) 1094static void alc_auto_init_amp(struct hda_codec *codec, int type)
1034{ 1095{
1035 unsigned int tmp; 1096 unsigned int tmp;
@@ -1087,15 +1148,7 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
1087 case 0x10ec0885: 1148 case 0x10ec0885:
1088 case 0x10ec0887: 1149 case 0x10ec0887:
1089 case 0x10ec0889: 1150 case 0x10ec0889:
1090 snd_hda_codec_write(codec, 0x20, 0, 1151 alc889_coef_init(codec);
1091 AC_VERB_SET_COEF_INDEX, 7);
1092 tmp = snd_hda_codec_read(codec, 0x20, 0,
1093 AC_VERB_GET_PROC_COEF, 0);
1094 snd_hda_codec_write(codec, 0x20, 0,
1095 AC_VERB_SET_COEF_INDEX, 7);
1096 snd_hda_codec_write(codec, 0x20, 0,
1097 AC_VERB_SET_PROC_COEF,
1098 tmp | 0x2010);
1099 break; 1152 break;
1100 case 0x10ec0888: 1153 case 0x10ec0888:
1101 alc888_coef_init(codec); 1154 alc888_coef_init(codec);
@@ -1141,6 +1194,55 @@ static void alc_init_auto_hp(struct hda_codec *codec)
1141 spec->unsol_event = alc_sku_unsol_event; 1194 spec->unsol_event = alc_sku_unsol_event;
1142} 1195}
1143 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
1144/* check subsystem ID and set up device-specific initialization; 1246/* check subsystem ID and set up device-specific initialization;
1145 * return 1 if initialized, 0 if invalid SSID 1247 * return 1 if initialized, 0 if invalid SSID
1146 */ 1248 */
@@ -1242,6 +1344,7 @@ do_sku:
1242 } 1344 }
1243 1345
1244 alc_init_auto_hp(codec); 1346 alc_init_auto_hp(codec);
1347 alc_init_auto_mic(codec);
1245 return 1; 1348 return 1;
1246} 1349}
1247 1350
@@ -1254,6 +1357,7 @@ static void alc_ssid_check(struct hda_codec *codec,
1254 "Enable default setup for auto mode as fallback\n"); 1357 "Enable default setup for auto mode as fallback\n");
1255 spec->init_amp = ALC_INIT_DEFAULT; 1358 spec->init_amp = ALC_INIT_DEFAULT;
1256 alc_init_auto_hp(codec); 1359 alc_init_auto_hp(codec);
1360 alc_init_auto_mic(codec);
1257 } 1361 }
1258} 1362}
1259 1363
@@ -1392,7 +1496,7 @@ static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1392static void alc_automute_amp(struct hda_codec *codec) 1496static void alc_automute_amp(struct hda_codec *codec)
1393{ 1497{
1394 struct alc_spec *spec = codec->spec; 1498 struct alc_spec *spec = codec->spec;
1395 unsigned int val, mute; 1499 unsigned int val, mute, pincap;
1396 hda_nid_t nid; 1500 hda_nid_t nid;
1397 int i; 1501 int i;
1398 1502
@@ -1401,6 +1505,10 @@ static void alc_automute_amp(struct hda_codec *codec)
1401 nid = spec->autocfg.hp_pins[i]; 1505 nid = spec->autocfg.hp_pins[i];
1402 if (!nid) 1506 if (!nid)
1403 break; 1507 break;
1508 pincap = snd_hda_query_pin_caps(codec, nid);
1509 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1510 snd_hda_codec_read(codec, nid, 0,
1511 AC_VERB_SET_PIN_SENSE, 0);
1404 val = snd_hda_codec_read(codec, nid, 0, 1512 val = snd_hda_codec_read(codec, nid, 0,
1405 AC_VERB_GET_PIN_SENSE, 0); 1513 AC_VERB_GET_PIN_SENSE, 0);
1406 if (val & AC_PINSENSE_PRESENCE) { 1514 if (val & AC_PINSENSE_PRESENCE) {
@@ -1431,7 +1539,25 @@ static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1431 alc_automute_amp(codec); 1539 alc_automute_amp(codec);
1432} 1540}
1433 1541
1434static 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)
1435{ 1561{
1436 struct alc_spec *spec = codec->spec; 1562 struct alc_spec *spec = codec->spec;
1437 1563
@@ -1439,7 +1565,6 @@ static void alc888_fujitsu_xa3530_init_hook(struct hda_codec *codec)
1439 spec->autocfg.hp_pins[1] = 0x1b; /* hp */ 1565 spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1440 spec->autocfg.speaker_pins[0] = 0x14; /* speaker */ 1566 spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1441 spec->autocfg.speaker_pins[1] = 0x15; /* bass */ 1567 spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1442 alc_automute_amp(codec);
1443} 1568}
1444 1569
1445/* 1570/*
@@ -1471,6 +1596,10 @@ static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1471static struct hda_verb alc888_acer_aspire_6530g_verbs[] = { 1596static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1472/* Bias voltage on for external mic port */ 1597/* Bias voltage on for external mic port */
1473 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80}, 1598 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1599/* Front Mic: set to PIN_IN (empty by default) */
1600 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1601/* Unselect Front Mic by default in input mixer 3 */
1602 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1474/* Enable unsolicited event for HP jack */ 1603/* Enable unsolicited event for HP jack */
1475 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 1604 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1476/* Enable speaker output */ 1605/* Enable speaker output */
@@ -1560,18 +1689,22 @@ static struct hda_input_mux alc888_2_capture_sources[2] = {
1560static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = { 1689static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1561 /* Interal mic only available on one ADC */ 1690 /* Interal mic only available on one ADC */
1562 { 1691 {
1563 .num_items = 3, 1692 .num_items = 5,
1564 .items = { 1693 .items = {
1565 { "Ext Mic", 0x0 }, 1694 { "Ext Mic", 0x0 },
1695 { "Line In", 0x2 },
1566 { "CD", 0x4 }, 1696 { "CD", 0x4 },
1697 { "Input Mix", 0xa },
1567 { "Int Mic", 0xb }, 1698 { "Int Mic", 0xb },
1568 }, 1699 },
1569 }, 1700 },
1570 { 1701 {
1571 .num_items = 2, 1702 .num_items = 4,
1572 .items = { 1703 .items = {
1573 { "Ext Mic", 0x0 }, 1704 { "Ext Mic", 0x0 },
1705 { "Line In", 0x2 },
1574 { "CD", 0x4 }, 1706 { "CD", 0x4 },
1707 { "Input Mix", 0xa },
1575 }, 1708 },
1576 } 1709 }
1577}; 1710};
@@ -1630,16 +1763,25 @@ static struct snd_kcontrol_new alc888_base_mixer[] = {
1630 { } /* end */ 1763 { } /* end */
1631}; 1764};
1632 1765
1633static void alc888_acer_aspire_4930g_init_hook(struct hda_codec *codec) 1766static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1634{ 1767{
1635 struct alc_spec *spec = codec->spec; 1768 struct alc_spec *spec = codec->spec;
1636 1769
1637 spec->autocfg.hp_pins[0] = 0x15; 1770 spec->autocfg.hp_pins[0] = 0x15;
1638 spec->autocfg.speaker_pins[0] = 0x14; 1771 spec->autocfg.speaker_pins[0] = 0x14;
1639 alc_automute_amp(codec);
1640} 1772}
1641 1773
1642static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec) 1774static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1775{
1776 struct alc_spec *spec = codec->spec;
1777
1778 spec->autocfg.hp_pins[0] = 0x15;
1779 spec->autocfg.speaker_pins[0] = 0x14;
1780 spec->autocfg.speaker_pins[1] = 0x16;
1781 spec->autocfg.speaker_pins[2] = 0x17;
1782}
1783
1784static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1643{ 1785{
1644 struct alc_spec *spec = codec->spec; 1786 struct alc_spec *spec = codec->spec;
1645 1787
@@ -1647,7 +1789,6 @@ static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec)
1647 spec->autocfg.speaker_pins[0] = 0x14; 1789 spec->autocfg.speaker_pins[0] = 0x14;
1648 spec->autocfg.speaker_pins[1] = 0x16; 1790 spec->autocfg.speaker_pins[1] = 0x16;
1649 spec->autocfg.speaker_pins[2] = 0x1b; 1791 spec->autocfg.speaker_pins[2] = 0x1b;
1650 alc_automute_amp(codec);
1651} 1792}
1652 1793
1653/* 1794/*
@@ -2627,13 +2768,17 @@ static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2627 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);
2628} 2769}
2629 2770
2630static void alc880_uniwill_init_hook(struct hda_codec *codec) 2771static void alc880_uniwill_setup(struct hda_codec *codec)
2631{ 2772{
2632 struct alc_spec *spec = codec->spec; 2773 struct alc_spec *spec = codec->spec;
2633 2774
2634 spec->autocfg.hp_pins[0] = 0x14; 2775 spec->autocfg.hp_pins[0] = 0x14;
2635 spec->autocfg.speaker_pins[0] = 0x15; 2776 spec->autocfg.speaker_pins[0] = 0x15;
2636 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{
2637 alc_automute_amp(codec); 2782 alc_automute_amp(codec);
2638 alc880_uniwill_mic_automute(codec); 2783 alc880_uniwill_mic_automute(codec);
2639} 2784}
@@ -2654,13 +2799,12 @@ static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2654 } 2799 }
2655} 2800}
2656 2801
2657static void alc880_uniwill_p53_init_hook(struct hda_codec *codec) 2802static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2658{ 2803{
2659 struct alc_spec *spec = codec->spec; 2804 struct alc_spec *spec = codec->spec;
2660 2805
2661 spec->autocfg.hp_pins[0] = 0x14; 2806 spec->autocfg.hp_pins[0] = 0x14;
2662 spec->autocfg.speaker_pins[0] = 0x15; 2807 spec->autocfg.speaker_pins[0] = 0x15;
2663 alc_automute_amp(codec);
2664} 2808}
2665 2809
2666static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec) 2810static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
@@ -2923,13 +3067,12 @@ static struct hda_verb alc880_lg_init_verbs[] = {
2923}; 3067};
2924 3068
2925/* toggle speaker-output according to the hp-jack state */ 3069/* toggle speaker-output according to the hp-jack state */
2926static void alc880_lg_init_hook(struct hda_codec *codec) 3070static void alc880_lg_setup(struct hda_codec *codec)
2927{ 3071{
2928 struct alc_spec *spec = codec->spec; 3072 struct alc_spec *spec = codec->spec;
2929 3073
2930 spec->autocfg.hp_pins[0] = 0x1b; 3074 spec->autocfg.hp_pins[0] = 0x1b;
2931 spec->autocfg.speaker_pins[0] = 0x17; 3075 spec->autocfg.speaker_pins[0] = 0x17;
2932 alc_automute_amp(codec);
2933} 3076}
2934 3077
2935/* 3078/*
@@ -3008,13 +3151,12 @@ static struct hda_verb alc880_lg_lw_init_verbs[] = {
3008}; 3151};
3009 3152
3010/* toggle speaker-output according to the hp-jack state */ 3153/* toggle speaker-output according to the hp-jack state */
3011static void alc880_lg_lw_init_hook(struct hda_codec *codec) 3154static void alc880_lg_lw_setup(struct hda_codec *codec)
3012{ 3155{
3013 struct alc_spec *spec = codec->spec; 3156 struct alc_spec *spec = codec->spec;
3014 3157
3015 spec->autocfg.hp_pins[0] = 0x1b; 3158 spec->autocfg.hp_pins[0] = 0x1b;
3016 spec->autocfg.speaker_pins[0] = 0x14; 3159 spec->autocfg.speaker_pins[0] = 0x14;
3017 alc_automute_amp(codec);
3018} 3160}
3019 3161
3020static struct snd_kcontrol_new alc880_medion_rim_mixer[] = { 3162static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
@@ -3080,13 +3222,12 @@ static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3080 alc880_medion_rim_automute(codec); 3222 alc880_medion_rim_automute(codec);
3081} 3223}
3082 3224
3083static void alc880_medion_rim_init_hook(struct hda_codec *codec) 3225static void alc880_medion_rim_setup(struct hda_codec *codec)
3084{ 3226{
3085 struct alc_spec *spec = codec->spec; 3227 struct alc_spec *spec = codec->spec;
3086 3228
3087 spec->autocfg.hp_pins[0] = 0x14; 3229 spec->autocfg.hp_pins[0] = 0x14;
3088 spec->autocfg.speaker_pins[0] = 0x1b; 3230 spec->autocfg.speaker_pins[0] = 0x1b;
3089 alc880_medion_rim_automute(codec);
3090} 3231}
3091 3232
3092#ifdef CONFIG_SND_HDA_POWER_SAVE 3233#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -3953,7 +4094,8 @@ static struct alc_config_preset alc880_presets[] = {
3953 .channel_mode = alc880_2_jack_modes, 4094 .channel_mode = alc880_2_jack_modes,
3954 .input_mux = &alc880_f1734_capture_source, 4095 .input_mux = &alc880_f1734_capture_source,
3955 .unsol_event = alc880_uniwill_p53_unsol_event, 4096 .unsol_event = alc880_uniwill_p53_unsol_event,
3956 .init_hook = alc880_uniwill_p53_init_hook, 4097 .setup = alc880_uniwill_p53_setup,
4098 .init_hook = alc_automute_amp,
3957 }, 4099 },
3958 [ALC880_ASUS] = { 4100 [ALC880_ASUS] = {
3959 .mixers = { alc880_asus_mixer }, 4101 .mixers = { alc880_asus_mixer },
@@ -4030,6 +4172,7 @@ static struct alc_config_preset alc880_presets[] = {
4030 .need_dac_fix = 1, 4172 .need_dac_fix = 1,
4031 .input_mux = &alc880_capture_source, 4173 .input_mux = &alc880_capture_source,
4032 .unsol_event = alc880_uniwill_unsol_event, 4174 .unsol_event = alc880_uniwill_unsol_event,
4175 .setup = alc880_uniwill_setup,
4033 .init_hook = alc880_uniwill_init_hook, 4176 .init_hook = alc880_uniwill_init_hook,
4034 }, 4177 },
4035 [ALC880_UNIWILL_P53] = { 4178 [ALC880_UNIWILL_P53] = {
@@ -4042,7 +4185,8 @@ static struct alc_config_preset alc880_presets[] = {
4042 .channel_mode = alc880_threestack_modes, 4185 .channel_mode = alc880_threestack_modes,
4043 .input_mux = &alc880_capture_source, 4186 .input_mux = &alc880_capture_source,
4044 .unsol_event = alc880_uniwill_p53_unsol_event, 4187 .unsol_event = alc880_uniwill_p53_unsol_event,
4045 .init_hook = alc880_uniwill_p53_init_hook, 4188 .setup = alc880_uniwill_p53_setup,
4189 .init_hook = alc_automute_amp,
4046 }, 4190 },
4047 [ALC880_FUJITSU] = { 4191 [ALC880_FUJITSU] = {
4048 .mixers = { alc880_fujitsu_mixer }, 4192 .mixers = { alc880_fujitsu_mixer },
@@ -4056,7 +4200,8 @@ static struct alc_config_preset alc880_presets[] = {
4056 .channel_mode = alc880_2_jack_modes, 4200 .channel_mode = alc880_2_jack_modes,
4057 .input_mux = &alc880_capture_source, 4201 .input_mux = &alc880_capture_source,
4058 .unsol_event = alc880_uniwill_p53_unsol_event, 4202 .unsol_event = alc880_uniwill_p53_unsol_event,
4059 .init_hook = alc880_uniwill_p53_init_hook, 4203 .setup = alc880_uniwill_p53_setup,
4204 .init_hook = alc_automute_amp,
4060 }, 4205 },
4061 [ALC880_CLEVO] = { 4206 [ALC880_CLEVO] = {
4062 .mixers = { alc880_three_stack_mixer }, 4207 .mixers = { alc880_three_stack_mixer },
@@ -4082,7 +4227,8 @@ static struct alc_config_preset alc880_presets[] = {
4082 .need_dac_fix = 1, 4227 .need_dac_fix = 1,
4083 .input_mux = &alc880_lg_capture_source, 4228 .input_mux = &alc880_lg_capture_source,
4084 .unsol_event = alc_automute_amp_unsol_event, 4229 .unsol_event = alc_automute_amp_unsol_event,
4085 .init_hook = alc880_lg_init_hook, 4230 .setup = alc880_lg_setup,
4231 .init_hook = alc_automute_amp,
4086#ifdef CONFIG_SND_HDA_POWER_SAVE 4232#ifdef CONFIG_SND_HDA_POWER_SAVE
4087 .loopbacks = alc880_lg_loopbacks, 4233 .loopbacks = alc880_lg_loopbacks,
4088#endif 4234#endif
@@ -4098,7 +4244,8 @@ static struct alc_config_preset alc880_presets[] = {
4098 .channel_mode = alc880_lg_lw_modes, 4244 .channel_mode = alc880_lg_lw_modes,
4099 .input_mux = &alc880_lg_lw_capture_source, 4245 .input_mux = &alc880_lg_lw_capture_source,
4100 .unsol_event = alc_automute_amp_unsol_event, 4246 .unsol_event = alc_automute_amp_unsol_event,
4101 .init_hook = alc880_lg_lw_init_hook, 4247 .setup = alc880_lg_lw_setup,
4248 .init_hook = alc_automute_amp,
4102 }, 4249 },
4103 [ALC880_MEDION_RIM] = { 4250 [ALC880_MEDION_RIM] = {
4104 .mixers = { alc880_medion_rim_mixer }, 4251 .mixers = { alc880_medion_rim_mixer },
@@ -4112,7 +4259,8 @@ static struct alc_config_preset alc880_presets[] = {
4112 .channel_mode = alc880_2_jack_modes, 4259 .channel_mode = alc880_2_jack_modes,
4113 .input_mux = &alc880_medion_rim_capture_source, 4260 .input_mux = &alc880_medion_rim_capture_source,
4114 .unsol_event = alc880_medion_rim_unsol_event, 4261 .unsol_event = alc880_medion_rim_unsol_event,
4115 .init_hook = alc880_medion_rim_init_hook, 4262 .setup = alc880_medion_rim_setup,
4263 .init_hook = alc880_medion_rim_automute,
4116 }, 4264 },
4117#ifdef CONFIG_SND_DEBUG 4265#ifdef CONFIG_SND_DEBUG
4118 [ALC880_TEST] = { 4266 [ALC880_TEST] = {
@@ -4165,8 +4313,6 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
4165#define alc880_fixed_pin_idx(nid) ((nid) - 0x14) 4313#define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
4166#define alc880_is_multi_pin(nid) ((nid) >= 0x18) 4314#define alc880_is_multi_pin(nid) ((nid) >= 0x18)
4167#define alc880_multi_pin_idx(nid) ((nid) - 0x18) 4315#define alc880_multi_pin_idx(nid) ((nid) - 0x18)
4168#define alc880_is_input_pin(nid) ((nid) >= 0x18)
4169#define alc880_input_pin_idx(nid) ((nid) - 0x18)
4170#define alc880_idx_to_dac(nid) ((nid) + 0x02) 4316#define alc880_idx_to_dac(nid) ((nid) + 0x02)
4171#define alc880_dac_to_idx(nid) ((nid) - 0x02) 4317#define alc880_dac_to_idx(nid) ((nid) - 0x02)
4172#define alc880_idx_to_mixer(nid) ((nid) + 0x0c) 4318#define alc880_idx_to_mixer(nid) ((nid) + 0x0c)
@@ -4254,13 +4400,19 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4254 if (err < 0) 4400 if (err < 0)
4255 return err; 4401 return err;
4256 } else { 4402 } else {
4257 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);
4258 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 4410 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4259 HDA_COMPOSE_AMP_VAL(nid, 3, 0, 4411 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4260 HDA_OUTPUT)); 4412 HDA_OUTPUT));
4261 if (err < 0) 4413 if (err < 0)
4262 return err; 4414 return err;
4263 sprintf(name, "%s Playback Switch", chname[i]); 4415 sprintf(name, "%s Playback Switch", pfx);
4264 err = add_control(spec, ALC_CTL_BIND_MUTE, name, 4416 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4265 HDA_COMPOSE_AMP_VAL(nid, 3, 2, 4417 HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4266 HDA_INPUT)); 4418 HDA_INPUT));
@@ -4334,31 +4486,61 @@ static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4334 return 0; 4486 return 0;
4335} 4487}
4336 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
4337/* create playback/capture controls for input pins */ 4495/* create playback/capture controls for input pins */
4338static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec, 4496static int alc_auto_create_input_ctls(struct hda_codec *codec,
4339 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)
4340{ 4500{
4501 struct alc_spec *spec = codec->spec;
4341 struct hda_input_mux *imux = &spec->private_imux[0]; 4502 struct hda_input_mux *imux = &spec->private_imux[0];
4342 int i, err, idx; 4503 int i, err, idx;
4343 4504
4344 for (i = 0; i < AUTO_PIN_LAST; i++) { 4505 for (i = 0; i < AUTO_PIN_LAST; i++) {
4345 if (alc880_is_input_pin(cfg->input_pins[i])) { 4506 hda_nid_t pin;
4346 idx = alc880_input_pin_idx(cfg->input_pins[i]); 4507
4347 err = new_analog_input(spec, cfg->input_pins[i], 4508 pin = cfg->input_pins[i];
4348 auto_pin_cfg_labels[i], 4509 if (!alc_is_input_pin(codec, pin))
4349 idx, 0x0b); 4510 continue;
4350 if (err < 0) 4511
4351 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) {
4352 imux->items[imux->num_items].label = 4529 imux->items[imux->num_items].label =
4353 auto_pin_cfg_labels[i]; 4530 auto_pin_cfg_labels[i];
4354 imux->items[imux->num_items].index = 4531 imux->items[imux->num_items].index = idx;
4355 alc880_input_pin_idx(cfg->input_pins[i]);
4356 imux->num_items++; 4532 imux->num_items++;
4357 } 4533 }
4358 } 4534 }
4359 return 0; 4535 return 0;
4360} 4536}
4361 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
4362static 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,
4363 unsigned int pin_type) 4545 unsigned int pin_type)
4364{ 4546{
@@ -4424,7 +4606,7 @@ static void alc880_auto_init_analog_input(struct hda_codec *codec)
4424 4606
4425 for (i = 0; i < AUTO_PIN_LAST; i++) { 4607 for (i = 0; i < AUTO_PIN_LAST; i++) {
4426 hda_nid_t nid = spec->autocfg.input_pins[i]; 4608 hda_nid_t nid = spec->autocfg.input_pins[i];
4427 if (alc880_is_input_pin(nid)) { 4609 if (alc_is_input_pin(codec, nid)) {
4428 alc_set_input_pin(codec, nid, i); 4610 alc_set_input_pin(codec, nid, i);
4429 if (nid != ALC880_PIN_CD_NID && 4611 if (nid != ALC880_PIN_CD_NID &&
4430 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 4612 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -4467,7 +4649,7 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
4467 "Headphone"); 4649 "Headphone");
4468 if (err < 0) 4650 if (err < 0)
4469 return err; 4651 return err;
4470 err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg); 4652 err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4471 if (err < 0) 4653 if (err < 0)
4472 return err; 4654 return err;
4473 4655
@@ -4517,8 +4699,42 @@ static void alc880_auto_init(struct hda_codec *codec)
4517 alc_inithook(codec); 4699 alc_inithook(codec);
4518} 4700}
4519 4701
4520static 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)
4521{ 4736{
4737 struct alc_spec *spec = codec->spec;
4522 static struct snd_kcontrol_new *caps[2][3] = { 4738 static struct snd_kcontrol_new *caps[2][3] = {
4523 { alc_capture_mixer_nosrc1, 4739 { alc_capture_mixer_nosrc1,
4524 alc_capture_mixer_nosrc2, 4740 alc_capture_mixer_nosrc2,
@@ -4529,7 +4745,10 @@ static void set_capture_mixer(struct alc_spec *spec)
4529 }; 4745 };
4530 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) { 4746 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4531 int mux; 4747 int mux;
4532 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)
4533 mux = 1; 4752 mux = 1;
4534 else 4753 else
4535 mux = 0; 4754 mux = 0;
@@ -4560,8 +4779,8 @@ static int patch_alc880(struct hda_codec *codec)
4560 alc880_models, 4779 alc880_models,
4561 alc880_cfg_tbl); 4780 alc880_cfg_tbl);
4562 if (board_config < 0) { 4781 if (board_config < 0) {
4563 printk(KERN_INFO "hda_codec: Unknown model for %s, " 4782 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4564 "trying auto-probe from BIOS...\n", codec->chip_name); 4783 codec->chip_name);
4565 board_config = ALC880_AUTO; 4784 board_config = ALC880_AUTO;
4566 } 4785 }
4567 4786
@@ -4586,7 +4805,7 @@ static int patch_alc880(struct hda_codec *codec)
4586 } 4805 }
4587 4806
4588 if (board_config != ALC880_AUTO) 4807 if (board_config != ALC880_AUTO)
4589 setup_preset(spec, &alc880_presets[board_config]); 4808 setup_preset(codec, &alc880_presets[board_config]);
4590 4809
4591 spec->stream_analog_playback = &alc880_pcm_analog_playback; 4810 spec->stream_analog_playback = &alc880_pcm_analog_playback;
4592 spec->stream_analog_capture = &alc880_pcm_analog_capture; 4811 spec->stream_analog_capture = &alc880_pcm_analog_capture;
@@ -4599,7 +4818,7 @@ static int patch_alc880(struct hda_codec *codec)
4599 /* check whether NID 0x07 is valid */ 4818 /* check whether NID 0x07 is valid */
4600 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]); 4819 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4601 /* get type */ 4820 /* get type */
4602 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 4821 wcap = get_wcaps_type(wcap);
4603 if (wcap != AC_WID_AUD_IN) { 4822 if (wcap != AC_WID_AUD_IN) {
4604 spec->adc_nids = alc880_adc_nids_alt; 4823 spec->adc_nids = alc880_adc_nids_alt;
4605 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt); 4824 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
@@ -4608,7 +4827,7 @@ static int patch_alc880(struct hda_codec *codec)
4608 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids); 4827 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4609 } 4828 }
4610 } 4829 }
4611 set_capture_mixer(spec); 4830 set_capture_mixer(codec);
4612 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 4831 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4613 4832
4614 spec->vmaster_nid = 0x0c; 4833 spec->vmaster_nid = 0x0c;
@@ -5800,7 +6019,14 @@ static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5800 6019
5801 nid = cfg->line_out_pins[0]; 6020 nid = cfg->line_out_pins[0];
5802 if (nid) { 6021 if (nid) {
5803 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);
5804 if (err < 0) 6030 if (err < 0)
5805 return err; 6031 return err;
5806 } 6032 }
@@ -5823,39 +6049,10 @@ static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5823} 6049}
5824 6050
5825/* create playback/capture controls for input pins */ 6051/* create playback/capture controls for input pins */
5826static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec, 6052static int alc260_auto_create_input_ctls(struct hda_codec *codec,
5827 const struct auto_pin_cfg *cfg) 6053 const struct auto_pin_cfg *cfg)
5828{ 6054{
5829 struct hda_input_mux *imux = &spec->private_imux[0]; 6055 return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
5830 int i, err, idx;
5831
5832 for (i = 0; i < AUTO_PIN_LAST; i++) {
5833 if (cfg->input_pins[i] >= 0x12) {
5834 idx = cfg->input_pins[i] - 0x12;
5835 err = new_analog_input(spec, cfg->input_pins[i],
5836 auto_pin_cfg_labels[i], idx,
5837 0x07);
5838 if (err < 0)
5839 return err;
5840 imux->items[imux->num_items].label =
5841 auto_pin_cfg_labels[i];
5842 imux->items[imux->num_items].index = idx;
5843 imux->num_items++;
5844 }
5845 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5846 idx = cfg->input_pins[i] - 0x09;
5847 err = new_analog_input(spec, cfg->input_pins[i],
5848 auto_pin_cfg_labels[i], idx,
5849 0x07);
5850 if (err < 0)
5851 return err;
5852 imux->items[imux->num_items].label =
5853 auto_pin_cfg_labels[i];
5854 imux->items[imux->num_items].index = idx;
5855 imux->num_items++;
5856 }
5857 }
5858 return 0;
5859} 6056}
5860 6057
5861static void alc260_auto_set_output_and_unmute(struct hda_codec *codec, 6058static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
@@ -5969,7 +6166,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
5969 return err; 6166 return err;
5970 if (!spec->kctls.list) 6167 if (!spec->kctls.list)
5971 return 0; /* can't find valid BIOS pin config */ 6168 return 0; /* can't find valid BIOS pin config */
5972 err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg); 6169 err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
5973 if (err < 0) 6170 if (err < 0)
5974 return err; 6171 return err;
5975 6172
@@ -6204,8 +6401,7 @@ static int patch_alc260(struct hda_codec *codec)
6204 alc260_models, 6401 alc260_models,
6205 alc260_cfg_tbl); 6402 alc260_cfg_tbl);
6206 if (board_config < 0) { 6403 if (board_config < 0) {
6207 snd_printd(KERN_INFO "hda_codec: Unknown model for %s, " 6404 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6208 "trying auto-probe from BIOS...\n",
6209 codec->chip_name); 6405 codec->chip_name);
6210 board_config = ALC260_AUTO; 6406 board_config = ALC260_AUTO;
6211 } 6407 }
@@ -6231,7 +6427,7 @@ static int patch_alc260(struct hda_codec *codec)
6231 } 6427 }
6232 6428
6233 if (board_config != ALC260_AUTO) 6429 if (board_config != ALC260_AUTO)
6234 setup_preset(spec, &alc260_presets[board_config]); 6430 setup_preset(codec, &alc260_presets[board_config]);
6235 6431
6236 spec->stream_analog_playback = &alc260_pcm_analog_playback; 6432 spec->stream_analog_playback = &alc260_pcm_analog_playback;
6237 spec->stream_analog_capture = &alc260_pcm_analog_capture; 6433 spec->stream_analog_capture = &alc260_pcm_analog_capture;
@@ -6242,7 +6438,7 @@ static int patch_alc260(struct hda_codec *codec)
6242 if (!spec->adc_nids && spec->input_mux) { 6438 if (!spec->adc_nids && spec->input_mux) {
6243 /* check whether NID 0x04 is valid */ 6439 /* check whether NID 0x04 is valid */
6244 unsigned int wcap = get_wcaps(codec, 0x04); 6440 unsigned int wcap = get_wcaps(codec, 0x04);
6245 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 6441 wcap = get_wcaps_type(wcap);
6246 /* get type */ 6442 /* get type */
6247 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) {
6248 spec->adc_nids = alc260_adc_nids_alt; 6444 spec->adc_nids = alc260_adc_nids_alt;
@@ -6252,7 +6448,7 @@ static int patch_alc260(struct hda_codec *codec)
6252 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids); 6448 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6253 } 6449 }
6254 } 6450 }
6255 set_capture_mixer(spec); 6451 set_capture_mixer(codec);
6256 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); 6452 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6257 6453
6258 spec->vmaster_nid = 0x08; 6454 spec->vmaster_nid = 0x08;
@@ -6271,7 +6467,7 @@ static int patch_alc260(struct hda_codec *codec)
6271 6467
6272 6468
6273/* 6469/*
6274 * ALC882 support 6470 * ALC882/883/885/888/889 support
6275 * 6471 *
6276 * 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
6277 * 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.
@@ -6283,22 +6479,35 @@ static int patch_alc260(struct hda_codec *codec)
6283 */ 6479 */
6284#define ALC882_DIGOUT_NID 0x06 6480#define ALC882_DIGOUT_NID 0x06
6285#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
6286 6486
6287static struct hda_channel_mode alc882_ch_modes[1] = { 6487static struct hda_channel_mode alc882_ch_modes[1] = {
6288 { 8, NULL } 6488 { 8, NULL }
6289}; 6489};
6290 6490
6491/* DACs */
6291static hda_nid_t alc882_dac_nids[4] = { 6492static hda_nid_t alc882_dac_nids[4] = {
6292 /* front, rear, clfe, rear_surr */ 6493 /* front, rear, clfe, rear_surr */
6293 0x02, 0x03, 0x04, 0x05 6494 0x02, 0x03, 0x04, 0x05
6294}; 6495};
6496#define alc883_dac_nids alc882_dac_nids
6295 6497
6296/* identical with ALC880 */ 6498/* ADCs */
6297#define alc882_adc_nids alc880_adc_nids 6499#define alc882_adc_nids alc880_adc_nids
6298#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
6299 6505
6300static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 }; 6506static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6301static 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
6302 6511
6303/* input MUX */ 6512/* input MUX */
6304/* FIXME: should be a matrix-type input source selection */ 6513/* FIXME: should be a matrix-type input source selection */
@@ -6313,6 +6522,17 @@ static struct hda_input_mux alc882_capture_source = {
6313 }, 6522 },
6314}; 6523};
6315 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
6316static struct hda_input_mux mb5_capture_source = { 6536static struct hda_input_mux mb5_capture_source = {
6317 .num_items = 3, 6537 .num_items = 3,
6318 .items = { 6538 .items = {
@@ -6322,6 +6542,77 @@ static struct hda_input_mux mb5_capture_source = {
6322 }, 6542 },
6323}; 6543};
6324 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
6325/* 6616/*
6326 * 2ch mode 6617 * 2ch mode
6327 */ 6618 */
@@ -6334,6 +6625,18 @@ static struct hda_verb alc882_3ST_ch2_init[] = {
6334}; 6625};
6335 6626
6336/* 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/*
6337 * 6ch mode 6640 * 6ch mode
6338 */ 6641 */
6339static struct hda_verb alc882_3ST_ch6_init[] = { 6642static struct hda_verb alc882_3ST_ch6_init[] = {
@@ -6346,11 +6649,60 @@ static struct hda_verb alc882_3ST_ch6_init[] = {
6346 { } /* end */ 6649 { } /* end */
6347}; 6650};
6348 6651
6349static struct hda_channel_mode alc882_3ST_6ch_modes[2] = { 6652static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6350 { 2, alc882_3ST_ch2_init }, 6653 { 2, alc882_3ST_ch2_init },
6654 { 4, alc882_3ST_ch4_init },
6351 { 6, alc882_3ST_ch6_init }, 6655 { 6, alc882_3ST_ch6_init },
6352}; 6656};
6353 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
6354/* 6706/*
6355 * 6ch mode 6707 * 6ch mode
6356 */ 6708 */
@@ -6393,9 +6745,9 @@ static struct hda_verb alc885_mbp_ch2_init[] = {
6393}; 6745};
6394 6746
6395/* 6747/*
6396 * 6ch mode 6748 * 4ch mode
6397 */ 6749 */
6398static struct hda_verb alc885_mbp_ch6_init[] = { 6750static struct hda_verb alc885_mbp_ch4_init[] = {
6399 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, 6751 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6400 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 6752 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6401 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 }, 6753 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
@@ -6404,9 +6756,9 @@ static struct hda_verb alc885_mbp_ch6_init[] = {
6404 { } /* end */ 6756 { } /* end */
6405}; 6757};
6406 6758
6407static struct hda_channel_mode alc885_mbp_6ch_modes[2] = { 6759static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
6408 { 2, alc885_mbp_ch2_init }, 6760 { 2, alc885_mbp_ch2_init },
6409 { 6, alc885_mbp_ch6_init }, 6761 { 4, alc885_mbp_ch4_init },
6410}; 6762};
6411 6763
6412/* 6764/*
@@ -6438,6 +6790,189 @@ static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6438 { 6, alc885_mb5_ch6_init }, 6790 { 6, alc885_mb5_ch6_init },
6439}; 6791};
6440 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
6441/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17 6976/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6442 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b 6977 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6443 */ 6978 */
@@ -6467,10 +7002,11 @@ static struct snd_kcontrol_new alc882_base_mixer[] = {
6467}; 7002};
6468 7003
6469static struct snd_kcontrol_new alc885_mbp3_mixer[] = { 7004static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6470 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT), 7005 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6471 HDA_BIND_MUTE ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT), 7006 HDA_BIND_MUTE ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
6472 HDA_CODEC_MUTE ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT), 7007 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
6473 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),
6474 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 7010 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6475 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 7011 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6476 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT), 7012 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
@@ -6573,7 +7109,7 @@ static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6573 { } /* end */ 7109 { } /* end */
6574}; 7110};
6575 7111
6576static struct hda_verb alc882_init_verbs[] = { 7112static struct hda_verb alc882_base_init_verbs[] = {
6577 /* Front mixer: unmute input/output amp left and right (volume = 0) */ 7113 /* Front mixer: unmute input/output amp left and right (volume = 0) */
6578 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 7114 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6579 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7115 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
@@ -6591,6 +7127,13 @@ static struct hda_verb alc882_init_verbs[] = {
6591 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7127 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6592 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 7128 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6593 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
6594 /* Front Pin: output 0 (0x0c) */ 7137 /* Front Pin: output 0 (0x0c) */
6595 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7138 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6596 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 7139 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -6625,11 +7168,6 @@ static struct hda_verb alc882_init_verbs[] = {
6625 7168
6626 /* FIXME: use matrix-type input source selection */ 7169 /* FIXME: use matrix-type input source selection */
6627 /* 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 */
6628 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6629 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6630 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6631 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6632 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6633 /* Input mixer2 */ 7171 /* Input mixer2 */
6634 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7172 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6635 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 7173 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
@@ -6640,9 +7178,6 @@ static struct hda_verb alc882_init_verbs[] = {
6640 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 7178 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6641 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 7179 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6642 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 7180 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6643 /* ADC1: mute amp left and right */
6644 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6645 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6646 /* ADC2: mute amp left and right */ 7181 /* ADC2: mute amp left and right */
6647 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7182 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6648 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, 7183 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -6653,6 +7188,18 @@ static struct hda_verb alc882_init_verbs[] = {
6653 { } 7188 { }
6654}; 7189};
6655 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
6656static struct hda_verb alc882_eapd_verbs[] = { 7203static struct hda_verb alc882_eapd_verbs[] = {
6657 /* change to EAPD mode */ 7204 /* change to EAPD mode */
6658 {0x20, AC_VERB_SET_COEF_INDEX, 0x07}, 7205 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
@@ -6660,6 +7207,110 @@ static struct hda_verb alc882_eapd_verbs[] = {
6660 { } 7207 { }
6661}; 7208};
6662 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
6663/* Mac Pro test */ 7314/* Mac Pro test */
6664static struct snd_kcontrol_new alc882_macpro_mixer[] = { 7315static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6665 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7316 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -6784,14 +7435,18 @@ static struct hda_verb alc885_mbp3_init_verbs[] = {
6784 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 7435 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6785 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7436 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6786 {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)},
6787 /* Front Pin: output 0 (0x0c) */ 7442 /* Front Pin: output 0 (0x0c) */
6788 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7443 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 7444 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6790 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, 7445 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6791 /* HP Pin: output 0 (0x0d) */ 7446 /* HP Pin: output 0 (0x0e) */
6792 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4}, 7447 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6793 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 7448 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6794 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 7449 {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
6795 {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},
6796 /* Mic (rear) pin: input vref at 80% */ 7451 /* Mic (rear) pin: input vref at 80% */
6797 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 7452 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
@@ -6863,23 +7518,21 @@ static struct hda_verb alc885_imac24_init_verbs[] = {
6863}; 7518};
6864 7519
6865/* Toggle speaker-output according to the hp-jack state */ 7520/* Toggle speaker-output according to the hp-jack state */
6866static void alc885_imac24_automute_init_hook(struct hda_codec *codec) 7521static void alc885_imac24_setup(struct hda_codec *codec)
6867{ 7522{
6868 struct alc_spec *spec = codec->spec; 7523 struct alc_spec *spec = codec->spec;
6869 7524
6870 spec->autocfg.hp_pins[0] = 0x14; 7525 spec->autocfg.hp_pins[0] = 0x14;
6871 spec->autocfg.speaker_pins[0] = 0x18; 7526 spec->autocfg.speaker_pins[0] = 0x18;
6872 spec->autocfg.speaker_pins[1] = 0x1a; 7527 spec->autocfg.speaker_pins[1] = 0x1a;
6873 alc_automute_amp(codec);
6874} 7528}
6875 7529
6876static void alc885_mbp3_init_hook(struct hda_codec *codec) 7530static void alc885_mbp3_setup(struct hda_codec *codec)
6877{ 7531{
6878 struct alc_spec *spec = codec->spec; 7532 struct alc_spec *spec = codec->spec;
6879 7533
6880 spec->autocfg.hp_pins[0] = 0x15; 7534 spec->autocfg.hp_pins[0] = 0x15;
6881 spec->autocfg.speaker_pins[0] = 0x14; 7535 spec->autocfg.speaker_pins[0] = 0x14;
6882 alc_automute_amp(codec);
6883} 7536}
6884 7537
6885 7538
@@ -6895,9 +7548,6 @@ static struct hda_verb alc882_targa_verbs[] = {
6895 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */ 7548 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6896 7549
6897 {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},
6898 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6899 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6900 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6901 { } /* end */ 7551 { } /* end */
6902}; 7552};
6903 7553
@@ -6910,13 +7560,12 @@ static void alc882_targa_automute(struct hda_codec *codec)
6910 spec->jack_present ? 1 : 3); 7560 spec->jack_present ? 1 : 3);
6911} 7561}
6912 7562
6913static void alc882_targa_init_hook(struct hda_codec *codec) 7563static void alc882_targa_setup(struct hda_codec *codec)
6914{ 7564{
6915 struct alc_spec *spec = codec->spec; 7565 struct alc_spec *spec = codec->spec;
6916 7566
6917 spec->autocfg.hp_pins[0] = 0x14; 7567 spec->autocfg.hp_pins[0] = 0x14;
6918 spec->autocfg.speaker_pins[0] = 0x1b; 7568 spec->autocfg.speaker_pins[0] = 0x1b;
6919 alc882_targa_automute(codec);
6920} 7569}
6921 7570
6922static 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)
@@ -7004,18 +7653,16 @@ static void alc885_macpro_init_hook(struct hda_codec *codec)
7004static void alc885_imac24_init_hook(struct hda_codec *codec) 7653static void alc885_imac24_init_hook(struct hda_codec *codec)
7005{ 7654{
7006 alc885_macpro_init_hook(codec); 7655 alc885_macpro_init_hook(codec);
7007 alc885_imac24_automute_init_hook(codec); 7656 alc_automute_amp(codec);
7008} 7657}
7009 7658
7010/* 7659/*
7011 * generic initialization of ADC, input mixers and output mixers 7660 * generic initialization of ADC, input mixers and output mixers
7012 */ 7661 */
7013static struct hda_verb alc882_auto_init_verbs[] = { 7662static struct hda_verb alc883_auto_init_verbs[] = {
7014 /* 7663 /*
7015 * Unmute ADC0-2 and set the default input to mic-in 7664 * Unmute ADC0-2 and set the default input to mic-in
7016 */ 7665 */
7017 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7018 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7019 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, 7666 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7020 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7667 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7021 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00}, 7668 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -7056,11 +7703,6 @@ static struct hda_verb alc882_auto_init_verbs[] = {
7056 7703
7057 /* FIXME: use matrix-type input source selection */ 7704 /* FIXME: use matrix-type input source selection */
7058 /* 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 */
7059 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7060 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7061 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7062 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7063 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7064 /* Input mixer2 */ 7706 /* Input mixer2 */
7065 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, 7707 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7066 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))}, 7708 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
@@ -7075,819 +7717,6 @@ static struct hda_verb alc882_auto_init_verbs[] = {
7075 { } 7717 { }
7076}; 7718};
7077 7719
7078#ifdef CONFIG_SND_HDA_POWER_SAVE
7079#define alc882_loopbacks alc880_loopbacks
7080#endif
7081
7082/* pcm configuration: identical with ALC880 */
7083#define alc882_pcm_analog_playback alc880_pcm_analog_playback
7084#define alc882_pcm_analog_capture alc880_pcm_analog_capture
7085#define alc882_pcm_digital_playback alc880_pcm_digital_playback
7086#define alc882_pcm_digital_capture alc880_pcm_digital_capture
7087
7088/*
7089 * configuration and preset
7090 */
7091static const char *alc882_models[ALC882_MODEL_LAST] = {
7092 [ALC882_3ST_DIG] = "3stack-dig",
7093 [ALC882_6ST_DIG] = "6stack-dig",
7094 [ALC882_ARIMA] = "arima",
7095 [ALC882_W2JC] = "w2jc",
7096 [ALC882_TARGA] = "targa",
7097 [ALC882_ASUS_A7J] = "asus-a7j",
7098 [ALC882_ASUS_A7M] = "asus-a7m",
7099 [ALC885_MACPRO] = "macpro",
7100 [ALC885_MB5] = "mb5",
7101 [ALC885_MBP3] = "mbp3",
7102 [ALC885_IMAC24] = "imac24",
7103 [ALC882_AUTO] = "auto",
7104};
7105
7106static struct snd_pci_quirk alc882_cfg_tbl[] = {
7107 SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
7108 SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
7109 SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
7110 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
7111 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
7112 SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
7113 SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
7114 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
7115 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
7116 SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8 */
7117 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
7118 SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
7119 {}
7120};
7121
7122static struct alc_config_preset alc882_presets[] = {
7123 [ALC882_3ST_DIG] = {
7124 .mixers = { alc882_base_mixer },
7125 .init_verbs = { alc882_init_verbs },
7126 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7127 .dac_nids = alc882_dac_nids,
7128 .dig_out_nid = ALC882_DIGOUT_NID,
7129 .dig_in_nid = ALC882_DIGIN_NID,
7130 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7131 .channel_mode = alc882_ch_modes,
7132 .need_dac_fix = 1,
7133 .input_mux = &alc882_capture_source,
7134 },
7135 [ALC882_6ST_DIG] = {
7136 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7137 .init_verbs = { alc882_init_verbs },
7138 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7139 .dac_nids = alc882_dac_nids,
7140 .dig_out_nid = ALC882_DIGOUT_NID,
7141 .dig_in_nid = ALC882_DIGIN_NID,
7142 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7143 .channel_mode = alc882_sixstack_modes,
7144 .input_mux = &alc882_capture_source,
7145 },
7146 [ALC882_ARIMA] = {
7147 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7148 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
7149 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7150 .dac_nids = alc882_dac_nids,
7151 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7152 .channel_mode = alc882_sixstack_modes,
7153 .input_mux = &alc882_capture_source,
7154 },
7155 [ALC882_W2JC] = {
7156 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
7157 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7158 alc880_gpio1_init_verbs },
7159 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7160 .dac_nids = alc882_dac_nids,
7161 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7162 .channel_mode = alc880_threestack_modes,
7163 .need_dac_fix = 1,
7164 .input_mux = &alc882_capture_source,
7165 .dig_out_nid = ALC882_DIGOUT_NID,
7166 },
7167 [ALC885_MBP3] = {
7168 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
7169 .init_verbs = { alc885_mbp3_init_verbs,
7170 alc880_gpio1_init_verbs },
7171 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7172 .dac_nids = alc882_dac_nids,
7173 .channel_mode = alc885_mbp_6ch_modes,
7174 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
7175 .input_mux = &alc882_capture_source,
7176 .dig_out_nid = ALC882_DIGOUT_NID,
7177 .dig_in_nid = ALC882_DIGIN_NID,
7178 .unsol_event = alc_automute_amp_unsol_event,
7179 .init_hook = alc885_mbp3_init_hook,
7180 },
7181 [ALC885_MB5] = {
7182 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
7183 .init_verbs = { alc885_mb5_init_verbs,
7184 alc880_gpio1_init_verbs },
7185 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7186 .dac_nids = alc882_dac_nids,
7187 .channel_mode = alc885_mb5_6ch_modes,
7188 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
7189 .input_mux = &mb5_capture_source,
7190 .dig_out_nid = ALC882_DIGOUT_NID,
7191 .dig_in_nid = ALC882_DIGIN_NID,
7192 },
7193 [ALC885_MACPRO] = {
7194 .mixers = { alc882_macpro_mixer },
7195 .init_verbs = { alc882_macpro_init_verbs },
7196 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7197 .dac_nids = alc882_dac_nids,
7198 .dig_out_nid = ALC882_DIGOUT_NID,
7199 .dig_in_nid = ALC882_DIGIN_NID,
7200 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7201 .channel_mode = alc882_ch_modes,
7202 .input_mux = &alc882_capture_source,
7203 .init_hook = alc885_macpro_init_hook,
7204 },
7205 [ALC885_IMAC24] = {
7206 .mixers = { alc885_imac24_mixer },
7207 .init_verbs = { alc885_imac24_init_verbs },
7208 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7209 .dac_nids = alc882_dac_nids,
7210 .dig_out_nid = ALC882_DIGOUT_NID,
7211 .dig_in_nid = ALC882_DIGIN_NID,
7212 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7213 .channel_mode = alc882_ch_modes,
7214 .input_mux = &alc882_capture_source,
7215 .unsol_event = alc_automute_amp_unsol_event,
7216 .init_hook = alc885_imac24_init_hook,
7217 },
7218 [ALC882_TARGA] = {
7219 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
7220 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
7221 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7222 .dac_nids = alc882_dac_nids,
7223 .dig_out_nid = ALC882_DIGOUT_NID,
7224 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7225 .adc_nids = alc882_adc_nids,
7226 .capsrc_nids = alc882_capsrc_nids,
7227 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7228 .channel_mode = alc882_3ST_6ch_modes,
7229 .need_dac_fix = 1,
7230 .input_mux = &alc882_capture_source,
7231 .unsol_event = alc882_targa_unsol_event,
7232 .init_hook = alc882_targa_init_hook,
7233 },
7234 [ALC882_ASUS_A7J] = {
7235 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
7236 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
7237 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7238 .dac_nids = alc882_dac_nids,
7239 .dig_out_nid = ALC882_DIGOUT_NID,
7240 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7241 .adc_nids = alc882_adc_nids,
7242 .capsrc_nids = alc882_capsrc_nids,
7243 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7244 .channel_mode = alc882_3ST_6ch_modes,
7245 .need_dac_fix = 1,
7246 .input_mux = &alc882_capture_source,
7247 },
7248 [ALC882_ASUS_A7M] = {
7249 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
7250 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7251 alc880_gpio1_init_verbs,
7252 alc882_asus_a7m_verbs },
7253 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7254 .dac_nids = alc882_dac_nids,
7255 .dig_out_nid = ALC882_DIGOUT_NID,
7256 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7257 .channel_mode = alc880_threestack_modes,
7258 .need_dac_fix = 1,
7259 .input_mux = &alc882_capture_source,
7260 },
7261};
7262
7263
7264/*
7265 * Pin config fixes
7266 */
7267enum {
7268 PINFIX_ABIT_AW9D_MAX
7269};
7270
7271static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
7272 { 0x15, 0x01080104 }, /* side */
7273 { 0x16, 0x01011012 }, /* rear */
7274 { 0x17, 0x01016011 }, /* clfe */
7275 { }
7276};
7277
7278static const struct alc_pincfg *alc882_pin_fixes[] = {
7279 [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
7280};
7281
7282static struct snd_pci_quirk alc882_pinfix_tbl[] = {
7283 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
7284 {}
7285};
7286
7287/*
7288 * BIOS auto configuration
7289 */
7290static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
7291 hda_nid_t nid, int pin_type,
7292 int dac_idx)
7293{
7294 /* set as output */
7295 struct alc_spec *spec = codec->spec;
7296 int idx;
7297
7298 alc_set_pin_output(codec, nid, pin_type);
7299 if (spec->multiout.dac_nids[dac_idx] == 0x25)
7300 idx = 4;
7301 else
7302 idx = spec->multiout.dac_nids[dac_idx] - 2;
7303 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7304
7305}
7306
7307static void alc882_auto_init_multi_out(struct hda_codec *codec)
7308{
7309 struct alc_spec *spec = codec->spec;
7310 int i;
7311
7312 for (i = 0; i <= HDA_SIDE; i++) {
7313 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7314 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7315 if (nid)
7316 alc882_auto_set_output_and_unmute(codec, nid, pin_type,
7317 i);
7318 }
7319}
7320
7321static void alc882_auto_init_hp_out(struct hda_codec *codec)
7322{
7323 struct alc_spec *spec = codec->spec;
7324 hda_nid_t pin;
7325
7326 pin = spec->autocfg.hp_pins[0];
7327 if (pin) /* connect to front */
7328 /* use dac 0 */
7329 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7330 pin = spec->autocfg.speaker_pins[0];
7331 if (pin)
7332 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7333}
7334
7335#define alc882_is_input_pin(nid) alc880_is_input_pin(nid)
7336#define ALC882_PIN_CD_NID ALC880_PIN_CD_NID
7337
7338static void alc882_auto_init_analog_input(struct hda_codec *codec)
7339{
7340 struct alc_spec *spec = codec->spec;
7341 int i;
7342
7343 for (i = 0; i < AUTO_PIN_LAST; i++) {
7344 hda_nid_t nid = spec->autocfg.input_pins[i];
7345 if (!nid)
7346 continue;
7347 alc_set_input_pin(codec, nid, AUTO_PIN_FRONT_MIC /*i*/);
7348 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
7349 snd_hda_codec_write(codec, nid, 0,
7350 AC_VERB_SET_AMP_GAIN_MUTE,
7351 AMP_OUT_MUTE);
7352 }
7353}
7354
7355static void alc882_auto_init_input_src(struct hda_codec *codec)
7356{
7357 struct alc_spec *spec = codec->spec;
7358 int c;
7359
7360 for (c = 0; c < spec->num_adc_nids; c++) {
7361 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
7362 hda_nid_t nid = spec->capsrc_nids[c];
7363 unsigned int mux_idx;
7364 const struct hda_input_mux *imux;
7365 int conns, mute, idx, item;
7366
7367 conns = snd_hda_get_connections(codec, nid, conn_list,
7368 ARRAY_SIZE(conn_list));
7369 if (conns < 0)
7370 continue;
7371 mux_idx = c >= spec->num_mux_defs ? 0 : c;
7372 imux = &spec->input_mux[mux_idx];
7373 for (idx = 0; idx < conns; idx++) {
7374 /* if the current connection is the selected one,
7375 * unmute it as default - otherwise mute it
7376 */
7377 mute = AMP_IN_MUTE(idx);
7378 for (item = 0; item < imux->num_items; item++) {
7379 if (imux->items[item].index == idx) {
7380 if (spec->cur_mux[c] == item)
7381 mute = AMP_IN_UNMUTE(idx);
7382 break;
7383 }
7384 }
7385 /* check if we have a selector or mixer
7386 * we could check for the widget type instead, but
7387 * just check for Amp-In presence (in case of mixer
7388 * without amp-in there is something wrong, this
7389 * function shouldn't be used or capsrc nid is wrong)
7390 */
7391 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
7392 snd_hda_codec_write(codec, nid, 0,
7393 AC_VERB_SET_AMP_GAIN_MUTE,
7394 mute);
7395 else if (mute != AMP_IN_MUTE(idx))
7396 snd_hda_codec_write(codec, nid, 0,
7397 AC_VERB_SET_CONNECT_SEL,
7398 idx);
7399 }
7400 }
7401}
7402
7403/* add mic boosts if needed */
7404static int alc_auto_add_mic_boost(struct hda_codec *codec)
7405{
7406 struct alc_spec *spec = codec->spec;
7407 int err;
7408 hda_nid_t nid;
7409
7410 nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
7411 if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7412 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7413 "Mic Boost",
7414 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7415 if (err < 0)
7416 return err;
7417 }
7418 nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
7419 if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7420 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7421 "Front Mic Boost",
7422 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7423 if (err < 0)
7424 return err;
7425 }
7426 return 0;
7427}
7428
7429/* almost identical with ALC880 parser... */
7430static int alc882_parse_auto_config(struct hda_codec *codec)
7431{
7432 struct alc_spec *spec = codec->spec;
7433 int err = alc880_parse_auto_config(codec);
7434
7435 if (err < 0)
7436 return err;
7437 else if (!err)
7438 return 0; /* no config found */
7439
7440 err = alc_auto_add_mic_boost(codec);
7441 if (err < 0)
7442 return err;
7443
7444 /* hack - override the init verbs */
7445 spec->init_verbs[0] = alc882_auto_init_verbs;
7446
7447 return 1; /* config found */
7448}
7449
7450/* additional initialization for auto-configuration model */
7451static void alc882_auto_init(struct hda_codec *codec)
7452{
7453 struct alc_spec *spec = codec->spec;
7454 alc882_auto_init_multi_out(codec);
7455 alc882_auto_init_hp_out(codec);
7456 alc882_auto_init_analog_input(codec);
7457 alc882_auto_init_input_src(codec);
7458 if (spec->unsol_event)
7459 alc_inithook(codec);
7460}
7461
7462static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7463
7464static int patch_alc882(struct hda_codec *codec)
7465{
7466 struct alc_spec *spec;
7467 int err, board_config;
7468
7469 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7470 if (spec == NULL)
7471 return -ENOMEM;
7472
7473 codec->spec = spec;
7474
7475 board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7476 alc882_models,
7477 alc882_cfg_tbl);
7478
7479 if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7480 /* Pick up systems that don't supply PCI SSID */
7481 switch (codec->subsystem_id) {
7482 case 0x106b0c00: /* Mac Pro */
7483 board_config = ALC885_MACPRO;
7484 break;
7485 case 0x106b1000: /* iMac 24 */
7486 case 0x106b2800: /* AppleTV */
7487 case 0x106b3e00: /* iMac 24 Aluminium */
7488 board_config = ALC885_IMAC24;
7489 break;
7490 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
7491 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7492 case 0x106b00a4: /* MacbookPro4,1 */
7493 case 0x106b2c00: /* Macbook Pro rev3 */
7494 /* Macbook 3.1 (0x106b3600) is handled by patch_alc883() */
7495 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7496 board_config = ALC885_MBP3;
7497 break;
7498 case 0x106b3f00: /* Macbook 5,1 */
7499 case 0x106b4000: /* Macbook Pro 5,1 - FIXME: HP jack sense
7500 * seems not working, so apparently
7501 * no perfect solution yet
7502 */
7503 board_config = ALC885_MB5;
7504 break;
7505 default:
7506 /* ALC889A is handled better as ALC888-compatible */
7507 if (codec->revision_id == 0x100101 ||
7508 codec->revision_id == 0x100103) {
7509 alc_free(codec);
7510 return patch_alc883(codec);
7511 }
7512 printk(KERN_INFO "hda_codec: Unknown model for %s, "
7513 "trying auto-probe from BIOS...\n",
7514 codec->chip_name);
7515 board_config = ALC882_AUTO;
7516 }
7517 }
7518
7519 alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7520
7521 if (board_config == ALC882_AUTO) {
7522 /* automatic parse from the BIOS config */
7523 err = alc882_parse_auto_config(codec);
7524 if (err < 0) {
7525 alc_free(codec);
7526 return err;
7527 } else if (!err) {
7528 printk(KERN_INFO
7529 "hda_codec: Cannot set up configuration "
7530 "from BIOS. Using base mode...\n");
7531 board_config = ALC882_3ST_DIG;
7532 }
7533 }
7534
7535 err = snd_hda_attach_beep_device(codec, 0x1);
7536 if (err < 0) {
7537 alc_free(codec);
7538 return err;
7539 }
7540
7541 if (board_config != ALC882_AUTO)
7542 setup_preset(spec, &alc882_presets[board_config]);
7543
7544 spec->stream_analog_playback = &alc882_pcm_analog_playback;
7545 spec->stream_analog_capture = &alc882_pcm_analog_capture;
7546 /* FIXME: setup DAC5 */
7547 /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7548 spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7549
7550 spec->stream_digital_playback = &alc882_pcm_digital_playback;
7551 spec->stream_digital_capture = &alc882_pcm_digital_capture;
7552
7553 if (!spec->adc_nids && spec->input_mux) {
7554 /* check whether NID 0x07 is valid */
7555 unsigned int wcap = get_wcaps(codec, 0x07);
7556 /* get type */
7557 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7558 if (wcap != AC_WID_AUD_IN) {
7559 spec->adc_nids = alc882_adc_nids_alt;
7560 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7561 spec->capsrc_nids = alc882_capsrc_nids_alt;
7562 } else {
7563 spec->adc_nids = alc882_adc_nids;
7564 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7565 spec->capsrc_nids = alc882_capsrc_nids;
7566 }
7567 }
7568 set_capture_mixer(spec);
7569 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7570
7571 spec->vmaster_nid = 0x0c;
7572
7573 codec->patch_ops = alc_patch_ops;
7574 if (board_config == ALC882_AUTO)
7575 spec->init_hook = alc882_auto_init;
7576#ifdef CONFIG_SND_HDA_POWER_SAVE
7577 if (!spec->loopback.amplist)
7578 spec->loopback.amplist = alc882_loopbacks;
7579#endif
7580 codec->proc_widget_hook = print_realtek_coef;
7581
7582 return 0;
7583}
7584
7585/*
7586 * ALC883 support
7587 *
7588 * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7589 * configuration. Each pin widget can choose any input DACs and a mixer.
7590 * Each ADC is connected from a mixer of all inputs. This makes possible
7591 * 6-channel independent captures.
7592 *
7593 * In addition, an independent DAC for the multi-playback (not used in this
7594 * driver yet).
7595 */
7596#define ALC883_DIGOUT_NID 0x06
7597#define ALC883_DIGIN_NID 0x0a
7598
7599#define ALC1200_DIGOUT_NID 0x10
7600
7601static hda_nid_t alc883_dac_nids[4] = {
7602 /* front, rear, clfe, rear_surr */
7603 0x02, 0x03, 0x04, 0x05
7604};
7605
7606static hda_nid_t alc883_adc_nids[2] = {
7607 /* ADC1-2 */
7608 0x08, 0x09,
7609};
7610
7611static hda_nid_t alc883_adc_nids_alt[1] = {
7612 /* ADC1 */
7613 0x08,
7614};
7615
7616static hda_nid_t alc883_adc_nids_rev[2] = {
7617 /* ADC2-1 */
7618 0x09, 0x08
7619};
7620
7621#define alc889_adc_nids alc880_adc_nids
7622
7623static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7624
7625static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7626
7627#define alc889_capsrc_nids alc882_capsrc_nids
7628
7629/* input MUX */
7630/* FIXME: should be a matrix-type input source selection */
7631
7632static struct hda_input_mux alc883_capture_source = {
7633 .num_items = 4,
7634 .items = {
7635 { "Mic", 0x0 },
7636 { "Front Mic", 0x1 },
7637 { "Line", 0x2 },
7638 { "CD", 0x4 },
7639 },
7640};
7641
7642static struct hda_input_mux alc883_3stack_6ch_intel = {
7643 .num_items = 4,
7644 .items = {
7645 { "Mic", 0x1 },
7646 { "Front Mic", 0x0 },
7647 { "Line", 0x2 },
7648 { "CD", 0x4 },
7649 },
7650};
7651
7652static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7653 .num_items = 2,
7654 .items = {
7655 { "Mic", 0x1 },
7656 { "Line", 0x2 },
7657 },
7658};
7659
7660static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7661 .num_items = 4,
7662 .items = {
7663 { "Mic", 0x0 },
7664 { "iMic", 0x1 },
7665 { "Line", 0x2 },
7666 { "CD", 0x4 },
7667 },
7668};
7669
7670static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7671 .num_items = 2,
7672 .items = {
7673 { "Mic", 0x0 },
7674 { "Int Mic", 0x1 },
7675 },
7676};
7677
7678static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7679 .num_items = 3,
7680 .items = {
7681 { "Mic", 0x0 },
7682 { "Front Mic", 0x1 },
7683 { "Line", 0x4 },
7684 },
7685};
7686
7687static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7688 .num_items = 2,
7689 .items = {
7690 { "Mic", 0x0 },
7691 { "Line", 0x2 },
7692 },
7693};
7694
7695static struct hda_input_mux alc889A_mb31_capture_source = {
7696 .num_items = 2,
7697 .items = {
7698 { "Mic", 0x0 },
7699 /* Front Mic (0x01) unused */
7700 { "Line", 0x2 },
7701 /* Line 2 (0x03) unused */
7702 /* CD (0x04) unsused? */
7703 },
7704};
7705
7706/*
7707 * 2ch mode
7708 */
7709static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7710 { 2, NULL }
7711};
7712
7713/*
7714 * 2ch mode
7715 */
7716static struct hda_verb alc883_3ST_ch2_init[] = {
7717 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7718 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7719 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7720 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7721 { } /* end */
7722};
7723
7724/*
7725 * 4ch mode
7726 */
7727static struct hda_verb alc883_3ST_ch4_init[] = {
7728 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7729 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7730 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7731 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7732 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7733 { } /* end */
7734};
7735
7736/*
7737 * 6ch mode
7738 */
7739static struct hda_verb alc883_3ST_ch6_init[] = {
7740 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7741 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7742 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7743 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7744 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7745 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7746 { } /* end */
7747};
7748
7749static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7750 { 2, alc883_3ST_ch2_init },
7751 { 4, alc883_3ST_ch4_init },
7752 { 6, alc883_3ST_ch6_init },
7753};
7754
7755
7756/*
7757 * 2ch mode
7758 */
7759static struct hda_verb alc883_4ST_ch2_init[] = {
7760 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7761 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7762 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7763 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7764 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7765 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7766 { } /* end */
7767};
7768
7769/*
7770 * 4ch mode
7771 */
7772static struct hda_verb alc883_4ST_ch4_init[] = {
7773 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7774 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7775 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7776 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7777 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7778 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7779 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7780 { } /* end */
7781};
7782
7783/*
7784 * 6ch mode
7785 */
7786static struct hda_verb alc883_4ST_ch6_init[] = {
7787 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7788 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7789 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7790 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7791 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7792 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7793 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7794 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7795 { } /* end */
7796};
7797
7798/*
7799 * 8ch mode
7800 */
7801static struct hda_verb alc883_4ST_ch8_init[] = {
7802 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7803 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7804 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
7805 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7806 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7807 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7808 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7809 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7810 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7811 { } /* end */
7812};
7813
7814static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
7815 { 2, alc883_4ST_ch2_init },
7816 { 4, alc883_4ST_ch4_init },
7817 { 6, alc883_4ST_ch6_init },
7818 { 8, alc883_4ST_ch8_init },
7819};
7820
7821
7822/*
7823 * 2ch mode
7824 */
7825static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7826 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7827 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7828 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7829 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7830 { } /* end */
7831};
7832
7833/*
7834 * 4ch mode
7835 */
7836static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7837 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7838 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7839 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7840 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7841 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7842 { } /* end */
7843};
7844
7845/*
7846 * 6ch mode
7847 */
7848static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7849 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7850 { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7851 { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7852 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7853 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7854 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7855 { } /* end */
7856};
7857
7858static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7859 { 2, alc883_3ST_ch2_intel_init },
7860 { 4, alc883_3ST_ch4_intel_init },
7861 { 6, alc883_3ST_ch6_intel_init },
7862};
7863
7864/*
7865 * 6ch mode
7866 */
7867static struct hda_verb alc883_sixstack_ch6_init[] = {
7868 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7869 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7870 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7871 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7872 { } /* end */
7873};
7874
7875/*
7876 * 8ch mode
7877 */
7878static struct hda_verb alc883_sixstack_ch8_init[] = {
7879 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7880 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7881 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7882 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7883 { } /* end */
7884};
7885
7886static struct hda_channel_mode alc883_sixstack_modes[2] = {
7887 { 6, alc883_sixstack_ch6_init },
7888 { 8, alc883_sixstack_ch8_init },
7889};
7890
7891/* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */ 7720/* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7892static struct hda_verb alc889A_mb31_ch2_init[] = { 7721static struct hda_verb alc889A_mb31_ch2_init[] = {
7893 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP as front */ 7722 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP as front */
@@ -7938,34 +7767,7 @@ static struct hda_verb alc883_medion_eapd_verbs[] = {
7938 { } 7767 { }
7939}; 7768};
7940 7769
7941/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17 7770#define alc883_base_mixer alc882_base_mixer
7942 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7943 */
7944
7945static struct snd_kcontrol_new alc883_base_mixer[] = {
7946 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7947 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7948 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7949 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7950 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7951 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7952 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7953 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7954 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7955 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7956 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7957 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7958 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7959 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7960 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7961 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7962 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7963 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7964 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7965 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7966 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7967 { } /* end */
7968};
7969 7771
7970static struct snd_kcontrol_new alc883_mitac_mixer[] = { 7772static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7971 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7773 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -8076,6 +7878,30 @@ static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
8076 { } /* end */ 7878 { } /* end */
8077}; 7879};
8078 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
8079static struct snd_kcontrol_new alc883_fivestack_mixer[] = { 7905static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8080 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7906 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8081 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 7907 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -8101,8 +7927,9 @@ static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8101 7927
8102static struct snd_kcontrol_new alc883_targa_mixer[] = { 7928static struct snd_kcontrol_new alc883_targa_mixer[] = {
8103 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),
8104 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT), 7931 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8105 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 7932 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8106 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 7933 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8107 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 7934 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8108 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),
@@ -8121,8 +7948,9 @@ static struct snd_kcontrol_new alc883_targa_mixer[] = {
8121 7948
8122static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = { 7949static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
8123 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),
8124 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT), 7952 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8125 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 7953 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8126 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 7954 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8127 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 7955 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8128 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 7956 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
@@ -8134,6 +7962,15 @@ static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
8134 { } /* end */ 7962 { } /* end */
8135}; 7963};
8136 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
8137static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = { 7974static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
8138 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7975 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8139 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 7976 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -8189,6 +8026,8 @@ static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8189 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 8026 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8190 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 8027 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8191 HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT), 8028 HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8029 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8030 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8192 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 8031 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8193 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 8032 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8194 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8033 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
@@ -8314,93 +8153,14 @@ static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8314 { } /* end */ 8153 { } /* end */
8315}; 8154};
8316 8155
8317static struct hda_verb alc883_init_verbs[] = {
8318 /* ADC1: mute amp left and right */
8319 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8320 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8321 /* ADC2: mute amp left and right */
8322 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8323 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8324 /* Front mixer: unmute input/output amp left and right (volume = 0) */
8325 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8326 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8327 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8328 /* Rear mixer */
8329 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8330 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8331 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8332 /* CLFE mixer */
8333 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8334 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8335 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8336 /* Side mixer */
8337 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8338 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8339 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8340
8341 /* mute analog input loopbacks */
8342 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8343 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8344 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8345 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8346 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8347
8348 /* Front Pin: output 0 (0x0c) */
8349 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8350 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8351 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8352 /* Rear Pin: output 1 (0x0d) */
8353 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8354 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8355 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8356 /* CLFE Pin: output 2 (0x0e) */
8357 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8358 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8359 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8360 /* Side Pin: output 3 (0x0f) */
8361 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8362 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8363 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8364 /* Mic (rear) pin: input vref at 80% */
8365 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8366 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8367 /* Front Mic pin: input vref at 80% */
8368 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8369 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8370 /* Line In pin: input */
8371 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8372 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8373 /* Line-2 In: Headphone output (output 0 - 0x0c) */
8374 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8375 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8376 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8377 /* CD pin widget for input */
8378 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8379
8380 /* FIXME: use matrix-type input source selection */
8381 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8382 /* Input mixer2 */
8383 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8384 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8385 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8386 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8387 /* Input mixer3 */
8388 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8389 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8390 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8391 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8392 { }
8393};
8394
8395/* toggle speaker-output according to the hp-jack state */ 8156/* toggle speaker-output according to the hp-jack state */
8396static void alc883_mitac_init_hook(struct hda_codec *codec) 8157static void alc883_mitac_setup(struct hda_codec *codec)
8397{ 8158{
8398 struct alc_spec *spec = codec->spec; 8159 struct alc_spec *spec = codec->spec;
8399 8160
8400 spec->autocfg.hp_pins[0] = 0x15; 8161 spec->autocfg.hp_pins[0] = 0x15;
8401 spec->autocfg.speaker_pins[0] = 0x14; 8162 spec->autocfg.speaker_pins[0] = 0x14;
8402 spec->autocfg.speaker_pins[1] = 0x17; 8163 spec->autocfg.speaker_pins[1] = 0x17;
8403 alc_automute_amp(codec);
8404} 8164}
8405 8165
8406/* auto-toggle front mic */ 8166/* auto-toggle front mic */
@@ -8432,6 +8192,22 @@ static struct hda_verb alc883_mitac_verbs[] = {
8432 { } /* end */ 8192 { } /* end */
8433}; 8193};
8434 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
8435static struct hda_verb alc883_clevo_m720_verbs[] = { 8211static struct hda_verb alc883_clevo_m720_verbs[] = {
8436 /* HP */ 8212 /* HP */
8437 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 8213 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -8555,7 +8331,7 @@ static struct hda_verb alc883_vaiott_verbs[] = {
8555 { } /* end */ 8331 { } /* end */
8556}; 8332};
8557 8333
8558static void alc888_3st_hp_init_hook(struct hda_codec *codec) 8334static void alc888_3st_hp_setup(struct hda_codec *codec)
8559{ 8335{
8560 struct alc_spec *spec = codec->spec; 8336 struct alc_spec *spec = codec->spec;
8561 8337
@@ -8563,7 +8339,6 @@ static void alc888_3st_hp_init_hook(struct hda_codec *codec)
8563 spec->autocfg.speaker_pins[0] = 0x14; 8339 spec->autocfg.speaker_pins[0] = 0x14;
8564 spec->autocfg.speaker_pins[1] = 0x16; 8340 spec->autocfg.speaker_pins[1] = 0x16;
8565 spec->autocfg.speaker_pins[2] = 0x18; 8341 spec->autocfg.speaker_pins[2] = 0x18;
8566 alc_automute_amp(codec);
8567} 8342}
8568 8343
8569static struct hda_verb alc888_3st_hp_verbs[] = { 8344static struct hda_verb alc888_3st_hp_verbs[] = {
@@ -8660,13 +8435,12 @@ static struct hda_verb alc883_medion_md2_verbs[] = {
8660}; 8435};
8661 8436
8662/* toggle speaker-output according to the hp-jack state */ 8437/* toggle speaker-output according to the hp-jack state */
8663static void alc883_medion_md2_init_hook(struct hda_codec *codec) 8438static void alc883_medion_md2_setup(struct hda_codec *codec)
8664{ 8439{
8665 struct alc_spec *spec = codec->spec; 8440 struct alc_spec *spec = codec->spec;
8666 8441
8667 spec->autocfg.hp_pins[0] = 0x14; 8442 spec->autocfg.hp_pins[0] = 0x14;
8668 spec->autocfg.speaker_pins[0] = 0x15; 8443 spec->autocfg.speaker_pins[0] = 0x15;
8669 alc_automute_amp(codec);
8670} 8444}
8671 8445
8672/* toggle speaker-output according to the hp-jack state */ 8446/* toggle speaker-output according to the hp-jack state */
@@ -8683,12 +8457,16 @@ static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8683 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8457 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8684} 8458}
8685 8459
8686static void alc883_clevo_m720_init_hook(struct hda_codec *codec) 8460static void alc883_clevo_m720_setup(struct hda_codec *codec)
8687{ 8461{
8688 struct alc_spec *spec = codec->spec; 8462 struct alc_spec *spec = codec->spec;
8689 8463
8690 spec->autocfg.hp_pins[0] = 0x15; 8464 spec->autocfg.hp_pins[0] = 0x15;
8691 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{
8692 alc_automute_amp(codec); 8470 alc_automute_amp(codec);
8693 alc883_clevo_m720_mic_automute(codec); 8471 alc883_clevo_m720_mic_automute(codec);
8694} 8472}
@@ -8707,22 +8485,20 @@ static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8707} 8485}
8708 8486
8709/* toggle speaker-output according to the hp-jack state */ 8487/* toggle speaker-output according to the hp-jack state */
8710static void alc883_2ch_fujitsu_pi2515_init_hook(struct hda_codec *codec) 8488static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8711{ 8489{
8712 struct alc_spec *spec = codec->spec; 8490 struct alc_spec *spec = codec->spec;
8713 8491
8714 spec->autocfg.hp_pins[0] = 0x14; 8492 spec->autocfg.hp_pins[0] = 0x14;
8715 spec->autocfg.speaker_pins[0] = 0x15; 8493 spec->autocfg.speaker_pins[0] = 0x15;
8716 alc_automute_amp(codec);
8717} 8494}
8718 8495
8719static void alc883_haier_w66_init_hook(struct hda_codec *codec) 8496static void alc883_haier_w66_setup(struct hda_codec *codec)
8720{ 8497{
8721 struct alc_spec *spec = codec->spec; 8498 struct alc_spec *spec = codec->spec;
8722 8499
8723 spec->autocfg.hp_pins[0] = 0x1b; 8500 spec->autocfg.hp_pins[0] = 0x1b;
8724 spec->autocfg.speaker_pins[0] = 0x14; 8501 spec->autocfg.speaker_pins[0] = 0x14;
8725 alc_automute_amp(codec);
8726} 8502}
8727 8503
8728static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec) 8504static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
@@ -8761,14 +8537,13 @@ static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8761} 8537}
8762 8538
8763/* toggle speaker-output according to the hp-jack state */ 8539/* toggle speaker-output according to the hp-jack state */
8764static void alc883_acer_aspire_init_hook(struct hda_codec *codec) 8540static void alc883_acer_aspire_setup(struct hda_codec *codec)
8765{ 8541{
8766 struct alc_spec *spec = codec->spec; 8542 struct alc_spec *spec = codec->spec;
8767 8543
8768 spec->autocfg.hp_pins[0] = 0x14; 8544 spec->autocfg.hp_pins[0] = 0x14;
8769 spec->autocfg.speaker_pins[0] = 0x15; 8545 spec->autocfg.speaker_pins[0] = 0x15;
8770 spec->autocfg.speaker_pins[1] = 0x16; 8546 spec->autocfg.speaker_pins[1] = 0x16;
8771 alc_automute_amp(codec);
8772} 8547}
8773 8548
8774static struct hda_verb alc883_acer_eapd_verbs[] = { 8549static struct hda_verb alc883_acer_eapd_verbs[] = {
@@ -8789,7 +8564,14 @@ static struct hda_verb alc883_acer_eapd_verbs[] = {
8789 { } 8564 { }
8790}; 8565};
8791 8566
8792static 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)
8793{ 8575{
8794 struct alc_spec *spec = codec->spec; 8576 struct alc_spec *spec = codec->spec;
8795 8577
@@ -8798,10 +8580,9 @@ static void alc888_6st_dell_init_hook(struct hda_codec *codec)
8798 spec->autocfg.speaker_pins[1] = 0x15; 8580 spec->autocfg.speaker_pins[1] = 0x15;
8799 spec->autocfg.speaker_pins[2] = 0x16; 8581 spec->autocfg.speaker_pins[2] = 0x16;
8800 spec->autocfg.speaker_pins[3] = 0x17; 8582 spec->autocfg.speaker_pins[3] = 0x17;
8801 alc_automute_amp(codec);
8802} 8583}
8803 8584
8804static void alc888_lenovo_sky_init_hook(struct hda_codec *codec) 8585static void alc888_lenovo_sky_setup(struct hda_codec *codec)
8805{ 8586{
8806 struct alc_spec *spec = codec->spec; 8587 struct alc_spec *spec = codec->spec;
8807 8588
@@ -8811,82 +8592,17 @@ static void alc888_lenovo_sky_init_hook(struct hda_codec *codec)
8811 spec->autocfg.speaker_pins[2] = 0x16; 8592 spec->autocfg.speaker_pins[2] = 0x16;
8812 spec->autocfg.speaker_pins[3] = 0x17; 8593 spec->autocfg.speaker_pins[3] = 0x17;
8813 spec->autocfg.speaker_pins[4] = 0x1a; 8594 spec->autocfg.speaker_pins[4] = 0x1a;
8814 alc_automute_amp(codec);
8815} 8595}
8816 8596
8817static void alc883_vaiott_init_hook(struct hda_codec *codec) 8597static void alc883_vaiott_setup(struct hda_codec *codec)
8818{ 8598{
8819 struct alc_spec *spec = codec->spec; 8599 struct alc_spec *spec = codec->spec;
8820 8600
8821 spec->autocfg.hp_pins[0] = 0x15; 8601 spec->autocfg.hp_pins[0] = 0x15;
8822 spec->autocfg.speaker_pins[0] = 0x14; 8602 spec->autocfg.speaker_pins[0] = 0x14;
8823 spec->autocfg.speaker_pins[1] = 0x17; 8603 spec->autocfg.speaker_pins[1] = 0x17;
8824 alc_automute_amp(codec);
8825} 8604}
8826 8605
8827/*
8828 * generic initialization of ADC, input mixers and output mixers
8829 */
8830static struct hda_verb alc883_auto_init_verbs[] = {
8831 /*
8832 * Unmute ADC0-2 and set the default input to mic-in
8833 */
8834 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8835 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8836 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8837 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8838
8839 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8840 * mixer widget
8841 * Note: PASD motherboards uses the Line In 2 as the input for
8842 * front panel mic (mic 2)
8843 */
8844 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8845 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8846 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8847 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8848 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8849 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8850
8851 /*
8852 * Set up output mixers (0x0c - 0x0f)
8853 */
8854 /* set vol=0 to output mixers */
8855 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8856 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8857 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8858 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8859 /* set up input amps for analog loopback */
8860 /* Amp Indices: DAC = 0, mixer = 1 */
8861 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8862 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8863 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8864 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8865 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8866 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8867 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8868 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8869 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8870 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8871
8872 /* FIXME: use matrix-type input source selection */
8873 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8874 /* Input mixer1 */
8875 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8876 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8877 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8878 /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8879 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8880 /* Input mixer2 */
8881 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8882 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8883 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8884 /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8885 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8886
8887 { }
8888};
8889
8890static struct hda_verb alc888_asus_m90v_verbs[] = { 8606static struct hda_verb alc888_asus_m90v_verbs[] = {
8891 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8607 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8892 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8608 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
@@ -8897,19 +8613,7 @@ static struct hda_verb alc888_asus_m90v_verbs[] = {
8897 { } /* end */ 8613 { } /* end */
8898}; 8614};
8899 8615
8900static void alc883_nb_mic_automute(struct hda_codec *codec) 8616static void alc883_mode2_setup(struct hda_codec *codec)
8901{
8902 unsigned int present;
8903
8904 present = snd_hda_codec_read(codec, 0x18, 0,
8905 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8906 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8907 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8908 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8909 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8910}
8911
8912static void alc883_M90V_init_hook(struct hda_codec *codec)
8913{ 8617{
8914 struct alc_spec *spec = codec->spec; 8618 struct alc_spec *spec = codec->spec;
8915 8619
@@ -8917,26 +8621,11 @@ static void alc883_M90V_init_hook(struct hda_codec *codec)
8917 spec->autocfg.speaker_pins[0] = 0x14; 8621 spec->autocfg.speaker_pins[0] = 0x14;
8918 spec->autocfg.speaker_pins[1] = 0x15; 8622 spec->autocfg.speaker_pins[1] = 0x15;
8919 spec->autocfg.speaker_pins[2] = 0x16; 8623 spec->autocfg.speaker_pins[2] = 0x16;
8920 alc_automute_pin(codec); 8624 spec->ext_mic.pin = 0x18;
8921} 8625 spec->int_mic.pin = 0x19;
8922 8626 spec->ext_mic.mux_idx = 0;
8923static void alc883_mode2_unsol_event(struct hda_codec *codec, 8627 spec->int_mic.mux_idx = 1;
8924 unsigned int res) 8628 spec->auto_mic = 1;
8925{
8926 switch (res >> 26) {
8927 case ALC880_MIC_EVENT:
8928 alc883_nb_mic_automute(codec);
8929 break;
8930 default:
8931 alc_sku_unsol_event(codec, res);
8932 break;
8933 }
8934}
8935
8936static void alc883_mode2_inithook(struct hda_codec *codec)
8937{
8938 alc883_M90V_init_hook(codec);
8939 alc883_nb_mic_automute(codec);
8940} 8629}
8941 8630
8942static struct hda_verb alc888_asus_eee1601_verbs[] = { 8631static struct hda_verb alc888_asus_eee1601_verbs[] = {
@@ -8997,25 +8686,44 @@ static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
8997 alc889A_mb31_automute(codec); 8686 alc889A_mb31_automute(codec);
8998} 8687}
8999 8688
8689
9000#ifdef CONFIG_SND_HDA_POWER_SAVE 8690#ifdef CONFIG_SND_HDA_POWER_SAVE
9001#define alc883_loopbacks alc880_loopbacks 8691#define alc882_loopbacks alc880_loopbacks
9002#endif 8692#endif
9003 8693
9004/* pcm configuration: identical with ALC880 */ 8694/* pcm configuration: identical with ALC880 */
9005#define alc883_pcm_analog_playback alc880_pcm_analog_playback 8695#define alc882_pcm_analog_playback alc880_pcm_analog_playback
9006#define alc883_pcm_analog_capture alc880_pcm_analog_capture 8696#define alc882_pcm_analog_capture alc880_pcm_analog_capture
9007#define alc883_pcm_analog_alt_capture alc880_pcm_analog_alt_capture 8697#define alc882_pcm_digital_playback alc880_pcm_digital_playback
9008#define alc883_pcm_digital_playback alc880_pcm_digital_playback 8698#define alc882_pcm_digital_capture alc880_pcm_digital_capture
9009#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};
9010 8707
9011/* 8708/*
9012 * configuration and preset 8709 * configuration and preset
9013 */ 8710 */
9014static const char *alc883_models[ALC883_MODEL_LAST] = { 8711static const char *alc882_models[ALC882_MODEL_LAST] = {
9015 [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",
9016 [ALC883_3ST_6ch_DIG] = "3stack-6ch-dig", 8724 [ALC883_3ST_6ch_DIG] = "3stack-6ch-dig",
9017 [ALC883_3ST_6ch] = "3stack-6ch", 8725 [ALC883_3ST_6ch] = "3stack-6ch",
9018 [ALC883_6ST_DIG] = "6stack-dig", 8726 [ALC883_6ST_DIG] = "alc883-6stack-dig",
9019 [ALC883_TARGA_DIG] = "targa-dig", 8727 [ALC883_TARGA_DIG] = "targa-dig",
9020 [ALC883_TARGA_2ch_DIG] = "targa-2ch-dig", 8728 [ALC883_TARGA_2ch_DIG] = "targa-2ch-dig",
9021 [ALC883_TARGA_8ch_DIG] = "targa-8ch-dig", 8729 [ALC883_TARGA_8ch_DIG] = "targa-8ch-dig",
@@ -9024,6 +8732,7 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
9024 [ALC888_ACER_ASPIRE_4930G] = "acer-aspire-4930g", 8732 [ALC888_ACER_ASPIRE_4930G] = "acer-aspire-4930g",
9025 [ALC888_ACER_ASPIRE_6530G] = "acer-aspire-6530g", 8733 [ALC888_ACER_ASPIRE_6530G] = "acer-aspire-6530g",
9026 [ALC888_ACER_ASPIRE_8930G] = "acer-aspire-8930g", 8734 [ALC888_ACER_ASPIRE_8930G] = "acer-aspire-8930g",
8735 [ALC888_ACER_ASPIRE_7730G] = "acer-aspire-7730g",
9027 [ALC883_MEDION] = "medion", 8736 [ALC883_MEDION] = "medion",
9028 [ALC883_MEDION_MD2] = "medion-md2", 8737 [ALC883_MEDION_MD2] = "medion-md2",
9029 [ALC883_LAPTOP_EAPD] = "laptop-eapd", 8738 [ALC883_LAPTOP_EAPD] = "laptop-eapd",
@@ -9035,18 +8744,22 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
9035 [ALC888_3ST_HP] = "3stack-hp", 8744 [ALC888_3ST_HP] = "3stack-hp",
9036 [ALC888_6ST_DELL] = "6stack-dell", 8745 [ALC888_6ST_DELL] = "6stack-dell",
9037 [ALC883_MITAC] = "mitac", 8746 [ALC883_MITAC] = "mitac",
8747 [ALC883_CLEVO_M540R] = "clevo-m540r",
9038 [ALC883_CLEVO_M720] = "clevo-m720", 8748 [ALC883_CLEVO_M720] = "clevo-m720",
9039 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515", 8749 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
9040 [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530", 8750 [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
9041 [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",
9042 [ALC1200_ASUS_P5Q] = "asus-p5q", 8754 [ALC1200_ASUS_P5Q] = "asus-p5q",
9043 [ALC889A_MB31] = "mb31", 8755 [ALC889A_MB31] = "mb31",
9044 [ALC883_SONY_VAIO_TT] = "sony-vaio-tt", 8756 [ALC883_SONY_VAIO_TT] = "sony-vaio-tt",
9045 [ALC883_AUTO] = "auto", 8757 [ALC882_AUTO] = "auto",
9046}; 8758};
9047 8759
9048static struct snd_pci_quirk alc883_cfg_tbl[] = { 8760static struct snd_pci_quirk alc882_cfg_tbl[] = {
9049 SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG), 8761 SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
8762
9050 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE), 8763 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
9051 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE), 8764 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
9052 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE), 8765 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
@@ -9061,40 +8774,56 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9061 ALC888_ACER_ASPIRE_8930G), 8774 ALC888_ACER_ASPIRE_8930G),
9062 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G", 8775 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
9063 ALC888_ACER_ASPIRE_8930G), 8776 ALC888_ACER_ASPIRE_8930G),
9064 SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO), 8777 SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
9065 SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO), 8778 SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
9066 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G", 8779 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
9067 ALC888_ACER_ASPIRE_4930G), 8780 ALC888_ACER_ASPIRE_6530G),
9068 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G", 8781 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
9069 ALC888_ACER_ASPIRE_6530G), 8782 ALC888_ACER_ASPIRE_6530G),
8783 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
8784 ALC888_ACER_ASPIRE_7730G),
9070 /* default Acer -- disabled as it causes more problems. 8785 /* default Acer -- disabled as it causes more problems.
9071 * model=auto should work fine now 8786 * model=auto should work fine now
9072 */ 8787 */
9073 /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */ 8788 /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
8789
9074 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL), 8790 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8791
9075 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), 8792 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
9076 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP), 8793 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
9077 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP), 8794 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
9078 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG), 8795 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
9079 SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP), 8796 SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
9080 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),
9081 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),
9082 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),
9083 SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG), 8807 SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
9084 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),
9085 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),
9086 SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG), 8812 SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
9087 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG), 8813 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
9088 SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC), 8814 SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
9089 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC), 8815 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
9090 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD), 8816 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
9091 SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL), 8817 SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
9092 SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch), 8818 SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
9093 SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG), 8819 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
8820
9094 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG), 8821 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
9095 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG), 8822 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
9096 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 */
9097 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),
9098 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG), 8827 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
9099 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG), 8828 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
9100 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG), 8829 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
@@ -9103,6 +8832,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9103 SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG), 8832 SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
9104 SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG), 8833 SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
9105 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),
9106 SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG), 8836 SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
9107 SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG), 8837 SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
9108 SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG), 8838 SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
@@ -9116,11 +8846,15 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9116 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG), 8846 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
9117 SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG), 8847 SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
9118 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
9119 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG), 8851 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
9120 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720), 8852 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
9121 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),
9122 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD), 8855 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
9123 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), */
9124 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION), 8858 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
9125 SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx", 8859 SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
9126 ALC883_FUJITSU_PI2515), 8860 ALC883_FUJITSU_PI2515),
@@ -9135,24 +8869,186 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9135 SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG), 8869 SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
9136 SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG), 8870 SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
9137 SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66), 8871 SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8872
9138 SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL), 8873 SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
9139 SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL), 8874 SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
9140 SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC), 8875 SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
9141 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),
9142 SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch), 8879 SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
9143 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
9144 {}
9145};
9146 8880
9147static hda_nid_t alc883_slave_dig_outs[] = { 8881 {}
9148 ALC1200_DIGOUT_NID, 0,
9149}; 8882};
9150 8883
9151static hda_nid_t alc1200_slave_dig_outs[] = { 8884/* codec SSID table for Intel Mac */
9152 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 */
9153}; 8902};
9154 8903
9155static 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 },
9156 [ALC883_3ST_2ch_DIG] = { 9052 [ALC883_3ST_2ch_DIG] = {
9157 .mixers = { alc883_3ST_2ch_mixer }, 9053 .mixers = { alc883_3ST_2ch_mixer },
9158 .init_verbs = { alc883_init_verbs }, 9054 .init_verbs = { alc883_init_verbs },
@@ -9199,6 +9095,46 @@ static struct alc_config_preset alc883_presets[] = {
9199 .need_dac_fix = 1, 9095 .need_dac_fix = 1,
9200 .input_mux = &alc883_3stack_6ch_intel, 9096 .input_mux = &alc883_3stack_6ch_intel,
9201 }, 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 },
9202 [ALC883_6ST_DIG] = { 9138 [ALC883_6ST_DIG] = {
9203 .mixers = { alc883_base_mixer, alc883_chmode_mixer }, 9139 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9204 .init_verbs = { alc883_init_verbs }, 9140 .init_verbs = { alc883_init_verbs },
@@ -9212,7 +9148,8 @@ static struct alc_config_preset alc883_presets[] = {
9212 }, 9148 },
9213 [ALC883_TARGA_DIG] = { 9149 [ALC883_TARGA_DIG] = {
9214 .mixers = { alc883_targa_mixer, alc883_chmode_mixer }, 9150 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9215 .init_verbs = { alc883_init_verbs, alc883_targa_verbs}, 9151 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9152 alc883_targa_verbs},
9216 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9153 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9217 .dac_nids = alc883_dac_nids, 9154 .dac_nids = alc883_dac_nids,
9218 .dig_out_nid = ALC883_DIGOUT_NID, 9155 .dig_out_nid = ALC883_DIGOUT_NID,
@@ -9221,11 +9158,13 @@ static struct alc_config_preset alc883_presets[] = {
9221 .need_dac_fix = 1, 9158 .need_dac_fix = 1,
9222 .input_mux = &alc883_capture_source, 9159 .input_mux = &alc883_capture_source,
9223 .unsol_event = alc883_targa_unsol_event, 9160 .unsol_event = alc883_targa_unsol_event,
9224 .init_hook = alc883_targa_init_hook, 9161 .setup = alc882_targa_setup,
9162 .init_hook = alc882_targa_automute,
9225 }, 9163 },
9226 [ALC883_TARGA_2ch_DIG] = { 9164 [ALC883_TARGA_2ch_DIG] = {
9227 .mixers = { alc883_targa_2ch_mixer}, 9165 .mixers = { alc883_targa_2ch_mixer},
9228 .init_verbs = { alc883_init_verbs, alc883_targa_verbs}, 9166 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9167 alc883_targa_verbs},
9229 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9168 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9230 .dac_nids = alc883_dac_nids, 9169 .dac_nids = alc883_dac_nids,
9231 .adc_nids = alc883_adc_nids_alt, 9170 .adc_nids = alc883_adc_nids_alt,
@@ -9235,10 +9174,12 @@ static struct alc_config_preset alc883_presets[] = {
9235 .channel_mode = alc883_3ST_2ch_modes, 9174 .channel_mode = alc883_3ST_2ch_modes,
9236 .input_mux = &alc883_capture_source, 9175 .input_mux = &alc883_capture_source,
9237 .unsol_event = alc883_targa_unsol_event, 9176 .unsol_event = alc883_targa_unsol_event,
9238 .init_hook = alc883_targa_init_hook, 9177 .setup = alc882_targa_setup,
9178 .init_hook = alc882_targa_automute,
9239 }, 9179 },
9240 [ALC883_TARGA_8ch_DIG] = { 9180 [ALC883_TARGA_8ch_DIG] = {
9241 .mixers = { alc883_base_mixer, alc883_chmode_mixer }, 9181 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
9182 alc883_chmode_mixer },
9242 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs, 9183 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9243 alc883_targa_verbs }, 9184 alc883_targa_verbs },
9244 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9185 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
@@ -9253,7 +9194,8 @@ static struct alc_config_preset alc883_presets[] = {
9253 .need_dac_fix = 1, 9194 .need_dac_fix = 1,
9254 .input_mux = &alc883_capture_source, 9195 .input_mux = &alc883_capture_source,
9255 .unsol_event = alc883_targa_unsol_event, 9196 .unsol_event = alc883_targa_unsol_event,
9256 .init_hook = alc883_targa_init_hook, 9197 .setup = alc882_targa_setup,
9198 .init_hook = alc882_targa_automute,
9257 }, 9199 },
9258 [ALC883_ACER] = { 9200 [ALC883_ACER] = {
9259 .mixers = { alc883_base_mixer }, 9201 .mixers = { alc883_base_mixer },
@@ -9279,7 +9221,8 @@ static struct alc_config_preset alc883_presets[] = {
9279 .channel_mode = alc883_3ST_2ch_modes, 9221 .channel_mode = alc883_3ST_2ch_modes,
9280 .input_mux = &alc883_capture_source, 9222 .input_mux = &alc883_capture_source,
9281 .unsol_event = alc_automute_amp_unsol_event, 9223 .unsol_event = alc_automute_amp_unsol_event,
9282 .init_hook = alc883_acer_aspire_init_hook, 9224 .setup = alc883_acer_aspire_setup,
9225 .init_hook = alc_automute_amp,
9283 }, 9226 },
9284 [ALC888_ACER_ASPIRE_4930G] = { 9227 [ALC888_ACER_ASPIRE_4930G] = {
9285 .mixers = { alc888_base_mixer, 9228 .mixers = { alc888_base_mixer,
@@ -9299,7 +9242,8 @@ static struct alc_config_preset alc883_presets[] = {
9299 ARRAY_SIZE(alc888_2_capture_sources), 9242 ARRAY_SIZE(alc888_2_capture_sources),
9300 .input_mux = alc888_2_capture_sources, 9243 .input_mux = alc888_2_capture_sources,
9301 .unsol_event = alc_automute_amp_unsol_event, 9244 .unsol_event = alc_automute_amp_unsol_event,
9302 .init_hook = alc888_acer_aspire_4930g_init_hook, 9245 .setup = alc888_acer_aspire_4930g_setup,
9246 .init_hook = alc_automute_amp,
9303 }, 9247 },
9304 [ALC888_ACER_ASPIRE_6530G] = { 9248 [ALC888_ACER_ASPIRE_6530G] = {
9305 .mixers = { alc888_acer_aspire_6530_mixer }, 9249 .mixers = { alc888_acer_aspire_6530_mixer },
@@ -9317,7 +9261,8 @@ static struct alc_config_preset alc883_presets[] = {
9317 ARRAY_SIZE(alc888_2_capture_sources), 9261 ARRAY_SIZE(alc888_2_capture_sources),
9318 .input_mux = alc888_acer_aspire_6530_sources, 9262 .input_mux = alc888_acer_aspire_6530_sources,
9319 .unsol_event = alc_automute_amp_unsol_event, 9263 .unsol_event = alc_automute_amp_unsol_event,
9320 .init_hook = alc888_acer_aspire_4930g_init_hook, 9264 .setup = alc888_acer_aspire_6530g_setup,
9265 .init_hook = alc_automute_amp,
9321 }, 9266 },
9322 [ALC888_ACER_ASPIRE_8930G] = { 9267 [ALC888_ACER_ASPIRE_8930G] = {
9323 .mixers = { alc888_base_mixer, 9268 .mixers = { alc888_base_mixer,
@@ -9338,7 +9283,28 @@ static struct alc_config_preset alc883_presets[] = {
9338 ARRAY_SIZE(alc889_capture_sources), 9283 ARRAY_SIZE(alc889_capture_sources),
9339 .input_mux = alc889_capture_sources, 9284 .input_mux = alc889_capture_sources,
9340 .unsol_event = alc_automute_amp_unsol_event, 9285 .unsol_event = alc_automute_amp_unsol_event,
9341 .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,
9342 }, 9308 },
9343 [ALC883_MEDION] = { 9309 [ALC883_MEDION] = {
9344 .mixers = { alc883_fivestack_mixer, 9310 .mixers = { alc883_fivestack_mixer,
@@ -9363,7 +9329,8 @@ static struct alc_config_preset alc883_presets[] = {
9363 .channel_mode = alc883_3ST_2ch_modes, 9329 .channel_mode = alc883_3ST_2ch_modes,
9364 .input_mux = &alc883_capture_source, 9330 .input_mux = &alc883_capture_source,
9365 .unsol_event = alc_automute_amp_unsol_event, 9331 .unsol_event = alc_automute_amp_unsol_event,
9366 .init_hook = alc883_medion_md2_init_hook, 9332 .setup = alc883_medion_md2_setup,
9333 .init_hook = alc_automute_amp,
9367 }, 9334 },
9368 [ALC883_LAPTOP_EAPD] = { 9335 [ALC883_LAPTOP_EAPD] = {
9369 .mixers = { alc883_base_mixer }, 9336 .mixers = { alc883_base_mixer },
@@ -9374,6 +9341,21 @@ static struct alc_config_preset alc883_presets[] = {
9374 .channel_mode = alc883_3ST_2ch_modes, 9341 .channel_mode = alc883_3ST_2ch_modes,
9375 .input_mux = &alc883_capture_source, 9342 .input_mux = &alc883_capture_source,
9376 }, 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 },
9377 [ALC883_CLEVO_M720] = { 9359 [ALC883_CLEVO_M720] = {
9378 .mixers = { alc883_clevo_m720_mixer }, 9360 .mixers = { alc883_clevo_m720_mixer },
9379 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs }, 9361 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
@@ -9384,6 +9366,7 @@ static struct alc_config_preset alc883_presets[] = {
9384 .channel_mode = alc883_3ST_2ch_modes, 9366 .channel_mode = alc883_3ST_2ch_modes,
9385 .input_mux = &alc883_capture_source, 9367 .input_mux = &alc883_capture_source,
9386 .unsol_event = alc883_clevo_m720_unsol_event, 9368 .unsol_event = alc883_clevo_m720_unsol_event,
9369 .setup = alc883_clevo_m720_setup,
9387 .init_hook = alc883_clevo_m720_init_hook, 9370 .init_hook = alc883_clevo_m720_init_hook,
9388 }, 9371 },
9389 [ALC883_LENOVO_101E_2ch] = { 9372 [ALC883_LENOVO_101E_2ch] = {
@@ -9409,7 +9392,8 @@ static struct alc_config_preset alc883_presets[] = {
9409 .need_dac_fix = 1, 9392 .need_dac_fix = 1,
9410 .input_mux = &alc883_lenovo_nb0763_capture_source, 9393 .input_mux = &alc883_lenovo_nb0763_capture_source,
9411 .unsol_event = alc_automute_amp_unsol_event, 9394 .unsol_event = alc_automute_amp_unsol_event,
9412 .init_hook = alc883_medion_md2_init_hook, 9395 .setup = alc883_medion_md2_setup,
9396 .init_hook = alc_automute_amp,
9413 }, 9397 },
9414 [ALC888_LENOVO_MS7195_DIG] = { 9398 [ALC888_LENOVO_MS7195_DIG] = {
9415 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer }, 9399 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
@@ -9434,7 +9418,8 @@ static struct alc_config_preset alc883_presets[] = {
9434 .channel_mode = alc883_3ST_2ch_modes, 9418 .channel_mode = alc883_3ST_2ch_modes,
9435 .input_mux = &alc883_capture_source, 9419 .input_mux = &alc883_capture_source,
9436 .unsol_event = alc_automute_amp_unsol_event, 9420 .unsol_event = alc_automute_amp_unsol_event,
9437 .init_hook = alc883_haier_w66_init_hook, 9421 .setup = alc883_haier_w66_setup,
9422 .init_hook = alc_automute_amp,
9438 }, 9423 },
9439 [ALC888_3ST_HP] = { 9424 [ALC888_3ST_HP] = {
9440 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer }, 9425 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
@@ -9446,7 +9431,8 @@ static struct alc_config_preset alc883_presets[] = {
9446 .need_dac_fix = 1, 9431 .need_dac_fix = 1,
9447 .input_mux = &alc883_capture_source, 9432 .input_mux = &alc883_capture_source,
9448 .unsol_event = alc_automute_amp_unsol_event, 9433 .unsol_event = alc_automute_amp_unsol_event,
9449 .init_hook = alc888_3st_hp_init_hook, 9434 .setup = alc888_3st_hp_setup,
9435 .init_hook = alc_automute_amp,
9450 }, 9436 },
9451 [ALC888_6ST_DELL] = { 9437 [ALC888_6ST_DELL] = {
9452 .mixers = { alc883_base_mixer, alc883_chmode_mixer }, 9438 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
@@ -9459,7 +9445,8 @@ static struct alc_config_preset alc883_presets[] = {
9459 .channel_mode = alc883_sixstack_modes, 9445 .channel_mode = alc883_sixstack_modes,
9460 .input_mux = &alc883_capture_source, 9446 .input_mux = &alc883_capture_source,
9461 .unsol_event = alc_automute_amp_unsol_event, 9447 .unsol_event = alc_automute_amp_unsol_event,
9462 .init_hook = alc888_6st_dell_init_hook, 9448 .setup = alc888_6st_dell_setup,
9449 .init_hook = alc_automute_amp,
9463 }, 9450 },
9464 [ALC883_MITAC] = { 9451 [ALC883_MITAC] = {
9465 .mixers = { alc883_mitac_mixer }, 9452 .mixers = { alc883_mitac_mixer },
@@ -9470,7 +9457,8 @@ static struct alc_config_preset alc883_presets[] = {
9470 .channel_mode = alc883_3ST_2ch_modes, 9457 .channel_mode = alc883_3ST_2ch_modes,
9471 .input_mux = &alc883_capture_source, 9458 .input_mux = &alc883_capture_source,
9472 .unsol_event = alc_automute_amp_unsol_event, 9459 .unsol_event = alc_automute_amp_unsol_event,
9473 .init_hook = alc883_mitac_init_hook, 9460 .setup = alc883_mitac_setup,
9461 .init_hook = alc_automute_amp,
9474 }, 9462 },
9475 [ALC883_FUJITSU_PI2515] = { 9463 [ALC883_FUJITSU_PI2515] = {
9476 .mixers = { alc883_2ch_fujitsu_pi2515_mixer }, 9464 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
@@ -9483,7 +9471,8 @@ static struct alc_config_preset alc883_presets[] = {
9483 .channel_mode = alc883_3ST_2ch_modes, 9471 .channel_mode = alc883_3ST_2ch_modes,
9484 .input_mux = &alc883_fujitsu_pi2515_capture_source, 9472 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9485 .unsol_event = alc_automute_amp_unsol_event, 9473 .unsol_event = alc_automute_amp_unsol_event,
9486 .init_hook = alc883_2ch_fujitsu_pi2515_init_hook, 9474 .setup = alc883_2ch_fujitsu_pi2515_setup,
9475 .init_hook = alc_automute_amp,
9487 }, 9476 },
9488 [ALC888_FUJITSU_XA3530] = { 9477 [ALC888_FUJITSU_XA3530] = {
9489 .mixers = { alc888_base_mixer, alc883_chmode_mixer }, 9478 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
@@ -9501,7 +9490,8 @@ static struct alc_config_preset alc883_presets[] = {
9501 ARRAY_SIZE(alc888_2_capture_sources), 9490 ARRAY_SIZE(alc888_2_capture_sources),
9502 .input_mux = alc888_2_capture_sources, 9491 .input_mux = alc888_2_capture_sources,
9503 .unsol_event = alc_automute_amp_unsol_event, 9492 .unsol_event = alc_automute_amp_unsol_event,
9504 .init_hook = alc888_fujitsu_xa3530_init_hook, 9493 .setup = alc888_fujitsu_xa3530_setup,
9494 .init_hook = alc_automute_amp,
9505 }, 9495 },
9506 [ALC888_LENOVO_SKY] = { 9496 [ALC888_LENOVO_SKY] = {
9507 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer }, 9497 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
@@ -9514,7 +9504,8 @@ static struct alc_config_preset alc883_presets[] = {
9514 .need_dac_fix = 1, 9504 .need_dac_fix = 1,
9515 .input_mux = &alc883_lenovo_sky_capture_source, 9505 .input_mux = &alc883_lenovo_sky_capture_source,
9516 .unsol_event = alc_automute_amp_unsol_event, 9506 .unsol_event = alc_automute_amp_unsol_event,
9517 .init_hook = alc888_lenovo_sky_init_hook, 9507 .setup = alc888_lenovo_sky_setup,
9508 .init_hook = alc_automute_amp,
9518 }, 9509 },
9519 [ALC888_ASUS_M90V] = { 9510 [ALC888_ASUS_M90V] = {
9520 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer }, 9511 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
@@ -9527,8 +9518,9 @@ static struct alc_config_preset alc883_presets[] = {
9527 .channel_mode = alc883_3ST_6ch_modes, 9518 .channel_mode = alc883_3ST_6ch_modes,
9528 .need_dac_fix = 1, 9519 .need_dac_fix = 1,
9529 .input_mux = &alc883_fujitsu_pi2515_capture_source, 9520 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9530 .unsol_event = alc883_mode2_unsol_event, 9521 .unsol_event = alc_sku_unsol_event,
9531 .init_hook = alc883_mode2_inithook, 9522 .setup = alc883_mode2_setup,
9523 .init_hook = alc_inithook,
9532 }, 9524 },
9533 [ALC888_ASUS_EEE1601] = { 9525 [ALC888_ASUS_EEE1601] = {
9534 .mixers = { alc883_asus_eee1601_mixer }, 9526 .mixers = { alc883_asus_eee1601_mixer },
@@ -9581,15 +9573,45 @@ static struct alc_config_preset alc883_presets[] = {
9581 .channel_mode = alc883_3ST_2ch_modes, 9573 .channel_mode = alc883_3ST_2ch_modes,
9582 .input_mux = &alc883_capture_source, 9574 .input_mux = &alc883_capture_source,
9583 .unsol_event = alc_automute_amp_unsol_event, 9575 .unsol_event = alc_automute_amp_unsol_event,
9584 .init_hook = alc883_vaiott_init_hook, 9576 .setup = alc883_vaiott_setup,
9577 .init_hook = alc_automute_amp,
9585 }, 9578 },
9586}; 9579};
9587 9580
9588 9581
9589/* 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/*
9590 * BIOS auto configuration 9606 * BIOS auto configuration
9591 */ 9607 */
9592static 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,
9593 hda_nid_t nid, int pin_type, 9615 hda_nid_t nid, int pin_type,
9594 int dac_idx) 9616 int dac_idx)
9595{ 9617{
@@ -9606,7 +9628,7 @@ static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
9606 9628
9607} 9629}
9608 9630
9609static void alc883_auto_init_multi_out(struct hda_codec *codec) 9631static void alc882_auto_init_multi_out(struct hda_codec *codec)
9610{ 9632{
9611 struct alc_spec *spec = codec->spec; 9633 struct alc_spec *spec = codec->spec;
9612 int i; 9634 int i;
@@ -9615,12 +9637,12 @@ static void alc883_auto_init_multi_out(struct hda_codec *codec)
9615 hda_nid_t nid = spec->autocfg.line_out_pins[i]; 9637 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9616 int pin_type = get_pin_type(spec->autocfg.line_out_type); 9638 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9617 if (nid) 9639 if (nid)
9618 alc883_auto_set_output_and_unmute(codec, nid, pin_type, 9640 alc882_auto_set_output_and_unmute(codec, nid, pin_type,
9619 i); 9641 i);
9620 } 9642 }
9621} 9643}
9622 9644
9623static void alc883_auto_init_hp_out(struct hda_codec *codec) 9645static void alc882_auto_init_hp_out(struct hda_codec *codec)
9624{ 9646{
9625 struct alc_spec *spec = codec->spec; 9647 struct alc_spec *spec = codec->spec;
9626 hda_nid_t pin; 9648 hda_nid_t pin;
@@ -9628,91 +9650,191 @@ static void alc883_auto_init_hp_out(struct hda_codec *codec)
9628 pin = spec->autocfg.hp_pins[0]; 9650 pin = spec->autocfg.hp_pins[0];
9629 if (pin) /* connect to front */ 9651 if (pin) /* connect to front */
9630 /* use dac 0 */ 9652 /* use dac 0 */
9631 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 9653 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9632 pin = spec->autocfg.speaker_pins[0]; 9654 pin = spec->autocfg.speaker_pins[0];
9633 if (pin) 9655 if (pin)
9634 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); 9656 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9635} 9657}
9636 9658
9637#define alc883_is_input_pin(nid) alc880_is_input_pin(nid) 9659static void alc882_auto_init_analog_input(struct hda_codec *codec)
9638#define ALC883_PIN_CD_NID ALC880_PIN_CD_NID
9639
9640static void alc883_auto_init_analog_input(struct hda_codec *codec)
9641{ 9660{
9642 struct alc_spec *spec = codec->spec; 9661 struct alc_spec *spec = codec->spec;
9643 int i; 9662 int i;
9644 9663
9645 for (i = 0; i < AUTO_PIN_LAST; i++) { 9664 for (i = 0; i < AUTO_PIN_LAST; i++) {
9646 hda_nid_t nid = spec->autocfg.input_pins[i]; 9665 hda_nid_t nid = spec->autocfg.input_pins[i];
9647 if (alc883_is_input_pin(nid)) { 9666 if (!nid)
9648 alc_set_input_pin(codec, nid, i); 9667 continue;
9649 if (nid != ALC883_PIN_CD_NID && 9668 alc_set_input_pin(codec, nid, i);
9650 (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)
9651 snd_hda_codec_write(codec, nid, 0, 9713 snd_hda_codec_write(codec, nid, 0,
9652 AC_VERB_SET_AMP_GAIN_MUTE, 9714 AC_VERB_SET_AMP_GAIN_MUTE,
9653 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);
9654 } 9720 }
9655 } 9721 }
9656} 9722}
9657 9723
9658#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}
9659 9749
9660/* almost identical with ALC880 parser... */ 9750/* almost identical with ALC880 parser... */
9661static int alc883_parse_auto_config(struct hda_codec *codec) 9751static int alc882_parse_auto_config(struct hda_codec *codec)
9662{ 9752{
9663 struct alc_spec *spec = codec->spec; 9753 struct alc_spec *spec = codec->spec;
9664 int err = alc880_parse_auto_config(codec); 9754 static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
9665 struct auto_pin_cfg *cfg = &spec->autocfg; 9755 int i, err;
9666 int i;
9667 9756
9757 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9758 alc882_ignore);
9668 if (err < 0) 9759 if (err < 0)
9669 return err; 9760 return err;
9670 else if (!err) 9761 if (!spec->autocfg.line_outs)
9671 return 0; /* no config found */ 9762 return 0; /* can't find valid BIOS pin config */
9672 9763
9673 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);
9674 if (err < 0) 9780 if (err < 0)
9675 return err; 9781 return err;
9676 9782
9677 /* hack - override the init verbs */ 9783 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9678 spec->init_verbs[0] = alc883_auto_init_verbs;
9679 9784
9680 /* setup input_mux for ALC889 */ 9785 /* check multiple SPDIF-out (for recent codecs) */
9681 if (codec->vendor_id == 0x10ec0889) { 9786 for (i = 0; i < spec->autocfg.dig_outs; i++) {
9682 /* digital-mic input pin is excluded in alc880_auto_create..() 9787 hda_nid_t dig_nid;
9683 * because it's under 0x18 9788 err = snd_hda_get_connections(codec,
9684 */ 9789 spec->autocfg.dig_out_pins[i],
9685 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 || 9790 &dig_nid, 1);
9686 cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) { 9791 if (err < 0)
9687 struct hda_input_mux *imux = &spec->private_imux[0]; 9792 continue;
9688 for (i = 1; i < 3; i++) 9793 if (!i)
9689 memcpy(&spec->private_imux[i], 9794 spec->multiout.dig_out_nid = dig_nid;
9690 &spec->private_imux[0], 9795 else {
9691 sizeof(spec->private_imux[0])); 9796 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9692 imux->items[imux->num_items].label = "Int DMic"; 9797 spec->slave_dig_outs[i - 1] = dig_nid;
9693 imux->items[imux->num_items].index = 0x0b; 9798 if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
9694 imux->num_items++; 9799 break;
9695 spec->num_mux_defs = 3;
9696 spec->input_mux = spec->private_imux;
9697 } 9800 }
9698 } 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;
9699 9821
9700 return 1; /* config found */ 9822 return 1; /* config found */
9701} 9823}
9702 9824
9703/* additional initialization for auto-configuration model */ 9825/* additional initialization for auto-configuration model */
9704static void alc883_auto_init(struct hda_codec *codec) 9826static void alc882_auto_init(struct hda_codec *codec)
9705{ 9827{
9706 struct alc_spec *spec = codec->spec; 9828 struct alc_spec *spec = codec->spec;
9707 alc883_auto_init_multi_out(codec); 9829 alc882_auto_init_multi_out(codec);
9708 alc883_auto_init_hp_out(codec); 9830 alc882_auto_init_hp_out(codec);
9709 alc883_auto_init_analog_input(codec); 9831 alc882_auto_init_analog_input(codec);
9710 alc883_auto_init_input_src(codec); 9832 alc882_auto_init_input_src(codec);
9711 if (spec->unsol_event) 9833 if (spec->unsol_event)
9712 alc_inithook(codec); 9834 alc_inithook(codec);
9713} 9835}
9714 9836
9715static int patch_alc883(struct hda_codec *codec) 9837static int patch_alc882(struct hda_codec *codec)
9716{ 9838{
9717 struct alc_spec *spec; 9839 struct alc_spec *spec;
9718 int err, board_config; 9840 int err, board_config;
@@ -9723,28 +9845,35 @@ static int patch_alc883(struct hda_codec *codec)
9723 9845
9724 codec->spec = spec; 9846 codec->spec = spec;
9725 9847
9726 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 }
9727 9857
9728 board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST, 9858 board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
9729 alc883_models, 9859 alc882_models,
9730 alc883_cfg_tbl); 9860 alc882_cfg_tbl);
9731 if (board_config < 0 || board_config >= ALC883_MODEL_LAST) { 9861
9732 /* Pick up systems that don't supply PCI SSID */ 9862 if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
9733 switch (codec->subsystem_id) { 9863 board_config = snd_hda_check_board_codec_sid_config(codec,
9734 case 0x106b3600: /* Macbook 3.1 */ 9864 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
9735 board_config = ALC889A_MB31; 9865
9736 break; 9866 if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9737 default: 9867 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
9738 printk(KERN_INFO 9868 codec->chip_name);
9739 "hda_codec: Unknown model for %s, trying " 9869 board_config = ALC882_AUTO;
9740 "auto-probe from BIOS...\n", codec->chip_name);
9741 board_config = ALC883_AUTO;
9742 }
9743 } 9870 }
9744 9871
9745 if (board_config == ALC883_AUTO) { 9872 alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
9873
9874 if (board_config == ALC882_AUTO) {
9746 /* automatic parse from the BIOS config */ 9875 /* automatic parse from the BIOS config */
9747 err = alc883_parse_auto_config(codec); 9876 err = alc882_parse_auto_config(codec);
9748 if (err < 0) { 9877 if (err < 0) {
9749 alc_free(codec); 9878 alc_free(codec);
9750 return err; 9879 return err;
@@ -9752,7 +9881,7 @@ static int patch_alc883(struct hda_codec *codec)
9752 printk(KERN_INFO 9881 printk(KERN_INFO
9753 "hda_codec: Cannot set up configuration " 9882 "hda_codec: Cannot set up configuration "
9754 "from BIOS. Using base mode...\n"); 9883 "from BIOS. Using base mode...\n");
9755 board_config = ALC883_3ST_2ch_DIG; 9884 board_config = ALC882_3ST_DIG;
9756 } 9885 }
9757 } 9886 }
9758 9887
@@ -9762,63 +9891,61 @@ static int patch_alc883(struct hda_codec *codec)
9762 return err; 9891 return err;
9763 } 9892 }
9764 9893
9765 if (board_config != ALC883_AUTO) 9894 if (board_config != ALC882_AUTO)
9766 setup_preset(spec, &alc883_presets[board_config]); 9895 setup_preset(codec, &alc882_presets[board_config]);
9767 9896
9768 switch (codec->vendor_id) { 9897 spec->stream_analog_playback = &alc882_pcm_analog_playback;
9769 case 0x10ec0888: 9898 spec->stream_analog_capture = &alc882_pcm_analog_capture;
9770 if (!spec->num_adc_nids) { 9899 /* FIXME: setup DAC5 */
9771 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids); 9900 /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
9772 spec->adc_nids = alc883_adc_nids; 9901 spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
9773 } 9902
9774 if (!spec->capsrc_nids) 9903 spec->stream_digital_playback = &alc882_pcm_digital_playback;
9775 spec->capsrc_nids = alc883_capsrc_nids; 9904 spec->stream_digital_capture = &alc882_pcm_digital_capture;
9905
9906 if (codec->vendor_id == 0x10ec0888)
9776 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */ 9907 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9777 break; 9908
9778 case 0x10ec0889: 9909 if (!spec->adc_nids && spec->input_mux) {
9779 if (!spec->num_adc_nids) { 9910 int i;
9780 spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids); 9911 spec->num_adc_nids = 0;
9781 spec->adc_nids = alc889_adc_nids; 9912 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
9782 } 9913 hda_nid_t cap;
9783 if (!spec->capsrc_nids) 9914 hda_nid_t nid = alc882_adc_nids[i];
9784 spec->capsrc_nids = alc889_capsrc_nids; 9915 unsigned int wcap = get_wcaps(codec, nid);
9785 break; 9916 /* get type */
9786 default: 9917 wcap = get_wcaps_type(wcap);
9787 if (!spec->num_adc_nids) { 9918 if (wcap != AC_WID_AUD_IN)
9788 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids); 9919 continue;
9789 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++;
9790 } 9926 }
9791 if (!spec->capsrc_nids) 9927 spec->adc_nids = spec->private_adc_nids;
9792 spec->capsrc_nids = alc883_capsrc_nids; 9928 spec->capsrc_nids = spec->private_capsrc_nids;
9793 break;
9794 } 9929 }
9795 9930
9796 spec->stream_analog_playback = &alc883_pcm_analog_playback; 9931 set_capture_mixer(codec);
9797 spec->stream_analog_capture = &alc883_pcm_analog_capture;
9798 spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9799
9800 spec->stream_digital_playback = &alc883_pcm_digital_playback;
9801 spec->stream_digital_capture = &alc883_pcm_digital_capture;
9802
9803 if (!spec->cap_mixer)
9804 set_capture_mixer(spec);
9805 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 9932 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9806 9933
9807 spec->vmaster_nid = 0x0c; 9934 spec->vmaster_nid = 0x0c;
9808 9935
9809 codec->patch_ops = alc_patch_ops; 9936 codec->patch_ops = alc_patch_ops;
9810 if (board_config == ALC883_AUTO) 9937 if (board_config == ALC882_AUTO)
9811 spec->init_hook = alc883_auto_init; 9938 spec->init_hook = alc882_auto_init;
9812
9813#ifdef CONFIG_SND_HDA_POWER_SAVE 9939#ifdef CONFIG_SND_HDA_POWER_SAVE
9814 if (!spec->loopback.amplist) 9940 if (!spec->loopback.amplist)
9815 spec->loopback.amplist = alc883_loopbacks; 9941 spec->loopback.amplist = alc882_loopbacks;
9816#endif 9942#endif
9817 codec->proc_widget_hook = print_realtek_coef; 9943 codec->proc_widget_hook = print_realtek_coef;
9818 9944
9819 return 0; 9945 return 0;
9820} 9946}
9821 9947
9948
9822/* 9949/*
9823 * ALC262 support 9950 * ALC262 support
9824 */ 9951 */
@@ -9994,13 +10121,12 @@ static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9994}; 10121};
9995 10122
9996/* 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 */
9997static void alc262_hp_t5735_init_hook(struct hda_codec *codec) 10124static void alc262_hp_t5735_setup(struct hda_codec *codec)
9998{ 10125{
9999 struct alc_spec *spec = codec->spec; 10126 struct alc_spec *spec = codec->spec;
10000 10127
10001 spec->autocfg.hp_pins[0] = 0x15; 10128 spec->autocfg.hp_pins[0] = 0x15;
10002 spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */ 10129 spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10003 alc_automute_amp(codec);
10004} 10130}
10005 10131
10006static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = { 10132static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
@@ -10157,22 +10283,20 @@ static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10157 alc262_hippo_automute(codec); 10283 alc262_hippo_automute(codec);
10158} 10284}
10159 10285
10160static void alc262_hippo_init_hook(struct hda_codec *codec) 10286static void alc262_hippo_setup(struct hda_codec *codec)
10161{ 10287{
10162 struct alc_spec *spec = codec->spec; 10288 struct alc_spec *spec = codec->spec;
10163 10289
10164 spec->autocfg.hp_pins[0] = 0x15; 10290 spec->autocfg.hp_pins[0] = 0x15;
10165 spec->autocfg.speaker_pins[0] = 0x14; 10291 spec->autocfg.speaker_pins[0] = 0x14;
10166 alc262_hippo_automute(codec);
10167} 10292}
10168 10293
10169static void alc262_hippo1_init_hook(struct hda_codec *codec) 10294static void alc262_hippo1_setup(struct hda_codec *codec)
10170{ 10295{
10171 struct alc_spec *spec = codec->spec; 10296 struct alc_spec *spec = codec->spec;
10172 10297
10173 spec->autocfg.hp_pins[0] = 0x1b; 10298 spec->autocfg.hp_pins[0] = 0x1b;
10174 spec->autocfg.speaker_pins[0] = 0x14; 10299 spec->autocfg.speaker_pins[0] = 0x14;
10175 alc262_hippo_automute(codec);
10176} 10300}
10177 10301
10178 10302
@@ -10229,13 +10353,12 @@ static struct hda_verb alc262_tyan_verbs[] = {
10229}; 10353};
10230 10354
10231/* unsolicited event for HP jack sensing */ 10355/* unsolicited event for HP jack sensing */
10232static void alc262_tyan_init_hook(struct hda_codec *codec) 10356static void alc262_tyan_setup(struct hda_codec *codec)
10233{ 10357{
10234 struct alc_spec *spec = codec->spec; 10358 struct alc_spec *spec = codec->spec;
10235 10359
10236 spec->autocfg.hp_pins[0] = 0x1b; 10360 spec->autocfg.hp_pins[0] = 0x1b;
10237 spec->autocfg.speaker_pins[0] = 0x15; 10361 spec->autocfg.speaker_pins[0] = 0x15;
10238 alc_automute_amp(codec);
10239} 10362}
10240 10363
10241 10364
@@ -10327,12 +10450,6 @@ static struct hda_verb alc262_eapd_verbs[] = {
10327 { } 10450 { }
10328}; 10451};
10329 10452
10330static struct hda_verb alc262_hippo_unsol_verbs[] = {
10331 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10332 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10333 {}
10334};
10335
10336static struct hda_verb alc262_hippo1_unsol_verbs[] = { 10453static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10337 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0}, 10454 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10338 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 10455 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -10353,14 +10470,6 @@ static struct hda_verb alc262_sony_unsol_verbs[] = {
10353 {} 10470 {}
10354}; 10471};
10355 10472
10356static struct hda_input_mux alc262_dmic_capture_source = {
10357 .num_items = 2,
10358 .items = {
10359 { "Int DMic", 0x9 },
10360 { "Mic", 0x0 },
10361 },
10362};
10363
10364static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = { 10473static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10365 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 10474 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10366 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), 10475 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
@@ -10382,35 +10491,17 @@ static struct hda_verb alc262_toshiba_s06_verbs[] = {
10382 {} 10491 {}
10383}; 10492};
10384 10493
10385static void alc262_dmic_automute(struct hda_codec *codec) 10494static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10386{
10387 unsigned int present;
10388
10389 present = snd_hda_codec_read(codec, 0x18, 0,
10390 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10391 snd_hda_codec_write(codec, 0x22, 0,
10392 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
10393}
10394
10395
10396/* unsolicited event for HP jack sensing */
10397static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
10398 unsigned int res)
10399{
10400 if ((res >> 26) == ALC880_MIC_EVENT)
10401 alc262_dmic_automute(codec);
10402 else
10403 alc_sku_unsol_event(codec, res);
10404}
10405
10406static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
10407{ 10495{
10408 struct alc_spec *spec = codec->spec; 10496 struct alc_spec *spec = codec->spec;
10409 10497
10410 spec->autocfg.hp_pins[0] = 0x15; 10498 spec->autocfg.hp_pins[0] = 0x15;
10411 spec->autocfg.speaker_pins[0] = 0x14; 10499 spec->autocfg.speaker_pins[0] = 0x14;
10412 alc_automute_pin(codec); 10500 spec->ext_mic.pin = 0x18;
10413 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;
10414} 10505}
10415 10506
10416/* 10507/*
@@ -10599,6 +10690,18 @@ static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10599 alc262_lenovo_3000_automute(codec, 1); 10690 alc262_lenovo_3000_automute(codec, 1);
10600} 10691}
10601 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
10602/* bind hp and internal speaker mute (with plug check) */ 10705/* bind hp and internal speaker mute (with plug check) */
10603static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol, 10706static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10604 struct snd_ctl_elem_value *ucontrol) 10707 struct snd_ctl_elem_value *ucontrol)
@@ -10607,13 +10710,8 @@ static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10607 long *valp = ucontrol->value.integer.value; 10710 long *valp = ucontrol->value.integer.value;
10608 int change; 10711 int change;
10609 10712
10610 change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 10713 change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10611 HDA_AMP_MUTE, 10714 change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10612 valp ? 0 : HDA_AMP_MUTE);
10613 change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10614 HDA_AMP_MUTE,
10615 valp ? 0 : HDA_AMP_MUTE);
10616
10617 if (change) 10715 if (change)
10618 alc262_fujitsu_automute(codec, 0); 10716 alc262_fujitsu_automute(codec, 0);
10619 return change; 10717 return change;
@@ -10648,10 +10746,7 @@ static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10648 long *valp = ucontrol->value.integer.value; 10746 long *valp = ucontrol->value.integer.value;
10649 int change; 10747 int change;
10650 10748
10651 change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0, 10749 change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10652 HDA_AMP_MUTE,
10653 valp ? 0 : HDA_AMP_MUTE);
10654
10655 if (change) 10750 if (change)
10656 alc262_lenovo_3000_automute(codec, 0); 10751 alc262_lenovo_3000_automute(codec, 0);
10657 return change; 10752 return change;
@@ -10824,104 +10919,111 @@ static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10824 { } /* end */ 10919 { } /* end */
10825}; 10920};
10826 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
10827/* add playback controls from the parsed DAC table */ 10973/* add playback controls from the parsed DAC table */
10828static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, 10974static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10829 const struct auto_pin_cfg *cfg) 10975 const struct auto_pin_cfg *cfg)
10830{ 10976{
10831 hda_nid_t nid; 10977 const char *pfx;
10978 int vbits;
10832 int err; 10979 int err;
10833 10980
10834 spec->multiout.num_dacs = 1; /* only use one dac */ 10981 spec->multiout.num_dacs = 1; /* only use one dac */
10835 spec->multiout.dac_nids = spec->private_dac_nids; 10982 spec->multiout.dac_nids = spec->private_dac_nids;
10836 spec->multiout.dac_nids[0] = 2; 10983 spec->multiout.dac_nids[0] = 2;
10837 10984
10838 nid = cfg->line_out_pins[0]; 10985 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
10839 if (nid) { 10986 pfx = "Master";
10840 err = add_control(spec, ALC_CTL_WIDGET_VOL, 10987 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
10841 "Front Playback Volume", 10988 pfx = "Speaker";
10842 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT)); 10989 else
10843 if (err < 0) 10990 pfx = "Front";
10844 return err; 10991 err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
10845 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 10992 if (err < 0)
10846 "Front Playback Switch", 10993 return err;
10847 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT)); 10994 err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
10848 if (err < 0) 10995 if (err < 0)
10849 return err; 10996 return err;
10850 } 10997 err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
10851 10998 if (err < 0)
10852 nid = cfg->speaker_pins[0]; 10999 return err;
10853 if (nid) {
10854 if (nid == 0x16) {
10855 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10856 "Speaker Playback Volume",
10857 HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10858 HDA_OUTPUT));
10859 if (err < 0)
10860 return err;
10861 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10862 "Speaker Playback Switch",
10863 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10864 HDA_OUTPUT));
10865 if (err < 0)
10866 return err;
10867 } else {
10868 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10869 "Speaker Playback Switch",
10870 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10871 HDA_OUTPUT));
10872 if (err < 0)
10873 return err;
10874 }
10875 }
10876 nid = cfg->hp_pins[0];
10877 if (nid) {
10878 /* spec->multiout.hp_nid = 2; */
10879 if (nid == 0x16) {
10880 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10881 "Headphone Playback Volume",
10882 HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10883 HDA_OUTPUT));
10884 if (err < 0)
10885 return err;
10886 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10887 "Headphone Playback Switch",
10888 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10889 HDA_OUTPUT));
10890 if (err < 0)
10891 return err;
10892 } else {
10893 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10894 "Headphone Playback Switch",
10895 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10896 HDA_OUTPUT));
10897 if (err < 0)
10898 return err;
10899 }
10900 }
10901 return 0;
10902}
10903
10904static int alc262_auto_create_analog_input_ctls(struct alc_spec *spec,
10905 const struct auto_pin_cfg *cfg)
10906{
10907 int err;
10908 11000
10909 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);
10910 if (err < 0) 11020 if (err < 0)
10911 return err; 11021 return err;
10912 /* digital-mic input pin is excluded in alc880_auto_create..()
10913 * because it's under 0x18
10914 */
10915 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
10916 cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
10917 struct hda_input_mux *imux = &spec->private_imux[0];
10918 imux->items[imux->num_items].label = "Int Mic";
10919 imux->items[imux->num_items].index = 0x09;
10920 imux->num_items++;
10921 }
10922 return 0; 11022 return 0;
10923} 11023}
10924 11024
11025#define alc262_auto_create_input_ctls \
11026 alc880_auto_create_input_ctls
10925 11027
10926/* 11028/*
10927 * generic initialization of ADC, input mixers and output mixers 11029 * generic initialization of ADC, input mixers and output mixers
@@ -11239,7 +11341,7 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
11239 err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg); 11341 err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11240 if (err < 0) 11342 if (err < 0)
11241 return err; 11343 return err;
11242 err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg); 11344 err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11243 if (err < 0) 11345 if (err < 0)
11244 return err; 11346 return err;
11245 11347
@@ -11370,7 +11472,7 @@ static struct alc_config_preset alc262_presets[] = {
11370 }, 11472 },
11371 [ALC262_HIPPO] = { 11473 [ALC262_HIPPO] = {
11372 .mixers = { alc262_hippo_mixer }, 11474 .mixers = { alc262_hippo_mixer },
11373 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs}, 11475 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11374 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 11476 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11375 .dac_nids = alc262_dac_nids, 11477 .dac_nids = alc262_dac_nids,
11376 .hp_nid = 0x03, 11478 .hp_nid = 0x03,
@@ -11379,7 +11481,8 @@ static struct alc_config_preset alc262_presets[] = {
11379 .channel_mode = alc262_modes, 11481 .channel_mode = alc262_modes,
11380 .input_mux = &alc262_capture_source, 11482 .input_mux = &alc262_capture_source,
11381 .unsol_event = alc262_hippo_unsol_event, 11483 .unsol_event = alc262_hippo_unsol_event,
11382 .init_hook = alc262_hippo_init_hook, 11484 .setup = alc262_hippo_setup,
11485 .init_hook = alc262_hippo_automute,
11383 }, 11486 },
11384 [ALC262_HIPPO_1] = { 11487 [ALC262_HIPPO_1] = {
11385 .mixers = { alc262_hippo1_mixer }, 11488 .mixers = { alc262_hippo1_mixer },
@@ -11392,7 +11495,8 @@ static struct alc_config_preset alc262_presets[] = {
11392 .channel_mode = alc262_modes, 11495 .channel_mode = alc262_modes,
11393 .input_mux = &alc262_capture_source, 11496 .input_mux = &alc262_capture_source,
11394 .unsol_event = alc262_hippo_unsol_event, 11497 .unsol_event = alc262_hippo_unsol_event,
11395 .init_hook = alc262_hippo1_init_hook, 11498 .setup = alc262_hippo1_setup,
11499 .init_hook = alc262_hippo_automute,
11396 }, 11500 },
11397 [ALC262_FUJITSU] = { 11501 [ALC262_FUJITSU] = {
11398 .mixers = { alc262_fujitsu_mixer }, 11502 .mixers = { alc262_fujitsu_mixer },
@@ -11455,7 +11559,8 @@ static struct alc_config_preset alc262_presets[] = {
11455 .channel_mode = alc262_modes, 11559 .channel_mode = alc262_modes,
11456 .input_mux = &alc262_capture_source, 11560 .input_mux = &alc262_capture_source,
11457 .unsol_event = alc_automute_amp_unsol_event, 11561 .unsol_event = alc_automute_amp_unsol_event,
11458 .init_hook = alc262_hp_t5735_init_hook, 11562 .setup = alc262_hp_t5735_setup,
11563 .init_hook = alc_automute_amp,
11459 }, 11564 },
11460 [ALC262_HP_RP5700] = { 11565 [ALC262_HP_RP5700] = {
11461 .mixers = { alc262_hp_rp5700_mixer }, 11566 .mixers = { alc262_hp_rp5700_mixer },
@@ -11486,11 +11591,13 @@ static struct alc_config_preset alc262_presets[] = {
11486 .channel_mode = alc262_modes, 11591 .channel_mode = alc262_modes,
11487 .input_mux = &alc262_capture_source, 11592 .input_mux = &alc262_capture_source,
11488 .unsol_event = alc262_hippo_unsol_event, 11593 .unsol_event = alc262_hippo_unsol_event,
11489 .init_hook = alc262_hippo_init_hook, 11594 .setup = alc262_hippo_setup,
11595 .init_hook = alc262_hippo_automute,
11490 }, 11596 },
11491 [ALC262_BENQ_T31] = { 11597 [ALC262_BENQ_T31] = {
11492 .mixers = { alc262_benq_t31_mixer }, 11598 .mixers = { alc262_benq_t31_mixer },
11493 .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 },
11494 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 11601 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11495 .dac_nids = alc262_dac_nids, 11602 .dac_nids = alc262_dac_nids,
11496 .hp_nid = 0x03, 11603 .hp_nid = 0x03,
@@ -11498,7 +11605,8 @@ static struct alc_config_preset alc262_presets[] = {
11498 .channel_mode = alc262_modes, 11605 .channel_mode = alc262_modes,
11499 .input_mux = &alc262_capture_source, 11606 .input_mux = &alc262_capture_source,
11500 .unsol_event = alc262_hippo_unsol_event, 11607 .unsol_event = alc262_hippo_unsol_event,
11501 .init_hook = alc262_hippo_init_hook, 11608 .setup = alc262_hippo_setup,
11609 .init_hook = alc262_hippo_automute,
11502 }, 11610 },
11503 [ALC262_ULTRA] = { 11611 [ALC262_ULTRA] = {
11504 .mixers = { alc262_ultra_mixer }, 11612 .mixers = { alc262_ultra_mixer },
@@ -11550,9 +11658,9 @@ static struct alc_config_preset alc262_presets[] = {
11550 .dig_out_nid = ALC262_DIGOUT_NID, 11658 .dig_out_nid = ALC262_DIGOUT_NID,
11551 .num_channel_mode = ARRAY_SIZE(alc262_modes), 11659 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11552 .channel_mode = alc262_modes, 11660 .channel_mode = alc262_modes,
11553 .input_mux = &alc262_dmic_capture_source, 11661 .unsol_event = alc_sku_unsol_event,
11554 .unsol_event = alc262_toshiba_s06_unsol_event, 11662 .setup = alc262_toshiba_s06_setup,
11555 .init_hook = alc262_toshiba_s06_init_hook, 11663 .init_hook = alc_inithook,
11556 }, 11664 },
11557 [ALC262_TOSHIBA_RX1] = { 11665 [ALC262_TOSHIBA_RX1] = {
11558 .mixers = { alc262_toshiba_rx1_mixer }, 11666 .mixers = { alc262_toshiba_rx1_mixer },
@@ -11564,7 +11672,8 @@ static struct alc_config_preset alc262_presets[] = {
11564 .channel_mode = alc262_modes, 11672 .channel_mode = alc262_modes,
11565 .input_mux = &alc262_capture_source, 11673 .input_mux = &alc262_capture_source,
11566 .unsol_event = alc262_hippo_unsol_event, 11674 .unsol_event = alc262_hippo_unsol_event,
11567 .init_hook = alc262_hippo_init_hook, 11675 .setup = alc262_hippo_setup,
11676 .init_hook = alc262_hippo_automute,
11568 }, 11677 },
11569 [ALC262_TYAN] = { 11678 [ALC262_TYAN] = {
11570 .mixers = { alc262_tyan_mixer }, 11679 .mixers = { alc262_tyan_mixer },
@@ -11577,7 +11686,8 @@ static struct alc_config_preset alc262_presets[] = {
11577 .channel_mode = alc262_modes, 11686 .channel_mode = alc262_modes,
11578 .input_mux = &alc262_capture_source, 11687 .input_mux = &alc262_capture_source,
11579 .unsol_event = alc_automute_amp_unsol_event, 11688 .unsol_event = alc_automute_amp_unsol_event,
11580 .init_hook = alc262_tyan_init_hook, 11689 .setup = alc262_tyan_setup,
11690 .init_hook = alc_automute_amp,
11581 }, 11691 },
11582}; 11692};
11583 11693
@@ -11612,8 +11722,8 @@ static int patch_alc262(struct hda_codec *codec)
11612 alc262_cfg_tbl); 11722 alc262_cfg_tbl);
11613 11723
11614 if (board_config < 0) { 11724 if (board_config < 0) {
11615 printk(KERN_INFO "hda_codec: Unknown model for %s, " 11725 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11616 "trying auto-probe from BIOS...\n", codec->chip_name); 11726 codec->chip_name);
11617 board_config = ALC262_AUTO; 11727 board_config = ALC262_AUTO;
11618 } 11728 }
11619 11729
@@ -11640,7 +11750,7 @@ static int patch_alc262(struct hda_codec *codec)
11640 } 11750 }
11641 11751
11642 if (board_config != ALC262_AUTO) 11752 if (board_config != ALC262_AUTO)
11643 setup_preset(spec, &alc262_presets[board_config]); 11753 setup_preset(codec, &alc262_presets[board_config]);
11644 11754
11645 spec->stream_analog_playback = &alc262_pcm_analog_playback; 11755 spec->stream_analog_playback = &alc262_pcm_analog_playback;
11646 spec->stream_analog_capture = &alc262_pcm_analog_capture; 11756 spec->stream_analog_capture = &alc262_pcm_analog_capture;
@@ -11666,7 +11776,7 @@ static int patch_alc262(struct hda_codec *codec)
11666 unsigned int wcap = get_wcaps(codec, 0x07); 11776 unsigned int wcap = get_wcaps(codec, 0x07);
11667 11777
11668 /* get type */ 11778 /* get type */
11669 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 11779 wcap = get_wcaps_type(wcap);
11670 if (wcap != AC_WID_AUD_IN) { 11780 if (wcap != AC_WID_AUD_IN) {
11671 spec->adc_nids = alc262_adc_nids_alt; 11781 spec->adc_nids = alc262_adc_nids_alt;
11672 spec->num_adc_nids = 11782 spec->num_adc_nids =
@@ -11681,7 +11791,7 @@ static int patch_alc262(struct hda_codec *codec)
11681 } 11791 }
11682 } 11792 }
11683 if (!spec->cap_mixer && !spec->no_analog) 11793 if (!spec->cap_mixer && !spec->no_analog)
11684 set_capture_mixer(spec); 11794 set_capture_mixer(codec);
11685 if (!spec->no_analog) 11795 if (!spec->no_analog)
11686 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 11796 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11687 11797
@@ -11773,14 +11883,6 @@ static struct hda_verb alc268_toshiba_verbs[] = {
11773 { } /* end */ 11883 { } /* end */
11774}; 11884};
11775 11885
11776static struct hda_input_mux alc268_acer_lc_capture_source = {
11777 .num_items = 2,
11778 .items = {
11779 { "i-Mic", 0x6 },
11780 { "E-Mic", 0x0 },
11781 },
11782};
11783
11784/* Acer specific */ 11886/* Acer specific */
11785/* bind volumes of both NID 0x02 and 0x03 */ 11887/* bind volumes of both NID 0x02 and 0x03 */
11786static struct hda_bind_ctls alc268_acer_bind_master_vol = { 11888static struct hda_bind_ctls alc268_acer_bind_master_vol = {
@@ -11822,12 +11924,7 @@ static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11822 long *valp = ucontrol->value.integer.value; 11924 long *valp = ucontrol->value.integer.value;
11823 int change; 11925 int change;
11824 11926
11825 change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0, 11927 change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
11826 HDA_AMP_MUTE,
11827 valp[0] ? 0 : HDA_AMP_MUTE);
11828 change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11829 HDA_AMP_MUTE,
11830 valp[1] ? 0 : HDA_AMP_MUTE);
11831 if (change) 11928 if (change)
11832 alc268_acer_automute(codec, 0); 11929 alc268_acer_automute(codec, 0);
11833 return change; 11930 return change;
@@ -11904,7 +12001,8 @@ static struct hda_verb alc268_acer_verbs[] = {
11904 12001
11905/* unsolicited event for HP jack sensing */ 12002/* unsolicited event for HP jack sensing */
11906#define alc268_toshiba_unsol_event alc262_hippo_unsol_event 12003#define alc268_toshiba_unsol_event alc262_hippo_unsol_event
11907#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
11908 12006
11909static void alc268_acer_unsol_event(struct hda_codec *codec, 12007static void alc268_acer_unsol_event(struct hda_codec *codec,
11910 unsigned int res) 12008 unsigned int res)
@@ -11934,30 +12032,33 @@ static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11934 AMP_IN_MUTE(0), bits); 12032 AMP_IN_MUTE(0), bits);
11935} 12033}
11936 12034
11937
11938static void alc268_acer_mic_automute(struct hda_codec *codec)
11939{
11940 unsigned int present;
11941
11942 present = snd_hda_codec_read(codec, 0x18, 0,
11943 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11944 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11945 present ? 0x0 : 0x6);
11946}
11947
11948static void alc268_acer_lc_unsol_event(struct hda_codec *codec, 12035static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11949 unsigned int res) 12036 unsigned int res)
11950{ 12037{
11951 if ((res >> 26) == ALC880_HP_EVENT) 12038 switch (res >> 26) {
12039 case ALC880_HP_EVENT:
11952 alc268_aspire_one_speaker_automute(codec); 12040 alc268_aspire_one_speaker_automute(codec);
11953 if ((res >> 26) == ALC880_MIC_EVENT) 12041 break;
11954 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;
11955} 12056}
11956 12057
11957static void alc268_acer_lc_init_hook(struct hda_codec *codec) 12058static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11958{ 12059{
11959 alc268_aspire_one_speaker_automute(codec); 12060 alc268_aspire_one_speaker_automute(codec);
11960 alc268_acer_mic_automute(codec); 12061 alc_mic_automute(codec);
11961} 12062}
11962 12063
11963static struct snd_kcontrol_new alc268_dell_mixer[] = { 12064static struct snd_kcontrol_new alc268_dell_mixer[] = {
@@ -11975,17 +12076,22 @@ static struct hda_verb alc268_dell_verbs[] = {
11975 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 12076 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11976 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 12077 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11977 {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},
11978 { } 12080 { }
11979}; 12081};
11980 12082
11981/* 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 */
11982static void alc268_dell_init_hook(struct hda_codec *codec) 12084static void alc268_dell_setup(struct hda_codec *codec)
11983{ 12085{
11984 struct alc_spec *spec = codec->spec; 12086 struct alc_spec *spec = codec->spec;
11985 12087
11986 spec->autocfg.hp_pins[0] = 0x15; 12088 spec->autocfg.hp_pins[0] = 0x15;
11987 spec->autocfg.speaker_pins[0] = 0x14; 12089 spec->autocfg.speaker_pins[0] = 0x14;
11988 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;
11989} 12095}
11990 12096
11991static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = { 12097static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
@@ -12006,38 +12112,16 @@ static struct hda_verb alc267_quanta_il1_verbs[] = {
12006 { } 12112 { }
12007}; 12113};
12008 12114
12009static void alc267_quanta_il1_mic_automute(struct hda_codec *codec) 12115static void alc267_quanta_il1_setup(struct hda_codec *codec)
12010{
12011 unsigned int present;
12012
12013 present = snd_hda_codec_read(codec, 0x18, 0,
12014 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12015 snd_hda_codec_write(codec, 0x23, 0,
12016 AC_VERB_SET_CONNECT_SEL,
12017 present ? 0x00 : 0x01);
12018}
12019
12020static void alc267_quanta_il1_init_hook(struct hda_codec *codec)
12021{ 12116{
12022 struct alc_spec *spec = codec->spec; 12117 struct alc_spec *spec = codec->spec;
12023
12024 spec->autocfg.hp_pins[0] = 0x15; 12118 spec->autocfg.hp_pins[0] = 0x15;
12025 spec->autocfg.speaker_pins[0] = 0x14; 12119 spec->autocfg.speaker_pins[0] = 0x14;
12026 alc_automute_pin(codec); 12120 spec->ext_mic.pin = 0x18;
12027 alc267_quanta_il1_mic_automute(codec); 12121 spec->ext_mic.mux_idx = 0;
12028} 12122 spec->int_mic.pin = 0x19;
12029 12123 spec->int_mic.mux_idx = 1;
12030static void alc267_quanta_il1_unsol_event(struct hda_codec *codec, 12124 spec->auto_mic = 1;
12031 unsigned int res)
12032{
12033 switch (res >> 26) {
12034 case ALC880_MIC_EVENT:
12035 alc267_quanta_il1_mic_automute(codec);
12036 break;
12037 default:
12038 alc_sku_unsol_event(codec, res);
12039 break;
12040 }
12041} 12125}
12042 12126
12043/* 12127/*
@@ -12117,21 +12201,16 @@ static struct hda_verb alc268_volume_init_verbs[] = {
12117 { } 12201 { }
12118}; 12202};
12119 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
12120static struct snd_kcontrol_new alc268_capture_alt_mixer[] = { 12210static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12121 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT), 12211 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12122 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT), 12212 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12123 { 12213 _DEFINE_CAPSRC(1),
12124 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12125 /* The multiple "Capture Source" controls confuse alsamixer
12126 * So call somewhat different..
12127 */
12128 /* .name = "Capture Source", */
12129 .name = "Input Source",
12130 .count = 1,
12131 .info = alc_mux_enum_info,
12132 .get = alc_mux_enum_get,
12133 .put = alc_mux_enum_put,
12134 },
12135 { } /* end */ 12214 { } /* end */
12136}; 12215};
12137 12216
@@ -12140,18 +12219,7 @@ static struct snd_kcontrol_new alc268_capture_mixer[] = {
12140 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT), 12219 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12141 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT), 12220 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12142 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT), 12221 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12143 { 12222 _DEFINE_CAPSRC(2),
12144 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12145 /* The multiple "Capture Source" controls confuse alsamixer
12146 * So call somewhat different..
12147 */
12148 /* .name = "Capture Source", */
12149 .name = "Input Source",
12150 .count = 2,
12151 .info = alc_mux_enum_info,
12152 .get = alc_mux_enum_get,
12153 .put = alc_mux_enum_put,
12154 },
12155 { } /* end */ 12223 { } /* end */
12156}; 12224};
12157 12225
@@ -12238,26 +12306,38 @@ static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12238 const char *ctlname, int idx) 12306 const char *ctlname, int idx)
12239{ 12307{
12240 char name[32]; 12308 char name[32];
12309 hda_nid_t dac;
12241 int err; 12310 int err;
12242 12311
12243 sprintf(name, "%s Playback Volume", ctlname); 12312 sprintf(name, "%s Playback Volume", ctlname);
12244 if (nid == 0x14) { 12313 switch (nid) {
12245 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 12314 case 0x14:
12246 HDA_COMPOSE_AMP_VAL(0x02, 3, idx, 12315 case 0x16:
12247 HDA_OUTPUT)); 12316 dac = 0x02;
12248 if (err < 0) 12317 break;
12249 return err; 12318 case 0x15:
12250 } 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) {
12251 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 12326 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12252 HDA_COMPOSE_AMP_VAL(0x03, 3, idx, 12327 HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12253 HDA_OUTPUT)); 12328 HDA_OUTPUT));
12254 if (err < 0) 12329 if (err < 0)
12255 return err; 12330 return err;
12256 } else 12331 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12257 return -1; 12332 }
12333
12258 sprintf(name, "%s Playback Switch", ctlname); 12334 sprintf(name, "%s Playback Switch", ctlname);
12259 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 12335 if (nid != 0x16)
12336 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12260 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));
12261 if (err < 0) 12341 if (err < 0)
12262 return err; 12342 return err;
12263 return 0; 12343 return 0;
@@ -12270,14 +12350,19 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12270 hda_nid_t nid; 12350 hda_nid_t nid;
12271 int err; 12351 int err;
12272 12352
12273 spec->multiout.num_dacs = 2; /* only use one dac */
12274 spec->multiout.dac_nids = spec->private_dac_nids; 12353 spec->multiout.dac_nids = spec->private_dac_nids;
12275 spec->multiout.dac_nids[0] = 2;
12276 spec->multiout.dac_nids[1] = 3;
12277 12354
12278 nid = cfg->line_out_pins[0]; 12355 nid = cfg->line_out_pins[0];
12279 if (nid) 12356 if (nid) {
12280 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 }
12281 12366
12282 nid = cfg->speaker_pins[0]; 12367 nid = cfg->speaker_pins[0];
12283 if (nid == 0x1d) { 12368 if (nid == 0x1d) {
@@ -12286,16 +12371,23 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12286 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); 12371 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12287 if (err < 0) 12372 if (err < 0)
12288 return err; 12373 return err;
12374 } else {
12375 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
12376 if (err < 0)
12377 return err;
12289 } 12378 }
12290 nid = cfg->hp_pins[0]; 12379 nid = cfg->hp_pins[0];
12291 if (nid) 12380 if (nid) {
12292 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 }
12293 12385
12294 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2]; 12386 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12295 if (nid == 0x16) { 12387 if (nid == 0x16) {
12296 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 12388 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12297 "Mono Playback Switch", 12389 "Mono Playback Switch",
12298 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT)); 12390 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12299 if (err < 0) 12391 if (err < 0)
12300 return err; 12392 return err;
12301 } 12393 }
@@ -12303,38 +12395,46 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12303} 12395}
12304 12396
12305/* create playback/capture controls for input pins */ 12397/* create playback/capture controls for input pins */
12306static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec, 12398static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12307 const struct auto_pin_cfg *cfg) 12399 const struct auto_pin_cfg *cfg)
12308{ 12400{
12309 struct hda_input_mux *imux = &spec->private_imux[0]; 12401 return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12310 int i, idx1; 12402}
12311 12403
12312 for (i = 0; i < AUTO_PIN_LAST; i++) { 12404static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
12313 switch(cfg->input_pins[i]) { 12405 hda_nid_t nid, int pin_type)
12314 case 0x18: 12406{
12315 idx1 = 0; /* Mic 1 */ 12407 int idx;
12316 break; 12408
12317 case 0x19: 12409 alc_set_pin_output(codec, nid, pin_type);
12318 idx1 = 1; /* Mic 2 */ 12410 if (nid == 0x14 || nid == 0x16)
12319 break; 12411 idx = 0;
12320 case 0x1a: 12412 else
12321 idx1 = 2; /* Line In */ 12413 idx = 1;
12322 break; 12414 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
12323 case 0x1c: 12415}
12324 idx1 = 3; /* CD */ 12416
12325 break; 12417static void alc268_auto_init_multi_out(struct hda_codec *codec)
12326 case 0x12: 12418{
12327 case 0x13: 12419 struct alc_spec *spec = codec->spec;
12328 idx1 = 6; /* digital mics */ 12420 hda_nid_t nid = spec->autocfg.line_out_pins[0];
12329 break; 12421 if (nid) {
12330 default: 12422 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12331 continue; 12423 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
12332 }
12333 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12334 imux->items[imux->num_items].index = idx1;
12335 imux->num_items++;
12336 } 12424 }
12337 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);
12338} 12438}
12339 12439
12340static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec) 12440static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
@@ -12345,9 +12445,10 @@ static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12345 hda_nid_t line_nid = spec->autocfg.line_out_pins[0]; 12445 hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12346 unsigned int dac_vol1, dac_vol2; 12446 unsigned int dac_vol1, dac_vol2;
12347 12447
12348 if (speaker_nid) { 12448 if (line_nid == 0x1d || speaker_nid == 0x1d) {
12349 snd_hda_codec_write(codec, speaker_nid, 0, 12449 snd_hda_codec_write(codec, speaker_nid, 0,
12350 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 12450 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12451 /* mute mixer inputs from 0x1d */
12351 snd_hda_codec_write(codec, 0x0f, 0, 12452 snd_hda_codec_write(codec, 0x0f, 0,
12352 AC_VERB_SET_AMP_GAIN_MUTE, 12453 AC_VERB_SET_AMP_GAIN_MUTE,
12353 AMP_IN_UNMUTE(1)); 12454 AMP_IN_UNMUTE(1));
@@ -12355,6 +12456,7 @@ static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12355 AC_VERB_SET_AMP_GAIN_MUTE, 12456 AC_VERB_SET_AMP_GAIN_MUTE,
12356 AMP_IN_UNMUTE(1)); 12457 AMP_IN_UNMUTE(1));
12357 } else { 12458 } else {
12459 /* unmute mixer inputs from 0x1d */
12358 snd_hda_codec_write(codec, 0x0f, 0, 12460 snd_hda_codec_write(codec, 0x0f, 0,
12359 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)); 12461 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12360 snd_hda_codec_write(codec, 0x10, 0, 12462 snd_hda_codec_write(codec, 0x10, 0,
@@ -12411,7 +12513,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
12411 err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg); 12513 err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12412 if (err < 0) 12514 if (err < 0)
12413 return err; 12515 return err;
12414 err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg); 12516 err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
12415 if (err < 0) 12517 if (err < 0)
12416 return err; 12518 return err;
12417 12519
@@ -12430,18 +12532,18 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
12430 add_mixer(spec, alc268_beep_mixer); 12532 add_mixer(spec, alc268_beep_mixer);
12431 12533
12432 add_verb(spec, alc268_volume_init_verbs); 12534 add_verb(spec, alc268_volume_init_verbs);
12433 spec->num_mux_defs = 1; 12535 spec->num_mux_defs = 2;
12434 spec->input_mux = &spec->private_imux[0]; 12536 spec->input_mux = &spec->private_imux[0];
12435 12537
12436 err = alc_auto_add_mic_boost(codec); 12538 err = alc_auto_add_mic_boost(codec);
12437 if (err < 0) 12539 if (err < 0)
12438 return err; 12540 return err;
12439 12541
12542 alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12543
12440 return 1; 12544 return 1;
12441} 12545}
12442 12546
12443#define alc268_auto_init_multi_out alc882_auto_init_multi_out
12444#define alc268_auto_init_hp_out alc882_auto_init_hp_out
12445#define alc268_auto_init_analog_input alc882_auto_init_analog_input 12547#define alc268_auto_init_analog_input alc882_auto_init_analog_input
12446 12548
12447/* init callback for auto-configuration model -- overriding the default init */ 12549/* init callback for auto-configuration model -- overriding the default init */
@@ -12484,12 +12586,13 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
12484 ALC268_ACER_ASPIRE_ONE), 12586 ALC268_ACER_ASPIRE_ONE),
12485 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL), 12587 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12486 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 */
12487 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series", 12592 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12488 ALC268_TOSHIBA), 12593 ALC268_AUTO),
12489 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST), 12594 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12490 SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO), 12595 SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12491 SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12492 ALC268_TOSHIBA),
12493 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA), 12596 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12494 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER), 12597 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12495 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1), 12598 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
@@ -12497,9 +12600,19 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
12497 {} 12600 {}
12498}; 12601};
12499 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
12500static struct alc_config_preset alc268_presets[] = { 12612static struct alc_config_preset alc268_presets[] = {
12501 [ALC267_QUANTA_IL1] = { 12613 [ALC267_QUANTA_IL1] = {
12502 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer }, 12614 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
12615 alc268_capture_nosrc_mixer },
12503 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12616 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12504 alc267_quanta_il1_verbs }, 12617 alc267_quanta_il1_verbs },
12505 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 12618 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -12509,9 +12622,9 @@ static struct alc_config_preset alc268_presets[] = {
12509 .hp_nid = 0x03, 12622 .hp_nid = 0x03,
12510 .num_channel_mode = ARRAY_SIZE(alc268_modes), 12623 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12511 .channel_mode = alc268_modes, 12624 .channel_mode = alc268_modes,
12512 .input_mux = &alc268_capture_source, 12625 .unsol_event = alc_sku_unsol_event,
12513 .unsol_event = alc267_quanta_il1_unsol_event, 12626 .setup = alc267_quanta_il1_setup,
12514 .init_hook = alc267_quanta_il1_init_hook, 12627 .init_hook = alc_inithook,
12515 }, 12628 },
12516 [ALC268_3ST] = { 12629 [ALC268_3ST] = {
12517 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer, 12630 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
@@ -12543,7 +12656,8 @@ static struct alc_config_preset alc268_presets[] = {
12543 .channel_mode = alc268_modes, 12656 .channel_mode = alc268_modes,
12544 .input_mux = &alc268_capture_source, 12657 .input_mux = &alc268_capture_source,
12545 .unsol_event = alc268_toshiba_unsol_event, 12658 .unsol_event = alc268_toshiba_unsol_event,
12546 .init_hook = alc268_toshiba_init_hook, 12659 .setup = alc268_toshiba_setup,
12660 .init_hook = alc268_toshiba_automute,
12547 }, 12661 },
12548 [ALC268_ACER] = { 12662 [ALC268_ACER] = {
12549 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer, 12663 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
@@ -12582,7 +12696,7 @@ static struct alc_config_preset alc268_presets[] = {
12582 [ALC268_ACER_ASPIRE_ONE] = { 12696 [ALC268_ACER_ASPIRE_ONE] = {
12583 .mixers = { alc268_acer_aspire_one_mixer, 12697 .mixers = { alc268_acer_aspire_one_mixer,
12584 alc268_beep_mixer, 12698 alc268_beep_mixer,
12585 alc268_capture_alt_mixer }, 12699 alc268_capture_nosrc_mixer },
12586 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12700 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12587 alc268_acer_aspire_one_verbs }, 12701 alc268_acer_aspire_one_verbs },
12588 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 12702 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -12593,22 +12707,26 @@ static struct alc_config_preset alc268_presets[] = {
12593 .hp_nid = 0x03, 12707 .hp_nid = 0x03,
12594 .num_channel_mode = ARRAY_SIZE(alc268_modes), 12708 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12595 .channel_mode = alc268_modes, 12709 .channel_mode = alc268_modes,
12596 .input_mux = &alc268_acer_lc_capture_source,
12597 .unsol_event = alc268_acer_lc_unsol_event, 12710 .unsol_event = alc268_acer_lc_unsol_event,
12711 .setup = alc268_acer_lc_setup,
12598 .init_hook = alc268_acer_lc_init_hook, 12712 .init_hook = alc268_acer_lc_init_hook,
12599 }, 12713 },
12600 [ALC268_DELL] = { 12714 [ALC268_DELL] = {
12601 .mixers = { alc268_dell_mixer, alc268_beep_mixer }, 12715 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
12716 alc268_capture_nosrc_mixer },
12602 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12717 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12603 alc268_dell_verbs }, 12718 alc268_dell_verbs },
12604 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 12719 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12605 .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,
12606 .hp_nid = 0x02, 12724 .hp_nid = 0x02,
12607 .num_channel_mode = ARRAY_SIZE(alc268_modes), 12725 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12608 .channel_mode = alc268_modes, 12726 .channel_mode = alc268_modes,
12609 .unsol_event = alc_sku_unsol_event, 12727 .unsol_event = alc_sku_unsol_event,
12610 .init_hook = alc268_dell_init_hook, 12728 .setup = alc268_dell_setup,
12611 .input_mux = &alc268_capture_source, 12729 .init_hook = alc_inithook,
12612 }, 12730 },
12613 [ALC268_ZEPTO] = { 12731 [ALC268_ZEPTO] = {
12614 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer, 12732 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
@@ -12625,8 +12743,8 @@ static struct alc_config_preset alc268_presets[] = {
12625 .num_channel_mode = ARRAY_SIZE(alc268_modes), 12743 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12626 .channel_mode = alc268_modes, 12744 .channel_mode = alc268_modes,
12627 .input_mux = &alc268_capture_source, 12745 .input_mux = &alc268_capture_source,
12628 .unsol_event = alc268_toshiba_unsol_event, 12746 .setup = alc268_toshiba_setup,
12629 .init_hook = alc268_toshiba_init_hook 12747 .init_hook = alc268_toshiba_automute,
12630 }, 12748 },
12631#ifdef CONFIG_SND_DEBUG 12749#ifdef CONFIG_SND_DEBUG
12632 [ALC268_TEST] = { 12750 [ALC268_TEST] = {
@@ -12663,9 +12781,13 @@ static int patch_alc268(struct hda_codec *codec)
12663 alc268_models, 12781 alc268_models,
12664 alc268_cfg_tbl); 12782 alc268_cfg_tbl);
12665 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
12666 if (board_config < 0 || board_config >= ALC268_MODEL_LAST) { 12788 if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12667 printk(KERN_INFO "hda_codec: Unknown model for %s, " 12789 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12668 "trying auto-probe from BIOS...\n", codec->chip_name); 12790 codec->chip_name);
12669 board_config = ALC268_AUTO; 12791 board_config = ALC268_AUTO;
12670 } 12792 }
12671 12793
@@ -12684,7 +12806,7 @@ static int patch_alc268(struct hda_codec *codec)
12684 } 12806 }
12685 12807
12686 if (board_config != ALC268_AUTO) 12808 if (board_config != ALC268_AUTO)
12687 setup_preset(spec, &alc268_presets[board_config]); 12809 setup_preset(codec, &alc268_presets[board_config]);
12688 12810
12689 spec->stream_analog_playback = &alc268_pcm_analog_playback; 12811 spec->stream_analog_playback = &alc268_pcm_analog_playback;
12690 spec->stream_analog_capture = &alc268_pcm_analog_capture; 12812 spec->stream_analog_capture = &alc268_pcm_analog_capture;
@@ -12721,11 +12843,15 @@ static int patch_alc268(struct hda_codec *codec)
12721 int i; 12843 int i;
12722 12844
12723 /* get type */ 12845 /* get type */
12724 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 12846 wcap = get_wcaps_type(wcap);
12725 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) {
12726 spec->adc_nids = alc268_adc_nids_alt; 12849 spec->adc_nids = alc268_adc_nids_alt;
12727 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt); 12850 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12728 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);
12729 } else { 12855 } else {
12730 spec->adc_nids = alc268_adc_nids; 12856 spec->adc_nids = alc268_adc_nids;
12731 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids); 12857 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
@@ -12736,6 +12862,8 @@ static int patch_alc268(struct hda_codec *codec)
12736 for (i = 0; i < spec->num_adc_nids; i++) 12862 for (i = 0; i < spec->num_adc_nids; i++)
12737 snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i], 12863 snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12738 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 :
12739 spec->input_mux->items[0].index); 12867 spec->input_mux->items[0].index);
12740 } 12868 }
12741 12869
@@ -12770,22 +12898,6 @@ static hda_nid_t alc269_capsrc_nids[1] = {
12770 * not a mux! 12898 * not a mux!
12771 */ 12899 */
12772 12900
12773static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12774 .num_items = 2,
12775 .items = {
12776 { "i-Mic", 0x5 },
12777 { "e-Mic", 0x0 },
12778 },
12779};
12780
12781static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12782 .num_items = 2,
12783 .items = {
12784 { "i-Mic", 0x1 },
12785 { "e-Mic", 0x0 },
12786 },
12787};
12788
12789#define alc269_modes alc260_modes 12901#define alc269_modes alc260_modes
12790#define alc269_capture_source alc880_lg_lw_capture_source 12902#define alc269_capture_source alc880_lg_lw_capture_source
12791 12903
@@ -12848,20 +12960,11 @@ static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12848 { } 12960 { }
12849}; 12961};
12850 12962
12851/* bind volumes of both NID 0x0c and 0x0d */
12852static struct hda_bind_ctls alc269_epc_bind_vol = {
12853 .ops = &snd_hda_bind_vol,
12854 .values = {
12855 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12856 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12857 0
12858 },
12859};
12860
12861static struct snd_kcontrol_new alc269_eeepc_mixer[] = { 12963static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12862 HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), 12964 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12863 HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol), 12965 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12864 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),
12865 { } /* end */ 12968 { } /* end */
12866}; 12969};
12867 12970
@@ -12874,12 +12977,7 @@ static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12874}; 12977};
12875 12978
12876/* FSC amilo */ 12979/* FSC amilo */
12877static struct snd_kcontrol_new alc269_fujitsu_mixer[] = { 12980#define alc269_fujitsu_mixer alc269_eeepc_mixer
12878 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12879 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12880 HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12881 { } /* end */
12882};
12883 12981
12884static struct hda_verb alc269_quanta_fl1_verbs[] = { 12982static struct hda_verb alc269_quanta_fl1_verbs[] = {
12885 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 12983 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
@@ -12961,16 +13059,6 @@ static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12961 AC_VERB_SET_PROC_COEF, 0x480); 13059 AC_VERB_SET_PROC_COEF, 0x480);
12962} 13060}
12963 13061
12964static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12965{
12966 unsigned int present;
12967
12968 present = snd_hda_codec_read(codec, 0x18, 0,
12969 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12970 snd_hda_codec_write(codec, 0x23, 0,
12971 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12972}
12973
12974static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec) 13062static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12975{ 13063{
12976 unsigned int present_laptop; 13064 unsigned int present_laptop;
@@ -12997,10 +13085,14 @@ static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12997static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec, 13085static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12998 unsigned int res) 13086 unsigned int res)
12999{ 13087{
13000 if ((res >> 26) == ALC880_HP_EVENT) 13088 switch (res >> 26) {
13089 case ALC880_HP_EVENT:
13001 alc269_quanta_fl1_speaker_automute(codec); 13090 alc269_quanta_fl1_speaker_automute(codec);
13002 if ((res >> 26) == ALC880_MIC_EVENT) 13091 break;
13003 alc269_quanta_fl1_mic_automute(codec); 13092 case ALC880_MIC_EVENT:
13093 alc_mic_automute(codec);
13094 break;
13095 }
13004} 13096}
13005 13097
13006static void alc269_lifebook_unsol_event(struct hda_codec *codec, 13098static void alc269_lifebook_unsol_event(struct hda_codec *codec,
@@ -13012,10 +13104,20 @@ static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13012 alc269_lifebook_mic_autoswitch(codec); 13104 alc269_lifebook_mic_autoswitch(codec);
13013} 13105}
13014 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
13015static void alc269_quanta_fl1_init_hook(struct hda_codec *codec) 13117static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13016{ 13118{
13017 alc269_quanta_fl1_speaker_automute(codec); 13119 alc269_quanta_fl1_speaker_automute(codec);
13018 alc269_quanta_fl1_mic_automute(codec); 13120 alc_mic_automute(codec);
13019} 13121}
13020 13122
13021static void alc269_lifebook_init_hook(struct hda_codec *codec) 13123static void alc269_lifebook_init_hook(struct hda_codec *codec)
@@ -13060,60 +13162,44 @@ static void alc269_speaker_automute(struct hda_codec *codec)
13060 AMP_IN_MUTE(0), bits); 13162 AMP_IN_MUTE(0), bits);
13061} 13163}
13062 13164
13063static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
13064{
13065 unsigned int present;
13066
13067 present = snd_hda_codec_read(codec, 0x18, 0,
13068 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13069 snd_hda_codec_write(codec, 0x23, 0,
13070 AC_VERB_SET_CONNECT_SEL, (present ? 0 : 5));
13071}
13072
13073static void alc269_eeepc_amic_automute(struct hda_codec *codec)
13074{
13075 unsigned int present;
13076
13077 present = snd_hda_codec_read(codec, 0x18, 0,
13078 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13079 snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13080 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13081 snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13082 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13083}
13084
13085/* unsolicited event for HP jack sensing */ 13165/* unsolicited event for HP jack sensing */
13086static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec, 13166static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13087 unsigned int res) 13167 unsigned int res)
13088{ 13168{
13089 if ((res >> 26) == ALC880_HP_EVENT) 13169 switch (res >> 26) {
13170 case ALC880_HP_EVENT:
13090 alc269_speaker_automute(codec); 13171 alc269_speaker_automute(codec);
13091 13172 break;
13092 if ((res >> 26) == ALC880_MIC_EVENT) 13173 case ALC880_MIC_EVENT:
13093 alc269_eeepc_dmic_automute(codec); 13174 alc_mic_automute(codec);
13175 break;
13176 }
13094} 13177}
13095 13178
13096static void alc269_eeepc_dmic_inithook(struct hda_codec *codec) 13179static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13097{ 13180{
13098 alc269_speaker_automute(codec); 13181 struct alc_spec *spec = codec->spec;
13099 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;
13100} 13187}
13101 13188
13102/* unsolicited event for HP jack sensing */ 13189static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13103static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
13104 unsigned int res)
13105{ 13190{
13106 if ((res >> 26) == ALC880_HP_EVENT) 13191 struct alc_spec *spec = codec->spec;
13107 alc269_speaker_automute(codec); 13192 spec->ext_mic.pin = 0x18;
13108 13193 spec->ext_mic.mux_idx = 0;
13109 if ((res >> 26) == ALC880_MIC_EVENT) 13194 spec->int_mic.pin = 0x19;
13110 alc269_eeepc_amic_automute(codec); 13195 spec->int_mic.mux_idx = 1;
13196 spec->auto_mic = 1;
13111} 13197}
13112 13198
13113static void alc269_eeepc_amic_inithook(struct hda_codec *codec) 13199static void alc269_eeepc_inithook(struct hda_codec *codec)
13114{ 13200{
13115 alc269_speaker_automute(codec); 13201 alc269_speaker_automute(codec);
13116 alc269_eeepc_amic_automute(codec); 13202 alc_mic_automute(codec);
13117} 13203}
13118 13204
13119/* 13205/*
@@ -13186,89 +13272,10 @@ static struct hda_verb alc269_init_verbs[] = {
13186 { } 13272 { }
13187}; 13273};
13188 13274
13189/* add playback controls from the parsed DAC table */ 13275#define alc269_auto_create_multi_out_ctls \
13190static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec, 13276 alc268_auto_create_multi_out_ctls
13191 const struct auto_pin_cfg *cfg) 13277#define alc269_auto_create_input_ctls \
13192{ 13278 alc268_auto_create_input_ctls
13193 hda_nid_t nid;
13194 int err;
13195
13196 spec->multiout.num_dacs = 1; /* only use one dac */
13197 spec->multiout.dac_nids = spec->private_dac_nids;
13198 spec->multiout.dac_nids[0] = 2;
13199
13200 nid = cfg->line_out_pins[0];
13201 if (nid) {
13202 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13203 "Front Playback Volume",
13204 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
13205 if (err < 0)
13206 return err;
13207 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13208 "Front Playback Switch",
13209 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13210 if (err < 0)
13211 return err;
13212 }
13213
13214 nid = cfg->speaker_pins[0];
13215 if (nid) {
13216 if (!cfg->line_out_pins[0]) {
13217 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13218 "Speaker Playback Volume",
13219 HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13220 HDA_OUTPUT));
13221 if (err < 0)
13222 return err;
13223 }
13224 if (nid == 0x16) {
13225 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13226 "Speaker Playback Switch",
13227 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13228 HDA_OUTPUT));
13229 if (err < 0)
13230 return err;
13231 } else {
13232 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13233 "Speaker Playback Switch",
13234 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13235 HDA_OUTPUT));
13236 if (err < 0)
13237 return err;
13238 }
13239 }
13240 nid = cfg->hp_pins[0];
13241 if (nid) {
13242 /* spec->multiout.hp_nid = 2; */
13243 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
13244 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13245 "Headphone Playback Volume",
13246 HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13247 HDA_OUTPUT));
13248 if (err < 0)
13249 return err;
13250 }
13251 if (nid == 0x16) {
13252 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13253 "Headphone Playback Switch",
13254 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13255 HDA_OUTPUT));
13256 if (err < 0)
13257 return err;
13258 } else {
13259 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13260 "Headphone Playback Switch",
13261 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13262 HDA_OUTPUT));
13263 if (err < 0)
13264 return err;
13265 }
13266 }
13267 return 0;
13268}
13269
13270#define alc269_auto_create_analog_input_ctls \
13271 alc262_auto_create_analog_input_ctls
13272 13279
13273#ifdef CONFIG_SND_HDA_POWER_SAVE 13280#ifdef CONFIG_SND_HDA_POWER_SAVE
13274#define alc269_loopbacks alc880_loopbacks 13281#define alc269_loopbacks alc880_loopbacks
@@ -13318,7 +13325,7 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
13318 err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg); 13325 err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13319 if (err < 0) 13326 if (err < 0)
13320 return err; 13327 return err;
13321 err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg); 13328 err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13322 if (err < 0) 13329 if (err < 0)
13323 return err; 13330 return err;
13324 13331
@@ -13343,13 +13350,15 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
13343 return err; 13350 return err;
13344 13351
13345 if (!spec->cap_mixer && !spec->no_analog) 13352 if (!spec->cap_mixer && !spec->no_analog)
13346 set_capture_mixer(spec); 13353 set_capture_mixer(codec);
13354
13355 alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13347 13356
13348 return 1; 13357 return 1;
13349} 13358}
13350 13359
13351#define alc269_auto_init_multi_out alc882_auto_init_multi_out 13360#define alc269_auto_init_multi_out alc268_auto_init_multi_out
13352#define alc269_auto_init_hp_out alc882_auto_init_hp_out 13361#define alc269_auto_init_hp_out alc268_auto_init_hp_out
13353#define alc269_auto_init_analog_input alc882_auto_init_analog_input 13362#define alc269_auto_init_analog_input alc882_auto_init_analog_input
13354 13363
13355 13364
@@ -13373,7 +13382,8 @@ static const char *alc269_models[ALC269_MODEL_LAST] = {
13373 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703", 13382 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703",
13374 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901", 13383 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901",
13375 [ALC269_FUJITSU] = "fujitsu", 13384 [ALC269_FUJITSU] = "fujitsu",
13376 [ALC269_LIFEBOOK] = "lifebook" 13385 [ALC269_LIFEBOOK] = "lifebook",
13386 [ALC269_AUTO] = "auto",
13377}; 13387};
13378 13388
13379static struct snd_pci_quirk alc269_cfg_tbl[] = { 13389static struct snd_pci_quirk alc269_cfg_tbl[] = {
@@ -13417,6 +13427,7 @@ static struct alc_config_preset alc269_presets[] = {
13417 .channel_mode = alc269_modes, 13427 .channel_mode = alc269_modes,
13418 .input_mux = &alc269_capture_source, 13428 .input_mux = &alc269_capture_source,
13419 .unsol_event = alc269_quanta_fl1_unsol_event, 13429 .unsol_event = alc269_quanta_fl1_unsol_event,
13430 .setup = alc269_quanta_fl1_setup,
13420 .init_hook = alc269_quanta_fl1_init_hook, 13431 .init_hook = alc269_quanta_fl1_init_hook,
13421 }, 13432 },
13422 [ALC269_ASUS_EEEPC_P703] = { 13433 [ALC269_ASUS_EEEPC_P703] = {
@@ -13429,9 +13440,9 @@ static struct alc_config_preset alc269_presets[] = {
13429 .hp_nid = 0x03, 13440 .hp_nid = 0x03,
13430 .num_channel_mode = ARRAY_SIZE(alc269_modes), 13441 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13431 .channel_mode = alc269_modes, 13442 .channel_mode = alc269_modes,
13432 .input_mux = &alc269_eeepc_amic_capture_source, 13443 .unsol_event = alc269_eeepc_unsol_event,
13433 .unsol_event = alc269_eeepc_amic_unsol_event, 13444 .setup = alc269_eeepc_amic_setup,
13434 .init_hook = alc269_eeepc_amic_inithook, 13445 .init_hook = alc269_eeepc_inithook,
13435 }, 13446 },
13436 [ALC269_ASUS_EEEPC_P901] = { 13447 [ALC269_ASUS_EEEPC_P901] = {
13437 .mixers = { alc269_eeepc_mixer }, 13448 .mixers = { alc269_eeepc_mixer },
@@ -13443,9 +13454,9 @@ static struct alc_config_preset alc269_presets[] = {
13443 .hp_nid = 0x03, 13454 .hp_nid = 0x03,
13444 .num_channel_mode = ARRAY_SIZE(alc269_modes), 13455 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13445 .channel_mode = alc269_modes, 13456 .channel_mode = alc269_modes,
13446 .input_mux = &alc269_eeepc_dmic_capture_source, 13457 .unsol_event = alc269_eeepc_unsol_event,
13447 .unsol_event = alc269_eeepc_dmic_unsol_event, 13458 .setup = alc269_eeepc_dmic_setup,
13448 .init_hook = alc269_eeepc_dmic_inithook, 13459 .init_hook = alc269_eeepc_inithook,
13449 }, 13460 },
13450 [ALC269_FUJITSU] = { 13461 [ALC269_FUJITSU] = {
13451 .mixers = { alc269_fujitsu_mixer }, 13462 .mixers = { alc269_fujitsu_mixer },
@@ -13457,9 +13468,9 @@ static struct alc_config_preset alc269_presets[] = {
13457 .hp_nid = 0x03, 13468 .hp_nid = 0x03,
13458 .num_channel_mode = ARRAY_SIZE(alc269_modes), 13469 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13459 .channel_mode = alc269_modes, 13470 .channel_mode = alc269_modes,
13460 .input_mux = &alc269_eeepc_dmic_capture_source, 13471 .unsol_event = alc269_eeepc_unsol_event,
13461 .unsol_event = alc269_eeepc_dmic_unsol_event, 13472 .setup = alc269_eeepc_dmic_setup,
13462 .init_hook = alc269_eeepc_dmic_inithook, 13473 .init_hook = alc269_eeepc_inithook,
13463 }, 13474 },
13464 [ALC269_LIFEBOOK] = { 13475 [ALC269_LIFEBOOK] = {
13465 .mixers = { alc269_lifebook_mixer }, 13476 .mixers = { alc269_lifebook_mixer },
@@ -13494,8 +13505,8 @@ static int patch_alc269(struct hda_codec *codec)
13494 alc269_cfg_tbl); 13505 alc269_cfg_tbl);
13495 13506
13496 if (board_config < 0) { 13507 if (board_config < 0) {
13497 printk(KERN_INFO "hda_codec: Unknown model for %s, " 13508 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13498 "trying auto-probe from BIOS...\n", codec->chip_name); 13509 codec->chip_name);
13499 board_config = ALC269_AUTO; 13510 board_config = ALC269_AUTO;
13500 } 13511 }
13501 13512
@@ -13520,7 +13531,7 @@ static int patch_alc269(struct hda_codec *codec)
13520 } 13531 }
13521 13532
13522 if (board_config != ALC269_AUTO) 13533 if (board_config != ALC269_AUTO)
13523 setup_preset(spec, &alc269_presets[board_config]); 13534 setup_preset(codec, &alc269_presets[board_config]);
13524 13535
13525 if (codec->subsystem_id == 0x17aa3bf8) { 13536 if (codec->subsystem_id == 0x17aa3bf8) {
13526 /* Due to a hardware problem on Lenovo Ideadpad, we need to 13537 /* Due to a hardware problem on Lenovo Ideadpad, we need to
@@ -13539,9 +13550,11 @@ static int patch_alc269(struct hda_codec *codec)
13539 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids); 13550 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13540 spec->capsrc_nids = alc269_capsrc_nids; 13551 spec->capsrc_nids = alc269_capsrc_nids;
13541 if (!spec->cap_mixer) 13552 if (!spec->cap_mixer)
13542 set_capture_mixer(spec); 13553 set_capture_mixer(codec);
13543 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); 13554 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13544 13555
13556 spec->vmaster_nid = 0x02;
13557
13545 codec->patch_ops = alc_patch_ops; 13558 codec->patch_ops = alc_patch_ops;
13546 if (board_config == ALC269_AUTO) 13559 if (board_config == ALC269_AUTO)
13547 spec->init_hook = alc269_auto_init; 13560 spec->init_hook = alc269_auto_init;
@@ -14087,23 +14100,23 @@ static struct hda_verb alc861_auto_init_verbs[] = {
14087 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 14100 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14088 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, 14101 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14089 14102
14090 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 14103 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14091 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 14104 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14092 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 14105 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14093 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 14106 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14094 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 14107 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14095 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 14108 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14096 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 14109 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14097 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 14110 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14098 14111
14099 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 14112 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14100 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 14113 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14101 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 14114 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14102 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, 14115 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14103 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 14116 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14104 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 14117 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14105 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 14118 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14106 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, 14119 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14107 14120
14108 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, /* set Mic 1 */ 14121 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, /* set Mic 1 */
14109 14122
@@ -14175,64 +14188,96 @@ static struct hda_input_mux alc861_capture_source = {
14175 }, 14188 },
14176}; 14189};
14177 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
14178/* fill in the dac_nids table from the parsed pin configuration */ 14216/* fill in the dac_nids table from the parsed pin configuration */
14179static int alc861_auto_fill_dac_nids(struct alc_spec *spec, 14217static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14180 const struct auto_pin_cfg *cfg) 14218 const struct auto_pin_cfg *cfg)
14181{ 14219{
14220 struct alc_spec *spec = codec->spec;
14182 int i; 14221 int i;
14183 hda_nid_t nid; 14222 hda_nid_t nid, dac;
14184 14223
14185 spec->multiout.dac_nids = spec->private_dac_nids; 14224 spec->multiout.dac_nids = spec->private_dac_nids;
14186 for (i = 0; i < cfg->line_outs; i++) { 14225 for (i = 0; i < cfg->line_outs; i++) {
14187 nid = cfg->line_out_pins[i]; 14226 nid = cfg->line_out_pins[i];
14188 if (nid) { 14227 dac = alc861_look_for_dac(codec, nid);
14189 if (i >= ARRAY_SIZE(alc861_dac_nids)) 14228 if (!dac)
14190 continue; 14229 continue;
14191 spec->multiout.dac_nids[i] = alc861_dac_nids[i]; 14230 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14192 }
14193 } 14231 }
14194 spec->multiout.num_dacs = cfg->line_outs;
14195 return 0; 14232 return 0;
14196} 14233}
14197 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
14198/* add playback controls from the parsed DAC table */ 14244/* add playback controls from the parsed DAC table */
14199static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec, 14245static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14200 const struct auto_pin_cfg *cfg) 14246 const struct auto_pin_cfg *cfg)
14201{ 14247{
14202 char name[32]; 14248 struct alc_spec *spec = codec->spec;
14203 static const char *chname[4] = { 14249 static const char *chname[4] = {
14204 "Front", "Surround", NULL /*CLFE*/, "Side" 14250 "Front", "Surround", NULL /*CLFE*/, "Side"
14205 }; 14251 };
14206 hda_nid_t nid; 14252 hda_nid_t nid;
14207 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 }
14208 14266
14209 for (i = 0; i < cfg->line_outs; i++) { 14267 for (i = 0; i < cfg->line_outs; i++) {
14210 nid = spec->multiout.dac_nids[i]; 14268 nid = spec->multiout.dac_nids[i];
14211 if (!nid) 14269 if (!nid)
14212 continue; 14270 continue;
14213 if (nid == 0x05) { 14271 if (i == 2) {
14214 /* Center/LFE */ 14272 /* Center/LFE */
14215 err = add_control(spec, ALC_CTL_BIND_MUTE, 14273 err = alc861_create_out_sw(codec, "Center", nid, 1);
14216 "Center Playback Switch",
14217 HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14218 HDA_OUTPUT));
14219 if (err < 0) 14274 if (err < 0)
14220 return err; 14275 return err;
14221 err = add_control(spec, ALC_CTL_BIND_MUTE, 14276 err = alc861_create_out_sw(codec, "LFE", nid, 2);
14222 "LFE Playback Switch",
14223 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14224 HDA_OUTPUT));
14225 if (err < 0) 14277 if (err < 0)
14226 return err; 14278 return err;
14227 } else { 14279 } else {
14228 for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1; 14280 err = alc861_create_out_sw(codec, chname[i], nid, 3);
14229 idx++)
14230 if (nid == alc861_dac_nids[idx])
14231 break;
14232 sprintf(name, "%s Playback Switch", chname[idx]);
14233 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14234 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14235 HDA_OUTPUT));
14236 if (err < 0) 14281 if (err < 0)
14237 return err; 14282 return err;
14238 } 14283 }
@@ -14240,8 +14285,9 @@ static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
14240 return 0; 14285 return 0;
14241} 14286}
14242 14287
14243static 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)
14244{ 14289{
14290 struct alc_spec *spec = codec->spec;
14245 int err; 14291 int err;
14246 hda_nid_t nid; 14292 hda_nid_t nid;
14247 14293
@@ -14249,70 +14295,49 @@ static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
14249 return 0; 14295 return 0;
14250 14296
14251 if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) { 14297 if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14252 nid = 0x03; 14298 nid = alc861_look_for_dac(codec, pin);
14253 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 14299 if (nid) {
14254 "Headphone Playback Switch", 14300 err = alc861_create_out_sw(codec, "Headphone", nid, 3);
14255 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT)); 14301 if (err < 0)
14256 if (err < 0) 14302 return err;
14257 return err; 14303 spec->multiout.hp_nid = nid;
14258 spec->multiout.hp_nid = nid; 14304 }
14259 } 14305 }
14260 return 0; 14306 return 0;
14261} 14307}
14262 14308
14263/* create playback/capture controls for input pins */ 14309/* create playback/capture controls for input pins */
14264static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec, 14310static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14265 const struct auto_pin_cfg *cfg) 14311 const struct auto_pin_cfg *cfg)
14266{ 14312{
14267 struct hda_input_mux *imux = &spec->private_imux[0]; 14313 return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14268 int i, err, idx, idx1;
14269
14270 for (i = 0; i < AUTO_PIN_LAST; i++) {
14271 switch (cfg->input_pins[i]) {
14272 case 0x0c:
14273 idx1 = 1;
14274 idx = 2; /* Line In */
14275 break;
14276 case 0x0f:
14277 idx1 = 2;
14278 idx = 2; /* Line In */
14279 break;
14280 case 0x0d:
14281 idx1 = 0;
14282 idx = 1; /* Mic In */
14283 break;
14284 case 0x10:
14285 idx1 = 3;
14286 idx = 1; /* Mic In */
14287 break;
14288 case 0x11:
14289 idx1 = 4;
14290 idx = 0; /* CD */
14291 break;
14292 default:
14293 continue;
14294 }
14295
14296 err = new_analog_input(spec, cfg->input_pins[i],
14297 auto_pin_cfg_labels[i], idx, 0x15);
14298 if (err < 0)
14299 return err;
14300
14301 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
14302 imux->items[imux->num_items].index = idx1;
14303 imux->num_items++;
14304 }
14305 return 0;
14306} 14314}
14307 14315
14308static void alc861_auto_set_output_and_unmute(struct hda_codec *codec, 14316static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14309 hda_nid_t nid, 14317 hda_nid_t nid,
14310 int pin_type, int dac_idx) 14318 int pin_type, hda_nid_t dac)
14311{ 14319{
14320 hda_nid_t mix, srcs[5];
14321 int i, num;
14322
14312 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,
14313 pin_type); 14324 pin_type);
14314 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,
14315 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 }
14316} 14341}
14317 14342
14318static void alc861_auto_init_multi_out(struct hda_codec *codec) 14343static void alc861_auto_init_multi_out(struct hda_codec *codec)
@@ -14335,12 +14360,13 @@ static void alc861_auto_init_hp_out(struct hda_codec *codec)
14335 hda_nid_t pin; 14360 hda_nid_t pin;
14336 14361
14337 pin = spec->autocfg.hp_pins[0]; 14362 pin = spec->autocfg.hp_pins[0];
14338 if (pin) /* connect to front */ 14363 if (pin)
14339 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP, 14364 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
14340 spec->multiout.dac_nids[0]); 14365 spec->multiout.hp_nid);
14341 pin = spec->autocfg.speaker_pins[0]; 14366 pin = spec->autocfg.speaker_pins[0];
14342 if (pin) 14367 if (pin)
14343 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]);
14344} 14370}
14345 14371
14346static void alc861_auto_init_analog_input(struct hda_codec *codec) 14372static void alc861_auto_init_analog_input(struct hda_codec *codec)
@@ -14372,16 +14398,16 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
14372 if (!spec->autocfg.line_outs) 14398 if (!spec->autocfg.line_outs)
14373 return 0; /* can't find valid BIOS pin config */ 14399 return 0; /* can't find valid BIOS pin config */
14374 14400
14375 err = alc861_auto_fill_dac_nids(spec, &spec->autocfg); 14401 err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
14376 if (err < 0) 14402 if (err < 0)
14377 return err; 14403 return err;
14378 err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg); 14404 err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
14379 if (err < 0) 14405 if (err < 0)
14380 return err; 14406 return err;
14381 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]);
14382 if (err < 0) 14408 if (err < 0)
14383 return err; 14409 return err;
14384 err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg); 14410 err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
14385 if (err < 0) 14411 if (err < 0)
14386 return err; 14412 return err;
14387 14413
@@ -14400,7 +14426,7 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
14400 14426
14401 spec->adc_nids = alc861_adc_nids; 14427 spec->adc_nids = alc861_adc_nids;
14402 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids); 14428 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14403 set_capture_mixer(spec); 14429 set_capture_mixer(codec);
14404 14430
14405 alc_ssid_check(codec, 0x0e, 0x0f, 0x0b); 14431 alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14406 14432
@@ -14593,8 +14619,8 @@ static int patch_alc861(struct hda_codec *codec)
14593 alc861_cfg_tbl); 14619 alc861_cfg_tbl);
14594 14620
14595 if (board_config < 0) { 14621 if (board_config < 0) {
14596 printk(KERN_INFO "hda_codec: Unknown model for %s, " 14622 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14597 "trying auto-probe from BIOS...\n", codec->chip_name); 14623 codec->chip_name);
14598 board_config = ALC861_AUTO; 14624 board_config = ALC861_AUTO;
14599 } 14625 }
14600 14626
@@ -14619,7 +14645,7 @@ static int patch_alc861(struct hda_codec *codec)
14619 } 14645 }
14620 14646
14621 if (board_config != ALC861_AUTO) 14647 if (board_config != ALC861_AUTO)
14622 setup_preset(spec, &alc861_presets[board_config]); 14648 setup_preset(codec, &alc861_presets[board_config]);
14623 14649
14624 spec->stream_analog_playback = &alc861_pcm_analog_playback; 14650 spec->stream_analog_playback = &alc861_pcm_analog_playback;
14625 spec->stream_analog_capture = &alc861_pcm_analog_capture; 14651 spec->stream_analog_capture = &alc861_pcm_analog_capture;
@@ -15022,12 +15048,15 @@ static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15022 HDA_AMP_MUTE, bits); 15048 HDA_AMP_MUTE, bits);
15023} 15049}
15024 15050
15025static void alc861vd_lenovo_init_hook(struct hda_codec *codec) 15051static void alc861vd_lenovo_setup(struct hda_codec *codec)
15026{ 15052{
15027 struct alc_spec *spec = codec->spec; 15053 struct alc_spec *spec = codec->spec;
15028
15029 spec->autocfg.hp_pins[0] = 0x1b; 15054 spec->autocfg.hp_pins[0] = 0x1b;
15030 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{
15031 alc_automute_amp(codec); 15060 alc_automute_amp(codec);
15032 alc861vd_lenovo_mic_automute(codec); 15061 alc861vd_lenovo_mic_automute(codec);
15033} 15062}
@@ -15091,13 +15120,12 @@ static struct hda_verb alc861vd_dallas_verbs[] = {
15091}; 15120};
15092 15121
15093/* toggle speaker-output according to the hp-jack state */ 15122/* toggle speaker-output according to the hp-jack state */
15094static void alc861vd_dallas_init_hook(struct hda_codec *codec) 15123static void alc861vd_dallas_setup(struct hda_codec *codec)
15095{ 15124{
15096 struct alc_spec *spec = codec->spec; 15125 struct alc_spec *spec = codec->spec;
15097 15126
15098 spec->autocfg.hp_pins[0] = 0x15; 15127 spec->autocfg.hp_pins[0] = 0x15;
15099 spec->autocfg.speaker_pins[0] = 0x14; 15128 spec->autocfg.speaker_pins[0] = 0x14;
15100 alc_automute_amp(codec);
15101} 15129}
15102 15130
15103#ifdef CONFIG_SND_HDA_POWER_SAVE 15131#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -15136,7 +15164,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15136 SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST), 15164 SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15137 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO), 15165 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15138 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/ 15166 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15139 SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS), 15167 SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15140 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO), 15168 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15141 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS), 15169 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15142 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG), 15170 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
@@ -15211,6 +15239,7 @@ static struct alc_config_preset alc861vd_presets[] = {
15211 .channel_mode = alc861vd_3stack_2ch_modes, 15239 .channel_mode = alc861vd_3stack_2ch_modes,
15212 .input_mux = &alc861vd_capture_source, 15240 .input_mux = &alc861vd_capture_source,
15213 .unsol_event = alc861vd_lenovo_unsol_event, 15241 .unsol_event = alc861vd_lenovo_unsol_event,
15242 .setup = alc861vd_lenovo_setup,
15214 .init_hook = alc861vd_lenovo_init_hook, 15243 .init_hook = alc861vd_lenovo_init_hook,
15215 }, 15244 },
15216 [ALC861VD_DALLAS] = { 15245 [ALC861VD_DALLAS] = {
@@ -15222,7 +15251,8 @@ static struct alc_config_preset alc861vd_presets[] = {
15222 .channel_mode = alc861vd_3stack_2ch_modes, 15251 .channel_mode = alc861vd_3stack_2ch_modes,
15223 .input_mux = &alc861vd_dallas_capture_source, 15252 .input_mux = &alc861vd_dallas_capture_source,
15224 .unsol_event = alc_automute_amp_unsol_event, 15253 .unsol_event = alc_automute_amp_unsol_event,
15225 .init_hook = alc861vd_dallas_init_hook, 15254 .setup = alc861vd_dallas_setup,
15255 .init_hook = alc_automute_amp,
15226 }, 15256 },
15227 [ALC861VD_HP] = { 15257 [ALC861VD_HP] = {
15228 .mixers = { alc861vd_hp_mixer }, 15258 .mixers = { alc861vd_hp_mixer },
@@ -15234,7 +15264,8 @@ static struct alc_config_preset alc861vd_presets[] = {
15234 .channel_mode = alc861vd_3stack_2ch_modes, 15264 .channel_mode = alc861vd_3stack_2ch_modes,
15235 .input_mux = &alc861vd_hp_capture_source, 15265 .input_mux = &alc861vd_hp_capture_source,
15236 .unsol_event = alc_automute_amp_unsol_event, 15266 .unsol_event = alc_automute_amp_unsol_event,
15237 .init_hook = alc861vd_dallas_init_hook, 15267 .setup = alc861vd_dallas_setup,
15268 .init_hook = alc_automute_amp,
15238 }, 15269 },
15239 [ALC660VD_ASUS_V1S] = { 15270 [ALC660VD_ASUS_V1S] = {
15240 .mixers = { alc861vd_lenovo_mixer }, 15271 .mixers = { alc861vd_lenovo_mixer },
@@ -15249,6 +15280,7 @@ static struct alc_config_preset alc861vd_presets[] = {
15249 .channel_mode = alc861vd_3stack_2ch_modes, 15280 .channel_mode = alc861vd_3stack_2ch_modes,
15250 .input_mux = &alc861vd_capture_source, 15281 .input_mux = &alc861vd_capture_source,
15251 .unsol_event = alc861vd_lenovo_unsol_event, 15282 .unsol_event = alc861vd_lenovo_unsol_event,
15283 .setup = alc861vd_lenovo_setup,
15252 .init_hook = alc861vd_lenovo_init_hook, 15284 .init_hook = alc861vd_lenovo_init_hook,
15253 }, 15285 },
15254}; 15286};
@@ -15256,6 +15288,13 @@ static struct alc_config_preset alc861vd_presets[] = {
15256/* 15288/*
15257 * BIOS auto configuration 15289 * BIOS auto configuration
15258 */ 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
15259static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec, 15298static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15260 hda_nid_t nid, int pin_type, int dac_idx) 15299 hda_nid_t nid, int pin_type, int dac_idx)
15261{ 15300{
@@ -15290,7 +15329,6 @@ static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15290 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); 15329 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15291} 15330}
15292 15331
15293#define alc861vd_is_input_pin(nid) alc880_is_input_pin(nid)
15294#define ALC861VD_PIN_CD_NID ALC880_PIN_CD_NID 15332#define ALC861VD_PIN_CD_NID ALC880_PIN_CD_NID
15295 15333
15296static void alc861vd_auto_init_analog_input(struct hda_codec *codec) 15334static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
@@ -15300,7 +15338,7 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15300 15338
15301 for (i = 0; i < AUTO_PIN_LAST; i++) { 15339 for (i = 0; i < AUTO_PIN_LAST; i++) {
15302 hda_nid_t nid = spec->autocfg.input_pins[i]; 15340 hda_nid_t nid = spec->autocfg.input_pins[i];
15303 if (alc861vd_is_input_pin(nid)) { 15341 if (alc_is_input_pin(codec, nid)) {
15304 alc_set_input_pin(codec, nid, i); 15342 alc_set_input_pin(codec, nid, i);
15305 if (nid != ALC861VD_PIN_CD_NID && 15343 if (nid != ALC861VD_PIN_CD_NID &&
15306 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 15344 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -15364,13 +15402,25 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15364 if (err < 0) 15402 if (err < 0)
15365 return err; 15403 return err;
15366 } else { 15404 } else {
15367 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);
15368 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 15415 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15369 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, 15416 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15370 HDA_OUTPUT)); 15417 HDA_OUTPUT));
15371 if (err < 0) 15418 if (err < 0)
15372 return err; 15419 return err;
15373 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);
15374 err = add_control(spec, ALC_CTL_BIND_MUTE, name, 15424 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15375 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, 15425 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15376 HDA_INPUT)); 15426 HDA_INPUT));
@@ -15463,7 +15513,7 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
15463 "Headphone"); 15513 "Headphone");
15464 if (err < 0) 15514 if (err < 0)
15465 return err; 15515 return err;
15466 err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg); 15516 err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
15467 if (err < 0) 15517 if (err < 0)
15468 return err; 15518 return err;
15469 15519
@@ -15517,8 +15567,8 @@ static int patch_alc861vd(struct hda_codec *codec)
15517 alc861vd_cfg_tbl); 15567 alc861vd_cfg_tbl);
15518 15568
15519 if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) { 15569 if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15520 printk(KERN_INFO "hda_codec: Unknown model for %s, " 15570 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15521 "trying auto-probe from BIOS...\n", codec->chip_name); 15571 codec->chip_name);
15522 board_config = ALC861VD_AUTO; 15572 board_config = ALC861VD_AUTO;
15523 } 15573 }
15524 15574
@@ -15543,7 +15593,7 @@ static int patch_alc861vd(struct hda_codec *codec)
15543 } 15593 }
15544 15594
15545 if (board_config != ALC861VD_AUTO) 15595 if (board_config != ALC861VD_AUTO)
15546 setup_preset(spec, &alc861vd_presets[board_config]); 15596 setup_preset(codec, &alc861vd_presets[board_config]);
15547 15597
15548 if (codec->vendor_id == 0x10ec0660) { 15598 if (codec->vendor_id == 0x10ec0660) {
15549 /* always turn on EAPD */ 15599 /* always turn on EAPD */
@@ -15556,11 +15606,14 @@ static int patch_alc861vd(struct hda_codec *codec)
15556 spec->stream_digital_playback = &alc861vd_pcm_digital_playback; 15606 spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15557 spec->stream_digital_capture = &alc861vd_pcm_digital_capture; 15607 spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15558 15608
15559 spec->adc_nids = alc861vd_adc_nids; 15609 if (!spec->adc_nids) {
15560 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids); 15610 spec->adc_nids = alc861vd_adc_nids;
15561 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;
15562 15615
15563 set_capture_mixer(spec); 15616 set_capture_mixer(codec);
15564 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 15617 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15565 15618
15566 spec->vmaster_nid = 0x02; 15619 spec->vmaster_nid = 0x02;
@@ -15601,9 +15654,9 @@ static hda_nid_t alc272_dac_nids[2] = {
15601 0x02, 0x03 15654 0x02, 0x03
15602}; 15655};
15603 15656
15604static hda_nid_t alc662_adc_nids[1] = { 15657static hda_nid_t alc662_adc_nids[2] = {
15605 /* ADC1-2 */ 15658 /* ADC1-2 */
15606 0x09, 15659 0x09, 0x08
15607}; 15660};
15608 15661
15609static hda_nid_t alc272_adc_nids[1] = { 15662static hda_nid_t alc272_adc_nids[1] = {
@@ -15611,7 +15664,7 @@ static hda_nid_t alc272_adc_nids[1] = {
15611 0x08, 15664 0x08,
15612}; 15665};
15613 15666
15614static hda_nid_t alc662_capsrc_nids[1] = { 0x22 }; 15667static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
15615static hda_nid_t alc272_capsrc_nids[1] = { 0x23 }; 15668static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15616 15669
15617 15670
@@ -15635,14 +15688,6 @@ static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15635 }, 15688 },
15636}; 15689};
15637 15690
15638static struct hda_input_mux alc662_eeepc_capture_source = {
15639 .num_items = 2,
15640 .items = {
15641 { "i-Mic", 0x1 },
15642 { "e-Mic", 0x0 },
15643 },
15644};
15645
15646static struct hda_input_mux alc663_capture_source = { 15691static struct hda_input_mux alc663_capture_source = {
15647 .num_items = 3, 15692 .num_items = 3,
15648 .items = { 15693 .items = {
@@ -15652,23 +15697,7 @@ static struct hda_input_mux alc663_capture_source = {
15652 }, 15697 },
15653}; 15698};
15654 15699
15655static struct hda_input_mux alc663_m51va_capture_source = { 15700#if 0 /* set to 1 for testing other input sources below */
15656 .num_items = 2,
15657 .items = {
15658 { "Ext-Mic", 0x0 },
15659 { "D-Mic", 0x9 },
15660 },
15661};
15662
15663#if 1 /* set to 0 for testing other input sources below */
15664static struct hda_input_mux alc272_nc10_capture_source = {
15665 .num_items = 2,
15666 .items = {
15667 { "Autoselect Mic", 0x0 },
15668 { "Internal Mic", 0x1 },
15669 },
15670};
15671#else
15672static struct hda_input_mux alc272_nc10_capture_source = { 15701static struct hda_input_mux alc272_nc10_capture_source = {
15673 .num_items = 16, 15702 .num_items = 16,
15674 .items = { 15703 .items = {
@@ -16337,47 +16366,44 @@ static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16337 alc662_lenovo_101e_ispeaker_automute(codec); 16366 alc662_lenovo_101e_ispeaker_automute(codec);
16338} 16367}
16339 16368
16340static void alc662_eeepc_mic_automute(struct hda_codec *codec)
16341{
16342 unsigned int present;
16343
16344 present = snd_hda_codec_read(codec, 0x18, 0,
16345 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16346 snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16347 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16348 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16349 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16350 snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16351 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16352 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16353 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16354}
16355
16356/* unsolicited event for HP jack sensing */ 16369/* unsolicited event for HP jack sensing */
16357static void alc662_eeepc_unsol_event(struct hda_codec *codec, 16370static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16358 unsigned int res) 16371 unsigned int res)
16359{ 16372{
16360 if ((res >> 26) == ALC880_MIC_EVENT) 16373 if ((res >> 26) == ALC880_MIC_EVENT)
16361 alc662_eeepc_mic_automute(codec); 16374 alc_mic_automute(codec);
16362 else 16375 else
16363 alc262_hippo_unsol_event(codec, res); 16376 alc262_hippo_unsol_event(codec, res);
16364} 16377}
16365 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
16366static void alc662_eeepc_inithook(struct hda_codec *codec) 16391static void alc662_eeepc_inithook(struct hda_codec *codec)
16367{ 16392{
16368 alc262_hippo1_init_hook(codec); 16393 alc262_hippo_automute(codec);
16369 alc662_eeepc_mic_automute(codec); 16394 alc_mic_automute(codec);
16370} 16395}
16371 16396
16372static void alc662_eeepc_ep20_inithook(struct hda_codec *codec) 16397static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
16373{ 16398{
16374 struct alc_spec *spec = codec->spec; 16399 struct alc_spec *spec = codec->spec;
16375 16400
16376 spec->autocfg.hp_pins[0] = 0x14; 16401 spec->autocfg.hp_pins[0] = 0x14;
16377 spec->autocfg.speaker_pins[0] = 0x1b; 16402 spec->autocfg.speaker_pins[0] = 0x1b;
16378 alc262_hippo_master_update(codec);
16379} 16403}
16380 16404
16405#define alc662_eeepc_ep20_inithook alc262_hippo_master_update
16406
16381static void alc663_m51va_speaker_automute(struct hda_codec *codec) 16407static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16382{ 16408{
16383 unsigned int present; 16409 unsigned int present;
@@ -16488,23 +16514,6 @@ static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16488 } 16514 }
16489} 16515}
16490 16516
16491static void alc663_m51va_mic_automute(struct hda_codec *codec)
16492{
16493 unsigned int present;
16494
16495 present = snd_hda_codec_read(codec, 0x18, 0,
16496 AC_VERB_GET_PIN_SENSE, 0)
16497 & AC_PINSENSE_PRESENCE;
16498 snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16499 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16500 snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16501 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16502 snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16503 0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16504 snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16505 0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16506}
16507
16508static void alc663_m51va_unsol_event(struct hda_codec *codec, 16517static void alc663_m51va_unsol_event(struct hda_codec *codec,
16509 unsigned int res) 16518 unsigned int res)
16510{ 16519{
@@ -16513,36 +16522,32 @@ static void alc663_m51va_unsol_event(struct hda_codec *codec,
16513 alc663_m51va_speaker_automute(codec); 16522 alc663_m51va_speaker_automute(codec);
16514 break; 16523 break;
16515 case ALC880_MIC_EVENT: 16524 case ALC880_MIC_EVENT:
16516 alc663_m51va_mic_automute(codec); 16525 alc_mic_automute(codec);
16517 break; 16526 break;
16518 } 16527 }
16519} 16528}
16520 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
16521static void alc663_m51va_inithook(struct hda_codec *codec) 16540static void alc663_m51va_inithook(struct hda_codec *codec)
16522{ 16541{
16523 alc663_m51va_speaker_automute(codec); 16542 alc663_m51va_speaker_automute(codec);
16524 alc663_m51va_mic_automute(codec); 16543 alc_mic_automute(codec);
16525} 16544}
16526 16545
16527/* ***************** Mode1 ******************************/ 16546/* ***************** Mode1 ******************************/
16528static void alc663_mode1_unsol_event(struct hda_codec *codec, 16547#define alc663_mode1_unsol_event alc663_m51va_unsol_event
16529 unsigned int res) 16548#define alc663_mode1_setup alc663_m51va_setup
16530{ 16549#define alc663_mode1_inithook alc663_m51va_inithook
16531 switch (res >> 26) {
16532 case ALC880_HP_EVENT:
16533 alc663_m51va_speaker_automute(codec);
16534 break;
16535 case ALC880_MIC_EVENT:
16536 alc662_eeepc_mic_automute(codec);
16537 break;
16538 }
16539}
16540 16550
16541static void alc663_mode1_inithook(struct hda_codec *codec)
16542{
16543 alc663_m51va_speaker_automute(codec);
16544 alc662_eeepc_mic_automute(codec);
16545}
16546/* ***************** Mode2 ******************************/ 16551/* ***************** Mode2 ******************************/
16547static void alc662_mode2_unsol_event(struct hda_codec *codec, 16552static void alc662_mode2_unsol_event(struct hda_codec *codec,
16548 unsigned int res) 16553 unsigned int res)
@@ -16552,15 +16557,17 @@ static void alc662_mode2_unsol_event(struct hda_codec *codec,
16552 alc662_f5z_speaker_automute(codec); 16557 alc662_f5z_speaker_automute(codec);
16553 break; 16558 break;
16554 case ALC880_MIC_EVENT: 16559 case ALC880_MIC_EVENT:
16555 alc662_eeepc_mic_automute(codec); 16560 alc_mic_automute(codec);
16556 break; 16561 break;
16557 } 16562 }
16558} 16563}
16559 16564
16565#define alc662_mode2_setup alc663_m51va_setup
16566
16560static void alc662_mode2_inithook(struct hda_codec *codec) 16567static void alc662_mode2_inithook(struct hda_codec *codec)
16561{ 16568{
16562 alc662_f5z_speaker_automute(codec); 16569 alc662_f5z_speaker_automute(codec);
16563 alc662_eeepc_mic_automute(codec); 16570 alc_mic_automute(codec);
16564} 16571}
16565/* ***************** Mode3 ******************************/ 16572/* ***************** Mode3 ******************************/
16566static void alc663_mode3_unsol_event(struct hda_codec *codec, 16573static void alc663_mode3_unsol_event(struct hda_codec *codec,
@@ -16571,15 +16578,17 @@ static void alc663_mode3_unsol_event(struct hda_codec *codec,
16571 alc663_two_hp_m1_speaker_automute(codec); 16578 alc663_two_hp_m1_speaker_automute(codec);
16572 break; 16579 break;
16573 case ALC880_MIC_EVENT: 16580 case ALC880_MIC_EVENT:
16574 alc662_eeepc_mic_automute(codec); 16581 alc_mic_automute(codec);
16575 break; 16582 break;
16576 } 16583 }
16577} 16584}
16578 16585
16586#define alc663_mode3_setup alc663_m51va_setup
16587
16579static void alc663_mode3_inithook(struct hda_codec *codec) 16588static void alc663_mode3_inithook(struct hda_codec *codec)
16580{ 16589{
16581 alc663_two_hp_m1_speaker_automute(codec); 16590 alc663_two_hp_m1_speaker_automute(codec);
16582 alc662_eeepc_mic_automute(codec); 16591 alc_mic_automute(codec);
16583} 16592}
16584/* ***************** Mode4 ******************************/ 16593/* ***************** Mode4 ******************************/
16585static void alc663_mode4_unsol_event(struct hda_codec *codec, 16594static void alc663_mode4_unsol_event(struct hda_codec *codec,
@@ -16590,15 +16599,17 @@ static void alc663_mode4_unsol_event(struct hda_codec *codec,
16590 alc663_21jd_two_speaker_automute(codec); 16599 alc663_21jd_two_speaker_automute(codec);
16591 break; 16600 break;
16592 case ALC880_MIC_EVENT: 16601 case ALC880_MIC_EVENT:
16593 alc662_eeepc_mic_automute(codec); 16602 alc_mic_automute(codec);
16594 break; 16603 break;
16595 } 16604 }
16596} 16605}
16597 16606
16607#define alc663_mode4_setup alc663_m51va_setup
16608
16598static void alc663_mode4_inithook(struct hda_codec *codec) 16609static void alc663_mode4_inithook(struct hda_codec *codec)
16599{ 16610{
16600 alc663_21jd_two_speaker_automute(codec); 16611 alc663_21jd_two_speaker_automute(codec);
16601 alc662_eeepc_mic_automute(codec); 16612 alc_mic_automute(codec);
16602} 16613}
16603/* ***************** Mode5 ******************************/ 16614/* ***************** Mode5 ******************************/
16604static void alc663_mode5_unsol_event(struct hda_codec *codec, 16615static void alc663_mode5_unsol_event(struct hda_codec *codec,
@@ -16609,15 +16620,17 @@ static void alc663_mode5_unsol_event(struct hda_codec *codec,
16609 alc663_15jd_two_speaker_automute(codec); 16620 alc663_15jd_two_speaker_automute(codec);
16610 break; 16621 break;
16611 case ALC880_MIC_EVENT: 16622 case ALC880_MIC_EVENT:
16612 alc662_eeepc_mic_automute(codec); 16623 alc_mic_automute(codec);
16613 break; 16624 break;
16614 } 16625 }
16615} 16626}
16616 16627
16628#define alc663_mode5_setup alc663_m51va_setup
16629
16617static void alc663_mode5_inithook(struct hda_codec *codec) 16630static void alc663_mode5_inithook(struct hda_codec *codec)
16618{ 16631{
16619 alc663_15jd_two_speaker_automute(codec); 16632 alc663_15jd_two_speaker_automute(codec);
16620 alc662_eeepc_mic_automute(codec); 16633 alc_mic_automute(codec);
16621} 16634}
16622/* ***************** Mode6 ******************************/ 16635/* ***************** Mode6 ******************************/
16623static void alc663_mode6_unsol_event(struct hda_codec *codec, 16636static void alc663_mode6_unsol_event(struct hda_codec *codec,
@@ -16628,15 +16641,17 @@ static void alc663_mode6_unsol_event(struct hda_codec *codec,
16628 alc663_two_hp_m2_speaker_automute(codec); 16641 alc663_two_hp_m2_speaker_automute(codec);
16629 break; 16642 break;
16630 case ALC880_MIC_EVENT: 16643 case ALC880_MIC_EVENT:
16631 alc662_eeepc_mic_automute(codec); 16644 alc_mic_automute(codec);
16632 break; 16645 break;
16633 } 16646 }
16634} 16647}
16635 16648
16649#define alc663_mode6_setup alc663_m51va_setup
16650
16636static void alc663_mode6_inithook(struct hda_codec *codec) 16651static void alc663_mode6_inithook(struct hda_codec *codec)
16637{ 16652{
16638 alc663_two_hp_m2_speaker_automute(codec); 16653 alc663_two_hp_m2_speaker_automute(codec);
16639 alc662_eeepc_mic_automute(codec); 16654 alc_mic_automute(codec);
16640} 16655}
16641 16656
16642static void alc663_g71v_hp_automute(struct hda_codec *codec) 16657static void alc663_g71v_hp_automute(struct hda_codec *codec)
@@ -16678,16 +16693,18 @@ static void alc663_g71v_unsol_event(struct hda_codec *codec,
16678 alc663_g71v_front_automute(codec); 16693 alc663_g71v_front_automute(codec);
16679 break; 16694 break;
16680 case ALC880_MIC_EVENT: 16695 case ALC880_MIC_EVENT:
16681 alc662_eeepc_mic_automute(codec); 16696 alc_mic_automute(codec);
16682 break; 16697 break;
16683 } 16698 }
16684} 16699}
16685 16700
16701#define alc663_g71v_setup alc663_m51va_setup
16702
16686static void alc663_g71v_inithook(struct hda_codec *codec) 16703static void alc663_g71v_inithook(struct hda_codec *codec)
16687{ 16704{
16688 alc663_g71v_front_automute(codec); 16705 alc663_g71v_front_automute(codec);
16689 alc663_g71v_hp_automute(codec); 16706 alc663_g71v_hp_automute(codec);
16690 alc662_eeepc_mic_automute(codec); 16707 alc_mic_automute(codec);
16691} 16708}
16692 16709
16693static void alc663_g50v_unsol_event(struct hda_codec *codec, 16710static void alc663_g50v_unsol_event(struct hda_codec *codec,
@@ -16698,15 +16715,17 @@ static void alc663_g50v_unsol_event(struct hda_codec *codec,
16698 alc663_m51va_speaker_automute(codec); 16715 alc663_m51va_speaker_automute(codec);
16699 break; 16716 break;
16700 case ALC880_MIC_EVENT: 16717 case ALC880_MIC_EVENT:
16701 alc662_eeepc_mic_automute(codec); 16718 alc_mic_automute(codec);
16702 break; 16719 break;
16703 } 16720 }
16704} 16721}
16705 16722
16723#define alc663_g50v_setup alc663_m51va_setup
16724
16706static void alc663_g50v_inithook(struct hda_codec *codec) 16725static void alc663_g50v_inithook(struct hda_codec *codec)
16707{ 16726{
16708 alc663_m51va_speaker_automute(codec); 16727 alc663_m51va_speaker_automute(codec);
16709 alc662_eeepc_mic_automute(codec); 16728 alc_mic_automute(codec);
16710} 16729}
16711 16730
16712static struct snd_kcontrol_new alc662_ecs_mixer[] = { 16731static struct snd_kcontrol_new alc662_ecs_mixer[] = {
@@ -16833,6 +16852,7 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
16833 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS), 16852 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16834 SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K", 16853 SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16835 ALC662_3ST_6ch_DIG), 16854 ALC662_3ST_6ch_DIG),
16855 SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB200", ALC663_ASUS_MODE4),
16836 SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10), 16856 SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16837 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L", 16857 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16838 ALC662_3ST_6ch_DIG), 16858 ALC662_3ST_6ch_DIG),
@@ -16910,8 +16930,8 @@ static struct alc_config_preset alc662_presets[] = {
16910 .dac_nids = alc662_dac_nids, 16930 .dac_nids = alc662_dac_nids,
16911 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16931 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16912 .channel_mode = alc662_3ST_2ch_modes, 16932 .channel_mode = alc662_3ST_2ch_modes,
16913 .input_mux = &alc662_eeepc_capture_source,
16914 .unsol_event = alc662_eeepc_unsol_event, 16933 .unsol_event = alc662_eeepc_unsol_event,
16934 .setup = alc662_eeepc_setup,
16915 .init_hook = alc662_eeepc_inithook, 16935 .init_hook = alc662_eeepc_inithook,
16916 }, 16936 },
16917 [ALC662_ASUS_EEEPC_EP20] = { 16937 [ALC662_ASUS_EEEPC_EP20] = {
@@ -16925,6 +16945,7 @@ static struct alc_config_preset alc662_presets[] = {
16925 .channel_mode = alc662_3ST_6ch_modes, 16945 .channel_mode = alc662_3ST_6ch_modes,
16926 .input_mux = &alc662_lenovo_101e_capture_source, 16946 .input_mux = &alc662_lenovo_101e_capture_source,
16927 .unsol_event = alc662_eeepc_unsol_event, 16947 .unsol_event = alc662_eeepc_unsol_event,
16948 .setup = alc662_eeepc_ep20_setup,
16928 .init_hook = alc662_eeepc_ep20_inithook, 16949 .init_hook = alc662_eeepc_ep20_inithook,
16929 }, 16950 },
16930 [ALC662_ECS] = { 16951 [ALC662_ECS] = {
@@ -16935,8 +16956,8 @@ static struct alc_config_preset alc662_presets[] = {
16935 .dac_nids = alc662_dac_nids, 16956 .dac_nids = alc662_dac_nids,
16936 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16957 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16937 .channel_mode = alc662_3ST_2ch_modes, 16958 .channel_mode = alc662_3ST_2ch_modes,
16938 .input_mux = &alc662_eeepc_capture_source,
16939 .unsol_event = alc662_eeepc_unsol_event, 16959 .unsol_event = alc662_eeepc_unsol_event,
16960 .setup = alc662_eeepc_setup,
16940 .init_hook = alc662_eeepc_inithook, 16961 .init_hook = alc662_eeepc_inithook,
16941 }, 16962 },
16942 [ALC663_ASUS_M51VA] = { 16963 [ALC663_ASUS_M51VA] = {
@@ -16947,8 +16968,8 @@ static struct alc_config_preset alc662_presets[] = {
16947 .dig_out_nid = ALC662_DIGOUT_NID, 16968 .dig_out_nid = ALC662_DIGOUT_NID,
16948 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16969 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16949 .channel_mode = alc662_3ST_2ch_modes, 16970 .channel_mode = alc662_3ST_2ch_modes,
16950 .input_mux = &alc663_m51va_capture_source,
16951 .unsol_event = alc663_m51va_unsol_event, 16971 .unsol_event = alc663_m51va_unsol_event,
16972 .setup = alc663_m51va_setup,
16952 .init_hook = alc663_m51va_inithook, 16973 .init_hook = alc663_m51va_inithook,
16953 }, 16974 },
16954 [ALC663_ASUS_G71V] = { 16975 [ALC663_ASUS_G71V] = {
@@ -16959,8 +16980,8 @@ static struct alc_config_preset alc662_presets[] = {
16959 .dig_out_nid = ALC662_DIGOUT_NID, 16980 .dig_out_nid = ALC662_DIGOUT_NID,
16960 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16981 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16961 .channel_mode = alc662_3ST_2ch_modes, 16982 .channel_mode = alc662_3ST_2ch_modes,
16962 .input_mux = &alc662_eeepc_capture_source,
16963 .unsol_event = alc663_g71v_unsol_event, 16983 .unsol_event = alc663_g71v_unsol_event,
16984 .setup = alc663_g71v_setup,
16964 .init_hook = alc663_g71v_inithook, 16985 .init_hook = alc663_g71v_inithook,
16965 }, 16986 },
16966 [ALC663_ASUS_H13] = { 16987 [ALC663_ASUS_H13] = {
@@ -16970,7 +16991,6 @@ static struct alc_config_preset alc662_presets[] = {
16970 .dac_nids = alc662_dac_nids, 16991 .dac_nids = alc662_dac_nids,
16971 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 16992 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16972 .channel_mode = alc662_3ST_2ch_modes, 16993 .channel_mode = alc662_3ST_2ch_modes,
16973 .input_mux = &alc663_m51va_capture_source,
16974 .unsol_event = alc663_m51va_unsol_event, 16994 .unsol_event = alc663_m51va_unsol_event,
16975 .init_hook = alc663_m51va_inithook, 16995 .init_hook = alc663_m51va_inithook,
16976 }, 16996 },
@@ -16984,6 +17004,7 @@ static struct alc_config_preset alc662_presets[] = {
16984 .channel_mode = alc662_3ST_6ch_modes, 17004 .channel_mode = alc662_3ST_6ch_modes,
16985 .input_mux = &alc663_capture_source, 17005 .input_mux = &alc663_capture_source,
16986 .unsol_event = alc663_g50v_unsol_event, 17006 .unsol_event = alc663_g50v_unsol_event,
17007 .setup = alc663_g50v_setup,
16987 .init_hook = alc663_g50v_inithook, 17008 .init_hook = alc663_g50v_inithook,
16988 }, 17009 },
16989 [ALC663_ASUS_MODE1] = { 17010 [ALC663_ASUS_MODE1] = {
@@ -16997,8 +17018,8 @@ static struct alc_config_preset alc662_presets[] = {
16997 .dig_out_nid = ALC662_DIGOUT_NID, 17018 .dig_out_nid = ALC662_DIGOUT_NID,
16998 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17019 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16999 .channel_mode = alc662_3ST_2ch_modes, 17020 .channel_mode = alc662_3ST_2ch_modes,
17000 .input_mux = &alc662_eeepc_capture_source,
17001 .unsol_event = alc663_mode1_unsol_event, 17021 .unsol_event = alc663_mode1_unsol_event,
17022 .setup = alc663_mode1_setup,
17002 .init_hook = alc663_mode1_inithook, 17023 .init_hook = alc663_mode1_inithook,
17003 }, 17024 },
17004 [ALC662_ASUS_MODE2] = { 17025 [ALC662_ASUS_MODE2] = {
@@ -17011,8 +17032,8 @@ static struct alc_config_preset alc662_presets[] = {
17011 .dig_out_nid = ALC662_DIGOUT_NID, 17032 .dig_out_nid = ALC662_DIGOUT_NID,
17012 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17033 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17013 .channel_mode = alc662_3ST_2ch_modes, 17034 .channel_mode = alc662_3ST_2ch_modes,
17014 .input_mux = &alc662_eeepc_capture_source,
17015 .unsol_event = alc662_mode2_unsol_event, 17035 .unsol_event = alc662_mode2_unsol_event,
17036 .setup = alc662_mode2_setup,
17016 .init_hook = alc662_mode2_inithook, 17037 .init_hook = alc662_mode2_inithook,
17017 }, 17038 },
17018 [ALC663_ASUS_MODE3] = { 17039 [ALC663_ASUS_MODE3] = {
@@ -17026,8 +17047,8 @@ static struct alc_config_preset alc662_presets[] = {
17026 .dig_out_nid = ALC662_DIGOUT_NID, 17047 .dig_out_nid = ALC662_DIGOUT_NID,
17027 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17048 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17028 .channel_mode = alc662_3ST_2ch_modes, 17049 .channel_mode = alc662_3ST_2ch_modes,
17029 .input_mux = &alc662_eeepc_capture_source,
17030 .unsol_event = alc663_mode3_unsol_event, 17050 .unsol_event = alc663_mode3_unsol_event,
17051 .setup = alc663_mode3_setup,
17031 .init_hook = alc663_mode3_inithook, 17052 .init_hook = alc663_mode3_inithook,
17032 }, 17053 },
17033 [ALC663_ASUS_MODE4] = { 17054 [ALC663_ASUS_MODE4] = {
@@ -17041,8 +17062,8 @@ static struct alc_config_preset alc662_presets[] = {
17041 .dig_out_nid = ALC662_DIGOUT_NID, 17062 .dig_out_nid = ALC662_DIGOUT_NID,
17042 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17063 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17043 .channel_mode = alc662_3ST_2ch_modes, 17064 .channel_mode = alc662_3ST_2ch_modes,
17044 .input_mux = &alc662_eeepc_capture_source,
17045 .unsol_event = alc663_mode4_unsol_event, 17065 .unsol_event = alc663_mode4_unsol_event,
17066 .setup = alc663_mode4_setup,
17046 .init_hook = alc663_mode4_inithook, 17067 .init_hook = alc663_mode4_inithook,
17047 }, 17068 },
17048 [ALC663_ASUS_MODE5] = { 17069 [ALC663_ASUS_MODE5] = {
@@ -17056,8 +17077,8 @@ static struct alc_config_preset alc662_presets[] = {
17056 .dig_out_nid = ALC662_DIGOUT_NID, 17077 .dig_out_nid = ALC662_DIGOUT_NID,
17057 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17078 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17058 .channel_mode = alc662_3ST_2ch_modes, 17079 .channel_mode = alc662_3ST_2ch_modes,
17059 .input_mux = &alc662_eeepc_capture_source,
17060 .unsol_event = alc663_mode5_unsol_event, 17080 .unsol_event = alc663_mode5_unsol_event,
17081 .setup = alc663_mode5_setup,
17061 .init_hook = alc663_mode5_inithook, 17082 .init_hook = alc663_mode5_inithook,
17062 }, 17083 },
17063 [ALC663_ASUS_MODE6] = { 17084 [ALC663_ASUS_MODE6] = {
@@ -17071,8 +17092,8 @@ static struct alc_config_preset alc662_presets[] = {
17071 .dig_out_nid = ALC662_DIGOUT_NID, 17092 .dig_out_nid = ALC662_DIGOUT_NID,
17072 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17093 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17073 .channel_mode = alc662_3ST_2ch_modes, 17094 .channel_mode = alc662_3ST_2ch_modes,
17074 .input_mux = &alc662_eeepc_capture_source,
17075 .unsol_event = alc663_mode6_unsol_event, 17095 .unsol_event = alc663_mode6_unsol_event,
17096 .setup = alc663_mode6_setup,
17076 .init_hook = alc663_mode6_inithook, 17097 .init_hook = alc663_mode6_inithook,
17077 }, 17098 },
17078 [ALC272_DELL] = { 17099 [ALC272_DELL] = {
@@ -17086,8 +17107,8 @@ static struct alc_config_preset alc662_presets[] = {
17086 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids), 17107 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17087 .capsrc_nids = alc272_capsrc_nids, 17108 .capsrc_nids = alc272_capsrc_nids,
17088 .channel_mode = alc662_3ST_2ch_modes, 17109 .channel_mode = alc662_3ST_2ch_modes,
17089 .input_mux = &alc663_m51va_capture_source,
17090 .unsol_event = alc663_m51va_unsol_event, 17110 .unsol_event = alc663_m51va_unsol_event,
17111 .setup = alc663_m51va_setup,
17091 .init_hook = alc663_m51va_inithook, 17112 .init_hook = alc663_m51va_inithook,
17092 }, 17113 },
17093 [ALC272_DELL_ZM1] = { 17114 [ALC272_DELL_ZM1] = {
@@ -17098,11 +17119,11 @@ static struct alc_config_preset alc662_presets[] = {
17098 .dac_nids = alc662_dac_nids, 17119 .dac_nids = alc662_dac_nids,
17099 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17120 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17100 .adc_nids = alc662_adc_nids, 17121 .adc_nids = alc662_adc_nids,
17101 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids), 17122 .num_adc_nids = 1,
17102 .capsrc_nids = alc662_capsrc_nids, 17123 .capsrc_nids = alc662_capsrc_nids,
17103 .channel_mode = alc662_3ST_2ch_modes, 17124 .channel_mode = alc662_3ST_2ch_modes,
17104 .input_mux = &alc663_m51va_capture_source,
17105 .unsol_event = alc663_m51va_unsol_event, 17125 .unsol_event = alc663_m51va_unsol_event,
17126 .setup = alc663_m51va_setup,
17106 .init_hook = alc663_m51va_inithook, 17127 .init_hook = alc663_m51va_inithook,
17107 }, 17128 },
17108 [ALC272_SAMSUNG_NC10] = { 17129 [ALC272_SAMSUNG_NC10] = {
@@ -17113,8 +17134,9 @@ static struct alc_config_preset alc662_presets[] = {
17113 .dac_nids = alc272_dac_nids, 17134 .dac_nids = alc272_dac_nids,
17114 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 17135 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17115 .channel_mode = alc662_3ST_2ch_modes, 17136 .channel_mode = alc662_3ST_2ch_modes,
17116 .input_mux = &alc272_nc10_capture_source, 17137 /*.input_mux = &alc272_nc10_capture_source,*/
17117 .unsol_event = alc663_mode4_unsol_event, 17138 .unsol_event = alc663_mode4_unsol_event,
17139 .setup = alc663_mode4_setup,
17118 .init_hook = alc663_mode4_inithook, 17140 .init_hook = alc663_mode4_inithook,
17119 }, 17141 },
17120}; 17142};
@@ -17124,58 +17146,145 @@ static struct alc_config_preset alc662_presets[] = {
17124 * BIOS auto configuration 17146 * BIOS auto configuration
17125 */ 17147 */
17126 17148
17149/* convert from MIX nid to DAC */
17150static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
17151{
17152 if (nid == 0x0f)
17153 return 0x02;
17154 else if (nid >= 0x0c && nid <= 0x0e)
17155 return nid - 0x0c + 0x02;
17156 else
17157 return 0;
17158}
17159
17160/* get MIX nid connected to the given pin targeted to DAC */
17161static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
17162 hda_nid_t dac)
17163{
17164 hda_nid_t mix[4];
17165 int i, num;
17166
17167 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
17168 for (i = 0; i < num; i++) {
17169 if (alc662_mix_to_dac(mix[i]) == dac)
17170 return mix[i];
17171 }
17172 return 0;
17173}
17174
17175/* look for an empty DAC slot */
17176static hda_nid_t alc662_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
17177{
17178 struct alc_spec *spec = codec->spec;
17179 hda_nid_t srcs[5];
17180 int i, j, num;
17181
17182 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
17183 if (num < 0)
17184 return 0;
17185 for (i = 0; i < num; i++) {
17186 hda_nid_t nid = alc662_mix_to_dac(srcs[i]);
17187 if (!nid)
17188 continue;
17189 for (j = 0; j < spec->multiout.num_dacs; j++)
17190 if (spec->multiout.dac_nids[j] == nid)
17191 break;
17192 if (j >= spec->multiout.num_dacs)
17193 return nid;
17194 }
17195 return 0;
17196}
17197
17198/* fill in the dac_nids table from the parsed pin configuration */
17199static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17200 const struct auto_pin_cfg *cfg)
17201{
17202 struct alc_spec *spec = codec->spec;
17203 int i;
17204 hda_nid_t dac;
17205
17206 spec->multiout.dac_nids = spec->private_dac_nids;
17207 for (i = 0; i < cfg->line_outs; i++) {
17208 dac = alc662_look_for_dac(codec, cfg->line_out_pins[i]);
17209 if (!dac)
17210 continue;
17211 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
17212 }
17213 return 0;
17214}
17215
17216static int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17217 hda_nid_t nid, unsigned int chs)
17218{
17219 char name[32];
17220 sprintf(name, "%s Playback Volume", pfx);
17221 return add_control(spec, ALC_CTL_WIDGET_VOL, name,
17222 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17223}
17224
17225static int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17226 hda_nid_t nid, unsigned int chs)
17227{
17228 char name[32];
17229 sprintf(name, "%s Playback Switch", pfx);
17230 return add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17231 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17232}
17233
17234#define alc662_add_stereo_vol(spec, pfx, nid) \
17235 alc662_add_vol_ctl(spec, pfx, nid, 3)
17236#define alc662_add_stereo_sw(spec, pfx, nid) \
17237 alc662_add_sw_ctl(spec, pfx, nid, 3)
17238
17127/* add playback controls from the parsed DAC table */ 17239/* add playback controls from the parsed DAC table */
17128static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec, 17240static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
17129 const struct auto_pin_cfg *cfg) 17241 const struct auto_pin_cfg *cfg)
17130{ 17242{
17131 char name[32]; 17243 struct alc_spec *spec = codec->spec;
17132 static const char *chname[4] = { 17244 static const char *chname[4] = {
17133 "Front", "Surround", NULL /*CLFE*/, "Side" 17245 "Front", "Surround", NULL /*CLFE*/, "Side"
17134 }; 17246 };
17135 hda_nid_t nid; 17247 hda_nid_t nid, mix;
17136 int i, err; 17248 int i, err;
17137 17249
17138 for (i = 0; i < cfg->line_outs; i++) { 17250 for (i = 0; i < cfg->line_outs; i++) {
17139 if (!spec->multiout.dac_nids[i]) 17251 nid = spec->multiout.dac_nids[i];
17252 if (!nid)
17253 continue;
17254 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
17255 if (!mix)
17140 continue; 17256 continue;
17141 nid = alc880_idx_to_dac(i);
17142 if (i == 2) { 17257 if (i == 2) {
17143 /* Center/LFE */ 17258 /* Center/LFE */
17144 err = add_control(spec, ALC_CTL_WIDGET_VOL, 17259 err = alc662_add_vol_ctl(spec, "Center", nid, 1);
17145 "Center Playback Volume",
17146 HDA_COMPOSE_AMP_VAL(nid, 1, 0,
17147 HDA_OUTPUT));
17148 if (err < 0) 17260 if (err < 0)
17149 return err; 17261 return err;
17150 err = add_control(spec, ALC_CTL_WIDGET_VOL, 17262 err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
17151 "LFE Playback Volume",
17152 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
17153 HDA_OUTPUT));
17154 if (err < 0) 17263 if (err < 0)
17155 return err; 17264 return err;
17156 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 17265 err = alc662_add_sw_ctl(spec, "Center", mix, 1);
17157 "Center Playback Switch",
17158 HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
17159 HDA_INPUT));
17160 if (err < 0) 17266 if (err < 0)
17161 return err; 17267 return err;
17162 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 17268 err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
17163 "LFE Playback Switch",
17164 HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
17165 HDA_INPUT));
17166 if (err < 0) 17269 if (err < 0)
17167 return err; 17270 return err;
17168 } else { 17271 } else {
17169 sprintf(name, "%s Playback Volume", chname[i]); 17272 const char *pfx;
17170 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 17273 if (cfg->line_outs == 1 &&
17171 HDA_COMPOSE_AMP_VAL(nid, 3, 0, 17274 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
17172 HDA_OUTPUT)); 17275 if (cfg->hp_outs)
17276 pfx = "Speaker";
17277 else
17278 pfx = "PCM";
17279 } else
17280 pfx = chname[i];
17281 err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17173 if (err < 0) 17282 if (err < 0)
17174 return err; 17283 return err;
17175 sprintf(name, "%s Playback Switch", chname[i]); 17284 if (cfg->line_outs == 1 &&
17176 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 17285 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
17177 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i), 17286 pfx = "Speaker";
17178 3, 0, HDA_INPUT)); 17287 err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17179 if (err < 0) 17288 if (err < 0)
17180 return err; 17289 return err;
17181 } 17290 }
@@ -17184,139 +17293,75 @@ static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
17184} 17293}
17185 17294
17186/* add playback controls for speaker and HP outputs */ 17295/* add playback controls for speaker and HP outputs */
17187static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin, 17296/* return DAC nid if any new DAC is assigned */
17297static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17188 const char *pfx) 17298 const char *pfx)
17189{ 17299{
17190 hda_nid_t nid; 17300 struct alc_spec *spec = codec->spec;
17301 hda_nid_t nid, mix;
17191 int err; 17302 int err;
17192 char name[32];
17193 17303
17194 if (!pin) 17304 if (!pin)
17195 return 0; 17305 return 0;
17196 17306 nid = alc662_look_for_dac(codec, pin);
17197 if (pin == 0x17) { 17307 if (!nid) {
17198 /* ALC663 has a mono output pin on 0x17 */ 17308 char name[32];
17199 sprintf(name, "%s Playback Switch", pfx); 17309 /* the corresponding DAC is already occupied */
17200 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 17310 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17201 HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT)); 17311 return 0; /* no way */
17202 return err; 17312 /* create a switch only */
17203 }
17204
17205 if (alc880_is_fixed_pin(pin)) {
17206 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17207 /* printk(KERN_DEBUG "DAC nid=%x\n",nid); */
17208 /* specify the DAC as the extra output */
17209 if (!spec->multiout.hp_nid)
17210 spec->multiout.hp_nid = nid;
17211 else
17212 spec->multiout.extra_out_nid[0] = nid;
17213 /* control HP volume/switch on the output mixer amp */
17214 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17215 sprintf(name, "%s Playback Volume", pfx);
17216 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
17217 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
17218 if (err < 0)
17219 return err;
17220 sprintf(name, "%s Playback Switch", pfx);
17221 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
17222 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
17223 if (err < 0)
17224 return err;
17225 } else if (alc880_is_multi_pin(pin)) {
17226 /* set manual connection */
17227 /* we have only a switch on HP-out PIN */
17228 sprintf(name, "%s Playback Switch", pfx); 17313 sprintf(name, "%s Playback Switch", pfx);
17229 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 17314 return add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17230 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 17315 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17231 if (err < 0)
17232 return err;
17233 } 17316 }
17234 return 0;
17235}
17236
17237/* return the index of the src widget from the connection list of the nid.
17238 * return -1 if not found
17239 */
17240static int alc662_input_pin_idx(struct hda_codec *codec, hda_nid_t nid,
17241 hda_nid_t src)
17242{
17243 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
17244 int i, conns;
17245
17246 conns = snd_hda_get_connections(codec, nid, conn_list,
17247 ARRAY_SIZE(conn_list));
17248 if (conns < 0)
17249 return -1;
17250 for (i = 0; i < conns; i++)
17251 if (conn_list[i] == src)
17252 return i;
17253 return -1;
17254}
17255 17317
17256static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid) 17318 mix = alc662_dac_to_mix(codec, pin, nid);
17257{ 17319 if (!mix)
17258 unsigned int pincap = snd_hda_query_pin_caps(codec, nid); 17320 return 0;
17259 return (pincap & AC_PINCAP_IN) != 0; 17321 err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17322 if (err < 0)
17323 return err;
17324 err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17325 if (err < 0)
17326 return err;
17327 return nid;
17260} 17328}
17261 17329
17262/* create playback/capture controls for input pins */ 17330/* create playback/capture controls for input pins */
17263static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec, 17331#define alc662_auto_create_input_ctls \
17264 const struct auto_pin_cfg *cfg) 17332 alc880_auto_create_input_ctls
17265{
17266 struct alc_spec *spec = codec->spec;
17267 struct hda_input_mux *imux = &spec->private_imux[0];
17268 int i, err, idx;
17269
17270 for (i = 0; i < AUTO_PIN_LAST; i++) {
17271 if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
17272 idx = alc662_input_pin_idx(codec, 0x0b,
17273 cfg->input_pins[i]);
17274 if (idx >= 0) {
17275 err = new_analog_input(spec, cfg->input_pins[i],
17276 auto_pin_cfg_labels[i],
17277 idx, 0x0b);
17278 if (err < 0)
17279 return err;
17280 }
17281 idx = alc662_input_pin_idx(codec, 0x22,
17282 cfg->input_pins[i]);
17283 if (idx >= 0) {
17284 imux->items[imux->num_items].label =
17285 auto_pin_cfg_labels[i];
17286 imux->items[imux->num_items].index = idx;
17287 imux->num_items++;
17288 }
17289 }
17290 }
17291 return 0;
17292}
17293 17333
17294static void alc662_auto_set_output_and_unmute(struct hda_codec *codec, 17334static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17295 hda_nid_t nid, int pin_type, 17335 hda_nid_t nid, int pin_type,
17296 int dac_idx) 17336 hda_nid_t dac)
17297{ 17337{
17338 int i, num;
17339 hda_nid_t srcs[4];
17340
17298 alc_set_pin_output(codec, nid, pin_type); 17341 alc_set_pin_output(codec, nid, pin_type);
17299 /* need the manual connection? */ 17342 /* need the manual connection? */
17300 if (alc880_is_multi_pin(nid)) { 17343 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
17301 struct alc_spec *spec = codec->spec; 17344 if (num <= 1)
17302 int idx = alc880_multi_pin_idx(nid); 17345 return;
17303 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0, 17346 for (i = 0; i < num; i++) {
17304 AC_VERB_SET_CONNECT_SEL, 17347 if (alc662_mix_to_dac(srcs[i]) != dac)
17305 alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx])); 17348 continue;
17349 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
17350 return;
17306 } 17351 }
17307} 17352}
17308 17353
17309static void alc662_auto_init_multi_out(struct hda_codec *codec) 17354static void alc662_auto_init_multi_out(struct hda_codec *codec)
17310{ 17355{
17311 struct alc_spec *spec = codec->spec; 17356 struct alc_spec *spec = codec->spec;
17357 int pin_type = get_pin_type(spec->autocfg.line_out_type);
17312 int i; 17358 int i;
17313 17359
17314 for (i = 0; i <= HDA_SIDE; i++) { 17360 for (i = 0; i <= HDA_SIDE; i++) {
17315 hda_nid_t nid = spec->autocfg.line_out_pins[i]; 17361 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17316 int pin_type = get_pin_type(spec->autocfg.line_out_type);
17317 if (nid) 17362 if (nid)
17318 alc662_auto_set_output_and_unmute(codec, nid, pin_type, 17363 alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17319 i); 17364 spec->multiout.dac_nids[i]);
17320 } 17365 }
17321} 17366}
17322 17367
@@ -17326,12 +17371,13 @@ static void alc662_auto_init_hp_out(struct hda_codec *codec)
17326 hda_nid_t pin; 17371 hda_nid_t pin;
17327 17372
17328 pin = spec->autocfg.hp_pins[0]; 17373 pin = spec->autocfg.hp_pins[0];
17329 if (pin) /* connect to front */ 17374 if (pin)
17330 /* use dac 0 */ 17375 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
17331 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 17376 spec->multiout.hp_nid);
17332 pin = spec->autocfg.speaker_pins[0]; 17377 pin = spec->autocfg.speaker_pins[0];
17333 if (pin) 17378 if (pin)
17334 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); 17379 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
17380 spec->multiout.extra_out_nid[0]);
17335} 17381}
17336 17382
17337#define ALC662_PIN_CD_NID ALC880_PIN_CD_NID 17383#define ALC662_PIN_CD_NID ALC880_PIN_CD_NID
@@ -17343,7 +17389,7 @@ static void alc662_auto_init_analog_input(struct hda_codec *codec)
17343 17389
17344 for (i = 0; i < AUTO_PIN_LAST; i++) { 17390 for (i = 0; i < AUTO_PIN_LAST; i++) {
17345 hda_nid_t nid = spec->autocfg.input_pins[i]; 17391 hda_nid_t nid = spec->autocfg.input_pins[i];
17346 if (alc662_is_input_pin(codec, nid)) { 17392 if (alc_is_input_pin(codec, nid)) {
17347 alc_set_input_pin(codec, nid, i); 17393 alc_set_input_pin(codec, nid, i);
17348 if (nid != ALC662_PIN_CD_NID && 17394 if (nid != ALC662_PIN_CD_NID &&
17349 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 17395 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -17369,22 +17415,26 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
17369 if (!spec->autocfg.line_outs) 17415 if (!spec->autocfg.line_outs)
17370 return 0; /* can't find valid BIOS pin config */ 17416 return 0; /* can't find valid BIOS pin config */
17371 17417
17372 err = alc880_auto_fill_dac_nids(spec, &spec->autocfg); 17418 err = alc662_auto_fill_dac_nids(codec, &spec->autocfg);
17373 if (err < 0) 17419 if (err < 0)
17374 return err; 17420 return err;
17375 err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg); 17421 err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
17376 if (err < 0) 17422 if (err < 0)
17377 return err; 17423 return err;
17378 err = alc662_auto_create_extra_out(spec, 17424 err = alc662_auto_create_extra_out(codec,
17379 spec->autocfg.speaker_pins[0], 17425 spec->autocfg.speaker_pins[0],
17380 "Speaker"); 17426 "Speaker");
17381 if (err < 0) 17427 if (err < 0)
17382 return err; 17428 return err;
17383 err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0], 17429 if (err)
17430 spec->multiout.extra_out_nid[0] = err;
17431 err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
17384 "Headphone"); 17432 "Headphone");
17385 if (err < 0) 17433 if (err < 0)
17386 return err; 17434 return err;
17387 err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg); 17435 if (err)
17436 spec->multiout.hp_nid = err;
17437 err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
17388 if (err < 0) 17438 if (err < 0)
17389 return err; 17439 return err;
17390 17440
@@ -17441,8 +17491,8 @@ static int patch_alc662(struct hda_codec *codec)
17441 alc662_models, 17491 alc662_models,
17442 alc662_cfg_tbl); 17492 alc662_cfg_tbl);
17443 if (board_config < 0) { 17493 if (board_config < 0) {
17444 printk(KERN_INFO "hda_codec: Unknown model for %s, " 17494 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17445 "trying auto-probe from BIOS...\n", codec->chip_name); 17495 codec->chip_name);
17446 board_config = ALC662_AUTO; 17496 board_config = ALC662_AUTO;
17447 } 17497 }
17448 17498
@@ -17467,7 +17517,7 @@ static int patch_alc662(struct hda_codec *codec)
17467 } 17517 }
17468 17518
17469 if (board_config != ALC662_AUTO) 17519 if (board_config != ALC662_AUTO)
17470 setup_preset(spec, &alc662_presets[board_config]); 17520 setup_preset(codec, &alc662_presets[board_config]);
17471 17521
17472 spec->stream_analog_playback = &alc662_pcm_analog_playback; 17522 spec->stream_analog_playback = &alc662_pcm_analog_playback;
17473 spec->stream_analog_capture = &alc662_pcm_analog_capture; 17523 spec->stream_analog_capture = &alc662_pcm_analog_capture;
@@ -17475,12 +17525,15 @@ static int patch_alc662(struct hda_codec *codec)
17475 spec->stream_digital_playback = &alc662_pcm_digital_playback; 17525 spec->stream_digital_playback = &alc662_pcm_digital_playback;
17476 spec->stream_digital_capture = &alc662_pcm_digital_capture; 17526 spec->stream_digital_capture = &alc662_pcm_digital_capture;
17477 17527
17478 spec->adc_nids = alc662_adc_nids; 17528 if (!spec->adc_nids) {
17479 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids); 17529 spec->adc_nids = alc662_adc_nids;
17480 spec->capsrc_nids = alc662_capsrc_nids; 17530 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17531 }
17532 if (!spec->capsrc_nids)
17533 spec->capsrc_nids = alc662_capsrc_nids;
17481 17534
17482 if (!spec->cap_mixer) 17535 if (!spec->cap_mixer)
17483 set_capture_mixer(spec); 17536 set_capture_mixer(codec);
17484 if (codec->vendor_id == 0x10ec0662) 17537 if (codec->vendor_id == 0x10ec0662)
17485 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 17538 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17486 else 17539 else
@@ -17516,23 +17569,23 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
17516 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, 17569 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17517 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, 17570 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17518 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", 17571 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17519 .patch = patch_alc883 }, 17572 .patch = patch_alc882 },
17520 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", 17573 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17521 .patch = patch_alc662 }, 17574 .patch = patch_alc662 },
17522 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, 17575 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17523 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, 17576 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17524 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, 17577 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17525 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 }, 17578 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
17526 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", 17579 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17527 .patch = patch_alc882 }, /* should be patch_alc883() in future */ 17580 .patch = patch_alc882 },
17528 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", 17581 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17529 .patch = patch_alc882 }, /* should be patch_alc883() in future */ 17582 .patch = patch_alc882 },
17530 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, 17583 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17531 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 }, 17584 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17532 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", 17585 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17533 .patch = patch_alc883 }, 17586 .patch = patch_alc882 },
17534 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 }, 17587 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
17535 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 }, 17588 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17536 {} /* terminator */ 17589 {} /* terminator */
17537}; 17590};
17538 17591
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 14f3c3e0f62d..a9b26828a651 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 signed char mux_idx;
186 signed 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,239 @@ 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 }
3430 }
3431
3432 return 0;
3433}
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;
3617 } 3454 }
3455 return 0;
3456}
3618 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 i = get_connection_index(codec, spec->mux_nids[0], pin);
3473 if (i < 0)
3474 return -1;
3475 mic->mux_idx = i;
3476 mic->dmux_idx = -1;
3477 if (spec->dmux_nids)
3478 mic->dmux_idx = get_connection_index(codec,
3479 spec->dmux_nids[0],
3480 spec->mux_nids[0]);
3481 } else if (spec->dmux_nids) {
3482 /* digital pin */
3483 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3484 if (i < 0)
3485 return -1;
3486 mic->dmux_idx = i;
3487 mic->mux_idx = -1;
3488 if (spec->mux_nids)
3489 mic->mux_idx = get_connection_index(codec,
3490 spec->mux_nids[0],
3491 spec->dmux_nids[0]);
3492 }
3619 return 0; 3493 return 0;
3620} 3494}
3621 3495
3496/* return non-zero if the device is for automatic mic switch */
3497static int stac_check_auto_mic(struct hda_codec *codec)
3498{
3499 struct sigmatel_spec *spec = codec->spec;
3500 struct auto_pin_cfg *cfg = &spec->autocfg;
3501 hda_nid_t fixed, ext;
3502 int i;
3503
3504 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3505 if (cfg->input_pins[i])
3506 return 0; /* must be exclusively mics */
3507 }
3508 fixed = ext = 0;
3509 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3510 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3511 return 0;
3512 for (i = 0; i < spec->num_dmics; i++)
3513 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3514 return 0;
3515 if (!fixed || !ext)
3516 return 0;
3517 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3518 return 0; /* no unsol support */
3519 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3520 set_mic_route(codec, &spec->int_mic, fixed))
3521 return 0; /* something is wrong */
3522 return 1;
3523}
3524
3622/* create playback/capture controls for input pins */ 3525/* 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) 3526static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3624{ 3527{
3625 struct sigmatel_spec *spec = codec->spec; 3528 struct sigmatel_spec *spec = codec->spec;
3626 struct hda_input_mux *imux = &spec->private_imux; 3529 struct hda_input_mux *imux = &spec->private_imux;
3627 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS]; 3530 int i, j;
3628 int i, j, k;
3629 3531
3630 for (i = 0; i < AUTO_PIN_LAST; i++) { 3532 for (i = 0; i < AUTO_PIN_LAST; i++) {
3631 int index; 3533 hda_nid_t nid = cfg->input_pins[i];
3534 int index, err;
3632 3535
3633 if (!cfg->input_pins[i]) 3536 if (!nid)
3634 continue; 3537 continue;
3635 index = -1; 3538 index = -1;
3636 for (j = 0; j < spec->num_muxes; j++) { 3539 for (j = 0; j < spec->num_muxes; j++) {
3637 int num_cons; 3540 index = get_connection_index(codec, spec->mux_nids[j],
3638 num_cons = snd_hda_get_connections(codec, 3541 nid);
3639 spec->mux_nids[j], 3542 if (index >= 0)
3640 con_lst, 3543 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 } 3544 }
3648 continue; 3545 if (index < 0)
3649 found: 3546 continue;
3547
3548 err = create_elem_capture_vol(codec, nid,
3549 auto_pin_cfg_labels[i],
3550 HDA_INPUT);
3551 if (err < 0)
3552 return err;
3553
3650 imux->items[imux->num_items].label = auto_pin_cfg_labels[i]; 3554 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3651 imux->items[imux->num_items].index = index; 3555 imux->items[imux->num_items].index = index;
3652 imux->num_items++; 3556 imux->num_items++;
3653 } 3557 }
3558 spec->num_analog_muxes = imux->num_items;
3654 3559
3655 if (imux->num_items) { 3560 if (imux->num_items) {
3656 /* 3561 /*
@@ -3702,7 +3607,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3702{ 3607{
3703 struct sigmatel_spec *spec = codec->spec; 3608 struct sigmatel_spec *spec = codec->spec;
3704 int hp_swap = 0; 3609 int hp_swap = 0;
3705 int err; 3610 int i, err;
3706 3611
3707 if ((err = snd_hda_parse_pin_def_config(codec, 3612 if ((err = snd_hda_parse_pin_def_config(codec,
3708 &spec->autocfg, 3613 &spec->autocfg,
@@ -3742,11 +3647,10 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3742 if (snd_hda_get_connections(codec, 3647 if (snd_hda_get_connections(codec,
3743 spec->autocfg.mono_out_pin, conn_list, 1) && 3648 spec->autocfg.mono_out_pin, conn_list, 1) &&
3744 snd_hda_get_connections(codec, conn_list[0], 3649 snd_hda_get_connections(codec, conn_list[0],
3745 conn_list, 1)) { 3650 conn_list, 1) > 0) {
3746 3651
3747 int wcaps = get_wcaps(codec, conn_list[0]); 3652 int wcaps = get_wcaps(codec, conn_list[0]);
3748 int wid_type = (wcaps & AC_WCAP_TYPE) 3653 int wid_type = get_wcaps_type(wcaps);
3749 >> AC_WCAP_TYPE_SHIFT;
3750 /* LR swap check, some stac925x have a mux that 3654 /* LR swap check, some stac925x have a mux that
3751 * changes the DACs output path instead of the 3655 * changes the DACs output path instead of the
3752 * mono-mux path. 3656 * mono-mux path.
@@ -3837,6 +3741,21 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3837 spec->autocfg.line_outs = 0; 3741 spec->autocfg.line_outs = 0;
3838 } 3742 }
3839 3743
3744 if (stac_check_auto_mic(codec)) {
3745 spec->auto_mic = 1;
3746 /* only one capture for auto-mic */
3747 spec->num_adcs = 1;
3748 spec->num_caps = 1;
3749 spec->num_muxes = 1;
3750 }
3751
3752 for (i = 0; i < spec->num_caps; i++) {
3753 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3754 spec->capsws[i], i);
3755 if (err < 0)
3756 return err;
3757 }
3758
3840 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg); 3759 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3841 if (err < 0) 3760 if (err < 0)
3842 return err; 3761 return err;
@@ -3846,11 +3765,6 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3846 if (err < 0) 3765 if (err < 0)
3847 return err; 3766 return err;
3848 } 3767 }
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) 3768 if (spec->num_dmics > 0 && !spec->dinput_mux)
3855 if ((err = stac92xx_auto_create_dmic_input_ctls(codec, 3769 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3856 &spec->autocfg)) < 0) 3770 &spec->autocfg)) < 0)
@@ -3887,7 +3801,6 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3887 spec->dinput_mux = &spec->private_dimux; 3801 spec->dinput_mux = &spec->private_dimux;
3888 spec->sinput_mux = &spec->private_smux; 3802 spec->sinput_mux = &spec->private_smux;
3889 spec->mono_mux = &spec->private_mono_mux; 3803 spec->mono_mux = &spec->private_mono_mux;
3890 spec->amp_mux = &spec->private_amp_mux;
3891 return 1; 3804 return 1;
3892} 3805}
3893 3806
@@ -4065,7 +3978,7 @@ static int stac92xx_add_jack(struct hda_codec *codec,
4065 jack->nid = nid; 3978 jack->nid = nid;
4066 jack->type = type; 3979 jack->type = type;
4067 3980
4068 sprintf(name, "%s at %s %s Jack", 3981 snprintf(name, sizeof(name), "%s at %s %s Jack",
4069 snd_hda_get_jack_type(def_conf), 3982 snd_hda_get_jack_type(def_conf),
4070 snd_hda_get_jack_connectivity(def_conf), 3983 snd_hda_get_jack_connectivity(def_conf),
4071 snd_hda_get_jack_location(def_conf)); 3984 snd_hda_get_jack_location(def_conf));
@@ -4099,14 +4012,14 @@ static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4099} 4012}
4100 4013
4101static struct sigmatel_event *stac_get_event(struct hda_codec *codec, 4014static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4102 hda_nid_t nid, unsigned char type) 4015 hda_nid_t nid)
4103{ 4016{
4104 struct sigmatel_spec *spec = codec->spec; 4017 struct sigmatel_spec *spec = codec->spec;
4105 struct sigmatel_event *event = spec->events.list; 4018 struct sigmatel_event *event = spec->events.list;
4106 int i; 4019 int i;
4107 4020
4108 for (i = 0; i < spec->events.used; i++, event++) { 4021 for (i = 0; i < spec->events.used; i++, event++) {
4109 if (event->nid == nid && event->type == type) 4022 if (event->nid == nid)
4110 return event; 4023 return event;
4111 } 4024 }
4112 return NULL; 4025 return NULL;
@@ -4126,24 +4039,32 @@ static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4126 return NULL; 4039 return NULL;
4127} 4040}
4128 4041
4129static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid, 4042/* check if given nid is a valid pin and no other events are assigned
4130 unsigned int type) 4043 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4044 * Otherwise, returns zero.
4045 */
4046static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4047 unsigned int type)
4131{ 4048{
4132 struct sigmatel_event *event; 4049 struct sigmatel_event *event;
4133 int tag; 4050 int tag;
4134 4051
4135 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)) 4052 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4136 return; 4053 return 0;
4137 event = stac_get_event(codec, nid, type); 4054 event = stac_get_event(codec, nid);
4138 if (event) 4055 if (event) {
4056 if (event->type != type)
4057 return 0;
4139 tag = event->tag; 4058 tag = event->tag;
4140 else 4059 } else {
4141 tag = stac_add_event(codec->spec, nid, type, 0); 4060 tag = stac_add_event(codec->spec, nid, type, 0);
4142 if (tag < 0) 4061 if (tag < 0)
4143 return; 4062 return 0;
4063 }
4144 snd_hda_codec_write_cache(codec, nid, 0, 4064 snd_hda_codec_write_cache(codec, nid, 0,
4145 AC_VERB_SET_UNSOLICITED_ENABLE, 4065 AC_VERB_SET_UNSOLICITED_ENABLE,
4146 AC_USRSP_EN | tag); 4066 AC_USRSP_EN | tag);
4067 return 1;
4147} 4068}
4148 4069
4149static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid) 4070static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
@@ -4236,20 +4157,39 @@ static int stac92xx_init(struct hda_codec *codec)
4236 hda_nid_t nid = cfg->hp_pins[i]; 4157 hda_nid_t nid = cfg->hp_pins[i];
4237 enable_pin_detect(codec, nid, STAC_HP_EVENT); 4158 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4238 } 4159 }
4160 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4161 cfg->speaker_outs > 0) {
4162 /* enable pin-detect for line-outs as well */
4163 for (i = 0; i < cfg->line_outs; i++) {
4164 hda_nid_t nid = cfg->line_out_pins[i];
4165 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4166 }
4167 }
4168
4239 /* force to enable the first line-out; the others are set up 4169 /* force to enable the first line-out; the others are set up
4240 * in unsol_event 4170 * in unsol_event
4241 */ 4171 */
4242 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0], 4172 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4243 AC_PINCTL_OUT_EN); 4173 AC_PINCTL_OUT_EN);
4244 /* fake event to set up pins */ 4174 /* fake event to set up pins */
4245 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0], 4175 if (cfg->hp_pins[0])
4246 STAC_HP_EVENT); 4176 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4177 else if (cfg->line_out_pins[0])
4178 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4247 } else { 4179 } else {
4248 stac92xx_auto_init_multi_out(codec); 4180 stac92xx_auto_init_multi_out(codec);
4249 stac92xx_auto_init_hp_out(codec); 4181 stac92xx_auto_init_hp_out(codec);
4250 for (i = 0; i < cfg->hp_outs; i++) 4182 for (i = 0; i < cfg->hp_outs; i++)
4251 stac_toggle_power_map(codec, cfg->hp_pins[i], 1); 4183 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4252 } 4184 }
4185 if (spec->auto_mic) {
4186 /* initialize connection to analog input */
4187 if (spec->dmux_nids)
4188 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4189 AC_VERB_SET_CONNECT_SEL, 0);
4190 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4191 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4192 }
4253 for (i = 0; i < AUTO_PIN_LAST; i++) { 4193 for (i = 0; i < AUTO_PIN_LAST; i++) {
4254 hda_nid_t nid = cfg->input_pins[i]; 4194 hda_nid_t nid = cfg->input_pins[i];
4255 if (nid) { 4195 if (nid) {
@@ -4276,10 +4216,9 @@ static int stac92xx_init(struct hda_codec *codec)
4276 } 4216 }
4277 conf = snd_hda_codec_get_pincfg(codec, nid); 4217 conf = snd_hda_codec_get_pincfg(codec, nid);
4278 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) { 4218 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4279 enable_pin_detect(codec, nid, 4219 if (enable_pin_detect(codec, nid,
4280 STAC_INSERT_EVENT); 4220 STAC_INSERT_EVENT))
4281 stac_issue_unsol_event(codec, nid, 4221 stac_issue_unsol_event(codec, nid);
4282 STAC_INSERT_EVENT);
4283 } 4222 }
4284 } 4223 }
4285 } 4224 }
@@ -4324,10 +4263,8 @@ static int stac92xx_init(struct hda_codec *codec)
4324 stac_toggle_power_map(codec, nid, 1); 4263 stac_toggle_power_map(codec, nid, 1);
4325 continue; 4264 continue;
4326 } 4265 }
4327 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) { 4266 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4328 enable_pin_detect(codec, nid, STAC_PWR_EVENT); 4267 stac_issue_unsol_event(codec, nid);
4329 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
4330 }
4331 } 4268 }
4332 if (spec->dac_list) 4269 if (spec->dac_list)
4333 stac92xx_power_down(codec); 4270 stac92xx_power_down(codec);
@@ -4431,6 +4368,48 @@ static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4431 return 0; 4368 return 0;
4432} 4369}
4433 4370
4371static void stac92xx_line_out_detect(struct hda_codec *codec,
4372 int presence)
4373{
4374 struct sigmatel_spec *spec = codec->spec;
4375 struct auto_pin_cfg *cfg = &spec->autocfg;
4376 int i;
4377
4378 for (i = 0; i < cfg->line_outs; i++) {
4379 if (presence)
4380 break;
4381 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4382 if (presence) {
4383 unsigned int pinctl;
4384 pinctl = snd_hda_codec_read(codec,
4385 cfg->line_out_pins[i], 0,
4386 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4387 if (pinctl & AC_PINCTL_IN_EN)
4388 presence = 0; /* mic- or line-input */
4389 }
4390 }
4391
4392 if (presence) {
4393 /* disable speakers */
4394 for (i = 0; i < cfg->speaker_outs; i++)
4395 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4396 AC_PINCTL_OUT_EN);
4397 if (spec->eapd_mask && spec->eapd_switch)
4398 stac_gpio_set(codec, spec->gpio_mask,
4399 spec->gpio_dir, spec->gpio_data &
4400 ~spec->eapd_mask);
4401 } else {
4402 /* enable speakers */
4403 for (i = 0; i < cfg->speaker_outs; i++)
4404 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4405 AC_PINCTL_OUT_EN);
4406 if (spec->eapd_mask && spec->eapd_switch)
4407 stac_gpio_set(codec, spec->gpio_mask,
4408 spec->gpio_dir, spec->gpio_data |
4409 spec->eapd_mask);
4410 }
4411}
4412
4434/* return non-zero if the hp-pin of the given array index isn't 4413/* return non-zero if the hp-pin of the given array index isn't
4435 * a jack-detection target 4414 * a jack-detection target
4436 */ 4415 */
@@ -4483,13 +4462,6 @@ static void stac92xx_hp_detect(struct hda_codec *codec)
4483 for (i = 0; i < cfg->line_outs; i++) 4462 for (i = 0; i < cfg->line_outs; i++)
4484 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i], 4463 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4485 AC_PINCTL_OUT_EN); 4464 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 { 4465 } else {
4494 /* enable lineouts */ 4466 /* enable lineouts */
4495 if (spec->hp_switch) 4467 if (spec->hp_switch)
@@ -4498,14 +4470,8 @@ static void stac92xx_hp_detect(struct hda_codec *codec)
4498 for (i = 0; i < cfg->line_outs; i++) 4470 for (i = 0; i < cfg->line_outs; i++)
4499 stac92xx_set_pinctl(codec, cfg->line_out_pins[i], 4471 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4500 AC_PINCTL_OUT_EN); 4472 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 } 4473 }
4474 stac92xx_line_out_detect(codec, presence);
4509 /* toggle hp outs */ 4475 /* toggle hp outs */
4510 for (i = 0; i < cfg->hp_outs; i++) { 4476 for (i = 0; i < cfg->hp_outs; i++) {
4511 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN; 4477 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
@@ -4590,10 +4556,28 @@ static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4590 } 4556 }
4591} 4557}
4592 4558
4593static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid, 4559static void stac92xx_mic_detect(struct hda_codec *codec)
4594 unsigned char type) 4560{
4561 struct sigmatel_spec *spec = codec->spec;
4562 struct sigmatel_mic_route *mic;
4563
4564 if (get_pin_presence(codec, spec->ext_mic.pin))
4565 mic = &spec->ext_mic;
4566 else
4567 mic = &spec->int_mic;
4568 if (mic->dmux_idx >= 0)
4569 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4570 AC_VERB_SET_CONNECT_SEL,
4571 mic->dmux_idx);
4572 if (mic->mux_idx >= 0)
4573 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4574 AC_VERB_SET_CONNECT_SEL,
4575 mic->mux_idx);
4576}
4577
4578static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4595{ 4579{
4596 struct sigmatel_event *event = stac_get_event(codec, nid, type); 4580 struct sigmatel_event *event = stac_get_event(codec, nid);
4597 if (!event) 4581 if (!event)
4598 return; 4582 return;
4599 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26); 4583 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
@@ -4612,8 +4596,18 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4612 4596
4613 switch (event->type) { 4597 switch (event->type) {
4614 case STAC_HP_EVENT: 4598 case STAC_HP_EVENT:
4599 case STAC_LO_EVENT:
4615 stac92xx_hp_detect(codec); 4600 stac92xx_hp_detect(codec);
4616 /* fallthru */ 4601 break;
4602 case STAC_MIC_EVENT:
4603 stac92xx_mic_detect(codec);
4604 break;
4605 }
4606
4607 switch (event->type) {
4608 case STAC_HP_EVENT:
4609 case STAC_LO_EVENT:
4610 case STAC_MIC_EVENT:
4617 case STAC_INSERT_EVENT: 4611 case STAC_INSERT_EVENT:
4618 case STAC_PWR_EVENT: 4612 case STAC_PWR_EVENT:
4619 if (spec->num_pwrs > 0) 4613 if (spec->num_pwrs > 0)
@@ -4703,9 +4697,13 @@ static int stac92xx_resume(struct hda_codec *codec)
4703 snd_hda_codec_resume_amp(codec); 4697 snd_hda_codec_resume_amp(codec);
4704 snd_hda_codec_resume_cache(codec); 4698 snd_hda_codec_resume_cache(codec);
4705 /* fake event to set up pins again to override cached values */ 4699 /* fake event to set up pins again to override cached values */
4706 if (spec->hp_detect) 4700 if (spec->hp_detect) {
4707 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0], 4701 if (spec->autocfg.hp_pins[0])
4708 STAC_HP_EVENT); 4702 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4703 else if (spec->autocfg.line_out_pins[0])
4704 stac_issue_unsol_event(codec,
4705 spec->autocfg.line_out_pins[0]);
4706 }
4709 return 0; 4707 return 0;
4710} 4708}
4711 4709
@@ -4745,6 +4743,19 @@ static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4745static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state) 4743static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4746{ 4744{
4747 struct sigmatel_spec *spec = codec->spec; 4745 struct sigmatel_spec *spec = codec->spec;
4746 int i;
4747 hda_nid_t nid;
4748
4749 /* reset each pin before powering down DAC/ADC to avoid click noise */
4750 nid = codec->start_nid;
4751 for (i = 0; i < codec->num_nodes; i++, nid++) {
4752 unsigned int wcaps = get_wcaps(codec, nid);
4753 unsigned int wid_type = get_wcaps_type(wcaps);
4754 if (wid_type == AC_WID_PIN)
4755 snd_hda_codec_read(codec, nid, 0,
4756 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4757 }
4758
4748 if (spec->eapd_mask) 4759 if (spec->eapd_mask)
4749 stac_gpio_set(codec, spec->gpio_mask, 4760 stac_gpio_set(codec, spec->gpio_mask,
4750 spec->gpio_dir, spec->gpio_data & 4761 spec->gpio_dir, spec->gpio_data &
@@ -4781,7 +4792,8 @@ static int patch_stac9200(struct hda_codec *codec)
4781 stac9200_models, 4792 stac9200_models,
4782 stac9200_cfg_tbl); 4793 stac9200_cfg_tbl);
4783 if (spec->board_config < 0) 4794 if (spec->board_config < 0)
4784 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n"); 4795 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4796 codec->chip_name);
4785 else 4797 else
4786 stac92xx_set_config_regs(codec, 4798 stac92xx_set_config_regs(codec,
4787 stac9200_brd_tbl[spec->board_config]); 4799 stac9200_brd_tbl[spec->board_config]);
@@ -4853,8 +4865,8 @@ static int patch_stac925x(struct hda_codec *codec)
4853 stac925x_cfg_tbl); 4865 stac925x_cfg_tbl);
4854 again: 4866 again:
4855 if (spec->board_config < 0) 4867 if (spec->board_config < 0)
4856 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x," 4868 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4857 "using BIOS defaults\n"); 4869 codec->chip_name);
4858 else 4870 else
4859 stac92xx_set_config_regs(codec, 4871 stac92xx_set_config_regs(codec,
4860 stac925x_brd_tbl[spec->board_config]); 4872 stac925x_brd_tbl[spec->board_config]);
@@ -4884,6 +4896,9 @@ static int patch_stac925x(struct hda_codec *codec)
4884 4896
4885 spec->init = stac925x_core_init; 4897 spec->init = stac925x_core_init;
4886 spec->mixer = stac925x_mixer; 4898 spec->mixer = stac925x_mixer;
4899 spec->num_caps = 1;
4900 spec->capvols = stac925x_capvols;
4901 spec->capsws = stac925x_capsws;
4887 4902
4888 err = stac92xx_parse_auto_config(codec, 0x8, 0x7); 4903 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
4889 if (!err) { 4904 if (!err) {
@@ -4905,16 +4920,6 @@ static int patch_stac925x(struct hda_codec *codec)
4905 return 0; 4920 return 0;
4906} 4921}
4907 4922
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) 4923static int patch_stac92hd73xx(struct hda_codec *codec)
4919{ 4924{
4920 struct sigmatel_spec *spec; 4925 struct sigmatel_spec *spec;
@@ -4934,10 +4939,16 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4934 STAC_92HD73XX_MODELS, 4939 STAC_92HD73XX_MODELS,
4935 stac92hd73xx_models, 4940 stac92hd73xx_models,
4936 stac92hd73xx_cfg_tbl); 4941 stac92hd73xx_cfg_tbl);
4942 /* check codec subsystem id if not found */
4943 if (spec->board_config < 0)
4944 spec->board_config =
4945 snd_hda_check_board_codec_sid_config(codec,
4946 STAC_92HD73XX_MODELS, stac92hd73xx_models,
4947 stac92hd73xx_codec_id_cfg_tbl);
4937again: 4948again:
4938 if (spec->board_config < 0) 4949 if (spec->board_config < 0)
4939 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 4950 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4940 " STAC92HD73XX, using BIOS defaults\n"); 4951 codec->chip_name);
4941 else 4952 else
4942 stac92xx_set_config_regs(codec, 4953 stac92xx_set_config_regs(codec,
4943 stac92hd73xx_brd_tbl[spec->board_config]); 4954 stac92hd73xx_brd_tbl[spec->board_config]);
@@ -4950,20 +4961,15 @@ again:
4950 "number of channels defaulting to DAC count\n"); 4961 "number of channels defaulting to DAC count\n");
4951 num_dacs = STAC92HD73_DAC_COUNT; 4962 num_dacs = STAC92HD73_DAC_COUNT;
4952 } 4963 }
4964 spec->init = stac92hd73xx_core_init;
4953 switch (num_dacs) { 4965 switch (num_dacs) {
4954 case 0x3: /* 6 Channel */ 4966 case 0x3: /* 6 Channel */
4955 spec->mixer = stac92hd73xx_6ch_mixer;
4956 spec->init = stac92hd73xx_6ch_core_init;
4957 spec->aloopback_ctl = stac92hd73xx_6ch_loopback; 4967 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
4958 break; 4968 break;
4959 case 0x4: /* 8 Channel */ 4969 case 0x4: /* 8 Channel */
4960 spec->mixer = stac92hd73xx_8ch_mixer;
4961 spec->init = stac92hd73xx_8ch_core_init;
4962 spec->aloopback_ctl = stac92hd73xx_8ch_loopback; 4970 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
4963 break; 4971 break;
4964 case 0x5: /* 10 Channel */ 4972 case 0x5: /* 10 Channel */
4965 spec->mixer = stac92hd73xx_10ch_mixer;
4966 spec->init = stac92hd73xx_10ch_core_init;
4967 spec->aloopback_ctl = stac92hd73xx_10ch_loopback; 4973 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4968 break; 4974 break;
4969 } 4975 }
@@ -4978,14 +4984,14 @@ again:
4978 spec->dmic_nids = stac92hd73xx_dmic_nids; 4984 spec->dmic_nids = stac92hd73xx_dmic_nids;
4979 spec->dmux_nids = stac92hd73xx_dmux_nids; 4985 spec->dmux_nids = stac92hd73xx_dmux_nids;
4980 spec->smux_nids = stac92hd73xx_smux_nids; 4986 spec->smux_nids = stac92hd73xx_smux_nids;
4981 spec->amp_nids = stac92hd73xx_amp_nids;
4982 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
4983 4987
4984 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids); 4988 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4985 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids); 4989 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
4986 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids); 4990 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
4987 memcpy(&spec->private_dimux, &stac92hd73xx_dmux, 4991
4988 sizeof(stac92hd73xx_dmux)); 4992 spec->num_caps = STAC92HD73XX_NUM_CAPS;
4993 spec->capvols = stac92hd73xx_capvols;
4994 spec->capsws = stac92hd73xx_capsws;
4989 4995
4990 switch (spec->board_config) { 4996 switch (spec->board_config) {
4991 case STAC_DELL_EQ: 4997 case STAC_DELL_EQ:
@@ -4995,43 +5001,40 @@ again:
4995 case STAC_DELL_M6_DMIC: 5001 case STAC_DELL_M6_DMIC:
4996 case STAC_DELL_M6_BOTH: 5002 case STAC_DELL_M6_BOTH:
4997 spec->num_smuxes = 0; 5003 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; 5004 spec->eapd_switch = 0;
5001 spec->num_amps = 1;
5002 5005
5003 if (spec->board_config != STAC_DELL_EQ)
5004 spec->init = dell_m6_core_init;
5005 switch (spec->board_config) { 5006 switch (spec->board_config) {
5006 case STAC_DELL_M6_AMIC: /* Analog Mics */ 5007 case STAC_DELL_M6_AMIC: /* Analog Mics */
5007 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170); 5008 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5008 spec->num_dmics = 0; 5009 spec->num_dmics = 0;
5009 spec->private_dimux.num_items = 1;
5010 break; 5010 break;
5011 case STAC_DELL_M6_DMIC: /* Digital Mics */ 5011 case STAC_DELL_M6_DMIC: /* Digital Mics */
5012 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160); 5012 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5013 spec->num_dmics = 1; 5013 spec->num_dmics = 1;
5014 spec->private_dimux.num_items = 2;
5015 break; 5014 break;
5016 case STAC_DELL_M6_BOTH: /* Both */ 5015 case STAC_DELL_M6_BOTH: /* Both */
5017 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170); 5016 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5018 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160); 5017 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5019 spec->num_dmics = 1; 5018 spec->num_dmics = 1;
5020 spec->private_dimux.num_items = 2;
5021 break; 5019 break;
5022 } 5020 }
5023 break; 5021 break;
5022 case STAC_ALIENWARE_M17X:
5023 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5024 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5025 spec->eapd_switch = 0;
5026 break;
5024 default: 5027 default:
5025 spec->num_dmics = STAC92HD73XX_NUM_DMICS; 5028 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5026 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids); 5029 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5027 spec->eapd_switch = 1; 5030 spec->eapd_switch = 1;
5031 break;
5028 } 5032 }
5029 if (spec->board_config > STAC_92HD73XX_REF) { 5033 if (spec->board_config != STAC_92HD73XX_REF) {
5030 /* GPIO0 High = Enable EAPD */ 5034 /* GPIO0 High = Enable EAPD */
5031 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1; 5035 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5032 spec->gpio_data = 0x01; 5036 spec->gpio_data = 0x01;
5033 } 5037 }
5034 spec->dinput_mux = &spec->private_dimux;
5035 5038
5036 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 5039 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5037 spec->pwr_nids = stac92hd73xx_pwr_nids; 5040 spec->pwr_nids = stac92hd73xx_pwr_nids;
@@ -5063,15 +5066,6 @@ again:
5063 return 0; 5066 return 0;
5064} 5067}
5065 5068
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) 5069static int patch_stac92hd83xxx(struct hda_codec *codec)
5076{ 5070{
5077 struct sigmatel_spec *spec; 5071 struct sigmatel_spec *spec;
@@ -5086,34 +5080,31 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
5086 5080
5087 codec->spec = spec; 5081 codec->spec = spec;
5088 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs; 5082 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5089 spec->mono_nid = 0x19;
5090 spec->digbeep_nid = 0x21; 5083 spec->digbeep_nid = 0x21;
5091 spec->dmic_nids = stac92hd83xxx_dmic_nids; 5084 spec->mux_nids = stac92hd83xxx_mux_nids;
5092 spec->dmux_nids = stac92hd83xxx_dmux_nids; 5085 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
5093 spec->adc_nids = stac92hd83xxx_adc_nids; 5086 spec->adc_nids = stac92hd83xxx_adc_nids;
5087 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5094 spec->pwr_nids = stac92hd83xxx_pwr_nids; 5088 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5095 spec->amp_nids = stac92hd83xxx_amp_nids;
5096 spec->pwr_mapping = stac92hd83xxx_pwr_mapping; 5089 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5097 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids); 5090 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5098 spec->multiout.dac_nids = spec->dac_nids; 5091 spec->multiout.dac_nids = spec->dac_nids;
5099 5092
5100 spec->init = stac92hd83xxx_core_init; 5093 spec->init = stac92hd83xxx_core_init;
5101 spec->mixer = stac92hd83xxx_mixer;
5102 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids); 5094 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; 5095 spec->pin_nids = stac92hd83xxx_pin_nids;
5096 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5097 spec->capvols = stac92hd83xxx_capvols;
5098 spec->capsws = stac92hd83xxx_capsws;
5099
5109 spec->board_config = snd_hda_check_board_config(codec, 5100 spec->board_config = snd_hda_check_board_config(codec,
5110 STAC_92HD83XXX_MODELS, 5101 STAC_92HD83XXX_MODELS,
5111 stac92hd83xxx_models, 5102 stac92hd83xxx_models,
5112 stac92hd83xxx_cfg_tbl); 5103 stac92hd83xxx_cfg_tbl);
5113again: 5104again:
5114 if (spec->board_config < 0) 5105 if (spec->board_config < 0)
5115 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5106 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5116 " STAC92HD83XXX, using BIOS defaults\n"); 5107 codec->chip_name);
5117 else 5108 else
5118 stac92xx_set_config_regs(codec, 5109 stac92xx_set_config_regs(codec,
5119 stac92hd83xxx_brd_tbl[spec->board_config]); 5110 stac92hd83xxx_brd_tbl[spec->board_config]);
@@ -5155,6 +5146,8 @@ again:
5155 5146
5156 num_dacs = snd_hda_get_connections(codec, nid, 5147 num_dacs = snd_hda_get_connections(codec, nid,
5157 conn, STAC92HD83_DAC_COUNT + 1) - 1; 5148 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5149 if (num_dacs < 0)
5150 num_dacs = STAC92HD83_DAC_COUNT;
5158 5151
5159 /* set port X to select the last DAC 5152 /* set port X to select the last DAC
5160 */ 5153 */
@@ -5168,25 +5161,6 @@ again:
5168 return 0; 5161 return 0;
5169} 5162}
5170 5163
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) */ 5164/* get the pin connection (fixed, none, etc) */
5191static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx) 5165static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5192{ 5166{
@@ -5247,7 +5221,6 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
5247 struct sigmatel_spec *spec; 5221 struct sigmatel_spec *spec;
5248 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init; 5222 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5249 int err = 0; 5223 int err = 0;
5250 unsigned int ndmic_nids = 0;
5251 5224
5252 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5225 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5253 if (spec == NULL) 5226 if (spec == NULL)
@@ -5276,13 +5249,13 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
5276 stac92hd71bxx_cfg_tbl); 5249 stac92hd71bxx_cfg_tbl);
5277again: 5250again:
5278 if (spec->board_config < 0) 5251 if (spec->board_config < 0)
5279 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5252 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5280 " STAC92HD71BXX, using BIOS defaults\n"); 5253 codec->chip_name);
5281 else 5254 else
5282 stac92xx_set_config_regs(codec, 5255 stac92xx_set_config_regs(codec,
5283 stac92hd71bxx_brd_tbl[spec->board_config]); 5256 stac92hd71bxx_brd_tbl[spec->board_config]);
5284 5257
5285 if (spec->board_config > STAC_92HD71BXX_REF) { 5258 if (spec->board_config != STAC_92HD71BXX_REF) {
5286 /* GPIO0 = EAPD */ 5259 /* GPIO0 = EAPD */
5287 spec->gpio_mask = 0x01; 5260 spec->gpio_mask = 0x01;
5288 spec->gpio_dir = 0x01; 5261 spec->gpio_dir = 0x01;
@@ -5292,6 +5265,10 @@ again:
5292 spec->dmic_nids = stac92hd71bxx_dmic_nids; 5265 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5293 spec->dmux_nids = stac92hd71bxx_dmux_nids; 5266 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5294 5267
5268 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5269 spec->capvols = stac92hd71bxx_capvols;
5270 spec->capsws = stac92hd71bxx_capsws;
5271
5295 switch (codec->vendor_id) { 5272 switch (codec->vendor_id) {
5296 case 0x111d76b6: /* 4 Port without Analog Mixer */ 5273 case 0x111d76b6: /* 4 Port without Analog Mixer */
5297 case 0x111d76b7: 5274 case 0x111d76b7:
@@ -5299,24 +5276,13 @@ again:
5299 /* fallthru */ 5276 /* fallthru */
5300 case 0x111d76b4: /* 6 Port without Analog Mixer */ 5277 case 0x111d76b4: /* 6 Port without Analog Mixer */
5301 case 0x111d76b5: 5278 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; 5279 spec->init = stac92hd71bxx_core_init;
5306 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs; 5280 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5307 spec->num_dmics = stac92hd71bxx_connected_ports(codec, 5281 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5308 stac92hd71bxx_dmic_nids, 5282 stac92hd71bxx_dmic_nids,
5309 STAC92HD71BXX_NUM_DMICS); 5283 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; 5284 break;
5316 case 0x111d7608: /* 5 Port with Analog Mixer */ 5285 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) { 5286 switch (spec->board_config) {
5321 case STAC_HP_M4: 5287 case STAC_HP_M4:
5322 /* Enable VREF power saving on GPIO1 detect */ 5288 /* Enable VREF power saving on GPIO1 detect */
@@ -5338,11 +5304,8 @@ again:
5338 5304
5339 /* no output amps */ 5305 /* no output amps */
5340 spec->num_pwrs = 0; 5306 spec->num_pwrs = 0;
5341 spec->mixer = stac92hd71bxx_analog_mixer;
5342 spec->dinput_mux = &spec->private_dimux;
5343
5344 /* disable VSW */ 5307 /* disable VSW */
5345 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF]; 5308 spec->init = stac92hd71bxx_core_init;
5346 unmute_init++; 5309 unmute_init++;
5347 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0); 5310 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5348 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3); 5311 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
@@ -5350,8 +5313,6 @@ again:
5350 spec->num_dmics = stac92hd71bxx_connected_ports(codec, 5313 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5351 stac92hd71bxx_dmic_nids, 5314 stac92hd71bxx_dmic_nids,
5352 STAC92HD71BXX_NUM_DMICS - 1); 5315 STAC92HD71BXX_NUM_DMICS - 1);
5353 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5354 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
5355 break; 5316 break;
5356 case 0x111d7603: /* 6 Port with Analog Mixer */ 5317 case 0x111d7603: /* 6 Port with Analog Mixer */
5357 if ((codec->revision_id & 0xf) == 1) 5318 if ((codec->revision_id & 0xf) == 1)
@@ -5361,17 +5322,12 @@ again:
5361 spec->num_pwrs = 0; 5322 spec->num_pwrs = 0;
5362 /* fallthru */ 5323 /* fallthru */
5363 default: 5324 default:
5364 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer, 5325 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; 5326 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5370 spec->num_dmics = stac92hd71bxx_connected_ports(codec, 5327 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5371 stac92hd71bxx_dmic_nids, 5328 stac92hd71bxx_dmic_nids,
5372 STAC92HD71BXX_NUM_DMICS); 5329 STAC92HD71BXX_NUM_DMICS);
5373 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids); 5330 break;
5374 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5375 } 5331 }
5376 5332
5377 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) 5333 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
@@ -5399,6 +5355,7 @@ again:
5399 5355
5400 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids); 5356 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5401 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids); 5357 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5358 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5402 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e); 5359 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5403 5360
5404 switch (spec->board_config) { 5361 switch (spec->board_config) {
@@ -5431,6 +5388,11 @@ again:
5431 case STAC_HP_DV5: 5388 case STAC_HP_DV5:
5432 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010); 5389 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5433 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN); 5390 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5391 /* HP dv6 gives the headphone pin as a line-out. Thus we
5392 * need to set hp_detect flag here to force to enable HP
5393 * detection.
5394 */
5395 spec->hp_detect = 1;
5434 break; 5396 break;
5435 case STAC_HP_HDX: 5397 case STAC_HP_HDX:
5436 spec->num_dmics = 1; 5398 spec->num_dmics = 1;
@@ -5453,8 +5415,6 @@ again:
5453#endif 5415#endif
5454 5416
5455 spec->multiout.dac_nids = spec->dac_nids; 5417 spec->multiout.dac_nids = spec->dac_nids;
5456 if (spec->dinput_mux)
5457 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
5458 5418
5459 err = stac92xx_parse_auto_config(codec, 0x21, 0); 5419 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5460 if (!err) { 5420 if (!err) {
@@ -5532,8 +5492,8 @@ static int patch_stac922x(struct hda_codec *codec)
5532 5492
5533 again: 5493 again:
5534 if (spec->board_config < 0) 5494 if (spec->board_config < 0)
5535 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, " 5495 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5536 "using BIOS defaults\n"); 5496 codec->chip_name);
5537 else 5497 else
5538 stac92xx_set_config_regs(codec, 5498 stac92xx_set_config_regs(codec,
5539 stac922x_brd_tbl[spec->board_config]); 5499 stac922x_brd_tbl[spec->board_config]);
@@ -5546,7 +5506,10 @@ static int patch_stac922x(struct hda_codec *codec)
5546 spec->num_pwrs = 0; 5506 spec->num_pwrs = 0;
5547 5507
5548 spec->init = stac922x_core_init; 5508 spec->init = stac922x_core_init;
5549 spec->mixer = stac922x_mixer; 5509
5510 spec->num_caps = STAC922X_NUM_CAPS;
5511 spec->capvols = stac922x_capvols;
5512 spec->capsws = stac922x_capsws;
5550 5513
5551 spec->multiout.dac_nids = spec->dac_nids; 5514 spec->multiout.dac_nids = spec->dac_nids;
5552 5515
@@ -5595,8 +5558,8 @@ static int patch_stac927x(struct hda_codec *codec)
5595 stac927x_cfg_tbl); 5558 stac927x_cfg_tbl);
5596 again: 5559 again:
5597 if (spec->board_config < 0) 5560 if (spec->board_config < 0)
5598 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5561 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5599 "STAC927x, using BIOS defaults\n"); 5562 codec->chip_name);
5600 else 5563 else
5601 stac92xx_set_config_regs(codec, 5564 stac92xx_set_config_regs(codec,
5602 stac927x_brd_tbl[spec->board_config]); 5565 stac927x_brd_tbl[spec->board_config]);
@@ -5612,16 +5575,18 @@ static int patch_stac927x(struct hda_codec *codec)
5612 spec->dac_list = stac927x_dac_nids; 5575 spec->dac_list = stac927x_dac_nids;
5613 spec->multiout.dac_nids = spec->dac_nids; 5576 spec->multiout.dac_nids = spec->dac_nids;
5614 5577
5578 if (spec->board_config != STAC_D965_REF) {
5579 /* GPIO0 High = Enable EAPD */
5580 spec->eapd_mask = spec->gpio_mask = 0x01;
5581 spec->gpio_dir = spec->gpio_data = 0x01;
5582 }
5583
5615 switch (spec->board_config) { 5584 switch (spec->board_config) {
5616 case STAC_D965_3ST: 5585 case STAC_D965_3ST:
5617 case STAC_D965_5ST: 5586 case STAC_D965_5ST:
5618 /* GPIO0 High = Enable EAPD */ 5587 /* 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; 5588 spec->num_dmics = 0;
5622
5623 spec->init = d965_core_init; 5589 spec->init = d965_core_init;
5624 spec->mixer = stac927x_mixer;
5625 break; 5590 break;
5626 case STAC_DELL_BIOS: 5591 case STAC_DELL_BIOS:
5627 switch (codec->subsystem_id) { 5592 switch (codec->subsystem_id) {
@@ -5639,29 +5604,28 @@ static int patch_stac927x(struct hda_codec *codec)
5639 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130); 5604 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5640 /* fallthru */ 5605 /* fallthru */
5641 case STAC_DELL_3ST: 5606 case STAC_DELL_3ST:
5642 /* GPIO2 High = Enable EAPD */ 5607 if (codec->subsystem_id != 0x1028022f) {
5643 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04; 5608 /* GPIO2 High = Enable EAPD */
5644 spec->gpio_data = 0x04; 5609 spec->eapd_mask = spec->gpio_mask = 0x04;
5610 spec->gpio_dir = spec->gpio_data = 0x04;
5611 }
5645 spec->dmic_nids = stac927x_dmic_nids; 5612 spec->dmic_nids = stac927x_dmic_nids;
5646 spec->num_dmics = STAC927X_NUM_DMICS; 5613 spec->num_dmics = STAC927X_NUM_DMICS;
5647 5614
5648 spec->init = d965_core_init; 5615 spec->init = d965_core_init;
5649 spec->mixer = stac927x_mixer;
5650 spec->dmux_nids = stac927x_dmux_nids; 5616 spec->dmux_nids = stac927x_dmux_nids;
5651 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids); 5617 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5652 break; 5618 break;
5653 default: 5619 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; 5620 spec->num_dmics = 0;
5660
5661 spec->init = stac927x_core_init; 5621 spec->init = stac927x_core_init;
5662 spec->mixer = stac927x_mixer; 5622 break;
5663 } 5623 }
5664 5624
5625 spec->num_caps = STAC927X_NUM_CAPS;
5626 spec->capvols = stac927x_capvols;
5627 spec->capsws = stac927x_capsws;
5628
5665 spec->num_pwrs = 0; 5629 spec->num_pwrs = 0;
5666 spec->aloopback_ctl = stac927x_loopback; 5630 spec->aloopback_ctl = stac927x_loopback;
5667 spec->aloopback_mask = 0x40; 5631 spec->aloopback_mask = 0x40;
@@ -5723,7 +5687,8 @@ static int patch_stac9205(struct hda_codec *codec)
5723 stac9205_cfg_tbl); 5687 stac9205_cfg_tbl);
5724 again: 5688 again:
5725 if (spec->board_config < 0) 5689 if (spec->board_config < 0)
5726 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n"); 5690 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5691 codec->chip_name);
5727 else 5692 else
5728 stac92xx_set_config_regs(codec, 5693 stac92xx_set_config_regs(codec,
5729 stac9205_brd_tbl[spec->board_config]); 5694 stac9205_brd_tbl[spec->board_config]);
@@ -5742,9 +5707,12 @@ static int patch_stac9205(struct hda_codec *codec)
5742 spec->num_pwrs = 0; 5707 spec->num_pwrs = 0;
5743 5708
5744 spec->init = stac9205_core_init; 5709 spec->init = stac9205_core_init;
5745 spec->mixer = stac9205_mixer;
5746 spec->aloopback_ctl = stac9205_loopback; 5710 spec->aloopback_ctl = stac9205_loopback;
5747 5711
5712 spec->num_caps = STAC9205_NUM_CAPS;
5713 spec->capvols = stac9205_capvols;
5714 spec->capsws = stac9205_capsws;
5715
5748 spec->aloopback_mask = 0x40; 5716 spec->aloopback_mask = 0x40;
5749 spec->aloopback_shift = 0; 5717 spec->aloopback_shift = 0;
5750 /* Turn on/off EAPD per HP plugging */ 5718 /* Turn on/off EAPD per HP plugging */
@@ -5819,12 +5787,6 @@ static struct hda_verb stac9872_core_init[] = {
5819 {} 5787 {}
5820}; 5788};
5821 5789
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[] = { 5790static hda_nid_t stac9872_pin_nids[] = {
5829 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 5791 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5830 0x11, 0x13, 0x14, 5792 0x11, 0x13, 0x14,
@@ -5838,6 +5800,11 @@ static hda_nid_t stac9872_mux_nids[] = {
5838 0x15 5800 0x15
5839}; 5801};
5840 5802
5803static unsigned long stac9872_capvols[] = {
5804 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
5805};
5806#define stac9872_capsws stac9872_capvols
5807
5841static unsigned int stac9872_vaio_pin_configs[9] = { 5808static unsigned int stac9872_vaio_pin_configs[9] = {
5842 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030, 5809 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5843 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0, 5810 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
@@ -5854,6 +5821,8 @@ static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5854}; 5821};
5855 5822
5856static struct snd_pci_quirk stac9872_cfg_tbl[] = { 5823static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5824 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
5825 "Sony VAIO F/S", STAC_9872_VAIO),
5857 {} /* terminator */ 5826 {} /* terminator */
5858}; 5827};
5859 5828
@@ -5866,26 +5835,28 @@ static int patch_stac9872(struct hda_codec *codec)
5866 if (spec == NULL) 5835 if (spec == NULL)
5867 return -ENOMEM; 5836 return -ENOMEM;
5868 codec->spec = spec; 5837 codec->spec = spec;
5838 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5839 spec->pin_nids = stac9872_pin_nids;
5869 5840
5870 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS, 5841 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5871 stac9872_models, 5842 stac9872_models,
5872 stac9872_cfg_tbl); 5843 stac9872_cfg_tbl);
5873 if (spec->board_config < 0) 5844 if (spec->board_config < 0)
5874 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9872, " 5845 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5875 "using BIOS defaults\n"); 5846 codec->chip_name);
5876 else 5847 else
5877 stac92xx_set_config_regs(codec, 5848 stac92xx_set_config_regs(codec,
5878 stac9872_brd_tbl[spec->board_config]); 5849 stac9872_brd_tbl[spec->board_config]);
5879 5850
5880 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5881 spec->pin_nids = stac9872_pin_nids;
5882 spec->multiout.dac_nids = spec->dac_nids; 5851 spec->multiout.dac_nids = spec->dac_nids;
5883 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids); 5852 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5884 spec->adc_nids = stac9872_adc_nids; 5853 spec->adc_nids = stac9872_adc_nids;
5885 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids); 5854 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5886 spec->mux_nids = stac9872_mux_nids; 5855 spec->mux_nids = stac9872_mux_nids;
5887 spec->mixer = stac9872_mixer;
5888 spec->init = stac9872_core_init; 5856 spec->init = stac9872_core_init;
5857 spec->num_caps = 1;
5858 spec->capvols = stac9872_capvols;
5859 spec->capsws = stac9872_capsws;
5889 5860
5890 err = stac92xx_parse_auto_config(codec, 0x10, 0x12); 5861 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5891 if (err < 0) { 5862 if (err < 0) {
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 8e004fb6961a..ee89db90c9b6 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.c b/sound/pci/ice1712/ice1712.c
index 0d0cdbdb4486..cecf1ffeeaaa 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -107,7 +107,7 @@ MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE.");
107 107
108 108
109static const struct pci_device_id snd_ice1712_ids[] = { 109static const struct pci_device_id snd_ice1712_ids[] = {
110 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */ 110 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_ICE_1712), 0 }, /* ICE1712 */
111 { 0, } 111 { 0, }
112}; 112};
113 113
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index adc909ec125c..9da2dae64c5b 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 36ade77cf371..af6e00148621 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -93,7 +93,7 @@ MODULE_PARM_DESC(model, "Use the given board model.");
93 93
94/* Both VT1720 and VT1724 have the same PCI IDs */ 94/* Both VT1720 and VT1724 have the same PCI IDs */
95static const struct pci_device_id snd_vt1724_ids[] = { 95static const struct pci_device_id snd_vt1724_ids[] = {
96 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 96 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_VT1724), 0 },
97 { 0, } 97 { 0, }
98}; 98};
99 99
@@ -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 043a93879bd5..c75515f5be6f 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/intel8x0.c b/sound/pci/intel8x0.c
index 8aa5687f392a..754867ed4785 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -421,29 +421,29 @@ struct intel8x0 {
421}; 421};
422 422
423static struct pci_device_id snd_intel8x0_ids[] = { 423static struct pci_device_id snd_intel8x0_ids[] = {
424 { 0x8086, 0x2415, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */ 424 { PCI_VDEVICE(INTEL, 0x2415), DEVICE_INTEL }, /* 82801AA */
425 { 0x8086, 0x2425, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */ 425 { PCI_VDEVICE(INTEL, 0x2425), DEVICE_INTEL }, /* 82901AB */
426 { 0x8086, 0x2445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */ 426 { PCI_VDEVICE(INTEL, 0x2445), DEVICE_INTEL }, /* 82801BA */
427 { 0x8086, 0x2485, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */ 427 { PCI_VDEVICE(INTEL, 0x2485), DEVICE_INTEL }, /* ICH3 */
428 { 0x8086, 0x24c5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH4 */ 428 { PCI_VDEVICE(INTEL, 0x24c5), DEVICE_INTEL_ICH4 }, /* ICH4 */
429 { 0x8086, 0x24d5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH5 */ 429 { PCI_VDEVICE(INTEL, 0x24d5), DEVICE_INTEL_ICH4 }, /* ICH5 */
430 { 0x8086, 0x25a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB */ 430 { PCI_VDEVICE(INTEL, 0x25a6), DEVICE_INTEL_ICH4 }, /* ESB */
431 { 0x8086, 0x266e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH6 */ 431 { PCI_VDEVICE(INTEL, 0x266e), DEVICE_INTEL_ICH4 }, /* ICH6 */
432 { 0x8086, 0x27de, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH7 */ 432 { PCI_VDEVICE(INTEL, 0x27de), DEVICE_INTEL_ICH4 }, /* ICH7 */
433 { 0x8086, 0x2698, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB2 */ 433 { PCI_VDEVICE(INTEL, 0x2698), DEVICE_INTEL_ICH4 }, /* ESB2 */
434 { 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */ 434 { PCI_VDEVICE(INTEL, 0x7195), DEVICE_INTEL }, /* 440MX */
435 { 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7012 */ 435 { PCI_VDEVICE(SI, 0x7012), DEVICE_SIS }, /* SI7012 */
436 { 0x10de, 0x01b1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */ 436 { PCI_VDEVICE(NVIDIA, 0x01b1), DEVICE_NFORCE }, /* NFORCE */
437 { 0x10de, 0x003a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* MCP04 */ 437 { PCI_VDEVICE(NVIDIA, 0x003a), DEVICE_NFORCE }, /* MCP04 */
438 { 0x10de, 0x006a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */ 438 { PCI_VDEVICE(NVIDIA, 0x006a), DEVICE_NFORCE }, /* NFORCE2 */
439 { 0x10de, 0x0059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK804 */ 439 { PCI_VDEVICE(NVIDIA, 0x0059), DEVICE_NFORCE }, /* CK804 */
440 { 0x10de, 0x008a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8 */ 440 { PCI_VDEVICE(NVIDIA, 0x008a), DEVICE_NFORCE }, /* CK8 */
441 { 0x10de, 0x00da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */ 441 { PCI_VDEVICE(NVIDIA, 0x00da), DEVICE_NFORCE }, /* NFORCE3 */
442 { 0x10de, 0x00ea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8S */ 442 { PCI_VDEVICE(NVIDIA, 0x00ea), DEVICE_NFORCE }, /* CK8S */
443 { 0x10de, 0x026b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* MCP51 */ 443 { PCI_VDEVICE(NVIDIA, 0x026b), DEVICE_NFORCE }, /* MCP51 */
444 { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */ 444 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
445 { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */ 445 { PCI_VDEVICE(AMD, 0x7445), DEVICE_INTEL }, /* AMD768 */
446 { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */ 446 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
447 { 0, } 447 { 0, }
448}; 448};
449 449
@@ -1954,6 +1954,18 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1954 .name = "Sony S1XP", 1954 .name = "Sony S1XP",
1955 .type = AC97_TUNE_INV_EAPD 1955 .type = AC97_TUNE_INV_EAPD
1956 }, 1956 },
1957 {
1958 .subvendor = 0x104d,
1959 .subdevice = 0x81c0,
1960 .name = "Sony VAIO VGN-T350P", /*AD1981B*/
1961 .type = AC97_TUNE_INV_EAPD
1962 },
1963 {
1964 .subvendor = 0x104d,
1965 .subdevice = 0x81c5,
1966 .name = "Sony VAIO VGN-B1VP", /*AD1981B*/
1967 .type = AC97_TUNE_INV_EAPD
1968 },
1957 { 1969 {
1958 .subvendor = 0x1043, 1970 .subvendor = 0x1043,
1959 .subdevice = 0x80f3, 1971 .subdevice = 0x80f3,
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index 6ec0fc50d6be..9e7d12e7673f 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -220,24 +220,24 @@ struct intel8x0m {
220}; 220};
221 221
222static struct pci_device_id snd_intel8x0m_ids[] = { 222static struct pci_device_id snd_intel8x0m_ids[] = {
223 { 0x8086, 0x2416, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */ 223 { PCI_VDEVICE(INTEL, 0x2416), DEVICE_INTEL }, /* 82801AA */
224 { 0x8086, 0x2426, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */ 224 { PCI_VDEVICE(INTEL, 0x2426), DEVICE_INTEL }, /* 82901AB */
225 { 0x8086, 0x2446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */ 225 { PCI_VDEVICE(INTEL, 0x2446), DEVICE_INTEL }, /* 82801BA */
226 { 0x8086, 0x2486, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */ 226 { PCI_VDEVICE(INTEL, 0x2486), DEVICE_INTEL }, /* ICH3 */
227 { 0x8086, 0x24c6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH4 */ 227 { PCI_VDEVICE(INTEL, 0x24c6), DEVICE_INTEL }, /* ICH4 */
228 { 0x8086, 0x24d6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH5 */ 228 { PCI_VDEVICE(INTEL, 0x24d6), DEVICE_INTEL }, /* ICH5 */
229 { 0x8086, 0x266d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH6 */ 229 { PCI_VDEVICE(INTEL, 0x266d), DEVICE_INTEL }, /* ICH6 */
230 { 0x8086, 0x27dd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH7 */ 230 { PCI_VDEVICE(INTEL, 0x27dd), DEVICE_INTEL }, /* ICH7 */
231 { 0x8086, 0x7196, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */ 231 { PCI_VDEVICE(INTEL, 0x7196), DEVICE_INTEL }, /* 440MX */
232 { 0x1022, 0x7446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */ 232 { PCI_VDEVICE(AMD, 0x7446), DEVICE_INTEL }, /* AMD768 */
233 { 0x1039, 0x7013, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7013 */ 233 { PCI_VDEVICE(SI, 0x7013), DEVICE_SIS }, /* SI7013 */
234 { 0x10de, 0x01c1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */ 234 { PCI_VDEVICE(NVIDIA, 0x01c1), DEVICE_NFORCE }, /* NFORCE */
235 { 0x10de, 0x0069, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */ 235 { PCI_VDEVICE(NVIDIA, 0x0069), DEVICE_NFORCE }, /* NFORCE2 */
236 { 0x10de, 0x0089, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2s */ 236 { PCI_VDEVICE(NVIDIA, 0x0089), DEVICE_NFORCE }, /* NFORCE2s */
237 { 0x10de, 0x00d9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */ 237 { PCI_VDEVICE(NVIDIA, 0x00d9), DEVICE_NFORCE }, /* NFORCE3 */
238#if 0 238#if 0
239 { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */ 239 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
240 { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */ 240 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
241#endif 241#endif
242 { 0, } 242 { 0, }
243}; 243};
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c
index 18da2ef04d09..11b8c6514b3d 100644
--- a/sound/pci/lx6464es/lx6464es.c
+++ b/sound/pci/lx6464es/lx6464es.c
@@ -654,13 +654,12 @@ static int __devinit lx_init_ethersound_config(struct lx6464es *chip)
654 int i; 654 int i;
655 u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES); 655 u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES);
656 656
657 u32 default_conf_es = (64 << IOCR_OUTPUTS_OFFSET) | 657 /* configure 64 io channels */
658 u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK) |
658 (64 << IOCR_INPUTS_OFFSET) | 659 (64 << IOCR_INPUTS_OFFSET) |
660 (64 << IOCR_OUTPUTS_OFFSET) |
659 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET); 661 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET);
660 662
661 u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK)
662 | (default_conf_es & CONFES_WRITE_PART_MASK);
663
664 snd_printdd("->lx_init_ethersound\n"); 663 snd_printdd("->lx_init_ethersound\n");
665 664
666 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE; 665 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE;
diff --git a/sound/pci/lx6464es/lx6464es.h b/sound/pci/lx6464es/lx6464es.h
index 012c010c8c89..51afc048961d 100644
--- a/sound/pci/lx6464es/lx6464es.h
+++ b/sound/pci/lx6464es/lx6464es.h
@@ -86,7 +86,6 @@ struct lx6464es {
86 86
87 /* messaging */ 87 /* messaging */
88 spinlock_t msg_lock; /* message spinlock */ 88 spinlock_t msg_lock; /* message spinlock */
89 atomic_t send_message_locked;
90 struct lx_rmh rmh; 89 struct lx_rmh rmh;
91 90
92 /* configuration */ 91 /* configuration */
@@ -95,7 +94,6 @@ struct lx6464es {
95 uint hardware_running[2]; 94 uint hardware_running[2];
96 u32 board_sample_rate; /* sample rate read from 95 u32 board_sample_rate; /* sample rate read from
97 * board */ 96 * board */
98 u32 sample_rate; /* our sample rate */
99 u16 pcm_granularity; /* board blocksize */ 97 u16 pcm_granularity; /* board blocksize */
100 98
101 /* dma */ 99 /* dma */
diff --git a/sound/pci/lx6464es/lx_core.c b/sound/pci/lx6464es/lx_core.c
index 5812780d6e89..3086b751da4a 100644
--- a/sound/pci/lx6464es/lx_core.c
+++ b/sound/pci/lx6464es/lx_core.c
@@ -314,98 +314,6 @@ static inline void lx_message_dump(struct lx_rmh *rmh)
314#define XILINX_POLL_NO_SLEEP 100 314#define XILINX_POLL_NO_SLEEP 100
315#define XILINX_POLL_ITERATIONS 150 315#define XILINX_POLL_ITERATIONS 150
316 316
317#if 0 /* not used now */
318static int lx_message_send(struct lx6464es *chip, struct lx_rmh *rmh)
319{
320 u32 reg = ED_DSP_TIMED_OUT;
321 int dwloop;
322 int answer_received;
323
324 if (lx_dsp_reg_read(chip, eReg_CSM) & (Reg_CSM_MC | Reg_CSM_MR)) {
325 snd_printk(KERN_ERR LXP "PIOSendMessage eReg_CSM %x\n", reg);
326 return -EBUSY;
327 }
328
329 /* write command */
330 lx_dsp_reg_writebuf(chip, eReg_CRM1, rmh->cmd, rmh->cmd_len);
331
332 snd_BUG_ON(atomic_read(&chip->send_message_locked) != 0);
333 atomic_set(&chip->send_message_locked, 1);
334
335 /* MicoBlaze gogogo */
336 lx_dsp_reg_write(chip, eReg_CSM, Reg_CSM_MC);
337
338 /* wait for interrupt to answer */
339 for (dwloop = 0; dwloop != XILINX_TIMEOUT_MS; ++dwloop) {
340 answer_received = atomic_read(&chip->send_message_locked);
341 if (answer_received == 0)
342 break;
343 msleep(1);
344 }
345
346 if (answer_received == 0) {
347 /* in Debug mode verify Reg_CSM_MR */
348 snd_BUG_ON(!(lx_dsp_reg_read(chip, eReg_CSM) & Reg_CSM_MR));
349
350 /* command finished, read status */
351 if (rmh->dsp_stat == 0)
352 reg = lx_dsp_reg_read(chip, eReg_CRM1);
353 else
354 reg = 0;
355 } else {
356 int i;
357 snd_printk(KERN_WARNING LXP "TIMEOUT lx_message_send! "
358 "Interrupts disabled?\n");
359
360 /* attente bit Reg_CSM_MR */
361 for (i = 0; i != XILINX_POLL_ITERATIONS; i++) {
362 if ((lx_dsp_reg_read(chip, eReg_CSM) & Reg_CSM_MR)) {
363 if (rmh->dsp_stat == 0)
364 reg = lx_dsp_reg_read(chip, eReg_CRM1);
365 else
366 reg = 0;
367 goto polling_successful;
368 }
369
370 if (i > XILINX_POLL_NO_SLEEP)
371 msleep(1);
372 }
373 snd_printk(KERN_WARNING LXP "TIMEOUT lx_message_send! "
374 "polling failed\n");
375
376polling_successful:
377 atomic_set(&chip->send_message_locked, 0);
378 }
379
380 if ((reg & ERROR_VALUE) == 0) {
381 /* read response */
382 if (rmh->stat_len) {
383 snd_BUG_ON(rmh->stat_len >= (REG_CRM_NUMBER-1));
384
385 lx_dsp_reg_readbuf(chip, eReg_CRM2, rmh->stat,
386 rmh->stat_len);
387 }
388 } else
389 snd_printk(KERN_WARNING LXP "lx_message_send: error_value %x\n",
390 reg);
391
392 /* clear Reg_CSM_MR */
393 lx_dsp_reg_write(chip, eReg_CSM, 0);
394
395 switch (reg) {
396 case ED_DSP_TIMED_OUT:
397 snd_printk(KERN_WARNING LXP "lx_message_send: dsp timeout\n");
398 return -ETIMEDOUT;
399
400 case ED_DSP_CRASHED:
401 snd_printk(KERN_WARNING LXP "lx_message_send: dsp crashed\n");
402 return -EAGAIN;
403 }
404
405 lx_message_dump(rmh);
406 return 0;
407}
408#endif /* not used now */
409 317
410static int lx_message_send_atomic(struct lx6464es *chip, struct lx_rmh *rmh) 318static int lx_message_send_atomic(struct lx6464es *chip, struct lx_rmh *rmh)
411{ 319{
@@ -423,7 +331,7 @@ static int lx_message_send_atomic(struct lx6464es *chip, struct lx_rmh *rmh)
423 /* MicoBlaze gogogo */ 331 /* MicoBlaze gogogo */
424 lx_dsp_reg_write(chip, eReg_CSM, Reg_CSM_MC); 332 lx_dsp_reg_write(chip, eReg_CSM, Reg_CSM_MC);
425 333
426 /* wait for interrupt to answer */ 334 /* wait for device to answer */
427 for (dwloop = 0; dwloop != XILINX_TIMEOUT_MS * 1000; ++dwloop) { 335 for (dwloop = 0; dwloop != XILINX_TIMEOUT_MS * 1000; ++dwloop) {
428 if (lx_dsp_reg_read(chip, eReg_CSM) & Reg_CSM_MR) { 336 if (lx_dsp_reg_read(chip, eReg_CSM) & Reg_CSM_MR) {
429 if (rmh->dsp_stat == 0) 337 if (rmh->dsp_stat == 0)
@@ -1175,10 +1083,6 @@ static int lx_interrupt_ack(struct lx6464es *chip, u32 *r_irqsrc,
1175 *r_async_escmd = 1; 1083 *r_async_escmd = 1;
1176 } 1084 }
1177 1085
1178 if (irqsrc & MASK_SYS_STATUS_CMD_DONE)
1179 /* xilinx command notification */
1180 atomic_set(&chip->send_message_locked, 0);
1181
1182 if (irq_async) { 1086 if (irq_async) {
1183 /* snd_printd("interrupt: async event pending\n"); */ 1087 /* snd_printd("interrupt: async event pending\n"); */
1184 *r_async_pending = 1; 1088 *r_async_pending = 1;
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index 82bc5b9e7629..a83d1968a845 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -61,7 +61,7 @@ MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
61 */ 61 */
62 62
63static struct pci_device_id snd_mixart_ids[] = { 63static struct pci_device_id snd_mixart_ids[] = {
64 { 0x1057, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* MC8240 */ 64 { PCI_VDEVICE(MOTOROLA, 0x0003), 0, }, /* MC8240 */
65 { 0, } 65 { 0, }
66}; 66};
67 67
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 522a040855d4..97a0731331a1 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -263,9 +263,9 @@ struct nm256 {
263 * PCI ids 263 * PCI ids
264 */ 264 */
265static struct pci_device_id snd_nm256_ids[] = { 265static struct pci_device_id snd_nm256_ids[] = {
266 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 266 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO), 0},
267 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 267 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO), 0},
268 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 268 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO), 0},
269 {0,}, 269 {0,},
270}; 270};
271 271
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index c1eb923f2ac9..09b2b2a36df5 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 312251d39696..9a8936e20744 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_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 304da169bfdc..5401c547c4e3 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -575,8 +575,10 @@ static int ac97_switch_put(struct snd_kcontrol *ctl,
575static int ac97_volume_info(struct snd_kcontrol *ctl, 575static int ac97_volume_info(struct snd_kcontrol *ctl,
576 struct snd_ctl_elem_info *info) 576 struct snd_ctl_elem_info *info)
577{ 577{
578 int stereo = (ctl->private_value >> 16) & 1;
579
578 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 580 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
579 info->count = 2; 581 info->count = stereo ? 2 : 1;
580 info->value.integer.min = 0; 582 info->value.integer.min = 0;
581 info->value.integer.max = 0x1f; 583 info->value.integer.max = 0x1f;
582 return 0; 584 return 0;
@@ -587,6 +589,7 @@ static int ac97_volume_get(struct snd_kcontrol *ctl,
587{ 589{
588 struct oxygen *chip = ctl->private_data; 590 struct oxygen *chip = ctl->private_data;
589 unsigned int codec = (ctl->private_value >> 24) & 1; 591 unsigned int codec = (ctl->private_value >> 24) & 1;
592 int stereo = (ctl->private_value >> 16) & 1;
590 unsigned int index = ctl->private_value & 0xff; 593 unsigned int index = ctl->private_value & 0xff;
591 u16 reg; 594 u16 reg;
592 595
@@ -594,7 +597,8 @@ static int ac97_volume_get(struct snd_kcontrol *ctl,
594 reg = oxygen_read_ac97(chip, codec, index); 597 reg = oxygen_read_ac97(chip, codec, index);
595 mutex_unlock(&chip->mutex); 598 mutex_unlock(&chip->mutex);
596 value->value.integer.value[0] = 31 - (reg & 0x1f); 599 value->value.integer.value[0] = 31 - (reg & 0x1f);
597 value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f); 600 if (stereo)
601 value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f);
598 return 0; 602 return 0;
599} 603}
600 604
@@ -603,6 +607,7 @@ static int ac97_volume_put(struct snd_kcontrol *ctl,
603{ 607{
604 struct oxygen *chip = ctl->private_data; 608 struct oxygen *chip = ctl->private_data;
605 unsigned int codec = (ctl->private_value >> 24) & 1; 609 unsigned int codec = (ctl->private_value >> 24) & 1;
610 int stereo = (ctl->private_value >> 16) & 1;
606 unsigned int index = ctl->private_value & 0xff; 611 unsigned int index = ctl->private_value & 0xff;
607 u16 oldreg, newreg; 612 u16 oldreg, newreg;
608 int change; 613 int change;
@@ -612,8 +617,11 @@ static int ac97_volume_put(struct snd_kcontrol *ctl,
612 newreg = oldreg; 617 newreg = oldreg;
613 newreg = (newreg & ~0x1f) | 618 newreg = (newreg & ~0x1f) |
614 (31 - (value->value.integer.value[0] & 0x1f)); 619 (31 - (value->value.integer.value[0] & 0x1f));
615 newreg = (newreg & ~0x1f00) | 620 if (stereo)
616 ((31 - (value->value.integer.value[0] & 0x1f)) << 8); 621 newreg = (newreg & ~0x1f00) |
622 ((31 - (value->value.integer.value[1] & 0x1f)) << 8);
623 else
624 newreg = (newreg & ~0x1f00) | ((newreg & 0x1f) << 8);
617 change = newreg != oldreg; 625 change = newreg != oldreg;
618 if (change) 626 if (change)
619 oxygen_write_ac97(chip, codec, index, newreg); 627 oxygen_write_ac97(chip, codec, index, newreg);
@@ -673,7 +681,7 @@ static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl,
673 .private_value = ((codec) << 24) | ((invert) << 16) | \ 681 .private_value = ((codec) << 24) | ((invert) << 16) | \
674 ((bitnr) << 8) | (index), \ 682 ((bitnr) << 8) | (index), \
675 } 683 }
676#define AC97_VOLUME(xname, codec, index) { \ 684#define AC97_VOLUME(xname, codec, index, stereo) { \
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
678 .name = xname, \ 686 .name = xname, \
679 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ 687 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
@@ -682,7 +690,7 @@ static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl,
682 .get = ac97_volume_get, \ 690 .get = ac97_volume_get, \
683 .put = ac97_volume_put, \ 691 .put = ac97_volume_put, \
684 .tlv = { .p = ac97_db_scale, }, \ 692 .tlv = { .p = ac97_db_scale, }, \
685 .private_value = ((codec) << 24) | (index), \ 693 .private_value = ((codec) << 24) | ((stereo) << 16) | (index), \
686 } 694 }
687 695
688static DECLARE_TLV_DB_SCALE(monitor_db_scale, -1000, 1000, 0); 696static DECLARE_TLV_DB_SCALE(monitor_db_scale, -1000, 1000, 0);
@@ -882,18 +890,18 @@ static const struct {
882}; 890};
883 891
884static const struct snd_kcontrol_new ac97_controls[] = { 892static const struct snd_kcontrol_new ac97_controls[] = {
885 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC), 893 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC, 0),
886 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1), 894 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1),
887 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0), 895 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0),
888 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1), 896 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1),
889 AC97_VOLUME("CD Capture Volume", 0, AC97_CD), 897 AC97_VOLUME("CD Capture Volume", 0, AC97_CD, 1),
890 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1), 898 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1),
891 AC97_VOLUME("Aux Capture Volume", 0, AC97_AUX), 899 AC97_VOLUME("Aux Capture Volume", 0, AC97_AUX, 1),
892 AC97_SWITCH("Aux Capture Switch", 0, AC97_AUX, 15, 1), 900 AC97_SWITCH("Aux Capture Switch", 0, AC97_AUX, 15, 1),
893}; 901};
894 902
895static const struct snd_kcontrol_new ac97_fp_controls[] = { 903static const struct snd_kcontrol_new ac97_fp_controls[] = {
896 AC97_VOLUME("Front Panel Playback Volume", 1, AC97_HEADPHONE), 904 AC97_VOLUME("Front Panel Playback Volume", 1, AC97_HEADPHONE, 1),
897 AC97_SWITCH("Front Panel Playback Switch", 1, AC97_HEADPHONE, 15, 1), 905 AC97_SWITCH("Front Panel Playback Switch", 1, AC97_HEADPHONE, 15, 1),
898 { 906 {
899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index 3b5ca70c9d4d..ef2345d82b86 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 bf971f7cfdc6..6ebcb6bdd712 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 235a71e5ac8d..b5ca02e2038c 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/rme32.c b/sound/pci/rme32.c
index d7b966e7c4cf..f977dba7cbd0 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -227,12 +227,9 @@ struct rme32 {
227}; 227};
228 228
229static struct pci_device_id snd_rme32_ids[] = { 229static struct pci_device_id snd_rme32_ids[] = {
230 {PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32, 230 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32), 0,},
231 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,}, 231 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_8), 0,},
232 {PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_8, 232 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_PRO), 0,},
233 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
234 {PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_PRO,
235 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
236 {0,} 233 {0,}
237}; 234};
238 235
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index 55fb1c131f58..2ba5c0fd55db 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -232,14 +232,10 @@ struct rme96 {
232}; 232};
233 233
234static struct pci_device_id snd_rme96_ids[] = { 234static struct pci_device_id snd_rme96_ids[] = {
235 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96, 235 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96), 0, },
236 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 236 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8), 0, },
237 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8, 237 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PRO), 0, },
238 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 238 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST), 0, },
239 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PRO,
240 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
241 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST,
242 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
243 { 0, } 239 { 0, }
244}; 240};
245 241
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 3da5c029f93b..7bb827c7d806 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/sonicvibes.c b/sound/pci/sonicvibes.c
index 7dc60ad4772e..1f6406c4534d 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -243,7 +243,7 @@ struct sonicvibes {
243}; 243};
244 244
245static struct pci_device_id snd_sonic_ids[] = { 245static struct pci_device_id snd_sonic_ids[] = {
246 { 0x5333, 0xca00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 246 { PCI_VDEVICE(S3, 0xca00), 0, },
247 { 0, } 247 { 0, }
248}; 248};
249 249
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 949fcaf6b70e..acfa4760da49 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -402,9 +402,9 @@ struct via82xx {
402 402
403static struct pci_device_id snd_via82xx_ids[] = { 403static struct pci_device_id snd_via82xx_ids[] = {
404 /* 0x1106, 0x3058 */ 404 /* 0x1106, 0x3058 */
405 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ 405 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686_5), TYPE_CARD_VIA686, }, /* 686A */
406 /* 0x1106, 0x3059 */ 406 /* 0x1106, 0x3059 */
407 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ 407 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233_5), TYPE_CARD_VIA8233, }, /* VT8233 */
408 { 0, } 408 { 0, }
409}; 409};
410 410
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 0d54e3503c1e..47eb61561dfc 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -261,7 +261,7 @@ struct via82xx_modem {
261}; 261};
262 262
263static struct pci_device_id snd_via82xx_modem_ids[] = { 263static struct pci_device_id snd_via82xx_modem_ids[] = {
264 { 0x1106, 0x3068, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA82XX_MODEM, }, 264 { PCI_VDEVICE(VIA, 0x3068), TYPE_CARD_VIA82XX_MODEM, },
265 { 0, } 265 { 0, }
266}; 266};
267 267
diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c
index 6416d3f0c7be..a69e774d0b13 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.c b/sound/pci/ymfpci/ymfpci.c
index 4af66661f9b0..e6b18b90d451 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -67,12 +67,12 @@ module_param_array(rear_switch, bool, NULL, 0444);
67MODULE_PARM_DESC(rear_switch, "Enable shared rear/line-in switch"); 67MODULE_PARM_DESC(rear_switch, "Enable shared rear/line-in switch");
68 68
69static struct pci_device_id snd_ymfpci_ids[] = { 69static struct pci_device_id snd_ymfpci_ids[] = {
70 { 0x1073, 0x0004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF724 */ 70 { PCI_VDEVICE(YAMAHA, 0x0004), 0, }, /* YMF724 */
71 { 0x1073, 0x000d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF724F */ 71 { PCI_VDEVICE(YAMAHA, 0x000d), 0, }, /* YMF724F */
72 { 0x1073, 0x000a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF740 */ 72 { PCI_VDEVICE(YAMAHA, 0x000a), 0, }, /* YMF740 */
73 { 0x1073, 0x000c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF740C */ 73 { PCI_VDEVICE(YAMAHA, 0x000c), 0, }, /* YMF740C */
74 { 0x1073, 0x0010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF744 */ 74 { PCI_VDEVICE(YAMAHA, 0x0010), 0, }, /* YMF744 */
75 { 0x1073, 0x0012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF754 */ 75 { PCI_VDEVICE(YAMAHA, 0x0012), 0, }, /* YMF754 */
76 { 0, } 76 { 0, }
77}; 77};
78 78
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 2f0925236a1b..5518371db13f 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,
diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c
index 835fa19ed461..d06f780bd7e8 100644
--- a/sound/ppc/keywest.c
+++ b/sound/ppc/keywest.c
@@ -59,6 +59,18 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
59 strlcpy(info.type, "keywest", I2C_NAME_SIZE); 59 strlcpy(info.type, "keywest", I2C_NAME_SIZE);
60 info.addr = keywest_ctx->addr; 60 info.addr = keywest_ctx->addr;
61 keywest_ctx->client = i2c_new_device(adapter, &info); 61 keywest_ctx->client = i2c_new_device(adapter, &info);
62 if (!keywest_ctx->client)
63 return -ENODEV;
64 /*
65 * We know the driver is already loaded, so the device should be
66 * already bound. If not it means binding failed, and then there
67 * is no point in keeping the device instantiated.
68 */
69 if (!keywest_ctx->client->driver) {
70 i2c_unregister_device(keywest_ctx->client);
71 keywest_ctx->client = NULL;
72 return -ENODEV;
73 }
62 74
63 /* 75 /*
64 * Let i2c-core delete that device on driver removal. 76 * Let i2c-core delete that device on driver removal.
@@ -86,7 +98,7 @@ static const struct i2c_device_id keywest_i2c_id[] = {
86 { } 98 { }
87}; 99};
88 100
89struct i2c_driver keywest_driver = { 101static struct i2c_driver keywest_driver = {
90 .driver = { 102 .driver = {
91 .name = "PMac Keywest Audio", 103 .name = "PMac Keywest Audio",
92 }, 104 },
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index 130b12118d4f..885ba012557e 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -193,38 +193,6 @@ static struct snd_soc_card snd_soc_at91sam9g20ek = {
193 .set_bias_level = at91sam9g20ek_set_bias_level, 193 .set_bias_level = at91sam9g20ek_set_bias_level,
194}; 194};
195 195
196/*
197 * FIXME: This is a temporary bodge to avoid cross-tree merge issues.
198 * New drivers should register the wm8731 I2C device in the machine
199 * setup code (under arch/arm for ARM systems).
200 */
201static int wm8731_i2c_register(void)
202{
203 struct i2c_board_info info;
204 struct i2c_adapter *adapter;
205 struct i2c_client *client;
206
207 memset(&info, 0, sizeof(struct i2c_board_info));
208 info.addr = 0x1b;
209 strlcpy(info.type, "wm8731", I2C_NAME_SIZE);
210
211 adapter = i2c_get_adapter(0);
212 if (!adapter) {
213 printk(KERN_ERR "can't get i2c adapter 0\n");
214 return -ENODEV;
215 }
216
217 client = i2c_new_device(adapter, &info);
218 i2c_put_adapter(adapter);
219 if (!client) {
220 printk(KERN_ERR "can't add i2c device at 0x%x\n",
221 (unsigned int)info.addr);
222 return -ENODEV;
223 }
224
225 return 0;
226}
227
228static struct snd_soc_device at91sam9g20ek_snd_devdata = { 196static struct snd_soc_device at91sam9g20ek_snd_devdata = {
229 .card = &snd_soc_at91sam9g20ek, 197 .card = &snd_soc_at91sam9g20ek,
230 .codec_dev = &soc_codec_dev_wm8731, 198 .codec_dev = &soc_codec_dev_wm8731,
@@ -279,10 +247,6 @@ static int __init at91sam9g20ek_init(void)
279 } 247 }
280 ssc_p->ssc = ssc; 248 ssc_p->ssc = ssc;
281 249
282 ret = wm8731_i2c_register();
283 if (ret != 0)
284 goto err_ssc;
285
286 at91sam9g20ek_snd_device = platform_device_alloc("soc-audio", -1); 250 at91sam9g20ek_snd_device = platform_device_alloc("soc-audio", -1);
287 if (!at91sam9g20ek_snd_device) { 251 if (!at91sam9g20ek_snd_device) {
288 printk(KERN_ERR "ASoC: Platform device allocation failed\n"); 252 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index 1c8653523c8c..3f530f8a972a 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -992,14 +992,14 @@ static int __devinit wm8988_spi_probe(struct spi_device *spi)
992 codec->control_data = spi; 992 codec->control_data = spi;
993 codec->dev = &spi->dev; 993 codec->dev = &spi->dev;
994 994
995 spi->dev.driver_data = wm8988; 995 dev_set_drvdata(&spi->dev, wm8988);
996 996
997 return wm8988_register(wm8988, SND_SOC_SPI); 997 return wm8988_register(wm8988, SND_SOC_SPI);
998} 998}
999 999
1000static int __devexit wm8988_spi_remove(struct spi_device *spi) 1000static int __devexit wm8988_spi_remove(struct spi_device *spi)
1001{ 1001{
1002 struct wm8988_priv *wm8988 = spi->dev.driver_data; 1002 struct wm8988_priv *wm8988 = dev_get_drvdata(&spi->dev);
1003 1003
1004 wm8988_unregister(wm8988); 1004 wm8988_unregister(wm8988);
1005 1005
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index c64e55aa63b6..686e5aa97206 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -1027,7 +1027,7 @@ static int wm9081_hw_params(struct snd_pcm_substream *substream,
1027 - wm9081->fs); 1027 - wm9081->fs);
1028 for (i = 1; i < ARRAY_SIZE(clk_sys_rates); i++) { 1028 for (i = 1; i < ARRAY_SIZE(clk_sys_rates); i++) {
1029 cur_val = abs((wm9081->sysclk_rate / 1029 cur_val = abs((wm9081->sysclk_rate /
1030 clk_sys_rates[i].ratio) - wm9081->fs);; 1030 clk_sys_rates[i].ratio) - wm9081->fs);
1031 if (cur_val < best_val) { 1031 if (cur_val < best_val) {
1032 best = i; 1032 best = i;
1033 best_val = cur_val; 1033 best_val = cur_val;
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
index 1152d8ba8970..fb10f1d63fdb 100644
--- a/sound/soc/davinci/davinci-pcm.c
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -153,7 +153,7 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
153 prtd->master_lch = ret; 153 prtd->master_lch = ret;
154 154
155 /* Request parameter RAM reload slot */ 155 /* Request parameter RAM reload slot */
156 ret = edma_alloc_slot(EDMA_SLOT_ANY); 156 ret = edma_alloc_slot(EDMA_CTLR(prtd->master_lch), EDMA_SLOT_ANY);
157 if (ret < 0) { 157 if (ret < 0) {
158 edma_free_channel(prtd->master_lch); 158 edma_free_channel(prtd->master_lch);
159 return ret; 159 return ret;
@@ -170,8 +170,8 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
170 * so davinci_pcm_enqueue_dma() takes less time in IRQ. 170 * so davinci_pcm_enqueue_dma() takes less time in IRQ.
171 */ 171 */
172 edma_read_slot(prtd->slave_lch, &p_ram); 172 edma_read_slot(prtd->slave_lch, &p_ram);
173 p_ram.opt |= TCINTEN | EDMA_TCC(prtd->master_lch); 173 p_ram.opt |= TCINTEN | EDMA_TCC(EDMA_CHAN_SLOT(prtd->master_lch));
174 p_ram.link_bcntrld = prtd->slave_lch << 5; 174 p_ram.link_bcntrld = EDMA_CHAN_SLOT(prtd->slave_lch) << 5;
175 edma_write_slot(prtd->slave_lch, &p_ram); 175 edma_write_slot(prtd->slave_lch, &p_ram);
176 176
177 return 0; 177 return 0;
diff --git a/sound/soc/fsl/efika-audio-fabric.c b/sound/soc/fsl/efika-audio-fabric.c
index 85b0e7569504..3326e2a1e863 100644
--- a/sound/soc/fsl/efika-audio-fabric.c
+++ b/sound/soc/fsl/efika-audio-fabric.c
@@ -30,6 +30,8 @@
30#include "mpc5200_psc_ac97.h" 30#include "mpc5200_psc_ac97.h"
31#include "../codecs/stac9766.h" 31#include "../codecs/stac9766.h"
32 32
33#define DRV_NAME "efika-audio-fabric"
34
33static struct snd_soc_device device; 35static struct snd_soc_device device;
34static struct snd_soc_card card; 36static struct snd_soc_card card;
35 37
diff --git a/sound/soc/fsl/pcm030-audio-fabric.c b/sound/soc/fsl/pcm030-audio-fabric.c
index 8766f7a3893d..b928ef7d28eb 100644
--- a/sound/soc/fsl/pcm030-audio-fabric.c
+++ b/sound/soc/fsl/pcm030-audio-fabric.c
@@ -30,6 +30,8 @@
30#include "mpc5200_psc_ac97.h" 30#include "mpc5200_psc_ac97.h"
31#include "../codecs/wm9712.h" 31#include "../codecs/wm9712.h"
32 32
33#define DRV_NAME "pcm030-audio-fabric"
34
33static struct snd_soc_device device; 35static struct snd_soc_device device;
34static struct snd_soc_card card; 36static struct snd_soc_card card;
35 37
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c
index a2b1e8fd5d85..3bd7712f029b 100644
--- a/sound/soc/pxa/pxa-ssp.c
+++ b/sound/soc/pxa/pxa-ssp.c
@@ -351,7 +351,7 @@ static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
351 do_div(tmp, freq_out); 351 do_div(tmp, freq_out);
352 val = tmp; 352 val = tmp;
353 353
354 val = (val << 16) | 64;; 354 val = (val << 16) | 64;
355 ssp_write_reg(ssp, SSACDD, val); 355 ssp_write_reg(ssp, SSACDD, val);
356 356
357 ssacd |= (0x6 << 4); 357 ssacd |= (0x6 << 4);
diff --git a/sound/soc/s3c24xx/s3c24xx-ac97.h b/sound/soc/s3c24xx/s3c24xx-ac97.h
index a96dcadf28b4..e96f941a810b 100644
--- a/sound/soc/s3c24xx/s3c24xx-ac97.h
+++ b/sound/soc/s3c24xx/s3c24xx-ac97.h
@@ -20,12 +20,6 @@
20#define AC_CMD_ADDR(x) (x << 16) 20#define AC_CMD_ADDR(x) (x << 16)
21#define AC_CMD_DATA(x) (x & 0xffff) 21#define AC_CMD_DATA(x) (x & 0xffff)
22 22
23#ifdef CONFIG_CPU_S3C2440
24#define IRQ_S3C244x_AC97 IRQ_S3C2440_AC97
25#else
26#define IRQ_S3C244x_AC97 IRQ_S3C2443_AC97
27#endif
28
29extern struct snd_soc_dai s3c2443_ac97_dai[]; 23extern struct snd_soc_dai s3c2443_ac97_dai[];
30 24
31#endif /*S3C24XXAC97_H_*/ 25#endif /*S3C24XXAC97_H_*/
diff --git a/sound/soc/s3c24xx/s3c24xx_uda134x.c b/sound/soc/s3c24xx/s3c24xx_uda134x.c
index 8e79a416db57..c215d32d6322 100644
--- a/sound/soc/s3c24xx/s3c24xx_uda134x.c
+++ b/sound/soc/s3c24xx/s3c24xx_uda134x.c
@@ -67,7 +67,7 @@ static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream)
67{ 67{
68 int ret = 0; 68 int ret = 0;
69#ifdef ENFORCE_RATES 69#ifdef ENFORCE_RATES
70 struct snd_pcm_runtime *runtime = substream->runtime;; 70 struct snd_pcm_runtime *runtime = substream->runtime;
71#endif 71#endif
72 72
73 mutex_lock(&clk_lock); 73 mutex_lock(&clk_lock);
diff --git a/sound/sound_core.c b/sound/sound_core.c
index 12522e6913d9..49c998186592 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -10,6 +10,8 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/err.h> 12#include <linux/err.h>
13#include <linux/kdev_t.h>
14#include <linux/major.h>
13#include <sound/core.h> 15#include <sound/core.h>
14 16
15#ifdef CONFIG_SOUND_OSS_CORE 17#ifdef CONFIG_SOUND_OSS_CORE
@@ -27,8 +29,10 @@ MODULE_DESCRIPTION("Core sound module");
27MODULE_AUTHOR("Alan Cox"); 29MODULE_AUTHOR("Alan Cox");
28MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
29 31
30static char *sound_nodename(struct device *dev) 32static char *sound_devnode(struct device *dev, mode_t *mode)
31{ 33{
34 if (MAJOR(dev->devt) == SOUND_MAJOR)
35 return NULL;
32 return kasprintf(GFP_KERNEL, "snd/%s", dev_name(dev)); 36 return kasprintf(GFP_KERNEL, "snd/%s", dev_name(dev));
33} 37}
34 38
@@ -46,7 +50,7 @@ static int __init init_soundcore(void)
46 return PTR_ERR(sound_class); 50 return PTR_ERR(sound_class);
47 } 51 }
48 52
49 sound_class->nodename = sound_nodename; 53 sound_class->devnode = sound_devnode;
50 54
51 return 0; 55 return 0;
52} 56}
@@ -104,7 +108,6 @@ module_exit(cleanup_soundcore);
104#include <linux/types.h> 108#include <linux/types.h>
105#include <linux/kernel.h> 109#include <linux/kernel.h>
106#include <linux/sound.h> 110#include <linux/sound.h>
107#include <linux/major.h>
108#include <linux/kmod.h> 111#include <linux/kmod.h>
109 112
110#define SOUND_STEP 16 113#define SOUND_STEP 16
@@ -125,6 +128,46 @@ extern int msnd_pinnacle_init(void);
125#endif 128#endif
126 129
127/* 130/*
131 * By default, OSS sound_core claims full legacy minor range (0-255)
132 * of SOUND_MAJOR to trap open attempts to any sound minor and
133 * requests modules using custom sound-slot/service-* module aliases.
134 * The only benefit of doing this is allowing use of custom module
135 * aliases instead of the standard char-major-* ones. This behavior
136 * prevents alternative OSS implementation and is scheduled to be
137 * removed.
138 *
139 * CONFIG_SOUND_OSS_CORE_PRECLAIM and soundcore.preclaim_oss kernel
140 * parameter are added to allow distros and developers to try and
141 * switch to alternative implementations without needing to rebuild
142 * the kernel in the meantime. If preclaim_oss is non-zero, the
143 * kernel will behave the same as before. All SOUND_MAJOR minors are
144 * preclaimed and the custom module aliases along with standard chrdev
145 * ones are emitted if a missing device is opened. If preclaim_oss is
146 * zero, sound_core only grabs what's actually in use and for missing
147 * devices only the standard chrdev aliases are requested.
148 *
149 * All these clutters are scheduled to be removed along with
150 * sound-slot/service-* module aliases. Please take a look at
151 * feature-removal-schedule.txt for details.
152 */
153#ifdef CONFIG_SOUND_OSS_CORE_PRECLAIM
154static int preclaim_oss = 1;
155#else
156static int preclaim_oss = 0;
157#endif
158
159module_param(preclaim_oss, int, 0444);
160
161static int soundcore_open(struct inode *, struct file *);
162
163static const struct file_operations soundcore_fops =
164{
165 /* We must have an owner or the module locking fails */
166 .owner = THIS_MODULE,
167 .open = soundcore_open,
168};
169
170/*
128 * Low level list operator. Scan the ordered list, find a hole and 171 * Low level list operator. Scan the ordered list, find a hole and
129 * join into it. Called with the lock asserted 172 * join into it. Called with the lock asserted
130 */ 173 */
@@ -216,8 +259,9 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
216 259
217 if (!s) 260 if (!s)
218 return -ENOMEM; 261 return -ENOMEM;
219 262
220 spin_lock(&sound_loader_lock); 263 spin_lock(&sound_loader_lock);
264retry:
221 r = __sound_insert_unit(s, list, fops, index, low, top); 265 r = __sound_insert_unit(s, list, fops, index, low, top);
222 spin_unlock(&sound_loader_lock); 266 spin_unlock(&sound_loader_lock);
223 267
@@ -228,11 +272,31 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
228 else 272 else
229 sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP); 273 sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP);
230 274
275 if (!preclaim_oss) {
276 /*
277 * Something else might have grabbed the minor. If
278 * first free slot is requested, rescan with @low set
279 * to the next unit; otherwise, -EBUSY.
280 */
281 r = __register_chrdev(SOUND_MAJOR, s->unit_minor, 1, s->name,
282 &soundcore_fops);
283 if (r < 0) {
284 spin_lock(&sound_loader_lock);
285 __sound_remove_unit(list, s->unit_minor);
286 if (index < 0) {
287 low = s->unit_minor + SOUND_STEP;
288 goto retry;
289 }
290 spin_unlock(&sound_loader_lock);
291 return -EBUSY;
292 }
293 }
294
231 device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor), 295 device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
232 NULL, s->name+6); 296 NULL, s->name+6);
233 return r; 297 return s->unit_minor;
234 298
235 fail: 299fail:
236 kfree(s); 300 kfree(s);
237 return r; 301 return r;
238} 302}
@@ -251,6 +315,9 @@ static void sound_remove_unit(struct sound_unit **list, int unit)
251 p = __sound_remove_unit(list, unit); 315 p = __sound_remove_unit(list, unit);
252 spin_unlock(&sound_loader_lock); 316 spin_unlock(&sound_loader_lock);
253 if (p) { 317 if (p) {
318 if (!preclaim_oss)
319 __unregister_chrdev(SOUND_MAJOR, p->unit_minor, 1,
320 p->name);
254 device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor)); 321 device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
255 kfree(p); 322 kfree(p);
256 } 323 }
@@ -488,19 +555,6 @@ void unregister_sound_dsp(int unit)
488 555
489EXPORT_SYMBOL(unregister_sound_dsp); 556EXPORT_SYMBOL(unregister_sound_dsp);
490 557
491/*
492 * Now our file operations
493 */
494
495static int soundcore_open(struct inode *, struct file *);
496
497static const struct file_operations soundcore_fops=
498{
499 /* We must have an owner or the module locking fails */
500 .owner = THIS_MODULE,
501 .open = soundcore_open,
502};
503
504static struct sound_unit *__look_for_unit(int chain, int unit) 558static struct sound_unit *__look_for_unit(int chain, int unit)
505{ 559{
506 struct sound_unit *s; 560 struct sound_unit *s;
@@ -536,8 +590,9 @@ static int soundcore_open(struct inode *inode, struct file *file)
536 s = __look_for_unit(chain, unit); 590 s = __look_for_unit(chain, unit);
537 if (s) 591 if (s)
538 new_fops = fops_get(s->unit_fops); 592 new_fops = fops_get(s->unit_fops);
539 if (!new_fops) { 593 if (preclaim_oss && !new_fops) {
540 spin_unlock(&sound_loader_lock); 594 spin_unlock(&sound_loader_lock);
595
541 /* 596 /*
542 * Please, don't change this order or code. 597 * Please, don't change this order or code.
543 * For ALSA slot means soundcard and OSS emulation code 598 * For ALSA slot means soundcard and OSS emulation code
@@ -547,6 +602,17 @@ static int soundcore_open(struct inode *inode, struct file *file)
547 */ 602 */
548 request_module("sound-slot-%i", unit>>4); 603 request_module("sound-slot-%i", unit>>4);
549 request_module("sound-service-%i-%i", unit>>4, chain); 604 request_module("sound-service-%i-%i", unit>>4, chain);
605
606 /*
607 * sound-slot/service-* module aliases are scheduled
608 * for removal in favor of the standard char-major-*
609 * module aliases. For the time being, generate both
610 * the legacy and standard module aliases to ease
611 * transition.
612 */
613 if (request_module("char-major-%d-%d", SOUND_MAJOR, unit) > 0)
614 request_module("char-major-%d", SOUND_MAJOR);
615
550 spin_lock(&sound_loader_lock); 616 spin_lock(&sound_loader_lock);
551 s = __look_for_unit(chain, unit); 617 s = __look_for_unit(chain, unit);
552 if (s) 618 if (s)
@@ -590,7 +656,8 @@ static void cleanup_oss_soundcore(void)
590 656
591static int __init init_oss_soundcore(void) 657static int __init init_oss_soundcore(void)
592{ 658{
593 if (register_chrdev(SOUND_MAJOR, "sound", &soundcore_fops)==-1) { 659 if (preclaim_oss &&
660 register_chrdev(SOUND_MAJOR, "sound", &soundcore_fops) == -1) {
594 printk(KERN_ERR "soundcore: sound device already in use.\n"); 661 printk(KERN_ERR "soundcore: sound device already in use.\n");
595 return -EBUSY; 662 return -EBUSY;
596 } 663 }
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index 523aec188ccf..73525c048e7f 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -48,6 +48,7 @@ config SND_USB_CAIAQ
48 * Native Instruments Kore Controller 48 * Native Instruments Kore Controller
49 * Native Instruments Kore Controller 2 49 * Native Instruments Kore Controller 2
50 * Native Instruments Audio Kontrol 1 50 * Native Instruments Audio Kontrol 1
51 * Native Instruments Audio 2 DJ
51 * Native Instruments Audio 4 DJ 52 * Native Instruments Audio 4 DJ
52 * Native Instruments Audio 8 DJ 53 * Native Instruments Audio 8 DJ
53 * Native Instruments Guitar Rig Session I/O 54 * Native Instruments Guitar Rig Session I/O
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 8f9b60c5d74c..121af0644fd9 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -646,6 +646,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
646 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE): 646 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE):
647 dev->samplerates |= SNDRV_PCM_RATE_192000; 647 dev->samplerates |= SNDRV_PCM_RATE_192000;
648 /* fall thru */ 648 /* fall thru */
649 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ):
649 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): 650 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
650 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 651 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
651 dev->samplerates |= SNDRV_PCM_RATE_88200; 652 dev->samplerates |= SNDRV_PCM_RATE_88200;
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index 0e5db719de24..83e6c1312d47 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -35,13 +35,14 @@
35#include "input.h" 35#include "input.h"
36 36
37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.17"); 38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.19");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
41 "{Native Instruments, RigKontrol3}," 41 "{Native Instruments, RigKontrol3},"
42 "{Native Instruments, Kore Controller}," 42 "{Native Instruments, Kore Controller},"
43 "{Native Instruments, Kore Controller 2}," 43 "{Native Instruments, Kore Controller 2},"
44 "{Native Instruments, Audio Kontrol 1}," 44 "{Native Instruments, Audio Kontrol 1},"
45 "{Native Instruments, Audio 2 DJ},"
45 "{Native Instruments, Audio 4 DJ}," 46 "{Native Instruments, Audio 4 DJ},"
46 "{Native Instruments, Audio 8 DJ}," 47 "{Native Instruments, Audio 8 DJ},"
47 "{Native Instruments, Session I/O}," 48 "{Native Instruments, Session I/O},"
@@ -121,6 +122,11 @@ static struct usb_device_id snd_usb_id_table[] = {
121 .idVendor = USB_VID_NATIVEINSTRUMENTS, 122 .idVendor = USB_VID_NATIVEINSTRUMENTS,
122 .idProduct = USB_PID_AUDIO4DJ 123 .idProduct = USB_PID_AUDIO4DJ
123 }, 124 },
125 {
126 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
127 .idVendor = USB_VID_NATIVEINSTRUMENTS,
128 .idProduct = USB_PID_AUDIO2DJ
129 },
124 { /* terminator */ } 130 { /* terminator */ }
125}; 131};
126 132
@@ -349,7 +355,9 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
349 log("Unable to set up control system (ret=%d)\n", ret); 355 log("Unable to set up control system (ret=%d)\n", ret);
350} 356}
351 357
352static int create_card(struct usb_device* usb_dev, struct snd_card **cardp) 358static int create_card(struct usb_device *usb_dev,
359 struct usb_interface *intf,
360 struct snd_card **cardp)
353{ 361{
354 int devnum; 362 int devnum;
355 int err; 363 int err;
@@ -374,7 +382,7 @@ static int create_card(struct usb_device* usb_dev, struct snd_card **cardp)
374 dev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor), 382 dev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
375 le16_to_cpu(usb_dev->descriptor.idProduct)); 383 le16_to_cpu(usb_dev->descriptor.idProduct));
376 spin_lock_init(&dev->spinlock); 384 spin_lock_init(&dev->spinlock);
377 snd_card_set_dev(card, &usb_dev->dev); 385 snd_card_set_dev(card, &intf->dev);
378 386
379 *cardp = card; 387 *cardp = card;
380 return 0; 388 return 0;
@@ -461,7 +469,7 @@ static int __devinit snd_probe(struct usb_interface *intf,
461 struct snd_card *card; 469 struct snd_card *card;
462 struct usb_device *device = interface_to_usbdev(intf); 470 struct usb_device *device = interface_to_usbdev(intf);
463 471
464 ret = create_card(device, &card); 472 ret = create_card(device, intf, &card);
465 473
466 if (ret < 0) 474 if (ret < 0)
467 return ret; 475 return ret;
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index ece73514854e..44e3edf88bef 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -10,6 +10,7 @@
10#define USB_PID_KORECONTROLLER 0x4711 10#define USB_PID_KORECONTROLLER 0x4711
11#define USB_PID_KORECONTROLLER2 0x4712 11#define USB_PID_KORECONTROLLER2 0x4712
12#define USB_PID_AK1 0x0815 12#define USB_PID_AK1 0x0815
13#define USB_PID_AUDIO2DJ 0x041c
13#define USB_PID_AUDIO4DJ 0x0839 14#define USB_PID_AUDIO4DJ 0x0839
14#define USB_PID_AUDIO8DJ 0x1978 15#define USB_PID_AUDIO8DJ 0x1978
15#define USB_PID_SESSIONIO 0x1915 16#define USB_PID_SESSIONIO 0x1915
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index c7b902358b7b..8db0374e10d5 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -1083,6 +1083,8 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1083 } else 1083 } else
1084 urb_packs = 1; 1084 urb_packs = 1;
1085 urb_packs *= packs_per_ms; 1085 urb_packs *= packs_per_ms;
1086 if (subs->syncpipe)
1087 urb_packs = min(urb_packs, 1U << subs->syncinterval);
1086 1088
1087 /* decide how many packets to be used */ 1089 /* decide how many packets to be used */
1088 if (is_playback) { 1090 if (is_playback) {
@@ -2124,8 +2126,8 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s
2124 fp = list_entry(p, struct audioformat, list); 2126 fp = list_entry(p, struct audioformat, list);
2125 snd_iprintf(buffer, " Interface %d\n", fp->iface); 2127 snd_iprintf(buffer, " Interface %d\n", fp->iface);
2126 snd_iprintf(buffer, " Altset %d\n", fp->altsetting); 2128 snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
2127 snd_iprintf(buffer, " Format: %#x (%d bits)\n", 2129 snd_iprintf(buffer, " Format: %s\n",
2128 fp->format, snd_pcm_format_width(fp->format)); 2130 snd_pcm_format_name(fp->format));
2129 snd_iprintf(buffer, " Channels: %d\n", fp->channels); 2131 snd_iprintf(buffer, " Channels: %d\n", fp->channels);
2130 snd_iprintf(buffer, " Endpoint: %d %s (%s)\n", 2132 snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
2131 fp->endpoint & USB_ENDPOINT_NUMBER_MASK, 2133 fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
@@ -2661,7 +2663,7 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2661 struct usb_interface_descriptor *altsd; 2663 struct usb_interface_descriptor *altsd;
2662 int i, altno, err, stream; 2664 int i, altno, err, stream;
2663 int format; 2665 int format;
2664 struct audioformat *fp; 2666 struct audioformat *fp = NULL;
2665 unsigned char *fmt, *csep; 2667 unsigned char *fmt, *csep;
2666 int num; 2668 int num;
2667 2669
@@ -2734,6 +2736,18 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2734 continue; 2736 continue;
2735 } 2737 }
2736 2738
2739 /*
2740 * Blue Microphones workaround: The last altsetting is identical
2741 * with the previous one, except for a larger packet size, but
2742 * is actually a mislabeled two-channel setting; ignore it.
2743 */
2744 if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 &&
2745 fp && fp->altsetting == 1 && fp->channels == 1 &&
2746 fp->format == SNDRV_PCM_FORMAT_S16_LE &&
2747 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
2748 fp->maxpacksize * 2)
2749 continue;
2750
2737 csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT); 2751 csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);
2738 /* Creamware Noah has this descriptor after the 2nd endpoint */ 2752 /* Creamware Noah has this descriptor after the 2nd endpoint */
2739 if (!csep && altsd->bNumEndpoints >= 2) 2753 if (!csep && altsd->bNumEndpoints >= 2)
diff --git a/sound/usb/usbmidi.c b/sound/usb/usbmidi.c
index 2fb35cc22a30..0eff19ceb7e1 100644
--- a/sound/usb/usbmidi.c
+++ b/sound/usb/usbmidi.c
@@ -45,6 +45,7 @@
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/timer.h> 46#include <linux/timer.h>
47#include <linux/usb.h> 47#include <linux/usb.h>
48#include <linux/wait.h>
48#include <sound/core.h> 49#include <sound/core.h>
49#include <sound/rawmidi.h> 50#include <sound/rawmidi.h>
50#include <sound/asequencer.h> 51#include <sound/asequencer.h>
@@ -62,6 +63,9 @@
62 */ 63 */
63#define ERROR_DELAY_JIFFIES (HZ / 10) 64#define ERROR_DELAY_JIFFIES (HZ / 10)
64 65
66#define OUTPUT_URBS 7
67#define INPUT_URBS 7
68
65 69
66MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 70MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
67MODULE_DESCRIPTION("USB Audio/MIDI helper module"); 71MODULE_DESCRIPTION("USB Audio/MIDI helper module");
@@ -90,7 +94,7 @@ struct snd_usb_midi_endpoint;
90 94
91struct usb_protocol_ops { 95struct usb_protocol_ops {
92 void (*input)(struct snd_usb_midi_in_endpoint*, uint8_t*, int); 96 void (*input)(struct snd_usb_midi_in_endpoint*, uint8_t*, int);
93 void (*output)(struct snd_usb_midi_out_endpoint*); 97 void (*output)(struct snd_usb_midi_out_endpoint *ep, struct urb *urb);
94 void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t); 98 void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t);
95 void (*init_out_endpoint)(struct snd_usb_midi_out_endpoint*); 99 void (*init_out_endpoint)(struct snd_usb_midi_out_endpoint*);
96 void (*finish_out_endpoint)(struct snd_usb_midi_out_endpoint*); 100 void (*finish_out_endpoint)(struct snd_usb_midi_out_endpoint*);
@@ -116,11 +120,15 @@ struct snd_usb_midi {
116 120
117struct snd_usb_midi_out_endpoint { 121struct snd_usb_midi_out_endpoint {
118 struct snd_usb_midi* umidi; 122 struct snd_usb_midi* umidi;
119 struct urb* urb; 123 struct out_urb_context {
120 int urb_active; 124 struct urb *urb;
125 struct snd_usb_midi_out_endpoint *ep;
126 } urbs[OUTPUT_URBS];
127 unsigned int active_urbs;
128 unsigned int drain_urbs;
121 int max_transfer; /* size of urb buffer */ 129 int max_transfer; /* size of urb buffer */
122 struct tasklet_struct tasklet; 130 struct tasklet_struct tasklet;
123 131 unsigned int next_urb;
124 spinlock_t buffer_lock; 132 spinlock_t buffer_lock;
125 133
126 struct usbmidi_out_port { 134 struct usbmidi_out_port {
@@ -139,11 +147,13 @@ struct snd_usb_midi_out_endpoint {
139 uint8_t data[2]; 147 uint8_t data[2];
140 } ports[0x10]; 148 } ports[0x10];
141 int current_port; 149 int current_port;
150
151 wait_queue_head_t drain_wait;
142}; 152};
143 153
144struct snd_usb_midi_in_endpoint { 154struct snd_usb_midi_in_endpoint {
145 struct snd_usb_midi* umidi; 155 struct snd_usb_midi* umidi;
146 struct urb* urb; 156 struct urb* urbs[INPUT_URBS];
147 struct usbmidi_in_port { 157 struct usbmidi_in_port {
148 struct snd_rawmidi_substream *substream; 158 struct snd_rawmidi_substream *substream;
149 u8 running_status_length; 159 u8 running_status_length;
@@ -251,10 +261,17 @@ static void snd_usbmidi_in_urb_complete(struct urb* urb)
251 261
252static void snd_usbmidi_out_urb_complete(struct urb* urb) 262static void snd_usbmidi_out_urb_complete(struct urb* urb)
253{ 263{
254 struct snd_usb_midi_out_endpoint* ep = urb->context; 264 struct out_urb_context *context = urb->context;
265 struct snd_usb_midi_out_endpoint* ep = context->ep;
266 unsigned int urb_index;
255 267
256 spin_lock(&ep->buffer_lock); 268 spin_lock(&ep->buffer_lock);
257 ep->urb_active = 0; 269 urb_index = context - ep->urbs;
270 ep->active_urbs &= ~(1 << urb_index);
271 if (unlikely(ep->drain_urbs)) {
272 ep->drain_urbs &= ~(1 << urb_index);
273 wake_up(&ep->drain_wait);
274 }
258 spin_unlock(&ep->buffer_lock); 275 spin_unlock(&ep->buffer_lock);
259 if (urb->status < 0) { 276 if (urb->status < 0) {
260 int err = snd_usbmidi_urb_error(urb->status); 277 int err = snd_usbmidi_urb_error(urb->status);
@@ -274,24 +291,38 @@ static void snd_usbmidi_out_urb_complete(struct urb* urb)
274 */ 291 */
275static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep) 292static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep)
276{ 293{
277 struct urb* urb = ep->urb; 294 unsigned int urb_index;
295 struct urb* urb;
278 unsigned long flags; 296 unsigned long flags;
279 297
280 spin_lock_irqsave(&ep->buffer_lock, flags); 298 spin_lock_irqsave(&ep->buffer_lock, flags);
281 if (ep->urb_active || ep->umidi->chip->shutdown) { 299 if (ep->umidi->chip->shutdown) {
282 spin_unlock_irqrestore(&ep->buffer_lock, flags); 300 spin_unlock_irqrestore(&ep->buffer_lock, flags);
283 return; 301 return;
284 } 302 }
285 303
286 urb->transfer_buffer_length = 0; 304 urb_index = ep->next_urb;
287 ep->umidi->usb_protocol_ops->output(ep); 305 for (;;) {
306 if (!(ep->active_urbs & (1 << urb_index))) {
307 urb = ep->urbs[urb_index].urb;
308 urb->transfer_buffer_length = 0;
309 ep->umidi->usb_protocol_ops->output(ep, urb);
310 if (urb->transfer_buffer_length == 0)
311 break;
288 312
289 if (urb->transfer_buffer_length > 0) { 313 dump_urb("sending", urb->transfer_buffer,
290 dump_urb("sending", urb->transfer_buffer, 314 urb->transfer_buffer_length);
291 urb->transfer_buffer_length); 315 urb->dev = ep->umidi->chip->dev;
292 urb->dev = ep->umidi->chip->dev; 316 if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0)
293 ep->urb_active = snd_usbmidi_submit_urb(urb, GFP_ATOMIC) >= 0; 317 break;
318 ep->active_urbs |= 1 << urb_index;
319 }
320 if (++urb_index >= OUTPUT_URBS)
321 urb_index = 0;
322 if (urb_index == ep->next_urb)
323 break;
294 } 324 }
325 ep->next_urb = urb_index;
295 spin_unlock_irqrestore(&ep->buffer_lock, flags); 326 spin_unlock_irqrestore(&ep->buffer_lock, flags);
296} 327}
297 328
@@ -306,7 +337,7 @@ static void snd_usbmidi_out_tasklet(unsigned long data)
306static void snd_usbmidi_error_timer(unsigned long data) 337static void snd_usbmidi_error_timer(unsigned long data)
307{ 338{
308 struct snd_usb_midi *umidi = (struct snd_usb_midi *)data; 339 struct snd_usb_midi *umidi = (struct snd_usb_midi *)data;
309 int i; 340 unsigned int i, j;
310 341
311 spin_lock(&umidi->disc_lock); 342 spin_lock(&umidi->disc_lock);
312 if (umidi->disconnected) { 343 if (umidi->disconnected) {
@@ -317,8 +348,10 @@ static void snd_usbmidi_error_timer(unsigned long data)
317 struct snd_usb_midi_in_endpoint *in = umidi->endpoints[i].in; 348 struct snd_usb_midi_in_endpoint *in = umidi->endpoints[i].in;
318 if (in && in->error_resubmit) { 349 if (in && in->error_resubmit) {
319 in->error_resubmit = 0; 350 in->error_resubmit = 0;
320 in->urb->dev = umidi->chip->dev; 351 for (j = 0; j < INPUT_URBS; ++j) {
321 snd_usbmidi_submit_urb(in->urb, GFP_ATOMIC); 352 in->urbs[j]->dev = umidi->chip->dev;
353 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC);
354 }
322 } 355 }
323 if (umidi->endpoints[i].out) 356 if (umidi->endpoints[i].out)
324 snd_usbmidi_do_output(umidi->endpoints[i].out); 357 snd_usbmidi_do_output(umidi->endpoints[i].out);
@@ -330,13 +363,14 @@ static void snd_usbmidi_error_timer(unsigned long data)
330static int send_bulk_static_data(struct snd_usb_midi_out_endpoint* ep, 363static int send_bulk_static_data(struct snd_usb_midi_out_endpoint* ep,
331 const void *data, int len) 364 const void *data, int len)
332{ 365{
333 int err; 366 int err = 0;
334 void *buf = kmemdup(data, len, GFP_KERNEL); 367 void *buf = kmemdup(data, len, GFP_KERNEL);
335 if (!buf) 368 if (!buf)
336 return -ENOMEM; 369 return -ENOMEM;
337 dump_urb("sending", buf, len); 370 dump_urb("sending", buf, len);
338 err = usb_bulk_msg(ep->umidi->chip->dev, ep->urb->pipe, buf, len, 371 if (ep->urbs[0].urb)
339 NULL, 250); 372 err = usb_bulk_msg(ep->umidi->chip->dev, ep->urbs[0].urb->pipe,
373 buf, len, NULL, 250);
340 kfree(buf); 374 kfree(buf);
341 return err; 375 return err;
342} 376}
@@ -554,9 +588,9 @@ static void snd_usbmidi_transmit_byte(struct usbmidi_out_port* port,
554 } 588 }
555} 589}
556 590
557static void snd_usbmidi_standard_output(struct snd_usb_midi_out_endpoint* ep) 591static void snd_usbmidi_standard_output(struct snd_usb_midi_out_endpoint* ep,
592 struct urb *urb)
558{ 593{
559 struct urb* urb = ep->urb;
560 int p; 594 int p;
561 595
562 /* FIXME: lower-numbered ports can starve higher-numbered ports */ 596 /* FIXME: lower-numbered ports can starve higher-numbered ports */
@@ -613,14 +647,15 @@ static void snd_usbmidi_novation_input(struct snd_usb_midi_in_endpoint* ep,
613 snd_usbmidi_input_data(ep, 0, &buffer[2], buffer[0] - 1); 647 snd_usbmidi_input_data(ep, 0, &buffer[2], buffer[0] - 1);
614} 648}
615 649
616static void snd_usbmidi_novation_output(struct snd_usb_midi_out_endpoint* ep) 650static void snd_usbmidi_novation_output(struct snd_usb_midi_out_endpoint* ep,
651 struct urb *urb)
617{ 652{
618 uint8_t* transfer_buffer; 653 uint8_t* transfer_buffer;
619 int count; 654 int count;
620 655
621 if (!ep->ports[0].active) 656 if (!ep->ports[0].active)
622 return; 657 return;
623 transfer_buffer = ep->urb->transfer_buffer; 658 transfer_buffer = urb->transfer_buffer;
624 count = snd_rawmidi_transmit(ep->ports[0].substream, 659 count = snd_rawmidi_transmit(ep->ports[0].substream,
625 &transfer_buffer[2], 660 &transfer_buffer[2],
626 ep->max_transfer - 2); 661 ep->max_transfer - 2);
@@ -630,7 +665,7 @@ static void snd_usbmidi_novation_output(struct snd_usb_midi_out_endpoint* ep)
630 } 665 }
631 transfer_buffer[0] = 0; 666 transfer_buffer[0] = 0;
632 transfer_buffer[1] = count; 667 transfer_buffer[1] = count;
633 ep->urb->transfer_buffer_length = 2 + count; 668 urb->transfer_buffer_length = 2 + count;
634} 669}
635 670
636static struct usb_protocol_ops snd_usbmidi_novation_ops = { 671static struct usb_protocol_ops snd_usbmidi_novation_ops = {
@@ -648,20 +683,21 @@ static void snd_usbmidi_raw_input(struct snd_usb_midi_in_endpoint* ep,
648 snd_usbmidi_input_data(ep, 0, buffer, buffer_length); 683 snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
649} 684}
650 685
651static void snd_usbmidi_raw_output(struct snd_usb_midi_out_endpoint* ep) 686static void snd_usbmidi_raw_output(struct snd_usb_midi_out_endpoint* ep,
687 struct urb *urb)
652{ 688{
653 int count; 689 int count;
654 690
655 if (!ep->ports[0].active) 691 if (!ep->ports[0].active)
656 return; 692 return;
657 count = snd_rawmidi_transmit(ep->ports[0].substream, 693 count = snd_rawmidi_transmit(ep->ports[0].substream,
658 ep->urb->transfer_buffer, 694 urb->transfer_buffer,
659 ep->max_transfer); 695 ep->max_transfer);
660 if (count < 1) { 696 if (count < 1) {
661 ep->ports[0].active = 0; 697 ep->ports[0].active = 0;
662 return; 698 return;
663 } 699 }
664 ep->urb->transfer_buffer_length = count; 700 urb->transfer_buffer_length = count;
665} 701}
666 702
667static struct usb_protocol_ops snd_usbmidi_raw_ops = { 703static struct usb_protocol_ops snd_usbmidi_raw_ops = {
@@ -681,23 +717,25 @@ static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep,
681 snd_usbmidi_input_data(ep, 0, buffer, buffer_length); 717 snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
682} 718}
683 719
684static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep) 720static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
721 struct urb *urb)
685{ 722{
686 int count; 723 int count;
687 724
688 if (!ep->ports[0].active) 725 if (!ep->ports[0].active)
689 return; 726 return;
690 count = ep->urb->dev->speed == USB_SPEED_HIGH ? 1 : 2; 727 count = snd_usb_get_speed(ep->umidi->chip->dev) == USB_SPEED_HIGH
728 ? 1 : 2;
691 count = snd_rawmidi_transmit(ep->ports[0].substream, 729 count = snd_rawmidi_transmit(ep->ports[0].substream,
692 ep->urb->transfer_buffer, 730 urb->transfer_buffer,
693 count); 731 count);
694 if (count < 1) { 732 if (count < 1) {
695 ep->ports[0].active = 0; 733 ep->ports[0].active = 0;
696 return; 734 return;
697 } 735 }
698 736
699 memset(ep->urb->transfer_buffer + count, 0xFD, 9 - count); 737 memset(urb->transfer_buffer + count, 0xFD, 9 - count);
700 ep->urb->transfer_buffer_length = count; 738 urb->transfer_buffer_length = count;
701} 739}
702 740
703static struct usb_protocol_ops snd_usbmidi_122l_ops = { 741static struct usb_protocol_ops snd_usbmidi_122l_ops = {
@@ -786,10 +824,11 @@ static void snd_usbmidi_emagic_input(struct snd_usb_midi_in_endpoint* ep,
786 } 824 }
787} 825}
788 826
789static void snd_usbmidi_emagic_output(struct snd_usb_midi_out_endpoint* ep) 827static void snd_usbmidi_emagic_output(struct snd_usb_midi_out_endpoint* ep,
828 struct urb *urb)
790{ 829{
791 int port0 = ep->current_port; 830 int port0 = ep->current_port;
792 uint8_t* buf = ep->urb->transfer_buffer; 831 uint8_t* buf = urb->transfer_buffer;
793 int buf_free = ep->max_transfer; 832 int buf_free = ep->max_transfer;
794 int length, i; 833 int length, i;
795 834
@@ -829,7 +868,7 @@ static void snd_usbmidi_emagic_output(struct snd_usb_midi_out_endpoint* ep)
829 *buf = 0xff; 868 *buf = 0xff;
830 --buf_free; 869 --buf_free;
831 } 870 }
832 ep->urb->transfer_buffer_length = ep->max_transfer - buf_free; 871 urb->transfer_buffer_length = ep->max_transfer - buf_free;
833} 872}
834 873
835static struct usb_protocol_ops snd_usbmidi_emagic_ops = { 874static struct usb_protocol_ops snd_usbmidi_emagic_ops = {
@@ -884,6 +923,35 @@ static void snd_usbmidi_output_trigger(struct snd_rawmidi_substream *substream,
884 } 923 }
885} 924}
886 925
926static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream)
927{
928 struct usbmidi_out_port* port = substream->runtime->private_data;
929 struct snd_usb_midi_out_endpoint *ep = port->ep;
930 unsigned int drain_urbs;
931 DEFINE_WAIT(wait);
932 long timeout = msecs_to_jiffies(50);
933
934 /*
935 * The substream buffer is empty, but some data might still be in the
936 * currently active URBs, so we have to wait for those to complete.
937 */
938 spin_lock_irq(&ep->buffer_lock);
939 drain_urbs = ep->active_urbs;
940 if (drain_urbs) {
941 ep->drain_urbs |= drain_urbs;
942 do {
943 prepare_to_wait(&ep->drain_wait, &wait,
944 TASK_UNINTERRUPTIBLE);
945 spin_unlock_irq(&ep->buffer_lock);
946 timeout = schedule_timeout(timeout);
947 spin_lock_irq(&ep->buffer_lock);
948 drain_urbs &= ep->drain_urbs;
949 } while (drain_urbs && timeout);
950 finish_wait(&ep->drain_wait, &wait);
951 }
952 spin_unlock_irq(&ep->buffer_lock);
953}
954
887static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream) 955static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream)
888{ 956{
889 return 0; 957 return 0;
@@ -908,6 +976,7 @@ static struct snd_rawmidi_ops snd_usbmidi_output_ops = {
908 .open = snd_usbmidi_output_open, 976 .open = snd_usbmidi_output_open,
909 .close = snd_usbmidi_output_close, 977 .close = snd_usbmidi_output_close,
910 .trigger = snd_usbmidi_output_trigger, 978 .trigger = snd_usbmidi_output_trigger,
979 .drain = snd_usbmidi_output_drain,
911}; 980};
912 981
913static struct snd_rawmidi_ops snd_usbmidi_input_ops = { 982static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
@@ -916,19 +985,26 @@ static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
916 .trigger = snd_usbmidi_input_trigger 985 .trigger = snd_usbmidi_input_trigger
917}; 986};
918 987
988static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb,
989 unsigned int buffer_length)
990{
991 usb_buffer_free(umidi->chip->dev, buffer_length,
992 urb->transfer_buffer, urb->transfer_dma);
993 usb_free_urb(urb);
994}
995
919/* 996/*
920 * Frees an input endpoint. 997 * Frees an input endpoint.
921 * May be called when ep hasn't been initialized completely. 998 * May be called when ep hasn't been initialized completely.
922 */ 999 */
923static void snd_usbmidi_in_endpoint_delete(struct snd_usb_midi_in_endpoint* ep) 1000static void snd_usbmidi_in_endpoint_delete(struct snd_usb_midi_in_endpoint* ep)
924{ 1001{
925 if (ep->urb) { 1002 unsigned int i;
926 usb_buffer_free(ep->umidi->chip->dev, 1003
927 ep->urb->transfer_buffer_length, 1004 for (i = 0; i < INPUT_URBS; ++i)
928 ep->urb->transfer_buffer, 1005 if (ep->urbs[i])
929 ep->urb->transfer_dma); 1006 free_urb_and_buffer(ep->umidi, ep->urbs[i],
930 usb_free_urb(ep->urb); 1007 ep->urbs[i]->transfer_buffer_length);
931 }
932 kfree(ep); 1008 kfree(ep);
933} 1009}
934 1010
@@ -943,6 +1019,7 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
943 void* buffer; 1019 void* buffer;
944 unsigned int pipe; 1020 unsigned int pipe;
945 int length; 1021 int length;
1022 unsigned int i;
946 1023
947 rep->in = NULL; 1024 rep->in = NULL;
948 ep = kzalloc(sizeof(*ep), GFP_KERNEL); 1025 ep = kzalloc(sizeof(*ep), GFP_KERNEL);
@@ -950,30 +1027,36 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
950 return -ENOMEM; 1027 return -ENOMEM;
951 ep->umidi = umidi; 1028 ep->umidi = umidi;
952 1029
953 ep->urb = usb_alloc_urb(0, GFP_KERNEL); 1030 for (i = 0; i < INPUT_URBS; ++i) {
954 if (!ep->urb) { 1031 ep->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
955 snd_usbmidi_in_endpoint_delete(ep); 1032 if (!ep->urbs[i]) {
956 return -ENOMEM; 1033 snd_usbmidi_in_endpoint_delete(ep);
1034 return -ENOMEM;
1035 }
957 } 1036 }
958 if (ep_info->in_interval) 1037 if (ep_info->in_interval)
959 pipe = usb_rcvintpipe(umidi->chip->dev, ep_info->in_ep); 1038 pipe = usb_rcvintpipe(umidi->chip->dev, ep_info->in_ep);
960 else 1039 else
961 pipe = usb_rcvbulkpipe(umidi->chip->dev, ep_info->in_ep); 1040 pipe = usb_rcvbulkpipe(umidi->chip->dev, ep_info->in_ep);
962 length = usb_maxpacket(umidi->chip->dev, pipe, 0); 1041 length = usb_maxpacket(umidi->chip->dev, pipe, 0);
963 buffer = usb_buffer_alloc(umidi->chip->dev, length, GFP_KERNEL, 1042 for (i = 0; i < INPUT_URBS; ++i) {
964 &ep->urb->transfer_dma); 1043 buffer = usb_buffer_alloc(umidi->chip->dev, length, GFP_KERNEL,
965 if (!buffer) { 1044 &ep->urbs[i]->transfer_dma);
966 snd_usbmidi_in_endpoint_delete(ep); 1045 if (!buffer) {
967 return -ENOMEM; 1046 snd_usbmidi_in_endpoint_delete(ep);
1047 return -ENOMEM;
1048 }
1049 if (ep_info->in_interval)
1050 usb_fill_int_urb(ep->urbs[i], umidi->chip->dev,
1051 pipe, buffer, length,
1052 snd_usbmidi_in_urb_complete,
1053 ep, ep_info->in_interval);
1054 else
1055 usb_fill_bulk_urb(ep->urbs[i], umidi->chip->dev,
1056 pipe, buffer, length,
1057 snd_usbmidi_in_urb_complete, ep);
1058 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
968 } 1059 }
969 if (ep_info->in_interval)
970 usb_fill_int_urb(ep->urb, umidi->chip->dev, pipe, buffer,
971 length, snd_usbmidi_in_urb_complete, ep,
972 ep_info->in_interval);
973 else
974 usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer,
975 length, snd_usbmidi_in_urb_complete, ep);
976 ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
977 1060
978 rep->in = ep; 1061 rep->in = ep;
979 return 0; 1062 return 0;
@@ -994,12 +1077,12 @@ static unsigned int snd_usbmidi_count_bits(unsigned int x)
994 */ 1077 */
995static void snd_usbmidi_out_endpoint_delete(struct snd_usb_midi_out_endpoint* ep) 1078static void snd_usbmidi_out_endpoint_delete(struct snd_usb_midi_out_endpoint* ep)
996{ 1079{
997 if (ep->urb) { 1080 unsigned int i;
998 usb_buffer_free(ep->umidi->chip->dev, ep->max_transfer, 1081
999 ep->urb->transfer_buffer, 1082 for (i = 0; i < OUTPUT_URBS; ++i)
1000 ep->urb->transfer_dma); 1083 if (ep->urbs[i].urb)
1001 usb_free_urb(ep->urb); 1084 free_urb_and_buffer(ep->umidi, ep->urbs[i].urb,
1002 } 1085 ep->max_transfer);
1003 kfree(ep); 1086 kfree(ep);
1004} 1087}
1005 1088
@@ -1011,7 +1094,7 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1011 struct snd_usb_midi_endpoint* rep) 1094 struct snd_usb_midi_endpoint* rep)
1012{ 1095{
1013 struct snd_usb_midi_out_endpoint* ep; 1096 struct snd_usb_midi_out_endpoint* ep;
1014 int i; 1097 unsigned int i;
1015 unsigned int pipe; 1098 unsigned int pipe;
1016 void* buffer; 1099 void* buffer;
1017 1100
@@ -1021,38 +1104,46 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1021 return -ENOMEM; 1104 return -ENOMEM;
1022 ep->umidi = umidi; 1105 ep->umidi = umidi;
1023 1106
1024 ep->urb = usb_alloc_urb(0, GFP_KERNEL); 1107 for (i = 0; i < OUTPUT_URBS; ++i) {
1025 if (!ep->urb) { 1108 ep->urbs[i].urb = usb_alloc_urb(0, GFP_KERNEL);
1026 snd_usbmidi_out_endpoint_delete(ep); 1109 if (!ep->urbs[i].urb) {
1027 return -ENOMEM; 1110 snd_usbmidi_out_endpoint_delete(ep);
1111 return -ENOMEM;
1112 }
1113 ep->urbs[i].ep = ep;
1028 } 1114 }
1029 if (ep_info->out_interval) 1115 if (ep_info->out_interval)
1030 pipe = usb_sndintpipe(umidi->chip->dev, ep_info->out_ep); 1116 pipe = usb_sndintpipe(umidi->chip->dev, ep_info->out_ep);
1031 else 1117 else
1032 pipe = usb_sndbulkpipe(umidi->chip->dev, ep_info->out_ep); 1118 pipe = usb_sndbulkpipe(umidi->chip->dev, ep_info->out_ep);
1033 if (umidi->chip->usb_id == USB_ID(0x0a92, 0x1020)) /* ESI M4U */ 1119 if (umidi->chip->usb_id == USB_ID(0x0a92, 0x1020)) /* ESI M4U */
1034 /* FIXME: we need more URBs to get reasonable bandwidth here: */
1035 ep->max_transfer = 4; 1120 ep->max_transfer = 4;
1036 else 1121 else
1037 ep->max_transfer = usb_maxpacket(umidi->chip->dev, pipe, 1); 1122 ep->max_transfer = usb_maxpacket(umidi->chip->dev, pipe, 1);
1038 buffer = usb_buffer_alloc(umidi->chip->dev, ep->max_transfer, 1123 for (i = 0; i < OUTPUT_URBS; ++i) {
1039 GFP_KERNEL, &ep->urb->transfer_dma); 1124 buffer = usb_buffer_alloc(umidi->chip->dev,
1040 if (!buffer) { 1125 ep->max_transfer, GFP_KERNEL,
1041 snd_usbmidi_out_endpoint_delete(ep); 1126 &ep->urbs[i].urb->transfer_dma);
1042 return -ENOMEM; 1127 if (!buffer) {
1128 snd_usbmidi_out_endpoint_delete(ep);
1129 return -ENOMEM;
1130 }
1131 if (ep_info->out_interval)
1132 usb_fill_int_urb(ep->urbs[i].urb, umidi->chip->dev,
1133 pipe, buffer, ep->max_transfer,
1134 snd_usbmidi_out_urb_complete,
1135 &ep->urbs[i], ep_info->out_interval);
1136 else
1137 usb_fill_bulk_urb(ep->urbs[i].urb, umidi->chip->dev,
1138 pipe, buffer, ep->max_transfer,
1139 snd_usbmidi_out_urb_complete,
1140 &ep->urbs[i]);
1141 ep->urbs[i].urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1043 } 1142 }
1044 if (ep_info->out_interval)
1045 usb_fill_int_urb(ep->urb, umidi->chip->dev, pipe, buffer,
1046 ep->max_transfer, snd_usbmidi_out_urb_complete,
1047 ep, ep_info->out_interval);
1048 else
1049 usb_fill_bulk_urb(ep->urb, umidi->chip->dev,
1050 pipe, buffer, ep->max_transfer,
1051 snd_usbmidi_out_urb_complete, ep);
1052 ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1053 1143
1054 spin_lock_init(&ep->buffer_lock); 1144 spin_lock_init(&ep->buffer_lock);
1055 tasklet_init(&ep->tasklet, snd_usbmidi_out_tasklet, (unsigned long)ep); 1145 tasklet_init(&ep->tasklet, snd_usbmidi_out_tasklet, (unsigned long)ep);
1146 init_waitqueue_head(&ep->drain_wait);
1056 1147
1057 for (i = 0; i < 0x10; ++i) 1148 for (i = 0; i < 0x10; ++i)
1058 if (ep_info->out_cables & (1 << i)) { 1149 if (ep_info->out_cables & (1 << i)) {
@@ -1090,7 +1181,7 @@ static void snd_usbmidi_free(struct snd_usb_midi* umidi)
1090void snd_usbmidi_disconnect(struct list_head* p) 1181void snd_usbmidi_disconnect(struct list_head* p)
1091{ 1182{
1092 struct snd_usb_midi* umidi; 1183 struct snd_usb_midi* umidi;
1093 int i; 1184 unsigned int i, j;
1094 1185
1095 umidi = list_entry(p, struct snd_usb_midi, list); 1186 umidi = list_entry(p, struct snd_usb_midi, list);
1096 /* 1187 /*
@@ -1105,13 +1196,15 @@ void snd_usbmidi_disconnect(struct list_head* p)
1105 struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i]; 1196 struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i];
1106 if (ep->out) 1197 if (ep->out)
1107 tasklet_kill(&ep->out->tasklet); 1198 tasklet_kill(&ep->out->tasklet);
1108 if (ep->out && ep->out->urb) { 1199 if (ep->out) {
1109 usb_kill_urb(ep->out->urb); 1200 for (j = 0; j < OUTPUT_URBS; ++j)
1201 usb_kill_urb(ep->out->urbs[j].urb);
1110 if (umidi->usb_protocol_ops->finish_out_endpoint) 1202 if (umidi->usb_protocol_ops->finish_out_endpoint)
1111 umidi->usb_protocol_ops->finish_out_endpoint(ep->out); 1203 umidi->usb_protocol_ops->finish_out_endpoint(ep->out);
1112 } 1204 }
1113 if (ep->in) 1205 if (ep->in)
1114 usb_kill_urb(ep->in->urb); 1206 for (j = 0; j < INPUT_URBS; ++j)
1207 usb_kill_urb(ep->in->urbs[j]);
1115 /* free endpoints here; later call can result in Oops */ 1208 /* free endpoints here; later call can result in Oops */
1116 if (ep->out) { 1209 if (ep->out) {
1117 snd_usbmidi_out_endpoint_delete(ep->out); 1210 snd_usbmidi_out_endpoint_delete(ep->out);
@@ -1692,20 +1785,25 @@ static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
1692void snd_usbmidi_input_stop(struct list_head* p) 1785void snd_usbmidi_input_stop(struct list_head* p)
1693{ 1786{
1694 struct snd_usb_midi* umidi; 1787 struct snd_usb_midi* umidi;
1695 int i; 1788 unsigned int i, j;
1696 1789
1697 umidi = list_entry(p, struct snd_usb_midi, list); 1790 umidi = list_entry(p, struct snd_usb_midi, list);
1698 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) { 1791 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
1699 struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i]; 1792 struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i];
1700 if (ep->in) 1793 if (ep->in)
1701 usb_kill_urb(ep->in->urb); 1794 for (j = 0; j < INPUT_URBS; ++j)
1795 usb_kill_urb(ep->in->urbs[j]);
1702 } 1796 }
1703} 1797}
1704 1798
1705static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep) 1799static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep)
1706{ 1800{
1707 if (ep) { 1801 unsigned int i;
1708 struct urb* urb = ep->urb; 1802
1803 if (!ep)
1804 return;
1805 for (i = 0; i < INPUT_URBS; ++i) {
1806 struct urb* urb = ep->urbs[i];
1709 urb->dev = ep->umidi->chip->dev; 1807 urb->dev = ep->umidi->chip->dev;
1710 snd_usbmidi_submit_urb(urb, GFP_KERNEL); 1808 snd_usbmidi_submit_urb(urb, GFP_KERNEL);
1711 } 1809 }
diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c
index 4bd3a7a0edc1..9efcfd08d747 100644
--- a/sound/usb/usbmixer.c
+++ b/sound/usb/usbmixer.c
@@ -86,6 +86,7 @@ struct usb_mixer_interface {
86 u8 rc_buffer[6]; 86 u8 rc_buffer[6];
87 87
88 u8 audigy2nx_leds[3]; 88 u8 audigy2nx_leds[3];
89 u8 xonar_u1_status;
89}; 90};
90 91
91 92
@@ -461,7 +462,7 @@ static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
461 unsigned int size, unsigned int __user *_tlv) 462 unsigned int size, unsigned int __user *_tlv)
462{ 463{
463 struct usb_mixer_elem_info *cval = kcontrol->private_data; 464 struct usb_mixer_elem_info *cval = kcontrol->private_data;
464 DECLARE_TLV_DB_SCALE(scale, 0, 0, 0); 465 DECLARE_TLV_DB_MINMAX(scale, 0, 0);
465 466
466 if (size < sizeof(scale)) 467 if (size < sizeof(scale))
467 return -ENOMEM; 468 return -ENOMEM;
@@ -469,7 +470,16 @@ static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
469 * while ALSA TLV contains in 1/100 dB unit 470 * while ALSA TLV contains in 1/100 dB unit
470 */ 471 */
471 scale[2] = (convert_signed_value(cval, cval->min) * 100) / 256; 472 scale[2] = (convert_signed_value(cval, cval->min) * 100) / 256;
472 scale[3] = (convert_signed_value(cval, cval->res) * 100) / 256; 473 scale[3] = (convert_signed_value(cval, cval->max) * 100) / 256;
474 if (scale[3] <= scale[2]) {
475 /* something is wrong; assume it's either from/to 0dB */
476 if (scale[2] < 0)
477 scale[3] = 0;
478 else if (scale[2] > 0)
479 scale[2] = 0;
480 else /* totally crap, return an error */
481 return -EINVAL;
482 }
473 if (copy_to_user(_tlv, scale, sizeof(scale))) 483 if (copy_to_user(_tlv, scale, sizeof(scale)))
474 return -EFAULT; 484 return -EFAULT;
475 return 0; 485 return 0;
@@ -888,6 +898,11 @@ static struct snd_kcontrol_new usb_feature_unit_ctl = {
888 * build a feature control 898 * build a feature control
889 */ 899 */
890 900
901static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str)
902{
903 return strlcat(kctl->id.name, str, sizeof(kctl->id.name));
904}
905
891static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, 906static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
892 unsigned int ctl_mask, int control, 907 unsigned int ctl_mask, int control,
893 struct usb_audio_term *iterm, int unitid) 908 struct usb_audio_term *iterm, int unitid)
@@ -968,13 +983,13 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
968 */ 983 */
969 if (! mapped_name && ! (state->oterm.type >> 16)) { 984 if (! mapped_name && ! (state->oterm.type >> 16)) {
970 if ((state->oterm.type & 0xff00) == 0x0100) { 985 if ((state->oterm.type & 0xff00) == 0x0100) {
971 len = strlcat(kctl->id.name, " Capture", sizeof(kctl->id.name)); 986 len = append_ctl_name(kctl, " Capture");
972 } else { 987 } else {
973 len = strlcat(kctl->id.name + len, " Playback", sizeof(kctl->id.name)); 988 len = append_ctl_name(kctl, " Playback");
974 } 989 }
975 } 990 }
976 strlcat(kctl->id.name + len, control == USB_FEATURE_MUTE ? " Switch" : " Volume", 991 append_ctl_name(kctl, control == USB_FEATURE_MUTE ?
977 sizeof(kctl->id.name)); 992 " Switch" : " Volume");
978 if (control == USB_FEATURE_VOLUME) { 993 if (control == USB_FEATURE_VOLUME) {
979 kctl->tlv.c = mixer_vol_tlv; 994 kctl->tlv.c = mixer_vol_tlv;
980 kctl->vd[0].access |= 995 kctl->vd[0].access |=
@@ -990,20 +1005,35 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
990 break; 1005 break;
991 } 1006 }
992 1007
993 /* quirk for UDA1321/N101 */ 1008 /* volume control quirks */
994 /* note that detection between firmware 2.1.1.7 (N101) and later 2.1.1.21 */
995 /* is not very clear from datasheets */
996 /* I hope that the min value is -15360 for newer firmware --jk */
997 switch (state->chip->usb_id) { 1009 switch (state->chip->usb_id) {
998 case USB_ID(0x0471, 0x0101): 1010 case USB_ID(0x0471, 0x0101):
999 case USB_ID(0x0471, 0x0104): 1011 case USB_ID(0x0471, 0x0104):
1000 case USB_ID(0x0471, 0x0105): 1012 case USB_ID(0x0471, 0x0105):
1001 case USB_ID(0x0672, 0x1041): 1013 case USB_ID(0x0672, 0x1041):
1014 /* quirk for UDA1321/N101.
1015 * note that detection between firmware 2.1.1.7 (N101)
1016 * and later 2.1.1.21 is not very clear from datasheets.
1017 * I hope that the min value is -15360 for newer firmware --jk
1018 */
1002 if (!strcmp(kctl->id.name, "PCM Playback Volume") && 1019 if (!strcmp(kctl->id.name, "PCM Playback Volume") &&
1003 cval->min == -15616) { 1020 cval->min == -15616) {
1004 snd_printk(KERN_INFO "using volume control quirk for the UDA1321/N101 chip\n"); 1021 snd_printk(KERN_INFO
1022 "set volume quirk for UDA1321/N101 chip\n");
1005 cval->max = -256; 1023 cval->max = -256;
1006 } 1024 }
1025 break;
1026
1027 case USB_ID(0x046d, 0x09a4):
1028 if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
1029 snd_printk(KERN_INFO
1030 "set volume quirk for QuickCam E3500\n");
1031 cval->min = 6080;
1032 cval->max = 8768;
1033 cval->res = 192;
1034 }
1035 break;
1036
1007 } 1037 }
1008 1038
1009 snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n", 1039 snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
@@ -1118,7 +1148,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
1118 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); 1148 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0);
1119 if (! len) 1149 if (! len)
1120 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); 1150 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1);
1121 strlcat(kctl->id.name + len, " Volume", sizeof(kctl->id.name)); 1151 append_ctl_name(kctl, " Volume");
1122 1152
1123 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", 1153 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n",
1124 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1154 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
@@ -1375,8 +1405,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
1375 if (! len) 1405 if (! len)
1376 strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); 1406 strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
1377 } 1407 }
1378 strlcat(kctl->id.name, " ", sizeof(kctl->id.name)); 1408 append_ctl_name(kctl, " ");
1379 strlcat(kctl->id.name, valinfo->suffix, sizeof(kctl->id.name)); 1409 append_ctl_name(kctl, valinfo->suffix);
1380 1410
1381 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", 1411 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n",
1382 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1412 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
@@ -1585,9 +1615,9 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
1585 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); 1615 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name));
1586 1616
1587 if ((state->oterm.type & 0xff00) == 0x0100) 1617 if ((state->oterm.type & 0xff00) == 0x0100)
1588 strlcat(kctl->id.name, " Capture Source", sizeof(kctl->id.name)); 1618 append_ctl_name(kctl, " Capture Source");
1589 else 1619 else
1590 strlcat(kctl->id.name, " Playback Source", sizeof(kctl->id.name)); 1620 append_ctl_name(kctl, " Playback Source");
1591 } 1621 }
1592 1622
1593 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", 1623 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n",
@@ -2018,6 +2048,58 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
2018 } 2048 }
2019} 2049}
2020 2050
2051static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
2052 struct snd_ctl_elem_value *ucontrol)
2053{
2054 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2055
2056 ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
2057 return 0;
2058}
2059
2060static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
2061 struct snd_ctl_elem_value *ucontrol)
2062{
2063 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2064 u8 old_status, new_status;
2065 int err, changed;
2066
2067 old_status = mixer->xonar_u1_status;
2068 if (ucontrol->value.integer.value[0])
2069 new_status = old_status | 0x02;
2070 else
2071 new_status = old_status & ~0x02;
2072 changed = new_status != old_status;
2073 err = snd_usb_ctl_msg(mixer->chip->dev,
2074 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
2075 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
2076 50, 0, &new_status, 1, 100);
2077 if (err < 0)
2078 return err;
2079 mixer->xonar_u1_status = new_status;
2080 return changed;
2081}
2082
2083static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
2084 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2085 .name = "Digital Playback Switch",
2086 .info = snd_ctl_boolean_mono_info,
2087 .get = snd_xonar_u1_switch_get,
2088 .put = snd_xonar_u1_switch_put,
2089};
2090
2091static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
2092{
2093 int err;
2094
2095 err = snd_ctl_add(mixer->chip->card,
2096 snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
2097 if (err < 0)
2098 return err;
2099 mixer->xonar_u1_status = 0x05;
2100 return 0;
2101}
2102
2021int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, 2103int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2022 int ignore_error) 2104 int ignore_error)
2023{ 2105{
@@ -2060,6 +2142,13 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2060 snd_audigy2nx_proc_read); 2142 snd_audigy2nx_proc_read);
2061 } 2143 }
2062 2144
2145 if (mixer->chip->usb_id == USB_ID(0x0b05, 0x1739) ||
2146 mixer->chip->usb_id == USB_ID(0x0b05, 0x1743)) {
2147 err = snd_xonar_u1_controls_create(mixer);
2148 if (err < 0)
2149 goto _error;
2150 }
2151
2063 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops); 2152 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops);
2064 if (err < 0) 2153 if (err < 0)
2065 goto _error; 2154 goto _error;
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index a5aae9d67f31..99f33766cd51 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -154,7 +154,7 @@ static void usb_stream_hwdep_vm_close(struct vm_area_struct *area)
154 snd_printdd(KERN_DEBUG "%i\n", atomic_read(&us122l->mmap_count)); 154 snd_printdd(KERN_DEBUG "%i\n", atomic_read(&us122l->mmap_count));
155} 155}
156 156
157static struct vm_operations_struct usb_stream_hwdep_vm_ops = { 157static const struct vm_operations_struct usb_stream_hwdep_vm_ops = {
158 .open = usb_stream_hwdep_vm_open, 158 .open = usb_stream_hwdep_vm_open,
159 .fault = usb_stream_hwdep_vm_fault, 159 .fault = usb_stream_hwdep_vm_fault,
160 .close = usb_stream_hwdep_vm_close, 160 .close = usb_stream_hwdep_vm_close,
@@ -514,7 +514,6 @@ static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
514 US122L(card)->chip.dev->bus->busnum, 514 US122L(card)->chip.dev->bus->busnum,
515 US122L(card)->chip.dev->devnum 515 US122L(card)->chip.dev->devnum
516 ); 516 );
517 snd_card_set_dev(card, &device->dev);
518 *cardp = card; 517 *cardp = card;
519 return 0; 518 return 0;
520} 519}
@@ -531,6 +530,7 @@ static int us122l_usb_probe(struct usb_interface *intf,
531 if (err < 0) 530 if (err < 0)
532 return err; 531 return err;
533 532
533 snd_card_set_dev(card, &intf->dev);
534 if (!us122l_create_card(card)) { 534 if (!us122l_create_card(card)) {
535 snd_card_free(card); 535 snd_card_free(card);
536 return -EINVAL; 536 return -EINVAL;
diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c
index f3d8f71265dd..52e04b2f35d3 100644
--- a/sound/usb/usx2y/usX2Yhwdep.c
+++ b/sound/usb/usx2y/usX2Yhwdep.c
@@ -53,7 +53,7 @@ static int snd_us428ctls_vm_fault(struct vm_area_struct *area,
53 return 0; 53 return 0;
54} 54}
55 55
56static struct vm_operations_struct us428ctls_vm_ops = { 56static const struct vm_operations_struct us428ctls_vm_ops = {
57 .fault = snd_us428ctls_vm_fault, 57 .fault = snd_us428ctls_vm_fault,
58}; 58};
59 59
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index 5ce0da23ee96..cb4bb8373ca2 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -364,7 +364,6 @@ static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
364 0,//us428(card)->usbmidi.ifnum, 364 0,//us428(card)->usbmidi.ifnum,
365 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum 365 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum
366 ); 366 );
367 snd_card_set_dev(card, &device->dev);
368 *cardp = card; 367 *cardp = card;
369 return 0; 368 return 0;
370} 369}
@@ -388,6 +387,7 @@ static int usX2Y_usb_probe(struct usb_device *device,
388 err = usX2Y_create_card(device, &card); 387 err = usX2Y_create_card(device, &card);
389 if (err < 0) 388 if (err < 0)
390 return err; 389 return err;
390 snd_card_set_dev(card, &intf->dev);
391 if ((err = usX2Y_hwdep_new(card, device)) < 0 || 391 if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
392 (err = snd_card_register(card)) < 0) { 392 (err = snd_card_register(card)) < 0) {
393 snd_card_free(card); 393 snd_card_free(card);
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index dd1ab6177840..9efd27f6b52f 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -296,9 +296,10 @@ static void usX2Y_error_urb_status(struct usX2Ydev *usX2Y,
296static void usX2Y_error_sequence(struct usX2Ydev *usX2Y, 296static void usX2Y_error_sequence(struct usX2Ydev *usX2Y,
297 struct snd_usX2Y_substream *subs, struct urb *urb) 297 struct snd_usX2Y_substream *subs, struct urb *urb)
298{ 298{
299 snd_printk(KERN_ERR "Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n" 299 snd_printk(KERN_ERR
300 KERN_ERR "Most propably some urb of usb-frame %i is still missing.\n" 300"Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n"
301 KERN_ERR "Cause could be too long delays in usb-hcd interrupt handling.\n", 301"Most propably some urb of usb-frame %i is still missing.\n"
302"Cause could be too long delays in usb-hcd interrupt handling.\n",
302 usb_get_current_frame_number(usX2Y->chip.dev), 303 usb_get_current_frame_number(usX2Y->chip.dev),
303 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", 304 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
304 usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame); 305 usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame);
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index 117946f2debb..4b2304c2e02d 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -697,7 +697,7 @@ static int snd_usX2Y_hwdep_pcm_vm_fault(struct vm_area_struct *area,
697} 697}
698 698
699 699
700static struct vm_operations_struct snd_usX2Y_hwdep_pcm_vm_ops = { 700static const struct vm_operations_struct snd_usX2Y_hwdep_pcm_vm_ops = {
701 .open = snd_usX2Y_hwdep_pcm_vm_open, 701 .open = snd_usX2Y_hwdep_pcm_vm_open,
702 .close = snd_usX2Y_hwdep_pcm_vm_close, 702 .close = snd_usX2Y_hwdep_pcm_vm_close,
703 .fault = snd_usX2Y_hwdep_pcm_vm_fault, 703 .fault = snd_usX2Y_hwdep_pcm_vm_fault,