aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/arm/pxa2xx-ac97.c83
-rw-r--r--sound/core/Kconfig4
-rw-r--r--sound/core/Makefile1
-rw-r--r--sound/core/info.c4
-rw-r--r--sound/core/init.c38
-rw-r--r--sound/core/memalloc.c5
-rw-r--r--sound/core/misc.c4
-rw-r--r--sound/core/oss/mixer_oss.c2
-rw-r--r--sound/core/seq/oss/seq_oss_synth.c9
-rw-r--r--sound/core/vmaster.c (renamed from sound/pci/hda/vmaster.c)13
-rw-r--r--sound/drivers/Kconfig20
-rw-r--r--sound/drivers/Makefile2
-rw-r--r--sound/drivers/dummy.c37
-rw-r--r--sound/drivers/ml403-ac97cr.c6
-rw-r--r--sound/drivers/mpu401/mpu401_uart.c25
-rw-r--r--sound/drivers/pcsp/Makefile2
-rw-r--r--sound/drivers/pcsp/pcsp.c235
-rw-r--r--sound/drivers/pcsp/pcsp.h82
-rw-r--r--sound/drivers/pcsp/pcsp_input.c116
-rw-r--r--sound/drivers/pcsp/pcsp_input.h14
-rw-r--r--sound/drivers/pcsp/pcsp_lib.c338
-rw-r--r--sound/drivers/pcsp/pcsp_mixer.c143
-rw-r--r--sound/i2c/other/ak4114.c24
-rw-r--r--sound/i2c/other/ak4xxx-adda.c16
-rw-r--r--sound/isa/sb/sb16_csp.c28
-rw-r--r--sound/isa/sb/sb_common.c6
-rw-r--r--sound/oss/dmabuf.c4
-rw-r--r--sound/oss/trident.c12
-rw-r--r--sound/oss/trident.h2
-rw-r--r--sound/oss/vwsnd.c6
-rw-r--r--sound/pci/Kconfig22
-rw-r--r--sound/pci/Makefile1
-rw-r--r--sound/pci/ac97/ac97_patch.c46
-rw-r--r--sound/pci/ac97/ac97_pcm.c1
-rw-r--r--sound/pci/ad1889.c6
-rw-r--r--sound/pci/ali5451/ali5451.c32
-rw-r--r--sound/pci/als300.c4
-rw-r--r--sound/pci/atiixp.c2
-rw-r--r--sound/pci/atiixp_modem.c2
-rw-r--r--sound/pci/au88x0/au88x0.c2
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c10
-rw-r--r--sound/pci/aw2/Makefile3
-rw-r--r--sound/pci/aw2/aw2-alsa.c794
-rw-r--r--sound/pci/aw2/aw2-saa7146.c465
-rw-r--r--sound/pci/aw2/aw2-saa7146.h105
-rw-r--r--sound/pci/aw2/aw2-tsl.c110
-rw-r--r--sound/pci/aw2/saa7146.h168
-rw-r--r--sound/pci/azt3328.c7
-rw-r--r--sound/pci/ca0106/ca0106_main.c21
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c59
-rw-r--r--sound/pci/cmipci.c13
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c6
-rw-r--r--sound/pci/echoaudio/echoaudio.c7
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c15
-rw-r--r--sound/pci/emu10k1/emu10k1x.c30
-rw-r--r--sound/pci/emu10k1/emuproc.c2
-rw-r--r--sound/pci/ens1370.c9
-rw-r--r--sound/pci/es1938.c5
-rw-r--r--sound/pci/es1968.c42
-rw-r--r--sound/pci/fm801.c8
-rw-r--r--sound/pci/hda/Makefile2
-rw-r--r--sound/pci/hda/hda_codec.c201
-rw-r--r--sound/pci/hda/hda_codec.h13
-rw-r--r--sound/pci/hda/hda_generic.c4
-rw-r--r--sound/pci/hda/hda_intel.c459
-rw-r--r--sound/pci/hda/hda_local.h20
-rw-r--r--sound/pci/hda/hda_patch.h28
-rw-r--r--sound/pci/hda/patch_analog.c581
-rw-r--r--sound/pci/hda/patch_atihdmi.c8
-rw-r--r--sound/pci/hda/patch_cmedia.c13
-rw-r--r--sound/pci/hda/patch_conexant.c68
-rw-r--r--sound/pci/hda/patch_realtek.c1334
-rw-r--r--sound/pci/hda/patch_si3054.c4
-rw-r--r--sound/pci/hda/patch_sigmatel.c391
-rw-r--r--sound/pci/hda/patch_via.c14
-rw-r--r--sound/pci/ice1712/delta.c22
-rw-r--r--sound/pci/ice1712/delta.h2
-rw-r--r--sound/pci/ice1712/ews.c15
-rw-r--r--sound/pci/ice1712/ews.h4
-rw-r--r--sound/pci/ice1712/hoontech.c21
-rw-r--r--sound/pci/ice1712/ice1712.c45
-rw-r--r--sound/pci/ice1712/ice1712.h17
-rw-r--r--sound/pci/ice1712/ice1724.c430
-rw-r--r--sound/pci/ice1712/juli.c486
-rw-r--r--sound/pci/ice1712/pontis.c4
-rw-r--r--sound/pci/ice1712/prodigy192.c37
-rw-r--r--sound/pci/ice1712/revo.c55
-rw-r--r--sound/pci/intel8x0.c33
-rw-r--r--sound/pci/intel8x0m.c9
-rw-r--r--sound/pci/korg1212/korg1212.c1
-rw-r--r--sound/pci/maestro3.c38
-rw-r--r--sound/pci/nm256/nm256.c4
-rw-r--r--sound/pci/oxygen/cs4362a.h69
-rw-r--r--sound/pci/oxygen/cs4398.h69
-rw-r--r--sound/pci/oxygen/hifier.c36
-rw-r--r--sound/pci/oxygen/oxygen.c129
-rw-r--r--sound/pci/oxygen/oxygen.h23
-rw-r--r--sound/pci/oxygen/oxygen_io.c23
-rw-r--r--sound/pci/oxygen/oxygen_lib.c113
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c217
-rw-r--r--sound/pci/oxygen/oxygen_pcm.c78
-rw-r--r--sound/pci/oxygen/pcm1796.h58
-rw-r--r--sound/pci/oxygen/virtuoso.c594
-rw-r--r--sound/pci/oxygen/wm8785.h45
-rw-r--r--sound/pci/pcxhr/pcxhr.c7
-rw-r--r--sound/pci/pcxhr/pcxhr_core.c33
-rw-r--r--sound/pci/riptide/riptide.c14
-rw-r--r--sound/pci/rme32.c3
-rw-r--r--sound/pci/rme96.c3
-rw-r--r--sound/pci/rme9652/hdsp.c54
-rw-r--r--sound/pci/rme9652/hdspm.c19
-rw-r--r--sound/pci/sis7019.c7
-rw-r--r--sound/pci/trident/trident_main.c4
-rw-r--r--sound/pci/via82xx.c2
-rw-r--r--sound/pci/via82xx_modem.c2
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c4
-rw-r--r--sound/ppc/awacs.c265
-rw-r--r--sound/ppc/awacs.h21
-rw-r--r--sound/ppc/burgundy.c465
-rw-r--r--sound/ppc/burgundy.h31
-rw-r--r--sound/ppc/pmac.c10
-rw-r--r--sound/ppc/snd_ps3.c2
-rw-r--r--sound/sh/aica.c2
-rw-r--r--sound/soc/Kconfig2
-rw-r--r--sound/soc/Makefile2
-rw-r--r--sound/soc/at91/eti_b1_wm8731.c30
-rw-r--r--sound/soc/codecs/Kconfig4
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/ac97.c16
-rw-r--r--sound/soc/codecs/cs4270.c2
-rw-r--r--sound/soc/codecs/tlv320aic3x.c22
-rw-r--r--sound/soc/codecs/wm8731.c23
-rw-r--r--sound/soc/codecs/wm8750.c27
-rw-r--r--sound/soc/codecs/wm8753.c39
-rw-r--r--sound/soc/codecs/wm9712.c70
-rw-r--r--sound/soc/codecs/wm9713.c1300
-rw-r--r--sound/soc/codecs/wm9713.h53
-rw-r--r--sound/soc/davinci/Kconfig19
-rw-r--r--sound/soc/davinci/Makefile11
-rw-r--r--sound/soc/davinci/davinci-evm.c208
-rw-r--r--sound/soc/davinci/davinci-i2s.c407
-rw-r--r--sound/soc/davinci/davinci-i2s.h17
-rw-r--r--sound/soc/davinci/davinci-pcm.c389
-rw-r--r--sound/soc/davinci/davinci-pcm.h29
-rw-r--r--sound/soc/fsl/fsl_dma.c1
-rw-r--r--sound/soc/fsl/fsl_ssi.c1
-rw-r--r--sound/soc/omap/Kconfig19
-rw-r--r--sound/soc/omap/Makefile11
-rw-r--r--sound/soc/omap/n810.c336
-rw-r--r--sound/soc/omap/omap-mcbsp.c414
-rw-r--r--sound/soc/omap/omap-mcbsp.h49
-rw-r--r--sound/soc/omap/omap-pcm.c357
-rw-r--r--sound/soc/omap/omap-pcm.h35
-rw-r--r--sound/soc/pxa/corgi.c11
-rw-r--r--sound/soc/pxa/poodle.c8
-rw-r--r--sound/soc/pxa/pxa2xx-ac97.c88
-rw-r--r--sound/soc/pxa/pxa2xx-i2s.c1
-rw-r--r--sound/soc/pxa/pxa2xx-pcm.c9
-rw-r--r--sound/soc/pxa/spitz.c6
-rw-r--r--sound/soc/s3c24xx/ln2440sbc_alc650.c4
-rw-r--r--sound/soc/s3c24xx/neo1973_wm8753.c59
-rw-r--r--sound/soc/s3c24xx/s3c2443-ac97.c9
-rw-r--r--sound/soc/s3c24xx/s3c24xx-i2s.c41
-rw-r--r--sound/soc/s3c24xx/s3c24xx-pcm.c63
-rw-r--r--sound/soc/sh/Kconfig1
-rw-r--r--sound/soc/soc-core.c2
-rw-r--r--sound/soc/soc-dapm.c7
-rw-r--r--sound/spi/at73c213.c44
-rw-r--r--sound/usb/caiaq/caiaq-audio.c81
-rw-r--r--sound/usb/caiaq/caiaq-device.c4
-rw-r--r--sound/usb/usbaudio.c98
-rw-r--r--sound/usb/usbquirks.h75
172 files changed, 12136 insertions, 2413 deletions
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index 5d86e6809752..5b3274b465eb 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -16,6 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/wait.h> 18#include <linux/wait.h>
19#include <linux/clk.h>
19#include <linux/delay.h> 20#include <linux/delay.h>
20 21
21#include <sound/core.h> 22#include <sound/core.h>
@@ -27,6 +28,7 @@
27#include <linux/mutex.h> 28#include <linux/mutex.h>
28#include <asm/hardware.h> 29#include <asm/hardware.h>
29#include <asm/arch/pxa-regs.h> 30#include <asm/arch/pxa-regs.h>
31#include <asm/arch/pxa2xx-gpio.h>
30#include <asm/arch/audio.h> 32#include <asm/arch/audio.h>
31 33
32#include "pxa2xx-pcm.h" 34#include "pxa2xx-pcm.h"
@@ -35,6 +37,10 @@
35static DEFINE_MUTEX(car_mutex); 37static DEFINE_MUTEX(car_mutex);
36static DECLARE_WAIT_QUEUE_HEAD(gsr_wq); 38static DECLARE_WAIT_QUEUE_HEAD(gsr_wq);
37static volatile long gsr_bits; 39static volatile long gsr_bits;
40static struct clk *ac97_clk;
41#ifdef CONFIG_PXA27x
42static struct clk *ac97conf_clk;
43#endif
38 44
39/* 45/*
40 * Beware PXA27x bugs: 46 * Beware PXA27x bugs:
@@ -66,7 +72,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg
66 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 && 72 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 &&
67 !((GSR | gsr_bits) & GSR_SDONE)) { 73 !((GSR | gsr_bits) & GSR_SDONE)) {
68 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n", 74 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n",
69 __FUNCTION__, reg, GSR | gsr_bits); 75 __func__, reg, GSR | gsr_bits);
70 val = -1; 76 val = -1;
71 goto out; 77 goto out;
72 } 78 }
@@ -98,7 +104,7 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigne
98 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 && 104 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 &&
99 !((GSR | gsr_bits) & GSR_CDONE)) 105 !((GSR | gsr_bits) & GSR_CDONE))
100 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n", 106 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n",
101 __FUNCTION__, reg, GSR | gsr_bits); 107 __func__, reg, GSR | gsr_bits);
102 108
103 mutex_unlock(&car_mutex); 109 mutex_unlock(&car_mutex);
104} 110}
@@ -106,17 +112,35 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigne
106static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) 112static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
107{ 113{
108 /* First, try cold reset */ 114 /* First, try cold reset */
115#ifdef CONFIG_PXA3xx
116 int timeout;
117
118 /* Hold CLKBPB for 100us */
119 GCR = 0;
120 GCR = GCR_CLKBPB;
121 udelay(100);
122 GCR = 0;
123#endif
124
109 GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 125 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
110 GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 126 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
111 127
112 gsr_bits = 0; 128 gsr_bits = 0;
113#ifdef CONFIG_PXA27x 129#ifdef CONFIG_PXA27x
114 /* PXA27x Developers Manual section 13.5.2.2.1 */ 130 /* PXA27x Developers Manual section 13.5.2.2.1 */
115 pxa_set_cken(CKEN_AC97CONF, 1); 131 clk_enable(ac97conf_clk);
116 udelay(5); 132 udelay(5);
117 pxa_set_cken(CKEN_AC97CONF, 0); 133 clk_disable(ac97conf_clk);
118 GCR = GCR_COLD_RST; 134 GCR = GCR_COLD_RST;
119 udelay(50); 135 udelay(50);
136#elif defined(CONFIG_PXA3xx)
137 timeout = 1000;
138 /* Can't use interrupts on PXA3xx */
139 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
140
141 GCR = GCR_WARM_RST | GCR_COLD_RST;
142 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
143 mdelay(10);
120#else 144#else
121 GCR = GCR_COLD_RST; 145 GCR = GCR_COLD_RST;
122 GCR |= GCR_CDONE_IE|GCR_SDONE_IE; 146 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
@@ -125,7 +149,7 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
125 149
126 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) { 150 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) {
127 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n", 151 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
128 __FUNCTION__, gsr_bits); 152 __func__, gsr_bits);
129 153
130 /* let's try warm reset */ 154 /* let's try warm reset */
131 gsr_bits = 0; 155 gsr_bits = 0;
@@ -137,6 +161,12 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
137 GCR |= GCR_WARM_RST; 161 GCR |= GCR_WARM_RST;
138 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 162 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
139 udelay(500); 163 udelay(500);
164#elif defined(CONFIG_PXA3xx)
165 timeout = 100;
166 /* Can't use interrupts */
167 GCR |= GCR_WARM_RST;
168 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
169 mdelay(1);
140#else 170#else
141 GCR |= GCR_WARM_RST|GCR_PRIRDY_IEN|GCR_SECRDY_IEN; 171 GCR |= GCR_WARM_RST|GCR_PRIRDY_IEN|GCR_SECRDY_IEN;
142 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1); 172 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
@@ -144,7 +174,7 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
144 174
145 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 175 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
146 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", 176 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
147 __FUNCTION__, gsr_bits); 177 __func__, gsr_bits);
148 } 178 }
149 179
150 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 180 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
@@ -259,7 +289,7 @@ static int pxa2xx_ac97_do_suspend(struct snd_card *card, pm_message_t state)
259 if (platform_ops && platform_ops->suspend) 289 if (platform_ops && platform_ops->suspend)
260 platform_ops->suspend(platform_ops->priv); 290 platform_ops->suspend(platform_ops->priv);
261 GCR |= GCR_ACLINK_OFF; 291 GCR |= GCR_ACLINK_OFF;
262 pxa_set_cken(CKEN_AC97, 0); 292 clk_disable(ac97_clk);
263 293
264 return 0; 294 return 0;
265} 295}
@@ -268,7 +298,7 @@ static int pxa2xx_ac97_do_resume(struct snd_card *card)
268{ 298{
269 pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; 299 pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
270 300
271 pxa_set_cken(CKEN_AC97, 1); 301 clk_enable(ac97_clk);
272 if (platform_ops && platform_ops->resume) 302 if (platform_ops && platform_ops->resume)
273 platform_ops->resume(platform_ops->priv); 303 platform_ops->resume(platform_ops->priv);
274 snd_ac97_resume(pxa2xx_ac97_ac97); 304 snd_ac97_resume(pxa2xx_ac97_ac97);
@@ -335,8 +365,21 @@ static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
335#ifdef CONFIG_PXA27x 365#ifdef CONFIG_PXA27x
336 /* Use GPIO 113 as AC97 Reset on Bulverde */ 366 /* Use GPIO 113 as AC97 Reset on Bulverde */
337 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 367 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
368 ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK");
369 if (IS_ERR(ac97conf_clk)) {
370 ret = PTR_ERR(ac97conf_clk);
371 ac97conf_clk = NULL;
372 goto err;
373 }
338#endif 374#endif
339 pxa_set_cken(CKEN_AC97, 1); 375
376 ac97_clk = clk_get(&dev->dev, "AC97CLK");
377 if (IS_ERR(ac97_clk)) {
378 ret = PTR_ERR(ac97_clk);
379 ac97_clk = NULL;
380 goto err;
381 }
382 clk_enable(ac97_clk);
340 383
341 ret = snd_ac97_bus(card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus); 384 ret = snd_ac97_bus(card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus);
342 if (ret) 385 if (ret)
@@ -361,11 +404,19 @@ static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
361 err: 404 err:
362 if (card) 405 if (card)
363 snd_card_free(card); 406 snd_card_free(card);
364 if (CKEN & (1 << CKEN_AC97)) { 407 if (ac97_clk) {
365 GCR |= GCR_ACLINK_OFF; 408 GCR |= GCR_ACLINK_OFF;
366 free_irq(IRQ_AC97, NULL); 409 free_irq(IRQ_AC97, NULL);
367 pxa_set_cken(CKEN_AC97, 0); 410 clk_disable(ac97_clk);
411 clk_put(ac97_clk);
412 ac97_clk = NULL;
413 }
414#ifdef CONFIG_PXA27x
415 if (ac97conf_clk) {
416 clk_put(ac97conf_clk);
417 ac97conf_clk = NULL;
368 } 418 }
419#endif
369 return ret; 420 return ret;
370} 421}
371 422
@@ -378,7 +429,13 @@ static int __devexit pxa2xx_ac97_remove(struct platform_device *dev)
378 platform_set_drvdata(dev, NULL); 429 platform_set_drvdata(dev, NULL);
379 GCR |= GCR_ACLINK_OFF; 430 GCR |= GCR_ACLINK_OFF;
380 free_irq(IRQ_AC97, NULL); 431 free_irq(IRQ_AC97, NULL);
381 pxa_set_cken(CKEN_AC97, 0); 432 clk_disable(ac97_clk);
433 clk_put(ac97_clk);
434 ac97_clk = NULL;
435#ifdef CONFIG_PXA27x
436 clk_put(ac97conf_clk);
437 ac97conf_clk = NULL;
438#endif
382 } 439 }
383 440
384 return 0; 441 return 0;
@@ -391,6 +448,7 @@ static struct platform_driver pxa2xx_ac97_driver = {
391 .resume = pxa2xx_ac97_resume, 448 .resume = pxa2xx_ac97_resume,
392 .driver = { 449 .driver = {
393 .name = "pxa2xx-ac97", 450 .name = "pxa2xx-ac97",
451 .owner = THIS_MODULE,
394 }, 452 },
395}; 453};
396 454
@@ -410,3 +468,4 @@ module_exit(pxa2xx_ac97_exit);
410MODULE_AUTHOR("Nicolas Pitre"); 468MODULE_AUTHOR("Nicolas Pitre");
411MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); 469MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
412MODULE_LICENSE("GPL"); 470MODULE_LICENSE("GPL");
471MODULE_ALIAS("platform:pxa2xx-ac97");
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 829ca38b595e..a8d71c6c8e75 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -181,3 +181,7 @@ config SND_PCM_XRUN_DEBUG
181 It is usually not required, but if you have trouble with 181 It is usually not required, but if you have trouble with
182 sound clicking when system is loaded, it may help to determine 182 sound clicking when system is loaded, it may help to determine
183 the process or driver which causes the scheduling gaps. 183 the process or driver which causes the scheduling gaps.
184
185config SND_VMASTER
186 bool
187 depends on SND
diff --git a/sound/core/Makefile b/sound/core/Makefile
index 267039a97bd5..da8e685eef9c 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -6,6 +6,7 @@
6snd-y := sound.o init.o memory.o info.o control.o misc.o device.o 6snd-y := sound.o init.o memory.o info.o control.o misc.o device.o
7snd-$(CONFIG_ISA_DMA_API) += isadma.o 7snd-$(CONFIG_ISA_DMA_API) += isadma.o
8snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o 8snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o
9snd-$(CONFIG_SND_VMASTER) += vmaster.o
9 10
10snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \ 11snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \
11 pcm_memory.o 12 pcm_memory.o
diff --git a/sound/core/info.c b/sound/core/info.c
index 9977ec2eace3..cb5ead3e202d 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -544,7 +544,7 @@ int __init snd_info_init(void)
544{ 544{
545 struct proc_dir_entry *p; 545 struct proc_dir_entry *p;
546 546
547 p = snd_create_proc_entry("asound", S_IFDIR | S_IRUGO | S_IXUGO, &proc_root); 547 p = snd_create_proc_entry("asound", S_IFDIR | S_IRUGO | S_IXUGO, NULL);
548 if (p == NULL) 548 if (p == NULL)
549 return -ENOMEM; 549 return -ENOMEM;
550 snd_proc_root = p; 550 snd_proc_root = p;
@@ -594,7 +594,7 @@ int __exit snd_info_done(void)
594#ifdef CONFIG_SND_OSSEMUL 594#ifdef CONFIG_SND_OSSEMUL
595 snd_info_free_entry(snd_oss_root); 595 snd_info_free_entry(snd_oss_root);
596#endif 596#endif
597 snd_remove_proc_entry(&proc_root, snd_proc_root); 597 snd_remove_proc_entry(NULL, snd_proc_root);
598 } 598 }
599 return 0; 599 return 0;
600} 600}
diff --git a/sound/core/init.c b/sound/core/init.c
index e3338d6071ef..ac0573416130 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -254,7 +254,7 @@ static int snd_disconnect_release(struct inode *inode, struct file *file)
254 if (likely(df)) 254 if (likely(df))
255 return df->disconnected_f_op->release(inode, file); 255 return df->disconnected_f_op->release(inode, file);
256 256
257 panic("%s(%p, %p) failed!", __FUNCTION__, inode, file); 257 panic("%s(%p, %p) failed!", __func__, inode, file);
258} 258}
259 259
260static unsigned int snd_disconnect_poll(struct file * file, poll_table * wait) 260static unsigned int snd_disconnect_poll(struct file * file, poll_table * wait)
@@ -311,6 +311,9 @@ int snd_card_disconnect(struct snd_card *card)
311 struct file *file; 311 struct file *file;
312 int err; 312 int err;
313 313
314 if (!card)
315 return -EINVAL;
316
314 spin_lock(&card->files_lock); 317 spin_lock(&card->files_lock);
315 if (card->shutdown) { 318 if (card->shutdown) {
316 spin_unlock(&card->files_lock); 319 spin_unlock(&card->files_lock);
@@ -322,6 +325,7 @@ int snd_card_disconnect(struct snd_card *card)
322 /* phase 1: disable fops (user space) operations for ALSA API */ 325 /* phase 1: disable fops (user space) operations for ALSA API */
323 mutex_lock(&snd_card_mutex); 326 mutex_lock(&snd_card_mutex);
324 snd_cards[card->number] = NULL; 327 snd_cards[card->number] = NULL;
328 snd_cards_lock &= ~(1 << card->number);
325 mutex_unlock(&snd_card_mutex); 329 mutex_unlock(&snd_card_mutex);
326 330
327 /* phase 2: replace file->f_op with special dummy operations */ 331 /* phase 2: replace file->f_op with special dummy operations */
@@ -360,6 +364,15 @@ int snd_card_disconnect(struct snd_card *card)
360 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number); 364 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number);
361 365
362 snd_info_card_disconnect(card); 366 snd_info_card_disconnect(card);
367#ifndef CONFIG_SYSFS_DEPRECATED
368 if (card->card_dev) {
369 device_unregister(card->card_dev);
370 card->card_dev = NULL;
371 }
372#endif
373#ifdef CONFIG_PM
374 wake_up(&card->power_sleep);
375#endif
363 return 0; 376 return 0;
364} 377}
365 378
@@ -401,33 +414,14 @@ static int snd_card_do_free(struct snd_card *card)
401 snd_printk(KERN_WARNING "unable to free card info\n"); 414 snd_printk(KERN_WARNING "unable to free card info\n");
402 /* Not fatal error */ 415 /* Not fatal error */
403 } 416 }
404#ifndef CONFIG_SYSFS_DEPRECATED
405 if (card->card_dev)
406 device_unregister(card->card_dev);
407#endif
408 kfree(card); 417 kfree(card);
409 return 0; 418 return 0;
410} 419}
411 420
412static int snd_card_free_prepare(struct snd_card *card)
413{
414 if (card == NULL)
415 return -EINVAL;
416 (void) snd_card_disconnect(card);
417 mutex_lock(&snd_card_mutex);
418 snd_cards[card->number] = NULL;
419 snd_cards_lock &= ~(1 << card->number);
420 mutex_unlock(&snd_card_mutex);
421#ifdef CONFIG_PM
422 wake_up(&card->power_sleep);
423#endif
424 return 0;
425}
426
427int snd_card_free_when_closed(struct snd_card *card) 421int snd_card_free_when_closed(struct snd_card *card)
428{ 422{
429 int free_now = 0; 423 int free_now = 0;
430 int ret = snd_card_free_prepare(card); 424 int ret = snd_card_disconnect(card);
431 if (ret) 425 if (ret)
432 return ret; 426 return ret;
433 427
@@ -447,7 +441,7 @@ EXPORT_SYMBOL(snd_card_free_when_closed);
447 441
448int snd_card_free(struct snd_card *card) 442int snd_card_free(struct snd_card *card)
449{ 443{
450 int ret = snd_card_free_prepare(card); 444 int ret = snd_card_disconnect(card);
451 if (ret) 445 if (ret)
452 return ret; 446 return ret;
453 447
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 920e5780c228..23b7bc02728b 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -629,9 +629,8 @@ static const struct file_operations snd_mem_proc_fops = {
629static int __init snd_mem_init(void) 629static int __init snd_mem_init(void)
630{ 630{
631#ifdef CONFIG_PROC_FS 631#ifdef CONFIG_PROC_FS
632 snd_mem_proc = create_proc_entry(SND_MEM_PROC_FILE, 0644, NULL); 632 snd_mem_proc = proc_create(SND_MEM_PROC_FILE, 0644, NULL,
633 if (snd_mem_proc) 633 &snd_mem_proc_fops);
634 snd_mem_proc->proc_fops = &snd_mem_proc_fops;
635#endif 634#endif
636 return 0; 635 return 0;
637} 636}
diff --git a/sound/core/misc.c b/sound/core/misc.c
index 102d1c36cf26..38524f615d94 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -39,7 +39,7 @@ void snd_verbose_printk(const char *file, int line, const char *format, ...)
39{ 39{
40 va_list args; 40 va_list args;
41 41
42 if (format[0] == '<' && format[1] >= '0' && format[1] <= '9' && format[2] == '>') { 42 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
43 char tmp[] = "<0>"; 43 char tmp[] = "<0>";
44 tmp[1] = format[1]; 44 tmp[1] = format[1];
45 printk("%sALSA %s:%d: ", tmp, file, line); 45 printk("%sALSA %s:%d: ", tmp, file, line);
@@ -60,7 +60,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
60{ 60{
61 va_list args; 61 va_list args;
62 62
63 if (format[0] == '<' && format[1] >= '0' && format[1] <= '9' && format[2] == '>') { 63 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
64 char tmp[] = "<0>"; 64 char tmp[] = "<0>";
65 tmp[1] = format[1]; 65 tmp[1] = format[1];
66 printk("%sALSA %s:%d: ", tmp, file, line); 66 printk("%sALSA %s:%d: ", tmp, file, line);
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 75daed298a15..581aa2c60e65 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1257,6 +1257,8 @@ static void snd_mixer_oss_build(struct snd_mixer_oss *mixer)
1257 { SOUND_MIXER_DIGITAL3, "Digital", 2 }, 1257 { SOUND_MIXER_DIGITAL3, "Digital", 2 },
1258 { SOUND_MIXER_PHONEIN, "Phone", 0 }, 1258 { SOUND_MIXER_PHONEIN, "Phone", 0 },
1259 { SOUND_MIXER_PHONEOUT, "Master Mono", 0 }, 1259 { SOUND_MIXER_PHONEOUT, "Master Mono", 0 },
1260 { SOUND_MIXER_PHONEOUT, "Speaker", 0 }, /*fallback*/
1261 { SOUND_MIXER_PHONEOUT, "Mono", 0 }, /*fallback*/
1260 { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */ 1262 { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */
1261 { SOUND_MIXER_VIDEO, "Video", 0 }, 1263 { SOUND_MIXER_VIDEO, "Video", 0 },
1262 { SOUND_MIXER_RADIO, "Radio", 0 }, 1264 { SOUND_MIXER_RADIO, "Radio", 0 },
diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c
index ab570a0a6183..558dadbf45f1 100644
--- a/sound/core/seq/oss/seq_oss_synth.c
+++ b/sound/core/seq/oss/seq_oss_synth.c
@@ -245,8 +245,13 @@ snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
245 info->nr_voices = rec->nr_voices; 245 info->nr_voices = rec->nr_voices;
246 if (info->nr_voices > 0) { 246 if (info->nr_voices > 0) {
247 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL); 247 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL);
248 if (!info->ch) 248 if (!info->ch) {
249 BUG(); 249 snd_printk(KERN_ERR "Cannot malloc\n");
250 rec->oper.close(&info->arg);
251 module_put(rec->oper.owner);
252 snd_use_lock_free(&rec->use_lock);
253 continue;
254 }
250 reset_channels(info); 255 reset_channels(info);
251 } 256 }
252 debug_printk(("synth %d assigned\n", i)); 257 debug_printk(("synth %d assigned\n", i));
diff --git a/sound/pci/hda/vmaster.c b/sound/core/vmaster.c
index 2da49d20a1fc..4cc57f902e2c 100644
--- a/sound/pci/hda/vmaster.c
+++ b/sound/core/vmaster.c
@@ -12,6 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <sound/core.h> 13#include <sound/core.h>
14#include <sound/control.h> 14#include <sound/control.h>
15#include <sound/tlv.h>
15 16
16/* 17/*
17 * a subset of information returned via ctl info callback 18 * a subset of information returned via ctl info callback
@@ -34,6 +35,7 @@ struct link_master {
34 struct list_head slaves; 35 struct list_head slaves;
35 struct link_ctl_info info; 36 struct link_ctl_info info;
36 int val; /* the master value */ 37 int val; /* the master value */
38 unsigned int tlv[4];
37}; 39};
38 40
39/* 41/*
@@ -253,6 +255,8 @@ int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
253 return 0; 255 return 0;
254} 256}
255 257
258EXPORT_SYMBOL(snd_ctl_add_slave);
259
256/* 260/*
257 * ctl callbacks for master controls 261 * ctl callbacks for master controls
258 */ 262 */
@@ -355,10 +359,13 @@ struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
355 kctl->private_free = master_free; 359 kctl->private_free = master_free;
356 360
357 /* additional (constant) TLV read */ 361 /* additional (constant) TLV read */
358 if (tlv) { 362 if (tlv && tlv[0] == SNDRV_CTL_TLVT_DB_SCALE) {
359 /* FIXME: this assumes that the max volume is 0 dB */
360 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; 363 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
361 kctl->tlv.p = tlv; 364 memcpy(master->tlv, tlv, sizeof(master->tlv));
365 kctl->tlv.p = master->tlv;
362 } 366 }
367
363 return kctl; 368 return kctl;
364} 369}
370
371EXPORT_SYMBOL(snd_ctl_make_virtual_master);
diff --git a/sound/drivers/Kconfig b/sound/drivers/Kconfig
index 75d4fe09fdf3..a78a8d045175 100644
--- a/sound/drivers/Kconfig
+++ b/sound/drivers/Kconfig
@@ -4,6 +4,26 @@ menu "Generic devices"
4 depends on SND!=n 4 depends on SND!=n
5 5
6 6
7config SND_PCSP
8 tristate "Internal PC speaker support"
9 depends on X86_PC && HIGH_RES_TIMERS
10 depends on INPUT
11 depends on SND
12 select SND_PCM
13 help
14 If you don't have a sound card in your computer, you can include a
15 driver for the PC speaker which allows it to act like a primitive
16 sound card.
17 This driver also replaces the pcspkr driver for beeps.
18
19 You can compile this as a module which will be called snd-pcsp.
20
21 You don't need this driver if you only want your pc-speaker to beep.
22 You don't need this driver if you have a tablet piezo beeper
23 in your PC instead of the real speaker.
24
25 It should not hurt to say Y or M here in all other cases.
26
7config SND_MPU401_UART 27config SND_MPU401_UART
8 tristate 28 tristate
9 select SND_RAWMIDI 29 select SND_RAWMIDI
diff --git a/sound/drivers/Makefile b/sound/drivers/Makefile
index 8e5530006e1f..d4a07f9ff2c7 100644
--- a/sound/drivers/Makefile
+++ b/sound/drivers/Makefile
@@ -20,4 +20,4 @@ obj-$(CONFIG_SND_MTS64) += snd-mts64.o
20obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o 20obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o
21obj-$(CONFIG_SND_ML403_AC97CR) += snd-ml403-ac97cr.o 21obj-$(CONFIG_SND_ML403_AC97CR) += snd-ml403-ac97cr.o
22 22
23obj-$(CONFIG_SND) += opl3/ opl4/ mpu401/ vx/ 23obj-$(CONFIG_SND) += opl3/ opl4/ mpu401/ vx/ pcsp/
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index a240eaeb5c62..4e4c69e6cb4c 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -181,10 +181,10 @@ struct snd_dummy_pcm {
181 struct snd_dummy *dummy; 181 struct snd_dummy *dummy;
182 spinlock_t lock; 182 spinlock_t lock;
183 struct timer_list timer; 183 struct timer_list timer;
184 unsigned int pcm_size; 184 unsigned int pcm_buffer_size;
185 unsigned int pcm_count; 185 unsigned int pcm_period_size;
186 unsigned int pcm_bps; /* bytes per second */ 186 unsigned int pcm_bps; /* bytes per second */
187 unsigned int pcm_jiffie; /* bytes per one jiffie */ 187 unsigned int pcm_hz; /* HZ */
188 unsigned int pcm_irq_pos; /* IRQ position */ 188 unsigned int pcm_irq_pos; /* IRQ position */
189 unsigned int pcm_buf_pos; /* position in buffer */ 189 unsigned int pcm_buf_pos; /* position in buffer */
190 struct snd_pcm_substream *substream; 190 struct snd_pcm_substream *substream;
@@ -230,19 +230,24 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
230{ 230{
231 struct snd_pcm_runtime *runtime = substream->runtime; 231 struct snd_pcm_runtime *runtime = substream->runtime;
232 struct snd_dummy_pcm *dpcm = runtime->private_data; 232 struct snd_dummy_pcm *dpcm = runtime->private_data;
233 unsigned int bps; 233 int bps;
234
235 bps = snd_pcm_format_width(runtime->format) * runtime->rate *
236 runtime->channels / 8;
234 237
235 bps = runtime->rate * runtime->channels;
236 bps *= snd_pcm_format_width(runtime->format);
237 bps /= 8;
238 if (bps <= 0) 238 if (bps <= 0)
239 return -EINVAL; 239 return -EINVAL;
240
240 dpcm->pcm_bps = bps; 241 dpcm->pcm_bps = bps;
241 dpcm->pcm_jiffie = bps / HZ; 242 dpcm->pcm_hz = HZ;
242 dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); 243 dpcm->pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream);
243 dpcm->pcm_count = snd_pcm_lib_period_bytes(substream); 244 dpcm->pcm_period_size = snd_pcm_lib_period_bytes(substream);
244 dpcm->pcm_irq_pos = 0; 245 dpcm->pcm_irq_pos = 0;
245 dpcm->pcm_buf_pos = 0; 246 dpcm->pcm_buf_pos = 0;
247
248 snd_pcm_format_set_silence(runtime->format, runtime->dma_area,
249 bytes_to_samples(runtime, runtime->dma_bytes));
250
246 return 0; 251 return 0;
247} 252}
248 253
@@ -254,11 +259,11 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data)
254 spin_lock_irqsave(&dpcm->lock, flags); 259 spin_lock_irqsave(&dpcm->lock, flags);
255 dpcm->timer.expires = 1 + jiffies; 260 dpcm->timer.expires = 1 + jiffies;
256 add_timer(&dpcm->timer); 261 add_timer(&dpcm->timer);
257 dpcm->pcm_irq_pos += dpcm->pcm_jiffie; 262 dpcm->pcm_irq_pos += dpcm->pcm_bps;
258 dpcm->pcm_buf_pos += dpcm->pcm_jiffie; 263 dpcm->pcm_buf_pos += dpcm->pcm_bps;
259 dpcm->pcm_buf_pos %= dpcm->pcm_size; 264 dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz;
260 if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { 265 if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) {
261 dpcm->pcm_irq_pos %= dpcm->pcm_count; 266 dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz;
262 spin_unlock_irqrestore(&dpcm->lock, flags); 267 spin_unlock_irqrestore(&dpcm->lock, flags);
263 snd_pcm_period_elapsed(dpcm->substream); 268 snd_pcm_period_elapsed(dpcm->substream);
264 } else 269 } else
@@ -270,7 +275,7 @@ static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *su
270 struct snd_pcm_runtime *runtime = substream->runtime; 275 struct snd_pcm_runtime *runtime = substream->runtime;
271 struct snd_dummy_pcm *dpcm = runtime->private_data; 276 struct snd_dummy_pcm *dpcm = runtime->private_data;
272 277
273 return bytes_to_frames(runtime, dpcm->pcm_buf_pos); 278 return bytes_to_frames(runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz);
274} 279}
275 280
276static struct snd_pcm_hardware snd_card_dummy_playback = 281static struct snd_pcm_hardware snd_card_dummy_playback =
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c
index 05a871aa7b81..ecdbeb6d3603 100644
--- a/sound/drivers/ml403-ac97cr.c
+++ b/sound/drivers/ml403-ac97cr.c
@@ -1191,8 +1191,6 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
1191 return err; 1191 return err;
1192 } 1192 }
1193 1193
1194 snd_card_set_dev(card, &pfdev->dev);
1195
1196 *rml403_ac97cr = ml403_ac97cr; 1194 *rml403_ac97cr = ml403_ac97cr;
1197 return 0; 1195 return 0;
1198} 1196}
@@ -1330,11 +1328,15 @@ static int snd_ml403_ac97cr_remove(struct platform_device *pfdev)
1330 return 0; 1328 return 0;
1331} 1329}
1332 1330
1331/* work with hotplug and coldplug */
1332MODULE_ALIAS("platform:" SND_ML403_AC97CR_DRIVER);
1333
1333static struct platform_driver snd_ml403_ac97cr_driver = { 1334static struct platform_driver snd_ml403_ac97cr_driver = {
1334 .probe = snd_ml403_ac97cr_probe, 1335 .probe = snd_ml403_ac97cr_probe,
1335 .remove = snd_ml403_ac97cr_remove, 1336 .remove = snd_ml403_ac97cr_remove,
1336 .driver = { 1337 .driver = {
1337 .name = SND_ML403_AC97CR_DRIVER, 1338 .name = SND_ML403_AC97CR_DRIVER,
1339 .owner = THIS_MODULE,
1338 }, 1340 },
1339}; 1341};
1340 1342
diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index 5993864acbd3..2af09996a3d0 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -49,12 +49,10 @@ static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu);
49 49
50 */ 50 */
51 51
52#define snd_mpu401_input_avail(mpu) (!(mpu->read(mpu, MPU401C(mpu)) & 0x80)) 52#define snd_mpu401_input_avail(mpu) \
53#define snd_mpu401_output_ready(mpu) (!(mpu->read(mpu, MPU401C(mpu)) & 0x40)) 53 (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_RX_EMPTY))
54 54#define snd_mpu401_output_ready(mpu) \
55#define MPU401_RESET 0xff 55 (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_TX_FULL))
56#define MPU401_ENTER_UART 0x3f
57#define MPU401_ACK 0xfe
58 56
59/* Build in lowlevel io */ 57/* Build in lowlevel io */
60static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data, 58static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data,
@@ -245,7 +243,7 @@ static int snd_mpu401_uart_cmd(struct snd_mpu401 * mpu, unsigned char cmd,
245#endif 243#endif
246 } 244 }
247 mpu->write(mpu, cmd, MPU401C(mpu)); 245 mpu->write(mpu, cmd, MPU401C(mpu));
248 if (ack) { 246 if (ack && !(mpu->info_flags & MPU401_INFO_NO_ACK)) {
249 ok = 0; 247 ok = 0;
250 timeout = 10000; 248 timeout = 10000;
251 while (!ok && timeout-- > 0) { 249 while (!ok && timeout-- > 0) {
@@ -425,16 +423,17 @@ static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu)
425static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu) 423static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu)
426{ 424{
427 unsigned char byte; 425 unsigned char byte;
428 int max = 256, timeout; 426 int max = 256;
429 427
430 do { 428 do {
431 if (snd_rawmidi_transmit_peek(mpu->substream_output, 429 if (snd_rawmidi_transmit_peek(mpu->substream_output,
432 &byte, 1) == 1) { 430 &byte, 1) == 1) {
433 for (timeout = 100; timeout > 0; timeout--) { 431 /*
434 if (snd_mpu401_output_ready(mpu)) 432 * Try twice because there is hardware that insists on
435 break; 433 * setting the output busy bit after each write.
436 } 434 */
437 if (timeout == 0) 435 if (!snd_mpu401_output_ready(mpu) &&
436 !snd_mpu401_output_ready(mpu))
438 break; /* Tx FIFO full - try again later */ 437 break; /* Tx FIFO full - try again later */
439 mpu->write(mpu, byte, MPU401D(mpu)); 438 mpu->write(mpu, byte, MPU401D(mpu));
440 snd_rawmidi_transmit_ack(mpu->substream_output, 1); 439 snd_rawmidi_transmit_ack(mpu->substream_output, 1);
diff --git a/sound/drivers/pcsp/Makefile b/sound/drivers/pcsp/Makefile
new file mode 100644
index 000000000000..b19555b440da
--- /dev/null
+++ b/sound/drivers/pcsp/Makefile
@@ -0,0 +1,2 @@
1snd-pcsp-objs := pcsp.o pcsp_lib.o pcsp_mixer.o pcsp_input.o
2obj-$(CONFIG_SND_PCSP) += snd-pcsp.o
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
new file mode 100644
index 000000000000..59203511e77d
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp.c
@@ -0,0 +1,235 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1997-2001 David Woodhouse
5 * Copyright (C) 2001-2008 Stas Sergeev
6 */
7
8#include <linux/init.h>
9#include <linux/moduleparam.h>
10#include <linux/platform_device.h>
11#include <sound/core.h>
12#include <sound/initval.h>
13#include <sound/pcm.h>
14#include <linux/input.h>
15#include <linux/delay.h>
16#include <asm/bitops.h>
17#include "pcsp_input.h"
18#include "pcsp.h"
19
20MODULE_AUTHOR("Stas Sergeev <stsp@users.sourceforge.net>");
21MODULE_DESCRIPTION("PC-Speaker driver");
22MODULE_LICENSE("GPL");
23MODULE_SUPPORTED_DEVICE("{{PC-Speaker, pcsp}}");
24MODULE_ALIAS("platform:pcspkr");
25
26static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
27static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
28static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
29
30module_param(index, int, 0444);
31MODULE_PARM_DESC(index, "Index value for pcsp soundcard.");
32module_param(id, charp, 0444);
33MODULE_PARM_DESC(id, "ID string for pcsp soundcard.");
34module_param(enable, bool, 0444);
35MODULE_PARM_DESC(enable, "Enable PC-Speaker sound.");
36
37struct snd_pcsp pcsp_chip;
38
39static int __devinit snd_pcsp_create(struct snd_card *card)
40{
41 static struct snd_device_ops ops = { };
42 struct timespec tp;
43 int err;
44 int div, min_div, order;
45
46 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
47 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) {
48 printk(KERN_ERR "PCSP: Timer resolution is not sufficient "
49 "(%linS)\n", tp.tv_nsec);
50 printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI "
51 "enabled.\n");
52 return -EIO;
53 }
54
55 if (loops_per_jiffy >= PCSP_MIN_LPJ && tp.tv_nsec <= PCSP_MIN_PERIOD_NS)
56 min_div = MIN_DIV;
57 else
58 min_div = MAX_DIV;
59#if PCSP_DEBUG
60 printk("PCSP: lpj=%li, min_div=%i, res=%li\n",
61 loops_per_jiffy, min_div, tp.tv_nsec);
62#endif
63
64 div = MAX_DIV / min_div;
65 order = fls(div) - 1;
66
67 pcsp_chip.max_treble = min(order, PCSP_MAX_TREBLE);
68 pcsp_chip.treble = min(pcsp_chip.max_treble, PCSP_DEFAULT_TREBLE);
69 pcsp_chip.playback_ptr = 0;
70 pcsp_chip.period_ptr = 0;
71 atomic_set(&pcsp_chip.timer_active, 0);
72 pcsp_chip.enable = 1;
73 pcsp_chip.pcspkr = 1;
74
75 spin_lock_init(&pcsp_chip.substream_lock);
76
77 pcsp_chip.card = card;
78 pcsp_chip.port = 0x61;
79 pcsp_chip.irq = -1;
80 pcsp_chip.dma = -1;
81
82 /* Register device */
83 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, &pcsp_chip, &ops);
84 if (err < 0)
85 return err;
86
87 return 0;
88}
89
90static int __devinit snd_card_pcsp_probe(int devnum, struct device *dev)
91{
92 struct snd_card *card;
93 int err;
94
95 if (devnum != 0)
96 return -EINVAL;
97
98 hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
99 pcsp_chip.timer.cb_mode = HRTIMER_CB_IRQSAFE;
100 pcsp_chip.timer.function = pcsp_do_timer;
101
102 card = snd_card_new(index, id, THIS_MODULE, 0);
103 if (!card)
104 return -ENOMEM;
105
106 err = snd_pcsp_create(card);
107 if (err < 0) {
108 snd_card_free(card);
109 return err;
110 }
111 err = snd_pcsp_new_pcm(&pcsp_chip);
112 if (err < 0) {
113 snd_card_free(card);
114 return err;
115 }
116 err = snd_pcsp_new_mixer(&pcsp_chip);
117 if (err < 0) {
118 snd_card_free(card);
119 return err;
120 }
121
122 snd_card_set_dev(pcsp_chip.card, dev);
123
124 strcpy(card->driver, "PC-Speaker");
125 strcpy(card->shortname, "pcsp");
126 sprintf(card->longname, "Internal PC-Speaker at port 0x%x",
127 pcsp_chip.port);
128
129 err = snd_card_register(card);
130 if (err < 0) {
131 snd_card_free(card);
132 return err;
133 }
134
135 return 0;
136}
137
138static int __devinit alsa_card_pcsp_init(struct device *dev)
139{
140 int err;
141
142 err = snd_card_pcsp_probe(0, dev);
143 if (err) {
144 printk(KERN_ERR "PC-Speaker initialization failed.\n");
145 return err;
146 }
147
148#ifdef CONFIG_DEBUG_PAGEALLOC
149 /* Well, CONFIG_DEBUG_PAGEALLOC makes the sound horrible. Lets alert */
150 printk(KERN_WARNING "PCSP: CONFIG_DEBUG_PAGEALLOC is enabled, "
151 "which may make the sound noisy.\n");
152#endif
153
154 return 0;
155}
156
157static void __devexit alsa_card_pcsp_exit(struct snd_pcsp *chip)
158{
159 snd_card_free(chip->card);
160}
161
162static int __devinit pcsp_probe(struct platform_device *dev)
163{
164 int err;
165
166 err = pcspkr_input_init(&pcsp_chip.input_dev, &dev->dev);
167 if (err < 0)
168 return err;
169
170 err = alsa_card_pcsp_init(&dev->dev);
171 if (err < 0) {
172 pcspkr_input_remove(pcsp_chip.input_dev);
173 return err;
174 }
175
176 platform_set_drvdata(dev, &pcsp_chip);
177 return 0;
178}
179
180static int __devexit pcsp_remove(struct platform_device *dev)
181{
182 struct snd_pcsp *chip = platform_get_drvdata(dev);
183 alsa_card_pcsp_exit(chip);
184 pcspkr_input_remove(chip->input_dev);
185 platform_set_drvdata(dev, NULL);
186 return 0;
187}
188
189static void pcsp_stop_beep(struct snd_pcsp *chip)
190{
191 spin_lock_irq(&chip->substream_lock);
192 if (!chip->playback_substream)
193 pcspkr_stop_sound();
194 spin_unlock_irq(&chip->substream_lock);
195}
196
197static int pcsp_suspend(struct platform_device *dev, pm_message_t state)
198{
199 struct snd_pcsp *chip = platform_get_drvdata(dev);
200 pcsp_stop_beep(chip);
201 snd_pcm_suspend_all(chip->pcm);
202 return 0;
203}
204
205static void pcsp_shutdown(struct platform_device *dev)
206{
207 struct snd_pcsp *chip = platform_get_drvdata(dev);
208 pcsp_stop_beep(chip);
209}
210
211static struct platform_driver pcsp_platform_driver = {
212 .driver = {
213 .name = "pcspkr",
214 .owner = THIS_MODULE,
215 },
216 .probe = pcsp_probe,
217 .remove = __devexit_p(pcsp_remove),
218 .suspend = pcsp_suspend,
219 .shutdown = pcsp_shutdown,
220};
221
222static int __init pcsp_init(void)
223{
224 if (!enable)
225 return -ENODEV;
226 return platform_driver_register(&pcsp_platform_driver);
227}
228
229static void __exit pcsp_exit(void)
230{
231 platform_driver_unregister(&pcsp_platform_driver);
232}
233
234module_init(pcsp_init);
235module_exit(pcsp_exit);
diff --git a/sound/drivers/pcsp/pcsp.h b/sound/drivers/pcsp/pcsp.h
new file mode 100644
index 000000000000..f07cc1ee1fe7
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp.h
@@ -0,0 +1,82 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1993-1997 Michael Beck
5 * Copyright (C) 1997-2001 David Woodhouse
6 * Copyright (C) 2001-2008 Stas Sergeev
7 */
8
9#ifndef __PCSP_H__
10#define __PCSP_H__
11
12#include <linux/hrtimer.h>
13#if defined(CONFIG_MIPS) || defined(CONFIG_X86)
14/* Use the global PIT lock ! */
15#include <asm/i8253.h>
16#else
17#include <asm/8253pit.h>
18static DEFINE_SPINLOCK(i8253_lock);
19#endif
20
21#define PCSP_SOUND_VERSION 0x400 /* read 4.00 */
22#define PCSP_DEBUG 0
23
24/* default timer freq for PC-Speaker: 18643 Hz */
25#define DIV_18KHZ 64
26#define MAX_DIV DIV_18KHZ
27#define CUR_DIV() (MAX_DIV >> chip->treble)
28#define PCSP_MAX_TREBLE 1
29
30/* unfortunately, with hrtimers 37KHz does not work very well :( */
31#define PCSP_DEFAULT_TREBLE 0
32#define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE)
33
34/* wild guess */
35#define PCSP_MIN_LPJ 1000000
36#define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1)
37#define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV)
38#define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble))
39#define PCSP_RATE() (PIT_TICK_RATE / CUR_DIV())
40#define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE
41#define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE
42#define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1)
43#define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1)
44#define PCSP_CALC_NS(div) ({ \
45 u64 __val = 1000000000ULL * (div); \
46 do_div(__val, PIT_TICK_RATE); \
47 __val; \
48})
49#define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV())
50
51#define PCSP_MAX_PERIOD_SIZE (64*1024)
52#define PCSP_MAX_PERIODS 512
53#define PCSP_BUFFER_SIZE (128*1024)
54
55struct snd_pcsp {
56 struct snd_card *card;
57 struct snd_pcm *pcm;
58 struct input_dev *input_dev;
59 struct hrtimer timer;
60 unsigned short port, irq, dma;
61 spinlock_t substream_lock;
62 struct snd_pcm_substream *playback_substream;
63 size_t playback_ptr;
64 size_t period_ptr;
65 atomic_t timer_active;
66 int thalf;
67 u64 ns_rem;
68 unsigned char val61;
69 int enable;
70 int max_treble;
71 int treble;
72 int pcspkr;
73};
74
75extern struct snd_pcsp pcsp_chip;
76
77extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
78
79extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
80extern int snd_pcsp_new_mixer(struct snd_pcsp *chip);
81
82#endif
diff --git a/sound/drivers/pcsp/pcsp_input.c b/sound/drivers/pcsp/pcsp_input.c
new file mode 100644
index 000000000000..cd9b83e7f7d1
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_input.c
@@ -0,0 +1,116 @@
1/*
2 * PC Speaker beeper driver for Linux
3 *
4 * Copyright (c) 2002 Vojtech Pavlik
5 * Copyright (c) 1992 Orest Zborowski
6 *
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation
13 */
14
15#include <linux/init.h>
16#include <linux/input.h>
17#include <asm/io.h>
18#include "pcsp.h"
19
20static void pcspkr_do_sound(unsigned int count)
21{
22 unsigned long flags;
23
24 spin_lock_irqsave(&i8253_lock, flags);
25
26 if (count) {
27 /* enable counter 2 */
28 outb_p(inb_p(0x61) | 3, 0x61);
29 /* set command for counter 2, 2 byte write */
30 outb_p(0xB6, 0x43);
31 /* select desired HZ */
32 outb_p(count & 0xff, 0x42);
33 outb((count >> 8) & 0xff, 0x42);
34 } else {
35 /* disable counter 2 */
36 outb(inb_p(0x61) & 0xFC, 0x61);
37 }
38
39 spin_unlock_irqrestore(&i8253_lock, flags);
40}
41
42void pcspkr_stop_sound(void)
43{
44 pcspkr_do_sound(0);
45}
46
47static int pcspkr_input_event(struct input_dev *dev, unsigned int type,
48 unsigned int code, int value)
49{
50 unsigned int count = 0;
51
52 if (atomic_read(&pcsp_chip.timer_active) || !pcsp_chip.pcspkr)
53 return 0;
54
55 switch (type) {
56 case EV_SND:
57 switch (code) {
58 case SND_BELL:
59 if (value)
60 value = 1000;
61 case SND_TONE:
62 break;
63 default:
64 return -1;
65 }
66 break;
67
68 default:
69 return -1;
70 }
71
72 if (value > 20 && value < 32767)
73 count = PIT_TICK_RATE / value;
74
75 pcspkr_do_sound(count);
76
77 return 0;
78}
79
80int __devinit pcspkr_input_init(struct input_dev **rdev, struct device *dev)
81{
82 int err;
83
84 struct input_dev *input_dev = input_allocate_device();
85 if (!input_dev)
86 return -ENOMEM;
87
88 input_dev->name = "PC Speaker";
89 input_dev->phys = "isa0061/input0";
90 input_dev->id.bustype = BUS_ISA;
91 input_dev->id.vendor = 0x001f;
92 input_dev->id.product = 0x0001;
93 input_dev->id.version = 0x0100;
94 input_dev->dev.parent = dev;
95
96 input_dev->evbit[0] = BIT(EV_SND);
97 input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
98 input_dev->event = pcspkr_input_event;
99
100 err = input_register_device(input_dev);
101 if (err) {
102 input_free_device(input_dev);
103 return err;
104 }
105
106 *rdev = input_dev;
107 return 0;
108}
109
110int pcspkr_input_remove(struct input_dev *dev)
111{
112 pcspkr_stop_sound();
113 input_unregister_device(dev); /* this also does kfree() */
114
115 return 0;
116}
diff --git a/sound/drivers/pcsp/pcsp_input.h b/sound/drivers/pcsp/pcsp_input.h
new file mode 100644
index 000000000000..e66738c78333
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_input.h
@@ -0,0 +1,14 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 2001-2008 Stas Sergeev
5 */
6
7#ifndef __PCSP_INPUT_H__
8#define __PCSP_INPUT_H__
9
10int __devinit pcspkr_input_init(struct input_dev **rdev, struct device *dev);
11int pcspkr_input_remove(struct input_dev *dev);
12void pcspkr_stop_sound(void);
13
14#endif
diff --git a/sound/drivers/pcsp/pcsp_lib.c b/sound/drivers/pcsp/pcsp_lib.c
new file mode 100644
index 000000000000..ac6238e93513
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_lib.c
@@ -0,0 +1,338 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1993-1997 Michael Beck
5 * Copyright (C) 1997-2001 David Woodhouse
6 * Copyright (C) 2001-2008 Stas Sergeev
7 */
8
9#include <linux/module.h>
10#include <linux/moduleparam.h>
11#include <sound/pcm.h>
12#include <linux/interrupt.h>
13#include <asm/io.h>
14#include "pcsp.h"
15
16static int nforce_wa;
17module_param(nforce_wa, bool, 0444);
18MODULE_PARM_DESC(nforce_wa, "Apply NForce chipset workaround "
19 "(expect bad sound)");
20
21static void pcsp_start_timer(unsigned long dummy)
22{
23 hrtimer_start(&pcsp_chip.timer, ktime_set(0, 0), HRTIMER_MODE_REL);
24}
25
26/*
27 * We need the hrtimer_start as a tasklet to avoid
28 * the nasty locking problem. :(
29 * The problem:
30 * - The timer handler is called with the cpu_base->lock
31 * already held by hrtimer code.
32 * - snd_pcm_period_elapsed() takes the
33 * substream->self_group.lock.
34 * So far so good.
35 * But the snd_pcsp_trigger() is called with the
36 * substream->self_group.lock held, and it calls
37 * hrtimer_start(), which takes the cpu_base->lock.
38 * You see the problem. We have the code pathes
39 * which take two locks in a reverse order. This
40 * can deadlock and the lock validator complains.
41 * The only solution I could find was to move the
42 * hrtimer_start() into a tasklet. -stsp
43 */
44static DECLARE_TASKLET(pcsp_start_timer_tasklet, pcsp_start_timer, 0);
45
46enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle)
47{
48 unsigned long flags;
49 unsigned char timer_cnt, val;
50 int periods_elapsed;
51 u64 ns;
52 size_t period_bytes, buffer_bytes;
53 struct snd_pcm_substream *substream;
54 struct snd_pcm_runtime *runtime;
55 struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer);
56
57 if (chip->thalf) {
58 outb(chip->val61, 0x61);
59 chip->thalf = 0;
60 if (!atomic_read(&chip->timer_active))
61 return HRTIMER_NORESTART;
62 hrtimer_forward(&chip->timer, chip->timer.expires,
63 ktime_set(0, chip->ns_rem));
64 return HRTIMER_RESTART;
65 }
66
67 /* hrtimer calls us from both hardirq and softirq contexts,
68 * so irqsave :( */
69 spin_lock_irqsave(&chip->substream_lock, flags);
70 /* Takashi Iwai says regarding this extra lock:
71
72 If the irq handler handles some data on the DMA buffer, it should
73 do snd_pcm_stream_lock().
74 That protects basically against all races among PCM callbacks, yes.
75 However, there are two remaining issues:
76 1. The substream pointer you try to lock isn't protected _before_
77 this lock yet.
78 2. snd_pcm_period_elapsed() itself acquires the lock.
79 The requirement of another lock is because of 1. When you get
80 chip->playback_substream, it's not protected.
81 Keeping this lock while snd_pcm_period_elapsed() assures the substream
82 is still protected (at least, not released). And the other status is
83 handled properly inside snd_pcm_stream_lock() in
84 snd_pcm_period_elapsed().
85
86 */
87 if (!chip->playback_substream)
88 goto exit_nr_unlock1;
89 substream = chip->playback_substream;
90 snd_pcm_stream_lock(substream);
91 if (!atomic_read(&chip->timer_active))
92 goto exit_nr_unlock2;
93
94 runtime = substream->runtime;
95 /* assume it is u8 mono */
96 val = runtime->dma_area[chip->playback_ptr];
97 timer_cnt = val * CUR_DIV() / 256;
98
99 if (timer_cnt && chip->enable) {
100 spin_lock(&i8253_lock);
101 if (!nforce_wa) {
102 outb_p(chip->val61, 0x61);
103 outb_p(timer_cnt, 0x42);
104 outb(chip->val61 ^ 1, 0x61);
105 } else {
106 outb(chip->val61 ^ 2, 0x61);
107 chip->thalf = 1;
108 }
109 spin_unlock(&i8253_lock);
110 }
111
112 period_bytes = snd_pcm_lib_period_bytes(substream);
113 buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
114 chip->playback_ptr += PCSP_INDEX_INC();
115 periods_elapsed = chip->playback_ptr - chip->period_ptr;
116 if (periods_elapsed < 0) {
117 printk(KERN_WARNING "PCSP: playback_ptr inconsistent "
118 "(%zi %zi %zi)\n",
119 chip->playback_ptr, period_bytes, buffer_bytes);
120 periods_elapsed += buffer_bytes;
121 }
122 periods_elapsed /= period_bytes;
123 /* wrap the pointer _before_ calling snd_pcm_period_elapsed(),
124 * or ALSA will BUG on us. */
125 chip->playback_ptr %= buffer_bytes;
126
127 snd_pcm_stream_unlock(substream);
128
129 if (periods_elapsed) {
130 snd_pcm_period_elapsed(substream);
131 chip->period_ptr += periods_elapsed * period_bytes;
132 chip->period_ptr %= buffer_bytes;
133 }
134
135 spin_unlock_irqrestore(&chip->substream_lock, flags);
136
137 if (!atomic_read(&chip->timer_active))
138 return HRTIMER_NORESTART;
139
140 chip->ns_rem = PCSP_PERIOD_NS();
141 ns = (chip->thalf ? PCSP_CALC_NS(timer_cnt) : chip->ns_rem);
142 chip->ns_rem -= ns;
143 hrtimer_forward(&chip->timer, chip->timer.expires, ktime_set(0, ns));
144 return HRTIMER_RESTART;
145
146exit_nr_unlock2:
147 snd_pcm_stream_unlock(substream);
148exit_nr_unlock1:
149 spin_unlock_irqrestore(&chip->substream_lock, flags);
150 return HRTIMER_NORESTART;
151}
152
153static void pcsp_start_playing(struct snd_pcsp *chip)
154{
155#if PCSP_DEBUG
156 printk(KERN_INFO "PCSP: start_playing called\n");
157#endif
158 if (atomic_read(&chip->timer_active)) {
159 printk(KERN_ERR "PCSP: Timer already active\n");
160 return;
161 }
162
163 spin_lock(&i8253_lock);
164 chip->val61 = inb(0x61) | 0x03;
165 outb_p(0x92, 0x43); /* binary, mode 1, LSB only, ch 2 */
166 spin_unlock(&i8253_lock);
167 atomic_set(&chip->timer_active, 1);
168 chip->thalf = 0;
169
170 tasklet_schedule(&pcsp_start_timer_tasklet);
171}
172
173static void pcsp_stop_playing(struct snd_pcsp *chip)
174{
175#if PCSP_DEBUG
176 printk(KERN_INFO "PCSP: stop_playing called\n");
177#endif
178 if (!atomic_read(&chip->timer_active))
179 return;
180
181 atomic_set(&chip->timer_active, 0);
182 spin_lock(&i8253_lock);
183 /* restore the timer */
184 outb_p(0xb6, 0x43); /* binary, mode 3, LSB/MSB, ch 2 */
185 outb(chip->val61 & 0xFC, 0x61);
186 spin_unlock(&i8253_lock);
187}
188
189static int snd_pcsp_playback_close(struct snd_pcm_substream *substream)
190{
191 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
192#if PCSP_DEBUG
193 printk(KERN_INFO "PCSP: close called\n");
194#endif
195 if (atomic_read(&chip->timer_active)) {
196 printk(KERN_ERR "PCSP: timer still active\n");
197 pcsp_stop_playing(chip);
198 }
199 spin_lock_irq(&chip->substream_lock);
200 chip->playback_substream = NULL;
201 spin_unlock_irq(&chip->substream_lock);
202 return 0;
203}
204
205static int snd_pcsp_playback_hw_params(struct snd_pcm_substream *substream,
206 struct snd_pcm_hw_params *hw_params)
207{
208 int err;
209 err = snd_pcm_lib_malloc_pages(substream,
210 params_buffer_bytes(hw_params));
211 if (err < 0)
212 return err;
213 return 0;
214}
215
216static int snd_pcsp_playback_hw_free(struct snd_pcm_substream *substream)
217{
218#if PCSP_DEBUG
219 printk(KERN_INFO "PCSP: hw_free called\n");
220#endif
221 return snd_pcm_lib_free_pages(substream);
222}
223
224static int snd_pcsp_playback_prepare(struct snd_pcm_substream *substream)
225{
226 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
227#if PCSP_DEBUG
228 printk(KERN_INFO "PCSP: prepare called, "
229 "size=%zi psize=%zi f=%zi f1=%i\n",
230 snd_pcm_lib_buffer_bytes(substream),
231 snd_pcm_lib_period_bytes(substream),
232 snd_pcm_lib_buffer_bytes(substream) /
233 snd_pcm_lib_period_bytes(substream),
234 substream->runtime->periods);
235#endif
236 chip->playback_ptr = 0;
237 chip->period_ptr = 0;
238 return 0;
239}
240
241static int snd_pcsp_trigger(struct snd_pcm_substream *substream, int cmd)
242{
243 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
244#if PCSP_DEBUG
245 printk(KERN_INFO "PCSP: trigger called\n");
246#endif
247 switch (cmd) {
248 case SNDRV_PCM_TRIGGER_START:
249 case SNDRV_PCM_TRIGGER_RESUME:
250 pcsp_start_playing(chip);
251 break;
252 case SNDRV_PCM_TRIGGER_STOP:
253 case SNDRV_PCM_TRIGGER_SUSPEND:
254 pcsp_stop_playing(chip);
255 break;
256 default:
257 return -EINVAL;
258 }
259 return 0;
260}
261
262static snd_pcm_uframes_t snd_pcsp_playback_pointer(struct snd_pcm_substream
263 *substream)
264{
265 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
266 return bytes_to_frames(substream->runtime, chip->playback_ptr);
267}
268
269static struct snd_pcm_hardware snd_pcsp_playback = {
270 .info = (SNDRV_PCM_INFO_INTERLEAVED |
271 SNDRV_PCM_INFO_HALF_DUPLEX |
272 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
273 .formats = SNDRV_PCM_FMTBIT_U8,
274 .rates = SNDRV_PCM_RATE_KNOT,
275 .rate_min = PCSP_DEFAULT_SRATE,
276 .rate_max = PCSP_DEFAULT_SRATE,
277 .channels_min = 1,
278 .channels_max = 1,
279 .buffer_bytes_max = PCSP_BUFFER_SIZE,
280 .period_bytes_min = 64,
281 .period_bytes_max = PCSP_MAX_PERIOD_SIZE,
282 .periods_min = 2,
283 .periods_max = PCSP_MAX_PERIODS,
284 .fifo_size = 0,
285};
286
287static int snd_pcsp_playback_open(struct snd_pcm_substream *substream)
288{
289 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
290 struct snd_pcm_runtime *runtime = substream->runtime;
291#if PCSP_DEBUG
292 printk(KERN_INFO "PCSP: open called\n");
293#endif
294 if (atomic_read(&chip->timer_active)) {
295 printk(KERN_ERR "PCSP: still active!!\n");
296 return -EBUSY;
297 }
298 runtime->hw = snd_pcsp_playback;
299 spin_lock_irq(&chip->substream_lock);
300 chip->playback_substream = substream;
301 spin_unlock_irq(&chip->substream_lock);
302 return 0;
303}
304
305static struct snd_pcm_ops snd_pcsp_playback_ops = {
306 .open = snd_pcsp_playback_open,
307 .close = snd_pcsp_playback_close,
308 .ioctl = snd_pcm_lib_ioctl,
309 .hw_params = snd_pcsp_playback_hw_params,
310 .hw_free = snd_pcsp_playback_hw_free,
311 .prepare = snd_pcsp_playback_prepare,
312 .trigger = snd_pcsp_trigger,
313 .pointer = snd_pcsp_playback_pointer,
314};
315
316int __devinit snd_pcsp_new_pcm(struct snd_pcsp *chip)
317{
318 int err;
319
320 err = snd_pcm_new(chip->card, "pcspeaker", 0, 1, 0, &chip->pcm);
321 if (err < 0)
322 return err;
323
324 snd_pcm_set_ops(chip->pcm, SNDRV_PCM_STREAM_PLAYBACK,
325 &snd_pcsp_playback_ops);
326
327 chip->pcm->private_data = chip;
328 chip->pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
329 strcpy(chip->pcm->name, "pcsp");
330
331 snd_pcm_lib_preallocate_pages_for_all(chip->pcm,
332 SNDRV_DMA_TYPE_CONTINUOUS,
333 snd_dma_continuous_data
334 (GFP_KERNEL), PCSP_BUFFER_SIZE,
335 PCSP_BUFFER_SIZE);
336
337 return 0;
338}
diff --git a/sound/drivers/pcsp/pcsp_mixer.c b/sound/drivers/pcsp/pcsp_mixer.c
new file mode 100644
index 000000000000..64a695fef74e
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_mixer.c
@@ -0,0 +1,143 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Mixer implementation.
5 * Copyright (C) 2001-2008 Stas Sergeev
6 */
7
8#include <sound/core.h>
9#include <sound/control.h>
10#include "pcsp.h"
11
12
13static int pcsp_enable_info(struct snd_kcontrol *kcontrol,
14 struct snd_ctl_elem_info *uinfo)
15{
16 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
17 uinfo->count = 1;
18 uinfo->value.integer.min = 0;
19 uinfo->value.integer.max = 1;
20 return 0;
21}
22
23static int pcsp_enable_get(struct snd_kcontrol *kcontrol,
24 struct snd_ctl_elem_value *ucontrol)
25{
26 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
27 ucontrol->value.integer.value[0] = chip->enable;
28 return 0;
29}
30
31static int pcsp_enable_put(struct snd_kcontrol *kcontrol,
32 struct snd_ctl_elem_value *ucontrol)
33{
34 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
35 int changed = 0;
36 int enab = ucontrol->value.integer.value[0];
37 if (enab != chip->enable) {
38 chip->enable = enab;
39 changed = 1;
40 }
41 return changed;
42}
43
44static int pcsp_treble_info(struct snd_kcontrol *kcontrol,
45 struct snd_ctl_elem_info *uinfo)
46{
47 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
48 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
49 uinfo->count = 1;
50 uinfo->value.enumerated.items = chip->max_treble + 1;
51 if (uinfo->value.enumerated.item > chip->max_treble)
52 uinfo->value.enumerated.item = chip->max_treble;
53 sprintf(uinfo->value.enumerated.name, "%d", PCSP_RATE());
54 return 0;
55}
56
57static int pcsp_treble_get(struct snd_kcontrol *kcontrol,
58 struct snd_ctl_elem_value *ucontrol)
59{
60 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
61 ucontrol->value.enumerated.item[0] = chip->treble;
62 return 0;
63}
64
65static int pcsp_treble_put(struct snd_kcontrol *kcontrol,
66 struct snd_ctl_elem_value *ucontrol)
67{
68 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
69 int changed = 0;
70 int treble = ucontrol->value.enumerated.item[0];
71 if (treble != chip->treble) {
72 chip->treble = treble;
73#if PCSP_DEBUG
74 printk(KERN_INFO "PCSP: rate set to %i\n", PCSP_RATE());
75#endif
76 changed = 1;
77 }
78 return changed;
79}
80
81static int pcsp_pcspkr_info(struct snd_kcontrol *kcontrol,
82 struct snd_ctl_elem_info *uinfo)
83{
84 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
85 uinfo->count = 1;
86 uinfo->value.integer.min = 0;
87 uinfo->value.integer.max = 1;
88 return 0;
89}
90
91static int pcsp_pcspkr_get(struct snd_kcontrol *kcontrol,
92 struct snd_ctl_elem_value *ucontrol)
93{
94 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
95 ucontrol->value.integer.value[0] = chip->pcspkr;
96 return 0;
97}
98
99static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
100 struct snd_ctl_elem_value *ucontrol)
101{
102 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
103 int changed = 0;
104 int spkr = ucontrol->value.integer.value[0];
105 if (spkr != chip->pcspkr) {
106 chip->pcspkr = spkr;
107 changed = 1;
108 }
109 return changed;
110}
111
112#define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
113{ \
114 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
115 .name = ctl_name, \
116 .info = pcsp_##ctl_type##_info, \
117 .get = pcsp_##ctl_type##_get, \
118 .put = pcsp_##ctl_type##_put, \
119}
120
121static struct snd_kcontrol_new __devinitdata snd_pcsp_controls[] = {
122 PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
123 PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
124 PCSP_MIXER_CONTROL(pcspkr, "PC Speaker Playback Switch"),
125};
126
127int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip)
128{
129 struct snd_card *card = chip->card;
130 int i, err;
131
132 for (i = 0; i < ARRAY_SIZE(snd_pcsp_controls); i++) {
133 err = snd_ctl_add(card,
134 snd_ctl_new1(snd_pcsp_controls + i,
135 chip));
136 if (err < 0)
137 return err;
138 }
139
140 strcpy(card->mixername, "PC-Speaker");
141
142 return 0;
143}
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index 15061bd72776..d20d893b3b60 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -27,6 +27,7 @@
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/ak4114.h> 28#include <sound/ak4114.h>
29#include <sound/asoundef.h> 29#include <sound/asoundef.h>
30#include <sound/info.h>
30 31
31MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 32MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
32MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei"); 33MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei");
@@ -446,6 +447,26 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = {
446} 447}
447}; 448};
448 449
450
451static void snd_ak4114_proc_regs_read(struct snd_info_entry *entry,
452 struct snd_info_buffer *buffer)
453{
454 struct ak4114 *ak4114 = entry->private_data;
455 int reg, val;
456 /* all ak4114 registers 0x00 - 0x1f */
457 for (reg = 0; reg < 0x20; reg++) {
458 val = reg_read(ak4114, reg);
459 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
460 }
461}
462
463static void snd_ak4114_proc_init(struct ak4114 *ak4114)
464{
465 struct snd_info_entry *entry;
466 if (!snd_card_proc_new(ak4114->card, "ak4114", &entry))
467 snd_info_set_text_ops(entry, ak4114, snd_ak4114_proc_regs_read);
468}
469
449int snd_ak4114_build(struct ak4114 *ak4114, 470int snd_ak4114_build(struct ak4114 *ak4114,
450 struct snd_pcm_substream *ply_substream, 471 struct snd_pcm_substream *ply_substream,
451 struct snd_pcm_substream *cap_substream) 472 struct snd_pcm_substream *cap_substream)
@@ -478,6 +499,7 @@ int snd_ak4114_build(struct ak4114 *ak4114,
478 return err; 499 return err;
479 ak4114->kctls[idx] = kctl; 500 ak4114->kctls[idx] = kctl;
480 } 501 }
502 snd_ak4114_proc_init(ak4114);
481 /* trigger workq */ 503 /* trigger workq */
482 schedule_delayed_work(&ak4114->work, HZ / 10); 504 schedule_delayed_work(&ak4114->work, HZ / 10);
483 return 0; 505 return 0;
@@ -590,7 +612,7 @@ static void ak4114_stats(struct work_struct *work)
590 struct ak4114 *chip = container_of(work, struct ak4114, work.work); 612 struct ak4114 *chip = container_of(work, struct ak4114, work.work);
591 613
592 if (!chip->init) 614 if (!chip->init)
593 snd_ak4114_check_rate_and_errors(chip, 0); 615 snd_ak4114_check_rate_and_errors(chip, chip->check_flags);
594 616
595 schedule_delayed_work(&chip->work, HZ / 10); 617 schedule_delayed_work(&chip->work, HZ / 10);
596} 618}
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c
index 35fbbf2cb9fa..288926d2e205 100644
--- a/sound/i2c/other/ak4xxx-adda.c
+++ b/sound/i2c/other/ak4xxx-adda.c
@@ -70,7 +70,8 @@ static void ak4524_reset(struct snd_akm4xxx *ak, int state)
70} 70}
71 71
72/* reset procedure for AK4355 and AK4358 */ 72/* reset procedure for AK4355 and AK4358 */
73static void ak4355_reset(struct snd_akm4xxx *ak, int state) 73static void ak435X_reset(struct snd_akm4xxx *ak, int state,
74 unsigned char total_regs)
74{ 75{
75 unsigned char reg; 76 unsigned char reg;
76 77
@@ -78,7 +79,7 @@ static void ak4355_reset(struct snd_akm4xxx *ak, int state)
78 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */ 79 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
79 return; 80 return;
80 } 81 }
81 for (reg = 0x00; reg < 0x0b; reg++) 82 for (reg = 0x00; reg < total_regs; reg++)
82 if (reg != 0x01) 83 if (reg != 0x01)
83 snd_akm4xxx_write(ak, 0, reg, 84 snd_akm4xxx_write(ak, 0, reg,
84 snd_akm4xxx_get(ak, 0, reg)); 85 snd_akm4xxx_get(ak, 0, reg));
@@ -118,8 +119,10 @@ void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
118 /* FIXME: needed for ak4529? */ 119 /* FIXME: needed for ak4529? */
119 break; 120 break;
120 case SND_AK4355: 121 case SND_AK4355:
122 ak435X_reset(ak, state, 0x0b);
123 break;
121 case SND_AK4358: 124 case SND_AK4358:
122 ak4355_reset(ak, state); 125 ak435X_reset(ak, state, 0x10);
123 break; 126 break;
124 case SND_AK4381: 127 case SND_AK4381:
125 ak4381_reset(ak, state); 128 ak4381_reset(ak, state);
@@ -292,11 +295,6 @@ void snd_akm4xxx_init(struct snd_akm4xxx *ak)
292 case SND_AK5365: 295 case SND_AK5365:
293 /* FIXME: any init sequence? */ 296 /* FIXME: any init sequence? */
294 return; 297 return;
295 case NON_AKM:
296 /* fake value for non-akm codecs using akm infrastructure
297 * (e.g. of ice1724) - certainly FIXME
298 */
299 return;
300 default: 298 default:
301 snd_BUG(); 299 snd_BUG();
302 return; 300 return;
@@ -374,6 +372,8 @@ static int put_ak_reg(struct snd_kcontrol *kcontrol, int addr,
374 nval = mask - nval; 372 nval = mask - nval;
375 if (AK_GET_NEEDSMSB(kcontrol->private_value)) 373 if (AK_GET_NEEDSMSB(kcontrol->private_value))
376 nval |= 0x80; 374 nval |= 0x80;
375 /* printk(KERN_DEBUG "DEBUG - AK writing reg: chip %x addr %x,
376 nval %x\n", chip, addr, nval); */
377 snd_akm4xxx_write(ak, chip, addr, nval); 377 snd_akm4xxx_write(ak, chip, addr, nval);
378 return 1; 378 return 1;
379} 379}
diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c
index bed29ca22239..f3fd7b4f4668 100644
--- a/sound/isa/sb/sb16_csp.c
+++ b/sound/isa/sb/sb16_csp.c
@@ -331,7 +331,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
331 return -EFAULT; 331 return -EFAULT;
332 if ((file_h.name != RIFF_HEADER) || 332 if ((file_h.name != RIFF_HEADER) ||
333 (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) { 333 (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) {
334 snd_printd("%s: Invalid RIFF header\n", __FUNCTION__); 334 snd_printd("%s: Invalid RIFF header\n", __func__);
335 return -EINVAL; 335 return -EINVAL;
336 } 336 }
337 data_ptr += sizeof(file_h); 337 data_ptr += sizeof(file_h);
@@ -340,7 +340,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
340 if (copy_from_user(&item_type, data_ptr, sizeof(item_type))) 340 if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
341 return -EFAULT; 341 return -EFAULT;
342 if (item_type != CSP__HEADER) { 342 if (item_type != CSP__HEADER) {
343 snd_printd("%s: Invalid RIFF file type\n", __FUNCTION__); 343 snd_printd("%s: Invalid RIFF file type\n", __func__);
344 return -EINVAL; 344 return -EINVAL;
345 } 345 }
346 data_ptr += sizeof (item_type); 346 data_ptr += sizeof (item_type);
@@ -395,7 +395,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
395 return -EFAULT; 395 return -EFAULT;
396 396
397 if (code_h.name != MAIN_HEADER) { 397 if (code_h.name != MAIN_HEADER) {
398 snd_printd("%s: Missing 'main' microcode\n", __FUNCTION__); 398 snd_printd("%s: Missing 'main' microcode\n", __func__);
399 return -EINVAL; 399 return -EINVAL;
400 } 400 }
401 data_ptr += sizeof(code_h); 401 data_ptr += sizeof(code_h);
@@ -439,7 +439,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
439 p->acc_format = p->acc_width = p->acc_rates = 0; 439 p->acc_format = p->acc_width = p->acc_rates = 0;
440 p->mode = 0; 440 p->mode = 0;
441 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n", 441 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n",
442 __FUNCTION__, 442 __func__,
443 le16_to_cpu(funcdesc_h.VOC_type)); 443 le16_to_cpu(funcdesc_h.VOC_type));
444 return -EINVAL; 444 return -EINVAL;
445 } 445 }
@@ -458,7 +458,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
458 return 0; 458 return 0;
459 } 459 }
460 } 460 }
461 snd_printd("%s: Function #%d not found\n", __FUNCTION__, info.func_req); 461 snd_printd("%s: Function #%d not found\n", __func__, info.func_req);
462 return -EINVAL; 462 return -EINVAL;
463} 463}
464 464
@@ -612,7 +612,7 @@ static int get_version(struct snd_sb *chip)
612static int snd_sb_csp_check_version(struct snd_sb_csp * p) 612static int snd_sb_csp_check_version(struct snd_sb_csp * p)
613{ 613{
614 if (p->version < 0x10 || p->version > 0x1f) { 614 if (p->version < 0x10 || p->version > 0x1f) {
615 snd_printd("%s: Invalid CSP version: 0x%x\n", __FUNCTION__, p->version); 615 snd_printd("%s: Invalid CSP version: 0x%x\n", __func__, p->version);
616 return 1; 616 return 1;
617 } 617 }
618 return 0; 618 return 0;
@@ -631,7 +631,7 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int
631 spin_lock_irqsave(&p->chip->reg_lock, flags); 631 spin_lock_irqsave(&p->chip->reg_lock, flags);
632 snd_sbdsp_command(p->chip, 0x01); /* CSP download command */ 632 snd_sbdsp_command(p->chip, 0x01); /* CSP download command */
633 if (snd_sbdsp_get_byte(p->chip)) { 633 if (snd_sbdsp_get_byte(p->chip)) {
634 snd_printd("%s: Download command failed\n", __FUNCTION__); 634 snd_printd("%s: Download command failed\n", __func__);
635 goto __fail; 635 goto __fail;
636 } 636 }
637 /* Send CSP low byte (size - 1) */ 637 /* Send CSP low byte (size - 1) */
@@ -658,7 +658,7 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int
658 udelay (10); 658 udelay (10);
659 } 659 }
660 if (status != 0x55) { 660 if (status != 0x55) {
661 snd_printd("%s: Microcode initialization failed\n", __FUNCTION__); 661 snd_printd("%s: Microcode initialization failed\n", __func__);
662 goto __fail; 662 goto __fail;
663 } 663 }
664 } else { 664 } else {
@@ -824,19 +824,19 @@ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channel
824 unsigned long flags; 824 unsigned long flags;
825 825
826 if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) { 826 if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) {
827 snd_printd("%s: Microcode not loaded\n", __FUNCTION__); 827 snd_printd("%s: Microcode not loaded\n", __func__);
828 return -ENXIO; 828 return -ENXIO;
829 } 829 }
830 if (p->running & SNDRV_SB_CSP_ST_RUNNING) { 830 if (p->running & SNDRV_SB_CSP_ST_RUNNING) {
831 snd_printd("%s: CSP already running\n", __FUNCTION__); 831 snd_printd("%s: CSP already running\n", __func__);
832 return -EBUSY; 832 return -EBUSY;
833 } 833 }
834 if (!(sample_width & p->acc_width)) { 834 if (!(sample_width & p->acc_width)) {
835 snd_printd("%s: Unsupported PCM sample width\n", __FUNCTION__); 835 snd_printd("%s: Unsupported PCM sample width\n", __func__);
836 return -EINVAL; 836 return -EINVAL;
837 } 837 }
838 if (!(channels & p->acc_channels)) { 838 if (!(channels & p->acc_channels)) {
839 snd_printd("%s: Invalid number of channels\n", __FUNCTION__); 839 snd_printd("%s: Invalid number of channels\n", __func__);
840 return -EINVAL; 840 return -EINVAL;
841 } 841 }
842 842
@@ -858,11 +858,11 @@ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channel
858 s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */ 858 s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */
859 859
860 if (set_codec_parameter(p->chip, 0x81, s_type)) { 860 if (set_codec_parameter(p->chip, 0x81, s_type)) {
861 snd_printd("%s: Set sample type command failed\n", __FUNCTION__); 861 snd_printd("%s: Set sample type command failed\n", __func__);
862 goto __fail; 862 goto __fail;
863 } 863 }
864 if (set_codec_parameter(p->chip, 0x80, 0x00)) { 864 if (set_codec_parameter(p->chip, 0x80, 0x00)) {
865 snd_printd("%s: Codec start command failed\n", __FUNCTION__); 865 snd_printd("%s: Codec start command failed\n", __func__);
866 goto __fail; 866 goto __fail;
867 } 867 }
868 p->run_width = sample_width; 868 p->run_width = sample_width;
diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c
index d63c1af550de..b432d9ae874b 100644
--- a/sound/isa/sb/sb_common.c
+++ b/sound/isa/sb/sb_common.c
@@ -51,7 +51,7 @@ int snd_sbdsp_command(struct snd_sb *chip, unsigned char val)
51 outb(val, SBP(chip, COMMAND)); 51 outb(val, SBP(chip, COMMAND));
52 return 1; 52 return 1;
53 } 53 }
54 snd_printd("%s [0x%lx]: timeout (0x%x)\n", __FUNCTION__, chip->port, val); 54 snd_printd("%s [0x%lx]: timeout (0x%x)\n", __func__, chip->port, val);
55 return 0; 55 return 0;
56} 56}
57 57
@@ -68,7 +68,7 @@ int snd_sbdsp_get_byte(struct snd_sb *chip)
68 return val; 68 return val;
69 } 69 }
70 } 70 }
71 snd_printd("%s [0x%lx]: timeout\n", __FUNCTION__, chip->port); 71 snd_printd("%s [0x%lx]: timeout\n", __func__, chip->port);
72 return -ENODEV; 72 return -ENODEV;
73} 73}
74 74
@@ -87,7 +87,7 @@ int snd_sbdsp_reset(struct snd_sb *chip)
87 else 87 else
88 break; 88 break;
89 } 89 }
90 snd_printdd("%s [0x%lx] failed...\n", __FUNCTION__, chip->port); 90 snd_printdd("%s [0x%lx] failed...\n", __func__, chip->port);
91 return -ENODEV; 91 return -ENODEV;
92} 92}
93 93
diff --git a/sound/oss/dmabuf.c b/sound/oss/dmabuf.c
index eaf69971bf92..1e90d769b62e 100644
--- a/sound/oss/dmabuf.c
+++ b/sound/oss/dmabuf.c
@@ -795,9 +795,9 @@ static int find_output_space(int dev, char **buf, int *size)
795#ifdef BE_CONSERVATIVE 795#ifdef BE_CONSERVATIVE
796 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size; 796 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size;
797#else 797#else
798 active_offs = DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT); 798 active_offs = max(DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT), 0);
799 /* Check for pointer wrapping situation */ 799 /* Check for pointer wrapping situation */
800 if (active_offs < 0 || active_offs >= dmap->bytes_in_use) 800 if (active_offs >= dmap->bytes_in_use)
801 active_offs = 0; 801 active_offs = 0;
802 active_offs += dmap->byte_counter; 802 active_offs += dmap->byte_counter;
803#endif 803#endif
diff --git a/sound/oss/trident.c b/sound/oss/trident.c
index d6af9065d1c0..f43f91ef86c7 100644
--- a/sound/oss/trident.c
+++ b/sound/oss/trident.c
@@ -3076,8 +3076,7 @@ ali_ac97_get(struct trident_card *card, int secondary, u8 reg)
3076 u16 wcontrol; 3076 u16 wcontrol;
3077 unsigned long flags; 3077 unsigned long flags;
3078 3078
3079 if (!card) 3079 BUG_ON(!card);
3080 BUG();
3081 3080
3082 address = ALI_AC97_READ; 3081 address = ALI_AC97_READ;
3083 if (card->revision == ALI_5451_V02) { 3082 if (card->revision == ALI_5451_V02) {
@@ -3148,8 +3147,7 @@ ali_ac97_set(struct trident_card *card, int secondary, u8 reg, u16 val)
3148 3147
3149 data = ((u32) val) << 16; 3148 data = ((u32) val) << 16;
3150 3149
3151 if (!card) 3150 BUG_ON(!card);
3152 BUG();
3153 3151
3154 address = ALI_AC97_WRITE; 3152 address = ALI_AC97_WRITE;
3155 mask = ALI_AC97_WRITE_ACTION | ALI_AC97_AUDIO_BUSY; 3153 mask = ALI_AC97_WRITE_ACTION | ALI_AC97_AUDIO_BUSY;
@@ -3213,8 +3211,7 @@ ali_ac97_read(struct ac97_codec *codec, u8 reg)
3213 struct trident_card *card = NULL; 3211 struct trident_card *card = NULL;
3214 3212
3215 /* Added by Matt Wu */ 3213 /* Added by Matt Wu */
3216 if (!codec) 3214 BUG_ON(!codec);
3217 BUG();
3218 3215
3219 card = (struct trident_card *) codec->private_data; 3216 card = (struct trident_card *) codec->private_data;
3220 3217
@@ -3240,8 +3237,7 @@ ali_ac97_write(struct ac97_codec *codec, u8 reg, u16 val)
3240 struct trident_card *card; 3237 struct trident_card *card;
3241 3238
3242 /* Added by Matt Wu */ 3239 /* Added by Matt Wu */
3243 if (!codec) 3240 BUG_ON(!codec);
3244 BUG();
3245 3241
3246 card = (struct trident_card *) codec->private_data; 3242 card = (struct trident_card *) codec->private_data;
3247 3243
diff --git a/sound/oss/trident.h b/sound/oss/trident.h
index 4713b49fc91d..ff30a1d7c2f1 100644
--- a/sound/oss/trident.h
+++ b/sound/oss/trident.h
@@ -322,7 +322,7 @@ enum miscint_bits {
322#define VALIDATE_MAGIC(FOO,MAG) \ 322#define VALIDATE_MAGIC(FOO,MAG) \
323({ \ 323({ \
324 if (!(FOO) || (FOO)->magic != MAG) { \ 324 if (!(FOO) || (FOO)->magic != MAG) { \
325 printk(invalid_magic,__FUNCTION__); \ 325 printk(invalid_magic,__func__); \
326 return -ENXIO; \ 326 return -ENXIO; \
327 } \ 327 } \
328}) 328})
diff --git a/sound/oss/vwsnd.c b/sound/oss/vwsnd.c
index d25249a932bf..2c5aaa58046d 100644
--- a/sound/oss/vwsnd.c
+++ b/sound/oss/vwsnd.c
@@ -194,11 +194,11 @@ static void dbgassert(const char *fcn, int line, const char *expr)
194 * DBGRV - debug print function return when verbose 194 * DBGRV - debug print function return when verbose
195 */ 195 */
196 196
197#define ASSERT(e) ((e) ? (void) 0 : dbgassert(__FUNCTION__, __LINE__, #e)) 197#define ASSERT(e) ((e) ? (void) 0 : dbgassert(__func__, __LINE__, #e))
198#define DBGDO(x) x 198#define DBGDO(x) x
199#define DBGX(fmt, args...) (in_interrupt() ? 0 : printk(KERN_ERR fmt, ##args)) 199#define DBGX(fmt, args...) (in_interrupt() ? 0 : printk(KERN_ERR fmt, ##args))
200#define DBGP(fmt, args...) (DBGX("%s: " fmt, __FUNCTION__ , ##args)) 200#define DBGP(fmt, args...) (DBGX("%s: " fmt, __func__ , ##args))
201#define DBGE(fmt, args...) (DBGX("%s" fmt, __FUNCTION__ , ##args)) 201#define DBGE(fmt, args...) (DBGX("%s" fmt, __func__ , ##args))
202#define DBGC(rtn) (DBGP("calling %s\n", rtn)) 202#define DBGC(rtn) (DBGP("calling %s\n", rtn))
203#define DBGR() (DBGP("returning\n")) 203#define DBGR() (DBGP("returning\n"))
204#define DBGXV(fmt, args...) (shut_up ? 0 : DBGX(fmt, ##args)) 204#define DBGXV(fmt, args...) (shut_up ? 0 : DBGX(fmt, ##args))
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 812085d521f1..581debf37dcb 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -122,6 +122,21 @@ config SND_AU8830
122 To compile this driver as a module, choose M here: the module 122 To compile this driver as a module, choose M here: the module
123 will be called snd-au8830. 123 will be called snd-au8830.
124 124
125config SND_AW2
126 tristate "Emagic Audiowerk 2"
127 depends on SND
128 help
129 Say Y here to include support for Emagic Audiowerk 2 soundcards.
130
131 Supported features: Analog and SPDIF output. Analog or SPDIF input.
132 Note: Switch between analog and digital input does not always work.
133 It can produce continuous noise. The workaround is to switch again
134 (and again) between digital and analog input until it works.
135
136 To compile this driver as a module, choose M here: the module
137 will be called snd-aw2.
138
139
125config SND_AZT3328 140config SND_AZT3328
126 tristate "Aztech AZF3328 / PCI168 (EXPERIMENTAL)" 141 tristate "Aztech AZF3328 / PCI168 (EXPERIMENTAL)"
127 depends on SND && EXPERIMENTAL 142 depends on SND && EXPERIMENTAL
@@ -162,6 +177,7 @@ config SND_CA0106
162 depends on SND 177 depends on SND
163 select SND_AC97_CODEC 178 select SND_AC97_CODEC
164 select SND_RAWMIDI 179 select SND_RAWMIDI
180 select SND_VMASTER
165 help 181 help
166 Say Y here to include support for the Sound Blaster Audigy LS 182 Say Y here to include support for the Sound Blaster Audigy LS
167 and Live 24bit. 183 and Live 24bit.
@@ -517,6 +533,7 @@ config SND_HDA_INTEL
517 tristate "Intel HD Audio" 533 tristate "Intel HD Audio"
518 depends on SND 534 depends on SND
519 select SND_PCM 535 select SND_PCM
536 select SND_VMASTER
520 help 537 help
521 Say Y here to include support for Intel "High Definition 538 Say Y here to include support for Intel "High Definition
522 Audio" (Azalia) motherboard devices. 539 Audio" (Azalia) motherboard devices.
@@ -680,6 +697,7 @@ config SND_ICE1724
680 depends on SND 697 depends on SND
681 select SND_MPU401_UART 698 select SND_MPU401_UART
682 select SND_AC97_CODEC 699 select SND_AC97_CODEC
700 select SND_VMASTER
683 help 701 help
684 Say Y here to include support for soundcards based on 702 Say Y here to include support for soundcards based on
685 ICE/VT1724/1720 (Envy24HT/PT) chips. 703 ICE/VT1724/1720 (Envy24HT/PT) chips.
@@ -896,12 +914,12 @@ config SND_VIA82XX_MODEM
896 will be called snd-via82xx-modem. 914 will be called snd-via82xx-modem.
897 915
898config SND_VIRTUOSO 916config SND_VIRTUOSO
899 tristate "Asus Virtuoso 200 (Xonar)" 917 tristate "Asus Virtuoso 100/200 (Xonar)"
900 depends on SND 918 depends on SND
901 select SND_OXYGEN_LIB 919 select SND_OXYGEN_LIB
902 help 920 help
903 Say Y here to include support for sound cards based on the 921 Say Y here to include support for sound cards based on the
904 Asus AV200 chip, i.e., Xonar D2 and Xonar D2X. 922 Asus AV100/AV200 chips, i.e., Xonar D2, DX and D2X.
905 923
906 To compile this driver as a module, choose M here: the module 924 To compile this driver as a module, choose M here: the module
907 will be called snd-virtuoso. 925 will be called snd-virtuoso.
diff --git a/sound/pci/Makefile b/sound/pci/Makefile
index 2d42fd28f4e7..85ef14bc8056 100644
--- a/sound/pci/Makefile
+++ b/sound/pci/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_SND) += \
58 ac97/ \ 58 ac97/ \
59 ali5451/ \ 59 ali5451/ \
60 au88x0/ \ 60 au88x0/ \
61 aw2/ \
61 ca0106/ \ 62 ca0106/ \
62 cs46xx/ \ 63 cs46xx/ \
63 cs5535audio/ \ 64 cs5535audio/ \
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 50c637e55ffa..39198e505b12 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -114,10 +114,9 @@ static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd
114 114
115static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 115static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
116{ 116{
117 static const char *texts[] = { "2ch", "4ch", "6ch" }; 117 static const char *texts[] = { "2ch", "4ch", "6ch", "8ch" };
118 if (kcontrol->private_value) 118 return ac97_enum_text_info(kcontrol, uinfo, texts,
119 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */ 119 kcontrol->private_value);
120 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
121} 120}
122 121
123static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 122static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -133,13 +132,8 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
133 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 132 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
134 unsigned char mode = ucontrol->value.enumerated.item[0]; 133 unsigned char mode = ucontrol->value.enumerated.item[0];
135 134
136 if (kcontrol->private_value) { 135 if (mode >= kcontrol->private_value)
137 if (mode >= 2) 136 return -EINVAL;
138 return -EINVAL;
139 } else {
140 if (mode >= 3)
141 return -EINVAL;
142 }
143 137
144 if (mode != ac97->channel_mode) { 138 if (mode != ac97->channel_mode) {
145 ac97->channel_mode = mode; 139 ac97->channel_mode = mode;
@@ -158,6 +152,7 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
158 .get = ac97_surround_jack_mode_get, \ 152 .get = ac97_surround_jack_mode_get, \
159 .put = ac97_surround_jack_mode_put, \ 153 .put = ac97_surround_jack_mode_put, \
160 } 154 }
155/* 6ch */
161#define AC97_CHANNEL_MODE_CTL \ 156#define AC97_CHANNEL_MODE_CTL \
162 { \ 157 { \
163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -165,7 +160,9 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
165 .info = ac97_channel_mode_info, \ 160 .info = ac97_channel_mode_info, \
166 .get = ac97_channel_mode_get, \ 161 .get = ac97_channel_mode_get, \
167 .put = ac97_channel_mode_put, \ 162 .put = ac97_channel_mode_put, \
163 .private_value = 3, \
168 } 164 }
165/* 4ch */
169#define AC97_CHANNEL_MODE_4CH_CTL \ 166#define AC97_CHANNEL_MODE_4CH_CTL \
170 { \ 167 { \
171 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -173,7 +170,17 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
173 .info = ac97_channel_mode_info, \ 170 .info = ac97_channel_mode_info, \
174 .get = ac97_channel_mode_get, \ 171 .get = ac97_channel_mode_get, \
175 .put = ac97_channel_mode_put, \ 172 .put = ac97_channel_mode_put, \
176 .private_value = 1, \ 173 .private_value = 2, \
174 }
175/* 8ch */
176#define AC97_CHANNEL_MODE_8CH_CTL \
177 { \
178 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
179 .name = "Channel Mode", \
180 .info = ac97_channel_mode_info, \
181 .get = ac97_channel_mode_get, \
182 .put = ac97_channel_mode_put, \
183 .private_value = 4, \
177 } 184 }
178 185
179static inline int is_surround_on(struct snd_ac97 *ac97) 186static inline int is_surround_on(struct snd_ac97 *ac97)
@@ -210,6 +217,10 @@ static inline int is_shared_micin(struct snd_ac97 *ac97)
210 return !ac97->indep_surround && !is_clfe_on(ac97); 217 return !ac97->indep_surround && !is_clfe_on(ac97);
211} 218}
212 219
220static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
221{
222 return is_surround_on(ac97);
223}
213 224
214/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */ 225/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
215/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */ 226/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
@@ -2816,10 +2827,12 @@ static int patch_alc655(struct snd_ac97 * ac97)
2816 2827
2817#define AC97_ALC850_JACK_SELECT 0x76 2828#define AC97_ALC850_JACK_SELECT 0x76
2818#define AC97_ALC850_MISC1 0x7a 2829#define AC97_ALC850_MISC1 0x7a
2830#define AC97_ALC850_MULTICH 0x6a
2819 2831
2820static void alc850_update_jacks(struct snd_ac97 *ac97) 2832static void alc850_update_jacks(struct snd_ac97 *ac97)
2821{ 2833{
2822 int shared; 2834 int shared;
2835 int aux_is_back_surround;
2823 2836
2824 /* shared Line-In / Surround Out */ 2837 /* shared Line-In / Surround Out */
2825 shared = is_shared_surrout(ac97); 2838 shared = is_shared_surrout(ac97);
@@ -2837,13 +2850,18 @@ static void alc850_update_jacks(struct snd_ac97 *ac97)
2837 /* MIC-IN = 1, CENTER-LFE = 5 */ 2850 /* MIC-IN = 1, CENTER-LFE = 5 */
2838 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, 2851 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2839 shared ? (5<<4) : (1<<4)); 2852 shared ? (5<<4) : (1<<4));
2853
2854 aux_is_back_surround = alc850_is_aux_back_surround(ac97);
2855 /* Aux is Back Surround */
2856 snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
2857 aux_is_back_surround ? (1<<10) : (0<<10));
2840} 2858}
2841 2859
2842static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { 2860static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
2843 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2861 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2844 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), 2862 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2845 AC97_SURROUND_JACK_MODE_CTL, 2863 AC97_SURROUND_JACK_MODE_CTL,
2846 AC97_CHANNEL_MODE_CTL, 2864 AC97_CHANNEL_MODE_8CH_CTL,
2847}; 2865};
2848 2866
2849static int patch_alc850_specific(struct snd_ac97 *ac97) 2867static int patch_alc850_specific(struct snd_ac97 *ac97)
@@ -2869,6 +2887,7 @@ static int patch_alc850(struct snd_ac97 *ac97)
2869 ac97->build_ops = &patch_alc850_ops; 2887 ac97->build_ops = &patch_alc850_ops;
2870 2888
2871 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ 2889 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2890 ac97->flags |= AC97_HAS_8CH;
2872 2891
2873 /* assume only page 0 for writing cache */ 2892 /* assume only page 0 for writing cache */
2874 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 2893 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
@@ -2878,6 +2897,7 @@ static int patch_alc850(struct snd_ac97 *ac97)
2878 spdif-in monitor off, spdif-in PCM off 2897 spdif-in monitor off, spdif-in PCM off
2879 center on mic off, surround on line-in off 2898 center on mic off, surround on line-in off
2880 duplicate front off 2899 duplicate front off
2900 NB default bit 10=0 = Aux is Capture, not Back Surround
2881 */ 2901 */
2882 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 2902 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2883 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off 2903 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c
index 3674f35c4a79..48cbda9378c5 100644
--- a/sound/pci/ac97/ac97_pcm.c
+++ b/sound/pci/ac97/ac97_pcm.c
@@ -574,7 +574,6 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
574 r = rate > 48000; 574 r = rate > 48000;
575 bus = pcm->bus; 575 bus = pcm->bus;
576 if (cfg == AC97_PCM_CFG_SPDIF) { 576 if (cfg == AC97_PCM_CFG_SPDIF) {
577 int err;
578 for (cidx = 0; cidx < 4; cidx++) 577 for (cidx = 0; cidx < 4; cidx++)
579 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) { 578 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) {
580 err = set_spdif_rate(bus->codec[cidx], rate); 579 err = set_spdif_rate(bus->codec[cidx], rate);
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index a66d5150bb7a..39ec55b57b1e 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -264,10 +264,10 @@ snd_ad1889_ac97_ready(struct snd_ad1889 *chip)
264 mdelay(1); 264 mdelay(1);
265 if (!retry) { 265 if (!retry) {
266 snd_printk(KERN_ERR PFX "[%s] Link is not ready.\n", 266 snd_printk(KERN_ERR PFX "[%s] Link is not ready.\n",
267 __FUNCTION__); 267 __func__);
268 return -EIO; 268 return -EIO;
269 } 269 }
270 ad1889_debug("[%s] ready after %d ms\n", __FUNCTION__, 400 - retry); 270 ad1889_debug("[%s] ready after %d ms\n", __func__, 400 - retry);
271 271
272 return 0; 272 return 0;
273} 273}
@@ -854,8 +854,6 @@ snd_ad1889_free(struct snd_ad1889 *chip)
854 854
855 spin_unlock_irq(&chip->lock); 855 spin_unlock_irq(&chip->lock);
856 856
857 synchronize_irq(chip->irq);
858
859 if (chip->irq >= 0) 857 if (chip->irq >= 0)
860 free_irq(chip->irq, chip); 858 free_irq(chip->irq, chip);
861 859
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index 6a905ed9cbd6..1a0fd65ec280 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -1809,26 +1809,26 @@ static int snd_ali5451_spdif_get(struct snd_kcontrol *kcontrol,
1809 struct snd_ctl_elem_value *ucontrol) 1809 struct snd_ctl_elem_value *ucontrol)
1810{ 1810{
1811 struct snd_ali *codec = kcontrol->private_data; 1811 struct snd_ali *codec = kcontrol->private_data;
1812 unsigned int enable; 1812 unsigned int spdif_enable;
1813 1813
1814 enable = ucontrol->value.integer.value[0] ? 1 : 0; 1814 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0;
1815 1815
1816 spin_lock_irq(&codec->reg_lock); 1816 spin_lock_irq(&codec->reg_lock);
1817 switch (kcontrol->private_value) { 1817 switch (kcontrol->private_value) {
1818 case 0: 1818 case 0:
1819 enable = (codec->spdif_mask & 0x02) ? 1 : 0; 1819 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0;
1820 break; 1820 break;
1821 case 1: 1821 case 1:
1822 enable = ((codec->spdif_mask & 0x02) && 1822 spdif_enable = ((codec->spdif_mask & 0x02) &&
1823 (codec->spdif_mask & 0x04)) ? 1 : 0; 1823 (codec->spdif_mask & 0x04)) ? 1 : 0;
1824 break; 1824 break;
1825 case 2: 1825 case 2:
1826 enable = (codec->spdif_mask & 0x01) ? 1 : 0; 1826 spdif_enable = (codec->spdif_mask & 0x01) ? 1 : 0;
1827 break; 1827 break;
1828 default: 1828 default:
1829 break; 1829 break;
1830 } 1830 }
1831 ucontrol->value.integer.value[0] = enable; 1831 ucontrol->value.integer.value[0] = spdif_enable;
1832 spin_unlock_irq(&codec->reg_lock); 1832 spin_unlock_irq(&codec->reg_lock);
1833 return 0; 1833 return 0;
1834} 1834}
@@ -1837,17 +1837,17 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1837 struct snd_ctl_elem_value *ucontrol) 1837 struct snd_ctl_elem_value *ucontrol)
1838{ 1838{
1839 struct snd_ali *codec = kcontrol->private_data; 1839 struct snd_ali *codec = kcontrol->private_data;
1840 unsigned int change = 0, enable = 0; 1840 unsigned int change = 0, spdif_enable = 0;
1841 1841
1842 enable = ucontrol->value.integer.value[0] ? 1 : 0; 1842 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0;
1843 1843
1844 spin_lock_irq(&codec->reg_lock); 1844 spin_lock_irq(&codec->reg_lock);
1845 switch (kcontrol->private_value) { 1845 switch (kcontrol->private_value) {
1846 case 0: 1846 case 0:
1847 change = (codec->spdif_mask & 0x02) ? 1 : 0; 1847 change = (codec->spdif_mask & 0x02) ? 1 : 0;
1848 change = change ^ enable; 1848 change = change ^ spdif_enable;
1849 if (change) { 1849 if (change) {
1850 if (enable) { 1850 if (spdif_enable) {
1851 codec->spdif_mask |= 0x02; 1851 codec->spdif_mask |= 0x02;
1852 snd_ali_enable_spdif_out(codec); 1852 snd_ali_enable_spdif_out(codec);
1853 } else { 1853 } else {
@@ -1859,9 +1859,9 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1859 break; 1859 break;
1860 case 1: 1860 case 1:
1861 change = (codec->spdif_mask & 0x04) ? 1 : 0; 1861 change = (codec->spdif_mask & 0x04) ? 1 : 0;
1862 change = change ^ enable; 1862 change = change ^ spdif_enable;
1863 if (change && (codec->spdif_mask & 0x02)) { 1863 if (change && (codec->spdif_mask & 0x02)) {
1864 if (enable) { 1864 if (spdif_enable) {
1865 codec->spdif_mask |= 0x04; 1865 codec->spdif_mask |= 0x04;
1866 snd_ali_enable_spdif_chnout(codec); 1866 snd_ali_enable_spdif_chnout(codec);
1867 } else { 1867 } else {
@@ -1872,9 +1872,9 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1872 break; 1872 break;
1873 case 2: 1873 case 2:
1874 change = (codec->spdif_mask & 0x01) ? 1 : 0; 1874 change = (codec->spdif_mask & 0x01) ? 1 : 0;
1875 change = change ^ enable; 1875 change = change ^ spdif_enable;
1876 if (change) { 1876 if (change) {
1877 if (enable) { 1877 if (spdif_enable) {
1878 codec->spdif_mask |= 0x01; 1878 codec->spdif_mask |= 0x01;
1879 snd_ali_enable_spdif_in(codec); 1879 snd_ali_enable_spdif_in(codec);
1880 } else { 1880 } else {
@@ -2047,10 +2047,8 @@ static int snd_ali_free(struct snd_ali * codec)
2047{ 2047{
2048 if (codec->hw_initialized) 2048 if (codec->hw_initialized)
2049 snd_ali_disable_address_interrupt(codec); 2049 snd_ali_disable_address_interrupt(codec);
2050 if (codec->irq >= 0) { 2050 if (codec->irq >= 0)
2051 synchronize_irq(codec->irq);
2052 free_irq(codec->irq, codec); 2051 free_irq(codec->irq, codec);
2053 }
2054 if (codec->port) 2052 if (codec->port)
2055 pci_release_regions(codec->pci); 2053 pci_release_regions(codec->pci);
2056 pci_disable_device(codec->pci); 2054 pci_disable_device(codec->pci);
diff --git a/sound/pci/als300.c b/sound/pci/als300.c
index 0e990a735821..8df6824b51cd 100644
--- a/sound/pci/als300.c
+++ b/sound/pci/als300.c
@@ -92,8 +92,8 @@
92 92
93#if DEBUG_CALLS 93#if DEBUG_CALLS
94#define snd_als300_dbgcalls(format, args...) printk(format, ##args) 94#define snd_als300_dbgcalls(format, args...) printk(format, ##args)
95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__) 95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__) 96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
97#else 97#else
98#define snd_als300_dbgcalls(format, args...) 98#define snd_als300_dbgcalls(format, args...)
99#define snd_als300_dbgcallenter() 99#define snd_als300_dbgcallenter()
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 4594186b83ee..457228fb22aa 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -1553,7 +1553,7 @@ static int snd_atiixp_free(struct atiixp *chip)
1553 if (chip->irq < 0) 1553 if (chip->irq < 0)
1554 goto __hw_end; 1554 goto __hw_end;
1555 snd_atiixp_chip_stop(chip); 1555 snd_atiixp_chip_stop(chip);
1556 synchronize_irq(chip->irq); 1556
1557 __hw_end: 1557 __hw_end:
1558 if (chip->irq >= 0) 1558 if (chip->irq >= 0)
1559 free_irq(chip->irq, chip); 1559 free_irq(chip->irq, chip);
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index a67a869180d4..d457a32a7939 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -1197,7 +1197,7 @@ static int snd_atiixp_free(struct atiixp_modem *chip)
1197 if (chip->irq < 0) 1197 if (chip->irq < 0)
1198 goto __hw_end; 1198 goto __hw_end;
1199 snd_atiixp_chip_stop(chip); 1199 snd_atiixp_chip_stop(chip);
1200 synchronize_irq(chip->irq); 1200
1201 __hw_end: 1201 __hw_end:
1202 if (chip->irq >= 0) 1202 if (chip->irq >= 0)
1203 free_irq(chip->irq, chip); 1203 free_irq(chip->irq, chip);
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index 26819e2f5761..68368e490074 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -126,7 +126,6 @@ static int snd_vortex_dev_free(struct snd_device *device)
126 vortex_gameport_unregister(vortex); 126 vortex_gameport_unregister(vortex);
127 vortex_core_shutdown(vortex); 127 vortex_core_shutdown(vortex);
128 // Take down PCI interface. 128 // Take down PCI interface.
129 synchronize_irq(vortex->irq);
130 free_irq(vortex->irq, vortex); 129 free_irq(vortex->irq, vortex);
131 iounmap(vortex->mmio); 130 iounmap(vortex->mmio);
132 pci_release_regions(vortex->pci_dev); 131 pci_release_regions(vortex->pci_dev);
@@ -220,7 +219,6 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
220 return 0; 219 return 0;
221 220
222 alloc_out: 221 alloc_out:
223 synchronize_irq(chip->irq);
224 free_irq(chip->irq, chip); 222 free_irq(chip->irq, chip);
225 irq_out: 223 irq_out:
226 vortex_core_shutdown(chip); 224 vortex_core_shutdown(chip);
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index 526c6c5ecf7b..f9a58b4a30eb 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -498,14 +498,14 @@ static struct snd_kcontrol_new snd_vortex_mixer_spdif[] __devinitdata = {
498}; 498};
499 499
500/* create a pcm device */ 500/* create a pcm device */
501static int __devinit snd_vortex_new_pcm(vortex_t * chip, int idx, int nr) 501static int __devinit snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
502{ 502{
503 struct snd_pcm *pcm; 503 struct snd_pcm *pcm;
504 struct snd_kcontrol *kctl; 504 struct snd_kcontrol *kctl;
505 int i; 505 int i;
506 int err, nr_capt; 506 int err, nr_capt;
507 507
508 if ((chip == 0) || (idx < 0) || (idx >= VORTEX_PCM_LAST)) 508 if (!chip || idx < 0 || idx >= VORTEX_PCM_LAST)
509 return -ENODEV; 509 return -ENODEV;
510 510
511 /* idx indicates which kind of PCM device. ADB, SPDIF, I2S and A3D share the 511 /* idx indicates which kind of PCM device. ADB, SPDIF, I2S and A3D share the
@@ -514,9 +514,9 @@ static int __devinit snd_vortex_new_pcm(vortex_t * chip, int idx, int nr)
514 nr_capt = nr; 514 nr_capt = nr;
515 else 515 else
516 nr_capt = 0; 516 nr_capt = 0;
517 if ((err = 517 err = snd_pcm_new(chip->card, vortex_pcm_prettyname[idx], idx, nr,
518 snd_pcm_new(chip->card, vortex_pcm_prettyname[idx], idx, nr, 518 nr_capt, &pcm);
519 nr_capt, &pcm)) < 0) 519 if (err < 0)
520 return err; 520 return err;
521 strcpy(pcm->name, vortex_pcm_name[idx]); 521 strcpy(pcm->name, vortex_pcm_name[idx]);
522 chip->pcm[idx] = pcm; 522 chip->pcm[idx] = pcm;
diff --git a/sound/pci/aw2/Makefile b/sound/pci/aw2/Makefile
new file mode 100644
index 000000000000..842335d3b735
--- /dev/null
+++ b/sound/pci/aw2/Makefile
@@ -0,0 +1,3 @@
1snd-aw2-objs := aw2-alsa.o aw2-saa7146.o
2
3obj-$(CONFIG_SND_AW2) += snd-aw2.o
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c
new file mode 100644
index 000000000000..56f87cd33c19
--- /dev/null
+++ b/sound/pci/aw2/aw2-alsa.c
@@ -0,0 +1,794 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23#include <linux/init.h>
24#include <linux/pci.h>
25#include <linux/dma-mapping.h>
26#include <linux/slab.h>
27#include <linux/interrupt.h>
28#include <linux/delay.h>
29#include <asm/io.h>
30#include <sound/core.h>
31#include <sound/initval.h>
32#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/control.h>
35
36#include "saa7146.h"
37#include "aw2-saa7146.h"
38
39MODULE_AUTHOR("Cedric Bregardis <cedric.bregardis@free.fr>, "
40 "Jean-Christian Hassler <jhassler@free.fr>");
41MODULE_DESCRIPTION("Emagic Audiowerk 2 sound driver");
42MODULE_LICENSE("GPL");
43
44/*********************************
45 * DEFINES
46 ********************************/
47#define PCI_VENDOR_ID_SAA7146 0x1131
48#define PCI_DEVICE_ID_SAA7146 0x7146
49
50#define CTL_ROUTE_ANALOG 0
51#define CTL_ROUTE_DIGITAL 1
52
53/*********************************
54 * TYPEDEFS
55 ********************************/
56 /* hardware definition */
57static struct snd_pcm_hardware snd_aw2_playback_hw = {
58 .info = (SNDRV_PCM_INFO_MMAP |
59 SNDRV_PCM_INFO_INTERLEAVED |
60 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
61 .formats = SNDRV_PCM_FMTBIT_S16_LE,
62 .rates = SNDRV_PCM_RATE_44100,
63 .rate_min = 44100,
64 .rate_max = 44100,
65 .channels_min = 2,
66 .channels_max = 4,
67 .buffer_bytes_max = 32768,
68 .period_bytes_min = 4096,
69 .period_bytes_max = 32768,
70 .periods_min = 1,
71 .periods_max = 1024,
72};
73
74static struct snd_pcm_hardware snd_aw2_capture_hw = {
75 .info = (SNDRV_PCM_INFO_MMAP |
76 SNDRV_PCM_INFO_INTERLEAVED |
77 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
78 .formats = SNDRV_PCM_FMTBIT_S16_LE,
79 .rates = SNDRV_PCM_RATE_44100,
80 .rate_min = 44100,
81 .rate_max = 44100,
82 .channels_min = 2,
83 .channels_max = 2,
84 .buffer_bytes_max = 32768,
85 .period_bytes_min = 4096,
86 .period_bytes_max = 32768,
87 .periods_min = 1,
88 .periods_max = 1024,
89};
90
91struct aw2_pcm_device {
92 struct snd_pcm *pcm;
93 unsigned int stream_number;
94 struct aw2 *chip;
95};
96
97struct aw2 {
98 struct snd_aw2_saa7146 saa7146;
99
100 struct pci_dev *pci;
101 int irq;
102 spinlock_t reg_lock;
103 struct mutex mtx;
104
105 unsigned long iobase_phys;
106 void __iomem *iobase_virt;
107
108 struct snd_card *card;
109
110 struct aw2_pcm_device device_playback[NB_STREAM_PLAYBACK];
111 struct aw2_pcm_device device_capture[NB_STREAM_CAPTURE];
112};
113
114/*********************************
115 * FUNCTION DECLARATIONS
116 ********************************/
117static int __init alsa_card_aw2_init(void);
118static void __exit alsa_card_aw2_exit(void);
119static int snd_aw2_dev_free(struct snd_device *device);
120static int __devinit snd_aw2_create(struct snd_card *card,
121 struct pci_dev *pci, struct aw2 **rchip);
122static int __devinit snd_aw2_probe(struct pci_dev *pci,
123 const struct pci_device_id *pci_id);
124static void __devexit snd_aw2_remove(struct pci_dev *pci);
125static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream);
126static int snd_aw2_pcm_playback_close(struct snd_pcm_substream *substream);
127static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream);
128static int snd_aw2_pcm_capture_close(struct snd_pcm_substream *substream);
129static int snd_aw2_pcm_hw_params(struct snd_pcm_substream *substream,
130 struct snd_pcm_hw_params *hw_params);
131static int snd_aw2_pcm_hw_free(struct snd_pcm_substream *substream);
132static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream);
133static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream);
134static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream,
135 int cmd);
136static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream,
137 int cmd);
138static snd_pcm_uframes_t snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
139 *substream);
140static snd_pcm_uframes_t snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
141 *substream);
142static int __devinit snd_aw2_new_pcm(struct aw2 *chip);
143
144static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
145 struct snd_ctl_elem_info *uinfo);
146static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
147 struct snd_ctl_elem_value
148 *ucontrol);
149static int snd_aw2_control_switch_capture_put(struct snd_kcontrol *kcontrol,
150 struct snd_ctl_elem_value
151 *ucontrol);
152
153/*********************************
154 * VARIABLES
155 ********************************/
156static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
157static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
158static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
159
160module_param_array(index, int, NULL, 0444);
161MODULE_PARM_DESC(index, "Index value for Audiowerk2 soundcard.");
162module_param_array(id, charp, NULL, 0444);
163MODULE_PARM_DESC(id, "ID string for the Audiowerk2 soundcard.");
164module_param_array(enable, bool, NULL, 0444);
165MODULE_PARM_DESC(enable, "Enable Audiowerk2 soundcard.");
166
167static struct pci_device_id snd_aw2_ids[] = {
168 {PCI_VENDOR_ID_SAA7146, PCI_DEVICE_ID_SAA7146, PCI_ANY_ID, PCI_ANY_ID,
169 0, 0, 0},
170 {0}
171};
172
173MODULE_DEVICE_TABLE(pci, snd_aw2_ids);
174
175/* pci_driver definition */
176static struct pci_driver driver = {
177 .name = "Emagic Audiowerk 2",
178 .id_table = snd_aw2_ids,
179 .probe = snd_aw2_probe,
180 .remove = __devexit_p(snd_aw2_remove),
181};
182
183/* operators for playback PCM alsa interface */
184static struct snd_pcm_ops snd_aw2_playback_ops = {
185 .open = snd_aw2_pcm_playback_open,
186 .close = snd_aw2_pcm_playback_close,
187 .ioctl = snd_pcm_lib_ioctl,
188 .hw_params = snd_aw2_pcm_hw_params,
189 .hw_free = snd_aw2_pcm_hw_free,
190 .prepare = snd_aw2_pcm_prepare_playback,
191 .trigger = snd_aw2_pcm_trigger_playback,
192 .pointer = snd_aw2_pcm_pointer_playback,
193};
194
195/* operators for capture PCM alsa interface */
196static struct snd_pcm_ops snd_aw2_capture_ops = {
197 .open = snd_aw2_pcm_capture_open,
198 .close = snd_aw2_pcm_capture_close,
199 .ioctl = snd_pcm_lib_ioctl,
200 .hw_params = snd_aw2_pcm_hw_params,
201 .hw_free = snd_aw2_pcm_hw_free,
202 .prepare = snd_aw2_pcm_prepare_capture,
203 .trigger = snd_aw2_pcm_trigger_capture,
204 .pointer = snd_aw2_pcm_pointer_capture,
205};
206
207static struct snd_kcontrol_new aw2_control __devinitdata = {
208 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
209 .name = "PCM Capture Route",
210 .index = 0,
211 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
212 .private_value = 0xffff,
213 .info = snd_aw2_control_switch_capture_info,
214 .get = snd_aw2_control_switch_capture_get,
215 .put = snd_aw2_control_switch_capture_put
216};
217
218/*********************************
219 * FUNCTION IMPLEMENTATIONS
220 ********************************/
221
222/* initialization of the module */
223static int __init alsa_card_aw2_init(void)
224{
225 snd_printdd(KERN_DEBUG "aw2: Load aw2 module\n");
226 return pci_register_driver(&driver);
227}
228
229/* clean up the module */
230static void __exit alsa_card_aw2_exit(void)
231{
232 snd_printdd(KERN_DEBUG "aw2: Unload aw2 module\n");
233 pci_unregister_driver(&driver);
234}
235
236module_init(alsa_card_aw2_init);
237module_exit(alsa_card_aw2_exit);
238
239/* component-destructor */
240static int snd_aw2_dev_free(struct snd_device *device)
241{
242 struct aw2 *chip = device->device_data;
243
244 /* Free hardware */
245 snd_aw2_saa7146_free(&chip->saa7146);
246
247 /* release the irq */
248 if (chip->irq >= 0)
249 free_irq(chip->irq, (void *)chip);
250 /* release the i/o ports & memory */
251 if (chip->iobase_virt)
252 iounmap(chip->iobase_virt);
253
254 pci_release_regions(chip->pci);
255 /* disable the PCI entry */
256 pci_disable_device(chip->pci);
257 /* release the data */
258 kfree(chip);
259
260 return 0;
261}
262
263/* chip-specific constructor */
264static int __devinit snd_aw2_create(struct snd_card *card,
265 struct pci_dev *pci, struct aw2 **rchip)
266{
267 struct aw2 *chip;
268 int err;
269 static struct snd_device_ops ops = {
270 .dev_free = snd_aw2_dev_free,
271 };
272
273 *rchip = NULL;
274
275 /* initialize the PCI entry */
276 err = pci_enable_device(pci);
277 if (err < 0)
278 return err;
279 pci_set_master(pci);
280
281 /* check PCI availability (32bit DMA) */
282 if ((pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0) ||
283 (pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0)) {
284 printk(KERN_ERR "aw2: Impossible to set 32bit mask DMA\n");
285 pci_disable_device(pci);
286 return -ENXIO;
287 }
288 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
289 if (chip == NULL) {
290 pci_disable_device(pci);
291 return -ENOMEM;
292 }
293
294 /* initialize the stuff */
295 chip->card = card;
296 chip->pci = pci;
297 chip->irq = -1;
298
299 /* (1) PCI resource allocation */
300 err = pci_request_regions(pci, "Audiowerk2");
301 if (err < 0) {
302 pci_disable_device(pci);
303 kfree(chip);
304 return err;
305 }
306 chip->iobase_phys = pci_resource_start(pci, 0);
307 chip->iobase_virt =
308 ioremap_nocache(chip->iobase_phys,
309 pci_resource_len(pci, 0));
310
311 if (chip->iobase_virt == NULL) {
312 printk(KERN_ERR "aw2: unable to remap memory region");
313 pci_release_regions(pci);
314 pci_disable_device(pci);
315 kfree(chip);
316 return -ENOMEM;
317 }
318
319
320 if (request_irq(pci->irq, snd_aw2_saa7146_interrupt,
321 IRQF_SHARED, "Audiowerk2", chip)) {
322 printk(KERN_ERR "aw2: Cannot grab irq %d\n", pci->irq);
323
324 iounmap(chip->iobase_virt);
325 pci_release_regions(chip->pci);
326 pci_disable_device(chip->pci);
327 kfree(chip);
328 return -EBUSY;
329 }
330 chip->irq = pci->irq;
331
332 /* (2) initialization of the chip hardware */
333 snd_aw2_saa7146_setup(&chip->saa7146, chip->iobase_virt);
334 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
335 if (err < 0) {
336 free_irq(chip->irq, (void *)chip);
337 iounmap(chip->iobase_virt);
338 pci_release_regions(chip->pci);
339 pci_disable_device(chip->pci);
340 kfree(chip);
341 return err;
342 }
343
344 snd_card_set_dev(card, &pci->dev);
345 *rchip = chip;
346
347 printk(KERN_INFO
348 "Audiowerk 2 sound card (saa7146 chipset) detected and "
349 "managed\n");
350 return 0;
351}
352
353/* constructor */
354static int __devinit snd_aw2_probe(struct pci_dev *pci,
355 const struct pci_device_id *pci_id)
356{
357 static int dev;
358 struct snd_card *card;
359 struct aw2 *chip;
360 int err;
361
362 /* (1) Continue if device is not enabled, else inc dev */
363 if (dev >= SNDRV_CARDS)
364 return -ENODEV;
365 if (!enable[dev]) {
366 dev++;
367 return -ENOENT;
368 }
369
370 /* (2) Create card instance */
371 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
372 if (card == NULL)
373 return -ENOMEM;
374
375 /* (3) Create main component */
376 err = snd_aw2_create(card, pci, &chip);
377 if (err < 0) {
378 snd_card_free(card);
379 return err;
380 }
381
382 /* initialize mutex */
383 mutex_init(&chip->mtx);
384 /* init spinlock */
385 spin_lock_init(&chip->reg_lock);
386 /* (4) Define driver ID and name string */
387 strcpy(card->driver, "aw2");
388 strcpy(card->shortname, "Audiowerk2");
389
390 sprintf(card->longname, "%s with SAA7146 irq %i",
391 card->shortname, chip->irq);
392
393 /* (5) Create other components */
394 snd_aw2_new_pcm(chip);
395
396 /* (6) Register card instance */
397 err = snd_card_register(card);
398 if (err < 0) {
399 snd_card_free(card);
400 return err;
401 }
402
403 /* (7) Set PCI driver data */
404 pci_set_drvdata(pci, card);
405
406 dev++;
407 return 0;
408}
409
410/* destructor */
411static void __devexit snd_aw2_remove(struct pci_dev *pci)
412{
413 snd_card_free(pci_get_drvdata(pci));
414 pci_set_drvdata(pci, NULL);
415}
416
417/* open callback */
418static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream)
419{
420 struct snd_pcm_runtime *runtime = substream->runtime;
421
422 snd_printdd(KERN_DEBUG "aw2: Playback_open \n");
423 runtime->hw = snd_aw2_playback_hw;
424 return 0;
425}
426
427/* close callback */
428static int snd_aw2_pcm_playback_close(struct snd_pcm_substream *substream)
429{
430 return 0;
431
432}
433
434static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream)
435{
436 struct snd_pcm_runtime *runtime = substream->runtime;
437
438 snd_printdd(KERN_DEBUG "aw2: Capture_open \n");
439 runtime->hw = snd_aw2_capture_hw;
440 return 0;
441}
442
443/* close callback */
444static int snd_aw2_pcm_capture_close(struct snd_pcm_substream *substream)
445{
446 /* TODO: something to do ? */
447 return 0;
448}
449
450 /* hw_params callback */
451static int snd_aw2_pcm_hw_params(struct snd_pcm_substream *substream,
452 struct snd_pcm_hw_params *hw_params)
453{
454 return snd_pcm_lib_malloc_pages(substream,
455 params_buffer_bytes(hw_params));
456}
457
458/* hw_free callback */
459static int snd_aw2_pcm_hw_free(struct snd_pcm_substream *substream)
460{
461 return snd_pcm_lib_free_pages(substream);
462}
463
464/* prepare callback for playback */
465static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream)
466{
467 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
468 struct aw2 *chip = pcm_device->chip;
469 struct snd_pcm_runtime *runtime = substream->runtime;
470 unsigned long period_size, buffer_size;
471
472 mutex_lock(&chip->mtx);
473
474 period_size = snd_pcm_lib_period_bytes(substream);
475 buffer_size = snd_pcm_lib_buffer_bytes(substream);
476
477 snd_aw2_saa7146_pcm_init_playback(&chip->saa7146,
478 pcm_device->stream_number,
479 runtime->dma_addr, period_size,
480 buffer_size);
481
482 /* Define Interrupt callback */
483 snd_aw2_saa7146_define_it_playback_callback(pcm_device->stream_number,
484 (snd_aw2_saa7146_it_cb)
485 snd_pcm_period_elapsed,
486 (void *)substream);
487
488 mutex_unlock(&chip->mtx);
489
490 return 0;
491}
492
493/* prepare callback for capture */
494static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream)
495{
496 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
497 struct aw2 *chip = pcm_device->chip;
498 struct snd_pcm_runtime *runtime = substream->runtime;
499 unsigned long period_size, buffer_size;
500
501 mutex_lock(&chip->mtx);
502
503 period_size = snd_pcm_lib_period_bytes(substream);
504 buffer_size = snd_pcm_lib_buffer_bytes(substream);
505
506 snd_aw2_saa7146_pcm_init_capture(&chip->saa7146,
507 pcm_device->stream_number,
508 runtime->dma_addr, period_size,
509 buffer_size);
510
511 /* Define Interrupt callback */
512 snd_aw2_saa7146_define_it_capture_callback(pcm_device->stream_number,
513 (snd_aw2_saa7146_it_cb)
514 snd_pcm_period_elapsed,
515 (void *)substream);
516
517 mutex_unlock(&chip->mtx);
518
519 return 0;
520}
521
522/* playback trigger callback */
523static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream,
524 int cmd)
525{
526 int status = 0;
527 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
528 struct aw2 *chip = pcm_device->chip;
529 spin_lock(&chip->reg_lock);
530 switch (cmd) {
531 case SNDRV_PCM_TRIGGER_START:
532 snd_aw2_saa7146_pcm_trigger_start_playback(&chip->saa7146,
533 pcm_device->
534 stream_number);
535 break;
536 case SNDRV_PCM_TRIGGER_STOP:
537 snd_aw2_saa7146_pcm_trigger_stop_playback(&chip->saa7146,
538 pcm_device->
539 stream_number);
540 break;
541 default:
542 status = -EINVAL;
543 }
544 spin_unlock(&chip->reg_lock);
545 return status;
546}
547
548/* capture trigger callback */
549static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream,
550 int cmd)
551{
552 int status = 0;
553 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
554 struct aw2 *chip = pcm_device->chip;
555 spin_lock(&chip->reg_lock);
556 switch (cmd) {
557 case SNDRV_PCM_TRIGGER_START:
558 snd_aw2_saa7146_pcm_trigger_start_capture(&chip->saa7146,
559 pcm_device->
560 stream_number);
561 break;
562 case SNDRV_PCM_TRIGGER_STOP:
563 snd_aw2_saa7146_pcm_trigger_stop_capture(&chip->saa7146,
564 pcm_device->
565 stream_number);
566 break;
567 default:
568 status = -EINVAL;
569 }
570 spin_unlock(&chip->reg_lock);
571 return status;
572}
573
574/* playback pointer callback */
575static snd_pcm_uframes_t snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
576 *substream)
577{
578 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
579 struct aw2 *chip = pcm_device->chip;
580 unsigned int current_ptr;
581
582 /* get the current hardware pointer */
583 struct snd_pcm_runtime *runtime = substream->runtime;
584 current_ptr =
585 snd_aw2_saa7146_get_hw_ptr_playback(&chip->saa7146,
586 pcm_device->stream_number,
587 runtime->dma_area,
588 runtime->buffer_size);
589
590 return bytes_to_frames(substream->runtime, current_ptr);
591}
592
593/* capture pointer callback */
594static snd_pcm_uframes_t snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
595 *substream)
596{
597 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
598 struct aw2 *chip = pcm_device->chip;
599 unsigned int current_ptr;
600
601 /* get the current hardware pointer */
602 struct snd_pcm_runtime *runtime = substream->runtime;
603 current_ptr =
604 snd_aw2_saa7146_get_hw_ptr_capture(&chip->saa7146,
605 pcm_device->stream_number,
606 runtime->dma_area,
607 runtime->buffer_size);
608
609 return bytes_to_frames(substream->runtime, current_ptr);
610}
611
612/* create a pcm device */
613static int __devinit snd_aw2_new_pcm(struct aw2 *chip)
614{
615 struct snd_pcm *pcm_playback_ana;
616 struct snd_pcm *pcm_playback_num;
617 struct snd_pcm *pcm_capture;
618 struct aw2_pcm_device *pcm_device;
619 int err = 0;
620
621 /* Create new Alsa PCM device */
622
623 err = snd_pcm_new(chip->card, "Audiowerk2 analog playback", 0, 1, 0,
624 &pcm_playback_ana);
625 if (err < 0) {
626 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
627 return err;
628 }
629
630 /* Creation ok */
631 pcm_device = &chip->device_playback[NUM_STREAM_PLAYBACK_ANA];
632
633 /* Set PCM device name */
634 strcpy(pcm_playback_ana->name, "Analog playback");
635 /* Associate private data to PCM device */
636 pcm_playback_ana->private_data = pcm_device;
637 /* set operators of PCM device */
638 snd_pcm_set_ops(pcm_playback_ana, SNDRV_PCM_STREAM_PLAYBACK,
639 &snd_aw2_playback_ops);
640 /* store PCM device */
641 pcm_device->pcm = pcm_playback_ana;
642 /* give base chip pointer to our internal pcm device
643 structure */
644 pcm_device->chip = chip;
645 /* Give stream number to PCM device */
646 pcm_device->stream_number = NUM_STREAM_PLAYBACK_ANA;
647
648 /* pre-allocation of buffers */
649 /* Preallocate continuous pages. */
650 err = snd_pcm_lib_preallocate_pages_for_all(pcm_playback_ana,
651 SNDRV_DMA_TYPE_DEV,
652 snd_dma_pci_data
653 (chip->pci),
654 64 * 1024, 64 * 1024);
655 if (err)
656 printk(KERN_ERR "aw2: snd_pcm_lib_preallocate_pages_for_all "
657 "error (0x%X)\n", err);
658
659 err = snd_pcm_new(chip->card, "Audiowerk2 digital playback", 1, 1, 0,
660 &pcm_playback_num);
661
662 if (err < 0) {
663 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
664 return err;
665 }
666 /* Creation ok */
667 pcm_device = &chip->device_playback[NUM_STREAM_PLAYBACK_DIG];
668
669 /* Set PCM device name */
670 strcpy(pcm_playback_num->name, "Digital playback");
671 /* Associate private data to PCM device */
672 pcm_playback_num->private_data = pcm_device;
673 /* set operators of PCM device */
674 snd_pcm_set_ops(pcm_playback_num, SNDRV_PCM_STREAM_PLAYBACK,
675 &snd_aw2_playback_ops);
676 /* store PCM device */
677 pcm_device->pcm = pcm_playback_num;
678 /* give base chip pointer to our internal pcm device
679 structure */
680 pcm_device->chip = chip;
681 /* Give stream number to PCM device */
682 pcm_device->stream_number = NUM_STREAM_PLAYBACK_DIG;
683
684 /* pre-allocation of buffers */
685 /* Preallocate continuous pages. */
686 err = snd_pcm_lib_preallocate_pages_for_all(pcm_playback_num,
687 SNDRV_DMA_TYPE_DEV,
688 snd_dma_pci_data
689 (chip->pci),
690 64 * 1024, 64 * 1024);
691 if (err)
692 printk(KERN_ERR
693 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
694 "(0x%X)\n", err);
695
696
697
698 err = snd_pcm_new(chip->card, "Audiowerk2 capture", 2, 0, 1,
699 &pcm_capture);
700
701 if (err < 0) {
702 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
703 return err;
704 }
705
706 /* Creation ok */
707 pcm_device = &chip->device_capture[NUM_STREAM_CAPTURE_ANA];
708
709 /* Set PCM device name */
710 strcpy(pcm_capture->name, "Capture");
711 /* Associate private data to PCM device */
712 pcm_capture->private_data = pcm_device;
713 /* set operators of PCM device */
714 snd_pcm_set_ops(pcm_capture, SNDRV_PCM_STREAM_CAPTURE,
715 &snd_aw2_capture_ops);
716 /* store PCM device */
717 pcm_device->pcm = pcm_capture;
718 /* give base chip pointer to our internal pcm device
719 structure */
720 pcm_device->chip = chip;
721 /* Give stream number to PCM device */
722 pcm_device->stream_number = NUM_STREAM_CAPTURE_ANA;
723
724 /* pre-allocation of buffers */
725 /* Preallocate continuous pages. */
726 err = snd_pcm_lib_preallocate_pages_for_all(pcm_capture,
727 SNDRV_DMA_TYPE_DEV,
728 snd_dma_pci_data
729 (chip->pci),
730 64 * 1024, 64 * 1024);
731 if (err)
732 printk(KERN_ERR
733 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
734 "(0x%X)\n", err);
735
736
737 /* Create control */
738 err = snd_ctl_add(chip->card, snd_ctl_new1(&aw2_control, chip));
739 if (err < 0) {
740 printk(KERN_ERR "aw2: snd_ctl_add error (0x%X)\n", err);
741 return err;
742 }
743
744 return 0;
745}
746
747static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
748 struct snd_ctl_elem_info *uinfo)
749{
750 static char *texts[2] = {
751 "Analog", "Digital"
752 };
753 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
754 uinfo->count = 1;
755 uinfo->value.enumerated.items = 2;
756 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) {
757 uinfo->value.enumerated.item =
758 uinfo->value.enumerated.items - 1;
759 }
760 strcpy(uinfo->value.enumerated.name,
761 texts[uinfo->value.enumerated.item]);
762 return 0;
763}
764
765static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_value
767 *ucontrol)
768{
769 struct aw2 *chip = snd_kcontrol_chip(kcontrol);
770 if (snd_aw2_saa7146_is_using_digital_input(&chip->saa7146))
771 ucontrol->value.enumerated.item[0] = CTL_ROUTE_DIGITAL;
772 else
773 ucontrol->value.enumerated.item[0] = CTL_ROUTE_ANALOG;
774 return 0;
775}
776
777static int snd_aw2_control_switch_capture_put(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_value
779 *ucontrol)
780{
781 struct aw2 *chip = snd_kcontrol_chip(kcontrol);
782 int changed = 0;
783 int is_disgital =
784 snd_aw2_saa7146_is_using_digital_input(&chip->saa7146);
785
786 if (((ucontrol->value.integer.value[0] == CTL_ROUTE_DIGITAL)
787 && !is_disgital)
788 || ((ucontrol->value.integer.value[0] == CTL_ROUTE_ANALOG)
789 && is_disgital)) {
790 snd_aw2_saa7146_use_digital_input(&chip->saa7146, !is_disgital);
791 changed = 1;
792 }
793 return changed;
794}
diff --git a/sound/pci/aw2/aw2-saa7146.c b/sound/pci/aw2/aw2-saa7146.c
new file mode 100644
index 000000000000..6a3891ab69dd
--- /dev/null
+++ b/sound/pci/aw2/aw2-saa7146.c
@@ -0,0 +1,465 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24#define AW2_SAA7146_M
25
26#include <linux/init.h>
27#include <linux/pci.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31#include <asm/system.h>
32#include <asm/io.h>
33#include <sound/core.h>
34#include <sound/initval.h>
35#include <sound/pcm.h>
36#include <sound/pcm_params.h>
37
38#include "saa7146.h"
39#include "aw2-saa7146.h"
40
41#include "aw2-tsl.c"
42
43#define WRITEREG(value, addr) writel((value), chip->base_addr + (addr))
44#define READREG(addr) readl(chip->base_addr + (addr))
45
46static struct snd_aw2_saa7146_cb_param
47 arr_substream_it_playback_cb[NB_STREAM_PLAYBACK];
48static struct snd_aw2_saa7146_cb_param
49 arr_substream_it_capture_cb[NB_STREAM_CAPTURE];
50
51static int snd_aw2_saa7146_get_limit(int size);
52
53/* chip-specific destructor */
54int snd_aw2_saa7146_free(struct snd_aw2_saa7146 *chip)
55{
56 /* disable all irqs */
57 WRITEREG(0, IER);
58
59 /* reset saa7146 */
60 WRITEREG((MRST_N << 16), MC1);
61
62 /* Unset base addr */
63 chip->base_addr = NULL;
64
65 return 0;
66}
67
68void snd_aw2_saa7146_setup(struct snd_aw2_saa7146 *chip,
69 void __iomem *pci_base_addr)
70{
71 /* set PCI burst/threshold
72
73 Burst length definition
74 VALUE BURST LENGTH
75 000 1 Dword
76 001 2 Dwords
77 010 4 Dwords
78 011 8 Dwords
79 100 16 Dwords
80 101 32 Dwords
81 110 64 Dwords
82 111 128 Dwords
83
84 Threshold definition
85 VALUE WRITE MODE READ MODE
86 00 1 Dword of valid data 1 empty Dword
87 01 4 Dwords of valid data 4 empty Dwords
88 10 8 Dwords of valid data 8 empty Dwords
89 11 16 Dwords of valid data 16 empty Dwords */
90
91 unsigned int acon2;
92 unsigned int acon1 = 0;
93 int i;
94
95 /* Set base addr */
96 chip->base_addr = pci_base_addr;
97
98 /* disable all irqs */
99 WRITEREG(0, IER);
100
101 /* reset saa7146 */
102 WRITEREG((MRST_N << 16), MC1);
103
104 /* enable audio interface */
105#ifdef __BIG_ENDIAN
106 acon1 |= A1_SWAP;
107 acon1 |= A2_SWAP;
108#endif
109 /* WS0_CTRL, WS0_SYNC: input TSL1, I2S */
110
111 /* At initialization WS1 and WS2 are disbaled (configured as input */
112 acon1 |= 0 * WS1_CTRL;
113 acon1 |= 0 * WS2_CTRL;
114
115 /* WS4 is not used. So it must not restart A2.
116 This is why it is configured as output (force to low) */
117 acon1 |= 3 * WS4_CTRL;
118
119 /* WS3_CTRL, WS3_SYNC: output TSL2, I2S */
120 acon1 |= 2 * WS3_CTRL;
121
122 /* A1 and A2 are active and asynchronous */
123 acon1 |= 3 * AUDIO_MODE;
124 WRITEREG(acon1, ACON1);
125
126 /* The following comes from original windows driver.
127 It is needed to have a correct behavior of input and output
128 simultenously, but I don't know why ! */
129 WRITEREG(3 * (BurstA1_in) + 3 * (ThreshA1_in) +
130 3 * (BurstA1_out) + 3 * (ThreshA1_out) +
131 3 * (BurstA2_out) + 3 * (ThreshA2_out), PCI_BT_A);
132
133 /* enable audio port pins */
134 WRITEREG((EAP << 16) | EAP, MC1);
135
136 /* enable I2C */
137 WRITEREG((EI2C << 16) | EI2C, MC1);
138 /* enable interrupts */
139 WRITEREG(A1_out | A2_out | A1_in | IIC_S | IIC_E, IER);
140
141 /* audio configuration */
142 acon2 = A2_CLKSRC | BCLK1_OEN;
143 WRITEREG(acon2, ACON2);
144
145 /* By default use analog input */
146 snd_aw2_saa7146_use_digital_input(chip, 0);
147
148 /* TSL setup */
149 for (i = 0; i < 8; ++i) {
150 WRITEREG(tsl1[i], TSL1 + (i * 4));
151 WRITEREG(tsl2[i], TSL2 + (i * 4));
152 }
153
154}
155
156void snd_aw2_saa7146_pcm_init_playback(struct snd_aw2_saa7146 *chip,
157 int stream_number,
158 unsigned long dma_addr,
159 unsigned long period_size,
160 unsigned long buffer_size)
161{
162 unsigned long dw_page, dw_limit;
163
164 /* Configure DMA for substream
165 Configuration informations: ALSA has allocated continuous memory
166 pages. So we don't need to use MMU of saa7146.
167 */
168
169 /* No MMU -> nothing to do with PageA1, we only configure the limit of
170 PageAx_out register */
171 /* Disable MMU */
172 dw_page = (0L << 11);
173
174 /* Configure Limit for DMA access.
175 The limit register defines an address limit, which generates
176 an interrupt if passed by the actual PCI address pointer.
177 '0001' means an interrupt will be generated if the lower
178 6 bits (64 bytes) of the PCI address are zero. '0010'
179 defines a limit of 128 bytes, '0011' one of 256 bytes, and
180 so on up to 1 Mbyte defined by '1111'. This interrupt range
181 can be calculated as follows:
182 Range = 2^(5 + Limit) bytes.
183 */
184 dw_limit = snd_aw2_saa7146_get_limit(period_size);
185 dw_page |= (dw_limit << 4);
186
187 if (stream_number == 0) {
188 WRITEREG(dw_page, PageA2_out);
189
190 /* Base address for DMA transfert. */
191 /* This address has been reserved by ALSA. */
192 /* This is a physical address */
193 WRITEREG(dma_addr, BaseA2_out);
194
195 /* Define upper limit for DMA access */
196 WRITEREG(dma_addr + buffer_size, ProtA2_out);
197
198 } else if (stream_number == 1) {
199 WRITEREG(dw_page, PageA1_out);
200
201 /* Base address for DMA transfert. */
202 /* This address has been reserved by ALSA. */
203 /* This is a physical address */
204 WRITEREG(dma_addr, BaseA1_out);
205
206 /* Define upper limit for DMA access */
207 WRITEREG(dma_addr + buffer_size, ProtA1_out);
208 } else {
209 printk(KERN_ERR
210 "aw2: snd_aw2_saa7146_pcm_init_playback: "
211 "Substream number is not 0 or 1 -> not managed\n");
212 }
213}
214
215void snd_aw2_saa7146_pcm_init_capture(struct snd_aw2_saa7146 *chip,
216 int stream_number, unsigned long dma_addr,
217 unsigned long period_size,
218 unsigned long buffer_size)
219{
220 unsigned long dw_page, dw_limit;
221
222 /* Configure DMA for substream
223 Configuration informations: ALSA has allocated continuous memory
224 pages. So we don't need to use MMU of saa7146.
225 */
226
227 /* No MMU -> nothing to do with PageA1, we only configure the limit of
228 PageAx_out register */
229 /* Disable MMU */
230 dw_page = (0L << 11);
231
232 /* Configure Limit for DMA access.
233 The limit register defines an address limit, which generates
234 an interrupt if passed by the actual PCI address pointer.
235 '0001' means an interrupt will be generated if the lower
236 6 bits (64 bytes) of the PCI address are zero. '0010'
237 defines a limit of 128 bytes, '0011' one of 256 bytes, and
238 so on up to 1 Mbyte defined by '1111'. This interrupt range
239 can be calculated as follows:
240 Range = 2^(5 + Limit) bytes.
241 */
242 dw_limit = snd_aw2_saa7146_get_limit(period_size);
243 dw_page |= (dw_limit << 4);
244
245 if (stream_number == 0) {
246 WRITEREG(dw_page, PageA1_in);
247
248 /* Base address for DMA transfert. */
249 /* This address has been reserved by ALSA. */
250 /* This is a physical address */
251 WRITEREG(dma_addr, BaseA1_in);
252
253 /* Define upper limit for DMA access */
254 WRITEREG(dma_addr + buffer_size, ProtA1_in);
255 } else {
256 printk(KERN_ERR
257 "aw2: snd_aw2_saa7146_pcm_init_capture: "
258 "Substream number is not 0 -> not managed\n");
259 }
260}
261
262void snd_aw2_saa7146_define_it_playback_callback(unsigned int stream_number,
263 snd_aw2_saa7146_it_cb
264 p_it_callback,
265 void *p_callback_param)
266{
267 if (stream_number < NB_STREAM_PLAYBACK) {
268 arr_substream_it_playback_cb[stream_number].p_it_callback =
269 (snd_aw2_saa7146_it_cb) p_it_callback;
270 arr_substream_it_playback_cb[stream_number].p_callback_param =
271 (void *)p_callback_param;
272 }
273}
274
275void snd_aw2_saa7146_define_it_capture_callback(unsigned int stream_number,
276 snd_aw2_saa7146_it_cb
277 p_it_callback,
278 void *p_callback_param)
279{
280 if (stream_number < NB_STREAM_CAPTURE) {
281 arr_substream_it_capture_cb[stream_number].p_it_callback =
282 (snd_aw2_saa7146_it_cb) p_it_callback;
283 arr_substream_it_capture_cb[stream_number].p_callback_param =
284 (void *)p_callback_param;
285 }
286}
287
288void snd_aw2_saa7146_pcm_trigger_start_playback(struct snd_aw2_saa7146 *chip,
289 int stream_number)
290{
291 unsigned int acon1 = 0;
292 /* In aw8 driver, dma transfert is always active. It is
293 started and stopped in a larger "space" */
294 acon1 = READREG(ACON1);
295 if (stream_number == 0) {
296 WRITEREG((TR_E_A2_OUT << 16) | TR_E_A2_OUT, MC1);
297
298 /* WS2_CTRL, WS2_SYNC: output TSL2, I2S */
299 acon1 |= 2 * WS2_CTRL;
300 WRITEREG(acon1, ACON1);
301
302 } else if (stream_number == 1) {
303 WRITEREG((TR_E_A1_OUT << 16) | TR_E_A1_OUT, MC1);
304
305 /* WS1_CTRL, WS1_SYNC: output TSL1, I2S */
306 acon1 |= 1 * WS1_CTRL;
307 WRITEREG(acon1, ACON1);
308 }
309}
310
311void snd_aw2_saa7146_pcm_trigger_stop_playback(struct snd_aw2_saa7146 *chip,
312 int stream_number)
313{
314 unsigned int acon1 = 0;
315 acon1 = READREG(ACON1);
316 if (stream_number == 0) {
317 /* WS2_CTRL, WS2_SYNC: output TSL2, I2S */
318 acon1 &= ~(3 * WS2_CTRL);
319 WRITEREG(acon1, ACON1);
320
321 WRITEREG((TR_E_A2_OUT << 16), MC1);
322 } else if (stream_number == 1) {
323 /* WS1_CTRL, WS1_SYNC: output TSL1, I2S */
324 acon1 &= ~(3 * WS1_CTRL);
325 WRITEREG(acon1, ACON1);
326
327 WRITEREG((TR_E_A1_OUT << 16), MC1);
328 }
329}
330
331void snd_aw2_saa7146_pcm_trigger_start_capture(struct snd_aw2_saa7146 *chip,
332 int stream_number)
333{
334 /* In aw8 driver, dma transfert is always active. It is
335 started and stopped in a larger "space" */
336 if (stream_number == 0)
337 WRITEREG((TR_E_A1_IN << 16) | TR_E_A1_IN, MC1);
338}
339
340void snd_aw2_saa7146_pcm_trigger_stop_capture(struct snd_aw2_saa7146 *chip,
341 int stream_number)
342{
343 if (stream_number == 0)
344 WRITEREG((TR_E_A1_IN << 16), MC1);
345}
346
347irqreturn_t snd_aw2_saa7146_interrupt(int irq, void *dev_id)
348{
349 unsigned int isr;
350 unsigned int iicsta;
351 struct snd_aw2_saa7146 *chip = dev_id;
352
353 isr = READREG(ISR);
354 if (!isr)
355 return IRQ_NONE;
356
357 WRITEREG(isr, ISR);
358
359 if (isr & (IIC_S | IIC_E)) {
360 iicsta = READREG(IICSTA);
361 WRITEREG(0x100, IICSTA);
362 }
363
364 if (isr & A1_out) {
365 if (arr_substream_it_playback_cb[1].p_it_callback != NULL) {
366 arr_substream_it_playback_cb[1].
367 p_it_callback(arr_substream_it_playback_cb[1].
368 p_callback_param);
369 }
370 }
371 if (isr & A2_out) {
372 if (arr_substream_it_playback_cb[0].p_it_callback != NULL) {
373 arr_substream_it_playback_cb[0].
374 p_it_callback(arr_substream_it_playback_cb[0].
375 p_callback_param);
376 }
377
378 }
379 if (isr & A1_in) {
380 if (arr_substream_it_capture_cb[0].p_it_callback != NULL) {
381 arr_substream_it_capture_cb[0].
382 p_it_callback(arr_substream_it_capture_cb[0].
383 p_callback_param);
384 }
385 }
386 return IRQ_HANDLED;
387}
388
389unsigned int snd_aw2_saa7146_get_hw_ptr_playback(struct snd_aw2_saa7146 *chip,
390 int stream_number,
391 unsigned char *start_addr,
392 unsigned int buffer_size)
393{
394 long pci_adp = 0;
395 size_t ptr = 0;
396
397 if (stream_number == 0) {
398 pci_adp = READREG(PCI_ADP3);
399 ptr = pci_adp - (long)start_addr;
400
401 if (ptr == buffer_size)
402 ptr = 0;
403 }
404 if (stream_number == 1) {
405 pci_adp = READREG(PCI_ADP1);
406 ptr = pci_adp - (size_t) start_addr;
407
408 if (ptr == buffer_size)
409 ptr = 0;
410 }
411 return ptr;
412}
413
414unsigned int snd_aw2_saa7146_get_hw_ptr_capture(struct snd_aw2_saa7146 *chip,
415 int stream_number,
416 unsigned char *start_addr,
417 unsigned int buffer_size)
418{
419 size_t pci_adp = 0;
420 size_t ptr = 0;
421 if (stream_number == 0) {
422 pci_adp = READREG(PCI_ADP2);
423 ptr = pci_adp - (size_t) start_addr;
424
425 if (ptr == buffer_size)
426 ptr = 0;
427 }
428 return ptr;
429}
430
431void snd_aw2_saa7146_use_digital_input(struct snd_aw2_saa7146 *chip,
432 int use_digital)
433{
434 /* FIXME: switch between analog and digital input does not always work.
435 It can produce a kind of white noise. It seams that received data
436 are inverted sometime (endian inversion). Why ? I don't know, maybe
437 a problem of synchronization... However for the time being I have
438 not found the problem. Workaround: switch again (and again) between
439 digital and analog input until it works. */
440 if (use_digital)
441 WRITEREG(0x40, GPIO_CTRL);
442 else
443 WRITEREG(0x50, GPIO_CTRL);
444}
445
446int snd_aw2_saa7146_is_using_digital_input(struct snd_aw2_saa7146 *chip)
447{
448 unsigned int reg_val = READREG(GPIO_CTRL);
449 if ((reg_val & 0xFF) == 0x40)
450 return 1;
451 else
452 return 0;
453}
454
455
456static int snd_aw2_saa7146_get_limit(int size)
457{
458 int limitsize = 32;
459 int limit = 0;
460 while (limitsize < size) {
461 limitsize *= 2;
462 limit++;
463 }
464 return limit;
465}
diff --git a/sound/pci/aw2/aw2-saa7146.h b/sound/pci/aw2/aw2-saa7146.h
new file mode 100644
index 000000000000..5b35e358937f
--- /dev/null
+++ b/sound/pci/aw2/aw2-saa7146.h
@@ -0,0 +1,105 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24#ifndef AW2_SAA7146_H
25#define AW2_SAA7146_H
26
27#define NB_STREAM_PLAYBACK 2
28#define NB_STREAM_CAPTURE 1
29
30#define NUM_STREAM_PLAYBACK_ANA 0
31#define NUM_STREAM_PLAYBACK_DIG 1
32
33#define NUM_STREAM_CAPTURE_ANA 0
34
35typedef void (*snd_aw2_saa7146_it_cb) (void *);
36
37struct snd_aw2_saa7146_cb_param {
38 snd_aw2_saa7146_it_cb p_it_callback;
39 void *p_callback_param;
40};
41
42/* definition of the chip-specific record */
43
44struct snd_aw2_saa7146 {
45 void __iomem *base_addr;
46};
47
48extern void snd_aw2_saa7146_setup(struct snd_aw2_saa7146 *chip,
49 void __iomem *pci_base_addr);
50extern int snd_aw2_saa7146_free(struct snd_aw2_saa7146 *chip);
51
52extern void snd_aw2_saa7146_pcm_init_playback(struct snd_aw2_saa7146 *chip,
53 int stream_number,
54 unsigned long dma_addr,
55 unsigned long period_size,
56 unsigned long buffer_size);
57extern void snd_aw2_saa7146_pcm_init_capture(struct snd_aw2_saa7146 *chip,
58 int stream_number,
59 unsigned long dma_addr,
60 unsigned long period_size,
61 unsigned long buffer_size);
62extern void snd_aw2_saa7146_define_it_playback_callback(unsigned int
63 stream_number,
64 snd_aw2_saa7146_it_cb
65 p_it_callback,
66 void *p_callback_param);
67extern void snd_aw2_saa7146_define_it_capture_callback(unsigned int
68 stream_number,
69 snd_aw2_saa7146_it_cb
70 p_it_callback,
71 void *p_callback_param);
72extern void snd_aw2_saa7146_pcm_trigger_start_capture(struct snd_aw2_saa7146
73 *chip, int stream_number);
74extern void snd_aw2_saa7146_pcm_trigger_stop_capture(struct snd_aw2_saa7146
75 *chip, int stream_number);
76
77extern void snd_aw2_saa7146_pcm_trigger_start_playback(struct snd_aw2_saa7146
78 *chip,
79 int stream_number);
80extern void snd_aw2_saa7146_pcm_trigger_stop_playback(struct snd_aw2_saa7146
81 *chip, int stream_number);
82
83extern irqreturn_t snd_aw2_saa7146_interrupt(int irq, void *dev_id);
84extern unsigned int snd_aw2_saa7146_get_hw_ptr_playback(struct snd_aw2_saa7146
85 *chip,
86 int stream_number,
87 unsigned char
88 *start_addr,
89 unsigned int
90 buffer_size);
91extern unsigned int snd_aw2_saa7146_get_hw_ptr_capture(struct snd_aw2_saa7146
92 *chip,
93 int stream_number,
94 unsigned char
95 *start_addr,
96 unsigned int
97 buffer_size);
98
99extern void snd_aw2_saa7146_use_digital_input(struct snd_aw2_saa7146 *chip,
100 int use_digital);
101
102extern int snd_aw2_saa7146_is_using_digital_input(struct snd_aw2_saa7146
103 *chip);
104
105#endif
diff --git a/sound/pci/aw2/aw2-tsl.c b/sound/pci/aw2/aw2-tsl.c
new file mode 100644
index 000000000000..459b0311ea31
--- /dev/null
+++ b/sound/pci/aw2/aw2-tsl.c
@@ -0,0 +1,110 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 * Copyright 1998 Emagic Soft- und Hardware GmbH
6 * Copyright 2002 Martijn Sipkema
7 *
8 * This file is part of the Audiowerk2 ALSA driver
9 *
10 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.
13 *
14 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 * USA.
23 *
24 *****************************************************************************/
25
26#define TSL_WS0 (1UL << 31)
27#define TSL_WS1 (1UL << 30)
28#define TSL_WS2 (1UL << 29)
29#define TSL_WS3 (1UL << 28)
30#define TSL_WS4 (1UL << 27)
31#define TSL_DIS_A1 (1UL << 24)
32#define TSL_SDW_A1 (1UL << 23)
33#define TSL_SIB_A1 (1UL << 22)
34#define TSL_SF_A1 (1UL << 21)
35#define TSL_LF_A1 (1UL << 20)
36#define TSL_BSEL_A1 (1UL << 17)
37#define TSL_DOD_A1 (1UL << 15)
38#define TSL_LOW_A1 (1UL << 14)
39#define TSL_DIS_A2 (1UL << 11)
40#define TSL_SDW_A2 (1UL << 10)
41#define TSL_SIB_A2 (1UL << 9)
42#define TSL_SF_A2 (1UL << 8)
43#define TSL_LF_A2 (1UL << 7)
44#define TSL_BSEL_A2 (1UL << 4)
45#define TSL_DOD_A2 (1UL << 2)
46#define TSL_LOW_A2 (1UL << 1)
47#define TSL_EOS (1UL << 0)
48
49 /* Audiowerk8 hardware setup: */
50 /* WS0, SD4, TSL1 - Analog/ digital in */
51 /* WS1, SD0, TSL1 - Analog out #1, digital out */
52 /* WS2, SD2, TSL1 - Analog out #2 */
53 /* WS3, SD1, TSL2 - Analog out #3 */
54 /* WS4, SD3, TSL2 - Analog out #4 */
55
56 /* Audiowerk8 timing: */
57 /* Timeslot: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ... */
58
59 /* A1_INPUT: */
60 /* SD4: <_ADC-L_>-------<_ADC-R_>-------< */
61 /* WS0: _______________/---------------\_ */
62
63 /* A1_OUTPUT: */
64 /* SD0: <_1-L___>-------<_1-R___>-------< */
65 /* WS1: _______________/---------------\_ */
66 /* SD2: >-------<_2-L___>-------<_2-R___> */
67 /* WS2: -------\_______________/--------- */
68
69 /* A2_OUTPUT: */
70 /* SD1: <_3-L___>-------<_3-R___>-------< */
71 /* WS3: _______________/---------------\_ */
72 /* SD3: >-------<_4-L___>-------<_4-R___> */
73 /* WS4: -------\_______________/--------- */
74
75static int tsl1[8] = {
76 1 * TSL_SDW_A1 | 3 * TSL_BSEL_A1 |
77 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_LF_A1,
78
79 1 * TSL_SDW_A1 | 2 * TSL_BSEL_A1 |
80 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
81
82 0 * TSL_SDW_A1 | 3 * TSL_BSEL_A1 |
83 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
84
85 0 * TSL_SDW_A1 | 2 * TSL_BSEL_A1 |
86 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
87
88 1 * TSL_SDW_A1 | 1 * TSL_BSEL_A1 |
89 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
90
91 1 * TSL_SDW_A1 | 0 * TSL_BSEL_A1 |
92 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
93
94 0 * TSL_SDW_A1 | 1 * TSL_BSEL_A1 |
95 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
96
97 0 * TSL_SDW_A1 | 0 * TSL_BSEL_A1 | 0 * TSL_DIS_A1 |
98 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0 | TSL_SF_A1 | TSL_EOS,
99};
100
101static int tsl2[8] = {
102 0 * TSL_SDW_A2 | 3 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_LF_A2,
103 0 * TSL_SDW_A2 | 2 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
104 0 * TSL_SDW_A2 | 3 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
105 0 * TSL_SDW_A2 | 2 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
106 0 * TSL_SDW_A2 | 1 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
107 0 * TSL_SDW_A2 | 0 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
108 0 * TSL_SDW_A2 | 1 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
109 0 * TSL_SDW_A2 | 0 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2 | TSL_EOS
110};
diff --git a/sound/pci/aw2/saa7146.h b/sound/pci/aw2/saa7146.h
new file mode 100644
index 000000000000..ce0ab5f9ee9c
--- /dev/null
+++ b/sound/pci/aw2/saa7146.h
@@ -0,0 +1,168 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24/* SAA7146 registers */
25#define PCI_BT_A 0x4C
26#define IICTFR 0x8C
27#define IICSTA 0x90
28#define BaseA1_in 0x94
29#define ProtA1_in 0x98
30#define PageA1_in 0x9C
31#define BaseA1_out 0xA0
32#define ProtA1_out 0xA4
33#define PageA1_out 0xA8
34#define BaseA2_in 0xAC
35#define ProtA2_in 0xB0
36#define PageA2_in 0xB4
37#define BaseA2_out 0xB8
38#define ProtA2_out 0xBC
39#define PageA2_out 0xC0
40#define IER 0xDC
41#define GPIO_CTRL 0xE0
42#define ACON1 0xF4
43#define ACON2 0xF8
44#define MC1 0xFC
45#define MC2 0x100
46#define ISR 0x10C
47#define PSR 0x110
48#define SSR 0x114
49#define PCI_ADP1 0x12C
50#define PCI_ADP2 0x130
51#define PCI_ADP3 0x134
52#define PCI_ADP4 0x138
53#define LEVEL_REP 0x140
54#define FB_BUFFER1 0x144
55#define FB_BUFFER2 0x148
56#define TSL1 0x180
57#define TSL2 0x1C0
58
59#define ME (1UL << 11)
60#define LIMIT (1UL << 4)
61#define PV (1UL << 3)
62
63/* PSR/ISR/IER */
64#define PPEF (1UL << 31)
65#define PABO (1UL << 30)
66#define IIC_S (1UL << 17)
67#define IIC_E (1UL << 16)
68#define A2_in (1UL << 15)
69#define A2_out (1UL << 14)
70#define A1_in (1UL << 13)
71#define A1_out (1UL << 12)
72#define AFOU (1UL << 11)
73#define PIN3 (1UL << 6)
74#define PIN2 (1UL << 5)
75#define PIN1 (1UL << 4)
76#define PIN0 (1UL << 3)
77#define ECS (1UL << 2)
78#define EC3S (1UL << 1)
79#define EC0S (1UL << 0)
80
81/* SSR */
82#define PRQ (1UL << 31)
83#define PMA (1UL << 30)
84#define IIC_EA (1UL << 21)
85#define IIC_EW (1UL << 20)
86#define IIC_ER (1UL << 19)
87#define IIC_EL (1UL << 18)
88#define IIC_EF (1UL << 17)
89#define AF2_in (1UL << 10)
90#define AF2_out (1UL << 9)
91#define AF1_in (1UL << 8)
92#define AF1_out (1UL << 7)
93#define EC5S (1UL << 3)
94#define EC4S (1UL << 2)
95#define EC2S (1UL << 1)
96#define EC1S (1UL << 0)
97
98/* PCI_BT_A */
99#define BurstA1_in (1UL << 26)
100#define ThreshA1_in (1UL << 24)
101#define BurstA1_out (1UL << 18)
102#define ThreshA1_out (1UL << 16)
103#define BurstA2_in (1UL << 10)
104#define ThreshA2_in (1UL << 8)
105#define BurstA2_out (1UL << 2)
106#define ThreshA2_out (1UL << 0)
107
108/* MC1 */
109#define MRST_N (1UL << 15)
110#define EAP (1UL << 9)
111#define EI2C (1UL << 8)
112#define TR_E_A2_OUT (1UL << 3)
113#define TR_E_A2_IN (1UL << 2)
114#define TR_E_A1_OUT (1UL << 1)
115#define TR_E_A1_IN (1UL << 0)
116
117/* MC2 */
118#define UPLD_IIC (1UL << 0)
119
120/* ACON1 */
121#define AUDIO_MODE (1UL << 29)
122#define MAXLEVEL (1UL << 22)
123#define A1_SWAP (1UL << 21)
124#define A2_SWAP (1UL << 20)
125#define WS0_CTRL (1UL << 18)
126#define WS0_SYNC (1UL << 16)
127#define WS1_CTRL (1UL << 14)
128#define WS1_SYNC (1UL << 12)
129#define WS2_CTRL (1UL << 10)
130#define WS2_SYNC (1UL << 8)
131#define WS3_CTRL (1UL << 6)
132#define WS3_SYNC (1UL << 4)
133#define WS4_CTRL (1UL << 2)
134#define WS4_SYNC (1UL << 0)
135
136/* ACON2 */
137#define A1_CLKSRC (1UL << 27)
138#define A2_CLKSRC (1UL << 22)
139#define INVERT_BCLK1 (1UL << 21)
140#define INVERT_BCLK2 (1UL << 20)
141#define BCLK1_OEN (1UL << 19)
142#define BCLK2_OEN (1UL << 18)
143
144/* IICSTA */
145#define IICCC (1UL << 8)
146#define ABORT (1UL << 7)
147#define SPERR (1UL << 6)
148#define APERR (1UL << 5)
149#define DTERR (1UL << 4)
150#define DRERR (1UL << 3)
151#define AL (1UL << 2)
152#define ERR (1UL << 1)
153#define BUSY (1UL << 0)
154
155/* IICTFR */
156#define BYTE2 (1UL << 24)
157#define BYTE1 (1UL << 16)
158#define BYTE0 (1UL << 8)
159#define ATRR2 (1UL << 6)
160#define ATRR1 (1UL << 4)
161#define ATRR0 (1UL << 2)
162#define ERR (1UL << 1)
163#define BUSY (1UL << 0)
164
165#define START 3
166#define CONT 2
167#define STOP 1
168#define NOP 0
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 4e71a55120a0..5f63af6b88a2 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -157,8 +157,8 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
157 157
158#if DEBUG_CALLS 158#if DEBUG_CALLS
159#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args) 159#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
160#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__) 160#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
161#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__) 161#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
162#else 162#else
163#define snd_azf3328_dbgcalls(format, args...) 163#define snd_azf3328_dbgcalls(format, args...)
164#define snd_azf3328_dbgcallenter() 164#define snd_azf3328_dbgcallenter()
@@ -1514,7 +1514,8 @@ snd_azf3328_free(struct snd_azf3328 *chip)
1514 /* well, at least we know how to disable the timer IRQ */ 1514 /* well, at least we know how to disable the timer IRQ */
1515 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00); 1515 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00);
1516 1516
1517 synchronize_irq(chip->irq); 1517 if (chip->irq >= 0)
1518 synchronize_irq(chip->irq);
1518__end_hw: 1519__end_hw:
1519 snd_azf3328_free_joystick(chip); 1520 snd_azf3328_free_joystick(chip);
1520 if (chip->irq >= 0) 1521 if (chip->irq >= 0)
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 176e0f0e8058..ecbe79b67e43 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -435,22 +435,22 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
435static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb) 435static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb)
436{ 436{
437 unsigned long flags; 437 unsigned long flags;
438 unsigned int enable; 438 unsigned int intr_enable;
439 439
440 spin_lock_irqsave(&emu->emu_lock, flags); 440 spin_lock_irqsave(&emu->emu_lock, flags);
441 enable = inl(emu->port + INTE) | intrenb; 441 intr_enable = inl(emu->port + INTE) | intrenb;
442 outl(enable, emu->port + INTE); 442 outl(intr_enable, emu->port + INTE);
443 spin_unlock_irqrestore(&emu->emu_lock, flags); 443 spin_unlock_irqrestore(&emu->emu_lock, flags);
444} 444}
445 445
446static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb) 446static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb)
447{ 447{
448 unsigned long flags; 448 unsigned long flags;
449 unsigned int enable; 449 unsigned int intr_enable;
450 450
451 spin_lock_irqsave(&emu->emu_lock, flags); 451 spin_lock_irqsave(&emu->emu_lock, flags);
452 enable = inl(emu->port + INTE) & ~intrenb; 452 intr_enable = inl(emu->port + INTE) & ~intrenb;
453 outl(enable, emu->port + INTE); 453 outl(intr_enable, emu->port + INTE);
454 spin_unlock_irqrestore(&emu->emu_lock, flags); 454 spin_unlock_irqrestore(&emu->emu_lock, flags);
455} 455}
456 456
@@ -1114,6 +1114,8 @@ static int snd_ca0106_free(struct snd_ca0106 *chip)
1114 * So we can fix: snd-malloc: Memory leak? pages not freed = 8 1114 * So we can fix: snd-malloc: Memory leak? pages not freed = 8
1115 */ 1115 */
1116 } 1116 }
1117 if (chip->irq >= 0)
1118 free_irq(chip->irq, chip);
1117 // release the data 1119 // release the data
1118#if 1 1120#if 1
1119 if (chip->buffer.area) 1121 if (chip->buffer.area)
@@ -1123,9 +1125,6 @@ static int snd_ca0106_free(struct snd_ca0106 *chip)
1123 // release the i/o port 1125 // release the i/o port
1124 release_and_free_resource(chip->res_port); 1126 release_and_free_resource(chip->res_port);
1125 1127
1126 // release the irq
1127 if (chip->irq >= 0)
1128 free_irq(chip->irq, chip);
1129 pci_disable_device(chip->pci); 1128 pci_disable_device(chip->pci);
1130 kfree(chip); 1129 kfree(chip);
1131 return 0; 1130 return 0;
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index af736869d9b1..3025ed1b6e1e 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -650,19 +650,55 @@ static int __devinit rename_ctl(struct snd_card *card, const char *src, const ch
650 650
651#define ADD_CTLS(emu, ctls) \ 651#define ADD_CTLS(emu, ctls) \
652 do { \ 652 do { \
653 int i, err; \ 653 int i, _err; \
654 for (i = 0; i < ARRAY_SIZE(ctls); i++) { \ 654 for (i = 0; i < ARRAY_SIZE(ctls); i++) { \
655 err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \ 655 _err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \
656 if (err < 0) \ 656 if (_err < 0) \
657 return err; \ 657 return _err; \
658 } \ 658 } \
659 } while (0) 659 } while (0)
660 660
661static __devinitdata
662DECLARE_TLV_DB_SCALE(snd_ca0106_master_db_scale, -6375, 50, 1);
663
664static char *slave_vols[] __devinitdata = {
665 "Analog Front Playback Volume",
666 "Analog Rear Playback Volume",
667 "Analog Center/LFE Playback Volume",
668 "Analog Side Playback Volume",
669 "IEC958 Front Playback Volume",
670 "IEC958 Rear Playback Volume",
671 "IEC958 Center/LFE Playback Volume",
672 "IEC958 Unknown Playback Volume",
673 "CAPTURE feedback Playback Volume",
674 NULL
675};
676
677static char *slave_sws[] __devinitdata = {
678 "Analog Front Playback Switch",
679 "Analog Rear Playback Switch",
680 "Analog Center/LFE Playback Switch",
681 "Analog Side Playback Switch",
682 "IEC958 Playback Switch",
683 NULL
684};
685
686static void __devinit add_slaves(struct snd_card *card,
687 struct snd_kcontrol *master, char **list)
688{
689 for (; *list; list++) {
690 struct snd_kcontrol *slave = ctl_find(card, *list);
691 if (slave)
692 snd_ctl_add_slave(master, slave);
693 }
694}
695
661int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu) 696int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
662{ 697{
663 int err; 698 int err;
664 struct snd_card *card = emu->card; 699 struct snd_card *card = emu->card;
665 char **c; 700 char **c;
701 struct snd_kcontrol *vmaster;
666 static char *ca0106_remove_ctls[] = { 702 static char *ca0106_remove_ctls[] = {
667 "Master Mono Playback Switch", 703 "Master Mono Playback Switch",
668 "Master Mono Playback Volume", 704 "Master Mono Playback Volume",
@@ -719,6 +755,21 @@ int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
719 } 755 }
720 if (emu->details->spi_dac == 1) 756 if (emu->details->spi_dac == 1)
721 ADD_CTLS(emu, snd_ca0106_volume_spi_dac_ctls); 757 ADD_CTLS(emu, snd_ca0106_volume_spi_dac_ctls);
758
759 /* Create virtual master controls */
760 vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
761 snd_ca0106_master_db_scale);
762 if (!vmaster)
763 return -ENOMEM;
764 add_slaves(card, vmaster, slave_vols);
765
766 if (emu->details->spi_dac == 1) {
767 vmaster = snd_ctl_make_virtual_master("Master Playback Switch",
768 NULL);
769 if (!vmaster)
770 return -ENOMEM;
771 add_slaves(card, vmaster, slave_sws);
772 }
722 return 0; 773 return 0;
723} 774}
724 775
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 135f30860753..9971b5b7735b 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2744,12 +2744,13 @@ static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_devic
2744 } 2744 }
2745 2745
2746 for (idx = 0; idx < CM_SAVED_MIXERS; idx++) { 2746 for (idx = 0; idx < CM_SAVED_MIXERS; idx++) {
2747 struct snd_ctl_elem_id id; 2747 struct snd_ctl_elem_id elem_id;
2748 struct snd_kcontrol *ctl; 2748 struct snd_kcontrol *ctl;
2749 memset(&id, 0, sizeof(id)); 2749 memset(&elem_id, 0, sizeof(elem_id));
2750 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2750 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2751 strcpy(id.name, cm_saved_mixer[idx].name); 2751 strcpy(elem_id.name, cm_saved_mixer[idx].name);
2752 if ((ctl = snd_ctl_find_id(cm->card, &id)) != NULL) 2752 ctl = snd_ctl_find_id(cm->card, &elem_id);
2753 if (ctl)
2753 cm->mixer_res_ctl[idx] = ctl; 2754 cm->mixer_res_ctl[idx] = ctl;
2754 } 2755 }
2755 2756
@@ -2932,8 +2933,6 @@ static int snd_cmipci_free(struct cmipci *cm)
2932 /* reset mixer */ 2933 /* reset mixer */
2933 snd_cmipci_mixer_write(cm, 0, 0); 2934 snd_cmipci_mixer_write(cm, 0, 0);
2934 2935
2935 synchronize_irq(cm->irq);
2936
2937 free_irq(cm->irq, cm); 2936 free_irq(cm->irq, cm);
2938 } 2937 }
2939 2938
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 87ddffcd9d89..e214e567dec8 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -2772,6 +2772,9 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
2772 if (chip->irq >= 0) 2772 if (chip->irq >= 0)
2773 free_irq(chip->irq, chip); 2773 free_irq(chip->irq, chip);
2774 2774
2775 if (chip->active_ctrl)
2776 chip->active_ctrl(chip, -chip->amplifier);
2777
2775 for (idx = 0; idx < 5; idx++) { 2778 for (idx = 0; idx < 5; idx++) {
2776 struct snd_cs46xx_region *region = &chip->region.idx[idx]; 2779 struct snd_cs46xx_region *region = &chip->region.idx[idx];
2777 if (region->remap_addr) 2780 if (region->remap_addr)
@@ -2779,9 +2782,6 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
2779 release_and_free_resource(region->resource); 2782 release_and_free_resource(region->resource);
2780 } 2783 }
2781 2784
2782 if (chip->active_ctrl)
2783 chip->active_ctrl(chip, -chip->amplifier);
2784
2785#ifdef CONFIG_SND_CS46XX_NEW_DSP 2785#ifdef CONFIG_SND_CS46XX_NEW_DSP
2786 if (chip->dsp_spos_instance) { 2786 if (chip->dsp_spos_instance) {
2787 cs46xx_dsp_spos_destroy(chip); 2787 cs46xx_dsp_spos_destroy(chip);
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 90ec090792ba..e16dc92e82fb 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -1852,15 +1852,16 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1852static int snd_echo_free(struct echoaudio *chip) 1852static int snd_echo_free(struct echoaudio *chip)
1853{ 1853{
1854 DE_INIT(("Stop DSP...\n")); 1854 DE_INIT(("Stop DSP...\n"));
1855 if (chip->comm_page) { 1855 if (chip->comm_page)
1856 rest_in_peace(chip); 1856 rest_in_peace(chip);
1857 snd_dma_free_pages(&chip->commpage_dma_buf);
1858 }
1859 DE_INIT(("Stopped.\n")); 1857 DE_INIT(("Stopped.\n"));
1860 1858
1861 if (chip->irq >= 0) 1859 if (chip->irq >= 0)
1862 free_irq(chip->irq, chip); 1860 free_irq(chip->irq, chip);
1863 1861
1862 if (chip->comm_page)
1863 snd_dma_free_pages(&chip->commpage_dma_buf);
1864
1864 if (chip->dsp_registers) 1865 if (chip->dsp_registers)
1865 iounmap(chip->dsp_registers); 1866 iounmap(chip->dsp_registers);
1866 1867
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 9a9b977d3cf1..abde5b901884 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -1249,11 +1249,6 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1249 if (emu->port) { /* avoid access to already used hardware */ 1249 if (emu->port) { /* avoid access to already used hardware */
1250 snd_emu10k1_fx8010_tram_setup(emu, 0); 1250 snd_emu10k1_fx8010_tram_setup(emu, 0);
1251 snd_emu10k1_done(emu); 1251 snd_emu10k1_done(emu);
1252 /* remove reserved page */
1253 if (emu->reserved_page) {
1254 snd_emu10k1_synth_free(emu, (struct snd_util_memblk *)emu->reserved_page);
1255 emu->reserved_page = NULL;
1256 }
1257 snd_emu10k1_free_efx(emu); 1252 snd_emu10k1_free_efx(emu);
1258 } 1253 }
1259 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) { 1254 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) {
@@ -1262,6 +1257,14 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1262 } 1257 }
1263 if (emu->emu1010.firmware_thread) 1258 if (emu->emu1010.firmware_thread)
1264 kthread_stop(emu->emu1010.firmware_thread); 1259 kthread_stop(emu->emu1010.firmware_thread);
1260 if (emu->irq >= 0)
1261 free_irq(emu->irq, emu);
1262 /* remove reserved page */
1263 if (emu->reserved_page) {
1264 snd_emu10k1_synth_free(emu,
1265 (struct snd_util_memblk *)emu->reserved_page);
1266 emu->reserved_page = NULL;
1267 }
1265 if (emu->memhdr) 1268 if (emu->memhdr)
1266 snd_util_memhdr_free(emu->memhdr); 1269 snd_util_memhdr_free(emu->memhdr);
1267 if (emu->silent_page.area) 1270 if (emu->silent_page.area)
@@ -1273,8 +1276,6 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1273#ifdef CONFIG_PM 1276#ifdef CONFIG_PM
1274 free_pm_buffer(emu); 1277 free_pm_buffer(emu);
1275#endif 1278#endif
1276 if (emu->irq >= 0)
1277 free_irq(emu->irq, emu);
1278 if (emu->port) 1279 if (emu->port)
1279 pci_release_regions(emu->pci); 1280 pci_release_regions(emu->pci);
1280 if (emu->card_capabilities->ca0151_chip) /* P16V */ 1281 if (emu->card_capabilities->ca0151_chip) /* P16V */
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 5512abd98bd9..491a4a50f869 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -327,22 +327,22 @@ static void snd_emu10k1x_ptr_write(struct emu10k1x *emu,
327static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb) 327static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb)
328{ 328{
329 unsigned long flags; 329 unsigned long flags;
330 unsigned int enable; 330 unsigned int intr_enable;
331 331
332 spin_lock_irqsave(&emu->emu_lock, flags); 332 spin_lock_irqsave(&emu->emu_lock, flags);
333 enable = inl(emu->port + INTE) | intrenb; 333 intr_enable = inl(emu->port + INTE) | intrenb;
334 outl(enable, emu->port + INTE); 334 outl(intr_enable, emu->port + INTE);
335 spin_unlock_irqrestore(&emu->emu_lock, flags); 335 spin_unlock_irqrestore(&emu->emu_lock, flags);
336} 336}
337 337
338static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb) 338static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb)
339{ 339{
340 unsigned long flags; 340 unsigned long flags;
341 unsigned int enable; 341 unsigned int intr_enable;
342 342
343 spin_lock_irqsave(&emu->emu_lock, flags); 343 spin_lock_irqsave(&emu->emu_lock, flags);
344 enable = inl(emu->port + INTE) & ~intrenb; 344 intr_enable = inl(emu->port + INTE) & ~intrenb;
345 outl(enable, emu->port + INTE); 345 outl(intr_enable, emu->port + INTE);
346 spin_unlock_irqrestore(&emu->emu_lock, flags); 346 spin_unlock_irqrestore(&emu->emu_lock, flags);
347} 347}
348 348
@@ -754,13 +754,13 @@ static int snd_emu10k1x_free(struct emu10k1x *chip)
754 // disable audio 754 // disable audio
755 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); 755 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
756 756
757 // release the i/o port 757 /* release the irq */
758 release_and_free_resource(chip->res_port);
759
760 // release the irq
761 if (chip->irq >= 0) 758 if (chip->irq >= 0)
762 free_irq(chip->irq, chip); 759 free_irq(chip->irq, chip);
763 760
761 // release the i/o port
762 release_and_free_resource(chip->res_port);
763
764 // release the DMA 764 // release the DMA
765 if (chip->dma_buffer.area) { 765 if (chip->dma_buffer.area) {
766 snd_dma_free_pages(&chip->dma_buffer); 766 snd_dma_free_pages(&chip->dma_buffer);
@@ -795,9 +795,9 @@ static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id)
795 795
796 // capture interrupt 796 // capture interrupt
797 if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) { 797 if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) {
798 struct emu10k1x_voice *pvoice = &chip->capture_voice; 798 struct emu10k1x_voice *cap_voice = &chip->capture_voice;
799 if (pvoice->use) 799 if (cap_voice->use)
800 snd_emu10k1x_pcm_interrupt(chip, pvoice); 800 snd_emu10k1x_pcm_interrupt(chip, cap_voice);
801 else 801 else
802 snd_emu10k1x_intr_disable(chip, 802 snd_emu10k1x_intr_disable(chip,
803 INTE_CAP_0_LOOP | 803 INTE_CAP_0_LOOP |
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index f3caa3f890c6..216f9748aff5 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -412,7 +412,7 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
412 struct snd_info_buffer *buffer) 412 struct snd_info_buffer *buffer)
413{ 413{
414 struct snd_emu10k1 *emu = entry->private_data; 414 struct snd_emu10k1 *emu = entry->private_data;
415 int value; 415 u32 value;
416 unsigned long flags; 416 unsigned long flags;
417 int i; 417 int i;
418 snd_iprintf(buffer, "EMU1010 Registers:\n\n"); 418 snd_iprintf(buffer, "EMU1010 Registers:\n\n");
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 72d85a5ae6a0..fbf1124f7c79 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -1635,20 +1635,20 @@ static int __devinit snd_ensoniq_1371_mixer(struct ensoniq *ensoniq,
1635 if (has_spdif > 0 || 1635 if (has_spdif > 0 ||
1636 (!has_spdif && es1371_quirk_lookup(ensoniq, es1371_spdif_present))) { 1636 (!has_spdif && es1371_quirk_lookup(ensoniq, es1371_spdif_present))) {
1637 struct snd_kcontrol *kctl; 1637 struct snd_kcontrol *kctl;
1638 int i, index = 0; 1638 int i, is_spdif = 0;
1639 1639
1640 ensoniq->spdif_default = ensoniq->spdif_stream = 1640 ensoniq->spdif_default = ensoniq->spdif_stream =
1641 SNDRV_PCM_DEFAULT_CON_SPDIF; 1641 SNDRV_PCM_DEFAULT_CON_SPDIF;
1642 outl(ensoniq->spdif_default, ES_REG(ensoniq, CHANNEL_STATUS)); 1642 outl(ensoniq->spdif_default, ES_REG(ensoniq, CHANNEL_STATUS));
1643 1643
1644 if (ensoniq->u.es1371.ac97->ext_id & AC97_EI_SPDIF) 1644 if (ensoniq->u.es1371.ac97->ext_id & AC97_EI_SPDIF)
1645 index++; 1645 is_spdif++;
1646 1646
1647 for (i = 0; i < ARRAY_SIZE(snd_es1371_mixer_spdif); i++) { 1647 for (i = 0; i < ARRAY_SIZE(snd_es1371_mixer_spdif); i++) {
1648 kctl = snd_ctl_new1(&snd_es1371_mixer_spdif[i], ensoniq); 1648 kctl = snd_ctl_new1(&snd_es1371_mixer_spdif[i], ensoniq);
1649 if (!kctl) 1649 if (!kctl)
1650 return -ENOMEM; 1650 return -ENOMEM;
1651 kctl->id.index = index; 1651 kctl->id.index = is_spdif;
1652 err = snd_ctl_add(card, kctl); 1652 err = snd_ctl_add(card, kctl);
1653 if (err < 0) 1653 if (err < 0)
1654 return err; 1654 return err;
@@ -1910,7 +1910,8 @@ static int snd_ensoniq_free(struct ensoniq *ensoniq)
1910 outl(0, ES_REG(ensoniq, CONTROL)); /* switch everything off */ 1910 outl(0, ES_REG(ensoniq, CONTROL)); /* switch everything off */
1911 outl(0, ES_REG(ensoniq, SERIAL)); /* clear serial interface */ 1911 outl(0, ES_REG(ensoniq, SERIAL)); /* clear serial interface */
1912#endif 1912#endif
1913 synchronize_irq(ensoniq->irq); 1913 if (ensoniq->irq >= 0)
1914 synchronize_irq(ensoniq->irq);
1914 pci_set_power_state(ensoniq->pci, 3); 1915 pci_set_power_state(ensoniq->pci, 3);
1915 __hw_end: 1916 __hw_end:
1916#ifdef CHIP1370 1917#ifdef CHIP1370
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 1a314fa99c45..84fac1fbf103 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1488,7 +1488,6 @@ static int es1938_suspend(struct pci_dev *pci, pm_message_t state)
1488 1488
1489 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */ 1489 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
1490 if (chip->irq >= 0) { 1490 if (chip->irq >= 0) {
1491 synchronize_irq(chip->irq);
1492 free_irq(chip->irq, chip); 1491 free_irq(chip->irq, chip);
1493 chip->irq = -1; 1492 chip->irq = -1;
1494 } 1493 }
@@ -1578,10 +1577,8 @@ static int snd_es1938_free(struct es1938 *chip)
1578 1577
1579 snd_es1938_free_gameport(chip); 1578 snd_es1938_free_gameport(chip);
1580 1579
1581 if (chip->irq >= 0) { 1580 if (chip->irq >= 0)
1582 synchronize_irq(chip->irq);
1583 free_irq(chip->irq, chip); 1581 free_irq(chip->irq, chip);
1584 }
1585 pci_release_regions(chip->pci); 1582 pci_release_regions(chip->pci);
1586 pci_disable_device(chip->pci); 1583 pci_disable_device(chip->pci);
1587 kfree(chip); 1584 kfree(chip);
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 7d911a18c082..1bf298d214b9 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -1827,6 +1827,22 @@ snd_es1968_pcm(struct es1968 *chip, int device)
1827 1827
1828 return 0; 1828 return 0;
1829} 1829}
1830/*
1831 * suppress jitter on some maestros when playing stereo
1832 */
1833static void snd_es1968_suppress_jitter(struct es1968 *chip, struct esschan *es)
1834{
1835 unsigned int cp1;
1836 unsigned int cp2;
1837 unsigned int diff;
1838
1839 cp1 = __apu_get_register(chip, 0, 5);
1840 cp2 = __apu_get_register(chip, 1, 5);
1841 diff = (cp1 > cp2 ? cp1 - cp2 : cp2 - cp1);
1842
1843 if (diff > 1)
1844 __maestro_write(chip, IDR0_DATA_PORT, cp1);
1845}
1830 1846
1831/* 1847/*
1832 * update pointer 1848 * update pointer
@@ -1948,8 +1964,11 @@ static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id)
1948 struct esschan *es; 1964 struct esschan *es;
1949 spin_lock(&chip->substream_lock); 1965 spin_lock(&chip->substream_lock);
1950 list_for_each_entry(es, &chip->substream_list, list) { 1966 list_for_each_entry(es, &chip->substream_list, list) {
1951 if (es->running) 1967 if (es->running) {
1952 snd_es1968_update_pcm(chip, es); 1968 snd_es1968_update_pcm(chip, es);
1969 if (es->fmt & ESS_FMT_STEREO)
1970 snd_es1968_suppress_jitter(chip, es);
1971 }
1953 } 1972 }
1954 spin_unlock(&chip->substream_lock); 1973 spin_unlock(&chip->substream_lock);
1955 if (chip->in_measurement) { 1974 if (chip->in_measurement) {
@@ -1972,7 +1991,7 @@ snd_es1968_mixer(struct es1968 *chip)
1972{ 1991{
1973 struct snd_ac97_bus *pbus; 1992 struct snd_ac97_bus *pbus;
1974 struct snd_ac97_template ac97; 1993 struct snd_ac97_template ac97;
1975 struct snd_ctl_elem_id id; 1994 struct snd_ctl_elem_id elem_id;
1976 int err; 1995 int err;
1977 static struct snd_ac97_bus_ops ops = { 1996 static struct snd_ac97_bus_ops ops = {
1978 .write = snd_es1968_ac97_write, 1997 .write = snd_es1968_ac97_write,
@@ -1989,14 +2008,14 @@ snd_es1968_mixer(struct es1968 *chip)
1989 return err; 2008 return err;
1990 2009
1991 /* attach master switch / volumes for h/w volume control */ 2010 /* attach master switch / volumes for h/w volume control */
1992 memset(&id, 0, sizeof(id)); 2011 memset(&elem_id, 0, sizeof(elem_id));
1993 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2012 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1994 strcpy(id.name, "Master Playback Switch"); 2013 strcpy(elem_id.name, "Master Playback Switch");
1995 chip->master_switch = snd_ctl_find_id(chip->card, &id); 2014 chip->master_switch = snd_ctl_find_id(chip->card, &elem_id);
1996 memset(&id, 0, sizeof(id)); 2015 memset(&elem_id, 0, sizeof(elem_id));
1997 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2016 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1998 strcpy(id.name, "Master Playback Volume"); 2017 strcpy(elem_id.name, "Master Playback Volume");
1999 chip->master_volume = snd_ctl_find_id(chip->card, &id); 2018 chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
2000 2019
2001 return 0; 2020 return 0;
2002} 2021}
@@ -2456,7 +2475,8 @@ static inline void snd_es1968_free_gameport(struct es1968 *chip) { }
2456static int snd_es1968_free(struct es1968 *chip) 2475static int snd_es1968_free(struct es1968 *chip)
2457{ 2476{
2458 if (chip->io_port) { 2477 if (chip->io_port) {
2459 synchronize_irq(chip->irq); 2478 if (chip->irq >= 0)
2479 synchronize_irq(chip->irq);
2460 outw(1, chip->io_port + 0x04); /* clear WP interrupts */ 2480 outw(1, chip->io_port + 0x04); /* clear WP interrupts */
2461 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */ 2481 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */
2462 } 2482 }
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index 4c300e6149fc..c129f9e2072c 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -1285,7 +1285,6 @@ static int wait_for_codec(struct fm801 *chip, unsigned int codec_id,
1285 1285
1286static int snd_fm801_chip_init(struct fm801 *chip, int resume) 1286static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1287{ 1287{
1288 int id;
1289 unsigned short cmdw; 1288 unsigned short cmdw;
1290 1289
1291 if (chip->tea575x_tuner & 0x0010) 1290 if (chip->tea575x_tuner & 0x0010)
@@ -1310,13 +1309,14 @@ static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1310 } else { 1309 } else {
1311 /* my card has the secondary codec */ 1310 /* my card has the secondary codec */
1312 /* at address #3, so the loop is inverted */ 1311 /* at address #3, so the loop is inverted */
1313 for (id = 3; id > 0; id--) { 1312 int i;
1314 if (! wait_for_codec(chip, id, AC97_VENDOR_ID1, 1313 for (i = 3; i > 0; i--) {
1314 if (!wait_for_codec(chip, i, AC97_VENDOR_ID1,
1315 msecs_to_jiffies(50))) { 1315 msecs_to_jiffies(50))) {
1316 cmdw = inw(FM801_REG(chip, AC97_DATA)); 1316 cmdw = inw(FM801_REG(chip, AC97_DATA));
1317 if (cmdw != 0xffff && cmdw != 0) { 1317 if (cmdw != 0xffff && cmdw != 0) {
1318 chip->secondary = 1; 1318 chip->secondary = 1;
1319 chip->secondary_addr = id; 1319 chip->secondary_addr = i;
1320 break; 1320 break;
1321 } 1321 }
1322 } 1322 }
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 9e0d8a1268aa..ab0c726d648e 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -2,7 +2,7 @@ snd-hda-intel-y := hda_intel.o
2# since snd-hda-intel is the only driver using hda-codec, 2# since snd-hda-intel is the only driver using hda-codec,
3# merge it into a single module although it was originally 3# merge it into a single module although it was originally
4# designed to be individual modules 4# designed to be individual modules
5snd-hda-intel-y += hda_codec.o vmaster.o 5snd-hda-intel-y += hda_codec.o
6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o 6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o
7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 8snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 37c413923db8..a6be6e3e8716 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -31,6 +31,7 @@
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include "hda_local.h" 32#include "hda_local.h"
33#include <sound/hda_hwdep.h> 33#include <sound/hda_hwdep.h>
34#include "hda_patch.h" /* codec presets */
34 35
35#ifdef CONFIG_SND_HDA_POWER_SAVE 36#ifdef CONFIG_SND_HDA_POWER_SAVE
36/* define this option here to hide as static */ 37/* define this option here to hide as static */
@@ -51,21 +52,50 @@ struct hda_vendor_id {
51 52
52/* codec vendor labels */ 53/* codec vendor labels */
53static struct hda_vendor_id hda_vendor_ids[] = { 54static struct hda_vendor_id hda_vendor_ids[] = {
54 { 0x10ec, "Realtek" }, 55 { 0x1002, "ATI" },
55 { 0x1057, "Motorola" }, 56 { 0x1057, "Motorola" },
57 { 0x1095, "Silicon Image" },
58 { 0x10ec, "Realtek" },
56 { 0x1106, "VIA" }, 59 { 0x1106, "VIA" },
57 { 0x111d, "IDT" }, 60 { 0x111d, "IDT" },
61 { 0x11c1, "LSI" },
58 { 0x11d4, "Analog Devices" }, 62 { 0x11d4, "Analog Devices" },
59 { 0x13f6, "C-Media" }, 63 { 0x13f6, "C-Media" },
60 { 0x14f1, "Conexant" }, 64 { 0x14f1, "Conexant" },
65 { 0x17e8, "Chrontel" },
66 { 0x1854, "LG" },
61 { 0x434d, "C-Media" }, 67 { 0x434d, "C-Media" },
62 { 0x8384, "SigmaTel" }, 68 { 0x8384, "SigmaTel" },
63 {} /* terminator */ 69 {} /* terminator */
64}; 70};
65 71
66/* codec presets */ 72static const struct hda_codec_preset *hda_preset_tables[] = {
67#include "hda_patch.h" 73#ifdef CONFIG_SND_HDA_CODEC_REALTEK
68 74 snd_hda_preset_realtek,
75#endif
76#ifdef CONFIG_SND_HDA_CODEC_CMEDIA
77 snd_hda_preset_cmedia,
78#endif
79#ifdef CONFIG_SND_HDA_CODEC_ANALOG
80 snd_hda_preset_analog,
81#endif
82#ifdef CONFIG_SND_HDA_CODEC_SIGMATEL
83 snd_hda_preset_sigmatel,
84#endif
85#ifdef CONFIG_SND_HDA_CODEC_SI3054
86 snd_hda_preset_si3054,
87#endif
88#ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
89 snd_hda_preset_atihdmi,
90#endif
91#ifdef CONFIG_SND_HDA_CODEC_CONEXANT
92 snd_hda_preset_conexant,
93#endif
94#ifdef CONFIG_SND_HDA_CODEC_VIA
95 snd_hda_preset_via,
96#endif
97 NULL
98};
69 99
70#ifdef CONFIG_SND_HDA_POWER_SAVE 100#ifdef CONFIG_SND_HDA_POWER_SAVE
71static void hda_power_work(struct work_struct *work); 101static void hda_power_work(struct work_struct *work);
@@ -690,6 +720,19 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
690 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format); 720 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
691} 721}
692 722
723void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
724{
725 if (!nid)
726 return;
727
728 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
729 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
730#if 0 /* keep the format */
731 msleep(1);
732 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
733#endif
734}
735
693/* 736/*
694 * amp access functions 737 * amp access functions
695 */ 738 */
@@ -1037,16 +1080,24 @@ void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1037} 1080}
1038 1081
1039/* find a mixer control element with the given name */ 1082/* find a mixer control element with the given name */
1040struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 1083static struct snd_kcontrol *
1041 const char *name) 1084_snd_hda_find_mixer_ctl(struct hda_codec *codec,
1085 const char *name, int idx)
1042{ 1086{
1043 struct snd_ctl_elem_id id; 1087 struct snd_ctl_elem_id id;
1044 memset(&id, 0, sizeof(id)); 1088 memset(&id, 0, sizeof(id));
1045 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1089 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1090 id.index = idx;
1046 strcpy(id.name, name); 1091 strcpy(id.name, name);
1047 return snd_ctl_find_id(codec->bus->card, &id); 1092 return snd_ctl_find_id(codec->bus->card, &id);
1048} 1093}
1049 1094
1095struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1096 const char *name)
1097{
1098 return _snd_hda_find_mixer_ctl(codec, name, 0);
1099}
1100
1050/* create a virtual master control and add slaves */ 1101/* create a virtual master control and add slaves */
1051int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1102int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1052 unsigned int *tlv, const char **slaves) 1103 unsigned int *tlv, const char **slaves)
@@ -1481,6 +1532,8 @@ static struct snd_kcontrol_new dig_mixes[] = {
1481 { } /* end */ 1532 { } /* end */
1482}; 1533};
1483 1534
1535#define SPDIF_MAX_IDX 4 /* 4 instances should be enough to probe */
1536
1484/** 1537/**
1485 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls 1538 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls
1486 * @codec: the HDA codec 1539 * @codec: the HDA codec
@@ -1496,9 +1549,20 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1496 int err; 1549 int err;
1497 struct snd_kcontrol *kctl; 1550 struct snd_kcontrol *kctl;
1498 struct snd_kcontrol_new *dig_mix; 1551 struct snd_kcontrol_new *dig_mix;
1552 int idx;
1499 1553
1554 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1555 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch",
1556 idx))
1557 break;
1558 }
1559 if (idx >= SPDIF_MAX_IDX) {
1560 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n");
1561 return -EBUSY;
1562 }
1500 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { 1563 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
1501 kctl = snd_ctl_new1(dig_mix, codec); 1564 kctl = snd_ctl_new1(dig_mix, codec);
1565 kctl->id.index = idx;
1502 kctl->private_value = nid; 1566 kctl->private_value = nid;
1503 err = snd_ctl_add(codec->bus->card, kctl); 1567 err = snd_ctl_add(codec->bus->card, kctl);
1504 if (err < 0) 1568 if (err < 0)
@@ -1512,6 +1576,43 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1512} 1576}
1513 1577
1514/* 1578/*
1579 * SPDIF sharing with analog output
1580 */
1581static int spdif_share_sw_get(struct snd_kcontrol *kcontrol,
1582 struct snd_ctl_elem_value *ucontrol)
1583{
1584 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
1585 ucontrol->value.integer.value[0] = mout->share_spdif;
1586 return 0;
1587}
1588
1589static int spdif_share_sw_put(struct snd_kcontrol *kcontrol,
1590 struct snd_ctl_elem_value *ucontrol)
1591{
1592 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
1593 mout->share_spdif = !!ucontrol->value.integer.value[0];
1594 return 0;
1595}
1596
1597static struct snd_kcontrol_new spdif_share_sw = {
1598 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1599 .name = "IEC958 Default PCM Playback Switch",
1600 .info = snd_ctl_boolean_mono_info,
1601 .get = spdif_share_sw_get,
1602 .put = spdif_share_sw_put,
1603};
1604
1605int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
1606 struct hda_multi_out *mout)
1607{
1608 if (!mout->dig_out_nid)
1609 return 0;
1610 /* ATTENTION: here mout is passed as private_data, instead of codec */
1611 return snd_ctl_add(codec->bus->card,
1612 snd_ctl_new1(&spdif_share_sw, mout));
1613}
1614
1615/*
1515 * SPDIF input 1616 * SPDIF input
1516 */ 1617 */
1517 1618
@@ -1595,7 +1696,17 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1595 int err; 1696 int err;
1596 struct snd_kcontrol *kctl; 1697 struct snd_kcontrol *kctl;
1597 struct snd_kcontrol_new *dig_mix; 1698 struct snd_kcontrol_new *dig_mix;
1699 int idx;
1598 1700
1701 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1702 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Capture Switch",
1703 idx))
1704 break;
1705 }
1706 if (idx >= SPDIF_MAX_IDX) {
1707 printk(KERN_ERR "hda_codec: too many IEC958 inputs\n");
1708 return -EBUSY;
1709 }
1599 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { 1710 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1600 kctl = snd_ctl_new1(dig_mix, codec); 1711 kctl = snd_ctl_new1(dig_mix, codec);
1601 kctl->private_value = nid; 1712 kctl->private_value = nid;
@@ -2106,7 +2217,7 @@ static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
2106 struct hda_codec *codec, 2217 struct hda_codec *codec,
2107 struct snd_pcm_substream *substream) 2218 struct snd_pcm_substream *substream)
2108{ 2219{
2109 snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0); 2220 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2110 return 0; 2221 return 0;
2111} 2222}
2112 2223
@@ -2491,7 +2602,7 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
2491 mutex_lock(&codec->spdif_mutex); 2602 mutex_lock(&codec->spdif_mutex);
2492 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP) 2603 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
2493 /* already opened as analog dup; reset it once */ 2604 /* already opened as analog dup; reset it once */
2494 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0); 2605 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2495 mout->dig_out_used = HDA_DIG_EXCLUSIVE; 2606 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
2496 mutex_unlock(&codec->spdif_mutex); 2607 mutex_unlock(&codec->spdif_mutex);
2497 return 0; 2608 return 0;
@@ -2526,9 +2637,36 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
2526 */ 2637 */
2527int snd_hda_multi_out_analog_open(struct hda_codec *codec, 2638int snd_hda_multi_out_analog_open(struct hda_codec *codec,
2528 struct hda_multi_out *mout, 2639 struct hda_multi_out *mout,
2529 struct snd_pcm_substream *substream) 2640 struct snd_pcm_substream *substream,
2530{ 2641 struct hda_pcm_stream *hinfo)
2531 substream->runtime->hw.channels_max = mout->max_channels; 2642{
2643 struct snd_pcm_runtime *runtime = substream->runtime;
2644 runtime->hw.channels_max = mout->max_channels;
2645 if (mout->dig_out_nid) {
2646 if (!mout->analog_rates) {
2647 mout->analog_rates = hinfo->rates;
2648 mout->analog_formats = hinfo->formats;
2649 mout->analog_maxbps = hinfo->maxbps;
2650 } else {
2651 runtime->hw.rates = mout->analog_rates;
2652 runtime->hw.formats = mout->analog_formats;
2653 hinfo->maxbps = mout->analog_maxbps;
2654 }
2655 if (!mout->spdif_rates) {
2656 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
2657 &mout->spdif_rates,
2658 &mout->spdif_formats,
2659 &mout->spdif_maxbps);
2660 }
2661 mutex_lock(&codec->spdif_mutex);
2662 if (mout->share_spdif) {
2663 runtime->hw.rates &= mout->spdif_rates;
2664 runtime->hw.formats &= mout->spdif_formats;
2665 if (mout->spdif_maxbps < hinfo->maxbps)
2666 hinfo->maxbps = mout->spdif_maxbps;
2667 }
2668 mutex_unlock(&codec->spdif_mutex);
2669 }
2532 return snd_pcm_hw_constraint_step(substream->runtime, 0, 2670 return snd_pcm_hw_constraint_step(substream->runtime, 0,
2533 SNDRV_PCM_HW_PARAM_CHANNELS, 2); 2671 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2534} 2672}
@@ -2548,7 +2686,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2548 int i; 2686 int i;
2549 2687
2550 mutex_lock(&codec->spdif_mutex); 2688 mutex_lock(&codec->spdif_mutex);
2551 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { 2689 if (mout->dig_out_nid && mout->share_spdif &&
2690 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
2552 if (chs == 2 && 2691 if (chs == 2 &&
2553 snd_hda_is_supported_format(codec, mout->dig_out_nid, 2692 snd_hda_is_supported_format(codec, mout->dig_out_nid,
2554 format) && 2693 format) &&
@@ -2558,8 +2697,7 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2558 stream_tag, format); 2697 stream_tag, format);
2559 } else { 2698 } else {
2560 mout->dig_out_used = 0; 2699 mout->dig_out_used = 0;
2561 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 2700 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2562 0, 0, 0);
2563 } 2701 }
2564 } 2702 }
2565 mutex_unlock(&codec->spdif_mutex); 2703 mutex_unlock(&codec->spdif_mutex);
@@ -2601,17 +2739,16 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2601 int i; 2739 int i;
2602 2740
2603 for (i = 0; i < mout->num_dacs; i++) 2741 for (i = 0; i < mout->num_dacs; i++)
2604 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); 2742 snd_hda_codec_cleanup_stream(codec, nids[i]);
2605 if (mout->hp_nid) 2743 if (mout->hp_nid)
2606 snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0); 2744 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
2607 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) 2745 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
2608 if (mout->extra_out_nid[i]) 2746 if (mout->extra_out_nid[i])
2609 snd_hda_codec_setup_stream(codec, 2747 snd_hda_codec_cleanup_stream(codec,
2610 mout->extra_out_nid[i], 2748 mout->extra_out_nid[i]);
2611 0, 0, 0);
2612 mutex_lock(&codec->spdif_mutex); 2749 mutex_lock(&codec->spdif_mutex);
2613 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) { 2750 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
2614 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0); 2751 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2615 mout->dig_out_used = 0; 2752 mout->dig_out_used = 0;
2616 } 2753 }
2617 mutex_unlock(&codec->spdif_mutex); 2754 mutex_unlock(&codec->spdif_mutex);
@@ -2790,6 +2927,30 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
2790 } 2927 }
2791 } 2928 }
2792 2929
2930 /* FIX-UP:
2931 * If no line-out is defined but multiple HPs are found,
2932 * some of them might be the real line-outs.
2933 */
2934 if (!cfg->line_outs && cfg->hp_outs > 1) {
2935 int i = 0;
2936 while (i < cfg->hp_outs) {
2937 /* The real HPs should have the sequence 0x0f */
2938 if ((sequences_hp[i] & 0x0f) == 0x0f) {
2939 i++;
2940 continue;
2941 }
2942 /* Move it to the line-out table */
2943 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
2944 sequences_line_out[cfg->line_outs] = sequences_hp[i];
2945 cfg->line_outs++;
2946 cfg->hp_outs--;
2947 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
2948 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
2949 memmove(sequences_hp + i - 1, sequences_hp + i,
2950 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
2951 }
2952 }
2953
2793 /* sort by sequence */ 2954 /* sort by sequence */
2794 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out, 2955 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
2795 cfg->line_outs); 2956 cfg->line_outs);
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index f14871151be9..dcd390b2bbaa 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -590,11 +590,21 @@ struct hda_pcm_stream {
590 struct hda_pcm_ops ops; 590 struct hda_pcm_ops ops;
591}; 591};
592 592
593/* PCM types */
594enum {
595 HDA_PCM_TYPE_AUDIO,
596 HDA_PCM_TYPE_SPDIF,
597 HDA_PCM_TYPE_HDMI,
598 HDA_PCM_TYPE_MODEM,
599 HDA_PCM_NTYPES
600};
601
593/* for PCM creation */ 602/* for PCM creation */
594struct hda_pcm { 603struct hda_pcm {
595 char *name; 604 char *name;
596 struct hda_pcm_stream stream[2]; 605 struct hda_pcm_stream stream[2];
597 unsigned int is_modem; /* modem codec? */ 606 unsigned int pcm_type; /* HDA_PCM_TYPE_XXX */
607 int device; /* assigned device number */
598}; 608};
599 609
600/* codec information */ 610/* codec information */
@@ -712,6 +722,7 @@ int snd_hda_build_pcms(struct hda_bus *bus);
712void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, 722void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
713 u32 stream_tag, 723 u32 stream_tag,
714 int channel_id, int format); 724 int channel_id, int format);
725void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid);
715unsigned int snd_hda_calc_stream_format(unsigned int rate, 726unsigned int snd_hda_calc_stream_format(unsigned int rate,
716 unsigned int channels, 727 unsigned int channels,
717 unsigned int format, 728 unsigned int format,
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index f9de7c467c25..59e4389c94a4 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -1007,8 +1007,8 @@ static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo,
1007{ 1007{
1008 struct hda_gspec *spec = codec->spec; 1008 struct hda_gspec *spec = codec->spec;
1009 1009
1010 snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0); 1010 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1011 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, 0, 0, 0); 1011 snd_hda_codec_cleanup_stream(codec, spec->dac_node[1]->nid);
1012 return 0; 1012 return 0;
1013} 1013}
1014 1014
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 4be36c84b36c..b3a618eb42cd 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -39,6 +39,7 @@
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/kernel.h> 40#include <linux/kernel.h>
41#include <linux/module.h> 41#include <linux/module.h>
42#include <linux/dma-mapping.h>
42#include <linux/moduleparam.h> 43#include <linux/moduleparam.h>
43#include <linux/init.h> 44#include <linux/init.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
@@ -185,35 +186,28 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
185 186
186/* max number of SDs */ 187/* max number of SDs */
187/* ICH, ATI and VIA have 4 playback and 4 capture */ 188/* ICH, ATI and VIA have 4 playback and 4 capture */
188#define ICH6_CAPTURE_INDEX 0
189#define ICH6_NUM_CAPTURE 4 189#define ICH6_NUM_CAPTURE 4
190#define ICH6_PLAYBACK_INDEX 4
191#define ICH6_NUM_PLAYBACK 4 190#define ICH6_NUM_PLAYBACK 4
192 191
193/* ULI has 6 playback and 5 capture */ 192/* ULI has 6 playback and 5 capture */
194#define ULI_CAPTURE_INDEX 0
195#define ULI_NUM_CAPTURE 5 193#define ULI_NUM_CAPTURE 5
196#define ULI_PLAYBACK_INDEX 5
197#define ULI_NUM_PLAYBACK 6 194#define ULI_NUM_PLAYBACK 6
198 195
199/* ATI HDMI has 1 playback and 0 capture */ 196/* ATI HDMI has 1 playback and 0 capture */
200#define ATIHDMI_CAPTURE_INDEX 0
201#define ATIHDMI_NUM_CAPTURE 0 197#define ATIHDMI_NUM_CAPTURE 0
202#define ATIHDMI_PLAYBACK_INDEX 0
203#define ATIHDMI_NUM_PLAYBACK 1 198#define ATIHDMI_NUM_PLAYBACK 1
204 199
205/* this number is statically defined for simplicity */ 200/* this number is statically defined for simplicity */
206#define MAX_AZX_DEV 16 201#define MAX_AZX_DEV 16
207 202
208/* max number of fragments - we may use more if allocating more pages for BDL */ 203/* max number of fragments - we may use more if allocating more pages for BDL */
209#define BDL_SIZE PAGE_ALIGN(8192) 204#define BDL_SIZE 4096
210#define AZX_MAX_FRAG (BDL_SIZE / (MAX_AZX_DEV * 16)) 205#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
206#define AZX_MAX_FRAG 32
211/* max buffer size - no h/w limit, you can increase as you like */ 207/* max buffer size - no h/w limit, you can increase as you like */
212#define AZX_MAX_BUF_SIZE (1024*1024*1024) 208#define AZX_MAX_BUF_SIZE (1024*1024*1024)
213/* max number of PCM devics per card */ 209/* max number of PCM devics per card */
214#define AZX_MAX_AUDIO_PCMS 6 210#define AZX_MAX_PCMS 8
215#define AZX_MAX_MODEM_PCMS 2
216#define AZX_MAX_PCMS (AZX_MAX_AUDIO_PCMS + AZX_MAX_MODEM_PCMS)
217 211
218/* RIRB int mask: overrun[2], response[0] */ 212/* RIRB int mask: overrun[2], response[0] */
219#define RIRB_INT_RESPONSE 0x01 213#define RIRB_INT_RESPONSE 0x01
@@ -227,6 +221,9 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
227/* SD_CTL bits */ 221/* SD_CTL bits */
228#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ 222#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
229#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */ 223#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
224#define SD_CTL_STRIPE (3 << 16) /* stripe control */
225#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
226#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
230#define SD_CTL_STREAM_TAG_MASK (0xf << 20) 227#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
231#define SD_CTL_STREAM_TAG_SHIFT 20 228#define SD_CTL_STREAM_TAG_SHIFT 20
232 229
@@ -284,12 +281,10 @@ enum {
284 */ 281 */
285 282
286struct azx_dev { 283struct azx_dev {
287 u32 *bdl; /* virtual address of the BDL */ 284 struct snd_dma_buffer bdl; /* BDL buffer */
288 dma_addr_t bdl_addr; /* physical address of the BDL */
289 u32 *posbuf; /* position buffer pointer */ 285 u32 *posbuf; /* position buffer pointer */
290 286
291 unsigned int bufsize; /* size of the play buffer in bytes */ 287 unsigned int bufsize; /* size of the play buffer in bytes */
292 unsigned int fragsize; /* size of each period in bytes */
293 unsigned int frags; /* number for period in the play buffer */ 288 unsigned int frags; /* number for period in the play buffer */
294 unsigned int fifo_size; /* FIFO size */ 289 unsigned int fifo_size; /* FIFO size */
295 290
@@ -350,7 +345,6 @@ struct azx {
350 struct azx_dev *azx_dev; 345 struct azx_dev *azx_dev;
351 346
352 /* PCM */ 347 /* PCM */
353 unsigned int pcm_devs;
354 struct snd_pcm *pcm[AZX_MAX_PCMS]; 348 struct snd_pcm *pcm[AZX_MAX_PCMS];
355 349
356 /* HD codec */ 350 /* HD codec */
@@ -361,8 +355,7 @@ struct azx {
361 struct azx_rb corb; 355 struct azx_rb corb;
362 struct azx_rb rirb; 356 struct azx_rb rirb;
363 357
364 /* BDL, CORB/RIRB and position buffers */ 358 /* CORB/RIRB and position buffers */
365 struct snd_dma_buffer bdl;
366 struct snd_dma_buffer rb; 359 struct snd_dma_buffer rb;
367 struct snd_dma_buffer posbuf; 360 struct snd_dma_buffer posbuf;
368 361
@@ -546,8 +539,9 @@ static void azx_update_rirb(struct azx *chip)
546 if (res_ex & ICH6_RIRB_EX_UNSOL_EV) 539 if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
547 snd_hda_queue_unsol_event(chip->bus, res, res_ex); 540 snd_hda_queue_unsol_event(chip->bus, res, res_ex);
548 else if (chip->rirb.cmds) { 541 else if (chip->rirb.cmds) {
549 chip->rirb.cmds--;
550 chip->rirb.res = res; 542 chip->rirb.res = res;
543 smp_wmb();
544 chip->rirb.cmds--;
551 } 545 }
552 } 546 }
553} 547}
@@ -566,8 +560,10 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec)
566 azx_update_rirb(chip); 560 azx_update_rirb(chip);
567 spin_unlock_irq(&chip->reg_lock); 561 spin_unlock_irq(&chip->reg_lock);
568 } 562 }
569 if (!chip->rirb.cmds) 563 if (!chip->rirb.cmds) {
564 smp_rmb();
570 return chip->rirb.res; /* the last value */ 565 return chip->rirb.res; /* the last value */
566 }
571 if (time_after(jiffies, timeout)) 567 if (time_after(jiffies, timeout))
572 break; 568 break;
573 if (codec->bus->needs_damn_long_delay) 569 if (codec->bus->needs_damn_long_delay)
@@ -965,30 +961,57 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
965/* 961/*
966 * set up BDL entries 962 * set up BDL entries
967 */ 963 */
968static void azx_setup_periods(struct azx_dev *azx_dev) 964static int azx_setup_periods(struct snd_pcm_substream *substream,
965 struct azx_dev *azx_dev)
969{ 966{
970 u32 *bdl = azx_dev->bdl; 967 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
971 dma_addr_t dma_addr = azx_dev->substream->runtime->dma_addr; 968 u32 *bdl;
972 int idx; 969 int i, ofs, periods, period_bytes;
973 970
974 /* reset BDL address */ 971 /* reset BDL address */
975 azx_sd_writel(azx_dev, SD_BDLPL, 0); 972 azx_sd_writel(azx_dev, SD_BDLPL, 0);
976 azx_sd_writel(azx_dev, SD_BDLPU, 0); 973 azx_sd_writel(azx_dev, SD_BDLPU, 0);
977 974
975 period_bytes = snd_pcm_lib_period_bytes(substream);
976 periods = azx_dev->bufsize / period_bytes;
977
978 /* program the initial BDL entries */ 978 /* program the initial BDL entries */
979 for (idx = 0; idx < azx_dev->frags; idx++) { 979 bdl = (u32 *)azx_dev->bdl.area;
980 unsigned int off = idx << 2; /* 4 dword step */ 980 ofs = 0;
981 dma_addr_t addr = dma_addr + idx * azx_dev->fragsize; 981 azx_dev->frags = 0;
982 /* program the address field of the BDL entry */ 982 for (i = 0; i < periods; i++) {
983 bdl[off] = cpu_to_le32((u32)addr); 983 int size, rest;
984 bdl[off+1] = cpu_to_le32(upper_32bit(addr)); 984 if (i >= AZX_MAX_BDL_ENTRIES) {
985 985 snd_printk(KERN_ERR "Too many BDL entries: "
986 /* program the size field of the BDL entry */ 986 "buffer=%d, period=%d\n",
987 bdl[off+2] = cpu_to_le32(azx_dev->fragsize); 987 azx_dev->bufsize, period_bytes);
988 988 /* reset */
989 /* program the IOC to enable interrupt when buffer completes */ 989 azx_sd_writel(azx_dev, SD_BDLPL, 0);
990 bdl[off+3] = cpu_to_le32(0x01); 990 azx_sd_writel(azx_dev, SD_BDLPU, 0);
991 return -EINVAL;
992 }
993 rest = period_bytes;
994 do {
995 dma_addr_t addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs);
996 /* program the address field of the BDL entry */
997 bdl[0] = cpu_to_le32((u32)addr);
998 bdl[1] = cpu_to_le32(upper_32bit(addr));
999 /* program the size field of the BDL entry */
1000 size = PAGE_SIZE - (ofs % PAGE_SIZE);
1001 if (rest < size)
1002 size = rest;
1003 bdl[2] = cpu_to_le32(size);
1004 /* program the IOC to enable interrupt
1005 * only when the whole fragment is processed
1006 */
1007 rest -= size;
1008 bdl[3] = rest ? 0 : cpu_to_le32(0x01);
1009 bdl += 4;
1010 azx_dev->frags++;
1011 ofs += size;
1012 } while (rest > 0);
991 } 1013 }
1014 return 0;
992} 1015}
993 1016
994/* 1017/*
@@ -1037,14 +1060,17 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1037 1060
1038 /* program the BDL address */ 1061 /* program the BDL address */
1039 /* lower BDL address */ 1062 /* lower BDL address */
1040 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl_addr); 1063 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
1041 /* upper BDL address */ 1064 /* upper BDL address */
1042 azx_sd_writel(azx_dev, SD_BDLPU, upper_32bit(azx_dev->bdl_addr)); 1065 azx_sd_writel(azx_dev, SD_BDLPU, upper_32bit(azx_dev->bdl.addr));
1043 1066
1044 /* enable the position buffer */ 1067 /* enable the position buffer */
1045 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE)) 1068 if (chip->position_fix == POS_FIX_POSBUF ||
1046 azx_writel(chip, DPLBASE, 1069 chip->position_fix == POS_FIX_AUTO) {
1047 (u32)chip->posbuf.addr |ICH6_DPLBASE_ENABLE); 1070 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
1071 azx_writel(chip, DPLBASE,
1072 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
1073 }
1048 1074
1049 /* set the interrupt enable bits in the descriptor control register */ 1075 /* set the interrupt enable bits in the descriptor control register */
1050 azx_sd_writel(azx_dev, SD_CTL, 1076 azx_sd_writel(azx_dev, SD_CTL,
@@ -1157,7 +1183,8 @@ static struct snd_pcm_hardware azx_pcm_hw = {
1157 SNDRV_PCM_INFO_MMAP_VALID | 1183 SNDRV_PCM_INFO_MMAP_VALID |
1158 /* No full-resume yet implemented */ 1184 /* No full-resume yet implemented */
1159 /* SNDRV_PCM_INFO_RESUME |*/ 1185 /* SNDRV_PCM_INFO_RESUME |*/
1160 SNDRV_PCM_INFO_PAUSE), 1186 SNDRV_PCM_INFO_PAUSE |
1187 SNDRV_PCM_INFO_SYNC_START),
1161 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1188 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1162 .rates = SNDRV_PCM_RATE_48000, 1189 .rates = SNDRV_PCM_RATE_48000,
1163 .rate_min = 48000, 1190 .rate_min = 48000,
@@ -1219,6 +1246,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1219 spin_unlock_irqrestore(&chip->reg_lock, flags); 1246 spin_unlock_irqrestore(&chip->reg_lock, flags);
1220 1247
1221 runtime->private_data = azx_dev; 1248 runtime->private_data = azx_dev;
1249 snd_pcm_set_sync(substream);
1222 mutex_unlock(&chip->open_mutex); 1250 mutex_unlock(&chip->open_mutex);
1223 return 0; 1251 return 0;
1224} 1252}
@@ -1275,8 +1303,6 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1275 struct snd_pcm_runtime *runtime = substream->runtime; 1303 struct snd_pcm_runtime *runtime = substream->runtime;
1276 1304
1277 azx_dev->bufsize = snd_pcm_lib_buffer_bytes(substream); 1305 azx_dev->bufsize = snd_pcm_lib_buffer_bytes(substream);
1278 azx_dev->fragsize = snd_pcm_lib_period_bytes(substream);
1279 azx_dev->frags = azx_dev->bufsize / azx_dev->fragsize;
1280 azx_dev->format_val = snd_hda_calc_stream_format(runtime->rate, 1306 azx_dev->format_val = snd_hda_calc_stream_format(runtime->rate,
1281 runtime->channels, 1307 runtime->channels,
1282 runtime->format, 1308 runtime->format,
@@ -1288,10 +1314,10 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1288 return -EINVAL; 1314 return -EINVAL;
1289 } 1315 }
1290 1316
1291 snd_printdd("azx_pcm_prepare: bufsize=0x%x, fragsize=0x%x, " 1317 snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
1292 "format=0x%x\n", 1318 azx_dev->bufsize, azx_dev->format_val);
1293 azx_dev->bufsize, azx_dev->fragsize, azx_dev->format_val); 1319 if (azx_setup_periods(substream, azx_dev) < 0)
1294 azx_setup_periods(azx_dev); 1320 return -EINVAL;
1295 azx_setup_controller(chip, azx_dev); 1321 azx_setup_controller(chip, azx_dev);
1296 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1322 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1297 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1; 1323 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
@@ -1305,37 +1331,94 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1305static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 1331static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1306{ 1332{
1307 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1333 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1308 struct azx_dev *azx_dev = get_azx_dev(substream);
1309 struct azx *chip = apcm->chip; 1334 struct azx *chip = apcm->chip;
1310 int err = 0; 1335 struct azx_dev *azx_dev;
1336 struct snd_pcm_substream *s;
1337 int start, nsync = 0, sbits = 0;
1338 int nwait, timeout;
1311 1339
1312 spin_lock(&chip->reg_lock);
1313 switch (cmd) { 1340 switch (cmd) {
1314 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1341 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1315 case SNDRV_PCM_TRIGGER_RESUME: 1342 case SNDRV_PCM_TRIGGER_RESUME:
1316 case SNDRV_PCM_TRIGGER_START: 1343 case SNDRV_PCM_TRIGGER_START:
1317 azx_stream_start(chip, azx_dev); 1344 start = 1;
1318 azx_dev->running = 1;
1319 break; 1345 break;
1320 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1346 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1321 case SNDRV_PCM_TRIGGER_SUSPEND: 1347 case SNDRV_PCM_TRIGGER_SUSPEND:
1322 case SNDRV_PCM_TRIGGER_STOP: 1348 case SNDRV_PCM_TRIGGER_STOP:
1323 azx_stream_stop(chip, azx_dev); 1349 start = 0;
1324 azx_dev->running = 0;
1325 break; 1350 break;
1326 default: 1351 default:
1327 err = -EINVAL; 1352 return -EINVAL;
1353 }
1354
1355 snd_pcm_group_for_each_entry(s, substream) {
1356 if (s->pcm->card != substream->pcm->card)
1357 continue;
1358 azx_dev = get_azx_dev(s);
1359 sbits |= 1 << azx_dev->index;
1360 nsync++;
1361 snd_pcm_trigger_done(s, substream);
1362 }
1363
1364 spin_lock(&chip->reg_lock);
1365 if (nsync > 1) {
1366 /* first, set SYNC bits of corresponding streams */
1367 azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
1368 }
1369 snd_pcm_group_for_each_entry(s, substream) {
1370 if (s->pcm->card != substream->pcm->card)
1371 continue;
1372 azx_dev = get_azx_dev(s);
1373 if (start)
1374 azx_stream_start(chip, azx_dev);
1375 else
1376 azx_stream_stop(chip, azx_dev);
1377 azx_dev->running = start;
1328 } 1378 }
1329 spin_unlock(&chip->reg_lock); 1379 spin_unlock(&chip->reg_lock);
1330 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH || 1380 if (start) {
1331 cmd == SNDRV_PCM_TRIGGER_SUSPEND || 1381 if (nsync == 1)
1332 cmd == SNDRV_PCM_TRIGGER_STOP) { 1382 return 0;
1333 int timeout = 5000; 1383 /* wait until all FIFOs get ready */
1334 while ((azx_sd_readb(azx_dev, SD_CTL) & SD_CTL_DMA_START) && 1384 for (timeout = 5000; timeout; timeout--) {
1335 --timeout) 1385 nwait = 0;
1336 ; 1386 snd_pcm_group_for_each_entry(s, substream) {
1387 if (s->pcm->card != substream->pcm->card)
1388 continue;
1389 azx_dev = get_azx_dev(s);
1390 if (!(azx_sd_readb(azx_dev, SD_STS) &
1391 SD_STS_FIFO_READY))
1392 nwait++;
1393 }
1394 if (!nwait)
1395 break;
1396 cpu_relax();
1397 }
1398 } else {
1399 /* wait until all RUN bits are cleared */
1400 for (timeout = 5000; timeout; timeout--) {
1401 nwait = 0;
1402 snd_pcm_group_for_each_entry(s, substream) {
1403 if (s->pcm->card != substream->pcm->card)
1404 continue;
1405 azx_dev = get_azx_dev(s);
1406 if (azx_sd_readb(azx_dev, SD_CTL) &
1407 SD_CTL_DMA_START)
1408 nwait++;
1409 }
1410 if (!nwait)
1411 break;
1412 cpu_relax();
1413 }
1337 } 1414 }
1338 return err; 1415 if (nsync > 1) {
1416 spin_lock(&chip->reg_lock);
1417 /* reset SYNC bits */
1418 azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
1419 spin_unlock(&chip->reg_lock);
1420 }
1421 return 0;
1339} 1422}
1340 1423
1341static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) 1424static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
@@ -1378,6 +1461,7 @@ static struct snd_pcm_ops azx_pcm_ops = {
1378 .prepare = azx_pcm_prepare, 1461 .prepare = azx_pcm_prepare,
1379 .trigger = azx_pcm_trigger, 1462 .trigger = azx_pcm_trigger,
1380 .pointer = azx_pcm_pointer, 1463 .pointer = azx_pcm_pointer,
1464 .page = snd_pcm_sgbuf_ops_page,
1381}; 1465};
1382 1466
1383static void azx_pcm_free(struct snd_pcm *pcm) 1467static void azx_pcm_free(struct snd_pcm *pcm)
@@ -1386,7 +1470,7 @@ static void azx_pcm_free(struct snd_pcm *pcm)
1386} 1470}
1387 1471
1388static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec, 1472static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1389 struct hda_pcm *cpcm, int pcm_dev) 1473 struct hda_pcm *cpcm)
1390{ 1474{
1391 int err; 1475 int err;
1392 struct snd_pcm *pcm; 1476 struct snd_pcm *pcm;
@@ -1400,7 +1484,7 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1400 1484
1401 snd_assert(cpcm->name, return -EINVAL); 1485 snd_assert(cpcm->name, return -EINVAL);
1402 1486
1403 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, 1487 err = snd_pcm_new(chip->card, cpcm->name, cpcm->device,
1404 cpcm->stream[0].substreams, 1488 cpcm->stream[0].substreams,
1405 cpcm->stream[1].substreams, 1489 cpcm->stream[1].substreams,
1406 &pcm); 1490 &pcm);
@@ -1420,62 +1504,70 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1420 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops); 1504 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops);
1421 if (cpcm->stream[1].substreams) 1505 if (cpcm->stream[1].substreams)
1422 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops); 1506 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops);
1423 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 1507 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1424 snd_dma_pci_data(chip->pci), 1508 snd_dma_pci_data(chip->pci),
1425 1024 * 64, 1024 * 1024); 1509 1024 * 64, 1024 * 1024);
1426 chip->pcm[pcm_dev] = pcm; 1510 chip->pcm[cpcm->device] = pcm;
1427 if (chip->pcm_devs < pcm_dev + 1)
1428 chip->pcm_devs = pcm_dev + 1;
1429
1430 return 0; 1511 return 0;
1431} 1512}
1432 1513
1433static int __devinit azx_pcm_create(struct azx *chip) 1514static int __devinit azx_pcm_create(struct azx *chip)
1434{ 1515{
1516 static const char *dev_name[HDA_PCM_NTYPES] = {
1517 "Audio", "SPDIF", "HDMI", "Modem"
1518 };
1519 /* starting device index for each PCM type */
1520 static int dev_idx[HDA_PCM_NTYPES] = {
1521 [HDA_PCM_TYPE_AUDIO] = 0,
1522 [HDA_PCM_TYPE_SPDIF] = 1,
1523 [HDA_PCM_TYPE_HDMI] = 3,
1524 [HDA_PCM_TYPE_MODEM] = 6
1525 };
1526 /* normal audio device indices; not linear to keep compatibility */
1527 static int audio_idx[4] = { 0, 2, 4, 5 };
1435 struct hda_codec *codec; 1528 struct hda_codec *codec;
1436 int c, err; 1529 int c, err;
1437 int pcm_dev; 1530 int num_devs[HDA_PCM_NTYPES];
1438 1531
1439 err = snd_hda_build_pcms(chip->bus); 1532 err = snd_hda_build_pcms(chip->bus);
1440 if (err < 0) 1533 if (err < 0)
1441 return err; 1534 return err;
1442 1535
1443 /* create audio PCMs */ 1536 /* create audio PCMs */
1444 pcm_dev = 0; 1537 memset(num_devs, 0, sizeof(num_devs));
1445 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1446 for (c = 0; c < codec->num_pcms; c++) {
1447 if (codec->pcm_info[c].is_modem)
1448 continue; /* create later */
1449 if (pcm_dev >= AZX_MAX_AUDIO_PCMS) {
1450 snd_printk(KERN_ERR SFX
1451 "Too many audio PCMs\n");
1452 return -EINVAL;
1453 }
1454 err = create_codec_pcm(chip, codec,
1455 &codec->pcm_info[c], pcm_dev);
1456 if (err < 0)
1457 return err;
1458 pcm_dev++;
1459 }
1460 }
1461
1462 /* create modem PCMs */
1463 pcm_dev = AZX_MAX_AUDIO_PCMS;
1464 list_for_each_entry(codec, &chip->bus->codec_list, list) { 1538 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1465 for (c = 0; c < codec->num_pcms; c++) { 1539 for (c = 0; c < codec->num_pcms; c++) {
1466 if (!codec->pcm_info[c].is_modem) 1540 struct hda_pcm *cpcm = &codec->pcm_info[c];
1467 continue; /* already created */ 1541 int type = cpcm->pcm_type;
1468 if (pcm_dev >= AZX_MAX_PCMS) { 1542 switch (type) {
1469 snd_printk(KERN_ERR SFX 1543 case HDA_PCM_TYPE_AUDIO:
1470 "Too many modem PCMs\n"); 1544 if (num_devs[type] >= ARRAY_SIZE(audio_idx)) {
1471 return -EINVAL; 1545 snd_printk(KERN_WARNING
1546 "Too many audio devices\n");
1547 continue;
1548 }
1549 cpcm->device = audio_idx[num_devs[type]];
1550 break;
1551 case HDA_PCM_TYPE_SPDIF:
1552 case HDA_PCM_TYPE_HDMI:
1553 case HDA_PCM_TYPE_MODEM:
1554 if (num_devs[type]) {
1555 snd_printk(KERN_WARNING
1556 "%s already defined\n",
1557 dev_name[type]);
1558 continue;
1559 }
1560 cpcm->device = dev_idx[type];
1561 break;
1562 default:
1563 snd_printk(KERN_WARNING
1564 "Invalid PCM type %d\n", type);
1565 continue;
1472 } 1566 }
1473 err = create_codec_pcm(chip, codec, 1567 num_devs[type]++;
1474 &codec->pcm_info[c], pcm_dev); 1568 err = create_codec_pcm(chip, codec, cpcm);
1475 if (err < 0) 1569 if (err < 0)
1476 return err; 1570 return err;
1477 chip->pcm[pcm_dev]->dev_class = SNDRV_PCM_CLASS_MODEM;
1478 pcm_dev++;
1479 } 1571 }
1480 } 1572 }
1481 return 0; 1573 return 0;
@@ -1502,10 +1594,7 @@ static int __devinit azx_init_stream(struct azx *chip)
1502 * and initialize 1594 * and initialize
1503 */ 1595 */
1504 for (i = 0; i < chip->num_streams; i++) { 1596 for (i = 0; i < chip->num_streams; i++) {
1505 unsigned int off = sizeof(u32) * (i * AZX_MAX_FRAG * 4);
1506 struct azx_dev *azx_dev = &chip->azx_dev[i]; 1597 struct azx_dev *azx_dev = &chip->azx_dev[i];
1507 azx_dev->bdl = (u32 *)(chip->bdl.area + off);
1508 azx_dev->bdl_addr = chip->bdl.addr + off;
1509 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); 1598 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
1510 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ 1599 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
1511 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); 1600 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
@@ -1587,13 +1676,12 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
1587 int i; 1676 int i;
1588 1677
1589 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1678 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1590 for (i = 0; i < chip->pcm_devs; i++) 1679 for (i = 0; i < AZX_MAX_PCMS; i++)
1591 snd_pcm_suspend_all(chip->pcm[i]); 1680 snd_pcm_suspend_all(chip->pcm[i]);
1592 if (chip->initialized) 1681 if (chip->initialized)
1593 snd_hda_suspend(chip->bus, state); 1682 snd_hda_suspend(chip->bus, state);
1594 azx_stop_chip(chip); 1683 azx_stop_chip(chip);
1595 if (chip->irq >= 0) { 1684 if (chip->irq >= 0) {
1596 synchronize_irq(chip->irq);
1597 free_irq(chip->irq, chip); 1685 free_irq(chip->irq, chip);
1598 chip->irq = -1; 1686 chip->irq = -1;
1599 } 1687 }
@@ -1641,24 +1729,26 @@ static int azx_resume(struct pci_dev *pci)
1641 */ 1729 */
1642static int azx_free(struct azx *chip) 1730static int azx_free(struct azx *chip)
1643{ 1731{
1732 int i;
1733
1644 if (chip->initialized) { 1734 if (chip->initialized) {
1645 int i;
1646 for (i = 0; i < chip->num_streams; i++) 1735 for (i = 0; i < chip->num_streams; i++)
1647 azx_stream_stop(chip, &chip->azx_dev[i]); 1736 azx_stream_stop(chip, &chip->azx_dev[i]);
1648 azx_stop_chip(chip); 1737 azx_stop_chip(chip);
1649 } 1738 }
1650 1739
1651 if (chip->irq >= 0) { 1740 if (chip->irq >= 0)
1652 synchronize_irq(chip->irq);
1653 free_irq(chip->irq, (void*)chip); 1741 free_irq(chip->irq, (void*)chip);
1654 }
1655 if (chip->msi) 1742 if (chip->msi)
1656 pci_disable_msi(chip->pci); 1743 pci_disable_msi(chip->pci);
1657 if (chip->remap_addr) 1744 if (chip->remap_addr)
1658 iounmap(chip->remap_addr); 1745 iounmap(chip->remap_addr);
1659 1746
1660 if (chip->bdl.area) 1747 if (chip->azx_dev) {
1661 snd_dma_free_pages(&chip->bdl); 1748 for (i = 0; i < chip->num_streams; i++)
1749 if (chip->azx_dev[i].bdl.area)
1750 snd_dma_free_pages(&chip->azx_dev[i].bdl);
1751 }
1662 if (chip->rb.area) 1752 if (chip->rb.area)
1663 snd_dma_free_pages(&chip->rb); 1753 snd_dma_free_pages(&chip->rb);
1664 if (chip->posbuf.area) 1754 if (chip->posbuf.area)
@@ -1682,6 +1772,7 @@ static int azx_dev_free(struct snd_device *device)
1682static struct snd_pci_quirk position_fix_list[] __devinitdata = { 1772static struct snd_pci_quirk position_fix_list[] __devinitdata = {
1683 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_NONE), 1773 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_NONE),
1684 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_NONE), 1774 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_NONE),
1775 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_NONE),
1685 {} 1776 {}
1686}; 1777};
1687 1778
@@ -1740,7 +1831,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1740 struct azx **rchip) 1831 struct azx **rchip)
1741{ 1832{
1742 struct azx *chip; 1833 struct azx *chip;
1743 int err; 1834 int i, err;
1744 unsigned short gcap; 1835 unsigned short gcap;
1745 static struct snd_device_ops ops = { 1836 static struct snd_device_ops ops = {
1746 .dev_free = azx_dev_free, 1837 .dev_free = azx_dev_free,
@@ -1812,38 +1903,35 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1812 gcap = azx_readw(chip, GCAP); 1903 gcap = azx_readw(chip, GCAP);
1813 snd_printdd("chipset global capabilities = 0x%x\n", gcap); 1904 snd_printdd("chipset global capabilities = 0x%x\n", gcap);
1814 1905
1815 if (gcap) { 1906 /* allow 64bit DMA address if supported by H/W */
1816 /* read number of streams from GCAP register instead of using 1907 if ((gcap & 0x01) && !pci_set_dma_mask(pci, DMA_64BIT_MASK))
1817 * hardcoded value 1908 pci_set_consistent_dma_mask(pci, DMA_64BIT_MASK);
1818 */ 1909
1819 chip->playback_streams = (gcap & (0xF << 12)) >> 12; 1910 /* read number of streams from GCAP register instead of using
1820 chip->capture_streams = (gcap & (0xF << 8)) >> 8; 1911 * hardcoded value
1821 chip->playback_index_offset = chip->capture_streams; 1912 */
1822 chip->capture_index_offset = 0; 1913 chip->capture_streams = (gcap >> 8) & 0x0f;
1823 } else { 1914 chip->playback_streams = (gcap >> 12) & 0x0f;
1915 if (!chip->playback_streams && !chip->capture_streams) {
1824 /* gcap didn't give any info, switching to old method */ 1916 /* gcap didn't give any info, switching to old method */
1825 1917
1826 switch (chip->driver_type) { 1918 switch (chip->driver_type) {
1827 case AZX_DRIVER_ULI: 1919 case AZX_DRIVER_ULI:
1828 chip->playback_streams = ULI_NUM_PLAYBACK; 1920 chip->playback_streams = ULI_NUM_PLAYBACK;
1829 chip->capture_streams = ULI_NUM_CAPTURE; 1921 chip->capture_streams = ULI_NUM_CAPTURE;
1830 chip->playback_index_offset = ULI_PLAYBACK_INDEX;
1831 chip->capture_index_offset = ULI_CAPTURE_INDEX;
1832 break; 1922 break;
1833 case AZX_DRIVER_ATIHDMI: 1923 case AZX_DRIVER_ATIHDMI:
1834 chip->playback_streams = ATIHDMI_NUM_PLAYBACK; 1924 chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
1835 chip->capture_streams = ATIHDMI_NUM_CAPTURE; 1925 chip->capture_streams = ATIHDMI_NUM_CAPTURE;
1836 chip->playback_index_offset = ATIHDMI_PLAYBACK_INDEX;
1837 chip->capture_index_offset = ATIHDMI_CAPTURE_INDEX;
1838 break; 1926 break;
1839 default: 1927 default:
1840 chip->playback_streams = ICH6_NUM_PLAYBACK; 1928 chip->playback_streams = ICH6_NUM_PLAYBACK;
1841 chip->capture_streams = ICH6_NUM_CAPTURE; 1929 chip->capture_streams = ICH6_NUM_CAPTURE;
1842 chip->playback_index_offset = ICH6_PLAYBACK_INDEX;
1843 chip->capture_index_offset = ICH6_CAPTURE_INDEX;
1844 break; 1930 break;
1845 } 1931 }
1846 } 1932 }
1933 chip->capture_index_offset = 0;
1934 chip->playback_index_offset = chip->capture_streams;
1847 chip->num_streams = chip->playback_streams + chip->capture_streams; 1935 chip->num_streams = chip->playback_streams + chip->capture_streams;
1848 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), 1936 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
1849 GFP_KERNEL); 1937 GFP_KERNEL);
@@ -1852,13 +1940,15 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1852 goto errout; 1940 goto errout;
1853 } 1941 }
1854 1942
1855 /* allocate memory for the BDL for each stream */ 1943 for (i = 0; i < chip->num_streams; i++) {
1856 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 1944 /* allocate memory for the BDL for each stream */
1857 snd_dma_pci_data(chip->pci), 1945 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
1858 BDL_SIZE, &chip->bdl); 1946 snd_dma_pci_data(chip->pci),
1859 if (err < 0) { 1947 BDL_SIZE, &chip->azx_dev[i].bdl);
1860 snd_printk(KERN_ERR SFX "cannot allocate BDL\n"); 1948 if (err < 0) {
1861 goto errout; 1949 snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
1950 goto errout;
1951 }
1862 } 1952 }
1863 /* allocate memory for the position buffer */ 1953 /* allocate memory for the position buffer */
1864 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 1954 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
@@ -1994,48 +2084,63 @@ static void __devexit azx_remove(struct pci_dev *pci)
1994 2084
1995/* PCI IDs */ 2085/* PCI IDs */
1996static struct pci_device_id azx_ids[] = { 2086static struct pci_device_id azx_ids[] = {
1997 { 0x8086, 0x2668, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH6 */ 2087 /* ICH 6..10 */
1998 { 0x8086, 0x27d8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH7 */ 2088 { PCI_DEVICE(0x8086, 0x2668), .driver_data = AZX_DRIVER_ICH },
1999 { 0x8086, 0x269a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ESB2 */ 2089 { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH },
2000 { 0x8086, 0x284b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH8 */ 2090 { PCI_DEVICE(0x8086, 0x269a), .driver_data = AZX_DRIVER_ICH },
2001 { 0x8086, 0x293e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH9 */ 2091 { PCI_DEVICE(0x8086, 0x284b), .driver_data = AZX_DRIVER_ICH },
2002 { 0x8086, 0x293f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH9 */ 2092 { PCI_DEVICE(0x8086, 0x293e), .driver_data = AZX_DRIVER_ICH },
2003 { 0x8086, 0x3a3e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH10 */ 2093 { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH },
2004 { 0x8086, 0x3a6e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH10 */ 2094 { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH },
2005 { 0x8086, 0x811b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SCH }, /* SCH*/ 2095 { PCI_DEVICE(0x8086, 0x3a6e), .driver_data = AZX_DRIVER_ICH },
2006 { 0x1002, 0x437b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB450 */ 2096 /* SCH */
2007 { 0x1002, 0x4383, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB600 */ 2097 { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
2008 { 0x1002, 0x793b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS600 HDMI */ 2098 /* ATI SB 450/600 */
2009 { 0x1002, 0x7919, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS690 HDMI */ 2099 { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
2010 { 0x1002, 0x960f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS780 HDMI */ 2100 { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
2011 { 0x1002, 0xaa00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI R600 HDMI */ 2101 /* ATI HDMI */
2012 { 0x1002, 0xaa08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV630 HDMI */ 2102 { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
2013 { 0x1002, 0xaa10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV610 HDMI */ 2103 { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
2014 { 0x1002, 0xaa18, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV670 HDMI */ 2104 { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
2015 { 0x1002, 0xaa20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV635 HDMI */ 2105 { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
2016 { 0x1002, 0xaa28, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV620 HDMI */ 2106 { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
2017 { 0x1002, 0xaa30, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV770 HDMI */ 2107 { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
2018 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */ 2108 { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
2019 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */ 2109 { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
2020 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */ 2110 { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
2021 { 0x10de, 0x026c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP51 */ 2111 { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
2022 { 0x10de, 0x0371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP55 */ 2112 { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
2023 { 0x10de, 0x03e4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP61 */ 2113 { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
2024 { 0x10de, 0x03f0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP61 */ 2114 { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
2025 { 0x10de, 0x044a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP65 */ 2115 /* VIA VT8251/VT8237A */
2026 { 0x10de, 0x044b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP65 */ 2116 { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
2027 { 0x10de, 0x055c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP67 */ 2117 /* SIS966 */
2028 { 0x10de, 0x055d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP67 */ 2118 { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
2029 { 0x10de, 0x07fc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP73 */ 2119 /* ULI M5461 */
2030 { 0x10de, 0x07fd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP73 */ 2120 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
2031 { 0x10de, 0x0774, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2121 /* NVIDIA MCP */
2032 { 0x10de, 0x0775, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2122 { PCI_DEVICE(0x10de, 0x026c), .driver_data = AZX_DRIVER_NVIDIA },
2033 { 0x10de, 0x0776, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2123 { PCI_DEVICE(0x10de, 0x0371), .driver_data = AZX_DRIVER_NVIDIA },
2034 { 0x10de, 0x0777, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2124 { PCI_DEVICE(0x10de, 0x03e4), .driver_data = AZX_DRIVER_NVIDIA },
2035 { 0x10de, 0x0ac0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2125 { PCI_DEVICE(0x10de, 0x03f0), .driver_data = AZX_DRIVER_NVIDIA },
2036 { 0x10de, 0x0ac1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2126 { PCI_DEVICE(0x10de, 0x044a), .driver_data = AZX_DRIVER_NVIDIA },
2037 { 0x10de, 0x0ac2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2127 { PCI_DEVICE(0x10de, 0x044b), .driver_data = AZX_DRIVER_NVIDIA },
2038 { 0x10de, 0x0ac3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2128 { PCI_DEVICE(0x10de, 0x055c), .driver_data = AZX_DRIVER_NVIDIA },
2129 { PCI_DEVICE(0x10de, 0x055d), .driver_data = AZX_DRIVER_NVIDIA },
2130 { PCI_DEVICE(0x10de, 0x0774), .driver_data = AZX_DRIVER_NVIDIA },
2131 { PCI_DEVICE(0x10de, 0x0775), .driver_data = AZX_DRIVER_NVIDIA },
2132 { PCI_DEVICE(0x10de, 0x0776), .driver_data = AZX_DRIVER_NVIDIA },
2133 { PCI_DEVICE(0x10de, 0x0777), .driver_data = AZX_DRIVER_NVIDIA },
2134 { PCI_DEVICE(0x10de, 0x07fc), .driver_data = AZX_DRIVER_NVIDIA },
2135 { PCI_DEVICE(0x10de, 0x07fd), .driver_data = AZX_DRIVER_NVIDIA },
2136 { PCI_DEVICE(0x10de, 0x0ac0), .driver_data = AZX_DRIVER_NVIDIA },
2137 { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA },
2138 { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA },
2139 { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA },
2140 { PCI_DEVICE(0x10de, 0x0bd4), .driver_data = AZX_DRIVER_NVIDIA },
2141 { PCI_DEVICE(0x10de, 0x0bd5), .driver_data = AZX_DRIVER_NVIDIA },
2142 { PCI_DEVICE(0x10de, 0x0bd6), .driver_data = AZX_DRIVER_NVIDIA },
2143 { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA },
2039 { 0, } 2144 { 0, }
2040}; 2145};
2041MODULE_DEVICE_TABLE(pci, azx_ids); 2146MODULE_DEVICE_TABLE(pci, azx_ids);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index ad0014ab71f9..5c9e578f7f2d 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -228,8 +228,18 @@ struct hda_multi_out {
228 int max_channels; /* currently supported analog channels */ 228 int max_channels; /* currently supported analog channels */
229 int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */ 229 int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
230 int no_share_stream; /* don't share a stream with multiple pins */ 230 int no_share_stream; /* don't share a stream with multiple pins */
231 int share_spdif; /* share SPDIF pin */
232 /* PCM information for both analog and SPDIF DACs */
233 unsigned int analog_rates;
234 unsigned int analog_maxbps;
235 u64 analog_formats;
236 unsigned int spdif_rates;
237 unsigned int spdif_maxbps;
238 u64 spdif_formats;
231}; 239};
232 240
241int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
242 struct hda_multi_out *mout);
233int snd_hda_multi_out_dig_open(struct hda_codec *codec, 243int snd_hda_multi_out_dig_open(struct hda_codec *codec,
234 struct hda_multi_out *mout); 244 struct hda_multi_out *mout);
235int snd_hda_multi_out_dig_close(struct hda_codec *codec, 245int snd_hda_multi_out_dig_close(struct hda_codec *codec,
@@ -241,7 +251,8 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
241 struct snd_pcm_substream *substream); 251 struct snd_pcm_substream *substream);
242int snd_hda_multi_out_analog_open(struct hda_codec *codec, 252int snd_hda_multi_out_analog_open(struct hda_codec *codec,
243 struct hda_multi_out *mout, 253 struct hda_multi_out *mout,
244 struct snd_pcm_substream *substream); 254 struct snd_pcm_substream *substream,
255 struct hda_pcm_stream *hinfo);
245int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, 256int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
246 struct hda_multi_out *mout, 257 struct hda_multi_out *mout,
247 unsigned int stream_tag, 258 unsigned int stream_tag,
@@ -407,11 +418,4 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
407 hda_nid_t nid); 418 hda_nid_t nid);
408#endif /* CONFIG_SND_HDA_POWER_SAVE */ 419#endif /* CONFIG_SND_HDA_POWER_SAVE */
409 420
410/*
411 * virtual master control
412 */
413struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
414 const unsigned int *tlv);
415int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave);
416
417#endif /* __SOUND_HDA_LOCAL_H */ 421#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/hda_patch.h b/sound/pci/hda/hda_patch.h
index f5c23bb16d7e..2fdf2358dbc2 100644
--- a/sound/pci/hda/hda_patch.h
+++ b/sound/pci/hda/hda_patch.h
@@ -18,31 +18,3 @@ extern struct hda_codec_preset snd_hda_preset_atihdmi[];
18extern struct hda_codec_preset snd_hda_preset_conexant[]; 18extern struct hda_codec_preset snd_hda_preset_conexant[];
19/* VIA codecs */ 19/* VIA codecs */
20extern struct hda_codec_preset snd_hda_preset_via[]; 20extern struct hda_codec_preset snd_hda_preset_via[];
21
22static const struct hda_codec_preset *hda_preset_tables[] = {
23#ifdef CONFIG_SND_HDA_CODEC_REALTEK
24 snd_hda_preset_realtek,
25#endif
26#ifdef CONFIG_SND_HDA_CODEC_CMEDIA
27 snd_hda_preset_cmedia,
28#endif
29#ifdef CONFIG_SND_HDA_CODEC_ANALOG
30 snd_hda_preset_analog,
31#endif
32#ifdef CONFIG_SND_HDA_CODEC_SIGMATEL
33 snd_hda_preset_sigmatel,
34#endif
35#ifdef CONFIG_SND_HDA_CODEC_SI3054
36 snd_hda_preset_si3054,
37#endif
38#ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
39 snd_hda_preset_atihdmi,
40#endif
41#ifdef CONFIG_SND_HDA_CODEC_CONEXANT
42 snd_hda_preset_conexant,
43#endif
44#ifdef CONFIG_SND_HDA_CODEC_VIA
45 snd_hda_preset_via,
46#endif
47 NULL
48};
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index c8649282c2cf..e0a605adde42 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -28,6 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_patch.h"
31 32
32struct ad198x_spec { 33struct ad198x_spec {
33 struct snd_kcontrol_new *mixers[5]; 34 struct snd_kcontrol_new *mixers[5];
@@ -80,7 +81,6 @@ struct ad198x_spec {
80#endif 81#endif
81 /* for virtual master */ 82 /* for virtual master */
82 hda_nid_t vmaster_nid; 83 hda_nid_t vmaster_nid;
83 u32 vmaster_tlv[4];
84 const char **slave_vols; 84 const char **slave_vols;
85 const char **slave_sws; 85 const char **slave_sws;
86}; 86};
@@ -171,6 +171,11 @@ static int ad198x_build_controls(struct hda_codec *codec)
171 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 171 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
172 if (err < 0) 172 if (err < 0)
173 return err; 173 return err;
174 err = snd_hda_create_spdif_share_sw(codec,
175 &spec->multiout);
176 if (err < 0)
177 return err;
178 spec->multiout.share_spdif = 1;
174 } 179 }
175 if (spec->dig_in_nid) { 180 if (spec->dig_in_nid) {
176 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 181 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -180,10 +185,11 @@ static int ad198x_build_controls(struct hda_codec *codec)
180 185
181 /* if we have no master control, let's create it */ 186 /* if we have no master control, let's create it */
182 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 187 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
188 unsigned int vmaster_tlv[4];
183 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 189 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
184 HDA_OUTPUT, spec->vmaster_tlv); 190 HDA_OUTPUT, vmaster_tlv);
185 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 191 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
186 spec->vmaster_tlv, 192 vmaster_tlv,
187 (spec->slave_vols ? 193 (spec->slave_vols ?
188 spec->slave_vols : ad_slave_vols)); 194 spec->slave_vols : ad_slave_vols));
189 if (err < 0) 195 if (err < 0)
@@ -217,7 +223,8 @@ static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
217 struct snd_pcm_substream *substream) 223 struct snd_pcm_substream *substream)
218{ 224{
219 struct ad198x_spec *spec = codec->spec; 225 struct ad198x_spec *spec = codec->spec;
220 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 226 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
227 hinfo);
221} 228}
222 229
223static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 230static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -289,8 +296,7 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
289 struct snd_pcm_substream *substream) 296 struct snd_pcm_substream *substream)
290{ 297{
291 struct ad198x_spec *spec = codec->spec; 298 struct ad198x_spec *spec = codec->spec;
292 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 299 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
293 0, 0, 0);
294 return 0; 300 return 0;
295} 301}
296 302
@@ -359,6 +365,7 @@ static int ad198x_build_pcms(struct hda_codec *codec)
359 info++; 365 info++;
360 codec->num_pcms++; 366 codec->num_pcms++;
361 info->name = "AD198x Digital"; 367 info->name = "AD198x Digital";
368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
362 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback; 369 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
363 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 370 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
364 if (spec->dig_in_nid) { 371 if (spec->dig_in_nid) {
@@ -611,13 +618,19 @@ static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
611 }, 618 },
612}; 619};
613 620
621static struct hda_input_mux ad1986a_automic_capture_source = {
622 .num_items = 2,
623 .items = {
624 { "Mic", 0x0 },
625 { "Mix", 0x5 },
626 },
627};
628
614static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = { 629static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
615 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol), 630 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
616 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw), 631 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
617 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT), 632 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
618 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), 633 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
619 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
620 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
621 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 634 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
622 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 635 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
623 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 636 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
@@ -641,6 +654,33 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
641 { } /* end */ 654 { } /* end */
642}; 655};
643 656
657/* re-connect the mic boost input according to the jack sensing */
658static void ad1986a_automic(struct hda_codec *codec)
659{
660 unsigned int present;
661 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
662 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
663 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
664 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
665}
666
667#define AD1986A_MIC_EVENT 0x36
668
669static void ad1986a_automic_unsol_event(struct hda_codec *codec,
670 unsigned int res)
671{
672 if ((res >> 26) != AD1986A_MIC_EVENT)
673 return;
674 ad1986a_automic(codec);
675}
676
677static int ad1986a_automic_init(struct hda_codec *codec)
678{
679 ad198x_init(codec);
680 ad1986a_automic(codec);
681 return 0;
682}
683
644/* laptop-automute - 2ch only */ 684/* laptop-automute - 2ch only */
645 685
646static void ad1986a_update_hp(struct hda_codec *codec) 686static void ad1986a_update_hp(struct hda_codec *codec)
@@ -844,6 +884,15 @@ static struct hda_verb ad1986a_eapd_init_verbs[] = {
844 {} 884 {}
845}; 885};
846 886
887static struct hda_verb ad1986a_automic_verbs[] = {
888 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
889 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
890 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
891 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
892 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
893 {}
894};
895
847/* Ultra initialization */ 896/* Ultra initialization */
848static struct hda_verb ad1986a_ultra_init[] = { 897static struct hda_verb ad1986a_ultra_init[] = {
849 /* eapd initialization */ 898 /* eapd initialization */
@@ -986,14 +1035,17 @@ static int patch_ad1986a(struct hda_codec *codec)
986 break; 1035 break;
987 case AD1986A_LAPTOP_EAPD: 1036 case AD1986A_LAPTOP_EAPD:
988 spec->mixers[0] = ad1986a_laptop_eapd_mixers; 1037 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
989 spec->num_init_verbs = 2; 1038 spec->num_init_verbs = 3;
990 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1039 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1040 spec->init_verbs[2] = ad1986a_automic_verbs;
991 spec->multiout.max_channels = 2; 1041 spec->multiout.max_channels = 2;
992 spec->multiout.num_dacs = 1; 1042 spec->multiout.num_dacs = 1;
993 spec->multiout.dac_nids = ad1986a_laptop_dac_nids; 1043 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
994 if (!is_jack_available(codec, 0x25)) 1044 if (!is_jack_available(codec, 0x25))
995 spec->multiout.dig_out_nid = 0; 1045 spec->multiout.dig_out_nid = 0;
996 spec->input_mux = &ad1986a_laptop_eapd_capture_source; 1046 spec->input_mux = &ad1986a_automic_capture_source;
1047 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1048 codec->patch_ops.init = ad1986a_automic_init;
997 break; 1049 break;
998 case AD1986A_LAPTOP_AUTOMUTE: 1050 case AD1986A_LAPTOP_AUTOMUTE:
999 spec->mixers[0] = ad1986a_laptop_automute_mixers; 1051 spec->mixers[0] = ad1986a_laptop_automute_mixers;
@@ -1365,7 +1417,10 @@ static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1365 1417
1366 if (! ad198x_eapd_put(kcontrol, ucontrol)) 1418 if (! ad198x_eapd_put(kcontrol, ucontrol))
1367 return 0; 1419 return 0;
1368 1420 /* change speaker pin appropriately */
1421 snd_hda_codec_write(codec, 0x05, 0,
1422 AC_VERB_SET_PIN_WIDGET_CONTROL,
1423 spec->cur_eapd ? PIN_OUT : 0);
1369 /* toggle HP mute appropriately */ 1424 /* toggle HP mute appropriately */
1370 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0, 1425 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1371 HDA_AMP_MUTE, 1426 HDA_AMP_MUTE,
@@ -2087,6 +2142,10 @@ static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2087 { } /* end */ 2142 { } /* end */
2088}; 2143};
2089 2144
2145static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2146 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2147 { } /* end */
2148};
2090 2149
2091/* 2150/*
2092 * initialization verbs 2151 * initialization verbs
@@ -2187,6 +2246,13 @@ static struct hda_verb ad1988_spdif_init_verbs[] = {
2187 { } 2246 { }
2188}; 2247};
2189 2248
2249/* AD1989 has no ADC -> SPDIF route */
2250static struct hda_verb ad1989_spdif_init_verbs[] = {
2251 /* SPDIF out pin */
2252 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2253 { }
2254};
2255
2190/* 2256/*
2191 * verbs for 3stack (+dig) 2257 * verbs for 3stack (+dig)
2192 */ 2258 */
@@ -2894,10 +2960,19 @@ static int patch_ad1988(struct hda_codec *codec)
2894 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers; 2960 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2895 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs; 2961 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2896 if (spec->multiout.dig_out_nid) { 2962 if (spec->multiout.dig_out_nid) {
2897 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers; 2963 if (codec->vendor_id >= 0x11d4989a) {
2898 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs; 2964 spec->mixers[spec->num_mixers++] =
2965 ad1989_spdif_out_mixers;
2966 spec->init_verbs[spec->num_init_verbs++] =
2967 ad1989_spdif_init_verbs;
2968 } else {
2969 spec->mixers[spec->num_mixers++] =
2970 ad1988_spdif_out_mixers;
2971 spec->init_verbs[spec->num_init_verbs++] =
2972 ad1988_spdif_init_verbs;
2973 }
2899 } 2974 }
2900 if (spec->dig_in_nid) 2975 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
2901 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers; 2976 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2902 2977
2903 codec->patch_ops = ad198x_patch_ops; 2978 codec->patch_ops = ad198x_patch_ops;
@@ -3133,11 +3208,12 @@ static int patch_ad1884(struct hda_codec *codec)
3133 * Lenovo Thinkpad T61/X61 3208 * Lenovo Thinkpad T61/X61
3134 */ 3209 */
3135static struct hda_input_mux ad1984_thinkpad_capture_source = { 3210static struct hda_input_mux ad1984_thinkpad_capture_source = {
3136 .num_items = 3, 3211 .num_items = 4,
3137 .items = { 3212 .items = {
3138 { "Mic", 0x0 }, 3213 { "Mic", 0x0 },
3139 { "Internal Mic", 0x1 }, 3214 { "Internal Mic", 0x1 },
3140 { "Mix", 0x3 }, 3215 { "Mix", 0x3 },
3216 { "Docking-Station", 0x4 },
3141 }, 3217 },
3142}; 3218};
3143 3219
@@ -3268,8 +3344,7 @@ static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3268 struct hda_codec *codec, 3344 struct hda_codec *codec,
3269 struct snd_pcm_substream *substream) 3345 struct snd_pcm_substream *substream)
3270{ 3346{
3271 snd_hda_codec_setup_stream(codec, 0x05 + substream->number, 3347 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3272 0, 0, 0);
3273 return 0; 3348 return 0;
3274} 3349}
3275 3350
@@ -3356,6 +3431,472 @@ static int patch_ad1984(struct hda_codec *codec)
3356 3431
3357 3432
3358/* 3433/*
3434 * AD1883 / AD1884A / AD1984A / AD1984B
3435 *
3436 * port-B (0x14) - front mic-in
3437 * port-E (0x1c) - rear mic-in
3438 * port-F (0x16) - CD / ext out
3439 * port-C (0x15) - rear line-in
3440 * port-D (0x12) - rear line-out
3441 * port-A (0x11) - front hp-out
3442 *
3443 * AD1984A = AD1884A + digital-mic
3444 * AD1883 = equivalent with AD1984A
3445 * AD1984B = AD1984A + extra SPDIF-out
3446 *
3447 * FIXME:
3448 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3449 */
3450
3451static hda_nid_t ad1884a_dac_nids[1] = {
3452 0x03,
3453};
3454
3455#define ad1884a_adc_nids ad1884_adc_nids
3456#define ad1884a_capsrc_nids ad1884_capsrc_nids
3457
3458#define AD1884A_SPDIF_OUT 0x02
3459
3460static struct hda_input_mux ad1884a_capture_source = {
3461 .num_items = 5,
3462 .items = {
3463 { "Front Mic", 0x0 },
3464 { "Mic", 0x4 },
3465 { "Line", 0x1 },
3466 { "CD", 0x2 },
3467 { "Mix", 0x3 },
3468 },
3469};
3470
3471static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3472 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3473 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3474 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3475 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3476 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3477 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3478 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3479 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3480 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3481 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3482 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3483 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3484 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3485 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3486 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3487 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3488 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3489 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3490 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3491 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3492 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3493 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3494 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3495 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3496 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3497 {
3498 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3499 /* The multiple "Capture Source" controls confuse alsamixer
3500 * So call somewhat different..
3501 */
3502 /* .name = "Capture Source", */
3503 .name = "Input Source",
3504 .count = 2,
3505 .info = ad198x_mux_enum_info,
3506 .get = ad198x_mux_enum_get,
3507 .put = ad198x_mux_enum_put,
3508 },
3509 /* SPDIF controls */
3510 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3511 {
3512 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3513 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3514 /* identical with ad1983 */
3515 .info = ad1983_spdif_route_info,
3516 .get = ad1983_spdif_route_get,
3517 .put = ad1983_spdif_route_put,
3518 },
3519 { } /* end */
3520};
3521
3522/*
3523 * initialization verbs
3524 */
3525static struct hda_verb ad1884a_init_verbs[] = {
3526 /* DACs; unmute as default */
3527 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3528 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3529 /* Port-A (HP) mixer - route only from analog mixer */
3530 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3531 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3532 /* Port-A pin */
3533 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3534 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3535 /* Port-D (Line-out) mixer - route only from analog mixer */
3536 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3537 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3538 /* Port-D pin */
3539 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3540 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3541 /* Mono-out mixer - route only from analog mixer */
3542 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3543 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3544 /* Mono-out pin */
3545 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3546 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3547 /* Port-B (front mic) pin */
3548 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3549 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3550 /* Port-C (rear line-in) pin */
3551 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3552 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3553 /* Port-E (rear mic) pin */
3554 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3555 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3556 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3557 /* Port-F (CD) pin */
3558 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3559 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3560 /* Analog mixer; mute as default */
3561 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3562 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3563 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3564 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3565 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3566 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3567 /* Analog Mix output amp */
3568 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3569 /* capture sources */
3570 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3571 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3572 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3573 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3574 /* SPDIF output amp */
3575 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3576 { } /* end */
3577};
3578
3579#ifdef CONFIG_SND_HDA_POWER_SAVE
3580static struct hda_amp_list ad1884a_loopbacks[] = {
3581 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3582 { 0x20, HDA_INPUT, 1 }, /* Mic */
3583 { 0x20, HDA_INPUT, 2 }, /* CD */
3584 { 0x20, HDA_INPUT, 4 }, /* Docking */
3585 { } /* end */
3586};
3587#endif
3588
3589/*
3590 * Laptop model
3591 *
3592 * Port A: Headphone jack
3593 * Port B: MIC jack
3594 * Port C: Internal MIC
3595 * Port D: Dock Line Out (if enabled)
3596 * Port E: Dock Line In (if enabled)
3597 * Port F: Internal speakers
3598 */
3599
3600static struct hda_input_mux ad1884a_laptop_capture_source = {
3601 .num_items = 4,
3602 .items = {
3603 { "Mic", 0x0 }, /* port-B */
3604 { "Internal Mic", 0x1 }, /* port-C */
3605 { "Dock Mic", 0x4 }, /* port-E */
3606 { "Mix", 0x3 },
3607 },
3608};
3609
3610static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3611 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3612 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3613 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3614 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3615 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3616 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3617 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3618 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3619 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3620 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3621 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3622 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3623 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3624 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3625 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3626 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3627 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3628 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3629 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3630 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3631 {
3632 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3633 /* The multiple "Capture Source" controls confuse alsamixer
3634 * So call somewhat different..
3635 */
3636 /* .name = "Capture Source", */
3637 .name = "Input Source",
3638 .count = 2,
3639 .info = ad198x_mux_enum_info,
3640 .get = ad198x_mux_enum_get,
3641 .put = ad198x_mux_enum_put,
3642 },
3643 { } /* end */
3644};
3645
3646static struct hda_input_mux ad1884a_mobile_capture_source = {
3647 .num_items = 2,
3648 .items = {
3649 { "Mic", 0x1 }, /* port-C */
3650 { "Mix", 0x3 },
3651 },
3652};
3653
3654static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3655 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3656 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3657 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3658 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3659 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3660 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3661 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3662 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3663 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3664 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3665 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3666 {
3667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3668 .name = "Capture Source",
3669 .info = ad198x_mux_enum_info,
3670 .get = ad198x_mux_enum_get,
3671 .put = ad198x_mux_enum_put,
3672 },
3673 { } /* end */
3674};
3675
3676/* mute internal speaker if HP is plugged */
3677static void ad1884a_hp_automute(struct hda_codec *codec)
3678{
3679 unsigned int present;
3680
3681 present = snd_hda_codec_read(codec, 0x11, 0,
3682 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3683 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3684 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3685 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3686 present ? 0x00 : 0x02);
3687}
3688
3689#define AD1884A_HP_EVENT 0x37
3690
3691/* unsolicited event for HP jack sensing */
3692static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3693{
3694 if ((res >> 26) != AD1884A_HP_EVENT)
3695 return;
3696 ad1884a_hp_automute(codec);
3697}
3698
3699/* initialize jack-sensing, too */
3700static int ad1884a_hp_init(struct hda_codec *codec)
3701{
3702 ad198x_init(codec);
3703 ad1884a_hp_automute(codec);
3704 return 0;
3705}
3706
3707/* additional verbs for laptop model */
3708static struct hda_verb ad1884a_laptop_verbs[] = {
3709 /* Port-A (HP) pin - always unmuted */
3710 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3711 /* Port-F (int speaker) mixer - route only from analog mixer */
3712 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3713 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3714 /* Port-F pin */
3715 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3716 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3717 /* analog mix */
3718 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3719 /* unsolicited event for pin-sense */
3720 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3721 { } /* end */
3722};
3723
3724/*
3725 * Thinkpad X300
3726 * 0x11 - HP
3727 * 0x12 - speaker
3728 * 0x14 - mic-in
3729 * 0x17 - built-in mic
3730 */
3731
3732static struct hda_verb ad1984a_thinkpad_verbs[] = {
3733 /* HP unmute */
3734 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3735 /* analog mix */
3736 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3737 /* turn on EAPD */
3738 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3739 /* unsolicited event for pin-sense */
3740 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3741 /* internal mic - dmic */
3742 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3743 /* set magic COEFs for dmic */
3744 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3745 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
3746 { } /* end */
3747};
3748
3749static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3750 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3751 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3752 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3753 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3754 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3755 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3756 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3757 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3758 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3759 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3760 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3761 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3762 {
3763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3764 .name = "Capture Source",
3765 .info = ad198x_mux_enum_info,
3766 .get = ad198x_mux_enum_get,
3767 .put = ad198x_mux_enum_put,
3768 },
3769 { } /* end */
3770};
3771
3772static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3773 .num_items = 3,
3774 .items = {
3775 { "Mic", 0x0 },
3776 { "Internal Mic", 0x5 },
3777 { "Mix", 0x3 },
3778 },
3779};
3780
3781/* mute internal speaker if HP is plugged */
3782static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3783{
3784 unsigned int present;
3785
3786 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3787 & AC_PINSENSE_PRESENCE;
3788 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3789 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3790}
3791
3792/* unsolicited event for HP jack sensing */
3793static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3794 unsigned int res)
3795{
3796 if ((res >> 26) != AD1884A_HP_EVENT)
3797 return;
3798 ad1984a_thinkpad_automute(codec);
3799}
3800
3801/* initialize jack-sensing, too */
3802static int ad1984a_thinkpad_init(struct hda_codec *codec)
3803{
3804 ad198x_init(codec);
3805 ad1984a_thinkpad_automute(codec);
3806 return 0;
3807}
3808
3809/*
3810 */
3811
3812enum {
3813 AD1884A_DESKTOP,
3814 AD1884A_LAPTOP,
3815 AD1884A_MOBILE,
3816 AD1884A_THINKPAD,
3817 AD1884A_MODELS
3818};
3819
3820static const char *ad1884a_models[AD1884A_MODELS] = {
3821 [AD1884A_DESKTOP] = "desktop",
3822 [AD1884A_LAPTOP] = "laptop",
3823 [AD1884A_MOBILE] = "mobile",
3824 [AD1884A_THINKPAD] = "thinkpad",
3825};
3826
3827static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3828 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3829 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3830 {}
3831};
3832
3833static int patch_ad1884a(struct hda_codec *codec)
3834{
3835 struct ad198x_spec *spec;
3836 int board_config;
3837
3838 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3839 if (spec == NULL)
3840 return -ENOMEM;
3841
3842 mutex_init(&spec->amp_mutex);
3843 codec->spec = spec;
3844
3845 spec->multiout.max_channels = 2;
3846 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3847 spec->multiout.dac_nids = ad1884a_dac_nids;
3848 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3849 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3850 spec->adc_nids = ad1884a_adc_nids;
3851 spec->capsrc_nids = ad1884a_capsrc_nids;
3852 spec->input_mux = &ad1884a_capture_source;
3853 spec->num_mixers = 1;
3854 spec->mixers[0] = ad1884a_base_mixers;
3855 spec->num_init_verbs = 1;
3856 spec->init_verbs[0] = ad1884a_init_verbs;
3857 spec->spdif_route = 0;
3858#ifdef CONFIG_SND_HDA_POWER_SAVE
3859 spec->loopback.amplist = ad1884a_loopbacks;
3860#endif
3861 codec->patch_ops = ad198x_patch_ops;
3862
3863 /* override some parameters */
3864 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
3865 ad1884a_models,
3866 ad1884a_cfg_tbl);
3867 switch (board_config) {
3868 case AD1884A_LAPTOP:
3869 spec->mixers[0] = ad1884a_laptop_mixers;
3870 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3871 spec->multiout.dig_out_nid = 0;
3872 spec->input_mux = &ad1884a_laptop_capture_source;
3873 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3874 codec->patch_ops.init = ad1884a_hp_init;
3875 break;
3876 case AD1884A_MOBILE:
3877 spec->mixers[0] = ad1884a_mobile_mixers;
3878 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3879 spec->multiout.dig_out_nid = 0;
3880 spec->input_mux = &ad1884a_mobile_capture_source;
3881 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3882 codec->patch_ops.init = ad1884a_hp_init;
3883 break;
3884 case AD1884A_THINKPAD:
3885 spec->mixers[0] = ad1984a_thinkpad_mixers;
3886 spec->init_verbs[spec->num_init_verbs++] =
3887 ad1984a_thinkpad_verbs;
3888 spec->multiout.dig_out_nid = 0;
3889 spec->input_mux = &ad1984a_thinkpad_capture_source;
3890 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
3891 codec->patch_ops.init = ad1984a_thinkpad_init;
3892 break;
3893 }
3894
3895 return 0;
3896}
3897
3898
3899/*
3359 * AD1882 3900 * AD1882
3360 * 3901 *
3361 * port-A - front hp-out 3902 * port-A - front hp-out
@@ -3654,13 +4195,19 @@ static int patch_ad1882(struct hda_codec *codec)
3654 * patch entries 4195 * patch entries
3655 */ 4196 */
3656struct hda_codec_preset snd_hda_preset_analog[] = { 4197struct hda_codec_preset snd_hda_preset_analog[] = {
4198 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
3657 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 }, 4199 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4200 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
3658 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 }, 4201 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4202 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4203 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
3659 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 }, 4204 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
3660 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 }, 4205 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
3661 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 }, 4206 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
3662 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a }, 4207 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
3663 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 }, 4208 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
3664 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 }, 4209 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4210 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4211 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
3665 {} /* terminator */ 4212 {} /* terminator */
3666}; 4213};
diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c
index 9a8bb4ce3f8d..12272508b112 100644
--- a/sound/pci/hda/patch_atihdmi.c
+++ b/sound/pci/hda/patch_atihdmi.c
@@ -27,6 +27,7 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
30 31
31struct atihdmi_spec { 32struct atihdmi_spec {
32 struct hda_multi_out multiout; 33 struct hda_multi_out multiout;
@@ -58,6 +59,10 @@ static int atihdmi_build_controls(struct hda_codec *codec)
58static int atihdmi_init(struct hda_codec *codec) 59static int atihdmi_init(struct hda_codec *codec)
59{ 60{
60 snd_hda_sequence_write(codec, atihdmi_basic_init); 61 snd_hda_sequence_write(codec, atihdmi_basic_init);
62 /* SI codec requires to unmute the pin */
63 if (get_wcaps(codec, 0x03) & AC_WCAP_OUT_AMP)
64 snd_hda_codec_write(codec, 0x03, 0, AC_VERB_SET_AMP_GAIN_MUTE,
65 AMP_OUT_UNMUTE);
61 return 0; 66 return 0;
62} 67}
63 68
@@ -112,6 +117,7 @@ static int atihdmi_build_pcms(struct hda_codec *codec)
112 codec->pcm_info = info; 117 codec->pcm_info = info;
113 118
114 info->name = "ATI HDMI"; 119 info->name = "ATI HDMI";
120 info->pcm_type = HDA_PCM_TYPE_HDMI;
115 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback; 121 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
116 122
117 return 0; 123 return 0;
@@ -158,5 +164,7 @@ struct hda_codec_preset snd_hda_preset_atihdmi[] = {
158 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, 164 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
159 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi }, 165 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
160 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi }, 166 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi },
167 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi },
168 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi },
161 {} /* terminator */ 169 {} /* terminator */
162}; 170};
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 3d6097ba1d68..c73ce074a6ea 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -28,6 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_patch.h"
31#define NUM_PINS 11 32#define NUM_PINS 11
32 33
33 34
@@ -329,6 +330,11 @@ static int cmi9880_build_controls(struct hda_codec *codec)
329 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 330 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
330 if (err < 0) 331 if (err < 0)
331 return err; 332 return err;
333 err = snd_hda_create_spdif_share_sw(codec,
334 &spec->multiout);
335 if (err < 0)
336 return err;
337 spec->multiout.share_spdif = 1;
332 } 338 }
333 if (spec->dig_in_nid) { 339 if (spec->dig_in_nid) {
334 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 340 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -432,7 +438,8 @@ static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo,
432 struct snd_pcm_substream *substream) 438 struct snd_pcm_substream *substream)
433{ 439{
434 struct cmi_spec *spec = codec->spec; 440 struct cmi_spec *spec = codec->spec;
435 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 441 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
442 hinfo);
436} 443}
437 444
438static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 445static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -506,7 +513,7 @@ static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
506{ 513{
507 struct cmi_spec *spec = codec->spec; 514 struct cmi_spec *spec = codec->spec;
508 515
509 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); 516 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
510 return 0; 517 return 0;
511} 518}
512 519
@@ -571,6 +578,7 @@ static int cmi9880_build_pcms(struct hda_codec *codec)
571 codec->num_pcms++; 578 codec->num_pcms++;
572 info++; 579 info++;
573 info->name = "CMI9880 Digital"; 580 info->name = "CMI9880 Digital";
581 info->pcm_type = HDA_PCM_TYPE_SPDIF;
574 if (spec->multiout.dig_out_nid) { 582 if (spec->multiout.dig_out_nid) {
575 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback; 583 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 584 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -603,6 +611,7 @@ static const char *cmi9880_models[CMI_MODELS] = {
603 611
604static struct snd_pci_quirk cmi9880_cfg_tbl[] = { 612static struct snd_pci_quirk cmi9880_cfg_tbl[] = {
605 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG), 613 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG),
614 SND_PCI_QUIRK(0x1854, 0x0032, "LG", CMI_FULL_DIG),
606 {} /* terminator */ 615 {} /* terminator */
607}; 616};
608 617
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 7206b30cbf94..36fd85260035 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -27,6 +27,7 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
30 31
31#define CXT_PIN_DIR_IN 0x00 32#define CXT_PIN_DIR_IN 0x00
32#define CXT_PIN_DIR_OUT 0x01 33#define CXT_PIN_DIR_OUT 0x01
@@ -98,7 +99,8 @@ static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
98 struct snd_pcm_substream *substream) 99 struct snd_pcm_substream *substream)
99{ 100{
100 struct conexant_spec *spec = codec->spec; 101 struct conexant_spec *spec = codec->spec;
101 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 102 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
103 hinfo);
102} 104}
103 105
104static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 106static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -172,8 +174,7 @@ static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
172 struct snd_pcm_substream *substream) 174 struct snd_pcm_substream *substream)
173{ 175{
174 struct conexant_spec *spec = codec->spec; 176 struct conexant_spec *spec = codec->spec;
175 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 177 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
176 0, 0, 0);
177 return 0; 178 return 0;
178} 179}
179 180
@@ -241,7 +242,7 @@ static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
241 struct snd_pcm_substream *substream) 242 struct snd_pcm_substream *substream)
242{ 243{
243 struct conexant_spec *spec = codec->spec; 244 struct conexant_spec *spec = codec->spec;
244 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0); 245 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
245 spec->cur_adc = 0; 246 spec->cur_adc = 0;
246 return 0; 247 return 0;
247} 248}
@@ -284,6 +285,7 @@ static int conexant_build_pcms(struct hda_codec *codec)
284 info++; 285 info++;
285 codec->num_pcms++; 286 codec->num_pcms++;
286 info->name = "Conexant Digital"; 287 info->name = "Conexant Digital";
288 info->pcm_type = HDA_PCM_TYPE_SPDIF;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
288 conexant_pcm_digital_playback; 290 conexant_pcm_digital_playback;
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 291 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
@@ -371,6 +373,11 @@ static int conexant_build_controls(struct hda_codec *codec)
371 spec->multiout.dig_out_nid); 373 spec->multiout.dig_out_nid);
372 if (err < 0) 374 if (err < 0)
373 return err; 375 return err;
376 err = snd_hda_create_spdif_share_sw(codec,
377 &spec->multiout);
378 if (err < 0)
379 return err;
380 spec->multiout.share_spdif = 1;
374 } 381 }
375 if (spec->dig_in_nid) { 382 if (spec->dig_in_nid) {
376 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 383 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
@@ -511,6 +518,14 @@ static struct hda_input_mux cxt5045_capture_source_benq = {
511 } 518 }
512}; 519};
513 520
521static struct hda_input_mux cxt5045_capture_source_hp530 = {
522 .num_items = 2,
523 .items = {
524 { "ExtMic", 0x1 },
525 { "IntMic", 0x2 },
526 }
527};
528
514/* turn on/off EAPD (+ mute HP) as a master switch */ 529/* turn on/off EAPD (+ mute HP) as a master switch */
515static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 530static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
516 struct snd_ctl_elem_value *ucontrol) 531 struct snd_ctl_elem_value *ucontrol)
@@ -639,6 +654,37 @@ static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
639 {} 654 {}
640}; 655};
641 656
657static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
658 {
659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
660 .name = "Capture Source",
661 .info = conexant_mux_enum_info,
662 .get = conexant_mux_enum_get,
663 .put = conexant_mux_enum_put
664 },
665 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
666 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
667 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
668 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
669 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
670 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
671 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
672 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
673 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
674 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
675 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
676 {
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
678 .name = "Master Playback Switch",
679 .info = cxt_eapd_info,
680 .get = cxt_eapd_get,
681 .put = cxt5045_hp_master_sw_put,
682 .private_value = 0x10,
683 },
684
685 {}
686};
687
642static struct hda_verb cxt5045_init_verbs[] = { 688static struct hda_verb cxt5045_init_verbs[] = {
643 /* Line in, Mic */ 689 /* Line in, Mic */
644 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 690 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
@@ -833,6 +879,7 @@ enum {
833 CXT5045_LAPTOP_MICSENSE, 879 CXT5045_LAPTOP_MICSENSE,
834 CXT5045_LAPTOP_HPMICSENSE, 880 CXT5045_LAPTOP_HPMICSENSE,
835 CXT5045_BENQ, 881 CXT5045_BENQ,
882 CXT5045_LAPTOP_HP530,
836#ifdef CONFIG_SND_DEBUG 883#ifdef CONFIG_SND_DEBUG
837 CXT5045_TEST, 884 CXT5045_TEST,
838#endif 885#endif
@@ -844,6 +891,7 @@ static const char *cxt5045_models[CXT5045_MODELS] = {
844 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 891 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
845 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 892 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
846 [CXT5045_BENQ] = "benq", 893 [CXT5045_BENQ] = "benq",
894 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
847#ifdef CONFIG_SND_DEBUG 895#ifdef CONFIG_SND_DEBUG
848 [CXT5045_TEST] = "test", 896 [CXT5045_TEST] = "test",
849#endif 897#endif
@@ -857,7 +905,7 @@ static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
857 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE), 905 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
858 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE), 906 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
859 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE), 907 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
860 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE), 908 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
861 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE), 909 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
862 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 910 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
863 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 911 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
@@ -941,6 +989,14 @@ static int patch_cxt5045(struct hda_codec *codec)
941 spec->num_mixers = 2; 989 spec->num_mixers = 2;
942 codec->patch_ops.init = cxt5045_init; 990 codec->patch_ops.init = cxt5045_init;
943 break; 991 break;
992 case CXT5045_LAPTOP_HP530:
993 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
994 spec->input_mux = &cxt5045_capture_source_hp530;
995 spec->num_init_verbs = 2;
996 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
997 spec->mixers[0] = cxt5045_mixers_hp530;
998 codec->patch_ops.init = cxt5045_init;
999 break;
944#ifdef CONFIG_SND_DEBUG 1000#ifdef CONFIG_SND_DEBUG
945 case CXT5045_TEST: 1001 case CXT5045_TEST:
946 spec->input_mux = &cxt5045_test_capture_source; 1002 spec->input_mux = &cxt5045_test_capture_source;
@@ -1537,7 +1593,7 @@ static void cxt5051_portc_automic(struct hda_codec *codec)
1537 new_adc = spec->adc_nids[spec->cur_adc_idx]; 1593 new_adc = spec->adc_nids[spec->cur_adc_idx];
1538 if (spec->cur_adc && spec->cur_adc != new_adc) { 1594 if (spec->cur_adc && spec->cur_adc != new_adc) {
1539 /* stream is running, let's swap the current ADC */ 1595 /* stream is running, let's swap the current ADC */
1540 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0); 1596 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1541 spec->cur_adc = new_adc; 1597 spec->cur_adc = new_adc;
1542 snd_hda_codec_setup_stream(codec, new_adc, 1598 snd_hda_codec_setup_stream(codec, new_adc,
1543 spec->cur_adc_stream_tag, 0, 1599 spec->cur_adc_stream_tag, 0,
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 33282f9c01c7..d9783a4263e0 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -30,6 +30,7 @@
30#include <sound/core.h> 30#include <sound/core.h>
31#include "hda_codec.h" 31#include "hda_codec.h"
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_patch.h"
33 34
34#define ALC880_FRONT_EVENT 0x01 35#define ALC880_FRONT_EVENT 0x01
35#define ALC880_DCVOL_EVENT 0x02 36#define ALC880_DCVOL_EVENT 0x02
@@ -59,6 +60,7 @@ enum {
59 ALC880_TCL_S700, 60 ALC880_TCL_S700,
60 ALC880_LG, 61 ALC880_LG,
61 ALC880_LG_LW, 62 ALC880_LG_LW,
63 ALC880_MEDION_RIM,
62#ifdef CONFIG_SND_DEBUG 64#ifdef CONFIG_SND_DEBUG
63 ALC880_TEST, 65 ALC880_TEST,
64#endif 66#endif
@@ -97,16 +99,19 @@ enum {
97 ALC262_SONY_ASSAMD, 99 ALC262_SONY_ASSAMD,
98 ALC262_BENQ_T31, 100 ALC262_BENQ_T31,
99 ALC262_ULTRA, 101 ALC262_ULTRA,
102 ALC262_LENOVO_3000,
100 ALC262_AUTO, 103 ALC262_AUTO,
101 ALC262_MODEL_LAST /* last tag */ 104 ALC262_MODEL_LAST /* last tag */
102}; 105};
103 106
104/* ALC268 models */ 107/* ALC268 models */
105enum { 108enum {
109 ALC267_QUANTA_IL1,
106 ALC268_3ST, 110 ALC268_3ST,
107 ALC268_TOSHIBA, 111 ALC268_TOSHIBA,
108 ALC268_ACER, 112 ALC268_ACER,
109 ALC268_DELL, 113 ALC268_DELL,
114 ALC268_ZEPTO,
110#ifdef CONFIG_SND_DEBUG 115#ifdef CONFIG_SND_DEBUG
111 ALC268_TEST, 116 ALC268_TEST,
112#endif 117#endif
@@ -195,10 +200,11 @@ enum {
195 ALC883_LENOVO_NB0763, 200 ALC883_LENOVO_NB0763,
196 ALC888_LENOVO_MS7195_DIG, 201 ALC888_LENOVO_MS7195_DIG,
197 ALC883_HAIER_W66, 202 ALC883_HAIER_W66,
198 ALC888_6ST_HP,
199 ALC888_3ST_HP, 203 ALC888_3ST_HP,
200 ALC888_6ST_DELL, 204 ALC888_6ST_DELL,
201 ALC883_MITAC, 205 ALC883_MITAC,
206 ALC883_CLEVO_M720,
207 ALC883_FUJITSU_PI2515,
202 ALC883_AUTO, 208 ALC883_AUTO,
203 ALC883_MODEL_LAST, 209 ALC883_MODEL_LAST,
204}; 210};
@@ -237,6 +243,7 @@ struct alc_spec {
237 /* capture */ 243 /* capture */
238 unsigned int num_adc_nids; 244 unsigned int num_adc_nids;
239 hda_nid_t *adc_nids; 245 hda_nid_t *adc_nids;
246 hda_nid_t *capsrc_nids;
240 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 247 hda_nid_t dig_in_nid; /* digital-in NID; optional */
241 248
242 /* capture source */ 249 /* capture source */
@@ -270,7 +277,6 @@ struct alc_spec {
270 277
271 /* for virtual master */ 278 /* for virtual master */
272 hda_nid_t vmaster_nid; 279 hda_nid_t vmaster_nid;
273 u32 vmaster_tlv[4];
274#ifdef CONFIG_SND_HDA_POWER_SAVE 280#ifdef CONFIG_SND_HDA_POWER_SAVE
275 struct hda_loopback_check loopback; 281 struct hda_loopback_check loopback;
276#endif 282#endif
@@ -290,6 +296,7 @@ struct alc_config_preset {
290 hda_nid_t hp_nid; /* optional */ 296 hda_nid_t hp_nid; /* optional */
291 unsigned int num_adc_nids; 297 unsigned int num_adc_nids;
292 hda_nid_t *adc_nids; 298 hda_nid_t *adc_nids;
299 hda_nid_t *capsrc_nids;
293 hda_nid_t dig_in_nid; 300 hda_nid_t dig_in_nid;
294 unsigned int num_channel_mode; 301 unsigned int num_channel_mode;
295 const struct hda_channel_mode *channel_mode; 302 const struct hda_channel_mode *channel_mode;
@@ -336,9 +343,10 @@ static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
336 struct alc_spec *spec = codec->spec; 343 struct alc_spec *spec = codec->spec;
337 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 344 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
338 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; 345 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
346 hda_nid_t nid = spec->capsrc_nids ?
347 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
339 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol, 348 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
340 spec->adc_nids[adc_idx], 349 nid, &spec->cur_mux[adc_idx]);
341 &spec->cur_mux[adc_idx]);
342} 350}
343 351
344 352
@@ -707,6 +715,7 @@ static void setup_preset(struct alc_spec *spec,
707 715
708 spec->num_adc_nids = preset->num_adc_nids; 716 spec->num_adc_nids = preset->num_adc_nids;
709 spec->adc_nids = preset->adc_nids; 717 spec->adc_nids = preset->adc_nids;
718 spec->capsrc_nids = preset->capsrc_nids;
710 spec->dig_in_nid = preset->dig_in_nid; 719 spec->dig_in_nid = preset->dig_in_nid;
711 720
712 spec->unsol_event = preset->unsol_event; 721 spec->unsol_event = preset->unsol_event;
@@ -741,7 +750,6 @@ static struct hda_verb alc_gpio3_init_verbs[] = {
741static void alc_sku_automute(struct hda_codec *codec) 750static void alc_sku_automute(struct hda_codec *codec)
742{ 751{
743 struct alc_spec *spec = codec->spec; 752 struct alc_spec *spec = codec->spec;
744 unsigned int mute;
745 unsigned int present; 753 unsigned int present;
746 unsigned int hp_nid = spec->autocfg.hp_pins[0]; 754 unsigned int hp_nid = spec->autocfg.hp_pins[0];
747 unsigned int sp_nid = spec->autocfg.speaker_pins[0]; 755 unsigned int sp_nid = spec->autocfg.speaker_pins[0];
@@ -751,16 +759,8 @@ static void alc_sku_automute(struct hda_codec *codec)
751 present = snd_hda_codec_read(codec, hp_nid, 0, 759 present = snd_hda_codec_read(codec, hp_nid, 0,
752 AC_VERB_GET_PIN_SENSE, 0); 760 AC_VERB_GET_PIN_SENSE, 0);
753 spec->jack_present = (present & 0x80000000) != 0; 761 spec->jack_present = (present & 0x80000000) != 0;
754 if (spec->jack_present) { 762 snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
755 /* mute internal speaker */ 763 spec->jack_present ? 0 : PIN_OUT);
756 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
757 HDA_AMP_MUTE, HDA_AMP_MUTE);
758 } else {
759 /* unmute internal speaker if necessary */
760 mute = snd_hda_codec_amp_read(codec, hp_nid, 0, HDA_OUTPUT, 0);
761 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
762 HDA_AMP_MUTE, mute);
763 }
764} 764}
765 765
766/* unsolicited event for HP jack sensing */ 766/* unsolicited event for HP jack sensing */
@@ -1319,11 +1319,19 @@ static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1319 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 1319 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1320 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 1320 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1321 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 1321 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1322 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 1322 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1323 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 1323 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1324 { } /* end */ 1324 { } /* end */
1325}; 1325};
1326 1326
1327static struct hda_input_mux alc880_f1734_capture_source = {
1328 .num_items = 2,
1329 .items = {
1330 { "Mic", 0x1 },
1331 { "CD", 0x4 },
1332 },
1333};
1334
1327 1335
1328/* 1336/*
1329 * ALC880 ASUS model 1337 * ALC880 ASUS model
@@ -1516,6 +1524,11 @@ static int alc_build_controls(struct hda_codec *codec)
1516 spec->multiout.dig_out_nid); 1524 spec->multiout.dig_out_nid);
1517 if (err < 0) 1525 if (err < 0)
1518 return err; 1526 return err;
1527 err = snd_hda_create_spdif_share_sw(codec,
1528 &spec->multiout);
1529 if (err < 0)
1530 return err;
1531 spec->multiout.share_spdif = 1;
1519 } 1532 }
1520 if (spec->dig_in_nid) { 1533 if (spec->dig_in_nid) {
1521 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 1534 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -1525,10 +1538,11 @@ static int alc_build_controls(struct hda_codec *codec)
1525 1538
1526 /* if we have no master control, let's create it */ 1539 /* if we have no master control, let's create it */
1527 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 1540 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1541 unsigned int vmaster_tlv[4];
1528 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 1542 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1529 HDA_OUTPUT, spec->vmaster_tlv); 1543 HDA_OUTPUT, vmaster_tlv);
1530 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 1544 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1531 spec->vmaster_tlv, alc_slave_vols); 1545 vmaster_tlv, alc_slave_vols);
1532 if (err < 0) 1546 if (err < 0)
1533 return err; 1547 return err;
1534 } 1548 }
@@ -1882,7 +1896,7 @@ static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1882 present = snd_hda_codec_read(codec, 0x14, 0, 1896 present = snd_hda_codec_read(codec, 0x14, 0,
1883 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1897 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1884 bits = present ? HDA_AMP_MUTE : 0; 1898 bits = present ? HDA_AMP_MUTE : 0;
1885 snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits); 1899 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1886} 1900}
1887 1901
1888static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec) 1902static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
@@ -1915,6 +1929,7 @@ static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1915 * HP = 0x14, speaker-out = 0x15, mic = 0x18 1929 * HP = 0x14, speaker-out = 0x15, mic = 0x18
1916 */ 1930 */
1917static struct hda_verb alc880_pin_f1734_init_verbs[] = { 1931static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1932 {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
1918 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, 1933 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1919 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, 1934 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1920 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, 1935 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
@@ -1927,7 +1942,7 @@ static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1927 1942
1928 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1943 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1929 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 1944 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1930 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1945 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
1931 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 1946 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1932 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1947 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1933 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1948 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -1935,6 +1950,9 @@ static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1935 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1950 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1936 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1951 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1937 1952
1953 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
1954 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
1955
1938 { } 1956 { }
1939}; 1957};
1940 1958
@@ -2258,6 +2276,75 @@ static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2258 alc880_lg_lw_automute(codec); 2276 alc880_lg_lw_automute(codec);
2259} 2277}
2260 2278
2279static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2280 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2281 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2282 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2283 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2284 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2285 HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2286 { } /* end */
2287};
2288
2289static struct hda_input_mux alc880_medion_rim_capture_source = {
2290 .num_items = 2,
2291 .items = {
2292 { "Mic", 0x0 },
2293 { "Internal Mic", 0x1 },
2294 },
2295};
2296
2297static struct hda_verb alc880_medion_rim_init_verbs[] = {
2298 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2299
2300 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2301 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2302
2303 /* Mic1 (rear panel) pin widget for input and vref at 80% */
2304 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2305 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2306 /* Mic2 (as headphone out) for HP output */
2307 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2308 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2309 /* Internal Speaker */
2310 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2311 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2312
2313 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2314 {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
2315
2316 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2317 { }
2318};
2319
2320/* toggle speaker-output according to the hp-jack state */
2321static void alc880_medion_rim_automute(struct hda_codec *codec)
2322{
2323 unsigned int present;
2324 unsigned char bits;
2325
2326 present = snd_hda_codec_read(codec, 0x14, 0,
2327 AC_VERB_GET_PIN_SENSE, 0)
2328 & AC_PINSENSE_PRESENCE;
2329 bits = present ? HDA_AMP_MUTE : 0;
2330 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2331 HDA_AMP_MUTE, bits);
2332 if (present)
2333 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2334 else
2335 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2336}
2337
2338static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2339 unsigned int res)
2340{
2341 /* Looks like the unsol event is incompatible with the standard
2342 * definition. 4bit tag is placed at 28 bit!
2343 */
2344 if ((res >> 28) == ALC880_HP_EVENT)
2345 alc880_medion_rim_automute(codec);
2346}
2347
2261#ifdef CONFIG_SND_HDA_POWER_SAVE 2348#ifdef CONFIG_SND_HDA_POWER_SAVE
2262static struct hda_amp_list alc880_loopbacks[] = { 2349static struct hda_amp_list alc880_loopbacks[] = {
2263 { 0x0b, HDA_INPUT, 0 }, 2350 { 0x0b, HDA_INPUT, 0 },
@@ -2318,7 +2405,8 @@ static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2318 struct snd_pcm_substream *substream) 2405 struct snd_pcm_substream *substream)
2319{ 2406{
2320 struct alc_spec *spec = codec->spec; 2407 struct alc_spec *spec = codec->spec;
2321 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 2408 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2409 hinfo);
2322} 2410}
2323 2411
2324static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2412static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -2392,8 +2480,8 @@ static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2392{ 2480{
2393 struct alc_spec *spec = codec->spec; 2481 struct alc_spec *spec = codec->spec;
2394 2482
2395 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], 2483 snd_hda_codec_cleanup_stream(codec,
2396 0, 0, 0); 2484 spec->adc_nids[substream->number + 1]);
2397 return 0; 2485 return 0;
2398} 2486}
2399 2487
@@ -2498,6 +2586,7 @@ static int alc_build_pcms(struct hda_codec *codec)
2498 codec->num_pcms = 2; 2586 codec->num_pcms = 2;
2499 info = spec->pcm_rec + 1; 2587 info = spec->pcm_rec + 1;
2500 info->name = spec->stream_name_digital; 2588 info->name = spec->stream_name_digital;
2589 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2501 if (spec->multiout.dig_out_nid && 2590 if (spec->multiout.dig_out_nid &&
2502 spec->stream_digital_playback) { 2591 spec->stream_digital_playback) {
2503 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback); 2592 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
@@ -2560,6 +2649,7 @@ static void alc_free(struct hda_codec *codec)
2560 kfree(spec->kctl_alloc); 2649 kfree(spec->kctl_alloc);
2561 } 2650 }
2562 kfree(spec); 2651 kfree(spec);
2652 codec->spec = NULL; /* to be sure */
2563} 2653}
2564 2654
2565/* 2655/*
@@ -2862,6 +2952,7 @@ static const char *alc880_models[ALC880_MODEL_LAST] = {
2862 [ALC880_F1734] = "F1734", 2952 [ALC880_F1734] = "F1734",
2863 [ALC880_LG] = "lg", 2953 [ALC880_LG] = "lg",
2864 [ALC880_LG_LW] = "lg-lw", 2954 [ALC880_LG_LW] = "lg-lw",
2955 [ALC880_MEDION_RIM] = "medion",
2865#ifdef CONFIG_SND_DEBUG 2956#ifdef CONFIG_SND_DEBUG
2866 [ALC880_TEST] = "test", 2957 [ALC880_TEST] = "test",
2867#endif 2958#endif
@@ -2913,6 +3004,7 @@ static struct snd_pci_quirk alc880_cfg_tbl[] = {
2913 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL), 3004 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2914 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53), 3005 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2915 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810), 3006 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3007 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
2916 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG), 3008 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2917 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG), 3009 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2918 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734), 3010 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
@@ -3057,7 +3149,9 @@ static struct alc_config_preset alc880_presets[] = {
3057 .hp_nid = 0x02, 3149 .hp_nid = 0x02,
3058 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes), 3150 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3059 .channel_mode = alc880_2_jack_modes, 3151 .channel_mode = alc880_2_jack_modes,
3060 .input_mux = &alc880_capture_source, 3152 .input_mux = &alc880_f1734_capture_source,
3153 .unsol_event = alc880_uniwill_p53_unsol_event,
3154 .init_hook = alc880_uniwill_p53_hp_automute,
3061 }, 3155 },
3062 [ALC880_ASUS] = { 3156 [ALC880_ASUS] = {
3063 .mixers = { alc880_asus_mixer }, 3157 .mixers = { alc880_asus_mixer },
@@ -3205,6 +3299,20 @@ static struct alc_config_preset alc880_presets[] = {
3205 .unsol_event = alc880_lg_lw_unsol_event, 3299 .unsol_event = alc880_lg_lw_unsol_event,
3206 .init_hook = alc880_lg_lw_automute, 3300 .init_hook = alc880_lg_lw_automute,
3207 }, 3301 },
3302 [ALC880_MEDION_RIM] = {
3303 .mixers = { alc880_medion_rim_mixer },
3304 .init_verbs = { alc880_volume_init_verbs,
3305 alc880_medion_rim_init_verbs,
3306 alc_gpio2_init_verbs },
3307 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3308 .dac_nids = alc880_dac_nids,
3309 .dig_out_nid = ALC880_DIGOUT_NID,
3310 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3311 .channel_mode = alc880_2_jack_modes,
3312 .input_mux = &alc880_medion_rim_capture_source,
3313 .unsol_event = alc880_medion_rim_unsol_event,
3314 .init_hook = alc880_medion_rim_automute,
3315 },
3208#ifdef CONFIG_SND_DEBUG 3316#ifdef CONFIG_SND_DEBUG
3209 [ALC880_TEST] = { 3317 [ALC880_TEST] = {
3210 .mixers = { alc880_test_mixer }, 3318 .mixers = { alc880_test_mixer },
@@ -3467,15 +3575,21 @@ static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3467 return 0; 3575 return 0;
3468} 3576}
3469 3577
3470static void alc880_auto_set_output_and_unmute(struct hda_codec *codec, 3578static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3471 hda_nid_t nid, int pin_type, 3579 unsigned int pin_type)
3472 int dac_idx)
3473{ 3580{
3474 /* set as output */
3475 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 3581 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3476 pin_type); 3582 pin_type);
3583 /* unmute pin */
3477 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 3584 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3478 AMP_OUT_UNMUTE); 3585 AMP_OUT_UNMUTE);
3586}
3587
3588static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3589 hda_nid_t nid, int pin_type,
3590 int dac_idx)
3591{
3592 alc_set_pin_output(codec, nid, pin_type);
3479 /* need the manual connection? */ 3593 /* need the manual connection? */
3480 if (alc880_is_multi_pin(nid)) { 3594 if (alc880_is_multi_pin(nid)) {
3481 struct alc_spec *spec = codec->spec; 3595 struct alc_spec *spec = codec->spec;
@@ -3597,9 +3711,12 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
3597/* additional initialization for auto-configuration model */ 3711/* additional initialization for auto-configuration model */
3598static void alc880_auto_init(struct hda_codec *codec) 3712static void alc880_auto_init(struct hda_codec *codec)
3599{ 3713{
3714 struct alc_spec *spec = codec->spec;
3600 alc880_auto_init_multi_out(codec); 3715 alc880_auto_init_multi_out(codec);
3601 alc880_auto_init_extra_out(codec); 3716 alc880_auto_init_extra_out(codec);
3602 alc880_auto_init_analog_input(codec); 3717 alc880_auto_init_analog_input(codec);
3718 if (spec->unsol_event)
3719 alc_sku_automute(codec);
3603} 3720}
3604 3721
3605/* 3722/*
@@ -4795,11 +4912,7 @@ static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4795 hda_nid_t nid, int pin_type, 4912 hda_nid_t nid, int pin_type,
4796 int sel_idx) 4913 int sel_idx)
4797{ 4914{
4798 /* set as output */ 4915 alc_set_pin_output(codec, nid, pin_type);
4799 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4800 pin_type);
4801 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4802 AMP_OUT_UNMUTE);
4803 /* need the manual connection? */ 4916 /* need the manual connection? */
4804 if (nid >= 0x12) { 4917 if (nid >= 0x12) {
4805 int idx = nid - 0x12; 4918 int idx = nid - 0x12;
@@ -4929,7 +5042,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
4929 /* check whether NID 0x04 is valid */ 5042 /* check whether NID 0x04 is valid */
4930 wcap = get_wcaps(codec, 0x04); 5043 wcap = get_wcaps(codec, 0x04);
4931 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */ 5044 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4932 if (wcap != AC_WID_AUD_IN) { 5045 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
4933 spec->adc_nids = alc260_adc_nids_alt; 5046 spec->adc_nids = alc260_adc_nids_alt;
4934 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt); 5047 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4935 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer; 5048 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
@@ -4946,8 +5059,11 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
4946/* additional initialization for auto-configuration model */ 5059/* additional initialization for auto-configuration model */
4947static void alc260_auto_init(struct hda_codec *codec) 5060static void alc260_auto_init(struct hda_codec *codec)
4948{ 5061{
5062 struct alc_spec *spec = codec->spec;
4949 alc260_auto_init_multi_out(codec); 5063 alc260_auto_init_multi_out(codec);
4950 alc260_auto_init_analog_input(codec); 5064 alc260_auto_init_analog_input(codec);
5065 if (spec->unsol_event)
5066 alc_sku_automute(codec);
4951} 5067}
4952 5068
4953#ifdef CONFIG_SND_HDA_POWER_SAVE 5069#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -5204,6 +5320,9 @@ static hda_nid_t alc882_dac_nids[4] = {
5204#define alc882_adc_nids alc880_adc_nids 5320#define alc882_adc_nids alc880_adc_nids
5205#define alc882_adc_nids_alt alc880_adc_nids_alt 5321#define alc882_adc_nids_alt alc880_adc_nids_alt
5206 5322
5323static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5324static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5325
5207/* input MUX */ 5326/* input MUX */
5208/* FIXME: should be a matrix-type input source selection */ 5327/* FIXME: should be a matrix-type input source selection */
5209 5328
@@ -5226,15 +5345,11 @@ static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5226 struct alc_spec *spec = codec->spec; 5345 struct alc_spec *spec = codec->spec;
5227 const struct hda_input_mux *imux = spec->input_mux; 5346 const struct hda_input_mux *imux = spec->input_mux;
5228 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 5347 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5229 static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 }; 5348 hda_nid_t nid = spec->capsrc_nids ?
5230 hda_nid_t nid; 5349 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5231 unsigned int *cur_val = &spec->cur_mux[adc_idx]; 5350 unsigned int *cur_val = &spec->cur_mux[adc_idx];
5232 unsigned int i, idx; 5351 unsigned int i, idx;
5233 5352
5234 if (spec->num_adc_nids < 3)
5235 nid = capture_mixers[adc_idx + 1];
5236 else
5237 nid = capture_mixers[adc_idx];
5238 idx = ucontrol->value.enumerated.item[0]; 5353 idx = ucontrol->value.enumerated.item[0];
5239 if (idx >= imux->num_items) 5354 if (idx >= imux->num_items)
5240 idx = imux->num_items - 1; 5355 idx = imux->num_items - 1;
@@ -6111,6 +6226,7 @@ static struct alc_config_preset alc882_presets[] = {
6111 .dig_out_nid = ALC882_DIGOUT_NID, 6226 .dig_out_nid = ALC882_DIGOUT_NID,
6112 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids), 6227 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6113 .adc_nids = alc882_adc_nids, 6228 .adc_nids = alc882_adc_nids,
6229 .capsrc_nids = alc882_capsrc_nids,
6114 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes), 6230 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6115 .channel_mode = alc882_3ST_6ch_modes, 6231 .channel_mode = alc882_3ST_6ch_modes,
6116 .need_dac_fix = 1, 6232 .need_dac_fix = 1,
@@ -6127,6 +6243,7 @@ static struct alc_config_preset alc882_presets[] = {
6127 .dig_out_nid = ALC882_DIGOUT_NID, 6243 .dig_out_nid = ALC882_DIGOUT_NID,
6128 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids), 6244 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6129 .adc_nids = alc882_adc_nids, 6245 .adc_nids = alc882_adc_nids,
6246 .capsrc_nids = alc882_capsrc_nids,
6130 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes), 6247 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6131 .channel_mode = alc882_3ST_6ch_modes, 6248 .channel_mode = alc882_3ST_6ch_modes,
6132 .need_dac_fix = 1, 6249 .need_dac_fix = 1,
@@ -6182,15 +6299,11 @@ static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6182 struct alc_spec *spec = codec->spec; 6299 struct alc_spec *spec = codec->spec;
6183 int idx; 6300 int idx;
6184 6301
6302 alc_set_pin_output(codec, nid, pin_type);
6185 if (spec->multiout.dac_nids[dac_idx] == 0x25) 6303 if (spec->multiout.dac_nids[dac_idx] == 0x25)
6186 idx = 4; 6304 idx = 4;
6187 else 6305 else
6188 idx = spec->multiout.dac_nids[dac_idx] - 2; 6306 idx = spec->multiout.dac_nids[dac_idx] - 2;
6189
6190 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
6191 pin_type);
6192 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6193 AMP_OUT_UNMUTE);
6194 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx); 6307 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6195 6308
6196} 6309}
@@ -6219,6 +6332,9 @@ static void alc882_auto_init_hp_out(struct hda_codec *codec)
6219 if (pin) /* connect to front */ 6332 if (pin) /* connect to front */
6220 /* use dac 0 */ 6333 /* use dac 0 */
6221 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 6334 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6335 pin = spec->autocfg.speaker_pins[0];
6336 if (pin)
6337 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6222} 6338}
6223 6339
6224#define alc882_is_input_pin(nid) alc880_is_input_pin(nid) 6340#define alc882_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -6231,16 +6347,21 @@ static void alc882_auto_init_analog_input(struct hda_codec *codec)
6231 6347
6232 for (i = 0; i < AUTO_PIN_LAST; i++) { 6348 for (i = 0; i < AUTO_PIN_LAST; i++) {
6233 hda_nid_t nid = spec->autocfg.input_pins[i]; 6349 hda_nid_t nid = spec->autocfg.input_pins[i];
6234 if (alc882_is_input_pin(nid)) { 6350 unsigned int vref;
6235 snd_hda_codec_write(codec, nid, 0, 6351 if (!nid)
6236 AC_VERB_SET_PIN_WIDGET_CONTROL, 6352 continue;
6237 i <= AUTO_PIN_FRONT_MIC ? 6353 vref = PIN_IN;
6238 PIN_VREF80 : PIN_IN); 6354 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6239 if (nid != ALC882_PIN_CD_NID) 6355 if (snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP) &
6240 snd_hda_codec_write(codec, nid, 0, 6356 AC_PINCAP_VREF_80)
6241 AC_VERB_SET_AMP_GAIN_MUTE, 6357 vref = PIN_VREF80;
6242 AMP_OUT_MUTE);
6243 } 6358 }
6359 snd_hda_codec_write(codec, nid, 0,
6360 AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6361 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6362 snd_hda_codec_write(codec, nid, 0,
6363 AC_VERB_SET_AMP_GAIN_MUTE,
6364 AMP_OUT_MUTE);
6244 } 6365 }
6245} 6366}
6246 6367
@@ -6294,11 +6415,16 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
6294/* additional initialization for auto-configuration model */ 6415/* additional initialization for auto-configuration model */
6295static void alc882_auto_init(struct hda_codec *codec) 6416static void alc882_auto_init(struct hda_codec *codec)
6296{ 6417{
6418 struct alc_spec *spec = codec->spec;
6297 alc882_auto_init_multi_out(codec); 6419 alc882_auto_init_multi_out(codec);
6298 alc882_auto_init_hp_out(codec); 6420 alc882_auto_init_hp_out(codec);
6299 alc882_auto_init_analog_input(codec); 6421 alc882_auto_init_analog_input(codec);
6422 if (spec->unsol_event)
6423 alc_sku_automute(codec);
6300} 6424}
6301 6425
6426static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6427
6302static int patch_alc882(struct hda_codec *codec) 6428static int patch_alc882(struct hda_codec *codec)
6303{ 6429{
6304 struct alc_spec *spec; 6430 struct alc_spec *spec;
@@ -6328,6 +6454,11 @@ static int patch_alc882(struct hda_codec *codec)
6328 board_config = ALC885_MBP3; 6454 board_config = ALC885_MBP3;
6329 break; 6455 break;
6330 default: 6456 default:
6457 /* ALC889A is handled better as ALC888-compatible */
6458 if (codec->revision_id == 0x100103) {
6459 alc_free(codec);
6460 return patch_alc883(codec);
6461 }
6331 printk(KERN_INFO "hda_codec: Unknown model for ALC882, " 6462 printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6332 "trying auto-probe from BIOS...\n"); 6463 "trying auto-probe from BIOS...\n");
6333 board_config = ALC882_AUTO; 6464 board_config = ALC882_AUTO;
@@ -6372,12 +6503,14 @@ static int patch_alc882(struct hda_codec *codec)
6372 if (wcap != AC_WID_AUD_IN) { 6503 if (wcap != AC_WID_AUD_IN) {
6373 spec->adc_nids = alc882_adc_nids_alt; 6504 spec->adc_nids = alc882_adc_nids_alt;
6374 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt); 6505 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6506 spec->capsrc_nids = alc882_capsrc_nids_alt;
6375 spec->mixers[spec->num_mixers] = 6507 spec->mixers[spec->num_mixers] =
6376 alc882_capture_alt_mixer; 6508 alc882_capture_alt_mixer;
6377 spec->num_mixers++; 6509 spec->num_mixers++;
6378 } else { 6510 } else {
6379 spec->adc_nids = alc882_adc_nids; 6511 spec->adc_nids = alc882_adc_nids;
6380 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids); 6512 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6513 spec->capsrc_nids = alc882_capsrc_nids;
6381 spec->mixers[spec->num_mixers] = alc882_capture_mixer; 6514 spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6382 spec->num_mixers++; 6515 spec->num_mixers++;
6383 } 6516 }
@@ -6412,7 +6545,7 @@ static int patch_alc882(struct hda_codec *codec)
6412 6545
6413static hda_nid_t alc883_dac_nids[4] = { 6546static hda_nid_t alc883_dac_nids[4] = {
6414 /* front, rear, clfe, rear_surr */ 6547 /* front, rear, clfe, rear_surr */
6415 0x02, 0x04, 0x03, 0x05 6548 0x02, 0x03, 0x04, 0x05
6416}; 6549};
6417 6550
6418static hda_nid_t alc883_adc_nids[2] = { 6551static hda_nid_t alc883_adc_nids[2] = {
@@ -6420,6 +6553,8 @@ static hda_nid_t alc883_adc_nids[2] = {
6420 0x08, 0x09, 6553 0x08, 0x09,
6421}; 6554};
6422 6555
6556static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6557
6423/* input MUX */ 6558/* input MUX */
6424/* FIXME: should be a matrix-type input source selection */ 6559/* FIXME: should be a matrix-type input source selection */
6425 6560
@@ -6451,35 +6586,18 @@ static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6451 }, 6586 },
6452}; 6587};
6453 6588
6589static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6590 .num_items = 2,
6591 .items = {
6592 { "Mic", 0x0 },
6593 { "Int Mic", 0x1 },
6594 },
6595};
6596
6454#define alc883_mux_enum_info alc_mux_enum_info 6597#define alc883_mux_enum_info alc_mux_enum_info
6455#define alc883_mux_enum_get alc_mux_enum_get 6598#define alc883_mux_enum_get alc_mux_enum_get
6456 6599/* ALC883 has the ALC882-type input selection */
6457static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol, 6600#define alc883_mux_enum_put alc882_mux_enum_put
6458 struct snd_ctl_elem_value *ucontrol)
6459{
6460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6461 struct alc_spec *spec = codec->spec;
6462 const struct hda_input_mux *imux = spec->input_mux;
6463 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6464 static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
6465 hda_nid_t nid = capture_mixers[adc_idx];
6466 unsigned int *cur_val = &spec->cur_mux[adc_idx];
6467 unsigned int i, idx;
6468
6469 idx = ucontrol->value.enumerated.item[0];
6470 if (idx >= imux->num_items)
6471 idx = imux->num_items - 1;
6472 if (*cur_val == idx)
6473 return 0;
6474 for (i = 0; i < imux->num_items; i++) {
6475 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
6476 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
6477 imux->items[i].index,
6478 HDA_AMP_MUTE, v);
6479 }
6480 *cur_val = idx;
6481 return 1;
6482}
6483 6601
6484/* 6602/*
6485 * 2ch mode 6603 * 2ch mode
@@ -6638,6 +6756,60 @@ static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6638 { } /* end */ 6756 { } /* end */
6639}; 6757};
6640 6758
6759static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6760 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6761 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6762 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6763 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6764 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6765 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6766 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6767 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6768 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6769 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6770 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6771 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6772 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6773 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6774 {
6775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6776 /* .name = "Capture Source", */
6777 .name = "Input Source",
6778 .count = 2,
6779 .info = alc883_mux_enum_info,
6780 .get = alc883_mux_enum_get,
6781 .put = alc883_mux_enum_put,
6782 },
6783 { } /* end */
6784};
6785
6786static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6787 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6788 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6789 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6790 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6791 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6792 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6793 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6794 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6795 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6796 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6797 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6798 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6799 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6800 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6801 {
6802 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6803 /* .name = "Capture Source", */
6804 .name = "Input Source",
6805 .count = 2,
6806 .info = alc883_mux_enum_info,
6807 .get = alc883_mux_enum_get,
6808 .put = alc883_mux_enum_put,
6809 },
6810 { } /* end */
6811};
6812
6641static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = { 6813static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6642 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 6814 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6643 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 6815 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -6787,6 +6959,9 @@ static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6787 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 6959 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6788 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 6960 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6789 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 6961 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6962 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6963 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6964 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6790 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 6965 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6791 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 6966 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6792 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT), 6967 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
@@ -6878,124 +7053,6 @@ static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6878 { } /* end */ 7053 { } /* end */
6879}; 7054};
6880 7055
6881static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6882 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6883 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6884 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6885 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6886 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6887 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6888 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6889 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6890 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6891 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6892 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6893 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6894 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6895 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6896 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6897 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6898 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6899 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6900 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6901 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6902 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6903 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6904 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6905 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6906 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6907 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6908 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6909 {
6910 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6911 /* .name = "Capture Source", */
6912 .name = "Input Source",
6913 .count = 2,
6914 .info = alc883_mux_enum_info,
6915 .get = alc883_mux_enum_get,
6916 .put = alc883_mux_enum_put,
6917 },
6918 { } /* end */
6919};
6920
6921static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6922 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6923 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6924 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6925 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6926 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6927 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6928 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6929 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6930 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6931 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6932 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6933 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6934 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6935 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6936 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6937 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6938 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6939 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6940 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6941 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6942 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6943 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6944 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6945 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6946 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6947 {
6948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6949 /* .name = "Capture Source", */
6950 .name = "Input Source",
6951 .count = 2,
6952 .info = alc883_mux_enum_info,
6953 .get = alc883_mux_enum_get,
6954 .put = alc883_mux_enum_put,
6955 },
6956 { } /* end */
6957};
6958
6959static struct snd_kcontrol_new alc888_6st_dell_mixer[] = {
6960 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6961 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6962 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6963 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6964 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6965 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6966 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6967 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6968 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6969 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6970 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6971 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6972 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6973 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6974 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6975 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6976 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6977 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6978 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6979 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6980 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6981 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6982 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6983 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6984 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6985 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6986 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6987 {
6988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6989 /* .name = "Capture Source", */
6990 .name = "Input Source",
6991 .count = 2,
6992 .info = alc883_mux_enum_info,
6993 .get = alc883_mux_enum_get,
6994 .put = alc883_mux_enum_put,
6995 },
6996 { } /* end */
6997};
6998
6999static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = { 7056static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7000 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7057 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7001 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 7058 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -7171,6 +7228,35 @@ static struct hda_verb alc883_mitac_verbs[] = {
7171 { } /* end */ 7228 { } /* end */
7172}; 7229};
7173 7230
7231static struct hda_verb alc883_clevo_m720_verbs[] = {
7232 /* HP */
7233 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7234 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7235 /* Int speaker */
7236 {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7237 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7238
7239 /* enable unsolicited event */
7240 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7241 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7242
7243 { } /* end */
7244};
7245
7246static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7247 /* HP */
7248 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7249 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7250 /* Subwoofer */
7251 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7252 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7253
7254 /* enable unsolicited event */
7255 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7256
7257 { } /* end */
7258};
7259
7174static struct hda_verb alc883_tagra_verbs[] = { 7260static struct hda_verb alc883_tagra_verbs[] = {
7175 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7261 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7176 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 7262 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -7227,26 +7313,14 @@ static struct hda_verb alc883_haier_w66_verbs[] = {
7227 { } /* end */ 7313 { } /* end */
7228}; 7314};
7229 7315
7230static struct hda_verb alc888_6st_hp_verbs[] = {
7231 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7232 {0x15, AC_VERB_SET_CONNECT_SEL, 0x02}, /* Rear : output 2 (0x0e) */
7233 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* CLFE : output 1 (0x0d) */
7234 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03}, /* Side : output 3 (0x0f) */
7235 { }
7236};
7237
7238static struct hda_verb alc888_3st_hp_verbs[] = { 7316static struct hda_verb alc888_3st_hp_verbs[] = {
7239 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */ 7317 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7240 {0x18, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */ 7318 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */
7241 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02}, /* CLFE : output 2 (0x0e) */ 7319 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* CLFE : output 2 (0x0e) */
7242 { } 7320 { }
7243}; 7321};
7244 7322
7245static struct hda_verb alc888_6st_dell_verbs[] = { 7323static struct hda_verb alc888_6st_dell_verbs[] = {
7246 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7247 {0x15, AC_VERB_SET_CONNECT_SEL, 0x02}, /* Rear : output 1 (0x0e) */
7248 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* CLFE : output 2 (0x0d) */
7249 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03}, /* Side : output 3 (0x0f) */
7250 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 7324 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7251 { } 7325 { }
7252}; 7326};
@@ -7354,6 +7428,68 @@ static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7354 alc883_tagra_automute(codec); 7428 alc883_tagra_automute(codec);
7355} 7429}
7356 7430
7431/* toggle speaker-output according to the hp-jack state */
7432static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7433{
7434 unsigned int present;
7435 unsigned char bits;
7436
7437 present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7438 & AC_PINSENSE_PRESENCE;
7439 bits = present ? HDA_AMP_MUTE : 0;
7440 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7441 HDA_AMP_MUTE, bits);
7442}
7443
7444static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7445{
7446 unsigned int present;
7447
7448 present = snd_hda_codec_read(codec, 0x18, 0,
7449 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7450 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7451 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7452}
7453
7454static void alc883_clevo_m720_automute(struct hda_codec *codec)
7455{
7456 alc883_clevo_m720_hp_automute(codec);
7457 alc883_clevo_m720_mic_automute(codec);
7458}
7459
7460static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7461 unsigned int res)
7462{
7463 switch (res >> 26) {
7464 case ALC880_HP_EVENT:
7465 alc883_clevo_m720_hp_automute(codec);
7466 break;
7467 case ALC880_MIC_EVENT:
7468 alc883_clevo_m720_mic_automute(codec);
7469 break;
7470 }
7471}
7472
7473/* toggle speaker-output according to the hp-jack state */
7474static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7475{
7476 unsigned int present;
7477 unsigned char bits;
7478
7479 present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7480 & AC_PINSENSE_PRESENCE;
7481 bits = present ? HDA_AMP_MUTE : 0;
7482 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7483 HDA_AMP_MUTE, bits);
7484}
7485
7486static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7487 unsigned int res)
7488{
7489 if ((res >> 26) == ALC880_HP_EVENT)
7490 alc883_2ch_fujitsu_pi2515_automute(codec);
7491}
7492
7357static void alc883_haier_w66_automute(struct hda_codec *codec) 7493static void alc883_haier_w66_automute(struct hda_codec *codec)
7358{ 7494{
7359 unsigned int present; 7495 unsigned int present;
@@ -7587,10 +7723,11 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
7587 [ALC883_LENOVO_NB0763] = "lenovo-nb0763", 7723 [ALC883_LENOVO_NB0763] = "lenovo-nb0763",
7588 [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig", 7724 [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7589 [ALC883_HAIER_W66] = "haier-w66", 7725 [ALC883_HAIER_W66] = "haier-w66",
7590 [ALC888_6ST_HP] = "6stack-hp",
7591 [ALC888_3ST_HP] = "3stack-hp", 7726 [ALC888_3ST_HP] = "3stack-hp",
7592 [ALC888_6ST_DELL] = "6stack-dell", 7727 [ALC888_6ST_DELL] = "6stack-dell",
7593 [ALC883_MITAC] = "mitac", 7728 [ALC883_MITAC] = "mitac",
7729 [ALC883_CLEVO_M720] = "clevo-m720",
7730 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7594 [ALC883_AUTO] = "auto", 7731 [ALC883_AUTO] = "auto",
7595}; 7732};
7596 7733
@@ -7604,7 +7741,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7604 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), 7741 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7605 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP), 7742 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7606 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP), 7743 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7607 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP), 7744 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7608 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG), 7745 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7609 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG), 7746 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7610 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC), 7747 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
@@ -7614,7 +7751,9 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7614 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG), 7751 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7615 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG), 7752 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7616 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG), 7753 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7754 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7617 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG), 7755 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7756 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7618 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG), 7757 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7619 SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG), 7758 SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7620 SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG), 7759 SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
@@ -7627,13 +7766,17 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7627 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG), 7766 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7628 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG), 7767 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7629 SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG), 7768 SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7769 SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7630 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG), 7770 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7631 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG), 7771 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7632 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG), 7772 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7633 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG), 7773 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7774 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7775 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7634 SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD), 7776 SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7635 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch), 7777 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7636 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION), 7778 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7779 SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7637 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch), 7780 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7638 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763), 7781 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7639 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763), 7782 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
@@ -7652,8 +7795,6 @@ static struct alc_config_preset alc883_presets[] = {
7652 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7795 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7653 .dac_nids = alc883_dac_nids, 7796 .dac_nids = alc883_dac_nids,
7654 .dig_out_nid = ALC883_DIGOUT_NID, 7797 .dig_out_nid = ALC883_DIGOUT_NID,
7655 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7656 .adc_nids = alc883_adc_nids,
7657 .dig_in_nid = ALC883_DIGIN_NID, 7798 .dig_in_nid = ALC883_DIGIN_NID,
7658 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7799 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7659 .channel_mode = alc883_3ST_2ch_modes, 7800 .channel_mode = alc883_3ST_2ch_modes,
@@ -7665,8 +7806,6 @@ static struct alc_config_preset alc883_presets[] = {
7665 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7806 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7666 .dac_nids = alc883_dac_nids, 7807 .dac_nids = alc883_dac_nids,
7667 .dig_out_nid = ALC883_DIGOUT_NID, 7808 .dig_out_nid = ALC883_DIGOUT_NID,
7668 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7669 .adc_nids = alc883_adc_nids,
7670 .dig_in_nid = ALC883_DIGIN_NID, 7809 .dig_in_nid = ALC883_DIGIN_NID,
7671 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7810 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7672 .channel_mode = alc883_3ST_6ch_modes, 7811 .channel_mode = alc883_3ST_6ch_modes,
@@ -7678,8 +7817,6 @@ static struct alc_config_preset alc883_presets[] = {
7678 .init_verbs = { alc883_init_verbs }, 7817 .init_verbs = { alc883_init_verbs },
7679 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7818 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7680 .dac_nids = alc883_dac_nids, 7819 .dac_nids = alc883_dac_nids,
7681 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7682 .adc_nids = alc883_adc_nids,
7683 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7820 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7684 .channel_mode = alc883_3ST_6ch_modes, 7821 .channel_mode = alc883_3ST_6ch_modes,
7685 .need_dac_fix = 1, 7822 .need_dac_fix = 1,
@@ -7691,8 +7828,6 @@ static struct alc_config_preset alc883_presets[] = {
7691 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7828 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7692 .dac_nids = alc883_dac_nids, 7829 .dac_nids = alc883_dac_nids,
7693 .dig_out_nid = ALC883_DIGOUT_NID, 7830 .dig_out_nid = ALC883_DIGOUT_NID,
7694 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7695 .adc_nids = alc883_adc_nids,
7696 .dig_in_nid = ALC883_DIGIN_NID, 7831 .dig_in_nid = ALC883_DIGIN_NID,
7697 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7832 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7698 .channel_mode = alc883_sixstack_modes, 7833 .channel_mode = alc883_sixstack_modes,
@@ -7704,8 +7839,6 @@ static struct alc_config_preset alc883_presets[] = {
7704 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7839 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7705 .dac_nids = alc883_dac_nids, 7840 .dac_nids = alc883_dac_nids,
7706 .dig_out_nid = ALC883_DIGOUT_NID, 7841 .dig_out_nid = ALC883_DIGOUT_NID,
7707 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7708 .adc_nids = alc883_adc_nids,
7709 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7842 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7710 .channel_mode = alc883_3ST_6ch_modes, 7843 .channel_mode = alc883_3ST_6ch_modes,
7711 .need_dac_fix = 1, 7844 .need_dac_fix = 1,
@@ -7719,8 +7852,6 @@ static struct alc_config_preset alc883_presets[] = {
7719 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7852 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7720 .dac_nids = alc883_dac_nids, 7853 .dac_nids = alc883_dac_nids,
7721 .dig_out_nid = ALC883_DIGOUT_NID, 7854 .dig_out_nid = ALC883_DIGOUT_NID,
7722 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7723 .adc_nids = alc883_adc_nids,
7724 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7855 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7725 .channel_mode = alc883_3ST_2ch_modes, 7856 .channel_mode = alc883_3ST_2ch_modes,
7726 .input_mux = &alc883_capture_source, 7857 .input_mux = &alc883_capture_source,
@@ -7737,8 +7868,6 @@ static struct alc_config_preset alc883_presets[] = {
7737 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs }, 7868 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7738 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7869 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7739 .dac_nids = alc883_dac_nids, 7870 .dac_nids = alc883_dac_nids,
7740 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7741 .adc_nids = alc883_adc_nids,
7742 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7871 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7743 .channel_mode = alc883_3ST_2ch_modes, 7872 .channel_mode = alc883_3ST_2ch_modes,
7744 .input_mux = &alc883_capture_source, 7873 .input_mux = &alc883_capture_source,
@@ -7749,8 +7878,6 @@ static struct alc_config_preset alc883_presets[] = {
7749 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7878 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7750 .dac_nids = alc883_dac_nids, 7879 .dac_nids = alc883_dac_nids,
7751 .dig_out_nid = ALC883_DIGOUT_NID, 7880 .dig_out_nid = ALC883_DIGOUT_NID,
7752 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7753 .adc_nids = alc883_adc_nids,
7754 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7881 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7755 .channel_mode = alc883_3ST_2ch_modes, 7882 .channel_mode = alc883_3ST_2ch_modes,
7756 .input_mux = &alc883_capture_source, 7883 .input_mux = &alc883_capture_source,
@@ -7764,8 +7891,6 @@ static struct alc_config_preset alc883_presets[] = {
7764 alc883_medion_eapd_verbs }, 7891 alc883_medion_eapd_verbs },
7765 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7892 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7766 .dac_nids = alc883_dac_nids, 7893 .dac_nids = alc883_dac_nids,
7767 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7768 .adc_nids = alc883_adc_nids,
7769 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7894 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7770 .channel_mode = alc883_sixstack_modes, 7895 .channel_mode = alc883_sixstack_modes,
7771 .input_mux = &alc883_capture_source, 7896 .input_mux = &alc883_capture_source,
@@ -7776,8 +7901,6 @@ static struct alc_config_preset alc883_presets[] = {
7776 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7901 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7777 .dac_nids = alc883_dac_nids, 7902 .dac_nids = alc883_dac_nids,
7778 .dig_out_nid = ALC883_DIGOUT_NID, 7903 .dig_out_nid = ALC883_DIGOUT_NID,
7779 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7780 .adc_nids = alc883_adc_nids,
7781 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7904 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7782 .channel_mode = alc883_3ST_2ch_modes, 7905 .channel_mode = alc883_3ST_2ch_modes,
7783 .input_mux = &alc883_capture_source, 7906 .input_mux = &alc883_capture_source,
@@ -7789,19 +7912,27 @@ static struct alc_config_preset alc883_presets[] = {
7789 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs }, 7912 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7790 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7913 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7791 .dac_nids = alc883_dac_nids, 7914 .dac_nids = alc883_dac_nids,
7792 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7793 .adc_nids = alc883_adc_nids,
7794 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7915 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7795 .channel_mode = alc883_3ST_2ch_modes, 7916 .channel_mode = alc883_3ST_2ch_modes,
7796 .input_mux = &alc883_capture_source, 7917 .input_mux = &alc883_capture_source,
7797 }, 7918 },
7919 [ALC883_CLEVO_M720] = {
7920 .mixers = { alc883_clevo_m720_mixer },
7921 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
7922 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7923 .dac_nids = alc883_dac_nids,
7924 .dig_out_nid = ALC883_DIGOUT_NID,
7925 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7926 .channel_mode = alc883_3ST_2ch_modes,
7927 .input_mux = &alc883_capture_source,
7928 .unsol_event = alc883_clevo_m720_unsol_event,
7929 .init_hook = alc883_clevo_m720_automute,
7930 },
7798 [ALC883_LENOVO_101E_2ch] = { 7931 [ALC883_LENOVO_101E_2ch] = {
7799 .mixers = { alc883_lenovo_101e_2ch_mixer}, 7932 .mixers = { alc883_lenovo_101e_2ch_mixer},
7800 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs}, 7933 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7801 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7934 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7802 .dac_nids = alc883_dac_nids, 7935 .dac_nids = alc883_dac_nids,
7803 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7804 .adc_nids = alc883_adc_nids,
7805 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7936 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7806 .channel_mode = alc883_3ST_2ch_modes, 7937 .channel_mode = alc883_3ST_2ch_modes,
7807 .input_mux = &alc883_lenovo_101e_capture_source, 7938 .input_mux = &alc883_lenovo_101e_capture_source,
@@ -7813,8 +7944,6 @@ static struct alc_config_preset alc883_presets[] = {
7813 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs}, 7944 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7814 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7945 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7815 .dac_nids = alc883_dac_nids, 7946 .dac_nids = alc883_dac_nids,
7816 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7817 .adc_nids = alc883_adc_nids,
7818 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7947 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7819 .channel_mode = alc883_3ST_2ch_modes, 7948 .channel_mode = alc883_3ST_2ch_modes,
7820 .need_dac_fix = 1, 7949 .need_dac_fix = 1,
@@ -7828,8 +7957,6 @@ static struct alc_config_preset alc883_presets[] = {
7828 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7957 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7829 .dac_nids = alc883_dac_nids, 7958 .dac_nids = alc883_dac_nids,
7830 .dig_out_nid = ALC883_DIGOUT_NID, 7959 .dig_out_nid = ALC883_DIGOUT_NID,
7831 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7832 .adc_nids = alc883_adc_nids,
7833 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7960 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7834 .channel_mode = alc883_3ST_6ch_modes, 7961 .channel_mode = alc883_3ST_6ch_modes,
7835 .need_dac_fix = 1, 7962 .need_dac_fix = 1,
@@ -7843,47 +7970,28 @@ static struct alc_config_preset alc883_presets[] = {
7843 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7970 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7844 .dac_nids = alc883_dac_nids, 7971 .dac_nids = alc883_dac_nids,
7845 .dig_out_nid = ALC883_DIGOUT_NID, 7972 .dig_out_nid = ALC883_DIGOUT_NID,
7846 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7847 .adc_nids = alc883_adc_nids,
7848 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7973 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7849 .channel_mode = alc883_3ST_2ch_modes, 7974 .channel_mode = alc883_3ST_2ch_modes,
7850 .input_mux = &alc883_capture_source, 7975 .input_mux = &alc883_capture_source,
7851 .unsol_event = alc883_haier_w66_unsol_event, 7976 .unsol_event = alc883_haier_w66_unsol_event,
7852 .init_hook = alc883_haier_w66_automute, 7977 .init_hook = alc883_haier_w66_automute,
7853 },
7854 [ALC888_6ST_HP] = {
7855 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7856 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7857 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7858 .dac_nids = alc883_dac_nids,
7859 .dig_out_nid = ALC883_DIGOUT_NID,
7860 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7861 .adc_nids = alc883_adc_nids,
7862 .dig_in_nid = ALC883_DIGIN_NID,
7863 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7864 .channel_mode = alc883_sixstack_modes,
7865 .input_mux = &alc883_capture_source,
7866 }, 7978 },
7867 [ALC888_3ST_HP] = { 7979 [ALC888_3ST_HP] = {
7868 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer }, 7980 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7869 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs }, 7981 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7870 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7982 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7871 .dac_nids = alc883_dac_nids, 7983 .dac_nids = alc883_dac_nids,
7872 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7873 .adc_nids = alc883_adc_nids,
7874 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes), 7984 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7875 .channel_mode = alc888_3st_hp_modes, 7985 .channel_mode = alc888_3st_hp_modes,
7876 .need_dac_fix = 1, 7986 .need_dac_fix = 1,
7877 .input_mux = &alc883_capture_source, 7987 .input_mux = &alc883_capture_source,
7878 }, 7988 },
7879 [ALC888_6ST_DELL] = { 7989 [ALC888_6ST_DELL] = {
7880 .mixers = { alc888_6st_dell_mixer, alc883_chmode_mixer }, 7990 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7881 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs }, 7991 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
7882 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7992 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7883 .dac_nids = alc883_dac_nids, 7993 .dac_nids = alc883_dac_nids,
7884 .dig_out_nid = ALC883_DIGOUT_NID, 7994 .dig_out_nid = ALC883_DIGOUT_NID,
7885 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7886 .adc_nids = alc883_adc_nids,
7887 .dig_in_nid = ALC883_DIGIN_NID, 7995 .dig_in_nid = ALC883_DIGIN_NID,
7888 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7996 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7889 .channel_mode = alc883_sixstack_modes, 7997 .channel_mode = alc883_sixstack_modes,
@@ -7896,14 +8004,25 @@ static struct alc_config_preset alc883_presets[] = {
7896 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs }, 8004 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
7897 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 8005 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7898 .dac_nids = alc883_dac_nids, 8006 .dac_nids = alc883_dac_nids,
7899 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7900 .adc_nids = alc883_adc_nids,
7901 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 8007 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7902 .channel_mode = alc883_3ST_2ch_modes, 8008 .channel_mode = alc883_3ST_2ch_modes,
7903 .input_mux = &alc883_capture_source, 8009 .input_mux = &alc883_capture_source,
7904 .unsol_event = alc883_mitac_unsol_event, 8010 .unsol_event = alc883_mitac_unsol_event,
7905 .init_hook = alc883_mitac_automute, 8011 .init_hook = alc883_mitac_automute,
7906 }, 8012 },
8013 [ALC883_FUJITSU_PI2515] = {
8014 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8015 .init_verbs = { alc883_init_verbs,
8016 alc883_2ch_fujitsu_pi2515_verbs},
8017 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8018 .dac_nids = alc883_dac_nids,
8019 .dig_out_nid = ALC883_DIGOUT_NID,
8020 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8021 .channel_mode = alc883_3ST_2ch_modes,
8022 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8023 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8024 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8025 },
7907}; 8026};
7908 8027
7909 8028
@@ -7918,15 +8037,11 @@ static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7918 struct alc_spec *spec = codec->spec; 8037 struct alc_spec *spec = codec->spec;
7919 int idx; 8038 int idx;
7920 8039
8040 alc_set_pin_output(codec, nid, pin_type);
7921 if (spec->multiout.dac_nids[dac_idx] == 0x25) 8041 if (spec->multiout.dac_nids[dac_idx] == 0x25)
7922 idx = 4; 8042 idx = 4;
7923 else 8043 else
7924 idx = spec->multiout.dac_nids[dac_idx] - 2; 8044 idx = spec->multiout.dac_nids[dac_idx] - 2;
7925
7926 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7927 pin_type);
7928 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7929 AMP_OUT_UNMUTE);
7930 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx); 8045 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7931 8046
7932} 8047}
@@ -7955,6 +8070,9 @@ static void alc883_auto_init_hp_out(struct hda_codec *codec)
7955 if (pin) /* connect to front */ 8070 if (pin) /* connect to front */
7956 /* use dac 0 */ 8071 /* use dac 0 */
7957 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 8072 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8073 pin = spec->autocfg.speaker_pins[0];
8074 if (pin)
8075 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7958} 8076}
7959 8077
7960#define alc883_is_input_pin(nid) alc880_is_input_pin(nid) 8078#define alc883_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -8006,9 +8124,12 @@ static int alc883_parse_auto_config(struct hda_codec *codec)
8006/* additional initialization for auto-configuration model */ 8124/* additional initialization for auto-configuration model */
8007static void alc883_auto_init(struct hda_codec *codec) 8125static void alc883_auto_init(struct hda_codec *codec)
8008{ 8126{
8127 struct alc_spec *spec = codec->spec;
8009 alc883_auto_init_multi_out(codec); 8128 alc883_auto_init_multi_out(codec);
8010 alc883_auto_init_hp_out(codec); 8129 alc883_auto_init_hp_out(codec);
8011 alc883_auto_init_analog_input(codec); 8130 alc883_auto_init_analog_input(codec);
8131 if (spec->unsol_event)
8132 alc_sku_automute(codec);
8012} 8133}
8013 8134
8014static int patch_alc883(struct hda_codec *codec) 8135static int patch_alc883(struct hda_codec *codec)
@@ -8057,10 +8178,9 @@ static int patch_alc883(struct hda_codec *codec)
8057 spec->stream_digital_playback = &alc883_pcm_digital_playback; 8178 spec->stream_digital_playback = &alc883_pcm_digital_playback;
8058 spec->stream_digital_capture = &alc883_pcm_digital_capture; 8179 spec->stream_digital_capture = &alc883_pcm_digital_capture;
8059 8180
8060 if (!spec->adc_nids && spec->input_mux) { 8181 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8061 spec->adc_nids = alc883_adc_nids; 8182 spec->adc_nids = alc883_adc_nids;
8062 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids); 8183 spec->capsrc_nids = alc883_capsrc_nids;
8063 }
8064 8184
8065 spec->vmaster_nid = 0x0c; 8185 spec->vmaster_nid = 0x0c;
8066 8186
@@ -8085,6 +8205,8 @@ static int patch_alc883(struct hda_codec *codec)
8085#define alc262_dac_nids alc260_dac_nids 8205#define alc262_dac_nids alc260_dac_nids
8086#define alc262_adc_nids alc882_adc_nids 8206#define alc262_adc_nids alc882_adc_nids
8087#define alc262_adc_nids_alt alc882_adc_nids_alt 8207#define alc262_adc_nids_alt alc882_adc_nids_alt
8208#define alc262_capsrc_nids alc882_capsrc_nids
8209#define alc262_capsrc_nids_alt alc882_capsrc_nids_alt
8088 8210
8089#define alc262_modes alc260_modes 8211#define alc262_modes alc260_modes
8090#define alc262_capture_source alc882_capture_source 8212#define alc262_capture_source alc882_capture_source
@@ -8585,7 +8707,8 @@ static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8585 8707
8586/* 8708/*
8587 * fujitsu model 8709 * fujitsu model
8588 * 0x14 = headphone/spdif-out, 0x15 = internal speaker 8710 * 0x14 = headphone/spdif-out, 0x15 = internal speaker,
8711 * 0x1b = port replicator headphone out
8589 */ 8712 */
8590 8713
8591#define ALC_HP_EVENT 0x37 8714#define ALC_HP_EVENT 0x37
@@ -8593,6 +8716,14 @@ static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8593static struct hda_verb alc262_fujitsu_unsol_verbs[] = { 8716static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8594 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT}, 8717 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8595 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 8718 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8719 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8720 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8721 {}
8722};
8723
8724static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
8725 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8726 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8596 {} 8727 {}
8597}; 8728};
8598 8729
@@ -8633,12 +8764,16 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8633 unsigned int mute; 8764 unsigned int mute;
8634 8765
8635 if (force || !spec->sense_updated) { 8766 if (force || !spec->sense_updated) {
8636 unsigned int present; 8767 unsigned int present_int_hp, present_dock_hp;
8637 /* need to execute and sync at first */ 8768 /* need to execute and sync at first */
8638 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0); 8769 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8639 present = snd_hda_codec_read(codec, 0x14, 0, 8770 present_int_hp = snd_hda_codec_read(codec, 0x14, 0,
8640 AC_VERB_GET_PIN_SENSE, 0); 8771 AC_VERB_GET_PIN_SENSE, 0);
8641 spec->jack_present = (present & 0x80000000) != 0; 8772 snd_hda_codec_read(codec, 0x1B, 0, AC_VERB_SET_PIN_SENSE, 0);
8773 present_dock_hp = snd_hda_codec_read(codec, 0x1b, 0,
8774 AC_VERB_GET_PIN_SENSE, 0);
8775 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8776 spec->jack_present |= (present_dock_hp & 0x80000000) != 0;
8642 spec->sense_updated = 1; 8777 spec->sense_updated = 1;
8643 } 8778 }
8644 if (spec->jack_present) { 8779 if (spec->jack_present) {
@@ -8672,6 +8807,46 @@ static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8672 }, 8807 },
8673}; 8808};
8674 8809
8810/* mute/unmute internal speaker according to the hp jack and mute state */
8811static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
8812{
8813 struct alc_spec *spec = codec->spec;
8814 unsigned int mute;
8815
8816 if (force || !spec->sense_updated) {
8817 unsigned int present_int_hp;
8818 /* need to execute and sync at first */
8819 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8820 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
8821 AC_VERB_GET_PIN_SENSE, 0);
8822 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8823 spec->sense_updated = 1;
8824 }
8825 if (spec->jack_present) {
8826 /* mute internal speaker */
8827 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8828 HDA_AMP_MUTE, HDA_AMP_MUTE);
8829 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8830 HDA_AMP_MUTE, HDA_AMP_MUTE);
8831 } else {
8832 /* unmute internal speaker if necessary */
8833 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8834 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8835 HDA_AMP_MUTE, mute);
8836 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8837 HDA_AMP_MUTE, mute);
8838 }
8839}
8840
8841/* unsolicited event for HP jack sensing */
8842static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
8843 unsigned int res)
8844{
8845 if ((res >> 26) != ALC_HP_EVENT)
8846 return;
8847 alc262_lenovo_3000_automute(codec, 1);
8848}
8849
8675/* bind hp and internal speaker mute (with plug check) */ 8850/* bind hp and internal speaker mute (with plug check) */
8676static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol, 8851static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8677 struct snd_ctl_elem_value *ucontrol) 8852 struct snd_ctl_elem_value *ucontrol)
@@ -8680,12 +8855,13 @@ static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8680 long *valp = ucontrol->value.integer.value; 8855 long *valp = ucontrol->value.integer.value;
8681 int change; 8856 int change;
8682 8857
8683 change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0, 8858 change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8684 HDA_AMP_MUTE, 8859 HDA_AMP_MUTE,
8685 valp[0] ? 0 : HDA_AMP_MUTE); 8860 valp ? 0 : HDA_AMP_MUTE);
8686 change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0, 8861 change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8687 HDA_AMP_MUTE, 8862 HDA_AMP_MUTE,
8688 valp[1] ? 0 : HDA_AMP_MUTE); 8863 valp ? 0 : HDA_AMP_MUTE);
8864
8689 if (change) 8865 if (change)
8690 alc262_fujitsu_automute(codec, 0); 8866 alc262_fujitsu_automute(codec, 0);
8691 return change; 8867 return change;
@@ -8703,6 +8879,46 @@ static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8703 }, 8879 },
8704 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 8880 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8705 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 8881 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8882 HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
8883 HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
8884 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8885 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8886 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8887 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8888 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8889 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8890 { } /* end */
8891};
8892
8893/* bind hp and internal speaker mute (with plug check) */
8894static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
8895 struct snd_ctl_elem_value *ucontrol)
8896{
8897 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8898 long *valp = ucontrol->value.integer.value;
8899 int change;
8900
8901 change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8902 HDA_AMP_MUTE,
8903 valp ? 0 : HDA_AMP_MUTE);
8904
8905 if (change)
8906 alc262_lenovo_3000_automute(codec, 0);
8907 return change;
8908}
8909
8910static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
8911 HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8912 {
8913 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8914 .name = "Master Playback Switch",
8915 .info = snd_hda_mixer_amp_switch_info,
8916 .get = snd_hda_mixer_amp_switch_get,
8917 .put = alc262_lenovo_3000_master_sw_put,
8918 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
8919 },
8920 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8921 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8706 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8922 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8707 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8923 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8708 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8924 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
@@ -8730,59 +8946,72 @@ static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8730 8946
8731/* Samsung Q1 Ultra Vista model setup */ 8947/* Samsung Q1 Ultra Vista model setup */
8732static struct snd_kcontrol_new alc262_ultra_mixer[] = { 8948static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8733 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 8949 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8734 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT), 8950 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
8735 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8736 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 8951 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8737 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 8952 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8738 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT), 8953 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8954 HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
8739 { } /* end */ 8955 { } /* end */
8740}; 8956};
8741 8957
8742static struct hda_verb alc262_ultra_verbs[] = { 8958static struct hda_verb alc262_ultra_verbs[] = {
8743 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, 8959 /* output mixer */
8960 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8961 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8962 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8963 /* speaker */
8964 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8965 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8966 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8967 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8968 /* HP */
8744 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 8969 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8745 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 8970 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8746 /* Mic is on Node 0x19 */ 8971 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8747 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24}, 8972 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8748 {0x22, AC_VERB_SET_CONNECT_SEL, 0x01}, 8973 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8749 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8974 /* internal mic */
8750 {0x23, AC_VERB_SET_CONNECT_SEL, 0x01}, 8975 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8751 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8976 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8752 {0x24, AC_VERB_SET_CONNECT_SEL, 0x01}, 8977 /* ADC, choose mic */
8753 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8978 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8979 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8980 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8981 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8982 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8983 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8984 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8985 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8986 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8987 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
8754 {} 8988 {}
8755}; 8989};
8756 8990
8757static struct hda_input_mux alc262_ultra_capture_source = {
8758 .num_items = 1,
8759 .items = {
8760 { "Mic", 0x1 },
8761 },
8762};
8763
8764/* mute/unmute internal speaker according to the hp jack and mute state */ 8991/* mute/unmute internal speaker according to the hp jack and mute state */
8765static void alc262_ultra_automute(struct hda_codec *codec) 8992static void alc262_ultra_automute(struct hda_codec *codec)
8766{ 8993{
8767 struct alc_spec *spec = codec->spec; 8994 struct alc_spec *spec = codec->spec;
8768 unsigned int mute; 8995 unsigned int mute;
8769 unsigned int present;
8770 8996
8771 /* need to execute and sync at first */ 8997 mute = 0;
8772 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0); 8998 /* auto-mute only when HP is used as HP */
8773 present = snd_hda_codec_read(codec, 0x15, 0, 8999 if (!spec->cur_mux[0]) {
8774 AC_VERB_GET_PIN_SENSE, 0); 9000 unsigned int present;
8775 spec->jack_present = (present & 0x80000000) != 0; 9001 /* need to execute and sync at first */
8776 if (spec->jack_present) { 9002 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8777 /* mute internal speaker */ 9003 present = snd_hda_codec_read(codec, 0x15, 0,
8778 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 9004 AC_VERB_GET_PIN_SENSE, 0);
8779 HDA_AMP_MUTE, HDA_AMP_MUTE); 9005 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8780 } else { 9006 if (spec->jack_present)
8781 /* unmute internal speaker if necessary */ 9007 mute = HDA_AMP_MUTE;
8782 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8783 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8784 HDA_AMP_MUTE, mute);
8785 } 9008 }
9009 /* mute/unmute internal speaker */
9010 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9011 HDA_AMP_MUTE, mute);
9012 /* mute/unmute HP */
9013 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9014 HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
8786} 9015}
8787 9016
8788/* unsolicited event for HP jack sensing */ 9017/* unsolicited event for HP jack sensing */
@@ -8794,6 +9023,45 @@ static void alc262_ultra_unsol_event(struct hda_codec *codec,
8794 alc262_ultra_automute(codec); 9023 alc262_ultra_automute(codec);
8795} 9024}
8796 9025
9026static struct hda_input_mux alc262_ultra_capture_source = {
9027 .num_items = 2,
9028 .items = {
9029 { "Mic", 0x1 },
9030 { "Headphone", 0x7 },
9031 },
9032};
9033
9034static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9035 struct snd_ctl_elem_value *ucontrol)
9036{
9037 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9038 struct alc_spec *spec = codec->spec;
9039 int ret;
9040
9041 ret = alc882_mux_enum_put(kcontrol, ucontrol);
9042 if (!ret)
9043 return 0;
9044 /* reprogram the HP pin as mic or HP according to the input source */
9045 snd_hda_codec_write_cache(codec, 0x15, 0,
9046 AC_VERB_SET_PIN_WIDGET_CONTROL,
9047 spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9048 alc262_ultra_automute(codec); /* mute/unmute HP */
9049 return ret;
9050}
9051
9052static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9053 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9054 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9055 {
9056 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9057 .name = "Capture Source",
9058 .info = alc882_mux_enum_info,
9059 .get = alc882_mux_enum_get,
9060 .put = alc262_ultra_mux_enum_put,
9061 },
9062 { } /* end */
9063};
9064
8797/* add playback controls from the parsed DAC table */ 9065/* add playback controls from the parsed DAC table */
8798static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, 9066static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
8799 const struct auto_pin_cfg *cfg) 9067 const struct auto_pin_cfg *cfg)
@@ -9185,9 +9453,12 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
9185/* init callback for auto-configuration model -- overriding the default init */ 9453/* init callback for auto-configuration model -- overriding the default init */
9186static void alc262_auto_init(struct hda_codec *codec) 9454static void alc262_auto_init(struct hda_codec *codec)
9187{ 9455{
9456 struct alc_spec *spec = codec->spec;
9188 alc262_auto_init_multi_out(codec); 9457 alc262_auto_init_multi_out(codec);
9189 alc262_auto_init_hp_out(codec); 9458 alc262_auto_init_hp_out(codec);
9190 alc262_auto_init_analog_input(codec); 9459 alc262_auto_init_analog_input(codec);
9460 if (spec->unsol_event)
9461 alc_sku_automute(codec);
9191} 9462}
9192 9463
9193/* 9464/*
@@ -9206,6 +9477,7 @@ static const char *alc262_models[ALC262_MODEL_LAST] = {
9206 [ALC262_BENQ_T31] = "benq-t31", 9477 [ALC262_BENQ_T31] = "benq-t31",
9207 [ALC262_SONY_ASSAMD] = "sony-assamd", 9478 [ALC262_SONY_ASSAMD] = "sony-assamd",
9208 [ALC262_ULTRA] = "ultra", 9479 [ALC262_ULTRA] = "ultra",
9480 [ALC262_LENOVO_3000] = "lenovo-3000",
9209 [ALC262_AUTO] = "auto", 9481 [ALC262_AUTO] = "auto",
9210}; 9482};
9211 9483
@@ -9241,6 +9513,8 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
9241 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU), 9513 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9242 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU), 9514 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9243 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA), 9515 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9516 SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9517 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9244 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8), 9518 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9245 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31), 9519 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9246 SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1), 9520 SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
@@ -9390,18 +9664,32 @@ static struct alc_config_preset alc262_presets[] = {
9390 .init_hook = alc262_hippo_automute, 9664 .init_hook = alc262_hippo_automute,
9391 }, 9665 },
9392 [ALC262_ULTRA] = { 9666 [ALC262_ULTRA] = {
9393 .mixers = { alc262_ultra_mixer }, 9667 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9394 .init_verbs = { alc262_init_verbs, alc262_ultra_verbs }, 9668 .init_verbs = { alc262_ultra_verbs },
9395 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 9669 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9396 .dac_nids = alc262_dac_nids, 9670 .dac_nids = alc262_dac_nids,
9397 .hp_nid = 0x03,
9398 .dig_out_nid = ALC262_DIGOUT_NID,
9399 .num_channel_mode = ARRAY_SIZE(alc262_modes), 9671 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9400 .channel_mode = alc262_modes, 9672 .channel_mode = alc262_modes,
9401 .input_mux = &alc262_ultra_capture_source, 9673 .input_mux = &alc262_ultra_capture_source,
9674 .adc_nids = alc262_adc_nids, /* ADC0 */
9675 .capsrc_nids = alc262_capsrc_nids,
9676 .num_adc_nids = 1, /* single ADC */
9402 .unsol_event = alc262_ultra_unsol_event, 9677 .unsol_event = alc262_ultra_unsol_event,
9403 .init_hook = alc262_ultra_automute, 9678 .init_hook = alc262_ultra_automute,
9404 }, 9679 },
9680 [ALC262_LENOVO_3000] = {
9681 .mixers = { alc262_lenovo_3000_mixer },
9682 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9683 alc262_lenovo_3000_unsol_verbs },
9684 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9685 .dac_nids = alc262_dac_nids,
9686 .hp_nid = 0x03,
9687 .dig_out_nid = ALC262_DIGOUT_NID,
9688 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9689 .channel_mode = alc262_modes,
9690 .input_mux = &alc262_fujitsu_capture_source,
9691 .unsol_event = alc262_lenovo_3000_unsol_event,
9692 },
9405}; 9693};
9406 9694
9407static int patch_alc262(struct hda_codec *codec) 9695static int patch_alc262(struct hda_codec *codec)
@@ -9472,12 +9760,14 @@ static int patch_alc262(struct hda_codec *codec)
9472 if (wcap != AC_WID_AUD_IN) { 9760 if (wcap != AC_WID_AUD_IN) {
9473 spec->adc_nids = alc262_adc_nids_alt; 9761 spec->adc_nids = alc262_adc_nids_alt;
9474 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt); 9762 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9763 spec->capsrc_nids = alc262_capsrc_nids_alt;
9475 spec->mixers[spec->num_mixers] = 9764 spec->mixers[spec->num_mixers] =
9476 alc262_capture_alt_mixer; 9765 alc262_capture_alt_mixer;
9477 spec->num_mixers++; 9766 spec->num_mixers++;
9478 } else { 9767 } else {
9479 spec->adc_nids = alc262_adc_nids; 9768 spec->adc_nids = alc262_adc_nids;
9480 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids); 9769 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9770 spec->capsrc_nids = alc262_capsrc_nids;
9481 spec->mixers[spec->num_mixers] = alc262_capture_mixer; 9771 spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9482 spec->num_mixers++; 9772 spec->num_mixers++;
9483 } 9773 }
@@ -9517,6 +9807,8 @@ static hda_nid_t alc268_adc_nids_alt[1] = {
9517 0x08 9807 0x08
9518}; 9808};
9519 9809
9810static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
9811
9520static struct snd_kcontrol_new alc268_base_mixer[] = { 9812static struct snd_kcontrol_new alc268_base_mixer[] = {
9521 /* output mixer control */ 9813 /* output mixer control */
9522 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT), 9814 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
@@ -9529,6 +9821,22 @@ static struct snd_kcontrol_new alc268_base_mixer[] = {
9529 { } 9821 { }
9530}; 9822};
9531 9823
9824/* bind Beep switches of both NID 0x0f and 0x10 */
9825static struct hda_bind_ctls alc268_bind_beep_sw = {
9826 .ops = &snd_hda_bind_sw,
9827 .values = {
9828 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
9829 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
9830 0
9831 },
9832};
9833
9834static struct snd_kcontrol_new alc268_beep_mixer[] = {
9835 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
9836 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
9837 { }
9838};
9839
9532static struct hda_verb alc268_eapd_verbs[] = { 9840static struct hda_verb alc268_eapd_verbs[] = {
9533 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, 9841 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9534 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, 9842 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
@@ -9613,8 +9921,12 @@ static struct snd_kcontrol_new alc268_acer_mixer[] = {
9613}; 9921};
9614 9922
9615static struct hda_verb alc268_acer_verbs[] = { 9923static struct hda_verb alc268_acer_verbs[] = {
9924 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
9925 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9616 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 9926 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9617 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9927 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9928 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9929 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9618 9930
9619 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 9931 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9620 { } 9932 { }
@@ -9685,6 +9997,64 @@ static void alc268_dell_unsol_event(struct hda_codec *codec,
9685 9997
9686#define alc268_dell_init_hook alc268_dell_automute 9998#define alc268_dell_init_hook alc268_dell_automute
9687 9999
10000static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10001 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10002 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10003 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10004 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10005 HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10006 HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10007 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10008 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10009 { }
10010};
10011
10012static struct hda_verb alc267_quanta_il1_verbs[] = {
10013 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10014 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10015 { }
10016};
10017
10018static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10019{
10020 unsigned int present;
10021
10022 present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10023 & AC_PINSENSE_PRESENCE;
10024 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10025 present ? 0 : PIN_OUT);
10026}
10027
10028static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10029{
10030 unsigned int present;
10031
10032 present = snd_hda_codec_read(codec, 0x18, 0,
10033 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10034 snd_hda_codec_write(codec, 0x23, 0,
10035 AC_VERB_SET_CONNECT_SEL,
10036 present ? 0x00 : 0x01);
10037}
10038
10039static void alc267_quanta_il1_automute(struct hda_codec *codec)
10040{
10041 alc267_quanta_il1_hp_automute(codec);
10042 alc267_quanta_il1_mic_automute(codec);
10043}
10044
10045static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10046 unsigned int res)
10047{
10048 switch (res >> 26) {
10049 case ALC880_HP_EVENT:
10050 alc267_quanta_il1_hp_automute(codec);
10051 break;
10052 case ALC880_MIC_EVENT:
10053 alc267_quanta_il1_mic_automute(codec);
10054 break;
10055 }
10056}
10057
9688/* 10058/*
9689 * generic initialization of ADC, input mixers and output mixers 10059 * generic initialization of ADC, input mixers and output mixers
9690 */ 10060 */
@@ -9725,7 +10095,11 @@ static struct hda_verb alc268_base_init_verbs[] = {
9725 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10095 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9726 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10096 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9727 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10097 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9728 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, 10098
10099 /* set PCBEEP vol = 0, mute connections */
10100 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10101 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10102 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9729 10103
9730 /* Unmute Selector 23h,24h and set the default input to mic-in */ 10104 /* Unmute Selector 23h,24h and set the default input to mic-in */
9731 10105
@@ -9764,29 +10138,17 @@ static struct hda_verb alc268_volume_init_verbs[] = {
9764 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10138 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9765 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10139 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9766 10140
9767 /* set PCBEEP vol = 0 */ 10141 /* set PCBEEP vol = 0, mute connections */
9768 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))}, 10142 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10143 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10144 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9769 10145
9770 { } 10146 { }
9771}; 10147};
9772 10148
9773#define alc268_mux_enum_info alc_mux_enum_info 10149#define alc268_mux_enum_info alc_mux_enum_info
9774#define alc268_mux_enum_get alc_mux_enum_get 10150#define alc268_mux_enum_get alc_mux_enum_get
9775 10151#define alc268_mux_enum_put alc_mux_enum_put
9776static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
9777 struct snd_ctl_elem_value *ucontrol)
9778{
9779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9780 struct alc_spec *spec = codec->spec;
9781
9782 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
9783 static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
9784 hda_nid_t nid = capture_mixers[adc_idx];
9785
9786 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
9787 nid,
9788 &spec->cur_mux[adc_idx]);
9789}
9790 10152
9791static struct snd_kcontrol_new alc268_capture_alt_mixer[] = { 10153static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
9792 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT), 10154 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
@@ -9836,13 +10198,17 @@ static struct hda_input_mux alc268_capture_source = {
9836 }, 10198 },
9837}; 10199};
9838 10200
10201static struct hda_input_mux alc268_acer_capture_source = {
10202 .num_items = 3,
10203 .items = {
10204 { "Mic", 0x0 },
10205 { "Internal Mic", 0x6 },
10206 { "Line", 0x2 },
10207 },
10208};
10209
9839#ifdef CONFIG_SND_DEBUG 10210#ifdef CONFIG_SND_DEBUG
9840static struct snd_kcontrol_new alc268_test_mixer[] = { 10211static struct snd_kcontrol_new alc268_test_mixer[] = {
9841 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9842 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9843 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9844 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9845
9846 /* Volume widgets */ 10212 /* Volume widgets */
9847 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT), 10213 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9848 HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT), 10214 HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
@@ -9981,6 +10347,10 @@ static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
9981 case 0x1c: 10347 case 0x1c:
9982 idx1 = 3; /* CD */ 10348 idx1 = 3; /* CD */
9983 break; 10349 break;
10350 case 0x12:
10351 case 0x13:
10352 idx1 = 6; /* digital mics */
10353 break;
9984 default: 10354 default:
9985 continue; 10355 continue;
9986 } 10356 }
@@ -10073,6 +10443,9 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
10073 if (spec->kctl_alloc) 10443 if (spec->kctl_alloc)
10074 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 10444 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10075 10445
10446 if (spec->autocfg.speaker_pins[0] != 0x1d)
10447 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10448
10076 spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs; 10449 spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10077 spec->num_mux_defs = 1; 10450 spec->num_mux_defs = 1;
10078 spec->input_mux = &spec->private_imux; 10451 spec->input_mux = &spec->private_imux;
@@ -10091,20 +10464,25 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
10091/* init callback for auto-configuration model -- overriding the default init */ 10464/* init callback for auto-configuration model -- overriding the default init */
10092static void alc268_auto_init(struct hda_codec *codec) 10465static void alc268_auto_init(struct hda_codec *codec)
10093{ 10466{
10467 struct alc_spec *spec = codec->spec;
10094 alc268_auto_init_multi_out(codec); 10468 alc268_auto_init_multi_out(codec);
10095 alc268_auto_init_hp_out(codec); 10469 alc268_auto_init_hp_out(codec);
10096 alc268_auto_init_mono_speaker_out(codec); 10470 alc268_auto_init_mono_speaker_out(codec);
10097 alc268_auto_init_analog_input(codec); 10471 alc268_auto_init_analog_input(codec);
10472 if (spec->unsol_event)
10473 alc_sku_automute(codec);
10098} 10474}
10099 10475
10100/* 10476/*
10101 * configuration and preset 10477 * configuration and preset
10102 */ 10478 */
10103static const char *alc268_models[ALC268_MODEL_LAST] = { 10479static const char *alc268_models[ALC268_MODEL_LAST] = {
10480 [ALC267_QUANTA_IL1] = "quanta-il1",
10104 [ALC268_3ST] = "3stack", 10481 [ALC268_3ST] = "3stack",
10105 [ALC268_TOSHIBA] = "toshiba", 10482 [ALC268_TOSHIBA] = "toshiba",
10106 [ALC268_ACER] = "acer", 10483 [ALC268_ACER] = "acer",
10107 [ALC268_DELL] = "dell", 10484 [ALC268_DELL] = "dell",
10485 [ALC268_ZEPTO] = "zepto",
10108#ifdef CONFIG_SND_DEBUG 10486#ifdef CONFIG_SND_DEBUG
10109 [ALC268_TEST] = "test", 10487 [ALC268_TEST] = "test",
10110#endif 10488#endif
@@ -10112,6 +10490,7 @@ static const char *alc268_models[ALC268_MODEL_LAST] = {
10112}; 10490};
10113 10491
10114static struct snd_pci_quirk alc268_cfg_tbl[] = { 10492static struct snd_pci_quirk alc268_cfg_tbl[] = {
10493 SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10115 SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER), 10494 SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10116 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER), 10495 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10117 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER), 10496 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
@@ -10122,17 +10501,36 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
10122 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA), 10501 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10123 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA), 10502 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10124 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER), 10503 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10504 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10505 SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10125 {} 10506 {}
10126}; 10507};
10127 10508
10128static struct alc_config_preset alc268_presets[] = { 10509static struct alc_config_preset alc268_presets[] = {
10510 [ALC267_QUANTA_IL1] = {
10511 .mixers = { alc267_quanta_il1_mixer },
10512 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10513 alc267_quanta_il1_verbs },
10514 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10515 .dac_nids = alc268_dac_nids,
10516 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10517 .adc_nids = alc268_adc_nids_alt,
10518 .hp_nid = 0x03,
10519 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10520 .channel_mode = alc268_modes,
10521 .input_mux = &alc268_capture_source,
10522 .unsol_event = alc267_quanta_il1_unsol_event,
10523 .init_hook = alc267_quanta_il1_automute,
10524 },
10129 [ALC268_3ST] = { 10525 [ALC268_3ST] = {
10130 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer }, 10526 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10527 alc268_beep_mixer },
10131 .init_verbs = { alc268_base_init_verbs }, 10528 .init_verbs = { alc268_base_init_verbs },
10132 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10529 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10133 .dac_nids = alc268_dac_nids, 10530 .dac_nids = alc268_dac_nids,
10134 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10531 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10135 .adc_nids = alc268_adc_nids_alt, 10532 .adc_nids = alc268_adc_nids_alt,
10533 .capsrc_nids = alc268_capsrc_nids,
10136 .hp_nid = 0x03, 10534 .hp_nid = 0x03,
10137 .dig_out_nid = ALC268_DIGOUT_NID, 10535 .dig_out_nid = ALC268_DIGOUT_NID,
10138 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10536 .num_channel_mode = ARRAY_SIZE(alc268_modes),
@@ -10140,13 +10538,15 @@ static struct alc_config_preset alc268_presets[] = {
10140 .input_mux = &alc268_capture_source, 10538 .input_mux = &alc268_capture_source,
10141 }, 10539 },
10142 [ALC268_TOSHIBA] = { 10540 [ALC268_TOSHIBA] = {
10143 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer }, 10541 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10542 alc268_beep_mixer },
10144 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10543 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10145 alc268_toshiba_verbs }, 10544 alc268_toshiba_verbs },
10146 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10545 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10147 .dac_nids = alc268_dac_nids, 10546 .dac_nids = alc268_dac_nids,
10148 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10547 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10149 .adc_nids = alc268_adc_nids_alt, 10548 .adc_nids = alc268_adc_nids_alt,
10549 .capsrc_nids = alc268_capsrc_nids,
10150 .hp_nid = 0x03, 10550 .hp_nid = 0x03,
10151 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10551 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10152 .channel_mode = alc268_modes, 10552 .channel_mode = alc268_modes,
@@ -10155,22 +10555,24 @@ static struct alc_config_preset alc268_presets[] = {
10155 .init_hook = alc268_toshiba_automute, 10555 .init_hook = alc268_toshiba_automute,
10156 }, 10556 },
10157 [ALC268_ACER] = { 10557 [ALC268_ACER] = {
10158 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer }, 10558 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10559 alc268_beep_mixer },
10159 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10560 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10160 alc268_acer_verbs }, 10561 alc268_acer_verbs },
10161 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10562 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10162 .dac_nids = alc268_dac_nids, 10563 .dac_nids = alc268_dac_nids,
10163 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10564 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10164 .adc_nids = alc268_adc_nids_alt, 10565 .adc_nids = alc268_adc_nids_alt,
10566 .capsrc_nids = alc268_capsrc_nids,
10165 .hp_nid = 0x02, 10567 .hp_nid = 0x02,
10166 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10568 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10167 .channel_mode = alc268_modes, 10569 .channel_mode = alc268_modes,
10168 .input_mux = &alc268_capture_source, 10570 .input_mux = &alc268_acer_capture_source,
10169 .unsol_event = alc268_acer_unsol_event, 10571 .unsol_event = alc268_acer_unsol_event,
10170 .init_hook = alc268_acer_init_hook, 10572 .init_hook = alc268_acer_init_hook,
10171 }, 10573 },
10172 [ALC268_DELL] = { 10574 [ALC268_DELL] = {
10173 .mixers = { alc268_dell_mixer }, 10575 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10174 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10576 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10175 alc268_dell_verbs }, 10577 alc268_dell_verbs },
10176 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10578 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -10182,6 +10584,24 @@ static struct alc_config_preset alc268_presets[] = {
10182 .init_hook = alc268_dell_init_hook, 10584 .init_hook = alc268_dell_init_hook,
10183 .input_mux = &alc268_capture_source, 10585 .input_mux = &alc268_capture_source,
10184 }, 10586 },
10587 [ALC268_ZEPTO] = {
10588 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10589 alc268_beep_mixer },
10590 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10591 alc268_toshiba_verbs },
10592 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10593 .dac_nids = alc268_dac_nids,
10594 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10595 .adc_nids = alc268_adc_nids_alt,
10596 .capsrc_nids = alc268_capsrc_nids,
10597 .hp_nid = 0x03,
10598 .dig_out_nid = ALC268_DIGOUT_NID,
10599 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10600 .channel_mode = alc268_modes,
10601 .input_mux = &alc268_capture_source,
10602 .unsol_event = alc268_toshiba_unsol_event,
10603 .init_hook = alc268_toshiba_automute
10604 },
10185#ifdef CONFIG_SND_DEBUG 10605#ifdef CONFIG_SND_DEBUG
10186 [ALC268_TEST] = { 10606 [ALC268_TEST] = {
10187 .mixers = { alc268_test_mixer, alc268_capture_mixer }, 10607 .mixers = { alc268_test_mixer, alc268_capture_mixer },
@@ -10191,6 +10611,7 @@ static struct alc_config_preset alc268_presets[] = {
10191 .dac_nids = alc268_dac_nids, 10611 .dac_nids = alc268_dac_nids,
10192 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10612 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10193 .adc_nids = alc268_adc_nids_alt, 10613 .adc_nids = alc268_adc_nids_alt,
10614 .capsrc_nids = alc268_capsrc_nids,
10194 .hp_nid = 0x03, 10615 .hp_nid = 0x03,
10195 .dig_out_nid = ALC268_DIGOUT_NID, 10616 .dig_out_nid = ALC268_DIGOUT_NID,
10196 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10617 .num_channel_mode = ARRAY_SIZE(alc268_modes),
@@ -10247,13 +10668,22 @@ static int patch_alc268(struct hda_codec *codec)
10247 spec->stream_name_digital = "ALC268 Digital"; 10668 spec->stream_name_digital = "ALC268 Digital";
10248 spec->stream_digital_playback = &alc268_pcm_digital_playback; 10669 spec->stream_digital_playback = &alc268_pcm_digital_playback;
10249 10670
10671 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10672 /* override the amp caps for beep generator */
10673 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10674 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10675 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10676 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10677 (0 << AC_AMPCAP_MUTE_SHIFT));
10678
10250 if (!spec->adc_nids && spec->input_mux) { 10679 if (!spec->adc_nids && spec->input_mux) {
10251 /* check whether NID 0x07 is valid */ 10680 /* check whether NID 0x07 is valid */
10252 unsigned int wcap = get_wcaps(codec, 0x07); 10681 unsigned int wcap = get_wcaps(codec, 0x07);
10682 int i;
10253 10683
10254 /* get type */ 10684 /* get type */
10255 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 10685 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10256 if (wcap != AC_WID_AUD_IN) { 10686 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
10257 spec->adc_nids = alc268_adc_nids_alt; 10687 spec->adc_nids = alc268_adc_nids_alt;
10258 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt); 10688 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
10259 spec->mixers[spec->num_mixers] = 10689 spec->mixers[spec->num_mixers] =
@@ -10266,6 +10696,12 @@ static int patch_alc268(struct hda_codec *codec)
10266 alc268_capture_mixer; 10696 alc268_capture_mixer;
10267 spec->num_mixers++; 10697 spec->num_mixers++;
10268 } 10698 }
10699 spec->capsrc_nids = alc268_capsrc_nids;
10700 /* set default input source */
10701 for (i = 0; i < spec->num_adc_nids; i++)
10702 snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
10703 0, AC_VERB_SET_CONNECT_SEL,
10704 spec->input_mux->items[0].index);
10269 } 10705 }
10270 10706
10271 spec->vmaster_nid = 0x02; 10707 spec->vmaster_nid = 0x02;
@@ -10539,9 +10975,12 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
10539/* init callback for auto-configuration model -- overriding the default init */ 10975/* init callback for auto-configuration model -- overriding the default init */
10540static void alc269_auto_init(struct hda_codec *codec) 10976static void alc269_auto_init(struct hda_codec *codec)
10541{ 10977{
10978 struct alc_spec *spec = codec->spec;
10542 alc269_auto_init_multi_out(codec); 10979 alc269_auto_init_multi_out(codec);
10543 alc269_auto_init_hp_out(codec); 10980 alc269_auto_init_hp_out(codec);
10544 alc269_auto_init_analog_input(codec); 10981 alc269_auto_init_analog_input(codec);
10982 if (spec->unsol_event)
10983 alc_sku_automute(codec);
10545} 10984}
10546 10985
10547/* 10986/*
@@ -11463,13 +11902,7 @@ static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
11463 hda_nid_t nid, 11902 hda_nid_t nid,
11464 int pin_type, int dac_idx) 11903 int pin_type, int dac_idx)
11465{ 11904{
11466 /* set as output */ 11905 alc_set_pin_output(codec, nid, pin_type);
11467
11468 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11469 pin_type);
11470 snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11471 AMP_OUT_UNMUTE);
11472
11473} 11906}
11474 11907
11475static void alc861_auto_init_multi_out(struct hda_codec *codec) 11908static void alc861_auto_init_multi_out(struct hda_codec *codec)
@@ -11496,6 +11929,9 @@ static void alc861_auto_init_hp_out(struct hda_codec *codec)
11496 if (pin) /* connect to front */ 11929 if (pin) /* connect to front */
11497 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP, 11930 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
11498 spec->multiout.dac_nids[0]); 11931 spec->multiout.dac_nids[0]);
11932 pin = spec->autocfg.speaker_pins[0];
11933 if (pin)
11934 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
11499} 11935}
11500 11936
11501static void alc861_auto_init_analog_input(struct hda_codec *codec) 11937static void alc861_auto_init_analog_input(struct hda_codec *codec)
@@ -11568,9 +12004,12 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
11568/* additional initialization for auto-configuration model */ 12004/* additional initialization for auto-configuration model */
11569static void alc861_auto_init(struct hda_codec *codec) 12005static void alc861_auto_init(struct hda_codec *codec)
11570{ 12006{
12007 struct alc_spec *spec = codec->spec;
11571 alc861_auto_init_multi_out(codec); 12008 alc861_auto_init_multi_out(codec);
11572 alc861_auto_init_hp_out(codec); 12009 alc861_auto_init_hp_out(codec);
11573 alc861_auto_init_analog_input(codec); 12010 alc861_auto_init_analog_input(codec);
12011 if (spec->unsol_event)
12012 alc_sku_automute(codec);
11574} 12013}
11575 12014
11576#ifdef CONFIG_SND_HDA_POWER_SAVE 12015#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -11822,6 +12261,8 @@ static hda_nid_t alc861vd_adc_nids[1] = {
11822 0x09, 12261 0x09,
11823}; 12262};
11824 12263
12264static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12265
11825/* input MUX */ 12266/* input MUX */
11826/* FIXME: should be a matrix-type input source selection */ 12267/* FIXME: should be a matrix-type input source selection */
11827static struct hda_input_mux alc861vd_capture_source = { 12268static struct hda_input_mux alc861vd_capture_source = {
@@ -11835,11 +12276,10 @@ static struct hda_input_mux alc861vd_capture_source = {
11835}; 12276};
11836 12277
11837static struct hda_input_mux alc861vd_dallas_capture_source = { 12278static struct hda_input_mux alc861vd_dallas_capture_source = {
11838 .num_items = 3, 12279 .num_items = 2,
11839 .items = { 12280 .items = {
11840 { "Front Mic", 0x0 }, 12281 { "Ext Mic", 0x0 },
11841 { "ATAPI Mic", 0x1 }, 12282 { "Int Mic", 0x1 },
11842 { "Line In", 0x5 },
11843 }, 12283 },
11844}; 12284};
11845 12285
@@ -11853,33 +12293,8 @@ static struct hda_input_mux alc861vd_hp_capture_source = {
11853 12293
11854#define alc861vd_mux_enum_info alc_mux_enum_info 12294#define alc861vd_mux_enum_info alc_mux_enum_info
11855#define alc861vd_mux_enum_get alc_mux_enum_get 12295#define alc861vd_mux_enum_get alc_mux_enum_get
11856 12296/* ALC861VD has the ALC882-type input selection (but has only one ADC) */
11857static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol, 12297#define alc861vd_mux_enum_put alc882_mux_enum_put
11858 struct snd_ctl_elem_value *ucontrol)
11859{
11860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11861 struct alc_spec *spec = codec->spec;
11862 const struct hda_input_mux *imux = spec->input_mux;
11863 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11864 static hda_nid_t capture_mixers[1] = { 0x22 };
11865 hda_nid_t nid = capture_mixers[adc_idx];
11866 unsigned int *cur_val = &spec->cur_mux[adc_idx];
11867 unsigned int i, idx;
11868
11869 idx = ucontrol->value.enumerated.item[0];
11870 if (idx >= imux->num_items)
11871 idx = imux->num_items - 1;
11872 if (*cur_val == idx)
11873 return 0;
11874 for (i = 0; i < imux->num_items; i++) {
11875 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11876 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11877 imux->items[i].index,
11878 HDA_AMP_MUTE, v);
11879 }
11880 *cur_val = idx;
11881 return 1;
11882}
11883 12298
11884/* 12299/*
11885 * 2ch mode 12300 * 2ch mode
@@ -12034,20 +12449,22 @@ static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12034 { } /* end */ 12449 { } /* end */
12035}; 12450};
12036 12451
12037/* Pin assignment: Front=0x14, HP = 0x15, 12452/* Pin assignment: Speaker=0x14, HP = 0x15,
12038 * Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d 12453 * Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12039 */ 12454 */
12040static struct snd_kcontrol_new alc861vd_dallas_mixer[] = { 12455static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12041 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 12456 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12042 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 12457 HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12043 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT), 12458 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12044 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT), 12459 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12045 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 12460 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12046 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 12461 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12047 HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 12462 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12048 HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 12463 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12049 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT), 12464 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12050 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT), 12465 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12466 HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12467 HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12051 { } /* end */ 12468 { } /* end */
12052}; 12469};
12053 12470
@@ -12348,6 +12765,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
12348 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/ 12765 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
12349 SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS), 12766 SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
12350 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO), 12767 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
12768 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
12351 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG), 12769 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
12352 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO), 12770 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
12353 SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO), 12771 SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
@@ -12362,8 +12780,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12362 alc861vd_3stack_init_verbs }, 12780 alc861vd_3stack_init_verbs },
12363 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12781 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12364 .dac_nids = alc660vd_dac_nids, 12782 .dac_nids = alc660vd_dac_nids,
12365 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12366 .adc_nids = alc861vd_adc_nids,
12367 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12783 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12368 .channel_mode = alc861vd_3stack_2ch_modes, 12784 .channel_mode = alc861vd_3stack_2ch_modes,
12369 .input_mux = &alc861vd_capture_source, 12785 .input_mux = &alc861vd_capture_source,
@@ -12375,8 +12791,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12375 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12791 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12376 .dac_nids = alc660vd_dac_nids, 12792 .dac_nids = alc660vd_dac_nids,
12377 .dig_out_nid = ALC861VD_DIGOUT_NID, 12793 .dig_out_nid = ALC861VD_DIGOUT_NID,
12378 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12379 .adc_nids = alc861vd_adc_nids,
12380 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12794 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12381 .channel_mode = alc861vd_3stack_2ch_modes, 12795 .channel_mode = alc861vd_3stack_2ch_modes,
12382 .input_mux = &alc861vd_capture_source, 12796 .input_mux = &alc861vd_capture_source,
@@ -12421,8 +12835,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12421 alc861vd_lenovo_unsol_verbs }, 12835 alc861vd_lenovo_unsol_verbs },
12422 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12836 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12423 .dac_nids = alc660vd_dac_nids, 12837 .dac_nids = alc660vd_dac_nids,
12424 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12425 .adc_nids = alc861vd_adc_nids,
12426 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12838 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12427 .channel_mode = alc861vd_3stack_2ch_modes, 12839 .channel_mode = alc861vd_3stack_2ch_modes,
12428 .input_mux = &alc861vd_capture_source, 12840 .input_mux = &alc861vd_capture_source,
@@ -12434,8 +12846,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12434 .init_verbs = { alc861vd_dallas_verbs }, 12846 .init_verbs = { alc861vd_dallas_verbs },
12435 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids), 12847 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12436 .dac_nids = alc861vd_dac_nids, 12848 .dac_nids = alc861vd_dac_nids,
12437 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12438 .adc_nids = alc861vd_adc_nids,
12439 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12849 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12440 .channel_mode = alc861vd_3stack_2ch_modes, 12850 .channel_mode = alc861vd_3stack_2ch_modes,
12441 .input_mux = &alc861vd_dallas_capture_source, 12851 .input_mux = &alc861vd_dallas_capture_source,
@@ -12447,9 +12857,7 @@ static struct alc_config_preset alc861vd_presets[] = {
12447 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs }, 12857 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
12448 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids), 12858 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12449 .dac_nids = alc861vd_dac_nids, 12859 .dac_nids = alc861vd_dac_nids,
12450 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12451 .dig_out_nid = ALC861VD_DIGOUT_NID, 12860 .dig_out_nid = ALC861VD_DIGOUT_NID,
12452 .adc_nids = alc861vd_adc_nids,
12453 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12861 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12454 .channel_mode = alc861vd_3stack_2ch_modes, 12862 .channel_mode = alc861vd_3stack_2ch_modes,
12455 .input_mux = &alc861vd_hp_capture_source, 12863 .input_mux = &alc861vd_hp_capture_source,
@@ -12464,11 +12872,7 @@ static struct alc_config_preset alc861vd_presets[] = {
12464static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec, 12872static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
12465 hda_nid_t nid, int pin_type, int dac_idx) 12873 hda_nid_t nid, int pin_type, int dac_idx)
12466{ 12874{
12467 /* set as output */ 12875 alc_set_pin_output(codec, nid, pin_type);
12468 snd_hda_codec_write(codec, nid, 0,
12469 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
12470 snd_hda_codec_write(codec, nid, 0,
12471 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
12472} 12876}
12473 12877
12474static void alc861vd_auto_init_multi_out(struct hda_codec *codec) 12878static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
@@ -12495,6 +12899,9 @@ static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
12495 pin = spec->autocfg.hp_pins[0]; 12899 pin = spec->autocfg.hp_pins[0];
12496 if (pin) /* connect to front and use dac 0 */ 12900 if (pin) /* connect to front and use dac 0 */
12497 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 12901 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12902 pin = spec->autocfg.speaker_pins[0];
12903 if (pin)
12904 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12498} 12905}
12499 12906
12500#define alc861vd_is_input_pin(nid) alc880_is_input_pin(nid) 12907#define alc861vd_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -12698,9 +13105,12 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
12698/* additional initialization for auto-configuration model */ 13105/* additional initialization for auto-configuration model */
12699static void alc861vd_auto_init(struct hda_codec *codec) 13106static void alc861vd_auto_init(struct hda_codec *codec)
12700{ 13107{
13108 struct alc_spec *spec = codec->spec;
12701 alc861vd_auto_init_multi_out(codec); 13109 alc861vd_auto_init_multi_out(codec);
12702 alc861vd_auto_init_hp_out(codec); 13110 alc861vd_auto_init_hp_out(codec);
12703 alc861vd_auto_init_analog_input(codec); 13111 alc861vd_auto_init_analog_input(codec);
13112 if (spec->unsol_event)
13113 alc_sku_automute(codec);
12704} 13114}
12705 13115
12706static int patch_alc861vd(struct hda_codec *codec) 13116static int patch_alc861vd(struct hda_codec *codec)
@@ -12751,6 +13161,7 @@ static int patch_alc861vd(struct hda_codec *codec)
12751 13161
12752 spec->adc_nids = alc861vd_adc_nids; 13162 spec->adc_nids = alc861vd_adc_nids;
12753 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids); 13163 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13164 spec->capsrc_nids = alc861vd_capsrc_nids;
12754 13165
12755 spec->mixers[spec->num_mixers] = alc861vd_capture_mixer; 13166 spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
12756 spec->num_mixers++; 13167 spec->num_mixers++;
@@ -12792,9 +13203,11 @@ static hda_nid_t alc662_adc_nids[1] = {
12792 /* ADC1-2 */ 13203 /* ADC1-2 */
12793 0x09, 13204 0x09,
12794}; 13205};
13206
13207static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13208
12795/* input MUX */ 13209/* input MUX */
12796/* FIXME: should be a matrix-type input source selection */ 13210/* FIXME: should be a matrix-type input source selection */
12797
12798static struct hda_input_mux alc662_capture_source = { 13211static struct hda_input_mux alc662_capture_source = {
12799 .num_items = 4, 13212 .num_items = 4,
12800 .items = { 13213 .items = {
@@ -12823,33 +13236,8 @@ static struct hda_input_mux alc662_eeepc_capture_source = {
12823 13236
12824#define alc662_mux_enum_info alc_mux_enum_info 13237#define alc662_mux_enum_info alc_mux_enum_info
12825#define alc662_mux_enum_get alc_mux_enum_get 13238#define alc662_mux_enum_get alc_mux_enum_get
13239#define alc662_mux_enum_put alc882_mux_enum_put
12826 13240
12827static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
12828 struct snd_ctl_elem_value *ucontrol)
12829{
12830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
12831 struct alc_spec *spec = codec->spec;
12832 const struct hda_input_mux *imux = spec->input_mux;
12833 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
12834 static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
12835 hda_nid_t nid = capture_mixers[adc_idx];
12836 unsigned int *cur_val = &spec->cur_mux[adc_idx];
12837 unsigned int i, idx;
12838
12839 idx = ucontrol->value.enumerated.item[0];
12840 if (idx >= imux->num_items)
12841 idx = imux->num_items - 1;
12842 if (*cur_val == idx)
12843 return 0;
12844 for (i = 0; i < imux->num_items; i++) {
12845 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
12846 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
12847 imux->items[i].index,
12848 HDA_AMP_MUTE, v);
12849 }
12850 *cur_val = idx;
12851 return 1;
12852}
12853/* 13241/*
12854 * 2ch mode 13242 * 2ch mode
12855 */ 13243 */
@@ -12918,13 +13306,13 @@ static struct hda_channel_mode alc662_5stack_modes[2] = {
12918static struct snd_kcontrol_new alc662_base_mixer[] = { 13306static struct snd_kcontrol_new alc662_base_mixer[] = {
12919 /* output mixer control */ 13307 /* output mixer control */
12920 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT), 13308 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12921 HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT), 13309 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12922 HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT), 13310 HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12923 HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT), 13311 HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
12924 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT), 13312 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12925 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT), 13313 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12926 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT), 13314 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
12927 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT), 13315 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
12928 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13316 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12929 13317
12930 /*Input mixer control */ 13318 /*Input mixer control */
@@ -12941,7 +13329,7 @@ static struct snd_kcontrol_new alc662_base_mixer[] = {
12941 13329
12942static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = { 13330static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12943 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 13331 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12944 HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT), 13332 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12945 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13333 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12946 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 13334 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12947 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 13335 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -12958,13 +13346,13 @@ static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12958 13346
12959static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = { 13347static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
12960 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 13348 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12961 HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT), 13349 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12962 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT), 13350 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12963 HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT), 13351 HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
12964 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT), 13352 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12965 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT), 13353 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12966 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT), 13354 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
12967 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT), 13355 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
12968 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13356 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12969 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 13357 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12970 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 13358 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -13313,6 +13701,7 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
13313}; 13701};
13314 13702
13315static struct snd_pci_quirk alc662_cfg_tbl[] = { 13703static struct snd_pci_quirk alc662_cfg_tbl[] = {
13704 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
13316 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701), 13705 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
13317 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20), 13706 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
13318 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E), 13707 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
@@ -13326,8 +13715,6 @@ static struct alc_config_preset alc662_presets[] = {
13326 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13715 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13327 .dac_nids = alc662_dac_nids, 13716 .dac_nids = alc662_dac_nids,
13328 .dig_out_nid = ALC662_DIGOUT_NID, 13717 .dig_out_nid = ALC662_DIGOUT_NID,
13329 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13330 .adc_nids = alc662_adc_nids,
13331 .dig_in_nid = ALC662_DIGIN_NID, 13718 .dig_in_nid = ALC662_DIGIN_NID,
13332 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13719 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13333 .channel_mode = alc662_3ST_2ch_modes, 13720 .channel_mode = alc662_3ST_2ch_modes,
@@ -13340,8 +13727,6 @@ static struct alc_config_preset alc662_presets[] = {
13340 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13727 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13341 .dac_nids = alc662_dac_nids, 13728 .dac_nids = alc662_dac_nids,
13342 .dig_out_nid = ALC662_DIGOUT_NID, 13729 .dig_out_nid = ALC662_DIGOUT_NID,
13343 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13344 .adc_nids = alc662_adc_nids,
13345 .dig_in_nid = ALC662_DIGIN_NID, 13730 .dig_in_nid = ALC662_DIGIN_NID,
13346 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13731 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13347 .channel_mode = alc662_3ST_6ch_modes, 13732 .channel_mode = alc662_3ST_6ch_modes,
@@ -13354,8 +13739,6 @@ static struct alc_config_preset alc662_presets[] = {
13354 .init_verbs = { alc662_init_verbs }, 13739 .init_verbs = { alc662_init_verbs },
13355 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13740 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13356 .dac_nids = alc662_dac_nids, 13741 .dac_nids = alc662_dac_nids,
13357 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13358 .adc_nids = alc662_adc_nids,
13359 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13742 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13360 .channel_mode = alc662_3ST_6ch_modes, 13743 .channel_mode = alc662_3ST_6ch_modes,
13361 .need_dac_fix = 1, 13744 .need_dac_fix = 1,
@@ -13368,8 +13751,6 @@ static struct alc_config_preset alc662_presets[] = {
13368 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13751 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13369 .dac_nids = alc662_dac_nids, 13752 .dac_nids = alc662_dac_nids,
13370 .dig_out_nid = ALC662_DIGOUT_NID, 13753 .dig_out_nid = ALC662_DIGOUT_NID,
13371 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13372 .adc_nids = alc662_adc_nids,
13373 .dig_in_nid = ALC662_DIGIN_NID, 13754 .dig_in_nid = ALC662_DIGIN_NID,
13374 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes), 13755 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
13375 .channel_mode = alc662_5stack_modes, 13756 .channel_mode = alc662_5stack_modes,
@@ -13380,8 +13761,6 @@ static struct alc_config_preset alc662_presets[] = {
13380 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs }, 13761 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
13381 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13762 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13382 .dac_nids = alc662_dac_nids, 13763 .dac_nids = alc662_dac_nids,
13383 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13384 .adc_nids = alc662_adc_nids,
13385 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13764 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13386 .channel_mode = alc662_3ST_2ch_modes, 13765 .channel_mode = alc662_3ST_2ch_modes,
13387 .input_mux = &alc662_lenovo_101e_capture_source, 13766 .input_mux = &alc662_lenovo_101e_capture_source,
@@ -13394,8 +13773,6 @@ static struct alc_config_preset alc662_presets[] = {
13394 alc662_eeepc_sue_init_verbs }, 13773 alc662_eeepc_sue_init_verbs },
13395 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13774 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13396 .dac_nids = alc662_dac_nids, 13775 .dac_nids = alc662_dac_nids,
13397 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
13398 .adc_nids = alc662_adc_nids,
13399 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13776 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13400 .channel_mode = alc662_3ST_2ch_modes, 13777 .channel_mode = alc662_3ST_2ch_modes,
13401 .input_mux = &alc662_eeepc_capture_source, 13778 .input_mux = &alc662_eeepc_capture_source,
@@ -13409,8 +13786,6 @@ static struct alc_config_preset alc662_presets[] = {
13409 alc662_eeepc_ep20_sue_init_verbs }, 13786 alc662_eeepc_ep20_sue_init_verbs },
13410 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13787 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13411 .dac_nids = alc662_dac_nids, 13788 .dac_nids = alc662_dac_nids,
13412 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13413 .adc_nids = alc662_adc_nids,
13414 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13789 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13415 .channel_mode = alc662_3ST_6ch_modes, 13790 .channel_mode = alc662_3ST_6ch_modes,
13416 .input_mux = &alc662_lenovo_101e_capture_source, 13791 .input_mux = &alc662_lenovo_101e_capture_source,
@@ -13556,11 +13931,7 @@ static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
13556 hda_nid_t nid, int pin_type, 13931 hda_nid_t nid, int pin_type,
13557 int dac_idx) 13932 int dac_idx)
13558{ 13933{
13559 /* set as output */ 13934 alc_set_pin_output(codec, nid, pin_type);
13560 snd_hda_codec_write(codec, nid, 0,
13561 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
13562 snd_hda_codec_write(codec, nid, 0,
13563 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
13564 /* need the manual connection? */ 13935 /* need the manual connection? */
13565 if (alc880_is_multi_pin(nid)) { 13936 if (alc880_is_multi_pin(nid)) {
13566 struct alc_spec *spec = codec->spec; 13937 struct alc_spec *spec = codec->spec;
@@ -13595,6 +13966,9 @@ static void alc662_auto_init_hp_out(struct hda_codec *codec)
13595 if (pin) /* connect to front */ 13966 if (pin) /* connect to front */
13596 /* use dac 0 */ 13967 /* use dac 0 */
13597 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 13968 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13969 pin = spec->autocfg.speaker_pins[0];
13970 if (pin)
13971 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13598} 13972}
13599 13973
13600#define alc662_is_input_pin(nid) alc880_is_input_pin(nid) 13974#define alc662_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -13672,9 +14046,12 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
13672/* additional initialization for auto-configuration model */ 14046/* additional initialization for auto-configuration model */
13673static void alc662_auto_init(struct hda_codec *codec) 14047static void alc662_auto_init(struct hda_codec *codec)
13674{ 14048{
14049 struct alc_spec *spec = codec->spec;
13675 alc662_auto_init_multi_out(codec); 14050 alc662_auto_init_multi_out(codec);
13676 alc662_auto_init_hp_out(codec); 14051 alc662_auto_init_hp_out(codec);
13677 alc662_auto_init_analog_input(codec); 14052 alc662_auto_init_analog_input(codec);
14053 if (spec->unsol_event)
14054 alc_sku_automute(codec);
13678} 14055}
13679 14056
13680static int patch_alc662(struct hda_codec *codec) 14057static int patch_alc662(struct hda_codec *codec)
@@ -13722,10 +14099,9 @@ static int patch_alc662(struct hda_codec *codec)
13722 spec->stream_digital_playback = &alc662_pcm_digital_playback; 14099 spec->stream_digital_playback = &alc662_pcm_digital_playback;
13723 spec->stream_digital_capture = &alc662_pcm_digital_capture; 14100 spec->stream_digital_capture = &alc662_pcm_digital_capture;
13724 14101
13725 if (!spec->adc_nids && spec->input_mux) { 14102 spec->adc_nids = alc662_adc_nids;
13726 spec->adc_nids = alc662_adc_nids; 14103 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
13727 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids); 14104 spec->capsrc_nids = alc662_capsrc_nids;
13728 }
13729 14105
13730 spec->vmaster_nid = 0x02; 14106 spec->vmaster_nid = 0x02;
13731 14107
@@ -13761,6 +14137,8 @@ struct hda_codec_preset snd_hda_preset_realtek[] = {
13761 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, 14137 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
13762 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, 14138 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
13763 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 }, 14139 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14140 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14141 .patch = patch_alc882 }, /* should be patch_alc883() in future */
13764 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, 14142 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
13765 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 }, 14143 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
13766 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 }, 14144 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index d22f5a6b850f..9332b63e406c 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -28,7 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31 31#include "hda_patch.h"
32 32
33/* si3054 verbs */ 33/* si3054 verbs */
34#define SI3054_VERB_READ_NODE 0x900 34#define SI3054_VERB_READ_NODE 0x900
@@ -206,7 +206,7 @@ static int si3054_build_pcms(struct hda_codec *codec)
206 info->name = "Si3054 Modem"; 206 info->name = "Si3054 Modem";
207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm; 207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm;
208 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm; 208 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm;
209 info->is_modem = 1; 209 info->pcm_type = HDA_PCM_TYPE_MODEM;
210 return 0; 210 return 0;
211} 211}
212 212
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index caf48edaa921..b3a15d616873 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -32,6 +32,7 @@
32#include <sound/asoundef.h> 32#include <sound/asoundef.h>
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_patch.h"
35 36
36#define NUM_CONTROL_ALLOC 32 37#define NUM_CONTROL_ALLOC 32
37#define STAC_PWR_EVENT 0x20 38#define STAC_PWR_EVENT 0x20
@@ -39,6 +40,7 @@
39 40
40enum { 41enum {
41 STAC_REF, 42 STAC_REF,
43 STAC_9200_OQO,
42 STAC_9200_DELL_D21, 44 STAC_9200_DELL_D21,
43 STAC_9200_DELL_D22, 45 STAC_9200_DELL_D22,
44 STAC_9200_DELL_D23, 46 STAC_9200_DELL_D23,
@@ -50,6 +52,7 @@ enum {
50 STAC_9200_DELL_M26, 52 STAC_9200_DELL_M26,
51 STAC_9200_DELL_M27, 53 STAC_9200_DELL_M27,
52 STAC_9200_GATEWAY, 54 STAC_9200_GATEWAY,
55 STAC_9200_PANASONIC,
53 STAC_9200_MODELS 56 STAC_9200_MODELS
54}; 57};
55 58
@@ -63,11 +66,14 @@ enum {
63 66
64enum { 67enum {
65 STAC_92HD73XX_REF, 68 STAC_92HD73XX_REF,
69 STAC_DELL_M6,
66 STAC_92HD73XX_MODELS 70 STAC_92HD73XX_MODELS
67}; 71};
68 72
69enum { 73enum {
70 STAC_92HD71BXX_REF, 74 STAC_92HD71BXX_REF,
75 STAC_DELL_M4_1,
76 STAC_DELL_M4_2,
71 STAC_92HD71BXX_MODELS 77 STAC_92HD71BXX_MODELS
72}; 78};
73 79
@@ -123,6 +129,7 @@ struct sigmatel_spec {
123 unsigned int hp_detect: 1; 129 unsigned int hp_detect: 1;
124 130
125 /* gpio lines */ 131 /* gpio lines */
132 unsigned int eapd_mask;
126 unsigned int gpio_mask; 133 unsigned int gpio_mask;
127 unsigned int gpio_dir; 134 unsigned int gpio_dir;
128 unsigned int gpio_data; 135 unsigned int gpio_data;
@@ -135,6 +142,7 @@ struct sigmatel_spec {
135 /* power management */ 142 /* power management */
136 unsigned int num_pwrs; 143 unsigned int num_pwrs;
137 hda_nid_t *pwr_nids; 144 hda_nid_t *pwr_nids;
145 hda_nid_t *dac_list;
138 146
139 /* playback */ 147 /* playback */
140 struct hda_input_mux *mono_mux; 148 struct hda_input_mux *mono_mux;
@@ -173,6 +181,7 @@ struct sigmatel_spec {
173 /* i/o switches */ 181 /* i/o switches */
174 unsigned int io_switch[2]; 182 unsigned int io_switch[2];
175 unsigned int clfe_swap; 183 unsigned int clfe_swap;
184 unsigned int hp_switch;
176 unsigned int aloopback; 185 unsigned int aloopback;
177 186
178 struct hda_pcm pcm_rec[2]; /* PCM information */ 187 struct hda_pcm pcm_rec[2]; /* PCM information */
@@ -184,9 +193,6 @@ struct sigmatel_spec {
184 struct hda_input_mux private_dimux; 193 struct hda_input_mux private_dimux;
185 struct hda_input_mux private_imux; 194 struct hda_input_mux private_imux;
186 struct hda_input_mux private_mono_mux; 195 struct hda_input_mux private_mono_mux;
187
188 /* virtual master */
189 unsigned int vmaster_tlv[4];
190}; 196};
191 197
192static hda_nid_t stac9200_adc_nids[1] = { 198static hda_nid_t stac9200_adc_nids[1] = {
@@ -244,7 +250,7 @@ static hda_nid_t stac92hd71bxx_dmux_nids[1] = {
244 0x1c, 250 0x1c,
245}; 251};
246 252
247static hda_nid_t stac92hd71bxx_dac_nids[2] = { 253static hda_nid_t stac92hd71bxx_dac_nids[1] = {
248 0x10, /*0x11, */ 254 0x10, /*0x11, */
249}; 255};
250 256
@@ -290,6 +296,10 @@ static hda_nid_t stac927x_mux_nids[3] = {
290 0x15, 0x16, 0x17 296 0x15, 0x16, 0x17
291}; 297};
292 298
299static hda_nid_t stac927x_dac_nids[6] = {
300 0x02, 0x03, 0x04, 0x05, 0x06, 0
301};
302
293static hda_nid_t stac927x_dmux_nids[1] = { 303static hda_nid_t stac927x_dmux_nids[1] = {
294 0x1b, 304 0x1b,
295}; 305};
@@ -331,10 +341,10 @@ static hda_nid_t stac922x_pin_nids[10] = {
331 0x0f, 0x10, 0x11, 0x15, 0x1b, 341 0x0f, 0x10, 0x11, 0x15, 0x1b,
332}; 342};
333 343
334static hda_nid_t stac92hd73xx_pin_nids[12] = { 344static hda_nid_t stac92hd73xx_pin_nids[13] = {
335 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 345 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
336 0x0f, 0x10, 0x11, 0x12, 0x13, 346 0x0f, 0x10, 0x11, 0x12, 0x13,
337 0x14, 0x22 347 0x14, 0x1e, 0x22
338}; 348};
339 349
340static hda_nid_t stac92hd71bxx_pin_nids[10] = { 350static hda_nid_t stac92hd71bxx_pin_nids[10] = {
@@ -527,6 +537,43 @@ static struct hda_verb stac92hd73xx_6ch_core_init[] = {
527 {} 537 {}
528}; 538};
529 539
540static struct hda_verb dell_eq_core_init[] = {
541 /* set master volume to max value without distortion
542 * and direct control */
543 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
544 /* setup audio connections */
545 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
546 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
547 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
548 /* setup adcs to point to mixer */
549 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
550 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
551 /* setup import muxs */
552 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
553 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
554 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
555 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
556 {}
557};
558
559static struct hda_verb dell_m6_core_init[] = {
560 /* set master volume and direct control */
561 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
562 /* setup audio connections */
563 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
564 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
565 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
566 /* setup adcs to point to mixer */
567 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
568 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
569 /* setup import muxs */
570 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
571 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
572 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
573 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
574 {}
575};
576
530static struct hda_verb stac92hd73xx_8ch_core_init[] = { 577static struct hda_verb stac92hd73xx_8ch_core_init[] = {
531 /* set master volume and direct control */ 578 /* set master volume and direct control */
532 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 579 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
@@ -910,6 +957,11 @@ static int stac92xx_build_controls(struct hda_codec *codec)
910 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 957 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
911 if (err < 0) 958 if (err < 0)
912 return err; 959 return err;
960 err = snd_hda_create_spdif_share_sw(codec,
961 &spec->multiout);
962 if (err < 0)
963 return err;
964 spec->multiout.share_spdif = 1;
913 } 965 }
914 if (spec->dig_in_nid) { 966 if (spec->dig_in_nid) {
915 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 967 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -919,10 +971,11 @@ static int stac92xx_build_controls(struct hda_codec *codec)
919 971
920 /* if we have no master control, let's create it */ 972 /* if we have no master control, let's create it */
921 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 973 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
974 unsigned int vmaster_tlv[4];
922 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0], 975 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
923 HDA_OUTPUT, spec->vmaster_tlv); 976 HDA_OUTPUT, vmaster_tlv);
924 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 977 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
925 spec->vmaster_tlv, slave_vols); 978 vmaster_tlv, slave_vols);
926 if (err < 0) 979 if (err < 0)
927 return err; 980 return err;
928 } 981 }
@@ -1052,9 +1105,15 @@ static unsigned int dell9200_m27_pin_configs[8] = {
1052 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc, 1105 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1053}; 1106};
1054 1107
1108static unsigned int oqo9200_pin_configs[8] = {
1109 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1110 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1111};
1112
1055 1113
1056static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = { 1114static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1057 [STAC_REF] = ref9200_pin_configs, 1115 [STAC_REF] = ref9200_pin_configs,
1116 [STAC_9200_OQO] = oqo9200_pin_configs,
1058 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs, 1117 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1059 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs, 1118 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1060 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs, 1119 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
@@ -1065,10 +1124,12 @@ static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1065 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs, 1124 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1066 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs, 1125 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1067 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs, 1126 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1127 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1068}; 1128};
1069 1129
1070static const char *stac9200_models[STAC_9200_MODELS] = { 1130static const char *stac9200_models[STAC_9200_MODELS] = {
1071 [STAC_REF] = "ref", 1131 [STAC_REF] = "ref",
1132 [STAC_9200_OQO] = "oqo",
1072 [STAC_9200_DELL_D21] = "dell-d21", 1133 [STAC_9200_DELL_D21] = "dell-d21",
1073 [STAC_9200_DELL_D22] = "dell-d22", 1134 [STAC_9200_DELL_D22] = "dell-d22",
1074 [STAC_9200_DELL_D23] = "dell-d23", 1135 [STAC_9200_DELL_D23] = "dell-d23",
@@ -1080,6 +1141,7 @@ static const char *stac9200_models[STAC_9200_MODELS] = {
1080 [STAC_9200_DELL_M26] = "dell-m26", 1141 [STAC_9200_DELL_M26] = "dell-m26",
1081 [STAC_9200_DELL_M27] = "dell-m27", 1142 [STAC_9200_DELL_M27] = "dell-m27",
1082 [STAC_9200_GATEWAY] = "gateway", 1143 [STAC_9200_GATEWAY] = "gateway",
1144 [STAC_9200_PANASONIC] = "panasonic",
1083}; 1145};
1084 1146
1085static struct snd_pci_quirk stac9200_cfg_tbl[] = { 1147static struct snd_pci_quirk stac9200_cfg_tbl[] = {
@@ -1146,13 +1208,15 @@ static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1146 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6, 1208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1147 "unknown Dell", STAC_9200_DELL_M26), 1209 "unknown Dell", STAC_9200_DELL_M26),
1148 /* Panasonic */ 1210 /* Panasonic */
1149 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF), 1211 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1150 /* Gateway machines needs EAPD to be set on resume */ 1212 /* Gateway machines needs EAPD to be set on resume */
1151 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY), 1213 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1152 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", 1214 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1153 STAC_9200_GATEWAY), 1215 STAC_9200_GATEWAY),
1154 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", 1216 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1155 STAC_9200_GATEWAY), 1217 STAC_9200_GATEWAY),
1218 /* OQO Mobile */
1219 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1156 {} /* terminator */ 1220 {} /* terminator */
1157}; 1221};
1158 1222
@@ -1202,24 +1266,48 @@ static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1202 {} /* terminator */ 1266 {} /* terminator */
1203}; 1267};
1204 1268
1205static unsigned int ref92hd73xx_pin_configs[12] = { 1269static unsigned int ref92hd73xx_pin_configs[13] = {
1206 0x02214030, 0x02a19040, 0x01a19020, 0x02214030, 1270 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1207 0x0181302e, 0x01014010, 0x01014020, 0x01014030, 1271 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1208 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050, 1272 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1273 0x01452050,
1274};
1275
1276static unsigned int dell_m6_pin_configs[13] = {
1277 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1278 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1279 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1280 0x4f0000f0,
1209}; 1281};
1210 1282
1211static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = { 1283static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1212 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs, 1284 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1285 [STAC_DELL_M6] = dell_m6_pin_configs,
1213}; 1286};
1214 1287
1215static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = { 1288static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1216 [STAC_92HD73XX_REF] = "ref", 1289 [STAC_92HD73XX_REF] = "ref",
1290 [STAC_DELL_M6] = "dell-m6",
1217}; 1291};
1218 1292
1219static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = { 1293static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1220 /* SigmaTel reference board */ 1294 /* SigmaTel reference board */
1221 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1295 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1222 "DFI LanParty", STAC_92HD73XX_REF), 1296 "DFI LanParty", STAC_92HD73XX_REF),
1297 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1298 "unknown Dell", STAC_DELL_M6),
1299 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1300 "unknown Dell", STAC_DELL_M6),
1301 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1302 "unknown Dell", STAC_DELL_M6),
1303 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1304 "unknown Dell", STAC_DELL_M6),
1305 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1306 "unknown Dell", STAC_DELL_M6),
1307 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1308 "unknown Dell", STAC_DELL_M6),
1309 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1310 "unknown Dell", STAC_DELL_M6),
1223 {} /* terminator */ 1311 {} /* terminator */
1224}; 1312};
1225 1313
@@ -1229,18 +1317,56 @@ static unsigned int ref92hd71bxx_pin_configs[10] = {
1229 0x90a000f0, 0x01452050, 1317 0x90a000f0, 0x01452050,
1230}; 1318};
1231 1319
1320static unsigned int dell_m4_1_pin_configs[13] = {
1321 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1322 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1323 0x40f000f0, 0x4f0000f0,
1324};
1325
1326static unsigned int dell_m4_2_pin_configs[13] = {
1327 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1328 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1329 0x40f000f0, 0x044413b0,
1330};
1331
1232static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = { 1332static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1233 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs, 1333 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1334 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1335 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1234}; 1336};
1235 1337
1236static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = { 1338static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1237 [STAC_92HD71BXX_REF] = "ref", 1339 [STAC_92HD71BXX_REF] = "ref",
1340 [STAC_DELL_M4_1] = "dell-m4-1",
1341 [STAC_DELL_M4_2] = "dell-m4-2",
1238}; 1342};
1239 1343
1240static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = { 1344static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1241 /* SigmaTel reference board */ 1345 /* SigmaTel reference board */
1242 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1346 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1243 "DFI LanParty", STAC_92HD71BXX_REF), 1347 "DFI LanParty", STAC_92HD71BXX_REF),
1348 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1349 "unknown Dell", STAC_DELL_M4_1),
1350 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1351 "unknown Dell", STAC_DELL_M4_1),
1352 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1353 "unknown Dell", STAC_DELL_M4_1),
1354 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1355 "unknown Dell", STAC_DELL_M4_1),
1356 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1357 "unknown Dell", STAC_DELL_M4_1),
1358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1359 "unknown Dell", STAC_DELL_M4_1),
1360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1361 "unknown Dell", STAC_DELL_M4_1),
1362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1363 "unknown Dell", STAC_DELL_M4_2),
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1365 "unknown Dell", STAC_DELL_M4_2),
1366 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1367 "unknown Dell", STAC_DELL_M4_2),
1368 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1369 "unknown Dell", STAC_DELL_M4_2),
1244 {} /* terminator */ 1370 {} /* terminator */
1245}; 1371};
1246 1372
@@ -1733,7 +1859,8 @@ static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1733 struct snd_pcm_substream *substream) 1859 struct snd_pcm_substream *substream)
1734{ 1860{
1735 struct sigmatel_spec *spec = codec->spec; 1861 struct sigmatel_spec *spec = codec->spec;
1736 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 1862 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1863 hinfo);
1737} 1864}
1738 1865
1739static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1866static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -1807,7 +1934,7 @@ static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1807{ 1934{
1808 struct sigmatel_spec *spec = codec->spec; 1935 struct sigmatel_spec *spec = codec->spec;
1809 1936
1810 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); 1937 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1811 return 0; 1938 return 0;
1812} 1939}
1813 1940
@@ -1889,6 +2016,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
1889 codec->num_pcms++; 2016 codec->num_pcms++;
1890 info++; 2017 info++;
1891 info->name = "STAC92xx Digital"; 2018 info->name = "STAC92xx Digital";
2019 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1892 if (spec->multiout.dig_out_nid) { 2020 if (spec->multiout.dig_out_nid) {
1893 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback; 2021 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1894 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 2022 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -1925,6 +2053,34 @@ static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int
1925 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); 2053 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1926} 2054}
1927 2055
2056#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2057
2058static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2059 struct snd_ctl_elem_value *ucontrol)
2060{
2061 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2062 struct sigmatel_spec *spec = codec->spec;
2063
2064 ucontrol->value.integer.value[0] = spec->hp_switch;
2065 return 0;
2066}
2067
2068static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2069 struct snd_ctl_elem_value *ucontrol)
2070{
2071 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2072 struct sigmatel_spec *spec = codec->spec;
2073
2074 spec->hp_switch = ucontrol->value.integer.value[0];
2075
2076 /* check to be sure that the ports are upto date with
2077 * switch changes
2078 */
2079 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2080
2081 return 1;
2082}
2083
1928#define stac92xx_io_switch_info snd_ctl_boolean_mono_info 2084#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
1929 2085
1930static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2086static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1996,6 +2152,15 @@ static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1996 return 1; 2152 return 1;
1997} 2153}
1998 2154
2155#define STAC_CODEC_HP_SWITCH(xname) \
2156 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2157 .name = xname, \
2158 .index = 0, \
2159 .info = stac92xx_hp_switch_info, \
2160 .get = stac92xx_hp_switch_get, \
2161 .put = stac92xx_hp_switch_put, \
2162 }
2163
1999#define STAC_CODEC_IO_SWITCH(xname, xpval) \ 2164#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2000 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 2165 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2001 .name = xname, \ 2166 .name = xname, \
@@ -2020,6 +2185,7 @@ enum {
2020 STAC_CTL_WIDGET_VOL, 2185 STAC_CTL_WIDGET_VOL,
2021 STAC_CTL_WIDGET_MUTE, 2186 STAC_CTL_WIDGET_MUTE,
2022 STAC_CTL_WIDGET_MONO_MUX, 2187 STAC_CTL_WIDGET_MONO_MUX,
2188 STAC_CTL_WIDGET_HP_SWITCH,
2023 STAC_CTL_WIDGET_IO_SWITCH, 2189 STAC_CTL_WIDGET_IO_SWITCH,
2024 STAC_CTL_WIDGET_CLFE_SWITCH 2190 STAC_CTL_WIDGET_CLFE_SWITCH
2025}; 2191};
@@ -2028,6 +2194,7 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2028 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2194 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2029 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2195 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2030 STAC_MONO_MUX, 2196 STAC_MONO_MUX,
2197 STAC_CODEC_HP_SWITCH(NULL),
2031 STAC_CODEC_IO_SWITCH(NULL, 0), 2198 STAC_CODEC_IO_SWITCH(NULL, 0),
2032 STAC_CODEC_CLFE_SWITCH(NULL, 0), 2199 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2033}; 2200};
@@ -2222,6 +2389,29 @@ static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_
2222 return 0; 2389 return 0;
2223} 2390}
2224 2391
2392static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2393{
2394 if (!spec->multiout.hp_nid)
2395 spec->multiout.hp_nid = nid;
2396 else if (spec->multiout.num_dacs > 4) {
2397 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2398 return 1;
2399 } else {
2400 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2401 spec->multiout.num_dacs++;
2402 }
2403 return 0;
2404}
2405
2406static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2407{
2408 if (is_in_dac_nids(spec, nid))
2409 return 1;
2410 if (spec->multiout.hp_nid == nid)
2411 return 1;
2412 return 0;
2413}
2414
2225/* add playback controls from the parsed DAC table */ 2415/* add playback controls from the parsed DAC table */
2226static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec, 2416static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2227 const struct auto_pin_cfg *cfg) 2417 const struct auto_pin_cfg *cfg)
@@ -2236,7 +2426,7 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2236 unsigned int wid_caps, pincap; 2426 unsigned int wid_caps, pincap;
2237 2427
2238 2428
2239 for (i = 0; i < cfg->line_outs; i++) { 2429 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
2240 if (!spec->multiout.dac_nids[i]) 2430 if (!spec->multiout.dac_nids[i])
2241 continue; 2431 continue;
2242 2432
@@ -2269,6 +2459,14 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2269 } 2459 }
2270 } 2460 }
2271 2461
2462 if (cfg->hp_outs > 1) {
2463 err = stac92xx_add_control(spec,
2464 STAC_CTL_WIDGET_HP_SWITCH,
2465 "Headphone as Line Out Switch", 0);
2466 if (err < 0)
2467 return err;
2468 }
2469
2272 if (spec->line_switch) { 2470 if (spec->line_switch) {
2273 nid = cfg->input_pins[AUTO_PIN_LINE]; 2471 nid = cfg->input_pins[AUTO_PIN_LINE];
2274 pincap = snd_hda_param_read(codec, nid, 2472 pincap = snd_hda_param_read(codec, nid,
@@ -2284,10 +2482,11 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2284 2482
2285 if (spec->mic_switch) { 2483 if (spec->mic_switch) {
2286 unsigned int def_conf; 2484 unsigned int def_conf;
2287 nid = cfg->input_pins[AUTO_PIN_MIC]; 2485 unsigned int mic_pin = AUTO_PIN_MIC;
2486again:
2487 nid = cfg->input_pins[mic_pin];
2288 def_conf = snd_hda_codec_read(codec, nid, 0, 2488 def_conf = snd_hda_codec_read(codec, nid, 0,
2289 AC_VERB_GET_CONFIG_DEFAULT, 0); 2489 AC_VERB_GET_CONFIG_DEFAULT, 0);
2290
2291 /* some laptops have an internal analog microphone 2490 /* some laptops have an internal analog microphone
2292 * which can't be used as a output */ 2491 * which can't be used as a output */
2293 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) { 2492 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
@@ -2297,38 +2496,22 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2297 err = stac92xx_add_control(spec, 2496 err = stac92xx_add_control(spec,
2298 STAC_CTL_WIDGET_IO_SWITCH, 2497 STAC_CTL_WIDGET_IO_SWITCH,
2299 "Mic as Output Switch", (nid << 8) | 1); 2498 "Mic as Output Switch", (nid << 8) | 1);
2499 nid = snd_hda_codec_read(codec, nid, 0,
2500 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2501 if (!check_in_dac_nids(spec, nid))
2502 add_spec_dacs(spec, nid);
2300 if (err < 0) 2503 if (err < 0)
2301 return err; 2504 return err;
2302 } 2505 }
2506 } else if (mic_pin == AUTO_PIN_MIC) {
2507 mic_pin = AUTO_PIN_FRONT_MIC;
2508 goto again;
2303 } 2509 }
2304 } 2510 }
2305 2511
2306 return 0; 2512 return 0;
2307} 2513}
2308 2514
2309static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2310{
2311 if (is_in_dac_nids(spec, nid))
2312 return 1;
2313 if (spec->multiout.hp_nid == nid)
2314 return 1;
2315 return 0;
2316}
2317
2318static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2319{
2320 if (!spec->multiout.hp_nid)
2321 spec->multiout.hp_nid = nid;
2322 else if (spec->multiout.num_dacs > 4) {
2323 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2324 return 1;
2325 } else {
2326 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2327 spec->multiout.num_dacs++;
2328 }
2329 return 0;
2330}
2331
2332/* add playback controls for Speaker and HP outputs */ 2515/* add playback controls for Speaker and HP outputs */
2333static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, 2516static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2334 struct auto_pin_cfg *cfg) 2517 struct auto_pin_cfg *cfg)
@@ -2378,12 +2561,8 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2378 return err; 2561 return err;
2379 } 2562 }
2380 if (spec->multiout.hp_nid) { 2563 if (spec->multiout.hp_nid) {
2381 const char *pfx; 2564 err = create_controls(spec, "Headphone",
2382 if (old_num_dacs == spec->multiout.num_dacs) 2565 spec->multiout.hp_nid, 3);
2383 pfx = "Master";
2384 else
2385 pfx = "Headphone";
2386 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2387 if (err < 0) 2566 if (err < 0)
2388 return err; 2567 return err;
2389 } 2568 }
@@ -2745,7 +2924,7 @@ static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2745 */ 2924 */
2746 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) { 2925 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2747 hda_nid_t pin = spec->autocfg.speaker_pins[i]; 2926 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2748 unsigned long wcaps = get_wcaps(codec, pin); 2927 unsigned int wcaps = get_wcaps(codec, pin);
2749 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); 2928 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2750 if (wcaps == AC_WCAP_OUT_AMP) 2929 if (wcaps == AC_WCAP_OUT_AMP)
2751 /* found a mono speaker with an amp, must be lfe */ 2930 /* found a mono speaker with an amp, must be lfe */
@@ -2756,12 +2935,12 @@ static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2756 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) { 2935 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2757 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) { 2936 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2758 hda_nid_t pin = spec->autocfg.line_out_pins[i]; 2937 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2759 unsigned long cfg; 2938 unsigned int defcfg;
2760 cfg = snd_hda_codec_read(codec, pin, 0, 2939 defcfg = snd_hda_codec_read(codec, pin, 0,
2761 AC_VERB_GET_CONFIG_DEFAULT, 2940 AC_VERB_GET_CONFIG_DEFAULT,
2762 0x00); 2941 0x00);
2763 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) { 2942 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
2764 unsigned long wcaps = get_wcaps(codec, pin); 2943 unsigned int wcaps = get_wcaps(codec, pin);
2765 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); 2944 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2766 if (wcaps == AC_WCAP_OUT_AMP) 2945 if (wcaps == AC_WCAP_OUT_AMP)
2767 /* found a mono speaker with an amp, 2946 /* found a mono speaker with an amp,
@@ -2866,6 +3045,19 @@ static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
2866 return 0; /* nid is not a HP-Out */ 3045 return 0; /* nid is not a HP-Out */
2867}; 3046};
2868 3047
3048static void stac92xx_power_down(struct hda_codec *codec)
3049{
3050 struct sigmatel_spec *spec = codec->spec;
3051
3052 /* power down inactive DACs */
3053 hda_nid_t *dac;
3054 for (dac = spec->dac_list; *dac; dac++)
3055 if (!is_in_dac_nids(spec, *dac) &&
3056 spec->multiout.hp_nid != *dac)
3057 snd_hda_codec_write_cache(codec, *dac, 0,
3058 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3059}
3060
2869static int stac92xx_init(struct hda_codec *codec) 3061static int stac92xx_init(struct hda_codec *codec)
2870{ 3062{
2871 struct sigmatel_spec *spec = codec->spec; 3063 struct sigmatel_spec *spec = codec->spec;
@@ -2909,16 +3101,21 @@ static int stac92xx_init(struct hda_codec *codec)
2909 ? STAC_HP_EVENT : STAC_PWR_EVENT; 3101 ? STAC_HP_EVENT : STAC_PWR_EVENT;
2910 int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i], 3102 int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i],
2911 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 3103 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3104 int def_conf = snd_hda_codec_read(codec, spec->pwr_nids[i],
3105 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
2912 /* outputs are only ports capable of power management 3106 /* outputs are only ports capable of power management
2913 * any attempts on powering down a input port cause the 3107 * any attempts on powering down a input port cause the
2914 * referenced VREF to act quirky. 3108 * referenced VREF to act quirky.
2915 */ 3109 */
2916 if (pinctl & AC_PINCTL_IN_EN) 3110 if (pinctl & AC_PINCTL_IN_EN)
2917 continue; 3111 continue;
3112 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED)
3113 continue;
2918 enable_pin_detect(codec, spec->pwr_nids[i], event | i); 3114 enable_pin_detect(codec, spec->pwr_nids[i], event | i);
2919 codec->patch_ops.unsol_event(codec, (event | i) << 26); 3115 codec->patch_ops.unsol_event(codec, (event | i) << 26);
2920 } 3116 }
2921 3117 if (spec->dac_list)
3118 stac92xx_power_down(codec);
2922 if (cfg->dig_out_pin) 3119 if (cfg->dig_out_pin)
2923 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin, 3120 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2924 AC_PINCTL_OUT_EN); 3121 AC_PINCTL_OUT_EN);
@@ -3014,6 +3211,7 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3014{ 3211{
3015 struct sigmatel_spec *spec = codec->spec; 3212 struct sigmatel_spec *spec = codec->spec;
3016 struct auto_pin_cfg *cfg = &spec->autocfg; 3213 struct auto_pin_cfg *cfg = &spec->autocfg;
3214 int nid = cfg->hp_pins[cfg->hp_outs - 1];
3017 int i, presence; 3215 int i, presence;
3018 3216
3019 presence = 0; 3217 presence = 0;
@@ -3024,26 +3222,42 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3024 for (i = 0; i < cfg->hp_outs; i++) { 3222 for (i = 0; i < cfg->hp_outs; i++) {
3025 if (presence) 3223 if (presence)
3026 break; 3224 break;
3225 if (spec->hp_switch && cfg->hp_pins[i] == nid)
3226 break;
3027 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]); 3227 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
3028 } 3228 }
3029 3229
3030 if (presence) { 3230 if (presence) {
3031 /* disable lineouts, enable hp */ 3231 /* disable lineouts, enable hp */
3232 if (spec->hp_switch)
3233 stac92xx_reset_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3032 for (i = 0; i < cfg->line_outs; i++) 3234 for (i = 0; i < cfg->line_outs; i++)
3033 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i], 3235 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
3034 AC_PINCTL_OUT_EN); 3236 AC_PINCTL_OUT_EN);
3035 for (i = 0; i < cfg->speaker_outs; i++) 3237 for (i = 0; i < cfg->speaker_outs; i++)
3036 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i], 3238 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
3037 AC_PINCTL_OUT_EN); 3239 AC_PINCTL_OUT_EN);
3240 if (spec->eapd_mask)
3241 stac_gpio_set(codec, spec->gpio_mask,
3242 spec->gpio_dir, spec->gpio_data &
3243 ~spec->eapd_mask);
3038 } else { 3244 } else {
3039 /* enable lineouts, disable hp */ 3245 /* enable lineouts, disable hp */
3246 if (spec->hp_switch)
3247 stac92xx_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3040 for (i = 0; i < cfg->line_outs; i++) 3248 for (i = 0; i < cfg->line_outs; i++)
3041 stac92xx_set_pinctl(codec, cfg->line_out_pins[i], 3249 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
3042 AC_PINCTL_OUT_EN); 3250 AC_PINCTL_OUT_EN);
3043 for (i = 0; i < cfg->speaker_outs; i++) 3251 for (i = 0; i < cfg->speaker_outs; i++)
3044 stac92xx_set_pinctl(codec, cfg->speaker_pins[i], 3252 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
3045 AC_PINCTL_OUT_EN); 3253 AC_PINCTL_OUT_EN);
3254 if (spec->eapd_mask)
3255 stac_gpio_set(codec, spec->gpio_mask,
3256 spec->gpio_dir, spec->gpio_data |
3257 spec->eapd_mask);
3046 } 3258 }
3259 if (!spec->hp_switch && cfg->hp_outs > 1 && presence)
3260 stac92xx_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3047} 3261}
3048 3262
3049static void stac92xx_pin_sense(struct hda_codec *codec, int idx) 3263static void stac92xx_pin_sense(struct hda_codec *codec, int idx)
@@ -3091,6 +3305,9 @@ static int stac92xx_resume(struct hda_codec *codec)
3091 spec->gpio_dir, spec->gpio_data); 3305 spec->gpio_dir, spec->gpio_data);
3092 snd_hda_codec_resume_amp(codec); 3306 snd_hda_codec_resume_amp(codec);
3093 snd_hda_codec_resume_cache(codec); 3307 snd_hda_codec_resume_cache(codec);
3308 /* power down inactive DACs */
3309 if (spec->dac_list)
3310 stac92xx_power_down(codec);
3094 /* invoke unsolicited event to reset the HP state */ 3311 /* invoke unsolicited event to reset the HP state */
3095 if (spec->hp_detect) 3312 if (spec->hp_detect)
3096 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 3313 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
@@ -3147,12 +3364,18 @@ static int patch_stac9200(struct hda_codec *codec)
3147 spec->num_adcs = 1; 3364 spec->num_adcs = 1;
3148 spec->num_pwrs = 0; 3365 spec->num_pwrs = 0;
3149 3366
3150 if (spec->board_config == STAC_9200_GATEWAY) 3367 if (spec->board_config == STAC_9200_GATEWAY ||
3368 spec->board_config == STAC_9200_OQO)
3151 spec->init = stac9200_eapd_init; 3369 spec->init = stac9200_eapd_init;
3152 else 3370 else
3153 spec->init = stac9200_core_init; 3371 spec->init = stac9200_core_init;
3154 spec->mixer = stac9200_mixer; 3372 spec->mixer = stac9200_mixer;
3155 3373
3374 if (spec->board_config == STAC_9200_PANASONIC) {
3375 spec->gpio_mask = spec->gpio_dir = 0x09;
3376 spec->gpio_data = 0x00;
3377 }
3378
3156 err = stac9200_parse_auto_config(codec); 3379 err = stac9200_parse_auto_config(codec);
3157 if (err < 0) { 3380 if (err < 0) {
3158 stac92xx_free(codec); 3381 stac92xx_free(codec);
@@ -3293,6 +3516,7 @@ again:
3293 3516
3294 switch (spec->multiout.num_dacs) { 3517 switch (spec->multiout.num_dacs) {
3295 case 0x3: /* 6 Channel */ 3518 case 0x3: /* 6 Channel */
3519 spec->multiout.hp_nid = 0x17;
3296 spec->mixer = stac92hd73xx_6ch_mixer; 3520 spec->mixer = stac92hd73xx_6ch_mixer;
3297 spec->init = stac92hd73xx_6ch_core_init; 3521 spec->init = stac92hd73xx_6ch_core_init;
3298 break; 3522 break;
@@ -3318,13 +3542,42 @@ again:
3318 3542
3319 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids); 3543 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
3320 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids); 3544 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
3321 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
3322 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids); 3545 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
3323 spec->dinput_mux = &stac92hd73xx_dmux; 3546 spec->dinput_mux = &stac92hd73xx_dmux;
3324 /* GPIO0 High = Enable EAPD */ 3547 /* GPIO0 High = Enable EAPD */
3325 spec->gpio_mask = spec->gpio_dir = 0x1; 3548 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3326 spec->gpio_data = 0x01; 3549 spec->gpio_data = 0x01;
3327 3550
3551 switch (spec->board_config) {
3552 case STAC_DELL_M6:
3553 spec->init = dell_eq_core_init;
3554 switch (codec->subsystem_id) {
3555 case 0x1028025e: /* Analog Mics */
3556 case 0x1028025f:
3557 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3558 spec->num_dmics = 0;
3559 break;
3560 case 0x10280271: /* Digital Mics */
3561 case 0x10280272:
3562 spec->init = dell_m6_core_init;
3563 /* fall-through */
3564 case 0x10280254:
3565 case 0x10280255:
3566 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3567 spec->num_dmics = 1;
3568 break;
3569 case 0x10280256: /* Both */
3570 case 0x10280057:
3571 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3572 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3573 spec->num_dmics = 1;
3574 break;
3575 }
3576 break;
3577 default:
3578 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
3579 }
3580
3328 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 3581 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
3329 spec->pwr_nids = stac92hd73xx_pwr_nids; 3582 spec->pwr_nids = stac92hd73xx_pwr_nids;
3330 3583
@@ -3398,7 +3651,10 @@ again:
3398 spec->aloopback_shift = 0; 3651 spec->aloopback_shift = 0;
3399 3652
3400 /* GPIO0 High = EAPD */ 3653 /* GPIO0 High = EAPD */
3401 spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0x1; 3654 spec->gpio_mask = 0x01;
3655 spec->gpio_dir = 0x01;
3656 spec->gpio_mask = 0x01;
3657 spec->gpio_data = 0x01;
3402 3658
3403 spec->mux_nids = stac92hd71bxx_mux_nids; 3659 spec->mux_nids = stac92hd71bxx_mux_nids;
3404 spec->adc_nids = stac92hd71bxx_adc_nids; 3660 spec->adc_nids = stac92hd71bxx_adc_nids;
@@ -3413,7 +3669,7 @@ again:
3413 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids); 3669 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
3414 spec->pwr_nids = stac92hd71bxx_pwr_nids; 3670 spec->pwr_nids = stac92hd71bxx_pwr_nids;
3415 3671
3416 spec->multiout.num_dacs = 2; 3672 spec->multiout.num_dacs = 1;
3417 spec->multiout.hp_nid = 0x11; 3673 spec->multiout.hp_nid = 0x11;
3418 spec->multiout.dac_nids = stac92hd71bxx_dac_nids; 3674 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
3419 3675
@@ -3577,13 +3833,14 @@ static int patch_stac927x(struct hda_codec *codec)
3577 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids); 3833 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3578 spec->mux_nids = stac927x_mux_nids; 3834 spec->mux_nids = stac927x_mux_nids;
3579 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); 3835 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
3836 spec->dac_list = stac927x_dac_nids;
3580 spec->multiout.dac_nids = spec->dac_nids; 3837 spec->multiout.dac_nids = spec->dac_nids;
3581 3838
3582 switch (spec->board_config) { 3839 switch (spec->board_config) {
3583 case STAC_D965_3ST: 3840 case STAC_D965_3ST:
3584 case STAC_D965_5ST: 3841 case STAC_D965_5ST:
3585 /* GPIO0 High = Enable EAPD */ 3842 /* GPIO0 High = Enable EAPD */
3586 spec->gpio_mask = spec->gpio_dir = 0x01; 3843 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
3587 spec->gpio_data = 0x01; 3844 spec->gpio_data = 0x01;
3588 spec->num_dmics = 0; 3845 spec->num_dmics = 0;
3589 3846
@@ -3591,14 +3848,23 @@ static int patch_stac927x(struct hda_codec *codec)
3591 spec->mixer = stac927x_mixer; 3848 spec->mixer = stac927x_mixer;
3592 break; 3849 break;
3593 case STAC_DELL_BIOS: 3850 case STAC_DELL_BIOS:
3851 switch (codec->subsystem_id) {
3852 case 0x10280209:
3853 case 0x1028022e:
3854 /* correct the device field to SPDIF out */
3855 stac92xx_set_config_reg(codec, 0x21, 0x01442070);
3856 break;
3857 };
3858 /* configure the analog microphone on some laptops */
3859 stac92xx_set_config_reg(codec, 0x0c, 0x90a79130);
3594 /* correct the front output jack as a hp out */ 3860 /* correct the front output jack as a hp out */
3595 stac92xx_set_config_reg(codec, 0x0f, 0x02270110); 3861 stac92xx_set_config_reg(codec, 0x0f, 0x0227011f);
3596 /* correct the front input jack as a mic */ 3862 /* correct the front input jack as a mic */
3597 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130); 3863 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
3598 /* fallthru */ 3864 /* fallthru */
3599 case STAC_DELL_3ST: 3865 case STAC_DELL_3ST:
3600 /* GPIO2 High = Enable EAPD */ 3866 /* GPIO2 High = Enable EAPD */
3601 spec->gpio_mask = spec->gpio_dir = 0x04; 3867 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
3602 spec->gpio_data = 0x04; 3868 spec->gpio_data = 0x04;
3603 spec->dmic_nids = stac927x_dmic_nids; 3869 spec->dmic_nids = stac927x_dmic_nids;
3604 spec->num_dmics = STAC927X_NUM_DMICS; 3870 spec->num_dmics = STAC927X_NUM_DMICS;
@@ -3610,7 +3876,7 @@ static int patch_stac927x(struct hda_codec *codec)
3610 break; 3876 break;
3611 default: 3877 default:
3612 /* GPIO0 High = Enable EAPD */ 3878 /* GPIO0 High = Enable EAPD */
3613 spec->gpio_mask = spec->gpio_dir = 0x1; 3879 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3614 spec->gpio_data = 0x01; 3880 spec->gpio_data = 0x01;
3615 spec->num_dmics = 0; 3881 spec->num_dmics = 0;
3616 3882
@@ -3714,6 +3980,7 @@ static int patch_stac9205(struct hda_codec *codec)
3714 (AC_USRSP_EN | STAC_HP_EVENT)); 3980 (AC_USRSP_EN | STAC_HP_EVENT));
3715 3981
3716 spec->gpio_dir = 0x0b; 3982 spec->gpio_dir = 0x0b;
3983 spec->eapd_mask = 0x01;
3717 spec->gpio_mask = 0x1b; 3984 spec->gpio_mask = 0x1b;
3718 spec->gpio_mute = 0x10; 3985 spec->gpio_mute = 0x10;
3719 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute, 3986 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
@@ -3723,7 +3990,7 @@ static int patch_stac9205(struct hda_codec *codec)
3723 break; 3990 break;
3724 default: 3991 default:
3725 /* GPIO0 High = EAPD */ 3992 /* GPIO0 High = EAPD */
3726 spec->gpio_mask = spec->gpio_dir = 0x1; 3993 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3727 spec->gpio_data = 0x01; 3994 spec->gpio_data = 0x01;
3728 break; 3995 break;
3729 } 3996 }
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 4e5dd4cf36f5..52b1d81a26f7 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -39,7 +39,7 @@
39#include <sound/core.h> 39#include <sound/core.h>
40#include "hda_codec.h" 40#include "hda_codec.h"
41#include "hda_local.h" 41#include "hda_local.h"
42 42#include "hda_patch.h"
43 43
44/* amp values */ 44/* amp values */
45#define AMP_VAL_IDX_SHIFT 19 45#define AMP_VAL_IDX_SHIFT 19
@@ -357,7 +357,8 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
357 struct snd_pcm_substream *substream) 357 struct snd_pcm_substream *substream)
358{ 358{
359 struct via_spec *spec = codec->spec; 359 struct via_spec *spec = codec->spec;
360 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 360 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
361 hinfo);
361} 362}
362 363
363static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 364static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -430,8 +431,7 @@ static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
430 struct snd_pcm_substream *substream) 431 struct snd_pcm_substream *substream)
431{ 432{
432 struct via_spec *spec = codec->spec; 433 struct via_spec *spec = codec->spec;
433 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 434 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
434 0, 0, 0);
435 return 0; 435 return 0;
436} 436}
437 437
@@ -493,6 +493,11 @@ static int via_build_controls(struct hda_codec *codec)
493 spec->multiout.dig_out_nid); 493 spec->multiout.dig_out_nid);
494 if (err < 0) 494 if (err < 0)
495 return err; 495 return err;
496 err = snd_hda_create_spdif_share_sw(codec,
497 &spec->multiout);
498 if (err < 0)
499 return err;
500 spec->multiout.share_spdif = 1;
496 } 501 }
497 if (spec->dig_in_nid) { 502 if (spec->dig_in_nid) {
498 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 503 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -523,6 +528,7 @@ static int via_build_pcms(struct hda_codec *codec)
523 codec->num_pcms++; 528 codec->num_pcms++;
524 info++; 529 info++;
525 info->name = spec->stream_name_digital; 530 info->name = spec->stream_name_digital;
531 info->pcm_type = HDA_PCM_TYPE_SPDIF;
526 if (spec->multiout.dig_out_nid) { 532 if (spec->multiout.dig_out_nid) {
527 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 533 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
528 *(spec->stream_digital_playback); 534 *(spec->stream_digital_playback);
diff --git a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
index efd180b40e56..0ed96c178059 100644
--- a/sound/pci/ice1712/delta.c
+++ b/sound/pci/ice1712/delta.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24) 2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 * 3 *
4 * Lowlevel functions for M-Audio Delta 1010, 44, 66, Dio2496, Audiophile 4 * Lowlevel functions for M-Audio Delta 1010, 1010E, 44, 66, 66E, Dio2496,
5 * Digigram VX442 5 * Audiophile, Digigram VX442
6 * 6 *
7 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz> 7 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
8 * 8 *
@@ -86,6 +86,7 @@ static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
86 unsigned char tmp; 86 unsigned char tmp;
87 tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); 87 tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
88 switch (ice->eeprom.subvendor) { 88 switch (ice->eeprom.subvendor) {
89 case ICE1712_SUBDEVICE_DELTA1010E:
89 case ICE1712_SUBDEVICE_DELTA1010LT: 90 case ICE1712_SUBDEVICE_DELTA1010LT:
90 tmp &= ~ICE1712_DELTA_1010LT_CS; 91 tmp &= ~ICE1712_DELTA_1010LT_CS;
91 tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427; 92 tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427;
@@ -109,6 +110,7 @@ static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
109static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp) 110static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp)
110{ 111{
111 switch (ice->eeprom.subvendor) { 112 switch (ice->eeprom.subvendor) {
113 case ICE1712_SUBDEVICE_DELTA1010E:
112 case ICE1712_SUBDEVICE_DELTA1010LT: 114 case ICE1712_SUBDEVICE_DELTA1010LT:
113 tmp &= ~ICE1712_DELTA_1010LT_CS; 115 tmp &= ~ICE1712_DELTA_1010LT_CS;
114 tmp |= ICE1712_DELTA_1010LT_CS_NONE; 116 tmp |= ICE1712_DELTA_1010LT_CS_NONE;
@@ -534,6 +536,14 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
534 int err; 536 int err;
535 struct snd_akm4xxx *ak; 537 struct snd_akm4xxx *ak;
536 538
539 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA1010 &&
540 ice->eeprom.gpiodir == 0x7b)
541 ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA1010E;
542
543 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA66 &&
544 ice->eeprom.gpiodir == 0xfb)
545 ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA66E;
546
537 /* determine I2C, DACs and ADCs */ 547 /* determine I2C, DACs and ADCs */
538 switch (ice->eeprom.subvendor) { 548 switch (ice->eeprom.subvendor) {
539 case ICE1712_SUBDEVICE_AUDIOPHILE: 549 case ICE1712_SUBDEVICE_AUDIOPHILE:
@@ -550,6 +560,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
550 ice->num_total_adcs = ice->omni ? 8 : 4; 560 ice->num_total_adcs = ice->omni ? 8 : 4;
551 break; 561 break;
552 case ICE1712_SUBDEVICE_DELTA1010: 562 case ICE1712_SUBDEVICE_DELTA1010:
563 case ICE1712_SUBDEVICE_DELTA1010E:
553 case ICE1712_SUBDEVICE_DELTA1010LT: 564 case ICE1712_SUBDEVICE_DELTA1010LT:
554 case ICE1712_SUBDEVICE_MEDIASTATION: 565 case ICE1712_SUBDEVICE_MEDIASTATION:
555 ice->num_total_dacs = 8; 566 ice->num_total_dacs = 8;
@@ -559,6 +570,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
559 ice->num_total_dacs = 4; /* two AK4324 codecs */ 570 ice->num_total_dacs = 4; /* two AK4324 codecs */
560 break; 571 break;
561 case ICE1712_SUBDEVICE_VX442: 572 case ICE1712_SUBDEVICE_VX442:
573 case ICE1712_SUBDEVICE_DELTA66E: /* omni not suported yet */
562 ice->num_total_dacs = 4; 574 ice->num_total_dacs = 4;
563 ice->num_total_adcs = 4; 575 ice->num_total_adcs = 4;
564 break; 576 break;
@@ -568,8 +580,10 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
568 switch (ice->eeprom.subvendor) { 580 switch (ice->eeprom.subvendor) {
569 case ICE1712_SUBDEVICE_AUDIOPHILE: 581 case ICE1712_SUBDEVICE_AUDIOPHILE:
570 case ICE1712_SUBDEVICE_DELTA410: 582 case ICE1712_SUBDEVICE_DELTA410:
583 case ICE1712_SUBDEVICE_DELTA1010E:
571 case ICE1712_SUBDEVICE_DELTA1010LT: 584 case ICE1712_SUBDEVICE_DELTA1010LT:
572 case ICE1712_SUBDEVICE_VX442: 585 case ICE1712_SUBDEVICE_VX442:
586 case ICE1712_SUBDEVICE_DELTA66E:
573 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 587 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
574 snd_printk(KERN_ERR "unable to create I2C bus\n"); 588 snd_printk(KERN_ERR "unable to create I2C bus\n");
575 return err; 589 return err;
@@ -601,6 +615,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
601 /* no analog? */ 615 /* no analog? */
602 switch (ice->eeprom.subvendor) { 616 switch (ice->eeprom.subvendor) {
603 case ICE1712_SUBDEVICE_DELTA1010: 617 case ICE1712_SUBDEVICE_DELTA1010:
618 case ICE1712_SUBDEVICE_DELTA1010E:
604 case ICE1712_SUBDEVICE_DELTADIO2496: 619 case ICE1712_SUBDEVICE_DELTADIO2496:
605 case ICE1712_SUBDEVICE_MEDIASTATION: 620 case ICE1712_SUBDEVICE_MEDIASTATION:
606 return 0; 621 return 0;
@@ -627,6 +642,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
627 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice); 642 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
628 break; 643 break;
629 case ICE1712_SUBDEVICE_VX442: 644 case ICE1712_SUBDEVICE_VX442:
645 case ICE1712_SUBDEVICE_DELTA66E:
630 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice); 646 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
631 break; 647 break;
632 default: 648 default:
@@ -674,6 +690,7 @@ static int __devinit snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
674 if (err < 0) 690 if (err < 0)
675 return err; 691 return err;
676 break; 692 break;
693 case ICE1712_SUBDEVICE_DELTA1010E:
677 case ICE1712_SUBDEVICE_DELTA1010LT: 694 case ICE1712_SUBDEVICE_DELTA1010LT:
678 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice)); 695 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice));
679 if (err < 0) 696 if (err < 0)
@@ -716,6 +733,7 @@ static int __devinit snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
716 case ICE1712_SUBDEVICE_DELTA44: 733 case ICE1712_SUBDEVICE_DELTA44:
717 case ICE1712_SUBDEVICE_DELTA66: 734 case ICE1712_SUBDEVICE_DELTA66:
718 case ICE1712_SUBDEVICE_VX442: 735 case ICE1712_SUBDEVICE_VX442:
736 case ICE1712_SUBDEVICE_DELTA66E:
719 err = snd_ice1712_akm4xxx_build_controls(ice); 737 err = snd_ice1712_akm4xxx_build_controls(ice);
720 if (err < 0) 738 if (err < 0)
721 return err; 739 return err;
diff --git a/sound/pci/ice1712/delta.h b/sound/pci/ice1712/delta.h
index 26ea05a32f56..ea7116c304c0 100644
--- a/sound/pci/ice1712/delta.h
+++ b/sound/pci/ice1712/delta.h
@@ -36,8 +36,10 @@
36 "{Lionstracs,Mediastation}," 36 "{Lionstracs,Mediastation},"
37 37
38#define ICE1712_SUBDEVICE_DELTA1010 0x121430d6 38#define ICE1712_SUBDEVICE_DELTA1010 0x121430d6
39#define ICE1712_SUBDEVICE_DELTA1010E 0xff1430d6
39#define ICE1712_SUBDEVICE_DELTADIO2496 0x121431d6 40#define ICE1712_SUBDEVICE_DELTADIO2496 0x121431d6
40#define ICE1712_SUBDEVICE_DELTA66 0x121432d6 41#define ICE1712_SUBDEVICE_DELTA66 0x121432d6
42#define ICE1712_SUBDEVICE_DELTA66E 0xff1432d6
41#define ICE1712_SUBDEVICE_DELTA44 0x121433d6 43#define ICE1712_SUBDEVICE_DELTA44 0x121433d6
42#define ICE1712_SUBDEVICE_AUDIOPHILE 0x121434d6 44#define ICE1712_SUBDEVICE_AUDIOPHILE 0x121434d6
43#define ICE1712_SUBDEVICE_DELTA410 0x121438d6 45#define ICE1712_SUBDEVICE_DELTA410 0x121438d6
diff --git a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
index 064760d2a027..013fc4f04822 100644
--- a/sound/pci/ice1712/ews.c
+++ b/sound/pci/ice1712/ews.c
@@ -238,6 +238,7 @@ static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned
238 case ICE1712_SUBDEVICE_EWS88MT: 238 case ICE1712_SUBDEVICE_EWS88MT:
239 case ICE1712_SUBDEVICE_EWS88MT_NEW: 239 case ICE1712_SUBDEVICE_EWS88MT_NEW:
240 case ICE1712_SUBDEVICE_PHASE88: 240 case ICE1712_SUBDEVICE_PHASE88:
241 case ICE1712_SUBDEVICE_TS88:
241 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1) 242 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
242 != 1) 243 != 1)
243 goto _error; 244 goto _error;
@@ -433,6 +434,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
433 case ICE1712_SUBDEVICE_EWS88MT: 434 case ICE1712_SUBDEVICE_EWS88MT:
434 case ICE1712_SUBDEVICE_EWS88MT_NEW: 435 case ICE1712_SUBDEVICE_EWS88MT_NEW:
435 case ICE1712_SUBDEVICE_PHASE88: 436 case ICE1712_SUBDEVICE_PHASE88:
437 case ICE1712_SUBDEVICE_TS88:
436 ice->num_total_dacs = 8; 438 ice->num_total_dacs = 8;
437 ice->num_total_adcs = 8; 439 ice->num_total_adcs = 8;
438 break; 440 break;
@@ -475,6 +477,8 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
475 case ICE1712_SUBDEVICE_EWS88MT: 477 case ICE1712_SUBDEVICE_EWS88MT:
476 case ICE1712_SUBDEVICE_EWS88MT_NEW: 478 case ICE1712_SUBDEVICE_EWS88MT_NEW:
477 case ICE1712_SUBDEVICE_PHASE88: 479 case ICE1712_SUBDEVICE_PHASE88:
480 case ICE1712_SUBDEVICE_TS88:
481
478 err = snd_i2c_device_create(ice->i2c, "CS8404", 482 err = snd_i2c_device_create(ice->i2c, "CS8404",
479 ICE1712_EWS88MT_CS8404_ADDR, 483 ICE1712_EWS88MT_CS8404_ADDR,
480 &spec->i2cdevs[EWS_I2C_CS8404]); 484 &spec->i2cdevs[EWS_I2C_CS8404]);
@@ -518,6 +522,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
518 case ICE1712_SUBDEVICE_EWS88MT: 522 case ICE1712_SUBDEVICE_EWS88MT:
519 case ICE1712_SUBDEVICE_EWS88MT_NEW: 523 case ICE1712_SUBDEVICE_EWS88MT_NEW:
520 case ICE1712_SUBDEVICE_PHASE88: 524 case ICE1712_SUBDEVICE_PHASE88:
525 case ICE1712_SUBDEVICE_TS88:
521 case ICE1712_SUBDEVICE_EWS88D: 526 case ICE1712_SUBDEVICE_EWS88D:
522 /* set up CS8404 */ 527 /* set up CS8404 */
523 ice->spdif.ops.open = ews88_open_spdif; 528 ice->spdif.ops.open = ews88_open_spdif;
@@ -547,6 +552,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
547 case ICE1712_SUBDEVICE_EWS88MT: 552 case ICE1712_SUBDEVICE_EWS88MT:
548 case ICE1712_SUBDEVICE_EWS88MT_NEW: 553 case ICE1712_SUBDEVICE_EWS88MT_NEW:
549 case ICE1712_SUBDEVICE_PHASE88: 554 case ICE1712_SUBDEVICE_PHASE88:
555 case ICE1712_SUBDEVICE_TS88:
550 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice); 556 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
551 break; 557 break;
552 case ICE1712_SUBDEVICE_EWX2496: 558 case ICE1712_SUBDEVICE_EWX2496:
@@ -973,6 +979,7 @@ static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
973 case ICE1712_SUBDEVICE_EWS88MT: 979 case ICE1712_SUBDEVICE_EWS88MT:
974 case ICE1712_SUBDEVICE_EWS88MT_NEW: 980 case ICE1712_SUBDEVICE_EWS88MT_NEW:
975 case ICE1712_SUBDEVICE_PHASE88: 981 case ICE1712_SUBDEVICE_PHASE88:
982 case ICE1712_SUBDEVICE_TS88:
976 case ICE1712_SUBDEVICE_DMX6FIRE: 983 case ICE1712_SUBDEVICE_DMX6FIRE:
977 err = snd_ice1712_akm4xxx_build_controls(ice); 984 err = snd_ice1712_akm4xxx_build_controls(ice);
978 if (err < 0) 985 if (err < 0)
@@ -992,6 +999,7 @@ static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
992 case ICE1712_SUBDEVICE_EWS88MT: 999 case ICE1712_SUBDEVICE_EWS88MT:
993 case ICE1712_SUBDEVICE_EWS88MT_NEW: 1000 case ICE1712_SUBDEVICE_EWS88MT_NEW:
994 case ICE1712_SUBDEVICE_PHASE88: 1001 case ICE1712_SUBDEVICE_PHASE88:
1002 case ICE1712_SUBDEVICE_TS88:
995 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice)); 1003 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
996 if (err < 0) 1004 if (err < 0)
997 return err; 1005 return err;
@@ -1049,6 +1057,13 @@ struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
1049 .build_controls = snd_ice1712_ews_add_controls, 1057 .build_controls = snd_ice1712_ews_add_controls,
1050 }, 1058 },
1051 { 1059 {
1060 .subvendor = ICE1712_SUBDEVICE_TS88,
1061 .name = "terrasoniq TS88",
1062 .model = "phase88",
1063 .chip_init = snd_ice1712_ews_init,
1064 .build_controls = snd_ice1712_ews_add_controls,
1065 },
1066 {
1052 .subvendor = ICE1712_SUBDEVICE_EWS88D, 1067 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1053 .name = "TerraTec EWS88D", 1068 .name = "TerraTec EWS88D",
1054 .model = "ews88d", 1069 .model = "ews88d",
diff --git a/sound/pci/ice1712/ews.h b/sound/pci/ice1712/ews.h
index e4ed1b475b08..1c443718af03 100644
--- a/sound/pci/ice1712/ews.h
+++ b/sound/pci/ice1712/ews.h
@@ -30,7 +30,8 @@
30 "{TerraTec,EWS 88MT},"\ 30 "{TerraTec,EWS 88MT},"\
31 "{TerraTec,EWS 88D},"\ 31 "{TerraTec,EWS 88D},"\
32 "{TerraTec,DMX 6Fire},"\ 32 "{TerraTec,DMX 6Fire},"\
33 "{TerraTec,Phase 88}," 33 "{TerraTec,Phase 88}," \
34 "{terrasoniq,TS 88},"
34 35
35#define ICE1712_SUBDEVICE_EWX2496 0x3b153011 36#define ICE1712_SUBDEVICE_EWX2496 0x3b153011
36#define ICE1712_SUBDEVICE_EWS88MT 0x3b151511 37#define ICE1712_SUBDEVICE_EWS88MT 0x3b151511
@@ -38,6 +39,7 @@
38#define ICE1712_SUBDEVICE_EWS88D 0x3b152b11 39#define ICE1712_SUBDEVICE_EWS88D 0x3b152b11
39#define ICE1712_SUBDEVICE_DMX6FIRE 0x3b153811 40#define ICE1712_SUBDEVICE_DMX6FIRE 0x3b153811
40#define ICE1712_SUBDEVICE_PHASE88 0x3b155111 41#define ICE1712_SUBDEVICE_PHASE88 0x3b155111
42#define ICE1712_SUBDEVICE_TS88 0x3b157c11
41 43
42/* entry point */ 44/* entry point */
43extern struct snd_ice1712_card_info snd_ice1712_ews_cards[]; 45extern struct snd_ice1712_card_info snd_ice1712_ews_cards[];
diff --git a/sound/pci/ice1712/hoontech.c b/sound/pci/ice1712/hoontech.c
index cf5c7c0898fd..6914189073a4 100644
--- a/sound/pci/ice1712/hoontech.c
+++ b/sound/pci/ice1712/hoontech.c
@@ -208,6 +208,19 @@ static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
208 /* ICE1712_STDSP24_MUTE | 208 /* ICE1712_STDSP24_MUTE |
209 ICE1712_STDSP24_INSEL | 209 ICE1712_STDSP24_INSEL |
210 ICE1712_STDSP24_DAREAR; */ 210 ICE1712_STDSP24_DAREAR; */
211 /* These boxconfigs have caused problems in the past.
212 * The code is not optimal, but should now enable a working config to
213 * be achieved.
214 * ** MIDI IN can only be configured on one box **
215 * ICE1712_STDSP24_BOX_MIDI1 needs to be set for that box.
216 * Tests on a ADAC2000 box suggest the box config flags do not
217 * work as would be expected, and the inputs are crossed.
218 * Setting ICE1712_STDSP24_BOX_MIDI1 and ICE1712_STDSP24_BOX_MIDI2
219 * on the same box connects MIDI-In to both 401 uarts; both outputs
220 * are then active on all boxes.
221 * The default config here sets up everything on the first box.
222 * Alan Horstmann 5.2.2008
223 */
211 spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 | 224 spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 |
212 ICE1712_STDSP24_BOX_CHN2 | 225 ICE1712_STDSP24_BOX_CHN2 |
213 ICE1712_STDSP24_BOX_CHN3 | 226 ICE1712_STDSP24_BOX_CHN3 |
@@ -223,14 +236,14 @@ static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
223 (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0); 236 (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0);
224 snd_ice1712_stdsp24_insel(ice, 237 snd_ice1712_stdsp24_insel(ice,
225 (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0); 238 (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0);
226 for (box = 0; box < 1; box++) { 239 for (box = 0; box < 4; box++) {
227 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2) 240 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2)
228 snd_ice1712_stdsp24_midi2(ice, 1); 241 snd_ice1712_stdsp24_midi2(ice, 1);
229 for (chn = 0; chn < 4; chn++) 242 for (chn = 0; chn < 4; chn++)
230 snd_ice1712_stdsp24_box_channel(ice, box, chn, 243 snd_ice1712_stdsp24_box_channel(ice, box, chn,
231 (spec->boxconfig[box] & (1 << chn)) ? 1 : 0); 244 (spec->boxconfig[box] & (1 << chn)) ? 1 : 0);
232 snd_ice1712_stdsp24_box_midi(ice, box, 245 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1)
233 (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1) ? 1 : 0); 246 snd_ice1712_stdsp24_box_midi(ice, box, 1);
234 } 247 }
235 248
236 return 0; 249 return 0;
@@ -322,6 +335,8 @@ struct snd_ice1712_card_info snd_ice1712_hoontech_cards[] __devinitdata = {
322 .name = "Hoontech SoundTrack Audio DSP24", 335 .name = "Hoontech SoundTrack Audio DSP24",
323 .model = "dsp24", 336 .model = "dsp24",
324 .chip_init = snd_ice1712_hoontech_init, 337 .chip_init = snd_ice1712_hoontech_init,
338 .mpu401_1_name = "MIDI-1 Hoontech/STA DSP24",
339 .mpu401_2_name = "MIDI-2 Hoontech/STA DSP24",
325 }, 340 },
326 { 341 {
327 .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */ 342 .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index df292af67381..29d449d73c98 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -1297,11 +1297,14 @@ static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
1297static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1297static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1298{ 1298{
1299 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1299 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1300 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1300 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1301 kcontrol->private_value;
1301 1302
1302 spin_lock_irq(&ice->reg_lock); 1303 spin_lock_irq(&ice->reg_lock);
1303 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1); 1304 ucontrol->value.integer.value[0] =
1304 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1); 1305 !((ice->pro_volumes[priv_idx] >> 15) & 1);
1306 ucontrol->value.integer.value[1] =
1307 !((ice->pro_volumes[priv_idx] >> 31) & 1);
1305 spin_unlock_irq(&ice->reg_lock); 1308 spin_unlock_irq(&ice->reg_lock);
1306 return 0; 1309 return 0;
1307} 1310}
@@ -1309,16 +1312,17 @@ static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struc
1309static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1312static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1310{ 1313{
1311 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1314 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1312 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1315 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1316 kcontrol->private_value;
1313 unsigned int nval, change; 1317 unsigned int nval, change;
1314 1318
1315 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) | 1319 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1316 (ucontrol->value.integer.value[1] ? 0 : 0x80000000); 1320 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1317 spin_lock_irq(&ice->reg_lock); 1321 spin_lock_irq(&ice->reg_lock);
1318 nval |= ice->pro_volumes[index] & ~0x80008000; 1322 nval |= ice->pro_volumes[priv_idx] & ~0x80008000;
1319 change = nval != ice->pro_volumes[index]; 1323 change = nval != ice->pro_volumes[priv_idx];
1320 ice->pro_volumes[index] = nval; 1324 ice->pro_volumes[priv_idx] = nval;
1321 snd_ice1712_update_volume(ice, index); 1325 snd_ice1712_update_volume(ice, priv_idx);
1322 spin_unlock_irq(&ice->reg_lock); 1326 spin_unlock_irq(&ice->reg_lock);
1323 return change; 1327 return change;
1324} 1328}
@@ -1335,11 +1339,14 @@ static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, stru
1335static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1339static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1336{ 1340{
1337 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1341 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1338 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1342 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1343 kcontrol->private_value;
1339 1344
1340 spin_lock_irq(&ice->reg_lock); 1345 spin_lock_irq(&ice->reg_lock);
1341 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127; 1346 ucontrol->value.integer.value[0] =
1342 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127; 1347 (ice->pro_volumes[priv_idx] >> 0) & 127;
1348 ucontrol->value.integer.value[1] =
1349 (ice->pro_volumes[priv_idx] >> 16) & 127;
1343 spin_unlock_irq(&ice->reg_lock); 1350 spin_unlock_irq(&ice->reg_lock);
1344 return 0; 1351 return 0;
1345} 1352}
@@ -1347,16 +1354,17 @@ static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struc
1347static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1354static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1348{ 1355{
1349 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1356 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1350 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1357 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1358 kcontrol->private_value;
1351 unsigned int nval, change; 1359 unsigned int nval, change;
1352 1360
1353 nval = (ucontrol->value.integer.value[0] & 127) | 1361 nval = (ucontrol->value.integer.value[0] & 127) |
1354 ((ucontrol->value.integer.value[1] & 127) << 16); 1362 ((ucontrol->value.integer.value[1] & 127) << 16);
1355 spin_lock_irq(&ice->reg_lock); 1363 spin_lock_irq(&ice->reg_lock);
1356 nval |= ice->pro_volumes[index] & ~0x007f007f; 1364 nval |= ice->pro_volumes[priv_idx] & ~0x007f007f;
1357 change = nval != ice->pro_volumes[index]; 1365 change = nval != ice->pro_volumes[priv_idx];
1358 ice->pro_volumes[index] = nval; 1366 ice->pro_volumes[priv_idx] = nval;
1359 snd_ice1712_update_volume(ice, index); 1367 snd_ice1712_update_volume(ice, priv_idx);
1360 spin_unlock_irq(&ice->reg_lock); 1368 spin_unlock_irq(&ice->reg_lock);
1361 return change; 1369 return change;
1362} 1370}
@@ -2482,10 +2490,9 @@ static int snd_ice1712_free(struct snd_ice1712 *ice)
2482 outb(0xff, ICEREG(ice, IRQMASK)); 2490 outb(0xff, ICEREG(ice, IRQMASK));
2483 /* --- */ 2491 /* --- */
2484 __hw_end: 2492 __hw_end:
2485 if (ice->irq >= 0) { 2493 if (ice->irq >= 0)
2486 synchronize_irq(ice->irq);
2487 free_irq(ice->irq, ice); 2494 free_irq(ice->irq, ice);
2488 } 2495
2489 if (ice->port) 2496 if (ice->port)
2490 pci_release_regions(ice->pci); 2497 pci_release_regions(ice->pci);
2491 snd_ice1712_akm4xxx_free(ice); 2498 snd_ice1712_akm4xxx_free(ice);
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index 303cffe08bd8..3208901c740e 100644
--- a/sound/pci/ice1712/ice1712.h
+++ b/sound/pci/ice1712/ice1712.h
@@ -367,6 +367,15 @@ struct snd_ice1712 {
367 367
368 /* other board-specific data */ 368 /* other board-specific data */
369 void *spec; 369 void *spec;
370
371 /* VT172x specific */
372 int pro_rate_default;
373 int (*is_spdif_master)(struct snd_ice1712 *ice);
374 unsigned int (*get_rate)(struct snd_ice1712 *ice);
375 void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate);
376 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate);
377 void (*set_spdif_clock)(struct snd_ice1712 *ice);
378
370}; 379};
371 380
372 381
@@ -429,10 +438,14 @@ int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
429static inline void snd_ice1712_gpio_write_bits(struct snd_ice1712 *ice, 438static inline void snd_ice1712_gpio_write_bits(struct snd_ice1712 *ice,
430 unsigned int mask, unsigned int bits) 439 unsigned int mask, unsigned int bits)
431{ 440{
441 unsigned val;
442
432 ice->gpio.direction |= mask; 443 ice->gpio.direction |= mask;
433 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); 444 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
434 snd_ice1712_gpio_set_mask(ice, ~mask); 445 val = snd_ice1712_gpio_read(ice);
435 snd_ice1712_gpio_write(ice, mask & bits); 446 val &= ~mask;
447 val |= mask & bits;
448 snd_ice1712_gpio_write(ice, val);
436} 449}
437 450
438static inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice, 451static inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice,
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index f533850ec6e7..67350901772c 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -106,15 +106,19 @@ static unsigned int PRO_RATE_DEFAULT = 44100;
106 * Basic I/O 106 * Basic I/O
107 */ 107 */
108 108
109/*
110 * default rates, default clock routines
111 */
112
109/* check whether the clock mode is spdif-in */ 113/* check whether the clock mode is spdif-in */
110static inline int is_spdif_master(struct snd_ice1712 *ice) 114static inline int stdclock_is_spdif_master(struct snd_ice1712 *ice)
111{ 115{
112 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0; 116 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
113} 117}
114 118
115static inline int is_pro_rate_locked(struct snd_ice1712 *ice) 119static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
116{ 120{
117 return is_spdif_master(ice) || PRO_RATE_LOCKED; 121 return ice->is_spdif_master(ice) || PRO_RATE_LOCKED;
118} 122}
119 123
120/* 124/*
@@ -219,6 +223,32 @@ static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
219} 223}
220 224
221/* 225/*
226 * MPU401 accessor
227 */
228static unsigned char snd_vt1724_mpu401_read(struct snd_mpu401 *mpu,
229 unsigned long addr)
230{
231 /* fix status bits to the standard position */
232 /* only RX_EMPTY and TX_FULL are checked */
233 if (addr == MPU401C(mpu))
234 return (inb(addr) & 0x0c) << 4;
235 else
236 return inb(addr);
237}
238
239static void snd_vt1724_mpu401_write(struct snd_mpu401 *mpu,
240 unsigned char data, unsigned long addr)
241{
242 if (addr == MPU401C(mpu)) {
243 if (data == MPU401_ENTER_UART)
244 outb(0x01, addr);
245 /* what else? */
246 } else
247 outb(data, addr);
248}
249
250
251/*
222 * Interrupt handler 252 * Interrupt handler
223 */ 253 */
224 254
@@ -226,24 +256,53 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
226{ 256{
227 struct snd_ice1712 *ice = dev_id; 257 struct snd_ice1712 *ice = dev_id;
228 unsigned char status; 258 unsigned char status;
259 unsigned char status_mask =
260 VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX | VT1724_IRQ_MTPCM;
229 int handled = 0; 261 int handled = 0;
262#ifdef CONFIG_SND_DEBUG
263 int timeout = 0;
264#endif
230 265
231 while (1) { 266 while (1) {
232 status = inb(ICEREG1724(ice, IRQSTAT)); 267 status = inb(ICEREG1724(ice, IRQSTAT));
268 status &= status_mask;
233 if (status == 0) 269 if (status == 0)
234 break; 270 break;
235 271#ifdef CONFIG_SND_DEBUG
272 if (++timeout > 10) {
273 printk(KERN_ERR
274 "ice1724: Too long irq loop, status = 0x%x\n",
275 status);
276 break;
277 }
278#endif
236 handled = 1; 279 handled = 1;
237 /* these should probably be separated at some point, 280 if (status & VT1724_IRQ_MPU_TX) {
238 * but as we don't currently have MPU support on the board
239 * I will leave it
240 */
241 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
242 if (ice->rmidi[0]) 281 if (ice->rmidi[0])
243 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data); 282 snd_mpu401_uart_interrupt_tx(irq,
244 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT)); 283 ice->rmidi[0]->private_data);
245 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX); 284 else /* disable TX to be sure */
285 outb(inb(ICEREG1724(ice, IRQMASK)) |
286 VT1724_IRQ_MPU_TX,
287 ICEREG1724(ice, IRQMASK));
288 /* Due to mysterical reasons, MPU_TX is always
289 * generated (and can't be cleared) when a PCM
290 * playback is going. So let's ignore at the
291 * next loop.
292 */
293 status_mask &= ~VT1724_IRQ_MPU_TX;
246 } 294 }
295 if (status & VT1724_IRQ_MPU_RX) {
296 if (ice->rmidi[0])
297 snd_mpu401_uart_interrupt(irq,
298 ice->rmidi[0]->private_data);
299 else /* disable RX to be sure */
300 outb(inb(ICEREG1724(ice, IRQMASK)) |
301 VT1724_IRQ_MPU_RX,
302 ICEREG1724(ice, IRQMASK));
303 }
304 /* ack MPU irq */
305 outb(status, ICEREG1724(ice, IRQSTAT));
247 if (status & VT1724_IRQ_MTPCM) { 306 if (status & VT1724_IRQ_MTPCM) {
248 /* 307 /*
249 * Multi-track PCM 308 * Multi-track PCM
@@ -391,51 +450,61 @@ static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
391#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\ 450#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
392 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE) 451 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
393 452
394static int get_max_rate(struct snd_ice1712 *ice) 453static const unsigned int stdclock_rate_list[16] = {
454 48000, 24000, 12000, 9600, 32000, 16000, 8000, 96000, 44100,
455 22050, 11025, 88200, 176400, 0, 192000, 64000
456};
457
458static unsigned int stdclock_get_rate(struct snd_ice1712 *ice)
459{
460 unsigned int rate;
461 rate = stdclock_rate_list[inb(ICEMT1724(ice, RATE)) & 15];
462 return rate;
463}
464
465static void stdclock_set_rate(struct snd_ice1712 *ice, unsigned int rate)
395{ 466{
467 int i;
468 for (i = 0; i < ARRAY_SIZE(stdclock_rate_list); i++) {
469 if (stdclock_rate_list[i] == rate) {
470 outb(i, ICEMT1724(ice, RATE));
471 return;
472 }
473 }
474}
475
476static unsigned char stdclock_set_mclk(struct snd_ice1712 *ice,
477 unsigned int rate)
478{
479 unsigned char val, old;
480 /* check MT02 */
396 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 481 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
397 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720) 482 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
398 return 192000; 483 if (rate > 96000)
484 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
399 else 485 else
400 return 96000; 486 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
401 } else 487 if (val != old) {
402 return 48000; 488 outb(val, ICEMT1724(ice, I2S_FORMAT));
489 /* master clock changed */
490 return 1;
491 }
492 }
493 /* no change in master clock */
494 return 0;
403} 495}
404 496
405static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, 497static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
406 int force) 498 int force)
407{ 499{
408 unsigned long flags; 500 unsigned long flags;
409 unsigned char val, old; 501 unsigned char mclk_change;
410 unsigned int i, mclk_change; 502 unsigned int i, old_rate;
411 503
412 if (rate > get_max_rate(ice)) 504 if (rate > ice->hw_rates->list[ice->hw_rates->count - 1])
413 return; 505 return;
414
415 switch (rate) {
416 case 8000: val = 6; break;
417 case 9600: val = 3; break;
418 case 11025: val = 10; break;
419 case 12000: val = 2; break;
420 case 16000: val = 5; break;
421 case 22050: val = 9; break;
422 case 24000: val = 1; break;
423 case 32000: val = 4; break;
424 case 44100: val = 8; break;
425 case 48000: val = 0; break;
426 case 64000: val = 15; break;
427 case 88200: val = 11; break;
428 case 96000: val = 7; break;
429 case 176400: val = 12; break;
430 case 192000: val = 14; break;
431 default:
432 snd_BUG();
433 val = 0;
434 break;
435 }
436
437 spin_lock_irqsave(&ice->reg_lock, flags); 506 spin_lock_irqsave(&ice->reg_lock, flags);
438 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) || 507 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
439 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) { 508 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
440 /* running? we cannot change the rate now... */ 509 /* running? we cannot change the rate now... */
441 spin_unlock_irqrestore(&ice->reg_lock, flags); 510 spin_unlock_irqrestore(&ice->reg_lock, flags);
@@ -446,9 +515,9 @@ static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
446 return; 515 return;
447 } 516 }
448 517
449 old = inb(ICEMT1724(ice, RATE)); 518 old_rate = ice->get_rate(ice);
450 if (force || old != val) 519 if (force || (old_rate != rate))
451 outb(val, ICEMT1724(ice, RATE)); 520 ice->set_rate(ice, rate);
452 else if (rate == ice->cur_rate) { 521 else if (rate == ice->cur_rate) {
453 spin_unlock_irqrestore(&ice->reg_lock, flags); 522 spin_unlock_irqrestore(&ice->reg_lock, flags);
454 return; 523 return;
@@ -456,19 +525,9 @@ static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
456 525
457 ice->cur_rate = rate; 526 ice->cur_rate = rate;
458 527
459 /* check MT02 */ 528 /* setting master clock */
460 mclk_change = 0; 529 mclk_change = ice->set_mclk(ice, rate);
461 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 530
462 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
463 if (rate > 96000)
464 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
465 else
466 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
467 if (val != old) {
468 outb(val, ICEMT1724(ice, I2S_FORMAT));
469 mclk_change = 1;
470 }
471 }
472 spin_unlock_irqrestore(&ice->reg_lock, flags); 531 spin_unlock_irqrestore(&ice->reg_lock, flags);
473 532
474 if (mclk_change && ice->gpio.i2s_mclk_changed) 533 if (mclk_change && ice->gpio.i2s_mclk_changed)
@@ -727,43 +786,32 @@ static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
727/* 786/*
728 * set rate constraints 787 * set rate constraints
729 */ 788 */
730static int set_rate_constraints(struct snd_ice1712 *ice, 789static void set_std_hw_rates(struct snd_ice1712 *ice)
731 struct snd_pcm_substream *substream)
732{ 790{
733 struct snd_pcm_runtime *runtime = substream->runtime;
734 if (ice->hw_rates) {
735 /* hardware specific */
736 runtime->hw.rate_min = ice->hw_rates->list[0];
737 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
738 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
739 return snd_pcm_hw_constraint_list(runtime, 0,
740 SNDRV_PCM_HW_PARAM_RATE,
741 ice->hw_rates);
742 }
743 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 791 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
744 /* I2S */ 792 /* I2S */
745 /* VT1720 doesn't support more than 96kHz */ 793 /* VT1720 doesn't support more than 96kHz */
746 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720) 794 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
747 return snd_pcm_hw_constraint_list(runtime, 0, 795 ice->hw_rates = &hw_constraints_rates_192;
748 SNDRV_PCM_HW_PARAM_RATE, 796 else
749 &hw_constraints_rates_192); 797 ice->hw_rates = &hw_constraints_rates_96;
750 else { 798 } else {
751 runtime->hw.rates = SNDRV_PCM_RATE_KNOT |
752 SNDRV_PCM_RATE_8000_96000;
753 runtime->hw.rate_max = 96000;
754 return snd_pcm_hw_constraint_list(runtime, 0,
755 SNDRV_PCM_HW_PARAM_RATE,
756 &hw_constraints_rates_96);
757 }
758 } else if (ice->ac97) {
759 /* ACLINK */ 799 /* ACLINK */
760 runtime->hw.rate_max = 48000; 800 ice->hw_rates = &hw_constraints_rates_48;
761 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
762 return snd_pcm_hw_constraint_list(runtime, 0,
763 SNDRV_PCM_HW_PARAM_RATE,
764 &hw_constraints_rates_48);
765 } 801 }
766 return 0; 802}
803
804static int set_rate_constraints(struct snd_ice1712 *ice,
805 struct snd_pcm_substream *substream)
806{
807 struct snd_pcm_runtime *runtime = substream->runtime;
808
809 runtime->hw.rate_min = ice->hw_rates->list[0];
810 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
811 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
812 return snd_pcm_hw_constraint_list(runtime, 0,
813 SNDRV_PCM_HW_PARAM_RATE,
814 ice->hw_rates);
767} 815}
768 816
769/* multi-channel playback needs alignment 8x32bit regardless of the channels 817/* multi-channel playback needs alignment 8x32bit regardless of the channels
@@ -824,7 +872,7 @@ static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
824 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 872 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
825 873
826 if (PRO_RATE_RESET) 874 if (PRO_RATE_RESET)
827 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 875 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
828 ice->playback_pro_substream = NULL; 876 ice->playback_pro_substream = NULL;
829 877
830 return 0; 878 return 0;
@@ -835,7 +883,7 @@ static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
835 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 883 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
836 884
837 if (PRO_RATE_RESET) 885 if (PRO_RATE_RESET)
838 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 886 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
839 ice->capture_pro_substream = NULL; 887 ice->capture_pro_substream = NULL;
840 return 0; 888 return 0;
841} 889}
@@ -970,6 +1018,8 @@ static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
970 VT1724_BUFFER_ALIGN); 1018 VT1724_BUFFER_ALIGN);
971 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1019 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
972 VT1724_BUFFER_ALIGN); 1020 VT1724_BUFFER_ALIGN);
1021 if (ice->spdif.ops.open)
1022 ice->spdif.ops.open(ice, substream);
973 return 0; 1023 return 0;
974} 1024}
975 1025
@@ -978,8 +1028,10 @@ static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
978 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1028 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
979 1029
980 if (PRO_RATE_RESET) 1030 if (PRO_RATE_RESET)
981 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1031 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
982 ice->playback_con_substream = NULL; 1032 ice->playback_con_substream = NULL;
1033 if (ice->spdif.ops.close)
1034 ice->spdif.ops.close(ice, substream);
983 1035
984 return 0; 1036 return 0;
985} 1037}
@@ -1002,6 +1054,8 @@ static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
1002 VT1724_BUFFER_ALIGN); 1054 VT1724_BUFFER_ALIGN);
1003 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1055 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1004 VT1724_BUFFER_ALIGN); 1056 VT1724_BUFFER_ALIGN);
1057 if (ice->spdif.ops.open)
1058 ice->spdif.ops.open(ice, substream);
1005 return 0; 1059 return 0;
1006} 1060}
1007 1061
@@ -1010,8 +1064,10 @@ static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
1010 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1064 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1011 1065
1012 if (PRO_RATE_RESET) 1066 if (PRO_RATE_RESET)
1013 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1067 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
1014 ice->capture_con_substream = NULL; 1068 ice->capture_con_substream = NULL;
1069 if (ice->spdif.ops.close)
1070 ice->spdif.ops.close(ice, substream);
1015 1071
1016 return 0; 1072 return 0;
1017} 1073}
@@ -1154,7 +1210,7 @@ static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
1154 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1210 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1155 1211
1156 if (PRO_RATE_RESET) 1212 if (PRO_RATE_RESET)
1157 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1213 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
1158 ice->playback_con_substream_ds[substream->number] = NULL; 1214 ice->playback_con_substream_ds[substream->number] = NULL;
1159 ice->pcm_reserved[substream->number] = NULL; 1215 ice->pcm_reserved[substream->number] = NULL;
1160 1216
@@ -1572,50 +1628,18 @@ int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1572static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol, 1628static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1573 struct snd_ctl_elem_info *uinfo) 1629 struct snd_ctl_elem_info *uinfo)
1574{ 1630{
1575 static const char * const texts_1724[] = {
1576 "8000", /* 0: 6 */
1577 "9600", /* 1: 3 */
1578 "11025", /* 2: 10 */
1579 "12000", /* 3: 2 */
1580 "16000", /* 4: 5 */
1581 "22050", /* 5: 9 */
1582 "24000", /* 6: 1 */
1583 "32000", /* 7: 4 */
1584 "44100", /* 8: 8 */
1585 "48000", /* 9: 0 */
1586 "64000", /* 10: 15 */
1587 "88200", /* 11: 11 */
1588 "96000", /* 12: 7 */
1589 "176400", /* 13: 12 */
1590 "192000", /* 14: 14 */
1591 "IEC958 Input", /* 15: -- */
1592 };
1593 static const char * const texts_1720[] = {
1594 "8000", /* 0: 6 */
1595 "9600", /* 1: 3 */
1596 "11025", /* 2: 10 */
1597 "12000", /* 3: 2 */
1598 "16000", /* 4: 5 */
1599 "22050", /* 5: 9 */
1600 "24000", /* 6: 1 */
1601 "32000", /* 7: 4 */
1602 "44100", /* 8: 8 */
1603 "48000", /* 9: 0 */
1604 "64000", /* 10: 15 */
1605 "88200", /* 11: 11 */
1606 "96000", /* 12: 7 */
1607 "IEC958 Input", /* 13: -- */
1608 };
1609 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1631 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1610 1632
1611 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1633 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1612 uinfo->count = 1; 1634 uinfo->count = 1;
1613 uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16; 1635 uinfo->value.enumerated.items = ice->hw_rates->count + 1;
1614 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1636 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1615 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1637 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1616 strcpy(uinfo->value.enumerated.name, 1638 if (uinfo->value.enumerated.item == uinfo->value.enumerated.items - 1)
1617 ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] : 1639 strcpy(uinfo->value.enumerated.name, "IEC958 Input");
1618 texts_1724[uinfo->value.enumerated.item]); 1640 else
1641 sprintf(uinfo->value.enumerated.name, "%d",
1642 ice->hw_rates->list[uinfo->value.enumerated.item]);
1619 return 0; 1643 return 0;
1620} 1644}
1621 1645
@@ -1623,68 +1647,79 @@ static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1623 struct snd_ctl_elem_value *ucontrol) 1647 struct snd_ctl_elem_value *ucontrol)
1624{ 1648{
1625 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1649 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1626 static const unsigned char xlate[16] = { 1650 unsigned int i, rate;
1627 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1628 };
1629 unsigned char val;
1630 1651
1631 spin_lock_irq(&ice->reg_lock); 1652 spin_lock_irq(&ice->reg_lock);
1632 if (is_spdif_master(ice)) { 1653 if (ice->is_spdif_master(ice)) {
1633 ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15; 1654 ucontrol->value.enumerated.item[0] = ice->hw_rates->count;
1634 } else { 1655 } else {
1635 val = xlate[inb(ICEMT1724(ice, RATE)) & 15]; 1656 rate = ice->get_rate(ice);
1636 if (val == 255) { 1657 ucontrol->value.enumerated.item[0] = 0;
1637 snd_BUG(); 1658 for (i = 0; i < ice->hw_rates->count; i++) {
1638 val = 0; 1659 if (ice->hw_rates->list[i] == rate) {
1660 ucontrol->value.enumerated.item[0] = i;
1661 break;
1662 }
1639 } 1663 }
1640 ucontrol->value.enumerated.item[0] = val;
1641 } 1664 }
1642 spin_unlock_irq(&ice->reg_lock); 1665 spin_unlock_irq(&ice->reg_lock);
1643 return 0; 1666 return 0;
1644} 1667}
1645 1668
1669/* setting clock to external - SPDIF */
1670static void stdclock_set_spdif_clock(struct snd_ice1712 *ice)
1671{
1672 unsigned char oval;
1673 unsigned char i2s_oval;
1674 oval = inb(ICEMT1724(ice, RATE));
1675 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1676 /* setting 256fs */
1677 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1678 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT));
1679}
1680
1646static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol, 1681static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_value *ucontrol) 1682 struct snd_ctl_elem_value *ucontrol)
1648{ 1683{
1649 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1684 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1650 unsigned char oval; 1685 unsigned int old_rate, new_rate;
1651 int rate; 1686 unsigned int item = ucontrol->value.enumerated.item[0];
1652 int change = 0; 1687 unsigned int spdif = ice->hw_rates->count;
1653 int spdif = ice->vt1720 ? 13 : 15; 1688
1689 if (item > spdif)
1690 return -EINVAL;
1654 1691
1655 spin_lock_irq(&ice->reg_lock); 1692 spin_lock_irq(&ice->reg_lock);
1656 oval = inb(ICEMT1724(ice, RATE)); 1693 if (ice->is_spdif_master(ice))
1657 if (ucontrol->value.enumerated.item[0] == spdif) { 1694 old_rate = 0;
1658 unsigned char i2s_oval; 1695 else
1659 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE)); 1696 old_rate = ice->get_rate(ice);
1660 /* setting 256fs */ 1697 if (item == spdif) {
1661 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT)); 1698 /* switching to external clock via SPDIF */
1662 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, 1699 ice->set_spdif_clock(ice);
1663 ICEMT1724(ice, I2S_FORMAT)); 1700 new_rate = 0;
1664 } else { 1701 } else {
1665 rate = rates[ucontrol->value.integer.value[0] % 15]; 1702 /* internal on-card clock */
1666 if (rate <= get_max_rate(ice)) { 1703 new_rate = ice->hw_rates->list[item];
1667 PRO_RATE_DEFAULT = rate; 1704 ice->pro_rate_default = new_rate;
1668 spin_unlock_irq(&ice->reg_lock); 1705 spin_unlock_irq(&ice->reg_lock);
1669 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1); 1706 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
1670 spin_lock_irq(&ice->reg_lock); 1707 spin_lock_irq(&ice->reg_lock);
1671 }
1672 } 1708 }
1673 change = inb(ICEMT1724(ice, RATE)) != oval;
1674 spin_unlock_irq(&ice->reg_lock); 1709 spin_unlock_irq(&ice->reg_lock);
1675 1710
1676 if ((oval & VT1724_SPDIF_MASTER) != 1711 /* the first reset to the SPDIF master mode? */
1677 (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) { 1712 if (old_rate != new_rate && !new_rate) {
1678 /* notify akm chips as well */ 1713 /* notify akm chips as well */
1679 if (is_spdif_master(ice)) { 1714 unsigned int i;
1680 unsigned int i; 1715 if (ice->gpio.set_pro_rate)
1681 for (i = 0; i < ice->akm_codecs; i++) { 1716 ice->gpio.set_pro_rate(ice, 0);
1682 if (ice->akm[i].ops.set_rate_val) 1717 for (i = 0; i < ice->akm_codecs; i++) {
1683 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0); 1718 if (ice->akm[i].ops.set_rate_val)
1684 } 1719 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1685 } 1720 }
1686 } 1721 }
1687 return change; 1722 return old_rate != new_rate;
1688} 1723}
1689 1724
1690static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = { 1725static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
@@ -2065,12 +2100,16 @@ static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2065 2100
2066 2101
2067 2102
2068static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice) 2103static void __devinit snd_vt1724_chip_reset(struct snd_ice1712 *ice)
2069{ 2104{
2070 outb(VT1724_RESET , ICEREG1724(ice, CONTROL)); 2105 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
2071 udelay(200); 2106 msleep(10);
2072 outb(0, ICEREG1724(ice, CONTROL)); 2107 outb(0, ICEREG1724(ice, CONTROL));
2073 udelay(200); 2108 msleep(10);
2109}
2110
2111static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
2112{
2074 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG)); 2113 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2075 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG)); 2114 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
2076 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES)); 2115 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
@@ -2169,10 +2208,8 @@ static int snd_vt1724_free(struct snd_ice1712 *ice)
2169 outb(0xff, ICEREG1724(ice, IRQMASK)); 2208 outb(0xff, ICEREG1724(ice, IRQMASK));
2170 /* --- */ 2209 /* --- */
2171 __hw_end: 2210 __hw_end:
2172 if (ice->irq >= 0) { 2211 if (ice->irq >= 0)
2173 synchronize_irq(ice->irq);
2174 free_irq(ice->irq, ice); 2212 free_irq(ice->irq, ice);
2175 }
2176 pci_release_regions(ice->pci); 2213 pci_release_regions(ice->pci);
2177 snd_ice1712_akm4xxx_free(ice); 2214 snd_ice1712_akm4xxx_free(ice);
2178 pci_disable_device(ice->pci); 2215 pci_disable_device(ice->pci);
@@ -2243,6 +2280,7 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2243 2280
2244 ice->irq = pci->irq; 2281 ice->irq = pci->irq;
2245 2282
2283 snd_vt1724_chip_reset(ice);
2246 if (snd_vt1724_read_eeprom(ice, modelname) < 0) { 2284 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2247 snd_vt1724_free(ice); 2285 snd_vt1724_free(ice);
2248 return -EIO; 2286 return -EIO;
@@ -2253,10 +2291,7 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2253 } 2291 }
2254 2292
2255 /* unmask used interrupts */ 2293 /* unmask used interrupts */
2256 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401)) 2294 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2257 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2258 else
2259 mask = 0;
2260 outb(mask, ICEREG1724(ice, IRQMASK)); 2295 outb(mask, ICEREG1724(ice, IRQMASK));
2261 /* don't handle FIFO overrun/underruns (just yet), 2296 /* don't handle FIFO overrun/underruns (just yet),
2262 * since they cause machine lockups 2297 * since they cause machine lockups
@@ -2335,6 +2370,19 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2335 * was called so in ice1712 driver, and vt1724 driver is derived from 2370 * was called so in ice1712 driver, and vt1724 driver is derived from
2336 * ice1712 driver. 2371 * ice1712 driver.
2337 */ 2372 */
2373 ice->pro_rate_default = PRO_RATE_DEFAULT;
2374 if (!ice->is_spdif_master)
2375 ice->is_spdif_master = stdclock_is_spdif_master;
2376 if (!ice->get_rate)
2377 ice->get_rate = stdclock_get_rate;
2378 if (!ice->set_rate)
2379 ice->set_rate = stdclock_set_rate;
2380 if (!ice->set_mclk)
2381 ice->set_mclk = stdclock_set_mclk;
2382 if (!ice->set_spdif_clock)
2383 ice->set_spdif_clock = stdclock_set_spdif_clock;
2384 if (!ice->hw_rates)
2385 set_std_hw_rates(ice);
2338 2386
2339 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) { 2387 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2340 snd_card_free(card); 2388 snd_card_free(card);
@@ -2377,14 +2425,28 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2377 2425
2378 if (! c->no_mpu401) { 2426 if (! c->no_mpu401) {
2379 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) { 2427 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2428 struct snd_mpu401 *mpu;
2380 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712, 2429 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2381 ICEREG1724(ice, MPU_CTRL), 2430 ICEREG1724(ice, MPU_CTRL),
2382 MPU401_INFO_INTEGRATED, 2431 (MPU401_INFO_INTEGRATED |
2432 MPU401_INFO_NO_ACK |
2433 MPU401_INFO_TX_IRQ),
2383 ice->irq, 0, 2434 ice->irq, 0,
2384 &ice->rmidi[0])) < 0) { 2435 &ice->rmidi[0])) < 0) {
2385 snd_card_free(card); 2436 snd_card_free(card);
2386 return err; 2437 return err;
2387 } 2438 }
2439 mpu = ice->rmidi[0]->private_data;
2440 mpu->read = snd_vt1724_mpu401_read;
2441 mpu->write = snd_vt1724_mpu401_write;
2442 /* unmask MPU RX/TX irqs */
2443 outb(inb(ICEREG1724(ice, IRQMASK)) &
2444 ~(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX),
2445 ICEREG1724(ice, IRQMASK));
2446 /* set watermarks */
2447 outb(VT1724_MPU_RX_FIFO | 0x1,
2448 ICEREG1724(ice, MPU_FIFO_WM));
2449 outb(0x1, ICEREG1724(ice, MPU_FIFO_WM));
2388 } 2450 }
2389 } 2451 }
2390 2452
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index e8038c0ceb72..b4e0c16852a6 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -4,6 +4,8 @@
4 * Lowlevel functions for ESI Juli@ cards 4 * Lowlevel functions for ESI Juli@ cards
5 * 5 *
6 * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz> 6 * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz>
7 * 2008 Pavel Hofman <dustin@seznam.cz>
8 *
7 * 9 *
8 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
@@ -27,11 +29,11 @@
27#include <linux/init.h> 29#include <linux/init.h>
28#include <linux/slab.h> 30#include <linux/slab.h>
29#include <sound/core.h> 31#include <sound/core.h>
32#include <sound/tlv.h>
30 33
31#include "ice1712.h" 34#include "ice1712.h"
32#include "envy24ht.h" 35#include "envy24ht.h"
33#include "juli.h" 36#include "juli.h"
34
35struct juli_spec { 37struct juli_spec {
36 struct ak4114 *ak4114; 38 struct ak4114 *ak4114;
37 unsigned int analog: 1; 39 unsigned int analog: 1;
@@ -44,6 +46,32 @@ struct juli_spec {
44#define AK4358_ADDR 0x22 /* DAC */ 46#define AK4358_ADDR 0x22 /* DAC */
45 47
46/* 48/*
49 * Juli does not use the standard ICE1724 clock scheme. Juli's ice1724 chip is
50 * supplied by external clock provided by Xilinx array and MK73-1 PLL frequency
51 * multiplier. Actual frequency is set by ice1724 GPIOs hooked to the Xilinx.
52 *
53 * The clock circuitry is supplied by the two ice1724 crystals. This
54 * arrangement allows to generate independent clock signal for AK4114's input
55 * rate detection circuit. As a result, Juli, unlike most other
56 * ice1724+ak4114-based cards, detects spdif input rate correctly.
57 * This fact is applied in the driver, allowing to modify PCM stream rate
58 * parameter according to the actual input rate.
59 *
60 * Juli uses the remaining three stereo-channels of its DAC to optionally
61 * monitor analog input, digital input, and digital output. The corresponding
62 * I2S signals are routed by Xilinx, controlled by GPIOs.
63 *
64 * The master mute is implemented using output muting transistors (GPIO) in
65 * combination with smuting the DAC.
66 *
67 * The card itself has no HW master volume control, implemented using the
68 * vmaster control.
69 *
70 * TODO:
71 * researching and fixing the input monitors
72 */
73
74/*
47 * GPIO pins 75 * GPIO pins
48 */ 76 */
49#define GPIO_FREQ_MASK (3<<0) 77#define GPIO_FREQ_MASK (3<<0)
@@ -55,17 +83,82 @@ struct juli_spec {
55#define GPIO_MULTI_2X (1<<2) 83#define GPIO_MULTI_2X (1<<2)
56#define GPIO_MULTI_1X (2<<2) /* also external */ 84#define GPIO_MULTI_1X (2<<2) /* also external */
57#define GPIO_MULTI_HALF (3<<2) 85#define GPIO_MULTI_HALF (3<<2)
58#define GPIO_INTERNAL_CLOCK (1<<4) 86#define GPIO_INTERNAL_CLOCK (1<<4) /* 0 = external, 1 = internal */
87#define GPIO_CLOCK_MASK (1<<4)
59#define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */ 88#define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */
60#define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */ 89#define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */
61#define GPIO_AK5385A_CKS0 (1<<8) 90#define GPIO_AK5385A_CKS0 (1<<8)
62#define GPIO_AK5385A_DFS0 (1<<9) /* swapped with DFS1 according doc? */ 91#define GPIO_AK5385A_DFS1 (1<<9)
63#define GPIO_AK5385A_DFS1 (1<<10) 92#define GPIO_AK5385A_DFS0 (1<<10)
64#define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */ 93#define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */
65#define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */ 94#define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */
66#define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */ 95#define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */
67#define GPIO_AK5385A_MCLK (1<<14) /* must be 0 */ 96#define GPIO_AK5385A_CKS1 (1<<14) /* must be 0 */
68#define GPIO_MUTE_CONTROL (1<<15) /* 0 = off, 1 = on */ 97#define GPIO_MUTE_CONTROL (1<<15) /* output mute, 1 = muted */
98
99#define GPIO_RATE_MASK (GPIO_FREQ_MASK | GPIO_MULTI_MASK | \
100 GPIO_CLOCK_MASK)
101#define GPIO_AK5385A_MASK (GPIO_AK5385A_CKS0 | GPIO_AK5385A_DFS0 | \
102 GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS1)
103
104#define JULI_PCM_RATE (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
105 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
106 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
107 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
108 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
109
110#define GPIO_RATE_16000 (GPIO_FREQ_32KHZ | GPIO_MULTI_HALF | \
111 GPIO_INTERNAL_CLOCK)
112#define GPIO_RATE_22050 (GPIO_FREQ_44KHZ | GPIO_MULTI_HALF | \
113 GPIO_INTERNAL_CLOCK)
114#define GPIO_RATE_24000 (GPIO_FREQ_48KHZ | GPIO_MULTI_HALF | \
115 GPIO_INTERNAL_CLOCK)
116#define GPIO_RATE_32000 (GPIO_FREQ_32KHZ | GPIO_MULTI_1X | \
117 GPIO_INTERNAL_CLOCK)
118#define GPIO_RATE_44100 (GPIO_FREQ_44KHZ | GPIO_MULTI_1X | \
119 GPIO_INTERNAL_CLOCK)
120#define GPIO_RATE_48000 (GPIO_FREQ_48KHZ | GPIO_MULTI_1X | \
121 GPIO_INTERNAL_CLOCK)
122#define GPIO_RATE_64000 (GPIO_FREQ_32KHZ | GPIO_MULTI_2X | \
123 GPIO_INTERNAL_CLOCK)
124#define GPIO_RATE_88200 (GPIO_FREQ_44KHZ | GPIO_MULTI_2X | \
125 GPIO_INTERNAL_CLOCK)
126#define GPIO_RATE_96000 (GPIO_FREQ_48KHZ | GPIO_MULTI_2X | \
127 GPIO_INTERNAL_CLOCK)
128#define GPIO_RATE_176400 (GPIO_FREQ_44KHZ | GPIO_MULTI_4X | \
129 GPIO_INTERNAL_CLOCK)
130#define GPIO_RATE_192000 (GPIO_FREQ_48KHZ | GPIO_MULTI_4X | \
131 GPIO_INTERNAL_CLOCK)
132
133/*
134 * Initial setup of the conversion array GPIO <-> rate
135 */
136static unsigned int juli_rates[] = {
137 16000, 22050, 24000, 32000,
138 44100, 48000, 64000, 88200,
139 96000, 176400, 192000,
140};
141
142static unsigned int gpio_vals[] = {
143 GPIO_RATE_16000, GPIO_RATE_22050, GPIO_RATE_24000, GPIO_RATE_32000,
144 GPIO_RATE_44100, GPIO_RATE_48000, GPIO_RATE_64000, GPIO_RATE_88200,
145 GPIO_RATE_96000, GPIO_RATE_176400, GPIO_RATE_192000,
146};
147
148static struct snd_pcm_hw_constraint_list juli_rates_info = {
149 .count = ARRAY_SIZE(juli_rates),
150 .list = juli_rates,
151 .mask = 0,
152};
153
154static int get_gpio_val(int rate)
155{
156 int i;
157 for (i = 0; i < ARRAY_SIZE(juli_rates); i++)
158 if (juli_rates[i] == rate)
159 return gpio_vals[i];
160 return 0;
161}
69 162
70static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val) 163static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val)
71{ 164{
@@ -78,6 +171,27 @@ static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
78} 171}
79 172
80/* 173/*
174 * If SPDIF capture and slaved to SPDIF-IN, setting runtime rate
175 * to the external rate
176 */
177static void juli_spdif_in_open(struct snd_ice1712 *ice,
178 struct snd_pcm_substream *substream)
179{
180 struct juli_spec *spec = ice->spec;
181 struct snd_pcm_runtime *runtime = substream->runtime;
182 int rate;
183
184 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
185 !ice->is_spdif_master(ice))
186 return;
187 rate = snd_ak4114_external_rate(spec->ak4114);
188 if (rate >= runtime->hw.rate_min && rate <= runtime->hw.rate_max) {
189 runtime->hw.rate_min = rate;
190 runtime->hw.rate_max = rate;
191 }
192}
193
194/*
81 * AK4358 section 195 * AK4358 section
82 */ 196 */
83 197
@@ -99,57 +213,285 @@ static void juli_akm_write(struct snd_akm4xxx *ak, int chip,
99} 213}
100 214
101/* 215/*
102 * change the rate of envy24HT, AK4358 216 * change the rate of envy24HT, AK4358, AK5385
103 */ 217 */
104static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 218static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
105{ 219{
106 unsigned char old, tmp, dfs; 220 unsigned char old, tmp, ak4358_dfs;
221 unsigned int ak5385_pins, old_gpio, new_gpio;
222 struct snd_ice1712 *ice = ak->private_data[0];
223 struct juli_spec *spec = ice->spec;
107 224
108 if (rate == 0) /* no hint - S/PDIF input is master, simply return */ 225 if (rate == 0) /* no hint - S/PDIF input is master or the new spdif
226 input rate undetected, simply return */
109 return; 227 return;
110 228
111 /* adjust DFS on codecs */ 229 /* adjust DFS on codecs */
112 if (rate > 96000) 230 if (rate > 96000) {
113 dfs = 2; 231 ak4358_dfs = 2;
114 else if (rate > 48000) 232 ak5385_pins = GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS0;
115 dfs = 1; 233 } else if (rate > 48000) {
116 else 234 ak4358_dfs = 1;
117 dfs = 0; 235 ak5385_pins = GPIO_AK5385A_DFS0;
118 236 } else {
237 ak4358_dfs = 0;
238 ak5385_pins = 0;
239 }
240 /* AK5385 first, since it requires cold reset affecting both codecs */
241 old_gpio = ice->gpio.get_data(ice);
242 new_gpio = (old_gpio & ~GPIO_AK5385A_MASK) | ak5385_pins;
243 /* printk(KERN_DEBUG "JULI - ak5385 set_rate_val: new gpio 0x%x\n",
244 new_gpio); */
245 ice->gpio.set_data(ice, new_gpio);
246
247 /* cold reset */
248 old = inb(ICEMT1724(ice, AC97_CMD));
249 outb(old | VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
250 udelay(1);
251 outb(old & ~VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
252
253 /* AK4358 */
254 /* set new value, reset DFS */
119 tmp = snd_akm4xxx_get(ak, 0, 2); 255 tmp = snd_akm4xxx_get(ak, 0, 2);
120 old = (tmp >> 4) & 0x03;
121 if (old == dfs)
122 return;
123 /* reset DFS */
124 snd_akm4xxx_reset(ak, 1); 256 snd_akm4xxx_reset(ak, 1);
125 tmp = snd_akm4xxx_get(ak, 0, 2); 257 tmp = snd_akm4xxx_get(ak, 0, 2);
126 tmp &= ~(0x03 << 4); 258 tmp &= ~(0x03 << 4);
127 tmp |= dfs << 4; 259 tmp |= ak4358_dfs << 4;
128 snd_akm4xxx_set(ak, 0, 2, tmp); 260 snd_akm4xxx_set(ak, 0, 2, tmp);
129 snd_akm4xxx_reset(ak, 0); 261 snd_akm4xxx_reset(ak, 0);
262
263 /* reinit ak4114 */
264 snd_ak4114_reinit(spec->ak4114);
130} 265}
131 266
267#define AK_DAC(xname, xch) { .name = xname, .num_channels = xch }
268#define PCM_VOLUME "PCM Playback Volume"
269#define MONITOR_AN_IN_VOLUME "Monitor Analog In Volume"
270#define MONITOR_DIG_IN_VOLUME "Monitor Digital In Volume"
271#define MONITOR_DIG_OUT_VOLUME "Monitor Digital Out Volume"
272
273static const struct snd_akm4xxx_dac_channel juli_dac[] = {
274 AK_DAC(PCM_VOLUME, 2),
275 AK_DAC(MONITOR_AN_IN_VOLUME, 2),
276 AK_DAC(MONITOR_DIG_OUT_VOLUME, 2),
277 AK_DAC(MONITOR_DIG_IN_VOLUME, 2),
278};
279
280
132static struct snd_akm4xxx akm_juli_dac __devinitdata = { 281static struct snd_akm4xxx akm_juli_dac __devinitdata = {
133 .type = SND_AK4358, 282 .type = SND_AK4358,
134 .num_dacs = 2, 283 .num_dacs = 8, /* DAC1 - analog out
284 DAC2 - analog in monitor
285 DAC3 - digital out monitor
286 DAC4 - digital in monitor
287 */
135 .ops = { 288 .ops = {
136 .lock = juli_akm_lock, 289 .lock = juli_akm_lock,
137 .unlock = juli_akm_unlock, 290 .unlock = juli_akm_unlock,
138 .write = juli_akm_write, 291 .write = juli_akm_write,
139 .set_rate_val = juli_akm_set_rate_val 292 .set_rate_val = juli_akm_set_rate_val
293 },
294 .dac_info = juli_dac,
295};
296
297#define juli_mute_info snd_ctl_boolean_mono_info
298
299static int juli_mute_get(struct snd_kcontrol *kcontrol,
300 struct snd_ctl_elem_value *ucontrol)
301{
302 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
303 unsigned int val;
304 val = ice->gpio.get_data(ice) & (unsigned int) kcontrol->private_value;
305 if (kcontrol->private_value == GPIO_MUTE_CONTROL)
306 /* val 0 = signal on */
307 ucontrol->value.integer.value[0] = (val) ? 0 : 1;
308 else
309 /* val 1 = signal on */
310 ucontrol->value.integer.value[0] = (val) ? 1 : 0;
311 return 0;
312}
313
314static int juli_mute_put(struct snd_kcontrol *kcontrol,
315 struct snd_ctl_elem_value *ucontrol)
316{
317 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
318 unsigned int old_gpio, new_gpio;
319 old_gpio = ice->gpio.get_data(ice);
320 if (ucontrol->value.integer.value[0]) {
321 /* unmute */
322 if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
323 /* 0 = signal on */
324 new_gpio = old_gpio & ~GPIO_MUTE_CONTROL;
325 /* un-smuting DAC */
326 snd_akm4xxx_write(ice->akm, 0, 0x01, 0x01);
327 } else
328 /* 1 = signal on */
329 new_gpio = old_gpio |
330 (unsigned int) kcontrol->private_value;
331 } else {
332 /* mute */
333 if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
334 /* 1 = signal off */
335 new_gpio = old_gpio | GPIO_MUTE_CONTROL;
336 /* smuting DAC */
337 snd_akm4xxx_write(ice->akm, 0, 0x01, 0x03);
338 } else
339 /* 0 = signal off */
340 new_gpio = old_gpio &
341 ~((unsigned int) kcontrol->private_value);
342 }
343 /* printk("JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, \
344 new_gpio 0x%x\n",
345 (unsigned int)ucontrol->value.integer.value[0], old_gpio,
346 new_gpio); */
347 if (old_gpio != new_gpio) {
348 ice->gpio.set_data(ice, new_gpio);
349 return 1;
350 }
351 /* no change */
352 return 0;
353}
354
355static struct snd_kcontrol_new juli_mute_controls[] __devinitdata = {
356 {
357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358 .name = "Master Playback Switch",
359 .info = juli_mute_info,
360 .get = juli_mute_get,
361 .put = juli_mute_put,
362 .private_value = GPIO_MUTE_CONTROL,
363 },
364 /* Although the following functionality respects the succint NDA'd
365 * documentation from the card manufacturer, and the same way of
366 * operation is coded in OSS Juli driver, only Digital Out monitor
367 * seems to work. Surprisingly, Analog input monitor outputs Digital
368 * output data. The two are independent, as enabling both doubles
369 * volume of the monitor sound.
370 *
371 * Checking traces on the board suggests the functionality described
372 * by the manufacturer is correct - I2S from ADC and AK4114
373 * go to ICE as well as to Xilinx, I2S inputs of DAC2,3,4 (the monitor
374 * inputs) are fed from Xilinx.
375 *
376 * I even checked traces on board and coded a support in driver for
377 * an alternative possiblity - the unused I2S ICE output channels
378 * switched to HW-IN/SPDIF-IN and providing the monitoring signal to
379 * the DAC - to no avail. The I2S outputs seem to be unconnected.
380 *
381 * The windows driver supports the monitoring correctly.
382 */
383 {
384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
385 .name = "Monitor Analog In Switch",
386 .info = juli_mute_info,
387 .get = juli_mute_get,
388 .put = juli_mute_put,
389 .private_value = GPIO_ANAIN_MONITOR,
390 },
391 {
392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
393 .name = "Monitor Digital Out Switch",
394 .info = juli_mute_info,
395 .get = juli_mute_get,
396 .put = juli_mute_put,
397 .private_value = GPIO_DIGOUT_MONITOR,
398 },
399 {
400 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
401 .name = "Monitor Digital In Switch",
402 .info = juli_mute_info,
403 .get = juli_mute_get,
404 .put = juli_mute_put,
405 .private_value = GPIO_DIGIN_MONITOR,
406 },
407};
408
409
410static void ak4358_proc_regs_read(struct snd_info_entry *entry,
411 struct snd_info_buffer *buffer)
412{
413 struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
414 int reg, val;
415 for (reg = 0; reg <= 0xf; reg++) {
416 val = snd_akm4xxx_get(ice->akm, 0, reg);
417 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
140 } 418 }
419}
420
421static void ak4358_proc_init(struct snd_ice1712 *ice)
422{
423 struct snd_info_entry *entry;
424 if (!snd_card_proc_new(ice->card, "ak4358_codec", &entry))
425 snd_info_set_text_ops(entry, ice, ak4358_proc_regs_read);
426}
427
428static char *slave_vols[] __devinitdata = {
429 PCM_VOLUME,
430 MONITOR_AN_IN_VOLUME,
431 MONITOR_DIG_IN_VOLUME,
432 MONITOR_DIG_OUT_VOLUME,
433 NULL
141}; 434};
142 435
436static __devinitdata
437DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1);
438
439static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card,
440 const char *name)
441{
442 struct snd_ctl_elem_id sid;
443 memset(&sid, 0, sizeof(sid));
444 /* FIXME: strcpy is bad. */
445 strcpy(sid.name, name);
446 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
447 return snd_ctl_find_id(card, &sid);
448}
449
450static void __devinit add_slaves(struct snd_card *card,
451 struct snd_kcontrol *master, char **list)
452{
453 for (; *list; list++) {
454 struct snd_kcontrol *slave = ctl_find(card, *list);
455 /* printk(KERN_DEBUG "add_slaves - %s\n", *list); */
456 if (slave) {
457 /* printk(KERN_DEBUG "slave %s found\n", *list); */
458 snd_ctl_add_slave(master, slave);
459 }
460 }
461}
462
143static int __devinit juli_add_controls(struct snd_ice1712 *ice) 463static int __devinit juli_add_controls(struct snd_ice1712 *ice)
144{ 464{
145 struct juli_spec *spec = ice->spec; 465 struct juli_spec *spec = ice->spec;
146 int err; 466 int err;
467 unsigned int i;
468 struct snd_kcontrol *vmaster;
469
147 err = snd_ice1712_akm4xxx_build_controls(ice); 470 err = snd_ice1712_akm4xxx_build_controls(ice);
148 if (err < 0) 471 if (err < 0)
149 return err; 472 return err;
473
474 for (i = 0; i < ARRAY_SIZE(juli_mute_controls); i++) {
475 err = snd_ctl_add(ice->card,
476 snd_ctl_new1(&juli_mute_controls[i], ice));
477 if (err < 0)
478 return err;
479 }
480 /* Create virtual master control */
481 vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
482 juli_master_db_scale);
483 if (!vmaster)
484 return -ENOMEM;
485 add_slaves(ice->card, vmaster, slave_vols);
486 err = snd_ctl_add(ice->card, vmaster);
487 if (err < 0)
488 return err;
489
150 /* only capture SPDIF over AK4114 */ 490 /* only capture SPDIF over AK4114 */
151 err = snd_ak4114_build(spec->ak4114, NULL, 491 err = snd_ak4114_build(spec->ak4114, NULL,
152 ice->pcm_pro->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 492 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
493
494 ak4358_proc_init(ice);
153 if (err < 0) 495 if (err < 0)
154 return err; 496 return err;
155 return 0; 497 return 0;
@@ -158,6 +500,74 @@ static int __devinit juli_add_controls(struct snd_ice1712 *ice)
158/* 500/*
159 * initialize the chip 501 * initialize the chip
160 */ 502 */
503
504static inline int juli_is_spdif_master(struct snd_ice1712 *ice)
505{
506 return (ice->gpio.get_data(ice) & GPIO_INTERNAL_CLOCK) ? 0 : 1;
507}
508
509static unsigned int juli_get_rate(struct snd_ice1712 *ice)
510{
511 int i;
512 unsigned char result;
513
514 result = ice->gpio.get_data(ice) & GPIO_RATE_MASK;
515 for (i = 0; i < ARRAY_SIZE(gpio_vals); i++)
516 if (gpio_vals[i] == result)
517 return juli_rates[i];
518 return 0;
519}
520
521/* setting new rate */
522static void juli_set_rate(struct snd_ice1712 *ice, unsigned int rate)
523{
524 unsigned int old, new;
525 unsigned char val;
526
527 old = ice->gpio.get_data(ice);
528 new = (old & ~GPIO_RATE_MASK) | get_gpio_val(rate);
529 /* printk(KERN_DEBUG "JULI - set_rate: old %x, new %x\n",
530 old & GPIO_RATE_MASK,
531 new & GPIO_RATE_MASK); */
532
533 ice->gpio.set_data(ice, new);
534 /* switching to external clock - supplied by external circuits */
535 val = inb(ICEMT1724(ice, RATE));
536 outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
537}
538
539static inline unsigned char juli_set_mclk(struct snd_ice1712 *ice,
540 unsigned int rate)
541{
542 /* no change in master clock */
543 return 0;
544}
545
546/* setting clock to external - SPDIF */
547static void juli_set_spdif_clock(struct snd_ice1712 *ice)
548{
549 unsigned int old;
550 old = ice->gpio.get_data(ice);
551 /* external clock (= 0), multiply 1x, 48kHz */
552 ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X |
553 GPIO_FREQ_48KHZ);
554}
555
556/* Called when ak4114 detects change in the input SPDIF stream */
557static void juli_ak4114_change(struct ak4114 *ak4114, unsigned char c0,
558 unsigned char c1)
559{
560 struct snd_ice1712 *ice = ak4114->change_callback_private;
561 int rate;
562 if (ice->is_spdif_master(ice) && c1) {
563 /* only for SPDIF master mode, rate was changed */
564 rate = snd_ak4114_external_rate(ak4114);
565 /* printk(KERN_DEBUG "ak4114 - input rate changed to %d\n",
566 rate); */
567 juli_akm_set_rate_val(ice->akm, rate);
568 }
569}
570
161static int __devinit juli_init(struct snd_ice1712 *ice) 571static int __devinit juli_init(struct snd_ice1712 *ice)
162{ 572{
163 static const unsigned char ak4114_init_vals[] = { 573 static const unsigned char ak4114_init_vals[] = {
@@ -187,6 +597,11 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
187 ice, &spec->ak4114); 597 ice, &spec->ak4114);
188 if (err < 0) 598 if (err < 0)
189 return err; 599 return err;
600 /* callback for codecs rate setting */
601 spec->ak4114->change_callback = juli_ak4114_change;
602 spec->ak4114->change_callback_private = ice;
603 /* AK4114 in Juli can detect external rate correctly */
604 spec->ak4114->check_flags = 0;
190 605
191#if 0 606#if 0
192 /* it seems that the analog doughter board detection does not work 607 /* it seems that the analog doughter board detection does not work
@@ -210,6 +625,15 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
210 return err; 625 return err;
211 } 626 }
212 627
628 /* juli is clocked by Xilinx array */
629 ice->hw_rates = &juli_rates_info;
630 ice->is_spdif_master = juli_is_spdif_master;
631 ice->get_rate = juli_get_rate;
632 ice->set_rate = juli_set_rate;
633 ice->set_mclk = juli_set_mclk;
634 ice->set_spdif_clock = juli_set_spdif_clock;
635
636 ice->spdif.ops.open = juli_spdif_in_open;
213 return 0; 637 return 0;
214} 638}
215 639
@@ -220,18 +644,20 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
220 */ 644 */
221 645
222static unsigned char juli_eeprom[] __devinitdata = { 646static unsigned char juli_eeprom[] __devinitdata = {
223 [ICE_EEP2_SYSCONF] = 0x20, /* clock 512, mpu401, 1xADC, 1xDACs */ 647 [ICE_EEP2_SYSCONF] = 0x2b, /* clock 512, mpu401, 1xADC, 1xDACs,
648 SPDIF in */
224 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 649 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
225 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */ 650 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
226 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ 651 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
227 [ICE_EEP2_GPIO_DIR] = 0x9f, 652 [ICE_EEP2_GPIO_DIR] = 0x9f, /* 5, 6:inputs; 7, 4-0 outputs*/
228 [ICE_EEP2_GPIO_DIR1] = 0xff, 653 [ICE_EEP2_GPIO_DIR1] = 0xff,
229 [ICE_EEP2_GPIO_DIR2] = 0x7f, 654 [ICE_EEP2_GPIO_DIR2] = 0x7f,
230 [ICE_EEP2_GPIO_MASK] = 0x9f, 655 [ICE_EEP2_GPIO_MASK] = 0x60, /* 5, 6: locked; 7, 4-0 writable */
231 [ICE_EEP2_GPIO_MASK1] = 0xff, 656 [ICE_EEP2_GPIO_MASK1] = 0x00, /* 0-7 writable */
232 [ICE_EEP2_GPIO_MASK2] = 0x7f, 657 [ICE_EEP2_GPIO_MASK2] = 0x7f,
233 [ICE_EEP2_GPIO_STATE] = 0x16, /* internal clock, multiple 1x, 48kHz */ 658 [ICE_EEP2_GPIO_STATE] = GPIO_FREQ_48KHZ | GPIO_MULTI_1X |
234 [ICE_EEP2_GPIO_STATE1] = 0x80, /* mute */ 659 GPIO_INTERNAL_CLOCK, /* internal clock, multiple 1x, 48kHz*/
660 [ICE_EEP2_GPIO_STATE1] = 0x00, /* unmuted */
235 [ICE_EEP2_GPIO_STATE2] = 0x00, 661 [ICE_EEP2_GPIO_STATE2] = 0x00,
236}; 662};
237 663
diff --git a/sound/pci/ice1712/pontis.c b/sound/pci/ice1712/pontis.c
index 4945c81e8a96..203cdc1bf8da 100644
--- a/sound/pci/ice1712/pontis.c
+++ b/sound/pci/ice1712/pontis.c
@@ -246,7 +246,7 @@ static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
246 wm_put(ice, WM_ADC_MUX, nval); 246 wm_put(ice, WM_ADC_MUX, nval);
247 } 247 }
248 mutex_unlock(&ice->gpio_mutex); 248 mutex_unlock(&ice->gpio_mutex);
249 return 0; 249 return change;
250} 250}
251 251
252/* 252/*
@@ -450,7 +450,7 @@ static int cs_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
450 change = 1; 450 change = 1;
451 } 451 }
452 mutex_unlock(&ice->gpio_mutex); 452 mutex_unlock(&ice->gpio_mutex);
453 return 0; 453 return change;
454} 454}
455 455
456 456
diff --git a/sound/pci/ice1712/prodigy192.c b/sound/pci/ice1712/prodigy192.c
index 48cf40a8f32a..48d3679292a7 100644
--- a/sound/pci/ice1712/prodigy192.c
+++ b/sound/pci/ice1712/prodigy192.c
@@ -319,12 +319,11 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
319/* 319/*
320 * Handler for setting correct codec rate - called when rate change is detected 320 * Handler for setting correct codec rate - called when rate change is detected
321 */ 321 */
322static void stac9460_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 322static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
323{ 323{
324 unsigned char old, new; 324 unsigned char old, new;
325 int idx; 325 int idx;
326 unsigned char changed[7]; 326 unsigned char changed[7];
327 struct snd_ice1712 *ice = ak->private_data[0];
328 struct prodigy192_spec *spec = ice->spec; 327 struct prodigy192_spec *spec = ice->spec;
329 328
330 if (rate == 0) /* no hint - S/PDIF input is master, simply return */ 329 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
@@ -357,16 +356,6 @@ static void stac9460_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
357 mutex_unlock(&spec->mute_mutex); 356 mutex_unlock(&spec->mute_mutex);
358} 357}
359 358
360/* using akm infrastructure for setting rate of the codec */
361static struct snd_akm4xxx akmlike_stac9460 __devinitdata = {
362 .type = NON_AKM, /* special value */
363 .num_adcs = 6, /* not used in any way, just for completeness */
364 .num_dacs = 2,
365 .ops = {
366 .set_rate_val = stac9460_set_rate_val
367 }
368};
369
370 359
371static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); 360static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
372static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); 361static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
@@ -642,12 +631,19 @@ static int prodigy192_ak4114_init(struct snd_ice1712 *ice)
642 0x41, 0x02, 0x2c, 0x00, 0x00 631 0x41, 0x02, 0x2c, 0x00, 0x00
643 }; 632 };
644 struct prodigy192_spec *spec = ice->spec; 633 struct prodigy192_spec *spec = ice->spec;
634 int err;
645 635
646 return snd_ak4114_create(ice->card, 636 err = snd_ak4114_create(ice->card,
647 prodigy192_ak4114_read, 637 prodigy192_ak4114_read,
648 prodigy192_ak4114_write, 638 prodigy192_ak4114_write,
649 ak4114_init_vals, ak4114_init_txcsb, 639 ak4114_init_vals, ak4114_init_txcsb,
650 ice, &spec->ak4114); 640 ice, &spec->ak4114);
641 if (err < 0)
642 return err;
643 /* AK4114 in Prodigy192 cannot detect external rate correctly.
644 * No reason to stop capture stream due to incorrect checks */
645 spec->ak4114->check_flags = AK4114_CHECK_NO_RATE;
646 return 0;
651} 647}
652 648
653static void stac9460_proc_regs_read(struct snd_info_entry *entry, 649static void stac9460_proc_regs_read(struct snd_info_entry *entry,
@@ -743,7 +739,6 @@ static int __devinit prodigy192_init(struct snd_ice1712 *ice)
743 }; 739 };
744 const unsigned short *p; 740 const unsigned short *p;
745 int err = 0; 741 int err = 0;
746 struct snd_akm4xxx *ak;
747 struct prodigy192_spec *spec; 742 struct prodigy192_spec *spec;
748 743
749 /* prodigy 192 */ 744 /* prodigy 192 */
@@ -761,15 +756,7 @@ static int __devinit prodigy192_init(struct snd_ice1712 *ice)
761 p = stac_inits_prodigy; 756 p = stac_inits_prodigy;
762 for (; *p != (unsigned short)-1; p += 2) 757 for (; *p != (unsigned short)-1; p += 2)
763 stac9460_put(ice, p[0], p[1]); 758 stac9460_put(ice, p[0], p[1]);
764 /* reusing the akm codecs infrastructure, 759 ice->gpio.set_pro_rate = stac9460_set_rate_val;
765 * for setting rate on stac9460 */
766 ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
767 if (!ak)
768 return -ENOMEM;
769 ice->akm_codecs = 1;
770 err = snd_ice1712_akm4xxx_init(ak, &akmlike_stac9460, NULL, ice);
771 if (err < 0)
772 return err;
773 760
774 /* MI/ODI/O add on card with AK4114 */ 761 /* MI/ODI/O add on card with AK4114 */
775 if (prodigy192_miodio_exists(ice)) { 762 if (prodigy192_miodio_exists(ice)) {
@@ -825,10 +812,6 @@ struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = {
825 .build_controls = prodigy192_add_controls, 812 .build_controls = prodigy192_add_controls,
826 .eeprom_size = sizeof(prodigy71_eeprom), 813 .eeprom_size = sizeof(prodigy71_eeprom),
827 .eeprom_data = prodigy71_eeprom, 814 .eeprom_data = prodigy71_eeprom,
828 /* the current MPU401 code loops infinitely
829 * when opening midi device
830 */
831 .no_mpu401 = 1,
832 }, 815 },
833 { } /* terminator */ 816 { } /* terminator */
834}; 817};
diff --git a/sound/pci/ice1712/revo.c b/sound/pci/ice1712/revo.c
index 301bf929acd9..4d2631434dc8 100644
--- a/sound/pci/ice1712/revo.c
+++ b/sound/pci/ice1712/revo.c
@@ -322,17 +322,23 @@ static struct snd_pt2258 ptc_revo51_volume;
322static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 322static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
323{ 323{
324 struct snd_ice1712 *ice = ak->private_data[0]; 324 struct snd_ice1712 *ice = ak->private_data[0];
325 int dfs;
325 326
326 revo_set_rate_val(ak, rate); 327 revo_set_rate_val(ak, rate);
327 328
328#if 1 /* FIXME: do we need this procedure? */ 329 /* reset CKS */
329 /* reset DFS pin of AK5385A for ADC, too */ 330 snd_ice1712_gpio_write_bits(ice, 1 << 8, rate > 96000 ? 1 << 8 : 0);
330 /* DFS0 (pin 18) -- GPIO10 pin 77 */ 331 /* reset DFS pins of AK5385A for ADC, too */
331 snd_ice1712_save_gpio_status(ice); 332 if (rate > 96000)
332 snd_ice1712_gpio_write_bits(ice, 1 << 10, 333 dfs = 2;
333 rate > 48000 ? (1 << 10) : 0); 334 else if (rate > 48000)
334 snd_ice1712_restore_gpio_status(ice); 335 dfs = 1;
335#endif 336 else
337 dfs = 0;
338 snd_ice1712_gpio_write_bits(ice, 3 << 9, dfs << 9);
339 /* reset ADC */
340 snd_ice1712_gpio_write_bits(ice, 1 << 11, 0);
341 snd_ice1712_gpio_write_bits(ice, 1 << 11, 1 << 11);
336} 342}
337 343
338static const struct snd_akm4xxx_dac_channel ap192_dac[] = { 344static const struct snd_akm4xxx_dac_channel ap192_dac[] = {
@@ -353,28 +359,20 @@ static struct snd_ak4xxx_private akm_ap192_priv __devinitdata = {
353 .cif = 0, 359 .cif = 0,
354 .data_mask = VT1724_REVO_CDOUT, 360 .data_mask = VT1724_REVO_CDOUT,
355 .clk_mask = VT1724_REVO_CCLK, 361 .clk_mask = VT1724_REVO_CCLK,
356 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS3, 362 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
357 .cs_addr = VT1724_REVO_CS3, 363 .cs_addr = VT1724_REVO_CS1,
358 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS3, 364 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
359 .add_flags = VT1724_REVO_CCLK, /* high at init */ 365 .add_flags = VT1724_REVO_CCLK, /* high at init */
360 .mask_flags = 0, 366 .mask_flags = 0,
361}; 367};
362 368
363#if 0
364/* FIXME: ak4114 makes the sound much lower due to some confliction,
365 * so let's disable it right now...
366 */
367#define BUILD_AK4114_AP192
368#endif
369
370#ifdef BUILD_AK4114_AP192
371/* AK4114 support on Audiophile 192 */ 369/* AK4114 support on Audiophile 192 */
372/* CDTO (pin 32) -- GPIO2 pin 52 370/* CDTO (pin 32) -- GPIO2 pin 52
373 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358) 371 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358)
374 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358) 372 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358)
375 * CSN (pin 35) -- GPIO7 pin 59 373 * CSN (pin 35) -- GPIO7 pin 59
376 */ 374 */
377#define AK4114_ADDR 0x00 375#define AK4114_ADDR 0x02
378 376
379static void write_data(struct snd_ice1712 *ice, unsigned int gpio, 377static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
380 unsigned int data, int idx) 378 unsigned int data, int idx)
@@ -428,7 +426,7 @@ static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
428 tmp = snd_ice1712_gpio_read(ice); 426 tmp = snd_ice1712_gpio_read(ice);
429 tmp |= VT1724_REVO_CCLK; /* high at init */ 427 tmp |= VT1724_REVO_CCLK; /* high at init */
430 tmp |= VT1724_REVO_CS0; 428 tmp |= VT1724_REVO_CS0;
431 tmp &= ~VT1724_REVO_CS3; 429 tmp &= ~VT1724_REVO_CS1;
432 snd_ice1712_gpio_write(ice, tmp); 430 snd_ice1712_gpio_write(ice, tmp);
433 udelay(1); 431 udelay(1);
434 return tmp; 432 return tmp;
@@ -436,7 +434,7 @@ static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
436 434
437static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp) 435static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
438{ 436{
439 tmp |= VT1724_REVO_CS3; 437 tmp |= VT1724_REVO_CS1;
440 tmp |= VT1724_REVO_CS0; 438 tmp |= VT1724_REVO_CS0;
441 snd_ice1712_gpio_write(ice, tmp); 439 snd_ice1712_gpio_write(ice, tmp);
442 udelay(1); 440 udelay(1);
@@ -485,13 +483,17 @@ static int __devinit ap192_ak4114_init(struct snd_ice1712 *ice)
485 struct ak4114 *ak; 483 struct ak4114 *ak;
486 int err; 484 int err;
487 485
488 return snd_ak4114_create(ice->card, 486 err = snd_ak4114_create(ice->card,
489 ap192_ak4114_read, 487 ap192_ak4114_read,
490 ap192_ak4114_write, 488 ap192_ak4114_write,
491 ak4114_init_vals, ak4114_init_txcsb, 489 ak4114_init_vals, ak4114_init_txcsb,
492 ice, &ak); 490 ice, &ak);
491 /* AK4114 in Revo cannot detect external rate correctly.
492 * No reason to stop capture stream due to incorrect checks */
493 ak->check_flags = AK4114_CHECK_NO_RATE;
494
495 return 0; /* error ignored; it's no fatal error */
493} 496}
494#endif /* BUILD_AK4114_AP192 */
495 497
496static int __devinit revo_init(struct snd_ice1712 *ice) 498static int __devinit revo_init(struct snd_ice1712 *ice)
497{ 499{
@@ -557,6 +559,9 @@ static int __devinit revo_init(struct snd_ice1712 *ice)
557 if (err < 0) 559 if (err < 0)
558 return err; 560 return err;
559 561
562 /* unmute all codecs */
563 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE,
564 VT1724_REVO_MUTE);
560 break; 565 break;
561 } 566 }
562 567
@@ -588,11 +593,9 @@ static int __devinit revo_add_controls(struct snd_ice1712 *ice)
588 err = snd_ice1712_akm4xxx_build_controls(ice); 593 err = snd_ice1712_akm4xxx_build_controls(ice);
589 if (err < 0) 594 if (err < 0)
590 return err; 595 return err;
591#ifdef BUILD_AK4114_AP192
592 err = ap192_ak4114_init(ice); 596 err = ap192_ak4114_init(ice);
593 if (err < 0) 597 if (err < 0)
594 return err; 598 return err;
595#endif
596 break; 599 break;
597 } 600 }
598 return 0; 601 return 0;
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index c52abd0bf22e..048d99e25ab0 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -155,7 +155,8 @@ DEFINE_REGSET(SP, 0x60); /* SPDIF out */
155#define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */ 155#define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
156#define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */ 156#define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
157#define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */ 157#define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
158#define ICH_PCM_246_MASK 0x00300000 /* 6 channels (not all chips) */ 158#define ICH_PCM_246_MASK 0x00300000 /* chan mask (not all chips) */
159#define ICH_PCM_8 0x00300000 /* 8 channels (not all chips) */
159#define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */ 160#define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
160#define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */ 161#define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
161#define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */ 162#define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
@@ -382,6 +383,7 @@ struct intel8x0 {
382 383
383 unsigned multi4: 1, 384 unsigned multi4: 1,
384 multi6: 1, 385 multi6: 1,
386 multi8 :1,
385 dra: 1, 387 dra: 1,
386 smp20bit: 1; 388 smp20bit: 1;
387 unsigned in_ac97_init: 1, 389 unsigned in_ac97_init: 1,
@@ -997,6 +999,8 @@ static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,
997 cnt |= ICH_PCM_4; 999 cnt |= ICH_PCM_4;
998 else if (runtime->channels == 6) 1000 else if (runtime->channels == 6)
999 cnt |= ICH_PCM_6; 1001 cnt |= ICH_PCM_6;
1002 else if (runtime->channels == 8)
1003 cnt |= ICH_PCM_8;
1000 if (chip->device_type == DEVICE_NFORCE) { 1004 if (chip->device_type == DEVICE_NFORCE) {
1001 /* reset to 2ch once to keep the 6 channel data in alignment, 1005 /* reset to 2ch once to keep the 6 channel data in alignment,
1002 * to start from Front Left always 1006 * to start from Front Left always
@@ -1106,6 +1110,16 @@ static struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
1106 .mask = 0, 1110 .mask = 0,
1107}; 1111};
1108 1112
1113static unsigned int channels8[] = {
1114 2, 4, 6, 8,
1115};
1116
1117static struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
1118 .count = ARRAY_SIZE(channels8),
1119 .list = channels8,
1120 .mask = 0,
1121};
1122
1109static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev) 1123static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
1110{ 1124{
1111 struct intel8x0 *chip = snd_pcm_substream_chip(substream); 1125 struct intel8x0 *chip = snd_pcm_substream_chip(substream);
@@ -1136,7 +1150,12 @@ static int snd_intel8x0_playback_open(struct snd_pcm_substream *substream)
1136 if (err < 0) 1150 if (err < 0)
1137 return err; 1151 return err;
1138 1152
1139 if (chip->multi6) { 1153 if (chip->multi8) {
1154 runtime->hw.channels_max = 8;
1155 snd_pcm_hw_constraint_list(runtime, 0,
1156 SNDRV_PCM_HW_PARAM_CHANNELS,
1157 &hw_constraints_channels8);
1158 } else if (chip->multi6) {
1140 runtime->hw.channels_max = 6; 1159 runtime->hw.channels_max = 6;
1141 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 1160 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1142 &hw_constraints_channels6); 1161 &hw_constraints_channels6);
@@ -2203,8 +2222,11 @@ static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
2203 } 2222 }
2204 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) { 2223 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
2205 chip->multi4 = 1; 2224 chip->multi4 = 1;
2206 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) 2225 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) {
2207 chip->multi6 = 1; 2226 chip->multi6 = 1;
2227 if (chip->ac97[0]->flags & AC97_HAS_8CH)
2228 chip->multi8 = 1;
2229 }
2208 } 2230 }
2209 if (pbus->pcms[0].r[1].rslots[0]) { 2231 if (pbus->pcms[0].r[1].rslots[0]) {
2210 chip->dra = 1; 2232 chip->dra = 1;
@@ -2446,7 +2468,7 @@ static int snd_intel8x0_free(struct intel8x0 *chip)
2446 pci_write_config_dword(chip->pci, 0x4c, val); 2468 pci_write_config_dword(chip->pci, 0x4c, val);
2447 } 2469 }
2448 /* --- */ 2470 /* --- */
2449 synchronize_irq(chip->irq); 2471
2450 __hw_end: 2472 __hw_end:
2451 if (chip->irq >= 0) 2473 if (chip->irq >= 0)
2452 free_irq(chip->irq, chip); 2474 free_irq(chip->irq, chip);
@@ -2495,7 +2517,6 @@ static int intel8x0_suspend(struct pci_dev *pci, pm_message_t state)
2495 chip->sdm_saved = igetbyte(chip, ICHREG(SDM)); 2517 chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
2496 2518
2497 if (chip->irq >= 0) { 2519 if (chip->irq >= 0) {
2498 synchronize_irq(chip->irq);
2499 free_irq(chip->irq, chip); 2520 free_irq(chip->irq, chip);
2500 chip->irq = -1; 2521 chip->irq = -1;
2501 } 2522 }
@@ -2648,7 +2669,7 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2648 t = stop_time.tv_sec - start_time.tv_sec; 2669 t = stop_time.tv_sec - start_time.tv_sec;
2649 t *= 1000000; 2670 t *= 1000000;
2650 t += stop_time.tv_usec - start_time.tv_usec; 2671 t += stop_time.tv_usec - start_time.tv_usec;
2651 printk(KERN_INFO "%s: measured %lu usecs\n", __FUNCTION__, t); 2672 printk(KERN_INFO "%s: measured %lu usecs\n", __func__, t);
2652 if (t == 0) { 2673 if (t == 0) {
2653 snd_printk(KERN_ERR "?? calculation error..\n"); 2674 snd_printk(KERN_ERR "?? calculation error..\n");
2654 return; 2675 return;
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index cadda8d6b70f..faf674e671ac 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -985,17 +985,15 @@ static int snd_intel8x0_free(struct intel8x0m *chip)
985 /* reset channels */ 985 /* reset channels */
986 for (i = 0; i < chip->bdbars_count; i++) 986 for (i = 0; i < chip->bdbars_count; i++)
987 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS); 987 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
988 /* --- */ 988 __hw_end:
989 synchronize_irq(chip->irq); 989 if (chip->irq >= 0)
990 __hw_end: 990 free_irq(chip->irq, chip);
991 if (chip->bdbars.area) 991 if (chip->bdbars.area)
992 snd_dma_free_pages(&chip->bdbars); 992 snd_dma_free_pages(&chip->bdbars);
993 if (chip->addr) 993 if (chip->addr)
994 pci_iounmap(chip->pci, chip->addr); 994 pci_iounmap(chip->pci, chip->addr);
995 if (chip->bmaddr) 995 if (chip->bmaddr)
996 pci_iounmap(chip->pci, chip->bmaddr); 996 pci_iounmap(chip->pci, chip->bmaddr);
997 if (chip->irq >= 0)
998 free_irq(chip->irq, chip);
999 pci_release_regions(chip->pci); 997 pci_release_regions(chip->pci);
1000 pci_disable_device(chip->pci); 998 pci_disable_device(chip->pci);
1001 kfree(chip); 999 kfree(chip);
@@ -1017,7 +1015,6 @@ static int intel8x0m_suspend(struct pci_dev *pci, pm_message_t state)
1017 snd_pcm_suspend_all(chip->pcm[i]); 1015 snd_pcm_suspend_all(chip->pcm[i]);
1018 snd_ac97_suspend(chip->ac97); 1016 snd_ac97_suspend(chip->ac97);
1019 if (chip->irq >= 0) { 1017 if (chip->irq >= 0) {
1020 synchronize_irq(chip->irq);
1021 free_irq(chip->irq, chip); 1018 free_irq(chip->irq, chip);
1022 chip->irq = -1; 1019 chip->irq = -1;
1023 } 1020 }
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 10c713d9ac49..f4c85b52bde3 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -2102,7 +2102,6 @@ snd_korg1212_free(struct snd_korg1212 *korg1212)
2102 snd_korg1212_TurnOffIdleMonitor(korg1212); 2102 snd_korg1212_TurnOffIdleMonitor(korg1212);
2103 2103
2104 if (korg1212->irq >= 0) { 2104 if (korg1212->irq >= 0) {
2105 synchronize_irq(korg1212->irq);
2106 snd_korg1212_DisableCardInterrupts(korg1212); 2105 snd_korg1212_DisableCardInterrupts(korg1212);
2107 free_irq(korg1212->irq, korg1212); 2106 free_irq(korg1212->irq, korg1212);
2108 korg1212->irq = -1; 2107 korg1212->irq = -1;
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 04fa0a68416c..a536c59fbea1 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -2068,7 +2068,7 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
2068{ 2068{
2069 struct snd_ac97_bus *pbus; 2069 struct snd_ac97_bus *pbus;
2070 struct snd_ac97_template ac97; 2070 struct snd_ac97_template ac97;
2071 struct snd_ctl_elem_id id; 2071 struct snd_ctl_elem_id elem_id;
2072 int err; 2072 int err;
2073 static struct snd_ac97_bus_ops ops = { 2073 static struct snd_ac97_bus_ops ops = {
2074 .write = snd_m3_ac97_write, 2074 .write = snd_m3_ac97_write,
@@ -2088,14 +2088,14 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
2088 schedule_timeout_uninterruptible(msecs_to_jiffies(100)); 2088 schedule_timeout_uninterruptible(msecs_to_jiffies(100));
2089 snd_ac97_write(chip->ac97, AC97_PCM, 0); 2089 snd_ac97_write(chip->ac97, AC97_PCM, 0);
2090 2090
2091 memset(&id, 0, sizeof(id)); 2091 memset(&elem_id, 0, sizeof(elem_id));
2092 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2092 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2093 strcpy(id.name, "Master Playback Switch"); 2093 strcpy(elem_id.name, "Master Playback Switch");
2094 chip->master_switch = snd_ctl_find_id(chip->card, &id); 2094 chip->master_switch = snd_ctl_find_id(chip->card, &elem_id);
2095 memset(&id, 0, sizeof(id)); 2095 memset(&elem_id, 0, sizeof(elem_id));
2096 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2096 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2097 strcpy(id.name, "Master Playback Volume"); 2097 strcpy(elem_id.name, "Master Playback Volume");
2098 chip->master_volume = snd_ctl_find_id(chip->card, &id); 2098 chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
2099 2099
2100 return 0; 2100 return 0;
2101} 2101}
@@ -2542,10 +2542,8 @@ static int snd_m3_free(struct snd_m3 *chip)
2542 vfree(chip->suspend_mem); 2542 vfree(chip->suspend_mem);
2543#endif 2543#endif
2544 2544
2545 if (chip->irq >= 0) { 2545 if (chip->irq >= 0)
2546 synchronize_irq(chip->irq);
2547 free_irq(chip->irq, chip); 2546 free_irq(chip->irq, chip);
2548 }
2549 2547
2550 if (chip->iobase) 2548 if (chip->iobase)
2551 pci_release_regions(chip->pci); 2549 pci_release_regions(chip->pci);
@@ -2569,7 +2567,7 @@ static int m3_suspend(struct pci_dev *pci, pm_message_t state)
2569{ 2567{
2570 struct snd_card *card = pci_get_drvdata(pci); 2568 struct snd_card *card = pci_get_drvdata(pci);
2571 struct snd_m3 *chip = card->private_data; 2569 struct snd_m3 *chip = card->private_data;
2572 int i, index; 2570 int i, dsp_index;
2573 2571
2574 if (chip->suspend_mem == NULL) 2572 if (chip->suspend_mem == NULL)
2575 return 0; 2573 return 0;
@@ -2583,12 +2581,12 @@ static int m3_suspend(struct pci_dev *pci, pm_message_t state)
2583 snd_m3_assp_halt(chip); 2581 snd_m3_assp_halt(chip);
2584 2582
2585 /* save dsp image */ 2583 /* save dsp image */
2586 index = 0; 2584 dsp_index = 0;
2587 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++) 2585 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
2588 chip->suspend_mem[index++] = 2586 chip->suspend_mem[dsp_index++] =
2589 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_CODE, i); 2587 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_CODE, i);
2590 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++) 2588 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2591 chip->suspend_mem[index++] = 2589 chip->suspend_mem[dsp_index++] =
2592 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i); 2590 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i);
2593 2591
2594 pci_disable_device(pci); 2592 pci_disable_device(pci);
@@ -2601,7 +2599,7 @@ static int m3_resume(struct pci_dev *pci)
2601{ 2599{
2602 struct snd_card *card = pci_get_drvdata(pci); 2600 struct snd_card *card = pci_get_drvdata(pci);
2603 struct snd_m3 *chip = card->private_data; 2601 struct snd_m3 *chip = card->private_data;
2604 int i, index; 2602 int i, dsp_index;
2605 2603
2606 if (chip->suspend_mem == NULL) 2604 if (chip->suspend_mem == NULL)
2607 return 0; 2605 return 0;
@@ -2625,13 +2623,13 @@ static int m3_resume(struct pci_dev *pci)
2625 snd_m3_ac97_reset(chip); 2623 snd_m3_ac97_reset(chip);
2626 2624
2627 /* restore dsp image */ 2625 /* restore dsp image */
2628 index = 0; 2626 dsp_index = 0;
2629 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++) 2627 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
2630 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE, i, 2628 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE, i,
2631 chip->suspend_mem[index++]); 2629 chip->suspend_mem[dsp_index++]);
2632 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++) 2630 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2633 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, i, 2631 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, i,
2634 chip->suspend_mem[index++]); 2632 chip->suspend_mem[dsp_index++]);
2635 2633
2636 /* tell the dma engine to restart itself */ 2634 /* tell the dma engine to restart itself */
2637 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, 2635 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 7ac654e381da..7efb838d18a6 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -1439,7 +1439,7 @@ static int snd_nm256_free(struct nm256 *chip)
1439 snd_nm256_capture_stop(chip); 1439 snd_nm256_capture_stop(chip);
1440 1440
1441 if (chip->irq >= 0) 1441 if (chip->irq >= 0)
1442 synchronize_irq(chip->irq); 1442 free_irq(chip->irq, chip);
1443 1443
1444 if (chip->cport) 1444 if (chip->cport)
1445 iounmap(chip->cport); 1445 iounmap(chip->cport);
@@ -1447,8 +1447,6 @@ static int snd_nm256_free(struct nm256 *chip)
1447 iounmap(chip->buffer); 1447 iounmap(chip->buffer);
1448 release_and_free_resource(chip->res_cport); 1448 release_and_free_resource(chip->res_cport);
1449 release_and_free_resource(chip->res_buffer); 1449 release_and_free_resource(chip->res_buffer);
1450 if (chip->irq >= 0)
1451 free_irq(chip->irq, chip);
1452 1450
1453 pci_disable_device(chip->pci); 1451 pci_disable_device(chip->pci);
1454 kfree(chip->ac97_regs); 1452 kfree(chip->ac97_regs);
diff --git a/sound/pci/oxygen/cs4362a.h b/sound/pci/oxygen/cs4362a.h
new file mode 100644
index 000000000000..6a4fedf5e1ec
--- /dev/null
+++ b/sound/pci/oxygen/cs4362a.h
@@ -0,0 +1,69 @@
1/* register 01h */
2#define CS4362A_PDN 0x01
3#define CS4362A_DAC1_DIS 0x02
4#define CS4362A_DAC2_DIS 0x04
5#define CS4362A_DAC3_DIS 0x08
6#define CS4362A_MCLKDIV 0x20
7#define CS4362A_FREEZE 0x40
8#define CS4362A_CPEN 0x80
9/* register 02h */
10#define CS4362A_DIF_MASK 0x70
11#define CS4362A_DIF_LJUST 0x00
12#define CS4362A_DIF_I2S 0x10
13#define CS4362A_DIF_RJUST_16 0x20
14#define CS4362A_DIF_RJUST_24 0x30
15#define CS4362A_DIF_RJUST_20 0x40
16#define CS4362A_DIF_RJUST_18 0x50
17/* register 03h */
18#define CS4362A_MUTEC_MASK 0x03
19#define CS4362A_MUTEC_6 0x00
20#define CS4362A_MUTEC_1 0x01
21#define CS4362A_MUTEC_3 0x03
22#define CS4362A_AMUTE 0x04
23#define CS4362A_MUTEC_POL 0x08
24#define CS4362A_RMP_UP 0x10
25#define CS4362A_SNGLVOL 0x20
26#define CS4362A_ZERO_CROSS 0x40
27#define CS4362A_SOFT_RAMP 0x80
28/* register 04h */
29#define CS4362A_RMP_DN 0x01
30#define CS4362A_DEM_MASK 0x06
31#define CS4362A_DEM_NONE 0x00
32#define CS4362A_DEM_44100 0x02
33#define CS4362A_DEM_48000 0x04
34#define CS4362A_DEM_32000 0x06
35#define CS4362A_FILT_SEL 0x10
36/* register 05h */
37#define CS4362A_INV_A1 0x01
38#define CS4362A_INV_B1 0x02
39#define CS4362A_INV_A2 0x04
40#define CS4362A_INV_B2 0x08
41#define CS4362A_INV_A3 0x10
42#define CS4362A_INV_B3 0x20
43/* register 06h */
44#define CS4362A_FM_MASK 0x03
45#define CS4362A_FM_SINGLE 0x00
46#define CS4362A_FM_DOUBLE 0x01
47#define CS4362A_FM_QUAD 0x02
48#define CS4362A_FM_DSD 0x03
49#define CS4362A_ATAPI_MASK 0x7c
50#define CS4362A_ATAPI_B_MUTE 0x00
51#define CS4362A_ATAPI_B_R 0x04
52#define CS4362A_ATAPI_B_L 0x08
53#define CS4362A_ATAPI_B_LR 0x0c
54#define CS4362A_ATAPI_A_MUTE 0x00
55#define CS4362A_ATAPI_A_R 0x10
56#define CS4362A_ATAPI_A_L 0x20
57#define CS4362A_ATAPI_A_LR 0x30
58#define CS4362A_ATAPI_MIX_LR_VOL 0x40
59#define CS4362A_A_EQ_B 0x80
60/* register 07h */
61#define CS4362A_VOL_MASK 0x7f
62#define CS4362A_MUTE 0x80
63/* register 08h: like 07h */
64/* registers 09h..0Bh: like 06h..08h */
65/* registers 0Ch..0Eh: like 06h..08h */
66/* register 12h */
67#define CS4362A_REV_MASK 0x07
68#define CS4362A_PART_MASK 0xf8
69#define CS4362A_PART_CS4362A 0x50
diff --git a/sound/pci/oxygen/cs4398.h b/sound/pci/oxygen/cs4398.h
new file mode 100644
index 000000000000..5faf5efc8826
--- /dev/null
+++ b/sound/pci/oxygen/cs4398.h
@@ -0,0 +1,69 @@
1/* register 1 */
2#define CS4398_REV_MASK 0x07
3#define CS4398_PART_MASK 0xf8
4#define CS4398_PART_CS4398 0x70
5/* register 2 */
6#define CS4398_FM_MASK 0x03
7#define CS4398_FM_SINGLE 0x00
8#define CS4398_FM_DOUBLE 0x01
9#define CS4398_FM_QUAD 0x02
10#define CS4398_FM_DSD 0x03
11#define CS4398_DEM_MASK 0x0c
12#define CS4398_DEM_NONE 0x00
13#define CS4398_DEM_44100 0x04
14#define CS4398_DEM_48000 0x08
15#define CS4398_DEM_32000 0x0c
16#define CS4398_DIF_MASK 0x70
17#define CS4398_DIF_LJUST 0x00
18#define CS4398_DIF_I2S 0x10
19#define CS4398_DIF_RJUST_16 0x20
20#define CS4398_DIF_RJUST_24 0x30
21#define CS4398_DIF_RJUST_20 0x40
22#define CS4398_DIF_RJUST_18 0x50
23#define CS4398_DSD_SRC 0x80
24/* register 3 */
25#define CS4398_ATAPI_MASK 0x1f
26#define CS4398_ATAPI_B_MUTE 0x00
27#define CS4398_ATAPI_B_R 0x01
28#define CS4398_ATAPI_B_L 0x02
29#define CS4398_ATAPI_B_LR 0x03
30#define CS4398_ATAPI_A_MUTE 0x00
31#define CS4398_ATAPI_A_R 0x04
32#define CS4398_ATAPI_A_L 0x08
33#define CS4398_ATAPI_A_LR 0x0c
34#define CS4398_ATAPI_MIX_LR_VOL 0x10
35#define CS4398_INVERT_B 0x20
36#define CS4398_INVERT_A 0x40
37#define CS4398_VOL_B_EQ_A 0x80
38/* register 4 */
39#define CS4398_MUTEP_MASK 0x03
40#define CS4398_MUTEP_AUTO 0x00
41#define CS4398_MUTEP_LOW 0x02
42#define CS4398_MUTEP_HIGH 0x03
43#define CS4398_MUTE_B 0x08
44#define CS4398_MUTE_A 0x10
45#define CS4398_MUTEC_A_EQ_B 0x20
46#define CS4398_DAMUTE 0x40
47#define CS4398_PAMUTE 0x80
48/* register 5 */
49#define CS4398_VOL_A_MASK 0xff
50/* register 6 */
51#define CS4398_VOL_B_MASK 0xff
52/* register 7 */
53#define CS4398_DIR_DSD 0x01
54#define CS4398_FILT_SEL 0x04
55#define CS4398_RMP_DN 0x10
56#define CS4398_RMP_UP 0x20
57#define CS4398_ZERO_CROSS 0x40
58#define CS4398_SOFT_RAMP 0x80
59/* register 8 */
60#define CS4398_MCLKDIV3 0x08
61#define CS4398_MCLKDIV2 0x10
62#define CS4398_FREEZE 0x20
63#define CS4398_CPEN 0x40
64#define CS4398_PDN 0x80
65/* register 9 */
66#define CS4398_DSD_PM_EN 0x01
67#define CS4398_DSD_PM_MODE 0x02
68#define CS4398_INVALID_DSD 0x04
69#define CS4398_STATIC_DSD 0x08
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
index 666f69a3312e..090dd4354a28 100644
--- a/sound/pci/oxygen/hifier.c
+++ b/sound/pci/oxygen/hifier.c
@@ -66,12 +66,12 @@ static void hifier_init(struct oxygen *chip)
66{ 66{
67 struct hifier_data *data = chip->model_data; 67 struct hifier_data *data = chip->model_data;
68 68
69 data->ak4396_ctl2 = AK4396_DEM_OFF | AK4396_DFS_NORMAL; 69 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
70 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 70 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
71 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2); 71 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
72 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM); 72 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
73 ak4396_write(chip, AK4396_LCH_ATT, 0xff); 73 ak4396_write(chip, AK4396_LCH_ATT, 0);
74 ak4396_write(chip, AK4396_RCH_ATT, 0xff); 74 ak4396_write(chip, AK4396_RCH_ATT, 0);
75 75
76 snd_component_add(chip->card, "AK4396"); 76 snd_component_add(chip->card, "AK4396");
77 snd_component_add(chip->card, "CS5340"); 77 snd_component_add(chip->card, "CS5340");
@@ -127,22 +127,8 @@ static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
127 127
128static int hifier_control_filter(struct snd_kcontrol_new *template) 128static int hifier_control_filter(struct snd_kcontrol_new *template)
129{ 129{
130 if (!strcmp(template->name, "Master Playback Volume")) { 130 if (!strcmp(template->name, "Stereo Upmixing"))
131 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
132 template->tlv.p = ak4396_db_scale;
133 } else if (!strcmp(template->name, "Stereo Upmixing")) {
134 return 1; /* stereo only - we don't need upmixing */ 131 return 1; /* stereo only - we don't need upmixing */
135 } else if (!strcmp(template->name,
136 SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK)) ||
137 !strcmp(template->name,
138 SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT))) {
139 return 1; /* no digital input */
140 }
141 return 0;
142}
143
144static int hifier_mixer_init(struct oxygen *chip)
145{
146 return 0; 132 return 0;
147} 133}
148 134
@@ -153,18 +139,20 @@ static const struct oxygen_model model_hifier = {
153 .owner = THIS_MODULE, 139 .owner = THIS_MODULE,
154 .init = hifier_init, 140 .init = hifier_init,
155 .control_filter = hifier_control_filter, 141 .control_filter = hifier_control_filter,
156 .mixer_init = hifier_mixer_init,
157 .cleanup = hifier_cleanup, 142 .cleanup = hifier_cleanup,
158 .set_dac_params = set_ak4396_params, 143 .set_dac_params = set_ak4396_params,
159 .set_adc_params = set_cs5340_params, 144 .set_adc_params = set_cs5340_params,
160 .update_dac_volume = update_ak4396_volume, 145 .update_dac_volume = update_ak4396_volume,
161 .update_dac_mute = update_ak4396_mute, 146 .update_dac_mute = update_ak4396_mute,
147 .dac_tlv = ak4396_db_scale,
162 .model_data_size = sizeof(struct hifier_data), 148 .model_data_size = sizeof(struct hifier_data),
149 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
150 PLAYBACK_1_TO_SPDIF |
151 CAPTURE_0_FROM_I2S_1,
163 .dac_channels = 2, 152 .dac_channels = 2,
164 .used_channels = OXYGEN_CHANNEL_A | 153 .dac_volume_min = 0,
165 OXYGEN_CHANNEL_SPDIF | 154 .dac_volume_max = 255,
166 OXYGEN_CHANNEL_MULTICH, 155 .function_flags = OXYGEN_FUNCTION_SPI,
167 .function_flags = 0,
168 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 156 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
169 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 157 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
170}; 158};
@@ -181,7 +169,7 @@ static int __devinit hifier_probe(struct pci_dev *pci,
181 ++dev; 169 ++dev;
182 return -ENOENT; 170 return -ENOENT;
183 } 171 }
184 err = oxygen_pci_probe(pci, index[dev], id[dev], 0, &model_hifier); 172 err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier);
185 if (err >= 0) 173 if (err >= 0)
186 ++dev; 174 ++dev;
187 return err; 175 return err;
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 9a9941bb0460..63f185c1ed1e 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -39,7 +39,7 @@
39#include <sound/tlv.h> 39#include <sound/tlv.h>
40#include "oxygen.h" 40#include "oxygen.h"
41#include "ak4396.h" 41#include "ak4396.h"
42#include "cm9780.h" 42#include "wm8785.h"
43 43
44MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 44MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
45MODULE_DESCRIPTION("C-Media CMI8788 driver"); 45MODULE_DESCRIPTION("C-Media CMI8788 driver");
@@ -78,49 +78,6 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
78#define GPIO_AK5385_DFS_DOUBLE 0x0001 78#define GPIO_AK5385_DFS_DOUBLE 0x0001
79#define GPIO_AK5385_DFS_QUAD 0x0002 79#define GPIO_AK5385_DFS_QUAD 0x0002
80 80
81#define GPIO_LINE_MUTE CM9780_GPO0
82
83#define WM8785_R0 0
84#define WM8785_R1 1
85#define WM8785_R2 2
86#define WM8785_R7 7
87
88/* R0 */
89#define WM8785_MCR_MASK 0x007
90#define WM8785_MCR_SLAVE 0x000
91#define WM8785_MCR_MASTER_128 0x001
92#define WM8785_MCR_MASTER_192 0x002
93#define WM8785_MCR_MASTER_256 0x003
94#define WM8785_MCR_MASTER_384 0x004
95#define WM8785_MCR_MASTER_512 0x005
96#define WM8785_MCR_MASTER_768 0x006
97#define WM8785_OSR_MASK 0x018
98#define WM8785_OSR_SINGLE 0x000
99#define WM8785_OSR_DOUBLE 0x008
100#define WM8785_OSR_QUAD 0x010
101#define WM8785_FORMAT_MASK 0x060
102#define WM8785_FORMAT_RJUST 0x000
103#define WM8785_FORMAT_LJUST 0x020
104#define WM8785_FORMAT_I2S 0x040
105#define WM8785_FORMAT_DSP 0x060
106/* R1 */
107#define WM8785_WL_MASK 0x003
108#define WM8785_WL_16 0x000
109#define WM8785_WL_20 0x001
110#define WM8785_WL_24 0x002
111#define WM8785_WL_32 0x003
112#define WM8785_LRP 0x004
113#define WM8785_BCLKINV 0x008
114#define WM8785_LRSWAP 0x010
115#define WM8785_DEVNO_MASK 0x0e0
116/* R2 */
117#define WM8785_HPFR 0x001
118#define WM8785_HPFL 0x002
119#define WM8785_SDODIS 0x004
120#define WM8785_PWRDNR 0x008
121#define WM8785_PWRDNL 0x010
122#define WM8785_TDM_MASK 0x1c0
123
124struct generic_data { 81struct generic_data {
125 u8 ak4396_ctl2; 82 u8 ak4396_ctl2;
126}; 83};
@@ -155,7 +112,7 @@ static void ak4396_init(struct oxygen *chip)
155 struct generic_data *data = chip->model_data; 112 struct generic_data *data = chip->model_data;
156 unsigned int i; 113 unsigned int i;
157 114
158 data->ak4396_ctl2 = AK4396_DEM_OFF | AK4396_DFS_NORMAL; 115 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
159 for (i = 0; i < 4; ++i) { 116 for (i = 0; i < 4; ++i) {
160 ak4396_write(chip, i, 117 ak4396_write(chip, i,
161 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 118 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
@@ -163,8 +120,8 @@ static void ak4396_init(struct oxygen *chip)
163 AK4396_CONTROL_2, data->ak4396_ctl2); 120 AK4396_CONTROL_2, data->ak4396_ctl2);
164 ak4396_write(chip, i, 121 ak4396_write(chip, i,
165 AK4396_CONTROL_3, AK4396_PCM); 122 AK4396_CONTROL_3, AK4396_PCM);
166 ak4396_write(chip, i, AK4396_LCH_ATT, 0xff); 123 ak4396_write(chip, i, AK4396_LCH_ATT, 0);
167 ak4396_write(chip, i, AK4396_RCH_ATT, 0xff); 124 ak4396_write(chip, i, AK4396_RCH_ATT, 0);
168 } 125 }
169 snd_component_add(chip->card, "AK4396"); 126 snd_component_add(chip->card, "AK4396");
170} 127}
@@ -185,23 +142,16 @@ static void wm8785_init(struct oxygen *chip)
185 snd_component_add(chip->card, "WM8785"); 142 snd_component_add(chip->card, "WM8785");
186} 143}
187 144
188static void cmi9780_init(struct oxygen *chip)
189{
190 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS, GPIO_LINE_MUTE);
191}
192
193static void generic_init(struct oxygen *chip) 145static void generic_init(struct oxygen *chip)
194{ 146{
195 ak4396_init(chip); 147 ak4396_init(chip);
196 wm8785_init(chip); 148 wm8785_init(chip);
197 cmi9780_init(chip);
198} 149}
199 150
200static void meridian_init(struct oxygen *chip) 151static void meridian_init(struct oxygen *chip)
201{ 152{
202 ak4396_init(chip); 153 ak4396_init(chip);
203 ak5385_init(chip); 154 ak5385_init(chip);
204 cmi9780_init(chip);
205} 155}
206 156
207static void generic_cleanup(struct oxygen *chip) 157static void generic_cleanup(struct oxygen *chip)
@@ -297,59 +247,32 @@ static void set_ak5385_params(struct oxygen *chip,
297 value, GPIO_AK5385_DFS_MASK); 247 value, GPIO_AK5385_DFS_MASK);
298} 248}
299 249
300static void cmi9780_switch_hook(struct oxygen *chip, unsigned int codec,
301 unsigned int reg, int mute)
302{
303 if (codec != 0)
304 return;
305 switch (reg) {
306 case AC97_LINE:
307 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
308 mute ? GPIO_LINE_MUTE : 0,
309 GPIO_LINE_MUTE);
310 break;
311 case AC97_MIC:
312 case AC97_CD:
313 case AC97_AUX:
314 if (!mute)
315 oxygen_ac97_set_bits(chip, 0, CM9780_GPIO_STATUS,
316 GPIO_LINE_MUTE);
317 break;
318 }
319}
320
321static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 250static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
322 251
323static int ak4396_control_filter(struct snd_kcontrol_new *template)
324{
325 if (!strcmp(template->name, "Master Playback Volume")) {
326 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
327 template->tlv.p = ak4396_db_scale;
328 }
329 return 0;
330}
331
332static const struct oxygen_model model_generic = { 252static const struct oxygen_model model_generic = {
333 .shortname = "C-Media CMI8788", 253 .shortname = "C-Media CMI8788",
334 .longname = "C-Media Oxygen HD Audio", 254 .longname = "C-Media Oxygen HD Audio",
335 .chip = "CMI8788", 255 .chip = "CMI8788",
336 .owner = THIS_MODULE, 256 .owner = THIS_MODULE,
337 .init = generic_init, 257 .init = generic_init,
338 .control_filter = ak4396_control_filter,
339 .cleanup = generic_cleanup, 258 .cleanup = generic_cleanup,
340 .set_dac_params = set_ak4396_params, 259 .set_dac_params = set_ak4396_params,
341 .set_adc_params = set_wm8785_params, 260 .set_adc_params = set_wm8785_params,
342 .update_dac_volume = update_ak4396_volume, 261 .update_dac_volume = update_ak4396_volume,
343 .update_dac_mute = update_ak4396_mute, 262 .update_dac_mute = update_ak4396_mute,
344 .ac97_switch_hook = cmi9780_switch_hook, 263 .dac_tlv = ak4396_db_scale,
345 .model_data_size = sizeof(struct generic_data), 264 .model_data_size = sizeof(struct generic_data),
265 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
266 PLAYBACK_1_TO_SPDIF |
267 PLAYBACK_2_TO_AC97_1 |
268 CAPTURE_0_FROM_I2S_1 |
269 CAPTURE_1_FROM_SPDIF |
270 CAPTURE_2_FROM_AC97_1,
346 .dac_channels = 8, 271 .dac_channels = 8,
347 .used_channels = OXYGEN_CHANNEL_A | 272 .dac_volume_min = 0,
348 OXYGEN_CHANNEL_C | 273 .dac_volume_max = 255,
349 OXYGEN_CHANNEL_SPDIF | 274 .function_flags = OXYGEN_FUNCTION_SPI |
350 OXYGEN_CHANNEL_MULTICH | 275 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
351 OXYGEN_CHANNEL_AC97,
352 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5,
353 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 276 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
354 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 277 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
355}; 278};
@@ -359,21 +282,25 @@ static const struct oxygen_model model_meridian = {
359 .chip = "CMI8788", 282 .chip = "CMI8788",
360 .owner = THIS_MODULE, 283 .owner = THIS_MODULE,
361 .init = meridian_init, 284 .init = meridian_init,
362 .control_filter = ak4396_control_filter,
363 .cleanup = generic_cleanup, 285 .cleanup = generic_cleanup,
364 .set_dac_params = set_ak4396_params, 286 .set_dac_params = set_ak4396_params,
365 .set_adc_params = set_ak5385_params, 287 .set_adc_params = set_ak5385_params,
366 .update_dac_volume = update_ak4396_volume, 288 .update_dac_volume = update_ak4396_volume,
367 .update_dac_mute = update_ak4396_mute, 289 .update_dac_mute = update_ak4396_mute,
368 .ac97_switch_hook = cmi9780_switch_hook, 290 .dac_tlv = ak4396_db_scale,
369 .model_data_size = sizeof(struct generic_data), 291 .model_data_size = sizeof(struct generic_data),
292 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
293 PLAYBACK_1_TO_SPDIF |
294 PLAYBACK_2_TO_AC97_1 |
295 CAPTURE_0_FROM_I2S_2 |
296 CAPTURE_1_FROM_SPDIF |
297 CAPTURE_2_FROM_AC97_1,
370 .dac_channels = 8, 298 .dac_channels = 8,
371 .used_channels = OXYGEN_CHANNEL_B | 299 .dac_volume_min = 0,
372 OXYGEN_CHANNEL_C | 300 .dac_volume_max = 255,
373 OXYGEN_CHANNEL_SPDIF | 301 .misc_flags = OXYGEN_MISC_MIDI,
374 OXYGEN_CHANNEL_MULTICH | 302 .function_flags = OXYGEN_FUNCTION_SPI |
375 OXYGEN_CHANNEL_AC97, 303 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
376 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5,
377 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 304 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
378 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 305 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
379}; 306};
@@ -392,7 +319,7 @@ static int __devinit generic_oxygen_probe(struct pci_dev *pci,
392 return -ENOENT; 319 return -ENOENT;
393 } 320 }
394 is_meridian = pci_id->driver_data; 321 is_meridian = pci_id->driver_data;
395 err = oxygen_pci_probe(pci, index[dev], id[dev], is_meridian, 322 err = oxygen_pci_probe(pci, index[dev], id[dev],
396 is_meridian ? &model_meridian : &model_generic); 323 is_meridian ? &model_meridian : &model_generic);
397 if (err >= 0) 324 if (err >= 0)
398 ++dev; 325 ++dev;
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index ad50fb8b206b..a71c6e059260 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -16,6 +16,16 @@
16#define PCM_AC97 5 16#define PCM_AC97 5
17#define PCM_COUNT 6 17#define PCM_COUNT 6
18 18
19/* model-specific configuration of outputs/inputs */
20#define PLAYBACK_0_TO_I2S 0x001
21#define PLAYBACK_1_TO_SPDIF 0x004
22#define PLAYBACK_2_TO_AC97_1 0x008
23#define CAPTURE_0_FROM_I2S_1 0x010
24#define CAPTURE_0_FROM_I2S_2 0x020
25#define CAPTURE_1_FROM_SPDIF 0x080
26#define CAPTURE_2_FROM_I2S_2 0x100
27#define CAPTURE_2_FROM_AC97_1 0x200
28
19enum { 29enum {
20 CONTROL_SPDIF_PCM, 30 CONTROL_SPDIF_PCM,
21 CONTROL_SPDIF_INPUT_BITS, 31 CONTROL_SPDIF_INPUT_BITS,
@@ -87,12 +97,16 @@ struct oxygen_model {
87 struct snd_pcm_hw_params *params); 97 struct snd_pcm_hw_params *params);
88 void (*update_dac_volume)(struct oxygen *chip); 98 void (*update_dac_volume)(struct oxygen *chip);
89 void (*update_dac_mute)(struct oxygen *chip); 99 void (*update_dac_mute)(struct oxygen *chip);
90 void (*ac97_switch_hook)(struct oxygen *chip, unsigned int codec,
91 unsigned int reg, int mute);
92 void (*gpio_changed)(struct oxygen *chip); 100 void (*gpio_changed)(struct oxygen *chip);
101 void (*ac97_switch)(struct oxygen *chip,
102 unsigned int reg, unsigned int mute);
103 const unsigned int *dac_tlv;
93 size_t model_data_size; 104 size_t model_data_size;
105 unsigned int pcm_dev_cfg;
94 u8 dac_channels; 106 u8 dac_channels;
95 u8 used_channels; 107 u8 dac_volume_min;
108 u8 dac_volume_max;
109 u8 misc_flags;
96 u8 function_flags; 110 u8 function_flags;
97 u16 dac_i2s_format; 111 u16 dac_i2s_format;
98 u16 adc_i2s_format; 112 u16 adc_i2s_format;
@@ -100,7 +114,7 @@ struct oxygen_model {
100 114
101/* oxygen_lib.c */ 115/* oxygen_lib.c */
102 116
103int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, int midi, 117int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
104 const struct oxygen_model *model); 118 const struct oxygen_model *model);
105void oxygen_pci_remove(struct pci_dev *pci); 119void oxygen_pci_remove(struct pci_dev *pci);
106 120
@@ -137,6 +151,7 @@ void oxygen_write_ac97_masked(struct oxygen *chip, unsigned int codec,
137 unsigned int index, u16 data, u16 mask); 151 unsigned int index, u16 data, u16 mask);
138 152
139void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data); 153void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data);
154void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data);
140 155
141static inline void oxygen_set_bits8(struct oxygen *chip, 156static inline void oxygen_set_bits8(struct oxygen *chip,
142 unsigned int reg, u8 value) 157 unsigned int reg, u8 value)
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index 74e23ef9c946..5569606ee87f 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -190,12 +190,31 @@ void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data)
190 --count; 190 --count;
191 } 191 }
192 192
193 spin_lock_irq(&chip->reg_lock);
194 oxygen_write8(chip, OXYGEN_SPI_DATA1, data); 193 oxygen_write8(chip, OXYGEN_SPI_DATA1, data);
195 oxygen_write8(chip, OXYGEN_SPI_DATA2, data >> 8); 194 oxygen_write8(chip, OXYGEN_SPI_DATA2, data >> 8);
196 if (control & OXYGEN_SPI_DATA_LENGTH_3) 195 if (control & OXYGEN_SPI_DATA_LENGTH_3)
197 oxygen_write8(chip, OXYGEN_SPI_DATA3, data >> 16); 196 oxygen_write8(chip, OXYGEN_SPI_DATA3, data >> 16);
198 oxygen_write8(chip, OXYGEN_SPI_CONTROL, control); 197 oxygen_write8(chip, OXYGEN_SPI_CONTROL, control);
199 spin_unlock_irq(&chip->reg_lock);
200} 198}
201EXPORT_SYMBOL(oxygen_write_spi); 199EXPORT_SYMBOL(oxygen_write_spi);
200
201void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data)
202{
203 unsigned long timeout;
204
205 /* should not need more than about 300 us */
206 timeout = jiffies + msecs_to_jiffies(1);
207 do {
208 if (!(oxygen_read16(chip, OXYGEN_2WIRE_BUS_STATUS)
209 & OXYGEN_2WIRE_BUSY))
210 break;
211 udelay(1);
212 cond_resched();
213 } while (time_after_eq(timeout, jiffies));
214
215 oxygen_write8(chip, OXYGEN_2WIRE_MAP, map);
216 oxygen_write8(chip, OXYGEN_2WIRE_DATA, data);
217 oxygen_write8(chip, OXYGEN_2WIRE_CONTROL,
218 device | OXYGEN_2WIRE_DIR_WRITE);
219}
220EXPORT_SYMBOL(oxygen_write_i2c);
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 78c21155218e..897697d43506 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -221,7 +221,8 @@ static void oxygen_init(struct oxygen *chip)
221 221
222 chip->dac_routing = 1; 222 chip->dac_routing = 1;
223 for (i = 0; i < 8; ++i) 223 for (i = 0; i < 8; ++i)
224 chip->dac_volume[i] = 0xff; 224 chip->dac_volume[i] = chip->model->dac_volume_min;
225 chip->dac_mute = 1;
225 chip->spdif_playback_enable = 1; 226 chip->spdif_playback_enable = 1;
226 chip->spdif_bits = OXYGEN_SPDIF_C | OXYGEN_SPDIF_ORIGINAL | 227 chip->spdif_bits = OXYGEN_SPDIF_C | OXYGEN_SPDIF_ORIGINAL |
227 (IEC958_AES1_CON_PCM_CODER << OXYGEN_SPDIF_CATEGORY_SHIFT); 228 (IEC958_AES1_CON_PCM_CODER << OXYGEN_SPDIF_CATEGORY_SHIFT);
@@ -240,12 +241,12 @@ static void oxygen_init(struct oxygen *chip)
240 chip->has_ac97_0 = (i & OXYGEN_AC97_CODEC_0) != 0; 241 chip->has_ac97_0 = (i & OXYGEN_AC97_CODEC_0) != 0;
241 chip->has_ac97_1 = (i & OXYGEN_AC97_CODEC_1) != 0; 242 chip->has_ac97_1 = (i & OXYGEN_AC97_CODEC_1) != 0;
242 243
243 oxygen_set_bits8(chip, OXYGEN_FUNCTION,
244 OXYGEN_FUNCTION_RESET_CODEC |
245 chip->model->function_flags);
246 oxygen_write8_masked(chip, OXYGEN_FUNCTION, 244 oxygen_write8_masked(chip, OXYGEN_FUNCTION,
247 OXYGEN_FUNCTION_SPI, 245 OXYGEN_FUNCTION_RESET_CODEC |
248 OXYGEN_FUNCTION_2WIRE_SPI_MASK); 246 chip->model->function_flags,
247 OXYGEN_FUNCTION_RESET_CODEC |
248 OXYGEN_FUNCTION_2WIRE_SPI_MASK |
249 OXYGEN_FUNCTION_ENABLE_SPI_4_5);
249 oxygen_write8(chip, OXYGEN_DMA_STATUS, 0); 250 oxygen_write8(chip, OXYGEN_DMA_STATUS, 0);
250 oxygen_write8(chip, OXYGEN_DMA_PAUSE, 0); 251 oxygen_write8(chip, OXYGEN_DMA_PAUSE, 0);
251 oxygen_write8(chip, OXYGEN_PLAY_CHANNELS, 252 oxygen_write8(chip, OXYGEN_PLAY_CHANNELS,
@@ -253,11 +254,13 @@ static void oxygen_init(struct oxygen *chip)
253 OXYGEN_DMA_A_BURST_8 | 254 OXYGEN_DMA_A_BURST_8 |
254 OXYGEN_DMA_MULTICH_BURST_8); 255 OXYGEN_DMA_MULTICH_BURST_8);
255 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0); 256 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
256 oxygen_write8_masked(chip, OXYGEN_MISC, 0, 257 oxygen_write8_masked(chip, OXYGEN_MISC,
258 chip->model->misc_flags,
257 OXYGEN_MISC_WRITE_PCI_SUBID | 259 OXYGEN_MISC_WRITE_PCI_SUBID |
258 OXYGEN_MISC_REC_C_FROM_SPDIF | 260 OXYGEN_MISC_REC_C_FROM_SPDIF |
259 OXYGEN_MISC_REC_B_FROM_AC97 | 261 OXYGEN_MISC_REC_B_FROM_AC97 |
260 OXYGEN_MISC_REC_A_FROM_MULTICH); 262 OXYGEN_MISC_REC_A_FROM_MULTICH |
263 OXYGEN_MISC_MIDI);
261 oxygen_write8(chip, OXYGEN_REC_FORMAT, 264 oxygen_write8(chip, OXYGEN_REC_FORMAT,
262 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_A_SHIFT) | 265 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_A_SHIFT) |
263 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_B_SHIFT) | 266 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_B_SHIFT) |
@@ -267,35 +270,49 @@ static void oxygen_init(struct oxygen *chip)
267 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT)); 270 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT));
268 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2); 271 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2);
269 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT, 272 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT,
270 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST | 273 OXYGEN_RATE_48000 | chip->model->dac_i2s_format |
271 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | 274 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
272 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
273 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
274 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST |
275 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
276 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
277 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
278 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST |
279 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
280 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 275 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
276 if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1)
277 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
278 OXYGEN_RATE_48000 | chip->model->adc_i2s_format |
279 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
280 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
281 else
282 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
283 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
284 if (chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_2 |
285 CAPTURE_2_FROM_I2S_2))
286 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
287 OXYGEN_RATE_48000 | chip->model->adc_i2s_format |
288 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
289 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
290 else
291 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
292 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
281 oxygen_write16(chip, OXYGEN_I2S_C_FORMAT, 293 oxygen_write16(chip, OXYGEN_I2S_C_FORMAT,
282 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST | 294 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
283 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | 295 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
284 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 296 OXYGEN_SPDIF_OUT_ENABLE |
285 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL, 297 OXYGEN_SPDIF_LOOPBACK);
286 OXYGEN_SPDIF_SENSE_MASK | 298 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF)
287 OXYGEN_SPDIF_LOCK_MASK | 299 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL,
288 OXYGEN_SPDIF_RATE_MASK | 300 OXYGEN_SPDIF_SENSE_MASK |
289 OXYGEN_SPDIF_LOCK_PAR | 301 OXYGEN_SPDIF_LOCK_MASK |
290 OXYGEN_SPDIF_IN_CLOCK_96, 302 OXYGEN_SPDIF_RATE_MASK |
291 OXYGEN_SPDIF_OUT_ENABLE | 303 OXYGEN_SPDIF_LOCK_PAR |
292 OXYGEN_SPDIF_LOOPBACK | 304 OXYGEN_SPDIF_IN_CLOCK_96,
293 OXYGEN_SPDIF_SENSE_MASK | 305 OXYGEN_SPDIF_SENSE_MASK |
294 OXYGEN_SPDIF_LOCK_MASK | 306 OXYGEN_SPDIF_LOCK_MASK |
295 OXYGEN_SPDIF_RATE_MASK | 307 OXYGEN_SPDIF_RATE_MASK |
296 OXYGEN_SPDIF_SENSE_PAR | 308 OXYGEN_SPDIF_SENSE_PAR |
297 OXYGEN_SPDIF_LOCK_PAR | 309 OXYGEN_SPDIF_LOCK_PAR |
298 OXYGEN_SPDIF_IN_CLOCK_MASK); 310 OXYGEN_SPDIF_IN_CLOCK_MASK);
311 else
312 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
313 OXYGEN_SPDIF_SENSE_MASK |
314 OXYGEN_SPDIF_LOCK_MASK |
315 OXYGEN_SPDIF_RATE_MASK);
299 oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, chip->spdif_bits); 316 oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, chip->spdif_bits);
300 oxygen_clear_bits8(chip, OXYGEN_MPU401_CONTROL, OXYGEN_MPU401_LOOPBACK); 317 oxygen_clear_bits8(chip, OXYGEN_MPU401_CONTROL, OXYGEN_MPU401_LOOPBACK);
301 oxygen_write8(chip, OXYGEN_GPI_INTERRUPT_MASK, 0); 318 oxygen_write8(chip, OXYGEN_GPI_INTERRUPT_MASK, 0);
@@ -318,9 +335,12 @@ static void oxygen_init(struct oxygen *chip)
318 (2 << OXYGEN_A_MONITOR_ROUTE_2_SHIFT) | 335 (2 << OXYGEN_A_MONITOR_ROUTE_2_SHIFT) |
319 (3 << OXYGEN_A_MONITOR_ROUTE_3_SHIFT)); 336 (3 << OXYGEN_A_MONITOR_ROUTE_3_SHIFT));
320 337
321 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK, 338 if (chip->has_ac97_0 | chip->has_ac97_1)
322 OXYGEN_AC97_INT_READ_DONE | 339 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK,
323 OXYGEN_AC97_INT_WRITE_DONE); 340 OXYGEN_AC97_INT_READ_DONE |
341 OXYGEN_AC97_INT_WRITE_DONE);
342 else
343 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK, 0);
324 oxygen_write32(chip, OXYGEN_AC97_OUT_CONFIG, 0); 344 oxygen_write32(chip, OXYGEN_AC97_OUT_CONFIG, 0);
325 oxygen_write32(chip, OXYGEN_AC97_IN_CONFIG, 0); 345 oxygen_write32(chip, OXYGEN_AC97_IN_CONFIG, 0);
326 if (!(chip->has_ac97_0 | chip->has_ac97_1)) 346 if (!(chip->has_ac97_0 | chip->has_ac97_1))
@@ -351,6 +371,8 @@ static void oxygen_init(struct oxygen *chip)
351 oxygen_write_ac97(chip, 0, AC97_REC_GAIN, 0x8000); 371 oxygen_write_ac97(chip, 0, AC97_REC_GAIN, 0x8000);
352 oxygen_write_ac97(chip, 0, AC97_CENTER_LFE_MASTER, 0x8080); 372 oxygen_write_ac97(chip, 0, AC97_CENTER_LFE_MASTER, 0x8080);
353 oxygen_write_ac97(chip, 0, AC97_SURROUND_MASTER, 0x8080); 373 oxygen_write_ac97(chip, 0, AC97_SURROUND_MASTER, 0x8080);
374 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS,
375 CM9780_GPO0);
354 /* power down unused ADCs and DACs */ 376 /* power down unused ADCs and DACs */
355 oxygen_ac97_set_bits(chip, 0, AC97_POWERDOWN, 377 oxygen_ac97_set_bits(chip, 0, AC97_POWERDOWN,
356 AC97_PD_PR0 | AC97_PD_PR1); 378 AC97_PD_PR0 | AC97_PD_PR1);
@@ -388,10 +410,8 @@ static void oxygen_card_free(struct snd_card *card)
388 oxygen_write16(chip, OXYGEN_DMA_STATUS, 0); 410 oxygen_write16(chip, OXYGEN_DMA_STATUS, 0);
389 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0); 411 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
390 spin_unlock_irq(&chip->reg_lock); 412 spin_unlock_irq(&chip->reg_lock);
391 if (chip->irq >= 0) { 413 if (chip->irq >= 0)
392 free_irq(chip->irq, chip); 414 free_irq(chip->irq, chip);
393 synchronize_irq(chip->irq);
394 }
395 flush_scheduled_work(); 415 flush_scheduled_work();
396 chip->model->cleanup(chip); 416 chip->model->cleanup(chip);
397 mutex_destroy(&chip->mutex); 417 mutex_destroy(&chip->mutex);
@@ -400,7 +420,7 @@ static void oxygen_card_free(struct snd_card *card)
400} 420}
401 421
402int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, 422int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
403 int midi, const struct oxygen_model *model) 423 const struct oxygen_model *model)
404{ 424{
405 struct snd_card *card; 425 struct snd_card *card;
406 struct oxygen *chip; 426 struct oxygen *chip;
@@ -472,9 +492,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
472 if (err < 0) 492 if (err < 0)
473 goto err_card; 493 goto err_card;
474 494
475 oxygen_write8_masked(chip, OXYGEN_MISC, 495 if (model->misc_flags & OXYGEN_MISC_MIDI) {
476 midi ? OXYGEN_MISC_MIDI : 0, OXYGEN_MISC_MIDI);
477 if (midi) {
478 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 496 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
479 chip->addr + OXYGEN_MPU401, 497 chip->addr + OXYGEN_MPU401,
480 MPU401_INFO_INTEGRATED, 0, 0, 498 MPU401_INFO_INTEGRATED, 0, 0,
@@ -486,7 +504,10 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
486 oxygen_proc_init(chip); 504 oxygen_proc_init(chip);
487 505
488 spin_lock_irq(&chip->reg_lock); 506 spin_lock_irq(&chip->reg_lock);
489 chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_DETECT | OXYGEN_INT_AC97; 507 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF)
508 chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_DETECT;
509 if (chip->has_ac97_0 | chip->has_ac97_1)
510 chip->interrupt_mask |= OXYGEN_INT_AC97;
490 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); 511 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
491 spin_unlock_irq(&chip->reg_lock); 512 spin_unlock_irq(&chip->reg_lock);
492 513
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index a8e4623415d9..cc0cddadd589 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -32,8 +32,8 @@ static int dac_volume_info(struct snd_kcontrol *ctl,
32 32
33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
34 info->count = chip->model->dac_channels; 34 info->count = chip->model->dac_channels;
35 info->value.integer.min = 0; 35 info->value.integer.min = chip->model->dac_volume_min;
36 info->value.integer.max = 0xff; 36 info->value.integer.max = chip->model->dac_volume_max;
37 return 0; 37 return 0;
38} 38}
39 39
@@ -446,6 +446,50 @@ static int spdif_loopback_put(struct snd_kcontrol *ctl,
446 return changed; 446 return changed;
447} 447}
448 448
449static int monitor_volume_info(struct snd_kcontrol *ctl,
450 struct snd_ctl_elem_info *info)
451{
452 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
453 info->count = 1;
454 info->value.integer.min = 0;
455 info->value.integer.max = 1;
456 return 0;
457}
458
459static int monitor_get(struct snd_kcontrol *ctl,
460 struct snd_ctl_elem_value *value)
461{
462 struct oxygen *chip = ctl->private_data;
463 u8 bit = ctl->private_value;
464 int invert = ctl->private_value & (1 << 8);
465
466 value->value.integer.value[0] =
467 !!invert ^ !!(oxygen_read8(chip, OXYGEN_ADC_MONITOR) & bit);
468 return 0;
469}
470
471static int monitor_put(struct snd_kcontrol *ctl,
472 struct snd_ctl_elem_value *value)
473{
474 struct oxygen *chip = ctl->private_data;
475 u8 bit = ctl->private_value;
476 int invert = ctl->private_value & (1 << 8);
477 u8 oldreg, newreg;
478 int changed;
479
480 spin_lock_irq(&chip->reg_lock);
481 oldreg = oxygen_read8(chip, OXYGEN_ADC_MONITOR);
482 if ((!!value->value.integer.value[0] ^ !!invert) != 0)
483 newreg = oldreg | bit;
484 else
485 newreg = oldreg & ~bit;
486 changed = newreg != oldreg;
487 if (changed)
488 oxygen_write8(chip, OXYGEN_ADC_MONITOR, newreg);
489 spin_unlock_irq(&chip->reg_lock);
490 return changed;
491}
492
449static int ac97_switch_get(struct snd_kcontrol *ctl, 493static int ac97_switch_get(struct snd_kcontrol *ctl,
450 struct snd_ctl_elem_value *value) 494 struct snd_ctl_elem_value *value)
451{ 495{
@@ -466,6 +510,21 @@ static int ac97_switch_get(struct snd_kcontrol *ctl,
466 return 0; 510 return 0;
467} 511}
468 512
513static void mute_ac97_ctl(struct oxygen *chip, unsigned int control)
514{
515 unsigned int priv_idx = chip->controls[control]->private_value & 0xff;
516 u16 value;
517
518 value = oxygen_read_ac97(chip, 0, priv_idx);
519 if (!(value & 0x8000)) {
520 oxygen_write_ac97(chip, 0, priv_idx, value | 0x8000);
521 if (chip->model->ac97_switch)
522 chip->model->ac97_switch(chip, priv_idx, 0x8000);
523 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
524 &chip->controls[control]->id);
525 }
526}
527
469static int ac97_switch_put(struct snd_kcontrol *ctl, 528static int ac97_switch_put(struct snd_kcontrol *ctl,
470 struct snd_ctl_elem_value *value) 529 struct snd_ctl_elem_value *value)
471{ 530{
@@ -487,9 +546,24 @@ static int ac97_switch_put(struct snd_kcontrol *ctl,
487 change = newreg != oldreg; 546 change = newreg != oldreg;
488 if (change) { 547 if (change) {
489 oxygen_write_ac97(chip, codec, index, newreg); 548 oxygen_write_ac97(chip, codec, index, newreg);
490 if (bitnr == 15 && chip->model->ac97_switch_hook) 549 if (codec == 0 && chip->model->ac97_switch)
491 chip->model->ac97_switch_hook(chip, codec, index, 550 chip->model->ac97_switch(chip, index, newreg & 0x8000);
492 newreg & 0x8000); 551 if (index == AC97_LINE) {
552 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
553 newreg & 0x8000 ?
554 CM9780_GPO0 : 0, CM9780_GPO0);
555 if (!(newreg & 0x8000)) {
556 mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
557 mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
558 mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
559 }
560 } else if ((index == AC97_MIC || index == AC97_CD ||
561 index == AC97_VIDEO || index == AC97_AUX) &&
562 bitnr == 15 && !(newreg & 0x8000)) {
563 mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
564 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
565 CM9780_GPO0, CM9780_GPO0);
566 }
493 } 567 }
494 mutex_unlock(&chip->mutex); 568 mutex_unlock(&chip->mutex);
495 return change; 569 return change;
@@ -608,6 +682,7 @@ static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl,
608 .private_value = ((codec) << 24) | (index), \ 682 .private_value = ((codec) << 24) | (index), \
609 } 683 }
610 684
685static DECLARE_TLV_DB_SCALE(monitor_db_scale, -1000, 1000, 0);
611static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0); 686static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0);
612static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0); 687static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0);
613 688
@@ -667,6 +742,9 @@ static const struct snd_kcontrol_new controls[] = {
667 .get = spdif_pcm_get, 742 .get = spdif_pcm_get,
668 .put = spdif_pcm_put, 743 .put = spdif_pcm_put,
669 }, 744 },
745};
746
747static const struct snd_kcontrol_new spdif_input_controls[] = {
670 { 748 {
671 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 749 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
672 .device = 1, 750 .device = 1,
@@ -692,11 +770,118 @@ static const struct snd_kcontrol_new controls[] = {
692 }, 770 },
693}; 771};
694 772
773static const struct {
774 unsigned int pcm_dev;
775 struct snd_kcontrol_new controls[2];
776} monitor_controls[] = {
777 {
778 .pcm_dev = CAPTURE_0_FROM_I2S_1,
779 .controls = {
780 {
781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
782 .name = "Analog Input Monitor Switch",
783 .info = snd_ctl_boolean_mono_info,
784 .get = monitor_get,
785 .put = monitor_put,
786 .private_value = OXYGEN_ADC_MONITOR_A,
787 },
788 {
789 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
790 .name = "Analog Input Monitor Volume",
791 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
792 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
793 .info = monitor_volume_info,
794 .get = monitor_get,
795 .put = monitor_put,
796 .private_value = OXYGEN_ADC_MONITOR_A_HALF_VOL
797 | (1 << 8),
798 .tlv = { .p = monitor_db_scale, },
799 },
800 },
801 },
802 {
803 .pcm_dev = CAPTURE_0_FROM_I2S_2,
804 .controls = {
805 {
806 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
807 .name = "Analog Input Monitor Switch",
808 .info = snd_ctl_boolean_mono_info,
809 .get = monitor_get,
810 .put = monitor_put,
811 .private_value = OXYGEN_ADC_MONITOR_B,
812 },
813 {
814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815 .name = "Analog Input Monitor Volume",
816 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
817 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
818 .info = monitor_volume_info,
819 .get = monitor_get,
820 .put = monitor_put,
821 .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL
822 | (1 << 8),
823 .tlv = { .p = monitor_db_scale, },
824 },
825 },
826 },
827 {
828 .pcm_dev = CAPTURE_2_FROM_I2S_2,
829 .controls = {
830 {
831 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
832 .name = "Analog Input Monitor Switch",
833 .index = 1,
834 .info = snd_ctl_boolean_mono_info,
835 .get = monitor_get,
836 .put = monitor_put,
837 .private_value = OXYGEN_ADC_MONITOR_B,
838 },
839 {
840 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
841 .name = "Analog Input Monitor Volume",
842 .index = 1,
843 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
844 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
845 .info = monitor_volume_info,
846 .get = monitor_get,
847 .put = monitor_put,
848 .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL
849 | (1 << 8),
850 .tlv = { .p = monitor_db_scale, },
851 },
852 },
853 },
854 {
855 .pcm_dev = CAPTURE_1_FROM_SPDIF,
856 .controls = {
857 {
858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
859 .name = "Digital Input Monitor Switch",
860 .info = snd_ctl_boolean_mono_info,
861 .get = monitor_get,
862 .put = monitor_put,
863 .private_value = OXYGEN_ADC_MONITOR_C,
864 },
865 {
866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
867 .name = "Digital Input Monitor Volume",
868 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
869 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
870 .info = monitor_volume_info,
871 .get = monitor_get,
872 .put = monitor_put,
873 .private_value = OXYGEN_ADC_MONITOR_C_HALF_VOL
874 | (1 << 8),
875 .tlv = { .p = monitor_db_scale, },
876 },
877 },
878 },
879};
880
695static const struct snd_kcontrol_new ac97_controls[] = { 881static const struct snd_kcontrol_new ac97_controls[] = {
696 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC), 882 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC),
697 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1), 883 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1),
698 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0), 884 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0),
699 AC97_VOLUME("Line Capture Volume", 0, AC97_LINE),
700 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1), 885 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1),
701 AC97_VOLUME("CD Capture Volume", 0, AC97_CD), 886 AC97_VOLUME("CD Capture Volume", 0, AC97_CD),
702 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1), 887 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1),
@@ -756,6 +941,11 @@ static int add_controls(struct oxygen *chip,
756 return err; 941 return err;
757 if (err == 1) 942 if (err == 1)
758 continue; 943 continue;
944 if (!strcmp(template.name, "Master Playback Volume") &&
945 chip->model->dac_tlv) {
946 template.tlv.p = chip->model->dac_tlv;
947 template.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
948 }
759 ctl = snd_ctl_new1(&template, chip); 949 ctl = snd_ctl_new1(&template, chip);
760 if (!ctl) 950 if (!ctl)
761 return -ENOMEM; 951 return -ENOMEM;
@@ -773,11 +963,26 @@ static int add_controls(struct oxygen *chip,
773 963
774int oxygen_mixer_init(struct oxygen *chip) 964int oxygen_mixer_init(struct oxygen *chip)
775{ 965{
966 unsigned int i;
776 int err; 967 int err;
777 968
778 err = add_controls(chip, controls, ARRAY_SIZE(controls)); 969 err = add_controls(chip, controls, ARRAY_SIZE(controls));
779 if (err < 0) 970 if (err < 0)
780 return err; 971 return err;
972 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF) {
973 err = add_controls(chip, spdif_input_controls,
974 ARRAY_SIZE(spdif_input_controls));
975 if (err < 0)
976 return err;
977 }
978 for (i = 0; i < ARRAY_SIZE(monitor_controls); ++i) {
979 if (!(chip->model->pcm_dev_cfg & monitor_controls[i].pcm_dev))
980 continue;
981 err = add_controls(chip, monitor_controls[i].controls,
982 ARRAY_SIZE(monitor_controls[i].controls));
983 if (err < 0)
984 return err;
985 }
781 if (chip->has_ac97_0) { 986 if (chip->has_ac97_0) {
782 err = add_controls(chip, ac97_controls, 987 err = add_controls(chip, ac97_controls,
783 ARRAY_SIZE(ac97_controls)); 988 ARRAY_SIZE(ac97_controls));
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index b70046aca657..b17c405e069d 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -119,7 +119,7 @@ static int oxygen_open(struct snd_pcm_substream *substream,
119 119
120 runtime->private_data = (void *)(uintptr_t)channel; 120 runtime->private_data = (void *)(uintptr_t)channel;
121 if (channel == PCM_B && chip->has_ac97_1 && 121 if (channel == PCM_B && chip->has_ac97_1 &&
122 (chip->model->used_channels & OXYGEN_CHANNEL_AC97)) 122 (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1))
123 runtime->hw = oxygen_ac97_hardware; 123 runtime->hw = oxygen_ac97_hardware;
124 else 124 else
125 runtime->hw = *oxygen_hardware[channel]; 125 runtime->hw = *oxygen_hardware[channel];
@@ -365,7 +365,7 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
365 return err; 365 return err;
366 366
367 is_ac97 = chip->has_ac97_1 && 367 is_ac97 = chip->has_ac97_1 &&
368 (chip->model->used_channels & OXYGEN_CHANNEL_AC97); 368 (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1);
369 369
370 spin_lock_irq(&chip->reg_lock); 370 spin_lock_irq(&chip->reg_lock);
371 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, 371 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT,
@@ -640,34 +640,39 @@ int oxygen_pcm_init(struct oxygen *chip)
640 int outs, ins; 640 int outs, ins;
641 int err; 641 int err;
642 642
643 outs = 1; /* OXYGEN_CHANNEL_MULTICH is always used */ 643 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_0_TO_I2S);
644 ins = !!(chip->model->used_channels & (OXYGEN_CHANNEL_A | 644 ins = !!(chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_1 |
645 OXYGEN_CHANNEL_B)); 645 CAPTURE_0_FROM_I2S_2));
646 err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm); 646 if (outs | ins) {
647 if (err < 0) 647 err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm);
648 return err; 648 if (err < 0)
649 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &oxygen_multich_ops); 649 return err;
650 if (chip->model->used_channels & OXYGEN_CHANNEL_A) 650 if (outs)
651 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 651 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
652 &oxygen_rec_a_ops); 652 &oxygen_multich_ops);
653 else if (chip->model->used_channels & OXYGEN_CHANNEL_B) 653 if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1)
654 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 654 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
655 &oxygen_rec_b_ops); 655 &oxygen_rec_a_ops);
656 pcm->private_data = chip; 656 else if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_2)
657 pcm->private_free = oxygen_pcm_free; 657 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
658 strcpy(pcm->name, "Analog"); 658 &oxygen_rec_b_ops);
659 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, 659 pcm->private_data = chip;
660 SNDRV_DMA_TYPE_DEV, 660 pcm->private_free = oxygen_pcm_free;
661 snd_dma_pci_data(chip->pci), 661 strcpy(pcm->name, "Analog");
662 512 * 1024, 2048 * 1024); 662 if (outs)
663 if (ins) 663 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
664 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, 664 SNDRV_DMA_TYPE_DEV,
665 SNDRV_DMA_TYPE_DEV, 665 snd_dma_pci_data(chip->pci),
666 snd_dma_pci_data(chip->pci), 666 512 * 1024, 2048 * 1024);
667 128 * 1024, 256 * 1024); 667 if (ins)
668 668 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
669 outs = !!(chip->model->used_channels & OXYGEN_CHANNEL_SPDIF); 669 SNDRV_DMA_TYPE_DEV,
670 ins = !!(chip->model->used_channels & OXYGEN_CHANNEL_C); 670 snd_dma_pci_data(chip->pci),
671 128 * 1024, 256 * 1024);
672 }
673
674 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_1_TO_SPDIF);
675 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF);
671 if (outs | ins) { 676 if (outs | ins) {
672 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm); 677 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm);
673 if (err < 0) 678 if (err < 0)
@@ -686,12 +691,13 @@ int oxygen_pcm_init(struct oxygen *chip)
686 128 * 1024, 256 * 1024); 691 128 * 1024, 256 * 1024);
687 } 692 }
688 693
689 outs = chip->has_ac97_1 && 694 if (chip->has_ac97_1) {
690 (chip->model->used_channels & OXYGEN_CHANNEL_AC97); 695 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_2_TO_AC97_1);
691 ins = outs || 696 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1);
692 (chip->model->used_channels & (OXYGEN_CHANNEL_A | 697 } else {
693 OXYGEN_CHANNEL_B)) 698 outs = 0;
694 == (OXYGEN_CHANNEL_A | OXYGEN_CHANNEL_B); 699 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_I2S_2);
700 }
695 if (outs | ins) { 701 if (outs | ins) {
696 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2", 702 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2",
697 2, outs, ins, &pcm); 703 2, outs, ins, &pcm);
diff --git a/sound/pci/oxygen/pcm1796.h b/sound/pci/oxygen/pcm1796.h
new file mode 100644
index 000000000000..698bf46c710c
--- /dev/null
+++ b/sound/pci/oxygen/pcm1796.h
@@ -0,0 +1,58 @@
1#ifndef PCM1796_H_INCLUDED
2#define PCM1796_H_INCLUDED
3
4/* register 16 */
5#define PCM1796_ATL_MASK 0xff
6/* register 17 */
7#define PCM1796_ATR_MASK 0xff
8/* register 18 */
9#define PCM1796_MUTE 0x01
10#define PCM1796_DME 0x02
11#define PCM1796_DMF_MASK 0x0c
12#define PCM1796_DMF_DISABLED 0x00
13#define PCM1796_DMF_48 0x04
14#define PCM1796_DMF_441 0x08
15#define PCM1796_DMF_32 0x0c
16#define PCM1796_FMT_MASK 0x70
17#define PCM1796_FMT_16_RJUST 0x00
18#define PCM1796_FMT_20_RJUST 0x10
19#define PCM1796_FMT_24_RJUST 0x20
20#define PCM1796_FMT_24_LJUST 0x30
21#define PCM1796_FMT_16_I2S 0x40
22#define PCM1796_FMT_24_I2S 0x50
23#define PCM1796_ATLD 0x80
24/* register 19 */
25#define PCM1796_INZD 0x01
26#define PCM1796_FLT_MASK 0x02
27#define PCM1796_FLT_SHARP 0x00
28#define PCM1796_FLT_SLOW 0x02
29#define PCM1796_DFMS 0x04
30#define PCM1796_OPE 0x10
31#define PCM1796_ATS_MASK 0x60
32#define PCM1796_ATS_1 0x00
33#define PCM1796_ATS_2 0x20
34#define PCM1796_ATS_4 0x40
35#define PCM1796_ATS_8 0x60
36#define PCM1796_REV 0x80
37/* register 20 */
38#define PCM1796_OS_MASK 0x03
39#define PCM1796_OS_64 0x00
40#define PCM1796_OS_32 0x01
41#define PCM1796_OS_128 0x02
42#define PCM1796_CHSL_MASK 0x04
43#define PCM1796_CHSL_LEFT 0x00
44#define PCM1796_CHSL_RIGHT 0x04
45#define PCM1796_MONO 0x08
46#define PCM1796_DFTH 0x10
47#define PCM1796_DSD 0x20
48#define PCM1796_SRST 0x40
49/* register 21 */
50#define PCM1796_PCMZ 0x01
51#define PCM1796_DZ_MASK 0x06
52/* register 22 */
53#define PCM1796_ZFGL 0x01
54#define PCM1796_ZFGR 0x02
55/* register 23 */
56#define PCM1796_ID_MASK 0x1f
57
58#endif
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index d163397b85cc..7f84fa5deca2 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -18,6 +18,9 @@
18 */ 18 */
19 19
20/* 20/*
21 * Xonar D2/D2X
22 * ------------
23 *
21 * CMI8788: 24 * CMI8788:
22 * 25 *
23 * SPI 0 -> 1st PCM1796 (front) 26 * SPI 0 -> 1st PCM1796 (front)
@@ -30,10 +33,33 @@
30 * GPIO 5 <- external power present (D2X only) 33 * GPIO 5 <- external power present (D2X only)
31 * GPIO 7 -> ALT 34 * GPIO 7 -> ALT
32 * GPIO 8 -> enable output to speakers 35 * GPIO 8 -> enable output to speakers
36 */
37
38/*
39 * Xonar DX
40 * --------
41 *
42 * CMI8788:
43 *
44 * I²C <-> CS4398 (front)
45 * <-> CS4362A (surround, center/LFE, back)
46 *
47 * GPI 0 <- external power present
33 * 48 *
34 * CM9780: 49 * GPIO 0 -> enable output to speakers
50 * GPIO 1 -> enable front panel I/O
51 * GPIO 2 -> M0 of CS5361
52 * GPIO 3 -> M1 of CS5361
53 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
35 * 54 *
36 * GPIO 0 -> enable AC'97 bypass (line in -> ADC) 55 * CS4398:
56 *
57 * AD0 <- 1
58 * AD1 <- 1
59 *
60 * CS4362A:
61 *
62 * AD0 <- 0
37 */ 63 */
38 64
39#include <linux/pci.h> 65#include <linux/pci.h>
@@ -47,11 +73,14 @@
47#include <sound/tlv.h> 73#include <sound/tlv.h>
48#include "oxygen.h" 74#include "oxygen.h"
49#include "cm9780.h" 75#include "cm9780.h"
76#include "pcm1796.h"
77#include "cs4398.h"
78#include "cs4362a.h"
50 79
51MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 80MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
52MODULE_DESCRIPTION("Asus AV200 driver"); 81MODULE_DESCRIPTION("Asus AVx00 driver");
53MODULE_LICENSE("GPL"); 82MODULE_LICENSE("GPL");
54MODULE_SUPPORTED_DEVICE("{{Asus,AV200}}"); 83MODULE_SUPPORTED_DEVICE("{{Asus,AV100},{Asus,AV200}}");
55 84
56static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 85static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
57static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 86static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
@@ -64,80 +93,44 @@ MODULE_PARM_DESC(id, "ID string");
64module_param_array(enable, bool, NULL, 0444); 93module_param_array(enable, bool, NULL, 0444);
65MODULE_PARM_DESC(enable, "enable card"); 94MODULE_PARM_DESC(enable, "enable card");
66 95
96enum {
97 MODEL_D2,
98 MODEL_D2X,
99 MODEL_DX,
100};
101
67static struct pci_device_id xonar_ids[] __devinitdata = { 102static struct pci_device_id xonar_ids[] __devinitdata = {
68 { OXYGEN_PCI_SUBID(0x1043, 0x8269) }, /* Asus Xonar D2 */ 103 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 },
69 { OXYGEN_PCI_SUBID(0x1043, 0x82b7) }, /* Asus Xonar D2X */ 104 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX },
105 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
70 { } 106 { }
71}; 107};
72MODULE_DEVICE_TABLE(pci, xonar_ids); 108MODULE_DEVICE_TABLE(pci, xonar_ids);
73 109
74 110
75#define GPIO_CS5381_M_MASK 0x000c 111#define GPIO_CS53x1_M_MASK 0x000c
76#define GPIO_CS5381_M_SINGLE 0x0000 112#define GPIO_CS53x1_M_SINGLE 0x0000
77#define GPIO_CS5381_M_DOUBLE 0x0004 113#define GPIO_CS53x1_M_DOUBLE 0x0004
78#define GPIO_CS5381_M_QUAD 0x0008 114#define GPIO_CS53x1_M_QUAD 0x0008
79#define GPIO_EXT_POWER 0x0020 115
80#define GPIO_ALT 0x0080 116#define GPIO_D2X_EXT_POWER 0x0020
81#define GPIO_OUTPUT_ENABLE 0x0100 117#define GPIO_D2_ALT 0x0080
82 118#define GPIO_D2_OUTPUT_ENABLE 0x0100
83#define GPIO_LINE_MUTE CM9780_GPO0 119
84 120#define GPI_DX_EXT_POWER 0x01
85/* register 16 */ 121#define GPIO_DX_OUTPUT_ENABLE 0x0001
86#define PCM1796_ATL_MASK 0xff 122#define GPIO_DX_FRONT_PANEL 0x0002
87/* register 17 */ 123#define GPIO_DX_INPUT_ROUTE 0x0100
88#define PCM1796_ATR_MASK 0xff 124
89/* register 18 */ 125#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
90#define PCM1796_MUTE 0x01 126#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
91#define PCM1796_DME 0x02
92#define PCM1796_DMF_MASK 0x0c
93#define PCM1796_DMF_DISABLED 0x00
94#define PCM1796_DMF_48 0x04
95#define PCM1796_DMF_441 0x08
96#define PCM1796_DMF_32 0x0c
97#define PCM1796_FMT_MASK 0x70
98#define PCM1796_FMT_16_RJUST 0x00
99#define PCM1796_FMT_20_RJUST 0x10
100#define PCM1796_FMT_24_RJUST 0x20
101#define PCM1796_FMT_24_LJUST 0x30
102#define PCM1796_FMT_16_I2S 0x40
103#define PCM1796_FMT_24_I2S 0x50
104#define PCM1796_ATLD 0x80
105/* register 19 */
106#define PCM1796_INZD 0x01
107#define PCM1796_FLT_MASK 0x02
108#define PCM1796_FLT_SHARP 0x00
109#define PCM1796_FLT_SLOW 0x02
110#define PCM1796_DFMS 0x04
111#define PCM1796_OPE 0x10
112#define PCM1796_ATS_MASK 0x60
113#define PCM1796_ATS_1 0x00
114#define PCM1796_ATS_2 0x20
115#define PCM1796_ATS_4 0x40
116#define PCM1796_ATS_8 0x60
117#define PCM1796_REV 0x80
118/* register 20 */
119#define PCM1796_OS_MASK 0x03
120#define PCM1796_OS_64 0x00
121#define PCM1796_OS_32 0x01
122#define PCM1796_OS_128 0x02
123#define PCM1796_CHSL_MASK 0x04
124#define PCM1796_CHSL_LEFT 0x00
125#define PCM1796_CHSL_RIGHT 0x04
126#define PCM1796_MONO 0x08
127#define PCM1796_DFTH 0x10
128#define PCM1796_DSD 0x20
129#define PCM1796_SRST 0x40
130/* register 21 */
131#define PCM1796_PCMZ 0x01
132#define PCM1796_DZ_MASK 0x06
133/* register 22 */
134#define PCM1796_ZFGL 0x01
135#define PCM1796_ZFGR 0x02
136/* register 23 */
137#define PCM1796_ID_MASK 0x1f
138 127
139struct xonar_data { 128struct xonar_data {
140 u8 is_d2x; 129 unsigned int anti_pop_delay;
130 u16 output_enable_bit;
131 u8 ext_power_reg;
132 u8 ext_power_int_reg;
133 u8 ext_power_bit;
141 u8 has_power; 134 u8 has_power;
142}; 135};
143 136
@@ -156,62 +149,157 @@ static void pcm1796_write(struct oxygen *chip, unsigned int codec,
156 (reg << 8) | value); 149 (reg << 8) | value);
157} 150}
158 151
159static void xonar_init(struct oxygen *chip) 152static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
153{
154 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
155}
156
157static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
158{
159 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
160}
161
162static void xonar_common_init(struct oxygen *chip)
163{
164 struct xonar_data *data = chip->model_data;
165
166 if (data->ext_power_reg) {
167 oxygen_set_bits8(chip, data->ext_power_int_reg,
168 data->ext_power_bit);
169 chip->interrupt_mask |= OXYGEN_INT_GPIO;
170 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
171 & data->ext_power_bit);
172 }
173 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK);
174 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
175 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
176 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
177 msleep(data->anti_pop_delay);
178 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit);
179 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
180}
181
182static void xonar_d2_init(struct oxygen *chip)
160{ 183{
161 struct xonar_data *data = chip->model_data; 184 struct xonar_data *data = chip->model_data;
162 unsigned int i; 185 unsigned int i;
163 186
164 data->is_d2x = chip->pci->subsystem_device == 0x82b7; 187 data->anti_pop_delay = 300;
188 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
165 189
166 for (i = 0; i < 4; ++i) { 190 for (i = 0; i < 4; ++i) {
167 pcm1796_write(chip, i, 18, PCM1796_FMT_24_LJUST | PCM1796_ATLD); 191 pcm1796_write(chip, i, 18, PCM1796_MUTE | PCM1796_DMF_DISABLED |
192 PCM1796_FMT_24_LJUST | PCM1796_ATLD);
168 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); 193 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
169 pcm1796_write(chip, i, 20, PCM1796_OS_64); 194 pcm1796_write(chip, i, 20, PCM1796_OS_64);
170 pcm1796_write(chip, i, 21, 0); 195 pcm1796_write(chip, i, 21, 0);
171 pcm1796_write(chip, i, 16, 0xff); /* set ATL/ATR after ATLD */ 196 pcm1796_write(chip, i, 16, 0x0f); /* set ATL/ATR after ATLD */
172 pcm1796_write(chip, i, 17, 0xff); 197 pcm1796_write(chip, i, 17, 0x0f);
173 } 198 }
174 199
175 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, 200 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
176 GPIO_CS5381_M_MASK | GPIO_ALT); 201 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
177 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 202
178 GPIO_CS5381_M_SINGLE, 203 xonar_common_init(chip);
179 GPIO_CS5381_M_MASK | GPIO_ALT);
180 if (data->is_d2x) {
181 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
182 GPIO_EXT_POWER);
183 oxygen_set_bits16(chip, OXYGEN_GPIO_INTERRUPT_MASK,
184 GPIO_EXT_POWER);
185 chip->interrupt_mask |= OXYGEN_INT_GPIO;
186 data->has_power = !!(oxygen_read16(chip, OXYGEN_GPIO_DATA)
187 & GPIO_EXT_POWER);
188 }
189 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
190 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS, GPIO_LINE_MUTE);
191 msleep(300);
192 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_OUTPUT_ENABLE);
193 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_OUTPUT_ENABLE);
194 204
195 snd_component_add(chip->card, "PCM1796"); 205 snd_component_add(chip->card, "PCM1796");
196 snd_component_add(chip->card, "CS5381"); 206 snd_component_add(chip->card, "CS5381");
197} 207}
198 208
209static void xonar_d2x_init(struct oxygen *chip)
210{
211 struct xonar_data *data = chip->model_data;
212
213 data->ext_power_reg = OXYGEN_GPIO_DATA;
214 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
215 data->ext_power_bit = GPIO_D2X_EXT_POWER;
216 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
217 xonar_d2_init(chip);
218}
219
220static void xonar_dx_init(struct oxygen *chip)
221{
222 struct xonar_data *data = chip->model_data;
223
224 data->anti_pop_delay = 800;
225 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
226 data->ext_power_reg = OXYGEN_GPI_DATA;
227 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
228 data->ext_power_bit = GPI_DX_EXT_POWER;
229
230 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
231 OXYGEN_2WIRE_LENGTH_8 |
232 OXYGEN_2WIRE_INTERRUPT_MASK |
233 OXYGEN_2WIRE_SPEED_FAST);
234
235 /* set CPEN (control port mode) and power down */
236 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
237 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
238 /* configure */
239 cs4398_write(chip, 2, CS4398_FM_SINGLE |
240 CS4398_DEM_NONE | CS4398_DIF_LJUST);
241 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
242 cs4398_write(chip, 4, CS4398_MUTEP_LOW | CS4398_PAMUTE);
243 cs4398_write(chip, 5, 0xfe);
244 cs4398_write(chip, 6, 0xfe);
245 cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP |
246 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP);
247 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
248 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
249 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
250 cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE);
251 cs4362a_write(chip, 0x05, 0);
252 cs4362a_write(chip, 0x06, CS4362A_FM_SINGLE |
253 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
254 cs4362a_write(chip, 0x07, 0x7f | CS4362A_MUTE);
255 cs4362a_write(chip, 0x08, 0x7f | CS4362A_MUTE);
256 cs4362a_write(chip, 0x09, CS4362A_FM_SINGLE |
257 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
258 cs4362a_write(chip, 0x0a, 0x7f | CS4362A_MUTE);
259 cs4362a_write(chip, 0x0b, 0x7f | CS4362A_MUTE);
260 cs4362a_write(chip, 0x0c, CS4362A_FM_SINGLE |
261 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
262 cs4362a_write(chip, 0x0d, 0x7f | CS4362A_MUTE);
263 cs4362a_write(chip, 0x0e, 0x7f | CS4362A_MUTE);
264 /* clear power down */
265 cs4398_write(chip, 8, CS4398_CPEN);
266 cs4362a_write(chip, 0x01, CS4362A_CPEN);
267
268 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
269 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
270 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
271 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
272
273 xonar_common_init(chip);
274
275 snd_component_add(chip->card, "CS4398");
276 snd_component_add(chip->card, "CS4362A");
277 snd_component_add(chip->card, "CS5361");
278}
279
199static void xonar_cleanup(struct oxygen *chip) 280static void xonar_cleanup(struct oxygen *chip)
200{ 281{
201 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_OUTPUT_ENABLE); 282 struct xonar_data *data = chip->model_data;
283
284 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
285}
286
287static void xonar_dx_cleanup(struct oxygen *chip)
288{
289 xonar_cleanup(chip);
290 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
291 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
202} 292}
203 293
204static void set_pcm1796_params(struct oxygen *chip, 294static void set_pcm1796_params(struct oxygen *chip,
205 struct snd_pcm_hw_params *params) 295 struct snd_pcm_hw_params *params)
206{ 296{
207#if 0
208 unsigned int i; 297 unsigned int i;
209 u8 value; 298 u8 value;
210 299
211 value = params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64; 300 value = params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
212 for (i = 0; i < 4; ++i) 301 for (i = 0; i < 4; ++i)
213 pcm1796_write(chip, i, 20, value); 302 pcm1796_write(chip, i, 20, value);
214#endif
215} 303}
216 304
217static void update_pcm1796_volume(struct oxygen *chip) 305static void update_pcm1796_volume(struct oxygen *chip)
@@ -236,19 +324,73 @@ static void update_pcm1796_mute(struct oxygen *chip)
236 pcm1796_write(chip, i, 18, value); 324 pcm1796_write(chip, i, 18, value);
237} 325}
238 326
239static void set_cs5381_params(struct oxygen *chip, 327static void set_cs53x1_params(struct oxygen *chip,
240 struct snd_pcm_hw_params *params) 328 struct snd_pcm_hw_params *params)
241{ 329{
242 unsigned int value; 330 unsigned int value;
243 331
244 if (params_rate(params) <= 54000) 332 if (params_rate(params) <= 54000)
245 value = GPIO_CS5381_M_SINGLE; 333 value = GPIO_CS53x1_M_SINGLE;
246 else if (params_rate(params) <= 108000) 334 else if (params_rate(params) <= 108000)
247 value = GPIO_CS5381_M_DOUBLE; 335 value = GPIO_CS53x1_M_DOUBLE;
248 else 336 else
249 value = GPIO_CS5381_M_QUAD; 337 value = GPIO_CS53x1_M_QUAD;
250 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 338 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
251 value, GPIO_CS5381_M_MASK); 339 value, GPIO_CS53x1_M_MASK);
340}
341
342static void set_cs43xx_params(struct oxygen *chip,
343 struct snd_pcm_hw_params *params)
344{
345 u8 fm_cs4398, fm_cs4362a;
346
347 fm_cs4398 = CS4398_DEM_NONE | CS4398_DIF_LJUST;
348 fm_cs4362a = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
349 if (params_rate(params) <= 50000) {
350 fm_cs4398 |= CS4398_FM_SINGLE;
351 fm_cs4362a |= CS4362A_FM_SINGLE;
352 } else if (params_rate(params) <= 100000) {
353 fm_cs4398 |= CS4398_FM_DOUBLE;
354 fm_cs4362a |= CS4362A_FM_DOUBLE;
355 } else {
356 fm_cs4398 |= CS4398_FM_QUAD;
357 fm_cs4362a |= CS4362A_FM_QUAD;
358 }
359 cs4398_write(chip, 2, fm_cs4398);
360 cs4362a_write(chip, 0x06, fm_cs4362a);
361 cs4362a_write(chip, 0x09, fm_cs4362a);
362 cs4362a_write(chip, 0x0c, fm_cs4362a);
363}
364
365static void update_cs4362a_volumes(struct oxygen *chip)
366{
367 u8 mute;
368
369 mute = chip->dac_mute ? CS4362A_MUTE : 0;
370 cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
371 cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
372 cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
373 cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
374 cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
375 cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
376}
377
378static void update_cs43xx_volume(struct oxygen *chip)
379{
380 cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
381 cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
382 update_cs4362a_volumes(chip);
383}
384
385static void update_cs43xx_mute(struct oxygen *chip)
386{
387 u8 reg;
388
389 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
390 if (chip->dac_mute)
391 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
392 cs4398_write(chip, 4, reg);
393 update_cs4362a_volumes(chip);
252} 394}
253 395
254static void xonar_gpio_changed(struct oxygen *chip) 396static void xonar_gpio_changed(struct oxygen *chip)
@@ -256,10 +398,8 @@ static void xonar_gpio_changed(struct oxygen *chip)
256 struct xonar_data *data = chip->model_data; 398 struct xonar_data *data = chip->model_data;
257 u8 has_power; 399 u8 has_power;
258 400
259 if (!data->is_d2x) 401 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
260 return; 402 & data->ext_power_bit);
261 has_power = !!(oxygen_read16(chip, OXYGEN_GPIO_DATA)
262 & GPIO_EXT_POWER);
263 if (has_power != data->has_power) { 403 if (has_power != data->has_power) {
264 data->has_power = has_power; 404 data->has_power = has_power;
265 if (has_power) { 405 if (has_power) {
@@ -272,66 +412,13 @@ static void xonar_gpio_changed(struct oxygen *chip)
272 } 412 }
273} 413}
274 414
275static void mute_ac97_ctl(struct oxygen *chip, unsigned int control)
276{
277 unsigned int index = chip->controls[control]->private_value & 0xff;
278 u16 value;
279
280 value = oxygen_read_ac97(chip, 0, index);
281 if (!(value & 0x8000)) {
282 oxygen_write_ac97(chip, 0, index, value | 0x8000);
283 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
284 &chip->controls[control]->id);
285 }
286}
287
288static void xonar_ac97_switch_hook(struct oxygen *chip, unsigned int codec,
289 unsigned int reg, int mute)
290{
291 if (codec != 0)
292 return;
293 /* line-in is exclusive */
294 switch (reg) {
295 case AC97_LINE:
296 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
297 mute ? GPIO_LINE_MUTE : 0,
298 GPIO_LINE_MUTE);
299 if (!mute) {
300 mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
301 mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
302 mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
303 }
304 break;
305 case AC97_MIC:
306 case AC97_CD:
307 case AC97_VIDEO:
308 case AC97_AUX:
309 if (!mute) {
310 oxygen_ac97_set_bits(chip, 0, CM9780_GPIO_STATUS,
311 GPIO_LINE_MUTE);
312 mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
313 }
314 break;
315 }
316}
317
318static int pcm1796_volume_info(struct snd_kcontrol *ctl,
319 struct snd_ctl_elem_info *info)
320{
321 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
322 info->count = 8;
323 info->value.integer.min = 0x0f;
324 info->value.integer.max = 0xff;
325 return 0;
326}
327
328static int alt_switch_get(struct snd_kcontrol *ctl, 415static int alt_switch_get(struct snd_kcontrol *ctl,
329 struct snd_ctl_elem_value *value) 416 struct snd_ctl_elem_value *value)
330{ 417{
331 struct oxygen *chip = ctl->private_data; 418 struct oxygen *chip = ctl->private_data;
332 419
333 value->value.integer.value[0] = 420 value->value.integer.value[0] =
334 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_ALT); 421 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_D2_ALT);
335 return 0; 422 return 0;
336} 423}
337 424
@@ -345,9 +432,9 @@ static int alt_switch_put(struct snd_kcontrol *ctl,
345 spin_lock_irq(&chip->reg_lock); 432 spin_lock_irq(&chip->reg_lock);
346 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); 433 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
347 if (value->value.integer.value[0]) 434 if (value->value.integer.value[0])
348 new_bits = old_bits | GPIO_ALT; 435 new_bits = old_bits | GPIO_D2_ALT;
349 else 436 else
350 new_bits = old_bits & ~GPIO_ALT; 437 new_bits = old_bits & ~GPIO_D2_ALT;
351 changed = new_bits != old_bits; 438 changed = new_bits != old_bits;
352 if (changed) 439 if (changed)
353 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); 440 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
@@ -363,20 +450,68 @@ static const struct snd_kcontrol_new alt_switch = {
363 .put = alt_switch_put, 450 .put = alt_switch_put,
364}; 451};
365 452
453static int front_panel_get(struct snd_kcontrol *ctl,
454 struct snd_ctl_elem_value *value)
455{
456 struct oxygen *chip = ctl->private_data;
457
458 value->value.integer.value[0] =
459 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DX_FRONT_PANEL);
460 return 0;
461}
462
463static int front_panel_put(struct snd_kcontrol *ctl,
464 struct snd_ctl_elem_value *value)
465{
466 struct oxygen *chip = ctl->private_data;
467 u16 old_reg, new_reg;
468
469 spin_lock_irq(&chip->reg_lock);
470 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
471 if (value->value.integer.value[0])
472 new_reg = old_reg | GPIO_DX_FRONT_PANEL;
473 else
474 new_reg = old_reg & ~GPIO_DX_FRONT_PANEL;
475 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
476 spin_unlock_irq(&chip->reg_lock);
477 return old_reg != new_reg;
478}
479
480static const struct snd_kcontrol_new front_panel_switch = {
481 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
482 .name = "Front Panel Switch",
483 .info = snd_ctl_boolean_mono_info,
484 .get = front_panel_get,
485 .put = front_panel_put,
486};
487
488static void xonar_dx_ac97_switch(struct oxygen *chip,
489 unsigned int reg, unsigned int mute)
490{
491 if (reg == AC97_LINE) {
492 spin_lock_irq(&chip->reg_lock);
493 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
494 mute ? GPIO_DX_INPUT_ROUTE : 0,
495 GPIO_DX_INPUT_ROUTE);
496 spin_unlock_irq(&chip->reg_lock);
497 }
498}
499
366static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -12000, 50, 0); 500static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -12000, 50, 0);
501static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -12700, 100, 0);
367 502
368static int xonar_control_filter(struct snd_kcontrol_new *template) 503static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
369{ 504{
370 if (!strcmp(template->name, "Master Playback Volume")) { 505 if (!strncmp(template->name, "CD Capture ", 11))
371 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
372 template->info = pcm1796_volume_info,
373 template->tlv.p = pcm1796_db_scale;
374 } else if (!strncmp(template->name, "CD Capture ", 11)) {
375 /* CD in is actually connected to the video in pin */ 506 /* CD in is actually connected to the video in pin */
376 template->private_value ^= AC97_CD ^ AC97_VIDEO; 507 template->private_value ^= AC97_CD ^ AC97_VIDEO;
377 } else if (!strcmp(template->name, "Line Capture Volume")) { 508 return 0;
378 return 1; /* line-in bypasses the AC'97 mixer */ 509}
379 } 510
511static int xonar_dx_control_filter(struct snd_kcontrol_new *template)
512{
513 if (!strncmp(template->name, "CD Capture ", 11))
514 return 1; /* no CD input */
380 return 0; 515 return 0;
381} 516}
382 517
@@ -385,30 +520,96 @@ static int xonar_mixer_init(struct oxygen *chip)
385 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); 520 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
386} 521}
387 522
388static const struct oxygen_model model_xonar = { 523static int xonar_dx_mixer_init(struct oxygen *chip)
389 .shortname = "Asus AV200", 524{
390 .longname = "Asus Virtuoso 200", 525 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
391 .chip = "AV200", 526}
392 .owner = THIS_MODULE, 527
393 .init = xonar_init, 528static const struct oxygen_model xonar_models[] = {
394 .control_filter = xonar_control_filter, 529 [MODEL_D2] = {
395 .mixer_init = xonar_mixer_init, 530 .shortname = "Xonar D2",
396 .cleanup = xonar_cleanup, 531 .longname = "Asus Virtuoso 200",
397 .set_dac_params = set_pcm1796_params, 532 .chip = "AV200",
398 .set_adc_params = set_cs5381_params, 533 .owner = THIS_MODULE,
399 .update_dac_volume = update_pcm1796_volume, 534 .init = xonar_d2_init,
400 .update_dac_mute = update_pcm1796_mute, 535 .control_filter = xonar_d2_control_filter,
401 .ac97_switch_hook = xonar_ac97_switch_hook, 536 .mixer_init = xonar_mixer_init,
402 .gpio_changed = xonar_gpio_changed, 537 .cleanup = xonar_cleanup,
403 .model_data_size = sizeof(struct xonar_data), 538 .set_dac_params = set_pcm1796_params,
404 .dac_channels = 8, 539 .set_adc_params = set_cs53x1_params,
405 .used_channels = OXYGEN_CHANNEL_B | 540 .update_dac_volume = update_pcm1796_volume,
406 OXYGEN_CHANNEL_C | 541 .update_dac_mute = update_pcm1796_mute,
407 OXYGEN_CHANNEL_SPDIF | 542 .dac_tlv = pcm1796_db_scale,
408 OXYGEN_CHANNEL_MULTICH, 543 .model_data_size = sizeof(struct xonar_data),
409 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5, 544 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
410 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 545 PLAYBACK_1_TO_SPDIF |
411 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 546 CAPTURE_0_FROM_I2S_2 |
547 CAPTURE_1_FROM_SPDIF,
548 .dac_channels = 8,
549 .dac_volume_min = 0x0f,
550 .dac_volume_max = 0xff,
551 .misc_flags = OXYGEN_MISC_MIDI,
552 .function_flags = OXYGEN_FUNCTION_SPI |
553 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
554 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
555 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
556 },
557 [MODEL_D2X] = {
558 .shortname = "Xonar D2X",
559 .longname = "Asus Virtuoso 200",
560 .chip = "AV200",
561 .owner = THIS_MODULE,
562 .init = xonar_d2x_init,
563 .control_filter = xonar_d2_control_filter,
564 .mixer_init = xonar_mixer_init,
565 .cleanup = xonar_cleanup,
566 .set_dac_params = set_pcm1796_params,
567 .set_adc_params = set_cs53x1_params,
568 .update_dac_volume = update_pcm1796_volume,
569 .update_dac_mute = update_pcm1796_mute,
570 .gpio_changed = xonar_gpio_changed,
571 .dac_tlv = pcm1796_db_scale,
572 .model_data_size = sizeof(struct xonar_data),
573 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
574 PLAYBACK_1_TO_SPDIF |
575 CAPTURE_0_FROM_I2S_2 |
576 CAPTURE_1_FROM_SPDIF,
577 .dac_channels = 8,
578 .dac_volume_min = 0x0f,
579 .dac_volume_max = 0xff,
580 .misc_flags = OXYGEN_MISC_MIDI,
581 .function_flags = OXYGEN_FUNCTION_SPI |
582 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
583 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
584 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
585 },
586 [MODEL_DX] = {
587 .shortname = "Xonar DX",
588 .longname = "Asus Virtuoso 100",
589 .chip = "AV200",
590 .owner = THIS_MODULE,
591 .init = xonar_dx_init,
592 .control_filter = xonar_dx_control_filter,
593 .mixer_init = xonar_dx_mixer_init,
594 .cleanup = xonar_dx_cleanup,
595 .set_dac_params = set_cs43xx_params,
596 .set_adc_params = set_cs53x1_params,
597 .update_dac_volume = update_cs43xx_volume,
598 .update_dac_mute = update_cs43xx_mute,
599 .gpio_changed = xonar_gpio_changed,
600 .ac97_switch = xonar_dx_ac97_switch,
601 .dac_tlv = cs4362a_db_scale,
602 .model_data_size = sizeof(struct xonar_data),
603 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
604 PLAYBACK_1_TO_SPDIF |
605 CAPTURE_0_FROM_I2S_2,
606 .dac_channels = 8,
607 .dac_volume_min = 0,
608 .dac_volume_max = 127,
609 .function_flags = OXYGEN_FUNCTION_2WIRE,
610 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
611 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
612 },
412}; 613};
413 614
414static int __devinit xonar_probe(struct pci_dev *pci, 615static int __devinit xonar_probe(struct pci_dev *pci,
@@ -423,7 +624,8 @@ static int __devinit xonar_probe(struct pci_dev *pci,
423 ++dev; 624 ++dev;
424 return -ENOENT; 625 return -ENOENT;
425 } 626 }
426 err = oxygen_pci_probe(pci, index[dev], id[dev], 1, &model_xonar); 627 err = oxygen_pci_probe(pci, index[dev], id[dev],
628 &xonar_models[pci_id->driver_data]);
427 if (err >= 0) 629 if (err >= 0)
428 ++dev; 630 ++dev;
429 return err; 631 return err;
diff --git a/sound/pci/oxygen/wm8785.h b/sound/pci/oxygen/wm8785.h
new file mode 100644
index 000000000000..8c23e315ae66
--- /dev/null
+++ b/sound/pci/oxygen/wm8785.h
@@ -0,0 +1,45 @@
1#ifndef WM8785_H_INCLUDED
2#define WM8785_H_INCLUDED
3
4#define WM8785_R0 0
5#define WM8785_R1 1
6#define WM8785_R2 2
7#define WM8785_R7 7
8
9/* R0 */
10#define WM8785_MCR_MASK 0x007
11#define WM8785_MCR_SLAVE 0x000
12#define WM8785_MCR_MASTER_128 0x001
13#define WM8785_MCR_MASTER_192 0x002
14#define WM8785_MCR_MASTER_256 0x003
15#define WM8785_MCR_MASTER_384 0x004
16#define WM8785_MCR_MASTER_512 0x005
17#define WM8785_MCR_MASTER_768 0x006
18#define WM8785_OSR_MASK 0x018
19#define WM8785_OSR_SINGLE 0x000
20#define WM8785_OSR_DOUBLE 0x008
21#define WM8785_OSR_QUAD 0x010
22#define WM8785_FORMAT_MASK 0x060
23#define WM8785_FORMAT_RJUST 0x000
24#define WM8785_FORMAT_LJUST 0x020
25#define WM8785_FORMAT_I2S 0x040
26#define WM8785_FORMAT_DSP 0x060
27/* R1 */
28#define WM8785_WL_MASK 0x003
29#define WM8785_WL_16 0x000
30#define WM8785_WL_20 0x001
31#define WM8785_WL_24 0x002
32#define WM8785_WL_32 0x003
33#define WM8785_LRP 0x004
34#define WM8785_BCLKINV 0x008
35#define WM8785_LRSWAP 0x010
36#define WM8785_DEVNO_MASK 0x0e0
37/* R2 */
38#define WM8785_HPFR 0x001
39#define WM8785_HPFL 0x002
40#define WM8785_SDODIS 0x004
41#define WM8785_PWRDNR 0x008
42#define WM8785_PWRDNL 0x010
43#define WM8785_TDM_MASK 0x1c0
44
45#endif
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index 9d5bb76229a8..7fdcdc8c6b64 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -458,7 +458,7 @@ static int pcxhr_update_r_buffer(struct pcxhr_stream *stream)
458 458
459 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : addr(%p) bytes(%zx) subs(%d)\n", 459 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : addr(%p) bytes(%zx) subs(%d)\n",
460 is_capture ? 'c' : 'p', 460 is_capture ? 'c' : 'p',
461 chip->chip_idx, (void*)subs->runtime->dma_addr, 461 chip->chip_idx, (void *)(long)subs->runtime->dma_addr,
462 subs->runtime->dma_bytes, subs->number); 462 subs->runtime->dma_bytes, subs->number);
463 463
464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS); 464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS);
@@ -626,7 +626,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
626#ifdef CONFIG_SND_DEBUG_DETECT 626#ifdef CONFIG_SND_DEBUG_DETECT
627 do_gettimeofday(&my_tv2); 627 do_gettimeofday(&my_tv2);
628 snd_printdd("***TRIGGER TASKLET*** TIME = %ld (err = %x)\n", 628 snd_printdd("***TRIGGER TASKLET*** TIME = %ld (err = %x)\n",
629 my_tv2.tv_usec - my_tv1.tv_usec, err); 629 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
630#endif 630#endif
631} 631}
632 632
@@ -846,7 +846,6 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
846 struct pcxhr_mgr *mgr = chip->mgr; 846 struct pcxhr_mgr *mgr = chip->mgr;
847 struct snd_pcm_runtime *runtime = subs->runtime; 847 struct snd_pcm_runtime *runtime = subs->runtime;
848 struct pcxhr_stream *stream; 848 struct pcxhr_stream *stream;
849 int is_capture;
850 849
851 mutex_lock(&mgr->setup_mutex); 850 mutex_lock(&mgr->setup_mutex);
852 851
@@ -856,12 +855,10 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
856 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) { 855 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) {
857 snd_printdd("pcxhr_open playback chip%d subs%d\n", 856 snd_printdd("pcxhr_open playback chip%d subs%d\n",
858 chip->chip_idx, subs->number); 857 chip->chip_idx, subs->number);
859 is_capture = 0;
860 stream = &chip->playback_stream[subs->number]; 858 stream = &chip->playback_stream[subs->number];
861 } else { 859 } else {
862 snd_printdd("pcxhr_open capture chip%d subs%d\n", 860 snd_printdd("pcxhr_open capture chip%d subs%d\n",
863 chip->chip_idx, subs->number); 861 chip->chip_idx, subs->number);
864 is_capture = 1;
865 if (mgr->mono_capture) 862 if (mgr->mono_capture)
866 runtime->hw.channels_max = 1; 863 runtime->hw.channels_max = 1;
867 else 864 else
diff --git a/sound/pci/pcxhr/pcxhr_core.c b/sound/pci/pcxhr/pcxhr_core.c
index c4e415d07380..78aa81feaa4a 100644
--- a/sound/pci/pcxhr/pcxhr_core.c
+++ b/sound/pci/pcxhr/pcxhr_core.c
@@ -897,7 +897,7 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask, int capture_m
897#ifdef CONFIG_SND_DEBUG_DETECT 897#ifdef CONFIG_SND_DEBUG_DETECT
898 do_gettimeofday(&my_tv2); 898 do_gettimeofday(&my_tv2);
899 snd_printdd("***SET PIPE STATE*** TIME = %ld (err = %x)\n", 899 snd_printdd("***SET PIPE STATE*** TIME = %ld (err = %x)\n",
900 my_tv2.tv_usec - my_tv1.tv_usec, err); 900 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
901#endif 901#endif
902 return 0; 902 return 0;
903} 903}
@@ -1005,30 +1005,37 @@ void pcxhr_msg_tasklet(unsigned long arg)
1005 int nb_stream = (prmh->stat[i] >> (2*FIELD_SIZE)) & MASK_FIRST_FIELD; 1005 int nb_stream = (prmh->stat[i] >> (2*FIELD_SIZE)) & MASK_FIRST_FIELD;
1006 int pipe = prmh->stat[i] & MASK_FIRST_FIELD; 1006 int pipe = prmh->stat[i] & MASK_FIRST_FIELD;
1007 int is_capture = prmh->stat[i] & 0x400000; 1007 int is_capture = prmh->stat[i] & 0x400000;
1008 u32 err; 1008 u32 err2;
1009 1009
1010 if (prmh->stat[i] & 0x800000) { /* if BIT_END */ 1010 if (prmh->stat[i] & 0x800000) { /* if BIT_END */
1011 snd_printdd("TASKLET : End%sPipe %d\n", 1011 snd_printdd("TASKLET : End%sPipe %d\n",
1012 is_capture ? "Record" : "Play", pipe); 1012 is_capture ? "Record" : "Play", pipe);
1013 } 1013 }
1014 i++; 1014 i++;
1015 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1015 err2 = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1];
1016 if (err) 1016 if (err2)
1017 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_PIPE, 1017 pcxhr_handle_async_err(mgr, err2,
1018 PCXHR_ERR_PIPE,
1018 pipe, is_capture); 1019 pipe, is_capture);
1019 i += 2; 1020 i += 2;
1020 for (j = 0; j < nb_stream; j++) { 1021 for (j = 0; j < nb_stream; j++) {
1021 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1022 err2 = prmh->stat[i] ?
1022 if (err) 1023 prmh->stat[i] : prmh->stat[i+1];
1023 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_STREAM, 1024 if (err2)
1024 pipe, is_capture); 1025 pcxhr_handle_async_err(mgr, err2,
1026 PCXHR_ERR_STREAM,
1027 pipe,
1028 is_capture);
1025 i += 2; 1029 i += 2;
1026 } 1030 }
1027 for (j = 0; j < nb_audio; j++) { 1031 for (j = 0; j < nb_audio; j++) {
1028 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1032 err2 = prmh->stat[i] ?
1029 if (err) 1033 prmh->stat[i] : prmh->stat[i+1];
1030 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_AUDIO, 1034 if (err2)
1031 pipe, is_capture); 1035 pcxhr_handle_async_err(mgr, err2,
1036 PCXHR_ERR_AUDIO,
1037 pipe,
1038 is_capture);
1032 i += 2; 1039 i += 2;
1033 } 1040 }
1034 } 1041 }
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 9408b1eeec40..979f7da641ce 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -1630,14 +1630,14 @@ static int snd_riptide_playback_open(struct snd_pcm_substream *substream)
1630 struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1630 struct snd_riptide *chip = snd_pcm_substream_chip(substream);
1631 struct snd_pcm_runtime *runtime = substream->runtime; 1631 struct snd_pcm_runtime *runtime = substream->runtime;
1632 struct pcmhw *data; 1632 struct pcmhw *data;
1633 int index = substream->number; 1633 int sub_num = substream->number;
1634 1634
1635 chip->playback_substream[index] = substream; 1635 chip->playback_substream[sub_num] = substream;
1636 runtime->hw = snd_riptide_playback; 1636 runtime->hw = snd_riptide_playback;
1637 data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL); 1637 data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL);
1638 data->paths = lbus_play_paths[index]; 1638 data->paths = lbus_play_paths[sub_num];
1639 data->id = play_ids[index]; 1639 data->id = play_ids[sub_num];
1640 data->source = play_sources[index]; 1640 data->source = play_sources[sub_num];
1641 data->intdec[0] = 0xff; 1641 data->intdec[0] = 0xff;
1642 data->intdec[1] = 0xff; 1642 data->intdec[1] = 0xff;
1643 data->state = ST_STOP; 1643 data->state = ST_STOP;
@@ -1670,10 +1670,10 @@ static int snd_riptide_playback_close(struct snd_pcm_substream *substream)
1670{ 1670{
1671 struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1671 struct snd_riptide *chip = snd_pcm_substream_chip(substream);
1672 struct pcmhw *data = get_pcmhwdev(substream); 1672 struct pcmhw *data = get_pcmhwdev(substream);
1673 int index = substream->number; 1673 int sub_num = substream->number;
1674 1674
1675 substream->runtime->private_data = NULL; 1675 substream->runtime->private_data = NULL;
1676 chip->playback_substream[index] = NULL; 1676 chip->playback_substream[sub_num] = NULL;
1677 kfree(data); 1677 kfree(data);
1678 return 0; 1678 return 0;
1679} 1679}
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index df184aabce84..e7ef3a1a25a8 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1350,7 +1350,8 @@ static int __devinit snd_rme32_create(struct rme32 * rme32)
1350 return err; 1350 return err;
1351 rme32->port = pci_resource_start(rme32->pci, 0); 1351 rme32->port = pci_resource_start(rme32->pci, 0);
1352 1352
1353 if ((rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE)) == 0) { 1353 rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE);
1354 if (!rme32->iobase) {
1354 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", 1355 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n",
1355 rme32->port, rme32->port + RME32_IO_SIZE - 1); 1356 rme32->port, rme32->port + RME32_IO_SIZE - 1);
1356 return -ENOMEM; 1357 return -ENOMEM;
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index fb0a4ee8bc02..3fdd488d0975 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -1559,7 +1559,8 @@ snd_rme96_create(struct rme96 *rme96)
1559 return err; 1559 return err;
1560 rme96->port = pci_resource_start(rme96->pci, 0); 1560 rme96->port = pci_resource_start(rme96->pci, 0);
1561 1561
1562 if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) { 1562 rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE);
1563 if (!rme96->iobase) {
1563 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1); 1564 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1);
1564 return -ENOMEM; 1565 return -ENOMEM;
1565 } 1566 }
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 1be84f22d0de..4d6fbb36ab8a 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -318,6 +318,10 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
318#define HDSP_midi1IRQPending (1<<31) 318#define HDSP_midi1IRQPending (1<<31)
319 319
320#define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2) 320#define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
321#define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
322 HDSP_spdifFrequency1|\
323 HDSP_spdifFrequency2|\
324 HDSP_spdifFrequency3)
321 325
322#define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0) 326#define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
323#define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1) 327#define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
@@ -328,7 +332,9 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
328#define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1) 332#define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
329 333
330/* This is for H9632 cards */ 334/* This is for H9632 cards */
331#define HDSP_spdifFrequency128KHz HDSP_spdifFrequencyMask 335#define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
336 HDSP_spdifFrequency1|\
337 HDSP_spdifFrequency2)
332#define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3 338#define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
333#define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0) 339#define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
334 340
@@ -885,28 +891,15 @@ static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
885 return ret; 891 return ret;
886} 892}
887 893
888static int hdsp_external_sample_rate (struct hdsp *hdsp)
889{
890 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
891 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
892
893 switch (rate_bits) {
894 case HDSP_systemFrequency32: return 32000;
895 case HDSP_systemFrequency44_1: return 44100;
896 case HDSP_systemFrequency48: return 48000;
897 case HDSP_systemFrequency64: return 64000;
898 case HDSP_systemFrequency88_2: return 88200;
899 case HDSP_systemFrequency96: return 96000;
900 default:
901 return 0;
902 }
903}
904
905static int hdsp_spdif_sample_rate(struct hdsp *hdsp) 894static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
906{ 895{
907 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister); 896 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
908 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask); 897 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
909 898
899 /* For the 9632, the mask is different */
900 if (hdsp->io_type == H9632)
901 rate_bits = (status & HDSP_spdifFrequencyMask_9632);
902
910 if (status & HDSP_SPDIFErrorFlag) 903 if (status & HDSP_SPDIFErrorFlag)
911 return 0; 904 return 0;
912 905
@@ -933,6 +926,31 @@ static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
933 return 0; 926 return 0;
934} 927}
935 928
929static int hdsp_external_sample_rate(struct hdsp *hdsp)
930{
931 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
932 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
933
934 /* For the 9632 card, there seems to be no bit for indicating external
935 * sample rate greater than 96kHz. The card reports the corresponding
936 * single speed. So the best means seems to get spdif rate when
937 * autosync reference is spdif */
938 if (hdsp->io_type == H9632 &&
939 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
940 return hdsp_spdif_sample_rate(hdsp);
941
942 switch (rate_bits) {
943 case HDSP_systemFrequency32: return 32000;
944 case HDSP_systemFrequency44_1: return 44100;
945 case HDSP_systemFrequency48: return 48000;
946 case HDSP_systemFrequency64: return 64000;
947 case HDSP_systemFrequency88_2: return 88200;
948 case HDSP_systemFrequency96: return 96000;
949 default:
950 return 0;
951 }
952}
953
936static void hdsp_compute_period_size(struct hdsp *hdsp) 954static void hdsp_compute_period_size(struct hdsp *hdsp)
937{ 955{
938 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8)); 956 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 9a19ae6a64d9..ab423bc82342 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -540,7 +540,8 @@ static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf,
540 540
541static inline int HDSPM_bit2freq(int n) 541static inline int HDSPM_bit2freq(int n)
542{ 542{
543 static int bit2freq_tab[] = { 0, 32000, 44100, 48000, 64000, 88200, 543 static const int bit2freq_tab[] = {
544 0, 32000, 44100, 48000, 64000, 88200,
544 96000, 128000, 176400, 192000 }; 545 96000, 128000, 176400, 192000 };
545 if (n < 1 || n > 9) 546 if (n < 1 || n > 9)
546 return 0; 547 return 0;
@@ -582,7 +583,7 @@ static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
582 return hdspm->mixer->ch[chan].pb[pb]; 583 return hdspm->mixer->ch[chan].pb[pb];
583} 584}
584 585
585static inline int hdspm_write_in_gain(struct hdspm * hdspm, unsigned int chan, 586static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan,
586 unsigned int in, unsigned short data) 587 unsigned int in, unsigned short data)
587{ 588{
588 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) 589 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
@@ -595,7 +596,7 @@ static inline int hdspm_write_in_gain(struct hdspm * hdspm, unsigned int chan,
595 return 0; 596 return 0;
596} 597}
597 598
598static inline int hdspm_write_pb_gain(struct hdspm * hdspm, unsigned int chan, 599static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan,
599 unsigned int pb, unsigned short data) 600 unsigned int pb, unsigned short data)
600{ 601{
601 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) 602 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
@@ -621,7 +622,7 @@ static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
621} 622}
622 623
623/* check if same process is writing and reading */ 624/* check if same process is writing and reading */
624static inline int snd_hdspm_use_is_exclusive(struct hdspm * hdspm) 625static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
625{ 626{
626 unsigned long flags; 627 unsigned long flags;
627 int ret = 1; 628 int ret = 1;
@@ -636,7 +637,7 @@ static inline int snd_hdspm_use_is_exclusive(struct hdspm * hdspm)
636} 637}
637 638
638/* check for external sample rate */ 639/* check for external sample rate */
639static inline int hdspm_external_sample_rate(struct hdspm * hdspm) 640static int hdspm_external_sample_rate(struct hdspm *hdspm)
640{ 641{
641 if (hdspm->is_aes32) { 642 if (hdspm->is_aes32) {
642 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); 643 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
@@ -787,7 +788,7 @@ static inline void hdspm_stop_audio(struct hdspm * s)
787} 788}
788 789
789/* should I silence all or only opened ones ? doit all for first even is 4MB*/ 790/* should I silence all or only opened ones ? doit all for first even is 4MB*/
790static inline void hdspm_silence_playback(struct hdspm * hdspm) 791static void hdspm_silence_playback(struct hdspm *hdspm)
791{ 792{
792 int i; 793 int i;
793 int n = hdspm->period_bytes; 794 int n = hdspm->period_bytes;
@@ -1028,9 +1029,9 @@ static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id,
1028{ 1029{
1029 /* the hardware already does the relevant bit-mask with 0xff */ 1030 /* the hardware already does the relevant bit-mask with 0xff */
1030 if (id) 1031 if (id)
1031 return hdspm_write(hdspm, HDSPM_midiDataOut1, val); 1032 hdspm_write(hdspm, HDSPM_midiDataOut1, val);
1032 else 1033 else
1033 return hdspm_write(hdspm, HDSPM_midiDataOut0, val); 1034 hdspm_write(hdspm, HDSPM_midiDataOut0, val);
1034} 1035}
1035 1036
1036static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id) 1037static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
@@ -1057,7 +1058,7 @@ static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
1057 return 0; 1058 return 0;
1058} 1059}
1059 1060
1060static inline void snd_hdspm_flush_midi_input (struct hdspm *hdspm, int id) 1061static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)
1061{ 1062{
1062 while (snd_hdspm_midi_input_available (hdspm, id)) 1063 while (snd_hdspm_midi_input_available (hdspm, id))
1063 snd_hdspm_midi_read_byte (hdspm, id); 1064 snd_hdspm_midi_read_byte (hdspm, id);
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index dcd7cd010461..df2007e3be7c 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -920,7 +920,7 @@ static unsigned short sis_ac97_rw(struct sis7019 *sis, int codec, u32 cmd)
920 u16 status; 920 u16 status;
921 u16 rdy; 921 u16 rdy;
922 int count; 922 int count;
923 const static u16 codec_ready[3] = { 923 static const u16 codec_ready[3] = {
924 SIS_AC97_STATUS_CODEC_READY, 924 SIS_AC97_STATUS_CODEC_READY,
925 SIS_AC97_STATUS_CODEC2_READY, 925 SIS_AC97_STATUS_CODEC2_READY,
926 SIS_AC97_STATUS_CODEC3_READY, 926 SIS_AC97_STATUS_CODEC3_READY,
@@ -984,7 +984,7 @@ timeout:
984static void sis_ac97_write(struct snd_ac97 *ac97, unsigned short reg, 984static void sis_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
985 unsigned short val) 985 unsigned short val)
986{ 986{
987 const static u32 cmd[3] = { 987 static const u32 cmd[3] = {
988 SIS_AC97_CMD_CODEC_WRITE, 988 SIS_AC97_CMD_CODEC_WRITE,
989 SIS_AC97_CMD_CODEC2_WRITE, 989 SIS_AC97_CMD_CODEC2_WRITE,
990 SIS_AC97_CMD_CODEC3_WRITE, 990 SIS_AC97_CMD_CODEC3_WRITE,
@@ -995,7 +995,7 @@ static void sis_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
995 995
996static unsigned short sis_ac97_read(struct snd_ac97 *ac97, unsigned short reg) 996static unsigned short sis_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
997{ 997{
998 const static u32 cmd[3] = { 998 static const u32 cmd[3] = {
999 SIS_AC97_CMD_CODEC_READ, 999 SIS_AC97_CMD_CODEC_READ,
1000 SIS_AC97_CMD_CODEC2_READ, 1000 SIS_AC97_CMD_CODEC2_READ,
1001 SIS_AC97_CMD_CODEC3_READ, 1001 SIS_AC97_CMD_CODEC3_READ,
@@ -1194,7 +1194,6 @@ static int sis_suspend(struct pci_dev *pci, pm_message_t state)
1194 /* snd_pcm_suspend_all() stopped all channels, so we're quiescent. 1194 /* snd_pcm_suspend_all() stopped all channels, so we're quiescent.
1195 */ 1195 */
1196 if (sis->irq >= 0) { 1196 if (sis->irq >= 0) {
1197 synchronize_irq(sis->irq);
1198 free_irq(sis->irq, sis); 1197 free_irq(sis->irq, sis);
1199 sis->irq = -1; 1198 sis->irq = -1;
1200 } 1199 }
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index 71138ff9b310..bbcee2c09ae4 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -3676,6 +3676,8 @@ static int snd_trident_free(struct snd_trident *trident)
3676 else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { 3676 else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
3677 outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); 3677 outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
3678 } 3678 }
3679 if (trident->irq >= 0)
3680 free_irq(trident->irq, trident);
3679 if (trident->tlb.buffer.area) { 3681 if (trident->tlb.buffer.area) {
3680 outl(0, TRID_REG(trident, NX_TLBC)); 3682 outl(0, TRID_REG(trident, NX_TLBC));
3681 if (trident->tlb.memhdr) 3683 if (trident->tlb.memhdr)
@@ -3685,8 +3687,6 @@ static int snd_trident_free(struct snd_trident *trident)
3685 vfree(trident->tlb.shadow_entries); 3687 vfree(trident->tlb.shadow_entries);
3686 snd_dma_free_pages(&trident->tlb.buffer); 3688 snd_dma_free_pages(&trident->tlb.buffer);
3687 } 3689 }
3688 if (trident->irq >= 0)
3689 free_irq(trident->irq, trident);
3690 pci_release_regions(trident->pci); 3690 pci_release_regions(trident->pci);
3691 pci_disable_device(trident->pci); 3691 pci_disable_device(trident->pci);
3692 kfree(trident); 3692 kfree(trident);
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index a756be661f9a..b585cc3e4c47 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -2236,7 +2236,7 @@ static int snd_via82xx_free(struct via82xx *chip)
2236 /* disable interrupts */ 2236 /* disable interrupts */
2237 for (i = 0; i < chip->num_devs; i++) 2237 for (i = 0; i < chip->num_devs; i++)
2238 snd_via82xx_channel_reset(chip, &chip->devs[i]); 2238 snd_via82xx_channel_reset(chip, &chip->devs[i]);
2239 synchronize_irq(chip->irq); 2239
2240 if (chip->irq >= 0) 2240 if (chip->irq >= 0)
2241 free_irq(chip->irq, chip); 2241 free_irq(chip->irq, chip);
2242 __end_hw: 2242 __end_hw:
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index f5df1c79bee1..31f64ee39882 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -1075,7 +1075,7 @@ static int snd_via82xx_free(struct via82xx_modem *chip)
1075 /* disable interrupts */ 1075 /* disable interrupts */
1076 for (i = 0; i < chip->num_devs; i++) 1076 for (i = 0; i < chip->num_devs; i++)
1077 snd_via82xx_channel_reset(chip, &chip->devs[i]); 1077 snd_via82xx_channel_reset(chip, &chip->devs[i]);
1078 synchronize_irq(chip->irq); 1078
1079 __end_hw: 1079 __end_hw:
1080 if (chip->irq >= 0) 1080 if (chip->irq >= 0)
1081 free_irq(chip->irq, chip); 1081 free_irq(chip->irq, chip);
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 42c1eb7d35f5..29b3056c5109 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -2249,6 +2249,8 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip)
2249#ifdef CONFIG_PM 2249#ifdef CONFIG_PM
2250 vfree(chip->saved_regs); 2250 vfree(chip->saved_regs);
2251#endif 2251#endif
2252 if (chip->irq >= 0)
2253 free_irq(chip->irq, chip);
2252 release_and_free_resource(chip->mpu_res); 2254 release_and_free_resource(chip->mpu_res);
2253 release_and_free_resource(chip->fm_res); 2255 release_and_free_resource(chip->fm_res);
2254 snd_ymfpci_free_gameport(chip); 2256 snd_ymfpci_free_gameport(chip);
@@ -2257,8 +2259,6 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip)
2257 if (chip->work_ptr.area) 2259 if (chip->work_ptr.area)
2258 snd_dma_free_pages(&chip->work_ptr); 2260 snd_dma_free_pages(&chip->work_ptr);
2259 2261
2260 if (chip->irq >= 0)
2261 free_irq(chip->irq, chip);
2262 release_and_free_resource(chip->res_reg_area); 2262 release_and_free_resource(chip->res_reg_area);
2263 2263
2264 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl); 2264 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl);
diff --git a/sound/ppc/awacs.c b/sound/ppc/awacs.c
index 8441e780df00..566a6d0daf4a 100644
--- a/sound/ppc/awacs.c
+++ b/sound/ppc/awacs.c
@@ -141,7 +141,7 @@ static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
141 uinfo->value.integer.max = 15; 141 uinfo->value.integer.max = 15;
142 return 0; 142 return 0;
143} 143}
144 144
145static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol, 145static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
146 struct snd_ctl_elem_value *ucontrol) 146 struct snd_ctl_elem_value *ucontrol)
147{ 147{
@@ -267,7 +267,8 @@ static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
267static void awacs_set_cuda(int reg, int val) 267static void awacs_set_cuda(int reg, int val)
268{ 268{
269 struct adb_request req; 269 struct adb_request req;
270 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a, reg, val); 270 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a,
271 reg, val);
271 while (! req.complete) 272 while (! req.complete)
272 cuda_poll(); 273 cuda_poll();
273} 274}
@@ -289,11 +290,11 @@ static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble)
289/* 290/*
290 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo 291 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
291 */ 292 */
292static int awacs_amp_set_vol(struct awacs_amp *amp, int index, int lvol, int rvol, 293static int awacs_amp_set_vol(struct awacs_amp *amp, int index,
293 int do_check) 294 int lvol, int rvol, int do_check)
294{ 295{
295 if (do_check && amp->amp_vol[index][0] == lvol && 296 if (do_check && amp->amp_vol[index][0] == lvol &&
296 amp->amp_vol[index][1] == rvol) 297 amp->amp_vol[index][1] == rvol)
297 return 0; 298 return 0;
298 awacs_set_cuda(3 + index, lvol); 299 awacs_set_cuda(3 + index, lvol);
299 awacs_set_cuda(5 + index, rvol); 300 awacs_set_cuda(5 + index, rvol);
@@ -337,7 +338,7 @@ static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
337 uinfo->value.integer.max = 31; 338 uinfo->value.integer.max = 31;
338 return 0; 339 return 0;
339} 340}
340 341
341static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol, 342static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_value *ucontrol) 343 struct snd_ctl_elem_value *ucontrol)
343{ 344{
@@ -361,8 +362,10 @@ static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol,
361 snd_assert(amp, return -EINVAL); 362 snd_assert(amp, return -EINVAL);
362 snd_assert(index >= 0 && index <= 1, return -EINVAL); 363 snd_assert(index >= 0 && index <= 1, return -EINVAL);
363 364
364 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31)) | (amp->amp_vol[index][0] & 32); 365 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31))
365 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31)) | (amp->amp_vol[index][1] & 32); 366 | (amp->amp_vol[index][0] & 32);
367 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
368 | (amp->amp_vol[index][1] & 32);
366 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); 369 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
367} 370}
368 371
@@ -374,8 +377,10 @@ static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
374 struct awacs_amp *amp = chip->mixer_data; 377 struct awacs_amp *amp = chip->mixer_data;
375 snd_assert(amp, return -EINVAL); 378 snd_assert(amp, return -EINVAL);
376 snd_assert(index >= 0 && index <= 1, return -EINVAL); 379 snd_assert(index >= 0 && index <= 1, return -EINVAL);
377 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32) ? 0 : 1; 380 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
378 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32) ? 0 : 1; 381 ? 0 : 1;
382 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
383 ? 0 : 1;
379 return 0; 384 return 0;
380} 385}
381 386
@@ -389,8 +394,10 @@ static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
389 snd_assert(amp, return -EINVAL); 394 snd_assert(amp, return -EINVAL);
390 snd_assert(index >= 0 && index <= 1, return -EINVAL); 395 snd_assert(index >= 0 && index <= 1, return -EINVAL);
391 396
392 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32) | (amp->amp_vol[index][0] & 31); 397 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
393 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32) | (amp->amp_vol[index][1] & 31); 398 | (amp->amp_vol[index][0] & 31);
399 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
400 | (amp->amp_vol[index][1] & 31);
394 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); 401 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
395} 402}
396 403
@@ -403,7 +410,7 @@ static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
403 uinfo->value.integer.max = 14; 410 uinfo->value.integer.max = 14;
404 return 0; 411 return 0;
405} 412}
406 413
407static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol, 414static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol) 415 struct snd_ctl_elem_value *ucontrol)
409{ 416{
@@ -445,7 +452,7 @@ static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
445 uinfo->value.integer.max = 99; 452 uinfo->value.integer.max = 99;
446 return 0; 453 return 0;
447} 454}
448 455
449static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol, 456static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_value *ucontrol) 457 struct snd_ctl_elem_value *ucontrol)
451{ 458{
@@ -544,7 +551,7 @@ static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
544 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 551 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
545 uinfo->count = 1; 552 uinfo->count = 1;
546 uinfo->value.integer.min = 0; 553 uinfo->value.integer.min = 0;
547 uinfo->value.integer.max = 2; 554 uinfo->value.integer.max = 3;
548 return 0; 555 return 0;
549} 556}
550 557
@@ -552,16 +559,14 @@ static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_value *ucontrol) 559 struct snd_ctl_elem_value *ucontrol)
553{ 560{
554 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 561 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
555 int val; 562 int val = 0;
556 unsigned long flags; 563 unsigned long flags;
557 564
558 spin_lock_irqsave(&chip->reg_lock, flags); 565 spin_lock_irqsave(&chip->reg_lock, flags);
559 if (chip->awacs_reg[6] & MASK_MIC_BOOST) 566 if (chip->awacs_reg[6] & MASK_MIC_BOOST)
560 val = 2; 567 val |= 2;
561 else if (chip->awacs_reg[0] & MASK_GAINLINE) 568 if (chip->awacs_reg[0] & MASK_GAINLINE)
562 val = 1; 569 val |= 1;
563 else
564 val = 0;
565 spin_unlock_irqrestore(&chip->reg_lock, flags); 570 spin_unlock_irqrestore(&chip->reg_lock, flags);
566 ucontrol->value.integer.value[0] = val; 571 ucontrol->value.integer.value[0] = val;
567 return 0; 572 return 0;
@@ -578,11 +583,10 @@ static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
578 spin_lock_irqsave(&chip->reg_lock, flags); 583 spin_lock_irqsave(&chip->reg_lock, flags);
579 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE; 584 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
580 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST; 585 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
581 if (ucontrol->value.integer.value[0] > 0) { 586 if (ucontrol->value.integer.value[0] & 1)
582 val0 |= MASK_GAINLINE; 587 val0 |= MASK_GAINLINE;
583 if (ucontrol->value.integer.value[0] > 1) 588 if (ucontrol->value.integer.value[0] & 2)
584 val6 |= MASK_MIC_BOOST; 589 val6 |= MASK_MIC_BOOST;
585 }
586 if (val0 != chip->awacs_reg[0]) { 590 if (val0 != chip->awacs_reg[0]) {
587 snd_pmac_awacs_write_reg(chip, 0, val0); 591 snd_pmac_awacs_write_reg(chip, 0, val0);
588 changed = 1; 592 changed = 1;
@@ -599,9 +603,32 @@ static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
599 * lists of mixer elements 603 * lists of mixer elements
600 */ 604 */
601static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = { 605static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = {
602 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
603 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0), 606 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
604 AWACS_VOLUME("Capture Volume", 0, 4, 0), 607 AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
608/* AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */
609};
610
611static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = {
612 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
613 AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
614 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
615 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
616};
617
618static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = {
619 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
620 AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
621 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
622};
623
624static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = {
625 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
626 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
627 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
628};
629
630static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = {
631 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
605 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), 632 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
606}; 633};
607 634
@@ -621,35 +648,61 @@ static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
621static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata = 648static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
622AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1); 649AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
623 650
651static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata =
652AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
653
624static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = { 654static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
625 AWACS_SWITCH("Mic Boost", 0, SHIFT_GAINLINE, 0), 655 AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
626}; 656};
627 657
628static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = { 658static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = {
629 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 659 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
630 .name = "Mic Boost", 660 .name = "Mic Boost Capture Volume",
631 .info = snd_pmac_screamer_mic_boost_info, 661 .info = snd_pmac_screamer_mic_boost_info,
632 .get = snd_pmac_screamer_mic_boost_get, 662 .get = snd_pmac_screamer_mic_boost_get,
633 .put = snd_pmac_screamer_mic_boost_put, 663 .put = snd_pmac_screamer_mic_boost_put,
634 }, 664 },
635}; 665};
636 666
667static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata =
668{
669 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
670};
671
672static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata =
673{
674 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
675 AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
676};
677
678static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata =
679{
680 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
681 AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
682};
683
637static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = { 684static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = {
638 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1), 685 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
639}; 686};
687
640static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata = 688static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata =
641AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1); 689AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
642 690
691static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac __initdata =
692AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
693
643 694
644/* 695/*
645 * add new mixer elements to the card 696 * add new mixer elements to the card
646 */ 697 */
647static int build_mixers(struct snd_pmac *chip, int nums, struct snd_kcontrol_new *mixers) 698static int build_mixers(struct snd_pmac *chip, int nums,
699 struct snd_kcontrol_new *mixers)
648{ 700{
649 int i, err; 701 int i, err;
650 702
651 for (i = 0; i < nums; i++) { 703 for (i = 0; i < nums; i++) {
652 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip))) < 0) 704 err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
705 if (err < 0)
653 return err; 706 return err;
654 } 707 }
655 return 0; 708 return 0;
@@ -699,8 +752,10 @@ static void snd_pmac_awacs_resume(struct snd_pmac *chip)
699#ifdef PMAC_AMP_AVAIL 752#ifdef PMAC_AMP_AVAIL
700 if (chip->mixer_data) { 753 if (chip->mixer_data) {
701 struct awacs_amp *amp = chip->mixer_data; 754 struct awacs_amp *amp = chip->mixer_data;
702 awacs_amp_set_vol(amp, 0, amp->amp_vol[0][0], amp->amp_vol[0][1], 0); 755 awacs_amp_set_vol(amp, 0,
703 awacs_amp_set_vol(amp, 1, amp->amp_vol[1][0], amp->amp_vol[1][1], 0); 756 amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
757 awacs_amp_set_vol(amp, 1,
758 amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
704 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]); 759 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
705 awacs_amp_set_master(amp, amp->amp_master); 760 awacs_amp_set_master(amp, amp->amp_master);
706 } 761 }
@@ -708,6 +763,14 @@ static void snd_pmac_awacs_resume(struct snd_pmac *chip)
708} 763}
709#endif /* CONFIG_PM */ 764#endif /* CONFIG_PM */
710 765
766#define IS_PM7500 (machine_is_compatible("AAPL,7500"))
767#define IS_BEIGE (machine_is_compatible("AAPL,Gossamer"))
768#define IS_IMAC (machine_is_compatible("PowerMac2,1") \
769 || machine_is_compatible("PowerMac2,2") \
770 || machine_is_compatible("PowerMac4,1"))
771
772static int imac;
773
711#ifdef PMAC_SUPPORT_AUTOMUTE 774#ifdef PMAC_SUPPORT_AUTOMUTE
712/* 775/*
713 * auto-mute stuffs 776 * auto-mute stuffs
@@ -750,9 +813,16 @@ static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
750 } else 813 } else
751#endif 814#endif
752 { 815 {
753 int reg = chip->awacs_reg[1] | (MASK_HDMUTE|MASK_SPKMUTE); 816 int reg = chip->awacs_reg[1]
817 | (MASK_HDMUTE | MASK_SPKMUTE);
818 if (imac) {
819 reg &= ~MASK_SPKMUTE;
820 reg &= ~MASK_PAROUT1;
821 }
754 if (snd_pmac_awacs_detect_headphone(chip)) 822 if (snd_pmac_awacs_detect_headphone(chip))
755 reg &= ~MASK_HDMUTE; 823 reg &= ~MASK_HDMUTE;
824 else if (imac)
825 reg |= MASK_PAROUT1;
756 else 826 else
757 reg &= ~MASK_SPKMUTE; 827 reg &= ~MASK_SPKMUTE;
758 if (do_notify && reg == chip->awacs_reg[1]) 828 if (do_notify && reg == chip->awacs_reg[1])
@@ -778,8 +848,11 @@ static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
778int __init 848int __init
779snd_pmac_awacs_init(struct snd_pmac *chip) 849snd_pmac_awacs_init(struct snd_pmac *chip)
780{ 850{
851 int pm7500 = IS_PM7500;
852 int beige = IS_BEIGE;
781 int err, vol; 853 int err, vol;
782 854
855 imac = IS_IMAC;
783 /* looks like MASK_GAINLINE triggers something, so we set here 856 /* looks like MASK_GAINLINE triggers something, so we set here
784 * as start-up 857 * as start-up
785 */ 858 */
@@ -787,7 +860,7 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
787 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE; 860 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
788 /* FIXME: Only machines with external SRS module need MASK_PAROUT */ 861 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
789 if (chip->has_iic || chip->device_id == 0x5 || 862 if (chip->has_iic || chip->device_id == 0x5 ||
790 /*chip->_device_id == 0x8 || */ 863 /* chip->_device_id == 0x8 || */
791 chip->device_id == 0xb) 864 chip->device_id == 0xb)
792 chip->awacs_reg[1] |= MASK_PAROUT; 865 chip->awacs_reg[1] |= MASK_PAROUT;
793 /* get default volume from nvram */ 866 /* get default volume from nvram */
@@ -798,8 +871,10 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
798 chip->awacs_reg[2] = vol; 871 chip->awacs_reg[2] = vol;
799 chip->awacs_reg[4] = vol; 872 chip->awacs_reg[4] = vol;
800 if (chip->model == PMAC_SCREAMER) { 873 if (chip->model == PMAC_SCREAMER) {
801 chip->awacs_reg[5] = vol; /* FIXME: screamer has loopthru vol control */ 874 /* FIXME: screamer has loopthru vol control */
802 chip->awacs_reg[6] = MASK_MIC_BOOST; /* FIXME: maybe should be vol << 3 for PCMCIA speaker */ 875 chip->awacs_reg[5] = vol;
876 /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
877 chip->awacs_reg[6] = MASK_MIC_BOOST;
803 chip->awacs_reg[7] = 0; 878 chip->awacs_reg[7] = 0;
804 } 879 }
805 880
@@ -815,7 +890,8 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
815 return -ENOMEM; 890 return -ENOMEM;
816 chip->mixer_data = amp; 891 chip->mixer_data = amp;
817 chip->mixer_free = awacs_amp_free; 892 chip->mixer_free = awacs_amp_free;
818 awacs_amp_set_vol(amp, 0, 63, 63, 0); /* mute and zero vol */ 893 /* mute and zero vol */
894 awacs_amp_set_vol(amp, 0, 63, 63, 0);
819 awacs_amp_set_vol(amp, 1, 63, 63, 0); 895 awacs_amp_set_vol(amp, 1, 63, 63, 0);
820 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */ 896 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
821 awacs_amp_set_master(amp, 79); /* 0 dB */ 897 awacs_amp_set_master(amp, 79); /* 0 dB */
@@ -826,20 +902,25 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
826 /* set headphone-jack detection bit */ 902 /* set headphone-jack detection bit */
827 switch (chip->model) { 903 switch (chip->model) {
828 case PMAC_AWACS: 904 case PMAC_AWACS:
829 chip->hp_stat_mask = 0x04; 905 chip->hp_stat_mask = pm7500 ? MASK_HDPCONN
906 : MASK_LOCONN;
830 break; 907 break;
831 case PMAC_SCREAMER: 908 case PMAC_SCREAMER:
832 switch (chip->device_id) { 909 switch (chip->device_id) {
833 case 0x08: 910 case 0x08:
834 /* 1 = side jack, 2 = front jack */ 911 case 0x0B:
835 chip->hp_stat_mask = 0x03; 912 chip->hp_stat_mask = imac
913 ? MASK_LOCONN_IMAC |
914 MASK_HDPLCONN_IMAC |
915 MASK_HDPRCONN_IMAC
916 : MASK_HDPCONN;
836 break; 917 break;
837 case 0x00: 918 case 0x00:
838 case 0x05: 919 case 0x05:
839 chip->hp_stat_mask = 0x04; 920 chip->hp_stat_mask = MASK_LOCONN;
840 break; 921 break;
841 default: 922 default:
842 chip->hp_stat_mask = 0x08; 923 chip->hp_stat_mask = MASK_HDPCONN;
843 break; 924 break;
844 } 925 }
845 break; 926 break;
@@ -854,19 +935,43 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
854 */ 935 */
855 strcpy(chip->card->mixername, "PowerMac AWACS"); 936 strcpy(chip->card->mixername, "PowerMac AWACS");
856 937
857 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers), 938 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
858 snd_pmac_awacs_mixers)) < 0) 939 snd_pmac_awacs_mixers);
940 if (err < 0)
859 return err; 941 return err;
860 if (chip->model == PMAC_SCREAMER) 942 if (beige)
943 ;
944 else if (chip->model == PMAC_SCREAMER)
861 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2), 945 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
862 snd_pmac_screamer_mixers2); 946 snd_pmac_screamer_mixers2);
863 else 947 else if (!pm7500)
864 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2), 948 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
865 snd_pmac_awacs_mixers2); 949 snd_pmac_awacs_mixers2);
866 if (err < 0) 950 if (err < 0)
867 return err; 951 return err;
868 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_master_sw, chip); 952 if (pm7500)
869 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 953 err = build_mixers(chip,
954 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
955 snd_pmac_awacs_mixers_pmac7500);
956 else if (beige)
957 err = build_mixers(chip,
958 ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
959 snd_pmac_screamer_mixers_beige);
960 else if (imac)
961 err = build_mixers(chip,
962 ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
963 snd_pmac_screamer_mixers_imac);
964 else
965 err = build_mixers(chip,
966 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
967 snd_pmac_awacs_mixers_pmac);
968 if (err < 0)
969 return err;
970 chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac)
971 ? &snd_pmac_awacs_master_sw_imac
972 : &snd_pmac_awacs_master_sw, chip);
973 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
974 if (err < 0)
870 return err; 975 return err;
871#ifdef PMAC_AMP_AVAIL 976#ifdef PMAC_AMP_AVAIL
872 if (chip->mixer_data) { 977 if (chip->mixer_data) {
@@ -876,37 +981,58 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
876 * screamer registers. 981 * screamer registers.
877 * in this case, it seems the route C is not used. 982 * in this case, it seems the route C is not used.
878 */ 983 */
879 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol), 984 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
880 snd_pmac_awacs_amp_vol)) < 0) 985 snd_pmac_awacs_amp_vol);
986 if (err < 0)
881 return err; 987 return err;
882 /* overwrite */ 988 /* overwrite */
883 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw, chip); 989 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
884 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 990 chip);
991 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
992 if (err < 0)
885 return err; 993 return err;
886 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw, chip); 994 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
887 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 995 chip);
996 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
997 if (err < 0)
888 return err; 998 return err;
889 } else 999 } else
890#endif /* PMAC_AMP_AVAIL */ 1000#endif /* PMAC_AMP_AVAIL */
891 { 1001 {
892 /* route A = headphone, route C = speaker */ 1002 /* route A = headphone, route C = speaker */
893 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol), 1003 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol),
894 snd_pmac_awacs_speaker_vol)) < 0) 1004 snd_pmac_awacs_speaker_vol);
1005 if (err < 0)
895 return err; 1006 return err;
896 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_speaker_sw, chip); 1007 chip->speaker_sw_ctl = snd_ctl_new1(imac
897 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 1008 ? &snd_pmac_awacs_speaker_sw_imac
1009 : &snd_pmac_awacs_speaker_sw, chip);
1010 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1011 if (err < 0)
898 return err; 1012 return err;
899 } 1013 }
900 1014
901 if (chip->model == PMAC_SCREAMER) { 1015 if (beige)
902 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mic_boost), 1016 err = build_mixers(chip,
903 snd_pmac_screamer_mic_boost)) < 0) 1017 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
904 return err; 1018 snd_pmac_screamer_mic_boost_beige);
905 } else { 1019 else if (imac)
906 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost), 1020 err = build_mixers(chip,
907 snd_pmac_awacs_mic_boost)) < 0) 1021 ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
908 return err; 1022 snd_pmac_screamer_mic_boost_imac);
909 } 1023 else if (chip->model == PMAC_SCREAMER)
1024 err = build_mixers(chip,
1025 ARRAY_SIZE(snd_pmac_screamer_mic_boost),
1026 snd_pmac_screamer_mic_boost);
1027 else if (pm7500)
1028 err = build_mixers(chip,
1029 ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
1030 snd_pmac_awacs_mic_boost_pmac7500);
1031 else
1032 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
1033 snd_pmac_awacs_mic_boost);
1034 if (err < 0)
1035 return err;
910 1036
911 /* 1037 /*
912 * set lowlevel callbacks 1038 * set lowlevel callbacks
@@ -917,7 +1043,8 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
917 chip->resume = snd_pmac_awacs_resume; 1043 chip->resume = snd_pmac_awacs_resume;
918#endif 1044#endif
919#ifdef PMAC_SUPPORT_AUTOMUTE 1045#ifdef PMAC_SUPPORT_AUTOMUTE
920 if ((err = snd_pmac_add_automute(chip)) < 0) 1046 err = snd_pmac_add_automute(chip);
1047 if (err < 0)
921 return err; 1048 return err;
922 chip->detect_headphone = snd_pmac_awacs_detect_headphone; 1049 chip->detect_headphone = snd_pmac_awacs_detect_headphone;
923 chip->update_automute = snd_pmac_awacs_update_automute; 1050 chip->update_automute = snd_pmac_awacs_update_automute;
diff --git a/sound/ppc/awacs.h b/sound/ppc/awacs.h
index 1b2cc44eda57..c33e6a531cf7 100644
--- a/sound/ppc/awacs.h
+++ b/sound/ppc/awacs.h
@@ -116,6 +116,11 @@ struct awacs_regs {
116#define MASK_HDMUTE MASK_AMUTE 116#define MASK_HDMUTE MASK_AMUTE
117#define SHIFT_HDMUTE 9 117#define SHIFT_HDMUTE 9
118#define MASK_PAROUT (0x3 << 10) /* Parallel Out (???) */ 118#define MASK_PAROUT (0x3 << 10) /* Parallel Out (???) */
119#define MASK_PAROUT0 (0x1 << 10) /* Parallel Out (???) */
120#define MASK_PAROUT1 (0x1 << 11) /* Parallel Out (enable speaker) */
121#define SHIFT_PAROUT 10
122#define SHIFT_PAROUT0 10
123#define SHIFT_PAROUT1 11
119 124
120#define SAMPLERATE_48000 (0x0 << 3) /* 48 or 44.1 kHz */ 125#define SAMPLERATE_48000 (0x0 << 3) /* 48 or 44.1 kHz */
121#define SAMPLERATE_32000 (0x1 << 3) /* 32 or 29.4 kHz */ 126#define SAMPLERATE_32000 (0x1 << 3) /* 32 or 29.4 kHz */
@@ -139,7 +144,7 @@ struct awacs_regs {
139#define VOLLEFT(x) (((~(x)) << 6) & MASK_OUTVOLLEFT) 144#define VOLLEFT(x) (((~(x)) << 6) & MASK_OUTVOLLEFT)
140 145
141/* address 6 */ 146/* address 6 */
142#define MASK_MIC_BOOST (0x4) /* screamer mic boost */ 147#define MASK_MIC_BOOST (0x4) /* screamer mic boost */
143#define SHIFT_MIC_BOOST 2 148#define SHIFT_MIC_BOOST 2
144 149
145/* Audio Codec Status Reg Bit Masks */ 150/* Audio Codec Status Reg Bit Masks */
@@ -152,8 +157,15 @@ struct awacs_regs {
152#define MASK_REVISION (0xf << 12) /* Revision Number */ 157#define MASK_REVISION (0xf << 12) /* Revision Number */
153#define MASK_MFGID (0xf << 8) /* Mfg. ID */ 158#define MASK_MFGID (0xf << 8) /* Mfg. ID */
154#define MASK_CODSTATRES (0xf << 4) /* bits 4 - 7 reserved */ 159#define MASK_CODSTATRES (0xf << 4) /* bits 4 - 7 reserved */
155#define MASK_INPPORT (0xf) /* Input Port */ 160#define MASK_INSENSE (0xf) /* port sense bits: */
156#define MASK_HDPCONN 8 /* headphone plugged in */ 161#define MASK_HDPCONN 8 /* headphone plugged in */
162#define MASK_LOCONN 4 /* line-out plugged in */
163#define MASK_LICONN 2 /* line-in plugged in */
164#define MASK_MICCONN 1 /* microphone plugged in */
165#define MASK_LICONN_IMAC 8 /* line-in plugged in */
166#define MASK_HDPRCONN_IMAC 4 /* headphone right plugged in */
167#define MASK_HDPLCONN_IMAC 2 /* headphone left plugged in */
168#define MASK_LOCONN_IMAC 1 /* line-out plugged in */
157 169
158/* Clipping Count Reg Bit Masks */ 170/* Clipping Count Reg Bit Masks */
159/* -------- ----- --- --- ----- */ 171/* -------- ----- --- --- ----- */
@@ -163,7 +175,8 @@ struct awacs_regs {
163/* DBDMA ChannelStatus Bit Masks */ 175/* DBDMA ChannelStatus Bit Masks */
164/* ----- ------------- --- ----- */ 176/* ----- ------------- --- ----- */
165#define MASK_CSERR (0x1 << 7) /* Error */ 177#define MASK_CSERR (0x1 << 7) /* Error */
166#define MASK_EOI (0x1 << 6) /* End of Input -- only for Input Channel */ 178#define MASK_EOI (0x1 << 6) /* End of Input --
179 only for Input Channel */
167#define MASK_CSUNUSED (0x1f << 1) /* bits 1-5 not used */ 180#define MASK_CSUNUSED (0x1f << 1) /* bits 1-5 not used */
168#define MASK_WAIT (0x1) /* Wait */ 181#define MASK_WAIT (0x1) /* Wait */
169 182
diff --git a/sound/ppc/burgundy.c b/sound/ppc/burgundy.c
index 1a545ac0de04..f860d39af36b 100644
--- a/sound/ppc/burgundy.c
+++ b/sound/ppc/burgundy.c
@@ -102,7 +102,8 @@ snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
102} 102}
103 103
104static void 104static void
105snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr, unsigned int val) 105snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr,
106 unsigned int val)
106{ 107{
107 out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff)); 108 out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
108 snd_pmac_burgundy_busy_wait(chip); 109 snd_pmac_burgundy_busy_wait(chip);
@@ -126,8 +127,11 @@ snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr)
126 return val; 127 return val;
127} 128}
128 129
130#define BASE2ADDR(base) ((base) << 12)
131#define ADDR2BASE(addr) ((addr) >> 12)
132
129/* 133/*
130 * Burgundy volume: 0 - 100, stereo 134 * Burgundy volume: 0 - 100, stereo, word reg
131 */ 135 */
132static void 136static void
133snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address, 137snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address,
@@ -168,13 +172,6 @@ snd_pmac_burgundy_read_volume(struct snd_pmac *chip, unsigned int address,
168 volume[1] = 0; 172 volume[1] = 0;
169} 173}
170 174
171
172/*
173 */
174
175#define BASE2ADDR(base) ((base) << 12)
176#define ADDR2BASE(addr) ((addr) >> 12)
177
178static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol, 175static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol,
179 struct snd_ctl_elem_info *uinfo) 176 struct snd_ctl_elem_info *uinfo)
180{ 177{
@@ -191,8 +188,8 @@ static int snd_pmac_burgundy_get_volume(struct snd_kcontrol *kcontrol,
191 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 188 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
192 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 189 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
193 int shift = (kcontrol->private_value >> 8) & 0xff; 190 int shift = (kcontrol->private_value >> 8) & 0xff;
194 snd_pmac_burgundy_read_volume(chip, addr, ucontrol->value.integer.value, 191 snd_pmac_burgundy_read_volume(chip, addr,
195 shift); 192 ucontrol->value.integer.value, shift);
196 return 0; 193 return 0;
197} 194}
198 195
@@ -204,24 +201,163 @@ static int snd_pmac_burgundy_put_volume(struct snd_kcontrol *kcontrol,
204 int shift = (kcontrol->private_value >> 8) & 0xff; 201 int shift = (kcontrol->private_value >> 8) & 0xff;
205 long nvoices[2]; 202 long nvoices[2];
206 203
207 snd_pmac_burgundy_write_volume(chip, addr, ucontrol->value.integer.value, 204 snd_pmac_burgundy_write_volume(chip, addr,
208 shift); 205 ucontrol->value.integer.value, shift);
209 snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift); 206 snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift);
210 return (nvoices[0] != ucontrol->value.integer.value[0] || 207 return (nvoices[0] != ucontrol->value.integer.value[0] ||
211 nvoices[1] != ucontrol->value.integer.value[1]); 208 nvoices[1] != ucontrol->value.integer.value[1]);
212} 209}
213 210
214#define BURGUNDY_VOLUME(xname, xindex, addr, shift) \ 211#define BURGUNDY_VOLUME_W(xname, xindex, addr, shift) \
215{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 212{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
216 .info = snd_pmac_burgundy_info_volume,\ 213 .info = snd_pmac_burgundy_info_volume,\
217 .get = snd_pmac_burgundy_get_volume,\ 214 .get = snd_pmac_burgundy_get_volume,\
218 .put = snd_pmac_burgundy_put_volume,\ 215 .put = snd_pmac_burgundy_put_volume,\
219 .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) } 216 .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) }
220 217
221/* lineout/speaker */ 218/*
219 * Burgundy volume: 0 - 100, stereo, 2-byte reg
220 */
221static void
222snd_pmac_burgundy_write_volume_2b(struct snd_pmac *chip, unsigned int address,
223 long *volume, int off)
224{
225 int lvolume, rvolume;
222 226
223static int snd_pmac_burgundy_info_switch_out(struct snd_kcontrol *kcontrol, 227 off |= off << 2;
224 struct snd_ctl_elem_info *uinfo) 228 lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0;
229 rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0;
230
231 snd_pmac_burgundy_wcb(chip, address + off, lvolume);
232 snd_pmac_burgundy_wcb(chip, address + off + 0x500, rvolume);
233}
234
235static void
236snd_pmac_burgundy_read_volume_2b(struct snd_pmac *chip, unsigned int address,
237 long *volume, int off)
238{
239 volume[0] = snd_pmac_burgundy_rcb(chip, address + off);
240 if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
241 volume[0] -= BURGUNDY_VOLUME_OFFSET;
242 else
243 volume[0] = 0;
244 volume[1] = snd_pmac_burgundy_rcb(chip, address + off + 0x100);
245 if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
246 volume[1] -= BURGUNDY_VOLUME_OFFSET;
247 else
248 volume[1] = 0;
249}
250
251static int snd_pmac_burgundy_info_volume_2b(struct snd_kcontrol *kcontrol,
252 struct snd_ctl_elem_info *uinfo)
253{
254 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
255 uinfo->count = 2;
256 uinfo->value.integer.min = 0;
257 uinfo->value.integer.max = 100;
258 return 0;
259}
260
261static int snd_pmac_burgundy_get_volume_2b(struct snd_kcontrol *kcontrol,
262 struct snd_ctl_elem_value *ucontrol)
263{
264 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
265 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
266 int off = kcontrol->private_value & 0x300;
267 snd_pmac_burgundy_read_volume_2b(chip, addr,
268 ucontrol->value.integer.value, off);
269 return 0;
270}
271
272static int snd_pmac_burgundy_put_volume_2b(struct snd_kcontrol *kcontrol,
273 struct snd_ctl_elem_value *ucontrol)
274{
275 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
276 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
277 int off = kcontrol->private_value & 0x300;
278 long nvoices[2];
279
280 snd_pmac_burgundy_write_volume_2b(chip, addr,
281 ucontrol->value.integer.value, off);
282 snd_pmac_burgundy_read_volume_2b(chip, addr, nvoices, off);
283 return (nvoices[0] != ucontrol->value.integer.value[0] ||
284 nvoices[1] != ucontrol->value.integer.value[1]);
285}
286
287#define BURGUNDY_VOLUME_2B(xname, xindex, addr, off) \
288{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
289 .info = snd_pmac_burgundy_info_volume_2b,\
290 .get = snd_pmac_burgundy_get_volume_2b,\
291 .put = snd_pmac_burgundy_put_volume_2b,\
292 .private_value = ((ADDR2BASE(addr) & 0xff) | ((off) << 8)) }
293
294/*
295 * Burgundy gain/attenuation: 0 - 15, mono/stereo, byte reg
296 */
297static int snd_pmac_burgundy_info_gain(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_info *uinfo)
299{
300 int stereo = (kcontrol->private_value >> 24) & 1;
301 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
302 uinfo->count = stereo + 1;
303 uinfo->value.integer.min = 0;
304 uinfo->value.integer.max = 15;
305 return 0;
306}
307
308static int snd_pmac_burgundy_get_gain(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_value *ucontrol)
310{
311 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
312 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
313 int stereo = (kcontrol->private_value >> 24) & 1;
314 int atten = (kcontrol->private_value >> 25) & 1;
315 int oval;
316
317 oval = snd_pmac_burgundy_rcb(chip, addr);
318 if (atten)
319 oval = ~oval & 0xff;
320 ucontrol->value.integer.value[0] = oval & 0xf;
321 if (stereo)
322 ucontrol->value.integer.value[1] = (oval >> 4) & 0xf;
323 return 0;
324}
325
326static int snd_pmac_burgundy_put_gain(struct snd_kcontrol *kcontrol,
327 struct snd_ctl_elem_value *ucontrol)
328{
329 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
330 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
331 int stereo = (kcontrol->private_value >> 24) & 1;
332 int atten = (kcontrol->private_value >> 25) & 1;
333 int oval, val;
334
335 oval = snd_pmac_burgundy_rcb(chip, addr);
336 if (atten)
337 oval = ~oval & 0xff;
338 val = ucontrol->value.integer.value[0];
339 if (stereo)
340 val |= ucontrol->value.integer.value[1] << 4;
341 else
342 val |= ucontrol->value.integer.value[0] << 4;
343 if (atten)
344 val = ~val & 0xff;
345 snd_pmac_burgundy_wcb(chip, addr, val);
346 return val != oval;
347}
348
349#define BURGUNDY_VOLUME_B(xname, xindex, addr, stereo, atten) \
350{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
351 .info = snd_pmac_burgundy_info_gain,\
352 .get = snd_pmac_burgundy_get_gain,\
353 .put = snd_pmac_burgundy_put_gain,\
354 .private_value = (ADDR2BASE(addr) | ((stereo) << 24) | ((atten) << 25)) }
355
356/*
357 * Burgundy switch: 0/1, mono/stereo, word reg
358 */
359static int snd_pmac_burgundy_info_switch_w(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_info *uinfo)
225{ 361{
226 int stereo = (kcontrol->private_value >> 24) & 1; 362 int stereo = (kcontrol->private_value >> 24) & 1;
227 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 363 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
@@ -231,111 +367,207 @@ static int snd_pmac_burgundy_info_switch_out(struct snd_kcontrol *kcontrol,
231 return 0; 367 return 0;
232} 368}
233 369
234static int snd_pmac_burgundy_get_switch_out(struct snd_kcontrol *kcontrol, 370static int snd_pmac_burgundy_get_switch_w(struct snd_kcontrol *kcontrol,
235 struct snd_ctl_elem_value *ucontrol) 371 struct snd_ctl_elem_value *ucontrol)
236{ 372{
237 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 373 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
238 int lmask = kcontrol->private_value & 0xff; 374 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
239 int rmask = (kcontrol->private_value >> 8) & 0xff; 375 int lmask = 1 << (kcontrol->private_value & 0xff);
376 int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
240 int stereo = (kcontrol->private_value >> 24) & 1; 377 int stereo = (kcontrol->private_value >> 24) & 1;
241 int val = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 378 int val = snd_pmac_burgundy_rcw(chip, addr);
242 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0; 379 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
243 if (stereo) 380 if (stereo)
244 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0; 381 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
245 return 0; 382 return 0;
246} 383}
247 384
248static int snd_pmac_burgundy_put_switch_out(struct snd_kcontrol *kcontrol, 385static int snd_pmac_burgundy_put_switch_w(struct snd_kcontrol *kcontrol,
249 struct snd_ctl_elem_value *ucontrol) 386 struct snd_ctl_elem_value *ucontrol)
250{ 387{
251 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 388 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
252 int lmask = kcontrol->private_value & 0xff; 389 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
253 int rmask = (kcontrol->private_value >> 8) & 0xff; 390 int lmask = 1 << (kcontrol->private_value & 0xff);
391 int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
254 int stereo = (kcontrol->private_value >> 24) & 1; 392 int stereo = (kcontrol->private_value >> 24) & 1;
255 int val, oval; 393 int val, oval;
256 oval = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 394 oval = snd_pmac_burgundy_rcw(chip, addr);
257 val = oval & ~(lmask | rmask); 395 val = oval & ~(lmask | (stereo ? rmask : 0));
258 if (ucontrol->value.integer.value[0]) 396 if (ucontrol->value.integer.value[0])
259 val |= lmask; 397 val |= lmask;
260 if (stereo && ucontrol->value.integer.value[1]) 398 if (stereo && ucontrol->value.integer.value[1])
261 val |= rmask; 399 val |= rmask;
262 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, val); 400 snd_pmac_burgundy_wcw(chip, addr, val);
263 return val != oval; 401 return val != oval;
264} 402}
265 403
266#define BURGUNDY_OUTPUT_SWITCH(xname, xindex, lmask, rmask, stereo) \ 404#define BURGUNDY_SWITCH_W(xname, xindex, addr, lbit, rbit, stereo) \
267{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 405{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
268 .info = snd_pmac_burgundy_info_switch_out,\ 406 .info = snd_pmac_burgundy_info_switch_w,\
269 .get = snd_pmac_burgundy_get_switch_out,\ 407 .get = snd_pmac_burgundy_get_switch_w,\
270 .put = snd_pmac_burgundy_put_switch_out,\ 408 .put = snd_pmac_burgundy_put_switch_w,\
271 .private_value = ((lmask) | ((rmask) << 8) | ((stereo) << 24)) } 409 .private_value = ((lbit) | ((rbit) << 8)\
272 410 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
273/* line/speaker output volume */ 411
274static int snd_pmac_burgundy_info_volume_out(struct snd_kcontrol *kcontrol, 412/*
275 struct snd_ctl_elem_info *uinfo) 413 * Burgundy switch: 0/1, mono/stereo, byte reg, bit mask
414 */
415static int snd_pmac_burgundy_info_switch_b(struct snd_kcontrol *kcontrol,
416 struct snd_ctl_elem_info *uinfo)
276{ 417{
277 int stereo = (kcontrol->private_value >> 24) & 1; 418 int stereo = (kcontrol->private_value >> 24) & 1;
278 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 419 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
279 uinfo->count = stereo + 1; 420 uinfo->count = stereo + 1;
280 uinfo->value.integer.min = 0; 421 uinfo->value.integer.min = 0;
281 uinfo->value.integer.max = 15; 422 uinfo->value.integer.max = 1;
282 return 0; 423 return 0;
283} 424}
284 425
285static int snd_pmac_burgundy_get_volume_out(struct snd_kcontrol *kcontrol, 426static int snd_pmac_burgundy_get_switch_b(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_value *ucontrol) 427 struct snd_ctl_elem_value *ucontrol)
287{ 428{
288 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 429 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
289 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 430 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
431 int lmask = kcontrol->private_value & 0xff;
432 int rmask = (kcontrol->private_value >> 8) & 0xff;
290 int stereo = (kcontrol->private_value >> 24) & 1; 433 int stereo = (kcontrol->private_value >> 24) & 1;
291 int oval; 434 int val = snd_pmac_burgundy_rcb(chip, addr);
292 435 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
293 oval = ~snd_pmac_burgundy_rcb(chip, addr) & 0xff;
294 ucontrol->value.integer.value[0] = oval & 0xf;
295 if (stereo) 436 if (stereo)
296 ucontrol->value.integer.value[1] = (oval >> 4) & 0xf; 437 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
297 return 0; 438 return 0;
298} 439}
299 440
300static int snd_pmac_burgundy_put_volume_out(struct snd_kcontrol *kcontrol, 441static int snd_pmac_burgundy_put_switch_b(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol) 442 struct snd_ctl_elem_value *ucontrol)
302{ 443{
303 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 444 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
304 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 445 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
446 int lmask = kcontrol->private_value & 0xff;
447 int rmask = (kcontrol->private_value >> 8) & 0xff;
305 int stereo = (kcontrol->private_value >> 24) & 1; 448 int stereo = (kcontrol->private_value >> 24) & 1;
306 unsigned int oval, val; 449 int val, oval;
307 450 oval = snd_pmac_burgundy_rcb(chip, addr);
308 oval = ~snd_pmac_burgundy_rcb(chip, addr) & 0xff; 451 val = oval & ~(lmask | rmask);
309 val = ucontrol->value.integer.value[0] & 15; 452 if (ucontrol->value.integer.value[0])
310 if (stereo) 453 val |= lmask;
311 val |= (ucontrol->value.integer.value[1] & 15) << 4; 454 if (stereo && ucontrol->value.integer.value[1])
312 else 455 val |= rmask;
313 val |= val << 4;
314 val = ~val & 0xff;
315 snd_pmac_burgundy_wcb(chip, addr, val); 456 snd_pmac_burgundy_wcb(chip, addr, val);
316 return val != oval; 457 return val != oval;
317} 458}
318 459
319#define BURGUNDY_OUTPUT_VOLUME(xname, xindex, addr, stereo) \ 460#define BURGUNDY_SWITCH_B(xname, xindex, addr, lmask, rmask, stereo) \
320{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 461{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
321 .info = snd_pmac_burgundy_info_volume_out,\ 462 .info = snd_pmac_burgundy_info_switch_b,\
322 .get = snd_pmac_burgundy_get_volume_out,\ 463 .get = snd_pmac_burgundy_get_switch_b,\
323 .put = snd_pmac_burgundy_put_volume_out,\ 464 .put = snd_pmac_burgundy_put_switch_b,\
324 .private_value = (ADDR2BASE(addr) | ((stereo) << 24)) } 465 .private_value = ((lmask) | ((rmask) << 8)\
466 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
325 467
468/*
469 * Burgundy mixers
470 */
326static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] __initdata = { 471static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] __initdata = {
327 BURGUNDY_VOLUME("Master Playback Volume", 0, MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8), 472 BURGUNDY_VOLUME_W("Master Playback Volume", 0,
328 BURGUNDY_VOLUME("Line Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLLINE, 16), 473 MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8),
329 BURGUNDY_VOLUME("CD Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLCD, 16), 474 BURGUNDY_VOLUME_W("CD Capture Volume", 0,
330 BURGUNDY_VOLUME("Mic Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLMIC, 16), 475 MASK_ADDR_BURGUNDY_VOLCD, 16),
331 BURGUNDY_OUTPUT_VOLUME("PC Speaker Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENHP, 0), 476 BURGUNDY_VOLUME_2B("Input Capture Volume", 0,
332 /*BURGUNDY_OUTPUT_VOLUME("PCM Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1),*/ 477 MASK_ADDR_BURGUNDY_VOLMIX01, 2),
333 BURGUNDY_OUTPUT_VOLUME("Headphone Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1), 478 BURGUNDY_VOLUME_2B("Mixer Playback Volume", 0,
334}; 479 MASK_ADDR_BURGUNDY_VOLMIX23, 0),
335static struct snd_kcontrol_new snd_pmac_burgundy_master_sw __initdata = 480 BURGUNDY_VOLUME_B("CD Gain Capture Volume", 0,
336BURGUNDY_OUTPUT_SWITCH("Headphone Playback Switch", 0, BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 481 MASK_ADDR_BURGUNDY_GAINCD, 1, 0),
337static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw __initdata = 482 BURGUNDY_SWITCH_W("Master Capture Switch", 0,
338BURGUNDY_OUTPUT_SWITCH("PC Speaker Playback Switch", 0, BURGUNDY_OUTPUT_INTERN, 0, 0); 483 MASK_ADDR_BURGUNDY_OUTPUTENABLES, 24, 0, 0),
484 BURGUNDY_SWITCH_W("CD Capture Switch", 0,
485 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 0, 16, 1),
486 BURGUNDY_SWITCH_W("CD Playback Switch", 0,
487 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 0, 16, 1),
488/* BURGUNDY_SWITCH_W("Loop Capture Switch", 0,
489 * MASK_ADDR_BURGUNDY_CAPTURESELECTS, 8, 24, 1),
490 * BURGUNDY_SWITCH_B("Mixer out Capture Switch", 0,
491 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x02, 0, 0),
492 * BURGUNDY_SWITCH_B("Mixer Capture Switch", 0,
493 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x01, 0, 0),
494 * BURGUNDY_SWITCH_B("PCM out Capture Switch", 0,
495 * MASK_ADDR_BURGUNDY_HOSTIFEH, 0x02, 0, 0),
496 */ BURGUNDY_SWITCH_B("PCM Capture Switch", 0,
497 MASK_ADDR_BURGUNDY_HOSTIFEH, 0x01, 0, 0)
498};
499static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac[] __initdata = {
500 BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
501 MASK_ADDR_BURGUNDY_VOLLINE, 16),
502 BURGUNDY_VOLUME_W("Mic Capture Volume", 0,
503 MASK_ADDR_BURGUNDY_VOLMIC, 16),
504 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
505 MASK_ADDR_BURGUNDY_GAINLINE, 1, 0),
506 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0,
507 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
508 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0,
509 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
510 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
511 MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1),
512 BURGUNDY_VOLUME_B("Headphone Playback Volume", 0,
513 MASK_ADDR_BURGUNDY_ATTENHP, 1, 1),
514 BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
515 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 1, 17, 1),
516 BURGUNDY_SWITCH_W("Mic Capture Switch", 0,
517 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
518 BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
519 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 1, 17, 1),
520 BURGUNDY_SWITCH_W("Mic Playback Switch", 0,
521 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
522 BURGUNDY_SWITCH_B("Mic Boost Capture Switch", 0,
523 MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1)
524};
525static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac[] __initdata = {
526 BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
527 MASK_ADDR_BURGUNDY_VOLMIC, 16),
528 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
529 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
530 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0,
531 MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1),
532 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
533 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
534 BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
535 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
536 BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
537 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
538/* BURGUNDY_SWITCH_B("Line in Boost Capture Switch", 0,
539 * MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1) */
540};
541static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_imac __initdata =
542BURGUNDY_SWITCH_B("Master Playback Switch", 0,
543 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
544 BURGUNDY_OUTPUT_LEFT | BURGUNDY_LINEOUT_LEFT | BURGUNDY_HP_LEFT,
545 BURGUNDY_OUTPUT_RIGHT | BURGUNDY_LINEOUT_RIGHT | BURGUNDY_HP_RIGHT, 1);
546static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_pmac __initdata =
547BURGUNDY_SWITCH_B("Master Playback Switch", 0,
548 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
549 BURGUNDY_OUTPUT_INTERN
550 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
551static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __initdata =
552BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0,
553 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
554 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
555static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __initdata =
556BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0,
557 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
558 BURGUNDY_OUTPUT_INTERN, 0, 0);
559static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __initdata =
560BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
561 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
562 BURGUNDY_LINEOUT_LEFT, BURGUNDY_LINEOUT_RIGHT, 1);
563static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_pmac __initdata =
564BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
565 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
566 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
567static struct snd_kcontrol_new snd_pmac_burgundy_hp_sw_imac __initdata =
568BURGUNDY_SWITCH_B("Headphone Playback Switch", 0,
569 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
570 BURGUNDY_HP_LEFT, BURGUNDY_HP_RIGHT, 1);
339 571
340 572
341#ifdef PMAC_SUPPORT_AUTOMUTE 573#ifdef PMAC_SUPPORT_AUTOMUTE
@@ -350,16 +582,26 @@ static int snd_pmac_burgundy_detect_headphone(struct snd_pmac *chip)
350static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify) 582static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify)
351{ 583{
352 if (chip->auto_mute) { 584 if (chip->auto_mute) {
585 int imac = machine_is_compatible("iMac");
353 int reg, oreg; 586 int reg, oreg;
354 reg = oreg = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 587 reg = oreg = snd_pmac_burgundy_rcb(chip,
355 reg &= ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT | BURGUNDY_OUTPUT_INTERN); 588 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES);
589 reg &= imac ? ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
590 | BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
591 : ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
592 | BURGUNDY_OUTPUT_INTERN);
356 if (snd_pmac_burgundy_detect_headphone(chip)) 593 if (snd_pmac_burgundy_detect_headphone(chip))
357 reg |= BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT; 594 reg |= imac ? (BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
595 : (BURGUNDY_OUTPUT_LEFT
596 | BURGUNDY_OUTPUT_RIGHT);
358 else 597 else
359 reg |= BURGUNDY_OUTPUT_INTERN; 598 reg |= imac ? (BURGUNDY_OUTPUT_LEFT
599 | BURGUNDY_OUTPUT_RIGHT)
600 : (BURGUNDY_OUTPUT_INTERN);
360 if (do_notify && reg == oreg) 601 if (do_notify && reg == oreg)
361 return; 602 return;
362 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg); 603 snd_pmac_burgundy_wcb(chip,
604 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg);
363 if (do_notify) { 605 if (do_notify) {
364 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 606 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
365 &chip->master_sw_ctl->id); 607 &chip->master_sw_ctl->id);
@@ -378,6 +620,7 @@ static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_noti
378 */ 620 */
379int __init snd_pmac_burgundy_init(struct snd_pmac *chip) 621int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
380{ 622{
623 int imac = machine_is_compatible("iMac");
381 int i, err; 624 int i, err;
382 625
383 /* Checks to see the chip is alive and kicking */ 626 /* Checks to see the chip is alive and kicking */
@@ -386,7 +629,7 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
386 return 1; 629 return 1;
387 } 630 }
388 631
389 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES, 632 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES,
390 DEF_BURGUNDY_OUTPUTENABLES); 633 DEF_BURGUNDY_OUTPUTENABLES);
391 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 634 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
392 DEF_BURGUNDY_MORE_OUTPUTENABLES); 635 DEF_BURGUNDY_MORE_OUTPUTENABLES);
@@ -396,7 +639,8 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
396 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21, 639 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21,
397 DEF_BURGUNDY_INPSEL21); 640 DEF_BURGUNDY_INPSEL21);
398 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3, 641 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3,
399 DEF_BURGUNDY_INPSEL3); 642 imac ? DEF_BURGUNDY_INPSEL3_IMAC
643 : DEF_BURGUNDY_INPSEL3_PMAC);
400 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD, 644 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD,
401 DEF_BURGUNDY_GAINCD); 645 DEF_BURGUNDY_GAINCD);
402 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE, 646 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE,
@@ -422,27 +666,62 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
422 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC, 666 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC,
423 DEF_BURGUNDY_VOLMIC); 667 DEF_BURGUNDY_VOLMIC);
424 668
425 if (chip->hp_stat_mask == 0) 669 if (chip->hp_stat_mask == 0) {
426 /* set headphone-jack detection bit */ 670 /* set headphone-jack detection bit */
427 chip->hp_stat_mask = 0x04; 671 if (imac)
428 672 chip->hp_stat_mask = BURGUNDY_HPDETECT_IMAC_UPPER
673 | BURGUNDY_HPDETECT_IMAC_LOWER
674 | BURGUNDY_HPDETECT_IMAC_SIDE;
675 else
676 chip->hp_stat_mask = BURGUNDY_HPDETECT_PMAC_BACK;
677 }
429 /* 678 /*
430 * build burgundy mixers 679 * build burgundy mixers
431 */ 680 */
432 strcpy(chip->card->mixername, "PowerMac Burgundy"); 681 strcpy(chip->card->mixername, "PowerMac Burgundy");
433 682
434 for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) { 683 for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) {
435 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip))) < 0) 684 err = snd_ctl_add(chip->card,
685 snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip));
686 if (err < 0)
687 return err;
688 }
689 for (i = 0; i < (imac ? ARRAY_SIZE(snd_pmac_burgundy_mixers_imac)
690 : ARRAY_SIZE(snd_pmac_burgundy_mixers_pmac)); i++) {
691 err = snd_ctl_add(chip->card,
692 snd_ctl_new1(imac ? &snd_pmac_burgundy_mixers_imac[i]
693 : &snd_pmac_burgundy_mixers_pmac[i], chip));
694 if (err < 0)
436 return err; 695 return err;
437 } 696 }
438 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_burgundy_master_sw, chip); 697 chip->master_sw_ctl = snd_ctl_new1(imac
439 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 698 ? &snd_pmac_burgundy_master_sw_imac
699 : &snd_pmac_burgundy_master_sw_pmac, chip);
700 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
701 if (err < 0)
702 return err;
703 chip->master_sw_ctl = snd_ctl_new1(imac
704 ? &snd_pmac_burgundy_line_sw_imac
705 : &snd_pmac_burgundy_line_sw_pmac, chip);
706 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
707 if (err < 0)
440 return err; 708 return err;
441 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_burgundy_speaker_sw, chip); 709 if (imac) {
442 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 710 chip->master_sw_ctl = snd_ctl_new1(
711 &snd_pmac_burgundy_hp_sw_imac, chip);
712 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
713 if (err < 0)
714 return err;
715 }
716 chip->speaker_sw_ctl = snd_ctl_new1(imac
717 ? &snd_pmac_burgundy_speaker_sw_imac
718 : &snd_pmac_burgundy_speaker_sw_pmac, chip);
719 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
720 if (err < 0)
443 return err; 721 return err;
444#ifdef PMAC_SUPPORT_AUTOMUTE 722#ifdef PMAC_SUPPORT_AUTOMUTE
445 if ((err = snd_pmac_add_automute(chip)) < 0) 723 err = snd_pmac_add_automute(chip);
724 if (err < 0)
446 return err; 725 return err;
447 726
448 chip->detect_headphone = snd_pmac_burgundy_detect_headphone; 727 chip->detect_headphone = snd_pmac_burgundy_detect_headphone;
diff --git a/sound/ppc/burgundy.h b/sound/ppc/burgundy.h
index ebb457a8342c..7a7f9cf3d299 100644
--- a/sound/ppc/burgundy.h
+++ b/sound/ppc/burgundy.h
@@ -22,6 +22,7 @@
22#ifndef __BURGUNDY_H 22#ifndef __BURGUNDY_H
23#define __BURGUNDY_H 23#define __BURGUNDY_H
24 24
25#define MASK_ADDR_BURGUNDY_INPBOOST (0x10 << 12)
25#define MASK_ADDR_BURGUNDY_INPSEL21 (0x11 << 12) 26#define MASK_ADDR_BURGUNDY_INPSEL21 (0x11 << 12)
26#define MASK_ADDR_BURGUNDY_INPSEL3 (0x12 << 12) 27#define MASK_ADDR_BURGUNDY_INPSEL3 (0x12 << 12)
27 28
@@ -35,7 +36,10 @@
35#define MASK_ADDR_BURGUNDY_VOLCH3 (0x22 << 12) 36#define MASK_ADDR_BURGUNDY_VOLCH3 (0x22 << 12)
36#define MASK_ADDR_BURGUNDY_VOLCH4 (0x23 << 12) 37#define MASK_ADDR_BURGUNDY_VOLCH4 (0x23 << 12)
37 38
39#define MASK_ADDR_BURGUNDY_CAPTURESELECTS (0x2A << 12)
38#define MASK_ADDR_BURGUNDY_OUTPUTSELECTS (0x2B << 12) 40#define MASK_ADDR_BURGUNDY_OUTPUTSELECTS (0x2B << 12)
41#define MASK_ADDR_BURGUNDY_VOLMIX01 (0x2D << 12)
42#define MASK_ADDR_BURGUNDY_VOLMIX23 (0x2E << 12)
39#define MASK_ADDR_BURGUNDY_OUTPUTENABLES (0x2F << 12) 43#define MASK_ADDR_BURGUNDY_OUTPUTENABLES (0x2F << 12)
40 44
41#define MASK_ADDR_BURGUNDY_MASTER_VOLUME (0x30 << 12) 45#define MASK_ADDR_BURGUNDY_MASTER_VOLUME (0x30 << 12)
@@ -45,6 +49,10 @@
45#define MASK_ADDR_BURGUNDY_ATTENSPEAKER (0x62 << 12) 49#define MASK_ADDR_BURGUNDY_ATTENSPEAKER (0x62 << 12)
46#define MASK_ADDR_BURGUNDY_ATTENLINEOUT (0x63 << 12) 50#define MASK_ADDR_BURGUNDY_ATTENLINEOUT (0x63 << 12)
47#define MASK_ADDR_BURGUNDY_ATTENHP (0x64 << 12) 51#define MASK_ADDR_BURGUNDY_ATTENHP (0x64 << 12)
52#define MASK_ADDR_BURGUNDY_ATTENMONO (0x65 << 12)
53
54#define MASK_ADDR_BURGUNDY_HOSTIFAD (0x78 << 12)
55#define MASK_ADDR_BURGUNDY_HOSTIFEH (0x79 << 12)
48 56
49#define MASK_ADDR_BURGUNDY_VOLCD (MASK_ADDR_BURGUNDY_VOLCH1) 57#define MASK_ADDR_BURGUNDY_VOLCD (MASK_ADDR_BURGUNDY_VOLCH1)
50#define MASK_ADDR_BURGUNDY_VOLLINE (MASK_ADDR_BURGUNDY_VOLCH2) 58#define MASK_ADDR_BURGUNDY_VOLLINE (MASK_ADDR_BURGUNDY_VOLCH2)
@@ -59,21 +67,22 @@
59 67
60/* These are all default values for the burgundy */ 68/* These are all default values for the burgundy */
61#define DEF_BURGUNDY_INPSEL21 (0xAA) 69#define DEF_BURGUNDY_INPSEL21 (0xAA)
62#define DEF_BURGUNDY_INPSEL3 (0x0A) 70#define DEF_BURGUNDY_INPSEL3_IMAC (0x0A)
71#define DEF_BURGUNDY_INPSEL3_PMAC (0x05)
63 72
64#define DEF_BURGUNDY_GAINCD (0x33) 73#define DEF_BURGUNDY_GAINCD (0x33)
65#define DEF_BURGUNDY_GAINLINE (0x44) 74#define DEF_BURGUNDY_GAINLINE (0x44)
66#define DEF_BURGUNDY_GAINMIC (0x44) 75#define DEF_BURGUNDY_GAINMIC (0x44)
67#define DEF_BURGUNDY_GAINMODEM (0x06) 76#define DEF_BURGUNDY_GAINMODEM (0x06)
68 77
69/* Remember: lowest volume here is 0x9b */ 78/* Remember: lowest volume here is 0x9B (155) */
70#define DEF_BURGUNDY_VOLCD (0xCCCCCCCC) 79#define DEF_BURGUNDY_VOLCD (0xCCCCCCCC)
71#define DEF_BURGUNDY_VOLLINE (0x00000000) 80#define DEF_BURGUNDY_VOLLINE (0x00000000)
72#define DEF_BURGUNDY_VOLMIC (0x00000000) 81#define DEF_BURGUNDY_VOLMIC (0x00000000)
73#define DEF_BURGUNDY_VOLMODEM (0xCCCCCCCC) 82#define DEF_BURGUNDY_VOLMODEM (0xCCCCCCCC)
74 83
75#define DEF_BURGUNDY_OUTPUTSELECTS (0x010f010f) 84#define DEF_BURGUNDY_OUTPUTSELECTS (0x010F010F)
76#define DEF_BURGUNDY_OUTPUTENABLES (0x0A) 85#define DEF_BURGUNDY_OUTPUTENABLES (0x0100000A)
77 86
78/* #define DEF_BURGUNDY_MASTER_VOLUME (0xFFFFFFFF) */ /* too loud */ 87/* #define DEF_BURGUNDY_MASTER_VOLUME (0xFFFFFFFF) */ /* too loud */
79#define DEF_BURGUNDY_MASTER_VOLUME (0xDDDDDDDD) 88#define DEF_BURGUNDY_MASTER_VOLUME (0xDDDDDDDD)
@@ -84,12 +93,22 @@
84#define DEF_BURGUNDY_ATTENLINEOUT (0xCC) 93#define DEF_BURGUNDY_ATTENLINEOUT (0xCC)
85#define DEF_BURGUNDY_ATTENHP (0xCC) 94#define DEF_BURGUNDY_ATTENHP (0xCC)
86 95
87/* OUTPUTENABLES bits */ 96/* MORE_OUTPUTENABLES bits */
88#define BURGUNDY_OUTPUT_LEFT 0x02 97#define BURGUNDY_OUTPUT_LEFT 0x02
89#define BURGUNDY_OUTPUT_RIGHT 0x04 98#define BURGUNDY_OUTPUT_RIGHT 0x04
99#define BURGUNDY_LINEOUT_LEFT 0x08
100#define BURGUNDY_LINEOUT_RIGHT 0x10
101#define BURGUNDY_HP_LEFT 0x20
102#define BURGUNDY_HP_RIGHT 0x40
90#define BURGUNDY_OUTPUT_INTERN 0x80 103#define BURGUNDY_OUTPUT_INTERN 0x80
91 104
92/* volume offset */ 105/* Headphone detection bits */
106#define BURGUNDY_HPDETECT_PMAC_BACK 0x04
107#define BURGUNDY_HPDETECT_IMAC_SIDE 0x04
108#define BURGUNDY_HPDETECT_IMAC_UPPER 0x08
109#define BURGUNDY_HPDETECT_IMAC_LOWER 0x01
110
111/* Volume offset */
93#define BURGUNDY_VOLUME_OFFSET 155 112#define BURGUNDY_VOLUME_OFFSET 155
94 113
95#endif /* __BURGUNDY_H */ 114#endif /* __BURGUNDY_H */
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 613a565e04de..a38c0c790d2b 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -214,7 +214,7 @@ static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec,
214 int rate_index; 214 int rate_index;
215 long offset; 215 long offset;
216 struct pmac_stream *astr; 216 struct pmac_stream *astr;
217 217
218 rec->dma_size = snd_pcm_lib_buffer_bytes(subs); 218 rec->dma_size = snd_pcm_lib_buffer_bytes(subs);
219 rec->period_size = snd_pcm_lib_period_bytes(subs); 219 rec->period_size = snd_pcm_lib_period_bytes(subs);
220 rec->nperiods = rec->dma_size / rec->period_size; 220 rec->nperiods = rec->dma_size / rec->period_size;
@@ -643,7 +643,7 @@ static int snd_pmac_pcm_close(struct snd_pmac *chip, struct pmac_stream *rec,
643 /* reset constraints */ 643 /* reset constraints */
644 astr->cur_freqs = chip->freqs_ok; 644 astr->cur_freqs = chip->freqs_ok;
645 astr->cur_formats = chip->formats_ok; 645 astr->cur_formats = chip->formats_ok;
646 646
647 return 0; 647 return 0;
648} 648}
649 649
@@ -1300,9 +1300,9 @@ int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return)
1300 1300
1301 snd_pmac_sound_feature(chip, 1); 1301 snd_pmac_sound_feature(chip, 1);
1302 1302
1303 /* reset */ 1303 /* reset & enable interrupts */
1304 if (chip->model == PMAC_AWACS) 1304 if (chip->model <= PMAC_BURGUNDY)
1305 out_le32(&chip->awacs->control, 0x11); 1305 out_le32(&chip->awacs->control, chip->control_mask);
1306 1306
1307 /* Powerbooks have odd ways of enabling inputs such as 1307 /* Powerbooks have odd ways of enabling inputs such as
1308 an expansion-bay CD or sound from an internal modem 1308 an expansion-bay CD or sound from an internal modem
diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
index d8d0b4b2395a..20d0e328288a 100644
--- a/sound/ppc/snd_ps3.c
+++ b/sound/ppc/snd_ps3.c
@@ -137,7 +137,7 @@ static inline void update_mask_reg(unsigned int reg, u32 mask, u32 or_val)
137/* 137/*
138 * ALSA defs 138 * ALSA defs
139 */ 139 */
140const static struct snd_pcm_hardware snd_ps3_pcm_hw = { 140static const struct snd_pcm_hardware snd_ps3_pcm_hw = {
141 .info = (SNDRV_PCM_INFO_MMAP | 141 .info = (SNDRV_PCM_INFO_MMAP |
142 SNDRV_PCM_INFO_NONINTERLEAVED | 142 SNDRV_PCM_INFO_NONINTERLEAVED |
143 SNDRV_PCM_INFO_MMAP_VALID), 143 SNDRV_PCM_INFO_MMAP_VALID),
diff --git a/sound/sh/aica.c b/sound/sh/aica.c
index d49417bf78c6..9ca113326143 100644
--- a/sound/sh/aica.c
+++ b/sound/sh/aica.c
@@ -663,7 +663,7 @@ static int __init aica_init(void)
663 return err; 663 return err;
664 pd = platform_device_register_simple(SND_AICA_DRIVER, -1, 664 pd = platform_device_register_simple(SND_AICA_DRIVER, -1,
665 aica_memory_space, 2); 665 aica_memory_space, 2);
666 if (unlikely(IS_ERR(pd))) { 666 if (IS_ERR(pd)) {
667 platform_driver_unregister(&snd_aica_driver); 667 platform_driver_unregister(&snd_aica_driver);
668 return PTR_ERR(pd); 668 return PTR_ERR(pd);
669 } 669 }
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index 276585215160..18f28ac4bfe8 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -29,6 +29,8 @@ source "sound/soc/pxa/Kconfig"
29source "sound/soc/s3c24xx/Kconfig" 29source "sound/soc/s3c24xx/Kconfig"
30source "sound/soc/sh/Kconfig" 30source "sound/soc/sh/Kconfig"
31source "sound/soc/fsl/Kconfig" 31source "sound/soc/fsl/Kconfig"
32source "sound/soc/davinci/Kconfig"
33source "sound/soc/omap/Kconfig"
32 34
33# Supported codecs 35# Supported codecs
34source "sound/soc/codecs/Kconfig" 36source "sound/soc/codecs/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 4869c9ae7a03..782db2127108 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,4 +1,4 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o 1snd-soc-core-objs := soc-core.o soc-dapm.o
2 2
3obj-$(CONFIG_SND_SOC) += snd-soc-core.o 3obj-$(CONFIG_SND_SOC) += snd-soc-core.o
4obj-$(CONFIG_SND_SOC) += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ 4obj-$(CONFIG_SND_SOC) += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ davinci/ omap/
diff --git a/sound/soc/at91/eti_b1_wm8731.c b/sound/soc/at91/eti_b1_wm8731.c
index ad3ad9d662f8..1347dcf3f80b 100644
--- a/sound/soc/at91/eti_b1_wm8731.c
+++ b/sound/soc/at91/eti_b1_wm8731.c
@@ -33,8 +33,7 @@
33#include <sound/soc.h> 33#include <sound/soc.h>
34#include <sound/soc-dapm.h> 34#include <sound/soc-dapm.h>
35 35
36#include <asm/arch/hardware.h> 36#include <asm/hardware.h>
37#include <asm/arch/at91_pio.h>
38#include <asm/arch/gpio.h> 37#include <asm/arch/gpio.h>
39 38
40#include "../codecs/wm8731.h" 39#include "../codecs/wm8731.h"
@@ -47,13 +46,6 @@
47#define DBG(x...) 46#define DBG(x...)
48#endif 47#endif
49 48
50#define AT91_PIO_TF1 (1 << (AT91_PIN_PB6 - PIN_BASE) % 32)
51#define AT91_PIO_TK1 (1 << (AT91_PIN_PB7 - PIN_BASE) % 32)
52#define AT91_PIO_TD1 (1 << (AT91_PIN_PB8 - PIN_BASE) % 32)
53#define AT91_PIO_RD1 (1 << (AT91_PIN_PB9 - PIN_BASE) % 32)
54#define AT91_PIO_RK1 (1 << (AT91_PIN_PB10 - PIN_BASE) % 32)
55#define AT91_PIO_RF1 (1 << (AT91_PIN_PB11 - PIN_BASE) % 32)
56
57static struct clk *pck1_clk; 49static struct clk *pck1_clk;
58static struct clk *pllb_clk; 50static struct clk *pllb_clk;
59 51
@@ -276,7 +268,6 @@ static struct platform_device *eti_b1_snd_device;
276static int __init eti_b1_init(void) 268static int __init eti_b1_init(void)
277{ 269{
278 int ret; 270 int ret;
279 u32 ssc_pio_lines;
280 struct at91_ssc_periph *ssc = eti_b1_dai.cpu_dai->private_data; 271 struct at91_ssc_periph *ssc = eti_b1_dai.cpu_dai->private_data;
281 272
282 if (!request_mem_region(AT91RM9200_BASE_SSC1, SZ_16K, "soc-audio")) { 273 if (!request_mem_region(AT91RM9200_BASE_SSC1, SZ_16K, "soc-audio")) {
@@ -310,19 +301,12 @@ static int __init eti_b1_init(void)
310 goto fail_io_unmap; 301 goto fail_io_unmap;
311 } 302 }
312 303
313 ssc_pio_lines = AT91_PIO_TF1 | AT91_PIO_TK1 | AT91_PIO_TD1 304 at91_set_A_periph(AT91_PIN_PB6, 0); /* TF1 */
314 | AT91_PIO_RD1 /* | AT91_PIO_RK1 */ | AT91_PIO_RF1; 305 at91_set_A_periph(AT91_PIN_PB7, 0); /* TK1 */
315 306 at91_set_A_periph(AT91_PIN_PB8, 0); /* TD1 */
316 /* Reset all PIO registers and assign lines to peripheral A */ 307 at91_set_A_periph(AT91_PIN_PB9, 0); /* RD1 */
317 at91_sys_write(AT91_PIOB + PIO_PDR, ssc_pio_lines); 308/* at91_set_A_periph(AT91_PIN_PB10, 0);*/ /* RK1 */
318 at91_sys_write(AT91_PIOB + PIO_ODR, ssc_pio_lines); 309 at91_set_A_periph(AT91_PIN_PB11, 0); /* RF1 */
319 at91_sys_write(AT91_PIOB + PIO_IFDR, ssc_pio_lines);
320 at91_sys_write(AT91_PIOB + PIO_CODR, ssc_pio_lines);
321 at91_sys_write(AT91_PIOB + PIO_IDR, ssc_pio_lines);
322 at91_sys_write(AT91_PIOB + PIO_MDDR, ssc_pio_lines);
323 at91_sys_write(AT91_PIOB + PIO_PUDR, ssc_pio_lines);
324 at91_sys_write(AT91_PIOB + PIO_ASR, ssc_pio_lines);
325 at91_sys_write(AT91_PIOB + PIO_OWDR, ssc_pio_lines);
326 310
327 /* 311 /*
328 * Set PCK1 parent to PLLB and its rate to 12 Mhz. 312 * Set PCK1 parent to PLLB and its rate to 12 Mhz.
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 898a7d363284..3903ab7dfa4a 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -18,6 +18,10 @@ config SND_SOC_WM9712
18 tristate 18 tristate
19 depends on SND_SOC 19 depends on SND_SOC
20 20
21config SND_SOC_WM9713
22 tristate
23 depends on SND_SOC
24
21# Cirrus Logic CS4270 Codec 25# Cirrus Logic CS4270 Codec
22config SND_SOC_CS4270 26config SND_SOC_CS4270
23 tristate 27 tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index c6e5338c2666..4e1314c9d3ec 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -3,6 +3,7 @@ snd-soc-wm8731-objs := wm8731.o
3snd-soc-wm8750-objs := wm8750.o 3snd-soc-wm8750-objs := wm8750.o
4snd-soc-wm8753-objs := wm8753.o 4snd-soc-wm8753-objs := wm8753.o
5snd-soc-wm9712-objs := wm9712.o 5snd-soc-wm9712-objs := wm9712.o
6snd-soc-wm9713-objs := wm9713.o
6snd-soc-cs4270-objs := cs4270.o 7snd-soc-cs4270-objs := cs4270.o
7snd-soc-tlv320aic3x-objs := tlv320aic3x.o 8snd-soc-tlv320aic3x-objs := tlv320aic3x.o
8 9
@@ -11,5 +12,6 @@ obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o
11obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o 12obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o
12obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o 13obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o
13obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o 14obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
15obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
14obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 16obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
15obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o 17obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index 242130cf1abd..2a1ffe396908 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -40,7 +40,8 @@ static int ac97_prepare(struct snd_pcm_substream *substream)
40} 40}
41 41
42#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 42#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
43 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) 43 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
44 SNDRV_PCM_RATE_48000)
44 45
45struct snd_soc_codec_dai ac97_dai = { 46struct snd_soc_codec_dai ac97_dai = {
46 .name = "AC97 HiFi", 47 .name = "AC97 HiFi",
@@ -86,7 +87,7 @@ static int ac97_soc_probe(struct platform_device *pdev)
86 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION); 87 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
87 88
88 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 89 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
89 if (socdev->codec == NULL) 90 if (!socdev->codec)
90 return -ENOMEM; 91 return -ENOMEM;
91 codec = socdev->codec; 92 codec = socdev->codec;
92 mutex_init(&codec->mutex); 93 mutex_init(&codec->mutex);
@@ -102,17 +103,17 @@ static int ac97_soc_probe(struct platform_device *pdev)
102 103
103 /* register pcms */ 104 /* register pcms */
104 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 105 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
105 if(ret < 0) 106 if (ret < 0)
106 goto err; 107 goto err;
107 108
108 /* add codec as bus device for standard ac97 */ 109 /* add codec as bus device for standard ac97 */
109 ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus); 110 ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus);
110 if(ret < 0) 111 if (ret < 0)
111 goto bus_err; 112 goto bus_err;
112 113
113 memset(&ac97_template, 0, sizeof(struct snd_ac97_template)); 114 memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
114 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97); 115 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97);
115 if(ret < 0) 116 if (ret < 0)
116 goto bus_err; 117 goto bus_err;
117 118
118 ret = snd_soc_register_card(socdev); 119 ret = snd_soc_register_card(socdev);
@@ -135,7 +136,7 @@ static int ac97_soc_remove(struct platform_device *pdev)
135 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 136 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
136 struct snd_soc_codec *codec = socdev->codec; 137 struct snd_soc_codec *codec = socdev->codec;
137 138
138 if(codec == NULL) 139 if (!codec)
139 return 0; 140 return 0;
140 141
141 snd_soc_free_pcms(socdev); 142 snd_soc_free_pcms(socdev);
@@ -145,11 +146,10 @@ static int ac97_soc_remove(struct platform_device *pdev)
145 return 0; 146 return 0;
146} 147}
147 148
148struct snd_soc_codec_device soc_codec_dev_ac97= { 149struct snd_soc_codec_device soc_codec_dev_ac97 = {
149 .probe = ac97_soc_probe, 150 .probe = ac97_soc_probe,
150 .remove = ac97_soc_remove, 151 .remove = ac97_soc_remove,
151}; 152};
152
153EXPORT_SYMBOL_GPL(soc_codec_dev_ac97); 153EXPORT_SYMBOL_GPL(soc_codec_dev_ac97);
154 154
155MODULE_DESCRIPTION("Soc Generic AC97 driver"); 155MODULE_DESCRIPTION("Soc Generic AC97 driver");
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index bf2ab72d49bf..e73fcfd9f5cd 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -372,7 +372,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
372 struct snd_soc_device *socdev = rtd->socdev; 372 struct snd_soc_device *socdev = rtd->socdev;
373 struct snd_soc_codec *codec = socdev->codec; 373 struct snd_soc_codec *codec = socdev->codec;
374 struct cs4270_private *cs4270 = codec->private_data; 374 struct cs4270_private *cs4270 = codec->private_data;
375 unsigned int ret = 0; 375 int ret;
376 unsigned int i; 376 unsigned int i;
377 unsigned int rate; 377 unsigned int rate;
378 unsigned int ratio; 378 unsigned int ratio;
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 889a897d41ac..630684f4a0bc 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -660,33 +660,53 @@ struct aic3x_rate_divs {
660/* AIC3X codec mclk clock divider coefficients */ 660/* AIC3X codec mclk clock divider coefficients */
661static const struct aic3x_rate_divs aic3x_divs[] = { 661static const struct aic3x_rate_divs aic3x_divs[] = {
662 /* 8k */ 662 /* 8k */
663 {12000000, 8000, 48000, 0xa, 16, 3840},
664 {19200000, 8000, 48000, 0xa, 10, 2400},
663 {22579200, 8000, 48000, 0xa, 8, 7075}, 665 {22579200, 8000, 48000, 0xa, 8, 7075},
664 {33868800, 8000, 48000, 0xa, 5, 8049}, 666 {33868800, 8000, 48000, 0xa, 5, 8049},
665 /* 11.025k */ 667 /* 11.025k */
668 {12000000, 11025, 44100, 0x6, 15, 528},
669 {19200000, 11025, 44100, 0x6, 9, 4080},
666 {22579200, 11025, 44100, 0x6, 8, 0}, 670 {22579200, 11025, 44100, 0x6, 8, 0},
667 {33868800, 11025, 44100, 0x6, 5, 3333}, 671 {33868800, 11025, 44100, 0x6, 5, 3333},
668 /* 16k */ 672 /* 16k */
673 {12000000, 16000, 48000, 0x4, 16, 3840},
674 {19200000, 16000, 48000, 0x4, 10, 2400},
669 {22579200, 16000, 48000, 0x4, 8, 7075}, 675 {22579200, 16000, 48000, 0x4, 8, 7075},
670 {33868800, 16000, 48000, 0x4, 5, 8049}, 676 {33868800, 16000, 48000, 0x4, 5, 8049},
671 /* 22.05k */ 677 /* 22.05k */
678 {12000000, 22050, 44100, 0x2, 15, 528},
679 {19200000, 22050, 44100, 0x2, 9, 4080},
672 {22579200, 22050, 44100, 0x2, 8, 0}, 680 {22579200, 22050, 44100, 0x2, 8, 0},
673 {33868800, 22050, 44100, 0x2, 5, 3333}, 681 {33868800, 22050, 44100, 0x2, 5, 3333},
674 /* 32k */ 682 /* 32k */
683 {12000000, 32000, 48000, 0x1, 16, 3840},
684 {19200000, 32000, 48000, 0x1, 10, 2400},
675 {22579200, 32000, 48000, 0x1, 8, 7075}, 685 {22579200, 32000, 48000, 0x1, 8, 7075},
676 {33868800, 32000, 48000, 0x1, 5, 8049}, 686 {33868800, 32000, 48000, 0x1, 5, 8049},
677 /* 44.1k */ 687 /* 44.1k */
688 {12000000, 44100, 44100, 0x0, 15, 528},
689 {19200000, 44100, 44100, 0x0, 9, 4080},
678 {22579200, 44100, 44100, 0x0, 8, 0}, 690 {22579200, 44100, 44100, 0x0, 8, 0},
679 {33868800, 44100, 44100, 0x0, 5, 3333}, 691 {33868800, 44100, 44100, 0x0, 5, 3333},
680 /* 48k */ 692 /* 48k */
693 {12000000, 48000, 48000, 0x0, 16, 3840},
694 {19200000, 48000, 48000, 0x0, 10, 2400},
681 {22579200, 48000, 48000, 0x0, 8, 7075}, 695 {22579200, 48000, 48000, 0x0, 8, 7075},
682 {33868800, 48000, 48000, 0x0, 5, 8049}, 696 {33868800, 48000, 48000, 0x0, 5, 8049},
683 /* 64k */ 697 /* 64k */
698 {12000000, 64000, 96000, 0x1, 16, 3840},
699 {19200000, 64000, 96000, 0x1, 10, 2400},
684 {22579200, 64000, 96000, 0x1, 8, 7075}, 700 {22579200, 64000, 96000, 0x1, 8, 7075},
685 {33868800, 64000, 96000, 0x1, 5, 8049}, 701 {33868800, 64000, 96000, 0x1, 5, 8049},
686 /* 88.2k */ 702 /* 88.2k */
703 {12000000, 88200, 88200, 0x0, 15, 528},
704 {19200000, 88200, 88200, 0x0, 9, 4080},
687 {22579200, 88200, 88200, 0x0, 8, 0}, 705 {22579200, 88200, 88200, 0x0, 8, 0},
688 {33868800, 88200, 88200, 0x0, 5, 3333}, 706 {33868800, 88200, 88200, 0x0, 5, 3333},
689 /* 96k */ 707 /* 96k */
708 {12000000, 96000, 96000, 0x0, 16, 3840},
709 {19200000, 96000, 96000, 0x0, 10, 2400},
690 {22579200, 96000, 96000, 0x0, 8, 7075}, 710 {22579200, 96000, 96000, 0x0, 8, 7075},
691 {33868800, 96000, 96000, 0x0, 5, 8049}, 711 {33868800, 96000, 96000, 0x0, 5, 8049},
692}; 712};
@@ -807,6 +827,8 @@ static int aic3x_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
807 struct aic3x_priv *aic3x = codec->private_data; 827 struct aic3x_priv *aic3x = codec->private_data;
808 828
809 switch (freq) { 829 switch (freq) {
830 case 12000000:
831 case 19200000:
810 case 22579200: 832 case 22579200:
811 case 33868800: 833 case 33868800:
812 aic3x->sysclk = freq; 834 aic3x->sysclk = freq;
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 9c33fe874928..0cf9265fca8f 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -110,7 +110,7 @@ static int wm8731_write(struct snd_soc_codec *codec, unsigned int reg,
110 data[0] = (reg << 1) | ((value >> 8) & 0x0001); 110 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
111 data[1] = value & 0x00ff; 111 data[1] = value & 0x00ff;
112 112
113 wm8731_write_reg_cache (codec, reg, value); 113 wm8731_write_reg_cache(codec, reg, value);
114 if (codec->hw_write(codec->control_data, data, 2) == 2) 114 if (codec->hw_write(codec->control_data, data, 2) == 2)
115 return 0; 115 return 0;
116 else 116 else
@@ -154,8 +154,10 @@ static int wm8731_add_controls(struct snd_soc_codec *codec)
154 int err, i; 154 int err, i;
155 155
156 for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) { 156 for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) {
157 if ((err = snd_ctl_add(codec->card, 157 err = snd_ctl_add(codec->card,
158 snd_soc_cnew(&wm8731_snd_controls[i],codec, NULL))) < 0) 158 snd_soc_cnew(&wm8731_snd_controls[i],
159 codec, NULL));
160 if (err < 0)
159 return err; 161 return err;
160 } 162 }
161 163
@@ -221,15 +223,13 @@ static int wm8731_add_widgets(struct snd_soc_codec *codec)
221{ 223{
222 int i; 224 int i;
223 225
224 for(i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 226 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
225 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 227 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
226 }
227 228
228 /* set up audio path interconnects */ 229 /* set up audio path interconnects */
229 for(i = 0; intercon[i][0] != NULL; i++) { 230 for (i = 0; intercon[i][0] != NULL; i++)
230 snd_soc_dapm_connect_input(codec, intercon[i][0], 231 snd_soc_dapm_connect_input(codec, intercon[i][0],
231 intercon[i][1], intercon[i][2]); 232 intercon[i][1], intercon[i][2]);
232 }
233 233
234 snd_soc_dapm_new_widgets(codec); 234 snd_soc_dapm_new_widgets(codec);
235 return 0; 235 return 0;
@@ -589,7 +589,7 @@ pcm_err:
589 589
590static struct snd_soc_device *wm8731_socdev; 590static struct snd_soc_device *wm8731_socdev;
591 591
592#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 592#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
593 593
594/* 594/*
595 * WM8731 2 wire address is determined by GPIO5 595 * WM8731 2 wire address is determined by GPIO5
@@ -651,7 +651,7 @@ err:
651 651
652static int wm8731_i2c_detach(struct i2c_client *client) 652static int wm8731_i2c_detach(struct i2c_client *client)
653{ 653{
654 struct snd_soc_codec* codec = i2c_get_clientdata(client); 654 struct snd_soc_codec *codec = i2c_get_clientdata(client);
655 i2c_detach_client(client); 655 i2c_detach_client(client);
656 kfree(codec->reg_cache); 656 kfree(codec->reg_cache);
657 kfree(client); 657 kfree(client);
@@ -709,7 +709,7 @@ static int wm8731_probe(struct platform_device *pdev)
709 INIT_LIST_HEAD(&codec->dapm_paths); 709 INIT_LIST_HEAD(&codec->dapm_paths);
710 710
711 wm8731_socdev = socdev; 711 wm8731_socdev = socdev;
712#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 712#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
713 if (setup->i2c_address) { 713 if (setup->i2c_address) {
714 normal_i2c[0] = setup->i2c_address; 714 normal_i2c[0] = setup->i2c_address;
715 codec->hw_write = (hw_write_t)i2c_master_send; 715 codec->hw_write = (hw_write_t)i2c_master_send;
@@ -734,7 +734,7 @@ static int wm8731_remove(struct platform_device *pdev)
734 734
735 snd_soc_free_pcms(socdev); 735 snd_soc_free_pcms(socdev);
736 snd_soc_dapm_free(socdev); 736 snd_soc_dapm_free(socdev);
737#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 737#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
738 i2c_del_driver(&wm8731_i2c_driver); 738 i2c_del_driver(&wm8731_i2c_driver);
739#endif 739#endif
740 kfree(codec->private_data); 740 kfree(codec->private_data);
@@ -749,7 +749,6 @@ struct snd_soc_codec_device soc_codec_dev_wm8731 = {
749 .suspend = wm8731_suspend, 749 .suspend = wm8731_suspend,
750 .resume = wm8731_resume, 750 .resume = wm8731_resume,
751}; 751};
752
753EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); 752EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731);
754 753
755MODULE_DESCRIPTION("ASoC WM8731 driver"); 754MODULE_DESCRIPTION("ASoC WM8731 driver");
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 77a857b997a2..16cd5d4d5ad9 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -110,7 +110,7 @@ static int wm8750_write(struct snd_soc_codec *codec, unsigned int reg,
110 data[0] = (reg << 1) | ((value >> 8) & 0x0001); 110 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
111 data[1] = value & 0x00ff; 111 data[1] = value & 0x00ff;
112 112
113 wm8750_write_reg_cache (codec, reg, value); 113 wm8750_write_reg_cache(codec, reg, value);
114 if (codec->hw_write(codec->control_data, data, 2) == 2) 114 if (codec->hw_write(codec->control_data, data, 2) == 2)
115 return 0; 115 return 0;
116 else 116 else
@@ -257,7 +257,8 @@ static int wm8750_add_controls(struct snd_soc_codec *codec)
257 257
258 for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) { 258 for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) {
259 err = snd_ctl_add(codec->card, 259 err = snd_ctl_add(codec->card,
260 snd_soc_cnew(&wm8750_snd_controls[i],codec, NULL)); 260 snd_soc_cnew(&wm8750_snd_controls[i],
261 codec, NULL));
261 if (err < 0) 262 if (err < 0)
262 return err; 263 return err;
263 } 264 }
@@ -478,15 +479,13 @@ static int wm8750_add_widgets(struct snd_soc_codec *codec)
478{ 479{
479 int i; 480 int i;
480 481
481 for(i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) { 482 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
482 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]); 483 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
483 }
484 484
485 /* set up audio path audio_mapnects */ 485 /* set up audio path audio_mapnects */
486 for(i = 0; audio_map[i][0] != NULL; i++) { 486 for (i = 0; audio_map[i][0] != NULL; i++)
487 snd_soc_dapm_connect_input(codec, audio_map[i][0], 487 snd_soc_dapm_connect_input(codec, audio_map[i][0],
488 audio_map[i][1], audio_map[i][2]); 488 audio_map[i][1], audio_map[i][2]);
489 }
490 489
491 snd_soc_dapm_new_widgets(codec); 490 snd_soc_dapm_new_widgets(codec);
492 return 0; 491 return 0;
@@ -714,8 +713,8 @@ static int wm8750_dapm_event(struct snd_soc_codec *codec, int event)
714} 713}
715 714
716#define WM8750_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 715#define WM8750_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
717 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 716 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
718 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 717 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
719 718
720#define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 719#define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
721 SNDRV_PCM_FMTBIT_S24_LE) 720 SNDRV_PCM_FMTBIT_S24_LE)
@@ -784,7 +783,8 @@ static int wm8750_resume(struct platform_device *pdev)
784 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) { 783 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
785 wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2); 784 wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
786 codec->dapm_state = SNDRV_CTL_POWER_D0; 785 codec->dapm_state = SNDRV_CTL_POWER_D0;
787 schedule_delayed_work(&codec->delayed_work, msecs_to_jiffies(1000)); 786 schedule_delayed_work(&codec->delayed_work,
787 msecs_to_jiffies(1000));
788 } 788 }
789 789
790 return 0; 790 return 0;
@@ -864,7 +864,7 @@ pcm_err:
864 around */ 864 around */
865static struct snd_soc_device *wm8750_socdev; 865static struct snd_soc_device *wm8750_socdev;
866 866
867#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 867#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
868 868
869/* 869/*
870 * WM8731 2 wire address is determined by GPIO5 870 * WM8731 2 wire address is determined by GPIO5
@@ -979,8 +979,8 @@ static int wm8750_probe(struct platform_device *pdev)
979 INIT_LIST_HEAD(&codec->dapm_paths); 979 INIT_LIST_HEAD(&codec->dapm_paths);
980 wm8750_socdev = socdev; 980 wm8750_socdev = socdev;
981 INIT_DELAYED_WORK(&codec->delayed_work, wm8750_work); 981 INIT_DELAYED_WORK(&codec->delayed_work, wm8750_work);
982 982
983#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 983#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
984 if (setup->i2c_address) { 984 if (setup->i2c_address) {
985 normal_i2c[0] = setup->i2c_address; 985 normal_i2c[0] = setup->i2c_address;
986 codec->hw_write = (hw_write_t)i2c_master_send; 986 codec->hw_write = (hw_write_t)i2c_master_send;
@@ -1025,7 +1025,7 @@ static int wm8750_remove(struct platform_device *pdev)
1025 run_delayed_work(&codec->delayed_work); 1025 run_delayed_work(&codec->delayed_work);
1026 snd_soc_free_pcms(socdev); 1026 snd_soc_free_pcms(socdev);
1027 snd_soc_dapm_free(socdev); 1027 snd_soc_dapm_free(socdev);
1028#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1028#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1029 i2c_del_driver(&wm8750_i2c_driver); 1029 i2c_del_driver(&wm8750_i2c_driver);
1030#endif 1030#endif
1031 kfree(codec->private_data); 1031 kfree(codec->private_data);
@@ -1040,7 +1040,6 @@ struct snd_soc_codec_device soc_codec_dev_wm8750 = {
1040 .suspend = wm8750_suspend, 1040 .suspend = wm8750_suspend,
1041 .resume = wm8750_resume, 1041 .resume = wm8750_resume,
1042}; 1042};
1043
1044EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750); 1043EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750);
1045 1044
1046MODULE_DESCRIPTION("ASoC WM8750 driver"); 1045MODULE_DESCRIPTION("ASoC WM8750 driver");
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index ddd9c71b3fde..fb41826c4c4c 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -150,7 +150,7 @@ static int wm8753_write(struct snd_soc_codec *codec, unsigned int reg,
150 data[0] = (reg << 1) | ((value >> 8) & 0x0001); 150 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
151 data[1] = value & 0x00ff; 151 data[1] = value & 0x00ff;
152 152
153 wm8753_write_reg_cache (codec, reg, value); 153 wm8753_write_reg_cache(codec, reg, value);
154 if (codec->hw_write(codec->control_data, data, 2) == 2) 154 if (codec->hw_write(codec->control_data, data, 2) == 2)
155 return 0; 155 return 0;
156 else 156 else
@@ -198,6 +198,7 @@ static const char *wm8753_mic_sel[] = {"Mic 1", "Mic 2", "Mic 3"};
198static const char *wm8753_dai_mode[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"}; 198static const char *wm8753_dai_mode[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"};
199static const char *wm8753_dat_sel[] = {"Stereo", "Left ADC", "Right ADC", 199static const char *wm8753_dat_sel[] = {"Stereo", "Left ADC", "Right ADC",
200 "Channel Swap"}; 200 "Channel Swap"};
201static const char *wm8753_rout2_phase[] = {"Non Inverted", "Inverted"};
201 202
202static const struct soc_enum wm8753_enum[] = { 203static const struct soc_enum wm8753_enum[] = {
203SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base), 204SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base),
@@ -228,6 +229,7 @@ SOC_ENUM_SINGLE(WM8753_ADC, 4, 2, wm8753_adc_filter),
228SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel), 229SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel),
229SOC_ENUM_SINGLE(WM8753_IOCTL, 2, 4, wm8753_dai_mode), 230SOC_ENUM_SINGLE(WM8753_IOCTL, 2, 4, wm8753_dai_mode),
230SOC_ENUM_SINGLE(WM8753_ADC, 7, 4, wm8753_dat_sel), 231SOC_ENUM_SINGLE(WM8753_ADC, 7, 4, wm8753_dat_sel),
232SOC_ENUM_SINGLE(WM8753_OUTCTL, 2, 2, wm8753_rout2_phase),
231}; 233};
232 234
233 235
@@ -247,7 +249,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol,
247 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 249 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
248 int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL); 250 int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL);
249 251
250 if (((mode &0xc) >> 2) == ucontrol->value.integer.value[0]) 252 if (((mode & 0xc) >> 2) == ucontrol->value.integer.value[0])
251 return 0; 253 return 0;
252 254
253 mode &= 0xfff3; 255 mode &= 0xfff3;
@@ -279,7 +281,7 @@ SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V, WM8753_ROUT2V, 7, 1, 0
279 281
280SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1), 282SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1),
281SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1), 283SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1),
282SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 4, 7, 1), 284SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 0, 7, 1),
283SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0), 285SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0),
284 286
285SOC_ENUM("Bass Boost", wm8753_enum[0]), 287SOC_ENUM("Bass Boost", wm8753_enum[0]),
@@ -330,6 +332,7 @@ SOC_SINGLE("Mic1 Capture Volume", WM8753_INCTL1, 5, 3, 0),
330SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai), 332SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai),
331 333
332SOC_ENUM("ADC Data Select", wm8753_enum[27]), 334SOC_ENUM("ADC Data Select", wm8753_enum[27]),
335SOC_ENUM("ROUT2 Phase", wm8753_enum[28]),
333}; 336};
334 337
335/* add non dapm controls */ 338/* add non dapm controls */
@@ -339,7 +342,8 @@ static int wm8753_add_controls(struct snd_soc_codec *codec)
339 342
340 for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) { 343 for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) {
341 err = snd_ctl_add(codec->card, 344 err = snd_ctl_add(codec->card,
342 snd_soc_cnew(&wm8753_snd_controls[i],codec, NULL)); 345 snd_soc_cnew(&wm8753_snd_controls[i],
346 codec, NULL));
343 if (err < 0) 347 if (err < 0)
344 return err; 348 return err;
345 } 349 }
@@ -719,7 +723,7 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int target,
719 723
720 if ((Ndiv < 6) || (Ndiv > 12)) 724 if ((Ndiv < 6) || (Ndiv > 12))
721 printk(KERN_WARNING 725 printk(KERN_WARNING
722 "WM8753 N value outwith recommended range! N = %d\n",Ndiv); 726 "wm8753: unsupported N = %d\n", Ndiv);
723 727
724 pll_div->n = Ndiv; 728 pll_div->n = Ndiv;
725 Nmod = target % source; 729 Nmod = target % source;
@@ -1297,8 +1301,9 @@ static int wm8753_dapm_event(struct snd_soc_codec *codec, int event)
1297} 1301}
1298 1302
1299#define WM8753_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 1303#define WM8753_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
1300 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 1304 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
1301 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 1305 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1306 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
1302 1307
1303#define WM8753_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 1308#define WM8753_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1304 SNDRV_PCM_FMTBIT_S24_LE) 1309 SNDRV_PCM_FMTBIT_S24_LE)
@@ -1504,9 +1509,9 @@ static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
1504 struct snd_soc_codec *codec = socdev->codec; 1509 struct snd_soc_codec *codec = socdev->codec;
1505 1510
1506 /* we only need to suspend if we are a valid card */ 1511 /* we only need to suspend if we are a valid card */
1507 if(!codec->card) 1512 if (!codec->card)
1508 return 0; 1513 return 0;
1509 1514
1510 wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold); 1515 wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
1511 return 0; 1516 return 0;
1512} 1517}
@@ -1520,7 +1525,7 @@ static int wm8753_resume(struct platform_device *pdev)
1520 u16 *cache = codec->reg_cache; 1525 u16 *cache = codec->reg_cache;
1521 1526
1522 /* we only need to resume if we are a valid card */ 1527 /* we only need to resume if we are a valid card */
1523 if(!codec->card) 1528 if (!codec->card)
1524 return 0; 1529 return 0;
1525 1530
1526 /* Sync reg_cache with the hardware */ 1531 /* Sync reg_cache with the hardware */
@@ -1610,9 +1615,10 @@ static int wm8753_init(struct snd_soc_device *socdev)
1610 wm8753_add_widgets(codec); 1615 wm8753_add_widgets(codec);
1611 ret = snd_soc_register_card(socdev); 1616 ret = snd_soc_register_card(socdev);
1612 if (ret < 0) { 1617 if (ret < 0) {
1613 printk(KERN_ERR "wm8753: failed to register card\n"); 1618 printk(KERN_ERR "wm8753: failed to register card\n");
1614 goto card_err; 1619 goto card_err;
1615 } 1620 }
1621
1616 return ret; 1622 return ret;
1617 1623
1618card_err: 1624card_err:
@@ -1627,7 +1633,7 @@ pcm_err:
1627 around */ 1633 around */
1628static struct snd_soc_device *wm8753_socdev; 1634static struct snd_soc_device *wm8753_socdev;
1629 1635
1630#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1636#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1631 1637
1632/* 1638/*
1633 * WM8753 2 wire address is determined by GPIO5 1639 * WM8753 2 wire address is determined by GPIO5
@@ -1658,7 +1664,7 @@ static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
1658 client_template.addr = addr; 1664 client_template.addr = addr;
1659 1665
1660 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); 1666 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
1661 if (i2c == NULL){ 1667 if (!i2c) {
1662 kfree(codec); 1668 kfree(codec);
1663 return -ENOMEM; 1669 return -ENOMEM;
1664 } 1670 }
@@ -1746,7 +1752,7 @@ static int wm8753_probe(struct platform_device *pdev)
1746 wm8753_socdev = socdev; 1752 wm8753_socdev = socdev;
1747 INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); 1753 INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
1748 1754
1749#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1755#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1750 if (setup->i2c_address) { 1756 if (setup->i2c_address) {
1751 normal_i2c[0] = setup->i2c_address; 1757 normal_i2c[0] = setup->i2c_address;
1752 codec->hw_write = (hw_write_t)i2c_master_send; 1758 codec->hw_write = (hw_write_t)i2c_master_send;
@@ -1790,7 +1796,7 @@ static int wm8753_remove(struct platform_device *pdev)
1790 run_delayed_work(&codec->delayed_work); 1796 run_delayed_work(&codec->delayed_work);
1791 snd_soc_free_pcms(socdev); 1797 snd_soc_free_pcms(socdev);
1792 snd_soc_dapm_free(socdev); 1798 snd_soc_dapm_free(socdev);
1793#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1799#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1794 i2c_del_driver(&wm8753_i2c_driver); 1800 i2c_del_driver(&wm8753_i2c_driver);
1795#endif 1801#endif
1796 kfree(codec->private_data); 1802 kfree(codec->private_data);
@@ -1805,7 +1811,6 @@ struct snd_soc_codec_device soc_codec_dev_wm8753 = {
1805 .suspend = wm8753_suspend, 1811 .suspend = wm8753_suspend,
1806 .resume = wm8753_resume, 1812 .resume = wm8753_resume,
1807}; 1813};
1808
1809EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); 1814EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753);
1810 1815
1811MODULE_DESCRIPTION("ASoC WM8753 driver"); 1816MODULE_DESCRIPTION("ASoC WM8753 driver");
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index 524f7450804f..76c1e2d33e7d 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -37,23 +37,23 @@ static int ac97_write(struct snd_soc_codec *codec,
37 * WM9712 register cache 37 * WM9712 register cache
38 */ 38 */
39static const u16 wm9712_reg[] = { 39static const u16 wm9712_reg[] = {
40 0x6174, 0x8000, 0x8000, 0x8000, // 6 40 0x6174, 0x8000, 0x8000, 0x8000, /* 6 */
41 0x0f0f, 0xaaa0, 0xc008, 0x6808, // e 41 0x0f0f, 0xaaa0, 0xc008, 0x6808, /* e */
42 0xe808, 0xaaa0, 0xad00, 0x8000, // 16 42 0xe808, 0xaaa0, 0xad00, 0x8000, /* 16 */
43 0xe808, 0x3000, 0x8000, 0x0000, // 1e 43 0xe808, 0x3000, 0x8000, 0x0000, /* 1e */
44 0x0000, 0x0000, 0x0000, 0x000f, // 26 44 0x0000, 0x0000, 0x0000, 0x000f, /* 26 */
45 0x0405, 0x0410, 0xbb80, 0xbb80, // 2e 45 0x0405, 0x0410, 0xbb80, 0xbb80, /* 2e */
46 0x0000, 0xbb80, 0x0000, 0x0000, // 36 46 0x0000, 0xbb80, 0x0000, 0x0000, /* 36 */
47 0x0000, 0x2000, 0x0000, 0x0000, // 3e 47 0x0000, 0x2000, 0x0000, 0x0000, /* 3e */
48 0x0000, 0x0000, 0x0000, 0x0000, // 46 48 0x0000, 0x0000, 0x0000, 0x0000, /* 46 */
49 0x0000, 0x0000, 0xf83e, 0xffff, // 4e 49 0x0000, 0x0000, 0xf83e, 0xffff, /* 4e */
50 0x0000, 0x0000, 0x0000, 0xf83e, // 56 50 0x0000, 0x0000, 0x0000, 0xf83e, /* 56 */
51 0x0008, 0x0000, 0x0000, 0x0000, // 5e 51 0x0008, 0x0000, 0x0000, 0x0000, /* 5e */
52 0xb032, 0x3e00, 0x0000, 0x0000, // 66 52 0xb032, 0x3e00, 0x0000, 0x0000, /* 66 */
53 0x0000, 0x0000, 0x0000, 0x0000, // 6e 53 0x0000, 0x0000, 0x0000, 0x0000, /* 6e */
54 0x0000, 0x0000, 0x0000, 0x0006, // 76 54 0x0000, 0x0000, 0x0000, 0x0006, /* 76 */
55 0x0001, 0x0000, 0x574d, 0x4c12, // 7e 55 0x0001, 0x0000, 0x574d, 0x4c12, /* 7e */
56 0x0000, 0x0000 // virtual hp mixers 56 0x0000, 0x0000 /* virtual hp mixers */
57}; 57};
58 58
59/* virtual HP mixers regs */ 59/* virtual HP mixers regs */
@@ -94,7 +94,7 @@ static const struct snd_kcontrol_new wm9712_snd_ac97_controls[] = {
94SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1), 94SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1),
95SOC_SINGLE("Speaker Playback Switch", AC97_MASTER, 15, 1, 1), 95SOC_SINGLE("Speaker Playback Switch", AC97_MASTER, 15, 1, 1),
96SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1), 96SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
97SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE,15, 1, 1), 97SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1),
98SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1), 98SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1),
99 99
100SOC_SINGLE("Speaker Playback ZC Switch", AC97_MASTER, 7, 1, 0), 100SOC_SINGLE("Speaker Playback ZC Switch", AC97_MASTER, 7, 1, 0),
@@ -165,7 +165,8 @@ static int wm9712_add_controls(struct snd_soc_codec *codec)
165 165
166 for (i = 0; i < ARRAY_SIZE(wm9712_snd_ac97_controls); i++) { 166 for (i = 0; i < ARRAY_SIZE(wm9712_snd_ac97_controls); i++) {
167 err = snd_ctl_add(codec->card, 167 err = snd_ctl_add(codec->card,
168 snd_soc_cnew(&wm9712_snd_ac97_controls[i],codec, NULL)); 168 snd_soc_cnew(&wm9712_snd_ac97_controls[i],
169 codec, NULL));
169 if (err < 0) 170 if (err < 0)
170 return err; 171 return err;
171 } 172 }
@@ -363,7 +364,6 @@ static const char *audio_map[][3] = {
363 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"}, 364 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
364 {"Left HP Mixer", "Mic Sidetone Switch", "Mic PGA"}, 365 {"Left HP Mixer", "Mic Sidetone Switch", "Mic PGA"},
365 {"Left HP Mixer", NULL, "ALC Sidetone Mux"}, 366 {"Left HP Mixer", NULL, "ALC Sidetone Mux"},
366 //{"Right HP Mixer", NULL, "HP Mixer"},
367 367
368 /* Right HP mixer */ 368 /* Right HP mixer */
369 {"Right HP Mixer", "PCBeep Bypass Switch", "PCBEEP"}, 369 {"Right HP Mixer", "PCBeep Bypass Switch", "PCBEEP"},
@@ -454,15 +454,13 @@ static int wm9712_add_widgets(struct snd_soc_codec *codec)
454{ 454{
455 int i; 455 int i;
456 456
457 for(i = 0; i < ARRAY_SIZE(wm9712_dapm_widgets); i++) { 457 for (i = 0; i < ARRAY_SIZE(wm9712_dapm_widgets); i++)
458 snd_soc_dapm_new_control(codec, &wm9712_dapm_widgets[i]); 458 snd_soc_dapm_new_control(codec, &wm9712_dapm_widgets[i]);
459 }
460 459
461 /* set up audio path audio_mapnects */ 460 /* set up audio path connects */
462 for(i = 0; audio_map[i][0] != NULL; i++) { 461 for (i = 0; audio_map[i][0] != NULL; i++)
463 snd_soc_dapm_connect_input(codec, audio_map[i][0], 462 snd_soc_dapm_connect_input(codec, audio_map[i][0],
464 audio_map[i][1], audio_map[i][2]); 463 audio_map[i][1], audio_map[i][2]);
465 }
466 464
467 snd_soc_dapm_new_widgets(codec); 465 snd_soc_dapm_new_widgets(codec);
468 return 0; 466 return 0;
@@ -540,7 +538,8 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream)
540} 538}
541 539
542#define WM9712_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 540#define WM9712_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
543 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) 541 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
542 SNDRV_PCM_RATE_48000)
544 543
545struct snd_soc_codec_dai wm9712_dai[] = { 544struct snd_soc_codec_dai wm9712_dai[] = {
546{ 545{
@@ -577,26 +576,16 @@ EXPORT_SYMBOL_GPL(wm9712_dai);
577 576
578static int wm9712_dapm_event(struct snd_soc_codec *codec, int event) 577static int wm9712_dapm_event(struct snd_soc_codec *codec, int event)
579{ 578{
580 u16 reg;
581
582 switch (event) { 579 switch (event) {
583 case SNDRV_CTL_POWER_D0: /* full On */ 580 case SNDRV_CTL_POWER_D0: /* full On */
584 /* liam - maybe enable thermal shutdown */
585 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xdfff;
586 ac97_write(codec, AC97_EXTENDED_MID, reg);
587 break;
588 case SNDRV_CTL_POWER_D1: /* partial On */ 581 case SNDRV_CTL_POWER_D1: /* partial On */
589 case SNDRV_CTL_POWER_D2: /* partial On */ 582 case SNDRV_CTL_POWER_D2: /* partial On */
590 break; 583 break;
591 case SNDRV_CTL_POWER_D3hot: /* Off, with power */ 584 case SNDRV_CTL_POWER_D3hot: /* Off, with power */
592 /* enable master bias and vmid */
593 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xbbff;
594 ac97_write(codec, AC97_EXTENDED_MID, reg);
595 ac97_write(codec, AC97_POWERDOWN, 0x0000); 585 ac97_write(codec, AC97_POWERDOWN, 0x0000);
596 break; 586 break;
597 case SNDRV_CTL_POWER_D3cold: /* Off, without power */ 587 case SNDRV_CTL_POWER_D3cold: /* Off, without power */
598 /* disable everything including AC link */ 588 /* disable everything including AC link */
599 ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
600 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); 589 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
601 ac97_write(codec, AC97_POWERDOWN, 0xffff); 590 ac97_write(codec, AC97_POWERDOWN, 0xffff);
602 break; 591 break;
@@ -641,7 +630,7 @@ static int wm9712_soc_resume(struct platform_device *pdev)
641 u16 *cache = codec->reg_cache; 630 u16 *cache = codec->reg_cache;
642 631
643 ret = wm9712_reset(codec, 1); 632 ret = wm9712_reset(codec, 1);
644 if (ret < 0){ 633 if (ret < 0) {
645 printk(KERN_ERR "could not reset AC97 codec\n"); 634 printk(KERN_ERR "could not reset AC97 codec\n");
646 return ret; 635 return ret;
647 } 636 }
@@ -650,9 +639,9 @@ static int wm9712_soc_resume(struct platform_device *pdev)
650 639
651 if (ret == 0) { 640 if (ret == 0) {
652 /* Sync reg_cache with the hardware after cold reset */ 641 /* Sync reg_cache with the hardware after cold reset */
653 for (i = 2; i < ARRAY_SIZE(wm9712_reg) << 1; i+=2) { 642 for (i = 2; i < ARRAY_SIZE(wm9712_reg) << 1; i += 2) {
654 if (i == AC97_INT_PAGING || i == AC97_POWERDOWN || 643 if (i == AC97_INT_PAGING || i == AC97_POWERDOWN ||
655 (i > 0x58 && i != 0x5c)) 644 (i > 0x58 && i != 0x5c))
656 continue; 645 continue;
657 soc_ac97_ops.write(codec->ac97, i, cache[i>>1]); 646 soc_ac97_ops.write(codec->ac97, i, cache[i>>1]);
658 } 647 }
@@ -765,7 +754,6 @@ struct snd_soc_codec_device soc_codec_dev_wm9712 = {
765 .suspend = wm9712_soc_suspend, 754 .suspend = wm9712_soc_suspend,
766 .resume = wm9712_soc_resume, 755 .resume = wm9712_soc_resume,
767}; 756};
768
769EXPORT_SYMBOL_GPL(soc_codec_dev_wm9712); 757EXPORT_SYMBOL_GPL(soc_codec_dev_wm9712);
770 758
771MODULE_DESCRIPTION("ASoC WM9711/WM9712 driver"); 759MODULE_DESCRIPTION("ASoC WM9711/WM9712 driver");
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
new file mode 100644
index 000000000000..1f241161445c
--- /dev/null
+++ b/sound/soc/codecs/wm9713.c
@@ -0,0 +1,1300 @@
1/*
2 * wm9713.c -- ALSA Soc WM9713 codec support
3 *
4 * Copyright 2006 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * Revision history
14 * 4th Feb 2006 Initial version.
15 *
16 * Features:-
17 *
18 * o Support for AC97 Codec, Voice DAC and Aux DAC
19 * o Support for DAPM
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/device.h>
25#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/ac97_codec.h>
28#include <sound/initval.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32
33#include "wm9713.h"
34
35#define WM9713_VERSION "0.15"
36
37struct wm9713_priv {
38 u32 pll_in; /* PLL input frequency */
39 u32 pll_out; /* PLL output frequency */
40};
41
42static unsigned int ac97_read(struct snd_soc_codec *codec,
43 unsigned int reg);
44static int ac97_write(struct snd_soc_codec *codec,
45 unsigned int reg, unsigned int val);
46
47/*
48 * WM9713 register cache
49 * Reg 0x3c bit 15 is used by touch driver.
50 */
51static const u16 wm9713_reg[] = {
52 0x6174, 0x8080, 0x8080, 0x8080,
53 0xc880, 0xe808, 0xe808, 0x0808,
54 0x00da, 0x8000, 0xd600, 0xaaa0,
55 0xaaa0, 0xaaa0, 0x0000, 0x0000,
56 0x0f0f, 0x0040, 0x0000, 0x7f00,
57 0x0405, 0x0410, 0xbb80, 0xbb80,
58 0x0000, 0xbb80, 0x0000, 0x4523,
59 0x0000, 0x2000, 0x7eff, 0xffff,
60 0x0000, 0x0000, 0x0080, 0x0000,
61 0x0000, 0x0000, 0xfffe, 0xffff,
62 0x0000, 0x0000, 0x0000, 0xfffe,
63 0x4000, 0x0000, 0x0000, 0x0000,
64 0xb032, 0x3e00, 0x0000, 0x0000,
65 0x0000, 0x0000, 0x0000, 0x0000,
66 0x0000, 0x0000, 0x0000, 0x0006,
67 0x0001, 0x0000, 0x574d, 0x4c13,
68 0x0000, 0x0000, 0x0000
69};
70
71/* virtual HP mixers regs */
72#define HPL_MIXER 0x80
73#define HPR_MIXER 0x82
74#define MICB_MUX 0x82
75
76static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
77static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
78static const char *wm9713_rec_src[] =
79 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker",
80 "Mono Out", "Zh"};
81static const char *wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
82static const char *wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
83static const char *wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv",
84 "Mono Vmid", "Inv Vmid"};
85static const char *wm9713_spk_pga[] =
86 {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid",
87 "Speaker Vmid", "Inv Vmid"};
88static const char *wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone",
89 "Headphone Vmid"};
90static const char *wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"};
91static const char *wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"};
92static const char *wm9713_dac_inv[] =
93 {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone",
94 "Headphone Mono", "NC", "Vmid"};
95static const char *wm9713_bass[] = {"Linear Control", "Adaptive Boost"};
96static const char *wm9713_ng_type[] = {"Constant Gain", "Mute"};
97static const char *wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"};
98static const char *wm9713_micb_select[] = {"MPB", "MPA"};
99
100static const struct soc_enum wm9713_enum[] = {
101SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */
102SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */
103SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), /* record mux mono 2 */
104SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src), /* record mux left 3 */
105SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src), /* record mux right 4*/
106SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */
107SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/
108SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */
109SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */
110SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */
111SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 3, wm9713_hp_pga), /* headphone left input 10 */
112SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 3, wm9713_hp_pga), /* headphone right input 11 */
113SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */
114SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */
115SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */
116SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */
117SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */
118SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */
119SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */
120SOC_ENUM_SINGLE(MICB_MUX, 0, 2, wm9713_micb_select), /* mic selection 19 */
121};
122
123static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = {
124SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1),
125SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1),
126SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
127SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 7, 1, 1),
128SOC_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
129SOC_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
130SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
131SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
132
133SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
134SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
135
136SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
137SOC_ENUM("Capture Volume Steps", wm9713_enum[5]),
138SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0),
139SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
140
141SOC_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
142SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
143SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
144
145SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
146SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
147SOC_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
148SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
149SOC_ENUM("ALC Function", wm9713_enum[6]),
150SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
151SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
152SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
153SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
154SOC_ENUM("ALC NG Type", wm9713_enum[17]),
155SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
156
157SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0),
158SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
159
160SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
161SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO, 14, 1, 0),
162SOC_SINGLE("Out4 Playback Volume", AC97_MASTER_MONO, 8, 63, 1),
163
164SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO, 7, 1, 1),
165SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO, 6, 1, 0),
166SOC_SINGLE("Out3 Playback Volume", AC97_MASTER_MONO, 0, 63, 1),
167
168SOC_SINGLE("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1),
169SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1),
170SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
171SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1),
172
173SOC_SINGLE("PC Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1),
174SOC_SINGLE("PC Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1),
175SOC_SINGLE("PC Beep Playback Mono Volume", AC97_AUX, 4, 7, 1),
176
177SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1),
178SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1),
179SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1),
180
181SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1),
182SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1),
183SOC_SINGLE("Aux Playback Mono Volume", AC97_REC_SEL, 4, 7, 1),
184
185SOC_ENUM("Bass Control", wm9713_enum[16]),
186SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
187SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
188SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
189SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
190SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
191
192SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
193SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
194SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
195};
196
197/* add non dapm controls */
198static int wm9713_add_controls(struct snd_soc_codec *codec)
199{
200 int err, i;
201
202 for (i = 0; i < ARRAY_SIZE(wm9713_snd_ac97_controls); i++) {
203 err = snd_ctl_add(codec->card,
204 snd_soc_cnew(&wm9713_snd_ac97_controls[i],
205 codec, NULL));
206 if (err < 0)
207 return err;
208 }
209 return 0;
210}
211
212/* We have to create a fake left and right HP mixers because
213 * the codec only has a single control that is shared by both channels.
214 * This makes it impossible to determine the audio path using the current
215 * register map, thus we add a new (virtual) register to help determine the
216 * audio route within the device.
217 */
218static int mixer_event(struct snd_soc_dapm_widget *w,
219 struct snd_kcontrol *kcontrol, int event)
220{
221 u16 l, r, beep, tone, phone, rec, pcm, aux;
222
223 l = ac97_read(w->codec, HPL_MIXER);
224 r = ac97_read(w->codec, HPR_MIXER);
225 beep = ac97_read(w->codec, AC97_PC_BEEP);
226 tone = ac97_read(w->codec, AC97_MASTER_TONE);
227 phone = ac97_read(w->codec, AC97_PHONE);
228 rec = ac97_read(w->codec, AC97_REC_SEL);
229 pcm = ac97_read(w->codec, AC97_PCM);
230 aux = ac97_read(w->codec, AC97_AUX);
231
232 if (event & SND_SOC_DAPM_PRE_REG)
233 return 0;
234 if ((l & 0x1) || (r & 0x1))
235 ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff);
236 else
237 ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000);
238
239 if ((l & 0x2) || (r & 0x2))
240 ac97_write(w->codec, AC97_MASTER_TONE, tone & 0x7fff);
241 else
242 ac97_write(w->codec, AC97_MASTER_TONE, tone | 0x8000);
243
244 if ((l & 0x4) || (r & 0x4))
245 ac97_write(w->codec, AC97_PHONE, phone & 0x7fff);
246 else
247 ac97_write(w->codec, AC97_PHONE, phone | 0x8000);
248
249 if ((l & 0x8) || (r & 0x8))
250 ac97_write(w->codec, AC97_REC_SEL, rec & 0x7fff);
251 else
252 ac97_write(w->codec, AC97_REC_SEL, rec | 0x8000);
253
254 if ((l & 0x10) || (r & 0x10))
255 ac97_write(w->codec, AC97_PCM, pcm & 0x7fff);
256 else
257 ac97_write(w->codec, AC97_PCM, pcm | 0x8000);
258
259 if ((l & 0x20) || (r & 0x20))
260 ac97_write(w->codec, AC97_AUX, aux & 0x7fff);
261 else
262 ac97_write(w->codec, AC97_AUX, aux | 0x8000);
263
264 return 0;
265}
266
267/* Left Headphone Mixers */
268static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = {
269SOC_DAPM_SINGLE("PC Beep Playback Switch", HPL_MIXER, 5, 1, 0),
270SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0),
271SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0),
272SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0),
273SOC_DAPM_SINGLE("MonoIn Playback Switch", HPL_MIXER, 1, 1, 0),
274SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER, 0, 1, 0),
275};
276
277/* Right Headphone Mixers */
278static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = {
279SOC_DAPM_SINGLE("PC Beep Playback Switch", HPR_MIXER, 5, 1, 0),
280SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0),
281SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0),
282SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0),
283SOC_DAPM_SINGLE("MonoIn Playback Switch", HPR_MIXER, 1, 1, 0),
284SOC_DAPM_SINGLE("Bypass Playback Switch", HPR_MIXER, 0, 1, 0),
285};
286
287/* headphone capture mux */
288static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls =
289SOC_DAPM_ENUM("Route", wm9713_enum[1]);
290
291/* headphone mic mux */
292static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls =
293SOC_DAPM_ENUM("Route", wm9713_enum[0]);
294
295/* Speaker Mixer */
296static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = {
297SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 11, 1, 1),
298SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1),
299SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1),
300SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1),
301SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1),
302SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1),
303};
304
305/* Mono Mixer */
306static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = {
307SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 7, 1, 1),
308SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1),
309SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1),
310SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1),
311SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1),
312SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1),
313SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1),
314SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1),
315};
316
317/* mono mic mux */
318static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls =
319SOC_DAPM_ENUM("Route", wm9713_enum[2]);
320
321/* mono output mux */
322static const struct snd_kcontrol_new wm9713_mono_mux_controls =
323SOC_DAPM_ENUM("Route", wm9713_enum[7]);
324
325/* speaker left output mux */
326static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls =
327SOC_DAPM_ENUM("Route", wm9713_enum[8]);
328
329/* speaker right output mux */
330static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls =
331SOC_DAPM_ENUM("Route", wm9713_enum[9]);
332
333/* headphone left output mux */
334static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls =
335SOC_DAPM_ENUM("Route", wm9713_enum[10]);
336
337/* headphone right output mux */
338static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls =
339SOC_DAPM_ENUM("Route", wm9713_enum[11]);
340
341/* Out3 mux */
342static const struct snd_kcontrol_new wm9713_out3_mux_controls =
343SOC_DAPM_ENUM("Route", wm9713_enum[12]);
344
345/* Out4 mux */
346static const struct snd_kcontrol_new wm9713_out4_mux_controls =
347SOC_DAPM_ENUM("Route", wm9713_enum[13]);
348
349/* DAC inv mux 1 */
350static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls =
351SOC_DAPM_ENUM("Route", wm9713_enum[14]);
352
353/* DAC inv mux 2 */
354static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls =
355SOC_DAPM_ENUM("Route", wm9713_enum[15]);
356
357/* Capture source left */
358static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls =
359SOC_DAPM_ENUM("Route", wm9713_enum[3]);
360
361/* Capture source right */
362static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls =
363SOC_DAPM_ENUM("Route", wm9713_enum[4]);
364
365/* mic source */
366static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls =
367SOC_DAPM_ENUM("Route", wm9713_enum[18]);
368
369/* mic source B virtual control */
370static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls =
371SOC_DAPM_ENUM("Route", wm9713_enum[19]);
372
373static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = {
374SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0,
375 &wm9713_hp_rec_mux_controls),
376SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0,
377 &wm9713_hp_mic_mux_controls),
378SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0,
379 &wm9713_mono_mic_mux_controls),
380SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0,
381 &wm9713_mono_mux_controls),
382SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0,
383 &wm9713_hp_spkl_mux_controls),
384SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0,
385 &wm9713_hp_spkr_mux_controls),
386SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0,
387 &wm9713_hpl_out_mux_controls),
388SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0,
389 &wm9713_hpr_out_mux_controls),
390SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0,
391 &wm9713_out3_mux_controls),
392SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0,
393 &wm9713_out4_mux_controls),
394SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0,
395 &wm9713_dac_inv1_mux_controls),
396SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0,
397 &wm9713_dac_inv2_mux_controls),
398SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
399 &wm9713_rec_srcl_mux_controls),
400SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
401 &wm9713_rec_srcr_mux_controls),
402SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0,
403 &wm9713_mic_sel_mux_controls),
404SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0,
405 &wm9713_micb_sel_mux_controls),
406SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_EXTENDED_MID, 3, 1,
407 &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls),
408 mixer_event, SND_SOC_DAPM_POST_REG),
409SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_EXTENDED_MID, 2, 1,
410 &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls),
411 mixer_event, SND_SOC_DAPM_POST_REG),
412SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1,
413 &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)),
414SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1,
415 &wm9713_speaker_mixer_controls[0],
416 ARRAY_SIZE(wm9713_speaker_mixer_controls)),
417SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1),
418SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1),
419SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
420SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
421SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
422SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
423SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1),
424SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1),
425SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_EXTENDED_MID, 5, 1),
426SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_EXTENDED_MID, 4, 1),
427SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0),
428SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0),
429SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0),
430SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0),
431SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0),
432SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0),
433SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0),
434SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0),
435SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0),
436SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0),
437SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0),
438SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0),
439SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0),
440SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0),
441SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1),
442SND_SOC_DAPM_OUTPUT("MONO"),
443SND_SOC_DAPM_OUTPUT("HPL"),
444SND_SOC_DAPM_OUTPUT("HPR"),
445SND_SOC_DAPM_OUTPUT("SPKL"),
446SND_SOC_DAPM_OUTPUT("SPKR"),
447SND_SOC_DAPM_OUTPUT("OUT3"),
448SND_SOC_DAPM_OUTPUT("OUT4"),
449SND_SOC_DAPM_INPUT("LINEL"),
450SND_SOC_DAPM_INPUT("LINER"),
451SND_SOC_DAPM_INPUT("MONOIN"),
452SND_SOC_DAPM_INPUT("PCBEEP"),
453SND_SOC_DAPM_INPUT("MIC1"),
454SND_SOC_DAPM_INPUT("MIC2A"),
455SND_SOC_DAPM_INPUT("MIC2B"),
456SND_SOC_DAPM_VMID("VMID"),
457};
458
459static const char *audio_map[][3] = {
460 /* left HP mixer */
461 {"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
462 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
463 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
464 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
465 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
466 {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"},
467 {"Left HP Mixer", NULL, "Capture Headphone Mux"},
468
469 /* right HP mixer */
470 {"Right HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
471 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
472 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
473 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
474 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
475 {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"},
476 {"Right HP Mixer", NULL, "Capture Headphone Mux"},
477
478 /* virtual mixer - mixes left & right channels for spk and mono */
479 {"AC97 Mixer", NULL, "Left DAC"},
480 {"AC97 Mixer", NULL, "Right DAC"},
481 {"Line Mixer", NULL, "Right Line In"},
482 {"Line Mixer", NULL, "Left Line In"},
483 {"HP Mixer", NULL, "Left HP Mixer"},
484 {"HP Mixer", NULL, "Right HP Mixer"},
485 {"Capture Mixer", NULL, "Left Capture Source"},
486 {"Capture Mixer", NULL, "Right Capture Source"},
487
488 /* speaker mixer */
489 {"Speaker Mixer", "PC Beep Playback Switch", "PCBEEP"},
490 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
491 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
492 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
493 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
494 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
495
496 /* mono mixer */
497 {"Mono Mixer", "PC Beep Playback Switch", "PCBEEP"},
498 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
499 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
500 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
501 {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"},
502 {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"},
503 {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"},
504 {"Mono Mixer", NULL, "Capture Mono Mux"},
505
506 /* DAC inv mux 1 */
507 {"DAC Inv Mux 1", "Mono", "Mono Mixer"},
508 {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"},
509 {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"},
510 {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"},
511 {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"},
512
513 /* DAC inv mux 2 */
514 {"DAC Inv Mux 2", "Mono", "Mono Mixer"},
515 {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"},
516 {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"},
517 {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"},
518 {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"},
519
520 /* headphone left mux */
521 {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
522
523 /* headphone right mux */
524 {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
525
526 /* speaker left mux */
527 {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"},
528 {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"},
529 {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"},
530
531 /* speaker right mux */
532 {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"},
533 {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"},
534 {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"},
535
536 /* mono mux */
537 {"Mono Out Mux", "Mono", "Mono Mixer"},
538 {"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
539
540 /* out 3 mux */
541 {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"},
542
543 /* out 4 mux */
544 {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
545
546 /* output pga */
547 {"HPL", NULL, "Left Headphone"},
548 {"Left Headphone", NULL, "Left Headphone Out Mux"},
549 {"HPR", NULL, "Right Headphone"},
550 {"Right Headphone", NULL, "Right Headphone Out Mux"},
551 {"OUT3", NULL, "Out 3"},
552 {"Out 3", NULL, "Out 3 Mux"},
553 {"OUT4", NULL, "Out 4"},
554 {"Out 4", NULL, "Out 4 Mux"},
555 {"SPKL", NULL, "Left Speaker"},
556 {"Left Speaker", NULL, "Left Speaker Out Mux"},
557 {"SPKR", NULL, "Right Speaker"},
558 {"Right Speaker", NULL, "Right Speaker Out Mux"},
559 {"MONO", NULL, "Mono Out"},
560 {"Mono Out", NULL, "Mono Out Mux"},
561
562 /* input pga */
563 {"Left Line In", NULL, "LINEL"},
564 {"Right Line In", NULL, "LINER"},
565 {"Mono In", NULL, "MONOIN"},
566 {"Mic A PGA", NULL, "Mic A Pre Amp"},
567 {"Mic B PGA", NULL, "Mic B Pre Amp"},
568
569 /* left capture select */
570 {"Left Capture Source", "Mic 1", "Mic A Pre Amp"},
571 {"Left Capture Source", "Mic 2", "Mic B Pre Amp"},
572 {"Left Capture Source", "Line", "LINEL"},
573 {"Left Capture Source", "Mono In", "MONOIN"},
574 {"Left Capture Source", "Headphone", "Left HP Mixer"},
575 {"Left Capture Source", "Speaker", "Speaker Mixer"},
576 {"Left Capture Source", "Mono Out", "Mono Mixer"},
577
578 /* right capture select */
579 {"Right Capture Source", "Mic 1", "Mic A Pre Amp"},
580 {"Right Capture Source", "Mic 2", "Mic B Pre Amp"},
581 {"Right Capture Source", "Line", "LINER"},
582 {"Right Capture Source", "Mono In", "MONOIN"},
583 {"Right Capture Source", "Headphone", "Right HP Mixer"},
584 {"Right Capture Source", "Speaker", "Speaker Mixer"},
585 {"Right Capture Source", "Mono Out", "Mono Mixer"},
586
587 /* left ADC */
588 {"Left ADC", NULL, "Left Capture Source"},
589
590 /* right ADC */
591 {"Right ADC", NULL, "Right Capture Source"},
592
593 /* mic */
594 {"Mic A Pre Amp", NULL, "Mic A Source"},
595 {"Mic A Source", "Mic 1", "MIC1"},
596 {"Mic A Source", "Mic 2 A", "MIC2A"},
597 {"Mic A Source", "Mic 2 B", "Mic B Source"},
598 {"Mic B Pre Amp", "MPB", "Mic B Source"},
599 {"Mic B Source", NULL, "MIC2B"},
600
601 /* headphone capture */
602 {"Capture Headphone Mux", "Stereo", "Capture Mixer"},
603 {"Capture Headphone Mux", "Left", "Left Capture Source"},
604 {"Capture Headphone Mux", "Right", "Right Capture Source"},
605
606 /* mono capture */
607 {"Capture Mono Mux", "Stereo", "Capture Mixer"},
608 {"Capture Mono Mux", "Left", "Left Capture Source"},
609 {"Capture Mono Mux", "Right", "Right Capture Source"},
610
611 {NULL, NULL, NULL},
612};
613
614static int wm9713_add_widgets(struct snd_soc_codec *codec)
615{
616 int i;
617
618 for (i = 0; i < ARRAY_SIZE(wm9713_dapm_widgets); i++)
619 snd_soc_dapm_new_control(codec, &wm9713_dapm_widgets[i]);
620
621 /* set up audio path audio_mapnects */
622 for (i = 0; audio_map[i][0] != NULL; i++)
623 snd_soc_dapm_connect_input(codec, audio_map[i][0],
624 audio_map[i][1], audio_map[i][2]);
625
626 snd_soc_dapm_new_widgets(codec);
627 return 0;
628}
629
630static unsigned int ac97_read(struct snd_soc_codec *codec,
631 unsigned int reg)
632{
633 u16 *cache = codec->reg_cache;
634
635 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS ||
636 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
637 reg == AC97_CD)
638 return soc_ac97_ops.read(codec->ac97, reg);
639 else {
640 reg = reg >> 1;
641
642 if (reg > (ARRAY_SIZE(wm9713_reg)))
643 return -EIO;
644
645 return cache[reg];
646 }
647}
648
649static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
650 unsigned int val)
651{
652 u16 *cache = codec->reg_cache;
653 if (reg < 0x7c)
654 soc_ac97_ops.write(codec->ac97, reg, val);
655 reg = reg >> 1;
656 if (reg <= (ARRAY_SIZE(wm9713_reg)))
657 cache[reg] = val;
658
659 return 0;
660}
661
662/* PLL divisors */
663struct _pll_div {
664 u32 divsel:1;
665 u32 divctl:1;
666 u32 lf:1;
667 u32 n:4;
668 u32 k:24;
669};
670
671/* The size in bits of the PLL divide multiplied by 10
672 * to allow rounding later */
673#define FIXED_PLL_SIZE ((1 << 22) * 10)
674
675static void pll_factors(struct _pll_div *pll_div, unsigned int source)
676{
677 u64 Kpart;
678 unsigned int K, Ndiv, Nmod, target;
679
680 /* The the PLL output is always 98.304MHz. */
681 target = 98304000;
682
683 /* If the input frequency is over 14.4MHz then scale it down. */
684 if (source > 14400000) {
685 source >>= 1;
686 pll_div->divsel = 1;
687
688 if (source > 14400000) {
689 source >>= 1;
690 pll_div->divctl = 1;
691 } else
692 pll_div->divctl = 0;
693
694 } else {
695 pll_div->divsel = 0;
696 pll_div->divctl = 0;
697 }
698
699 /* Low frequency sources require an additional divide in the
700 * loop.
701 */
702 if (source < 8192000) {
703 pll_div->lf = 1;
704 target >>= 2;
705 } else
706 pll_div->lf = 0;
707
708 Ndiv = target / source;
709 if ((Ndiv < 5) || (Ndiv > 12))
710 printk(KERN_WARNING
711 "WM9713 PLL N value %d out of recommended range!\n",
712 Ndiv);
713
714 pll_div->n = Ndiv;
715 Nmod = target % source;
716 Kpart = FIXED_PLL_SIZE * (long long)Nmod;
717
718 do_div(Kpart, source);
719
720 K = Kpart & 0xFFFFFFFF;
721
722 /* Check if we need to round */
723 if ((K % 10) >= 5)
724 K += 5;
725
726 /* Move down to proper range now rounding is done */
727 K /= 10;
728
729 pll_div->k = K;
730}
731
732/**
733 * Please note that changing the PLL input frequency may require
734 * resynchronisation with the AC97 controller.
735 */
736static int wm9713_set_pll(struct snd_soc_codec *codec,
737 int pll_id, unsigned int freq_in, unsigned int freq_out)
738{
739 struct wm9713_priv *wm9713 = codec->private_data;
740 u16 reg, reg2;
741 struct _pll_div pll_div;
742
743 /* turn PLL off ? */
744 if (freq_in == 0 || freq_out == 0) {
745 /* disable PLL power and select ext source */
746 reg = ac97_read(codec, AC97_HANDSET_RATE);
747 ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080);
748 reg = ac97_read(codec, AC97_EXTENDED_MID);
749 ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200);
750 wm9713->pll_out = 0;
751 return 0;
752 }
753
754 pll_factors(&pll_div, freq_in);
755
756 if (pll_div.k == 0) {
757 reg = (pll_div.n << 12) | (pll_div.lf << 11) |
758 (pll_div.divsel << 9) | (pll_div.divctl << 8);
759 ac97_write(codec, AC97_LINE1_LEVEL, reg);
760 } else {
761 /* write the fractional k to the reg 0x46 pages */
762 reg2 = (pll_div.n << 12) | (pll_div.lf << 11) | (1 << 10) |
763 (pll_div.divsel << 9) | (pll_div.divctl << 8);
764
765 /* K [21:20] */
766 reg = reg2 | (0x5 << 4) | (pll_div.k >> 20);
767 ac97_write(codec, AC97_LINE1_LEVEL, reg);
768
769 /* K [19:16] */
770 reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf);
771 ac97_write(codec, AC97_LINE1_LEVEL, reg);
772
773 /* K [15:12] */
774 reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf);
775 ac97_write(codec, AC97_LINE1_LEVEL, reg);
776
777 /* K [11:8] */
778 reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf);
779 ac97_write(codec, AC97_LINE1_LEVEL, reg);
780
781 /* K [7:4] */
782 reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf);
783 ac97_write(codec, AC97_LINE1_LEVEL, reg);
784
785 reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */
786 ac97_write(codec, AC97_LINE1_LEVEL, reg);
787 }
788
789 /* turn PLL on and select as source */
790 reg = ac97_read(codec, AC97_EXTENDED_MID);
791 ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff);
792 reg = ac97_read(codec, AC97_HANDSET_RATE);
793 ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f);
794 wm9713->pll_out = freq_out;
795 wm9713->pll_in = freq_in;
796
797 /* wait 10ms AC97 link frames for the link to stabilise */
798 schedule_timeout_interruptible(msecs_to_jiffies(10));
799 return 0;
800}
801
802static int wm9713_set_dai_pll(struct snd_soc_codec_dai *codec_dai,
803 int pll_id, unsigned int freq_in, unsigned int freq_out)
804{
805 struct snd_soc_codec *codec = codec_dai->codec;
806 return wm9713_set_pll(codec, pll_id, freq_in, freq_out);
807}
808
809/*
810 * Tristate the PCM DAI lines, tristate can be disabled by calling
811 * wm9713_set_dai_fmt()
812 */
813static int wm9713_set_dai_tristate(struct snd_soc_codec_dai *codec_dai,
814 int tristate)
815{
816 struct snd_soc_codec *codec = codec_dai->codec;
817 u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0x9fff;
818
819 if (tristate)
820 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
821
822 return 0;
823}
824
825/*
826 * Configure WM9713 clock dividers.
827 * Voice DAC needs 256 FS
828 */
829static int wm9713_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai,
830 int div_id, int div)
831{
832 struct snd_soc_codec *codec = codec_dai->codec;
833 u16 reg;
834
835 switch (div_id) {
836 case WM9713_PCMCLK_DIV:
837 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xf0ff;
838 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
839 break;
840 case WM9713_CLKA_MULT:
841 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffd;
842 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
843 break;
844 case WM9713_CLKB_MULT:
845 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffb;
846 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
847 break;
848 case WM9713_HIFI_DIV:
849 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0x8fff;
850 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
851 break;
852 case WM9713_PCMBCLK_DIV:
853 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xf1ff;
854 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg | div);
855 break;
856 case WM9713_PCMCLK_PLL_DIV:
857 reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80;
858 ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x60 | div);
859 break;
860 case WM9713_HIFI_PLL_DIV:
861 reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80;
862 ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x70 | div);
863 break;
864 default:
865 return -EINVAL;
866 }
867
868 return 0;
869}
870
871static int wm9713_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
872 unsigned int fmt)
873{
874 struct snd_soc_codec *codec = codec_dai->codec;
875 u16 gpio = ac97_read(codec, AC97_GPIO_CFG) & 0xffc5;
876 u16 reg = 0x8000;
877
878 /* clock masters */
879 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
880 case SND_SOC_DAIFMT_CBM_CFM:
881 reg |= 0x4000;
882 gpio |= 0x0010;
883 break;
884 case SND_SOC_DAIFMT_CBM_CFS:
885 reg |= 0x6000;
886 gpio |= 0x0018;
887 break;
888 case SND_SOC_DAIFMT_CBS_CFS:
889 reg |= 0x0200;
890 gpio |= 0x001a;
891 break;
892 case SND_SOC_DAIFMT_CBS_CFM:
893 gpio |= 0x0012;
894 break;
895 }
896
897 /* clock inversion */
898 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
899 case SND_SOC_DAIFMT_IB_IF:
900 reg |= 0x00c0;
901 break;
902 case SND_SOC_DAIFMT_IB_NF:
903 reg |= 0x0080;
904 break;
905 case SND_SOC_DAIFMT_NB_IF:
906 reg |= 0x0040;
907 break;
908 }
909
910 /* DAI format */
911 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
912 case SND_SOC_DAIFMT_I2S:
913 reg |= 0x0002;
914 break;
915 case SND_SOC_DAIFMT_RIGHT_J:
916 break;
917 case SND_SOC_DAIFMT_LEFT_J:
918 reg |= 0x0001;
919 break;
920 case SND_SOC_DAIFMT_DSP_A:
921 reg |= 0x0003;
922 break;
923 case SND_SOC_DAIFMT_DSP_B:
924 reg |= 0x0043;
925 break;
926 }
927
928 ac97_write(codec, AC97_GPIO_CFG, gpio);
929 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
930 return 0;
931}
932
933static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream,
934 struct snd_pcm_hw_params *params)
935{
936 struct snd_soc_pcm_runtime *rtd = substream->private_data;
937 struct snd_soc_device *socdev = rtd->socdev;
938 struct snd_soc_codec *codec = socdev->codec;
939 u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3;
940
941 switch (params_format(params)) {
942 case SNDRV_PCM_FORMAT_S16_LE:
943 break;
944 case SNDRV_PCM_FORMAT_S20_3LE:
945 reg |= 0x0004;
946 break;
947 case SNDRV_PCM_FORMAT_S24_LE:
948 reg |= 0x0008;
949 break;
950 case SNDRV_PCM_FORMAT_S32_LE:
951 reg |= 0x000c;
952 break;
953 }
954
955 /* enable PCM interface in master mode */
956 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
957 return 0;
958}
959
960static void wm9713_voiceshutdown(struct snd_pcm_substream *substream)
961{
962 struct snd_soc_pcm_runtime *rtd = substream->private_data;
963 struct snd_soc_device *socdev = rtd->socdev;
964 struct snd_soc_codec *codec = socdev->codec;
965 u16 status;
966
967 /* Gracefully shut down the voice interface. */
968 status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000;
969 ac97_write(codec, AC97_HANDSET_RATE, 0x0280);
970 schedule_timeout_interruptible(msecs_to_jiffies(1));
971 ac97_write(codec, AC97_HANDSET_RATE, 0x0F80);
972 ac97_write(codec, AC97_EXTENDED_MID, status);
973}
974
975static int ac97_hifi_prepare(struct snd_pcm_substream *substream)
976{
977 struct snd_pcm_runtime *runtime = substream->runtime;
978 struct snd_soc_pcm_runtime *rtd = substream->private_data;
979 struct snd_soc_device *socdev = rtd->socdev;
980 struct snd_soc_codec *codec = socdev->codec;
981 int reg;
982 u16 vra;
983
984 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
985 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
986
987 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
988 reg = AC97_PCM_FRONT_DAC_RATE;
989 else
990 reg = AC97_PCM_LR_ADC_RATE;
991
992 return ac97_write(codec, reg, runtime->rate);
993}
994
995static int ac97_aux_prepare(struct snd_pcm_substream *substream)
996{
997 struct snd_pcm_runtime *runtime = substream->runtime;
998 struct snd_soc_pcm_runtime *rtd = substream->private_data;
999 struct snd_soc_device *socdev = rtd->socdev;
1000 struct snd_soc_codec *codec = socdev->codec;
1001 u16 vra, xsle;
1002
1003 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
1004 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
1005 xsle = ac97_read(codec, AC97_PCI_SID);
1006 ac97_write(codec, AC97_PCI_SID, xsle | 0x8000);
1007
1008 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
1009 return -ENODEV;
1010
1011 return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
1012}
1013
1014#define WM9713_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
1015 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
1016 SNDRV_PCM_RATE_48000)
1017
1018#define WM9713_PCM_FORMATS \
1019 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
1020 SNDRV_PCM_FORMAT_S24_LE)
1021
1022struct snd_soc_codec_dai wm9713_dai[] = {
1023{
1024 .name = "AC97 HiFi",
1025 .type = SND_SOC_DAI_AC97_BUS,
1026 .playback = {
1027 .stream_name = "HiFi Playback",
1028 .channels_min = 1,
1029 .channels_max = 2,
1030 .rates = WM9713_RATES,
1031 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1032 .capture = {
1033 .stream_name = "HiFi Capture",
1034 .channels_min = 1,
1035 .channels_max = 2,
1036 .rates = WM9713_RATES,
1037 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1038 .ops = {
1039 .prepare = ac97_hifi_prepare,},
1040 .dai_ops = {
1041 .set_clkdiv = wm9713_set_dai_clkdiv,
1042 .set_pll = wm9713_set_dai_pll,},
1043 },
1044 {
1045 .name = "AC97 Aux",
1046 .playback = {
1047 .stream_name = "Aux Playback",
1048 .channels_min = 1,
1049 .channels_max = 1,
1050 .rates = WM9713_RATES,
1051 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1052 .ops = {
1053 .prepare = ac97_aux_prepare,},
1054 .dai_ops = {
1055 .set_clkdiv = wm9713_set_dai_clkdiv,
1056 .set_pll = wm9713_set_dai_pll,},
1057 },
1058 {
1059 .name = "WM9713 Voice",
1060 .playback = {
1061 .stream_name = "Voice Playback",
1062 .channels_min = 1,
1063 .channels_max = 1,
1064 .rates = WM9713_RATES,
1065 .formats = WM9713_PCM_FORMATS,},
1066 .capture = {
1067 .stream_name = "Voice Capture",
1068 .channels_min = 1,
1069 .channels_max = 2,
1070 .rates = WM9713_RATES,
1071 .formats = WM9713_PCM_FORMATS,},
1072 .ops = {
1073 .hw_params = wm9713_pcm_hw_params,
1074 .shutdown = wm9713_voiceshutdown,},
1075 .dai_ops = {
1076 .set_clkdiv = wm9713_set_dai_clkdiv,
1077 .set_pll = wm9713_set_dai_pll,
1078 .set_fmt = wm9713_set_dai_fmt,
1079 .set_tristate = wm9713_set_dai_tristate,
1080 },
1081 },
1082};
1083EXPORT_SYMBOL_GPL(wm9713_dai);
1084
1085int wm9713_reset(struct snd_soc_codec *codec, int try_warm)
1086{
1087 if (try_warm && soc_ac97_ops.warm_reset) {
1088 soc_ac97_ops.warm_reset(codec->ac97);
1089 if (!(ac97_read(codec, 0) & 0x8000))
1090 return 1;
1091 }
1092
1093 soc_ac97_ops.reset(codec->ac97);
1094 if (ac97_read(codec, 0) & 0x8000)
1095 return -EIO;
1096 return 0;
1097}
1098EXPORT_SYMBOL_GPL(wm9713_reset);
1099
1100static int wm9713_dapm_event(struct snd_soc_codec *codec, int event)
1101{
1102 u16 reg;
1103
1104 switch (event) {
1105 case SNDRV_CTL_POWER_D0: /* full On */
1106 /* enable thermal shutdown */
1107 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x1bff;
1108 ac97_write(codec, AC97_EXTENDED_MID, reg);
1109 break;
1110 case SNDRV_CTL_POWER_D1: /* partial On */
1111 case SNDRV_CTL_POWER_D2: /* partial On */
1112 break;
1113 case SNDRV_CTL_POWER_D3hot: /* Off, with power */
1114 /* enable master bias and vmid */
1115 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x3bff;
1116 ac97_write(codec, AC97_EXTENDED_MID, reg);
1117 ac97_write(codec, AC97_POWERDOWN, 0x0000);
1118 break;
1119 case SNDRV_CTL_POWER_D3cold: /* Off, without power */
1120 /* disable everything including AC link */
1121 ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
1122 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
1123 ac97_write(codec, AC97_POWERDOWN, 0xffff);
1124 break;
1125 }
1126 codec->dapm_state = event;
1127 return 0;
1128}
1129
1130static int wm9713_soc_suspend(struct platform_device *pdev,
1131 pm_message_t state)
1132{
1133 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1134 struct snd_soc_codec *codec = socdev->codec;
1135 u16 reg;
1136
1137 /* Disable everything except touchpanel - that will be handled
1138 * by the touch driver and left disabled if touch is not in
1139 * use. */
1140 reg = ac97_read(codec, AC97_EXTENDED_MID);
1141 ac97_write(codec, AC97_EXTENDED_MID, reg | 0x7fff);
1142 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
1143 ac97_write(codec, AC97_POWERDOWN, 0x6f00);
1144 ac97_write(codec, AC97_POWERDOWN, 0xffff);
1145
1146 return 0;
1147}
1148
1149static int wm9713_soc_resume(struct platform_device *pdev)
1150{
1151 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1152 struct snd_soc_codec *codec = socdev->codec;
1153 struct wm9713_priv *wm9713 = codec->private_data;
1154 int i, ret;
1155 u16 *cache = codec->reg_cache;
1156
1157 ret = wm9713_reset(codec, 1);
1158 if (ret < 0) {
1159 printk(KERN_ERR "could not reset AC97 codec\n");
1160 return ret;
1161 }
1162
1163 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
1164
1165 /* do we need to re-start the PLL ? */
1166 if (wm9713->pll_out)
1167 wm9713_set_pll(codec, 0, wm9713->pll_in, wm9713->pll_out);
1168
1169 /* only synchronise the codec if warm reset failed */
1170 if (ret == 0) {
1171 for (i = 2; i < ARRAY_SIZE(wm9713_reg) << 1; i += 2) {
1172 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID ||
1173 i == AC97_EXTENDED_MSTATUS || i > 0x66)
1174 continue;
1175 soc_ac97_ops.write(codec->ac97, i, cache[i>>1]);
1176 }
1177 }
1178
1179 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
1180 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D0);
1181
1182 return ret;
1183}
1184
1185static int wm9713_soc_probe(struct platform_device *pdev)
1186{
1187 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1188 struct snd_soc_codec *codec;
1189 int ret = 0, reg;
1190
1191 printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION);
1192
1193 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
1194 if (socdev->codec == NULL)
1195 return -ENOMEM;
1196 codec = socdev->codec;
1197 mutex_init(&codec->mutex);
1198
1199 codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL);
1200 if (codec->reg_cache == NULL) {
1201 ret = -ENOMEM;
1202 goto cache_err;
1203 }
1204 codec->reg_cache_size = sizeof(wm9713_reg);
1205 codec->reg_cache_step = 2;
1206
1207 codec->private_data = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL);
1208 if (codec->private_data == NULL) {
1209 ret = -ENOMEM;
1210 goto priv_err;
1211 }
1212
1213 codec->name = "WM9713";
1214 codec->owner = THIS_MODULE;
1215 codec->dai = wm9713_dai;
1216 codec->num_dai = ARRAY_SIZE(wm9713_dai);
1217 codec->write = ac97_write;
1218 codec->read = ac97_read;
1219 codec->dapm_event = wm9713_dapm_event;
1220 INIT_LIST_HEAD(&codec->dapm_widgets);
1221 INIT_LIST_HEAD(&codec->dapm_paths);
1222
1223 ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0);
1224 if (ret < 0)
1225 goto codec_err;
1226
1227 /* register pcms */
1228 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1229 if (ret < 0)
1230 goto pcm_err;
1231
1232 /* do a cold reset for the controller and then try
1233 * a warm reset followed by an optional cold reset for codec */
1234 wm9713_reset(codec, 0);
1235 ret = wm9713_reset(codec, 1);
1236 if (ret < 0) {
1237 printk(KERN_ERR "AC97 link error\n");
1238 goto reset_err;
1239 }
1240
1241 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
1242
1243 /* unmute the adc - move to kcontrol */
1244 reg = ac97_read(codec, AC97_CD) & 0x7fff;
1245 ac97_write(codec, AC97_CD, reg);
1246
1247 wm9713_add_controls(codec);
1248 wm9713_add_widgets(codec);
1249 ret = snd_soc_register_card(socdev);
1250 if (ret < 0)
1251 goto reset_err;
1252 return 0;
1253
1254reset_err:
1255 snd_soc_free_pcms(socdev);
1256
1257pcm_err:
1258 snd_soc_free_ac97_codec(codec);
1259
1260codec_err:
1261 kfree(codec->private_data);
1262
1263priv_err:
1264 kfree(codec->reg_cache);
1265
1266cache_err:
1267 kfree(socdev->codec);
1268 socdev->codec = NULL;
1269 return ret;
1270}
1271
1272static int wm9713_soc_remove(struct platform_device *pdev)
1273{
1274 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1275 struct snd_soc_codec *codec = socdev->codec;
1276
1277 if (codec == NULL)
1278 return 0;
1279
1280 snd_soc_dapm_free(socdev);
1281 snd_soc_free_pcms(socdev);
1282 snd_soc_free_ac97_codec(codec);
1283 kfree(codec->private_data);
1284 kfree(codec->reg_cache);
1285 kfree(codec->dai);
1286 kfree(codec);
1287 return 0;
1288}
1289
1290struct snd_soc_codec_device soc_codec_dev_wm9713 = {
1291 .probe = wm9713_soc_probe,
1292 .remove = wm9713_soc_remove,
1293 .suspend = wm9713_soc_suspend,
1294 .resume = wm9713_soc_resume,
1295};
1296EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713);
1297
1298MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver");
1299MODULE_AUTHOR("Liam Girdwood");
1300MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm9713.h b/sound/soc/codecs/wm9713.h
new file mode 100644
index 000000000000..d357b6c8134b
--- /dev/null
+++ b/sound/soc/codecs/wm9713.h
@@ -0,0 +1,53 @@
1/*
2 * wm9713.h -- WM9713 Soc Audio driver
3 */
4
5#ifndef _WM9713_H
6#define _WM9713_H
7
8/* clock inputs */
9#define WM9713_CLKA_PIN 0
10#define WM9713_CLKB_PIN 1
11
12/* clock divider ID's */
13#define WM9713_PCMCLK_DIV 0
14#define WM9713_CLKA_MULT 1
15#define WM9713_CLKB_MULT 2
16#define WM9713_HIFI_DIV 3
17#define WM9713_PCMBCLK_DIV 4
18#define WM9713_PCMCLK_PLL_DIV 5
19#define WM9713_HIFI_PLL_DIV 6
20
21/* Calculate the appropriate bit mask for the external PCM clock divider */
22#define WM9713_PCMDIV(x) ((x - 1) << 8)
23
24/* Calculate the appropriate bit mask for the external HiFi clock divider */
25#define WM9713_HIFIDIV(x) ((x - 1) << 12)
26
27/* MCLK clock mulitipliers */
28#define WM9713_CLKA_X1 (0 << 1)
29#define WM9713_CLKA_X2 (1 << 1)
30#define WM9713_CLKB_X1 (0 << 2)
31#define WM9713_CLKB_X2 (1 << 2)
32
33/* MCLK clock MUX */
34#define WM9713_CLK_MUX_A (0 << 0)
35#define WM9713_CLK_MUX_B (1 << 0)
36
37/* Voice DAI BCLK divider */
38#define WM9713_PCMBCLK_DIV_1 (0 << 9)
39#define WM9713_PCMBCLK_DIV_2 (1 << 9)
40#define WM9713_PCMBCLK_DIV_4 (2 << 9)
41#define WM9713_PCMBCLK_DIV_8 (3 << 9)
42#define WM9713_PCMBCLK_DIV_16 (4 << 9)
43
44#define WM9713_DAI_AC97_HIFI 0
45#define WM9713_DAI_AC97_AUX 1
46#define WM9713_DAI_PCM_VOICE 2
47
48extern struct snd_soc_codec_device soc_codec_dev_wm9713;
49extern struct snd_soc_codec_dai wm9713_dai[3];
50
51int wm9713_reset(struct snd_soc_codec *codec, int try_warm);
52
53#endif
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
new file mode 100644
index 000000000000..20680c551aab
--- /dev/null
+++ b/sound/soc/davinci/Kconfig
@@ -0,0 +1,19 @@
1config SND_DAVINCI_SOC
2 tristate "SoC Audio for the TI DAVINCI chip"
3 depends on ARCH_DAVINCI && SND_SOC
4 help
5 Say Y or M if you want to add support for codecs attached to
6 the DAVINCI AC97 or I2S interface. You will also need
7 to select the audio interfaces to support below.
8
9config SND_DAVINCI_SOC_I2S
10 tristate
11
12config SND_DAVINCI_SOC_EVM
13 tristate "SoC Audio support for DaVinci EVM"
14 depends on SND_DAVINCI_SOC && MACH_DAVINCI_EVM
15 select SND_DAVINCI_SOC_I2S
16 select SND_SOC_TLV320AIC3X
17 help
18 Say Y if you want to add support for SoC audio on TI
19 DaVinci EVM platform.
diff --git a/sound/soc/davinci/Makefile b/sound/soc/davinci/Makefile
new file mode 100644
index 000000000000..ca772e5b4637
--- /dev/null
+++ b/sound/soc/davinci/Makefile
@@ -0,0 +1,11 @@
1# DAVINCI Platform Support
2snd-soc-davinci-objs := davinci-pcm.o
3snd-soc-davinci-i2s-objs := davinci-i2s.o
4
5obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o
6obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o
7
8# DAVINCI Machine Support
9snd-soc-evm-objs := davinci-evm.o
10
11obj-$(CONFIG_SND_DAVINCI_SOC_EVM) += snd-soc-evm.o
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
new file mode 100644
index 000000000000..fcd165240333
--- /dev/null
+++ b/sound/soc/davinci/davinci-evm.c
@@ -0,0 +1,208 @@
1/*
2 * ASoC driver for TI DAVINCI EVM platform
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/timer.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
17#include <sound/core.h>
18#include <sound/pcm.h>
19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
21
22#include <asm/mach-types.h>
23#include <asm/dma.h>
24#include <asm/arch/hardware.h>
25
26#include "../codecs/tlv320aic3x.h"
27#include "davinci-pcm.h"
28#include "davinci-i2s.h"
29
30#define EVM_CODEC_CLOCK 22579200
31
32static int evm_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
34{
35 struct snd_soc_pcm_runtime *rtd = substream->private_data;
36 struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
37 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
38 int ret = 0;
39
40 /* set codec DAI configuration */
41 ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
42 SND_SOC_DAIFMT_CBM_CFM);
43 if (ret < 0)
44 return ret;
45
46 /* set cpu DAI configuration */
47 ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
48 SND_SOC_DAIFMT_IB_NF);
49 if (ret < 0)
50 return ret;
51
52 /* set the codec system clock */
53 ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK,
54 SND_SOC_CLOCK_OUT);
55 if (ret < 0)
56 return ret;
57
58 return 0;
59}
60
61static struct snd_soc_ops evm_ops = {
62 .hw_params = evm_hw_params,
63};
64
65/* davinci-evm machine dapm widgets */
66static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
67 SND_SOC_DAPM_HP("Headphone Jack", NULL),
68 SND_SOC_DAPM_LINE("Line Out", NULL),
69 SND_SOC_DAPM_MIC("Mic Jack", NULL),
70 SND_SOC_DAPM_LINE("Line In", NULL),
71};
72
73/* davinci-evm machine audio_mapnections to the codec pins */
74static const char *audio_map[][3] = {
75 /* Headphone connected to HPLOUT, HPROUT */
76 {"Headphone Jack", NULL, "HPLOUT"},
77 {"Headphone Jack", NULL, "HPROUT"},
78
79 /* Line Out connected to LLOUT, RLOUT */
80 {"Line Out", NULL, "LLOUT"},
81 {"Line Out", NULL, "RLOUT"},
82
83 /* Mic connected to (MIC3L | MIC3R) */
84 {"MIC3L", NULL, "Mic Bias 2V"},
85 {"MIC3R", NULL, "Mic Bias 2V"},
86 {"Mic Bias 2V", NULL, "Mic Jack"},
87
88 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
89 {"LINE1L", NULL, "Line In"},
90 {"LINE2L", NULL, "Line In"},
91 {"LINE1R", NULL, "Line In"},
92 {"LINE2R", NULL, "Line In"},
93
94 {NULL, NULL, NULL},
95};
96
97/* Logic for a aic3x as connected on a davinci-evm */
98static int evm_aic3x_init(struct snd_soc_codec *codec)
99{
100 int i;
101
102 /* Add davinci-evm specific widgets */
103 for (i = 0; i < ARRAY_SIZE(aic3x_dapm_widgets); i++)
104 snd_soc_dapm_new_control(codec, &aic3x_dapm_widgets[i]);
105
106 /* Set up davinci-evm specific audio path audio_map */
107 for (i = 0; audio_map[i][0] != NULL; i++)
108 snd_soc_dapm_connect_input(codec, audio_map[i][0],
109 audio_map[i][1], audio_map[i][2]);
110
111 /* not connected */
112 snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0);
113 snd_soc_dapm_set_endpoint(codec, "HPLCOM", 0);
114 snd_soc_dapm_set_endpoint(codec, "HPRCOM", 0);
115
116 /* always connected */
117 snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
118 snd_soc_dapm_set_endpoint(codec, "Line Out", 1);
119 snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
120 snd_soc_dapm_set_endpoint(codec, "Line In", 1);
121
122 snd_soc_dapm_sync_endpoints(codec);
123
124 return 0;
125}
126
127/* davinci-evm digital audio interface glue - connects codec <--> CPU */
128static struct snd_soc_dai_link evm_dai = {
129 .name = "TLV320AIC3X",
130 .stream_name = "AIC3X",
131 .cpu_dai = &davinci_i2s_dai,
132 .codec_dai = &aic3x_dai,
133 .init = evm_aic3x_init,
134 .ops = &evm_ops,
135};
136
137/* davinci-evm audio machine driver */
138static struct snd_soc_machine snd_soc_machine_evm = {
139 .name = "DaVinci EVM",
140 .dai_link = &evm_dai,
141 .num_links = 1,
142};
143
144/* evm audio private data */
145static struct aic3x_setup_data evm_aic3x_setup = {
146 .i2c_address = 0x1b,
147};
148
149/* evm audio subsystem */
150static struct snd_soc_device evm_snd_devdata = {
151 .machine = &snd_soc_machine_evm,
152 .platform = &davinci_soc_platform,
153 .codec_dev = &soc_codec_dev_aic3x,
154 .codec_data = &evm_aic3x_setup,
155};
156
157static struct resource evm_snd_resources[] = {
158 {
159 .start = DAVINCI_MCBSP_BASE,
160 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
161 .flags = IORESOURCE_MEM,
162 },
163};
164
165static struct evm_snd_platform_data evm_snd_data = {
166 .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
167 .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
168};
169
170static struct platform_device *evm_snd_device;
171
172static int __init evm_init(void)
173{
174 int ret;
175
176 evm_snd_device = platform_device_alloc("soc-audio", 0);
177 if (!evm_snd_device)
178 return -ENOMEM;
179
180 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
181 evm_snd_devdata.dev = &evm_snd_device->dev;
182 evm_snd_device->dev.platform_data = &evm_snd_data;
183
184 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
185 ARRAY_SIZE(evm_snd_resources));
186 if (ret) {
187 platform_device_put(evm_snd_device);
188 return ret;
189 }
190
191 ret = platform_device_add(evm_snd_device);
192 if (ret)
193 platform_device_put(evm_snd_device);
194
195 return ret;
196}
197
198static void __exit evm_exit(void)
199{
200 platform_device_unregister(evm_snd_device);
201}
202
203module_init(evm_init);
204module_exit(evm_exit);
205
206MODULE_AUTHOR("Vladimir Barinov");
207MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
208MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
new file mode 100644
index 000000000000..c421774b33ee
--- /dev/null
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -0,0 +1,407 @@
1/*
2 * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/device.h>
15#include <linux/delay.h>
16#include <linux/io.h>
17#include <linux/clk.h>
18
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22#include <sound/initval.h>
23#include <sound/soc.h>
24
25#include "davinci-pcm.h"
26
27#define DAVINCI_MCBSP_DRR_REG 0x00
28#define DAVINCI_MCBSP_DXR_REG 0x04
29#define DAVINCI_MCBSP_SPCR_REG 0x08
30#define DAVINCI_MCBSP_RCR_REG 0x0c
31#define DAVINCI_MCBSP_XCR_REG 0x10
32#define DAVINCI_MCBSP_SRGR_REG 0x14
33#define DAVINCI_MCBSP_PCR_REG 0x24
34
35#define DAVINCI_MCBSP_SPCR_RRST (1 << 0)
36#define DAVINCI_MCBSP_SPCR_RINTM(v) ((v) << 4)
37#define DAVINCI_MCBSP_SPCR_XRST (1 << 16)
38#define DAVINCI_MCBSP_SPCR_XINTM(v) ((v) << 20)
39#define DAVINCI_MCBSP_SPCR_GRST (1 << 22)
40#define DAVINCI_MCBSP_SPCR_FRST (1 << 23)
41#define DAVINCI_MCBSP_SPCR_FREE (1 << 25)
42
43#define DAVINCI_MCBSP_RCR_RWDLEN1(v) ((v) << 5)
44#define DAVINCI_MCBSP_RCR_RFRLEN1(v) ((v) << 8)
45#define DAVINCI_MCBSP_RCR_RDATDLY(v) ((v) << 16)
46#define DAVINCI_MCBSP_RCR_RWDLEN2(v) ((v) << 21)
47
48#define DAVINCI_MCBSP_XCR_XWDLEN1(v) ((v) << 5)
49#define DAVINCI_MCBSP_XCR_XFRLEN1(v) ((v) << 8)
50#define DAVINCI_MCBSP_XCR_XDATDLY(v) ((v) << 16)
51#define DAVINCI_MCBSP_XCR_XFIG (1 << 18)
52#define DAVINCI_MCBSP_XCR_XWDLEN2(v) ((v) << 21)
53
54#define DAVINCI_MCBSP_SRGR_FWID(v) ((v) << 8)
55#define DAVINCI_MCBSP_SRGR_FPER(v) ((v) << 16)
56#define DAVINCI_MCBSP_SRGR_FSGM (1 << 28)
57
58#define DAVINCI_MCBSP_PCR_CLKRP (1 << 0)
59#define DAVINCI_MCBSP_PCR_CLKXP (1 << 1)
60#define DAVINCI_MCBSP_PCR_FSRP (1 << 2)
61#define DAVINCI_MCBSP_PCR_FSXP (1 << 3)
62#define DAVINCI_MCBSP_PCR_CLKRM (1 << 8)
63#define DAVINCI_MCBSP_PCR_CLKXM (1 << 9)
64#define DAVINCI_MCBSP_PCR_FSRM (1 << 10)
65#define DAVINCI_MCBSP_PCR_FSXM (1 << 11)
66
67#define MOD_REG_BIT(val, mask, set) do { \
68 if (set) { \
69 val |= mask; \
70 } else { \
71 val &= ~mask; \
72 } \
73} while (0)
74
75enum {
76 DAVINCI_MCBSP_WORD_8 = 0,
77 DAVINCI_MCBSP_WORD_12,
78 DAVINCI_MCBSP_WORD_16,
79 DAVINCI_MCBSP_WORD_20,
80 DAVINCI_MCBSP_WORD_24,
81 DAVINCI_MCBSP_WORD_32,
82};
83
84static struct davinci_pcm_dma_params davinci_i2s_pcm_out = {
85 .name = "I2S PCM Stereo out",
86};
87
88static struct davinci_pcm_dma_params davinci_i2s_pcm_in = {
89 .name = "I2S PCM Stereo in",
90};
91
92struct davinci_mcbsp_dev {
93 void __iomem *base;
94 struct clk *clk;
95 struct davinci_pcm_dma_params *dma_params[2];
96};
97
98static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev,
99 int reg, u32 val)
100{
101 __raw_writel(val, dev->base + reg);
102}
103
104static inline u32 davinci_mcbsp_read_reg(struct davinci_mcbsp_dev *dev, int reg)
105{
106 return __raw_readl(dev->base + reg);
107}
108
109static void davinci_mcbsp_start(struct snd_pcm_substream *substream)
110{
111 struct snd_soc_pcm_runtime *rtd = substream->private_data;
112 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
113 u32 w;
114
115 /* Start the sample generator and enable transmitter/receiver */
116 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
117 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST, 1);
118 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
119 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 1);
120 else
121 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 1);
122 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
123
124 /* Start frame sync */
125 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
126 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_FRST, 1);
127 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
128}
129
130static void davinci_mcbsp_stop(struct snd_pcm_substream *substream)
131{
132 struct snd_soc_pcm_runtime *rtd = substream->private_data;
133 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
134 u32 w;
135
136 /* Reset transmitter/receiver and sample rate/frame sync generators */
137 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
138 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST |
139 DAVINCI_MCBSP_SPCR_FRST, 0);
140 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
141 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 0);
142 else
143 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 0);
144 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
145}
146
147static int davinci_i2s_startup(struct snd_pcm_substream *substream)
148{
149 struct snd_soc_pcm_runtime *rtd = substream->private_data;
150 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
151 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
152
153 cpu_dai->dma_data = dev->dma_params[substream->stream];
154
155 return 0;
156}
157
158static int davinci_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
159 unsigned int fmt)
160{
161 struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
162 u32 w;
163
164 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
165 case SND_SOC_DAIFMT_CBS_CFS:
166 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG,
167 DAVINCI_MCBSP_PCR_FSXM |
168 DAVINCI_MCBSP_PCR_FSRM |
169 DAVINCI_MCBSP_PCR_CLKXM |
170 DAVINCI_MCBSP_PCR_CLKRM);
171 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG,
172 DAVINCI_MCBSP_SRGR_FSGM);
173 break;
174 case SND_SOC_DAIFMT_CBM_CFM:
175 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, 0);
176 break;
177 default:
178 return -EINVAL;
179 }
180
181 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
182 case SND_SOC_DAIFMT_IB_NF:
183 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
184 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP |
185 DAVINCI_MCBSP_PCR_CLKRP, 1);
186 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
187 break;
188 case SND_SOC_DAIFMT_NB_IF:
189 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
190 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_FSXP |
191 DAVINCI_MCBSP_PCR_FSRP, 1);
192 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
193 break;
194 case SND_SOC_DAIFMT_IB_IF:
195 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
196 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP |
197 DAVINCI_MCBSP_PCR_CLKRP |
198 DAVINCI_MCBSP_PCR_FSXP |
199 DAVINCI_MCBSP_PCR_FSRP, 1);
200 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
201 break;
202 case SND_SOC_DAIFMT_NB_NF:
203 break;
204 default:
205 return -EINVAL;
206 }
207
208 return 0;
209}
210
211static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
212 struct snd_pcm_hw_params *params)
213{
214 struct snd_soc_pcm_runtime *rtd = substream->private_data;
215 struct davinci_pcm_dma_params *dma_params = rtd->dai->cpu_dai->dma_data;
216 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
217 struct snd_interval *i = NULL;
218 int mcbsp_word_length;
219 u32 w;
220
221 /* general line settings */
222 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG,
223 DAVINCI_MCBSP_SPCR_RINTM(3) |
224 DAVINCI_MCBSP_SPCR_XINTM(3) |
225 DAVINCI_MCBSP_SPCR_FREE);
226 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG,
227 DAVINCI_MCBSP_RCR_RFRLEN1(1) |
228 DAVINCI_MCBSP_RCR_RDATDLY(1));
229 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG,
230 DAVINCI_MCBSP_XCR_XFRLEN1(1) |
231 DAVINCI_MCBSP_XCR_XDATDLY(1) |
232 DAVINCI_MCBSP_XCR_XFIG);
233
234 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
235 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG);
236 MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FWID(snd_interval_value(i) - 1), 1);
237 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w);
238
239 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_FRAME_BITS);
240 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG);
241 MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FPER(snd_interval_value(i) - 1), 1);
242 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w);
243
244 /* Determine xfer data type */
245 switch (params_format(params)) {
246 case SNDRV_PCM_FORMAT_S8:
247 dma_params->data_type = 1;
248 mcbsp_word_length = DAVINCI_MCBSP_WORD_8;
249 break;
250 case SNDRV_PCM_FORMAT_S16_LE:
251 dma_params->data_type = 2;
252 mcbsp_word_length = DAVINCI_MCBSP_WORD_16;
253 break;
254 case SNDRV_PCM_FORMAT_S32_LE:
255 dma_params->data_type = 4;
256 mcbsp_word_length = DAVINCI_MCBSP_WORD_32;
257 break;
258 default:
259 printk(KERN_WARNING "davinci-i2s: unsupported PCM format");
260 return -EINVAL;
261 }
262
263 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_RCR_REG);
264 MOD_REG_BIT(w, DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) |
265 DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length), 1);
266 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, w);
267
268 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_XCR_REG);
269 MOD_REG_BIT(w, DAVINCI_MCBSP_XCR_XWDLEN1(mcbsp_word_length) |
270 DAVINCI_MCBSP_XCR_XWDLEN2(mcbsp_word_length), 1);
271 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, w);
272
273 return 0;
274}
275
276static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
277{
278 int ret = 0;
279
280 switch (cmd) {
281 case SNDRV_PCM_TRIGGER_START:
282 case SNDRV_PCM_TRIGGER_RESUME:
283 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
284 davinci_mcbsp_start(substream);
285 break;
286 case SNDRV_PCM_TRIGGER_STOP:
287 case SNDRV_PCM_TRIGGER_SUSPEND:
288 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
289 davinci_mcbsp_stop(substream);
290 break;
291 default:
292 ret = -EINVAL;
293 }
294
295 return ret;
296}
297
298static int davinci_i2s_probe(struct platform_device *pdev)
299{
300 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
301 struct snd_soc_machine *machine = socdev->machine;
302 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
303 struct davinci_mcbsp_dev *dev;
304 struct resource *mem, *ioarea;
305 struct evm_snd_platform_data *pdata;
306 int ret;
307
308 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
309 if (!mem) {
310 dev_err(&pdev->dev, "no mem resource?\n");
311 return -ENODEV;
312 }
313
314 ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1,
315 pdev->name);
316 if (!ioarea) {
317 dev_err(&pdev->dev, "McBSP region already claimed\n");
318 return -EBUSY;
319 }
320
321 dev = kzalloc(sizeof(struct davinci_mcbsp_dev), GFP_KERNEL);
322 if (!dev) {
323 ret = -ENOMEM;
324 goto err_release_region;
325 }
326
327 cpu_dai->private_data = dev;
328
329 dev->clk = clk_get(&pdev->dev, "McBSPCLK");
330 if (IS_ERR(dev->clk)) {
331 ret = -ENODEV;
332 goto err_free_mem;
333 }
334 clk_enable(dev->clk);
335
336 dev->base = (void __iomem *)IO_ADDRESS(mem->start);
337 pdata = pdev->dev.platform_data;
338
339 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK] = &davinci_i2s_pcm_out;
340 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->channel = pdata->tx_dma_ch;
341 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->dma_addr =
342 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DXR_REG);
343
344 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE] = &davinci_i2s_pcm_in;
345 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->channel = pdata->rx_dma_ch;
346 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->dma_addr =
347 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DRR_REG);
348
349 return 0;
350
351err_free_mem:
352 kfree(dev);
353err_release_region:
354 release_mem_region(mem->start, (mem->end - mem->start) + 1);
355
356 return ret;
357}
358
359static void davinci_i2s_remove(struct platform_device *pdev)
360{
361 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
362 struct snd_soc_machine *machine = socdev->machine;
363 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
364 struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
365 struct resource *mem;
366
367 clk_disable(dev->clk);
368 clk_put(dev->clk);
369 dev->clk = NULL;
370
371 kfree(dev);
372
373 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
374 release_mem_region(mem->start, (mem->end - mem->start) + 1);
375}
376
377#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000
378
379struct snd_soc_cpu_dai davinci_i2s_dai = {
380 .name = "davinci-i2s",
381 .id = 0,
382 .type = SND_SOC_DAI_I2S,
383 .probe = davinci_i2s_probe,
384 .remove = davinci_i2s_remove,
385 .playback = {
386 .channels_min = 2,
387 .channels_max = 2,
388 .rates = DAVINCI_I2S_RATES,
389 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
390 .capture = {
391 .channels_min = 2,
392 .channels_max = 2,
393 .rates = DAVINCI_I2S_RATES,
394 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
395 .ops = {
396 .startup = davinci_i2s_startup,
397 .trigger = davinci_i2s_trigger,
398 .hw_params = davinci_i2s_hw_params,},
399 .dai_ops = {
400 .set_fmt = davinci_i2s_set_dai_fmt,
401 },
402};
403EXPORT_SYMBOL_GPL(davinci_i2s_dai);
404
405MODULE_AUTHOR("Vladimir Barinov");
406MODULE_DESCRIPTION("TI DAVINCI I2S (McBSP) SoC Interface");
407MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-i2s.h b/sound/soc/davinci/davinci-i2s.h
new file mode 100644
index 000000000000..9592d17db320
--- /dev/null
+++ b/sound/soc/davinci/davinci-i2s.h
@@ -0,0 +1,17 @@
1/*
2 * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _DAVINCI_I2S_H
13#define _DAVINCI_I2S_H
14
15extern struct snd_soc_cpu_dai davinci_i2s_dai;
16
17#endif
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
new file mode 100644
index 000000000000..6a76927c9971
--- /dev/null
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -0,0 +1,389 @@
1/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
16#include <linux/dma-mapping.h>
17
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/pcm_params.h>
21#include <sound/soc.h>
22
23#include <asm/dma.h>
24
25#include "davinci-pcm.h"
26
27#define DAVINCI_PCM_DEBUG 0
28#if DAVINCI_PCM_DEBUG
29#define DPRINTK(x...) printk(KERN_DEBUG x)
30#else
31#define DPRINTK(x...)
32#endif
33
34static struct snd_pcm_hardware davinci_pcm_hardware = {
35 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
36 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
37 SNDRV_PCM_INFO_PAUSE),
38 .formats = (SNDRV_PCM_FMTBIT_S16_LE),
39 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
40 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
41 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
42 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
43 SNDRV_PCM_RATE_KNOT),
44 .rate_min = 8000,
45 .rate_max = 96000,
46 .channels_min = 2,
47 .channels_max = 2,
48 .buffer_bytes_max = 128 * 1024,
49 .period_bytes_min = 32,
50 .period_bytes_max = 8 * 1024,
51 .periods_min = 16,
52 .periods_max = 255,
53 .fifo_size = 0,
54};
55
56struct davinci_runtime_data {
57 spinlock_t lock;
58 int period; /* current DMA period */
59 int master_lch; /* Master DMA channel */
60 int slave_lch; /* Slave DMA channel */
61 struct davinci_pcm_dma_params *params; /* DMA params */
62};
63
64static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
65{
66 struct davinci_runtime_data *prtd = substream->runtime->private_data;
67 struct snd_pcm_runtime *runtime = substream->runtime;
68 int lch = prtd->slave_lch;
69 unsigned int period_size;
70 unsigned int dma_offset;
71 dma_addr_t dma_pos;
72 dma_addr_t src, dst;
73 unsigned short src_bidx, dst_bidx;
74 unsigned int data_type;
75 unsigned int count;
76
77 period_size = snd_pcm_lib_period_bytes(substream);
78 dma_offset = prtd->period * period_size;
79 dma_pos = runtime->dma_addr + dma_offset;
80
81 DPRINTK("audio_set_dma_params_play channel = %d dma_ptr = %x "
82 "period_size=%x\n", lch, dma_pos, period_size);
83
84 data_type = prtd->params->data_type;
85 count = period_size / data_type;
86
87 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
88 src = dma_pos;
89 dst = prtd->params->dma_addr;
90 src_bidx = data_type;
91 dst_bidx = 0;
92 } else {
93 src = prtd->params->dma_addr;
94 dst = dma_pos;
95 src_bidx = 0;
96 dst_bidx = data_type;
97 }
98
99 davinci_set_dma_src_params(lch, src, INCR, W8BIT);
100 davinci_set_dma_dest_params(lch, dst, INCR, W8BIT);
101 davinci_set_dma_src_index(lch, src_bidx, 0);
102 davinci_set_dma_dest_index(lch, dst_bidx, 0);
103 davinci_set_dma_transfer_params(lch, data_type, count, 1, 0, ASYNC);
104
105 prtd->period++;
106 if (unlikely(prtd->period >= runtime->periods))
107 prtd->period = 0;
108}
109
110static void davinci_pcm_dma_irq(int lch, u16 ch_status, void *data)
111{
112 struct snd_pcm_substream *substream = data;
113 struct davinci_runtime_data *prtd = substream->runtime->private_data;
114
115 DPRINTK("lch=%d, status=0x%x\n", lch, ch_status);
116
117 if (unlikely(ch_status != DMA_COMPLETE))
118 return;
119
120 if (snd_pcm_running(substream)) {
121 snd_pcm_period_elapsed(substream);
122
123 spin_lock(&prtd->lock);
124 davinci_pcm_enqueue_dma(substream);
125 spin_unlock(&prtd->lock);
126 }
127}
128
129static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
130{
131 struct davinci_runtime_data *prtd = substream->runtime->private_data;
132 struct snd_soc_pcm_runtime *rtd = substream->private_data;
133 struct davinci_pcm_dma_params *dma_data = rtd->dai->cpu_dai->dma_data;
134 int tcc = TCC_ANY;
135 int ret;
136
137 if (!dma_data)
138 return -ENODEV;
139
140 prtd->params = dma_data;
141
142 /* Request master DMA channel */
143 ret = davinci_request_dma(prtd->params->channel, prtd->params->name,
144 davinci_pcm_dma_irq, substream,
145 &prtd->master_lch, &tcc, EVENTQ_0);
146 if (ret)
147 return ret;
148
149 /* Request slave DMA channel */
150 ret = davinci_request_dma(PARAM_ANY, "Link",
151 NULL, NULL, &prtd->slave_lch, &tcc, EVENTQ_0);
152 if (ret) {
153 davinci_free_dma(prtd->master_lch);
154 return ret;
155 }
156
157 /* Link slave DMA channel in loopback */
158 davinci_dma_link_lch(prtd->slave_lch, prtd->slave_lch);
159
160 return 0;
161}
162
163static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
164{
165 struct davinci_runtime_data *prtd = substream->runtime->private_data;
166 int ret = 0;
167
168 spin_lock(&prtd->lock);
169
170 switch (cmd) {
171 case SNDRV_PCM_TRIGGER_START:
172 case SNDRV_PCM_TRIGGER_RESUME:
173 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
174 davinci_start_dma(prtd->master_lch);
175 break;
176 case SNDRV_PCM_TRIGGER_STOP:
177 case SNDRV_PCM_TRIGGER_SUSPEND:
178 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
179 davinci_stop_dma(prtd->master_lch);
180 break;
181 default:
182 ret = -EINVAL;
183 break;
184 }
185
186 spin_unlock(&prtd->lock);
187
188 return ret;
189}
190
191static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
192{
193 struct davinci_runtime_data *prtd = substream->runtime->private_data;
194 struct paramentry_descriptor temp;
195
196 prtd->period = 0;
197 davinci_pcm_enqueue_dma(substream);
198
199 /* Get slave channel dma params for master channel startup */
200 davinci_get_dma_params(prtd->slave_lch, &temp);
201 davinci_set_dma_params(prtd->master_lch, &temp);
202
203 return 0;
204}
205
206static snd_pcm_uframes_t
207davinci_pcm_pointer(struct snd_pcm_substream *substream)
208{
209 struct snd_pcm_runtime *runtime = substream->runtime;
210 struct davinci_runtime_data *prtd = runtime->private_data;
211 unsigned int offset;
212 dma_addr_t count;
213 dma_addr_t src, dst;
214
215 spin_lock(&prtd->lock);
216
217 davinci_dma_getposition(prtd->master_lch, &src, &dst);
218 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
219 count = src - runtime->dma_addr;
220 else
221 count = dst - runtime->dma_addr;;
222
223 spin_unlock(&prtd->lock);
224
225 offset = bytes_to_frames(runtime, count);
226 if (offset >= runtime->buffer_size)
227 offset = 0;
228
229 return offset;
230}
231
232static int davinci_pcm_open(struct snd_pcm_substream *substream)
233{
234 struct snd_pcm_runtime *runtime = substream->runtime;
235 struct davinci_runtime_data *prtd;
236 int ret = 0;
237
238 snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware);
239
240 prtd = kzalloc(sizeof(struct davinci_runtime_data), GFP_KERNEL);
241 if (prtd == NULL)
242 return -ENOMEM;
243
244 spin_lock_init(&prtd->lock);
245
246 runtime->private_data = prtd;
247
248 ret = davinci_pcm_dma_request(substream);
249 if (ret) {
250 printk(KERN_ERR "davinci_pcm: Failed to get dma channels\n");
251 kfree(prtd);
252 }
253
254 return ret;
255}
256
257static int davinci_pcm_close(struct snd_pcm_substream *substream)
258{
259 struct snd_pcm_runtime *runtime = substream->runtime;
260 struct davinci_runtime_data *prtd = runtime->private_data;
261
262 davinci_dma_unlink_lch(prtd->slave_lch, prtd->slave_lch);
263
264 davinci_free_dma(prtd->slave_lch);
265 davinci_free_dma(prtd->master_lch);
266
267 kfree(prtd);
268
269 return 0;
270}
271
272static int davinci_pcm_hw_params(struct snd_pcm_substream *substream,
273 struct snd_pcm_hw_params *hw_params)
274{
275 return snd_pcm_lib_malloc_pages(substream,
276 params_buffer_bytes(hw_params));
277}
278
279static int davinci_pcm_hw_free(struct snd_pcm_substream *substream)
280{
281 return snd_pcm_lib_free_pages(substream);
282}
283
284static int davinci_pcm_mmap(struct snd_pcm_substream *substream,
285 struct vm_area_struct *vma)
286{
287 struct snd_pcm_runtime *runtime = substream->runtime;
288
289 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
290 runtime->dma_area,
291 runtime->dma_addr,
292 runtime->dma_bytes);
293}
294
295struct snd_pcm_ops davinci_pcm_ops = {
296 .open = davinci_pcm_open,
297 .close = davinci_pcm_close,
298 .ioctl = snd_pcm_lib_ioctl,
299 .hw_params = davinci_pcm_hw_params,
300 .hw_free = davinci_pcm_hw_free,
301 .prepare = davinci_pcm_prepare,
302 .trigger = davinci_pcm_trigger,
303 .pointer = davinci_pcm_pointer,
304 .mmap = davinci_pcm_mmap,
305};
306
307static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
308{
309 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
310 struct snd_dma_buffer *buf = &substream->dma_buffer;
311 size_t size = davinci_pcm_hardware.buffer_bytes_max;
312
313 buf->dev.type = SNDRV_DMA_TYPE_DEV;
314 buf->dev.dev = pcm->card->dev;
315 buf->private_data = NULL;
316 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
317 &buf->addr, GFP_KERNEL);
318
319 DPRINTK("preallocate_dma_buffer: area=%p, addr=%p, size=%d\n",
320 (void *) buf->area, (void *) buf->addr, size);
321
322 if (!buf->area)
323 return -ENOMEM;
324
325 buf->bytes = size;
326 return 0;
327}
328
329static void davinci_pcm_free(struct snd_pcm *pcm)
330{
331 struct snd_pcm_substream *substream;
332 struct snd_dma_buffer *buf;
333 int stream;
334
335 for (stream = 0; stream < 2; stream++) {
336 substream = pcm->streams[stream].substream;
337 if (!substream)
338 continue;
339
340 buf = &substream->dma_buffer;
341 if (!buf->area)
342 continue;
343
344 dma_free_writecombine(pcm->card->dev, buf->bytes,
345 buf->area, buf->addr);
346 buf->area = NULL;
347 }
348}
349
350static u64 davinci_pcm_dmamask = 0xffffffff;
351
352static int davinci_pcm_new(struct snd_card *card,
353 struct snd_soc_codec_dai *dai, struct snd_pcm *pcm)
354{
355 int ret;
356
357 if (!card->dev->dma_mask)
358 card->dev->dma_mask = &davinci_pcm_dmamask;
359 if (!card->dev->coherent_dma_mask)
360 card->dev->coherent_dma_mask = 0xffffffff;
361
362 if (dai->playback.channels_min) {
363 ret = davinci_pcm_preallocate_dma_buffer(pcm,
364 SNDRV_PCM_STREAM_PLAYBACK);
365 if (ret)
366 return ret;
367 }
368
369 if (dai->capture.channels_min) {
370 ret = davinci_pcm_preallocate_dma_buffer(pcm,
371 SNDRV_PCM_STREAM_CAPTURE);
372 if (ret)
373 return ret;
374 }
375
376 return 0;
377}
378
379struct snd_soc_platform davinci_soc_platform = {
380 .name = "davinci-audio",
381 .pcm_ops = &davinci_pcm_ops,
382 .pcm_new = davinci_pcm_new,
383 .pcm_free = davinci_pcm_free,
384};
385EXPORT_SYMBOL_GPL(davinci_soc_platform);
386
387MODULE_AUTHOR("Vladimir Barinov");
388MODULE_DESCRIPTION("TI DAVINCI PCM DMA module");
389MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-pcm.h b/sound/soc/davinci/davinci-pcm.h
new file mode 100644
index 000000000000..8d6a45e75a6e
--- /dev/null
+++ b/sound/soc/davinci/davinci-pcm.h
@@ -0,0 +1,29 @@
1/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _DAVINCI_PCM_H
13#define _DAVINCI_PCM_H
14
15struct davinci_pcm_dma_params {
16 char *name; /* stream identifier */
17 int channel; /* sync dma channel ID */
18 dma_addr_t dma_addr; /* device physical address for DMA */
19 unsigned int data_type; /* xfer data type */
20};
21
22struct evm_snd_platform_data {
23 int tx_dma_ch;
24 int rx_dma_ch;
25};
26
27extern struct snd_soc_platform davinci_soc_platform;
28
29#endif
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 652514fc8142..78de7168d2ba 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -20,7 +20,6 @@
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22 22
23#include <sound/driver.h>
24#include <sound/core.h> 23#include <sound/core.h>
25#include <sound/pcm.h> 24#include <sound/pcm.h>
26#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 145ad13d52d1..b2a11b0d2e4c 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -15,7 +15,6 @@
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17 17
18#include <sound/driver.h>
19#include <sound/core.h> 18#include <sound/core.h>
20#include <sound/pcm.h> 19#include <sound/pcm.h>
21#include <sound/pcm_params.h> 20#include <sound/pcm_params.h>
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
new file mode 100644
index 000000000000..0230d83e8e5e
--- /dev/null
+++ b/sound/soc/omap/Kconfig
@@ -0,0 +1,19 @@
1menu "SoC Audio for the Texas Instruments OMAP"
2
3config SND_OMAP_SOC
4 tristate "SoC Audio for the Texas Instruments OMAP chips"
5 depends on ARCH_OMAP && SND_SOC
6
7config SND_OMAP_SOC_MCBSP
8 tristate
9 select OMAP_MCBSP
10
11config SND_OMAP_SOC_N810
12 tristate "SoC Audio support for Nokia N810"
13 depends on SND_OMAP_SOC && MACH_NOKIA_N810
14 select SND_OMAP_SOC_MCBSP
15 select SND_SOC_TLV320AIC3X
16 help
17 Say Y if you want to add support for SoC audio on Nokia N810.
18
19endmenu
diff --git a/sound/soc/omap/Makefile b/sound/soc/omap/Makefile
new file mode 100644
index 000000000000..d8d8d58075e3
--- /dev/null
+++ b/sound/soc/omap/Makefile
@@ -0,0 +1,11 @@
1# OMAP Platform Support
2snd-soc-omap-objs := omap-pcm.o
3snd-soc-omap-mcbsp-objs := omap-mcbsp.o
4
5obj-$(CONFIG_SND_OMAP_SOC) += snd-soc-omap.o
6obj-$(CONFIG_SND_OMAP_SOC_MCBSP) += snd-soc-omap-mcbsp.o
7
8# OMAP Machine Support
9snd-soc-n810-objs := n810.o
10
11obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
new file mode 100644
index 000000000000..83b1eb4e40f3
--- /dev/null
+++ b/sound/soc/omap/n810.c
@@ -0,0 +1,336 @@
1/*
2 * n810.c -- SoC audio for Nokia N810
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/clk.h>
25#include <linux/platform_device.h>
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30
31#include <asm/mach-types.h>
32#include <asm/arch/hardware.h>
33#include <asm/arch/gpio.h>
34#include <asm/arch/mcbsp.h>
35
36#include "omap-mcbsp.h"
37#include "omap-pcm.h"
38#include "../codecs/tlv320aic3x.h"
39
40#define RX44_HEADSET_AMP_GPIO 10
41#define RX44_SPEAKER_AMP_GPIO 101
42
43static struct clk *sys_clkout2;
44static struct clk *sys_clkout2_src;
45static struct clk *func96m_clk;
46
47static int n810_spk_func;
48static int n810_jack_func;
49
50static void n810_ext_control(struct snd_soc_codec *codec)
51{
52 snd_soc_dapm_set_endpoint(codec, "Ext Spk", n810_spk_func);
53 snd_soc_dapm_set_endpoint(codec, "Headphone Jack", n810_jack_func);
54
55 snd_soc_dapm_sync_endpoints(codec);
56}
57
58static int n810_startup(struct snd_pcm_substream *substream)
59{
60 struct snd_soc_pcm_runtime *rtd = substream->private_data;
61 struct snd_soc_codec *codec = rtd->socdev->codec;
62
63 n810_ext_control(codec);
64 return clk_enable(sys_clkout2);
65}
66
67static void n810_shutdown(struct snd_pcm_substream *substream)
68{
69 clk_disable(sys_clkout2);
70}
71
72static int n810_hw_params(struct snd_pcm_substream *substream,
73 struct snd_pcm_hw_params *params)
74{
75 struct snd_soc_pcm_runtime *rtd = substream->private_data;
76 struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
77 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
78 int err;
79
80 /* Set codec DAI configuration */
81 err = codec_dai->dai_ops.set_fmt(codec_dai,
82 SND_SOC_DAIFMT_I2S |
83 SND_SOC_DAIFMT_NB_NF |
84 SND_SOC_DAIFMT_CBM_CFM);
85 if (err < 0)
86 return err;
87
88 /* Set cpu DAI configuration */
89 err = cpu_dai->dai_ops.set_fmt(cpu_dai,
90 SND_SOC_DAIFMT_I2S |
91 SND_SOC_DAIFMT_NB_NF |
92 SND_SOC_DAIFMT_CBM_CFM);
93 if (err < 0)
94 return err;
95
96 /* Set the codec system clock for DAC and ADC */
97 err = codec_dai->dai_ops.set_sysclk(codec_dai, 0, 12000000,
98 SND_SOC_CLOCK_IN);
99
100 return err;
101}
102
103static struct snd_soc_ops n810_ops = {
104 .startup = n810_startup,
105 .hw_params = n810_hw_params,
106 .shutdown = n810_shutdown,
107};
108
109static int n810_get_spk(struct snd_kcontrol *kcontrol,
110 struct snd_ctl_elem_value *ucontrol)
111{
112 ucontrol->value.integer.value[0] = n810_spk_func;
113
114 return 0;
115}
116
117static int n810_set_spk(struct snd_kcontrol *kcontrol,
118 struct snd_ctl_elem_value *ucontrol)
119{
120 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
121
122 if (n810_spk_func == ucontrol->value.integer.value[0])
123 return 0;
124
125 n810_spk_func = ucontrol->value.integer.value[0];
126 n810_ext_control(codec);
127
128 return 1;
129}
130
131static int n810_get_jack(struct snd_kcontrol *kcontrol,
132 struct snd_ctl_elem_value *ucontrol)
133{
134 ucontrol->value.integer.value[0] = n810_jack_func;
135
136 return 0;
137}
138
139static int n810_set_jack(struct snd_kcontrol *kcontrol,
140 struct snd_ctl_elem_value *ucontrol)
141{
142 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
143
144 if (n810_jack_func == ucontrol->value.integer.value[0])
145 return 0;
146
147 n810_jack_func = ucontrol->value.integer.value[0];
148 n810_ext_control(codec);
149
150 return 1;
151}
152
153static int n810_spk_event(struct snd_soc_dapm_widget *w,
154 struct snd_kcontrol *k, int event)
155{
156 if (SND_SOC_DAPM_EVENT_ON(event))
157 omap_set_gpio_dataout(RX44_SPEAKER_AMP_GPIO, 1);
158 else
159 omap_set_gpio_dataout(RX44_SPEAKER_AMP_GPIO, 0);
160
161 return 0;
162}
163
164static int n810_jack_event(struct snd_soc_dapm_widget *w,
165 struct snd_kcontrol *k, int event)
166{
167 if (SND_SOC_DAPM_EVENT_ON(event))
168 omap_set_gpio_dataout(RX44_HEADSET_AMP_GPIO, 1);
169 else
170 omap_set_gpio_dataout(RX44_HEADSET_AMP_GPIO, 0);
171
172 return 0;
173}
174
175static const struct snd_soc_dapm_widget aic33_dapm_widgets[] = {
176 SND_SOC_DAPM_SPK("Ext Spk", n810_spk_event),
177 SND_SOC_DAPM_HP("Headphone Jack", n810_jack_event),
178};
179
180static const char *audio_map[][3] = {
181 {"Headphone Jack", NULL, "HPLOUT"},
182 {"Headphone Jack", NULL, "HPROUT"},
183
184 {"Ext Spk", NULL, "LLOUT"},
185 {"Ext Spk", NULL, "RLOUT"},
186};
187
188static const char *spk_function[] = {"Off", "On"};
189static const char *jack_function[] = {"Off", "Headphone"};
190static const struct soc_enum n810_enum[] = {
191 SOC_ENUM_SINGLE_EXT(2, spk_function),
192 SOC_ENUM_SINGLE_EXT(3, jack_function),
193};
194
195static const struct snd_kcontrol_new aic33_n810_controls[] = {
196 SOC_ENUM_EXT("Speaker Function", n810_enum[0],
197 n810_get_spk, n810_set_spk),
198 SOC_ENUM_EXT("Jack Function", n810_enum[1],
199 n810_get_jack, n810_set_jack),
200};
201
202static int n810_aic33_init(struct snd_soc_codec *codec)
203{
204 int i, err;
205
206 /* Not connected */
207 snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0);
208 snd_soc_dapm_set_endpoint(codec, "HPLCOM", 0);
209 snd_soc_dapm_set_endpoint(codec, "HPRCOM", 0);
210
211 /* Add N810 specific controls */
212 for (i = 0; i < ARRAY_SIZE(aic33_n810_controls); i++) {
213 err = snd_ctl_add(codec->card,
214 snd_soc_cnew(&aic33_n810_controls[i], codec, NULL));
215 if (err < 0)
216 return err;
217 }
218
219 /* Add N810 specific widgets */
220 for (i = 0; i < ARRAY_SIZE(aic33_dapm_widgets); i++)
221 snd_soc_dapm_new_control(codec, &aic33_dapm_widgets[i]);
222
223 /* Set up N810 specific audio path audio_map */
224 for (i = 0; i < ARRAY_SIZE(audio_map); i++)
225 snd_soc_dapm_connect_input(codec, audio_map[i][0],
226 audio_map[i][1], audio_map[i][2]);
227
228 snd_soc_dapm_sync_endpoints(codec);
229
230 return 0;
231}
232
233/* Digital audio interface glue - connects codec <--> CPU */
234static struct snd_soc_dai_link n810_dai = {
235 .name = "TLV320AIC33",
236 .stream_name = "AIC33",
237 .cpu_dai = &omap_mcbsp_dai[0],
238 .codec_dai = &aic3x_dai,
239 .init = n810_aic33_init,
240 .ops = &n810_ops,
241};
242
243/* Audio machine driver */
244static struct snd_soc_machine snd_soc_machine_n810 = {
245 .name = "N810",
246 .dai_link = &n810_dai,
247 .num_links = 1,
248};
249
250/* Audio private data */
251static struct aic3x_setup_data n810_aic33_setup = {
252 .i2c_address = 0x18,
253};
254
255/* Audio subsystem */
256static struct snd_soc_device n810_snd_devdata = {
257 .machine = &snd_soc_machine_n810,
258 .platform = &omap_soc_platform,
259 .codec_dev = &soc_codec_dev_aic3x,
260 .codec_data = &n810_aic33_setup,
261};
262
263static struct platform_device *n810_snd_device;
264
265static int __init n810_soc_init(void)
266{
267 int err;
268 struct device *dev;
269
270 if (!machine_is_nokia_n810())
271 return -ENODEV;
272
273 n810_snd_device = platform_device_alloc("soc-audio", -1);
274 if (!n810_snd_device)
275 return -ENOMEM;
276
277 platform_set_drvdata(n810_snd_device, &n810_snd_devdata);
278 n810_snd_devdata.dev = &n810_snd_device->dev;
279 *(unsigned int *)n810_dai.cpu_dai->private_data = 1; /* McBSP2 */
280 err = platform_device_add(n810_snd_device);
281 if (err)
282 goto err1;
283
284 dev = &n810_snd_device->dev;
285
286 sys_clkout2_src = clk_get(dev, "sys_clkout2_src");
287 if (IS_ERR(sys_clkout2_src)) {
288 dev_err(dev, "Could not get sys_clkout2_src clock\n");
289 return -ENODEV;
290 }
291 sys_clkout2 = clk_get(dev, "sys_clkout2");
292 if (IS_ERR(sys_clkout2)) {
293 dev_err(dev, "Could not get sys_clkout2\n");
294 goto err1;
295 }
296 /*
297 * Configure 12 MHz output on SYS_CLKOUT2. Therefore we must use
298 * 96 MHz as its parent in order to get 12 MHz
299 */
300 func96m_clk = clk_get(dev, "func_96m_ck");
301 if (IS_ERR(func96m_clk)) {
302 dev_err(dev, "Could not get func 96M clock\n");
303 goto err2;
304 }
305 clk_set_parent(sys_clkout2_src, func96m_clk);
306 clk_set_rate(sys_clkout2, 12000000);
307
308 if (omap_request_gpio(RX44_HEADSET_AMP_GPIO) < 0)
309 BUG();
310 if (omap_request_gpio(RX44_SPEAKER_AMP_GPIO) < 0)
311 BUG();
312 omap_set_gpio_direction(RX44_HEADSET_AMP_GPIO, 0);
313 omap_set_gpio_direction(RX44_SPEAKER_AMP_GPIO, 0);
314
315 return 0;
316err2:
317 clk_put(sys_clkout2);
318 platform_device_del(n810_snd_device);
319err1:
320 platform_device_put(n810_snd_device);
321
322 return err;
323
324}
325
326static void __exit n810_soc_exit(void)
327{
328 platform_device_unregister(n810_snd_device);
329}
330
331module_init(n810_soc_init);
332module_exit(n810_soc_exit);
333
334MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>");
335MODULE_DESCRIPTION("ALSA SoC Nokia N810");
336MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c
new file mode 100644
index 000000000000..40d87e6d0de8
--- /dev/null
+++ b/sound/soc/omap/omap-mcbsp.c
@@ -0,0 +1,414 @@
1/*
2 * omap-mcbsp.c -- OMAP ALSA SoC DAI driver using McBSP port
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/device.h>
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/initval.h>
31#include <sound/soc.h>
32
33#include <asm/arch/control.h>
34#include <asm/arch/dma.h>
35#include <asm/arch/mcbsp.h>
36#include "omap-mcbsp.h"
37#include "omap-pcm.h"
38
39#define OMAP_MCBSP_RATES (SNDRV_PCM_RATE_44100 | \
40 SNDRV_PCM_RATE_48000 | \
41 SNDRV_PCM_RATE_KNOT)
42
43struct omap_mcbsp_data {
44 unsigned int bus_id;
45 struct omap_mcbsp_reg_cfg regs;
46 /*
47 * Flags indicating is the bus already activated and configured by
48 * another substream
49 */
50 int active;
51 int configured;
52};
53
54#define to_mcbsp(priv) container_of((priv), struct omap_mcbsp_data, bus_id)
55
56static struct omap_mcbsp_data mcbsp_data[NUM_LINKS];
57
58/*
59 * Stream DMA parameters. DMA request line and port address are set runtime
60 * since they are different between OMAP1 and later OMAPs
61 */
62static struct omap_pcm_dma_data omap_mcbsp_dai_dma_params[NUM_LINKS][2] = {
63{
64 { .name = "I2S PCM Stereo out", },
65 { .name = "I2S PCM Stereo in", },
66},
67};
68
69#if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX)
70static const int omap1_dma_reqs[][2] = {
71 { OMAP_DMA_MCBSP1_TX, OMAP_DMA_MCBSP1_RX },
72 { OMAP_DMA_MCBSP2_TX, OMAP_DMA_MCBSP2_RX },
73 { OMAP_DMA_MCBSP3_TX, OMAP_DMA_MCBSP3_RX },
74};
75static const unsigned long omap1_mcbsp_port[][2] = {
76 { OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
77 OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1 },
78 { OMAP1510_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1,
79 OMAP1510_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1 },
80 { OMAP1510_MCBSP3_BASE + OMAP_MCBSP_REG_DXR1,
81 OMAP1510_MCBSP3_BASE + OMAP_MCBSP_REG_DRR1 },
82};
83#else
84static const int omap1_dma_reqs[][2] = {};
85static const unsigned long omap1_mcbsp_port[][2] = {};
86#endif
87#if defined(CONFIG_ARCH_OMAP2420)
88static const int omap2420_dma_reqs[][2] = {
89 { OMAP24XX_DMA_MCBSP1_TX, OMAP24XX_DMA_MCBSP1_RX },
90 { OMAP24XX_DMA_MCBSP2_TX, OMAP24XX_DMA_MCBSP2_RX },
91};
92static const unsigned long omap2420_mcbsp_port[][2] = {
93 { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
94 OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1 },
95 { OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1,
96 OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1 },
97};
98#else
99static const int omap2420_dma_reqs[][2] = {};
100static const unsigned long omap2420_mcbsp_port[][2] = {};
101#endif
102
103static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream)
104{
105 struct snd_soc_pcm_runtime *rtd = substream->private_data;
106 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
107 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
108 int err = 0;
109
110 if (!cpu_dai->active)
111 err = omap_mcbsp_request(mcbsp_data->bus_id);
112
113 return err;
114}
115
116static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream)
117{
118 struct snd_soc_pcm_runtime *rtd = substream->private_data;
119 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
120 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
121
122 if (!cpu_dai->active) {
123 omap_mcbsp_free(mcbsp_data->bus_id);
124 mcbsp_data->configured = 0;
125 }
126}
127
128static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd)
129{
130 struct snd_soc_pcm_runtime *rtd = substream->private_data;
131 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
132 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
133 int err = 0;
134
135 switch (cmd) {
136 case SNDRV_PCM_TRIGGER_START:
137 case SNDRV_PCM_TRIGGER_RESUME:
138 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
139 if (!mcbsp_data->active++)
140 omap_mcbsp_start(mcbsp_data->bus_id);
141 break;
142
143 case SNDRV_PCM_TRIGGER_STOP:
144 case SNDRV_PCM_TRIGGER_SUSPEND:
145 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
146 if (!--mcbsp_data->active)
147 omap_mcbsp_stop(mcbsp_data->bus_id);
148 break;
149 default:
150 err = -EINVAL;
151 }
152
153 return err;
154}
155
156static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
157 struct snd_pcm_hw_params *params)
158{
159 struct snd_soc_pcm_runtime *rtd = substream->private_data;
160 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
161 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
162 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
163 int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id;
164 unsigned long port;
165
166 if (cpu_class_is_omap1()) {
167 dma = omap1_dma_reqs[bus_id][substream->stream];
168 port = omap1_mcbsp_port[bus_id][substream->stream];
169 } else if (cpu_is_omap2420()) {
170 dma = omap2420_dma_reqs[bus_id][substream->stream];
171 port = omap2420_mcbsp_port[bus_id][substream->stream];
172 } else {
173 /*
174 * TODO: Add support for 2430 and 3430
175 */
176 return -ENODEV;
177 }
178 omap_mcbsp_dai_dma_params[id][substream->stream].dma_req = dma;
179 omap_mcbsp_dai_dma_params[id][substream->stream].port_addr = port;
180 cpu_dai->dma_data = &omap_mcbsp_dai_dma_params[id][substream->stream];
181
182 if (mcbsp_data->configured) {
183 /* McBSP already configured by another stream */
184 return 0;
185 }
186
187 switch (params_channels(params)) {
188 case 2:
189 /* Set 1 word per (McBPSP) frame and use dual-phase frames */
190 regs->rcr2 |= RFRLEN2(1 - 1) | RPHASE;
191 regs->rcr1 |= RFRLEN1(1 - 1);
192 regs->xcr2 |= XFRLEN2(1 - 1) | XPHASE;
193 regs->xcr1 |= XFRLEN1(1 - 1);
194 break;
195 default:
196 /* Unsupported number of channels */
197 return -EINVAL;
198 }
199
200 switch (params_format(params)) {
201 case SNDRV_PCM_FORMAT_S16_LE:
202 /* Set word lengths */
203 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_16);
204 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_16);
205 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_16);
206 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_16);
207 /* Set FS period and length in terms of bit clock periods */
208 regs->srgr2 |= FPER(16 * 2 - 1);
209 regs->srgr1 |= FWID(16 - 1);
210 break;
211 default:
212 /* Unsupported PCM format */
213 return -EINVAL;
214 }
215
216 omap_mcbsp_config(bus_id, &mcbsp_data->regs);
217 mcbsp_data->configured = 1;
218
219 return 0;
220}
221
222/*
223 * This must be called before _set_clkdiv and _set_sysclk since McBSP register
224 * cache is initialized here
225 */
226static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
227 unsigned int fmt)
228{
229 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
230 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
231
232 if (mcbsp_data->configured)
233 return 0;
234
235 memset(regs, 0, sizeof(*regs));
236 /* Generic McBSP register settings */
237 regs->spcr2 |= XINTM(3) | FREE;
238 regs->spcr1 |= RINTM(3);
239 regs->rcr2 |= RFIG;
240 regs->xcr2 |= XFIG;
241
242 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
243 case SND_SOC_DAIFMT_I2S:
244 /* 1-bit data delay */
245 regs->rcr2 |= RDATDLY(1);
246 regs->xcr2 |= XDATDLY(1);
247 break;
248 default:
249 /* Unsupported data format */
250 return -EINVAL;
251 }
252
253 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
254 case SND_SOC_DAIFMT_CBS_CFS:
255 /* McBSP master. Set FS and bit clocks as outputs */
256 regs->pcr0 |= FSXM | FSRM |
257 CLKXM | CLKRM;
258 /* Sample rate generator drives the FS */
259 regs->srgr2 |= FSGM;
260 break;
261 case SND_SOC_DAIFMT_CBM_CFM:
262 /* McBSP slave */
263 break;
264 default:
265 /* Unsupported master/slave configuration */
266 return -EINVAL;
267 }
268
269 /* Set bit clock (CLKX/CLKR) and FS polarities */
270 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
271 case SND_SOC_DAIFMT_NB_NF:
272 /*
273 * Normal BCLK + FS.
274 * FS active low. TX data driven on falling edge of bit clock
275 * and RX data sampled on rising edge of bit clock.
276 */
277 regs->pcr0 |= FSXP | FSRP |
278 CLKXP | CLKRP;
279 break;
280 case SND_SOC_DAIFMT_NB_IF:
281 regs->pcr0 |= CLKXP | CLKRP;
282 break;
283 case SND_SOC_DAIFMT_IB_NF:
284 regs->pcr0 |= FSXP | FSRP;
285 break;
286 case SND_SOC_DAIFMT_IB_IF:
287 break;
288 default:
289 return -EINVAL;
290 }
291
292 return 0;
293}
294
295static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_cpu_dai *cpu_dai,
296 int div_id, int div)
297{
298 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
299 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
300
301 if (div_id != OMAP_MCBSP_CLKGDV)
302 return -ENODEV;
303
304 regs->srgr1 |= CLKGDV(div - 1);
305
306 return 0;
307}
308
309static int omap_mcbsp_dai_set_clks_src(struct omap_mcbsp_data *mcbsp_data,
310 int clk_id)
311{
312 int sel_bit;
313 u16 reg;
314
315 if (cpu_class_is_omap1()) {
316 /* OMAP1's can use only external source clock */
317 if (unlikely(clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK))
318 return -EINVAL;
319 else
320 return 0;
321 }
322
323 switch (mcbsp_data->bus_id) {
324 case 0:
325 reg = OMAP2_CONTROL_DEVCONF0;
326 sel_bit = 2;
327 break;
328 case 1:
329 reg = OMAP2_CONTROL_DEVCONF0;
330 sel_bit = 6;
331 break;
332 /* TODO: Support for ports 3 - 5 in OMAP2430 and OMAP34xx */
333 default:
334 return -EINVAL;
335 }
336
337 if (cpu_class_is_omap2()) {
338 if (clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK) {
339 omap_ctrl_writel(omap_ctrl_readl(reg) &
340 ~(1 << sel_bit), reg);
341 } else {
342 omap_ctrl_writel(omap_ctrl_readl(reg) |
343 (1 << sel_bit), reg);
344 }
345 }
346
347 return 0;
348}
349
350static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai,
351 int clk_id, unsigned int freq,
352 int dir)
353{
354 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
355 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
356 int err = 0;
357
358 switch (clk_id) {
359 case OMAP_MCBSP_SYSCLK_CLK:
360 regs->srgr2 |= CLKSM;
361 break;
362 case OMAP_MCBSP_SYSCLK_CLKS_FCLK:
363 case OMAP_MCBSP_SYSCLK_CLKS_EXT:
364 err = omap_mcbsp_dai_set_clks_src(mcbsp_data, clk_id);
365 break;
366
367 case OMAP_MCBSP_SYSCLK_CLKX_EXT:
368 regs->srgr2 |= CLKSM;
369 case OMAP_MCBSP_SYSCLK_CLKR_EXT:
370 regs->pcr0 |= SCLKME;
371 break;
372 default:
373 err = -ENODEV;
374 }
375
376 return err;
377}
378
379struct snd_soc_cpu_dai omap_mcbsp_dai[NUM_LINKS] = {
380{
381 .name = "omap-mcbsp-dai",
382 .id = 0,
383 .type = SND_SOC_DAI_I2S,
384 .playback = {
385 .channels_min = 2,
386 .channels_max = 2,
387 .rates = OMAP_MCBSP_RATES,
388 .formats = SNDRV_PCM_FMTBIT_S16_LE,
389 },
390 .capture = {
391 .channels_min = 2,
392 .channels_max = 2,
393 .rates = OMAP_MCBSP_RATES,
394 .formats = SNDRV_PCM_FMTBIT_S16_LE,
395 },
396 .ops = {
397 .startup = omap_mcbsp_dai_startup,
398 .shutdown = omap_mcbsp_dai_shutdown,
399 .trigger = omap_mcbsp_dai_trigger,
400 .hw_params = omap_mcbsp_dai_hw_params,
401 },
402 .dai_ops = {
403 .set_fmt = omap_mcbsp_dai_set_dai_fmt,
404 .set_clkdiv = omap_mcbsp_dai_set_clkdiv,
405 .set_sysclk = omap_mcbsp_dai_set_dai_sysclk,
406 },
407 .private_data = &mcbsp_data[0].bus_id,
408},
409};
410EXPORT_SYMBOL_GPL(omap_mcbsp_dai);
411
412MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>");
413MODULE_DESCRIPTION("OMAP I2S SoC Interface");
414MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/omap-mcbsp.h b/sound/soc/omap/omap-mcbsp.h
new file mode 100644
index 000000000000..9965fd4b0427
--- /dev/null
+++ b/sound/soc/omap/omap-mcbsp.h
@@ -0,0 +1,49 @@
1/*
2 * omap-mcbsp.h
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef __OMAP_I2S_H__
25#define __OMAP_I2S_H__
26
27/* Source clocks for McBSP sample rate generator */
28enum omap_mcbsp_clksrg_clk {
29 OMAP_MCBSP_SYSCLK_CLKS_FCLK, /* Internal FCLK */
30 OMAP_MCBSP_SYSCLK_CLKS_EXT, /* External CLKS pin */
31 OMAP_MCBSP_SYSCLK_CLK, /* Internal ICLK */
32 OMAP_MCBSP_SYSCLK_CLKX_EXT, /* External CLKX pin */
33 OMAP_MCBSP_SYSCLK_CLKR_EXT, /* External CLKR pin */
34};
35
36/* McBSP dividers */
37enum omap_mcbsp_div {
38 OMAP_MCBSP_CLKGDV, /* Sample rate generator divider */
39};
40
41/*
42 * REVISIT: Preparation for the ASoC v2. Let the number of available links to
43 * be same than number of McBSP ports found in OMAP(s) we are compiling for.
44 */
45#define NUM_LINKS 1
46
47extern struct snd_soc_cpu_dai omap_mcbsp_dai[NUM_LINKS];
48
49#endif
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c
new file mode 100644
index 000000000000..62370202c649
--- /dev/null
+++ b/sound/soc/omap/omap-pcm.c
@@ -0,0 +1,357 @@
1/*
2 * omap-pcm.c -- ALSA PCM interface for the OMAP SoC
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/dma-mapping.h>
25#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/pcm_params.h>
28#include <sound/soc.h>
29
30#include <asm/arch/dma.h>
31#include "omap-pcm.h"
32
33static const struct snd_pcm_hardware omap_pcm_hardware = {
34 .info = SNDRV_PCM_INFO_MMAP |
35 SNDRV_PCM_INFO_MMAP_VALID |
36 SNDRV_PCM_INFO_INTERLEAVED |
37 SNDRV_PCM_INFO_PAUSE |
38 SNDRV_PCM_INFO_RESUME,
39 .formats = SNDRV_PCM_FMTBIT_S16_LE,
40 .period_bytes_min = 32,
41 .period_bytes_max = 64 * 1024,
42 .periods_min = 2,
43 .periods_max = 255,
44 .buffer_bytes_max = 128 * 1024,
45};
46
47struct omap_runtime_data {
48 spinlock_t lock;
49 struct omap_pcm_dma_data *dma_data;
50 int dma_ch;
51 int period_index;
52};
53
54static void omap_pcm_dma_irq(int ch, u16 stat, void *data)
55{
56 struct snd_pcm_substream *substream = data;
57 struct snd_pcm_runtime *runtime = substream->runtime;
58 struct omap_runtime_data *prtd = runtime->private_data;
59 unsigned long flags;
60
61 if (cpu_is_omap1510()) {
62 /*
63 * OMAP1510 doesn't support DMA chaining so have to restart
64 * the transfer after all periods are transferred
65 */
66 spin_lock_irqsave(&prtd->lock, flags);
67 if (prtd->period_index >= 0) {
68 if (++prtd->period_index == runtime->periods) {
69 prtd->period_index = 0;
70 omap_start_dma(prtd->dma_ch);
71 }
72 }
73 spin_unlock_irqrestore(&prtd->lock, flags);
74 }
75
76 snd_pcm_period_elapsed(substream);
77}
78
79/* this may get called several times by oss emulation */
80static int omap_pcm_hw_params(struct snd_pcm_substream *substream,
81 struct snd_pcm_hw_params *params)
82{
83 struct snd_pcm_runtime *runtime = substream->runtime;
84 struct snd_soc_pcm_runtime *rtd = substream->private_data;
85 struct omap_runtime_data *prtd = runtime->private_data;
86 struct omap_pcm_dma_data *dma_data = rtd->dai->cpu_dai->dma_data;
87 int err = 0;
88
89 if (!dma_data)
90 return -ENODEV;
91
92 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
93 runtime->dma_bytes = params_buffer_bytes(params);
94
95 if (prtd->dma_data)
96 return 0;
97 prtd->dma_data = dma_data;
98 err = omap_request_dma(dma_data->dma_req, dma_data->name,
99 omap_pcm_dma_irq, substream, &prtd->dma_ch);
100 if (!cpu_is_omap1510()) {
101 /*
102 * Link channel with itself so DMA doesn't need any
103 * reprogramming while looping the buffer
104 */
105 omap_dma_link_lch(prtd->dma_ch, prtd->dma_ch);
106 }
107
108 return err;
109}
110
111static int omap_pcm_hw_free(struct snd_pcm_substream *substream)
112{
113 struct snd_pcm_runtime *runtime = substream->runtime;
114 struct omap_runtime_data *prtd = runtime->private_data;
115
116 if (prtd->dma_data == NULL)
117 return 0;
118
119 if (!cpu_is_omap1510())
120 omap_dma_unlink_lch(prtd->dma_ch, prtd->dma_ch);
121 omap_free_dma(prtd->dma_ch);
122 prtd->dma_data = NULL;
123
124 snd_pcm_set_runtime_buffer(substream, NULL);
125
126 return 0;
127}
128
129static int omap_pcm_prepare(struct snd_pcm_substream *substream)
130{
131 struct snd_pcm_runtime *runtime = substream->runtime;
132 struct omap_runtime_data *prtd = runtime->private_data;
133 struct omap_pcm_dma_data *dma_data = prtd->dma_data;
134 struct omap_dma_channel_params dma_params;
135
136 memset(&dma_params, 0, sizeof(dma_params));
137 /*
138 * Note: Regardless of interface data formats supported by OMAP McBSP
139 * or EAC blocks, internal representation is always fixed 16-bit/sample
140 */
141 dma_params.data_type = OMAP_DMA_DATA_TYPE_S16;
142 dma_params.trigger = dma_data->dma_req;
143 dma_params.sync_mode = OMAP_DMA_SYNC_ELEMENT;
144 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
145 dma_params.src_amode = OMAP_DMA_AMODE_POST_INC;
146 dma_params.dst_amode = OMAP_DMA_AMODE_CONSTANT;
147 dma_params.src_or_dst_synch = OMAP_DMA_DST_SYNC;
148 dma_params.src_start = runtime->dma_addr;
149 dma_params.dst_start = dma_data->port_addr;
150 } else {
151 dma_params.src_amode = OMAP_DMA_AMODE_CONSTANT;
152 dma_params.dst_amode = OMAP_DMA_AMODE_POST_INC;
153 dma_params.src_or_dst_synch = OMAP_DMA_SRC_SYNC;
154 dma_params.src_start = dma_data->port_addr;
155 dma_params.dst_start = runtime->dma_addr;
156 }
157 /*
158 * Set DMA transfer frame size equal to ALSA period size and frame
159 * count as no. of ALSA periods. Then with DMA frame interrupt enabled,
160 * we can transfer the whole ALSA buffer with single DMA transfer but
161 * still can get an interrupt at each period bounary
162 */
163 dma_params.elem_count = snd_pcm_lib_period_bytes(substream) / 2;
164 dma_params.frame_count = runtime->periods;
165 omap_set_dma_params(prtd->dma_ch, &dma_params);
166
167 omap_enable_dma_irq(prtd->dma_ch, OMAP_DMA_FRAME_IRQ);
168
169 return 0;
170}
171
172static int omap_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
173{
174 struct snd_pcm_runtime *runtime = substream->runtime;
175 struct omap_runtime_data *prtd = runtime->private_data;
176 int ret = 0;
177
178 spin_lock_irq(&prtd->lock);
179 switch (cmd) {
180 case SNDRV_PCM_TRIGGER_START:
181 case SNDRV_PCM_TRIGGER_RESUME:
182 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
183 prtd->period_index = 0;
184 omap_start_dma(prtd->dma_ch);
185 break;
186
187 case SNDRV_PCM_TRIGGER_STOP:
188 case SNDRV_PCM_TRIGGER_SUSPEND:
189 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
190 prtd->period_index = -1;
191 omap_stop_dma(prtd->dma_ch);
192 break;
193 default:
194 ret = -EINVAL;
195 }
196 spin_unlock_irq(&prtd->lock);
197
198 return ret;
199}
200
201static snd_pcm_uframes_t omap_pcm_pointer(struct snd_pcm_substream *substream)
202{
203 struct snd_pcm_runtime *runtime = substream->runtime;
204 struct omap_runtime_data *prtd = runtime->private_data;
205 dma_addr_t ptr;
206 snd_pcm_uframes_t offset;
207
208 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
209 ptr = omap_get_dma_src_pos(prtd->dma_ch);
210 else
211 ptr = omap_get_dma_dst_pos(prtd->dma_ch);
212
213 offset = bytes_to_frames(runtime, ptr - runtime->dma_addr);
214 if (offset >= runtime->buffer_size)
215 offset = 0;
216
217 return offset;
218}
219
220static int omap_pcm_open(struct snd_pcm_substream *substream)
221{
222 struct snd_pcm_runtime *runtime = substream->runtime;
223 struct omap_runtime_data *prtd;
224 int ret;
225
226 snd_soc_set_runtime_hwparams(substream, &omap_pcm_hardware);
227
228 /* Ensure that buffer size is a multiple of period size */
229 ret = snd_pcm_hw_constraint_integer(runtime,
230 SNDRV_PCM_HW_PARAM_PERIODS);
231 if (ret < 0)
232 goto out;
233
234 prtd = kzalloc(sizeof(prtd), GFP_KERNEL);
235 if (prtd == NULL) {
236 ret = -ENOMEM;
237 goto out;
238 }
239 spin_lock_init(&prtd->lock);
240 runtime->private_data = prtd;
241
242out:
243 return ret;
244}
245
246static int omap_pcm_close(struct snd_pcm_substream *substream)
247{
248 struct snd_pcm_runtime *runtime = substream->runtime;
249
250 kfree(runtime->private_data);
251 return 0;
252}
253
254static int omap_pcm_mmap(struct snd_pcm_substream *substream,
255 struct vm_area_struct *vma)
256{
257 struct snd_pcm_runtime *runtime = substream->runtime;
258
259 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
260 runtime->dma_area,
261 runtime->dma_addr,
262 runtime->dma_bytes);
263}
264
265struct snd_pcm_ops omap_pcm_ops = {
266 .open = omap_pcm_open,
267 .close = omap_pcm_close,
268 .ioctl = snd_pcm_lib_ioctl,
269 .hw_params = omap_pcm_hw_params,
270 .hw_free = omap_pcm_hw_free,
271 .prepare = omap_pcm_prepare,
272 .trigger = omap_pcm_trigger,
273 .pointer = omap_pcm_pointer,
274 .mmap = omap_pcm_mmap,
275};
276
277static u64 omap_pcm_dmamask = DMA_BIT_MASK(32);
278
279static int omap_pcm_preallocate_dma_buffer(struct snd_pcm *pcm,
280 int stream)
281{
282 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
283 struct snd_dma_buffer *buf = &substream->dma_buffer;
284 size_t size = omap_pcm_hardware.buffer_bytes_max;
285
286 buf->dev.type = SNDRV_DMA_TYPE_DEV;
287 buf->dev.dev = pcm->card->dev;
288 buf->private_data = NULL;
289 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
290 &buf->addr, GFP_KERNEL);
291 if (!buf->area)
292 return -ENOMEM;
293
294 buf->bytes = size;
295 return 0;
296}
297
298static void omap_pcm_free_dma_buffers(struct snd_pcm *pcm)
299{
300 struct snd_pcm_substream *substream;
301 struct snd_dma_buffer *buf;
302 int stream;
303
304 for (stream = 0; stream < 2; stream++) {
305 substream = pcm->streams[stream].substream;
306 if (!substream)
307 continue;
308
309 buf = &substream->dma_buffer;
310 if (!buf->area)
311 continue;
312
313 dma_free_writecombine(pcm->card->dev, buf->bytes,
314 buf->area, buf->addr);
315 buf->area = NULL;
316 }
317}
318
319int omap_pcm_new(struct snd_card *card, struct snd_soc_codec_dai *dai,
320 struct snd_pcm *pcm)
321{
322 int ret = 0;
323
324 if (!card->dev->dma_mask)
325 card->dev->dma_mask = &omap_pcm_dmamask;
326 if (!card->dev->coherent_dma_mask)
327 card->dev->coherent_dma_mask = DMA_32BIT_MASK;
328
329 if (dai->playback.channels_min) {
330 ret = omap_pcm_preallocate_dma_buffer(pcm,
331 SNDRV_PCM_STREAM_PLAYBACK);
332 if (ret)
333 goto out;
334 }
335
336 if (dai->capture.channels_min) {
337 ret = omap_pcm_preallocate_dma_buffer(pcm,
338 SNDRV_PCM_STREAM_CAPTURE);
339 if (ret)
340 goto out;
341 }
342
343out:
344 return ret;
345}
346
347struct snd_soc_platform omap_soc_platform = {
348 .name = "omap-pcm-audio",
349 .pcm_ops = &omap_pcm_ops,
350 .pcm_new = omap_pcm_new,
351 .pcm_free = omap_pcm_free_dma_buffers,
352};
353EXPORT_SYMBOL_GPL(omap_soc_platform);
354
355MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>");
356MODULE_DESCRIPTION("OMAP PCM DMA module");
357MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/omap-pcm.h b/sound/soc/omap/omap-pcm.h
new file mode 100644
index 000000000000..e4369bdfd77d
--- /dev/null
+++ b/sound/soc/omap/omap-pcm.h
@@ -0,0 +1,35 @@
1/*
2 * omap-pcm.h
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef __OMAP_PCM_H__
25#define __OMAP_PCM_H__
26
27struct omap_pcm_dma_data {
28 char *name; /* stream identifier */
29 int dma_req; /* DMA request line */
30 unsigned long port_addr; /* transmit/receive register */
31};
32
33extern struct snd_soc_platform omap_soc_platform;
34
35#endif
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index 1a70a6ac98ce..7f32a1167572 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -297,21 +297,19 @@ static int corgi_wm8731_init(struct snd_soc_codec *codec)
297 /* Add corgi specific controls */ 297 /* Add corgi specific controls */
298 for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) { 298 for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) {
299 err = snd_ctl_add(codec->card, 299 err = snd_ctl_add(codec->card,
300 snd_soc_cnew(&wm8731_corgi_controls[i],codec, NULL)); 300 snd_soc_cnew(&wm8731_corgi_controls[i], codec, NULL));
301 if (err < 0) 301 if (err < 0)
302 return err; 302 return err;
303 } 303 }
304 304
305 /* Add corgi specific widgets */ 305 /* Add corgi specific widgets */
306 for(i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 306 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
307 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 307 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
308 }
309 308
310 /* Set up corgi specific audio path audio_map */ 309 /* Set up corgi specific audio path audio_map */
311 for(i = 0; audio_map[i][0] != NULL; i++) { 310 for (i = 0; audio_map[i][0] != NULL; i++)
312 snd_soc_dapm_connect_input(codec, audio_map[i][0], 311 snd_soc_dapm_connect_input(codec, audio_map[i][0],
313 audio_map[i][1], audio_map[i][2]); 312 audio_map[i][1], audio_map[i][2]);
314 }
315 313
316 snd_soc_dapm_sync_endpoints(codec); 314 snd_soc_dapm_sync_endpoints(codec);
317 return 0; 315 return 0;
@@ -353,7 +351,8 @@ static int __init corgi_init(void)
353{ 351{
354 int ret; 352 int ret;
355 353
356 if (!(machine_is_corgi() || machine_is_shepherd() || machine_is_husky())) 354 if (!(machine_is_corgi() || machine_is_shepherd() ||
355 machine_is_husky()))
357 return -ENODEV; 356 return -ENODEV;
358 357
359 corgi_snd_device = platform_device_alloc("soc-audio", -1); 358 corgi_snd_device = platform_device_alloc("soc-audio", -1);
diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c
index 4fbf8bba9627..7e830b218943 100644
--- a/sound/soc/pxa/poodle.c
+++ b/sound/soc/pxa/poodle.c
@@ -257,21 +257,19 @@ static int poodle_wm8731_init(struct snd_soc_codec *codec)
257 /* Add poodle specific controls */ 257 /* Add poodle specific controls */
258 for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) { 258 for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) {
259 err = snd_ctl_add(codec->card, 259 err = snd_ctl_add(codec->card,
260 snd_soc_cnew(&wm8731_poodle_controls[i],codec, NULL)); 260 snd_soc_cnew(&wm8731_poodle_controls[i], codec, NULL));
261 if (err < 0) 261 if (err < 0)
262 return err; 262 return err;
263 } 263 }
264 264
265 /* Add poodle specific widgets */ 265 /* Add poodle specific widgets */
266 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 266 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
267 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 267 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
268 }
269 268
270 /* Set up poodle specific audio path audio_map */ 269 /* Set up poodle specific audio path audio_map */
271 for (i = 0; audio_map[i][0] != NULL; i++) { 270 for (i = 0; audio_map[i][0] != NULL; i++)
272 snd_soc_dapm_connect_input(codec, audio_map[i][0], 271 snd_soc_dapm_connect_input(codec, audio_map[i][0],
273 audio_map[i][1], audio_map[i][2]); 272 audio_map[i][1], audio_map[i][2]);
274 }
275 273
276 snd_soc_dapm_sync_endpoints(codec); 274 snd_soc_dapm_sync_endpoints(codec);
277 return 0; 275 return 0;
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index 815c15336255..97ec2d90547c 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -15,6 +15,7 @@
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/wait.h> 17#include <linux/wait.h>
18#include <linux/clk.h>
18#include <linux/delay.h> 19#include <linux/delay.h>
19 20
20#include <sound/core.h> 21#include <sound/core.h>
@@ -27,6 +28,7 @@
27#include <linux/mutex.h> 28#include <linux/mutex.h>
28#include <asm/hardware.h> 29#include <asm/hardware.h>
29#include <asm/arch/pxa-regs.h> 30#include <asm/arch/pxa-regs.h>
31#include <asm/arch/pxa2xx-gpio.h>
30#include <asm/arch/audio.h> 32#include <asm/arch/audio.h>
31 33
32#include "pxa2xx-pcm.h" 34#include "pxa2xx-pcm.h"
@@ -35,6 +37,10 @@
35static DEFINE_MUTEX(car_mutex); 37static DEFINE_MUTEX(car_mutex);
36static DECLARE_WAIT_QUEUE_HEAD(gsr_wq); 38static DECLARE_WAIT_QUEUE_HEAD(gsr_wq);
37static volatile long gsr_bits; 39static volatile long gsr_bits;
40static struct clk *ac97_clk;
41#ifdef CONFIG_PXA27x
42static struct clk *ac97conf_clk;
43#endif
38 44
39/* 45/*
40 * Beware PXA27x bugs: 46 * Beware PXA27x bugs:
@@ -55,7 +61,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97,
55 mutex_lock(&car_mutex); 61 mutex_lock(&car_mutex);
56 62
57 /* set up primary or secondary codec/modem space */ 63 /* set up primary or secondary codec/modem space */
58#ifdef CONFIG_PXA27x 64#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
59 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 65 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
60#else 66#else
61 if (reg == AC97_GPIO_STATUS) 67 if (reg == AC97_GPIO_STATUS)
@@ -81,7 +87,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97,
81 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1); 87 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
82 if (!((GSR | gsr_bits) & GSR_SDONE)) { 88 if (!((GSR | gsr_bits) & GSR_SDONE)) {
83 printk(KERN_ERR "%s: read error (ac97_reg=%x GSR=%#lx)\n", 89 printk(KERN_ERR "%s: read error (ac97_reg=%x GSR=%#lx)\n",
84 __FUNCTION__, reg, GSR | gsr_bits); 90 __func__, reg, GSR | gsr_bits);
85 val = -1; 91 val = -1;
86 goto out; 92 goto out;
87 } 93 }
@@ -105,7 +111,7 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
105 mutex_lock(&car_mutex); 111 mutex_lock(&car_mutex);
106 112
107 /* set up primary or secondary codec/modem space */ 113 /* set up primary or secondary codec/modem space */
108#ifdef CONFIG_PXA27x 114#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
109 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 115 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
110#else 116#else
111 if (reg == AC97_GPIO_STATUS) 117 if (reg == AC97_GPIO_STATUS)
@@ -121,13 +127,16 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
121 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1); 127 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1);
122 if (!((GSR | gsr_bits) & GSR_CDONE)) 128 if (!((GSR | gsr_bits) & GSR_CDONE))
123 printk(KERN_ERR "%s: write error (ac97_reg=%x GSR=%#lx)\n", 129 printk(KERN_ERR "%s: write error (ac97_reg=%x GSR=%#lx)\n",
124 __FUNCTION__, reg, GSR | gsr_bits); 130 __func__, reg, GSR | gsr_bits);
125 131
126 mutex_unlock(&car_mutex); 132 mutex_unlock(&car_mutex);
127} 133}
128 134
129static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 135static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
130{ 136{
137#ifdef CONFIG_PXA3xx
138 int timeout = 100;
139#endif
131 gsr_bits = 0; 140 gsr_bits = 0;
132 141
133#ifdef CONFIG_PXA27x 142#ifdef CONFIG_PXA27x
@@ -138,6 +147,11 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
138 GCR |= GCR_WARM_RST; 147 GCR |= GCR_WARM_RST;
139 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 148 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
140 udelay(500); 149 udelay(500);
150#elif defined(CONFIG_PXA3xx)
151 /* Can't use interrupts */
152 GCR |= GCR_WARM_RST;
153 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
154 mdelay(1);
141#else 155#else
142 GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN; 156 GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN;
143 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1); 157 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
@@ -145,7 +159,7 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
145 159
146 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 160 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
147 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", 161 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
148 __FUNCTION__, gsr_bits); 162 __func__, gsr_bits);
149 163
150 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 164 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
151 GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 165 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
@@ -153,17 +167,34 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
153 167
154static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 168static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
155{ 169{
170#ifdef CONFIG_PXA3xx
171 int timeout = 1000;
172
173 /* Hold CLKBPB for 100us */
174 GCR = 0;
175 GCR = GCR_CLKBPB;
176 udelay(100);
177 GCR = 0;
178#endif
179
156 GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 180 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
157 GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 181 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
158 182
159 gsr_bits = 0; 183 gsr_bits = 0;
160#ifdef CONFIG_PXA27x 184#ifdef CONFIG_PXA27x
161 /* PXA27x Developers Manual section 13.5.2.2.1 */ 185 /* PXA27x Developers Manual section 13.5.2.2.1 */
162 pxa_set_cken(CKEN_AC97CONF, 1); 186 clk_enable(ac97conf_clk);
163 udelay(5); 187 udelay(5);
164 pxa_set_cken(CKEN_AC97CONF, 0); 188 clk_disable(ac97conf_clk);
165 GCR = GCR_COLD_RST; 189 GCR = GCR_COLD_RST;
166 udelay(50); 190 udelay(50);
191#elif defined(CONFIG_PXA3xx)
192 /* Can't use interrupts on PXA3xx */
193 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
194
195 GCR = GCR_WARM_RST | GCR_COLD_RST;
196 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
197 mdelay(10);
167#else 198#else
168 GCR = GCR_COLD_RST; 199 GCR = GCR_COLD_RST;
169 GCR |= GCR_CDONE_IE|GCR_SDONE_IE; 200 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
@@ -172,7 +203,7 @@ static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
172 203
173 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 204 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
174 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n", 205 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
175 __FUNCTION__, gsr_bits); 206 __func__, gsr_bits);
176 207
177 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 208 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
178 GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 209 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
@@ -255,7 +286,7 @@ static int pxa2xx_ac97_suspend(struct platform_device *pdev,
255 struct snd_soc_cpu_dai *dai) 286 struct snd_soc_cpu_dai *dai)
256{ 287{
257 GCR |= GCR_ACLINK_OFF; 288 GCR |= GCR_ACLINK_OFF;
258 pxa_set_cken(CKEN_AC97, 0); 289 clk_disable(ac97_clk);
259 return 0; 290 return 0;
260} 291}
261 292
@@ -270,7 +301,7 @@ static int pxa2xx_ac97_resume(struct platform_device *pdev,
270 /* Use GPIO 113 as AC97 Reset on Bulverde */ 301 /* Use GPIO 113 as AC97 Reset on Bulverde */
271 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 302 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
272#endif 303#endif
273 pxa_set_cken(CKEN_AC97, 1); 304 clk_enable(ac97_clk);
274 return 0; 305 return 0;
275} 306}
276 307
@@ -294,16 +325,33 @@ static int pxa2xx_ac97_probe(struct platform_device *pdev)
294#ifdef CONFIG_PXA27x 325#ifdef CONFIG_PXA27x
295 /* Use GPIO 113 as AC97 Reset on Bulverde */ 326 /* Use GPIO 113 as AC97 Reset on Bulverde */
296 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 327 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
328
329 ac97conf_clk = clk_get(&pdev->dev, "AC97CONFCLK");
330 if (IS_ERR(ac97conf_clk)) {
331 ret = PTR_ERR(ac97conf_clk);
332 ac97conf_clk = NULL;
333 goto err_irq;
334 }
297#endif 335#endif
298 pxa_set_cken(CKEN_AC97, 1); 336 ac97_clk = clk_get(&pdev->dev, "AC97CLK");
337 if (IS_ERR(ac97_clk)) {
338 ret = PTR_ERR(ac97_clk);
339 ac97_clk = NULL;
340 goto err_irq;
341 }
342 clk_enable(ac97_clk);
299 return 0; 343 return 0;
300 344
301 err: 345 err_irq:
302 if (CKEN & (1 << CKEN_AC97)) { 346 GCR |= GCR_ACLINK_OFF;
303 GCR |= GCR_ACLINK_OFF; 347#ifdef CONFIG_PXA27x
304 free_irq(IRQ_AC97, NULL); 348 if (ac97conf_clk) {
305 pxa_set_cken(CKEN_AC97, 0); 349 clk_put(ac97conf_clk);
350 ac97conf_clk = NULL;
306 } 351 }
352#endif
353 free_irq(IRQ_AC97, NULL);
354 err:
307 return ret; 355 return ret;
308} 356}
309 357
@@ -311,7 +359,13 @@ static void pxa2xx_ac97_remove(struct platform_device *pdev)
311{ 359{
312 GCR |= GCR_ACLINK_OFF; 360 GCR |= GCR_ACLINK_OFF;
313 free_irq(IRQ_AC97, NULL); 361 free_irq(IRQ_AC97, NULL);
314 pxa_set_cken(CKEN_AC97, 0); 362#ifdef CONFIG_PXA27x
363 clk_put(ac97conf_clk);
364 ac97conf_clk = NULL;
365#endif
366 clk_disable(ac97_clk);
367 clk_put(ac97_clk);
368 ac97_clk = NULL;
315} 369}
316 370
317static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream, 371static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream,
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c
index 692b90002489..425071030970 100644
--- a/sound/soc/pxa/pxa2xx-i2s.c
+++ b/sound/soc/pxa/pxa2xx-i2s.c
@@ -25,6 +25,7 @@
25 25
26#include <asm/hardware.h> 26#include <asm/hardware.h>
27#include <asm/arch/pxa-regs.h> 27#include <asm/arch/pxa-regs.h>
28#include <asm/arch/pxa2xx-gpio.h>
28#include <asm/arch/audio.h> 29#include <asm/arch/audio.h>
29 30
30#include "pxa2xx-pcm.h" 31#include "pxa2xx-pcm.h"
diff --git a/sound/soc/pxa/pxa2xx-pcm.c b/sound/soc/pxa/pxa2xx-pcm.c
index daeaa4c8b876..01ad7bf716b7 100644
--- a/sound/soc/pxa/pxa2xx-pcm.c
+++ b/sound/soc/pxa/pxa2xx-pcm.c
@@ -64,8 +64,8 @@ static void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id)
64 if (dcsr & DCSR_ENDINTR) { 64 if (dcsr & DCSR_ENDINTR) {
65 snd_pcm_period_elapsed(substream); 65 snd_pcm_period_elapsed(substream);
66 } else { 66 } else {
67 printk( KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n", 67 printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
68 prtd->params->name, dma_ch, dcsr ); 68 prtd->params->name, dma_ch, dcsr);
69 } 69 }
70} 70}
71 71
@@ -84,8 +84,8 @@ static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
84 84
85 /* return if this is a bufferless transfer e.g. 85 /* return if this is a bufferless transfer e.g.
86 * codec <--> BT codec or GSM modem -- lg FIXME */ 86 * codec <--> BT codec or GSM modem -- lg FIXME */
87 if (!dma) 87 if (!dma)
88 return 0; 88 return 0;
89 89
90 /* this may get called several times by oss emulation 90 /* this may get called several times by oss emulation
91 * with different params */ 91 * with different params */
@@ -363,7 +363,6 @@ struct snd_soc_platform pxa2xx_soc_platform = {
363 .pcm_new = pxa2xx_pcm_new, 363 .pcm_new = pxa2xx_pcm_new,
364 .pcm_free = pxa2xx_pcm_free_dma_buffers, 364 .pcm_free = pxa2xx_pcm_free_dma_buffers,
365}; 365};
366
367EXPORT_SYMBOL_GPL(pxa2xx_soc_platform); 366EXPORT_SYMBOL_GPL(pxa2xx_soc_platform);
368 367
369MODULE_AUTHOR("Nicolas Pitre"); 368MODULE_AUTHOR("Nicolas Pitre");
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index ecca39033fcc..d8b8372db00e 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -313,15 +313,13 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec)
313 } 313 }
314 314
315 /* Add spitz specific widgets */ 315 /* Add spitz specific widgets */
316 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) { 316 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
317 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]); 317 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
318 }
319 318
320 /* Set up spitz specific audio path audio_map */ 319 /* Set up spitz specific audio path audio_map */
321 for (i = 0; audio_map[i][0] != NULL; i++) { 320 for (i = 0; audio_map[i][0] != NULL; i++)
322 snd_soc_dapm_connect_input(codec, audio_map[i][0], 321 snd_soc_dapm_connect_input(codec, audio_map[i][0],
323 audio_map[i][1], audio_map[i][2]); 322 audio_map[i][1], audio_map[i][2]);
324 }
325 323
326 snd_soc_dapm_sync_endpoints(codec); 324 snd_soc_dapm_sync_endpoints(codec);
327 return 0; 325 return 0;
diff --git a/sound/soc/s3c24xx/ln2440sbc_alc650.c b/sound/soc/s3c24xx/ln2440sbc_alc650.c
index 9ed8f2e8da10..4eab2c19c454 100644
--- a/sound/soc/s3c24xx/ln2440sbc_alc650.c
+++ b/sound/soc/s3c24xx/ln2440sbc_alc650.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * SoC audio for ln2440sbc 2 * SoC audio for ln2440sbc
3 * 3 *
4 * Copyright 2007 KonekTel, a.s. 4 * Copyright 2007 KonekTel, a.s.
5 * Author: Ivan Kuten 5 * Author: Ivan Kuten
6 * ivan.kuten@promwad.com 6 * ivan.kuten@promwad.com
7 * 7 *
8 * Heavily based on smdk2443_wm9710.c 8 * Heavily based on smdk2443_wm9710.c
9 * Copyright 2007 Wolfson Microelectronics PLC. 9 * Copyright 2007 Wolfson Microelectronics PLC.
10 * Author: Graeme Gregory 10 * Author: Graeme Gregory
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index 6ee115ceb011..0e9d1c5f2484 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -33,7 +33,7 @@
33#include <asm/arch/regs-gpio.h> 33#include <asm/arch/regs-gpio.h>
34#include <asm/hardware.h> 34#include <asm/hardware.h>
35#include <asm/arch/audio.h> 35#include <asm/arch/audio.h>
36#include <asm/io.h> 36#include <linux/io.h>
37#include <asm/arch/spi-gpio.h> 37#include <asm/arch/spi-gpio.h>
38 38
39#include <asm/plat-s3c24xx/regs-iis.h> 39#include <asm/plat-s3c24xx/regs-iis.h>
@@ -122,7 +122,7 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
122 122
123 /* set MCLK division for sample rate */ 123 /* set MCLK division for sample rate */
124 ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK, 124 ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
125 S3C2410_IISMOD_32FS ); 125 S3C2410_IISMOD_32FS);
126 if (ret < 0) 126 if (ret < 0)
127 return ret; 127 return ret;
128 128
@@ -133,7 +133,7 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
133 133
134 /* set prescaler division for sample rate */ 134 /* set prescaler division for sample rate */
135 ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER, 135 ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
136 S3C24XX_PRESCALE(4,4)); 136 S3C24XX_PRESCALE(4, 4));
137 if (ret < 0) 137 if (ret < 0)
138 return ret; 138 return ret;
139 139
@@ -222,7 +222,7 @@ static struct snd_soc_ops neo1973_voice_ops = {
222 .hw_free = neo1973_voice_hw_free, 222 .hw_free = neo1973_voice_hw_free,
223}; 223};
224 224
225static int neo1973_scenario = 0; 225static int neo1973_scenario;
226 226
227static int neo1973_get_scenario(struct snd_kcontrol *kcontrol, 227static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol) 228 struct snd_ctl_elem_value *ucontrol)
@@ -233,7 +233,7 @@ static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
233 233
234static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario) 234static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
235{ 235{
236 switch(neo1973_scenario) { 236 switch (neo1973_scenario) {
237 case NEO_AUDIO_OFF: 237 case NEO_AUDIO_OFF:
238 snd_soc_dapm_set_endpoint(codec, "Audio Out", 0); 238 snd_soc_dapm_set_endpoint(codec, "Audio Out", 0);
239 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0); 239 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
@@ -334,7 +334,7 @@ static void lm4857_write_regs(void)
334static int lm4857_get_reg(struct snd_kcontrol *kcontrol, 334static int lm4857_get_reg(struct snd_kcontrol *kcontrol,
335 struct snd_ctl_elem_value *ucontrol) 335 struct snd_ctl_elem_value *ucontrol)
336{ 336{
337 int reg=kcontrol->private_value & 0xFF; 337 int reg = kcontrol->private_value & 0xFF;
338 int shift = (kcontrol->private_value >> 8) & 0x0F; 338 int shift = (kcontrol->private_value >> 8) & 0x0F;
339 int mask = (kcontrol->private_value >> 16) & 0xFF; 339 int mask = (kcontrol->private_value >> 16) & 0xFF;
340 340
@@ -349,11 +349,11 @@ static int lm4857_set_reg(struct snd_kcontrol *kcontrol,
349 int shift = (kcontrol->private_value >> 8) & 0x0F; 349 int shift = (kcontrol->private_value >> 8) & 0x0F;
350 int mask = (kcontrol->private_value >> 16) & 0xFF; 350 int mask = (kcontrol->private_value >> 16) & 0xFF;
351 351
352 if (((lm4857_regs[reg] >> shift ) & mask) == 352 if (((lm4857_regs[reg] >> shift) & mask) ==
353 ucontrol->value.integer.value[0]) 353 ucontrol->value.integer.value[0])
354 return 0; 354 return 0;
355 355
356 lm4857_regs[reg] &= ~ (mask << shift); 356 lm4857_regs[reg] &= ~(mask << shift);
357 lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift; 357 lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift;
358 lm4857_write_regs(); 358 lm4857_write_regs();
359 return 1; 359 return 1;
@@ -398,7 +398,7 @@ static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
398 398
399 399
400/* example machine audio_mapnections */ 400/* example machine audio_mapnections */
401static const char* audio_map[][3] = { 401static const char *audio_map[][3] = {
402 402
403 /* Connections to the lm4857 amp */ 403 /* Connections to the lm4857 amp */
404 {"Audio Out", NULL, "LOUT1"}, 404 {"Audio Out", NULL, "LOUT1"},
@@ -450,7 +450,7 @@ static const char *neo_scenarios[] = {
450}; 450};
451 451
452static const struct soc_enum neo_scenario_enum[] = { 452static const struct soc_enum neo_scenario_enum[] = {
453 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios),neo_scenarios), 453 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios), neo_scenarios),
454}; 454};
455 455
456static const struct snd_kcontrol_new wm8753_neo1973_controls[] = { 456static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
@@ -521,8 +521,8 @@ static int neo1973_wm8753_init(struct snd_soc_codec *codec)
521/* 521/*
522 * BT Codec DAI 522 * BT Codec DAI
523 */ 523 */
524static struct snd_soc_cpu_dai bt_dai = 524static struct snd_soc_cpu_dai bt_dai = {
525{ .name = "Bluetooth", 525 .name = "Bluetooth",
526 .id = 0, 526 .id = 0,
527 .type = SND_SOC_DAI_PCM, 527 .type = SND_SOC_DAI_PCM,
528 .playback = { 528 .playback = {
@@ -616,6 +616,35 @@ static int lm4857_i2c_attach(struct i2c_adapter *adap)
616 return i2c_probe(adap, &addr_data, lm4857_amp_probe); 616 return i2c_probe(adap, &addr_data, lm4857_amp_probe);
617} 617}
618 618
619static u8 lm4857_state;
620
621static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
622{
623 dev_dbg(&dev->dev, "lm4857_suspend\n");
624 lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf;
625 if (lm4857_state) {
626 lm4857_regs[LM4857_CTRL] &= 0xf0;
627 lm4857_write_regs();
628 }
629 return 0;
630}
631
632static int lm4857_resume(struct i2c_client *dev)
633{
634 if (lm4857_state) {
635 lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f);
636 lm4857_write_regs();
637 }
638 return 0;
639}
640
641static void lm4857_shutdown(struct i2c_client *dev)
642{
643 dev_dbg(&dev->dev, "lm4857_shutdown\n");
644 lm4857_regs[LM4857_CTRL] &= 0xf0;
645 lm4857_write_regs();
646}
647
619/* corgi i2c codec control layer */ 648/* corgi i2c codec control layer */
620static struct i2c_driver lm4857_i2c_driver = { 649static struct i2c_driver lm4857_i2c_driver = {
621 .driver = { 650 .driver = {
@@ -623,6 +652,9 @@ static struct i2c_driver lm4857_i2c_driver = {
623 .owner = THIS_MODULE, 652 .owner = THIS_MODULE,
624 }, 653 },
625 .id = I2C_DRIVERID_LM4857, 654 .id = I2C_DRIVERID_LM4857,
655 .suspend = lm4857_suspend,
656 .resume = lm4857_resume,
657 .shutdown = lm4857_shutdown,
626 .attach_adapter = lm4857_i2c_attach, 658 .attach_adapter = lm4857_i2c_attach,
627 .detach_client = lm4857_i2c_detach, 659 .detach_client = lm4857_i2c_detach,
628 .command = NULL, 660 .command = NULL,
@@ -659,6 +691,7 @@ static int __init neo1973_init(void)
659 691
660static void __exit neo1973_exit(void) 692static void __exit neo1973_exit(void)
661{ 693{
694 i2c_del_driver(&lm4857_i2c_driver);
662 platform_device_unregister(neo1973_snd_device); 695 platform_device_unregister(neo1973_snd_device);
663} 696}
664 697
@@ -666,6 +699,6 @@ module_init(neo1973_init);
666module_exit(neo1973_exit); 699module_exit(neo1973_exit);
667 700
668/* Module information */ 701/* Module information */
669MODULE_AUTHOR("Graeme Gregory, graeme.gregory@wolfsonmicro.com, www.wolfsonmicro.com"); 702MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org");
670MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973"); 703MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973");
671MODULE_LICENSE("GPL"); 704MODULE_LICENSE("GPL");
diff --git a/sound/soc/s3c24xx/s3c2443-ac97.c b/sound/soc/s3c24xx/s3c2443-ac97.c
index 1c1ddbf7f3c0..e81d9a6c83da 100644
--- a/sound/soc/s3c24xx/s3c2443-ac97.c
+++ b/sound/soc/s3c24xx/s3c2443-ac97.c
@@ -19,6 +19,7 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/io.h>
22#include <linux/wait.h> 23#include <linux/wait.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
24#include <linux/clk.h> 25#include <linux/clk.h>
@@ -30,7 +31,6 @@
30#include <sound/soc.h> 31#include <sound/soc.h>
31 32
32#include <asm/hardware.h> 33#include <asm/hardware.h>
33#include <asm/io.h>
34#include <asm/plat-s3c/regs-ac97.h> 34#include <asm/plat-s3c/regs-ac97.h>
35#include <asm/arch/regs-gpio.h> 35#include <asm/arch/regs-gpio.h>
36#include <asm/arch/regs-clock.h> 36#include <asm/arch/regs-clock.h>
@@ -47,7 +47,7 @@ struct s3c24xx_ac97_info {
47}; 47};
48static struct s3c24xx_ac97_info s3c24xx_ac97; 48static struct s3c24xx_ac97_info s3c24xx_ac97;
49 49
50DECLARE_COMPLETION(ac97_completion); 50static DECLARE_COMPLETION(ac97_completion);
51static u32 codec_ready; 51static u32 codec_ready;
52static DECLARE_MUTEX(ac97_mutex); 52static DECLARE_MUTEX(ac97_mutex);
53 53
@@ -290,7 +290,7 @@ static int s3c2443_ac97_trigger(struct snd_pcm_substream *substream, int cmd)
290 u32 ac_glbctrl; 290 u32 ac_glbctrl;
291 291
292 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL); 292 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL);
293 switch(cmd) { 293 switch (cmd) {
294 case SNDRV_PCM_TRIGGER_START: 294 case SNDRV_PCM_TRIGGER_START:
295 case SNDRV_PCM_TRIGGER_RESUME: 295 case SNDRV_PCM_TRIGGER_RESUME:
296 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 296 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@@ -333,7 +333,7 @@ static int s3c2443_ac97_mic_trigger(struct snd_pcm_substream *substream,
333 u32 ac_glbctrl; 333 u32 ac_glbctrl;
334 334
335 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL); 335 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL);
336 switch(cmd) { 336 switch (cmd) {
337 case SNDRV_PCM_TRIGGER_START: 337 case SNDRV_PCM_TRIGGER_START:
338 case SNDRV_PCM_TRIGGER_RESUME: 338 case SNDRV_PCM_TRIGGER_RESUME:
339 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 339 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@@ -391,7 +391,6 @@ struct snd_soc_cpu_dai s3c2443_ac97_dai[] = {
391 .trigger = s3c2443_ac97_mic_trigger,}, 391 .trigger = s3c2443_ac97_mic_trigger,},
392}, 392},
393}; 393};
394
395EXPORT_SYMBOL_GPL(s3c2443_ac97_dai); 394EXPORT_SYMBOL_GPL(s3c2443_ac97_dai);
396EXPORT_SYMBOL_GPL(soc_ac97_ops); 395EXPORT_SYMBOL_GPL(soc_ac97_ops);
397 396
diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.c b/sound/soc/s3c24xx/s3c24xx-i2s.c
index 0a3c630951be..4ebcd6a8bf28 100644
--- a/sound/soc/s3c24xx/s3c24xx-i2s.c
+++ b/sound/soc/s3c24xx/s3c24xx-i2s.c
@@ -25,6 +25,7 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/io.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include <sound/pcm.h> 30#include <sound/pcm.h>
30#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
@@ -32,7 +33,6 @@
32#include <sound/soc.h> 33#include <sound/soc.h>
33 34
34#include <asm/hardware.h> 35#include <asm/hardware.h>
35#include <asm/io.h>
36#include <asm/arch/regs-gpio.h> 36#include <asm/arch/regs-gpio.h>
37#include <asm/arch/regs-clock.h> 37#include <asm/arch/regs-clock.h>
38#include <asm/arch/audio.h> 38#include <asm/arch/audio.h>
@@ -46,7 +46,7 @@
46 46
47#define S3C24XX_I2S_DEBUG 0 47#define S3C24XX_I2S_DEBUG 0
48#if S3C24XX_I2S_DEBUG 48#if S3C24XX_I2S_DEBUG
49#define DBG(x...) printk(KERN_DEBUG x) 49#define DBG(x...) printk(KERN_DEBUG "s3c24xx-i2s: " x)
50#else 50#else
51#define DBG(x...) 51#define DBG(x...)
52#endif 52#endif
@@ -89,7 +89,7 @@ static void s3c24xx_snd_txctrl(int on)
89 u32 iiscon; 89 u32 iiscon;
90 u32 iismod; 90 u32 iismod;
91 91
92 DBG("Entered %s\n", __FUNCTION__); 92 DBG("Entered %s\n", __func__);
93 93
94 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 94 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
95 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 95 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -134,7 +134,7 @@ static void s3c24xx_snd_rxctrl(int on)
134 u32 iiscon; 134 u32 iiscon;
135 u32 iismod; 135 u32 iismod;
136 136
137 DBG("Entered %s\n", __FUNCTION__); 137 DBG("Entered %s\n", __func__);
138 138
139 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 139 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
140 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 140 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -159,10 +159,10 @@ static void s3c24xx_snd_rxctrl(int on)
159 * DMA engine will simply freeze randomly. 159 * DMA engine will simply freeze randomly.
160 */ 160 */
161 161
162 iisfcon &= ~S3C2410_IISFCON_RXENABLE; 162 iisfcon &= ~S3C2410_IISFCON_RXENABLE;
163 iisfcon &= ~S3C2410_IISFCON_RXDMA; 163 iisfcon &= ~S3C2410_IISFCON_RXDMA;
164 iiscon |= S3C2410_IISCON_RXIDLE; 164 iiscon |= S3C2410_IISCON_RXIDLE;
165 iiscon &= ~S3C2410_IISCON_RXDMAEN; 165 iiscon &= ~S3C2410_IISCON_RXDMAEN;
166 iismod &= ~S3C2410_IISMOD_RXMODE; 166 iismod &= ~S3C2410_IISMOD_RXMODE;
167 167
168 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); 168 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
@@ -182,7 +182,7 @@ static int s3c24xx_snd_lrsync(void)
182 u32 iiscon; 182 u32 iiscon;
183 unsigned long timeout = jiffies + msecs_to_jiffies(5); 183 unsigned long timeout = jiffies + msecs_to_jiffies(5);
184 184
185 DBG("Entered %s\n", __FUNCTION__); 185 DBG("Entered %s\n", __func__);
186 186
187 while (1) { 187 while (1) {
188 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 188 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -201,7 +201,7 @@ static int s3c24xx_snd_lrsync(void)
201 */ 201 */
202static inline int s3c24xx_snd_is_clkmaster(void) 202static inline int s3c24xx_snd_is_clkmaster(void)
203{ 203{
204 DBG("Entered %s\n", __FUNCTION__); 204 DBG("Entered %s\n", __func__);
205 205
206 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1; 206 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1;
207} 207}
@@ -214,7 +214,7 @@ static int s3c24xx_i2s_set_fmt(struct snd_soc_cpu_dai *cpu_dai,
214{ 214{
215 u32 iismod; 215 u32 iismod;
216 216
217 DBG("Entered %s\n", __FUNCTION__); 217 DBG("Entered %s\n", __func__);
218 218
219 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 219 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
220 DBG("hw_params r: IISMOD: %lx \n", iismod); 220 DBG("hw_params r: IISMOD: %lx \n", iismod);
@@ -250,7 +250,7 @@ static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
250 struct snd_soc_pcm_runtime *rtd = substream->private_data; 250 struct snd_soc_pcm_runtime *rtd = substream->private_data;
251 u32 iismod; 251 u32 iismod;
252 252
253 DBG("Entered %s\n", __FUNCTION__); 253 DBG("Entered %s\n", __func__);
254 254
255 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 255 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
256 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out; 256 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out;
@@ -278,7 +278,7 @@ static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
278{ 278{
279 int ret = 0; 279 int ret = 0;
280 280
281 DBG("Entered %s\n", __FUNCTION__); 281 DBG("Entered %s\n", __func__);
282 282
283 switch (cmd) { 283 switch (cmd) {
284 case SNDRV_PCM_TRIGGER_START: 284 case SNDRV_PCM_TRIGGER_START:
@@ -320,7 +320,7 @@ static int s3c24xx_i2s_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
320{ 320{
321 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 321 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
322 322
323 DBG("Entered %s\n", __FUNCTION__); 323 DBG("Entered %s\n", __func__);
324 324
325 iismod &= ~S3C2440_IISMOD_MPLL; 325 iismod &= ~S3C2440_IISMOD_MPLL;
326 326
@@ -346,7 +346,7 @@ static int s3c24xx_i2s_set_clkdiv(struct snd_soc_cpu_dai *cpu_dai,
346{ 346{
347 u32 reg; 347 u32 reg;
348 348
349 DBG("Entered %s\n", __FUNCTION__); 349 DBG("Entered %s\n", __func__);
350 350
351 switch (div_id) { 351 switch (div_id) {
352 case S3C24XX_DIV_BCLK: 352 case S3C24XX_DIV_BCLK:
@@ -381,13 +381,13 @@ EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate);
381 381
382static int s3c24xx_i2s_probe(struct platform_device *pdev) 382static int s3c24xx_i2s_probe(struct platform_device *pdev)
383{ 383{
384 DBG("Entered %s\n", __FUNCTION__); 384 DBG("Entered %s\n", __func__);
385 385
386 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100); 386 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100);
387 if (s3c24xx_i2s.regs == NULL) 387 if (s3c24xx_i2s.regs == NULL)
388 return -ENXIO; 388 return -ENXIO;
389 389
390 s3c24xx_i2s.iis_clk=clk_get(&pdev->dev, "iis"); 390 s3c24xx_i2s.iis_clk = clk_get(&pdev->dev, "iis");
391 if (s3c24xx_i2s.iis_clk == NULL) { 391 if (s3c24xx_i2s.iis_clk == NULL) {
392 DBG("failed to get iis_clock\n"); 392 DBG("failed to get iis_clock\n");
393 iounmap(s3c24xx_i2s.regs); 393 iounmap(s3c24xx_i2s.regs);
@@ -411,9 +411,11 @@ static int s3c24xx_i2s_probe(struct platform_device *pdev)
411} 411}
412 412
413#ifdef CONFIG_PM 413#ifdef CONFIG_PM
414int s3c24xx_i2s_suspend(struct platform_device *pdev, 414static int s3c24xx_i2s_suspend(struct platform_device *pdev,
415 struct snd_soc_cpu_dai *cpu_dai) 415 struct snd_soc_cpu_dai *cpu_dai)
416{ 416{
417 DBG("Entered %s\n", __func__);
418
417 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 419 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
418 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 420 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
419 s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 421 s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
@@ -424,9 +426,10 @@ int s3c24xx_i2s_suspend(struct platform_device *pdev,
424 return 0; 426 return 0;
425} 427}
426 428
427int s3c24xx_i2s_resume(struct platform_device *pdev, 429static int s3c24xx_i2s_resume(struct platform_device *pdev,
428 struct snd_soc_cpu_dai *cpu_dai) 430 struct snd_soc_cpu_dai *cpu_dai)
429{ 431{
432 DBG("Entered %s\n", __func__);
430 clk_enable(s3c24xx_i2s.iis_clk); 433 clk_enable(s3c24xx_i2s.iis_clk);
431 434
432 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); 435 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
diff --git a/sound/soc/s3c24xx/s3c24xx-pcm.c b/sound/soc/s3c24xx/s3c24xx-pcm.c
index 29a6c82f873a..6c70a81c730c 100644
--- a/sound/soc/s3c24xx/s3c24xx-pcm.c
+++ b/sound/soc/s3c24xx/s3c24xx-pcm.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/io.h>
23#include <linux/platform_device.h> 24#include <linux/platform_device.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
@@ -30,7 +31,6 @@
30#include <sound/soc.h> 31#include <sound/soc.h>
31 32
32#include <asm/dma.h> 33#include <asm/dma.h>
33#include <asm/io.h>
34#include <asm/hardware.h> 34#include <asm/hardware.h>
35#include <asm/arch/dma.h> 35#include <asm/arch/dma.h>
36#include <asm/arch/audio.h> 36#include <asm/arch/audio.h>
@@ -39,7 +39,7 @@
39 39
40#define S3C24XX_PCM_DEBUG 0 40#define S3C24XX_PCM_DEBUG 0
41#if S3C24XX_PCM_DEBUG 41#if S3C24XX_PCM_DEBUG
42#define DBG(x...) printk(KERN_DEBUG x) 42#define DBG(x...) printk(KERN_DEBUG "s3c24xx-pcm: " x)
43#else 43#else
44#define DBG(x...) 44#define DBG(x...)
45#endif 45#endif
@@ -88,20 +88,20 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
88 dma_addr_t pos = prtd->dma_pos; 88 dma_addr_t pos = prtd->dma_pos;
89 int ret; 89 int ret;
90 90
91 DBG("Entered %s\n", __FUNCTION__); 91 DBG("Entered %s\n", __func__);
92 92
93 while (prtd->dma_loaded < prtd->dma_limit) { 93 while (prtd->dma_loaded < prtd->dma_limit) {
94 unsigned long len = prtd->dma_period; 94 unsigned long len = prtd->dma_period;
95 95
96 DBG("dma_loaded: %d\n",prtd->dma_loaded); 96 DBG("dma_loaded: %d\n", prtd->dma_loaded);
97 97
98 if ((pos + len) > prtd->dma_end) { 98 if ((pos + len) > prtd->dma_end) {
99 len = prtd->dma_end - pos; 99 len = prtd->dma_end - pos;
100 DBG(KERN_DEBUG "%s: corrected dma len %ld\n", 100 DBG(KERN_DEBUG "%s: corrected dma len %ld\n",
101 __FUNCTION__, len); 101 __func__, len);
102 } 102 }
103 103
104 ret = s3c2410_dma_enqueue(prtd->params->channel, 104 ret = s3c2410_dma_enqueue(prtd->params->channel,
105 substream, pos, len); 105 substream, pos, len);
106 106
107 if (ret == 0) { 107 if (ret == 0) {
@@ -123,13 +123,13 @@ static void s3c24xx_audio_buffdone(struct s3c2410_dma_chan *channel,
123 struct snd_pcm_substream *substream = dev_id; 123 struct snd_pcm_substream *substream = dev_id;
124 struct s3c24xx_runtime_data *prtd; 124 struct s3c24xx_runtime_data *prtd;
125 125
126 DBG("Entered %s\n", __FUNCTION__); 126 DBG("Entered %s\n", __func__);
127 127
128 if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR) 128 if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR)
129 return; 129 return;
130 130
131 prtd = substream->runtime->private_data; 131 prtd = substream->runtime->private_data;
132 132
133 if (substream) 133 if (substream)
134 snd_pcm_period_elapsed(substream); 134 snd_pcm_period_elapsed(substream);
135 135
@@ -150,9 +150,9 @@ static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream,
150 struct snd_soc_pcm_runtime *rtd = substream->private_data; 150 struct snd_soc_pcm_runtime *rtd = substream->private_data;
151 struct s3c24xx_pcm_dma_params *dma = rtd->dai->cpu_dai->dma_data; 151 struct s3c24xx_pcm_dma_params *dma = rtd->dai->cpu_dai->dma_data;
152 unsigned long totbytes = params_buffer_bytes(params); 152 unsigned long totbytes = params_buffer_bytes(params);
153 int ret=0; 153 int ret = 0;
154 154
155 DBG("Entered %s\n", __FUNCTION__); 155 DBG("Entered %s\n", __func__);
156 156
157 /* return if this is a bufferless transfer e.g. 157 /* return if this is a bufferless transfer e.g.
158 * codec <--> BT codec or GSM modem -- lg FIXME */ 158 * codec <--> BT codec or GSM modem -- lg FIXME */
@@ -200,7 +200,7 @@ static int s3c24xx_pcm_hw_free(struct snd_pcm_substream *substream)
200{ 200{
201 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 201 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
202 202
203 DBG("Entered %s\n", __FUNCTION__); 203 DBG("Entered %s\n", __func__);
204 204
205 /* TODO - do we need to ensure DMA flushed */ 205 /* TODO - do we need to ensure DMA flushed */
206 snd_pcm_set_runtime_buffer(substream, NULL); 206 snd_pcm_set_runtime_buffer(substream, NULL);
@@ -218,12 +218,12 @@ static int s3c24xx_pcm_prepare(struct snd_pcm_substream *substream)
218 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 218 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
219 int ret = 0; 219 int ret = 0;
220 220
221 DBG("Entered %s\n", __FUNCTION__); 221 DBG("Entered %s\n", __func__);
222 222
223 /* return if this is a bufferless transfer e.g. 223 /* return if this is a bufferless transfer e.g.
224 * codec <--> BT codec or GSM modem -- lg FIXME */ 224 * codec <--> BT codec or GSM modem -- lg FIXME */
225 if (!prtd->params) 225 if (!prtd->params)
226 return 0; 226 return 0;
227 227
228 /* channel needs configuring for mem=>device, increment memory addr, 228 /* channel needs configuring for mem=>device, increment memory addr,
229 * sync to pclk, half-word transfers to the IIS-FIFO. */ 229 * sync to pclk, half-word transfers to the IIS-FIFO. */
@@ -263,7 +263,7 @@ static int s3c24xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
263 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 263 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
264 int ret = 0; 264 int ret = 0;
265 265
266 DBG("Entered %s\n", __FUNCTION__); 266 DBG("Entered %s\n", __func__);
267 267
268 spin_lock(&prtd->lock); 268 spin_lock(&prtd->lock);
269 269
@@ -293,15 +293,15 @@ static int s3c24xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
293 return ret; 293 return ret;
294} 294}
295 295
296static snd_pcm_uframes_t 296static snd_pcm_uframes_t
297 s3c24xx_pcm_pointer(struct snd_pcm_substream *substream) 297s3c24xx_pcm_pointer(struct snd_pcm_substream *substream)
298{ 298{
299 struct snd_pcm_runtime *runtime = substream->runtime; 299 struct snd_pcm_runtime *runtime = substream->runtime;
300 struct s3c24xx_runtime_data *prtd = runtime->private_data; 300 struct s3c24xx_runtime_data *prtd = runtime->private_data;
301 unsigned long res; 301 unsigned long res;
302 dma_addr_t src, dst; 302 dma_addr_t src, dst;
303 303
304 DBG("Entered %s\n", __FUNCTION__); 304 DBG("Entered %s\n", __func__);
305 305
306 spin_lock(&prtd->lock); 306 spin_lock(&prtd->lock);
307 s3c2410_dma_getposition(prtd->params->channel, &src, &dst); 307 s3c2410_dma_getposition(prtd->params->channel, &src, &dst);
@@ -313,7 +313,7 @@ static snd_pcm_uframes_t
313 313
314 spin_unlock(&prtd->lock); 314 spin_unlock(&prtd->lock);
315 315
316 DBG("Pointer %x %x\n",src,dst); 316 DBG("Pointer %x %x\n", src, dst);
317 317
318 /* we seem to be getting the odd error from the pcm library due 318 /* we seem to be getting the odd error from the pcm library due
319 * to out-of-bounds pointers. this is maybe due to the dma engine 319 * to out-of-bounds pointers. this is maybe due to the dma engine
@@ -334,7 +334,7 @@ static int s3c24xx_pcm_open(struct snd_pcm_substream *substream)
334 struct snd_pcm_runtime *runtime = substream->runtime; 334 struct snd_pcm_runtime *runtime = substream->runtime;
335 struct s3c24xx_runtime_data *prtd; 335 struct s3c24xx_runtime_data *prtd;
336 336
337 DBG("Entered %s\n", __FUNCTION__); 337 DBG("Entered %s\n", __func__);
338 338
339 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware); 339 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware);
340 340
@@ -353,13 +353,13 @@ static int s3c24xx_pcm_close(struct snd_pcm_substream *substream)
353 struct snd_pcm_runtime *runtime = substream->runtime; 353 struct snd_pcm_runtime *runtime = substream->runtime;
354 struct s3c24xx_runtime_data *prtd = runtime->private_data; 354 struct s3c24xx_runtime_data *prtd = runtime->private_data;
355 355
356 DBG("Entered %s\n", __FUNCTION__); 356 DBG("Entered %s\n", __func__);
357 357
358 if (prtd) 358 if (!prtd)
359 kfree(prtd);
360 else
361 DBG("s3c24xx_pcm_close called with prtd == NULL\n"); 359 DBG("s3c24xx_pcm_close called with prtd == NULL\n");
362 360
361 kfree(prtd);
362
363 return 0; 363 return 0;
364} 364}
365 365
@@ -368,12 +368,12 @@ static int s3c24xx_pcm_mmap(struct snd_pcm_substream *substream,
368{ 368{
369 struct snd_pcm_runtime *runtime = substream->runtime; 369 struct snd_pcm_runtime *runtime = substream->runtime;
370 370
371 DBG("Entered %s\n", __FUNCTION__); 371 DBG("Entered %s\n", __func__);
372 372
373 return dma_mmap_writecombine(substream->pcm->card->dev, vma, 373 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
374 runtime->dma_area, 374 runtime->dma_area,
375 runtime->dma_addr, 375 runtime->dma_addr,
376 runtime->dma_bytes); 376 runtime->dma_bytes);
377} 377}
378 378
379static struct snd_pcm_ops s3c24xx_pcm_ops = { 379static struct snd_pcm_ops s3c24xx_pcm_ops = {
@@ -394,7 +394,7 @@ static int s3c24xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
394 struct snd_dma_buffer *buf = &substream->dma_buffer; 394 struct snd_dma_buffer *buf = &substream->dma_buffer;
395 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max; 395 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max;
396 396
397 DBG("Entered %s\n", __FUNCTION__); 397 DBG("Entered %s\n", __func__);
398 398
399 buf->dev.type = SNDRV_DMA_TYPE_DEV; 399 buf->dev.type = SNDRV_DMA_TYPE_DEV;
400 buf->dev.dev = pcm->card->dev; 400 buf->dev.dev = pcm->card->dev;
@@ -413,7 +413,7 @@ static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
413 struct snd_dma_buffer *buf; 413 struct snd_dma_buffer *buf;
414 int stream; 414 int stream;
415 415
416 DBG("Entered %s\n", __FUNCTION__); 416 DBG("Entered %s\n", __func__);
417 417
418 for (stream = 0; stream < 2; stream++) { 418 for (stream = 0; stream < 2; stream++) {
419 substream = pcm->streams[stream].substream; 419 substream = pcm->streams[stream].substream;
@@ -432,12 +432,12 @@ static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
432 432
433static u64 s3c24xx_pcm_dmamask = DMA_32BIT_MASK; 433static u64 s3c24xx_pcm_dmamask = DMA_32BIT_MASK;
434 434
435static int s3c24xx_pcm_new(struct snd_card *card, 435static int s3c24xx_pcm_new(struct snd_card *card,
436 struct snd_soc_codec_dai *dai, struct snd_pcm *pcm) 436 struct snd_soc_codec_dai *dai, struct snd_pcm *pcm)
437{ 437{
438 int ret = 0; 438 int ret = 0;
439 439
440 DBG("Entered %s\n", __FUNCTION__); 440 DBG("Entered %s\n", __func__);
441 441
442 if (!card->dev->dma_mask) 442 if (!card->dev->dma_mask)
443 card->dev->dma_mask = &s3c24xx_pcm_dmamask; 443 card->dev->dma_mask = &s3c24xx_pcm_dmamask;
@@ -467,7 +467,6 @@ struct snd_soc_platform s3c24xx_soc_platform = {
467 .pcm_new = s3c24xx_pcm_new, 467 .pcm_new = s3c24xx_pcm_new,
468 .pcm_free = s3c24xx_pcm_free_dma_buffers, 468 .pcm_free = s3c24xx_pcm_free_dma_buffers,
469}; 469};
470
471EXPORT_SYMBOL_GPL(s3c24xx_soc_platform); 470EXPORT_SYMBOL_GPL(s3c24xx_soc_platform);
472 471
473MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 472MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index f03220d23e73..4c1e013381c9 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -1,4 +1,5 @@
1menu "SoC Audio support for SuperH" 1menu "SoC Audio support for SuperH"
2 depends on SUPERH
2 3
3config SND_SOC_PCM_SH7760 4config SND_SOC_PCM_SH7760
4 tristate "SoC Audio support for Renesas SH7760" 5 tristate "SoC Audio support for Renesas SH7760"
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 9eb5479787c1..e148db940cfc 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -839,6 +839,7 @@ static int soc_remove(struct platform_device *pdev)
839static struct platform_driver soc_driver = { 839static struct platform_driver soc_driver = {
840 .driver = { 840 .driver = {
841 .name = "soc-audio", 841 .name = "soc-audio",
842 .owner = THIS_MODULE,
842 }, 843 },
843 .probe = soc_probe, 844 .probe = soc_probe,
844 .remove = soc_remove, 845 .remove = soc_remove,
@@ -1601,3 +1602,4 @@ module_exit(snd_soc_exit);
1601MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); 1602MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1602MODULE_DESCRIPTION("ALSA SoC Core"); 1603MODULE_DESCRIPTION("ALSA SoC Core");
1603MODULE_LICENSE("GPL"); 1604MODULE_LICENSE("GPL");
1605MODULE_ALIAS("platform:soc-audio");
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 620d7ea3c15f..af3326c63504 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -226,7 +226,7 @@ static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
226 snd_soc_write(codec, widget->reg, new); 226 snd_soc_write(codec, widget->reg, new);
227 pop_wait(POP_TIME); 227 pop_wait(POP_TIME);
228 } 228 }
229 dbg("reg old %x new %x change %d\n", old, new, change); 229 dbg("reg %x old %x new %x change %d\n", widget->reg, old, new, change);
230 return change; 230 return change;
231} 231}
232 232
@@ -1288,7 +1288,7 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
1288 mutex_unlock(&codec->mutex); 1288 mutex_unlock(&codec->mutex);
1289 1289
1290 dapm_power_widgets(codec, event); 1290 dapm_power_widgets(codec, event);
1291 dump_dapm(codec, __FUNCTION__); 1291 dump_dapm(codec, __func__);
1292 return 0; 1292 return 0;
1293} 1293}
1294EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event); 1294EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
@@ -1334,10 +1334,11 @@ int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
1334 list_for_each_entry(w, &codec->dapm_widgets, list) { 1334 list_for_each_entry(w, &codec->dapm_widgets, list) {
1335 if (!strcmp(w->name, endpoint)) { 1335 if (!strcmp(w->name, endpoint)) {
1336 w->connected = status; 1336 w->connected = status;
1337 return 0;
1337 } 1338 }
1338 } 1339 }
1339 1340
1340 return 0; 1341 return -ENODEV;
1341} 1342}
1342EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint); 1343EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint);
1343 1344
diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 89d6e9c35140..09802e8a6fb8 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -118,7 +118,7 @@ static struct snd_pcm_hardware snd_at73c213_playback_hw = {
118 .rates = SNDRV_PCM_RATE_CONTINUOUS, 118 .rates = SNDRV_PCM_RATE_CONTINUOUS,
119 .rate_min = 8000, /* Replaced by chip->bitrate later. */ 119 .rate_min = 8000, /* Replaced by chip->bitrate later. */
120 .rate_max = 50000, /* Replaced by chip->bitrate later. */ 120 .rate_max = 50000, /* Replaced by chip->bitrate later. */
121 .channels_min = 2, 121 .channels_min = 1,
122 .channels_max = 2, 122 .channels_max = 2,
123 .buffer_bytes_max = 64 * 1024 - 1, 123 .buffer_bytes_max = 64 * 1024 - 1,
124 .period_bytes_min = 512, 124 .period_bytes_min = 512,
@@ -133,7 +133,8 @@ static struct snd_pcm_hardware snd_at73c213_playback_hw = {
133static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip) 133static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
134{ 134{
135 unsigned long ssc_rate = clk_get_rate(chip->ssc->clk); 135 unsigned long ssc_rate = clk_get_rate(chip->ssc->clk);
136 unsigned long dac_rate_new, ssc_div, status; 136 unsigned long dac_rate_new, ssc_div;
137 int status;
137 unsigned long ssc_div_max, ssc_div_min; 138 unsigned long ssc_div_max, ssc_div_min;
138 int max_tries; 139 int max_tries;
139 140
@@ -209,7 +210,13 @@ static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
209{ 210{
210 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream); 211 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
211 struct snd_pcm_runtime *runtime = substream->runtime; 212 struct snd_pcm_runtime *runtime = substream->runtime;
213 int err;
212 214
215 /* ensure buffer_size is a multiple of period_size */
216 err = snd_pcm_hw_constraint_integer(runtime,
217 SNDRV_PCM_HW_PARAM_PERIODS);
218 if (err < 0)
219 return err;
213 snd_at73c213_playback_hw.rate_min = chip->bitrate; 220 snd_at73c213_playback_hw.rate_min = chip->bitrate;
214 snd_at73c213_playback_hw.rate_max = chip->bitrate; 221 snd_at73c213_playback_hw.rate_max = chip->bitrate;
215 runtime->hw = snd_at73c213_playback_hw; 222 runtime->hw = snd_at73c213_playback_hw;
@@ -228,6 +235,14 @@ static int snd_at73c213_pcm_close(struct snd_pcm_substream *substream)
228static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream, 235static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream,
229 struct snd_pcm_hw_params *hw_params) 236 struct snd_pcm_hw_params *hw_params)
230{ 237{
238 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
239 int channels = params_channels(hw_params);
240 int val;
241
242 val = ssc_readl(chip->ssc->regs, TFMR);
243 val = SSC_BFINS(TFMR_DATNB, channels - 1, val);
244 ssc_writel(chip->ssc->regs, TFMR, val);
245
231 return snd_pcm_lib_malloc_pages(substream, 246 return snd_pcm_lib_malloc_pages(substream,
232 params_buffer_bytes(hw_params)); 247 params_buffer_bytes(hw_params));
233} 248}
@@ -249,10 +264,12 @@ static int snd_at73c213_pcm_prepare(struct snd_pcm_substream *substream)
249 264
250 ssc_writel(chip->ssc->regs, PDC_TPR, 265 ssc_writel(chip->ssc->regs, PDC_TPR,
251 (long)runtime->dma_addr); 266 (long)runtime->dma_addr);
252 ssc_writel(chip->ssc->regs, PDC_TCR, runtime->period_size * 2); 267 ssc_writel(chip->ssc->regs, PDC_TCR,
268 runtime->period_size * runtime->channels);
253 ssc_writel(chip->ssc->regs, PDC_TNPR, 269 ssc_writel(chip->ssc->regs, PDC_TNPR,
254 (long)runtime->dma_addr + block_size); 270 (long)runtime->dma_addr + block_size);
255 ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2); 271 ssc_writel(chip->ssc->regs, PDC_TNCR,
272 runtime->period_size * runtime->channels);
256 273
257 return 0; 274 return 0;
258} 275}
@@ -314,15 +331,6 @@ static struct snd_pcm_ops at73c213_playback_ops = {
314 .pointer = snd_at73c213_pcm_pointer, 331 .pointer = snd_at73c213_pcm_pointer,
315}; 332};
316 333
317static void snd_at73c213_pcm_free(struct snd_pcm *pcm)
318{
319 struct snd_at73c213 *chip = snd_pcm_chip(pcm);
320 if (chip->pcm) {
321 snd_pcm_lib_preallocate_free_for_all(chip->pcm);
322 chip->pcm = NULL;
323 }
324}
325
326static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device) 334static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
327{ 335{
328 struct snd_pcm *pcm; 336 struct snd_pcm *pcm;
@@ -334,7 +342,6 @@ static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
334 goto out; 342 goto out;
335 343
336 pcm->private_data = chip; 344 pcm->private_data = chip;
337 pcm->private_free = snd_at73c213_pcm_free;
338 pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER; 345 pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER;
339 strcpy(pcm->name, "at73c213"); 346 strcpy(pcm->name, "at73c213");
340 chip->pcm = pcm; 347 chip->pcm = pcm;
@@ -375,7 +382,8 @@ static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
375 382
376 ssc_writel(chip->ssc->regs, PDC_TNPR, 383 ssc_writel(chip->ssc->regs, PDC_TNPR,
377 (long)runtime->dma_addr + offset); 384 (long)runtime->dma_addr + offset);
378 ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2); 385 ssc_writel(chip->ssc->regs, PDC_TNCR,
386 runtime->period_size * runtime->channels);
379 retval = IRQ_HANDLED; 387 retval = IRQ_HANDLED;
380 } 388 }
381 389
@@ -737,7 +745,7 @@ cleanup:
737/* 745/*
738 * Device functions 746 * Device functions
739 */ 747 */
740static int snd_at73c213_ssc_init(struct snd_at73c213 *chip) 748static int __devinit snd_at73c213_ssc_init(struct snd_at73c213 *chip)
741{ 749{
742 /* 750 /*
743 * Continuous clock output. 751 * Continuous clock output.
@@ -767,7 +775,7 @@ static int snd_at73c213_ssc_init(struct snd_at73c213 *chip)
767 return 0; 775 return 0;
768} 776}
769 777
770static int snd_at73c213_chip_init(struct snd_at73c213 *chip) 778static int __devinit snd_at73c213_chip_init(struct snd_at73c213 *chip)
771{ 779{
772 int retval; 780 int retval;
773 unsigned char dac_ctrl = 0; 781 unsigned char dac_ctrl = 0;
@@ -933,7 +941,7 @@ out:
933 return retval; 941 return retval;
934} 942}
935 943
936static int snd_at73c213_probe(struct spi_device *spi) 944static int __devinit snd_at73c213_probe(struct spi_device *spi)
937{ 945{
938 struct snd_card *card; 946 struct snd_card *card;
939 struct snd_at73c213 *chip; 947 struct snd_at73c213 *chip;
diff --git a/sound/usb/caiaq/caiaq-audio.c b/sound/usb/caiaq/caiaq-audio.c
index 9cc4cd8283f9..24970a5c888f 100644
--- a/sound/usb/caiaq/caiaq-audio.c
+++ b/sound/usb/caiaq/caiaq-audio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006,2007 Daniel Mack, Karsten Wiese 2 * Copyright (c) 2006-2008 Daniel Mack, Karsten Wiese
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
@@ -39,7 +39,8 @@
39#define BYTES_PER_SAMPLE 3 39#define BYTES_PER_SAMPLE 3
40#define BYTES_PER_SAMPLE_USB 4 40#define BYTES_PER_SAMPLE_USB 4
41#define MAX_BUFFER_SIZE (128*1024) 41#define MAX_BUFFER_SIZE (128*1024)
42 42#define MAX_ENDPOINT_SIZE 512
43
43#define ENDPOINT_CAPTURE 2 44#define ENDPOINT_CAPTURE 2
44#define ENDPOINT_PLAYBACK 6 45#define ENDPOINT_PLAYBACK 6
45 46
@@ -77,10 +78,15 @@ static void
77deactivate_substream(struct snd_usb_caiaqdev *dev, 78deactivate_substream(struct snd_usb_caiaqdev *dev,
78 struct snd_pcm_substream *sub) 79 struct snd_pcm_substream *sub)
79{ 80{
81 unsigned long flags;
82 spin_lock_irqsave(&dev->spinlock, flags);
83
80 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 84 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
81 dev->sub_playback[sub->number] = NULL; 85 dev->sub_playback[sub->number] = NULL;
82 else 86 else
83 dev->sub_capture[sub->number] = NULL; 87 dev->sub_capture[sub->number] = NULL;
88
89 spin_unlock_irqrestore(&dev->spinlock, flags);
84} 90}
85 91
86static int 92static int
@@ -97,13 +103,13 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
97{ 103{
98 int i, ret; 104 int i, ret;
99 105
100 debug("stream_start(%p)\n", dev); 106 debug("%s(%p)\n", __func__, dev);
101 spin_lock_irq(&dev->spinlock); 107
102 if (dev->streaming) { 108 if (dev->streaming)
103 spin_unlock_irq(&dev->spinlock);
104 return -EINVAL; 109 return -EINVAL;
105 }
106 110
111 memset(dev->sub_playback, 0, sizeof(dev->sub_playback));
112 memset(dev->sub_capture, 0, sizeof(dev->sub_capture));
107 dev->input_panic = 0; 113 dev->input_panic = 0;
108 dev->output_panic = 0; 114 dev->output_panic = 0;
109 dev->first_packet = 1; 115 dev->first_packet = 1;
@@ -112,37 +118,35 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
112 for (i = 0; i < N_URBS; i++) { 118 for (i = 0; i < N_URBS; i++) {
113 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC); 119 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC);
114 if (ret) { 120 if (ret) {
115 log("unable to trigger initial read #%d! (ret = %d)\n", 121 log("unable to trigger read #%d! (ret %d)\n", i, ret);
116 i, ret);
117 dev->streaming = 0; 122 dev->streaming = 0;
118 spin_unlock_irq(&dev->spinlock);
119 return -EPIPE; 123 return -EPIPE;
120 } 124 }
121 } 125 }
122 126
123 spin_unlock_irq(&dev->spinlock);
124 return 0; 127 return 0;
125} 128}
126 129
127static void stream_stop(struct snd_usb_caiaqdev *dev) 130static void stream_stop(struct snd_usb_caiaqdev *dev)
128{ 131{
129 int i; 132 int i;
130 133
131 debug("stream_stop(%p)\n", dev); 134 debug("%s(%p)\n", __func__, dev);
132 if (!dev->streaming) 135 if (!dev->streaming)
133 return; 136 return;
134 137
135 dev->streaming = 0; 138 dev->streaming = 0;
139
136 for (i = 0; i < N_URBS; i++) { 140 for (i = 0; i < N_URBS; i++) {
137 usb_unlink_urb(dev->data_urbs_in[i]); 141 usb_kill_urb(dev->data_urbs_in[i]);
138 usb_unlink_urb(dev->data_urbs_out[i]); 142 usb_kill_urb(dev->data_urbs_out[i]);
139 } 143 }
140} 144}
141 145
142static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream) 146static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
143{ 147{
144 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 148 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
145 debug("snd_usb_caiaq_substream_open(%p)\n", substream); 149 debug("%s(%p)\n", __func__, substream);
146 substream->runtime->hw = dev->pcm_info; 150 substream->runtime->hw = dev->pcm_info;
147 snd_pcm_limit_hw_rates(substream->runtime); 151 snd_pcm_limit_hw_rates(substream->runtime);
148 return 0; 152 return 0;
@@ -152,7 +156,7 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
152{ 156{
153 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 157 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
154 158
155 debug("snd_usb_caiaq_substream_close(%p)\n", substream); 159 debug("%s(%p)\n", __func__, substream);
156 if (all_substreams_zero(dev->sub_playback) && 160 if (all_substreams_zero(dev->sub_playback) &&
157 all_substreams_zero(dev->sub_capture)) { 161 all_substreams_zero(dev->sub_capture)) {
158 /* when the last client has stopped streaming, 162 /* when the last client has stopped streaming,
@@ -160,24 +164,22 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
160 stream_stop(dev); 164 stream_stop(dev);
161 dev->pcm_info.rates = dev->samplerates; 165 dev->pcm_info.rates = dev->samplerates;
162 } 166 }
163 167
164 return 0; 168 return 0;
165} 169}
166 170
167static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub, 171static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub,
168 struct snd_pcm_hw_params *hw_params) 172 struct snd_pcm_hw_params *hw_params)
169{ 173{
170 debug("snd_usb_caiaq_pcm_hw_params(%p)\n", sub); 174 debug("%s(%p)\n", __func__, sub);
171 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params)); 175 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params));
172} 176}
173 177
174static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub) 178static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
175{ 179{
176 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 180 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
177 debug("snd_usb_caiaq_pcm_hw_free(%p)\n", sub); 181 debug("%s(%p)\n", __func__, sub);
178 spin_lock_irq(&dev->spinlock);
179 deactivate_substream(dev, sub); 182 deactivate_substream(dev, sub);
180 spin_unlock_irq(&dev->spinlock);
181 return snd_pcm_lib_free_pages(sub); 183 return snd_pcm_lib_free_pages(sub);
182} 184}
183 185
@@ -196,12 +198,12 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
196 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 198 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
197 struct snd_pcm_runtime *runtime = substream->runtime; 199 struct snd_pcm_runtime *runtime = substream->runtime;
198 200
199 debug("snd_usb_caiaq_pcm_prepare(%p)\n", substream); 201 debug("%s(%p)\n", __func__, substream);
200 202
201 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 203 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
202 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1; 204 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1;
203 else 205 else
204 dev->audio_in_buf_pos[index] = 0; 206 dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE;
205 207
206 if (dev->streaming) 208 if (dev->streaming)
207 return 0; 209 return 0;
@@ -220,7 +222,10 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
220 222
221 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE) 223 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
222 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams; 224 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams;
223 225
226 if (bpp > MAX_ENDPOINT_SIZE)
227 bpp = MAX_ENDPOINT_SIZE;
228
224 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate, 229 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate,
225 runtime->sample_bits, bpp); 230 runtime->sample_bits, bpp);
226 if (ret) 231 if (ret)
@@ -247,15 +252,11 @@ static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
247 switch (cmd) { 252 switch (cmd) {
248 case SNDRV_PCM_TRIGGER_START: 253 case SNDRV_PCM_TRIGGER_START:
249 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 254 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
250 spin_lock(&dev->spinlock);
251 activate_substream(dev, sub); 255 activate_substream(dev, sub);
252 spin_unlock(&dev->spinlock);
253 break; 256 break;
254 case SNDRV_PCM_TRIGGER_STOP: 257 case SNDRV_PCM_TRIGGER_STOP:
255 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 258 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
256 spin_lock(&dev->spinlock);
257 deactivate_substream(dev, sub); 259 deactivate_substream(dev, sub);
258 spin_unlock(&dev->spinlock);
259 break; 260 break;
260 default: 261 default:
261 return -EINVAL; 262 return -EINVAL;
@@ -328,8 +329,6 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
328 if (all_substreams_zero(dev->sub_capture)) 329 if (all_substreams_zero(dev->sub_capture))
329 return; 330 return;
330 331
331 spin_lock(&dev->spinlock);
332
333 for (i = 0; i < iso->actual_length;) { 332 for (i = 0; i < iso->actual_length;) {
334 for (stream = 0; stream < dev->n_streams; stream++, i++) { 333 for (stream = 0; stream < dev->n_streams; stream++, i++) {
335 sub = dev->sub_capture[stream]; 334 sub = dev->sub_capture[stream];
@@ -345,8 +344,6 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
345 } 344 }
346 } 345 }
347 } 346 }
348
349 spin_unlock(&dev->spinlock);
350} 347}
351 348
352static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev, 349static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
@@ -358,8 +355,6 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
358 struct snd_pcm_substream *sub; 355 struct snd_pcm_substream *sub;
359 int stream, i; 356 int stream, i;
360 357
361 spin_lock(&dev->spinlock);
362
363 for (i = 0; i < iso->actual_length;) { 358 for (i = 0; i < iso->actual_length;) {
364 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) { 359 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
365 for (stream = 0; 360 for (stream = 0;
@@ -393,8 +388,6 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
393 } 388 }
394 } 389 }
395 } 390 }
396
397 spin_unlock(&dev->spinlock);
398} 391}
399 392
400static void read_in_urb(struct snd_usb_caiaqdev *dev, 393static void read_in_urb(struct snd_usb_caiaqdev *dev,
@@ -418,8 +411,6 @@ static void read_in_urb(struct snd_usb_caiaqdev *dev,
418 dev->input_panic ? "(input)" : "", 411 dev->input_panic ? "(input)" : "",
419 dev->output_panic ? "(output)" : ""); 412 dev->output_panic ? "(output)" : "");
420 } 413 }
421
422 check_for_elapsed_periods(dev, dev->sub_capture);
423} 414}
424 415
425static void fill_out_urb(struct snd_usb_caiaqdev *dev, 416static void fill_out_urb(struct snd_usb_caiaqdev *dev,
@@ -429,8 +420,6 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
429 unsigned char *usb_buf = urb->transfer_buffer + iso->offset; 420 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
430 struct snd_pcm_substream *sub; 421 struct snd_pcm_substream *sub;
431 int stream, i; 422 int stream, i;
432
433 spin_lock(&dev->spinlock);
434 423
435 for (i = 0; i < iso->length;) { 424 for (i = 0; i < iso->length;) {
436 for (stream = 0; stream < dev->n_streams; stream++, i++) { 425 for (stream = 0; stream < dev->n_streams; stream++, i++) {
@@ -456,9 +445,6 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
456 for (stream = 0; stream < dev->n_streams; stream++, i++) 445 for (stream = 0; stream < dev->n_streams; stream++, i++)
457 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i); 446 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i);
458 } 447 }
459
460 spin_unlock(&dev->spinlock);
461 check_for_elapsed_periods(dev, dev->sub_playback);
462} 448}
463 449
464static void read_completed(struct urb *urb) 450static void read_completed(struct urb *urb)
@@ -472,6 +458,7 @@ static void read_completed(struct urb *urb)
472 return; 458 return;
473 459
474 dev = info->dev; 460 dev = info->dev;
461
475 if (!dev->streaming) 462 if (!dev->streaming)
476 return; 463 return;
477 464
@@ -489,8 +476,12 @@ static void read_completed(struct urb *urb)
489 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame; 476 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame;
490 477
491 if (len > 0) { 478 if (len > 0) {
479 spin_lock(&dev->spinlock);
492 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]); 480 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]);
493 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]); 481 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]);
482 spin_unlock(&dev->spinlock);
483 check_for_elapsed_periods(dev, dev->sub_playback);
484 check_for_elapsed_periods(dev, dev->sub_capture);
494 send_it = 1; 485 send_it = 1;
495 } 486 }
496 487
@@ -696,7 +687,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
696 687
697void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev) 688void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev)
698{ 689{
699 debug("snd_usb_caiaq_audio_free (%p)\n", dev); 690 debug("%s(%p)\n", __func__, dev);
700 stream_stop(dev); 691 stream_stop(dev);
701 free_urbs(dev->data_urbs_in); 692 free_urbs(dev->data_urbs_in);
702 free_urbs(dev->data_urbs_out); 693 free_urbs(dev->data_urbs_out);
diff --git a/sound/usb/caiaq/caiaq-device.c b/sound/usb/caiaq/caiaq-device.c
index 7c44a2c7f963..e97d8b2ac16a 100644
--- a/sound/usb/caiaq/caiaq-device.c
+++ b/sound/usb/caiaq/caiaq-device.c
@@ -42,7 +42,7 @@
42#endif 42#endif
43 43
44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.2"); 45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.6");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
48 "{Native Instruments, RigKontrol3}," 48 "{Native Instruments, RigKontrol3},"
@@ -456,7 +456,7 @@ static void snd_disconnect(struct usb_interface *intf)
456 struct snd_usb_caiaqdev *dev; 456 struct snd_usb_caiaqdev *dev;
457 struct snd_card *card = dev_get_drvdata(&intf->dev); 457 struct snd_card *card = dev_get_drvdata(&intf->dev);
458 458
459 debug("snd_disconnect(%p)\n", intf); 459 debug("%s(%p)\n", __func__, intf);
460 460
461 if (!card) 461 if (!card)
462 return; 462 return;
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index f48838a078cb..410be4aff1ba 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -64,9 +64,10 @@ MODULE_SUPPORTED_DEVICE("{{Generic,USB Audio}}");
64 64
65static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 65static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
66static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 66static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
67static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 67static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
68static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; /* Vendor ID for this card */ 68/* Vendor/product IDs for this card */
69static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; /* Product ID for this card */ 69static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
70static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
70static int nrpacks = 8; /* max. number of packets per urb */ 71static int nrpacks = 8; /* max. number of packets per urb */
71static int async_unlink = 1; 72static int async_unlink = 1;
72static int device_setup[SNDRV_CARDS]; /* device parameter for this card*/ 73static int device_setup[SNDRV_CARDS]; /* device parameter for this card*/
@@ -687,7 +688,7 @@ static void snd_complete_urb(struct urb *urb)
687 int err = 0; 688 int err = 0;
688 689
689 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) || 690 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
690 ! subs->running || /* can be stopped during retire callback */ 691 !subs->running || /* can be stopped during retire callback */
691 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 || 692 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
692 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 693 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
693 clear_bit(ctx->index, &subs->active_mask); 694 clear_bit(ctx->index, &subs->active_mask);
@@ -710,7 +711,7 @@ static void snd_complete_sync_urb(struct urb *urb)
710 int err = 0; 711 int err = 0;
711 712
712 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) || 713 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
713 ! subs->running || /* can be stopped during retire callback */ 714 !subs->running || /* can be stopped during retire callback */
714 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 || 715 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
715 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 716 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
716 clear_bit(ctx->index + 16, &subs->active_mask); 717 clear_bit(ctx->index + 16, &subs->active_mask);
@@ -740,7 +741,7 @@ static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t s
740 vfree(runtime->dma_area); 741 vfree(runtime->dma_area);
741 } 742 }
742 runtime->dma_area = vmalloc(size); 743 runtime->dma_area = vmalloc(size);
743 if (! runtime->dma_area) 744 if (!runtime->dma_area)
744 return -ENOMEM; 745 return -ENOMEM;
745 runtime->dma_bytes = size; 746 runtime->dma_bytes = size;
746 return 0; 747 return 0;
@@ -772,12 +773,12 @@ static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sl
772 773
773 async = !can_sleep && async_unlink; 774 async = !can_sleep && async_unlink;
774 775
775 if (! async && in_interrupt()) 776 if (!async && in_interrupt())
776 return 0; 777 return 0;
777 778
778 for (i = 0; i < subs->nurbs; i++) { 779 for (i = 0; i < subs->nurbs; i++) {
779 if (test_bit(i, &subs->active_mask)) { 780 if (test_bit(i, &subs->active_mask)) {
780 if (! test_and_set_bit(i, &subs->unlink_mask)) { 781 if (!test_and_set_bit(i, &subs->unlink_mask)) {
781 struct urb *u = subs->dataurb[i].urb; 782 struct urb *u = subs->dataurb[i].urb;
782 if (async) 783 if (async)
783 usb_unlink_urb(u); 784 usb_unlink_urb(u);
@@ -789,7 +790,7 @@ static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sl
789 if (subs->syncpipe) { 790 if (subs->syncpipe) {
790 for (i = 0; i < SYNC_URBS; i++) { 791 for (i = 0; i < SYNC_URBS; i++) {
791 if (test_bit(i+16, &subs->active_mask)) { 792 if (test_bit(i+16, &subs->active_mask)) {
792 if (! test_and_set_bit(i+16, &subs->unlink_mask)) { 793 if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
793 struct urb *u = subs->syncurb[i].urb; 794 struct urb *u = subs->syncurb[i].urb;
794 if (async) 795 if (async)
795 usb_unlink_urb(u); 796 usb_unlink_urb(u);
@@ -1137,12 +1138,12 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1137 if (subs->fmt_type == USB_FORMAT_TYPE_II) 1138 if (subs->fmt_type == USB_FORMAT_TYPE_II)
1138 u->packets++; /* for transfer delimiter */ 1139 u->packets++; /* for transfer delimiter */
1139 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); 1140 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
1140 if (! u->urb) 1141 if (!u->urb)
1141 goto out_of_memory; 1142 goto out_of_memory;
1142 u->urb->transfer_buffer = 1143 u->urb->transfer_buffer =
1143 usb_buffer_alloc(subs->dev, u->buffer_size, GFP_KERNEL, 1144 usb_buffer_alloc(subs->dev, u->buffer_size, GFP_KERNEL,
1144 &u->urb->transfer_dma); 1145 &u->urb->transfer_dma);
1145 if (! u->urb->transfer_buffer) 1146 if (!u->urb->transfer_buffer)
1146 goto out_of_memory; 1147 goto out_of_memory;
1147 u->urb->pipe = subs->datapipe; 1148 u->urb->pipe = subs->datapipe;
1148 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1149 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
@@ -1155,7 +1156,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1155 /* allocate and initialize sync urbs */ 1156 /* allocate and initialize sync urbs */
1156 subs->syncbuf = usb_buffer_alloc(subs->dev, SYNC_URBS * 4, 1157 subs->syncbuf = usb_buffer_alloc(subs->dev, SYNC_URBS * 4,
1157 GFP_KERNEL, &subs->sync_dma); 1158 GFP_KERNEL, &subs->sync_dma);
1158 if (! subs->syncbuf) 1159 if (!subs->syncbuf)
1159 goto out_of_memory; 1160 goto out_of_memory;
1160 for (i = 0; i < SYNC_URBS; i++) { 1161 for (i = 0; i < SYNC_URBS; i++) {
1161 struct snd_urb_ctx *u = &subs->syncurb[i]; 1162 struct snd_urb_ctx *u = &subs->syncurb[i];
@@ -1163,7 +1164,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1163 u->subs = subs; 1164 u->subs = subs;
1164 u->packets = 1; 1165 u->packets = 1;
1165 u->urb = usb_alloc_urb(1, GFP_KERNEL); 1166 u->urb = usb_alloc_urb(1, GFP_KERNEL);
1166 if (! u->urb) 1167 if (!u->urb)
1167 goto out_of_memory; 1168 goto out_of_memory;
1168 u->urb->transfer_buffer = subs->syncbuf + i * 4; 1169 u->urb->transfer_buffer = subs->syncbuf + i * 4;
1169 u->urb->transfer_dma = subs->sync_dma + i * 4; 1170 u->urb->transfer_dma = subs->sync_dma + i * 4;
@@ -1427,8 +1428,8 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
1427 subs->cur_audiofmt = fmt; 1428 subs->cur_audiofmt = fmt;
1428 1429
1429#if 0 1430#if 0
1430 printk("setting done: format = %d, rate = %d, channels = %d\n", 1431 printk("setting done: format = %d, rate = %d..%d, channels = %d\n",
1431 fmt->format, fmt->rate, fmt->channels); 1432 fmt->format, fmt->rate_min, fmt->rate_max, fmt->channels);
1432 printk(" datapipe = 0x%0x, syncpipe = 0x%0x\n", 1433 printk(" datapipe = 0x%0x, syncpipe = 0x%0x\n",
1433 subs->datapipe, subs->syncpipe); 1434 subs->datapipe, subs->syncpipe);
1434#endif 1435#endif
@@ -1463,7 +1464,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
1463 rate = params_rate(hw_params); 1464 rate = params_rate(hw_params);
1464 channels = params_channels(hw_params); 1465 channels = params_channels(hw_params);
1465 fmt = find_format(subs, format, rate, channels); 1466 fmt = find_format(subs, format, rate, channels);
1466 if (! fmt) { 1467 if (!fmt) {
1467 snd_printd(KERN_DEBUG "cannot set format: format = 0x%x, rate = %d, channels = %d\n", 1468 snd_printd(KERN_DEBUG "cannot set format: format = 0x%x, rate = %d, channels = %d\n",
1468 format, rate, channels); 1469 format, rate, channels);
1469 return -EINVAL; 1470 return -EINVAL;
@@ -1584,7 +1585,7 @@ static int hw_check_valid_format(struct snd_pcm_hw_params *params, struct audiof
1584 struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 1585 struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1585 1586
1586 /* check the format */ 1587 /* check the format */
1587 if (! snd_mask_test(fmts, fp->format)) { 1588 if (!snd_mask_test(fmts, fp->format)) {
1588 hwc_debug(" > check: no supported format %d\n", fp->format); 1589 hwc_debug(" > check: no supported format %d\n", fp->format);
1589 return 0; 1590 return 0;
1590 } 1591 }
@@ -1620,7 +1621,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
1620 list_for_each(p, &subs->fmt_list) { 1621 list_for_each(p, &subs->fmt_list) {
1621 struct audioformat *fp; 1622 struct audioformat *fp;
1622 fp = list_entry(p, struct audioformat, list); 1623 fp = list_entry(p, struct audioformat, list);
1623 if (! hw_check_valid_format(params, fp)) 1624 if (!hw_check_valid_format(params, fp))
1624 continue; 1625 continue;
1625 if (changed++) { 1626 if (changed++) {
1626 if (rmin > fp->rate_min) 1627 if (rmin > fp->rate_min)
@@ -1633,7 +1634,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
1633 } 1634 }
1634 } 1635 }
1635 1636
1636 if (! changed) { 1637 if (!changed) {
1637 hwc_debug(" --> get empty\n"); 1638 hwc_debug(" --> get empty\n");
1638 it->empty = 1; 1639 it->empty = 1;
1639 return -EINVAL; 1640 return -EINVAL;
@@ -1674,7 +1675,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
1674 list_for_each(p, &subs->fmt_list) { 1675 list_for_each(p, &subs->fmt_list) {
1675 struct audioformat *fp; 1676 struct audioformat *fp;
1676 fp = list_entry(p, struct audioformat, list); 1677 fp = list_entry(p, struct audioformat, list);
1677 if (! hw_check_valid_format(params, fp)) 1678 if (!hw_check_valid_format(params, fp))
1678 continue; 1679 continue;
1679 if (changed++) { 1680 if (changed++) {
1680 if (rmin > fp->channels) 1681 if (rmin > fp->channels)
@@ -1687,7 +1688,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
1687 } 1688 }
1688 } 1689 }
1689 1690
1690 if (! changed) { 1691 if (!changed) {
1691 hwc_debug(" --> get empty\n"); 1692 hwc_debug(" --> get empty\n");
1692 it->empty = 1; 1693 it->empty = 1;
1693 return -EINVAL; 1694 return -EINVAL;
@@ -1727,7 +1728,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
1727 list_for_each(p, &subs->fmt_list) { 1728 list_for_each(p, &subs->fmt_list) {
1728 struct audioformat *fp; 1729 struct audioformat *fp;
1729 fp = list_entry(p, struct audioformat, list); 1730 fp = list_entry(p, struct audioformat, list);
1730 if (! hw_check_valid_format(params, fp)) 1731 if (!hw_check_valid_format(params, fp))
1731 continue; 1732 continue;
1732 fbits |= (1ULL << fp->format); 1733 fbits |= (1ULL << fp->format);
1733 } 1734 }
@@ -1736,7 +1737,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
1736 oldbits[1] = fmt->bits[1]; 1737 oldbits[1] = fmt->bits[1];
1737 fmt->bits[0] &= (u32)fbits; 1738 fmt->bits[0] &= (u32)fbits;
1738 fmt->bits[1] &= (u32)(fbits >> 32); 1739 fmt->bits[1] &= (u32)(fbits >> 32);
1739 if (! fmt->bits[0] && ! fmt->bits[1]) { 1740 if (!fmt->bits[0] && !fmt->bits[1]) {
1740 hwc_debug(" --> get empty\n"); 1741 hwc_debug(" --> get empty\n");
1741 return -EINVAL; 1742 return -EINVAL;
1742 } 1743 }
@@ -1762,8 +1763,10 @@ static int check_hw_params_convention(struct snd_usb_substream *subs)
1762 1763
1763 channels = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL); 1764 channels = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL);
1764 rates = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL); 1765 rates = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL);
1765 if (!channels || !rates) 1766 if (!channels || !rates) {
1767 err = -ENOMEM;
1766 goto __out; 1768 goto __out;
1769 }
1767 1770
1768 list_for_each(p, &subs->fmt_list) { 1771 list_for_each(p, &subs->fmt_list) {
1769 struct audioformat *f; 1772 struct audioformat *f;
@@ -1916,7 +1919,10 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
1916 1000 * MIN_PACKS_URB, 1919 1000 * MIN_PACKS_URB,
1917 /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX); 1920 /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX);
1918 1921
1919 if (check_hw_params_convention(subs)) { 1922 err = check_hw_params_convention(subs);
1923 if (err < 0)
1924 return err;
1925 else if (err) {
1920 hwc_debug("setting extra hw constraints...\n"); 1926 hwc_debug("setting extra hw constraints...\n");
1921 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 1927 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1922 hw_rule_rate, subs, 1928 hw_rule_rate, subs,
@@ -2222,7 +2228,7 @@ static void proc_pcm_format_add(struct snd_usb_stream *stream)
2222 struct snd_card *card = stream->chip->card; 2228 struct snd_card *card = stream->chip->card;
2223 2229
2224 sprintf(name, "stream%d", stream->pcm_index); 2230 sprintf(name, "stream%d", stream->pcm_index);
2225 if (! snd_card_proc_new(card, name, &entry)) 2231 if (!snd_card_proc_new(card, name, &entry))
2226 snd_info_set_text_ops(entry, stream, proc_pcm_format_read); 2232 snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
2227} 2233}
2228 2234
@@ -2278,7 +2284,7 @@ static void free_substream(struct snd_usb_substream *subs)
2278{ 2284{
2279 struct list_head *p, *n; 2285 struct list_head *p, *n;
2280 2286
2281 if (! subs->num_formats) 2287 if (!subs->num_formats)
2282 return; /* not initialized */ 2288 return; /* not initialized */
2283 list_for_each_safe(p, n, &subs->fmt_list) { 2289 list_for_each_safe(p, n, &subs->fmt_list) {
2284 struct audioformat *fp = list_entry(p, struct audioformat, list); 2290 struct audioformat *fp = list_entry(p, struct audioformat, list);
@@ -2328,7 +2334,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud
2328 if (as->fmt_type != fp->fmt_type) 2334 if (as->fmt_type != fp->fmt_type)
2329 continue; 2335 continue;
2330 subs = &as->substream[stream]; 2336 subs = &as->substream[stream];
2331 if (! subs->endpoint) 2337 if (!subs->endpoint)
2332 continue; 2338 continue;
2333 if (subs->endpoint == fp->endpoint) { 2339 if (subs->endpoint == fp->endpoint) {
2334 list_add_tail(&fp->list, &subs->fmt_list); 2340 list_add_tail(&fp->list, &subs->fmt_list);
@@ -2354,7 +2360,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud
2354 2360
2355 /* create a new pcm */ 2361 /* create a new pcm */
2356 as = kzalloc(sizeof(*as), GFP_KERNEL); 2362 as = kzalloc(sizeof(*as), GFP_KERNEL);
2357 if (! as) 2363 if (!as)
2358 return -ENOMEM; 2364 return -ENOMEM;
2359 as->pcm_index = chip->pcm_devs; 2365 as->pcm_index = chip->pcm_devs;
2360 as->chip = chip; 2366 as->chip = chip;
@@ -2463,11 +2469,12 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2463 } 2469 }
2464 break; 2470 break;
2465 case USB_AUDIO_FORMAT_PCM8: 2471 case USB_AUDIO_FORMAT_PCM8:
2466 /* Dallas DS4201 workaround */ 2472 pcm_format = SNDRV_PCM_FORMAT_U8;
2473
2474 /* Dallas DS4201 workaround: it advertises U8 format, but really
2475 supports S8. */
2467 if (chip->usb_id == USB_ID(0x04fa, 0x4201)) 2476 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
2468 pcm_format = SNDRV_PCM_FORMAT_S8; 2477 pcm_format = SNDRV_PCM_FORMAT_S8;
2469 else
2470 pcm_format = SNDRV_PCM_FORMAT_U8;
2471 break; 2478 break;
2472 case USB_AUDIO_FORMAT_IEEE_FLOAT: 2479 case USB_AUDIO_FORMAT_IEEE_FLOAT:
2473 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE; 2480 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE;
@@ -2671,12 +2678,23 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2671 int format; 2678 int format;
2672 struct audioformat *fp; 2679 struct audioformat *fp;
2673 unsigned char *fmt, *csep; 2680 unsigned char *fmt, *csep;
2681 int num;
2674 2682
2675 dev = chip->dev; 2683 dev = chip->dev;
2676 2684
2677 /* parse the interface's altsettings */ 2685 /* parse the interface's altsettings */
2678 iface = usb_ifnum_to_if(dev, iface_no); 2686 iface = usb_ifnum_to_if(dev, iface_no);
2679 for (i = 0; i < iface->num_altsetting; i++) { 2687
2688 num = iface->num_altsetting;
2689
2690 /*
2691 * Dallas DS4201 workaround: It presents 5 altsettings, but the last
2692 * one misses syncpipe, and does not produce any sound.
2693 */
2694 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
2695 num = 4;
2696
2697 for (i = 0; i < num; i++) {
2680 alts = &iface->altsetting[i]; 2698 alts = &iface->altsetting[i];
2681 altsd = get_iface_desc(alts); 2699 altsd = get_iface_desc(alts);
2682 /* skip invalid one */ 2700 /* skip invalid one */
@@ -3375,14 +3393,14 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3375static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 3393static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3376{ 3394{
3377 struct snd_usb_audio *chip = entry->private_data; 3395 struct snd_usb_audio *chip = entry->private_data;
3378 if (! chip->shutdown) 3396 if (!chip->shutdown)
3379 snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum); 3397 snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
3380} 3398}
3381 3399
3382static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 3400static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3383{ 3401{
3384 struct snd_usb_audio *chip = entry->private_data; 3402 struct snd_usb_audio *chip = entry->private_data;
3385 if (! chip->shutdown) 3403 if (!chip->shutdown)
3386 snd_iprintf(buffer, "%04x:%04x\n", 3404 snd_iprintf(buffer, "%04x:%04x\n",
3387 USB_ID_VENDOR(chip->usb_id), 3405 USB_ID_VENDOR(chip->usb_id),
3388 USB_ID_PRODUCT(chip->usb_id)); 3406 USB_ID_PRODUCT(chip->usb_id));
@@ -3391,9 +3409,9 @@ static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_
3391static void snd_usb_audio_create_proc(struct snd_usb_audio *chip) 3409static void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
3392{ 3410{
3393 struct snd_info_entry *entry; 3411 struct snd_info_entry *entry;
3394 if (! snd_card_proc_new(chip->card, "usbbus", &entry)) 3412 if (!snd_card_proc_new(chip->card, "usbbus", &entry))
3395 snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read); 3413 snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
3396 if (! snd_card_proc_new(chip->card, "usbid", &entry)) 3414 if (!snd_card_proc_new(chip->card, "usbid", &entry))
3397 snd_info_set_text_ops(entry, chip, proc_audio_usbid_read); 3415 snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
3398} 3416}
3399 3417
@@ -3406,7 +3424,6 @@ static void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
3406 3424
3407static int snd_usb_audio_free(struct snd_usb_audio *chip) 3425static int snd_usb_audio_free(struct snd_usb_audio *chip)
3408{ 3426{
3409 usb_chip[chip->index] = NULL;
3410 kfree(chip); 3427 kfree(chip);
3411 return 0; 3428 return 0;
3412} 3429}
@@ -3600,8 +3617,8 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3600 snd_card_set_dev(chip->card, &intf->dev); 3617 snd_card_set_dev(chip->card, &intf->dev);
3601 break; 3618 break;
3602 } 3619 }
3603 if (! chip) { 3620 if (!chip) {
3604 snd_printk(KERN_ERR "no available usb audio device\n"); 3621 printk(KERN_ERR "no available usb audio device\n");
3605 goto __error; 3622 goto __error;
3606 } 3623 }
3607 } 3624 }
@@ -3671,6 +3688,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
3671 list_for_each(p, &chip->mixer_list) { 3688 list_for_each(p, &chip->mixer_list) {
3672 snd_usb_mixer_disconnect(p); 3689 snd_usb_mixer_disconnect(p);
3673 } 3690 }
3691 usb_chip[chip->index] = NULL;
3674 mutex_unlock(&register_mutex); 3692 mutex_unlock(&register_mutex);
3675 snd_card_free_when_closed(card); 3693 snd_card_free_when_closed(card);
3676 } else { 3694 } else {
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
index 938dff5f9cef..82a8d14c26af 100644
--- a/sound/usb/usbquirks.h
+++ b/sound/usb/usbquirks.h
@@ -39,6 +39,30 @@
39 .idProduct = prod, \ 39 .idProduct = prod, \
40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC 40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC
41 41
42/* Creative/E-Mu devices */
43{
44 USB_DEVICE(0x041e, 0x3010),
45 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
46 .vendor_name = "Creative Labs",
47 .product_name = "Sound Blaster MP3+",
48 .ifnum = QUIRK_NO_INTERFACE
49 }
50},
51{
52 /* E-Mu 0202 USB */
53 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
54 .idVendor = 0x041e,
55 .idProduct = 0x3f02,
56 .bInterfaceClass = USB_CLASS_AUDIO,
57},
58{
59 /* E-Mu 0404 USB */
60 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
61 .idVendor = 0x041e,
62 .idProduct = 0x3f04,
63 .bInterfaceClass = USB_CLASS_AUDIO,
64},
65
42/* 66/*
43 * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface 67 * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface
44 * class matches do not take effect without an explicit ID match. 68 * class matches do not take effect without an explicit ID match.
@@ -97,19 +121,7 @@
97 .bInterfaceClass = USB_CLASS_AUDIO, 121 .bInterfaceClass = USB_CLASS_AUDIO,
98 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 122 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL
99}, 123},
100/* E-Mu devices */ 124
101{
102 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
103 .idVendor = 0x041e,
104 .idProduct = 0x3f02,
105 .bInterfaceClass = USB_CLASS_AUDIO,
106},
107{
108 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
109 .idVendor = 0x041e,
110 .idProduct = 0x3f04,
111 .bInterfaceClass = USB_CLASS_AUDIO,
112},
113/* 125/*
114 * Yamaha devices 126 * Yamaha devices
115 */ 127 */
@@ -1165,19 +1177,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1165 } 1177 }
1166 } 1178 }
1167}, 1179},
1168{
1169 USB_DEVICE(0x582, 0x00a6),
1170 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1171 .vendor_name = "Roland",
1172 .product_name = "Juno-G",
1173 .ifnum = 0,
1174 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1175 .data = & (const struct snd_usb_midi_endpoint_info) {
1176 .out_cables = 0x0001,
1177 .in_cables = 0x0001
1178 }
1179 }
1180},
1181{ /* 1180{ /*
1182 * This quirk is for the "Advanced" modes of the Edirol UA-25. 1181 * This quirk is for the "Advanced" modes of the Edirol UA-25.
1183 * If the switch is not in an advanced setting, the UA-25 has 1182 * If the switch is not in an advanced setting, the UA-25 has
@@ -1336,6 +1335,19 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1336}, 1335},
1337 /* TODO: add Edirol MD-P1 support */ 1336 /* TODO: add Edirol MD-P1 support */
1338{ 1337{
1338 USB_DEVICE(0x582, 0x00a6),
1339 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1340 .vendor_name = "Roland",
1341 .product_name = "Juno-G",
1342 .ifnum = 0,
1343 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1344 .data = & (const struct snd_usb_midi_endpoint_info) {
1345 .out_cables = 0x0001,
1346 .in_cables = 0x0001
1347 }
1348 }
1349},
1350{
1339 /* Roland SH-201 */ 1351 /* Roland SH-201 */
1340 USB_DEVICE(0x0582, 0x00ad), 1352 USB_DEVICE(0x0582, 0x00ad),
1341 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 1353 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
@@ -1719,17 +1731,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1719 } 1731 }
1720}, 1732},
1721 1733
1722{
1723 /* Creative Sound Blaster MP3+ */
1724 USB_DEVICE(0x041e, 0x3010),
1725 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1726 .vendor_name = "Creative Labs",
1727 .product_name = "Sound Blaster MP3+",
1728 .ifnum = QUIRK_NO_INTERFACE
1729 }
1730
1731},
1732
1733/* Emagic devices */ 1734/* Emagic devices */
1734{ 1735{
1735 USB_DEVICE(0x086a, 0x0001), 1736 USB_DEVICE(0x086a, 0x0001),