aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/Kconfig6
-rw-r--r--sound/arm/Makefile2
-rw-r--r--sound/arm/aaci.c35
-rw-r--r--sound/arm/devdma.c80
-rw-r--r--sound/arm/devdma.h3
-rw-r--r--sound/core/control.c9
-rw-r--r--sound/core/isadma.c10
-rw-r--r--sound/core/oss/mixer_oss.c4
-rw-r--r--sound/core/pcm.c6
-rw-r--r--sound/core/pcm_native.c83
-rw-r--r--sound/core/rawmidi.c17
-rw-r--r--sound/drivers/pcsp/pcsp.c32
-rw-r--r--sound/drivers/pcsp/pcsp.h2
-rw-r--r--sound/drivers/pcsp/pcsp_mixer.c35
-rw-r--r--sound/i2c/cs8427.c15
-rw-r--r--sound/i2c/other/Makefile3
-rw-r--r--sound/i2c/other/ak4113.c639
-rw-r--r--sound/i2c/other/ak4xxx-adda.c136
-rw-r--r--sound/i2c/other/tea575x-tuner.c2
-rw-r--r--sound/isa/Kconfig12
-rw-r--r--sound/isa/cmi8330.c4
-rw-r--r--sound/isa/cs423x/cs4236.c15
-rw-r--r--sound/isa/cs423x/cs4236_lib.c241
-rw-r--r--sound/isa/es1688/es1688_lib.c2
-rw-r--r--sound/isa/es18xx.c221
-rw-r--r--sound/isa/opti9xx/miro.c785
-rw-r--r--sound/isa/opti9xx/miro.h73
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c112
-rw-r--r--sound/isa/sb/sb_mixer.c4
-rw-r--r--sound/isa/sscape.c727
-rw-r--r--sound/isa/wss/wss_lib.c105
-rw-r--r--sound/oss/Kconfig14
-rw-r--r--sound/oss/Makefile1
-rw-r--r--sound/oss/audio.c2
-rw-r--r--sound/oss/dmasound/dmasound_paula.c2
-rw-r--r--sound/oss/midi_synth.c2
-rw-r--r--sound/oss/mpu401.c2
-rw-r--r--sound/oss/sh_dac_audio.c3
-rw-r--r--sound/oss/sscape.c1480
-rw-r--r--sound/pci/Kconfig1
-rw-r--r--sound/pci/ac97/ac97_codec.c6
-rw-r--r--sound/pci/ac97/ac97_patch.c12
-rw-r--r--sound/pci/azt3328.c4
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c4
-rw-r--r--sound/pci/ca0106/ca0106_proc.c6
-rw-r--r--sound/pci/cmipci.c4
-rw-r--r--sound/pci/cs46xx/imgs/cwcdma.asp9
-rw-r--r--sound/pci/ctxfi/ctatc.c2
-rw-r--r--sound/pci/emu10k1/emu10k1x.c5
-rw-r--r--sound/pci/emu10k1/emumixer.c4
-rw-r--r--sound/pci/emu10k1/emuproc.c4
-rw-r--r--sound/pci/emu10k1/io.c2
-rw-r--r--sound/pci/es1938.c2
-rw-r--r--sound/pci/fm801.c40
-rw-r--r--sound/pci/hda/Kconfig13
-rw-r--r--sound/pci/hda/hda_beep.c114
-rw-r--r--sound/pci/hda/hda_beep.h10
-rw-r--r--sound/pci/hda/hda_codec.c607
-rw-r--r--sound/pci/hda/hda_codec.h11
-rw-r--r--sound/pci/hda/hda_eld.c20
-rw-r--r--sound/pci/hda/hda_generic.c17
-rw-r--r--sound/pci/hda/hda_hwdep.c38
-rw-r--r--sound/pci/hda/hda_intel.c50
-rw-r--r--sound/pci/hda/hda_local.h69
-rw-r--r--sound/pci/hda/hda_proc.c70
-rw-r--r--sound/pci/hda/patch_analog.c61
-rw-r--r--sound/pci/hda/patch_ca0110.c4
-rw-r--r--sound/pci/hda/patch_cirrus.c33
-rw-r--r--sound/pci/hda/patch_cmedia.c6
-rw-r--r--sound/pci/hda/patch_conexant.c189
-rw-r--r--sound/pci/hda/patch_intelhdmi.c488
-rw-r--r--sound/pci/hda/patch_realtek.c442
-rw-r--r--sound/pci/hda/patch_sigmatel.c149
-rw-r--r--sound/pci/hda/patch_via.c3509
-rw-r--r--sound/pci/ice1712/Makefile2
-rw-r--r--sound/pci/ice1712/ice1712.c12
-rw-r--r--sound/pci/ice1712/ice1712.h14
-rw-r--r--sound/pci/ice1712/ice1724.c103
-rw-r--r--sound/pci/ice1712/juli.c58
-rw-r--r--sound/pci/ice1712/quartet.c1130
-rw-r--r--sound/pci/ice1712/quartet.h10
-rw-r--r--sound/pci/intel8x0.c6
-rw-r--r--sound/pci/oxygen/Makefile3
-rw-r--r--sound/pci/oxygen/cs2000.h83
-rw-r--r--sound/pci/oxygen/hifier.c61
-rw-r--r--sound/pci/oxygen/oxygen.c248
-rw-r--r--sound/pci/oxygen/oxygen.h5
-rw-r--r--sound/pci/oxygen/oxygen_lib.c29
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c52
-rw-r--r--sound/pci/oxygen/oxygen_pcm.c19
-rw-r--r--sound/pci/oxygen/virtuoso.c1105
-rw-r--r--sound/pci/oxygen/xonar.h50
-rw-r--r--sound/pci/oxygen/xonar_cs43xx.c434
-rw-r--r--sound/pci/oxygen/xonar_hdmi.c128
-rw-r--r--sound/pci/oxygen/xonar_lib.c132
-rw-r--r--sound/pci/oxygen/xonar_pcm179x.c1115
-rw-r--r--sound/pci/rme9652/hdspm.c4
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf.c6
-rw-r--r--sound/pcmcia/vx/vxpocket.c6
-rw-r--r--sound/ppc/awacs.c12
-rw-r--r--sound/ppc/burgundy.c8
-rw-r--r--sound/ppc/tumbler.c2
-rw-r--r--sound/sh/Kconfig8
-rw-r--r--sound/sh/Makefile2
-rw-r--r--sound/sh/sh_dac_audio.c453
-rw-r--r--sound/soc/Makefile2
-rw-r--r--sound/soc/atmel/playpaq_wm8510.c2
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c2
-rw-r--r--sound/soc/au1x/dbdma2.c115
-rw-r--r--sound/soc/au1x/psc-ac97.c243
-rw-r--r--sound/soc/au1x/psc-i2s.c189
-rw-r--r--sound/soc/au1x/psc.h7
-rw-r--r--sound/soc/blackfin/bf5xx-ad1836.c7
-rw-r--r--sound/soc/blackfin/bf5xx-ad1938.c9
-rw-r--r--sound/soc/blackfin/bf5xx-i2s.c15
-rw-r--r--sound/soc/blackfin/bf5xx-tdm-pcm.c9
-rw-r--r--sound/soc/blackfin/bf5xx-tdm.c45
-rw-r--r--sound/soc/blackfin/bf5xx-tdm.h11
-rw-r--r--sound/soc/codecs/Kconfig25
-rw-r--r--sound/soc/codecs/Makefile12
-rw-r--r--sound/soc/codecs/ac97.c3
-rw-r--r--sound/soc/codecs/ad1836.c12
-rw-r--r--sound/soc/codecs/ad1938.c12
-rw-r--r--sound/soc/codecs/ad1980.c5
-rw-r--r--sound/soc/codecs/ad73311.c8
-rw-r--r--sound/soc/codecs/ads117x.c123
-rw-r--r--sound/soc/codecs/ads117x.h13
-rw-r--r--sound/soc/codecs/ak4104.c8
-rw-r--r--sound/soc/codecs/ak4535.c9
-rw-r--r--sound/soc/codecs/ak4642.c9
-rw-r--r--sound/soc/codecs/ak4671.c815
-rw-r--r--sound/soc/codecs/ak4671.h156
-rw-r--r--sound/soc/codecs/cs4270.c28
-rw-r--r--sound/soc/codecs/cx20442.c12
-rw-r--r--sound/soc/codecs/pcm3008.c9
-rw-r--r--sound/soc/codecs/ssm2602.c9
-rw-r--r--sound/soc/codecs/stac9766.c3
-rw-r--r--sound/soc/codecs/tlv320aic23.c11
-rw-r--r--sound/soc/codecs/tlv320aic26.c11
-rw-r--r--sound/soc/codecs/tlv320aic3x.c11
-rw-r--r--sound/soc/codecs/tlv320dac33.c1229
-rw-r--r--sound/soc/codecs/tlv320dac33.h267
-rw-r--r--sound/soc/codecs/tpa6130a2.c463
-rw-r--r--sound/soc/codecs/tpa6130a2.h61
-rw-r--r--sound/soc/codecs/twl4030.c452
-rw-r--r--sound/soc/codecs/twl4030.h242
-rw-r--r--sound/soc/codecs/uda134x.c13
-rw-r--r--sound/soc/codecs/uda1380.c9
-rw-r--r--sound/soc/codecs/wm8350.c32
-rw-r--r--sound/soc/codecs/wm8400.c32
-rw-r--r--sound/soc/codecs/wm8510.c14
-rw-r--r--sound/soc/codecs/wm8523.c26
-rw-r--r--sound/soc/codecs/wm8580.c30
-rw-r--r--sound/soc/codecs/wm8711.c633
-rw-r--r--sound/soc/codecs/wm8711.h42
-rw-r--r--sound/soc/codecs/wm8727.c135
-rw-r--r--sound/soc/codecs/wm8727.h21
-rw-r--r--sound/soc/codecs/wm8728.c10
-rw-r--r--sound/soc/codecs/wm8731.c94
-rw-r--r--sound/soc/codecs/wm8750.c9
-rw-r--r--sound/soc/codecs/wm8753.c49
-rw-r--r--sound/soc/codecs/wm8776.c43
-rw-r--r--sound/soc/codecs/wm8900.c34
-rw-r--r--sound/soc/codecs/wm8903.c34
-rw-r--r--sound/soc/codecs/wm8940.c28
-rw-r--r--sound/soc/codecs/wm8960.c30
-rw-r--r--sound/soc/codecs/wm8961.c27
-rw-r--r--sound/soc/codecs/wm8971.c11
-rw-r--r--sound/soc/codecs/wm8974.c36
-rw-r--r--sound/soc/codecs/wm8988.c44
-rw-r--r--sound/soc/codecs/wm8990.c14
-rw-r--r--sound/soc/codecs/wm8993.c53
-rw-r--r--sound/soc/codecs/wm9081.c27
-rw-r--r--sound/soc/codecs/wm9705.c7
-rw-r--r--sound/soc/codecs/wm9712.c7
-rw-r--r--sound/soc/codecs/wm9713.c32
-rw-r--r--sound/soc/codecs/wm_hubs.c51
-rw-r--r--sound/soc/codecs/wm_hubs.h5
-rw-r--r--sound/soc/davinci/Kconfig4
-rw-r--r--sound/soc/davinci/davinci-evm.c7
-rw-r--r--sound/soc/davinci/davinci-i2s.c85
-rw-r--r--sound/soc/davinci/davinci-mcasp.c18
-rw-r--r--sound/soc/davinci/davinci-mcasp.h5
-rw-r--r--sound/soc/davinci/davinci-pcm.c571
-rw-r--r--sound/soc/davinci/davinci-pcm.h2
-rw-r--r--sound/soc/fsl/mpc5200_dma.c123
-rw-r--r--sound/soc/fsl/mpc5200_dma.h24
-rw-r--r--sound/soc/fsl/mpc5200_psc_ac97.c39
-rw-r--r--sound/soc/imx/mx27vis_wm8974.c2
-rw-r--r--sound/soc/omap/Kconfig23
-rw-r--r--sound/soc/omap/Makefile4
-rw-r--r--sound/soc/omap/am3517evm.c202
-rw-r--r--sound/soc/omap/ams-delta.c8
-rw-r--r--sound/soc/omap/igep0020.c148
-rw-r--r--sound/soc/omap/n810.c2
-rw-r--r--sound/soc/omap/omap-mcbsp.c69
-rw-r--r--sound/soc/omap/omap-pcm.c2
-rw-r--r--sound/soc/omap/omap2evm.c2
-rw-r--r--sound/soc/omap/omap3beagle.c2
-rw-r--r--sound/soc/omap/omap3evm.c9
-rw-r--r--sound/soc/omap/omap3pandora.c24
-rw-r--r--sound/soc/omap/osk5912.c2
-rw-r--r--sound/soc/omap/overo.c6
-rw-r--r--sound/soc/omap/sdp3430.c2
-rw-r--r--sound/soc/omap/zoom2.c2
-rw-r--r--sound/soc/pxa/Kconfig12
-rw-r--r--sound/soc/pxa/Makefile2
-rw-r--r--sound/soc/pxa/magician.c2
-rw-r--r--sound/soc/pxa/pxa-ssp.c20
-rw-r--r--sound/soc/pxa/raumfeld.c335
-rw-r--r--sound/soc/pxa/zylonite.c5
-rw-r--r--sound/soc/s3c24xx/Kconfig12
-rw-r--r--sound/soc/s3c24xx/Makefile6
-rw-r--r--sound/soc/s3c24xx/jive_wm8750.c2
-rw-r--r--sound/soc/s3c24xx/ln2440sbc_alc650.c2
-rw-r--r--sound/soc/s3c24xx/neo1973_gta02_wm8753.c10
-rw-r--r--sound/soc/s3c24xx/neo1973_wm8753.c11
-rw-r--r--sound/soc/s3c24xx/s3c-dma.c (renamed from sound/soc/s3c24xx/s3c24xx-pcm.c)88
-rw-r--r--sound/soc/s3c24xx/s3c-dma.h (renamed from sound/soc/s3c24xx/s3c24xx-pcm.h)8
-rw-r--r--sound/soc/s3c24xx/s3c-i2s-v2.c35
-rw-r--r--sound/soc/s3c24xx/s3c-i2s-v2.h4
-rw-r--r--sound/soc/s3c24xx/s3c-pcm.c552
-rw-r--r--sound/soc/s3c24xx/s3c-pcm.h123
-rw-r--r--sound/soc/s3c24xx/s3c2412-i2s.c7
-rw-r--r--sound/soc/s3c24xx/s3c2443-ac97.c13
-rw-r--r--sound/soc/s3c24xx/s3c24xx-i2s.c14
-rw-r--r--sound/soc/s3c24xx/s3c24xx_simtec.c4
-rw-r--r--sound/soc/s3c24xx/s3c24xx_simtec_hermes.c2
-rw-r--r--sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c2
-rw-r--r--sound/soc/s3c24xx/s3c24xx_uda134x.c2
-rw-r--r--sound/soc/s3c24xx/s3c64xx-i2s.c26
-rw-r--r--sound/soc/s3c24xx/s3c64xx-i2s.h1
-rw-r--r--sound/soc/s3c24xx/smdk2443_wm9710.c2
-rw-r--r--sound/soc/s3c24xx/smdk64xx_wm8580.c268
-rw-r--r--sound/soc/s6000/s6000-pcm.c6
-rw-r--r--sound/soc/sh/Kconfig1
-rw-r--r--sound/soc/sh/fsi.c271
-rw-r--r--sound/soc/soc-cache.c46
-rw-r--r--sound/soc/soc-core.c566
-rw-r--r--sound/soc/soc-dapm.c135
-rw-r--r--sound/soc/soc-jack.c6
-rw-r--r--sound/soc/soc-utils.c74
-rw-r--r--sound/sound_core.c2
-rw-r--r--sound/synth/emux/soundfont.c2
-rw-r--r--sound/usb/usbaudio.c38
-rw-r--r--sound/usb/usbaudio.h7
-rw-r--r--sound/usb/usbmidi.c208
-rw-r--r--sound/usb/usbmixer_maps.c23
-rw-r--r--sound/usb/usbquirks.h23
-rw-r--r--sound/usb/usx2y/us122l.c135
-rw-r--r--sound/usb/usx2y/us122l.h4
-rw-r--r--sound/usb/usx2y/usX2Yhwdep.c8
-rw-r--r--sound/usb/usx2y/usbusx2y.c28
-rw-r--r--sound/usb/usx2y/usbusx2y.h6
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c34
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c8
256 files changed, 19550 insertions, 7575 deletions
diff --git a/sound/Kconfig b/sound/Kconfig
index 439e15c8faa3..fcad760f5691 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -1,6 +1,3 @@
1# sound/Config.in
2#
3
4menuconfig SOUND 1menuconfig SOUND
5 tristate "Sound card support" 2 tristate "Sound card support"
6 depends on HAS_IOMEM 3 depends on HAS_IOMEM
@@ -58,7 +55,7 @@ config SOUND_OSS_CORE_PRECLAIM
58 Please read Documentation/feature-removal-schedule.txt for 55 Please read Documentation/feature-removal-schedule.txt for
59 details. 56 details.
60 57
61 If unusre, say Y. 58 If unsure, say Y.
62 59
63source "sound/oss/dmasound/Kconfig" 60source "sound/oss/dmasound/Kconfig"
64 61
@@ -136,4 +133,3 @@ config AC97_BUS
136 sound subsystem and other function drivers completely unrelated to 133 sound subsystem and other function drivers completely unrelated to
137 sound although they're sharing the AC97 bus. Concerned drivers 134 sound although they're sharing the AC97 bus. Concerned drivers
138 should "select" this. 135 should "select" this.
139
diff --git a/sound/arm/Makefile b/sound/arm/Makefile
index 5a549ed6c8aa..8c0c851d4641 100644
--- a/sound/arm/Makefile
+++ b/sound/arm/Makefile
@@ -3,7 +3,7 @@
3# 3#
4 4
5obj-$(CONFIG_SND_ARMAACI) += snd-aaci.o 5obj-$(CONFIG_SND_ARMAACI) += snd-aaci.o
6snd-aaci-objs := aaci.o devdma.o 6snd-aaci-objs := aaci.o
7 7
8obj-$(CONFIG_SND_PXA2XX_PCM) += snd-pxa2xx-pcm.o 8obj-$(CONFIG_SND_PXA2XX_PCM) += snd-pxa2xx-pcm.o
9snd-pxa2xx-pcm-objs := pxa2xx-pcm.o 9snd-pxa2xx-pcm-objs := pxa2xx-pcm.o
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index 6c160a038b23..1497dce1b04a 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -18,10 +18,7 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/err.h> 19#include <linux/err.h>
20#include <linux/amba/bus.h> 20#include <linux/amba/bus.h>
21 21#include <linux/io.h>
22#include <asm/io.h>
23#include <asm/irq.h>
24#include <asm/sizes.h>
25 22
26#include <sound/core.h> 23#include <sound/core.h>
27#include <sound/initval.h> 24#include <sound/initval.h>
@@ -30,7 +27,6 @@
30#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
31 28
32#include "aaci.h" 29#include "aaci.h"
33#include "devdma.h"
34 30
35#define DRIVER_NAME "aaci-pl041" 31#define DRIVER_NAME "aaci-pl041"
36 32
@@ -492,7 +488,7 @@ static int aaci_pcm_hw_free(struct snd_pcm_substream *substream)
492 /* 488 /*
493 * Clear out the DMA and any allocated buffers. 489 * Clear out the DMA and any allocated buffers.
494 */ 490 */
495 devdma_hw_free(NULL, substream); 491 snd_pcm_lib_free_pages(substream);
496 492
497 return 0; 493 return 0;
498} 494}
@@ -509,20 +505,14 @@ static int aaci_pcm_hw_params(struct snd_pcm_substream *substream,
509 aacirun->pcm_open = 0; 505 aacirun->pcm_open = 0;
510 } 506 }
511 507
512 err = devdma_hw_alloc(NULL, substream, 508 err = snd_pcm_lib_malloc_pages(substream,
513 params_buffer_bytes(params)); 509 params_buffer_bytes(params));
514 if (err < 0) 510 if (err < 0)
515 goto out; 511 goto out;
516 512
517 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 513 err = snd_ac97_pcm_open(aacirun->pcm, params_rate(params),
518 err = snd_ac97_pcm_open(aacirun->pcm, params_rate(params), 514 params_channels(params),
519 params_channels(params), 515 aacirun->pcm->r[0].slots);
520 aacirun->pcm->r[0].slots);
521 else
522 err = snd_ac97_pcm_open(aacirun->pcm, params_rate(params),
523 params_channels(params),
524 aacirun->pcm->r[0].slots);
525
526 if (err) 516 if (err)
527 goto out; 517 goto out;
528 518
@@ -538,7 +528,7 @@ static int aaci_pcm_prepare(struct snd_pcm_substream *substream)
538 struct aaci_runtime *aacirun = runtime->private_data; 528 struct aaci_runtime *aacirun = runtime->private_data;
539 529
540 aacirun->start = (void *)runtime->dma_area; 530 aacirun->start = (void *)runtime->dma_area;
541 aacirun->end = aacirun->start + runtime->dma_bytes; 531 aacirun->end = aacirun->start + snd_pcm_lib_buffer_bytes(substream);
542 aacirun->ptr = aacirun->start; 532 aacirun->ptr = aacirun->start;
543 aacirun->period = 533 aacirun->period =
544 aacirun->bytes = frames_to_bytes(runtime, runtime->period_size); 534 aacirun->bytes = frames_to_bytes(runtime, runtime->period_size);
@@ -555,11 +545,6 @@ static snd_pcm_uframes_t aaci_pcm_pointer(struct snd_pcm_substream *substream)
555 return bytes_to_frames(runtime, bytes); 545 return bytes_to_frames(runtime, bytes);
556} 546}
557 547
558static int aaci_pcm_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma)
559{
560 return devdma_mmap(NULL, substream, vma);
561}
562
563 548
564/* 549/*
565 * Playback specific ALSA stuff 550 * Playback specific ALSA stuff
@@ -726,7 +711,6 @@ static struct snd_pcm_ops aaci_playback_ops = {
726 .prepare = aaci_pcm_prepare, 711 .prepare = aaci_pcm_prepare,
727 .trigger = aaci_pcm_playback_trigger, 712 .trigger = aaci_pcm_playback_trigger,
728 .pointer = aaci_pcm_pointer, 713 .pointer = aaci_pcm_pointer,
729 .mmap = aaci_pcm_mmap,
730}; 714};
731 715
732static int aaci_pcm_capture_hw_params(struct snd_pcm_substream *substream, 716static int aaci_pcm_capture_hw_params(struct snd_pcm_substream *substream,
@@ -854,7 +838,6 @@ static struct snd_pcm_ops aaci_capture_ops = {
854 .prepare = aaci_pcm_capture_prepare, 838 .prepare = aaci_pcm_capture_prepare,
855 .trigger = aaci_pcm_capture_trigger, 839 .trigger = aaci_pcm_capture_trigger,
856 .pointer = aaci_pcm_pointer, 840 .pointer = aaci_pcm_pointer,
857 .mmap = aaci_pcm_mmap,
858}; 841};
859 842
860/* 843/*
@@ -1044,6 +1027,8 @@ static int __devinit aaci_init_pcm(struct aaci *aaci)
1044 1027
1045 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &aaci_playback_ops); 1028 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &aaci_playback_ops);
1046 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &aaci_capture_ops); 1029 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &aaci_capture_ops);
1030 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1031 NULL, 0, 64 * 104);
1047 } 1032 }
1048 1033
1049 return ret; 1034 return ret;
diff --git a/sound/arm/devdma.c b/sound/arm/devdma.c
deleted file mode 100644
index 9d1e6665b546..000000000000
--- a/sound/arm/devdma.c
+++ /dev/null
@@ -1,80 +0,0 @@
1/*
2 * linux/sound/arm/devdma.c
3 *
4 * Copyright (C) 2003-2004 Russell King, All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ARM DMA shim for ALSA.
11 */
12#include <linux/device.h>
13#include <linux/dma-mapping.h>
14
15#include <sound/core.h>
16#include <sound/pcm.h>
17
18#include "devdma.h"
19
20void devdma_hw_free(struct device *dev, struct snd_pcm_substream *substream)
21{
22 struct snd_pcm_runtime *runtime = substream->runtime;
23 struct snd_dma_buffer *buf = runtime->dma_buffer_p;
24
25 if (runtime->dma_area == NULL)
26 return;
27
28 if (buf != &substream->dma_buffer) {
29 dma_free_coherent(buf->dev.dev, buf->bytes, buf->area, buf->addr);
30 kfree(runtime->dma_buffer_p);
31 }
32
33 snd_pcm_set_runtime_buffer(substream, NULL);
34}
35
36int devdma_hw_alloc(struct device *dev, struct snd_pcm_substream *substream, size_t size)
37{
38 struct snd_pcm_runtime *runtime = substream->runtime;
39 struct snd_dma_buffer *buf = runtime->dma_buffer_p;
40 int ret = 0;
41
42 if (buf) {
43 if (buf->bytes >= size)
44 goto out;
45 devdma_hw_free(dev, substream);
46 }
47
48 if (substream->dma_buffer.area != NULL && substream->dma_buffer.bytes >= size) {
49 buf = &substream->dma_buffer;
50 } else {
51 buf = kmalloc(sizeof(struct snd_dma_buffer), GFP_KERNEL);
52 if (!buf)
53 goto nomem;
54
55 buf->dev.type = SNDRV_DMA_TYPE_DEV;
56 buf->dev.dev = dev;
57 buf->area = dma_alloc_coherent(dev, size, &buf->addr, GFP_KERNEL);
58 buf->bytes = size;
59 buf->private_data = NULL;
60
61 if (!buf->area)
62 goto free;
63 }
64 snd_pcm_set_runtime_buffer(substream, buf);
65 ret = 1;
66 out:
67 runtime->dma_bytes = size;
68 return ret;
69
70 free:
71 kfree(buf);
72 nomem:
73 return -ENOMEM;
74}
75
76int devdma_mmap(struct device *dev, struct snd_pcm_substream *substream, struct vm_area_struct *vma)
77{
78 struct snd_pcm_runtime *runtime = substream->runtime;
79 return dma_mmap_coherent(dev, vma, runtime->dma_area, runtime->dma_addr, runtime->dma_bytes);
80}
diff --git a/sound/arm/devdma.h b/sound/arm/devdma.h
deleted file mode 100644
index d025329c8a0f..000000000000
--- a/sound/arm/devdma.h
+++ /dev/null
@@ -1,3 +0,0 @@
1void devdma_hw_free(struct device *dev, struct snd_pcm_substream *substream);
2int devdma_hw_alloc(struct device *dev, struct snd_pcm_substream *substream, size_t size);
3int devdma_mmap(struct device *dev, struct snd_pcm_substream *substream, struct vm_area_struct *vma);
diff --git a/sound/core/control.c b/sound/core/control.c
index a8b7fabe645e..268ab7471224 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -75,7 +75,7 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
75 ctl->card = card; 75 ctl->card = card;
76 ctl->prefer_pcm_subdevice = -1; 76 ctl->prefer_pcm_subdevice = -1;
77 ctl->prefer_rawmidi_subdevice = -1; 77 ctl->prefer_rawmidi_subdevice = -1;
78 ctl->pid = current->pid; 78 ctl->pid = get_pid(task_pid(current));
79 file->private_data = ctl; 79 file->private_data = ctl;
80 write_lock_irqsave(&card->ctl_files_rwlock, flags); 80 write_lock_irqsave(&card->ctl_files_rwlock, flags);
81 list_add_tail(&ctl->list, &card->ctl_files); 81 list_add_tail(&ctl->list, &card->ctl_files);
@@ -125,6 +125,7 @@ static int snd_ctl_release(struct inode *inode, struct file *file)
125 control->vd[idx].owner = NULL; 125 control->vd[idx].owner = NULL;
126 up_write(&card->controls_rwsem); 126 up_write(&card->controls_rwsem);
127 snd_ctl_empty_read_queue(ctl); 127 snd_ctl_empty_read_queue(ctl);
128 put_pid(ctl->pid);
128 kfree(ctl); 129 kfree(ctl);
129 module_put(card->module); 130 module_put(card->module);
130 snd_card_file_remove(card, file); 131 snd_card_file_remove(card, file);
@@ -672,7 +673,7 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
672 info->access |= SNDRV_CTL_ELEM_ACCESS_LOCK; 673 info->access |= SNDRV_CTL_ELEM_ACCESS_LOCK;
673 if (vd->owner == ctl) 674 if (vd->owner == ctl)
674 info->access |= SNDRV_CTL_ELEM_ACCESS_OWNER; 675 info->access |= SNDRV_CTL_ELEM_ACCESS_OWNER;
675 info->owner = vd->owner_pid; 676 info->owner = pid_vnr(vd->owner->pid);
676 } else { 677 } else {
677 info->owner = -1; 678 info->owner = -1;
678 } 679 }
@@ -827,7 +828,6 @@ static int snd_ctl_elem_lock(struct snd_ctl_file *file,
827 result = -EBUSY; 828 result = -EBUSY;
828 else { 829 else {
829 vd->owner = file; 830 vd->owner = file;
830 vd->owner_pid = current->pid;
831 result = 0; 831 result = 0;
832 } 832 }
833 } 833 }
@@ -858,7 +858,6 @@ static int snd_ctl_elem_unlock(struct snd_ctl_file *file,
858 result = -EPERM; 858 result = -EPERM;
859 else { 859 else {
860 vd->owner = NULL; 860 vd->owner = NULL;
861 vd->owner_pid = 0;
862 result = 0; 861 result = 0;
863 } 862 }
864 } 863 }
@@ -1120,7 +1119,7 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file,
1120 goto __kctl_end; 1119 goto __kctl_end;
1121 } 1120 }
1122 if (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { 1121 if (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
1123 if (file && vd->owner != NULL && vd->owner != file) { 1122 if (vd->owner != NULL && vd->owner != file) {
1124 err = -EPERM; 1123 err = -EPERM;
1125 goto __kctl_end; 1124 goto __kctl_end;
1126 } 1125 }
diff --git a/sound/core/isadma.c b/sound/core/isadma.c
index 79f0f16af339..950e19ba91fc 100644
--- a/sound/core/isadma.c
+++ b/sound/core/isadma.c
@@ -85,16 +85,24 @@ EXPORT_SYMBOL(snd_dma_disable);
85unsigned int snd_dma_pointer(unsigned long dma, unsigned int size) 85unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
86{ 86{
87 unsigned long flags; 87 unsigned long flags;
88 unsigned int result; 88 unsigned int result, result1;
89 89
90 flags = claim_dma_lock(); 90 flags = claim_dma_lock();
91 clear_dma_ff(dma); 91 clear_dma_ff(dma);
92 if (!isa_dma_bridge_buggy) 92 if (!isa_dma_bridge_buggy)
93 disable_dma(dma); 93 disable_dma(dma);
94 result = get_dma_residue(dma); 94 result = get_dma_residue(dma);
95 /*
96 * HACK - read the counter again and choose higher value in order to
97 * avoid reading during counter lower byte roll over if the
98 * isa_dma_bridge_buggy is set.
99 */
100 result1 = get_dma_residue(dma);
95 if (!isa_dma_bridge_buggy) 101 if (!isa_dma_bridge_buggy)
96 enable_dma(dma); 102 enable_dma(dma);
97 release_dma_lock(flags); 103 release_dma_lock(flags);
104 if (unlikely(result < result1))
105 result = result1;
98#ifdef CONFIG_SND_DEBUG 106#ifdef CONFIG_SND_DEBUG
99 if (result > size) 107 if (result > size)
100 snd_printk(KERN_ERR "pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size); 108 snd_printk(KERN_ERR "pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size);
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 772423889eb3..54e2eb56e4c2 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1251,7 +1251,9 @@ static void snd_mixer_oss_build(struct snd_mixer_oss *mixer)
1251 { SOUND_MIXER_SYNTH, "FM", 0 }, /* fallback */ 1251 { SOUND_MIXER_SYNTH, "FM", 0 }, /* fallback */
1252 { SOUND_MIXER_SYNTH, "Music", 0 }, /* fallback */ 1252 { SOUND_MIXER_SYNTH, "Music", 0 }, /* fallback */
1253 { SOUND_MIXER_PCM, "PCM", 0 }, 1253 { SOUND_MIXER_PCM, "PCM", 0 },
1254 { SOUND_MIXER_SPEAKER, "PC Speaker", 0 }, 1254 { SOUND_MIXER_SPEAKER, "Beep", 0 },
1255 { SOUND_MIXER_SPEAKER, "PC Speaker", 0 }, /* fallback */
1256 { SOUND_MIXER_SPEAKER, "Speaker", 0 }, /* fallback */
1255 { SOUND_MIXER_LINE, "Line", 0 }, 1257 { SOUND_MIXER_LINE, "Line", 0 },
1256 { SOUND_MIXER_MIC, "Mic", 0 }, 1258 { SOUND_MIXER_MIC, "Mic", 0 },
1257 { SOUND_MIXER_CD, "CD", 0 }, 1259 { SOUND_MIXER_CD, "CD", 0 },
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index c69c60b2a48a..6884ae031f6f 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -435,6 +435,7 @@ static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry,
435 return; 435 return;
436 } 436 }
437 snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state)); 437 snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state));
438 snd_iprintf(buffer, "owner_pid : %d\n", pid_vnr(substream->pid));
438 snd_iprintf(buffer, "trigger_time: %ld.%09ld\n", 439 snd_iprintf(buffer, "trigger_time: %ld.%09ld\n",
439 status.trigger_tstamp.tv_sec, status.trigger_tstamp.tv_nsec); 440 status.trigger_tstamp.tv_sec, status.trigger_tstamp.tv_nsec);
440 snd_iprintf(buffer, "tstamp : %ld.%09ld\n", 441 snd_iprintf(buffer, "tstamp : %ld.%09ld\n",
@@ -809,7 +810,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
809 card = pcm->card; 810 card = pcm->card;
810 read_lock(&card->ctl_files_rwlock); 811 read_lock(&card->ctl_files_rwlock);
811 list_for_each_entry(kctl, &card->ctl_files, list) { 812 list_for_each_entry(kctl, &card->ctl_files, list) {
812 if (kctl->pid == current->pid) { 813 if (kctl->pid == task_pid(current)) {
813 prefer_subdevice = kctl->prefer_pcm_subdevice; 814 prefer_subdevice = kctl->prefer_pcm_subdevice;
814 if (prefer_subdevice != -1) 815 if (prefer_subdevice != -1)
815 break; 816 break;
@@ -900,6 +901,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
900 substream->private_data = pcm->private_data; 901 substream->private_data = pcm->private_data;
901 substream->ref_count = 1; 902 substream->ref_count = 1;
902 substream->f_flags = file->f_flags; 903 substream->f_flags = file->f_flags;
904 substream->pid = get_pid(task_pid(current));
903 pstr->substream_opened++; 905 pstr->substream_opened++;
904 *rsubstream = substream; 906 *rsubstream = substream;
905 return 0; 907 return 0;
@@ -921,6 +923,8 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
921 kfree(runtime->hw_constraints.rules); 923 kfree(runtime->hw_constraints.rules);
922 kfree(runtime); 924 kfree(runtime);
923 substream->runtime = NULL; 925 substream->runtime = NULL;
926 put_pid(substream->pid);
927 substream->pid = NULL;
924 substream->pstr->substream_opened--; 928 substream->pstr->substream_opened--;
925} 929}
926 930
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index ab73edf2c89a..29ab46a12e11 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -26,6 +26,7 @@
26#include <linux/time.h> 26#include <linux/time.h>
27#include <linux/pm_qos_params.h> 27#include <linux/pm_qos_params.h>
28#include <linux/uio.h> 28#include <linux/uio.h>
29#include <linux/dma-mapping.h>
29#include <sound/core.h> 30#include <sound/core.h>
30#include <sound/control.h> 31#include <sound/control.h>
31#include <sound/info.h> 32#include <sound/info.h>
@@ -3061,6 +3062,27 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file
3061} 3062}
3062#endif /* coherent mmap */ 3063#endif /* coherent mmap */
3063 3064
3065static inline struct page *
3066snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs)
3067{
3068 void *vaddr = substream->runtime->dma_area + ofs;
3069#if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3070 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
3071 return virt_to_page(CAC_ADDR(vaddr));
3072#endif
3073#if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3074 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV) {
3075 dma_addr_t addr = substream->runtime->dma_addr + ofs;
3076 addr -= get_dma_offset(substream->dma_buffer.dev.dev);
3077 /* assume dma_handle set via pfn_to_phys() in
3078 * mm/dma-noncoherent.c
3079 */
3080 return pfn_to_page(addr >> PAGE_SHIFT);
3081 }
3082#endif
3083 return virt_to_page(vaddr);
3084}
3085
3064/* 3086/*
3065 * fault callback for mmapping a RAM page 3087 * fault callback for mmapping a RAM page
3066 */ 3088 */
@@ -3071,7 +3093,6 @@ static int snd_pcm_mmap_data_fault(struct vm_area_struct *area,
3071 struct snd_pcm_runtime *runtime; 3093 struct snd_pcm_runtime *runtime;
3072 unsigned long offset; 3094 unsigned long offset;
3073 struct page * page; 3095 struct page * page;
3074 void *vaddr;
3075 size_t dma_bytes; 3096 size_t dma_bytes;
3076 3097
3077 if (substream == NULL) 3098 if (substream == NULL)
@@ -3081,36 +3102,53 @@ static int snd_pcm_mmap_data_fault(struct vm_area_struct *area,
3081 dma_bytes = PAGE_ALIGN(runtime->dma_bytes); 3102 dma_bytes = PAGE_ALIGN(runtime->dma_bytes);
3082 if (offset > dma_bytes - PAGE_SIZE) 3103 if (offset > dma_bytes - PAGE_SIZE)
3083 return VM_FAULT_SIGBUS; 3104 return VM_FAULT_SIGBUS;
3084 if (substream->ops->page) { 3105 if (substream->ops->page)
3085 page = substream->ops->page(substream, offset); 3106 page = substream->ops->page(substream, offset);
3086 if (!page) 3107 else
3087 return VM_FAULT_SIGBUS; 3108 page = snd_pcm_default_page_ops(substream, offset);
3088 } else { 3109 if (!page)
3089 vaddr = runtime->dma_area + offset; 3110 return VM_FAULT_SIGBUS;
3090 page = virt_to_page(vaddr);
3091 }
3092 get_page(page); 3111 get_page(page);
3093 vmf->page = page; 3112 vmf->page = page;
3094 return 0; 3113 return 0;
3095} 3114}
3096 3115
3097static const struct vm_operations_struct snd_pcm_vm_ops_data = 3116static const struct vm_operations_struct snd_pcm_vm_ops_data = {
3098{ 3117 .open = snd_pcm_mmap_data_open,
3118 .close = snd_pcm_mmap_data_close,
3119};
3120
3121static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = {
3099 .open = snd_pcm_mmap_data_open, 3122 .open = snd_pcm_mmap_data_open,
3100 .close = snd_pcm_mmap_data_close, 3123 .close = snd_pcm_mmap_data_close,
3101 .fault = snd_pcm_mmap_data_fault, 3124 .fault = snd_pcm_mmap_data_fault,
3102}; 3125};
3103 3126
3127#ifndef ARCH_HAS_DMA_MMAP_COHERENT
3128/* This should be defined / handled globally! */
3129#ifdef CONFIG_ARM
3130#define ARCH_HAS_DMA_MMAP_COHERENT
3131#endif
3132#endif
3133
3104/* 3134/*
3105 * mmap the DMA buffer on RAM 3135 * mmap the DMA buffer on RAM
3106 */ 3136 */
3107static int snd_pcm_default_mmap(struct snd_pcm_substream *substream, 3137static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
3108 struct vm_area_struct *area) 3138 struct vm_area_struct *area)
3109{ 3139{
3110 area->vm_ops = &snd_pcm_vm_ops_data;
3111 area->vm_private_data = substream;
3112 area->vm_flags |= VM_RESERVED; 3140 area->vm_flags |= VM_RESERVED;
3113 atomic_inc(&substream->mmap_count); 3141#ifdef ARCH_HAS_DMA_MMAP_COHERENT
3142 if (!substream->ops->page &&
3143 substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
3144 return dma_mmap_coherent(substream->dma_buffer.dev.dev,
3145 area,
3146 substream->runtime->dma_area,
3147 substream->runtime->dma_addr,
3148 area->vm_end - area->vm_start);
3149#endif /* ARCH_HAS_DMA_MMAP_COHERENT */
3150 /* mmap with fault handler */
3151 area->vm_ops = &snd_pcm_vm_ops_data_fault;
3114 return 0; 3152 return 0;
3115} 3153}
3116 3154
@@ -3118,12 +3156,6 @@ static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
3118 * mmap the DMA buffer on I/O memory area 3156 * mmap the DMA buffer on I/O memory area
3119 */ 3157 */
3120#if SNDRV_PCM_INFO_MMAP_IOMEM 3158#if SNDRV_PCM_INFO_MMAP_IOMEM
3121static const struct vm_operations_struct snd_pcm_vm_ops_data_mmio =
3122{
3123 .open = snd_pcm_mmap_data_open,
3124 .close = snd_pcm_mmap_data_close,
3125};
3126
3127int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, 3159int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
3128 struct vm_area_struct *area) 3160 struct vm_area_struct *area)
3129{ 3161{
@@ -3133,8 +3165,6 @@ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
3133#ifdef pgprot_noncached 3165#ifdef pgprot_noncached
3134 area->vm_page_prot = pgprot_noncached(area->vm_page_prot); 3166 area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
3135#endif 3167#endif
3136 area->vm_ops = &snd_pcm_vm_ops_data_mmio;
3137 area->vm_private_data = substream;
3138 area->vm_flags |= VM_IO; 3168 area->vm_flags |= VM_IO;
3139 size = area->vm_end - area->vm_start; 3169 size = area->vm_end - area->vm_start;
3140 offset = area->vm_pgoff << PAGE_SHIFT; 3170 offset = area->vm_pgoff << PAGE_SHIFT;
@@ -3142,7 +3172,6 @@ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
3142 (substream->runtime->dma_addr + offset) >> PAGE_SHIFT, 3172 (substream->runtime->dma_addr + offset) >> PAGE_SHIFT,
3143 size, area->vm_page_prot)) 3173 size, area->vm_page_prot))
3144 return -EAGAIN; 3174 return -EAGAIN;
3145 atomic_inc(&substream->mmap_count);
3146 return 0; 3175 return 0;
3147} 3176}
3148 3177
@@ -3159,6 +3188,7 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
3159 long size; 3188 long size;
3160 unsigned long offset; 3189 unsigned long offset;
3161 size_t dma_bytes; 3190 size_t dma_bytes;
3191 int err;
3162 3192
3163 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 3193 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3164 if (!(area->vm_flags & (VM_WRITE|VM_READ))) 3194 if (!(area->vm_flags & (VM_WRITE|VM_READ)))
@@ -3183,10 +3213,15 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
3183 if (offset > dma_bytes - size) 3213 if (offset > dma_bytes - size)
3184 return -EINVAL; 3214 return -EINVAL;
3185 3215
3216 area->vm_ops = &snd_pcm_vm_ops_data;
3217 area->vm_private_data = substream;
3186 if (substream->ops->mmap) 3218 if (substream->ops->mmap)
3187 return substream->ops->mmap(substream, area); 3219 err = substream->ops->mmap(substream, area);
3188 else 3220 else
3189 return snd_pcm_default_mmap(substream, area); 3221 err = snd_pcm_default_mmap(substream, area);
3222 if (!err)
3223 atomic_inc(&substream->mmap_count);
3224 return err;
3190} 3225}
3191 3226
3192EXPORT_SYMBOL(snd_pcm_mmap_data); 3227EXPORT_SYMBOL(snd_pcm_mmap_data);
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 70d6f25ba526..2f766123b158 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -242,8 +242,6 @@ static int assign_substream(struct snd_rawmidi *rmidi, int subdevice,
242 return -ENXIO; 242 return -ENXIO;
243 if (subdevice >= 0 && subdevice >= s->substream_count) 243 if (subdevice >= 0 && subdevice >= s->substream_count)
244 return -ENODEV; 244 return -ENODEV;
245 if (s->substream_opened >= s->substream_count)
246 return -EAGAIN;
247 245
248 list_for_each_entry(substream, &s->substreams, list) { 246 list_for_each_entry(substream, &s->substreams, list) {
249 if (substream->opened) { 247 if (substream->opened) {
@@ -280,9 +278,10 @@ static int open_substream(struct snd_rawmidi *rmidi,
280 substream->active_sensing = 0; 278 substream->active_sensing = 0;
281 if (mode & SNDRV_RAWMIDI_LFLG_APPEND) 279 if (mode & SNDRV_RAWMIDI_LFLG_APPEND)
282 substream->append = 1; 280 substream->append = 1;
281 substream->pid = get_pid(task_pid(current));
282 rmidi->streams[substream->stream].substream_opened++;
283 } 283 }
284 substream->use_count++; 284 substream->use_count++;
285 rmidi->streams[substream->stream].substream_opened++;
286 return 0; 285 return 0;
287} 286}
288 287
@@ -413,7 +412,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
413 subdevice = -1; 412 subdevice = -1;
414 read_lock(&card->ctl_files_rwlock); 413 read_lock(&card->ctl_files_rwlock);
415 list_for_each_entry(kctl, &card->ctl_files, list) { 414 list_for_each_entry(kctl, &card->ctl_files, list) {
416 if (kctl->pid == current->pid) { 415 if (kctl->pid == task_pid(current)) {
417 subdevice = kctl->prefer_rawmidi_subdevice; 416 subdevice = kctl->prefer_rawmidi_subdevice;
418 if (subdevice != -1) 417 if (subdevice != -1)
419 break; 418 break;
@@ -466,7 +465,6 @@ static void close_substream(struct snd_rawmidi *rmidi,
466 struct snd_rawmidi_substream *substream, 465 struct snd_rawmidi_substream *substream,
467 int cleanup) 466 int cleanup)
468{ 467{
469 rmidi->streams[substream->stream].substream_opened--;
470 if (--substream->use_count) 468 if (--substream->use_count)
471 return; 469 return;
472 470
@@ -491,6 +489,9 @@ static void close_substream(struct snd_rawmidi *rmidi,
491 snd_rawmidi_runtime_free(substream); 489 snd_rawmidi_runtime_free(substream);
492 substream->opened = 0; 490 substream->opened = 0;
493 substream->append = 0; 491 substream->append = 0;
492 put_pid(substream->pid);
493 substream->pid = NULL;
494 rmidi->streams[substream->stream].substream_opened--;
494} 495}
495 496
496static void rawmidi_release_priv(struct snd_rawmidi_file *rfile) 497static void rawmidi_release_priv(struct snd_rawmidi_file *rfile)
@@ -1338,6 +1339,9 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
1338 substream->number, 1339 substream->number,
1339 (unsigned long) substream->bytes); 1340 (unsigned long) substream->bytes);
1340 if (substream->opened) { 1341 if (substream->opened) {
1342 snd_iprintf(buffer,
1343 " Owner PID : %d\n",
1344 pid_vnr(substream->pid));
1341 runtime = substream->runtime; 1345 runtime = substream->runtime;
1342 snd_iprintf(buffer, 1346 snd_iprintf(buffer,
1343 " Mode : %s\n" 1347 " Mode : %s\n"
@@ -1359,6 +1363,9 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
1359 substream->number, 1363 substream->number,
1360 (unsigned long) substream->bytes); 1364 (unsigned long) substream->bytes);
1361 if (substream->opened) { 1365 if (substream->opened) {
1366 snd_iprintf(buffer,
1367 " Owner PID : %d\n",
1368 pid_vnr(substream->pid));
1362 runtime = substream->runtime; 1369 runtime = substream->runtime;
1363 snd_iprintf(buffer, 1370 snd_iprintf(buffer,
1364 " Buffer size : %lu\n" 1371 " Buffer size : %lu\n"
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index b60cef257b58..f165c77d6273 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -26,6 +26,7 @@ MODULE_ALIAS("platform:pcspkr");
26static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ 26static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
27static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ 27static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
28static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */ 28static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
29static int nopcm; /* Disable PCM capability of the driver */
29 30
30module_param(index, int, 0444); 31module_param(index, int, 0444);
31MODULE_PARM_DESC(index, "Index value for pcsp soundcard."); 32MODULE_PARM_DESC(index, "Index value for pcsp soundcard.");
@@ -33,6 +34,8 @@ module_param(id, charp, 0444);
33MODULE_PARM_DESC(id, "ID string for pcsp soundcard."); 34MODULE_PARM_DESC(id, "ID string for pcsp soundcard.");
34module_param(enable, bool, 0444); 35module_param(enable, bool, 0444);
35MODULE_PARM_DESC(enable, "Enable PC-Speaker sound."); 36MODULE_PARM_DESC(enable, "Enable PC-Speaker sound.");
37module_param(nopcm, bool, 0444);
38MODULE_PARM_DESC(nopcm, "Disable PC-Speaker PCM sound. Only beeps remain.");
36 39
37struct snd_pcsp pcsp_chip; 40struct snd_pcsp pcsp_chip;
38 41
@@ -43,13 +46,16 @@ static int __devinit snd_pcsp_create(struct snd_card *card)
43 int err; 46 int err;
44 int div, min_div, order; 47 int div, min_div, order;
45 48
46 hrtimer_get_res(CLOCK_MONOTONIC, &tp); 49 if (!nopcm) {
47 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) { 50 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
48 printk(KERN_ERR "PCSP: Timer resolution is not sufficient " 51 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) {
49 "(%linS)\n", tp.tv_nsec); 52 printk(KERN_ERR "PCSP: Timer resolution is not sufficient "
50 printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI " 53 "(%linS)\n", tp.tv_nsec);
51 "enabled.\n"); 54 printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI "
52 return -EIO; 55 "enabled.\n");
56 printk(KERN_ERR "PCSP: Turned into nopcm mode.\n");
57 nopcm = 1;
58 }
53 } 59 }
54 60
55 if (loops_per_jiffy >= PCSP_MIN_LPJ && tp.tv_nsec <= PCSP_MIN_PERIOD_NS) 61 if (loops_per_jiffy >= PCSP_MIN_LPJ && tp.tv_nsec <= PCSP_MIN_PERIOD_NS)
@@ -107,12 +113,14 @@ static int __devinit snd_card_pcsp_probe(int devnum, struct device *dev)
107 snd_card_free(card); 113 snd_card_free(card);
108 return err; 114 return err;
109 } 115 }
110 err = snd_pcsp_new_pcm(&pcsp_chip); 116 if (!nopcm) {
111 if (err < 0) { 117 err = snd_pcsp_new_pcm(&pcsp_chip);
112 snd_card_free(card); 118 if (err < 0) {
113 return err; 119 snd_card_free(card);
120 return err;
121 }
114 } 122 }
115 err = snd_pcsp_new_mixer(&pcsp_chip); 123 err = snd_pcsp_new_mixer(&pcsp_chip, nopcm);
116 if (err < 0) { 124 if (err < 0) {
117 snd_card_free(card); 125 snd_card_free(card);
118 return err; 126 return err;
diff --git a/sound/drivers/pcsp/pcsp.h b/sound/drivers/pcsp/pcsp.h
index 174dd2ff0f22..1e123077923d 100644
--- a/sound/drivers/pcsp/pcsp.h
+++ b/sound/drivers/pcsp/pcsp.h
@@ -83,6 +83,6 @@ extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
83extern void pcsp_sync_stop(struct snd_pcsp *chip); 83extern void pcsp_sync_stop(struct snd_pcsp *chip);
84 84
85extern int snd_pcsp_new_pcm(struct snd_pcsp *chip); 85extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
86extern int snd_pcsp_new_mixer(struct snd_pcsp *chip); 86extern int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm);
87 87
88#endif 88#endif
diff --git a/sound/drivers/pcsp/pcsp_mixer.c b/sound/drivers/pcsp/pcsp_mixer.c
index 903bc846763f..6f633f4f3b96 100644
--- a/sound/drivers/pcsp/pcsp_mixer.c
+++ b/sound/drivers/pcsp/pcsp_mixer.c
@@ -119,24 +119,43 @@ static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
119 .put = pcsp_##ctl_type##_put, \ 119 .put = pcsp_##ctl_type##_put, \
120} 120}
121 121
122static struct snd_kcontrol_new __devinitdata snd_pcsp_controls[] = { 122static struct snd_kcontrol_new __devinitdata snd_pcsp_controls_pcm[] = {
123 PCSP_MIXER_CONTROL(enable, "Master Playback Switch"), 123 PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
124 PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"), 124 PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
125 PCSP_MIXER_CONTROL(pcspkr, "PC Speaker Playback Switch"),
126}; 125};
127 126
128int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip) 127static struct snd_kcontrol_new __devinitdata snd_pcsp_controls_spkr[] = {
128 PCSP_MIXER_CONTROL(pcspkr, "Beep Playback Switch"),
129};
130
131static int __devinit snd_pcsp_ctls_add(struct snd_pcsp *chip,
132 struct snd_kcontrol_new *ctls, int num)
129{ 133{
130 struct snd_card *card = chip->card;
131 int i, err; 134 int i, err;
135 struct snd_card *card = chip->card;
136 for (i = 0; i < num; i++) {
137 err = snd_ctl_add(card, snd_ctl_new1(ctls + i, chip));
138 if (err < 0)
139 return err;
140 }
141 return 0;
142}
143
144int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm)
145{
146 int err;
147 struct snd_card *card = chip->card;
132 148
133 for (i = 0; i < ARRAY_SIZE(snd_pcsp_controls); i++) { 149 if (!nopcm) {
134 err = snd_ctl_add(card, 150 err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_pcm,
135 snd_ctl_new1(snd_pcsp_controls + i, 151 ARRAY_SIZE(snd_pcsp_controls_pcm));
136 chip));
137 if (err < 0) 152 if (err < 0)
138 return err; 153 return err;
139 } 154 }
155 err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_spkr,
156 ARRAY_SIZE(snd_pcsp_controls_spkr));
157 if (err < 0)
158 return err;
140 159
141 strcpy(card->mixername, "PC-Speaker"); 160 strcpy(card->mixername, "PC-Speaker");
142 161
diff --git a/sound/i2c/cs8427.c b/sound/i2c/cs8427.c
index 020a5d512472..04ae8704cdcd 100644
--- a/sound/i2c/cs8427.c
+++ b/sound/i2c/cs8427.c
@@ -23,6 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/bitrev.h>
26#include <asm/unaligned.h> 27#include <asm/unaligned.h>
27#include <sound/core.h> 28#include <sound/core.h>
28#include <sound/control.h> 29#include <sound/control.h>
@@ -55,18 +56,6 @@ struct cs8427 {
55 struct cs8427_stream capture; 56 struct cs8427_stream capture;
56}; 57};
57 58
58static unsigned char swapbits(unsigned char val)
59{
60 int bit;
61 unsigned char res = 0;
62 for (bit = 0; bit < 8; bit++) {
63 res <<= 1;
64 res |= val & 1;
65 val >>= 1;
66 }
67 return res;
68}
69
70int snd_cs8427_reg_write(struct snd_i2c_device *device, unsigned char reg, 59int snd_cs8427_reg_write(struct snd_i2c_device *device, unsigned char reg,
71 unsigned char val) 60 unsigned char val)
72{ 61{
@@ -149,7 +138,7 @@ static int snd_cs8427_send_corudata(struct snd_i2c_device *device,
149 } 138 }
150 data[0] = CS8427_REG_AUTOINC | CS8427_REG_CORU_DATABUF; 139 data[0] = CS8427_REG_AUTOINC | CS8427_REG_CORU_DATABUF;
151 for (idx = 0; idx < count; idx++) 140 for (idx = 0; idx < count; idx++)
152 data[idx + 1] = swapbits(ndata[idx]); 141 data[idx + 1] = bitrev8(ndata[idx]);
153 if (snd_i2c_sendbytes(device, data, count + 1) != count + 1) 142 if (snd_i2c_sendbytes(device, data, count + 1) != count + 1)
154 return -EIO; 143 return -EIO;
155 return 1; 144 return 1;
diff --git a/sound/i2c/other/Makefile b/sound/i2c/other/Makefile
index 703d954238f4..2dad40f3f622 100644
--- a/sound/i2c/other/Makefile
+++ b/sound/i2c/other/Makefile
@@ -5,6 +5,7 @@
5 5
6snd-ak4114-objs := ak4114.o 6snd-ak4114-objs := ak4114.o
7snd-ak4117-objs := ak4117.o 7snd-ak4117-objs := ak4117.o
8snd-ak4113-objs := ak4113.o
8snd-ak4xxx-adda-objs := ak4xxx-adda.o 9snd-ak4xxx-adda-objs := ak4xxx-adda.o
9snd-pt2258-objs := pt2258.o 10snd-pt2258-objs := pt2258.o
10snd-tea575x-tuner-objs := tea575x-tuner.o 11snd-tea575x-tuner-objs := tea575x-tuner.o
@@ -12,5 +13,5 @@ snd-tea575x-tuner-objs := tea575x-tuner.o
12# Module Dependency 13# Module Dependency
13obj-$(CONFIG_SND_PDAUDIOCF) += snd-ak4117.o 14obj-$(CONFIG_SND_PDAUDIOCF) += snd-ak4117.o
14obj-$(CONFIG_SND_ICE1712) += snd-ak4xxx-adda.o 15obj-$(CONFIG_SND_ICE1712) += snd-ak4xxx-adda.o
15obj-$(CONFIG_SND_ICE1724) += snd-ak4114.o snd-ak4xxx-adda.o snd-pt2258.o 16obj-$(CONFIG_SND_ICE1724) += snd-ak4114.o snd-ak4113.o snd-ak4xxx-adda.o snd-pt2258.o
16obj-$(CONFIG_SND_FM801_TEA575X) += snd-tea575x-tuner.o 17obj-$(CONFIG_SND_FM801_TEA575X) += snd-tea575x-tuner.o
diff --git a/sound/i2c/other/ak4113.c b/sound/i2c/other/ak4113.c
new file mode 100644
index 000000000000..fff62cc8607c
--- /dev/null
+++ b/sound/i2c/other/ak4113.c
@@ -0,0 +1,639 @@
1/*
2 * Routines for control of the AK4113 via I2C/4-wire serial interface
3 * IEC958 (S/PDIF) receiver by Asahi Kasei
4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5 * Copyright (c) by Pavel Hofman <pavel.hofman@ivitera.com>
6 *
7 *
8 * 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
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <linux/slab.h>
25#include <linux/delay.h>
26#include <sound/core.h>
27#include <sound/control.h>
28#include <sound/pcm.h>
29#include <sound/ak4113.h>
30#include <sound/asoundef.h>
31#include <sound/info.h>
32
33MODULE_AUTHOR("Pavel Hofman <pavel.hofman@ivitera.com>");
34MODULE_DESCRIPTION("AK4113 IEC958 (S/PDIF) receiver by Asahi Kasei");
35MODULE_LICENSE("GPL");
36
37#define AK4113_ADDR 0x00 /* fixed address */
38
39static void ak4113_stats(struct work_struct *work);
40static void ak4113_init_regs(struct ak4113 *chip);
41
42
43static void reg_write(struct ak4113 *ak4113, unsigned char reg,
44 unsigned char val)
45{
46 ak4113->write(ak4113->private_data, reg, val);
47 if (reg < sizeof(ak4113->regmap))
48 ak4113->regmap[reg] = val;
49}
50
51static inline unsigned char reg_read(struct ak4113 *ak4113, unsigned char reg)
52{
53 return ak4113->read(ak4113->private_data, reg);
54}
55
56static void snd_ak4113_free(struct ak4113 *chip)
57{
58 chip->init = 1; /* don't schedule new work */
59 mb();
60 cancel_delayed_work(&chip->work);
61 flush_scheduled_work();
62 kfree(chip);
63}
64
65static int snd_ak4113_dev_free(struct snd_device *device)
66{
67 struct ak4113 *chip = device->device_data;
68 snd_ak4113_free(chip);
69 return 0;
70}
71
72int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,
73 ak4113_write_t *write, const unsigned char pgm[5],
74 void *private_data, struct ak4113 **r_ak4113)
75{
76 struct ak4113 *chip;
77 int err = 0;
78 unsigned char reg;
79 static struct snd_device_ops ops = {
80 .dev_free = snd_ak4113_dev_free,
81 };
82
83 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
84 if (chip == NULL)
85 return -ENOMEM;
86 spin_lock_init(&chip->lock);
87 chip->card = card;
88 chip->read = read;
89 chip->write = write;
90 chip->private_data = private_data;
91 INIT_DELAYED_WORK(&chip->work, ak4113_stats);
92
93 for (reg = 0; reg < AK4113_WRITABLE_REGS ; reg++)
94 chip->regmap[reg] = pgm[reg];
95 ak4113_init_regs(chip);
96
97 chip->rcs0 = reg_read(chip, AK4113_REG_RCS0) & ~(AK4113_QINT |
98 AK4113_CINT | AK4113_STC);
99 chip->rcs1 = reg_read(chip, AK4113_REG_RCS1);
100 chip->rcs2 = reg_read(chip, AK4113_REG_RCS2);
101 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
102 if (err < 0)
103 goto __fail;
104
105 if (r_ak4113)
106 *r_ak4113 = chip;
107 return 0;
108
109__fail:
110 snd_ak4113_free(chip);
111 return err < 0 ? err : -EIO;
112}
113EXPORT_SYMBOL_GPL(snd_ak4113_create);
114
115void snd_ak4113_reg_write(struct ak4113 *chip, unsigned char reg,
116 unsigned char mask, unsigned char val)
117{
118 if (reg >= AK4113_WRITABLE_REGS)
119 return;
120 reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val);
121}
122EXPORT_SYMBOL_GPL(snd_ak4113_reg_write);
123
124static void ak4113_init_regs(struct ak4113 *chip)
125{
126 unsigned char old = chip->regmap[AK4113_REG_PWRDN], reg;
127
128 /* bring the chip to reset state and powerdown state */
129 reg_write(chip, AK4113_REG_PWRDN, old & ~(AK4113_RST|AK4113_PWN));
130 udelay(200);
131 /* release reset, but leave powerdown */
132 reg_write(chip, AK4113_REG_PWRDN, (old | AK4113_RST) & ~AK4113_PWN);
133 udelay(200);
134 for (reg = 1; reg < AK4113_WRITABLE_REGS; reg++)
135 reg_write(chip, reg, chip->regmap[reg]);
136 /* release powerdown, everything is initialized now */
137 reg_write(chip, AK4113_REG_PWRDN, old | AK4113_RST | AK4113_PWN);
138}
139
140void snd_ak4113_reinit(struct ak4113 *chip)
141{
142 chip->init = 1;
143 mb();
144 flush_scheduled_work();
145 ak4113_init_regs(chip);
146 /* bring up statistics / event queing */
147 chip->init = 0;
148 if (chip->kctls[0])
149 schedule_delayed_work(&chip->work, HZ / 10);
150}
151EXPORT_SYMBOL_GPL(snd_ak4113_reinit);
152
153static unsigned int external_rate(unsigned char rcs1)
154{
155 switch (rcs1 & (AK4113_FS0|AK4113_FS1|AK4113_FS2|AK4113_FS3)) {
156 case AK4113_FS_8000HZ:
157 return 8000;
158 case AK4113_FS_11025HZ:
159 return 11025;
160 case AK4113_FS_16000HZ:
161 return 16000;
162 case AK4113_FS_22050HZ:
163 return 22050;
164 case AK4113_FS_24000HZ:
165 return 24000;
166 case AK4113_FS_32000HZ:
167 return 32000;
168 case AK4113_FS_44100HZ:
169 return 44100;
170 case AK4113_FS_48000HZ:
171 return 48000;
172 case AK4113_FS_64000HZ:
173 return 64000;
174 case AK4113_FS_88200HZ:
175 return 88200;
176 case AK4113_FS_96000HZ:
177 return 96000;
178 case AK4113_FS_176400HZ:
179 return 176400;
180 case AK4113_FS_192000HZ:
181 return 192000;
182 default:
183 return 0;
184 }
185}
186
187static int snd_ak4113_in_error_info(struct snd_kcontrol *kcontrol,
188 struct snd_ctl_elem_info *uinfo)
189{
190 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
191 uinfo->count = 1;
192 uinfo->value.integer.min = 0;
193 uinfo->value.integer.max = LONG_MAX;
194 return 0;
195}
196
197static int snd_ak4113_in_error_get(struct snd_kcontrol *kcontrol,
198 struct snd_ctl_elem_value *ucontrol)
199{
200 struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
201 long *ptr;
202
203 spin_lock_irq(&chip->lock);
204 ptr = (long *)(((char *)chip) + kcontrol->private_value);
205 ucontrol->value.integer.value[0] = *ptr;
206 *ptr = 0;
207 spin_unlock_irq(&chip->lock);
208 return 0;
209}
210
211#define snd_ak4113_in_bit_info snd_ctl_boolean_mono_info
212
213static int snd_ak4113_in_bit_get(struct snd_kcontrol *kcontrol,
214 struct snd_ctl_elem_value *ucontrol)
215{
216 struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
217 unsigned char reg = kcontrol->private_value & 0xff;
218 unsigned char bit = (kcontrol->private_value >> 8) & 0xff;
219 unsigned char inv = (kcontrol->private_value >> 31) & 1;
220
221 ucontrol->value.integer.value[0] =
222 ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv;
223 return 0;
224}
225
226static int snd_ak4113_rx_info(struct snd_kcontrol *kcontrol,
227 struct snd_ctl_elem_info *uinfo)
228{
229 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
230 uinfo->count = 1;
231 uinfo->value.integer.min = 0;
232 uinfo->value.integer.max = 5;
233 return 0;
234}
235
236static int snd_ak4113_rx_get(struct snd_kcontrol *kcontrol,
237 struct snd_ctl_elem_value *ucontrol)
238{
239 struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
240
241 ucontrol->value.integer.value[0] =
242 (AK4113_IPS(chip->regmap[AK4113_REG_IO1]));
243 return 0;
244}
245
246static int snd_ak4113_rx_put(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_value *ucontrol)
248{
249 struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
250 int change;
251 u8 old_val;
252
253 spin_lock_irq(&chip->lock);
254 old_val = chip->regmap[AK4113_REG_IO1];
255 change = ucontrol->value.integer.value[0] != AK4113_IPS(old_val);
256 if (change)
257 reg_write(chip, AK4113_REG_IO1,
258 (old_val & (~AK4113_IPS(0xff))) |
259 (AK4113_IPS(ucontrol->value.integer.value[0])));
260 spin_unlock_irq(&chip->lock);
261 return change;
262}
263
264static int snd_ak4113_rate_info(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_info *uinfo)
266{
267 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
268 uinfo->count = 1;
269 uinfo->value.integer.min = 0;
270 uinfo->value.integer.max = 192000;
271 return 0;
272}
273
274static int snd_ak4113_rate_get(struct snd_kcontrol *kcontrol,
275 struct snd_ctl_elem_value *ucontrol)
276{
277 struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
278
279 ucontrol->value.integer.value[0] = external_rate(reg_read(chip,
280 AK4113_REG_RCS1));
281 return 0;
282}
283
284static int snd_ak4113_spdif_info(struct snd_kcontrol *kcontrol,
285 struct snd_ctl_elem_info *uinfo)
286{
287 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
288 uinfo->count = 1;
289 return 0;
290}
291
292static int snd_ak4113_spdif_get(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
294{
295 struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
296 unsigned i;
297
298 for (i = 0; i < AK4113_REG_RXCSB_SIZE; i++)
299 ucontrol->value.iec958.status[i] = reg_read(chip,
300 AK4113_REG_RXCSB0 + i);
301 return 0;
302}
303
304static int snd_ak4113_spdif_mask_info(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_info *uinfo)
306{
307 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
308 uinfo->count = 1;
309 return 0;
310}
311
312static int snd_ak4113_spdif_mask_get(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol)
314{
315 memset(ucontrol->value.iec958.status, 0xff, AK4113_REG_RXCSB_SIZE);
316 return 0;
317}
318
319static int snd_ak4113_spdif_pinfo(struct snd_kcontrol *kcontrol,
320 struct snd_ctl_elem_info *uinfo)
321{
322 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
323 uinfo->value.integer.min = 0;
324 uinfo->value.integer.max = 0xffff;
325 uinfo->count = 4;
326 return 0;
327}
328
329static int snd_ak4113_spdif_pget(struct snd_kcontrol *kcontrol,
330 struct snd_ctl_elem_value *ucontrol)
331{
332 struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
333 unsigned short tmp;
334
335 ucontrol->value.integer.value[0] = 0xf8f2;
336 ucontrol->value.integer.value[1] = 0x4e1f;
337 tmp = reg_read(chip, AK4113_REG_Pc0) |
338 (reg_read(chip, AK4113_REG_Pc1) << 8);
339 ucontrol->value.integer.value[2] = tmp;
340 tmp = reg_read(chip, AK4113_REG_Pd0) |
341 (reg_read(chip, AK4113_REG_Pd1) << 8);
342 ucontrol->value.integer.value[3] = tmp;
343 return 0;
344}
345
346static int snd_ak4113_spdif_qinfo(struct snd_kcontrol *kcontrol,
347 struct snd_ctl_elem_info *uinfo)
348{
349 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
350 uinfo->count = AK4113_REG_QSUB_SIZE;
351 return 0;
352}
353
354static int snd_ak4113_spdif_qget(struct snd_kcontrol *kcontrol,
355 struct snd_ctl_elem_value *ucontrol)
356{
357 struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
358 unsigned i;
359
360 for (i = 0; i < AK4113_REG_QSUB_SIZE; i++)
361 ucontrol->value.bytes.data[i] = reg_read(chip,
362 AK4113_REG_QSUB_ADDR + i);
363 return 0;
364}
365
366/* Don't forget to change AK4113_CONTROLS define!!! */
367static struct snd_kcontrol_new snd_ak4113_iec958_controls[] = {
368{
369 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
370 .name = "IEC958 Parity Errors",
371 .access = SNDRV_CTL_ELEM_ACCESS_READ |
372 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
373 .info = snd_ak4113_in_error_info,
374 .get = snd_ak4113_in_error_get,
375 .private_value = offsetof(struct ak4113, parity_errors),
376},
377{
378 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
379 .name = "IEC958 V-Bit Errors",
380 .access = SNDRV_CTL_ELEM_ACCESS_READ |
381 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
382 .info = snd_ak4113_in_error_info,
383 .get = snd_ak4113_in_error_get,
384 .private_value = offsetof(struct ak4113, v_bit_errors),
385},
386{
387 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
388 .name = "IEC958 C-CRC Errors",
389 .access = SNDRV_CTL_ELEM_ACCESS_READ |
390 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
391 .info = snd_ak4113_in_error_info,
392 .get = snd_ak4113_in_error_get,
393 .private_value = offsetof(struct ak4113, ccrc_errors),
394},
395{
396 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
397 .name = "IEC958 Q-CRC Errors",
398 .access = SNDRV_CTL_ELEM_ACCESS_READ |
399 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
400 .info = snd_ak4113_in_error_info,
401 .get = snd_ak4113_in_error_get,
402 .private_value = offsetof(struct ak4113, qcrc_errors),
403},
404{
405 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
406 .name = "IEC958 External Rate",
407 .access = SNDRV_CTL_ELEM_ACCESS_READ |
408 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
409 .info = snd_ak4113_rate_info,
410 .get = snd_ak4113_rate_get,
411},
412{
413 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
414 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK),
415 .access = SNDRV_CTL_ELEM_ACCESS_READ,
416 .info = snd_ak4113_spdif_mask_info,
417 .get = snd_ak4113_spdif_mask_get,
418},
419{
420 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
421 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
422 .access = SNDRV_CTL_ELEM_ACCESS_READ |
423 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
424 .info = snd_ak4113_spdif_info,
425 .get = snd_ak4113_spdif_get,
426},
427{
428 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
429 .name = "IEC958 Preample Capture Default",
430 .access = SNDRV_CTL_ELEM_ACCESS_READ |
431 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
432 .info = snd_ak4113_spdif_pinfo,
433 .get = snd_ak4113_spdif_pget,
434},
435{
436 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
437 .name = "IEC958 Q-subcode Capture Default",
438 .access = SNDRV_CTL_ELEM_ACCESS_READ |
439 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
440 .info = snd_ak4113_spdif_qinfo,
441 .get = snd_ak4113_spdif_qget,
442},
443{
444 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
445 .name = "IEC958 Audio",
446 .access = SNDRV_CTL_ELEM_ACCESS_READ |
447 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
448 .info = snd_ak4113_in_bit_info,
449 .get = snd_ak4113_in_bit_get,
450 .private_value = (1<<31) | (1<<8) | AK4113_REG_RCS0,
451},
452{
453 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
454 .name = "IEC958 Non-PCM Bitstream",
455 .access = SNDRV_CTL_ELEM_ACCESS_READ |
456 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
457 .info = snd_ak4113_in_bit_info,
458 .get = snd_ak4113_in_bit_get,
459 .private_value = (0<<8) | AK4113_REG_RCS1,
460},
461{
462 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
463 .name = "IEC958 DTS Bitstream",
464 .access = SNDRV_CTL_ELEM_ACCESS_READ |
465 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
466 .info = snd_ak4113_in_bit_info,
467 .get = snd_ak4113_in_bit_get,
468 .private_value = (1<<8) | AK4113_REG_RCS1,
469},
470{
471 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
472 .name = "AK4113 Input Select",
473 .access = SNDRV_CTL_ELEM_ACCESS_READ |
474 SNDRV_CTL_ELEM_ACCESS_WRITE,
475 .info = snd_ak4113_rx_info,
476 .get = snd_ak4113_rx_get,
477 .put = snd_ak4113_rx_put,
478}
479};
480
481static void snd_ak4113_proc_regs_read(struct snd_info_entry *entry,
482 struct snd_info_buffer *buffer)
483{
484 struct ak4113 *ak4113 = entry->private_data;
485 int reg, val;
486 /* all ak4113 registers 0x00 - 0x1c */
487 for (reg = 0; reg < 0x1d; reg++) {
488 val = reg_read(ak4113, reg);
489 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
490 }
491}
492
493static void snd_ak4113_proc_init(struct ak4113 *ak4113)
494{
495 struct snd_info_entry *entry;
496 if (!snd_card_proc_new(ak4113->card, "ak4113", &entry))
497 snd_info_set_text_ops(entry, ak4113, snd_ak4113_proc_regs_read);
498}
499
500int snd_ak4113_build(struct ak4113 *ak4113,
501 struct snd_pcm_substream *cap_substream)
502{
503 struct snd_kcontrol *kctl;
504 unsigned int idx;
505 int err;
506
507 if (snd_BUG_ON(!cap_substream))
508 return -EINVAL;
509 ak4113->substream = cap_substream;
510 for (idx = 0; idx < AK4113_CONTROLS; idx++) {
511 kctl = snd_ctl_new1(&snd_ak4113_iec958_controls[idx], ak4113);
512 if (kctl == NULL)
513 return -ENOMEM;
514 kctl->id.device = cap_substream->pcm->device;
515 kctl->id.subdevice = cap_substream->number;
516 err = snd_ctl_add(ak4113->card, kctl);
517 if (err < 0)
518 return err;
519 ak4113->kctls[idx] = kctl;
520 }
521 snd_ak4113_proc_init(ak4113);
522 /* trigger workq */
523 schedule_delayed_work(&ak4113->work, HZ / 10);
524 return 0;
525}
526EXPORT_SYMBOL_GPL(snd_ak4113_build);
527
528int snd_ak4113_external_rate(struct ak4113 *ak4113)
529{
530 unsigned char rcs1;
531
532 rcs1 = reg_read(ak4113, AK4113_REG_RCS1);
533 return external_rate(rcs1);
534}
535EXPORT_SYMBOL_GPL(snd_ak4113_external_rate);
536
537int snd_ak4113_check_rate_and_errors(struct ak4113 *ak4113, unsigned int flags)
538{
539 struct snd_pcm_runtime *runtime =
540 ak4113->substream ? ak4113->substream->runtime : NULL;
541 unsigned long _flags;
542 int res = 0;
543 unsigned char rcs0, rcs1, rcs2;
544 unsigned char c0, c1;
545
546 rcs1 = reg_read(ak4113, AK4113_REG_RCS1);
547 if (flags & AK4113_CHECK_NO_STAT)
548 goto __rate;
549 rcs0 = reg_read(ak4113, AK4113_REG_RCS0);
550 rcs2 = reg_read(ak4113, AK4113_REG_RCS2);
551 spin_lock_irqsave(&ak4113->lock, _flags);
552 if (rcs0 & AK4113_PAR)
553 ak4113->parity_errors++;
554 if (rcs0 & AK4113_V)
555 ak4113->v_bit_errors++;
556 if (rcs2 & AK4113_CCRC)
557 ak4113->ccrc_errors++;
558 if (rcs2 & AK4113_QCRC)
559 ak4113->qcrc_errors++;
560 c0 = (ak4113->rcs0 & (AK4113_QINT | AK4113_CINT | AK4113_STC |
561 AK4113_AUDION | AK4113_AUTO | AK4113_UNLCK)) ^
562 (rcs0 & (AK4113_QINT | AK4113_CINT | AK4113_STC |
563 AK4113_AUDION | AK4113_AUTO | AK4113_UNLCK));
564 c1 = (ak4113->rcs1 & (AK4113_DTSCD | AK4113_NPCM | AK4113_PEM |
565 AK4113_DAT | 0xf0)) ^
566 (rcs1 & (AK4113_DTSCD | AK4113_NPCM | AK4113_PEM |
567 AK4113_DAT | 0xf0));
568 ak4113->rcs0 = rcs0 & ~(AK4113_QINT | AK4113_CINT | AK4113_STC);
569 ak4113->rcs1 = rcs1;
570 ak4113->rcs2 = rcs2;
571 spin_unlock_irqrestore(&ak4113->lock, _flags);
572
573 if (rcs0 & AK4113_PAR)
574 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
575 &ak4113->kctls[0]->id);
576 if (rcs0 & AK4113_V)
577 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
578 &ak4113->kctls[1]->id);
579 if (rcs2 & AK4113_CCRC)
580 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
581 &ak4113->kctls[2]->id);
582 if (rcs2 & AK4113_QCRC)
583 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
584 &ak4113->kctls[3]->id);
585
586 /* rate change */
587 if (c1 & 0xf0)
588 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
589 &ak4113->kctls[4]->id);
590
591 if ((c1 & AK4113_PEM) | (c0 & AK4113_CINT))
592 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
593 &ak4113->kctls[6]->id);
594 if (c0 & AK4113_QINT)
595 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
596 &ak4113->kctls[8]->id);
597
598 if (c0 & AK4113_AUDION)
599 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
600 &ak4113->kctls[9]->id);
601 if (c1 & AK4113_NPCM)
602 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
603 &ak4113->kctls[10]->id);
604 if (c1 & AK4113_DTSCD)
605 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
606 &ak4113->kctls[11]->id);
607
608 if (ak4113->change_callback && (c0 | c1) != 0)
609 ak4113->change_callback(ak4113, c0, c1);
610
611__rate:
612 /* compare rate */
613 res = external_rate(rcs1);
614 if (!(flags & AK4113_CHECK_NO_RATE) && runtime &&
615 (runtime->rate != res)) {
616 snd_pcm_stream_lock_irqsave(ak4113->substream, _flags);
617 if (snd_pcm_running(ak4113->substream)) {
618 /*printk(KERN_DEBUG "rate changed (%i <- %i)\n",
619 * runtime->rate, res); */
620 snd_pcm_stop(ak4113->substream,
621 SNDRV_PCM_STATE_DRAINING);
622 wake_up(&runtime->sleep);
623 res = 1;
624 }
625 snd_pcm_stream_unlock_irqrestore(ak4113->substream, _flags);
626 }
627 return res;
628}
629EXPORT_SYMBOL_GPL(snd_ak4113_check_rate_and_errors);
630
631static void ak4113_stats(struct work_struct *work)
632{
633 struct ak4113 *chip = container_of(work, struct ak4113, work.work);
634
635 if (!chip->init)
636 snd_ak4113_check_rate_and_errors(chip, chip->check_flags);
637
638 schedule_delayed_work(&chip->work, HZ / 10);
639}
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c
index ee47abab764e..1adb8a3c2b62 100644
--- a/sound/i2c/other/ak4xxx-adda.c
+++ b/sound/i2c/other/ak4xxx-adda.c
@@ -19,7 +19,7 @@
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * 21 *
22 */ 22 */
23 23
24#include <asm/io.h> 24#include <asm/io.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
@@ -29,6 +29,7 @@
29#include <sound/control.h> 29#include <sound/control.h>
30#include <sound/tlv.h> 30#include <sound/tlv.h>
31#include <sound/ak4xxx-adda.h> 31#include <sound/ak4xxx-adda.h>
32#include <sound/info.h>
32 33
33MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>"); 34MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>");
34MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters"); 35MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters");
@@ -52,26 +53,21 @@ EXPORT_SYMBOL(snd_akm4xxx_write);
52static void ak4524_reset(struct snd_akm4xxx *ak, int state) 53static void ak4524_reset(struct snd_akm4xxx *ak, int state)
53{ 54{
54 unsigned int chip; 55 unsigned int chip;
55 unsigned char reg, maxreg; 56 unsigned char reg;
56 57
57 if (ak->type == SND_AK4528)
58 maxreg = 0x06;
59 else
60 maxreg = 0x08;
61 for (chip = 0; chip < ak->num_dacs/2; chip++) { 58 for (chip = 0; chip < ak->num_dacs/2; chip++) {
62 snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03); 59 snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
63 if (state) 60 if (state)
64 continue; 61 continue;
65 /* DAC volumes */ 62 /* DAC volumes */
66 for (reg = 0x04; reg < maxreg; reg++) 63 for (reg = 0x04; reg < ak->total_regs; reg++)
67 snd_akm4xxx_write(ak, chip, reg, 64 snd_akm4xxx_write(ak, chip, reg,
68 snd_akm4xxx_get(ak, chip, reg)); 65 snd_akm4xxx_get(ak, chip, reg));
69 } 66 }
70} 67}
71 68
72/* reset procedure for AK4355 and AK4358 */ 69/* reset procedure for AK4355 and AK4358 */
73static void ak435X_reset(struct snd_akm4xxx *ak, int state, 70static void ak435X_reset(struct snd_akm4xxx *ak, int state)
74 unsigned char total_regs)
75{ 71{
76 unsigned char reg; 72 unsigned char reg;
77 73
@@ -79,7 +75,7 @@ static void ak435X_reset(struct snd_akm4xxx *ak, int state,
79 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */ 75 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
80 return; 76 return;
81 } 77 }
82 for (reg = 0x00; reg < total_regs; reg++) 78 for (reg = 0x00; reg < ak->total_regs; reg++)
83 if (reg != 0x01) 79 if (reg != 0x01)
84 snd_akm4xxx_write(ak, 0, reg, 80 snd_akm4xxx_write(ak, 0, reg,
85 snd_akm4xxx_get(ak, 0, reg)); 81 snd_akm4xxx_get(ak, 0, reg));
@@ -91,12 +87,11 @@ static void ak4381_reset(struct snd_akm4xxx *ak, int state)
91{ 87{
92 unsigned int chip; 88 unsigned int chip;
93 unsigned char reg; 89 unsigned char reg;
94
95 for (chip = 0; chip < ak->num_dacs/2; chip++) { 90 for (chip = 0; chip < ak->num_dacs/2; chip++) {
96 snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f); 91 snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
97 if (state) 92 if (state)
98 continue; 93 continue;
99 for (reg = 0x01; reg < 0x05; reg++) 94 for (reg = 0x01; reg < ak->total_regs; reg++)
100 snd_akm4xxx_write(ak, chip, reg, 95 snd_akm4xxx_write(ak, chip, reg,
101 snd_akm4xxx_get(ak, chip, reg)); 96 snd_akm4xxx_get(ak, chip, reg));
102 } 97 }
@@ -113,16 +108,17 @@ void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
113 switch (ak->type) { 108 switch (ak->type) {
114 case SND_AK4524: 109 case SND_AK4524:
115 case SND_AK4528: 110 case SND_AK4528:
111 case SND_AK4620:
116 ak4524_reset(ak, state); 112 ak4524_reset(ak, state);
117 break; 113 break;
118 case SND_AK4529: 114 case SND_AK4529:
119 /* FIXME: needed for ak4529? */ 115 /* FIXME: needed for ak4529? */
120 break; 116 break;
121 case SND_AK4355: 117 case SND_AK4355:
122 ak435X_reset(ak, state, 0x0b); 118 ak435X_reset(ak, state);
123 break; 119 break;
124 case SND_AK4358: 120 case SND_AK4358:
125 ak435X_reset(ak, state, 0x10); 121 ak435X_reset(ak, state);
126 break; 122 break;
127 case SND_AK4381: 123 case SND_AK4381:
128 ak4381_reset(ak, state); 124 ak4381_reset(ak, state);
@@ -139,7 +135,7 @@ EXPORT_SYMBOL(snd_akm4xxx_reset);
139 * Volume conversion table for non-linear volumes 135 * Volume conversion table for non-linear volumes
140 * from -63.5dB (mute) to 0dB step 0.5dB 136 * from -63.5dB (mute) to 0dB step 0.5dB
141 * 137 *
142 * Used for AK4524 input/ouput attenuation, AK4528, and 138 * Used for AK4524/AK4620 input/ouput attenuation, AK4528, and
143 * AK5365 input attenuation 139 * AK5365 input attenuation
144 */ 140 */
145static const unsigned char vol_cvt_datt[128] = { 141static const unsigned char vol_cvt_datt[128] = {
@@ -259,8 +255,22 @@ void snd_akm4xxx_init(struct snd_akm4xxx *ak)
259 0x00, 0x0f, /* 0: power-up, un-reset */ 255 0x00, 0x0f, /* 0: power-up, un-reset */
260 0xff, 0xff 256 0xff, 0xff
261 }; 257 };
258 static const unsigned char inits_ak4620[] = {
259 0x00, 0x07, /* 0: normal */
260 0x01, 0x00, /* 0: reset */
261 0x01, 0x02, /* 1: RSTAD */
262 0x01, 0x03, /* 1: RSTDA */
263 0x01, 0x0f, /* 1: normal */
264 0x02, 0x60, /* 2: 24bit I2S */
265 0x03, 0x01, /* 3: deemphasis off */
266 0x04, 0x00, /* 4: LIN muted */
267 0x05, 0x00, /* 5: RIN muted */
268 0x06, 0x00, /* 6: LOUT muted */
269 0x07, 0x00, /* 7: ROUT muted */
270 0xff, 0xff
271 };
262 272
263 int chip, num_chips; 273 int chip;
264 const unsigned char *ptr, *inits; 274 const unsigned char *ptr, *inits;
265 unsigned char reg, data; 275 unsigned char reg, data;
266 276
@@ -270,42 +280,64 @@ void snd_akm4xxx_init(struct snd_akm4xxx *ak)
270 switch (ak->type) { 280 switch (ak->type) {
271 case SND_AK4524: 281 case SND_AK4524:
272 inits = inits_ak4524; 282 inits = inits_ak4524;
273 num_chips = ak->num_dacs / 2; 283 ak->num_chips = ak->num_dacs / 2;
284 ak->name = "ak4524";
285 ak->total_regs = 0x08;
274 break; 286 break;
275 case SND_AK4528: 287 case SND_AK4528:
276 inits = inits_ak4528; 288 inits = inits_ak4528;
277 num_chips = ak->num_dacs / 2; 289 ak->num_chips = ak->num_dacs / 2;
290 ak->name = "ak4528";
291 ak->total_regs = 0x06;
278 break; 292 break;
279 case SND_AK4529: 293 case SND_AK4529:
280 inits = inits_ak4529; 294 inits = inits_ak4529;
281 num_chips = 1; 295 ak->num_chips = 1;
296 ak->name = "ak4529";
297 ak->total_regs = 0x0d;
282 break; 298 break;
283 case SND_AK4355: 299 case SND_AK4355:
284 inits = inits_ak4355; 300 inits = inits_ak4355;
285 num_chips = 1; 301 ak->num_chips = 1;
302 ak->name = "ak4355";
303 ak->total_regs = 0x0b;
286 break; 304 break;
287 case SND_AK4358: 305 case SND_AK4358:
288 inits = inits_ak4358; 306 inits = inits_ak4358;
289 num_chips = 1; 307 ak->num_chips = 1;
308 ak->name = "ak4358";
309 ak->total_regs = 0x10;
290 break; 310 break;
291 case SND_AK4381: 311 case SND_AK4381:
292 inits = inits_ak4381; 312 inits = inits_ak4381;
293 num_chips = ak->num_dacs / 2; 313 ak->num_chips = ak->num_dacs / 2;
314 ak->name = "ak4381";
315 ak->total_regs = 0x05;
294 break; 316 break;
295 case SND_AK5365: 317 case SND_AK5365:
296 /* FIXME: any init sequence? */ 318 /* FIXME: any init sequence? */
319 ak->num_chips = 1;
320 ak->name = "ak5365";
321 ak->total_regs = 0x08;
297 return; 322 return;
323 case SND_AK4620:
324 inits = inits_ak4620;
325 ak->num_chips = ak->num_dacs / 2;
326 ak->name = "ak4620";
327 ak->total_regs = 0x08;
328 break;
298 default: 329 default:
299 snd_BUG(); 330 snd_BUG();
300 return; 331 return;
301 } 332 }
302 333
303 for (chip = 0; chip < num_chips; chip++) { 334 for (chip = 0; chip < ak->num_chips; chip++) {
304 ptr = inits; 335 ptr = inits;
305 while (*ptr != 0xff) { 336 while (*ptr != 0xff) {
306 reg = *ptr++; 337 reg = *ptr++;
307 data = *ptr++; 338 data = *ptr++;
308 snd_akm4xxx_write(ak, chip, reg, data); 339 snd_akm4xxx_write(ak, chip, reg, data);
340 udelay(10);
309 } 341 }
310 } 342 }
311} 343}
@@ -688,6 +720,12 @@ static int build_dac_controls(struct snd_akm4xxx *ak)
688 AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); 720 AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255);
689 knew.tlv.p = db_scale_linear; 721 knew.tlv.p = db_scale_linear;
690 break; 722 break;
723 case SND_AK4620:
724 /* register 6 & 7 */
725 knew.private_value =
726 AK_COMPOSE(idx/2, (idx%2) + 6, 0, 255);
727 knew.tlv.p = db_scale_linear;
728 break;
691 default: 729 default:
692 return -EINVAL; 730 return -EINVAL;
693 } 731 }
@@ -704,10 +742,12 @@ static int build_dac_controls(struct snd_akm4xxx *ak)
704 742
705static int build_adc_controls(struct snd_akm4xxx *ak) 743static int build_adc_controls(struct snd_akm4xxx *ak)
706{ 744{
707 int idx, err, mixer_ch, num_stereo; 745 int idx, err, mixer_ch, num_stereo, max_steps;
708 struct snd_kcontrol_new knew; 746 struct snd_kcontrol_new knew;
709 747
710 mixer_ch = 0; 748 mixer_ch = 0;
749 if (ak->type == SND_AK4528)
750 return 0; /* no controls */
711 for (idx = 0; idx < ak->num_adcs;) { 751 for (idx = 0; idx < ak->num_adcs;) {
712 memset(&knew, 0, sizeof(knew)); 752 memset(&knew, 0, sizeof(knew));
713 if (! ak->adc_info || ! ak->adc_info[mixer_ch].name) { 753 if (! ak->adc_info || ! ak->adc_info[mixer_ch].name) {
@@ -733,13 +773,12 @@ static int build_adc_controls(struct snd_akm4xxx *ak)
733 } 773 }
734 /* register 4 & 5 */ 774 /* register 4 & 5 */
735 if (ak->type == SND_AK5365) 775 if (ak->type == SND_AK5365)
736 knew.private_value = 776 max_steps = 152;
737 AK_COMPOSE(idx/2, (idx%2) + 4, 0, 151) |
738 AK_VOL_CVT | AK_IPGA;
739 else 777 else
740 knew.private_value = 778 max_steps = 164;
741 AK_COMPOSE(idx/2, (idx%2) + 4, 0, 163) | 779 knew.private_value =
742 AK_VOL_CVT | AK_IPGA; 780 AK_COMPOSE(idx/2, (idx%2) + 4, 0, max_steps) |
781 AK_VOL_CVT | AK_IPGA;
743 knew.tlv.p = db_scale_vol_datt; 782 knew.tlv.p = db_scale_vol_datt;
744 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); 783 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
745 if (err < 0) 784 if (err < 0)
@@ -808,6 +847,7 @@ static int build_deemphasis(struct snd_akm4xxx *ak, int num_emphs)
808 switch (ak->type) { 847 switch (ak->type) {
809 case SND_AK4524: 848 case SND_AK4524:
810 case SND_AK4528: 849 case SND_AK4528:
850 case SND_AK4620:
811 /* register 3 */ 851 /* register 3 */
812 knew.private_value = AK_COMPOSE(idx, 3, 0, 0); 852 knew.private_value = AK_COMPOSE(idx, 3, 0, 0);
813 break; 853 break;
@@ -834,6 +874,35 @@ static int build_deemphasis(struct snd_akm4xxx *ak, int num_emphs)
834 return 0; 874 return 0;
835} 875}
836 876
877#ifdef CONFIG_PROC_FS
878static void proc_regs_read(struct snd_info_entry *entry,
879 struct snd_info_buffer *buffer)
880{
881 struct snd_akm4xxx *ak = (struct snd_akm4xxx *)entry->private_data;
882 int reg, val, chip;
883 for (chip = 0; chip < ak->num_chips; chip++) {
884 for (reg = 0; reg < ak->total_regs; reg++) {
885 val = snd_akm4xxx_get(ak, chip, reg);
886 snd_iprintf(buffer, "chip %d: 0x%02x = 0x%02x\n", chip,
887 reg, val);
888 }
889 }
890}
891
892static int proc_init(struct snd_akm4xxx *ak)
893{
894 struct snd_info_entry *entry;
895 int err;
896 err = snd_card_proc_new(ak->card, ak->name, &entry);
897 if (err < 0)
898 return err;
899 snd_info_set_text_ops(entry, ak, proc_regs_read);
900 return 0;
901}
902#else /* !CONFIG_PROC_FS */
903static int proc_init(struct snd_akm4xxx *ak) {}
904#endif
905
837int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak) 906int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak)
838{ 907{
839 int err, num_emphs; 908 int err, num_emphs;
@@ -845,18 +914,21 @@ int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak)
845 err = build_adc_controls(ak); 914 err = build_adc_controls(ak);
846 if (err < 0) 915 if (err < 0)
847 return err; 916 return err;
848
849 if (ak->type == SND_AK4355 || ak->type == SND_AK4358) 917 if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
850 num_emphs = 1; 918 num_emphs = 1;
919 else if (ak->type == SND_AK4620)
920 num_emphs = 0;
851 else 921 else
852 num_emphs = ak->num_dacs / 2; 922 num_emphs = ak->num_dacs / 2;
853 err = build_deemphasis(ak, num_emphs); 923 err = build_deemphasis(ak, num_emphs);
854 if (err < 0) 924 if (err < 0)
855 return err; 925 return err;
926 err = proc_init(ak);
927 if (err < 0)
928 return err;
856 929
857 return 0; 930 return 0;
858} 931}
859
860EXPORT_SYMBOL(snd_akm4xxx_build_controls); 932EXPORT_SYMBOL(snd_akm4xxx_build_controls);
861 933
862static int __init alsa_akm4xxx_module_init(void) 934static int __init alsa_akm4xxx_module_init(void)
diff --git a/sound/i2c/other/tea575x-tuner.c b/sound/i2c/other/tea575x-tuner.c
index d31c373e076d..c4c6ef73f9bf 100644
--- a/sound/i2c/other/tea575x-tuner.c
+++ b/sound/i2c/other/tea575x-tuner.c
@@ -225,7 +225,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
225 case V4L2_CID_AUDIO_MUTE: 225 case V4L2_CID_AUDIO_MUTE:
226 if (tea->ops->mute) { 226 if (tea->ops->mute) {
227 tea->ops->mute(tea, ctrl->value); 227 tea->ops->mute(tea, ctrl->value);
228 tea->mute = 1; 228 tea->mute = ctrl->value;
229 return 0; 229 return 0;
230 } 230 }
231 } 231 }
diff --git a/sound/isa/Kconfig b/sound/isa/Kconfig
index 51a7e3777e17..02fe81ca88fd 100644
--- a/sound/isa/Kconfig
+++ b/sound/isa/Kconfig
@@ -372,15 +372,21 @@ config SND_SGALAXY
372 372
373config SND_SSCAPE 373config SND_SSCAPE
374 tristate "Ensoniq SoundScape driver" 374 tristate "Ensoniq SoundScape driver"
375 select SND_HWDEP
376 select SND_MPU401_UART 375 select SND_MPU401_UART
377 select SND_WSS_LIB 376 select SND_WSS_LIB
377 select FW_LOADER
378 help 378 help
379 Say Y here to include support for Ensoniq SoundScape 379 Say Y here to include support for Ensoniq SoundScape
380 soundcards. 380 and Ensoniq OEM soundcards.
381 381
382 The PCM audio is supported on SoundScape Classic, Elite, PnP 382 The PCM audio is supported on SoundScape Classic, Elite, PnP
383 and VIVO cards. The MIDI support is very experimental. 383 and VIVO cards. The supported OEM cards are SPEA Media FX and
384 Reveal SC-600.
385 The MIDI support is very experimental and requires binary
386 firmware files called "scope.cod" and "sndscape.co?" where the
387 ? is digit 0, 1, 2, 3 or 4. The firmware files can be found
388 in DOS or Windows driver packages. One has to put the firmware
389 files into the /lib/firmware directory.
384 390
385 To compile this driver as a module, choose M here: the module 391 To compile this driver as a module, choose M here: the module
386 will be called snd-sscape. 392 will be called snd-sscape.
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
index 02f79d252718..8246aae32ab4 100644
--- a/sound/isa/cmi8330.c
+++ b/sound/isa/cmi8330.c
@@ -237,7 +237,7 @@ WSS_DOUBLE("Wavetable Capture Volume", 0,
237 CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0), 237 CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0),
238WSS_SINGLE("3D Control - Switch", 0, 238WSS_SINGLE("3D Control - Switch", 0,
239 CMI8330_RMUX3D, 5, 1, 1), 239 CMI8330_RMUX3D, 5, 1, 1),
240WSS_SINGLE("PC Speaker Playback Volume", 0, 240WSS_SINGLE("Beep Playback Volume", 0,
241 CMI8330_OUTPUTVOL, 3, 3, 0), 241 CMI8330_OUTPUTVOL, 3, 3, 0),
242WSS_DOUBLE("FM Playback Switch", 0, 242WSS_DOUBLE("FM Playback Switch", 0,
243 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), 243 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
@@ -262,7 +262,7 @@ SB_DOUBLE("SB Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3,
262SB_DOUBLE("SB Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31), 262SB_DOUBLE("SB Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
263SB_SINGLE("SB Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1), 263SB_SINGLE("SB Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
264SB_SINGLE("SB Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31), 264SB_SINGLE("SB Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
265SB_SINGLE("SB PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3), 265SB_SINGLE("SB Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
266SB_DOUBLE("SB Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3), 266SB_DOUBLE("SB Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
267SB_DOUBLE("SB Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3), 267SB_DOUBLE("SB Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
268SB_SINGLE("SB Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1), 268SB_SINGLE("SB Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1),
diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c
index a076a6ce8071..cc15d1d65a22 100644
--- a/sound/isa/cs423x/cs4236.c
+++ b/sound/isa/cs423x/cs4236.c
@@ -177,7 +177,7 @@ static struct pnp_card_device_id snd_cs423x_pnpids[] = {
177 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, 177 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
178 /* Digital PC 5000 Onboard - CS4236B */ 178 /* Digital PC 5000 Onboard - CS4236B */
179 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } }, 179 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
180 /* some uknown CS4236B */ 180 /* some unknown CS4236B */
181 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, 181 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
182 /* Intel PR440FX Onboard sound */ 182 /* Intel PR440FX Onboard sound */
183 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, 183 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
@@ -394,21 +394,15 @@ static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
394 return -EBUSY; 394 return -EBUSY;
395 } 395 }
396 396
397 err = snd_wss_create(card, port[dev], cport[dev], 397 err = snd_cs4236_create(card, port[dev], cport[dev],
398 irq[dev], 398 irq[dev],
399 dma1[dev], dma2[dev], 399 dma1[dev], dma2[dev],
400 WSS_HW_DETECT3, 0, &chip); 400 WSS_HW_DETECT3, 0, &chip);
401 if (err < 0) 401 if (err < 0)
402 return err; 402 return err;
403
404 acard->chip = chip;
403 if (chip->hardware & WSS_HW_CS4236B_MASK) { 405 if (chip->hardware & WSS_HW_CS4236B_MASK) {
404 snd_wss_free(chip);
405 err = snd_cs4236_create(card,
406 port[dev], cport[dev],
407 irq[dev], dma1[dev], dma2[dev],
408 WSS_HW_DETECT, 0, &chip);
409 if (err < 0)
410 return err;
411 acard->chip = chip;
412 406
413 err = snd_cs4236_pcm(chip, 0, &pcm); 407 err = snd_cs4236_pcm(chip, 0, &pcm);
414 if (err < 0) 408 if (err < 0)
@@ -418,7 +412,6 @@ static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
418 if (err < 0) 412 if (err < 0)
419 return err; 413 return err;
420 } else { 414 } else {
421 acard->chip = chip;
422 err = snd_wss_pcm(chip, 0, &pcm); 415 err = snd_wss_pcm(chip, 0, &pcm);
423 if (err < 0) 416 if (err < 0)
424 return err; 417 return err;
diff --git a/sound/isa/cs423x/cs4236_lib.c b/sound/isa/cs423x/cs4236_lib.c
index 38835f31298b..c5adca300632 100644
--- a/sound/isa/cs423x/cs4236_lib.c
+++ b/sound/isa/cs423x/cs4236_lib.c
@@ -87,6 +87,8 @@
87#include <sound/core.h> 87#include <sound/core.h>
88#include <sound/wss.h> 88#include <sound/wss.h>
89#include <sound/asoundef.h> 89#include <sound/asoundef.h>
90#include <sound/initval.h>
91#include <sound/tlv.h>
90 92
91/* 93/*
92 * 94 *
@@ -264,7 +266,10 @@ static void snd_cs4236_resume(struct snd_wss *chip)
264} 266}
265 267
266#endif /* CONFIG_PM */ 268#endif /* CONFIG_PM */
267 269/*
270 * This function does no fail if the chip is not CS4236B or compatible.
271 * It just an equivalent to the snd_wss_create() then.
272 */
268int snd_cs4236_create(struct snd_card *card, 273int snd_cs4236_create(struct snd_card *card,
269 unsigned long port, 274 unsigned long port,
270 unsigned long cport, 275 unsigned long cport,
@@ -281,21 +286,17 @@ int snd_cs4236_create(struct snd_card *card,
281 *rchip = NULL; 286 *rchip = NULL;
282 if (hardware == WSS_HW_DETECT) 287 if (hardware == WSS_HW_DETECT)
283 hardware = WSS_HW_DETECT3; 288 hardware = WSS_HW_DETECT3;
284 if (cport < 0x100) { 289
285 snd_printk(KERN_ERR "please, specify control port "
286 "for CS4236+ chips\n");
287 return -ENODEV;
288 }
289 err = snd_wss_create(card, port, cport, 290 err = snd_wss_create(card, port, cport,
290 irq, dma1, dma2, hardware, hwshare, &chip); 291 irq, dma1, dma2, hardware, hwshare, &chip);
291 if (err < 0) 292 if (err < 0)
292 return err; 293 return err;
293 294
294 if (!(chip->hardware & WSS_HW_CS4236B_MASK)) { 295 if ((chip->hardware & WSS_HW_CS4236B_MASK) == 0) {
295 snd_printk(KERN_ERR "CS4236+: MODE3 and extended registers " 296 snd_printd("chip is not CS4236+, hardware=0x%x\n",
296 "not available, hardware=0x%x\n", chip->hardware); 297 chip->hardware);
297 snd_device_free(card, chip); 298 *rchip = chip;
298 return -ENODEV; 299 return 0;
299 } 300 }
300#if 0 301#if 0
301 { 302 {
@@ -308,9 +309,16 @@ int snd_cs4236_create(struct snd_card *card,
308 idx, snd_cs4236_ctrl_in(chip, idx)); 309 idx, snd_cs4236_ctrl_in(chip, idx));
309 } 310 }
310#endif 311#endif
312 if (cport < 0x100 || cport == SNDRV_AUTO_PORT) {
313 snd_printk(KERN_ERR "please, specify control port "
314 "for CS4236+ chips\n");
315 snd_device_free(card, chip);
316 return -ENODEV;
317 }
311 ver1 = snd_cs4236_ctrl_in(chip, 1); 318 ver1 = snd_cs4236_ctrl_in(chip, 1);
312 ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION); 319 ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION);
313 snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2); 320 snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n",
321 cport, ver1, ver2);
314 if (ver1 != ver2) { 322 if (ver1 != ver2) {
315 snd_printk(KERN_ERR "CS4236+ chip detected, but " 323 snd_printk(KERN_ERR "CS4236+ chip detected, but "
316 "control port 0x%lx is not valid\n", cport); 324 "control port 0x%lx is not valid\n", cport);
@@ -321,13 +329,17 @@ int snd_cs4236_create(struct snd_card *card,
321 snd_cs4236_ctrl_out(chip, 2, 0xff); 329 snd_cs4236_ctrl_out(chip, 2, 0xff);
322 snd_cs4236_ctrl_out(chip, 3, 0x00); 330 snd_cs4236_ctrl_out(chip, 3, 0x00);
323 snd_cs4236_ctrl_out(chip, 4, 0x80); 331 snd_cs4236_ctrl_out(chip, 4, 0x80);
324 snd_cs4236_ctrl_out(chip, 5, ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE); 332 reg = ((IEC958_AES1_CON_PCM_CODER & 3) << 6) |
333 IEC958_AES0_CON_EMPHASIS_NONE;
334 snd_cs4236_ctrl_out(chip, 5, reg);
325 snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2); 335 snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2);
326 snd_cs4236_ctrl_out(chip, 7, 0x00); 336 snd_cs4236_ctrl_out(chip, 7, 0x00);
327 /* 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 output */ 337 /*
328 /* is working with this setup, other hardware should have */ 338 * 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958
329 /* different signal paths and this value should be selectable */ 339 * output is working with this setup, other hardware should
330 /* in the future */ 340 * have different signal paths and this value should be
341 * selectable in the future
342 */
331 snd_cs4236_ctrl_out(chip, 8, 0x8c); 343 snd_cs4236_ctrl_out(chip, 8, 0x8c);
332 chip->rate_constraint = snd_cs4236_xrate; 344 chip->rate_constraint = snd_cs4236_xrate;
333 chip->set_playback_format = snd_cs4236_playback_format; 345 chip->set_playback_format = snd_cs4236_playback_format;
@@ -339,9 +351,10 @@ int snd_cs4236_create(struct snd_card *card,
339 351
340 /* initialize extended registers */ 352 /* initialize extended registers */
341 for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++) 353 for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++)
342 snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]); 354 snd_cs4236_ext_out(chip, CS4236_I23VAL(reg),
355 snd_cs4236_ext_map[reg]);
343 356
344 /* initialize compatible but more featured registers */ 357 /* initialize compatible but more featured registers */
345 snd_wss_out(chip, CS4231_LEFT_INPUT, 0x40); 358 snd_wss_out(chip, CS4231_LEFT_INPUT, 0x40);
346 snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x40); 359 snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x40);
347 snd_wss_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff); 360 snd_wss_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff);
@@ -387,6 +400,14 @@ int snd_cs4236_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm)
387 .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \ 400 .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \
388 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } 401 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
389 402
403#define CS4236_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \
404{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
405 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
406 .info = snd_cs4236_info_single, \
407 .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \
408 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
409 .tlv = { .p = (xtlv) } }
410
390static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 411static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
391{ 412{
392 int mask = (kcontrol->private_value >> 16) & 0xff; 413 int mask = (kcontrol->private_value >> 16) & 0xff;
@@ -490,6 +511,16 @@ static int snd_cs4236_put_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_
490 .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \ 511 .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \
491 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } 512 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
492 513
514#define CS4236_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, \
515 shift_right, mask, invert, xtlv) \
516{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
517 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
518 .info = snd_cs4236_info_double, \
519 .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \
520 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | \
521 (shift_right << 19) | (mask << 24) | (invert << 22), \
522 .tlv = { .p = (xtlv) } }
523
493static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 524static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
494{ 525{
495 int mask = (kcontrol->private_value >> 24) & 0xff; 526 int mask = (kcontrol->private_value >> 24) & 0xff;
@@ -560,12 +591,23 @@ static int snd_cs4236_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_e
560 return change; 591 return change;
561} 592}
562 593
563#define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ 594#define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, \
595 shift_right, mask, invert) \
564{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 596{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
565 .info = snd_cs4236_info_double, \ 597 .info = snd_cs4236_info_double, \
566 .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \ 598 .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \
567 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } 599 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
568 600
601#define CS4236_DOUBLE1_TLV(xname, xindex, left_reg, right_reg, shift_left, \
602 shift_right, mask, invert, xtlv) \
603{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
604 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
605 .info = snd_cs4236_info_double, \
606 .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \
607 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | \
608 (shift_right << 19) | (mask << 24) | (invert << 22), \
609 .tlv = { .p = (xtlv) } }
610
569static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 611static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
570{ 612{
571 struct snd_wss *chip = snd_kcontrol_chip(kcontrol); 613 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
@@ -619,16 +661,18 @@ static int snd_cs4236_put_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_
619 return change; 661 return change;
620} 662}
621 663
622#define CS4236_MASTER_DIGITAL(xname, xindex) \ 664#define CS4236_MASTER_DIGITAL(xname, xindex, xtlv) \
623{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 665{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
666 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
624 .info = snd_cs4236_info_double, \ 667 .info = snd_cs4236_info_double, \
625 .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \ 668 .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \
626 .private_value = 71 << 24 } 669 .private_value = 71 << 24, \
670 .tlv = { .p = (xtlv) } }
627 671
628static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol) 672static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol)
629{ 673{
630 return (vol < 64) ? 63 - vol : 64 + (71 - vol); 674 return (vol < 64) ? 63 - vol : 64 + (71 - vol);
631} 675}
632 676
633static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 677static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
634{ 678{
@@ -661,11 +705,13 @@ static int snd_cs4236_put_master_digital(struct snd_kcontrol *kcontrol, struct s
661 return change; 705 return change;
662} 706}
663 707
664#define CS4235_OUTPUT_ACCU(xname, xindex) \ 708#define CS4235_OUTPUT_ACCU(xname, xindex, xtlv) \
665{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 709{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
710 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
666 .info = snd_cs4236_info_double, \ 711 .info = snd_cs4236_info_double, \
667 .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \ 712 .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \
668 .private_value = 3 << 24 } 713 .private_value = 3 << 24, \
714 .tlv = { .p = (xtlv) } }
669 715
670static inline int snd_cs4235_mixer_output_accu_get_volume(int vol) 716static inline int snd_cs4235_mixer_output_accu_get_volume(int vol)
671{ 717{
@@ -720,41 +766,56 @@ static int snd_cs4235_put_output_accu(struct snd_kcontrol *kcontrol, struct snd_
720 return change; 766 return change;
721} 767}
722 768
769static const DECLARE_TLV_DB_SCALE(db_scale_7bit, -9450, 150, 0);
770static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
771static const DECLARE_TLV_DB_SCALE(db_scale_6bit_12db_max, -8250, 150, 0);
772static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
773static const DECLARE_TLV_DB_SCALE(db_scale_5bit_22db_max, -2400, 150, 0);
774static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0);
775static const DECLARE_TLV_DB_SCALE(db_scale_2bit, -1800, 600, 0);
776static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
777
723static struct snd_kcontrol_new snd_cs4236_controls[] = { 778static struct snd_kcontrol_new snd_cs4236_controls[] = {
724 779
725CS4236_DOUBLE("Master Digital Playback Switch", 0, 780CS4236_DOUBLE("Master Digital Playback Switch", 0,
726 CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1), 781 CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
727CS4236_DOUBLE("Master Digital Capture Switch", 0, 782CS4236_DOUBLE("Master Digital Capture Switch", 0,
728 CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1), 783 CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
729CS4236_MASTER_DIGITAL("Master Digital Volume", 0), 784CS4236_MASTER_DIGITAL("Master Digital Volume", 0, db_scale_7bit),
730 785
731CS4236_DOUBLE("Capture Boost Volume", 0, 786CS4236_DOUBLE_TLV("Capture Boost Volume", 0,
732 CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1), 787 CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1,
788 db_scale_2bit),
733 789
734WSS_DOUBLE("PCM Playback Switch", 0, 790WSS_DOUBLE("PCM Playback Switch", 0,
735 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), 791 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
736WSS_DOUBLE("PCM Playback Volume", 0, 792WSS_DOUBLE_TLV("PCM Playback Volume", 0,
737 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), 793 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1,
794 db_scale_6bit),
738 795
739CS4236_DOUBLE("DSP Playback Switch", 0, 796CS4236_DOUBLE("DSP Playback Switch", 0,
740 CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), 797 CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
741CS4236_DOUBLE("DSP Playback Volume", 0, 798CS4236_DOUBLE_TLV("DSP Playback Volume", 0,
742 CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1), 799 CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1,
800 db_scale_6bit),
743 801
744CS4236_DOUBLE("FM Playback Switch", 0, 802CS4236_DOUBLE("FM Playback Switch", 0,
745 CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1), 803 CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
746CS4236_DOUBLE("FM Playback Volume", 0, 804CS4236_DOUBLE_TLV("FM Playback Volume", 0,
747 CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1), 805 CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1,
806 db_scale_6bit),
748 807
749CS4236_DOUBLE("Wavetable Playback Switch", 0, 808CS4236_DOUBLE("Wavetable Playback Switch", 0,
750 CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1), 809 CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
751CS4236_DOUBLE("Wavetable Playback Volume", 0, 810CS4236_DOUBLE_TLV("Wavetable Playback Volume", 0,
752 CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1), 811 CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1,
812 db_scale_6bit_12db_max),
753 813
754WSS_DOUBLE("Synth Playback Switch", 0, 814WSS_DOUBLE("Synth Playback Switch", 0,
755 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), 815 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
756WSS_DOUBLE("Synth Volume", 0, 816WSS_DOUBLE_TLV("Synth Volume", 0,
757 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), 817 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1,
818 db_scale_5bit_12db_max),
758WSS_DOUBLE("Synth Capture Switch", 0, 819WSS_DOUBLE("Synth Capture Switch", 0,
759 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), 820 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
760WSS_DOUBLE("Synth Capture Bypass", 0, 821WSS_DOUBLE("Synth Capture Bypass", 0,
@@ -764,14 +825,16 @@ CS4236_DOUBLE("Mic Playback Switch", 0,
764 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), 825 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
765CS4236_DOUBLE("Mic Capture Switch", 0, 826CS4236_DOUBLE("Mic Capture Switch", 0,
766 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), 827 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
767CS4236_DOUBLE("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1), 828CS4236_DOUBLE_TLV("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC,
768CS4236_DOUBLE("Mic Playback Boost", 0, 829 0, 0, 31, 1, db_scale_5bit_22db_max),
830CS4236_DOUBLE("Mic Playback Boost (+20dB)", 0,
769 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0), 831 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0),
770 832
771WSS_DOUBLE("Line Playback Switch", 0, 833WSS_DOUBLE("Line Playback Switch", 0,
772 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), 834 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
773WSS_DOUBLE("Line Volume", 0, 835WSS_DOUBLE_TLV("Line Volume", 0,
774 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), 836 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
837 db_scale_5bit_12db_max),
775WSS_DOUBLE("Line Capture Switch", 0, 838WSS_DOUBLE("Line Capture Switch", 0,
776 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), 839 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
777WSS_DOUBLE("Line Capture Bypass", 0, 840WSS_DOUBLE("Line Capture Bypass", 0,
@@ -779,57 +842,63 @@ WSS_DOUBLE("Line Capture Bypass", 0,
779 842
780WSS_DOUBLE("CD Playback Switch", 0, 843WSS_DOUBLE("CD Playback Switch", 0,
781 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), 844 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
782WSS_DOUBLE("CD Volume", 0, 845WSS_DOUBLE_TLV("CD Volume", 0,
783 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), 846 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
847 db_scale_5bit_12db_max),
784WSS_DOUBLE("CD Capture Switch", 0, 848WSS_DOUBLE("CD Capture Switch", 0,
785 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), 849 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
786 850
787CS4236_DOUBLE1("Mono Output Playback Switch", 0, 851CS4236_DOUBLE1("Mono Output Playback Switch", 0,
788 CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1), 852 CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
789CS4236_DOUBLE1("Mono Playback Switch", 0, 853CS4236_DOUBLE1("Beep Playback Switch", 0,
790 CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), 854 CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
791WSS_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), 855WSS_SINGLE_TLV("Beep Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1,
792WSS_SINGLE("Mono Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0), 856 db_scale_4bit),
857WSS_SINGLE("Beep Bypass Playback Switch", 0, CS4231_MONO_CTRL, 5, 1, 0),
793 858
794WSS_DOUBLE("Capture Volume", 0, 859WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT,
795 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0), 860 0, 0, 15, 0, db_scale_rec_gain),
796WSS_DOUBLE("Analog Loopback Capture Switch", 0, 861WSS_DOUBLE("Analog Loopback Capture Switch", 0,
797 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), 862 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
798 863
799WSS_SINGLE("Digital Loopback Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0), 864WSS_SINGLE("Loopback Digital Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
800CS4236_DOUBLE1("Digital Loopback Playback Volume", 0, 865CS4236_DOUBLE1_TLV("Loopback Digital Playback Volume", 0,
801 CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1) 866 CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1,
867 db_scale_6bit),
802}; 868};
803 869
870static const DECLARE_TLV_DB_SCALE(db_scale_5bit_6db_max, -5600, 200, 0);
871static const DECLARE_TLV_DB_SCALE(db_scale_2bit_16db_max, -2400, 800, 0);
872
804static struct snd_kcontrol_new snd_cs4235_controls[] = { 873static struct snd_kcontrol_new snd_cs4235_controls[] = {
805 874
806WSS_DOUBLE("Master Switch", 0, 875WSS_DOUBLE("Master Playback Switch", 0,
807 CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1), 876 CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1),
808WSS_DOUBLE("Master Volume", 0, 877WSS_DOUBLE_TLV("Master Playback Volume", 0,
809 CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1), 878 CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1,
810 879 db_scale_5bit_6db_max),
811CS4235_OUTPUT_ACCU("Playback Volume", 0),
812 880
813CS4236_DOUBLE("Master Digital Playback Switch", 0, 881CS4235_OUTPUT_ACCU("Playback Volume", 0, db_scale_2bit_16db_max),
814 CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
815CS4236_DOUBLE("Master Digital Capture Switch", 0,
816 CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
817CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
818 882
819WSS_DOUBLE("Master Digital Playback Switch", 1, 883WSS_DOUBLE("Synth Playback Switch", 1,
820 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), 884 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
821WSS_DOUBLE("Master Digital Capture Switch", 1, 885WSS_DOUBLE("Synth Capture Switch", 1,
822 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), 886 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
823WSS_DOUBLE("Master Digital Volume", 1, 887WSS_DOUBLE_TLV("Synth Volume", 1,
824 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), 888 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1,
889 db_scale_5bit_12db_max),
825 890
826CS4236_DOUBLE("Capture Volume", 0, 891CS4236_DOUBLE_TLV("Capture Volume", 0,
827 CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1), 892 CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1,
893 db_scale_2bit),
828 894
829WSS_DOUBLE("PCM Switch", 0, 895WSS_DOUBLE("PCM Playback Switch", 0,
830 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), 896 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
831WSS_DOUBLE("PCM Volume", 0, 897WSS_DOUBLE("PCM Capture Switch", 0,
832 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), 898 CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
899WSS_DOUBLE_TLV("PCM Volume", 0,
900 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1,
901 db_scale_6bit),
833 902
834CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), 903CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
835 904
@@ -842,29 +911,29 @@ CS4236_DOUBLE("Mic Capture Switch", 0,
842 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), 911 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
843CS4236_DOUBLE("Mic Playback Switch", 0, 912CS4236_DOUBLE("Mic Playback Switch", 0,
844 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), 913 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
845CS4236_SINGLE("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1), 914CS4236_SINGLE_TLV("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1,
846CS4236_SINGLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, 5, 1, 0), 915 db_scale_5bit_22db_max),
916CS4236_SINGLE("Mic Boost (+20dB)", 0, CS4236_LEFT_MIC, 5, 1, 0),
847 917
848WSS_DOUBLE("Aux Playback Switch", 0, 918WSS_DOUBLE("Line Playback Switch", 0,
849 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), 919 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
850WSS_DOUBLE("Aux Capture Switch", 0, 920WSS_DOUBLE("Line Capture Switch", 0,
851 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), 921 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
852WSS_DOUBLE("Aux Volume", 0, 922WSS_DOUBLE_TLV("Line Volume", 0,
853 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), 923 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
924 db_scale_5bit_12db_max),
854 925
855WSS_DOUBLE("Aux Playback Switch", 1, 926WSS_DOUBLE("CD Playback Switch", 1,
856 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), 927 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
857WSS_DOUBLE("Aux Capture Switch", 1, 928WSS_DOUBLE("CD Capture Switch", 1,
858 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), 929 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
859WSS_DOUBLE("Aux Volume", 1, 930WSS_DOUBLE_TLV("CD Volume", 1,
860 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), 931 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
861 932 db_scale_5bit_12db_max),
862CS4236_DOUBLE1("Master Mono Switch", 0,
863 CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
864 933
865CS4236_DOUBLE1("Mono Switch", 0, 934CS4236_DOUBLE1("Beep Playback Switch", 0,
866 CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), 935 CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
867WSS_SINGLE("Mono Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), 936WSS_SINGLE("Beep Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
868 937
869WSS_DOUBLE("Analog Loopback Switch", 0, 938WSS_DOUBLE("Analog Loopback Switch", 0,
870 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), 939 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c
index 4c6e14f87f2d..c76bb00c9d15 100644
--- a/sound/isa/es1688/es1688_lib.c
+++ b/sound/isa/es1688/es1688_lib.c
@@ -982,7 +982,7 @@ ES1688_DOUBLE("CD Playback Volume", 0, ES1688_CD_DEV, ES1688_CD_DEV, 4, 0, 15, 0
982ES1688_DOUBLE("FM Playback Volume", 0, ES1688_FM_DEV, ES1688_FM_DEV, 4, 0, 15, 0), 982ES1688_DOUBLE("FM Playback Volume", 0, ES1688_FM_DEV, ES1688_FM_DEV, 4, 0, 15, 0),
983ES1688_DOUBLE("Mic Playback Volume", 0, ES1688_MIC_DEV, ES1688_MIC_DEV, 4, 0, 15, 0), 983ES1688_DOUBLE("Mic Playback Volume", 0, ES1688_MIC_DEV, ES1688_MIC_DEV, 4, 0, 15, 0),
984ES1688_DOUBLE("Aux Playback Volume", 0, ES1688_AUX_DEV, ES1688_AUX_DEV, 4, 0, 15, 0), 984ES1688_DOUBLE("Aux Playback Volume", 0, ES1688_AUX_DEV, ES1688_AUX_DEV, 4, 0, 15, 0),
985ES1688_SINGLE("PC Speaker Playback Volume", 0, ES1688_SPEAKER_DEV, 0, 7, 0), 985ES1688_SINGLE("Beep Playback Volume", 0, ES1688_SPEAKER_DEV, 0, 7, 0),
986ES1688_DOUBLE("Capture Volume", 0, ES1688_RECLEV_DEV, ES1688_RECLEV_DEV, 4, 0, 15, 0), 986ES1688_DOUBLE("Capture Volume", 0, ES1688_RECLEV_DEV, ES1688_RECLEV_DEV, 4, 0, 15, 0),
987ES1688_SINGLE("Capture Switch", 0, ES1688_REC_DEV, 4, 1, 1), 987ES1688_SINGLE("Capture Switch", 0, ES1688_REC_DEV, 4, 1, 1),
988{ 988{
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index 8cfbff73a835..9a43baae7250 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -102,8 +102,6 @@
102 102
103struct snd_es18xx { 103struct snd_es18xx {
104 unsigned long port; /* port of ESS chip */ 104 unsigned long port; /* port of ESS chip */
105 unsigned long mpu_port; /* MPU-401 port of ESS chip */
106 unsigned long fm_port; /* FM port */
107 unsigned long ctrl_port; /* Control port of ESS chip */ 105 unsigned long ctrl_port; /* Control port of ESS chip */
108 struct resource *res_port; 106 struct resource *res_port;
109 struct resource *res_mpu_port; 107 struct resource *res_mpu_port;
@@ -116,12 +114,9 @@ struct snd_es18xx {
116 unsigned short audio2_vol; /* volume level of audio2 */ 114 unsigned short audio2_vol; /* volume level of audio2 */
117 115
118 unsigned short active; /* active channel mask */ 116 unsigned short active; /* active channel mask */
119 unsigned int dma1_size;
120 unsigned int dma2_size;
121 unsigned int dma1_shift; 117 unsigned int dma1_shift;
122 unsigned int dma2_shift; 118 unsigned int dma2_shift;
123 119
124 struct snd_card *card;
125 struct snd_pcm *pcm; 120 struct snd_pcm *pcm;
126 struct snd_pcm_substream *playback_a_substream; 121 struct snd_pcm_substream *playback_a_substream;
127 struct snd_pcm_substream *capture_a_substream; 122 struct snd_pcm_substream *capture_a_substream;
@@ -136,14 +131,9 @@ struct snd_es18xx {
136 131
137 spinlock_t reg_lock; 132 spinlock_t reg_lock;
138 spinlock_t mixer_lock; 133 spinlock_t mixer_lock;
139 spinlock_t ctrl_lock;
140#ifdef CONFIG_PM 134#ifdef CONFIG_PM
141 unsigned char pm_reg; 135 unsigned char pm_reg;
142#endif 136#endif
143};
144
145struct snd_audiodrive {
146 struct snd_es18xx *chip;
147#ifdef CONFIG_PNP 137#ifdef CONFIG_PNP
148 struct pnp_dev *dev; 138 struct pnp_dev *dev;
149 struct pnp_dev *devc; 139 struct pnp_dev *devc;
@@ -359,7 +349,7 @@ static inline int snd_es18xx_mixer_writable(struct snd_es18xx *chip, unsigned ch
359} 349}
360 350
361 351
362static int snd_es18xx_reset(struct snd_es18xx *chip) 352static int __devinit snd_es18xx_reset(struct snd_es18xx *chip)
363{ 353{
364 int i; 354 int i;
365 outb(0x03, chip->port + 0x06); 355 outb(0x03, chip->port + 0x06);
@@ -495,8 +485,6 @@ static int snd_es18xx_playback1_prepare(struct snd_es18xx *chip,
495 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 485 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
496 unsigned int count = snd_pcm_lib_period_bytes(substream); 486 unsigned int count = snd_pcm_lib_period_bytes(substream);
497 487
498 chip->dma2_size = size;
499
500 snd_es18xx_rate_set(chip, substream, DAC2); 488 snd_es18xx_rate_set(chip, substream, DAC2);
501 489
502 /* Transfer Count Reload */ 490 /* Transfer Count Reload */
@@ -596,8 +584,6 @@ static int snd_es18xx_capture_prepare(struct snd_pcm_substream *substream)
596 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 584 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
597 unsigned int count = snd_pcm_lib_period_bytes(substream); 585 unsigned int count = snd_pcm_lib_period_bytes(substream);
598 586
599 chip->dma1_size = size;
600
601 snd_es18xx_reset_fifo(chip); 587 snd_es18xx_reset_fifo(chip);
602 588
603 /* Set stereo/mono */ 589 /* Set stereo/mono */
@@ -664,8 +650,6 @@ static int snd_es18xx_playback2_prepare(struct snd_es18xx *chip,
664 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 650 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
665 unsigned int count = snd_pcm_lib_period_bytes(substream); 651 unsigned int count = snd_pcm_lib_period_bytes(substream);
666 652
667 chip->dma1_size = size;
668
669 snd_es18xx_reset_fifo(chip); 653 snd_es18xx_reset_fifo(chip);
670 654
671 /* Set stereo/mono */ 655 /* Set stereo/mono */
@@ -755,7 +739,8 @@ static int snd_es18xx_playback_trigger(struct snd_pcm_substream *substream,
755 739
756static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id) 740static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
757{ 741{
758 struct snd_es18xx *chip = dev_id; 742 struct snd_card *card = dev_id;
743 struct snd_es18xx *chip = card->private_data;
759 unsigned char status; 744 unsigned char status;
760 745
761 if (chip->caps & ES18XX_CONTROL) { 746 if (chip->caps & ES18XX_CONTROL) {
@@ -805,12 +790,16 @@ static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
805 int split = 0; 790 int split = 0;
806 if (chip->caps & ES18XX_HWV) { 791 if (chip->caps & ES18XX_HWV) {
807 split = snd_es18xx_mixer_read(chip, 0x64) & 0x80; 792 split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
808 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id); 793 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
809 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id); 794 &chip->hw_switch->id);
795 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
796 &chip->hw_volume->id);
810 } 797 }
811 if (!split) { 798 if (!split) {
812 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id); 799 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
813 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id); 800 &chip->master_switch->id);
801 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
802 &chip->master_volume->id);
814 } 803 }
815 /* ack interrupt */ 804 /* ack interrupt */
816 snd_es18xx_mixer_write(chip, 0x66, 0x00); 805 snd_es18xx_mixer_write(chip, 0x66, 0x00);
@@ -821,17 +810,18 @@ static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
821static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream) 810static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream)
822{ 811{
823 struct snd_es18xx *chip = snd_pcm_substream_chip(substream); 812 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
813 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
824 int pos; 814 int pos;
825 815
826 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { 816 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
827 if (!(chip->active & DAC2)) 817 if (!(chip->active & DAC2))
828 return 0; 818 return 0;
829 pos = snd_dma_pointer(chip->dma2, chip->dma2_size); 819 pos = snd_dma_pointer(chip->dma2, size);
830 return pos >> chip->dma2_shift; 820 return pos >> chip->dma2_shift;
831 } else { 821 } else {
832 if (!(chip->active & DAC1)) 822 if (!(chip->active & DAC1))
833 return 0; 823 return 0;
834 pos = snd_dma_pointer(chip->dma1, chip->dma1_size); 824 pos = snd_dma_pointer(chip->dma1, size);
835 return pos >> chip->dma1_shift; 825 return pos >> chip->dma1_shift;
836 } 826 }
837} 827}
@@ -839,11 +829,12 @@ static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *s
839static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream) 829static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream)
840{ 830{
841 struct snd_es18xx *chip = snd_pcm_substream_chip(substream); 831 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
832 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
842 int pos; 833 int pos;
843 834
844 if (!(chip->active & ADC1)) 835 if (!(chip->active & ADC1))
845 return 0; 836 return 0;
846 pos = snd_dma_pointer(chip->dma1, chip->dma1_size); 837 pos = snd_dma_pointer(chip->dma1, size);
847 return pos >> chip->dma1_shift; 838 return pos >> chip->dma1_shift;
848} 839}
849 840
@@ -974,9 +965,6 @@ static int snd_es18xx_capture_close(struct snd_pcm_substream *substream)
974 965
975static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 966static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
976{ 967{
977 static char *texts4Source[4] = {
978 "Mic", "CD", "Line", "Master"
979 };
980 static char *texts5Source[5] = { 968 static char *texts5Source[5] = {
981 "Mic", "CD", "Line", "Master", "Mix" 969 "Mic", "CD", "Line", "Master", "Mix"
982 }; 970 };
@@ -994,7 +982,8 @@ static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
994 uinfo->value.enumerated.items = 4; 982 uinfo->value.enumerated.items = 4;
995 if (uinfo->value.enumerated.item > 3) 983 if (uinfo->value.enumerated.item > 3)
996 uinfo->value.enumerated.item = 3; 984 uinfo->value.enumerated.item = 3;
997 strcpy(uinfo->value.enumerated.name, texts4Source[uinfo->value.enumerated.item]); 985 strcpy(uinfo->value.enumerated.name,
986 texts5Source[uinfo->value.enumerated.item]);
998 break; 987 break;
999 case 0x1887: 988 case 0x1887:
1000 case 0x1888: 989 case 0x1888:
@@ -1313,7 +1302,7 @@ ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1313 * The chipset specific mixer controls 1302 * The chipset specific mixer controls
1314 */ 1303 */
1315static struct snd_kcontrol_new snd_es18xx_opt_speaker = 1304static struct snd_kcontrol_new snd_es18xx_opt_speaker =
1316 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0); 1305 ES18XX_SINGLE("Beep Playback Volume", 0, 0x3c, 0, 7, 0);
1317 1306
1318static struct snd_kcontrol_new snd_es18xx_opt_1869[] = { 1307static struct snd_kcontrol_new snd_es18xx_opt_1869[] = {
1319ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), 1308ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
@@ -1378,11 +1367,9 @@ ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1378static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg) 1367static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg)
1379{ 1368{
1380 int data; 1369 int data;
1381 unsigned long flags; 1370
1382 spin_lock_irqsave(&chip->ctrl_lock, flags);
1383 outb(reg, chip->ctrl_port); 1371 outb(reg, chip->ctrl_port);
1384 data = inb(chip->ctrl_port + 1); 1372 data = inb(chip->ctrl_port + 1);
1385 spin_unlock_irqrestore(&chip->ctrl_lock, flags);
1386 return data; 1373 return data;
1387} 1374}
1388 1375
@@ -1398,7 +1385,9 @@ static void __devinit snd_es18xx_config_write(struct snd_es18xx *chip,
1398#endif 1385#endif
1399} 1386}
1400 1387
1401static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip) 1388static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip,
1389 unsigned long mpu_port,
1390 unsigned long fm_port)
1402{ 1391{
1403 int mask = 0; 1392 int mask = 0;
1404 1393
@@ -1412,15 +1401,15 @@ static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
1412 if (chip->caps & ES18XX_CONTROL) { 1401 if (chip->caps & ES18XX_CONTROL) {
1413 /* Hardware volume IRQ */ 1402 /* Hardware volume IRQ */
1414 snd_es18xx_config_write(chip, 0x27, chip->irq); 1403 snd_es18xx_config_write(chip, 0x27, chip->irq);
1415 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { 1404 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
1416 /* FM I/O */ 1405 /* FM I/O */
1417 snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8); 1406 snd_es18xx_config_write(chip, 0x62, fm_port >> 8);
1418 snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff); 1407 snd_es18xx_config_write(chip, 0x63, fm_port & 0xff);
1419 } 1408 }
1420 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { 1409 if (mpu_port > 0 && mpu_port != SNDRV_AUTO_PORT) {
1421 /* MPU-401 I/O */ 1410 /* MPU-401 I/O */
1422 snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8); 1411 snd_es18xx_config_write(chip, 0x64, mpu_port >> 8);
1423 snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff); 1412 snd_es18xx_config_write(chip, 0x65, mpu_port & 0xff);
1424 /* MPU-401 IRQ */ 1413 /* MPU-401 IRQ */
1425 snd_es18xx_config_write(chip, 0x28, chip->irq); 1414 snd_es18xx_config_write(chip, 0x28, chip->irq);
1426 } 1415 }
@@ -1507,11 +1496,12 @@ static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
1507 snd_es18xx_mixer_write(chip, 0x7A, 0x68); 1496 snd_es18xx_mixer_write(chip, 0x7A, 0x68);
1508 /* Enable and set hardware volume interrupt */ 1497 /* Enable and set hardware volume interrupt */
1509 snd_es18xx_mixer_write(chip, 0x64, 0x06); 1498 snd_es18xx_mixer_write(chip, 0x64, 0x06);
1510 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { 1499 if (mpu_port > 0 && mpu_port != SNDRV_AUTO_PORT) {
1511 /* MPU401 share irq with audio 1500 /* MPU401 share irq with audio
1512 Joystick enabled 1501 Joystick enabled
1513 FM enabled */ 1502 FM enabled */
1514 snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1); 1503 snd_es18xx_mixer_write(chip, 0x40,
1504 0x43 | (mpu_port & 0xf0) >> 1);
1515 } 1505 }
1516 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01); 1506 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01);
1517 } 1507 }
@@ -1629,7 +1619,9 @@ static int __devinit snd_es18xx_identify(struct snd_es18xx *chip)
1629 return 0; 1619 return 0;
1630} 1620}
1631 1621
1632static int __devinit snd_es18xx_probe(struct snd_es18xx *chip) 1622static int __devinit snd_es18xx_probe(struct snd_es18xx *chip,
1623 unsigned long mpu_port,
1624 unsigned long fm_port)
1633{ 1625{
1634 if (snd_es18xx_identify(chip) < 0) { 1626 if (snd_es18xx_identify(chip) < 0) {
1635 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port); 1627 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
@@ -1650,8 +1642,6 @@ static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
1650 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV; 1642 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
1651 break; 1643 break;
1652 case 0x1887: 1644 case 0x1887:
1653 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
1654 break;
1655 case 0x1888: 1645 case 0x1888:
1656 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME; 1646 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
1657 break; 1647 break;
@@ -1666,7 +1656,7 @@ static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
1666 if (chip->dma1 == chip->dma2) 1656 if (chip->dma1 == chip->dma2)
1667 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME); 1657 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME);
1668 1658
1669 return snd_es18xx_initialize(chip); 1659 return snd_es18xx_initialize(chip, mpu_port, fm_port);
1670} 1660}
1671 1661
1672static struct snd_pcm_ops snd_es18xx_playback_ops = { 1662static struct snd_pcm_ops snd_es18xx_playback_ops = {
@@ -1691,8 +1681,10 @@ static struct snd_pcm_ops snd_es18xx_capture_ops = {
1691 .pointer = snd_es18xx_capture_pointer, 1681 .pointer = snd_es18xx_capture_pointer,
1692}; 1682};
1693 1683
1694static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct snd_pcm ** rpcm) 1684static int __devinit snd_es18xx_pcm(struct snd_card *card, int device,
1685 struct snd_pcm **rpcm)
1695{ 1686{
1687 struct snd_es18xx *chip = card->private_data;
1696 struct snd_pcm *pcm; 1688 struct snd_pcm *pcm;
1697 char str[16]; 1689 char str[16];
1698 int err; 1690 int err;
@@ -1701,9 +1693,9 @@ static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct
1701 *rpcm = NULL; 1693 *rpcm = NULL;
1702 sprintf(str, "ES%x", chip->version); 1694 sprintf(str, "ES%x", chip->version);
1703 if (chip->caps & ES18XX_PCM2) 1695 if (chip->caps & ES18XX_PCM2)
1704 err = snd_pcm_new(chip->card, str, device, 2, 1, &pcm); 1696 err = snd_pcm_new(card, str, device, 2, 1, &pcm);
1705 else 1697 else
1706 err = snd_pcm_new(chip->card, str, device, 1, 1, &pcm); 1698 err = snd_pcm_new(card, str, device, 1, 1, &pcm);
1707 if (err < 0) 1699 if (err < 0)
1708 return err; 1700 return err;
1709 1701
@@ -1734,10 +1726,9 @@ static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct
1734#ifdef CONFIG_PM 1726#ifdef CONFIG_PM
1735static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state) 1727static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
1736{ 1728{
1737 struct snd_audiodrive *acard = card->private_data; 1729 struct snd_es18xx *chip = card->private_data;
1738 struct snd_es18xx *chip = acard->chip;
1739 1730
1740 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); 1731 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1741 1732
1742 snd_pcm_suspend_all(chip->pcm); 1733 snd_pcm_suspend_all(chip->pcm);
1743 1734
@@ -1752,24 +1743,25 @@ static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
1752 1743
1753static int snd_es18xx_resume(struct snd_card *card) 1744static int snd_es18xx_resume(struct snd_card *card)
1754{ 1745{
1755 struct snd_audiodrive *acard = card->private_data; 1746 struct snd_es18xx *chip = card->private_data;
1756 struct snd_es18xx *chip = acard->chip;
1757 1747
1758 /* restore PM register, we won't wake till (not 0x07) i/o activity though */ 1748 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1759 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM); 1749 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
1760 1750
1761 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); 1751 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1762 return 0; 1752 return 0;
1763} 1753}
1764#endif /* CONFIG_PM */ 1754#endif /* CONFIG_PM */
1765 1755
1766static int snd_es18xx_free(struct snd_es18xx *chip) 1756static int snd_es18xx_free(struct snd_card *card)
1767{ 1757{
1758 struct snd_es18xx *chip = card->private_data;
1759
1768 release_and_free_resource(chip->res_port); 1760 release_and_free_resource(chip->res_port);
1769 release_and_free_resource(chip->res_ctrl_port); 1761 release_and_free_resource(chip->res_ctrl_port);
1770 release_and_free_resource(chip->res_mpu_port); 1762 release_and_free_resource(chip->res_mpu_port);
1771 if (chip->irq >= 0) 1763 if (chip->irq >= 0)
1772 free_irq(chip->irq, (void *) chip); 1764 free_irq(chip->irq, (void *) card);
1773 if (chip->dma1 >= 0) { 1765 if (chip->dma1 >= 0) {
1774 disable_dma(chip->dma1); 1766 disable_dma(chip->dma1);
1775 free_dma(chip->dma1); 1767 free_dma(chip->dma1);
@@ -1778,93 +1770,82 @@ static int snd_es18xx_free(struct snd_es18xx *chip)
1778 disable_dma(chip->dma2); 1770 disable_dma(chip->dma2);
1779 free_dma(chip->dma2); 1771 free_dma(chip->dma2);
1780 } 1772 }
1781 kfree(chip);
1782 return 0; 1773 return 0;
1783} 1774}
1784 1775
1785static int snd_es18xx_dev_free(struct snd_device *device) 1776static int snd_es18xx_dev_free(struct snd_device *device)
1786{ 1777{
1787 struct snd_es18xx *chip = device->device_data; 1778 return snd_es18xx_free(device->card);
1788 return snd_es18xx_free(chip);
1789} 1779}
1790 1780
1791static int __devinit snd_es18xx_new_device(struct snd_card *card, 1781static int __devinit snd_es18xx_new_device(struct snd_card *card,
1792 unsigned long port, 1782 unsigned long port,
1793 unsigned long mpu_port, 1783 unsigned long mpu_port,
1794 unsigned long fm_port, 1784 unsigned long fm_port,
1795 int irq, int dma1, int dma2, 1785 int irq, int dma1, int dma2)
1796 struct snd_es18xx ** rchip)
1797{ 1786{
1798 struct snd_es18xx *chip; 1787 struct snd_es18xx *chip = card->private_data;
1799 static struct snd_device_ops ops = { 1788 static struct snd_device_ops ops = {
1800 .dev_free = snd_es18xx_dev_free, 1789 .dev_free = snd_es18xx_dev_free,
1801 }; 1790 };
1802 int err; 1791 int err;
1803 1792
1804 *rchip = NULL;
1805 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1806 if (chip == NULL)
1807 return -ENOMEM;
1808 spin_lock_init(&chip->reg_lock); 1793 spin_lock_init(&chip->reg_lock);
1809 spin_lock_init(&chip->mixer_lock); 1794 spin_lock_init(&chip->mixer_lock);
1810 spin_lock_init(&chip->ctrl_lock);
1811 chip->card = card;
1812 chip->port = port; 1795 chip->port = port;
1813 chip->mpu_port = mpu_port;
1814 chip->fm_port = fm_port;
1815 chip->irq = -1; 1796 chip->irq = -1;
1816 chip->dma1 = -1; 1797 chip->dma1 = -1;
1817 chip->dma2 = -1; 1798 chip->dma2 = -1;
1818 chip->audio2_vol = 0x00; 1799 chip->audio2_vol = 0x00;
1819 chip->active = 0; 1800 chip->active = 0;
1820 1801
1821 if ((chip->res_port = request_region(port, 16, "ES18xx")) == NULL) { 1802 chip->res_port = request_region(port, 16, "ES18xx");
1822 snd_es18xx_free(chip); 1803 if (chip->res_port == NULL) {
1804 snd_es18xx_free(card);
1823 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1); 1805 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
1824 return -EBUSY; 1806 return -EBUSY;
1825 } 1807 }
1826 1808
1827 if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx", (void *) chip)) { 1809 if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx",
1828 snd_es18xx_free(chip); 1810 (void *) card)) {
1811 snd_es18xx_free(card);
1829 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq); 1812 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
1830 return -EBUSY; 1813 return -EBUSY;
1831 } 1814 }
1832 chip->irq = irq; 1815 chip->irq = irq;
1833 1816
1834 if (request_dma(dma1, "ES18xx DMA 1")) { 1817 if (request_dma(dma1, "ES18xx DMA 1")) {
1835 snd_es18xx_free(chip); 1818 snd_es18xx_free(card);
1836 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1); 1819 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
1837 return -EBUSY; 1820 return -EBUSY;
1838 } 1821 }
1839 chip->dma1 = dma1; 1822 chip->dma1 = dma1;
1840 1823
1841 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) { 1824 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
1842 snd_es18xx_free(chip); 1825 snd_es18xx_free(card);
1843 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2); 1826 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
1844 return -EBUSY; 1827 return -EBUSY;
1845 } 1828 }
1846 chip->dma2 = dma2; 1829 chip->dma2 = dma2;
1847 1830
1848 if (snd_es18xx_probe(chip) < 0) { 1831 if (snd_es18xx_probe(chip, mpu_port, fm_port) < 0) {
1849 snd_es18xx_free(chip); 1832 snd_es18xx_free(card);
1850 return -ENODEV; 1833 return -ENODEV;
1851 } 1834 }
1852 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1835 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1853 snd_es18xx_free(chip); 1836 if (err < 0) {
1837 snd_es18xx_free(card);
1854 return err; 1838 return err;
1855 } 1839 }
1856 *rchip = chip;
1857 return 0; 1840 return 0;
1858} 1841}
1859 1842
1860static int __devinit snd_es18xx_mixer(struct snd_es18xx *chip) 1843static int __devinit snd_es18xx_mixer(struct snd_card *card)
1861{ 1844{
1862 struct snd_card *card; 1845 struct snd_es18xx *chip = card->private_data;
1863 int err; 1846 int err;
1864 unsigned int idx; 1847 unsigned int idx;
1865 1848
1866 card = chip->card;
1867
1868 strcpy(card->mixername, chip->pcm->name); 1849 strcpy(card->mixername, chip->pcm->name);
1869 1850
1870 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) { 1851 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
@@ -1986,7 +1967,7 @@ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
1986static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 1967static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
1987static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ 1968static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
1988#ifdef CONFIG_PNP 1969#ifdef CONFIG_PNP
1989static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 1970static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
1990#endif 1971#endif
1991static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */ 1972static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
1992#ifndef CONFIG_PNP 1973#ifndef CONFIG_PNP
@@ -2063,11 +2044,11 @@ static int __devinit snd_audiodrive_pnp_init_main(int dev, struct pnp_dev *pdev)
2063 return 0; 2044 return 0;
2064} 2045}
2065 2046
2066static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard, 2047static int __devinit snd_audiodrive_pnp(int dev, struct snd_es18xx *chip,
2067 struct pnp_dev *pdev) 2048 struct pnp_dev *pdev)
2068{ 2049{
2069 acard->dev = pdev; 2050 chip->dev = pdev;
2070 if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0) 2051 if (snd_audiodrive_pnp_init_main(dev, chip->dev) < 0)
2071 return -EBUSY; 2052 return -EBUSY;
2072 return 0; 2053 return 0;
2073} 2054}
@@ -2093,26 +2074,26 @@ static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
2093 2074
2094MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids); 2075MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
2095 2076
2096static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard, 2077static int __devinit snd_audiodrive_pnpc(int dev, struct snd_es18xx *chip,
2097 struct pnp_card_link *card, 2078 struct pnp_card_link *card,
2098 const struct pnp_card_device_id *id) 2079 const struct pnp_card_device_id *id)
2099{ 2080{
2100 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); 2081 chip->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
2101 if (acard->dev == NULL) 2082 if (chip->dev == NULL)
2102 return -EBUSY; 2083 return -EBUSY;
2103 2084
2104 acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL); 2085 chip->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
2105 if (acard->devc == NULL) 2086 if (chip->devc == NULL)
2106 return -EBUSY; 2087 return -EBUSY;
2107 2088
2108 /* Control port initialization */ 2089 /* Control port initialization */
2109 if (pnp_activate_dev(acard->devc) < 0) { 2090 if (pnp_activate_dev(chip->devc) < 0) {
2110 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n"); 2091 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
2111 return -EAGAIN; 2092 return -EAGAIN;
2112 } 2093 }
2113 snd_printdd("pnp: port=0x%llx\n", 2094 snd_printdd("pnp: port=0x%llx\n",
2114 (unsigned long long)pnp_port_start(acard->devc, 0)); 2095 (unsigned long long)pnp_port_start(chip->devc, 0));
2115 if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0) 2096 if (snd_audiodrive_pnp_init_main(dev, chip->dev) < 0)
2116 return -EBUSY; 2097 return -EBUSY;
2117 2098
2118 return 0; 2099 return 0;
@@ -2128,24 +2109,20 @@ static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard,
2128static int snd_es18xx_card_new(int dev, struct snd_card **cardp) 2109static int snd_es18xx_card_new(int dev, struct snd_card **cardp)
2129{ 2110{
2130 return snd_card_create(index[dev], id[dev], THIS_MODULE, 2111 return snd_card_create(index[dev], id[dev], THIS_MODULE,
2131 sizeof(struct snd_audiodrive), cardp); 2112 sizeof(struct snd_es18xx), cardp);
2132} 2113}
2133 2114
2134static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev) 2115static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2135{ 2116{
2136 struct snd_audiodrive *acard = card->private_data; 2117 struct snd_es18xx *chip = card->private_data;
2137 struct snd_es18xx *chip;
2138 struct snd_opl3 *opl3; 2118 struct snd_opl3 *opl3;
2139 int err; 2119 int err;
2140 2120
2141 if ((err = snd_es18xx_new_device(card, 2121 err = snd_es18xx_new_device(card,
2142 port[dev], 2122 port[dev], mpu_port[dev], fm_port[dev],
2143 mpu_port[dev], 2123 irq[dev], dma1[dev], dma2[dev]);
2144 fm_port[dev], 2124 if (err < 0)
2145 irq[dev], dma1[dev], dma2[dev],
2146 &chip)) < 0)
2147 return err; 2125 return err;
2148 acard->chip = chip;
2149 2126
2150 sprintf(card->driver, "ES%x", chip->version); 2127 sprintf(card->driver, "ES%x", chip->version);
2151 2128
@@ -2161,26 +2138,32 @@ static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2161 chip->port, 2138 chip->port,
2162 irq[dev], dma1[dev]); 2139 irq[dev], dma1[dev]);
2163 2140
2164 if ((err = snd_es18xx_pcm(chip, 0, NULL)) < 0) 2141 err = snd_es18xx_pcm(card, 0, NULL);
2142 if (err < 0)
2165 return err; 2143 return err;
2166 2144
2167 if ((err = snd_es18xx_mixer(chip)) < 0) 2145 err = snd_es18xx_mixer(card);
2146 if (err < 0)
2168 return err; 2147 return err;
2169 2148
2170 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { 2149 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
2171 if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) { 2150 if (snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2,
2172 snd_printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->fm_port); 2151 OPL3_HW_OPL3, 0, &opl3) < 0) {
2152 snd_printk(KERN_WARNING PFX
2153 "opl3 not detected at 0x%lx\n",
2154 fm_port[dev]);
2173 } else { 2155 } else {
2174 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) 2156 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
2157 if (err < 0)
2175 return err; 2158 return err;
2176 } 2159 }
2177 } 2160 }
2178 2161
2179 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { 2162 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
2180 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, 2163 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
2181 chip->mpu_port, 0, 2164 mpu_port[dev], 0,
2182 irq[dev], 0, 2165 irq[dev], 0, &chip->rmidi);
2183 &chip->rmidi)) < 0) 2166 if (err < 0)
2184 return err; 2167 return err;
2185 } 2168 }
2186 2169
diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c
index 02e30d7c6a93..b865e45a8f9b 100644
--- a/sound/isa/opti9xx/miro.c
+++ b/sound/isa/opti9xx/miro.c
@@ -25,6 +25,7 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/isa.h> 27#include <linux/isa.h>
28#include <linux/pnp.h>
28#include <linux/delay.h> 29#include <linux/delay.h>
29#include <linux/slab.h> 30#include <linux/slab.h>
30#include <linux/ioport.h> 31#include <linux/ioport.h>
@@ -40,7 +41,7 @@
40#define SNDRV_LEGACY_FIND_FREE_IRQ 41#define SNDRV_LEGACY_FIND_FREE_IRQ
41#define SNDRV_LEGACY_FIND_FREE_DMA 42#define SNDRV_LEGACY_FIND_FREE_DMA
42#include <sound/initval.h> 43#include <sound/initval.h>
43#include "miro.h" 44#include <sound/aci.h>
44 45
45MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>"); 46MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>");
46MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
@@ -60,6 +61,9 @@ static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
60static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ 61static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
61static int wss; 62static int wss;
62static int ide; 63static int ide;
64#ifdef CONFIG_PNP
65static int isapnp = 1; /* Enable ISA PnP detection */
66#endif
63 67
64module_param(index, int, 0444); 68module_param(index, int, 0444);
65MODULE_PARM_DESC(index, "Index value for miro soundcard."); 69MODULE_PARM_DESC(index, "Index value for miro soundcard.");
@@ -83,6 +87,10 @@ module_param(wss, int, 0444);
83MODULE_PARM_DESC(wss, "wss mode"); 87MODULE_PARM_DESC(wss, "wss mode");
84module_param(ide, int, 0444); 88module_param(ide, int, 0444);
85MODULE_PARM_DESC(ide, "enable ide port"); 89MODULE_PARM_DESC(ide, "enable ide port");
90#ifdef CONFIG_PNP
91module_param(isapnp, bool, 0444);
92MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
93#endif
86 94
87#define OPTi9XX_HW_DETECT 0 95#define OPTi9XX_HW_DETECT 0
88#define OPTi9XX_HW_82C928 1 96#define OPTi9XX_HW_82C928 1
@@ -96,7 +104,6 @@ MODULE_PARM_DESC(ide, "enable ide port");
96 104
97#define OPTi9XX_MC_REG(n) n 105#define OPTi9XX_MC_REG(n) n
98 106
99
100struct snd_miro { 107struct snd_miro {
101 unsigned short hardware; 108 unsigned short hardware;
102 unsigned char password; 109 unsigned char password;
@@ -110,7 +117,6 @@ struct snd_miro {
110 unsigned long pwd_reg; 117 unsigned long pwd_reg;
111 118
112 spinlock_t lock; 119 spinlock_t lock;
113 struct snd_card *card;
114 struct snd_pcm *pcm; 120 struct snd_pcm *pcm;
115 121
116 long wss_base; 122 long wss_base;
@@ -118,42 +124,48 @@ struct snd_miro {
118 int dma1; 124 int dma1;
119 int dma2; 125 int dma2;
120 126
121 long fm_port;
122
123 long mpu_port; 127 long mpu_port;
124 int mpu_irq; 128 int mpu_irq;
125 129
126 unsigned long aci_port; 130 struct snd_miro_aci *aci;
127 int aci_vendor;
128 int aci_product;
129 int aci_version;
130 int aci_amp;
131 int aci_preamp;
132 int aci_solomode;
133
134 struct mutex aci_mutex;
135}; 131};
136 132
137static void snd_miro_proc_init(struct snd_miro * miro); 133static struct snd_miro_aci aci_device;
138 134
139static char * snd_opti9xx_names[] = { 135static char * snd_opti9xx_names[] = {
140 "unkown", 136 "unknown",
141 "82C928", "82C929", 137 "82C928", "82C929",
142 "82C924", "82C925", 138 "82C924", "82C925",
143 "82C930", "82C931", "82C933" 139 "82C930", "82C931", "82C933"
144}; 140};
145 141
142static int snd_miro_pnp_is_probed;
143
144#ifdef CONFIG_PNP
145
146static struct pnp_card_device_id snd_miro_pnpids[] = {
147 /* PCM20 and PCM12 in PnP mode */
148 { .id = "MIR0924",
149 .devs = { { "MIR0000" }, { "MIR0002" }, { "MIR0005" } }, },
150 { .id = "" }
151};
152
153MODULE_DEVICE_TABLE(pnp_card, snd_miro_pnpids);
154
155#endif /* CONFIG_PNP */
156
146/* 157/*
147 * ACI control 158 * ACI control
148 */ 159 */
149 160
150static int aci_busy_wait(struct snd_miro * miro) 161static int aci_busy_wait(struct snd_miro_aci *aci)
151{ 162{
152 long timeout; 163 long timeout;
153 unsigned char byte; 164 unsigned char byte;
154 165
155 for (timeout = 1; timeout <= ACI_MINTIME+30; timeout++) { 166 for (timeout = 1; timeout <= ACI_MINTIME + 30; timeout++) {
156 if (((byte=inb(miro->aci_port + ACI_REG_BUSY)) & 1) == 0) { 167 byte = inb(aci->aci_port + ACI_REG_BUSY);
168 if ((byte & 1) == 0) {
157 if (timeout >= ACI_MINTIME) 169 if (timeout >= ACI_MINTIME)
158 snd_printd("aci ready in round %ld.\n", 170 snd_printd("aci ready in round %ld.\n",
159 timeout-ACI_MINTIME); 171 timeout-ACI_MINTIME);
@@ -179,10 +191,10 @@ static int aci_busy_wait(struct snd_miro * miro)
179 return -EBUSY; 191 return -EBUSY;
180} 192}
181 193
182static inline int aci_write(struct snd_miro * miro, unsigned char byte) 194static inline int aci_write(struct snd_miro_aci *aci, unsigned char byte)
183{ 195{
184 if (aci_busy_wait(miro) >= 0) { 196 if (aci_busy_wait(aci) >= 0) {
185 outb(byte, miro->aci_port + ACI_REG_COMMAND); 197 outb(byte, aci->aci_port + ACI_REG_COMMAND);
186 return 0; 198 return 0;
187 } else { 199 } else {
188 snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte); 200 snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte);
@@ -190,12 +202,12 @@ static inline int aci_write(struct snd_miro * miro, unsigned char byte)
190 } 202 }
191} 203}
192 204
193static inline int aci_read(struct snd_miro * miro) 205static inline int aci_read(struct snd_miro_aci *aci)
194{ 206{
195 unsigned char byte; 207 unsigned char byte;
196 208
197 if (aci_busy_wait(miro) >= 0) { 209 if (aci_busy_wait(aci) >= 0) {
198 byte=inb(miro->aci_port + ACI_REG_STATUS); 210 byte = inb(aci->aci_port + ACI_REG_STATUS);
199 return byte; 211 return byte;
200 } else { 212 } else {
201 snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n"); 213 snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n");
@@ -203,39 +215,49 @@ static inline int aci_read(struct snd_miro * miro)
203 } 215 }
204} 216}
205 217
206static int aci_cmd(struct snd_miro * miro, int write1, int write2, int write3) 218int snd_aci_cmd(struct snd_miro_aci *aci, int write1, int write2, int write3)
207{ 219{
208 int write[] = {write1, write2, write3}; 220 int write[] = {write1, write2, write3};
209 int value, i; 221 int value, i;
210 222
211 if (mutex_lock_interruptible(&miro->aci_mutex)) 223 if (mutex_lock_interruptible(&aci->aci_mutex))
212 return -EINTR; 224 return -EINTR;
213 225
214 for (i=0; i<3; i++) { 226 for (i=0; i<3; i++) {
215 if (write[i]< 0 || write[i] > 255) 227 if (write[i]< 0 || write[i] > 255)
216 break; 228 break;
217 else { 229 else {
218 value = aci_write(miro, write[i]); 230 value = aci_write(aci, write[i]);
219 if (value < 0) 231 if (value < 0)
220 goto out; 232 goto out;
221 } 233 }
222 } 234 }
223 235
224 value = aci_read(miro); 236 value = aci_read(aci);
225 237
226out: mutex_unlock(&miro->aci_mutex); 238out: mutex_unlock(&aci->aci_mutex);
227 return value; 239 return value;
228} 240}
241EXPORT_SYMBOL(snd_aci_cmd);
242
243static int aci_getvalue(struct snd_miro_aci *aci, unsigned char index)
244{
245 return snd_aci_cmd(aci, ACI_STATUS, index, -1);
246}
229 247
230static int aci_getvalue(struct snd_miro * miro, unsigned char index) 248static int aci_setvalue(struct snd_miro_aci *aci, unsigned char index,
249 int value)
231{ 250{
232 return aci_cmd(miro, ACI_STATUS, index, -1); 251 return snd_aci_cmd(aci, index, value, -1);
233} 252}
234 253
235static int aci_setvalue(struct snd_miro * miro, unsigned char index, int value) 254struct snd_miro_aci *snd_aci_get_aci(void)
236{ 255{
237 return aci_cmd(miro, index, value, -1); 256 if (aci_device.aci_port == 0)
257 return NULL;
258 return &aci_device;
238} 259}
260EXPORT_SYMBOL(snd_aci_get_aci);
239 261
240/* 262/*
241 * MIXER part 263 * MIXER part
@@ -249,8 +271,10 @@ static int snd_miro_get_capture(struct snd_kcontrol *kcontrol,
249 struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 271 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
250 int value; 272 int value;
251 273
252 if ((value = aci_getvalue(miro, ACI_S_GENERAL)) < 0) { 274 value = aci_getvalue(miro->aci, ACI_S_GENERAL);
253 snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", value); 275 if (value < 0) {
276 snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n",
277 value);
254 return value; 278 return value;
255 } 279 }
256 280
@@ -267,13 +291,15 @@ static int snd_miro_put_capture(struct snd_kcontrol *kcontrol,
267 291
268 value = !(ucontrol->value.integer.value[0]); 292 value = !(ucontrol->value.integer.value[0]);
269 293
270 if ((error = aci_setvalue(miro, ACI_SET_SOLOMODE, value)) < 0) { 294 error = aci_setvalue(miro->aci, ACI_SET_SOLOMODE, value);
271 snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", error); 295 if (error < 0) {
296 snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n",
297 error);
272 return error; 298 return error;
273 } 299 }
274 300
275 change = (value != miro->aci_solomode); 301 change = (value != miro->aci->aci_solomode);
276 miro->aci_solomode = value; 302 miro->aci->aci_solomode = value;
277 303
278 return change; 304 return change;
279} 305}
@@ -295,7 +321,7 @@ static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol,
295 struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 321 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
296 int value; 322 int value;
297 323
298 if (miro->aci_version <= 176) { 324 if (miro->aci->aci_version <= 176) {
299 325
300 /* 326 /*
301 OSS says it's not readable with versions < 176. 327 OSS says it's not readable with versions < 176.
@@ -303,12 +329,14 @@ static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol,
303 which is a PCM12 with aci_version = 176. 329 which is a PCM12 with aci_version = 176.
304 */ 330 */
305 331
306 ucontrol->value.integer.value[0] = miro->aci_preamp; 332 ucontrol->value.integer.value[0] = miro->aci->aci_preamp;
307 return 0; 333 return 0;
308 } 334 }
309 335
310 if ((value = aci_getvalue(miro, ACI_GET_PREAMP)) < 0) { 336 value = aci_getvalue(miro->aci, ACI_GET_PREAMP);
311 snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", value); 337 if (value < 0) {
338 snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n",
339 value);
312 return value; 340 return value;
313 } 341 }
314 342
@@ -325,13 +353,15 @@ static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol,
325 353
326 value = ucontrol->value.integer.value[0]; 354 value = ucontrol->value.integer.value[0];
327 355
328 if ((error = aci_setvalue(miro, ACI_SET_PREAMP, value)) < 0) { 356 error = aci_setvalue(miro->aci, ACI_SET_PREAMP, value);
329 snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", error); 357 if (error < 0) {
358 snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n",
359 error);
330 return error; 360 return error;
331 } 361 }
332 362
333 change = (value != miro->aci_preamp); 363 change = (value != miro->aci->aci_preamp);
334 miro->aci_preamp = value; 364 miro->aci->aci_preamp = value;
335 365
336 return change; 366 return change;
337} 367}
@@ -342,7 +372,7 @@ static int snd_miro_get_amp(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_value *ucontrol) 372 struct snd_ctl_elem_value *ucontrol)
343{ 373{
344 struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 374 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
345 ucontrol->value.integer.value[0] = miro->aci_amp; 375 ucontrol->value.integer.value[0] = miro->aci->aci_amp;
346 376
347 return 0; 377 return 0;
348} 378}
@@ -355,13 +385,14 @@ static int snd_miro_put_amp(struct snd_kcontrol *kcontrol,
355 385
356 value = ucontrol->value.integer.value[0]; 386 value = ucontrol->value.integer.value[0];
357 387
358 if ((error = aci_setvalue(miro, ACI_SET_POWERAMP, value)) < 0) { 388 error = aci_setvalue(miro->aci, ACI_SET_POWERAMP, value);
389 if (error < 0) {
359 snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error); 390 snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error);
360 return error; 391 return error;
361 } 392 }
362 393
363 change = (value != miro->aci_amp); 394 change = (value != miro->aci->aci_amp);
364 miro->aci_amp = value; 395 miro->aci->aci_amp = value;
365 396
366 return change; 397 return change;
367} 398}
@@ -410,12 +441,14 @@ static int snd_miro_get_double(struct snd_kcontrol *kcontrol,
410 int right_reg = kcontrol->private_value & 0xff; 441 int right_reg = kcontrol->private_value & 0xff;
411 int left_reg = right_reg + 1; 442 int left_reg = right_reg + 1;
412 443
413 if ((right_val = aci_getvalue(miro, right_reg)) < 0) { 444 right_val = aci_getvalue(miro->aci, right_reg);
445 if (right_val < 0) {
414 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val); 446 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val);
415 return right_val; 447 return right_val;
416 } 448 }
417 449
418 if ((left_val = aci_getvalue(miro, left_reg)) < 0) { 450 left_val = aci_getvalue(miro->aci, left_reg);
451 if (left_val < 0) {
419 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val); 452 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val);
420 return left_val; 453 return left_val;
421 } 454 }
@@ -451,6 +484,7 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
451 struct snd_ctl_elem_value *ucontrol) 484 struct snd_ctl_elem_value *ucontrol)
452{ 485{
453 struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 486 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
487 struct snd_miro_aci *aci = miro->aci;
454 int left, right, left_old, right_old; 488 int left, right, left_old, right_old;
455 int setreg_left, setreg_right, getreg_left, getreg_right; 489 int setreg_left, setreg_right, getreg_left, getreg_right;
456 int change, error; 490 int change, error;
@@ -459,21 +493,21 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
459 right = ucontrol->value.integer.value[1]; 493 right = ucontrol->value.integer.value[1];
460 494
461 setreg_right = (kcontrol->private_value >> 8) & 0xff; 495 setreg_right = (kcontrol->private_value >> 8) & 0xff;
462 if (setreg_right == ACI_SET_MASTER) { 496 setreg_left = setreg_right + 8;
463 setreg_left = setreg_right + 1; 497 if (setreg_right == ACI_SET_MASTER)
464 } else { 498 setreg_left -= 7;
465 setreg_left = setreg_right + 8;
466 }
467 499
468 getreg_right = kcontrol->private_value & 0xff; 500 getreg_right = kcontrol->private_value & 0xff;
469 getreg_left = getreg_right + 1; 501 getreg_left = getreg_right + 1;
470 502
471 if ((left_old = aci_getvalue(miro, getreg_left)) < 0) { 503 left_old = aci_getvalue(aci, getreg_left);
504 if (left_old < 0) {
472 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old); 505 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old);
473 return left_old; 506 return left_old;
474 } 507 }
475 508
476 if ((right_old = aci_getvalue(miro, getreg_right)) < 0) { 509 right_old = aci_getvalue(aci, getreg_right);
510 if (right_old < 0) {
477 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old); 511 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old);
478 return right_old; 512 return right_old;
479 } 513 }
@@ -492,13 +526,15 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
492 right_old = 0x80 - right_old; 526 right_old = 0x80 - right_old;
493 527
494 if (left >= 0) { 528 if (left >= 0) {
495 if ((error = aci_setvalue(miro, setreg_left, left)) < 0) { 529 error = aci_setvalue(aci, setreg_left, left);
530 if (error < 0) {
496 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 531 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
497 left, error); 532 left, error);
498 return error; 533 return error;
499 } 534 }
500 } else { 535 } else {
501 if ((error = aci_setvalue(miro, setreg_left, 0x80 - left)) < 0) { 536 error = aci_setvalue(aci, setreg_left, 0x80 - left);
537 if (error < 0) {
502 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 538 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
503 0x80 - left, error); 539 0x80 - left, error);
504 return error; 540 return error;
@@ -506,13 +542,15 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
506 } 542 }
507 543
508 if (right >= 0) { 544 if (right >= 0) {
509 if ((error = aci_setvalue(miro, setreg_right, right)) < 0) { 545 error = aci_setvalue(aci, setreg_right, right);
546 if (error < 0) {
510 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 547 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
511 right, error); 548 right, error);
512 return error; 549 return error;
513 } 550 }
514 } else { 551 } else {
515 if ((error = aci_setvalue(miro, setreg_right, 0x80 - right)) < 0) { 552 error = aci_setvalue(aci, setreg_right, 0x80 - right);
553 if (error < 0) {
516 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 554 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
517 0x80 - right, error); 555 0x80 - right, error);
518 return error; 556 return error;
@@ -530,12 +568,14 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
530 left_old = 0x20 - left_old; 568 left_old = 0x20 - left_old;
531 right_old = 0x20 - right_old; 569 right_old = 0x20 - right_old;
532 570
533 if ((error = aci_setvalue(miro, setreg_left, 0x20 - left)) < 0) { 571 error = aci_setvalue(aci, setreg_left, 0x20 - left);
572 if (error < 0) {
534 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 573 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
535 0x20 - left, error); 574 0x20 - left, error);
536 return error; 575 return error;
537 } 576 }
538 if ((error = aci_setvalue(miro, setreg_right, 0x20 - right)) < 0) { 577 error = aci_setvalue(aci, setreg_right, 0x20 - right);
578 if (error < 0) {
539 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 579 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
540 0x20 - right, error); 580 0x20 - right, error);
541 return error; 581 return error;
@@ -633,11 +673,13 @@ static unsigned char aci_init_values[][2] __devinitdata = {
633static int __devinit snd_set_aci_init_values(struct snd_miro *miro) 673static int __devinit snd_set_aci_init_values(struct snd_miro *miro)
634{ 674{
635 int idx, error; 675 int idx, error;
676 struct snd_miro_aci *aci = miro->aci;
636 677
637 /* enable WSS on PCM1 */ 678 /* enable WSS on PCM1 */
638 679
639 if ((miro->aci_product == 'A') && wss) { 680 if ((aci->aci_product == 'A') && wss) {
640 if ((error = aci_setvalue(miro, ACI_SET_WSS, wss)) < 0) { 681 error = aci_setvalue(aci, ACI_SET_WSS, wss);
682 if (error < 0) {
641 snd_printk(KERN_ERR "enabling WSS mode failed\n"); 683 snd_printk(KERN_ERR "enabling WSS mode failed\n");
642 return error; 684 return error;
643 } 685 }
@@ -646,7 +688,8 @@ static int __devinit snd_set_aci_init_values(struct snd_miro *miro)
646 /* enable IDE port */ 688 /* enable IDE port */
647 689
648 if (ide) { 690 if (ide) {
649 if ((error = aci_setvalue(miro, ACI_SET_IDE, ide)) < 0) { 691 error = aci_setvalue(aci, ACI_SET_IDE, ide);
692 if (error < 0) {
650 snd_printk(KERN_ERR "enabling IDE port failed\n"); 693 snd_printk(KERN_ERR "enabling IDE port failed\n");
651 return error; 694 return error;
652 } 695 }
@@ -654,32 +697,31 @@ static int __devinit snd_set_aci_init_values(struct snd_miro *miro)
654 697
655 /* set common aci values */ 698 /* set common aci values */
656 699
657 for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++) 700 for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++) {
658 if ((error = aci_setvalue(miro, aci_init_values[idx][0], 701 error = aci_setvalue(aci, aci_init_values[idx][0],
659 aci_init_values[idx][1])) < 0) { 702 aci_init_values[idx][1]);
703 if (error < 0) {
660 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 704 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
661 aci_init_values[idx][0], error); 705 aci_init_values[idx][0], error);
662 return error; 706 return error;
663 } 707 }
664 708 }
665 miro->aci_amp = 0; 709 aci->aci_amp = 0;
666 miro->aci_preamp = 0; 710 aci->aci_preamp = 0;
667 miro->aci_solomode = 1; 711 aci->aci_solomode = 1;
668 712
669 return 0; 713 return 0;
670} 714}
671 715
672static int __devinit snd_miro_mixer(struct snd_miro *miro) 716static int __devinit snd_miro_mixer(struct snd_card *card,
717 struct snd_miro *miro)
673{ 718{
674 struct snd_card *card;
675 unsigned int idx; 719 unsigned int idx;
676 int err; 720 int err;
677 721
678 if (snd_BUG_ON(!miro || !miro->card)) 722 if (snd_BUG_ON(!miro || !card))
679 return -EINVAL; 723 return -EINVAL;
680 724
681 card = miro->card;
682
683 switch (miro->hardware) { 725 switch (miro->hardware) {
684 case OPTi9XX_HW_82C924: 726 case OPTi9XX_HW_82C924:
685 strcpy(card->mixername, "ACI & OPTi924"); 727 strcpy(card->mixername, "ACI & OPTi924");
@@ -697,7 +739,8 @@ static int __devinit snd_miro_mixer(struct snd_miro *miro)
697 return err; 739 return err;
698 } 740 }
699 741
700 if ((miro->aci_product == 'A') || (miro->aci_product == 'B')) { 742 if ((miro->aci->aci_product == 'A') ||
743 (miro->aci->aci_product == 'B')) {
701 /* PCM1/PCM12 with power-amp and Line 2 */ 744 /* PCM1/PCM12 with power-amp and Line 2 */
702 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0) 745 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0)
703 return err; 746 return err;
@@ -705,16 +748,17 @@ static int __devinit snd_miro_mixer(struct snd_miro *miro)
705 return err; 748 return err;
706 } 749 }
707 750
708 if ((miro->aci_product == 'B') || (miro->aci_product == 'C')) { 751 if ((miro->aci->aci_product == 'B') ||
752 (miro->aci->aci_product == 'C')) {
709 /* PCM12/PCM20 with mic-preamp */ 753 /* PCM12/PCM20 with mic-preamp */
710 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0) 754 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0)
711 return err; 755 return err;
712 if (miro->aci_version >= 176) 756 if (miro->aci->aci_version >= 176)
713 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0) 757 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0)
714 return err; 758 return err;
715 } 759 }
716 760
717 if (miro->aci_product == 'C') { 761 if (miro->aci->aci_product == 'C') {
718 /* PCM20 with radio and 7 band equalizer */ 762 /* PCM20 with radio and 7 band equalizer */
719 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0) 763 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0)
720 return err; 764 return err;
@@ -757,21 +801,26 @@ static int __devinit snd_miro_init(struct snd_miro *chip,
757 chip->irq = -1; 801 chip->irq = -1;
758 chip->dma1 = -1; 802 chip->dma1 = -1;
759 chip->dma2 = -1; 803 chip->dma2 = -1;
760 chip->fm_port = -1;
761 chip->mpu_port = -1; 804 chip->mpu_port = -1;
762 chip->mpu_irq = -1; 805 chip->mpu_irq = -1;
763 806
807 chip->pwd_reg = 3;
808
809#ifdef CONFIG_PNP
810 if (isapnp && chip->mc_base)
811 /* PnP resource gives the least 10 bits */
812 chip->mc_base |= 0xc00;
813 else
814#endif
815 chip->mc_base = 0xf8c;
816
764 switch (hardware) { 817 switch (hardware) {
765 case OPTi9XX_HW_82C929: 818 case OPTi9XX_HW_82C929:
766 chip->mc_base = 0xf8c;
767 chip->password = 0xe3; 819 chip->password = 0xe3;
768 chip->pwd_reg = 3;
769 break; 820 break;
770 821
771 case OPTi9XX_HW_82C924: 822 case OPTi9XX_HW_82C924:
772 chip->mc_base = 0xf8c;
773 chip->password = 0xe5; 823 chip->password = 0xe5;
774 chip->pwd_reg = 3;
775 break; 824 break;
776 825
777 default: 826 default:
@@ -853,14 +902,15 @@ static void snd_miro_proc_read(struct snd_info_entry * entry,
853 struct snd_info_buffer *buffer) 902 struct snd_info_buffer *buffer)
854{ 903{
855 struct snd_miro *miro = (struct snd_miro *) entry->private_data; 904 struct snd_miro *miro = (struct snd_miro *) entry->private_data;
905 struct snd_miro_aci *aci = miro->aci;
856 char* model = "unknown"; 906 char* model = "unknown";
857 907
858 /* miroSOUND PCM1 pro, early PCM12 */ 908 /* miroSOUND PCM1 pro, early PCM12 */
859 909
860 if ((miro->hardware == OPTi9XX_HW_82C929) && 910 if ((miro->hardware == OPTi9XX_HW_82C929) &&
861 (miro->aci_vendor == 'm') && 911 (aci->aci_vendor == 'm') &&
862 (miro->aci_product == 'A')) { 912 (aci->aci_product == 'A')) {
863 switch(miro->aci_version) { 913 switch (aci->aci_version) {
864 case 3: 914 case 3:
865 model = "miroSOUND PCM1 pro"; 915 model = "miroSOUND PCM1 pro";
866 break; 916 break;
@@ -873,9 +923,9 @@ static void snd_miro_proc_read(struct snd_info_entry * entry,
873 /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */ 923 /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */
874 924
875 if ((miro->hardware == OPTi9XX_HW_82C924) && 925 if ((miro->hardware == OPTi9XX_HW_82C924) &&
876 (miro->aci_vendor == 'm') && 926 (aci->aci_vendor == 'm') &&
877 (miro->aci_product == 'B')) { 927 (aci->aci_product == 'B')) {
878 switch(miro->aci_version) { 928 switch (aci->aci_version) {
879 case 4: 929 case 4:
880 model = "miroSOUND PCM12"; 930 model = "miroSOUND PCM12";
881 break; 931 break;
@@ -891,9 +941,9 @@ static void snd_miro_proc_read(struct snd_info_entry * entry,
891 /* miroSOUND PCM20 radio */ 941 /* miroSOUND PCM20 radio */
892 942
893 if ((miro->hardware == OPTi9XX_HW_82C924) && 943 if ((miro->hardware == OPTi9XX_HW_82C924) &&
894 (miro->aci_vendor == 'm') && 944 (aci->aci_vendor == 'm') &&
895 (miro->aci_product == 'C')) { 945 (aci->aci_product == 'C')) {
896 switch(miro->aci_version) { 946 switch (aci->aci_version) {
897 case 7: 947 case 7:
898 model = "miroSOUND PCM20 radio (Rev. E)"; 948 model = "miroSOUND PCM20 radio (Rev. E)";
899 break; 949 break;
@@ -917,17 +967,17 @@ static void snd_miro_proc_read(struct snd_info_entry * entry,
917 967
918 snd_iprintf(buffer, "ACI information:\n"); 968 snd_iprintf(buffer, "ACI information:\n");
919 snd_iprintf(buffer, " vendor : "); 969 snd_iprintf(buffer, " vendor : ");
920 switch(miro->aci_vendor) { 970 switch (aci->aci_vendor) {
921 case 'm': 971 case 'm':
922 snd_iprintf(buffer, "Miro\n"); 972 snd_iprintf(buffer, "Miro\n");
923 break; 973 break;
924 default: 974 default:
925 snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_vendor); 975 snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_vendor);
926 break; 976 break;
927 } 977 }
928 978
929 snd_iprintf(buffer, " product : "); 979 snd_iprintf(buffer, " product : ");
930 switch(miro->aci_product) { 980 switch (aci->aci_product) {
931 case 'A': 981 case 'A':
932 snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n"); 982 snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n");
933 break; 983 break;
@@ -938,26 +988,27 @@ static void snd_miro_proc_read(struct snd_info_entry * entry,
938 snd_iprintf(buffer, "miroSOUND PCM20 radio\n"); 988 snd_iprintf(buffer, "miroSOUND PCM20 radio\n");
939 break; 989 break;
940 default: 990 default:
941 snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_product); 991 snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_product);
942 break; 992 break;
943 } 993 }
944 994
945 snd_iprintf(buffer, " firmware: %d (0x%x)\n", 995 snd_iprintf(buffer, " firmware: %d (0x%x)\n",
946 miro->aci_version, miro->aci_version); 996 aci->aci_version, aci->aci_version);
947 snd_iprintf(buffer, " port : 0x%lx-0x%lx\n", 997 snd_iprintf(buffer, " port : 0x%lx-0x%lx\n",
948 miro->aci_port, miro->aci_port+2); 998 aci->aci_port, aci->aci_port+2);
949 snd_iprintf(buffer, " wss : 0x%x\n", wss); 999 snd_iprintf(buffer, " wss : 0x%x\n", wss);
950 snd_iprintf(buffer, " ide : 0x%x\n", ide); 1000 snd_iprintf(buffer, " ide : 0x%x\n", ide);
951 snd_iprintf(buffer, " solomode: 0x%x\n", miro->aci_solomode); 1001 snd_iprintf(buffer, " solomode: 0x%x\n", aci->aci_solomode);
952 snd_iprintf(buffer, " amp : 0x%x\n", miro->aci_amp); 1002 snd_iprintf(buffer, " amp : 0x%x\n", aci->aci_amp);
953 snd_iprintf(buffer, " preamp : 0x%x\n", miro->aci_preamp); 1003 snd_iprintf(buffer, " preamp : 0x%x\n", aci->aci_preamp);
954} 1004}
955 1005
956static void __devinit snd_miro_proc_init(struct snd_miro * miro) 1006static void __devinit snd_miro_proc_init(struct snd_card *card,
1007 struct snd_miro *miro)
957{ 1008{
958 struct snd_info_entry *entry; 1009 struct snd_info_entry *entry;
959 1010
960 if (! snd_card_proc_new(miro->card, "miro", &entry)) 1011 if (!snd_card_proc_new(card, "miro", &entry))
961 snd_info_set_text_ops(entry, miro, snd_miro_proc_read); 1012 snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
962} 1013}
963 1014
@@ -974,37 +1025,40 @@ static int __devinit snd_miro_configure(struct snd_miro *chip)
974 unsigned char mpu_irq_bits; 1025 unsigned char mpu_irq_bits;
975 unsigned long flags; 1026 unsigned long flags;
976 1027
1028 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
1029 snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
1030 snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
1031
977 switch (chip->hardware) { 1032 switch (chip->hardware) {
978 case OPTi9XX_HW_82C924: 1033 case OPTi9XX_HW_82C924:
979 snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02); 1034 snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
980 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
981 snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
982 snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); 1035 snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
983 snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
984 break; 1036 break;
985 case OPTi9XX_HW_82C929: 1037 case OPTi9XX_HW_82C929:
986 /* untested init commands for OPTi929 */ 1038 /* untested init commands for OPTi929 */
987 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
988 snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
989 snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c); 1039 snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
990 snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
991 break; 1040 break;
992 default: 1041 default:
993 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware); 1042 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
994 return -EINVAL; 1043 return -EINVAL;
995 } 1044 }
996 1045
997 switch (chip->wss_base) { 1046 /* PnP resource says it decodes only 10 bits of address */
998 case 0x530: 1047 switch (chip->wss_base & 0x3ff) {
1048 case 0x130:
1049 chip->wss_base = 0x530;
999 wss_base_bits = 0x00; 1050 wss_base_bits = 0x00;
1000 break; 1051 break;
1001 case 0x604: 1052 case 0x204:
1053 chip->wss_base = 0x604;
1002 wss_base_bits = 0x03; 1054 wss_base_bits = 0x03;
1003 break; 1055 break;
1004 case 0xe80: 1056 case 0x280:
1057 chip->wss_base = 0xe80;
1005 wss_base_bits = 0x01; 1058 wss_base_bits = 0x01;
1006 break; 1059 break;
1007 case 0xf40: 1060 case 0x340:
1061 chip->wss_base = 0xf40;
1008 wss_base_bits = 0x02; 1062 wss_base_bits = 0x02;
1009 break; 1063 break;
1010 default: 1064 default:
@@ -1122,75 +1176,92 @@ __skip_mpu:
1122 return 0; 1176 return 0;
1123} 1177}
1124 1178
1179static int __devinit snd_miro_opti_check(struct snd_miro *chip)
1180{
1181 unsigned char value;
1182
1183 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
1184 "OPTi9xx MC");
1185 if (chip->res_mc_base == NULL)
1186 return -ENOMEM;
1187
1188 value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
1189 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
1190 if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
1191 return 0;
1192
1193 release_and_free_resource(chip->res_mc_base);
1194 chip->res_mc_base = NULL;
1195
1196 return -ENODEV;
1197}
1198
1125static int __devinit snd_card_miro_detect(struct snd_card *card, 1199static int __devinit snd_card_miro_detect(struct snd_card *card,
1126 struct snd_miro *chip) 1200 struct snd_miro *chip)
1127{ 1201{
1128 int i, err; 1202 int i, err;
1129 unsigned char value;
1130 1203
1131 for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) { 1204 for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) {
1132 1205
1133 if ((err = snd_miro_init(chip, i)) < 0) 1206 if ((err = snd_miro_init(chip, i)) < 0)
1134 return err; 1207 return err;
1135 1208
1136 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) 1209 err = snd_miro_opti_check(chip);
1137 continue; 1210 if (err == 0)
1138 1211 return 1;
1139 value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
1140 if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
1141 if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
1142 return 1;
1143
1144 release_and_free_resource(chip->res_mc_base);
1145 chip->res_mc_base = NULL;
1146
1147 } 1212 }
1148 1213
1149 return -ENODEV; 1214 return -ENODEV;
1150} 1215}
1151 1216
1152static int __devinit snd_card_miro_aci_detect(struct snd_card *card, 1217static int __devinit snd_card_miro_aci_detect(struct snd_card *card,
1153 struct snd_miro * miro) 1218 struct snd_miro *miro)
1154{ 1219{
1155 unsigned char regval; 1220 unsigned char regval;
1156 int i; 1221 int i;
1222 struct snd_miro_aci *aci = &aci_device;
1223
1224 miro->aci = aci;
1157 1225
1158 mutex_init(&miro->aci_mutex); 1226 mutex_init(&aci->aci_mutex);
1159 1227
1160 /* get ACI port from OPTi9xx MC 4 */ 1228 /* get ACI port from OPTi9xx MC 4 */
1161 1229
1162 miro->mc_base = 0xf8c;
1163 regval=inb(miro->mc_base + 4); 1230 regval=inb(miro->mc_base + 4);
1164 miro->aci_port = (regval & 0x10) ? 0x344: 0x354; 1231 aci->aci_port = (regval & 0x10) ? 0x344 : 0x354;
1165 1232
1166 if ((miro->res_aci_port = request_region(miro->aci_port, 3, "miro aci")) == NULL) { 1233 miro->res_aci_port = request_region(aci->aci_port, 3, "miro aci");
1234 if (miro->res_aci_port == NULL) {
1167 snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n", 1235 snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n",
1168 miro->aci_port, miro->aci_port+2); 1236 aci->aci_port, aci->aci_port+2);
1169 return -ENOMEM; 1237 return -ENOMEM;
1170 } 1238 }
1171 1239
1172 /* force ACI into a known state */ 1240 /* force ACI into a known state */
1173 for (i = 0; i < 3; i++) 1241 for (i = 0; i < 3; i++)
1174 if (aci_cmd(miro, ACI_ERROR_OP, -1, -1) < 0) { 1242 if (snd_aci_cmd(aci, ACI_ERROR_OP, -1, -1) < 0) {
1175 snd_printk(KERN_ERR "can't force aci into known state.\n"); 1243 snd_printk(KERN_ERR "can't force aci into known state.\n");
1176 return -ENXIO; 1244 return -ENXIO;
1177 } 1245 }
1178 1246
1179 if ((miro->aci_vendor=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0 || 1247 aci->aci_vendor = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1);
1180 (miro->aci_product=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0) { 1248 aci->aci_product = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1);
1181 snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", miro->aci_port); 1249 if (aci->aci_vendor < 0 || aci->aci_product < 0) {
1250 snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n",
1251 aci->aci_port);
1182 return -ENXIO; 1252 return -ENXIO;
1183 } 1253 }
1184 1254
1185 if ((miro->aci_version=aci_cmd(miro, ACI_READ_VERSION, -1, -1)) < 0) { 1255 aci->aci_version = snd_aci_cmd(aci, ACI_READ_VERSION, -1, -1);
1256 if (aci->aci_version < 0) {
1186 snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n", 1257 snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n",
1187 miro->aci_port); 1258 aci->aci_port);
1188 return -ENXIO; 1259 return -ENXIO;
1189 } 1260 }
1190 1261
1191 if (aci_cmd(miro, ACI_INIT, -1, -1) < 0 || 1262 if (snd_aci_cmd(aci, ACI_INIT, -1, -1) < 0 ||
1192 aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 || 1263 snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 ||
1193 aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) { 1264 snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) {
1194 snd_printk(KERN_ERR "can't initialize aci.\n"); 1265 snd_printk(KERN_ERR "can't initialize aci.\n");
1195 return -ENXIO; 1266 return -ENXIO;
1196 } 1267 }
@@ -1201,157 +1272,80 @@ static int __devinit snd_card_miro_aci_detect(struct snd_card *card,
1201static void snd_card_miro_free(struct snd_card *card) 1272static void snd_card_miro_free(struct snd_card *card)
1202{ 1273{
1203 struct snd_miro *miro = card->private_data; 1274 struct snd_miro *miro = card->private_data;
1204 1275
1205 release_and_free_resource(miro->res_aci_port); 1276 release_and_free_resource(miro->res_aci_port);
1277 if (miro->aci)
1278 miro->aci->aci_port = 0;
1206 release_and_free_resource(miro->res_mc_base); 1279 release_and_free_resource(miro->res_mc_base);
1207} 1280}
1208 1281
1209static int __devinit snd_miro_match(struct device *devptr, unsigned int n) 1282static int __devinit snd_miro_probe(struct snd_card *card)
1210{
1211 return 1;
1212}
1213
1214static int __devinit snd_miro_probe(struct device *devptr, unsigned int n)
1215{ 1283{
1216 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1217 static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
1218 static int possible_irqs[] = {11, 9, 10, 7, -1};
1219 static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
1220 static int possible_dma1s[] = {3, 1, 0, -1};
1221 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
1222
1223 int error; 1284 int error;
1224 struct snd_miro *miro; 1285 struct snd_miro *miro = card->private_data;
1225 struct snd_wss *codec; 1286 struct snd_wss *codec;
1226 struct snd_timer *timer; 1287 struct snd_timer *timer;
1227 struct snd_card *card;
1228 struct snd_pcm *pcm; 1288 struct snd_pcm *pcm;
1229 struct snd_rawmidi *rmidi; 1289 struct snd_rawmidi *rmidi;
1230 1290
1231 error = snd_card_create(index, id, THIS_MODULE, 1291 if (!miro->res_mc_base) {
1232 sizeof(struct snd_miro), &card); 1292 miro->res_mc_base = request_region(miro->mc_base,
1233 if (error < 0) 1293 miro->mc_base_size,
1234 return error; 1294 "miro (OPTi9xx MC)");
1235 1295 if (miro->res_mc_base == NULL) {
1236 card->private_free = snd_card_miro_free; 1296 snd_printk(KERN_ERR "request for OPTI9xx MC failed\n");
1237 miro = card->private_data; 1297 return -ENOMEM;
1238 miro->card = card; 1298 }
1239
1240 if ((error = snd_card_miro_aci_detect(card, miro)) < 0) {
1241 snd_card_free(card);
1242 snd_printk(KERN_ERR "unable to detect aci chip\n");
1243 return -ENODEV;
1244 } 1299 }
1245 1300
1246 /* init proc interface */ 1301 error = snd_card_miro_aci_detect(card, miro);
1247 snd_miro_proc_init(miro); 1302 if (error < 0) {
1248
1249 if ((error = snd_card_miro_detect(card, miro)) < 0) {
1250 snd_card_free(card); 1303 snd_card_free(card);
1251 snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n"); 1304 snd_printk(KERN_ERR "unable to detect aci chip\n");
1252 return -ENODEV; 1305 return -ENODEV;
1253 } 1306 }
1254 1307
1255 if (! miro->res_mc_base &&
1256 (miro->res_mc_base = request_region(miro->mc_base, miro->mc_base_size,
1257 "miro (OPTi9xx MC)")) == NULL) {
1258 snd_card_free(card);
1259 snd_printk(KERN_ERR "request for OPTI9xx MC failed\n");
1260 return -ENOMEM;
1261 }
1262
1263 miro->wss_base = port; 1308 miro->wss_base = port;
1264 miro->fm_port = fm_port;
1265 miro->mpu_port = mpu_port; 1309 miro->mpu_port = mpu_port;
1266 miro->irq = irq; 1310 miro->irq = irq;
1267 miro->mpu_irq = mpu_irq; 1311 miro->mpu_irq = mpu_irq;
1268 miro->dma1 = dma1; 1312 miro->dma1 = dma1;
1269 miro->dma2 = dma2; 1313 miro->dma2 = dma2;
1270 1314
1271 if (miro->wss_base == SNDRV_AUTO_PORT) { 1315 /* init proc interface */
1272 if ((miro->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) { 1316 snd_miro_proc_init(card, miro);
1273 snd_card_free(card);
1274 snd_printk(KERN_ERR "unable to find a free WSS port\n");
1275 return -EBUSY;
1276 }
1277 }
1278
1279 if (miro->mpu_port == SNDRV_AUTO_PORT) {
1280 if ((miro->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
1281 snd_card_free(card);
1282 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
1283 return -EBUSY;
1284 }
1285 }
1286 if (miro->irq == SNDRV_AUTO_IRQ) {
1287 if ((miro->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
1288 snd_card_free(card);
1289 snd_printk(KERN_ERR "unable to find a free IRQ\n");
1290 return -EBUSY;
1291 }
1292 }
1293 if (miro->mpu_irq == SNDRV_AUTO_IRQ) {
1294 if ((miro->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
1295 snd_card_free(card);
1296 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
1297 return -EBUSY;
1298 }
1299 }
1300 if (miro->dma1 == SNDRV_AUTO_DMA) {
1301 if ((miro->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
1302 snd_card_free(card);
1303 snd_printk(KERN_ERR "unable to find a free DMA1\n");
1304 return -EBUSY;
1305 }
1306 }
1307 if (miro->dma2 == SNDRV_AUTO_DMA) {
1308 if ((miro->dma2 = snd_legacy_find_free_dma(possible_dma2s[miro->dma1 % 4])) < 0) {
1309 snd_card_free(card);
1310 snd_printk(KERN_ERR "unable to find a free DMA2\n");
1311 return -EBUSY;
1312 }
1313 }
1314 1317
1315 error = snd_miro_configure(miro); 1318 error = snd_miro_configure(miro);
1316 if (error) { 1319 if (error)
1317 snd_card_free(card);
1318 return error; 1320 return error;
1319 }
1320 1321
1321 error = snd_wss_create(card, miro->wss_base + 4, -1, 1322 error = snd_wss_create(card, miro->wss_base + 4, -1,
1322 miro->irq, miro->dma1, miro->dma2, 1323 miro->irq, miro->dma1, miro->dma2,
1323 WSS_HW_AD1845, 0, &codec); 1324 WSS_HW_DETECT, 0, &codec);
1324 if (error < 0) { 1325 if (error < 0)
1325 snd_card_free(card);
1326 return error; 1326 return error;
1327 }
1328 1327
1329 error = snd_wss_pcm(codec, 0, &pcm); 1328 error = snd_wss_pcm(codec, 0, &pcm);
1330 if (error < 0) { 1329 if (error < 0)
1331 snd_card_free(card);
1332 return error; 1330 return error;
1333 } 1331
1334 error = snd_wss_mixer(codec); 1332 error = snd_wss_mixer(codec);
1335 if (error < 0) { 1333 if (error < 0)
1336 snd_card_free(card);
1337 return error; 1334 return error;
1338 } 1335
1339 error = snd_wss_timer(codec, 0, &timer); 1336 error = snd_wss_timer(codec, 0, &timer);
1340 if (error < 0) { 1337 if (error < 0)
1341 snd_card_free(card);
1342 return error; 1338 return error;
1343 }
1344 1339
1345 miro->pcm = pcm; 1340 miro->pcm = pcm;
1346 1341
1347 if ((error = snd_miro_mixer(miro)) < 0) { 1342 error = snd_miro_mixer(card, miro);
1348 snd_card_free(card); 1343 if (error < 0)
1349 return error; 1344 return error;
1350 }
1351 1345
1352 if (miro->aci_vendor == 'm') { 1346 if (miro->aci->aci_vendor == 'm') {
1353 /* It looks like a miro sound card. */ 1347 /* It looks like a miro sound card. */
1354 switch (miro->aci_product) { 1348 switch (miro->aci->aci_product) {
1355 case 'A': 1349 case 'A':
1356 sprintf(card->shortname, 1350 sprintf(card->shortname,
1357 "miroSOUND PCM1 pro / PCM12"); 1351 "miroSOUND PCM1 pro / PCM12");
@@ -1380,30 +1374,131 @@ static int __devinit snd_miro_probe(struct device *devptr, unsigned int n)
1380 card->shortname, miro->name, pcm->name, miro->wss_base + 4, 1374 card->shortname, miro->name, pcm->name, miro->wss_base + 4,
1381 miro->irq, miro->dma1, miro->dma2); 1375 miro->irq, miro->dma1, miro->dma2);
1382 1376
1383 if (miro->mpu_port <= 0 || miro->mpu_port == SNDRV_AUTO_PORT) 1377 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
1384 rmidi = NULL; 1378 rmidi = NULL;
1385 else 1379 else {
1386 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 1380 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
1387 miro->mpu_port, 0, miro->mpu_irq, IRQF_DISABLED, 1381 mpu_port, 0, miro->mpu_irq, IRQF_DISABLED,
1388 &rmidi))) 1382 &rmidi);
1389 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", miro->mpu_port); 1383 if (error < 0)
1384 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
1385 mpu_port);
1386 }
1390 1387
1391 if (miro->fm_port > 0 && miro->fm_port != SNDRV_AUTO_PORT) { 1388 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
1392 struct snd_opl3 *opl3 = NULL; 1389 struct snd_opl3 *opl3 = NULL;
1393 struct snd_opl4 *opl4; 1390 struct snd_opl4 *opl4;
1394 if (snd_opl4_create(card, miro->fm_port, miro->fm_port - 8, 1391
1392 if (snd_opl4_create(card, fm_port, fm_port - 8,
1395 2, &opl3, &opl4) < 0) 1393 2, &opl3, &opl4) < 0)
1396 snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n", miro->fm_port); 1394 snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n",
1395 fm_port);
1397 } 1396 }
1398 1397
1399 if ((error = snd_set_aci_init_values(miro)) < 0) { 1398 error = snd_set_aci_init_values(miro);
1400 snd_card_free(card); 1399 if (error < 0)
1401 return error; 1400 return error;
1401
1402 return snd_card_register(card);
1403}
1404
1405static int __devinit snd_miro_isa_match(struct device *devptr, unsigned int n)
1406{
1407#ifdef CONFIG_PNP
1408 if (snd_miro_pnp_is_probed)
1409 return 0;
1410 if (isapnp)
1411 return 0;
1412#endif
1413 return 1;
1414}
1415
1416static int __devinit snd_miro_isa_probe(struct device *devptr, unsigned int n)
1417{
1418 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1419 static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
1420 static int possible_irqs[] = {11, 9, 10, 7, -1};
1421 static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
1422 static int possible_dma1s[] = {3, 1, 0, -1};
1423 static int possible_dma2s[][2] = { {1, -1}, {0, -1}, {-1, -1},
1424 {0, -1} };
1425
1426 int error;
1427 struct snd_miro *miro;
1428 struct snd_card *card;
1429
1430 error = snd_card_create(index, id, THIS_MODULE,
1431 sizeof(struct snd_miro), &card);
1432 if (error < 0)
1433 return error;
1434
1435 card->private_free = snd_card_miro_free;
1436 miro = card->private_data;
1437
1438 error = snd_card_miro_detect(card, miro);
1439 if (error < 0) {
1440 snd_card_free(card);
1441 snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n");
1442 return -ENODEV;
1443 }
1444
1445 if (port == SNDRV_AUTO_PORT) {
1446 port = snd_legacy_find_free_ioport(possible_ports, 4);
1447 if (port < 0) {
1448 snd_card_free(card);
1449 snd_printk(KERN_ERR "unable to find a free WSS port\n");
1450 return -EBUSY;
1451 }
1452 }
1453
1454 if (mpu_port == SNDRV_AUTO_PORT) {
1455 mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2);
1456 if (mpu_port < 0) {
1457 snd_card_free(card);
1458 snd_printk(KERN_ERR
1459 "unable to find a free MPU401 port\n");
1460 return -EBUSY;
1461 }
1462 }
1463
1464 if (irq == SNDRV_AUTO_IRQ) {
1465 irq = snd_legacy_find_free_irq(possible_irqs);
1466 if (irq < 0) {
1467 snd_card_free(card);
1468 snd_printk(KERN_ERR "unable to find a free IRQ\n");
1469 return -EBUSY;
1470 }
1471 }
1472 if (mpu_irq == SNDRV_AUTO_IRQ) {
1473 mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs);
1474 if (mpu_irq < 0) {
1475 snd_card_free(card);
1476 snd_printk(KERN_ERR
1477 "unable to find a free MPU401 IRQ\n");
1478 return -EBUSY;
1479 }
1480 }
1481 if (dma1 == SNDRV_AUTO_DMA) {
1482 dma1 = snd_legacy_find_free_dma(possible_dma1s);
1483 if (dma1 < 0) {
1484 snd_card_free(card);
1485 snd_printk(KERN_ERR "unable to find a free DMA1\n");
1486 return -EBUSY;
1487 }
1488 }
1489 if (dma2 == SNDRV_AUTO_DMA) {
1490 dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]);
1491 if (dma2 < 0) {
1492 snd_card_free(card);
1493 snd_printk(KERN_ERR "unable to find a free DMA2\n");
1494 return -EBUSY;
1495 }
1402 } 1496 }
1403 1497
1404 snd_card_set_dev(card, devptr); 1498 snd_card_set_dev(card, devptr);
1405 1499
1406 if ((error = snd_card_register(card))) { 1500 error = snd_miro_probe(card);
1501 if (error < 0) {
1407 snd_card_free(card); 1502 snd_card_free(card);
1408 return error; 1503 return error;
1409 } 1504 }
@@ -1412,7 +1507,8 @@ static int __devinit snd_miro_probe(struct device *devptr, unsigned int n)
1412 return 0; 1507 return 0;
1413} 1508}
1414 1509
1415static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev) 1510static int __devexit snd_miro_isa_remove(struct device *devptr,
1511 unsigned int dev)
1416{ 1512{
1417 snd_card_free(dev_get_drvdata(devptr)); 1513 snd_card_free(dev_get_drvdata(devptr));
1418 dev_set_drvdata(devptr, NULL); 1514 dev_set_drvdata(devptr, NULL);
@@ -1422,23 +1518,164 @@ static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev)
1422#define DEV_NAME "miro" 1518#define DEV_NAME "miro"
1423 1519
1424static struct isa_driver snd_miro_driver = { 1520static struct isa_driver snd_miro_driver = {
1425 .match = snd_miro_match, 1521 .match = snd_miro_isa_match,
1426 .probe = snd_miro_probe, 1522 .probe = snd_miro_isa_probe,
1427 .remove = __devexit_p(snd_miro_remove), 1523 .remove = __devexit_p(snd_miro_isa_remove),
1428 /* FIXME: suspend/resume */ 1524 /* FIXME: suspend/resume */
1429 .driver = { 1525 .driver = {
1430 .name = DEV_NAME 1526 .name = DEV_NAME
1431 }, 1527 },
1432}; 1528};
1433 1529
1530#ifdef CONFIG_PNP
1531
1532static int __devinit snd_card_miro_pnp(struct snd_miro *chip,
1533 struct pnp_card_link *card,
1534 const struct pnp_card_device_id *pid)
1535{
1536 struct pnp_dev *pdev;
1537 int err;
1538 struct pnp_dev *devmpu;
1539 struct pnp_dev *devmc;
1540
1541 pdev = pnp_request_card_device(card, pid->devs[0].id, NULL);
1542 if (pdev == NULL)
1543 return -EBUSY;
1544
1545 devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
1546 if (devmpu == NULL)
1547 return -EBUSY;
1548
1549 devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
1550 if (devmc == NULL)
1551 return -EBUSY;
1552
1553 err = pnp_activate_dev(pdev);
1554 if (err < 0) {
1555 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
1556 return err;
1557 }
1558
1559 err = pnp_activate_dev(devmc);
1560 if (err < 0) {
1561 snd_printk(KERN_ERR "OPL syntg pnp configure failure: %d\n",
1562 err);
1563 return err;
1564 }
1565
1566 port = pnp_port_start(pdev, 1);
1567 fm_port = pnp_port_start(pdev, 2) + 8;
1568
1569 /*
1570 * The MC(0) is never accessed and the miroSOUND PCM20 card does not
1571 * include it in the PnP resource range. OPTI93x include it.
1572 */
1573 chip->mc_base = pnp_port_start(devmc, 0) - 1;
1574 chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
1575
1576 irq = pnp_irq(pdev, 0);
1577 dma1 = pnp_dma(pdev, 0);
1578 dma2 = pnp_dma(pdev, 1);
1579
1580 if (mpu_port > 0) {
1581 err = pnp_activate_dev(devmpu);
1582 if (err < 0) {
1583 snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
1584 mpu_port = -1;
1585 return err;
1586 }
1587 mpu_port = pnp_port_start(devmpu, 0);
1588 mpu_irq = pnp_irq(devmpu, 0);
1589 }
1590 return 0;
1591}
1592
1593static int __devinit snd_miro_pnp_probe(struct pnp_card_link *pcard,
1594 const struct pnp_card_device_id *pid)
1595{
1596 struct snd_card *card;
1597 int err;
1598 struct snd_miro *miro;
1599
1600 if (snd_miro_pnp_is_probed)
1601 return -EBUSY;
1602 if (!isapnp)
1603 return -ENODEV;
1604 err = snd_card_create(index, id, THIS_MODULE,
1605 sizeof(struct snd_miro), &card);
1606 if (err < 0)
1607 return err;
1608
1609 card->private_free = snd_card_miro_free;
1610 miro = card->private_data;
1611
1612 err = snd_card_miro_pnp(miro, pcard, pid);
1613 if (err) {
1614 snd_card_free(card);
1615 return err;
1616 }
1617
1618 /* only miroSOUND PCM20 and PCM12 == OPTi924 */
1619 err = snd_miro_init(miro, OPTi9XX_HW_82C924);
1620 if (err) {
1621 snd_card_free(card);
1622 return err;
1623 }
1624
1625 err = snd_miro_opti_check(miro);
1626 if (err) {
1627 snd_printk(KERN_ERR "OPTI chip not found\n");
1628 snd_card_free(card);
1629 return err;
1630 }
1631
1632 snd_card_set_dev(card, &pcard->card->dev);
1633 err = snd_miro_probe(card);
1634 if (err < 0) {
1635 snd_card_free(card);
1636 return err;
1637 }
1638 pnp_set_card_drvdata(pcard, card);
1639 snd_miro_pnp_is_probed = 1;
1640 return 0;
1641}
1642
1643static void __devexit snd_miro_pnp_remove(struct pnp_card_link * pcard)
1644{
1645 snd_card_free(pnp_get_card_drvdata(pcard));
1646 pnp_set_card_drvdata(pcard, NULL);
1647 snd_miro_pnp_is_probed = 0;
1648}
1649
1650static struct pnp_card_driver miro_pnpc_driver = {
1651 .flags = PNP_DRIVER_RES_DISABLE,
1652 .name = "miro",
1653 .id_table = snd_miro_pnpids,
1654 .probe = snd_miro_pnp_probe,
1655 .remove = __devexit_p(snd_miro_pnp_remove),
1656};
1657#endif
1658
1434static int __init alsa_card_miro_init(void) 1659static int __init alsa_card_miro_init(void)
1435{ 1660{
1661#ifdef CONFIG_PNP
1662 pnp_register_card_driver(&miro_pnpc_driver);
1663 if (snd_miro_pnp_is_probed)
1664 return 0;
1665 pnp_unregister_card_driver(&miro_pnpc_driver);
1666#endif
1436 return isa_register_driver(&snd_miro_driver, 1); 1667 return isa_register_driver(&snd_miro_driver, 1);
1437} 1668}
1438 1669
1439static void __exit alsa_card_miro_exit(void) 1670static void __exit alsa_card_miro_exit(void)
1440{ 1671{
1441 isa_unregister_driver(&snd_miro_driver); 1672 if (!snd_miro_pnp_is_probed) {
1673 isa_unregister_driver(&snd_miro_driver);
1674 return;
1675 }
1676#ifdef CONFIG_PNP
1677 pnp_unregister_card_driver(&miro_pnpc_driver);
1678#endif
1442} 1679}
1443 1680
1444module_init(alsa_card_miro_init) 1681module_init(alsa_card_miro_init)
diff --git a/sound/isa/opti9xx/miro.h b/sound/isa/opti9xx/miro.h
deleted file mode 100644
index 6e1385b8e07e..000000000000
--- a/sound/isa/opti9xx/miro.h
+++ /dev/null
@@ -1,73 +0,0 @@
1#ifndef _MIRO_H_
2#define _MIRO_H_
3
4#define ACI_REG_COMMAND 0 /* write register offset */
5#define ACI_REG_STATUS 1 /* read register offset */
6#define ACI_REG_BUSY 2 /* busy register offset */
7#define ACI_REG_RDS 2 /* PCM20: RDS register offset */
8#define ACI_MINTIME 500 /* ACI time out limit */
9
10#define ACI_SET_MUTE 0x0d
11#define ACI_SET_POWERAMP 0x0f
12#define ACI_SET_TUNERMUTE 0xa3
13#define ACI_SET_TUNERMONO 0xa4
14#define ACI_SET_IDE 0xd0
15#define ACI_SET_WSS 0xd1
16#define ACI_SET_SOLOMODE 0xd2
17#define ACI_SET_PREAMP 0x03
18#define ACI_GET_PREAMP 0x21
19#define ACI_WRITE_TUNE 0xa7
20#define ACI_READ_TUNERSTEREO 0xa8
21#define ACI_READ_TUNERSTATION 0xa9
22#define ACI_READ_VERSION 0xf1
23#define ACI_READ_IDCODE 0xf2
24#define ACI_INIT 0xff
25#define ACI_STATUS 0xf0
26#define ACI_S_GENERAL 0x00
27#define ACI_ERROR_OP 0xdf
28
29/* ACI Mixer */
30
31/* These are the values for the right channel GET registers.
32 Add an offset of 0x01 for the left channel register.
33 (left=right+0x01) */
34
35#define ACI_GET_MASTER 0x03
36#define ACI_GET_MIC 0x05
37#define ACI_GET_LINE 0x07
38#define ACI_GET_CD 0x09
39#define ACI_GET_SYNTH 0x0b
40#define ACI_GET_PCM 0x0d
41#define ACI_GET_LINE1 0x10 /* Radio on PCM20 */
42#define ACI_GET_LINE2 0x12
43
44#define ACI_GET_EQ1 0x22 /* from Bass ... */
45#define ACI_GET_EQ2 0x24
46#define ACI_GET_EQ3 0x26
47#define ACI_GET_EQ4 0x28
48#define ACI_GET_EQ5 0x2a
49#define ACI_GET_EQ6 0x2c
50#define ACI_GET_EQ7 0x2e /* ... to Treble */
51
52/* And these are the values for the right channel SET registers.
53 For left channel access you have to add an offset of 0x08.
54 MASTER is an exception, which needs an offset of 0x01 */
55
56#define ACI_SET_MASTER 0x00
57#define ACI_SET_MIC 0x30
58#define ACI_SET_LINE 0x31
59#define ACI_SET_CD 0x34
60#define ACI_SET_SYNTH 0x33
61#define ACI_SET_PCM 0x32
62#define ACI_SET_LINE1 0x35 /* Radio on PCM20 */
63#define ACI_SET_LINE2 0x36
64
65#define ACI_SET_EQ1 0x40 /* from Bass ... */
66#define ACI_SET_EQ2 0x41
67#define ACI_SET_EQ3 0x42
68#define ACI_SET_EQ4 0x43
69#define ACI_SET_EQ5 0x44
70#define ACI_SET_EQ6 0x45
71#define ACI_SET_EQ7 0x46 /* ... to Treble */
72
73#endif /* _MIRO_H_ */
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c
index 5cd555325b9d..d622d2906862 100644
--- a/sound/isa/opti9xx/opti92x-ad1848.c
+++ b/sound/isa/opti9xx/opti92x-ad1848.c
@@ -141,15 +141,7 @@ struct snd_opti9xx {
141 141
142 spinlock_t lock; 142 spinlock_t lock;
143 143
144 long wss_base;
145 int irq; 144 int irq;
146 int dma1;
147 int dma2;
148
149 long fm_port;
150
151 long mpu_port;
152 int mpu_irq;
153 145
154#ifdef CONFIG_PNP 146#ifdef CONFIG_PNP
155 struct pnp_dev *dev; 147 struct pnp_dev *dev;
@@ -185,7 +177,7 @@ MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
185#endif 177#endif
186 178
187static char * snd_opti9xx_names[] = { 179static char * snd_opti9xx_names[] = {
188 "unkown", 180 "unknown",
189 "82C928", "82C929", 181 "82C928", "82C929",
190 "82C924", "82C925", 182 "82C924", "82C925",
191 "82C930", "82C931", "82C933" 183 "82C930", "82C931", "82C933"
@@ -216,13 +208,7 @@ static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
216 208
217 spin_lock_init(&chip->lock); 209 spin_lock_init(&chip->lock);
218 210
219 chip->wss_base = -1;
220 chip->irq = -1; 211 chip->irq = -1;
221 chip->dma1 = -1;
222 chip->dma2 = -1;
223 chip->fm_port = -1;
224 chip->mpu_port = -1;
225 chip->mpu_irq = -1;
226 212
227 switch (hardware) { 213 switch (hardware) {
228#ifndef OPTi93X 214#ifndef OPTi93X
@@ -348,7 +334,10 @@ static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
348 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask))) 334 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
349 335
350 336
351static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip) 337static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip,
338 long wss_base,
339 int irq, int dma1, int dma2,
340 long mpu_port, int mpu_irq)
352{ 341{
353 unsigned char wss_base_bits; 342 unsigned char wss_base_bits;
354 unsigned char irq_bits; 343 unsigned char irq_bits;
@@ -416,7 +405,7 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
416 return -EINVAL; 405 return -EINVAL;
417 } 406 }
418 407
419 switch (chip->wss_base) { 408 switch (wss_base) {
420 case 0x530: 409 case 0x530:
421 wss_base_bits = 0x00; 410 wss_base_bits = 0x00;
422 break; 411 break;
@@ -430,14 +419,13 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
430 wss_base_bits = 0x02; 419 wss_base_bits = 0x02;
431 break; 420 break;
432 default: 421 default:
433 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", 422 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", wss_base);
434 chip->wss_base);
435 goto __skip_base; 423 goto __skip_base;
436 } 424 }
437 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30); 425 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
438 426
439__skip_base: 427__skip_base:
440 switch (chip->irq) { 428 switch (irq) {
441//#ifdef OPTi93X 429//#ifdef OPTi93X
442 case 5: 430 case 5:
443 irq_bits = 0x05; 431 irq_bits = 0x05;
@@ -456,11 +444,11 @@ __skip_base:
456 irq_bits = 0x04; 444 irq_bits = 0x04;
457 break; 445 break;
458 default: 446 default:
459 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", chip->irq); 447 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
460 goto __skip_resources; 448 goto __skip_resources;
461 } 449 }
462 450
463 switch (chip->dma1) { 451 switch (dma1) {
464 case 0: 452 case 0:
465 dma_bits = 0x01; 453 dma_bits = 0x01;
466 break; 454 break;
@@ -471,38 +459,36 @@ __skip_base:
471 dma_bits = 0x03; 459 dma_bits = 0x03;
472 break; 460 break;
473 default: 461 default:
474 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", 462 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
475 chip->dma1);
476 goto __skip_resources; 463 goto __skip_resources;
477 } 464 }
478 465
479#if defined(CS4231) || defined(OPTi93X) 466#if defined(CS4231) || defined(OPTi93X)
480 if (chip->dma1 == chip->dma2) { 467 if (dma1 == dma2) {
481 snd_printk(KERN_ERR "don't want to share dmas\n"); 468 snd_printk(KERN_ERR "don't want to share dmas\n");
482 return -EBUSY; 469 return -EBUSY;
483 } 470 }
484 471
485 switch (chip->dma2) { 472 switch (dma2) {
486 case 0: 473 case 0:
487 case 1: 474 case 1:
488 break; 475 break;
489 default: 476 default:
490 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", 477 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
491 chip->dma2);
492 goto __skip_resources; 478 goto __skip_resources;
493 } 479 }
494 dma_bits |= 0x04; 480 dma_bits |= 0x04;
495#endif /* CS4231 || OPTi93X */ 481#endif /* CS4231 || OPTi93X */
496 482
497#ifndef OPTi93X 483#ifndef OPTi93X
498 outb(irq_bits << 3 | dma_bits, chip->wss_base); 484 outb(irq_bits << 3 | dma_bits, wss_base);
499#else /* OPTi93X */ 485#else /* OPTi93X */
500 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits)); 486 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
501#endif /* OPTi93X */ 487#endif /* OPTi93X */
502 488
503__skip_resources: 489__skip_resources:
504 if (chip->hardware > OPTi9XX_HW_82C928) { 490 if (chip->hardware > OPTi9XX_HW_82C928) {
505 switch (chip->mpu_port) { 491 switch (mpu_port) {
506 case 0: 492 case 0:
507 case -1: 493 case -1:
508 break; 494 break;
@@ -520,12 +506,11 @@ __skip_resources:
520 break; 506 break;
521 default: 507 default:
522 snd_printk(KERN_WARNING 508 snd_printk(KERN_WARNING
523 "MPU-401 port 0x%lx not valid\n", 509 "MPU-401 port 0x%lx not valid\n", mpu_port);
524 chip->mpu_port);
525 goto __skip_mpu; 510 goto __skip_mpu;
526 } 511 }
527 512
528 switch (chip->mpu_irq) { 513 switch (mpu_irq) {
529 case 5: 514 case 5:
530 mpu_irq_bits = 0x02; 515 mpu_irq_bits = 0x02;
531 break; 516 break;
@@ -540,12 +525,12 @@ __skip_resources:
540 break; 525 break;
541 default: 526 default:
542 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n", 527 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
543 chip->mpu_irq); 528 mpu_irq);
544 goto __skip_mpu; 529 goto __skip_mpu;
545 } 530 }
546 531
547 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 532 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
548 (chip->mpu_port <= 0) ? 0x00 : 533 (mpu_port <= 0) ? 0x00 :
549 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3, 534 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
550 0xf8); 535 0xf8);
551 } 536 }
@@ -701,6 +686,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
701{ 686{
702 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; 687 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
703 int error; 688 int error;
689 int xdma2;
704 struct snd_opti9xx *chip = card->private_data; 690 struct snd_opti9xx *chip = card->private_data;
705 struct snd_wss *codec; 691 struct snd_wss *codec;
706#ifdef CS4231 692#ifdef CS4231
@@ -715,31 +701,25 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
715 "OPTi9xx MC")) == NULL) 701 "OPTi9xx MC")) == NULL)
716 return -ENOMEM; 702 return -ENOMEM;
717 703
718 chip->wss_base = port;
719 chip->fm_port = fm_port;
720 chip->mpu_port = mpu_port;
721 chip->irq = irq;
722 chip->mpu_irq = mpu_irq;
723 chip->dma1 = dma1;
724#if defined(CS4231) || defined(OPTi93X) 704#if defined(CS4231) || defined(OPTi93X)
725 chip->dma2 = dma2; 705 xdma2 = dma2;
726#else 706#else
727 chip->dma2 = -1; 707 xdma2 = -1;
728#endif 708#endif
729 709
730 if (chip->wss_base == SNDRV_AUTO_PORT) { 710 if (port == SNDRV_AUTO_PORT) {
731 chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4); 711 port = snd_legacy_find_free_ioport(possible_ports, 4);
732 if (chip->wss_base < 0) { 712 if (port < 0) {
733 snd_printk(KERN_ERR "unable to find a free WSS port\n"); 713 snd_printk(KERN_ERR "unable to find a free WSS port\n");
734 return -EBUSY; 714 return -EBUSY;
735 } 715 }
736 } 716 }
737 error = snd_opti9xx_configure(chip); 717 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
718 mpu_port, mpu_irq);
738 if (error) 719 if (error)
739 return error; 720 return error;
740 721
741 error = snd_wss_create(card, chip->wss_base + 4, -1, 722 error = snd_wss_create(card, port + 4, -1, irq, dma1, xdma2,
742 chip->irq, chip->dma1, chip->dma2,
743#ifdef OPTi93X 723#ifdef OPTi93X
744 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ, 724 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
745#else 725#else
@@ -763,35 +743,35 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
763 return error; 743 return error;
764#endif 744#endif
765#ifdef OPTi93X 745#ifdef OPTi93X
766 error = request_irq(chip->irq, snd_opti93x_interrupt, 746 error = request_irq(irq, snd_opti93x_interrupt,
767 IRQF_DISABLED, DEV_NAME" - WSS", codec); 747 IRQF_DISABLED, DEV_NAME" - WSS", codec);
768 if (error < 0) { 748 if (error < 0) {
769 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq); 749 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
770 return error; 750 return error;
771 } 751 }
772#endif 752#endif
753 chip->irq = irq;
773 strcpy(card->driver, chip->name); 754 strcpy(card->driver, chip->name);
774 sprintf(card->shortname, "OPTi %s", card->driver); 755 sprintf(card->shortname, "OPTi %s", card->driver);
775#if defined(CS4231) || defined(OPTi93X) 756#if defined(CS4231) || defined(OPTi93X)
776 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d", 757 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
777 card->shortname, pcm->name, chip->wss_base + 4, 758 card->shortname, pcm->name, port + 4, irq, dma1, xdma2);
778 chip->irq, chip->dma1, chip->dma2);
779#else 759#else
780 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d", 760 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
781 card->shortname, pcm->name, chip->wss_base + 4, 761 card->shortname, pcm->name, port + 4, irq, dma1);
782 chip->irq, chip->dma1);
783#endif /* CS4231 || OPTi93X */ 762#endif /* CS4231 || OPTi93X */
784 763
785 if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT) 764 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
786 rmidi = NULL; 765 rmidi = NULL;
787 else 766 else {
788 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 767 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
789 chip->mpu_port, 0, chip->mpu_irq, IRQF_DISABLED, 768 mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi);
790 &rmidi))) 769 if (error)
791 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", 770 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
792 chip->mpu_port); 771 mpu_port);
772 }
793 773
794 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { 774 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
795 struct snd_opl3 *opl3 = NULL; 775 struct snd_opl3 *opl3 = NULL;
796#ifndef OPTi93X 776#ifndef OPTi93X
797 if (chip->hardware == OPTi9XX_HW_82C928 || 777 if (chip->hardware == OPTi9XX_HW_82C928 ||
@@ -801,9 +781,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
801 /* assume we have an OPL4 */ 781 /* assume we have an OPL4 */
802 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 782 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
803 0x20, 0x20); 783 0x20, 0x20);
804 if (snd_opl4_create(card, 784 if (snd_opl4_create(card, fm_port, fm_port - 8,
805 chip->fm_port,
806 chip->fm_port - 8,
807 2, &opl3, &opl4) < 0) { 785 2, &opl3, &opl4) < 0) {
808 /* no luck, use OPL3 instead */ 786 /* no luck, use OPL3 instead */
809 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 787 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
@@ -811,12 +789,10 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
811 } 789 }
812 } 790 }
813#endif /* !OPTi93X */ 791#endif /* !OPTi93X */
814 if (!opl3 && snd_opl3_create(card, 792 if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
815 chip->fm_port,
816 chip->fm_port + 2,
817 OPL3_HW_AUTO, 0, &opl3) < 0) { 793 OPL3_HW_AUTO, 0, &opl3) < 0) {
818 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n", 794 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
819 chip->fm_port, chip->fm_port + 4 - 1); 795 fm_port, fm_port + 4 - 1);
820 } 796 }
821 if (opl3) { 797 if (opl3) {
822 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth); 798 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
diff --git a/sound/isa/sb/sb_mixer.c b/sound/isa/sb/sb_mixer.c
index 475220bbcc96..318ff0c823e7 100644
--- a/sound/isa/sb/sb_mixer.c
+++ b/sound/isa/sb/sb_mixer.c
@@ -631,7 +631,7 @@ static struct sbmix_elem snd_sb16_ctl_mic_play_switch =
631static struct sbmix_elem snd_sb16_ctl_mic_play_vol = 631static struct sbmix_elem snd_sb16_ctl_mic_play_vol =
632 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31); 632 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31);
633static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol = 633static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol =
634 SB_SINGLE("PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3); 634 SB_SINGLE("Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3);
635static struct sbmix_elem snd_sb16_ctl_capture_vol = 635static struct sbmix_elem snd_sb16_ctl_capture_vol =
636 SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3); 636 SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3);
637static struct sbmix_elem snd_sb16_ctl_play_vol = 637static struct sbmix_elem snd_sb16_ctl_play_vol =
@@ -689,7 +689,7 @@ static struct sbmix_elem snd_dt019x_ctl_cd_play_vol =
689static struct sbmix_elem snd_dt019x_ctl_mic_play_vol = 689static struct sbmix_elem snd_dt019x_ctl_mic_play_vol =
690 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7); 690 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7);
691static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol = 691static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol =
692 SB_SINGLE("PC Speaker Volume", SB_DT019X_SPKR_DEV, 0, 7); 692 SB_SINGLE("Beep Volume", SB_DT019X_SPKR_DEV, 0, 7);
693static struct sbmix_elem snd_dt019x_ctl_line_play_vol = 693static struct sbmix_elem snd_dt019x_ctl_line_play_vol =
694 SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15); 694 SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15);
695static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch = 695static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch =
diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c
index 66187122377c..e2d5d2d3ed96 100644
--- a/sound/isa/sscape.c
+++ b/sound/isa/sscape.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Low-level ALSA driver for the ENSONIQ SoundScape PnP 2 * Low-level ALSA driver for the ENSONIQ SoundScape
3 * Copyright (c) by Chris Rankin 3 * Copyright (c) by Chris Rankin
4 * 4 *
5 * This driver was written in part using information obtained from 5 * This driver was written in part using information obtained from
@@ -25,31 +25,36 @@
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/isa.h> 26#include <linux/isa.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/firmware.h>
28#include <linux/pnp.h> 29#include <linux/pnp.h>
29#include <linux/spinlock.h> 30#include <linux/spinlock.h>
30#include <linux/moduleparam.h> 31#include <linux/moduleparam.h>
31#include <asm/dma.h> 32#include <asm/dma.h>
32#include <sound/core.h> 33#include <sound/core.h>
33#include <sound/hwdep.h>
34#include <sound/wss.h> 34#include <sound/wss.h>
35#include <sound/mpu401.h> 35#include <sound/mpu401.h>
36#include <sound/initval.h> 36#include <sound/initval.h>
37 37
38#include <sound/sscape_ioctl.h>
39
40 38
41MODULE_AUTHOR("Chris Rankin"); 39MODULE_AUTHOR("Chris Rankin");
42MODULE_DESCRIPTION("ENSONIQ SoundScape PnP driver"); 40MODULE_DESCRIPTION("ENSONIQ SoundScape driver");
43MODULE_LICENSE("GPL"); 41MODULE_LICENSE("GPL");
44 42MODULE_FIRMWARE("sndscape.co0");
45static int index[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IDX; 43MODULE_FIRMWARE("sndscape.co1");
46static char* id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_STR; 44MODULE_FIRMWARE("sndscape.co2");
47static long port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT; 45MODULE_FIRMWARE("sndscape.co3");
48static long wss_port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT; 46MODULE_FIRMWARE("sndscape.co4");
49static int irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ; 47MODULE_FIRMWARE("scope.cod");
50static int mpu_irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ; 48
51static int dma[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA; 49static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
52static int dma2[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA; 50static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
51static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
52static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
53static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
54static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
55static int dma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
56static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
57static bool joystick[SNDRV_CARDS];
53 58
54module_param_array(index, int, NULL, 0444); 59module_param_array(index, int, NULL, 0444);
55MODULE_PARM_DESC(index, "Index number for SoundScape soundcard"); 60MODULE_PARM_DESC(index, "Index number for SoundScape soundcard");
@@ -75,6 +80,9 @@ MODULE_PARM_DESC(dma, "DMA # for SoundScape driver.");
75module_param_array(dma2, int, NULL, 0444); 80module_param_array(dma2, int, NULL, 0444);
76MODULE_PARM_DESC(dma2, "DMA2 # for SoundScape driver."); 81MODULE_PARM_DESC(dma2, "DMA2 # for SoundScape driver.");
77 82
83module_param_array(joystick, bool, NULL, 0444);
84MODULE_PARM_DESC(joystick, "Enable gameport.");
85
78#ifdef CONFIG_PNP 86#ifdef CONFIG_PNP
79static int isa_registered; 87static int isa_registered;
80static int pnp_registered; 88static int pnp_registered;
@@ -101,14 +109,14 @@ MODULE_DEVICE_TABLE(pnp_card, sscape_pnpids);
101#define RX_READY 0x01 109#define RX_READY 0x01
102#define TX_READY 0x02 110#define TX_READY 0x02
103 111
104#define CMD_ACK 0x80 112#define CMD_ACK 0x80
105#define CMD_SET_MIDI_VOL 0x84 113#define CMD_SET_MIDI_VOL 0x84
106#define CMD_GET_MIDI_VOL 0x85 114#define CMD_GET_MIDI_VOL 0x85
107#define CMD_XXX_MIDI_VOL 0x86 115#define CMD_XXX_MIDI_VOL 0x86
108#define CMD_SET_EXTMIDI 0x8a 116#define CMD_SET_EXTMIDI 0x8a
109#define CMD_GET_EXTMIDI 0x8b 117#define CMD_GET_EXTMIDI 0x8b
110#define CMD_SET_MT32 0x8c 118#define CMD_SET_MT32 0x8c
111#define CMD_GET_MT32 0x8d 119#define CMD_GET_MT32 0x8d
112 120
113enum GA_REG { 121enum GA_REG {
114 GA_INTSTAT_REG = 0, 122 GA_INTSTAT_REG = 0,
@@ -127,7 +135,8 @@ enum GA_REG {
127 135
128 136
129enum card_type { 137enum card_type {
130 SSCAPE, 138 MEDIA_FX, /* Sequoia S-1000 */
139 SSCAPE, /* Sequoia S-2000 */
131 SSCAPE_PNP, 140 SSCAPE_PNP,
132 SSCAPE_VIVO, 141 SSCAPE_VIVO,
133}; 142};
@@ -140,16 +149,7 @@ struct soundscape {
140 struct resource *io_res; 149 struct resource *io_res;
141 struct resource *wss_res; 150 struct resource *wss_res;
142 struct snd_wss *chip; 151 struct snd_wss *chip;
143 struct snd_mpu401 *mpu;
144 struct snd_hwdep *hw;
145 152
146 /*
147 * The MIDI device won't work until we've loaded
148 * its firmware via a hardware-dependent device IOCTL
149 */
150 spinlock_t fwlock;
151 int hw_in_use;
152 unsigned long midi_usage;
153 unsigned char midi_vol; 153 unsigned char midi_vol;
154}; 154};
155 155
@@ -161,28 +161,21 @@ static inline struct soundscape *get_card_soundscape(struct snd_card *c)
161 return (struct soundscape *) (c->private_data); 161 return (struct soundscape *) (c->private_data);
162} 162}
163 163
164static inline struct soundscape *get_mpu401_soundscape(struct snd_mpu401 * mpu)
165{
166 return (struct soundscape *) (mpu->private_data);
167}
168
169static inline struct soundscape *get_hwdep_soundscape(struct snd_hwdep * hw)
170{
171 return (struct soundscape *) (hw->private_data);
172}
173
174
175/* 164/*
176 * Allocates some kernel memory that we can use for DMA. 165 * Allocates some kernel memory that we can use for DMA.
177 * I think this means that the memory has to map to 166 * I think this means that the memory has to map to
178 * contiguous pages of physical memory. 167 * contiguous pages of physical memory.
179 */ 168 */
180static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf, unsigned long size) 169static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf,
170 unsigned long size)
181{ 171{
182 if (buf) { 172 if (buf) {
183 if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV, snd_dma_isa_data(), 173 if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV,
174 snd_dma_isa_data(),
184 size, buf) < 0) { 175 size, buf) < 0) {
185 snd_printk(KERN_ERR "sscape: Failed to allocate %lu bytes for DMA\n", size); 176 snd_printk(KERN_ERR "sscape: Failed to allocate "
177 "%lu bytes for DMA\n",
178 size);
186 return NULL; 179 return NULL;
187 } 180 }
188 } 181 }
@@ -199,13 +192,13 @@ static void free_dmabuf(struct snd_dma_buffer *buf)
199 snd_dma_free_pages(buf); 192 snd_dma_free_pages(buf);
200} 193}
201 194
202
203/* 195/*
204 * This function writes to the SoundScape's control registers, 196 * This function writes to the SoundScape's control registers,
205 * but doesn't do any locking. It's up to the caller to do that. 197 * but doesn't do any locking. It's up to the caller to do that.
206 * This is why this function is "unsafe" ... 198 * This is why this function is "unsafe" ...
207 */ 199 */
208static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg, unsigned char val) 200static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg,
201 unsigned char val)
209{ 202{
210 outb(reg, ODIE_ADDR_IO(io_base)); 203 outb(reg, ODIE_ADDR_IO(io_base));
211 outb(val, ODIE_DATA_IO(io_base)); 204 outb(val, ODIE_DATA_IO(io_base));
@@ -215,7 +208,8 @@ static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg, unsign
215 * Write to the SoundScape's control registers, and do the 208 * Write to the SoundScape's control registers, and do the
216 * necessary locking ... 209 * necessary locking ...
217 */ 210 */
218static void sscape_write(struct soundscape *s, enum GA_REG reg, unsigned char val) 211static void sscape_write(struct soundscape *s, enum GA_REG reg,
212 unsigned char val)
219{ 213{
220 unsigned long flags; 214 unsigned long flags;
221 215
@@ -228,7 +222,8 @@ static void sscape_write(struct soundscape *s, enum GA_REG reg, unsigned char va
228 * Read from the SoundScape's control registers, but leave any 222 * Read from the SoundScape's control registers, but leave any
229 * locking to the caller. This is why the function is "unsafe" ... 223 * locking to the caller. This is why the function is "unsafe" ...
230 */ 224 */
231static inline unsigned char sscape_read_unsafe(unsigned io_base, enum GA_REG reg) 225static inline unsigned char sscape_read_unsafe(unsigned io_base,
226 enum GA_REG reg)
232{ 227{
233 outb(reg, ODIE_ADDR_IO(io_base)); 228 outb(reg, ODIE_ADDR_IO(io_base));
234 return inb(ODIE_DATA_IO(io_base)); 229 return inb(ODIE_DATA_IO(io_base));
@@ -257,9 +252,8 @@ static inline void set_midi_mode_unsafe(unsigned io_base)
257static inline int host_read_unsafe(unsigned io_base) 252static inline int host_read_unsafe(unsigned io_base)
258{ 253{
259 int data = -1; 254 int data = -1;
260 if ((inb(HOST_CTRL_IO(io_base)) & RX_READY) != 0) { 255 if ((inb(HOST_CTRL_IO(io_base)) & RX_READY) != 0)
261 data = inb(HOST_DATA_IO(io_base)); 256 data = inb(HOST_DATA_IO(io_base));
262 }
263 257
264 return data; 258 return data;
265} 259}
@@ -301,7 +295,7 @@ static inline int host_write_unsafe(unsigned io_base, unsigned char data)
301 * Also leaves all locking-issues to the caller ... 295 * Also leaves all locking-issues to the caller ...
302 */ 296 */
303static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data, 297static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
304 unsigned timeout) 298 unsigned timeout)
305{ 299{
306 int err; 300 int err;
307 301
@@ -320,7 +314,7 @@ static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
320 * 314 *
321 * NOTE: This check is based upon observation, not documentation. 315 * NOTE: This check is based upon observation, not documentation.
322 */ 316 */
323static inline int verify_mpu401(const struct snd_mpu401 * mpu) 317static inline int verify_mpu401(const struct snd_mpu401 *mpu)
324{ 318{
325 return ((inb(MPU401C(mpu)) & 0xc0) == 0x80); 319 return ((inb(MPU401C(mpu)) & 0xc0) == 0x80);
326} 320}
@@ -328,7 +322,7 @@ static inline int verify_mpu401(const struct snd_mpu401 * mpu)
328/* 322/*
329 * This is apparently the standard way to initailise an MPU-401 323 * This is apparently the standard way to initailise an MPU-401
330 */ 324 */
331static inline void initialise_mpu401(const struct snd_mpu401 * mpu) 325static inline void initialise_mpu401(const struct snd_mpu401 *mpu)
332{ 326{
333 outb(0, MPU401D(mpu)); 327 outb(0, MPU401D(mpu));
334} 328}
@@ -338,9 +332,10 @@ static inline void initialise_mpu401(const struct snd_mpu401 * mpu)
338 * The AD1845 detection fails if we *don't* do this, so I 332 * The AD1845 detection fails if we *don't* do this, so I
339 * think that this is a good idea ... 333 * think that this is a good idea ...
340 */ 334 */
341static inline void activate_ad1845_unsafe(unsigned io_base) 335static void activate_ad1845_unsafe(unsigned io_base)
342{ 336{
343 sscape_write_unsafe(io_base, GA_HMCTL_REG, (sscape_read_unsafe(io_base, GA_HMCTL_REG) & 0xcf) | 0x10); 337 unsigned char val = sscape_read_unsafe(io_base, GA_HMCTL_REG);
338 sscape_write_unsafe(io_base, GA_HMCTL_REG, (val & 0xcf) | 0x10);
344 sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80); 339 sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80);
345} 340}
346 341
@@ -359,24 +354,27 @@ static void soundscape_free(struct snd_card *c)
359 * Tell the SoundScape to begin a DMA tranfer using the given channel. 354 * Tell the SoundScape to begin a DMA tranfer using the given channel.
360 * All locking issues are left to the caller. 355 * All locking issues are left to the caller.
361 */ 356 */
362static inline void sscape_start_dma_unsafe(unsigned io_base, enum GA_REG reg) 357static void sscape_start_dma_unsafe(unsigned io_base, enum GA_REG reg)
363{ 358{
364 sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) | 0x01); 359 sscape_write_unsafe(io_base, reg,
365 sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) & 0xfe); 360 sscape_read_unsafe(io_base, reg) | 0x01);
361 sscape_write_unsafe(io_base, reg,
362 sscape_read_unsafe(io_base, reg) & 0xfe);
366} 363}
367 364
368/* 365/*
369 * Wait for a DMA transfer to complete. This is a "limited busy-wait", 366 * Wait for a DMA transfer to complete. This is a "limited busy-wait",
370 * and all locking issues are left to the caller. 367 * and all locking issues are left to the caller.
371 */ 368 */
372static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg, unsigned timeout) 369static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg,
370 unsigned timeout)
373{ 371{
374 while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) { 372 while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) {
375 udelay(100); 373 udelay(100);
376 --timeout; 374 --timeout;
377 } /* while */ 375 } /* while */
378 376
379 return (sscape_read_unsafe(io_base, reg) & 0x01); 377 return sscape_read_unsafe(io_base, reg) & 0x01;
380} 378}
381 379
382/* 380/*
@@ -392,12 +390,12 @@ static int obp_startup_ack(struct soundscape *s, unsigned timeout)
392 390
393 do { 391 do {
394 unsigned long flags; 392 unsigned long flags;
395 unsigned char x; 393 int x;
396 394
397 spin_lock_irqsave(&s->lock, flags); 395 spin_lock_irqsave(&s->lock, flags);
398 x = inb(HOST_DATA_IO(s->io_base)); 396 x = host_read_unsafe(s->io_base);
399 spin_unlock_irqrestore(&s->lock, flags); 397 spin_unlock_irqrestore(&s->lock, flags);
400 if ((x & 0xfe) == 0xfe) 398 if (x == 0xfe || x == 0xff)
401 return 1; 399 return 1;
402 400
403 msleep(10); 401 msleep(10);
@@ -419,10 +417,10 @@ static int host_startup_ack(struct soundscape *s, unsigned timeout)
419 417
420 do { 418 do {
421 unsigned long flags; 419 unsigned long flags;
422 unsigned char x; 420 int x;
423 421
424 spin_lock_irqsave(&s->lock, flags); 422 spin_lock_irqsave(&s->lock, flags);
425 x = inb(HOST_DATA_IO(s->io_base)); 423 x = host_read_unsafe(s->io_base);
426 spin_unlock_irqrestore(&s->lock, flags); 424 spin_unlock_irqrestore(&s->lock, flags);
427 if (x == 0xfe) 425 if (x == 0xfe)
428 return 1; 426 return 1;
@@ -436,15 +434,15 @@ static int host_startup_ack(struct soundscape *s, unsigned timeout)
436/* 434/*
437 * Upload a byte-stream into the SoundScape using DMA channel A. 435 * Upload a byte-stream into the SoundScape using DMA channel A.
438 */ 436 */
439static int upload_dma_data(struct soundscape *s, 437static int upload_dma_data(struct soundscape *s, const unsigned char *data,
440 const unsigned char __user *data, 438 size_t size)
441 size_t size)
442{ 439{
443 unsigned long flags; 440 unsigned long flags;
444 struct snd_dma_buffer dma; 441 struct snd_dma_buffer dma;
445 int ret; 442 int ret;
443 unsigned char val;
446 444
447 if (!get_dmabuf(&dma, PAGE_ALIGN(size))) 445 if (!get_dmabuf(&dma, PAGE_ALIGN(32 * 1024)))
448 return -ENOMEM; 446 return -ENOMEM;
449 447
450 spin_lock_irqsave(&s->lock, flags); 448 spin_lock_irqsave(&s->lock, flags);
@@ -452,70 +450,57 @@ static int upload_dma_data(struct soundscape *s,
452 /* 450 /*
453 * Reset the board ... 451 * Reset the board ...
454 */ 452 */
455 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f); 453 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
454 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val & 0x3f);
456 455
457 /* 456 /*
458 * Enable the DMA channels and configure them ... 457 * Enable the DMA channels and configure them ...
459 */ 458 */
460 sscape_write_unsafe(s->io_base, GA_DMACFG_REG, 0x50); 459 val = (s->chip->dma1 << 4) | DMA_8BIT;
461 sscape_write_unsafe(s->io_base, GA_DMAA_REG, (s->chip->dma1 << 4) | DMA_8BIT); 460 sscape_write_unsafe(s->io_base, GA_DMAA_REG, val);
462 sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20); 461 sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20);
463 462
464 /* 463 /*
465 * Take the board out of reset ... 464 * Take the board out of reset ...
466 */ 465 */
467 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x80); 466 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
467 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x80);
468 468
469 /* 469 /*
470 * Upload the user's data (firmware?) to the SoundScape 470 * Upload the firmware to the SoundScape
471 * board through the DMA channel ... 471 * board through the DMA channel ...
472 */ 472 */
473 while (size != 0) { 473 while (size != 0) {
474 unsigned long len; 474 unsigned long len;
475 475
476 /*
477 * Apparently, copying to/from userspace can sleep.
478 * We are therefore forbidden from holding any
479 * spinlocks while we copy ...
480 */
481 spin_unlock_irqrestore(&s->lock, flags);
482
483 /*
484 * Remember that the data that we want to DMA
485 * comes from USERSPACE. We have already verified
486 * the userspace pointer ...
487 */
488 len = min(size, dma.bytes); 476 len = min(size, dma.bytes);
489 len -= __copy_from_user(dma.area, data, len); 477 memcpy(dma.area, data, len);
490 data += len; 478 data += len;
491 size -= len; 479 size -= len;
492 480
493 /*
494 * Grab that spinlock again, now that we've
495 * finished copying!
496 */
497 spin_lock_irqsave(&s->lock, flags);
498
499 snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE); 481 snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE);
500 sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG); 482 sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG);
501 if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) { 483 if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) {
502 /* 484 /*
503 * Don't forget to release this spinlock we're holding ... 485 * Don't forget to release this spinlock we're holding
504 */ 486 */
505 spin_unlock_irqrestore(&s->lock, flags); 487 spin_unlock_irqrestore(&s->lock, flags);
506 488
507 snd_printk(KERN_ERR "sscape: DMA upload has timed out\n"); 489 snd_printk(KERN_ERR
490 "sscape: DMA upload has timed out\n");
508 ret = -EAGAIN; 491 ret = -EAGAIN;
509 goto _release_dma; 492 goto _release_dma;
510 } 493 }
511 } /* while */ 494 } /* while */
512 495
513 set_host_mode_unsafe(s->io_base); 496 set_host_mode_unsafe(s->io_base);
497 outb(0x0, s->io_base);
514 498
515 /* 499 /*
516 * Boot the board ... (I think) 500 * Boot the board ... (I think)
517 */ 501 */
518 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x40); 502 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
503 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x40);
519 spin_unlock_irqrestore(&s->lock, flags); 504 spin_unlock_irqrestore(&s->lock, flags);
520 505
521 /* 506 /*
@@ -525,10 +510,12 @@ static int upload_dma_data(struct soundscape *s,
525 */ 510 */
526 ret = 0; 511 ret = 0;
527 if (!obp_startup_ack(s, 5000)) { 512 if (!obp_startup_ack(s, 5000)) {
528 snd_printk(KERN_ERR "sscape: No response from on-board processor after upload\n"); 513 snd_printk(KERN_ERR "sscape: No response "
514 "from on-board processor after upload\n");
529 ret = -EAGAIN; 515 ret = -EAGAIN;
530 } else if (!host_startup_ack(s, 5000)) { 516 } else if (!host_startup_ack(s, 5000)) {
531 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n"); 517 snd_printk(KERN_ERR
518 "sscape: SoundScape failed to initialise\n");
532 ret = -EAGAIN; 519 ret = -EAGAIN;
533 } 520 }
534 521
@@ -536,7 +523,7 @@ _release_dma:
536 /* 523 /*
537 * NOTE!!! We are NOT holding any spinlocks at this point !!! 524 * NOTE!!! We are NOT holding any spinlocks at this point !!!
538 */ 525 */
539 sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_ODIE ? 0x70 : 0x40)); 526 sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_OPUS ? 0x40 : 0x70));
540 free_dmabuf(&dma); 527 free_dmabuf(&dma);
541 528
542 return ret; 529 return ret;
@@ -546,167 +533,76 @@ _release_dma:
546 * Upload the bootblock(?) into the SoundScape. The only 533 * Upload the bootblock(?) into the SoundScape. The only
547 * purpose of this block of code seems to be to tell 534 * purpose of this block of code seems to be to tell
548 * us which version of the microcode we should be using. 535 * us which version of the microcode we should be using.
549 *
550 * NOTE: The boot-block data resides in USER-SPACE!!!
551 * However, we have already verified its memory
552 * addresses by the time we get here.
553 */ 536 */
554static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_bootblock __user *bb) 537static int sscape_upload_bootblock(struct snd_card *card)
555{ 538{
539 struct soundscape *sscape = get_card_soundscape(card);
556 unsigned long flags; 540 unsigned long flags;
541 const struct firmware *init_fw = NULL;
557 int data = 0; 542 int data = 0;
558 int ret; 543 int ret;
559 544
560 ret = upload_dma_data(sscape, bb->code, sizeof(bb->code)); 545 ret = request_firmware(&init_fw, "scope.cod", card->dev);
561 546 if (ret < 0) {
562 spin_lock_irqsave(&sscape->lock, flags); 547 snd_printk(KERN_ERR "sscape: Error loading scope.cod");
563 if (ret == 0) { 548 return ret;
564 data = host_read_ctrl_unsafe(sscape->io_base, 100);
565 }
566 set_midi_mode_unsafe(sscape->io_base);
567 spin_unlock_irqrestore(&sscape->lock, flags);
568
569 if (ret == 0) {
570 if (data < 0) {
571 snd_printk(KERN_ERR "sscape: timeout reading firmware version\n");
572 ret = -EAGAIN;
573 }
574 else if (__copy_to_user(&bb->version, &data, sizeof(bb->version))) {
575 ret = -EFAULT;
576 }
577 } 549 }
550 ret = upload_dma_data(sscape, init_fw->data, init_fw->size);
578 551
579 return ret; 552 release_firmware(init_fw);
580}
581
582/*
583 * Upload the microcode into the SoundScape. The
584 * microcode is 64K of data, and if we try to copy
585 * it into a local variable then we will SMASH THE
586 * KERNEL'S STACK! We therefore leave it in USER
587 * SPACE, and save ourselves from copying it at all.
588 */
589static int sscape_upload_microcode(struct soundscape *sscape,
590 const struct sscape_microcode __user *mc)
591{
592 unsigned long flags;
593 char __user *code;
594 int err;
595 553
596 /* 554 spin_lock_irqsave(&sscape->lock, flags);
597 * We are going to have to copy this data into a special 555 if (ret == 0)
598 * DMA-able buffer before we can upload it. We shall therefore 556 data = host_read_ctrl_unsafe(sscape->io_base, 100);
599 * just check that the data pointer is valid for now.
600 *
601 * NOTE: This buffer is 64K long! That's WAY too big to
602 * copy into a stack-temporary anyway.
603 */
604 if ( get_user(code, &mc->code) ||
605 !access_ok(VERIFY_READ, code, SSCAPE_MICROCODE_SIZE) )
606 return -EFAULT;
607 557
608 if ((err = upload_dma_data(sscape, code, SSCAPE_MICROCODE_SIZE)) == 0) { 558 if (data & 0x10)
609 snd_printk(KERN_INFO "sscape: MIDI firmware loaded\n"); 559 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2f);
610 }
611 560
612 spin_lock_irqsave(&sscape->lock, flags);
613 set_midi_mode_unsafe(sscape->io_base);
614 spin_unlock_irqrestore(&sscape->lock, flags); 561 spin_unlock_irqrestore(&sscape->lock, flags);
615 562
616 initialise_mpu401(sscape->mpu); 563 data &= 0xf;
564 if (ret == 0 && data > 7) {
565 snd_printk(KERN_ERR
566 "sscape: timeout reading firmware version\n");
567 ret = -EAGAIN;
568 }
617 569
618 return err; 570 return (ret == 0) ? data : ret;
619} 571}
620 572
621/* 573/*
622 * Hardware-specific device functions, to implement special 574 * Upload the microcode into the SoundScape.
623 * IOCTLs for the SoundScape card. This is how we upload
624 * the microcode into the card, for example, and so we
625 * must ensure that no two processes can open this device
626 * simultaneously, and that we can't open it at all if
627 * someone is using the MIDI device.
628 */ 575 */
629static int sscape_hw_open(struct snd_hwdep * hw, struct file *file) 576static int sscape_upload_microcode(struct snd_card *card, int version)
630{ 577{
631 register struct soundscape *sscape = get_hwdep_soundscape(hw); 578 struct soundscape *sscape = get_card_soundscape(card);
632 unsigned long flags; 579 const struct firmware *init_fw = NULL;
580 char name[14];
633 int err; 581 int err;
634 582
635 spin_lock_irqsave(&sscape->fwlock, flags); 583 snprintf(name, sizeof(name), "sndscape.co%d", version);
636 584
637 if ((sscape->midi_usage != 0) || sscape->hw_in_use) { 585 err = request_firmware(&init_fw, name, card->dev);
638 err = -EBUSY; 586 if (err < 0) {
639 } else { 587 snd_printk(KERN_ERR "sscape: Error loading sndscape.co%d",
640 sscape->hw_in_use = 1; 588 version);
641 err = 0; 589 return err;
642 } 590 }
591 err = upload_dma_data(sscape, init_fw->data, init_fw->size);
592 if (err == 0)
593 snd_printk(KERN_INFO "sscape: MIDI firmware loaded %d KBs\n",
594 init_fw->size >> 10);
643 595
644 spin_unlock_irqrestore(&sscape->fwlock, flags); 596 release_firmware(init_fw);
645 return err;
646}
647
648static int sscape_hw_release(struct snd_hwdep * hw, struct file *file)
649{
650 register struct soundscape *sscape = get_hwdep_soundscape(hw);
651 unsigned long flags;
652
653 spin_lock_irqsave(&sscape->fwlock, flags);
654 sscape->hw_in_use = 0;
655 spin_unlock_irqrestore(&sscape->fwlock, flags);
656 return 0;
657}
658
659static int sscape_hw_ioctl(struct snd_hwdep * hw, struct file *file,
660 unsigned int cmd, unsigned long arg)
661{
662 struct soundscape *sscape = get_hwdep_soundscape(hw);
663 int err = -EBUSY;
664
665 switch (cmd) {
666 case SND_SSCAPE_LOAD_BOOTB:
667 {
668 register struct sscape_bootblock __user *bb = (struct sscape_bootblock __user *) arg;
669
670 /*
671 * We are going to have to copy this data into a special
672 * DMA-able buffer before we can upload it. We shall therefore
673 * just check that the data pointer is valid for now ...
674 */
675 if ( !access_ok(VERIFY_READ, bb->code, sizeof(bb->code)) )
676 return -EFAULT;
677
678 /*
679 * Now check that we can write the firmware version number too...
680 */
681 if ( !access_ok(VERIFY_WRITE, &bb->version, sizeof(bb->version)) )
682 return -EFAULT;
683
684 err = sscape_upload_bootblock(sscape, bb);
685 }
686 break;
687
688 case SND_SSCAPE_LOAD_MCODE:
689 {
690 register const struct sscape_microcode __user *mc = (const struct sscape_microcode __user *) arg;
691
692 err = sscape_upload_microcode(sscape, mc);
693 }
694 break;
695
696 default:
697 err = -EINVAL;
698 break;
699 } /* switch */
700 597
701 return err; 598 return err;
702} 599}
703 600
704
705/* 601/*
706 * Mixer control for the SoundScape's MIDI device. 602 * Mixer control for the SoundScape's MIDI device.
707 */ 603 */
708static int sscape_midi_info(struct snd_kcontrol *ctl, 604static int sscape_midi_info(struct snd_kcontrol *ctl,
709 struct snd_ctl_elem_info *uinfo) 605 struct snd_ctl_elem_info *uinfo)
710{ 606{
711 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 607 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
712 uinfo->count = 1; 608 uinfo->count = 1;
@@ -716,7 +612,7 @@ static int sscape_midi_info(struct snd_kcontrol *ctl,
716} 612}
717 613
718static int sscape_midi_get(struct snd_kcontrol *kctl, 614static int sscape_midi_get(struct snd_kcontrol *kctl,
719 struct snd_ctl_elem_value *uctl) 615 struct snd_ctl_elem_value *uctl)
720{ 616{
721 struct snd_wss *chip = snd_kcontrol_chip(kctl); 617 struct snd_wss *chip = snd_kcontrol_chip(kctl);
722 struct snd_card *card = chip->card; 618 struct snd_card *card = chip->card;
@@ -730,16 +626,18 @@ static int sscape_midi_get(struct snd_kcontrol *kctl,
730} 626}
731 627
732static int sscape_midi_put(struct snd_kcontrol *kctl, 628static int sscape_midi_put(struct snd_kcontrol *kctl,
733 struct snd_ctl_elem_value *uctl) 629 struct snd_ctl_elem_value *uctl)
734{ 630{
735 struct snd_wss *chip = snd_kcontrol_chip(kctl); 631 struct snd_wss *chip = snd_kcontrol_chip(kctl);
736 struct snd_card *card = chip->card; 632 struct snd_card *card = chip->card;
737 register struct soundscape *s = get_card_soundscape(card); 633 struct soundscape *s = get_card_soundscape(card);
738 unsigned long flags; 634 unsigned long flags;
739 int change; 635 int change;
636 unsigned char new_val;
740 637
741 spin_lock_irqsave(&s->lock, flags); 638 spin_lock_irqsave(&s->lock, flags);
742 639
640 new_val = uctl->value.integer.value[0] & 127;
743 /* 641 /*
744 * We need to put the board into HOST mode before we 642 * We need to put the board into HOST mode before we
745 * can send any volume-changing HOST commands ... 643 * can send any volume-changing HOST commands ...
@@ -752,15 +650,16 @@ static int sscape_midi_put(struct snd_kcontrol *kctl,
752 * and then perform another volume-related command. Perhaps the 650 * and then perform another volume-related command. Perhaps the
753 * first command is an "open" and the second command is a "close"? 651 * first command is an "open" and the second command is a "close"?
754 */ 652 */
755 if (s->midi_vol == ((unsigned char) uctl->value.integer. value[0] & 127)) { 653 if (s->midi_vol == new_val) {
756 change = 0; 654 change = 0;
757 goto __skip_change; 655 goto __skip_change;
758 } 656 }
759 change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100) 657 change = host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100)
760 && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100) 658 && host_write_ctrl_unsafe(s->io_base, new_val, 100)
761 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100)); 659 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100)
762 s->midi_vol = (unsigned char) uctl->value.integer.value[0] & 127; 660 && host_write_ctrl_unsafe(s->io_base, new_val, 100);
763 __skip_change: 661 s->midi_vol = new_val;
662__skip_change:
764 663
765 /* 664 /*
766 * Take the board out of HOST mode and back into MIDI mode ... 665 * Take the board out of HOST mode and back into MIDI mode ...
@@ -784,20 +683,25 @@ static struct snd_kcontrol_new midi_mixer_ctl = {
784 * These IRQs are encoded as bit patterns so that they can be 683 * These IRQs are encoded as bit patterns so that they can be
785 * written to the control registers. 684 * written to the control registers.
786 */ 685 */
787static unsigned __devinit get_irq_config(int irq) 686static unsigned __devinit get_irq_config(int sscape_type, int irq)
788{ 687{
789 static const int valid_irq[] = { 9, 5, 7, 10 }; 688 static const int valid_irq[] = { 9, 5, 7, 10 };
689 static const int old_irq[] = { 9, 7, 5, 15 };
790 unsigned cfg; 690 unsigned cfg;
791 691
792 for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg) { 692 if (sscape_type == MEDIA_FX) {
793 if (irq == valid_irq[cfg]) 693 for (cfg = 0; cfg < ARRAY_SIZE(old_irq); ++cfg)
794 return cfg; 694 if (irq == old_irq[cfg])
795 } /* for */ 695 return cfg;
696 } else {
697 for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg)
698 if (irq == valid_irq[cfg])
699 return cfg;
700 }
796 701
797 return INVALID_IRQ; 702 return INVALID_IRQ;
798} 703}
799 704
800
801/* 705/*
802 * Perform certain arcane port-checks to see whether there 706 * Perform certain arcane port-checks to see whether there
803 * is a SoundScape board lurking behind the given ports. 707 * is a SoundScape board lurking behind the given ports.
@@ -842,11 +746,38 @@ static int __devinit detect_sscape(struct soundscape *s, long wss_io)
842 if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e) 746 if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e)
843 goto _done; 747 goto _done;
844 748
845 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f; 749 if (s->ic_type == IC_OPUS)
846 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0); 750 activate_ad1845_unsafe(s->io_base);
847 751
848 if (s->type == SSCAPE_VIVO) 752 if (s->type == SSCAPE_VIVO)
849 wss_io += 4; 753 wss_io += 4;
754
755 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
756 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
757
758 /* wait for WSS codec */
759 for (d = 0; d < 500; d++) {
760 if ((inb(wss_io) & 0x80) == 0)
761 break;
762 spin_unlock_irqrestore(&s->lock, flags);
763 msleep(1);
764 spin_lock_irqsave(&s->lock, flags);
765 }
766
767 if ((inb(wss_io) & 0x80) != 0)
768 goto _done;
769
770 if (inb(wss_io + 2) == 0xff)
771 goto _done;
772
773 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
774 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d);
775
776 if ((inb(wss_io) & 0x80) != 0)
777 s->type = MEDIA_FX;
778
779 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
780 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
850 /* wait for WSS codec */ 781 /* wait for WSS codec */
851 for (d = 0; d < 500; d++) { 782 for (d = 0; d < 500; d++) {
852 if ((inb(wss_io) & 0x80) == 0) 783 if ((inb(wss_io) & 0x80) == 0)
@@ -855,14 +786,13 @@ static int __devinit detect_sscape(struct soundscape *s, long wss_io)
855 msleep(1); 786 msleep(1);
856 spin_lock_irqsave(&s->lock, flags); 787 spin_lock_irqsave(&s->lock, flags);
857 } 788 }
858 snd_printd(KERN_INFO "init delay = %d ms\n", d);
859 789
860 /* 790 /*
861 * SoundScape successfully detected! 791 * SoundScape successfully detected!
862 */ 792 */
863 retval = 1; 793 retval = 1;
864 794
865 _done: 795_done:
866 spin_unlock_irqrestore(&s->lock, flags); 796 spin_unlock_irqrestore(&s->lock, flags);
867 return retval; 797 return retval;
868} 798}
@@ -873,63 +803,35 @@ static int __devinit detect_sscape(struct soundscape *s, long wss_io)
873 * to crash the machine. Also check that someone isn't using the hardware 803 * to crash the machine. Also check that someone isn't using the hardware
874 * IOCTL device. 804 * IOCTL device.
875 */ 805 */
876static int mpu401_open(struct snd_mpu401 * mpu) 806static int mpu401_open(struct snd_mpu401 *mpu)
877{ 807{
878 int err;
879
880 if (!verify_mpu401(mpu)) { 808 if (!verify_mpu401(mpu)) {
881 snd_printk(KERN_ERR "sscape: MIDI disabled, please load firmware\n"); 809 snd_printk(KERN_ERR "sscape: MIDI disabled, "
882 err = -ENODEV; 810 "please load firmware\n");
883 } else { 811 return -ENODEV;
884 register struct soundscape *sscape = get_mpu401_soundscape(mpu);
885 unsigned long flags;
886
887 spin_lock_irqsave(&sscape->fwlock, flags);
888
889 if (sscape->hw_in_use || (sscape->midi_usage == ULONG_MAX)) {
890 err = -EBUSY;
891 } else {
892 ++(sscape->midi_usage);
893 err = 0;
894 }
895
896 spin_unlock_irqrestore(&sscape->fwlock, flags);
897 } 812 }
898 813
899 return err; 814 return 0;
900}
901
902static void mpu401_close(struct snd_mpu401 * mpu)
903{
904 register struct soundscape *sscape = get_mpu401_soundscape(mpu);
905 unsigned long flags;
906
907 spin_lock_irqsave(&sscape->fwlock, flags);
908 --(sscape->midi_usage);
909 spin_unlock_irqrestore(&sscape->fwlock, flags);
910} 815}
911 816
912/* 817/*
913 * Initialse an MPU-401 subdevice for MIDI support on the SoundScape. 818 * Initialse an MPU-401 subdevice for MIDI support on the SoundScape.
914 */ 819 */
915static int __devinit create_mpu401(struct snd_card *card, int devnum, unsigned long port, int irq) 820static int __devinit create_mpu401(struct snd_card *card, int devnum,
821 unsigned long port, int irq)
916{ 822{
917 struct soundscape *sscape = get_card_soundscape(card); 823 struct soundscape *sscape = get_card_soundscape(card);
918 struct snd_rawmidi *rawmidi; 824 struct snd_rawmidi *rawmidi;
919 int err; 825 int err;
920 826
921 if ((err = snd_mpu401_uart_new(card, devnum, 827 err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port,
922 MPU401_HW_MPU401, 828 MPU401_INFO_INTEGRATED, irq, IRQF_DISABLED,
923 port, MPU401_INFO_INTEGRATED, 829 &rawmidi);
924 irq, IRQF_DISABLED, 830 if (err == 0) {
925 &rawmidi)) == 0) { 831 struct snd_mpu401 *mpu = rawmidi->private_data;
926 struct snd_mpu401 *mpu = (struct snd_mpu401 *) rawmidi->private_data;
927 mpu->open_input = mpu401_open; 832 mpu->open_input = mpu401_open;
928 mpu->open_output = mpu401_open; 833 mpu->open_output = mpu401_open;
929 mpu->close_input = mpu401_close;
930 mpu->close_output = mpu401_close;
931 mpu->private_data = sscape; 834 mpu->private_data = sscape;
932 sscape->mpu = mpu;
933 835
934 initialise_mpu401(mpu); 836 initialise_mpu401(mpu);
935 } 837 }
@@ -950,32 +852,34 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
950 register struct soundscape *sscape = get_card_soundscape(card); 852 register struct soundscape *sscape = get_card_soundscape(card);
951 struct snd_wss *chip; 853 struct snd_wss *chip;
952 int err; 854 int err;
855 int codec_type = WSS_HW_DETECT;
953 856
954 if (sscape->type == SSCAPE_VIVO) 857 switch (sscape->type) {
955 port += 4; 858 case MEDIA_FX:
859 case SSCAPE:
860 /*
861 * There are some freak examples of early Soundscape cards
862 * with CS4231 instead of AD1848/CS4248. Unfortunately, the
863 * CS4231 works only in CS4248 compatibility mode on
864 * these cards so force it.
865 */
866 if (sscape->ic_type != IC_OPUS)
867 codec_type = WSS_HW_AD1848;
868 break;
956 869
957 if (dma1 == dma2) 870 case SSCAPE_VIVO:
958 dma2 = -1; 871 port += 4;
872 break;
873 default:
874 break;
875 }
959 876
960 err = snd_wss_create(card, port, -1, irq, dma1, dma2, 877 err = snd_wss_create(card, port, -1, irq, dma1, dma2,
961 WSS_HW_DETECT, WSS_HWSHARE_DMA1, &chip); 878 codec_type, WSS_HWSHARE_DMA1, &chip);
962 if (!err) { 879 if (!err) {
963 unsigned long flags; 880 unsigned long flags;
964 struct snd_pcm *pcm; 881 struct snd_pcm *pcm;
965 882
966/*
967 * It turns out that the PLAYBACK_ENABLE bit is set
968 * by the lowlevel driver ...
969 *
970#define AD1845_IFACE_CONFIG \
971 (CS4231_AUTOCALIB | CS4231_RECORD_ENABLE | CS4231_PLAYBACK_ENABLE)
972 snd_wss_mce_up(chip);
973 spin_lock_irqsave(&chip->reg_lock, flags);
974 snd_wss_out(chip, CS4231_IFACE_CTRL, AD1845_IFACE_CONFIG);
975 spin_unlock_irqrestore(&chip->reg_lock, flags);
976 snd_wss_mce_down(chip);
977 */
978
979 if (sscape->type != SSCAPE_VIVO) { 883 if (sscape->type != SSCAPE_VIVO) {
980 /* 884 /*
981 * The input clock frequency on the SoundScape must 885 * The input clock frequency on the SoundScape must
@@ -1022,17 +926,10 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1022 } 926 }
1023 } 927 }
1024 928
1025 strcpy(card->driver, "SoundScape");
1026 strcpy(card->shortname, pcm->name);
1027 snprintf(card->longname, sizeof(card->longname),
1028 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
1029 pcm->name, chip->port, chip->irq,
1030 chip->dma1, chip->dma2);
1031
1032 sscape->chip = chip; 929 sscape->chip = chip;
1033 } 930 }
1034 931
1035 _error: 932_error:
1036 return err; 933 return err;
1037} 934}
1038 935
@@ -1051,21 +948,8 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1051 struct resource *wss_res; 948 struct resource *wss_res;
1052 unsigned long flags; 949 unsigned long flags;
1053 int err; 950 int err;
1054 951 int val;
1055 /* 952 const char *name;
1056 * Check that the user didn't pass us garbage data ...
1057 */
1058 irq_cfg = get_irq_config(irq[dev]);
1059 if (irq_cfg == INVALID_IRQ) {
1060 snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
1061 return -ENXIO;
1062 }
1063
1064 mpu_irq_cfg = get_irq_config(mpu_irq[dev]);
1065 if (mpu_irq_cfg == INVALID_IRQ) {
1066 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
1067 return -ENXIO;
1068 }
1069 953
1070 /* 954 /*
1071 * Grab IO ports that we will need to probe so that we 955 * Grab IO ports that we will need to probe so that we
@@ -1098,41 +982,51 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1098 } 982 }
1099 983
1100 spin_lock_init(&sscape->lock); 984 spin_lock_init(&sscape->lock);
1101 spin_lock_init(&sscape->fwlock);
1102 sscape->io_res = io_res; 985 sscape->io_res = io_res;
1103 sscape->wss_res = wss_res; 986 sscape->wss_res = wss_res;
1104 sscape->io_base = port[dev]; 987 sscape->io_base = port[dev];
1105 988
1106 if (!detect_sscape(sscape, wss_port[dev])) { 989 if (!detect_sscape(sscape, wss_port[dev])) {
1107 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", sscape->io_base); 990 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n",
991 sscape->io_base);
1108 err = -ENODEV; 992 err = -ENODEV;
1109 goto _release_dma; 993 goto _release_dma;
1110 } 994 }
1111 995
1112 printk(KERN_INFO "sscape: hardware detected at 0x%x, using IRQ %d, DMA %d\n", 996 switch (sscape->type) {
1113 sscape->io_base, irq[dev], dma[dev]); 997 case MEDIA_FX:
998 name = "MediaFX/SoundFX";
999 break;
1000 case SSCAPE:
1001 name = "Soundscape";
1002 break;
1003 case SSCAPE_PNP:
1004 name = "Soundscape PnP";
1005 break;
1006 case SSCAPE_VIVO:
1007 name = "Soundscape VIVO";
1008 break;
1009 default:
1010 name = "unknown Soundscape";
1011 break;
1012 }
1114 1013
1115 if (sscape->type != SSCAPE_VIVO) { 1014 printk(KERN_INFO "sscape: %s card detected at 0x%x, using IRQ %d, DMA %d\n",
1116 /* 1015 name, sscape->io_base, irq[dev], dma[dev]);
1117 * Now create the hardware-specific device so that we can 1016
1118 * load the microcode into the on-board processor. 1017 /*
1119 * We cannot use the MPU-401 MIDI system until this firmware 1018 * Check that the user didn't pass us garbage data ...
1120 * has been loaded into the card. 1019 */
1121 */ 1020 irq_cfg = get_irq_config(sscape->type, irq[dev]);
1122 err = snd_hwdep_new(card, "MC68EC000", 0, &(sscape->hw)); 1021 if (irq_cfg == INVALID_IRQ) {
1123 if (err < 0) { 1022 snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
1124 printk(KERN_ERR "sscape: Failed to create " 1023 return -ENXIO;
1125 "firmware device\n"); 1024 }
1126 goto _release_dma; 1025
1127 } 1026 mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]);
1128 strlcpy(sscape->hw->name, "SoundScape M68K", 1027 if (mpu_irq_cfg == INVALID_IRQ) {
1129 sizeof(sscape->hw->name)); 1028 snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
1130 sscape->hw->name[sizeof(sscape->hw->name) - 1] = '\0'; 1029 return -ENXIO;
1131 sscape->hw->iface = SNDRV_HWDEP_IFACE_SSCAPE;
1132 sscape->hw->ops.open = sscape_hw_open;
1133 sscape->hw->ops.release = sscape_hw_release;
1134 sscape->hw->ops.ioctl = sscape_hw_ioctl;
1135 sscape->hw->private_data = sscape;
1136 } 1030 }
1137 1031
1138 /* 1032 /*
@@ -1141,9 +1035,6 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1141 */ 1035 */
1142 spin_lock_irqsave(&sscape->lock, flags); 1036 spin_lock_irqsave(&sscape->lock, flags);
1143 1037
1144 activate_ad1845_unsafe(sscape->io_base);
1145
1146 sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x00); /* disable */
1147 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e); 1038 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e);
1148 sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00); 1039 sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00);
1149 1040
@@ -1151,15 +1042,23 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1151 * Enable and configure the DMA channels ... 1042 * Enable and configure the DMA channels ...
1152 */ 1043 */
1153 sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50); 1044 sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50);
1154 dma_cfg = (sscape->ic_type == IC_ODIE ? 0x70 : 0x40); 1045 dma_cfg = (sscape->ic_type == IC_OPUS ? 0x40 : 0x70);
1155 sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg); 1046 sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg);
1156 sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20); 1047 sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20);
1157 1048
1158 sscape_write_unsafe(sscape->io_base, 1049 mpu_irq_cfg |= mpu_irq_cfg << 2;
1159 GA_INTCFG_REG, 0xf0 | (mpu_irq_cfg << 2) | mpu_irq_cfg); 1050 val = sscape_read_unsafe(sscape->io_base, GA_HMCTL_REG) & 0xF7;
1051 if (joystick[dev])
1052 val |= 8;
1053 sscape_write_unsafe(sscape->io_base, GA_HMCTL_REG, val | 0x10);
1054 sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | mpu_irq_cfg);
1160 sscape_write_unsafe(sscape->io_base, 1055 sscape_write_unsafe(sscape->io_base,
1161 GA_CDCFG_REG, 0x09 | DMA_8BIT 1056 GA_CDCFG_REG, 0x09 | DMA_8BIT
1162 | (dma[dev] << 4) | (irq_cfg << 1)); 1057 | (dma[dev] << 4) | (irq_cfg << 1));
1058 /*
1059 * Enable the master IRQ ...
1060 */
1061 sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x80);
1163 1062
1164 spin_unlock_irqrestore(&sscape->lock, flags); 1063 spin_unlock_irqrestore(&sscape->lock, flags);
1165 1064
@@ -1170,32 +1069,56 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1170 err = create_ad1845(card, wss_port[dev], irq[dev], 1069 err = create_ad1845(card, wss_port[dev], irq[dev],
1171 dma[dev], dma2[dev]); 1070 dma[dev], dma2[dev]);
1172 if (err < 0) { 1071 if (err < 0) {
1173 printk(KERN_ERR "sscape: No AD1845 device at 0x%lx, IRQ %d\n", 1072 snd_printk(KERN_ERR
1174 wss_port[dev], irq[dev]); 1073 "sscape: No AD1845 device at 0x%lx, IRQ %d\n",
1074 wss_port[dev], irq[dev]);
1175 goto _release_dma; 1075 goto _release_dma;
1176 } 1076 }
1077 strcpy(card->driver, "SoundScape");
1078 strcpy(card->shortname, name);
1079 snprintf(card->longname, sizeof(card->longname),
1080 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
1081 name, sscape->chip->port, sscape->chip->irq,
1082 sscape->chip->dma1, sscape->chip->dma2);
1083
1177#define MIDI_DEVNUM 0 1084#define MIDI_DEVNUM 0
1178 if (sscape->type != SSCAPE_VIVO) { 1085 if (sscape->type != SSCAPE_VIVO) {
1179 err = create_mpu401(card, MIDI_DEVNUM, port[dev], mpu_irq[dev]); 1086 err = sscape_upload_bootblock(card);
1180 if (err < 0) { 1087 if (err >= 0)
1181 printk(KERN_ERR "sscape: Failed to create " 1088 err = sscape_upload_microcode(card, err);
1182 "MPU-401 device at 0x%lx\n",
1183 port[dev]);
1184 goto _release_dma;
1185 }
1186 1089
1187 /* 1090 if (err == 0) {
1188 * Enable the master IRQ ... 1091 err = create_mpu401(card, MIDI_DEVNUM, port[dev],
1189 */ 1092 mpu_irq[dev]);
1190 sscape_write(sscape, GA_INTENA_REG, 0x80); 1093 if (err < 0) {
1094 snd_printk(KERN_ERR "sscape: Failed to create "
1095 "MPU-401 device at 0x%lx\n",
1096 port[dev]);
1097 goto _release_dma;
1098 }
1191 1099
1192 /* 1100 /*
1193 * Initialize mixer 1101 * Initialize mixer
1194 */ 1102 */
1195 sscape->midi_vol = 0; 1103 spin_lock_irqsave(&sscape->lock, flags);
1196 host_write_ctrl_unsafe(sscape->io_base, CMD_SET_MIDI_VOL, 100); 1104 sscape->midi_vol = 0;
1197 host_write_ctrl_unsafe(sscape->io_base, 0, 100); 1105 host_write_ctrl_unsafe(sscape->io_base,
1198 host_write_ctrl_unsafe(sscape->io_base, CMD_XXX_MIDI_VOL, 100); 1106 CMD_SET_MIDI_VOL, 100);
1107 host_write_ctrl_unsafe(sscape->io_base,
1108 sscape->midi_vol, 100);
1109 host_write_ctrl_unsafe(sscape->io_base,
1110 CMD_XXX_MIDI_VOL, 100);
1111 host_write_ctrl_unsafe(sscape->io_base,
1112 sscape->midi_vol, 100);
1113 host_write_ctrl_unsafe(sscape->io_base,
1114 CMD_SET_EXTMIDI, 100);
1115 host_write_ctrl_unsafe(sscape->io_base,
1116 0, 100);
1117 host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100);
1118
1119 set_midi_mode_unsafe(sscape->io_base);
1120 spin_unlock_irqrestore(&sscape->lock, flags);
1121 }
1199 } 1122 }
1200 1123
1201 /* 1124 /*
@@ -1231,7 +1154,8 @@ static int __devinit snd_sscape_match(struct device *pdev, unsigned int i)
1231 mpu_irq[i] == SNDRV_AUTO_IRQ || 1154 mpu_irq[i] == SNDRV_AUTO_IRQ ||
1232 dma[i] == SNDRV_AUTO_DMA) { 1155 dma[i] == SNDRV_AUTO_DMA) {
1233 printk(KERN_INFO 1156 printk(KERN_INFO
1234 "sscape: insufficient parameters, need IO, IRQ, MPU-IRQ and DMA\n"); 1157 "sscape: insufficient parameters, "
1158 "need IO, IRQ, MPU-IRQ and DMA\n");
1235 return 0; 1159 return 0;
1236 } 1160 }
1237 1161
@@ -1253,13 +1177,15 @@ static int __devinit snd_sscape_probe(struct device *pdev, unsigned int dev)
1253 sscape->type = SSCAPE; 1177 sscape->type = SSCAPE;
1254 1178
1255 dma[dev] &= 0x03; 1179 dma[dev] &= 0x03;
1180 snd_card_set_dev(card, pdev);
1181
1256 ret = create_sscape(dev, card); 1182 ret = create_sscape(dev, card);
1257 if (ret < 0) 1183 if (ret < 0)
1258 goto _release_card; 1184 goto _release_card;
1259 1185
1260 snd_card_set_dev(card, pdev); 1186 ret = snd_card_register(card);
1261 if ((ret = snd_card_register(card)) < 0) { 1187 if (ret < 0) {
1262 printk(KERN_ERR "sscape: Failed to register sound card\n"); 1188 snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
1263 goto _release_card; 1189 goto _release_card;
1264 } 1190 }
1265 dev_set_drvdata(pdev, card); 1191 dev_set_drvdata(pdev, card);
@@ -1311,36 +1237,20 @@ static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
1311 * Allow this function to fail *quietly* if all the ISA PnP 1237 * Allow this function to fail *quietly* if all the ISA PnP
1312 * devices were configured using module parameters instead. 1238 * devices were configured using module parameters instead.
1313 */ 1239 */
1314 if ((idx = get_next_autoindex(idx)) >= SNDRV_CARDS) 1240 idx = get_next_autoindex(idx);
1241 if (idx >= SNDRV_CARDS)
1315 return -ENOSPC; 1242 return -ENOSPC;
1316 1243
1317 /* 1244 /*
1318 * We have found a candidate ISA PnP card. Now we
1319 * have to check that it has the devices that we
1320 * expect it to have.
1321 *
1322 * We will NOT try and autoconfigure all of the resources
1323 * needed and then activate the card as we are assuming that
1324 * has already been done at boot-time using /proc/isapnp.
1325 * We shall simply try to give each active card the resources
1326 * that it wants. This is a sensible strategy for a modular
1327 * system where unused modules are unloaded regularly.
1328 *
1329 * This strategy is utterly useless if we compile the driver
1330 * into the kernel, of course.
1331 */
1332 // printk(KERN_INFO "sscape: %s\n", card->name);
1333
1334 /*
1335 * Check that we still have room for another sound card ... 1245 * Check that we still have room for another sound card ...
1336 */ 1246 */
1337 dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL); 1247 dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
1338 if (! dev) 1248 if (!dev)
1339 return -ENODEV; 1249 return -ENODEV;
1340 1250
1341 if (!pnp_is_active(dev)) { 1251 if (!pnp_is_active(dev)) {
1342 if (pnp_activate_dev(dev) < 0) { 1252 if (pnp_activate_dev(dev) < 0) {
1343 printk(KERN_INFO "sscape: device is inactive\n"); 1253 snd_printk(KERN_INFO "sscape: device is inactive\n");
1344 return -EBUSY; 1254 return -EBUSY;
1345 } 1255 }
1346 } 1256 }
@@ -1378,14 +1288,15 @@ static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
1378 wss_port[idx] = pnp_port_start(dev, 1); 1288 wss_port[idx] = pnp_port_start(dev, 1);
1379 dma2[idx] = pnp_dma(dev, 1); 1289 dma2[idx] = pnp_dma(dev, 1);
1380 } 1290 }
1291 snd_card_set_dev(card, &pcard->card->dev);
1381 1292
1382 ret = create_sscape(idx, card); 1293 ret = create_sscape(idx, card);
1383 if (ret < 0) 1294 if (ret < 0)
1384 goto _release_card; 1295 goto _release_card;
1385 1296
1386 snd_card_set_dev(card, &pcard->card->dev); 1297 ret = snd_card_register(card);
1387 if ((ret = snd_card_register(card)) < 0) { 1298 if (ret < 0) {
1388 printk(KERN_ERR "sscape: Failed to register sound card\n"); 1299 snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
1389 goto _release_card; 1300 goto _release_card;
1390 } 1301 }
1391 1302
diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c
index 5d2ba1b749ab..5b9d6c18bc45 100644
--- a/sound/isa/wss/wss_lib.c
+++ b/sound/isa/wss/wss_lib.c
@@ -1682,7 +1682,7 @@ static void snd_wss_resume(struct snd_wss *chip)
1682} 1682}
1683#endif /* CONFIG_PM */ 1683#endif /* CONFIG_PM */
1684 1684
1685int snd_wss_free(struct snd_wss *chip) 1685static int snd_wss_free(struct snd_wss *chip)
1686{ 1686{
1687 release_and_free_resource(chip->res_port); 1687 release_and_free_resource(chip->res_port);
1688 release_and_free_resource(chip->res_cport); 1688 release_and_free_resource(chip->res_cport);
@@ -1705,7 +1705,6 @@ int snd_wss_free(struct snd_wss *chip)
1705 kfree(chip); 1705 kfree(chip);
1706 return 0; 1706 return 0;
1707} 1707}
1708EXPORT_SYMBOL(snd_wss_free);
1709 1708
1710static int snd_wss_dev_free(struct snd_device *device) 1709static int snd_wss_dev_free(struct snd_device *device)
1711{ 1710{
@@ -2198,84 +2197,61 @@ EXPORT_SYMBOL(snd_wss_put_double);
2198static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0); 2197static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
2199static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0); 2198static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
2200static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0); 2199static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
2200static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0);
2201 2201
2202static struct snd_kcontrol_new snd_ad1848_controls[] = { 2202static struct snd_kcontrol_new snd_wss_controls[] = {
2203WSS_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 2203WSS_DOUBLE("PCM Playback Switch", 0,
2204 7, 7, 1, 1), 2204 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2205WSS_DOUBLE_TLV("PCM Playback Volume", 0, 2205WSS_DOUBLE_TLV("PCM Playback Volume", 0,
2206 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1, 2206 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1,
2207 db_scale_6bit), 2207 db_scale_6bit),
2208WSS_DOUBLE("Aux Playback Switch", 0, 2208WSS_DOUBLE("Aux Playback Switch", 0,
2209 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), 2209 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
2210WSS_DOUBLE_TLV("Aux Playback Volume", 0, 2210WSS_DOUBLE_TLV("Aux Playback Volume", 0,
2211 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1, 2211 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
2212 db_scale_5bit_12db_max), 2212 db_scale_5bit_12db_max),
2213WSS_DOUBLE("Aux Playback Switch", 1, 2213WSS_DOUBLE("Aux Playback Switch", 1,
2214 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), 2214 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
2215WSS_DOUBLE_TLV("Aux Playback Volume", 1, 2215WSS_DOUBLE_TLV("Aux Playback Volume", 1,
2216 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1, 2216 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
2217 db_scale_5bit_12db_max), 2217 db_scale_5bit_12db_max),
2218WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 2218WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT,
2219 0, 0, 15, 0, db_scale_rec_gain), 2219 0, 0, 15, 0, db_scale_rec_gain),
2220{ 2220{
2221 .name = "Capture Source",
2222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2222 .name = "Capture Source",
2223 .info = snd_wss_info_mux, 2223 .info = snd_wss_info_mux,
2224 .get = snd_wss_get_mux, 2224 .get = snd_wss_get_mux,
2225 .put = snd_wss_put_mux, 2225 .put = snd_wss_put_mux,
2226}, 2226},
2227WSS_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0), 2227WSS_DOUBLE("Mic Boost (+20dB)", 0,
2228WSS_SINGLE_TLV("Loopback Capture Volume", 0, CS4231_LOOPBACK, 1, 63, 0, 2228 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
2229 db_scale_6bit), 2229WSS_SINGLE("Loopback Capture Switch", 0,
2230}; 2230 CS4231_LOOPBACK, 0, 1, 0),
2231 2231WSS_SINGLE_TLV("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1,
2232static struct snd_kcontrol_new snd_wss_controls[] = { 2232 db_scale_6bit),
2233WSS_DOUBLE("PCM Playback Switch", 0,
2234 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2235WSS_DOUBLE("PCM Playback Volume", 0,
2236 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
2237WSS_DOUBLE("Line Playback Switch", 0, 2233WSS_DOUBLE("Line Playback Switch", 0,
2238 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), 2234 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
2239WSS_DOUBLE("Line Playback Volume", 0, 2235WSS_DOUBLE_TLV("Line Playback Volume", 0,
2240 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), 2236 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1,
2241WSS_DOUBLE("Aux Playback Switch", 0, 2237 db_scale_5bit_12db_max),
2242 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), 2238WSS_SINGLE("Beep Playback Switch", 0,
2243WSS_DOUBLE("Aux Playback Volume", 0,
2244 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
2245WSS_DOUBLE("Aux Playback Switch", 1,
2246 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
2247WSS_DOUBLE("Aux Playback Volume", 1,
2248 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
2249WSS_SINGLE("Mono Playback Switch", 0,
2250 CS4231_MONO_CTRL, 7, 1, 1), 2239 CS4231_MONO_CTRL, 7, 1, 1),
2251WSS_SINGLE("Mono Playback Volume", 0, 2240WSS_SINGLE_TLV("Beep Playback Volume", 0,
2252 CS4231_MONO_CTRL, 0, 15, 1), 2241 CS4231_MONO_CTRL, 0, 15, 1,
2242 db_scale_4bit),
2253WSS_SINGLE("Mono Output Playback Switch", 0, 2243WSS_SINGLE("Mono Output Playback Switch", 0,
2254 CS4231_MONO_CTRL, 6, 1, 1), 2244 CS4231_MONO_CTRL, 6, 1, 1),
2255WSS_SINGLE("Mono Output Playback Bypass", 0, 2245WSS_SINGLE("Beep Bypass Playback Switch", 0,
2256 CS4231_MONO_CTRL, 5, 1, 0), 2246 CS4231_MONO_CTRL, 5, 1, 0),
2257WSS_DOUBLE("Capture Volume", 0,
2258 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
2259{
2260 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2261 .name = "Capture Source",
2262 .info = snd_wss_info_mux,
2263 .get = snd_wss_get_mux,
2264 .put = snd_wss_put_mux,
2265},
2266WSS_DOUBLE("Mic Boost", 0,
2267 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
2268WSS_SINGLE("Loopback Capture Switch", 0,
2269 CS4231_LOOPBACK, 0, 1, 0),
2270WSS_SINGLE("Loopback Capture Volume", 0,
2271 CS4231_LOOPBACK, 2, 63, 1)
2272}; 2247};
2273 2248
2274static struct snd_kcontrol_new snd_opti93x_controls[] = { 2249static struct snd_kcontrol_new snd_opti93x_controls[] = {
2275WSS_DOUBLE("Master Playback Switch", 0, 2250WSS_DOUBLE("Master Playback Switch", 0,
2276 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1), 2251 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
2277WSS_DOUBLE("Master Playback Volume", 0, 2252WSS_DOUBLE_TLV("Master Playback Volume", 0,
2278 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1), 2253 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
2254 db_scale_6bit),
2279WSS_DOUBLE("PCM Playback Switch", 0, 2255WSS_DOUBLE("PCM Playback Switch", 0,
2280 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), 2256 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2281WSS_DOUBLE("PCM Playback Volume", 0, 2257WSS_DOUBLE("PCM Playback Volume", 0,
@@ -2334,22 +2310,21 @@ int snd_wss_mixer(struct snd_wss *chip)
2334 if (err < 0) 2310 if (err < 0)
2335 return err; 2311 return err;
2336 } 2312 }
2337 else if (chip->hardware & WSS_HW_AD1848_MASK) 2313 else {
2338 for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++) { 2314 int count = ARRAY_SIZE(snd_wss_controls);
2339 err = snd_ctl_add(card, 2315
2340 snd_ctl_new1(&snd_ad1848_controls[idx], 2316 /* Use only the first 11 entries on AD1848 */
2341 chip)); 2317 if (chip->hardware & WSS_HW_AD1848_MASK)
2342 if (err < 0) 2318 count = 11;
2343 return err; 2319
2344 } 2320 for (idx = 0; idx < count; idx++) {
2345 else
2346 for (idx = 0; idx < ARRAY_SIZE(snd_wss_controls); idx++) {
2347 err = snd_ctl_add(card, 2321 err = snd_ctl_add(card,
2348 snd_ctl_new1(&snd_wss_controls[idx], 2322 snd_ctl_new1(&snd_wss_controls[idx],
2349 chip)); 2323 chip));
2350 if (err < 0) 2324 if (err < 0)
2351 return err; 2325 return err;
2352 } 2326 }
2327 }
2353 return 0; 2328 return 0;
2354} 2329}
2355EXPORT_SYMBOL(snd_wss_mixer); 2330EXPORT_SYMBOL(snd_wss_mixer);
diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig
index bcf2a0698d54..a513651fa149 100644
--- a/sound/oss/Kconfig
+++ b/sound/oss/Kconfig
@@ -1,5 +1,3 @@
1# drivers/sound/Config.in
2#
3# 18 Apr 1998, Michael Elizabeth Chastain, <mailto:mec@shout.net> 1# 18 Apr 1998, Michael Elizabeth Chastain, <mailto:mec@shout.net>
4# More hacking for modularisation. 2# More hacking for modularisation.
5# 3#
@@ -287,18 +285,6 @@ config SOUND_DMAP
287 285
288 Say Y unless you have 16MB or more RAM or a PCI sound card. 286 Say Y unless you have 16MB or more RAM or a PCI sound card.
289 287
290config SOUND_SSCAPE
291 tristate "Ensoniq SoundScape support"
292 help
293 Answer Y if you have a sound card based on the Ensoniq SoundScape
294 chipset. Such cards are being manufactured at least by Ensoniq, Spea
295 and Reveal (Reveal makes also other cards).
296
297 If you compile the driver into the kernel, you have to add
298 "sscape=<io>,<irq>,<dma>,<mpuio>,<mpuirq>" to the kernel command
299 line.
300
301
302config SOUND_VMIDI 288config SOUND_VMIDI
303 tristate "Loopback MIDI device support" 289 tristate "Loopback MIDI device support"
304 help 290 help
diff --git a/sound/oss/Makefile b/sound/oss/Makefile
index e0ae4d4d6a5c..567b8a74178a 100644
--- a/sound/oss/Makefile
+++ b/sound/oss/Makefile
@@ -13,7 +13,6 @@ obj-$(CONFIG_SOUND_SH_DAC_AUDIO) += sh_dac_audio.o
13obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o 13obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o
14obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o 14obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o
15obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o 15obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o
16obj-$(CONFIG_SOUND_SSCAPE) += sscape.o ad1848.o mpu401.o
17obj-$(CONFIG_SOUND_MSS) += ad1848.o 16obj-$(CONFIG_SOUND_MSS) += ad1848.o
18obj-$(CONFIG_SOUND_PAS) += pas2.o sb.o sb_lib.o uart401.o 17obj-$(CONFIG_SOUND_PAS) += pas2.o sb.o sb_lib.o uart401.o
19obj-$(CONFIG_SOUND_SB) += sb.o sb_lib.o uart401.o 18obj-$(CONFIG_SOUND_SB) += sb.o sb_lib.o uart401.o
diff --git a/sound/oss/audio.c b/sound/oss/audio.c
index b69c05b7ea7b..7df48a25c4ee 100644
--- a/sound/oss/audio.c
+++ b/sound/oss/audio.c
@@ -838,7 +838,7 @@ static int dma_ioctl(int dev, unsigned int cmd, void __user *arg)
838 if ((err = audio_devs[dev]->d->prepare_for_input(dev, 838 if ((err = audio_devs[dev]->d->prepare_for_input(dev,
839 dmap_in->fragment_size, dmap_in->nbufs)) < 0) { 839 dmap_in->fragment_size, dmap_in->nbufs)) < 0) {
840 spin_unlock_irqrestore(&dmap_in->lock,flags); 840 spin_unlock_irqrestore(&dmap_in->lock,flags);
841 return -err; 841 return err;
842 } 842 }
843 dmap_in->dma_mode = DMODE_INPUT; 843 dmap_in->dma_mode = DMODE_INPUT;
844 audio_devs[dev]->enable_bits |= PCM_ENABLE_INPUT; 844 audio_devs[dev]->enable_bits |= PCM_ENABLE_INPUT;
diff --git a/sound/oss/dmasound/dmasound_paula.c b/sound/oss/dmasound/dmasound_paula.c
index 06e9e88e4c05..bb14e4c67e89 100644
--- a/sound/oss/dmasound/dmasound_paula.c
+++ b/sound/oss/dmasound/dmasound_paula.c
@@ -657,7 +657,7 @@ static int AmiStateInfo(char *buffer, size_t space)
657 len += sprintf(buffer+len, "\tsound.volume_right = %d [0...64]\n", 657 len += sprintf(buffer+len, "\tsound.volume_right = %d [0...64]\n",
658 dmasound.volume_right); 658 dmasound.volume_right);
659 if (len >= space) { 659 if (len >= space) {
660 printk(KERN_ERR "dmasound_paula: overlowed state buffer alloc.\n") ; 660 printk(KERN_ERR "dmasound_paula: overflowed state buffer alloc.\n") ;
661 len = space ; 661 len = space ;
662 } 662 }
663 return len; 663 return len;
diff --git a/sound/oss/midi_synth.c b/sound/oss/midi_synth.c
index 9e450988ed36..3bc7104c5379 100644
--- a/sound/oss/midi_synth.c
+++ b/sound/oss/midi_synth.c
@@ -426,7 +426,7 @@ midi_synth_open(int dev, int mode)
426 int err; 426 int err;
427 struct midi_input_info *inc; 427 struct midi_input_info *inc;
428 428
429 if (orig_dev < 0 || orig_dev > num_midis || midi_devs[orig_dev] == NULL) 429 if (orig_dev < 0 || orig_dev >= num_midis || midi_devs[orig_dev] == NULL)
430 return -ENXIO; 430 return -ENXIO;
431 431
432 midi2synth[orig_dev] = dev; 432 midi2synth[orig_dev] = dev;
diff --git a/sound/oss/mpu401.c b/sound/oss/mpu401.c
index 734b8f9e2f78..0af9d24feb8f 100644
--- a/sound/oss/mpu401.c
+++ b/sound/oss/mpu401.c
@@ -770,7 +770,7 @@ static int mpu_synth_ioctl(int dev, unsigned int cmd, void __user *arg)
770 770
771 midi_dev = synth_devs[dev]->midi_dev; 771 midi_dev = synth_devs[dev]->midi_dev;
772 772
773 if (midi_dev < 0 || midi_dev > num_midis || midi_devs[midi_dev] == NULL) 773 if (midi_dev < 0 || midi_dev >= num_midis || midi_devs[midi_dev] == NULL)
774 return -ENXIO; 774 return -ENXIO;
775 775
776 devc = &dev_conf[midi_dev]; 776 devc = &dev_conf[midi_dev];
diff --git a/sound/oss/sh_dac_audio.c b/sound/oss/sh_dac_audio.c
index b2ed8757542a..4153752507e3 100644
--- a/sound/oss/sh_dac_audio.c
+++ b/sound/oss/sh_dac_audio.c
@@ -164,9 +164,6 @@ static ssize_t dac_audio_write(struct file *file, const char *buf, size_t count,
164 int free; 164 int free;
165 int nbytes; 165 int nbytes;
166 166
167 if (count < 0)
168 return -EINVAL;
169
170 if (!count) { 167 if (!count) {
171 dac_audio_sync(); 168 dac_audio_sync();
172 return 0; 169 return 0;
diff --git a/sound/oss/sscape.c b/sound/oss/sscape.c
deleted file mode 100644
index 30c36d1f35d7..000000000000
--- a/sound/oss/sscape.c
+++ /dev/null
@@ -1,1480 +0,0 @@
1/*
2 * sound/oss/sscape.c
3 *
4 * Low level driver for Ensoniq SoundScape
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * Sergey Smitienko : ensoniq p'n'p support
16 * Christoph Hellwig : adapted to module_init/module_exit
17 * Bartlomiej Zolnierkiewicz : added __init to attach_sscape()
18 * Chris Rankin : Specify that this module owns the coprocessor
19 * Arnaldo C. de Melo : added missing restore_flags in sscape_pnp_upload_file
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24
25#include "sound_config.h"
26#include "sound_firmware.h"
27
28#include <linux/types.h>
29#include <linux/errno.h>
30#include <linux/signal.h>
31#include <linux/fcntl.h>
32#include <linux/ctype.h>
33#include <linux/stddef.h>
34#include <linux/kmod.h>
35#include <asm/dma.h>
36#include <asm/io.h>
37#include <linux/wait.h>
38#include <linux/slab.h>
39#include <linux/ioport.h>
40#include <linux/delay.h>
41#include <linux/proc_fs.h>
42#include <linux/mm.h>
43#include <linux/spinlock.h>
44
45#include "coproc.h"
46
47#include "ad1848.h"
48#include "mpu401.h"
49
50/*
51 * I/O ports
52 */
53#define MIDI_DATA 0
54#define MIDI_CTRL 1
55#define HOST_CTRL 2
56#define TX_READY 0x02
57#define RX_READY 0x01
58#define HOST_DATA 3
59#define ODIE_ADDR 4
60#define ODIE_DATA 5
61
62/*
63 * Indirect registers
64 */
65
66#define GA_INTSTAT_REG 0
67#define GA_INTENA_REG 1
68#define GA_DMAA_REG 2
69#define GA_DMAB_REG 3
70#define GA_INTCFG_REG 4
71#define GA_DMACFG_REG 5
72#define GA_CDCFG_REG 6
73#define GA_SMCFGA_REG 7
74#define GA_SMCFGB_REG 8
75#define GA_HMCTL_REG 9
76
77/*
78 * DMA channel identifiers (A and B)
79 */
80
81#define SSCAPE_DMA_A 0
82#define SSCAPE_DMA_B 1
83
84#define PORT(name) (devc->base+name)
85
86/*
87 * Host commands recognized by the OBP microcode
88 */
89
90#define CMD_GEN_HOST_ACK 0x80
91#define CMD_GEN_MPU_ACK 0x81
92#define CMD_GET_BOARD_TYPE 0x82
93#define CMD_SET_CONTROL 0x88 /* Old firmware only */
94#define CMD_GET_CONTROL 0x89 /* Old firmware only */
95#define CTL_MASTER_VOL 0
96#define CTL_MIC_MODE 2
97#define CTL_SYNTH_VOL 4
98#define CTL_WAVE_VOL 7
99#define CMD_SET_EXTMIDI 0x8a
100#define CMD_GET_EXTMIDI 0x8b
101#define CMD_SET_MT32 0x8c
102#define CMD_GET_MT32 0x8d
103
104#define CMD_ACK 0x80
105
106#define IC_ODIE 1
107#define IC_OPUS 2
108
109typedef struct sscape_info
110{
111 int base, irq, dma;
112
113 int codec, codec_irq; /* required to setup pnp cards*/
114 int codec_type;
115 int ic_type;
116 char* raw_buf;
117 unsigned long raw_buf_phys;
118 int buffsize; /* -------------------------- */
119 spinlock_t lock;
120 int ok; /* Properly detected */
121 int failed;
122 int dma_allocated;
123 int codec_audiodev;
124 int opened;
125 int *osp;
126 int my_audiodev;
127} sscape_info;
128
129static struct sscape_info adev_info = {
130 0
131};
132
133static struct sscape_info *devc = &adev_info;
134static int sscape_mididev = -1;
135
136/* Some older cards have assigned interrupt bits differently than new ones */
137static char valid_interrupts_old[] = {
138 9, 7, 5, 15
139};
140
141static char valid_interrupts_new[] = {
142 9, 5, 7, 10
143};
144
145static char *valid_interrupts = valid_interrupts_new;
146
147/*
148 * See the bottom of the driver. This can be set by spea =0/1.
149 */
150
151#ifdef REVEAL_SPEA
152static char old_hardware = 1;
153#else
154static char old_hardware;
155#endif
156
157static void sleep(unsigned howlong)
158{
159 current->state = TASK_INTERRUPTIBLE;
160 schedule_timeout(howlong);
161}
162
163static unsigned char sscape_read(struct sscape_info *devc, int reg)
164{
165 unsigned long flags;
166 unsigned char val;
167
168 spin_lock_irqsave(&devc->lock,flags);
169 outb(reg, PORT(ODIE_ADDR));
170 val = inb(PORT(ODIE_DATA));
171 spin_unlock_irqrestore(&devc->lock,flags);
172 return val;
173}
174
175static void __sscape_write(int reg, int data)
176{
177 outb(reg, PORT(ODIE_ADDR));
178 outb(data, PORT(ODIE_DATA));
179}
180
181static void sscape_write(struct sscape_info *devc, int reg, int data)
182{
183 unsigned long flags;
184
185 spin_lock_irqsave(&devc->lock,flags);
186 __sscape_write(reg, data);
187 spin_unlock_irqrestore(&devc->lock,flags);
188}
189
190static unsigned char sscape_pnp_read_codec(sscape_info* devc, unsigned char reg)
191{
192 unsigned char res;
193 unsigned long flags;
194
195 spin_lock_irqsave(&devc->lock,flags);
196 outb( reg, devc -> codec);
197 res = inb (devc -> codec + 1);
198 spin_unlock_irqrestore(&devc->lock,flags);
199 return res;
200
201}
202
203static void sscape_pnp_write_codec(sscape_info* devc, unsigned char reg, unsigned char data)
204{
205 unsigned long flags;
206
207 spin_lock_irqsave(&devc->lock,flags);
208 outb( reg, devc -> codec);
209 outb( data, devc -> codec + 1);
210 spin_unlock_irqrestore(&devc->lock,flags);
211}
212
213static void host_open(struct sscape_info *devc)
214{
215 outb((0x00), PORT(HOST_CTRL)); /* Put the board to the host mode */
216}
217
218static void host_close(struct sscape_info *devc)
219{
220 outb((0x03), PORT(HOST_CTRL)); /* Put the board to the MIDI mode */
221}
222
223static int host_write(struct sscape_info *devc, unsigned char *data, int count)
224{
225 unsigned long flags;
226 int i, timeout_val;
227
228 spin_lock_irqsave(&devc->lock,flags);
229 /*
230 * Send the command and data bytes
231 */
232
233 for (i = 0; i < count; i++)
234 {
235 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
236 if (inb(PORT(HOST_CTRL)) & TX_READY)
237 break;
238
239 if (timeout_val <= 0)
240 {
241 spin_unlock_irqrestore(&devc->lock,flags);
242 return 0;
243 }
244 outb(data[i], PORT(HOST_DATA));
245 }
246 spin_unlock_irqrestore(&devc->lock,flags);
247 return 1;
248}
249
250static int host_read(struct sscape_info *devc)
251{
252 unsigned long flags;
253 int timeout_val;
254 unsigned char data;
255
256 spin_lock_irqsave(&devc->lock,flags);
257 /*
258 * Read a byte
259 */
260
261 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
262 if (inb(PORT(HOST_CTRL)) & RX_READY)
263 break;
264
265 if (timeout_val <= 0)
266 {
267 spin_unlock_irqrestore(&devc->lock,flags);
268 return -1;
269 }
270 data = inb(PORT(HOST_DATA));
271 spin_unlock_irqrestore(&devc->lock,flags);
272 return data;
273}
274
275#if 0 /* unused */
276static int host_command1(struct sscape_info *devc, int cmd)
277{
278 unsigned char buf[10];
279 buf[0] = (unsigned char) (cmd & 0xff);
280 return host_write(devc, buf, 1);
281}
282#endif /* unused */
283
284
285static int host_command2(struct sscape_info *devc, int cmd, int parm1)
286{
287 unsigned char buf[10];
288
289 buf[0] = (unsigned char) (cmd & 0xff);
290 buf[1] = (unsigned char) (parm1 & 0xff);
291
292 return host_write(devc, buf, 2);
293}
294
295static int host_command3(struct sscape_info *devc, int cmd, int parm1, int parm2)
296{
297 unsigned char buf[10];
298
299 buf[0] = (unsigned char) (cmd & 0xff);
300 buf[1] = (unsigned char) (parm1 & 0xff);
301 buf[2] = (unsigned char) (parm2 & 0xff);
302 return host_write(devc, buf, 3);
303}
304
305static void set_mt32(struct sscape_info *devc, int value)
306{
307 host_open(devc);
308 host_command2(devc, CMD_SET_MT32, value ? 1 : 0);
309 if (host_read(devc) != CMD_ACK)
310 {
311 /* printk( "SNDSCAPE: Setting MT32 mode failed\n"); */
312 }
313 host_close(devc);
314}
315
316static void set_control(struct sscape_info *devc, int ctrl, int value)
317{
318 host_open(devc);
319 host_command3(devc, CMD_SET_CONTROL, ctrl, value);
320 if (host_read(devc) != CMD_ACK)
321 {
322 /* printk( "SNDSCAPE: Setting control (%d) failed\n", ctrl); */
323 }
324 host_close(devc);
325}
326
327static void do_dma(struct sscape_info *devc, int dma_chan, unsigned long buf, int blk_size, int mode)
328{
329 unsigned char temp;
330
331 if (dma_chan != SSCAPE_DMA_A)
332 {
333 printk(KERN_WARNING "soundscape: Tried to use DMA channel != A. Why?\n");
334 return;
335 }
336 audio_devs[devc->codec_audiodev]->flags &= ~DMA_AUTOMODE;
337 DMAbuf_start_dma(devc->codec_audiodev, buf, blk_size, mode);
338 audio_devs[devc->codec_audiodev]->flags |= DMA_AUTOMODE;
339
340 temp = devc->dma << 4; /* Setup DMA channel select bits */
341 if (devc->dma <= 3)
342 temp |= 0x80; /* 8 bit DMA channel */
343
344 temp |= 1; /* Trigger DMA */
345 sscape_write(devc, GA_DMAA_REG, temp);
346 temp &= 0xfe; /* Clear DMA trigger */
347 sscape_write(devc, GA_DMAA_REG, temp);
348}
349
350static int verify_mpu(struct sscape_info *devc)
351{
352 /*
353 * The SoundScape board could be in three modes (MPU, 8250 and host).
354 * If the card is not in the MPU mode, enabling the MPU driver will
355 * cause infinite loop (the driver believes that there is always some
356 * received data in the buffer.
357 *
358 * Detect this by looking if there are more than 10 received MIDI bytes
359 * (0x00) in the buffer.
360 */
361
362 int i;
363
364 for (i = 0; i < 10; i++)
365 {
366 if (inb(devc->base + HOST_CTRL) & 0x80)
367 return 1;
368
369 if (inb(devc->base) != 0x00)
370 return 1;
371 }
372 printk(KERN_WARNING "SoundScape: The device is not in the MPU-401 mode\n");
373 return 0;
374}
375
376static int sscape_coproc_open(void *dev_info, int sub_device)
377{
378 if (sub_device == COPR_MIDI)
379 {
380 set_mt32(devc, 0);
381 if (!verify_mpu(devc))
382 return -EIO;
383 }
384 return 0;
385}
386
387static void sscape_coproc_close(void *dev_info, int sub_device)
388{
389 struct sscape_info *devc = dev_info;
390 unsigned long flags;
391
392 spin_lock_irqsave(&devc->lock,flags);
393 if (devc->dma_allocated)
394 {
395 __sscape_write(GA_DMAA_REG, 0x20); /* DMA channel disabled */
396 devc->dma_allocated = 0;
397 }
398 spin_unlock_irqrestore(&devc->lock,flags);
399 return;
400}
401
402static void sscape_coproc_reset(void *dev_info)
403{
404}
405
406static int sscape_download_boot(struct sscape_info *devc, unsigned char *block, int size, int flag)
407{
408 unsigned long flags;
409 unsigned char temp;
410 volatile int done, timeout_val;
411 static unsigned char codec_dma_bits;
412
413 if (flag & CPF_FIRST)
414 {
415 /*
416 * First block. Have to allocate DMA and to reset the board
417 * before continuing.
418 */
419
420 spin_lock_irqsave(&devc->lock,flags);
421 codec_dma_bits = sscape_read(devc, GA_CDCFG_REG);
422
423 if (devc->dma_allocated == 0)
424 devc->dma_allocated = 1;
425
426 spin_unlock_irqrestore(&devc->lock,flags);
427
428 sscape_write(devc, GA_HMCTL_REG,
429 (temp = sscape_read(devc, GA_HMCTL_REG)) & 0x3f); /*Reset */
430
431 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
432 sscape_read(devc, GA_HMCTL_REG); /* Delay */
433
434 /* Take board out of reset */
435 sscape_write(devc, GA_HMCTL_REG,
436 (temp = sscape_read(devc, GA_HMCTL_REG)) | 0x80);
437 }
438 /*
439 * Transfer one code block using DMA
440 */
441 if (audio_devs[devc->codec_audiodev]->dmap_out->raw_buf == NULL)
442 {
443 printk(KERN_WARNING "soundscape: DMA buffer not available\n");
444 return 0;
445 }
446 memcpy(audio_devs[devc->codec_audiodev]->dmap_out->raw_buf, block, size);
447
448 spin_lock_irqsave(&devc->lock,flags);
449
450 /******** INTERRUPTS DISABLED NOW ********/
451
452 do_dma(devc, SSCAPE_DMA_A,
453 audio_devs[devc->codec_audiodev]->dmap_out->raw_buf_phys,
454 size, DMA_MODE_WRITE);
455
456 /*
457 * Wait until transfer completes.
458 */
459
460 done = 0;
461 timeout_val = 30;
462 while (!done && timeout_val-- > 0)
463 {
464 int resid;
465
466 if (HZ / 50)
467 sleep(HZ / 50);
468 clear_dma_ff(devc->dma);
469 if ((resid = get_dma_residue(devc->dma)) == 0)
470 done = 1;
471 }
472
473 spin_unlock_irqrestore(&devc->lock,flags);
474 if (!done)
475 return 0;
476
477 if (flag & CPF_LAST)
478 {
479 /*
480 * Take the board out of reset
481 */
482 outb((0x00), PORT(HOST_CTRL));
483 outb((0x00), PORT(MIDI_CTRL));
484
485 temp = sscape_read(devc, GA_HMCTL_REG);
486 temp |= 0x40;
487 sscape_write(devc, GA_HMCTL_REG, temp); /* Kickstart the board */
488
489 /*
490 * Wait until the ODB wakes up
491 */
492 spin_lock_irqsave(&devc->lock,flags);
493 done = 0;
494 timeout_val = 5 * HZ;
495 while (!done && timeout_val-- > 0)
496 {
497 unsigned char x;
498
499 sleep(1);
500 x = inb(PORT(HOST_DATA));
501 if (x == 0xff || x == 0xfe) /* OBP startup acknowledge */
502 {
503 DDB(printk("Soundscape: Acknowledge = %x\n", x));
504 done = 1;
505 }
506 }
507 sscape_write(devc, GA_CDCFG_REG, codec_dma_bits);
508
509 spin_unlock_irqrestore(&devc->lock,flags);
510 if (!done)
511 {
512 printk(KERN_ERR "soundscape: The OBP didn't respond after code download\n");
513 return 0;
514 }
515 spin_lock_irqsave(&devc->lock,flags);
516 done = 0;
517 timeout_val = 5 * HZ;
518 while (!done && timeout_val-- > 0)
519 {
520 sleep(1);
521 if (inb(PORT(HOST_DATA)) == 0xfe) /* Host startup acknowledge */
522 done = 1;
523 }
524 spin_unlock_irqrestore(&devc->lock,flags);
525 if (!done)
526 {
527 printk(KERN_ERR "soundscape: OBP Initialization failed.\n");
528 return 0;
529 }
530 printk(KERN_INFO "SoundScape board initialized OK\n");
531 set_control(devc, CTL_MASTER_VOL, 100);
532 set_control(devc, CTL_SYNTH_VOL, 100);
533
534#ifdef SSCAPE_DEBUG3
535 /*
536 * Temporary debugging aid. Print contents of the registers after
537 * downloading the code.
538 */
539 {
540 int i;
541
542 for (i = 0; i < 13; i++)
543 printk("I%d = %02x (new value)\n", i, sscape_read(devc, i));
544 }
545#endif
546
547 }
548 return 1;
549}
550
551static int download_boot_block(void *dev_info, copr_buffer * buf)
552{
553 if (buf->len <= 0 || buf->len > sizeof(buf->data))
554 return -EINVAL;
555
556 if (!sscape_download_boot(devc, buf->data, buf->len, buf->flags))
557 {
558 printk(KERN_ERR "soundscape: Unable to load microcode block to the OBP.\n");
559 return -EIO;
560 }
561 return 0;
562}
563
564static int sscape_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
565{
566 copr_buffer *buf;
567 int err;
568
569 switch (cmd)
570 {
571 case SNDCTL_COPR_RESET:
572 sscape_coproc_reset(dev_info);
573 return 0;
574
575 case SNDCTL_COPR_LOAD:
576 buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
577 if (buf == NULL)
578 return -ENOSPC;
579 if (copy_from_user(buf, arg, sizeof(copr_buffer)))
580 {
581 vfree(buf);
582 return -EFAULT;
583 }
584 err = download_boot_block(dev_info, buf);
585 vfree(buf);
586 return err;
587
588 default:
589 return -EINVAL;
590 }
591}
592
593static coproc_operations sscape_coproc_operations =
594{
595 "SoundScape M68K",
596 THIS_MODULE,
597 sscape_coproc_open,
598 sscape_coproc_close,
599 sscape_coproc_ioctl,
600 sscape_coproc_reset,
601 &adev_info
602};
603
604static struct resource *sscape_ports;
605static int sscape_is_pnp;
606
607static void __init attach_sscape(struct address_info *hw_config)
608{
609#ifndef SSCAPE_REGS
610 /*
611 * Config register values for Spea/V7 Media FX and Ensoniq S-2000.
612 * These values are card
613 * dependent. If you have another SoundScape based card, you have to
614 * find the correct values. Do the following:
615 * - Compile this driver with SSCAPE_DEBUG1 defined.
616 * - Shut down and power off your machine.
617 * - Boot with DOS so that the SSINIT.EXE program is run.
618 * - Warm boot to {Linux|SYSV|BSD} and write down the lines displayed
619 * when detecting the SoundScape.
620 * - Modify the following list to use the values printed during boot.
621 * Undefine the SSCAPE_DEBUG1
622 */
623#define SSCAPE_REGS { \
624/* I0 */ 0x00, \
625/* I1 */ 0xf0, /* Note! Ignored. Set always to 0xf0 */ \
626/* I2 */ 0x20, /* Note! Ignored. Set always to 0x20 */ \
627/* I3 */ 0x20, /* Note! Ignored. Set always to 0x20 */ \
628/* I4 */ 0xf5, /* Ignored */ \
629/* I5 */ 0x10, \
630/* I6 */ 0x00, \
631/* I7 */ 0x2e, /* I7 MEM config A. Likely to vary between models */ \
632/* I8 */ 0x00, /* I8 MEM config B. Likely to vary between models */ \
633/* I9 */ 0x40 /* Ignored */ \
634 }
635#endif
636
637 unsigned long flags;
638 static unsigned char regs[10] = SSCAPE_REGS;
639
640 int i, irq_bits = 0xff;
641
642 if (old_hardware)
643 {
644 valid_interrupts = valid_interrupts_old;
645 conf_printf("Ensoniq SoundScape (old)", hw_config);
646 }
647 else
648 conf_printf("Ensoniq SoundScape", hw_config);
649
650 for (i = 0; i < 4; i++)
651 {
652 if (hw_config->irq == valid_interrupts[i])
653 {
654 irq_bits = i;
655 break;
656 }
657 }
658 if (hw_config->irq > 15 || (regs[4] = irq_bits == 0xff))
659 {
660 printk(KERN_ERR "Invalid IRQ%d\n", hw_config->irq);
661 release_region(devc->base, 2);
662 release_region(devc->base + 2, 6);
663 if (sscape_is_pnp)
664 release_region(devc->codec, 2);
665 return;
666 }
667
668 if (!sscape_is_pnp) {
669
670 spin_lock_irqsave(&devc->lock,flags);
671 /* Host interrupt enable */
672 sscape_write(devc, 1, 0xf0); /* All interrupts enabled */
673 /* DMA A status/trigger register */
674 sscape_write(devc, 2, 0x20); /* DMA channel disabled */
675 /* DMA B status/trigger register */
676 sscape_write(devc, 3, 0x20); /* DMA channel disabled */
677 /* Host interrupt config reg */
678 sscape_write(devc, 4, 0xf0 | (irq_bits << 2) | irq_bits);
679 /* Don't destroy CD-ROM DMA config bits (0xc0) */
680 sscape_write(devc, 5, (regs[5] & 0x3f) | (sscape_read(devc, 5) & 0xc0));
681 /* CD-ROM config (WSS codec actually) */
682 sscape_write(devc, 6, regs[6]);
683 sscape_write(devc, 7, regs[7]);
684 sscape_write(devc, 8, regs[8]);
685 /* Master control reg. Don't modify CR-ROM bits. Disable SB emul */
686 sscape_write(devc, 9, (sscape_read(devc, 9) & 0xf0) | 0x08);
687 spin_unlock_irqrestore(&devc->lock,flags);
688 }
689#ifdef SSCAPE_DEBUG2
690 /*
691 * Temporary debugging aid. Print contents of the registers after
692 * changing them.
693 */
694 {
695 int i;
696
697 for (i = 0; i < 13; i++)
698 printk("I%d = %02x (new value)\n", i, sscape_read(devc, i));
699 }
700#endif
701
702 if (probe_mpu401(hw_config, sscape_ports))
703 hw_config->always_detect = 1;
704 hw_config->name = "SoundScape";
705
706 hw_config->irq *= -1; /* Negative value signals IRQ sharing */
707 attach_mpu401(hw_config, THIS_MODULE);
708 hw_config->irq *= -1; /* Restore it */
709
710 if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
711 {
712 sscape_mididev = hw_config->slots[1];
713 midi_devs[hw_config->slots[1]]->coproc = &sscape_coproc_operations;
714 }
715 sscape_write(devc, GA_INTENA_REG, 0x80); /* Master IRQ enable */
716 devc->ok = 1;
717 devc->failed = 0;
718}
719
720static int detect_ga(sscape_info * devc)
721{
722 unsigned char save;
723
724 DDB(printk("Entered Soundscape detect_ga(%x)\n", devc->base));
725
726 /*
727 * First check that the address register of "ODIE" is
728 * there and that it has exactly 4 writable bits.
729 * First 4 bits
730 */
731
732 if ((save = inb(PORT(ODIE_ADDR))) & 0xf0)
733 {
734 DDB(printk("soundscape: Detect error A\n"));
735 return 0;
736 }
737 outb((0x00), PORT(ODIE_ADDR));
738 if (inb(PORT(ODIE_ADDR)) != 0x00)
739 {
740 DDB(printk("soundscape: Detect error B\n"));
741 return 0;
742 }
743 outb((0xff), PORT(ODIE_ADDR));
744 if (inb(PORT(ODIE_ADDR)) != 0x0f)
745 {
746 DDB(printk("soundscape: Detect error C\n"));
747 return 0;
748 }
749 outb((save), PORT(ODIE_ADDR));
750
751 /*
752 * Now verify that some indirect registers return zero on some bits.
753 * This may break the driver with some future revisions of "ODIE" but...
754 */
755
756 if (sscape_read(devc, 0) & 0x0c)
757 {
758 DDB(printk("soundscape: Detect error D (%x)\n", sscape_read(devc, 0)));
759 return 0;
760 }
761 if (sscape_read(devc, 1) & 0x0f)
762 {
763 DDB(printk("soundscape: Detect error E\n"));
764 return 0;
765 }
766 if (sscape_read(devc, 5) & 0x0f)
767 {
768 DDB(printk("soundscape: Detect error F\n"));
769 return 0;
770 }
771 return 1;
772}
773
774static int sscape_read_host_ctrl(sscape_info* devc)
775{
776 return host_read(devc);
777}
778
779static void sscape_write_host_ctrl2(sscape_info *devc, int a, int b)
780{
781 host_command2(devc, a, b);
782}
783
784static int sscape_alloc_dma(sscape_info *devc)
785{
786 char *start_addr, *end_addr;
787 int dma_pagesize;
788 int sz, size;
789 struct page *page;
790
791 if (devc->raw_buf != NULL) return 0; /* Already done */
792 dma_pagesize = (devc->dma < 4) ? (64 * 1024) : (128 * 1024);
793 devc->raw_buf = NULL;
794 devc->buffsize = 8192*4;
795 if (devc->buffsize > dma_pagesize) devc->buffsize = dma_pagesize;
796 start_addr = NULL;
797 /*
798 * Now loop until we get a free buffer. Try to get smaller buffer if
799 * it fails. Don't accept smaller than 8k buffer for performance
800 * reasons.
801 */
802 while (start_addr == NULL && devc->buffsize > PAGE_SIZE) {
803 for (sz = 0, size = PAGE_SIZE; size < devc->buffsize; sz++, size <<= 1);
804 devc->buffsize = PAGE_SIZE * (1 << sz);
805 start_addr = (char *) __get_free_pages(GFP_ATOMIC|GFP_DMA, sz);
806 if (start_addr == NULL) devc->buffsize /= 2;
807 }
808
809 if (start_addr == NULL) {
810 printk(KERN_ERR "sscape pnp init error: Couldn't allocate DMA buffer\n");
811 return 0;
812 } else {
813 /* make some checks */
814 end_addr = start_addr + devc->buffsize - 1;
815 /* now check if it fits into the same dma-pagesize */
816
817 if (((long) start_addr & ~(dma_pagesize - 1)) != ((long) end_addr & ~(dma_pagesize - 1))
818 || end_addr >= (char *) (MAX_DMA_ADDRESS)) {
819 printk(KERN_ERR "sscape pnp: Got invalid address 0x%lx for %db DMA-buffer\n", (long) start_addr, devc->buffsize);
820 return 0;
821 }
822 }
823 devc->raw_buf = start_addr;
824 devc->raw_buf_phys = virt_to_bus(start_addr);
825
826 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
827 SetPageReserved(page);
828 return 1;
829}
830
831static void sscape_free_dma(sscape_info *devc)
832{
833 int sz, size;
834 unsigned long start_addr, end_addr;
835 struct page *page;
836
837 if (devc->raw_buf == NULL) return;
838 for (sz = 0, size = PAGE_SIZE; size < devc->buffsize; sz++, size <<= 1);
839 start_addr = (unsigned long) devc->raw_buf;
840 end_addr = start_addr + devc->buffsize;
841
842 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
843 ClearPageReserved(page);
844
845 free_pages((unsigned long) devc->raw_buf, sz);
846 devc->raw_buf = NULL;
847}
848
849/* Intel version !!!!!!!!! */
850
851static int sscape_start_dma(int chan, unsigned long physaddr, int count, int dma_mode)
852{
853 unsigned long flags;
854
855 flags = claim_dma_lock();
856 disable_dma(chan);
857 clear_dma_ff(chan);
858 set_dma_mode(chan, dma_mode);
859 set_dma_addr(chan, physaddr);
860 set_dma_count(chan, count);
861 enable_dma(chan);
862 release_dma_lock(flags);
863 return 0;
864}
865
866static void sscape_pnp_start_dma(sscape_info* devc, int arg )
867{
868 int reg;
869 if (arg == 0) reg = 2;
870 else reg = 3;
871
872 sscape_write(devc, reg, sscape_read( devc, reg) | 0x01);
873 sscape_write(devc, reg, sscape_read( devc, reg) & 0xFE);
874}
875
876static int sscape_pnp_wait_dma (sscape_info* devc, int arg )
877{
878 int reg;
879 unsigned long i;
880 unsigned char d;
881
882 if (arg == 0) reg = 2;
883 else reg = 3;
884
885 sleep ( 1 );
886 i = 0;
887 do {
888 d = sscape_read(devc, reg) & 1;
889 if ( d == 1) break;
890 i++;
891 } while (i < 500000);
892 d = sscape_read(devc, reg) & 1;
893 return d;
894}
895
896static int sscape_pnp_alloc_dma(sscape_info* devc)
897{
898 /* printk(KERN_INFO "sscape: requesting dma\n"); */
899 if (request_dma(devc -> dma, "sscape")) return 0;
900 /* printk(KERN_INFO "sscape: dma channel allocated\n"); */
901 if (!sscape_alloc_dma(devc)) {
902 free_dma(devc -> dma);
903 return 0;
904 };
905 return 1;
906}
907
908static void sscape_pnp_free_dma(sscape_info* devc)
909{
910 sscape_free_dma( devc);
911 free_dma(devc -> dma );
912 /* printk(KERN_INFO "sscape: dma released\n"); */
913}
914
915static int sscape_pnp_upload_file(sscape_info* devc, char* fn)
916{
917 int done = 0;
918 int timeout_val;
919 char* data,*dt;
920 int len,l;
921 unsigned long flags;
922
923 sscape_write( devc, 9, sscape_read(devc, 9 ) & 0x3F );
924 sscape_write( devc, 2, (devc -> dma << 4) | 0x80 );
925 sscape_write( devc, 3, 0x20 );
926 sscape_write( devc, 9, sscape_read( devc, 9 ) | 0x80 );
927
928 len = mod_firmware_load(fn, &data);
929 if (len == 0) {
930 printk(KERN_ERR "sscape: file not found: %s\n", fn);
931 return 0;
932 }
933 dt = data;
934 spin_lock_irqsave(&devc->lock,flags);
935 while ( len > 0 ) {
936 if (len > devc -> buffsize) l = devc->buffsize;
937 else l = len;
938 len -= l;
939 memcpy(devc->raw_buf, dt, l); dt += l;
940 sscape_start_dma(devc->dma, devc->raw_buf_phys, l, 0x48);
941 sscape_pnp_start_dma ( devc, 0 );
942 if (sscape_pnp_wait_dma ( devc, 0 ) == 0) {
943 spin_unlock_irqrestore(&devc->lock,flags);
944 return 0;
945 }
946 }
947
948 spin_unlock_irqrestore(&devc->lock,flags);
949 vfree(data);
950
951 outb(0, devc -> base + 2);
952 outb(0, devc -> base);
953
954 sscape_write ( devc, 9, sscape_read( devc, 9 ) | 0x40);
955
956 timeout_val = 5 * HZ;
957 while (!done && timeout_val-- > 0)
958 {
959 unsigned char x;
960 sleep(1);
961 x = inb( devc -> base + 3);
962 if (x == 0xff || x == 0xfe) /* OBP startup acknowledge */
963 {
964 //printk(KERN_ERR "Soundscape: Acknowledge = %x\n", x);
965 done = 1;
966 }
967 }
968 timeout_val = 5 * HZ;
969 done = 0;
970 while (!done && timeout_val-- > 0)
971 {
972 unsigned char x;
973 sleep(1);
974 x = inb( devc -> base + 3);
975 if (x == 0xfe) /* OBP startup acknowledge */
976 {
977 //printk(KERN_ERR "Soundscape: Acknowledge = %x\n", x);
978 done = 1;
979 }
980 }
981
982 if ( !done ) printk(KERN_ERR "soundscape: OBP Initialization failed.\n");
983
984 sscape_write( devc, 2, devc->ic_type == IC_ODIE ? 0x70 : 0x40);
985 sscape_write( devc, 3, (devc -> dma << 4) + 0x80);
986 return 1;
987}
988
989static void __init sscape_pnp_init_hw(sscape_info* devc)
990{
991 unsigned char midi_irq = 0, sb_irq = 0;
992 unsigned i;
993 static char code_file_name[23] = "/sndscape/sndscape.cox";
994
995 int sscape_joystic_enable = 0x7f;
996 int sscape_mic_enable = 0;
997 int sscape_ext_midi = 0;
998
999 if ( !sscape_pnp_alloc_dma(devc) ) {
1000 printk(KERN_ERR "sscape: faild to allocate dma\n");
1001 return;
1002 }
1003
1004 for (i = 0; i < 4; i++) {
1005 if ( devc -> irq == valid_interrupts[i] )
1006 midi_irq = i;
1007 if ( devc -> codec_irq == valid_interrupts[i] )
1008 sb_irq = i;
1009 }
1010
1011 sscape_write( devc, 5, 0x50);
1012 sscape_write( devc, 7, 0x2e);
1013 sscape_write( devc, 8, 0x00);
1014
1015 sscape_write( devc, 2, devc->ic_type == IC_ODIE ? 0x70 : 0x40);
1016 sscape_write( devc, 3, ( devc -> dma << 4) | 0x80);
1017
1018 sscape_write (devc, 4, 0xF0 | (midi_irq<<2) | midi_irq);
1019
1020 i = 0x10; //sscape_read(devc, 9) & (devc->ic_type == IC_ODIE ? 0xf0 : 0xc0);
1021 if (sscape_joystic_enable) i |= 8;
1022
1023 sscape_write (devc, 9, i);
1024 sscape_write (devc, 6, 0x80);
1025 sscape_write (devc, 1, 0x80);
1026
1027 if (devc -> codec_type == 2) {
1028 sscape_pnp_write_codec( devc, 0x0C, 0x50);
1029 sscape_pnp_write_codec( devc, 0x10, sscape_pnp_read_codec( devc, 0x10) & 0x3F);
1030 sscape_pnp_write_codec( devc, 0x11, sscape_pnp_read_codec( devc, 0x11) | 0xC0);
1031 sscape_pnp_write_codec( devc, 29, 0x20);
1032 }
1033
1034 if (sscape_pnp_upload_file(devc, "/sndscape/scope.cod") == 0 ) {
1035 printk(KERN_ERR "sscape: faild to upload file /sndscape/scope.cod\n");
1036 sscape_pnp_free_dma(devc);
1037 return;
1038 }
1039
1040 i = sscape_read_host_ctrl( devc );
1041
1042 if ( (i & 0x0F) > 7 ) {
1043 printk(KERN_ERR "sscape: scope.cod faild\n");
1044 sscape_pnp_free_dma(devc);
1045 return;
1046 }
1047 if ( i & 0x10 ) sscape_write( devc, 7, 0x2F);
1048 code_file_name[21] = (char) ( i & 0x0F) + 0x30;
1049 if (sscape_pnp_upload_file( devc, code_file_name) == 0) {
1050 printk(KERN_ERR "sscape: faild to upload file %s\n", code_file_name);
1051 sscape_pnp_free_dma(devc);
1052 return;
1053 }
1054
1055 if (devc->ic_type != IC_ODIE) {
1056 sscape_pnp_write_codec( devc, 10, (sscape_pnp_read_codec(devc, 10) & 0x7f) |
1057 ( sscape_mic_enable == 0 ? 0x00 : 0x80) );
1058 }
1059 sscape_write_host_ctrl2( devc, 0x84, 0x64 ); /* MIDI volume */
1060 sscape_write_host_ctrl2( devc, 0x86, 0x64 ); /* MIDI volume?? */
1061 sscape_write_host_ctrl2( devc, 0x8A, sscape_ext_midi);
1062
1063 sscape_pnp_write_codec ( devc, 6, 0x3f ); //WAV_VOL
1064 sscape_pnp_write_codec ( devc, 7, 0x3f ); //WAV_VOL
1065 sscape_pnp_write_codec ( devc, 2, 0x1F ); //WD_CDXVOLL
1066 sscape_pnp_write_codec ( devc, 3, 0x1F ); //WD_CDXVOLR
1067
1068 if (devc -> codec_type == 1) {
1069 sscape_pnp_write_codec ( devc, 4, 0x1F );
1070 sscape_pnp_write_codec ( devc, 5, 0x1F );
1071 sscape_write_host_ctrl2( devc, 0x88, sscape_mic_enable);
1072 } else {
1073 int t;
1074 sscape_pnp_write_codec ( devc, 0x10, 0x1F << 1);
1075 sscape_pnp_write_codec ( devc, 0x11, 0xC0 | (0x1F << 1));
1076
1077 t = sscape_pnp_read_codec( devc, 0x00) & 0xDF;
1078 if ( (sscape_mic_enable == 0)) t |= 0;
1079 else t |= 0x20;
1080 sscape_pnp_write_codec ( devc, 0x00, t);
1081 t = sscape_pnp_read_codec( devc, 0x01) & 0xDF;
1082 if ( (sscape_mic_enable == 0) ) t |= 0;
1083 else t |= 0x20;
1084 sscape_pnp_write_codec ( devc, 0x01, t);
1085 sscape_pnp_write_codec ( devc, 0x40 | 29 , 0x20);
1086 outb(0, devc -> codec);
1087 }
1088 if (devc -> ic_type == IC_OPUS ) {
1089 int i = sscape_read( devc, 9 );
1090 sscape_write( devc, 9, i | 3 );
1091 sscape_write( devc, 3, 0x40);
1092
1093 if (request_region(0x228, 1, "sscape setup junk")) {
1094 outb(0, 0x228);
1095 release_region(0x228,1);
1096 }
1097 sscape_write( devc, 3, (devc -> dma << 4) | 0x80);
1098 sscape_write( devc, 9, i );
1099 }
1100
1101 host_close ( devc );
1102 sscape_pnp_free_dma(devc);
1103}
1104
1105static int __init detect_sscape_pnp(sscape_info* devc)
1106{
1107 long i, irq_bits = 0xff;
1108 unsigned int d;
1109
1110 DDB(printk("Entered detect_sscape_pnp(%x)\n", devc->base));
1111
1112 if (!request_region(devc->codec, 2, "sscape codec")) {
1113 printk(KERN_ERR "detect_sscape_pnp: port %x is not free\n", devc->codec);
1114 return 0;
1115 }
1116
1117 if ((inb(devc->base + 2) & 0x78) != 0)
1118 goto fail;
1119
1120 d = inb ( devc -> base + 4) & 0xF0;
1121 if (d & 0x80)
1122 goto fail;
1123
1124 if (d == 0) {
1125 devc->codec_type = 1;
1126 devc->ic_type = IC_ODIE;
1127 } else if ( (d & 0x60) != 0) {
1128 devc->codec_type = 2;
1129 devc->ic_type = IC_OPUS;
1130 } else if ( (d & 0x40) != 0) { /* WTF? */
1131 devc->codec_type = 2;
1132 devc->ic_type = IC_ODIE;
1133 } else
1134 goto fail;
1135
1136 sscape_is_pnp = 1;
1137
1138 outb(0xFA, devc -> base+4);
1139 if ((inb( devc -> base+4) & 0x9F) != 0x0A)
1140 goto fail;
1141 outb(0xFE, devc -> base+4);
1142 if ( (inb(devc -> base+4) & 0x9F) != 0x0E)
1143 goto fail;
1144 if ( (inb(devc -> base+5) & 0x9F) != 0x0E)
1145 goto fail;
1146
1147 if (devc->codec_type == 2) {
1148 if (devc->codec != devc->base + 8) {
1149 printk("soundscape warning: incorrect codec port specified\n");
1150 goto fail;
1151 }
1152 d = 0x10 | (sscape_read(devc, 9) & 0xCF);
1153 sscape_write(devc, 9, d);
1154 sscape_write(devc, 6, 0x80);
1155 } else {
1156 //todo: check codec is not base + 8
1157 }
1158
1159 d = (sscape_read(devc, 9) & 0x3F) | 0xC0;
1160 sscape_write(devc, 9, d);
1161
1162 for (i = 0; i < 550000; i++)
1163 if ( !(inb(devc -> codec) & 0x80) ) break;
1164
1165 d = inb(devc -> codec);
1166 if (d & 0x80)
1167 goto fail;
1168 if ( inb(devc -> codec + 2) == 0xFF)
1169 goto fail;
1170
1171 sscape_write(devc, 9, sscape_read(devc, 9) & 0x3F );
1172
1173 d = inb(devc -> codec) & 0x80;
1174 if ( d == 0) {
1175 printk(KERN_INFO "soundscape: hardware detected\n");
1176 valid_interrupts = valid_interrupts_new;
1177 } else {
1178 printk(KERN_INFO "soundscape: board looks like media fx\n");
1179 valid_interrupts = valid_interrupts_old;
1180 old_hardware = 1;
1181 }
1182
1183 sscape_write( devc, 9, 0xC0 | (sscape_read(devc, 9) & 0x3F) );
1184
1185 for (i = 0; i < 550000; i++)
1186 if ( !(inb(devc -> codec) & 0x80))
1187 break;
1188
1189 sscape_pnp_init_hw(devc);
1190
1191 for (i = 0; i < 4; i++)
1192 {
1193 if (devc->codec_irq == valid_interrupts[i]) {
1194 irq_bits = i;
1195 break;
1196 }
1197 }
1198 sscape_write(devc, GA_INTENA_REG, 0x00);
1199 sscape_write(devc, GA_DMACFG_REG, 0x50);
1200 sscape_write(devc, GA_DMAA_REG, 0x70);
1201 sscape_write(devc, GA_DMAB_REG, 0x20);
1202 sscape_write(devc, GA_INTCFG_REG, 0xf0);
1203 sscape_write(devc, GA_CDCFG_REG, 0x89 | (devc->dma << 4) | (irq_bits << 1));
1204
1205 sscape_pnp_write_codec( devc, 0, sscape_pnp_read_codec( devc, 0) | 0x20);
1206 sscape_pnp_write_codec( devc, 0, sscape_pnp_read_codec( devc, 1) | 0x20);
1207
1208 return 1;
1209fail:
1210 release_region(devc->codec, 2);
1211 return 0;
1212}
1213
1214static int __init probe_sscape(struct address_info *hw_config)
1215{
1216 devc->base = hw_config->io_base;
1217 devc->irq = hw_config->irq;
1218 devc->dma = hw_config->dma;
1219 devc->osp = hw_config->osp;
1220
1221#ifdef SSCAPE_DEBUG1
1222 /*
1223 * Temporary debugging aid. Print contents of the registers before
1224 * changing them.
1225 */
1226 {
1227 int i;
1228
1229 for (i = 0; i < 13; i++)
1230 printk("I%d = %02x (old value)\n", i, sscape_read(devc, i));
1231 }
1232#endif
1233 devc->failed = 1;
1234
1235 sscape_ports = request_region(devc->base, 2, "mpu401");
1236 if (!sscape_ports)
1237 return 0;
1238
1239 if (!request_region(devc->base + 2, 6, "SoundScape")) {
1240 release_region(devc->base, 2);
1241 return 0;
1242 }
1243
1244 if (!detect_ga(devc)) {
1245 if (detect_sscape_pnp(devc))
1246 return 1;
1247 release_region(devc->base, 2);
1248 release_region(devc->base + 2, 6);
1249 return 0;
1250 }
1251
1252 if (old_hardware) /* Check that it's really an old Spea/Reveal card. */
1253 {
1254 unsigned char tmp;
1255 int cc;
1256
1257 if (!((tmp = sscape_read(devc, GA_HMCTL_REG)) & 0xc0))
1258 {
1259 sscape_write(devc, GA_HMCTL_REG, tmp | 0x80);
1260 for (cc = 0; cc < 200000; ++cc)
1261 inb(devc->base + ODIE_ADDR);
1262 }
1263 }
1264 return 1;
1265}
1266
1267static int __init init_ss_ms_sound(struct address_info *hw_config)
1268{
1269 int i, irq_bits = 0xff;
1270 int ad_flags = 0;
1271 struct resource *ports;
1272
1273 if (devc->failed)
1274 {
1275 printk(KERN_ERR "soundscape: Card not detected\n");
1276 return 0;
1277 }
1278 if (devc->ok == 0)
1279 {
1280 printk(KERN_ERR "soundscape: Invalid initialization order.\n");
1281 return 0;
1282 }
1283 for (i = 0; i < 4; i++)
1284 {
1285 if (hw_config->irq == valid_interrupts[i])
1286 {
1287 irq_bits = i;
1288 break;
1289 }
1290 }
1291 if (irq_bits == 0xff) {
1292 printk(KERN_ERR "soundscape: Invalid MSS IRQ%d\n", hw_config->irq);
1293 return 0;
1294 }
1295
1296 if (old_hardware)
1297 ad_flags = 0x12345677; /* Tell that we may have a CS4248 chip (Spea-V7 Media FX) */
1298 else if (sscape_is_pnp)
1299 ad_flags = 0x87654321; /* Tell that we have a soundscape pnp with 1845 chip */
1300
1301 ports = request_region(hw_config->io_base, 4, "ad1848");
1302 if (!ports) {
1303 printk(KERN_ERR "soundscape: ports busy\n");
1304 return 0;
1305 }
1306
1307 if (!ad1848_detect(ports, &ad_flags, hw_config->osp)) {
1308 release_region(hw_config->io_base, 4);
1309 return 0;
1310 }
1311
1312 if (!sscape_is_pnp) /*pnp is already setup*/
1313 {
1314 /*
1315 * Setup the DMA polarity.
1316 */
1317 sscape_write(devc, GA_DMACFG_REG, 0x50);
1318
1319 /*
1320 * Take the gate-array off of the DMA channel.
1321 */
1322 sscape_write(devc, GA_DMAB_REG, 0x20);
1323
1324 /*
1325 * Init the AD1848 (CD-ROM) config reg.
1326 */
1327 sscape_write(devc, GA_CDCFG_REG, 0x89 | (hw_config->dma << 4) | (irq_bits << 1));
1328 }
1329
1330 if (hw_config->irq == devc->irq)
1331 printk(KERN_WARNING "soundscape: Warning! The WSS mode can't share IRQ with MIDI\n");
1332
1333 hw_config->slots[0] = ad1848_init(
1334 sscape_is_pnp ? "SoundScape" : "SoundScape PNP",
1335 ports,
1336 hw_config->irq,
1337 hw_config->dma,
1338 hw_config->dma,
1339 0,
1340 devc->osp,
1341 THIS_MODULE);
1342
1343
1344 if (hw_config->slots[0] != -1) /* The AD1848 driver installed itself */
1345 {
1346 audio_devs[hw_config->slots[0]]->coproc = &sscape_coproc_operations;
1347 devc->codec_audiodev = hw_config->slots[0];
1348 devc->my_audiodev = hw_config->slots[0];
1349
1350 /* Set proper routings here (what are they) */
1351 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE);
1352 }
1353
1354#ifdef SSCAPE_DEBUG5
1355 /*
1356 * Temporary debugging aid. Print contents of the registers
1357 * after the AD1848 device has been initialized.
1358 */
1359 {
1360 int i;
1361
1362 for (i = 0; i < 13; i++)
1363 printk("I%d = %02x\n", i, sscape_read(devc, i));
1364 }
1365#endif
1366 return 1;
1367}
1368
1369static void __exit unload_sscape(struct address_info *hw_config)
1370{
1371 release_region(devc->base + 2, 6);
1372 unload_mpu401(hw_config);
1373 if (sscape_is_pnp)
1374 release_region(devc->codec, 2);
1375}
1376
1377static void __exit unload_ss_ms_sound(struct address_info *hw_config)
1378{
1379 ad1848_unload(hw_config->io_base,
1380 hw_config->irq,
1381 devc->dma,
1382 devc->dma,
1383 0);
1384 sound_unload_audiodev(hw_config->slots[0]);
1385}
1386
1387static struct address_info cfg;
1388static struct address_info cfg_mpu;
1389
1390static int __initdata spea = -1;
1391static int mss = 0;
1392static int __initdata dma = -1;
1393static int __initdata irq = -1;
1394static int __initdata io = -1;
1395static int __initdata mpu_irq = -1;
1396static int __initdata mpu_io = -1;
1397
1398module_param(dma, int, 0);
1399module_param(irq, int, 0);
1400module_param(io, int, 0);
1401module_param(spea, int, 0); /* spea=0/1 set the old_hardware */
1402module_param(mpu_irq, int, 0);
1403module_param(mpu_io, int, 0);
1404module_param(mss, int, 0);
1405
1406static int __init init_sscape(void)
1407{
1408 printk(KERN_INFO "Soundscape driver Copyright (C) by Hannu Savolainen 1993-1996\n");
1409
1410 cfg.irq = irq;
1411 cfg.dma = dma;
1412 cfg.io_base = io;
1413
1414 cfg_mpu.irq = mpu_irq;
1415 cfg_mpu.io_base = mpu_io;
1416 /* WEH - Try to get right dma channel */
1417 cfg_mpu.dma = dma;
1418
1419 devc->codec = cfg.io_base;
1420 devc->codec_irq = cfg.irq;
1421 devc->codec_type = 0;
1422 devc->ic_type = 0;
1423 devc->raw_buf = NULL;
1424 spin_lock_init(&devc->lock);
1425
1426 if (cfg.dma == -1 || cfg.irq == -1 || cfg.io_base == -1) {
1427 printk(KERN_ERR "DMA, IRQ, and IO port must be specified.\n");
1428 return -EINVAL;
1429 }
1430
1431 if (cfg_mpu.irq == -1 && cfg_mpu.io_base != -1) {
1432 printk(KERN_ERR "MPU_IRQ must be specified if MPU_IO is set.\n");
1433 return -EINVAL;
1434 }
1435
1436 if(spea != -1) {
1437 old_hardware = spea;
1438 printk(KERN_INFO "Forcing %s hardware support.\n",
1439 spea?"new":"old");
1440 }
1441 if (probe_sscape(&cfg_mpu) == 0)
1442 return -ENODEV;
1443
1444 attach_sscape(&cfg_mpu);
1445
1446 mss = init_ss_ms_sound(&cfg);
1447
1448 return 0;
1449}
1450
1451static void __exit cleanup_sscape(void)
1452{
1453 if (mss)
1454 unload_ss_ms_sound(&cfg);
1455 unload_sscape(&cfg_mpu);
1456}
1457
1458module_init(init_sscape);
1459module_exit(cleanup_sscape);
1460
1461#ifndef MODULE
1462static int __init setup_sscape(char *str)
1463{
1464 /* io, irq, dma, mpu_io, mpu_irq */
1465 int ints[6];
1466
1467 str = get_options(str, ARRAY_SIZE(ints), ints);
1468
1469 io = ints[1];
1470 irq = ints[2];
1471 dma = ints[3];
1472 mpu_io = ints[4];
1473 mpu_irq = ints[5];
1474
1475 return 1;
1476}
1477
1478__setup("sscape=", setup_sscape);
1479#endif
1480MODULE_LICENSE("GPL");
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 75c602b5b132..351654cf7b09 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -570,6 +570,7 @@ config SND_ICE1712
570 tristate "ICEnsemble ICE1712 (Envy24)" 570 tristate "ICEnsemble ICE1712 (Envy24)"
571 select SND_MPU401_UART 571 select SND_MPU401_UART
572 select SND_AC97_CODEC 572 select SND_AC97_CODEC
573 select BITREVERSE
573 help 574 help
574 Say Y here to include support for soundcards based on the 575 Say Y here to include support for soundcards based on the
575 ICE1712 (Envy24) chip. 576 ICE1712 (Envy24) chip.
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 78288dbfc17a..20cb60afb200 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -603,8 +603,8 @@ AC97_SINGLE("Tone Control - Treble", AC97_MASTER_TONE, 0, 15, 1)
603}; 603};
604 604
605static const struct snd_kcontrol_new snd_ac97_controls_pc_beep[2] = { 605static const struct snd_kcontrol_new snd_ac97_controls_pc_beep[2] = {
606AC97_SINGLE("PC Speaker Playback Switch", AC97_PC_BEEP, 15, 1, 1), 606AC97_SINGLE("Beep Playback Switch", AC97_PC_BEEP, 15, 1, 1),
607AC97_SINGLE("PC Speaker Playback Volume", AC97_PC_BEEP, 1, 15, 1) 607AC97_SINGLE("Beep Playback Volume", AC97_PC_BEEP, 1, 15, 1)
608}; 608};
609 609
610static const struct snd_kcontrol_new snd_ac97_controls_mic_boost = 610static const struct snd_kcontrol_new snd_ac97_controls_mic_boost =
@@ -1393,7 +1393,7 @@ static int snd_ac97_mixer_build(struct snd_ac97 * ac97)
1393 } 1393 }
1394 } 1394 }
1395 1395
1396 /* build PC Speaker controls */ 1396 /* build Beep controls */
1397 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) && 1397 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
1398 ((ac97->flags & AC97_HAS_PC_BEEP) || 1398 ((ac97->flags & AC97_HAS_PC_BEEP) ||
1399 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) { 1399 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 7337abdbe4e3..139cf3b2b9d7 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -800,12 +800,12 @@ AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
800AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 800AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
801AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), 801AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
802 802
803AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1), 803AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
804AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1), 804AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
805AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1), 805AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
806AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1), 806AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
807AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1), 807AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
808AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1), 808AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
809 809
810AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), 810AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
811AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), 811AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 8451a0169f32..69867ace7860 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -830,8 +830,8 @@ static struct snd_kcontrol_new snd_azf3328_mixer_controls[] __devinitdata = {
830 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0), 830 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
831 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1), 831 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
832 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1), 832 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
833 AZF3328_MIXER_SWITCH("PC Speaker Playback Switch", IDX_MIXER_PCBEEP, 15, 1), 833 AZF3328_MIXER_SWITCH("Beep Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
834 AZF3328_MIXER_VOL_SPECIAL("PC Speaker Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1), 834 AZF3328_MIXER_VOL_SPECIAL("Beep Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
835 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1), 835 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
836 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1), 836 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
837 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1), 837 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index c8c6f437f5b3..8f443a9d61ec 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -792,8 +792,8 @@ int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
792 "Phone Playback Volume", 792 "Phone Playback Volume",
793 "Video Playback Switch", 793 "Video Playback Switch",
794 "Video Playback Volume", 794 "Video Playback Volume",
795 "PC Speaker Playback Switch", 795 "Beep Playback Switch",
796 "PC Speaker Playback Volume", 796 "Beep Playback Volume",
797 "Mono Output Select", 797 "Mono Output Select",
798 "Capture Source", 798 "Capture Source",
799 "Capture Switch", 799 "Capture Switch",
diff --git a/sound/pci/ca0106/ca0106_proc.c b/sound/pci/ca0106/ca0106_proc.c
index c62b7d10ec61..0470461cc03e 100644
--- a/sound/pci/ca0106/ca0106_proc.c
+++ b/sound/pci/ca0106/ca0106_proc.c
@@ -233,7 +233,7 @@ static void snd_ca0106_proc_dump_iec958( struct snd_info_buffer *buffer, u32 val
233 snd_iprintf(buffer, "user-defined\n"); 233 snd_iprintf(buffer, "user-defined\n");
234 break; 234 break;
235 default: 235 default:
236 snd_iprintf(buffer, "unkown\n"); 236 snd_iprintf(buffer, "unknown\n");
237 break; 237 break;
238 } 238 }
239 snd_iprintf(buffer, "Sample Bits: "); 239 snd_iprintf(buffer, "Sample Bits: ");
@@ -304,7 +304,7 @@ static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,
304 while (!snd_info_get_line(buffer, line, sizeof(line))) { 304 while (!snd_info_get_line(buffer, line, sizeof(line))) {
305 if (sscanf(line, "%x %x", &reg, &val) != 2) 305 if (sscanf(line, "%x %x", &reg, &val) != 2)
306 continue; 306 continue;
307 if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) { 307 if (reg < 0x40 && val <= 0xffffffff) {
308 spin_lock_irqsave(&emu->emu_lock, flags); 308 spin_lock_irqsave(&emu->emu_lock, flags);
309 outl(val, emu->port + (reg & 0xfffffffc)); 309 outl(val, emu->port + (reg & 0xfffffffc));
310 spin_unlock_irqrestore(&emu->emu_lock, flags); 310 spin_unlock_irqrestore(&emu->emu_lock, flags);
@@ -405,7 +405,7 @@ static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry,
405 while (!snd_info_get_line(buffer, line, sizeof(line))) { 405 while (!snd_info_get_line(buffer, line, sizeof(line))) {
406 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 406 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
407 continue; 407 continue;
408 if ((reg < 0x80) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) ) 408 if (reg < 0x80 && val <= 0xffffffff && channel_id <= 3)
409 snd_ca0106_ptr_write(emu, reg, channel_id, val); 409 snd_ca0106_ptr_write(emu, reg, channel_id, val);
410 } 410 }
411} 411}
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index ddcd4a9fd7e6..a312bae08f52 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2302,7 +2302,7 @@ static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
2302 CMIPCI_SB_VOL_MONO("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31), 2302 CMIPCI_SB_VOL_MONO("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
2303 CMIPCI_SB_SW_MONO("Mic Playback Switch", 0), 2303 CMIPCI_SB_SW_MONO("Mic Playback Switch", 0),
2304 CMIPCI_DOUBLE("Mic Capture Switch", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0, 1, 0, 0), 2304 CMIPCI_DOUBLE("Mic Capture Switch", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0, 1, 0, 0),
2305 CMIPCI_SB_VOL_MONO("PC Speaker Playback Volume", SB_DSP4_SPEAKER_DEV, 6, 3), 2305 CMIPCI_SB_VOL_MONO("Beep Playback Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
2306 CMIPCI_MIXER_VOL_STEREO("Aux Playback Volume", CM_REG_AUX_VOL, 4, 0, 15), 2306 CMIPCI_MIXER_VOL_STEREO("Aux Playback Volume", CM_REG_AUX_VOL, 4, 0, 15),
2307 CMIPCI_MIXER_SW_STEREO("Aux Playback Switch", CM_REG_MIXER2, CM_VAUXLM_SHIFT, CM_VAUXRM_SHIFT, 0), 2307 CMIPCI_MIXER_SW_STEREO("Aux Playback Switch", CM_REG_MIXER2, CM_VAUXLM_SHIFT, CM_VAUXRM_SHIFT, 0),
2308 CMIPCI_MIXER_SW_STEREO("Aux Capture Switch", CM_REG_MIXER2, CM_RAUXLEN_SHIFT, CM_RAUXREN_SHIFT, 0), 2308 CMIPCI_MIXER_SW_STEREO("Aux Capture Switch", CM_REG_MIXER2, CM_RAUXLEN_SHIFT, CM_RAUXREN_SHIFT, 0),
@@ -2310,7 +2310,7 @@ static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
2310 CMIPCI_MIXER_VOL_MONO("Mic Capture Volume", CM_REG_MIXER2, CM_VADMIC_SHIFT, 7), 2310 CMIPCI_MIXER_VOL_MONO("Mic Capture Volume", CM_REG_MIXER2, CM_VADMIC_SHIFT, 7),
2311 CMIPCI_SB_VOL_MONO("Phone Playback Volume", CM_REG_EXTENT_IND, 5, 7), 2311 CMIPCI_SB_VOL_MONO("Phone Playback Volume", CM_REG_EXTENT_IND, 5, 7),
2312 CMIPCI_DOUBLE("Phone Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 4, 4, 1, 0, 0), 2312 CMIPCI_DOUBLE("Phone Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 4, 4, 1, 0, 0),
2313 CMIPCI_DOUBLE("PC Speaker Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 3, 3, 1, 0, 0), 2313 CMIPCI_DOUBLE("Beep Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 3, 3, 1, 0, 0),
2314 CMIPCI_DOUBLE("Mic Boost Capture Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 0, 0, 1, 0, 0), 2314 CMIPCI_DOUBLE("Mic Boost Capture Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 0, 0, 1, 0, 0),
2315}; 2315};
2316 2316
diff --git a/sound/pci/cs46xx/imgs/cwcdma.asp b/sound/pci/cs46xx/imgs/cwcdma.asp
index 09d24c76f034..a65e1193c89a 100644
--- a/sound/pci/cs46xx/imgs/cwcdma.asp
+++ b/sound/pci/cs46xx/imgs/cwcdma.asp
@@ -26,10 +26,11 @@
26// 26//
27// 27//
28// The purpose of this code is very simple: make it possible to tranfser 28// The purpose of this code is very simple: make it possible to tranfser
29// the samples 'as they are' with no alteration from a PCMreader SCB (DMA from host) 29// the samples 'as they are' with no alteration from a PCMreader
30// to any other SCB. This is useful for AC3 throug SPDIF. SRC (source rate converters) 30// SCB (DMA from host) to any other SCB. This is useful for AC3 through SPDIF.
31// task always alters the samples in some how, however it's from 48khz -> 48khz. The 31// SRC (source rate converters) task always alters the samples in somehow,
32// alterations are not audible, but AC3 wont work. 32// however it's from 48khz -> 48khz.
33// The alterations are not audible, but AC3 wont work.
33// 34//
34// ... 35// ...
35// | 36// |
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index 75454648d50c..cb65bd0dd35b 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -240,7 +240,7 @@ static int select_rom(unsigned int pitch)
240 } else if (pitch == 0x02000000) { 240 } else if (pitch == 0x02000000) {
241 /* pitch == 2 */ 241 /* pitch == 2 */
242 return 3; 242 return 3;
243 } else if (pitch >= 0x0 && pitch <= 0x08000000) { 243 } else if (pitch <= 0x08000000) {
244 /* 0 <= pitch <= 8 */ 244 /* 0 <= pitch <= 8 */
245 return 0; 245 return 0;
246 } else { 246 } else {
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 36e08bd2b3cc..1d369ff73805 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -184,7 +184,7 @@ MODULE_PARM_DESC(enable, "Enable the EMU10K1X soundcard.");
184 * The hardware has 3 channels for playback and 1 for capture. 184 * The hardware has 3 channels for playback and 1 for capture.
185 * - channel 0 is the front channel 185 * - channel 0 is the front channel
186 * - channel 1 is the rear channel 186 * - channel 1 is the rear channel
187 * - channel 2 is the center/lfe chanel 187 * - channel 2 is the center/lfe channel
188 * Volume is controlled by the AC97 for the front and rear channels by 188 * Volume is controlled by the AC97 for the front and rear channels by
189 * the PCM Playback Volume, Sigmatel Surround Playback Volume and 189 * the PCM Playback Volume, Sigmatel Surround Playback Volume and
190 * Surround Playback Volume. The Sigmatel 4-Speaker Stereo switch affects 190 * Surround Playback Volume. The Sigmatel 4-Speaker Stereo switch affects
@@ -1040,8 +1040,7 @@ static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,
1040 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 1040 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
1041 continue; 1041 continue;
1042 1042
1043 if ((reg < 0x49) && (reg >= 0) && (val <= 0xffffffff) 1043 if (reg < 0x49 && val <= 0xffffffff && channel_id <= 2)
1044 && (channel_id >= 0) && (channel_id <= 2) )
1045 snd_emu10k1x_ptr_write(emu, reg, channel_id, val); 1044 snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
1046 } 1045 }
1047} 1046}
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index b0fb6c917c38..05afe06e353a 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -1818,8 +1818,8 @@ int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1818 "Master Playback Switch", "Master Capture Switch", 1818 "Master Playback Switch", "Master Capture Switch",
1819 "Master Playback Volume", "Master Capture Volume", 1819 "Master Playback Volume", "Master Capture Volume",
1820 "Wave Master Playback Volume", "Master Playback Volume", 1820 "Wave Master Playback Volume", "Master Playback Volume",
1821 "PC Speaker Playback Switch", "PC Speaker Capture Switch", 1821 "Beep Playback Switch", "Beep Capture Switch",
1822 "PC Speaker Playback Volume", "PC Speaker Capture Volume", 1822 "Beep Playback Volume", "Beep Capture Volume",
1823 "Phone Playback Switch", "Phone Capture Switch", 1823 "Phone Playback Switch", "Phone Capture Switch",
1824 "Phone Playback Volume", "Phone Capture Volume", 1824 "Phone Playback Volume", "Phone Capture Volume",
1825 "Mic Playback Switch", "Mic Capture Switch", 1825 "Mic Playback Switch", "Mic Capture Switch",
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index 216f9748aff5..baa7cd508cd8 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -451,7 +451,7 @@ static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
451 while (!snd_info_get_line(buffer, line, sizeof(line))) { 451 while (!snd_info_get_line(buffer, line, sizeof(line))) {
452 if (sscanf(line, "%x %x", &reg, &val) != 2) 452 if (sscanf(line, "%x %x", &reg, &val) != 2)
453 continue; 453 continue;
454 if ((reg < 0x40) && (reg >= 0) && (val <= 0xffffffff) ) { 454 if (reg < 0x40 && val <= 0xffffffff) {
455 spin_lock_irqsave(&emu->emu_lock, flags); 455 spin_lock_irqsave(&emu->emu_lock, flags);
456 outl(val, emu->port + (reg & 0xfffffffc)); 456 outl(val, emu->port + (reg & 0xfffffffc));
457 spin_unlock_irqrestore(&emu->emu_lock, flags); 457 spin_unlock_irqrestore(&emu->emu_lock, flags);
@@ -527,7 +527,7 @@ static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
527 while (!snd_info_get_line(buffer, line, sizeof(line))) { 527 while (!snd_info_get_line(buffer, line, sizeof(line))) {
528 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 528 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
529 continue; 529 continue;
530 if ((reg < 0xa0) && (reg >= 0) && (val <= 0xffffffff) && (channel_id >= 0) && (channel_id <= 3) ) 530 if (reg < 0xa0 && val <= 0xffffffff && channel_id <= 3)
531 snd_ptr_write(emu, iobase, reg, channel_id, val); 531 snd_ptr_write(emu, iobase, reg, channel_id, val);
532 } 532 }
533} 533}
diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c
index c1a5aa15af8f..5ef7080e14d0 100644
--- a/sound/pci/emu10k1/io.c
+++ b/sound/pci/emu10k1/io.c
@@ -256,7 +256,7 @@ int snd_emu1010_fpga_write(struct snd_emu10k1 * emu, u32 reg, u32 value)
256 if (reg > 0x3f) 256 if (reg > 0x3f)
257 return 1; 257 return 1;
258 reg += 0x40; /* 0x40 upwards are registers. */ 258 reg += 0x40; /* 0x40 upwards are registers. */
259 if (value < 0 || value > 0x3f) /* 0 to 0x3f are values */ 259 if (value > 0x3f) /* 0 to 0x3f are values */
260 return 1; 260 return 1;
261 spin_lock_irqsave(&emu->emu_lock, flags); 261 spin_lock_irqsave(&emu->emu_lock, flags);
262 outl(reg, emu->port + A_IOCFG); 262 outl(reg, emu->port + A_IOCFG);
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 820318ee62c1..fb83e1ffa5cb 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1387,7 +1387,7 @@ ES1938_DOUBLE_TLV("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0,
1387 db_scale_line), 1387 db_scale_line),
1388ES1938_DOUBLE_TLV("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0, 1388ES1938_DOUBLE_TLV("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0,
1389 db_scale_capture), 1389 db_scale_capture),
1390ES1938_SINGLE("PC Speaker Volume", 0, 0x3c, 0, 7, 0), 1390ES1938_SINGLE("Beep Volume", 0, 0x3c, 0, 7, 0),
1391ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0), 1391ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1392ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), 1392ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1393{ 1393{
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index 60cdb9e0b68d..83508b3964fb 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -55,7 +55,7 @@ static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card *
55 * 1 = MediaForte 256-PCS 55 * 1 = MediaForte 256-PCS
56 * 2 = MediaForte 256-PCPR 56 * 2 = MediaForte 256-PCPR
57 * 3 = MediaForte 64-PCR 57 * 3 = MediaForte 64-PCR
58 * 16 = setup tuner only (this is additional bit), i.e. SF-64-PCR FM card 58 * 16 = setup tuner only (this is additional bit), i.e. SF64-PCR FM card
59 * High 16-bits are video (radio) device number + 1 59 * High 16-bits are video (radio) device number + 1
60 */ 60 */
61static int tea575x_tuner[SNDRV_CARDS]; 61static int tea575x_tuner[SNDRV_CARDS];
@@ -67,7 +67,10 @@ MODULE_PARM_DESC(id, "ID string for the FM801 soundcard.");
67module_param_array(enable, bool, NULL, 0444); 67module_param_array(enable, bool, NULL, 0444);
68MODULE_PARM_DESC(enable, "Enable FM801 soundcard."); 68MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
69module_param_array(tea575x_tuner, int, NULL, 0444); 69module_param_array(tea575x_tuner, int, NULL, 0444);
70MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner."); 70MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (1 = SF256-PCS, 2=SF256-PCPR, 3=SF64-PCR, +16=tuner-only).");
71
72#define TUNER_ONLY (1<<4)
73#define TUNER_TYPE_MASK (~TUNER_ONLY & 0xFFFF)
71 74
72/* 75/*
73 * Direct registers 76 * Direct registers
@@ -160,7 +163,7 @@ struct fm801 {
160 unsigned int multichannel: 1, /* multichannel support */ 163 unsigned int multichannel: 1, /* multichannel support */
161 secondary: 1; /* secondary codec */ 164 secondary: 1; /* secondary codec */
162 unsigned char secondary_addr; /* address of the secondary codec */ 165 unsigned char secondary_addr; /* address of the secondary codec */
163 unsigned int tea575x_tuner; /* tuner flags */ 166 unsigned int tea575x_tuner; /* tuner access method & flags */
164 167
165 unsigned short ply_ctrl; /* playback control */ 168 unsigned short ply_ctrl; /* playback control */
166 unsigned short cap_ctrl; /* capture control */ 169 unsigned short cap_ctrl; /* capture control */
@@ -1287,7 +1290,7 @@ static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1287{ 1290{
1288 unsigned short cmdw; 1291 unsigned short cmdw;
1289 1292
1290 if (chip->tea575x_tuner & 0x0010) 1293 if (chip->tea575x_tuner & TUNER_ONLY)
1291 goto __ac97_ok; 1294 goto __ac97_ok;
1292 1295
1293 /* codec cold reset + AC'97 warm reset */ 1296 /* codec cold reset + AC'97 warm reset */
@@ -1296,11 +1299,13 @@ static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1296 udelay(100); 1299 udelay(100);
1297 outw(0, FM801_REG(chip, CODEC_CTRL)); 1300 outw(0, FM801_REG(chip, CODEC_CTRL));
1298 1301
1299 if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0) { 1302 if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0)
1300 snd_printk(KERN_ERR "Primary AC'97 codec not found\n"); 1303 if (!resume) {
1301 if (! resume) 1304 snd_printk(KERN_INFO "Primary AC'97 codec not found, "
1302 return -EIO; 1305 "assume SF64-PCR (tuner-only)\n");
1303 } 1306 chip->tea575x_tuner = 3 | TUNER_ONLY;
1307 goto __ac97_ok;
1308 }
1304 1309
1305 if (chip->multichannel) { 1310 if (chip->multichannel) {
1306 if (chip->secondary_addr) { 1311 if (chip->secondary_addr) {
@@ -1414,7 +1419,7 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1414 return err; 1419 return err;
1415 } 1420 }
1416 chip->port = pci_resource_start(pci, 0); 1421 chip->port = pci_resource_start(pci, 0);
1417 if ((tea575x_tuner & 0x0010) == 0) { 1422 if ((tea575x_tuner & TUNER_ONLY) == 0) {
1418 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED, 1423 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,
1419 "FM801", chip)) { 1424 "FM801", chip)) {
1420 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq); 1425 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
@@ -1429,6 +1434,14 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1429 chip->multichannel = 1; 1434 chip->multichannel = 1;
1430 1435
1431 snd_fm801_chip_init(chip, 0); 1436 snd_fm801_chip_init(chip, 0);
1437 /* init might set tuner access method */
1438 tea575x_tuner = chip->tea575x_tuner;
1439
1440 if (chip->irq >= 0 && (tea575x_tuner & TUNER_ONLY)) {
1441 pci_clear_master(pci);
1442 free_irq(chip->irq, chip);
1443 chip->irq = -1;
1444 }
1432 1445
1433 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1446 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1434 snd_fm801_free(chip); 1447 snd_fm801_free(chip);
@@ -1438,12 +1451,13 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1438 snd_card_set_dev(card, &pci->dev); 1451 snd_card_set_dev(card, &pci->dev);
1439 1452
1440#ifdef TEA575X_RADIO 1453#ifdef TEA575X_RADIO
1441 if (tea575x_tuner > 0 && (tea575x_tuner & 0x000f) < 4) { 1454 if ((tea575x_tuner & TUNER_TYPE_MASK) > 0 &&
1455 (tea575x_tuner & TUNER_TYPE_MASK) < 4) {
1442 chip->tea.dev_nr = tea575x_tuner >> 16; 1456 chip->tea.dev_nr = tea575x_tuner >> 16;
1443 chip->tea.card = card; 1457 chip->tea.card = card;
1444 chip->tea.freq_fixup = 10700; 1458 chip->tea.freq_fixup = 10700;
1445 chip->tea.private_data = chip; 1459 chip->tea.private_data = chip;
1446 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0x000f) - 1]; 1460 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & TUNER_TYPE_MASK) - 1];
1447 snd_tea575x_init(&chip->tea); 1461 snd_tea575x_init(&chip->tea);
1448 } 1462 }
1449#endif 1463#endif
@@ -1483,7 +1497,7 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
1483 sprintf(card->longname, "%s at 0x%lx, irq %i", 1497 sprintf(card->longname, "%s at 0x%lx, irq %i",
1484 card->shortname, chip->port, chip->irq); 1498 card->shortname, chip->port, chip->irq);
1485 1499
1486 if (tea575x_tuner[dev] & 0x0010) 1500 if (chip->tea575x_tuner & TUNER_ONLY)
1487 goto __fm801_tuner_only; 1501 goto __fm801_tuner_only;
1488 1502
1489 if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) { 1503 if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) {
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 55545e0818b5..556cff937be7 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -38,9 +38,20 @@ config SND_HDA_INPUT_BEEP
38 Say Y here to build a digital beep interface for HD-audio 38 Say Y here to build a digital beep interface for HD-audio
39 driver. This interface is used to generate digital beeps. 39 driver. This interface is used to generate digital beeps.
40 40
41config SND_HDA_INPUT_BEEP_MODE
42 int "Digital beep registration mode (0=off, 1=on, 2=mute sw on/off)"
43 depends on SND_HDA_INPUT_BEEP=y
44 default "1"
45 range 0 2
46 help
47 Set 0 to disable the digital beep interface for HD-audio by default.
48 Set 1 to always enable the digital beep interface for HD-audio by
49 default. Set 2 to control the beep device registration to input
50 layer using a "Beep Switch" in mixer applications.
51
41config SND_HDA_INPUT_JACK 52config SND_HDA_INPUT_JACK
42 bool "Support jack plugging notification via input layer" 53 bool "Support jack plugging notification via input layer"
43 depends on INPUT=y || INPUT=SND_HDA_INTEL 54 depends on INPUT=y || INPUT=SND
44 select SND_JACK 55 select SND_JACK
45 help 56 help
46 Say Y here to enable the jack plugging notification via 57 Say Y here to enable the jack plugging notification via
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 3f51a981e604..5fe34a8d8c81 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -113,23 +113,25 @@ static int snd_hda_beep_event(struct input_dev *dev, unsigned int type,
113 return 0; 113 return 0;
114} 114}
115 115
116int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) 116static void snd_hda_do_detach(struct hda_beep *beep)
117{
118 input_unregister_device(beep->dev);
119 beep->dev = NULL;
120 cancel_work_sync(&beep->beep_work);
121 /* turn off beep for sure */
122 snd_hda_codec_write_cache(beep->codec, beep->nid, 0,
123 AC_VERB_SET_BEEP_CONTROL, 0);
124}
125
126static int snd_hda_do_attach(struct hda_beep *beep)
117{ 127{
118 struct input_dev *input_dev; 128 struct input_dev *input_dev;
119 struct hda_beep *beep; 129 struct hda_codec *codec = beep->codec;
120 int err; 130 int err;
121 131
122 if (!snd_hda_get_bool_hint(codec, "beep"))
123 return 0; /* disabled explicitly */
124
125 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
126 if (beep == NULL)
127 return -ENOMEM;
128 snprintf(beep->phys, sizeof(beep->phys),
129 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
130 input_dev = input_allocate_device(); 132 input_dev = input_allocate_device();
131 if (!input_dev) { 133 if (!input_dev) {
132 kfree(beep); 134 printk(KERN_INFO "hda_beep: unable to allocate input device\n");
133 return -ENOMEM; 135 return -ENOMEM;
134 } 136 }
135 137
@@ -151,21 +153,96 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
151 err = input_register_device(input_dev); 153 err = input_register_device(input_dev);
152 if (err < 0) { 154 if (err < 0) {
153 input_free_device(input_dev); 155 input_free_device(input_dev);
154 kfree(beep); 156 printk(KERN_INFO "hda_beep: unable to register input device\n");
155 return err; 157 return err;
156 } 158 }
159 beep->dev = input_dev;
160 return 0;
161}
162
163static void snd_hda_do_register(struct work_struct *work)
164{
165 struct hda_beep *beep =
166 container_of(work, struct hda_beep, register_work);
167
168 mutex_lock(&beep->mutex);
169 if (beep->enabled && !beep->dev)
170 snd_hda_do_attach(beep);
171 mutex_unlock(&beep->mutex);
172}
173
174static void snd_hda_do_unregister(struct work_struct *work)
175{
176 struct hda_beep *beep =
177 container_of(work, struct hda_beep, unregister_work.work);
178
179 mutex_lock(&beep->mutex);
180 if (!beep->enabled && beep->dev)
181 snd_hda_do_detach(beep);
182 mutex_unlock(&beep->mutex);
183}
157 184
185int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
186{
187 struct hda_beep *beep = codec->beep;
188 enable = !!enable;
189 if (beep == NULL)
190 return 0;
191 if (beep->enabled != enable) {
192 beep->enabled = enable;
193 if (!enable) {
194 /* turn off beep */
195 snd_hda_codec_write_cache(beep->codec, beep->nid, 0,
196 AC_VERB_SET_BEEP_CONTROL, 0);
197 }
198 if (beep->mode == HDA_BEEP_MODE_SWREG) {
199 if (enable) {
200 cancel_delayed_work(&beep->unregister_work);
201 schedule_work(&beep->register_work);
202 } else {
203 schedule_delayed_work(&beep->unregister_work,
204 HZ);
205 }
206 }
207 return 1;
208 }
209 return 0;
210}
211EXPORT_SYMBOL_HDA(snd_hda_enable_beep_device);
212
213int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
214{
215 struct hda_beep *beep;
216
217 if (!snd_hda_get_bool_hint(codec, "beep"))
218 return 0; /* disabled explicitly by hints */
219 if (codec->beep_mode == HDA_BEEP_MODE_OFF)
220 return 0; /* disabled by module option */
221
222 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
223 if (beep == NULL)
224 return -ENOMEM;
225 snprintf(beep->phys, sizeof(beep->phys),
226 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
158 /* enable linear scale */ 227 /* enable linear scale */
159 snd_hda_codec_write(codec, nid, 0, 228 snd_hda_codec_write(codec, nid, 0,
160 AC_VERB_SET_DIGI_CONVERT_2, 0x01); 229 AC_VERB_SET_DIGI_CONVERT_2, 0x01);
161 230
162 beep->nid = nid; 231 beep->nid = nid;
163 beep->dev = input_dev;
164 beep->codec = codec; 232 beep->codec = codec;
165 beep->enabled = 1; 233 beep->mode = codec->beep_mode;
166 codec->beep = beep; 234 codec->beep = beep;
167 235
236 INIT_WORK(&beep->register_work, &snd_hda_do_register);
237 INIT_DELAYED_WORK(&beep->unregister_work, &snd_hda_do_unregister);
168 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep); 238 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
239 mutex_init(&beep->mutex);
240
241 if (beep->mode == HDA_BEEP_MODE_ON) {
242 beep->enabled = 1;
243 snd_hda_do_register(&beep->register_work);
244 }
245
169 return 0; 246 return 0;
170} 247}
171EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device); 248EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device);
@@ -174,11 +251,12 @@ void snd_hda_detach_beep_device(struct hda_codec *codec)
174{ 251{
175 struct hda_beep *beep = codec->beep; 252 struct hda_beep *beep = codec->beep;
176 if (beep) { 253 if (beep) {
177 cancel_work_sync(&beep->beep_work); 254 cancel_work_sync(&beep->register_work);
178 255 cancel_delayed_work(&beep->unregister_work);
179 input_unregister_device(beep->dev); 256 if (beep->enabled)
180 kfree(beep); 257 snd_hda_do_detach(beep);
181 codec->beep = NULL; 258 codec->beep = NULL;
259 kfree(beep);
182 } 260 }
183} 261}
184EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device); 262EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device);
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
index 0c3de787c717..f1de1bac042c 100644
--- a/sound/pci/hda/hda_beep.h
+++ b/sound/pci/hda/hda_beep.h
@@ -24,19 +24,29 @@
24 24
25#include "hda_codec.h" 25#include "hda_codec.h"
26 26
27#define HDA_BEEP_MODE_OFF 0
28#define HDA_BEEP_MODE_ON 1
29#define HDA_BEEP_MODE_SWREG 2
30
27/* beep information */ 31/* beep information */
28struct hda_beep { 32struct hda_beep {
29 struct input_dev *dev; 33 struct input_dev *dev;
30 struct hda_codec *codec; 34 struct hda_codec *codec;
35 unsigned int mode;
31 char phys[32]; 36 char phys[32];
32 int tone; 37 int tone;
33 hda_nid_t nid; 38 hda_nid_t nid;
34 unsigned int enabled:1; 39 unsigned int enabled:1;
40 unsigned int request_enable:1;
35 unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */ 41 unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */
42 struct work_struct register_work; /* registration work */
43 struct delayed_work unregister_work; /* unregistration work */
36 struct work_struct beep_work; /* scheduled task for beep event */ 44 struct work_struct beep_work; /* scheduled task for beep event */
45 struct mutex mutex;
37}; 46};
38 47
39#ifdef CONFIG_SND_HDA_INPUT_BEEP 48#ifdef CONFIG_SND_HDA_INPUT_BEEP
49int snd_hda_enable_beep_device(struct hda_codec *codec, int enable);
40int snd_hda_attach_beep_device(struct hda_codec *codec, int nid); 50int snd_hda_attach_beep_device(struct hda_codec *codec, int nid);
41void snd_hda_detach_beep_device(struct hda_codec *codec); 51void snd_hda_detach_beep_device(struct hda_codec *codec);
42#else 52#else
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index af989f660cca..9cfdb771928c 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -30,6 +30,7 @@
30#include <sound/tlv.h> 30#include <sound/tlv.h>
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_beep.h"
33#include <sound/hda_hwdep.h> 34#include <sound/hda_hwdep.h>
34 35
35/* 36/*
@@ -93,6 +94,13 @@ static void hda_keep_power_on(struct hda_codec *codec);
93static inline void hda_keep_power_on(struct hda_codec *codec) {} 94static inline void hda_keep_power_on(struct hda_codec *codec) {}
94#endif 95#endif
95 96
97/**
98 * snd_hda_get_jack_location - Give a location string of the jack
99 * @cfg: pin default config value
100 *
101 * Parse the pin default config value and returns the string of the
102 * jack location, e.g. "Rear", "Front", etc.
103 */
96const char *snd_hda_get_jack_location(u32 cfg) 104const char *snd_hda_get_jack_location(u32 cfg)
97{ 105{
98 static char *bases[7] = { 106 static char *bases[7] = {
@@ -120,6 +128,13 @@ const char *snd_hda_get_jack_location(u32 cfg)
120} 128}
121EXPORT_SYMBOL_HDA(snd_hda_get_jack_location); 129EXPORT_SYMBOL_HDA(snd_hda_get_jack_location);
122 130
131/**
132 * snd_hda_get_jack_connectivity - Give a connectivity string of the jack
133 * @cfg: pin default config value
134 *
135 * Parse the pin default config value and returns the string of the
136 * jack connectivity, i.e. external or internal connection.
137 */
123const char *snd_hda_get_jack_connectivity(u32 cfg) 138const char *snd_hda_get_jack_connectivity(u32 cfg)
124{ 139{
125 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" }; 140 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
@@ -128,6 +143,13 @@ const char *snd_hda_get_jack_connectivity(u32 cfg)
128} 143}
129EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity); 144EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity);
130 145
146/**
147 * snd_hda_get_jack_type - Give a type string of the jack
148 * @cfg: pin default config value
149 *
150 * Parse the pin default config value and returns the string of the
151 * jack type, i.e. the purpose of the jack, such as Line-Out or CD.
152 */
131const char *snd_hda_get_jack_type(u32 cfg) 153const char *snd_hda_get_jack_type(u32 cfg)
132{ 154{
133 static char *jack_types[16] = { 155 static char *jack_types[16] = {
@@ -515,6 +537,7 @@ static int snd_hda_bus_dev_register(struct snd_device *device)
515 struct hda_codec *codec; 537 struct hda_codec *codec;
516 list_for_each_entry(codec, &bus->codec_list, list) { 538 list_for_each_entry(codec, &bus->codec_list, list) {
517 snd_hda_hwdep_add_sysfs(codec); 539 snd_hda_hwdep_add_sysfs(codec);
540 snd_hda_hwdep_add_power_sysfs(codec);
518 } 541 }
519 return 0; 542 return 0;
520} 543}
@@ -820,6 +843,16 @@ int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
820 return 0; 843 return 0;
821} 844}
822 845
846/**
847 * snd_hda_codec_set_pincfg - Override a pin default configuration
848 * @codec: the HDA codec
849 * @nid: NID to set the pin config
850 * @cfg: the pin default config value
851 *
852 * Override a pin default configuration value in the cache.
853 * This value can be read by snd_hda_codec_get_pincfg() in a higher
854 * priority than the real hardware value.
855 */
823int snd_hda_codec_set_pincfg(struct hda_codec *codec, 856int snd_hda_codec_set_pincfg(struct hda_codec *codec,
824 hda_nid_t nid, unsigned int cfg) 857 hda_nid_t nid, unsigned int cfg)
825{ 858{
@@ -827,7 +860,15 @@ int snd_hda_codec_set_pincfg(struct hda_codec *codec,
827} 860}
828EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg); 861EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg);
829 862
830/* get the current pin config value of the given pin NID */ 863/**
864 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
865 * @codec: the HDA codec
866 * @nid: NID to get the pin config
867 *
868 * Get the current pin config value of the given pin NID.
869 * If the pincfg value is cached or overridden via sysfs or driver,
870 * returns the cached value.
871 */
831unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) 872unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
832{ 873{
833 struct hda_pincfg *pin; 874 struct hda_pincfg *pin;
@@ -944,7 +985,7 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
944 mutex_init(&codec->control_mutex); 985 mutex_init(&codec->control_mutex);
945 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 986 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
946 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 987 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
947 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32); 988 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 60);
948 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); 989 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
949 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); 990 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
950 if (codec->bus->modelname) { 991 if (codec->bus->modelname) {
@@ -1026,6 +1067,15 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
1026} 1067}
1027EXPORT_SYMBOL_HDA(snd_hda_codec_new); 1068EXPORT_SYMBOL_HDA(snd_hda_codec_new);
1028 1069
1070/**
1071 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1072 * @codec: the HDA codec
1073 *
1074 * Start parsing of the given codec tree and (re-)initialize the whole
1075 * patch instance.
1076 *
1077 * Returns 0 if successful or a negative error code.
1078 */
1029int snd_hda_codec_configure(struct hda_codec *codec) 1079int snd_hda_codec_configure(struct hda_codec *codec)
1030{ 1080{
1031 int err; 1081 int err;
@@ -1088,6 +1138,11 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1088} 1138}
1089EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream); 1139EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1090 1140
1141/**
1142 * snd_hda_codec_cleanup_stream - clean up the codec for closing
1143 * @codec: the CODEC to clean up
1144 * @nid: the NID to clean up
1145 */
1091void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid) 1146void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
1092{ 1147{
1093 if (!nid) 1148 if (!nid)
@@ -1163,8 +1218,17 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1163 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); 1218 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1164} 1219}
1165 1220
1166/* 1221/**
1167 * query AMP capabilities for the given widget and direction 1222 * query_amp_caps - query AMP capabilities
1223 * @codec: the HD-auio codec
1224 * @nid: the NID to query
1225 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1226 *
1227 * Query AMP capabilities for the given widget and direction.
1228 * Returns the obtained capability bits.
1229 *
1230 * When cap bits have been already read, this doesn't read again but
1231 * returns the cached value.
1168 */ 1232 */
1169u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 1233u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1170{ 1234{
@@ -1187,6 +1251,19 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1187} 1251}
1188EXPORT_SYMBOL_HDA(query_amp_caps); 1252EXPORT_SYMBOL_HDA(query_amp_caps);
1189 1253
1254/**
1255 * snd_hda_override_amp_caps - Override the AMP capabilities
1256 * @codec: the CODEC to clean up
1257 * @nid: the NID to clean up
1258 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1259 * @caps: the capability bits to set
1260 *
1261 * Override the cached AMP caps bits value by the given one.
1262 * This function is useful if the driver needs to adjust the AMP ranges,
1263 * e.g. limit to 0dB, etc.
1264 *
1265 * Returns zero if successful or a negative error code.
1266 */
1190int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 1267int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1191 unsigned int caps) 1268 unsigned int caps)
1192{ 1269{
@@ -1222,6 +1299,17 @@ static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid)
1222 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 1299 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1223} 1300}
1224 1301
1302/**
1303 * snd_hda_query_pin_caps - Query PIN capabilities
1304 * @codec: the HD-auio codec
1305 * @nid: the NID to query
1306 *
1307 * Query PIN capabilities for the given widget.
1308 * Returns the obtained capability bits.
1309 *
1310 * When cap bits have been already read, this doesn't read again but
1311 * returns the cached value.
1312 */
1225u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) 1313u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1226{ 1314{
1227 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), 1315 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid),
@@ -1229,6 +1317,40 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1229} 1317}
1230EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); 1318EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1231 1319
1320/**
1321 * snd_hda_pin_sense - execute pin sense measurement
1322 * @codec: the CODEC to sense
1323 * @nid: the pin NID to sense
1324 *
1325 * Execute necessary pin sense measurement and return its Presence Detect,
1326 * Impedance, ELD Valid etc. status bits.
1327 */
1328u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1329{
1330 u32 pincap = snd_hda_query_pin_caps(codec, nid);
1331
1332 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1333 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
1334
1335 return snd_hda_codec_read(codec, nid, 0,
1336 AC_VERB_GET_PIN_SENSE, 0);
1337}
1338EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1339
1340/**
1341 * snd_hda_jack_detect - query pin Presence Detect status
1342 * @codec: the CODEC to sense
1343 * @nid: the pin NID to sense
1344 *
1345 * Query and return the pin's Presence Detect status.
1346 */
1347int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1348{
1349 u32 sense = snd_hda_pin_sense(codec, nid);
1350 return !!(sense & AC_PINSENSE_PRESENCE);
1351}
1352EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1353
1232/* 1354/*
1233 * read the current volume to info 1355 * read the current volume to info
1234 * if the cache exists, read the cache value. 1356 * if the cache exists, read the cache value.
@@ -1269,8 +1391,15 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1269 info->vol[ch] = val; 1391 info->vol[ch] = val;
1270} 1392}
1271 1393
1272/* 1394/**
1273 * read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. 1395 * snd_hda_codec_amp_read - Read AMP value
1396 * @codec: HD-audio codec
1397 * @nid: NID to read the AMP value
1398 * @ch: channel (left=0 or right=1)
1399 * @direction: #HDA_INPUT or #HDA_OUTPUT
1400 * @index: the index value (only for input direction)
1401 *
1402 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
1274 */ 1403 */
1275int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 1404int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1276 int direction, int index) 1405 int direction, int index)
@@ -1283,8 +1412,18 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1283} 1412}
1284EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); 1413EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1285 1414
1286/* 1415/**
1287 * update the AMP value, mask = bit mask to set, val = the value 1416 * snd_hda_codec_amp_update - update the AMP value
1417 * @codec: HD-audio codec
1418 * @nid: NID to read the AMP value
1419 * @ch: channel (left=0 or right=1)
1420 * @direction: #HDA_INPUT or #HDA_OUTPUT
1421 * @idx: the index value (only for input direction)
1422 * @mask: bit mask to set
1423 * @val: the bits value to set
1424 *
1425 * Update the AMP value with a bit mask.
1426 * Returns 0 if the value is unchanged, 1 if changed.
1288 */ 1427 */
1289int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 1428int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1290 int direction, int idx, int mask, int val) 1429 int direction, int idx, int mask, int val)
@@ -1303,8 +1442,17 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1303} 1442}
1304EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update); 1443EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
1305 1444
1306/* 1445/**
1307 * update the AMP stereo with the same mask and value 1446 * snd_hda_codec_amp_stereo - update the AMP stereo values
1447 * @codec: HD-audio codec
1448 * @nid: NID to read the AMP value
1449 * @direction: #HDA_INPUT or #HDA_OUTPUT
1450 * @idx: the index value (only for input direction)
1451 * @mask: bit mask to set
1452 * @val: the bits value to set
1453 *
1454 * Update the AMP values like snd_hda_codec_amp_update(), but for a
1455 * stereo widget with the same mask and value.
1308 */ 1456 */
1309int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, 1457int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1310 int direction, int idx, int mask, int val) 1458 int direction, int idx, int mask, int val)
@@ -1318,7 +1466,12 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1318EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo); 1466EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1319 1467
1320#ifdef SND_HDA_NEEDS_RESUME 1468#ifdef SND_HDA_NEEDS_RESUME
1321/* resume the all amp commands from the cache */ 1469/**
1470 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
1471 * @codec: HD-audio codec
1472 *
1473 * Resume the all amp commands from the cache.
1474 */
1322void snd_hda_codec_resume_amp(struct hda_codec *codec) 1475void snd_hda_codec_resume_amp(struct hda_codec *codec)
1323{ 1476{
1324 struct hda_amp_info *buffer = codec->amp_cache.buf.list; 1477 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
@@ -1344,7 +1497,12 @@ void snd_hda_codec_resume_amp(struct hda_codec *codec)
1344EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp); 1497EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
1345#endif /* SND_HDA_NEEDS_RESUME */ 1498#endif /* SND_HDA_NEEDS_RESUME */
1346 1499
1347/* volume */ 1500/**
1501 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1502 *
1503 * The control element is supposed to have the private_value field
1504 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1505 */
1348int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 1506int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1349 struct snd_ctl_elem_info *uinfo) 1507 struct snd_ctl_elem_info *uinfo)
1350{ 1508{
@@ -1400,6 +1558,12 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1400 HDA_AMP_VOLMASK, val); 1558 HDA_AMP_VOLMASK, val);
1401} 1559}
1402 1560
1561/**
1562 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1563 *
1564 * The control element is supposed to have the private_value field
1565 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1566 */
1403int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, 1567int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1404 struct snd_ctl_elem_value *ucontrol) 1568 struct snd_ctl_elem_value *ucontrol)
1405{ 1569{
@@ -1419,6 +1583,12 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1419} 1583}
1420EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get); 1584EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1421 1585
1586/**
1587 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1588 *
1589 * The control element is supposed to have the private_value field
1590 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1591 */
1422int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, 1592int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1423 struct snd_ctl_elem_value *ucontrol) 1593 struct snd_ctl_elem_value *ucontrol)
1424{ 1594{
@@ -1443,6 +1613,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1443} 1613}
1444EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put); 1614EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1445 1615
1616/**
1617 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume
1618 *
1619 * The control element is supposed to have the private_value field
1620 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1621 */
1446int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1622int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1447 unsigned int size, unsigned int __user *_tlv) 1623 unsigned int size, unsigned int __user *_tlv)
1448{ 1624{
@@ -1472,8 +1648,16 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1472} 1648}
1473EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv); 1649EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1474 1650
1475/* 1651/**
1476 * set (static) TLV for virtual master volume; recalculated as max 0dB 1652 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1653 * @codec: HD-audio codec
1654 * @nid: NID of a reference widget
1655 * @dir: #HDA_INPUT or #HDA_OUTPUT
1656 * @tlv: TLV data to be stored, at least 4 elements
1657 *
1658 * Set (static) TLV data for a virtual master volume using the AMP caps
1659 * obtained from the reference NID.
1660 * The volume range is recalculated as if the max volume is 0dB.
1477 */ 1661 */
1478void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, 1662void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1479 unsigned int *tlv) 1663 unsigned int *tlv)
@@ -1507,6 +1691,13 @@ _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1507 return snd_ctl_find_id(codec->bus->card, &id); 1691 return snd_ctl_find_id(codec->bus->card, &id);
1508} 1692}
1509 1693
1694/**
1695 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1696 * @codec: HD-audio codec
1697 * @name: ctl id name string
1698 *
1699 * Get the control element with the given id string and IFACE_MIXER.
1700 */
1510struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 1701struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1511 const char *name) 1702 const char *name)
1512{ 1703{
@@ -1514,30 +1705,57 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1514} 1705}
1515EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl); 1706EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1516 1707
1517/* Add a control element and assign to the codec */ 1708/**
1518int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl) 1709 * snd_hda_ctl-add - Add a control element and assign to the codec
1710 * @codec: HD-audio codec
1711 * @nid: corresponding NID (optional)
1712 * @kctl: the control element to assign
1713 *
1714 * Add the given control element to an array inside the codec instance.
1715 * All control elements belonging to a codec are supposed to be added
1716 * by this function so that a proper clean-up works at the free or
1717 * reconfiguration time.
1718 *
1719 * If non-zero @nid is passed, the NID is assigned to the control element.
1720 * The assignment is shown in the codec proc file.
1721 *
1722 * snd_hda_ctl_add() checks the control subdev id field whether
1723 * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower
1724 * bits value is taken as the NID to assign.
1725 */
1726int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1727 struct snd_kcontrol *kctl)
1519{ 1728{
1520 int err; 1729 int err;
1521 struct snd_kcontrol **knewp; 1730 struct hda_nid_item *item;
1522 1731
1732 if (kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) {
1733 if (nid == 0)
1734 nid = kctl->id.subdevice & 0xffff;
1735 kctl->id.subdevice = 0;
1736 }
1523 err = snd_ctl_add(codec->bus->card, kctl); 1737 err = snd_ctl_add(codec->bus->card, kctl);
1524 if (err < 0) 1738 if (err < 0)
1525 return err; 1739 return err;
1526 knewp = snd_array_new(&codec->mixers); 1740 item = snd_array_new(&codec->mixers);
1527 if (!knewp) 1741 if (!item)
1528 return -ENOMEM; 1742 return -ENOMEM;
1529 *knewp = kctl; 1743 item->kctl = kctl;
1744 item->nid = nid;
1530 return 0; 1745 return 0;
1531} 1746}
1532EXPORT_SYMBOL_HDA(snd_hda_ctl_add); 1747EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1533 1748
1534/* Clear all controls assigned to the given codec */ 1749/**
1750 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1751 * @codec: HD-audio codec
1752 */
1535void snd_hda_ctls_clear(struct hda_codec *codec) 1753void snd_hda_ctls_clear(struct hda_codec *codec)
1536{ 1754{
1537 int i; 1755 int i;
1538 struct snd_kcontrol **kctls = codec->mixers.list; 1756 struct hda_nid_item *items = codec->mixers.list;
1539 for (i = 0; i < codec->mixers.used; i++) 1757 for (i = 0; i < codec->mixers.used; i++)
1540 snd_ctl_remove(codec->bus->card, kctls[i]); 1758 snd_ctl_remove(codec->bus->card, items[i].kctl);
1541 snd_array_free(&codec->mixers); 1759 snd_array_free(&codec->mixers);
1542} 1760}
1543 1761
@@ -1563,6 +1781,16 @@ static void hda_unlock_devices(struct snd_card *card)
1563 spin_unlock(&card->files_lock); 1781 spin_unlock(&card->files_lock);
1564} 1782}
1565 1783
1784/**
1785 * snd_hda_codec_reset - Clear all objects assigned to the codec
1786 * @codec: HD-audio codec
1787 *
1788 * This frees the all PCM and control elements assigned to the codec, and
1789 * clears the caches and restores the pin default configurations.
1790 *
1791 * When a device is being used, it returns -EBSY. If successfully freed,
1792 * returns zero.
1793 */
1566int snd_hda_codec_reset(struct hda_codec *codec) 1794int snd_hda_codec_reset(struct hda_codec *codec)
1567{ 1795{
1568 struct snd_card *card = codec->bus->card; 1796 struct snd_card *card = codec->bus->card;
@@ -1626,7 +1854,22 @@ int snd_hda_codec_reset(struct hda_codec *codec)
1626 return 0; 1854 return 0;
1627} 1855}
1628 1856
1629/* create a virtual master control and add slaves */ 1857/**
1858 * snd_hda_add_vmaster - create a virtual master control and add slaves
1859 * @codec: HD-audio codec
1860 * @name: vmaster control name
1861 * @tlv: TLV data (optional)
1862 * @slaves: slave control names (optional)
1863 *
1864 * Create a virtual master control with the given name. The TLV data
1865 * must be either NULL or a valid data.
1866 *
1867 * @slaves is a NULL-terminated array of strings, each of which is a
1868 * slave control name. All controls with these names are assigned to
1869 * the new virtual master control.
1870 *
1871 * This function returns zero if successful or a negative error code.
1872 */
1630int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1873int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1631 unsigned int *tlv, const char **slaves) 1874 unsigned int *tlv, const char **slaves)
1632{ 1875{
@@ -1643,7 +1886,7 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1643 kctl = snd_ctl_make_virtual_master(name, tlv); 1886 kctl = snd_ctl_make_virtual_master(name, tlv);
1644 if (!kctl) 1887 if (!kctl)
1645 return -ENOMEM; 1888 return -ENOMEM;
1646 err = snd_hda_ctl_add(codec, kctl); 1889 err = snd_hda_ctl_add(codec, 0, kctl);
1647 if (err < 0) 1890 if (err < 0)
1648 return err; 1891 return err;
1649 1892
@@ -1668,7 +1911,12 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1668} 1911}
1669EXPORT_SYMBOL_HDA(snd_hda_add_vmaster); 1912EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
1670 1913
1671/* switch */ 1914/**
1915 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
1916 *
1917 * The control element is supposed to have the private_value field
1918 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1919 */
1672int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, 1920int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1673 struct snd_ctl_elem_info *uinfo) 1921 struct snd_ctl_elem_info *uinfo)
1674{ 1922{
@@ -1682,6 +1930,12 @@ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1682} 1930}
1683EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info); 1931EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
1684 1932
1933/**
1934 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
1935 *
1936 * The control element is supposed to have the private_value field
1937 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1938 */
1685int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, 1939int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1686 struct snd_ctl_elem_value *ucontrol) 1940 struct snd_ctl_elem_value *ucontrol)
1687{ 1941{
@@ -1702,6 +1956,12 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1702} 1956}
1703EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get); 1957EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
1704 1958
1959/**
1960 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
1961 *
1962 * The control element is supposed to have the private_value field
1963 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1964 */
1705int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 1965int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol) 1966 struct snd_ctl_elem_value *ucontrol)
1707{ 1967{
@@ -1733,6 +1993,25 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1733} 1993}
1734EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put); 1994EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1735 1995
1996#ifdef CONFIG_SND_HDA_INPUT_BEEP
1997/**
1998 * snd_hda_mixer_amp_switch_put_beep - Put callback for a beep AMP switch
1999 *
2000 * This function calls snd_hda_enable_beep_device(), which behaves differently
2001 * depending on beep_mode option.
2002 */
2003int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
2004 struct snd_ctl_elem_value *ucontrol)
2005{
2006 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2007 long *valp = ucontrol->value.integer.value;
2008
2009 snd_hda_enable_beep_device(codec, *valp);
2010 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2011}
2012EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep);
2013#endif /* CONFIG_SND_HDA_INPUT_BEEP */
2014
1736/* 2015/*
1737 * bound volume controls 2016 * bound volume controls
1738 * 2017 *
@@ -1742,6 +2021,12 @@ EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1742#define AMP_VAL_IDX_SHIFT 19 2021#define AMP_VAL_IDX_SHIFT 19
1743#define AMP_VAL_IDX_MASK (0x0f<<19) 2022#define AMP_VAL_IDX_MASK (0x0f<<19)
1744 2023
2024/**
2025 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control
2026 *
2027 * The control element is supposed to have the private_value field
2028 * set up via HDA_BIND_MUTE*() macros.
2029 */
1745int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, 2030int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol) 2031 struct snd_ctl_elem_value *ucontrol)
1747{ 2032{
@@ -1759,6 +2044,12 @@ int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1759} 2044}
1760EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get); 2045EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
1761 2046
2047/**
2048 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control
2049 *
2050 * The control element is supposed to have the private_value field
2051 * set up via HDA_BIND_MUTE*() macros.
2052 */
1762int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, 2053int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol) 2054 struct snd_ctl_elem_value *ucontrol)
1764{ 2055{
@@ -1783,8 +2074,11 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1783} 2074}
1784EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put); 2075EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
1785 2076
1786/* 2077/**
1787 * generic bound volume/swtich controls 2078 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control
2079 *
2080 * The control element is supposed to have the private_value field
2081 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
1788 */ 2082 */
1789int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol, 2083int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1790 struct snd_ctl_elem_info *uinfo) 2084 struct snd_ctl_elem_info *uinfo)
@@ -1803,6 +2097,12 @@ int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1803} 2097}
1804EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info); 2098EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
1805 2099
2100/**
2101 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control
2102 *
2103 * The control element is supposed to have the private_value field
2104 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2105 */
1806int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, 2106int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1807 struct snd_ctl_elem_value *ucontrol) 2107 struct snd_ctl_elem_value *ucontrol)
1808{ 2108{
@@ -1820,6 +2120,12 @@ int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1820} 2120}
1821EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get); 2121EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
1822 2122
2123/**
2124 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control
2125 *
2126 * The control element is supposed to have the private_value field
2127 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2128 */
1823int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, 2129int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_value *ucontrol) 2130 struct snd_ctl_elem_value *ucontrol)
1825{ 2131{
@@ -1843,6 +2149,12 @@ int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1843} 2149}
1844EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put); 2150EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
1845 2151
2152/**
2153 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control
2154 *
2155 * The control element is supposed to have the private_value field
2156 * set up via HDA_BIND_VOL() macro.
2157 */
1846int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, 2158int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1847 unsigned int size, unsigned int __user *tlv) 2159 unsigned int size, unsigned int __user *tlv)
1848{ 2160{
@@ -2126,7 +2438,7 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
2126 return -ENOMEM; 2438 return -ENOMEM;
2127 kctl->id.index = idx; 2439 kctl->id.index = idx;
2128 kctl->private_value = nid; 2440 kctl->private_value = nid;
2129 err = snd_hda_ctl_add(codec, kctl); 2441 err = snd_hda_ctl_add(codec, nid, kctl);
2130 if (err < 0) 2442 if (err < 0)
2131 return err; 2443 return err;
2132 } 2444 }
@@ -2165,14 +2477,19 @@ static struct snd_kcontrol_new spdif_share_sw = {
2165 .put = spdif_share_sw_put, 2477 .put = spdif_share_sw_put,
2166}; 2478};
2167 2479
2480/**
2481 * snd_hda_create_spdif_share_sw - create Default PCM switch
2482 * @codec: the HDA codec
2483 * @mout: multi-out instance
2484 */
2168int snd_hda_create_spdif_share_sw(struct hda_codec *codec, 2485int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2169 struct hda_multi_out *mout) 2486 struct hda_multi_out *mout)
2170{ 2487{
2171 if (!mout->dig_out_nid) 2488 if (!mout->dig_out_nid)
2172 return 0; 2489 return 0;
2173 /* ATTENTION: here mout is passed as private_data, instead of codec */ 2490 /* ATTENTION: here mout is passed as private_data, instead of codec */
2174 return snd_hda_ctl_add(codec, 2491 return snd_hda_ctl_add(codec, mout->dig_out_nid,
2175 snd_ctl_new1(&spdif_share_sw, mout)); 2492 snd_ctl_new1(&spdif_share_sw, mout));
2176} 2493}
2177EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw); 2494EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
2178 2495
@@ -2276,7 +2593,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2276 if (!kctl) 2593 if (!kctl)
2277 return -ENOMEM; 2594 return -ENOMEM;
2278 kctl->private_value = nid; 2595 kctl->private_value = nid;
2279 err = snd_hda_ctl_add(codec, kctl); 2596 err = snd_hda_ctl_add(codec, nid, kctl);
2280 if (err < 0) 2597 if (err < 0)
2281 return err; 2598 return err;
2282 } 2599 }
@@ -2332,7 +2649,12 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
2332} 2649}
2333EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache); 2650EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
2334 2651
2335/* resume the all commands from the cache */ 2652/**
2653 * snd_hda_codec_resume_cache - Resume the all commands from the cache
2654 * @codec: HD-audio codec
2655 *
2656 * Execute all verbs recorded in the command caches to resume.
2657 */
2336void snd_hda_codec_resume_cache(struct hda_codec *codec) 2658void snd_hda_codec_resume_cache(struct hda_codec *codec)
2337{ 2659{
2338 struct hda_cache_head *buffer = codec->cmd_cache.buf.list; 2660 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
@@ -2452,9 +2774,11 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
2452 codec->afg ? codec->afg : codec->mfg, 2774 codec->afg ? codec->afg : codec->mfg,
2453 AC_PWRST_D3); 2775 AC_PWRST_D3);
2454#ifdef CONFIG_SND_HDA_POWER_SAVE 2776#ifdef CONFIG_SND_HDA_POWER_SAVE
2777 snd_hda_update_power_acct(codec);
2455 cancel_delayed_work(&codec->power_work); 2778 cancel_delayed_work(&codec->power_work);
2456 codec->power_on = 0; 2779 codec->power_on = 0;
2457 codec->power_transition = 0; 2780 codec->power_transition = 0;
2781 codec->power_jiffies = jiffies;
2458#endif 2782#endif
2459} 2783}
2460 2784
@@ -2756,8 +3080,12 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2756} 3080}
2757 3081
2758/** 3082/**
2759 * snd_hda_is_supported_format - check whether the given node supports 3083 * snd_hda_is_supported_format - Check the validity of the format
2760 * the format val 3084 * @codec: HD-audio codec
3085 * @nid: NID to check
3086 * @format: the HD-audio format value to check
3087 *
3088 * Check whether the given node supports the format value.
2761 * 3089 *
2762 * Returns 1 if supported, 0 if not. 3090 * Returns 1 if supported, 0 if not.
2763 */ 3091 */
@@ -2877,51 +3205,36 @@ static int set_pcm_default_values(struct hda_codec *codec,
2877 return 0; 3205 return 0;
2878} 3206}
2879 3207
3208/* global */
3209const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3210 "Audio", "SPDIF", "HDMI", "Modem"
3211};
3212
2880/* 3213/*
2881 * get the empty PCM device number to assign 3214 * get the empty PCM device number to assign
2882 */ 3215 */
2883static int get_empty_pcm_device(struct hda_bus *bus, int type) 3216static int get_empty_pcm_device(struct hda_bus *bus, int type)
2884{ 3217{
2885 static const char *dev_name[HDA_PCM_NTYPES] = { 3218 /* audio device indices; not linear to keep compatibility */
2886 "Audio", "SPDIF", "HDMI", "Modem" 3219 static int audio_idx[HDA_PCM_NTYPES][5] = {
2887 }; 3220 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
2888 /* starting device index for each PCM type */ 3221 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
2889 static int dev_idx[HDA_PCM_NTYPES] = { 3222 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
2890 [HDA_PCM_TYPE_AUDIO] = 0, 3223 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
2891 [HDA_PCM_TYPE_SPDIF] = 1,
2892 [HDA_PCM_TYPE_HDMI] = 3,
2893 [HDA_PCM_TYPE_MODEM] = 6
2894 }; 3224 };
2895 /* normal audio device indices; not linear to keep compatibility */ 3225 int i;
2896 static int audio_idx[4] = { 0, 2, 4, 5 }; 3226
2897 int i, dev; 3227 if (type >= HDA_PCM_NTYPES) {
2898
2899 switch (type) {
2900 case HDA_PCM_TYPE_AUDIO:
2901 for (i = 0; i < ARRAY_SIZE(audio_idx); i++) {
2902 dev = audio_idx[i];
2903 if (!test_bit(dev, bus->pcm_dev_bits))
2904 goto ok;
2905 }
2906 snd_printk(KERN_WARNING "Too many audio devices\n");
2907 return -EAGAIN;
2908 case HDA_PCM_TYPE_SPDIF:
2909 case HDA_PCM_TYPE_HDMI:
2910 case HDA_PCM_TYPE_MODEM:
2911 dev = dev_idx[type];
2912 if (test_bit(dev, bus->pcm_dev_bits)) {
2913 snd_printk(KERN_WARNING "%s already defined\n",
2914 dev_name[type]);
2915 return -EAGAIN;
2916 }
2917 break;
2918 default:
2919 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); 3228 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
2920 return -EINVAL; 3229 return -EINVAL;
2921 } 3230 }
2922 ok: 3231
2923 set_bit(dev, bus->pcm_dev_bits); 3232 for (i = 0; audio_idx[type][i] >= 0 ; i++)
2924 return dev; 3233 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
3234 return audio_idx[type][i];
3235
3236 snd_printk(KERN_WARNING "Too many %s devices\n", snd_hda_pcm_type_name[type]);
3237 return -EAGAIN;
2925} 3238}
2926 3239
2927/* 3240/*
@@ -3159,14 +3472,14 @@ EXPORT_SYMBOL_HDA(snd_hda_check_board_codec_sid_config);
3159 */ 3472 */
3160int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew) 3473int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3161{ 3474{
3162 int err; 3475 int err;
3163 3476
3164 for (; knew->name; knew++) { 3477 for (; knew->name; knew++) {
3165 struct snd_kcontrol *kctl; 3478 struct snd_kcontrol *kctl;
3166 kctl = snd_ctl_new1(knew, codec); 3479 kctl = snd_ctl_new1(knew, codec);
3167 if (!kctl) 3480 if (!kctl)
3168 return -ENOMEM; 3481 return -ENOMEM;
3169 err = snd_hda_ctl_add(codec, kctl); 3482 err = snd_hda_ctl_add(codec, 0, kctl);
3170 if (err < 0) { 3483 if (err < 0) {
3171 if (!codec->addr) 3484 if (!codec->addr)
3172 return err; 3485 return err;
@@ -3174,7 +3487,7 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3174 if (!kctl) 3487 if (!kctl)
3175 return -ENOMEM; 3488 return -ENOMEM;
3176 kctl->id.device = codec->addr; 3489 kctl->id.device = codec->addr;
3177 err = snd_hda_ctl_add(codec, kctl); 3490 err = snd_hda_ctl_add(codec, 0, kctl);
3178 if (err < 0) 3491 if (err < 0)
3179 return err; 3492 return err;
3180 } 3493 }
@@ -3207,8 +3520,27 @@ static void hda_keep_power_on(struct hda_codec *codec)
3207{ 3520{
3208 codec->power_count++; 3521 codec->power_count++;
3209 codec->power_on = 1; 3522 codec->power_on = 1;
3523 codec->power_jiffies = jiffies;
3210} 3524}
3211 3525
3526/* update the power on/off account with the current jiffies */
3527void snd_hda_update_power_acct(struct hda_codec *codec)
3528{
3529 unsigned long delta = jiffies - codec->power_jiffies;
3530 if (codec->power_on)
3531 codec->power_on_acct += delta;
3532 else
3533 codec->power_off_acct += delta;
3534 codec->power_jiffies += delta;
3535}
3536
3537/**
3538 * snd_hda_power_up - Power-up the codec
3539 * @codec: HD-audio codec
3540 *
3541 * Increment the power-up counter and power up the hardware really when
3542 * not turned on yet.
3543 */
3212void snd_hda_power_up(struct hda_codec *codec) 3544void snd_hda_power_up(struct hda_codec *codec)
3213{ 3545{
3214 struct hda_bus *bus = codec->bus; 3546 struct hda_bus *bus = codec->bus;
@@ -3217,7 +3549,9 @@ void snd_hda_power_up(struct hda_codec *codec)
3217 if (codec->power_on || codec->power_transition) 3549 if (codec->power_on || codec->power_transition)
3218 return; 3550 return;
3219 3551
3552 snd_hda_update_power_acct(codec);
3220 codec->power_on = 1; 3553 codec->power_on = 1;
3554 codec->power_jiffies = jiffies;
3221 if (bus->ops.pm_notify) 3555 if (bus->ops.pm_notify)
3222 bus->ops.pm_notify(bus); 3556 bus->ops.pm_notify(bus);
3223 hda_call_codec_resume(codec); 3557 hda_call_codec_resume(codec);
@@ -3229,9 +3563,13 @@ EXPORT_SYMBOL_HDA(snd_hda_power_up);
3229#define power_save(codec) \ 3563#define power_save(codec) \
3230 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3564 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
3231 3565
3232#define power_save(codec) \ 3566/**
3233 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3567 * snd_hda_power_down - Power-down the codec
3234 3568 * @codec: HD-audio codec
3569 *
3570 * Decrement the power-up counter and schedules the power-off work if
3571 * the counter rearches to zero.
3572 */
3235void snd_hda_power_down(struct hda_codec *codec) 3573void snd_hda_power_down(struct hda_codec *codec)
3236{ 3574{
3237 --codec->power_count; 3575 --codec->power_count;
@@ -3245,6 +3583,19 @@ void snd_hda_power_down(struct hda_codec *codec)
3245} 3583}
3246EXPORT_SYMBOL_HDA(snd_hda_power_down); 3584EXPORT_SYMBOL_HDA(snd_hda_power_down);
3247 3585
3586/**
3587 * snd_hda_check_amp_list_power - Check the amp list and update the power
3588 * @codec: HD-audio codec
3589 * @check: the object containing an AMP list and the status
3590 * @nid: NID to check / update
3591 *
3592 * Check whether the given NID is in the amp list. If it's in the list,
3593 * check the current AMP status, and update the the power-status according
3594 * to the mute status.
3595 *
3596 * This function is supposed to be set or called from the check_power_status
3597 * patch ops.
3598 */
3248int snd_hda_check_amp_list_power(struct hda_codec *codec, 3599int snd_hda_check_amp_list_power(struct hda_codec *codec,
3249 struct hda_loopback_check *check, 3600 struct hda_loopback_check *check,
3250 hda_nid_t nid) 3601 hda_nid_t nid)
@@ -3286,6 +3637,10 @@ EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
3286/* 3637/*
3287 * Channel mode helper 3638 * Channel mode helper
3288 */ 3639 */
3640
3641/**
3642 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
3643 */
3289int snd_hda_ch_mode_info(struct hda_codec *codec, 3644int snd_hda_ch_mode_info(struct hda_codec *codec,
3290 struct snd_ctl_elem_info *uinfo, 3645 struct snd_ctl_elem_info *uinfo,
3291 const struct hda_channel_mode *chmode, 3646 const struct hda_channel_mode *chmode,
@@ -3302,6 +3657,9 @@ int snd_hda_ch_mode_info(struct hda_codec *codec,
3302} 3657}
3303EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info); 3658EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
3304 3659
3660/**
3661 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
3662 */
3305int snd_hda_ch_mode_get(struct hda_codec *codec, 3663int snd_hda_ch_mode_get(struct hda_codec *codec,
3306 struct snd_ctl_elem_value *ucontrol, 3664 struct snd_ctl_elem_value *ucontrol,
3307 const struct hda_channel_mode *chmode, 3665 const struct hda_channel_mode *chmode,
@@ -3320,6 +3678,9 @@ int snd_hda_ch_mode_get(struct hda_codec *codec,
3320} 3678}
3321EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get); 3679EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
3322 3680
3681/**
3682 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
3683 */
3323int snd_hda_ch_mode_put(struct hda_codec *codec, 3684int snd_hda_ch_mode_put(struct hda_codec *codec,
3324 struct snd_ctl_elem_value *ucontrol, 3685 struct snd_ctl_elem_value *ucontrol,
3325 const struct hda_channel_mode *chmode, 3686 const struct hda_channel_mode *chmode,
@@ -3344,6 +3705,10 @@ EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
3344/* 3705/*
3345 * input MUX helper 3706 * input MUX helper
3346 */ 3707 */
3708
3709/**
3710 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
3711 */
3347int snd_hda_input_mux_info(const struct hda_input_mux *imux, 3712int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3348 struct snd_ctl_elem_info *uinfo) 3713 struct snd_ctl_elem_info *uinfo)
3349{ 3714{
@@ -3362,6 +3727,9 @@ int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3362} 3727}
3363EXPORT_SYMBOL_HDA(snd_hda_input_mux_info); 3728EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
3364 3729
3730/**
3731 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
3732 */
3365int snd_hda_input_mux_put(struct hda_codec *codec, 3733int snd_hda_input_mux_put(struct hda_codec *codec,
3366 const struct hda_input_mux *imux, 3734 const struct hda_input_mux *imux,
3367 struct snd_ctl_elem_value *ucontrol, 3735 struct snd_ctl_elem_value *ucontrol,
@@ -3421,8 +3789,29 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3421 } 3789 }
3422} 3790}
3423 3791
3424/* 3792/**
3425 * open the digital out in the exclusive mode 3793 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
3794 * @bus: HD-audio bus
3795 */
3796void snd_hda_bus_reboot_notify(struct hda_bus *bus)
3797{
3798 struct hda_codec *codec;
3799
3800 if (!bus)
3801 return;
3802 list_for_each_entry(codec, &bus->codec_list, list) {
3803#ifdef CONFIG_SND_HDA_POWER_SAVE
3804 if (!codec->power_on)
3805 continue;
3806#endif
3807 if (codec->patch_ops.reboot_notify)
3808 codec->patch_ops.reboot_notify(codec);
3809 }
3810}
3811EXPORT_SYMBOL_HDA(snd_hda_bus_reboot_notify);
3812
3813/**
3814 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3426 */ 3815 */
3427int snd_hda_multi_out_dig_open(struct hda_codec *codec, 3816int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3428 struct hda_multi_out *mout) 3817 struct hda_multi_out *mout)
@@ -3437,6 +3826,9 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3437} 3826}
3438EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open); 3827EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
3439 3828
3829/**
3830 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3831 */
3440int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, 3832int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3441 struct hda_multi_out *mout, 3833 struct hda_multi_out *mout,
3442 unsigned int stream_tag, 3834 unsigned int stream_tag,
@@ -3450,6 +3842,9 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3450} 3842}
3451EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare); 3843EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
3452 3844
3845/**
3846 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
3847 */
3453int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, 3848int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3454 struct hda_multi_out *mout) 3849 struct hda_multi_out *mout)
3455{ 3850{
@@ -3460,8 +3855,8 @@ int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3460} 3855}
3461EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup); 3856EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup);
3462 3857
3463/* 3858/**
3464 * release the digital out 3859 * snd_hda_multi_out_dig_close - release the digital out stream
3465 */ 3860 */
3466int snd_hda_multi_out_dig_close(struct hda_codec *codec, 3861int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3467 struct hda_multi_out *mout) 3862 struct hda_multi_out *mout)
@@ -3473,8 +3868,12 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3473} 3868}
3474EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close); 3869EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
3475 3870
3476/* 3871/**
3477 * set up more restrictions for analog out 3872 * snd_hda_multi_out_analog_open - open analog outputs
3873 *
3874 * Open analog outputs and set up the hw-constraints.
3875 * If the digital outputs can be opened as slave, open the digital
3876 * outputs, too.
3478 */ 3877 */
3479int snd_hda_multi_out_analog_open(struct hda_codec *codec, 3878int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3480 struct hda_multi_out *mout, 3879 struct hda_multi_out *mout,
@@ -3519,9 +3918,11 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3519} 3918}
3520EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open); 3919EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
3521 3920
3522/* 3921/**
3523 * set up the i/o for analog out 3922 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs.
3524 * when the digital out is available, copy the front out to digital out, too. 3923 *
3924 * Set up the i/o for analog out.
3925 * When the digital out is available, copy the front out to digital out, too.
3525 */ 3926 */
3526int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, 3927int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3527 struct hda_multi_out *mout, 3928 struct hda_multi_out *mout,
@@ -3578,8 +3979,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3578} 3979}
3579EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare); 3980EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
3580 3981
3581/* 3982/**
3582 * clean up the setting for analog out 3983 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
3583 */ 3984 */
3584int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, 3985int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3585 struct hda_multi_out *mout) 3986 struct hda_multi_out *mout)
@@ -3965,8 +4366,14 @@ EXPORT_SYMBOL_HDA(snd_hda_resume);
3965 * generic arrays 4366 * generic arrays
3966 */ 4367 */
3967 4368
3968/* get a new element from the given array 4369/**
3969 * if it exceeds the pre-allocated array size, re-allocate the array 4370 * snd_array_new - get a new element from the given array
4371 * @array: the array object
4372 *
4373 * Get a new element from the given array. If it exceeds the
4374 * pre-allocated array size, re-allocate the array.
4375 *
4376 * Returns NULL if allocation failed.
3970 */ 4377 */
3971void *snd_array_new(struct snd_array *array) 4378void *snd_array_new(struct snd_array *array)
3972{ 4379{
@@ -3990,7 +4397,10 @@ void *snd_array_new(struct snd_array *array)
3990} 4397}
3991EXPORT_SYMBOL_HDA(snd_array_new); 4398EXPORT_SYMBOL_HDA(snd_array_new);
3992 4399
3993/* free the given array elements */ 4400/**
4401 * snd_array_free - free the given array elements
4402 * @array: the array object
4403 */
3994void snd_array_free(struct snd_array *array) 4404void snd_array_free(struct snd_array *array)
3995{ 4405{
3996 kfree(array->list); 4406 kfree(array->list);
@@ -4000,7 +4410,12 @@ void snd_array_free(struct snd_array *array)
4000} 4410}
4001EXPORT_SYMBOL_HDA(snd_array_free); 4411EXPORT_SYMBOL_HDA(snd_array_free);
4002 4412
4003/* 4413/**
4414 * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
4415 * @pcm: PCM caps bits
4416 * @buf: the string buffer to write
4417 * @buflen: the max buffer length
4418 *
4004 * used by hda_proc.c and hda_eld.c 4419 * used by hda_proc.c and hda_eld.c
4005 */ 4420 */
4006void snd_print_pcm_rates(int pcm, char *buf, int buflen) 4421void snd_print_pcm_rates(int pcm, char *buf, int buflen)
@@ -4019,6 +4434,14 @@ void snd_print_pcm_rates(int pcm, char *buf, int buflen)
4019} 4434}
4020EXPORT_SYMBOL_HDA(snd_print_pcm_rates); 4435EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
4021 4436
4437/**
4438 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4439 * @pcm: PCM caps bits
4440 * @buf: the string buffer to write
4441 * @buflen: the max buffer length
4442 *
4443 * used by hda_proc.c and hda_eld.c
4444 */
4022void snd_print_pcm_bits(int pcm, char *buf, int buflen) 4445void snd_print_pcm_bits(int pcm, char *buf, int buflen)
4023{ 4446{
4024 static unsigned int bits[] = { 8, 16, 20, 24, 32 }; 4447 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 99552fb5f756..2d627613aea3 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -286,6 +286,10 @@ enum {
286#define AC_PWRST_D1SUP (1<<1) 286#define AC_PWRST_D1SUP (1<<1)
287#define AC_PWRST_D2SUP (1<<2) 287#define AC_PWRST_D2SUP (1<<2)
288#define AC_PWRST_D3SUP (1<<3) 288#define AC_PWRST_D3SUP (1<<3)
289#define AC_PWRST_D3COLDSUP (1<<4)
290#define AC_PWRST_S3D3COLDSUP (1<<29)
291#define AC_PWRST_CLKSTOP (1<<30)
292#define AC_PWRST_EPSS (1U<<31)
289 293
290/* Power state values */ 294/* Power state values */
291#define AC_PWRST_SETTING (0xf<<0) 295#define AC_PWRST_SETTING (0xf<<0)
@@ -674,6 +678,7 @@ struct hda_codec_ops {
674#ifdef CONFIG_SND_HDA_POWER_SAVE 678#ifdef CONFIG_SND_HDA_POWER_SAVE
675 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); 679 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
676#endif 680#endif
681 void (*reboot_notify)(struct hda_codec *codec);
677}; 682};
678 683
679/* record for amp information cache */ 684/* record for amp information cache */
@@ -771,6 +776,7 @@ struct hda_codec {
771 776
772 /* beep device */ 777 /* beep device */
773 struct hda_beep *beep; 778 struct hda_beep *beep;
779 unsigned int beep_mode;
774 780
775 /* widget capabilities cache */ 781 /* widget capabilities cache */
776 unsigned int num_nodes; 782 unsigned int num_nodes;
@@ -811,6 +817,9 @@ struct hda_codec {
811 unsigned int power_transition :1; /* power-state in transition */ 817 unsigned int power_transition :1; /* power-state in transition */
812 int power_count; /* current (global) power refcount */ 818 int power_count; /* current (global) power refcount */
813 struct delayed_work power_work; /* delayed task for powerdown */ 819 struct delayed_work power_work; /* delayed task for powerdown */
820 unsigned long power_on_acct;
821 unsigned long power_off_acct;
822 unsigned long power_jiffies;
814#endif 823#endif
815 824
816 /* codec-specific additional proc output */ 825 /* codec-specific additional proc output */
@@ -910,6 +919,7 @@ int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
910 * Misc 919 * Misc
911 */ 920 */
912void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); 921void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
922void snd_hda_bus_reboot_notify(struct hda_bus *bus);
913 923
914/* 924/*
915 * power management 925 * power management
@@ -933,6 +943,7 @@ const char *snd_hda_get_jack_location(u32 cfg);
933void snd_hda_power_up(struct hda_codec *codec); 943void snd_hda_power_up(struct hda_codec *codec);
934void snd_hda_power_down(struct hda_codec *codec); 944void snd_hda_power_down(struct hda_codec *codec);
935#define snd_hda_codec_needs_resume(codec) codec->power_count 945#define snd_hda_codec_needs_resume(codec) codec->power_count
946void snd_hda_update_power_acct(struct hda_codec *codec);
936#else 947#else
937static inline void snd_hda_power_up(struct hda_codec *codec) {} 948static inline void snd_hda_power_up(struct hda_codec *codec) {}
938static inline void snd_hda_power_down(struct hda_codec *codec) {} 949static inline void snd_hda_power_down(struct hda_codec *codec) {}
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index 9446a5abea13..4228f2fe5956 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -309,17 +309,12 @@ out_fail:
309 return -EINVAL; 309 return -EINVAL;
310} 310}
311 311
312static int hdmi_present_sense(struct hda_codec *codec, hda_nid_t nid)
313{
314 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0);
315}
316
317static int hdmi_eld_valid(struct hda_codec *codec, hda_nid_t nid) 312static int hdmi_eld_valid(struct hda_codec *codec, hda_nid_t nid)
318{ 313{
319 int eldv; 314 int eldv;
320 int present; 315 int present;
321 316
322 present = hdmi_present_sense(codec, nid); 317 present = snd_hda_pin_sense(codec, nid);
323 eldv = (present & AC_PINSENSE_ELDV); 318 eldv = (present & AC_PINSENSE_ELDV);
324 present = (present & AC_PINSENSE_PRESENCE); 319 present = (present & AC_PINSENSE_PRESENCE);
325 320
@@ -477,6 +472,8 @@ static void hdmi_print_eld_info(struct snd_info_entry *entry,
477 [4 ... 7] = "reserved" 472 [4 ... 7] = "reserved"
478 }; 473 };
479 474
475 snd_iprintf(buffer, "monitor_present\t\t%d\n", e->monitor_present);
476 snd_iprintf(buffer, "eld_valid\t\t%d\n", e->eld_valid);
480 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name); 477 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name);
481 snd_iprintf(buffer, "connection_type\t\t%s\n", 478 snd_iprintf(buffer, "connection_type\t\t%s\n",
482 eld_connection_type_names[e->conn_type]); 479 eld_connection_type_names[e->conn_type]);
@@ -518,7 +515,11 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
518 * monitor_name manufacture_id product_id 515 * monitor_name manufacture_id product_id
519 * eld_version edid_version 516 * eld_version edid_version
520 */ 517 */
521 if (!strcmp(name, "connection_type")) 518 if (!strcmp(name, "monitor_present"))
519 e->monitor_present = val;
520 else if (!strcmp(name, "eld_valid"))
521 e->eld_valid = val;
522 else if (!strcmp(name, "connection_type"))
522 e->conn_type = val; 523 e->conn_type = val;
523 else if (!strcmp(name, "port_id")) 524 else if (!strcmp(name, "port_id"))
524 e->port_id = val; 525 e->port_id = val;
@@ -560,13 +561,14 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
560} 561}
561 562
562 563
563int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld) 564int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
565 int index)
564{ 566{
565 char name[32]; 567 char name[32];
566 struct snd_info_entry *entry; 568 struct snd_info_entry *entry;
567 int err; 569 int err;
568 570
569 snprintf(name, sizeof(name), "eld#%d", codec->addr); 571 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
570 err = snd_card_proc_new(codec->bus->card, name, &entry); 572 err = snd_card_proc_new(codec->bus->card, name, &entry);
571 if (err < 0) 573 if (err < 0)
572 return err; 574 return err;
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index b36f6c5a92df..092c6a7c2ff3 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -727,7 +727,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
727 if (is_loopback) 727 if (is_loopback)
728 add_input_loopback(codec, node->nid, HDA_INPUT, index); 728 add_input_loopback(codec, node->nid, HDA_INPUT, index);
729 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); 729 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
730 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 730 err = snd_hda_ctl_add(codec, node->nid,
731 snd_ctl_new1(&knew, codec));
731 if (err < 0) 732 if (err < 0)
732 return err; 733 return err;
733 created = 1; 734 created = 1;
@@ -737,7 +738,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
737 if (is_loopback) 738 if (is_loopback)
738 add_input_loopback(codec, node->nid, HDA_OUTPUT, 0); 739 add_input_loopback(codec, node->nid, HDA_OUTPUT, 0);
739 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); 740 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
740 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 741 err = snd_hda_ctl_add(codec, node->nid,
742 snd_ctl_new1(&knew, codec));
741 if (err < 0) 743 if (err < 0)
742 return err; 744 return err;
743 created = 1; 745 created = 1;
@@ -751,7 +753,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
751 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) { 753 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) {
752 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT); 754 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT);
753 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); 755 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
754 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 756 err = snd_hda_ctl_add(codec, node->nid,
757 snd_ctl_new1(&knew, codec));
755 if (err < 0) 758 if (err < 0)
756 return err; 759 return err;
757 created = 1; 760 created = 1;
@@ -759,7 +762,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
759 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) { 762 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) {
760 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT); 763 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT);
761 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); 764 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
762 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 765 err = snd_hda_ctl_add(codec, node->nid,
766 snd_ctl_new1(&knew, codec));
763 if (err < 0) 767 if (err < 0)
764 return err; 768 return err;
765 created = 1; 769 created = 1;
@@ -857,7 +861,7 @@ static int build_input_controls(struct hda_codec *codec)
857 } 861 }
858 862
859 /* create input MUX if multiple sources are available */ 863 /* create input MUX if multiple sources are available */
860 err = snd_hda_ctl_add(codec, snd_ctl_new1(&cap_sel, codec)); 864 err = snd_hda_ctl_add(codec, 0, snd_ctl_new1(&cap_sel, codec));
861 if (err < 0) 865 if (err < 0)
862 return err; 866 return err;
863 867
@@ -875,7 +879,8 @@ static int build_input_controls(struct hda_codec *codec)
875 HDA_CODEC_VOLUME(name, adc_node->nid, 879 HDA_CODEC_VOLUME(name, adc_node->nid,
876 spec->input_mux.items[i].index, 880 spec->input_mux.items[i].index,
877 HDA_INPUT); 881 HDA_INPUT);
878 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 882 err = snd_hda_ctl_add(codec, adc_node->nid,
883 snd_ctl_new1(&knew, codec));
879 if (err < 0) 884 if (err < 0)
880 return err; 885 return err;
881 } 886 }
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index cc24e6721d74..d24328661c6a 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -154,6 +154,44 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec)
154 return 0; 154 return 0;
155} 155}
156 156
157#ifdef CONFIG_SND_HDA_POWER_SAVE
158static ssize_t power_on_acct_show(struct device *dev,
159 struct device_attribute *attr,
160 char *buf)
161{
162 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
163 struct hda_codec *codec = hwdep->private_data;
164 snd_hda_update_power_acct(codec);
165 return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
166}
167
168static ssize_t power_off_acct_show(struct device *dev,
169 struct device_attribute *attr,
170 char *buf)
171{
172 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
173 struct hda_codec *codec = hwdep->private_data;
174 snd_hda_update_power_acct(codec);
175 return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
176}
177
178static struct device_attribute power_attrs[] = {
179 __ATTR_RO(power_on_acct),
180 __ATTR_RO(power_off_acct),
181};
182
183int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
184{
185 struct snd_hwdep *hwdep = codec->hwdep;
186 int i;
187
188 for (i = 0; i < ARRAY_SIZE(power_attrs); i++)
189 snd_add_device_sysfs_file(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card,
190 hwdep->device, &power_attrs[i]);
191 return 0;
192}
193#endif /* CONFIG_SND_HDA_POWER_SAVE */
194
157#ifdef CONFIG_SND_HDA_RECONFIG 195#ifdef CONFIG_SND_HDA_RECONFIG
158 196
159/* 197/*
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 6517f589d01d..d822bfc6cad6 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -60,10 +60,14 @@ static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
60static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; 60static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
61static int probe_only[SNDRV_CARDS]; 61static int probe_only[SNDRV_CARDS];
62static int single_cmd; 62static int single_cmd;
63static int enable_msi; 63static int enable_msi = -1;
64#ifdef CONFIG_SND_HDA_PATCH_LOADER 64#ifdef CONFIG_SND_HDA_PATCH_LOADER
65static char *patch[SNDRV_CARDS]; 65static char *patch[SNDRV_CARDS];
66#endif 66#endif
67#ifdef CONFIG_SND_HDA_INPUT_BEEP
68static int beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
69 CONFIG_SND_HDA_INPUT_BEEP_MODE};
70#endif
67 71
68module_param_array(index, int, NULL, 0444); 72module_param_array(index, int, NULL, 0444);
69MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); 73MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
@@ -91,6 +95,11 @@ MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
91module_param_array(patch, charp, NULL, 0444); 95module_param_array(patch, charp, NULL, 0444);
92MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface."); 96MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
93#endif 97#endif
98#ifdef CONFIG_SND_HDA_INPUT_BEEP
99module_param_array(beep_mode, int, NULL, 0444);
100MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
101 "(0=off, 1=on, 2=mute switch on/off) (default=1).");
102#endif
94 103
95#ifdef CONFIG_SND_HDA_POWER_SAVE 104#ifdef CONFIG_SND_HDA_POWER_SAVE
96static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; 105static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
@@ -404,6 +413,7 @@ struct azx {
404 unsigned short codec_mask; 413 unsigned short codec_mask;
405 int codec_probe_mask; /* copied from probe_mask option */ 414 int codec_probe_mask; /* copied from probe_mask option */
406 struct hda_bus *bus; 415 struct hda_bus *bus;
416 unsigned int beep_mode;
407 417
408 /* CORB/RIRB */ 418 /* CORB/RIRB */
409 struct azx_rb corb; 419 struct azx_rb corb;
@@ -677,6 +687,14 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
677 } 687 }
678 } 688 }
679 689
690 if (!chip->polling_mode) {
691 snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
692 "switching to polling mode: last cmd=0x%08x\n",
693 chip->last_cmd[addr]);
694 chip->polling_mode = 1;
695 goto again;
696 }
697
680 if (chip->msi) { 698 if (chip->msi) {
681 snd_printk(KERN_WARNING SFX "No response from codec, " 699 snd_printk(KERN_WARNING SFX "No response from codec, "
682 "disabling MSI: last cmd=0x%08x\n", 700 "disabling MSI: last cmd=0x%08x\n",
@@ -692,14 +710,6 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
692 goto again; 710 goto again;
693 } 711 }
694 712
695 if (!chip->polling_mode) {
696 snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
697 "switching to polling mode: last cmd=0x%08x\n",
698 chip->last_cmd[addr]);
699 chip->polling_mode = 1;
700 goto again;
701 }
702
703 if (chip->probing) { 713 if (chip->probing) {
704 /* If this critical timeout happens during the codec probing 714 /* If this critical timeout happens during the codec probing
705 * phase, this is likely an access to a non-existing codec 715 * phase, this is likely an access to a non-existing codec
@@ -1404,6 +1414,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model)
1404 err = snd_hda_codec_new(chip->bus, c, &codec); 1414 err = snd_hda_codec_new(chip->bus, c, &codec);
1405 if (err < 0) 1415 if (err < 0)
1406 continue; 1416 continue;
1417 codec->beep_mode = chip->beep_mode;
1407 codecs++; 1418 codecs++;
1408 } 1419 }
1409 } 1420 }
@@ -2154,6 +2165,7 @@ static int azx_resume(struct pci_dev *pci)
2154static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf) 2165static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
2155{ 2166{
2156 struct azx *chip = container_of(nb, struct azx, reboot_notifier); 2167 struct azx *chip = container_of(nb, struct azx, reboot_notifier);
2168 snd_hda_bus_reboot_notify(chip->bus);
2157 azx_stop_chip(chip); 2169 azx_stop_chip(chip);
2158 return NOTIFY_OK; 2170 return NOTIFY_OK;
2159} 2171}
@@ -2221,7 +2233,9 @@ static int azx_dev_free(struct snd_device *device)
2221static struct snd_pci_quirk position_fix_list[] __devinitdata = { 2233static struct snd_pci_quirk position_fix_list[] __devinitdata = {
2222 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB), 2234 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
2223 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB), 2235 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
2236 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
2224 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB), 2237 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
2238 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
2225 {} 2239 {}
2226}; 2240};
2227 2241
@@ -2304,11 +2318,9 @@ static void __devinit check_probe_mask(struct azx *chip, int dev)
2304} 2318}
2305 2319
2306/* 2320/*
2307 * white-list for enable_msi 2321 * white/black-list for enable_msi
2308 */ 2322 */
2309static struct snd_pci_quirk msi_white_list[] __devinitdata = { 2323static struct snd_pci_quirk msi_black_list[] __devinitdata = {
2310 SND_PCI_QUIRK(0x103c, 0x30f7, "HP Pavilion dv4t-1300", 1),
2311 SND_PCI_QUIRK(0x103c, 0x3607, "HP Compa CQ40", 1),
2312 {} 2324 {}
2313}; 2325};
2314 2326
@@ -2316,10 +2328,12 @@ static void __devinit check_msi(struct azx *chip)
2316{ 2328{
2317 const struct snd_pci_quirk *q; 2329 const struct snd_pci_quirk *q;
2318 2330
2319 chip->msi = enable_msi; 2331 if (enable_msi >= 0) {
2320 if (chip->msi) 2332 chip->msi = !!enable_msi;
2321 return; 2333 return;
2322 q = snd_pci_quirk_lookup(chip->pci, msi_white_list); 2334 }
2335 chip->msi = 1; /* enable MSI as default */
2336 q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
2323 if (q) { 2337 if (q) {
2324 printk(KERN_INFO 2338 printk(KERN_INFO
2325 "hda_intel: msi for device %04x:%04x set to %d\n", 2339 "hda_intel: msi for device %04x:%04x set to %d\n",
@@ -2578,6 +2592,10 @@ static int __devinit azx_probe(struct pci_dev *pci,
2578 goto out_free; 2592 goto out_free;
2579 card->private_data = chip; 2593 card->private_data = chip;
2580 2594
2595#ifdef CONFIG_SND_HDA_INPUT_BEEP
2596 chip->beep_mode = beep_mode[dev];
2597#endif
2598
2581 /* create codec instances */ 2599 /* create codec instances */
2582 err = azx_codec_create(chip, model[dev]); 2600 err = azx_codec_create(chip, model[dev]);
2583 if (err < 0) 2601 if (err < 0)
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 5f1dcc59002b..5778ae882b83 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -23,6 +23,15 @@
23#ifndef __SOUND_HDA_LOCAL_H 23#ifndef __SOUND_HDA_LOCAL_H
24#define __SOUND_HDA_LOCAL_H 24#define __SOUND_HDA_LOCAL_H
25 25
26/* We abuse kcontrol_new.subdev field to pass the NID corresponding to
27 * the given new control. If id.subdev has a bit flag HDA_SUBDEV_NID_FLAG,
28 * snd_hda_ctl_add() takes the lower-bit subdev value as a valid NID.
29 *
30 * Note that the subdevice field is cleared again before the real registration
31 * in snd_hda_ctl_add(), so that this value won't appear in the outside.
32 */
33#define HDA_SUBDEV_NID_FLAG (1U << 31)
34
26/* 35/*
27 * for mixer controls 36 * for mixer controls
28 */ 37 */
@@ -33,6 +42,7 @@
33/* mono volume with index (index=0,1,...) (channel=1,2) */ 42/* mono volume with index (index=0,1,...) (channel=1,2) */
34#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 43#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
35 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 44 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
45 .subdevice = HDA_SUBDEV_NID_FLAG | (nid), \
36 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ 46 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
37 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 47 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
38 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \ 48 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
@@ -53,6 +63,7 @@
53/* mono mute switch with index (index=0,1,...) (channel=1,2) */ 63/* mono mute switch with index (index=0,1,...) (channel=1,2) */
54#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 64#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
55 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 65 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
66 .subdevice = HDA_SUBDEV_NID_FLAG | (nid), \
56 .info = snd_hda_mixer_amp_switch_info, \ 67 .info = snd_hda_mixer_amp_switch_info, \
57 .get = snd_hda_mixer_amp_switch_get, \ 68 .get = snd_hda_mixer_amp_switch_get, \
58 .put = snd_hda_mixer_amp_switch_put, \ 69 .put = snd_hda_mixer_amp_switch_put, \
@@ -66,6 +77,28 @@
66/* stereo mute switch */ 77/* stereo mute switch */
67#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \ 78#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
68 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction) 79 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
80#ifdef CONFIG_SND_HDA_INPUT_BEEP
81/* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
82#define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
83 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
84 .subdevice = HDA_SUBDEV_NID_FLAG | (nid), \
85 .info = snd_hda_mixer_amp_switch_info, \
86 .get = snd_hda_mixer_amp_switch_get, \
87 .put = snd_hda_mixer_amp_switch_put_beep, \
88 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
89#else
90/* no digital beep - just the standard one */
91#define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, ch, xidx, dir) \
92 HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, ch, xidx, dir)
93#endif /* CONFIG_SND_HDA_INPUT_BEEP */
94/* special beep mono mute switch */
95#define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
96 HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
97/* special beep stereo mute switch */
98#define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
99 HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
100
101extern const char *snd_hda_pcm_type_name[];
69 102
70int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 103int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
71 struct snd_ctl_elem_info *uinfo); 104 struct snd_ctl_elem_info *uinfo);
@@ -81,6 +114,10 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
81 struct snd_ctl_elem_value *ucontrol); 114 struct snd_ctl_elem_value *ucontrol);
82int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 115int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
83 struct snd_ctl_elem_value *ucontrol); 116 struct snd_ctl_elem_value *ucontrol);
117#ifdef CONFIG_SND_HDA_INPUT_BEEP
118int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
119 struct snd_ctl_elem_value *ucontrol);
120#endif
84/* lowlevel accessor with caching; use carefully */ 121/* lowlevel accessor with caching; use carefully */
85int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 122int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
86 int direction, int index); 123 int direction, int index);
@@ -424,8 +461,16 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
424int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 461int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
425 unsigned int caps); 462 unsigned int caps);
426u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); 463u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
464u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
465int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
427 466
428int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl); 467struct hda_nid_item {
468 struct snd_kcontrol *kctl;
469 hda_nid_t nid;
470};
471
472int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
473 struct snd_kcontrol *kctl);
429void snd_hda_ctls_clear(struct hda_codec *codec); 474void snd_hda_ctls_clear(struct hda_codec *codec);
430 475
431/* 476/*
@@ -437,6 +482,15 @@ int snd_hda_create_hwdep(struct hda_codec *codec);
437static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; } 482static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
438#endif 483#endif
439 484
485#if defined(CONFIG_SND_HDA_POWER_SAVE) && defined(CONFIG_SND_HDA_HWDEP)
486int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec);
487#else
488static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
489{
490 return 0;
491}
492#endif
493
440#ifdef CONFIG_SND_HDA_RECONFIG 494#ifdef CONFIG_SND_HDA_RECONFIG
441int snd_hda_hwdep_add_sysfs(struct hda_codec *codec); 495int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
442#else 496#else
@@ -490,7 +544,8 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
490 * AMP control callbacks 544 * AMP control callbacks
491 */ 545 */
492/* retrieve parameters from private_value */ 546/* retrieve parameters from private_value */
493#define get_amp_nid(kc) ((kc)->private_value & 0xffff) 547#define get_amp_nid_(pv) ((pv) & 0xffff)
548#define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
494#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3) 549#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
495#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1) 550#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
496#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf) 551#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
@@ -516,9 +571,11 @@ struct cea_sad {
516 * ELD: EDID Like Data 571 * ELD: EDID Like Data
517 */ 572 */
518struct hdmi_eld { 573struct hdmi_eld {
574 bool monitor_present;
575 bool eld_valid;
519 int eld_size; 576 int eld_size;
520 int baseline_len; 577 int baseline_len;
521 int eld_ver; /* (eld_ver == 0) indicates invalid ELD */ 578 int eld_ver;
522 int cea_edid_ver; 579 int cea_edid_ver;
523 char monitor_name[ELD_MAX_MNL + 1]; 580 char monitor_name[ELD_MAX_MNL + 1];
524 int manufacture_id; 581 int manufacture_id;
@@ -541,11 +598,13 @@ int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
541void snd_hdmi_show_eld(struct hdmi_eld *eld); 598void snd_hdmi_show_eld(struct hdmi_eld *eld);
542 599
543#ifdef CONFIG_PROC_FS 600#ifdef CONFIG_PROC_FS
544int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld); 601int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
602 int index);
545void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld); 603void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
546#else 604#else
547static inline int snd_hda_eld_proc_new(struct hda_codec *codec, 605static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
548 struct hdmi_eld *eld) 606 struct hdmi_eld *eld,
607 int index)
549{ 608{
550 return 0; 609 return 0;
551} 610}
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 95f24e4729f8..09476fc1ab64 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -26,6 +26,21 @@
26#include "hda_codec.h" 26#include "hda_codec.h"
27#include "hda_local.h" 27#include "hda_local.h"
28 28
29static char *bits_names(unsigned int bits, char *names[], int size)
30{
31 int i, n;
32 static char buf[128];
33
34 for (i = 0, n = 0; i < size; i++) {
35 if (bits & (1U<<i) && names[i])
36 n += snprintf(buf + n, sizeof(buf) - n, " %s",
37 names[i]);
38 }
39 buf[n] = '\0';
40
41 return buf;
42}
43
29static const char *get_wid_type_name(unsigned int wid_value) 44static const char *get_wid_type_name(unsigned int wid_value)
30{ 45{
31 static char *names[16] = { 46 static char *names[16] = {
@@ -46,6 +61,41 @@ static const char *get_wid_type_name(unsigned int wid_value)
46 return "UNKNOWN Widget"; 61 return "UNKNOWN Widget";
47} 62}
48 63
64static void print_nid_mixers(struct snd_info_buffer *buffer,
65 struct hda_codec *codec, hda_nid_t nid)
66{
67 int i;
68 struct hda_nid_item *items = codec->mixers.list;
69 struct snd_kcontrol *kctl;
70 for (i = 0; i < codec->mixers.used; i++) {
71 if (items[i].nid == nid) {
72 kctl = items[i].kctl;
73 snd_iprintf(buffer,
74 " Control: name=\"%s\", index=%i, device=%i\n",
75 kctl->id.name, kctl->id.index, kctl->id.device);
76 }
77 }
78}
79
80static void print_nid_pcms(struct snd_info_buffer *buffer,
81 struct hda_codec *codec, hda_nid_t nid)
82{
83 int pcm, type;
84 struct hda_pcm *cpcm;
85 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
86 cpcm = &codec->pcm_info[pcm];
87 for (type = 0; type < 2; type++) {
88 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
89 continue;
90 snd_iprintf(buffer, " Device: name=\"%s\", "
91 "type=\"%s\", device=%i\n",
92 cpcm->name,
93 snd_hda_pcm_type_name[cpcm->pcm_type],
94 cpcm->pcm->device);
95 }
96 }
97}
98
49static void print_amp_caps(struct snd_info_buffer *buffer, 99static void print_amp_caps(struct snd_info_buffer *buffer,
50 struct hda_codec *codec, hda_nid_t nid, int dir) 100 struct hda_codec *codec, hda_nid_t nid, int dir)
51{ 101{
@@ -363,8 +413,24 @@ static const char *get_pwr_state(u32 state)
363static void print_power_state(struct snd_info_buffer *buffer, 413static void print_power_state(struct snd_info_buffer *buffer,
364 struct hda_codec *codec, hda_nid_t nid) 414 struct hda_codec *codec, hda_nid_t nid)
365{ 415{
416 static char *names[] = {
417 [ilog2(AC_PWRST_D0SUP)] = "D0",
418 [ilog2(AC_PWRST_D1SUP)] = "D1",
419 [ilog2(AC_PWRST_D2SUP)] = "D2",
420 [ilog2(AC_PWRST_D3SUP)] = "D3",
421 [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
422 [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
423 [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
424 [ilog2(AC_PWRST_EPSS)] = "EPSS",
425 };
426
427 int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE);
366 int pwr = snd_hda_codec_read(codec, nid, 0, 428 int pwr = snd_hda_codec_read(codec, nid, 0,
367 AC_VERB_GET_POWER_STATE, 0); 429 AC_VERB_GET_POWER_STATE, 0);
430 if (sup)
431 snd_iprintf(buffer, " Power states: %s\n",
432 bits_names(sup, names, ARRAY_SIZE(names)));
433
368 snd_iprintf(buffer, " Power: setting=%s, actual=%s\n", 434 snd_iprintf(buffer, " Power: setting=%s, actual=%s\n",
369 get_pwr_state(pwr & AC_PWRST_SETTING), 435 get_pwr_state(pwr & AC_PWRST_SETTING),
370 get_pwr_state((pwr & AC_PWRST_ACTUAL) >> 436 get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
@@ -457,6 +523,7 @@ static void print_gpio(struct snd_info_buffer *buffer,
457 (data & (1<<i)) ? 1 : 0, 523 (data & (1<<i)) ? 1 : 0,
458 (unsol & (1<<i)) ? 1 : 0); 524 (unsol & (1<<i)) ? 1 : 0);
459 /* FIXME: add GPO and GPI pin information */ 525 /* FIXME: add GPO and GPI pin information */
526 print_nid_mixers(buffer, codec, nid);
460} 527}
461 528
462static void print_codec_info(struct snd_info_entry *entry, 529static void print_codec_info(struct snd_info_entry *entry,
@@ -536,6 +603,9 @@ static void print_codec_info(struct snd_info_entry *entry,
536 snd_iprintf(buffer, " CP"); 603 snd_iprintf(buffer, " CP");
537 snd_iprintf(buffer, "\n"); 604 snd_iprintf(buffer, "\n");
538 605
606 print_nid_mixers(buffer, codec, nid);
607 print_nid_pcms(buffer, codec, nid);
608
539 /* volume knob is a special widget that always have connection 609 /* volume knob is a special widget that always have connection
540 * list 610 * list
541 */ 611 */
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 2d603f6aba63..455a0494f907 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -156,15 +156,19 @@ static const char *ad_slave_sws[] = {
156 156
157static void ad198x_free_kctls(struct hda_codec *codec); 157static void ad198x_free_kctls(struct hda_codec *codec);
158 158
159#ifdef CONFIG_SND_HDA_INPUT_BEEP
159/* additional beep mixers; the actual parameters are overwritten at build */ 160/* additional beep mixers; the actual parameters are overwritten at build */
160static struct snd_kcontrol_new ad_beep_mixer[] = { 161static struct snd_kcontrol_new ad_beep_mixer[] = {
161 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT), 162 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
162 HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_OUTPUT), 163 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
163 { } /* end */ 164 { } /* end */
164}; 165};
165 166
166#define set_beep_amp(spec, nid, idx, dir) \ 167#define set_beep_amp(spec, nid, idx, dir) \
167 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */ 168 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
169#else
170#define set_beep_amp(spec, nid, idx, dir) /* NOP */
171#endif
168 172
169static int ad198x_build_controls(struct hda_codec *codec) 173static int ad198x_build_controls(struct hda_codec *codec)
170{ 174{
@@ -194,6 +198,7 @@ static int ad198x_build_controls(struct hda_codec *codec)
194 } 198 }
195 199
196 /* create beep controls if needed */ 200 /* create beep controls if needed */
201#ifdef CONFIG_SND_HDA_INPUT_BEEP
197 if (spec->beep_amp) { 202 if (spec->beep_amp) {
198 struct snd_kcontrol_new *knew; 203 struct snd_kcontrol_new *knew;
199 for (knew = ad_beep_mixer; knew->name; knew++) { 204 for (knew = ad_beep_mixer; knew->name; knew++) {
@@ -202,11 +207,14 @@ static int ad198x_build_controls(struct hda_codec *codec)
202 if (!kctl) 207 if (!kctl)
203 return -ENOMEM; 208 return -ENOMEM;
204 kctl->private_value = spec->beep_amp; 209 kctl->private_value = spec->beep_amp;
205 err = snd_hda_ctl_add(codec, kctl); 210 err = snd_hda_ctl_add(codec,
211 get_amp_nid_(spec->beep_amp),
212 kctl);
206 if (err < 0) 213 if (err < 0)
207 return err; 214 return err;
208 } 215 }
209 } 216 }
217#endif
210 218
211 /* if we have no master control, let's create it */ 219 /* if we have no master control, let's create it */
212 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 220 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
@@ -712,10 +720,10 @@ static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
712static void ad1986a_automic(struct hda_codec *codec) 720static void ad1986a_automic(struct hda_codec *codec)
713{ 721{
714 unsigned int present; 722 unsigned int present;
715 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0); 723 present = snd_hda_jack_detect(codec, 0x1f);
716 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */ 724 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
717 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL, 725 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
718 (present & AC_PINSENSE_PRESENCE) ? 0 : 2); 726 present ? 0 : 2);
719} 727}
720 728
721#define AD1986A_MIC_EVENT 0x36 729#define AD1986A_MIC_EVENT 0x36
@@ -754,10 +762,8 @@ static void ad1986a_update_hp(struct hda_codec *codec)
754static void ad1986a_hp_automute(struct hda_codec *codec) 762static void ad1986a_hp_automute(struct hda_codec *codec)
755{ 763{
756 struct ad198x_spec *spec = codec->spec; 764 struct ad198x_spec *spec = codec->spec;
757 unsigned int present;
758 765
759 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0); 766 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
760 spec->jack_present = !!(present & 0x80000000);
761 if (spec->inv_jack_detect) 767 if (spec->inv_jack_detect)
762 spec->jack_present = !spec->jack_present; 768 spec->jack_present = !spec->jack_present;
763 ad1986a_update_hp(codec); 769 ad1986a_update_hp(codec);
@@ -1547,8 +1553,7 @@ static void ad1981_hp_automute(struct hda_codec *codec)
1547{ 1553{
1548 unsigned int present; 1554 unsigned int present;
1549 1555
1550 present = snd_hda_codec_read(codec, 0x06, 0, 1556 present = snd_hda_jack_detect(codec, 0x06);
1551 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1552 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0, 1557 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1553 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 1558 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1554} 1559}
@@ -1568,8 +1573,7 @@ static void ad1981_hp_automic(struct hda_codec *codec)
1568 }; 1573 };
1569 unsigned int present; 1574 unsigned int present;
1570 1575
1571 present = snd_hda_codec_read(codec, 0x08, 0, 1576 present = snd_hda_jack_detect(codec, 0x08);
1572 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1573 if (present) 1577 if (present)
1574 snd_hda_sequence_write(codec, mic_jack_on); 1578 snd_hda_sequence_write(codec, mic_jack_on);
1575 else 1579 else
@@ -2524,7 +2528,7 @@ static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2524{ 2528{
2525 if ((res >> 26) != AD1988_HP_EVENT) 2529 if ((res >> 26) != AD1988_HP_EVENT)
2526 return; 2530 return;
2527 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31)) 2531 if (snd_hda_jack_detect(codec, 0x11))
2528 snd_hda_sequence_write(codec, ad1988_laptop_hp_on); 2532 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2529 else 2533 else
2530 snd_hda_sequence_write(codec, ad1988_laptop_hp_off); 2534 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
@@ -2569,6 +2573,8 @@ static int add_control(struct ad198x_spec *spec, int type, const char *name,
2569 knew->name = kstrdup(name, GFP_KERNEL); 2573 knew->name = kstrdup(name, GFP_KERNEL);
2570 if (! knew->name) 2574 if (! knew->name)
2571 return -ENOMEM; 2575 return -ENOMEM;
2576 if (get_amp_nid_(val))
2577 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
2572 knew->private_value = val; 2578 knew->private_value = val;
2573 return 0; 2579 return 0;
2574} 2580}
@@ -3768,8 +3774,7 @@ static void ad1884a_hp_automute(struct hda_codec *codec)
3768{ 3774{
3769 unsigned int present; 3775 unsigned int present;
3770 3776
3771 present = snd_hda_codec_read(codec, 0x11, 0, 3777 present = snd_hda_jack_detect(codec, 0x11);
3772 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3773 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, 3778 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3774 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 3779 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3775 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE, 3780 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
@@ -3781,8 +3786,7 @@ static void ad1884a_hp_automic(struct hda_codec *codec)
3781{ 3786{
3782 unsigned int present; 3787 unsigned int present;
3783 3788
3784 present = snd_hda_codec_read(codec, 0x14, 0, 3789 present = snd_hda_jack_detect(codec, 0x14);
3785 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3786 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, 3790 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3787 present ? 0 : 1); 3791 present ? 0 : 1);
3788} 3792}
@@ -3817,13 +3821,9 @@ static void ad1884a_laptop_automute(struct hda_codec *codec)
3817{ 3821{
3818 unsigned int present; 3822 unsigned int present;
3819 3823
3820 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0); 3824 present = snd_hda_jack_detect(codec, 0x11);
3821 present &= AC_PINSENSE_PRESENCE; 3825 if (!present)
3822 if (!present) { 3826 present = snd_hda_jack_detect(codec, 0x12);
3823 present = snd_hda_codec_read(codec, 0x12, 0,
3824 AC_VERB_GET_PIN_SENSE, 0);
3825 present &= AC_PINSENSE_PRESENCE;
3826 }
3827 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, 3827 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3828 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 3828 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3829 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE, 3829 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
@@ -3835,11 +3835,9 @@ static void ad1884a_laptop_automic(struct hda_codec *codec)
3835{ 3835{
3836 unsigned int idx; 3836 unsigned int idx;
3837 3837
3838 if (snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0) & 3838 if (snd_hda_jack_detect(codec, 0x14))
3839 AC_PINSENSE_PRESENCE)
3840 idx = 0; 3839 idx = 0;
3841 else if (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 3840 else if (snd_hda_jack_detect(codec, 0x1c))
3842 AC_PINSENSE_PRESENCE)
3843 idx = 4; 3841 idx = 4;
3844 else 3842 else
3845 idx = 1; 3843 idx = 1;
@@ -4008,8 +4006,7 @@ static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4008{ 4006{
4009 unsigned int present; 4007 unsigned int present;
4010 4008
4011 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) 4009 present = snd_hda_jack_detect(codec, 0x11);
4012 & AC_PINSENSE_PRESENCE;
4013 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0, 4010 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4014 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 4011 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4015} 4012}
@@ -4117,14 +4114,12 @@ static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4117/* switch to external mic if plugged */ 4114/* switch to external mic if plugged */
4118static void ad1984a_touchsmart_automic(struct hda_codec *codec) 4115static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4119{ 4116{
4120 if (snd_hda_codec_read(codec, 0x1c, 0, 4117 if (snd_hda_jack_detect(codec, 0x1c))
4121 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000) {
4122 snd_hda_codec_write(codec, 0x0c, 0, 4118 snd_hda_codec_write(codec, 0x0c, 0,
4123 AC_VERB_SET_CONNECT_SEL, 0x4); 4119 AC_VERB_SET_CONNECT_SEL, 0x4);
4124 } else { 4120 else
4125 snd_hda_codec_write(codec, 0x0c, 0, 4121 snd_hda_codec_write(codec, 0x0c, 0,
4126 AC_VERB_SET_CONNECT_SEL, 0x5); 4122 AC_VERB_SET_CONNECT_SEL, 0x5);
4127 }
4128} 4123}
4129 4124
4130 4125
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index d08353d3bb7f..af478019088e 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -144,7 +144,7 @@ static int _add_switch(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
144 struct snd_kcontrol_new knew = 144 struct snd_kcontrol_new knew =
145 HDA_CODEC_MUTE_MONO(namestr, nid, chan, 0, type); 145 HDA_CODEC_MUTE_MONO(namestr, nid, chan, 0, type);
146 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]); 146 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
147 return snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 147 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
148} 148}
149 149
150static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx, 150static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
@@ -155,7 +155,7 @@ static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
155 struct snd_kcontrol_new knew = 155 struct snd_kcontrol_new knew =
156 HDA_CODEC_VOLUME_MONO(namestr, nid, chan, 0, type); 156 HDA_CODEC_VOLUME_MONO(namestr, nid, chan, 0, type);
157 sprintf(namestr, "%s %s Volume", pfx, dirstr[dir]); 157 sprintf(namestr, "%s %s Volume", pfx, dirstr[dir]);
158 return snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 158 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
159} 159}
160 160
161#define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0) 161#define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0)
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 8ba306856d38..4b200da1bd18 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -500,7 +500,7 @@ static int add_mute(struct hda_codec *codec, const char *name, int index,
500 knew.private_value = pval; 500 knew.private_value = pval;
501 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]); 501 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]);
502 *kctlp = snd_ctl_new1(&knew, codec); 502 *kctlp = snd_ctl_new1(&knew, codec);
503 return snd_hda_ctl_add(codec, *kctlp); 503 return snd_hda_ctl_add(codec, get_amp_nid_(pval), *kctlp);
504} 504}
505 505
506static int add_volume(struct hda_codec *codec, const char *name, 506static int add_volume(struct hda_codec *codec, const char *name,
@@ -513,7 +513,7 @@ static int add_volume(struct hda_codec *codec, const char *name,
513 knew.private_value = pval; 513 knew.private_value = pval;
514 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]); 514 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
515 *kctlp = snd_ctl_new1(&knew, codec); 515 *kctlp = snd_ctl_new1(&knew, codec);
516 return snd_hda_ctl_add(codec, *kctlp); 516 return snd_hda_ctl_add(codec, get_amp_nid_(pval), *kctlp);
517} 517}
518 518
519static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) 519static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
@@ -536,14 +536,14 @@ static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
536 536
537 spec->vmaster_sw = 537 spec->vmaster_sw =
538 snd_ctl_make_virtual_master("Master Playback Switch", NULL); 538 snd_ctl_make_virtual_master("Master Playback Switch", NULL);
539 err = snd_hda_ctl_add(codec, spec->vmaster_sw); 539 err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw);
540 if (err < 0) 540 if (err < 0)
541 return err; 541 return err;
542 542
543 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv); 543 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
544 spec->vmaster_vol = 544 spec->vmaster_vol =
545 snd_ctl_make_virtual_master("Master Playback Volume", tlv); 545 snd_ctl_make_virtual_master("Master Playback Volume", tlv);
546 err = snd_hda_ctl_add(codec, spec->vmaster_vol); 546 err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol);
547 if (err < 0) 547 if (err < 0)
548 return err; 548 return err;
549 return 0; 549 return 0;
@@ -756,13 +756,13 @@ static int build_input(struct hda_codec *codec)
756 if (!kctl) 756 if (!kctl)
757 return -ENOMEM; 757 return -ENOMEM;
758 kctl->private_value = (long)spec->capture_bind[i]; 758 kctl->private_value = (long)spec->capture_bind[i];
759 err = snd_hda_ctl_add(codec, kctl); 759 err = snd_hda_ctl_add(codec, 0, kctl);
760 if (err < 0) 760 if (err < 0)
761 return err; 761 return err;
762 } 762 }
763 763
764 if (spec->num_inputs > 1 && !spec->mic_detect) { 764 if (spec->num_inputs > 1 && !spec->mic_detect) {
765 err = snd_hda_ctl_add(codec, 765 err = snd_hda_ctl_add(codec, 0,
766 snd_ctl_new1(&cs_capture_source, codec)); 766 snd_ctl_new1(&cs_capture_source, codec));
767 if (err < 0) 767 if (err < 0)
768 return err; 768 return err;
@@ -807,7 +807,7 @@ static void cs_automute(struct hda_codec *codec)
807{ 807{
808 struct cs_spec *spec = codec->spec; 808 struct cs_spec *spec = codec->spec;
809 struct auto_pin_cfg *cfg = &spec->autocfg; 809 struct auto_pin_cfg *cfg = &spec->autocfg;
810 unsigned int caps, present, hp_present; 810 unsigned int caps, hp_present;
811 hda_nid_t nid; 811 hda_nid_t nid;
812 int i; 812 int i;
813 813
@@ -817,12 +817,7 @@ static void cs_automute(struct hda_codec *codec)
817 caps = snd_hda_query_pin_caps(codec, nid); 817 caps = snd_hda_query_pin_caps(codec, nid);
818 if (!(caps & AC_PINCAP_PRES_DETECT)) 818 if (!(caps & AC_PINCAP_PRES_DETECT))
819 continue; 819 continue;
820 if (caps & AC_PINCAP_TRIG_REQ) 820 hp_present = snd_hda_jack_detect(codec, nid);
821 snd_hda_codec_read(codec, nid, 0,
822 AC_VERB_SET_PIN_SENSE, 0);
823 present = snd_hda_codec_read(codec, nid, 0,
824 AC_VERB_GET_PIN_SENSE, 0);
825 hp_present |= (present & AC_PINSENSE_PRESENCE) != 0;
826 if (hp_present) 821 if (hp_present)
827 break; 822 break;
828 } 823 }
@@ -844,15 +839,11 @@ static void cs_automic(struct hda_codec *codec)
844 struct cs_spec *spec = codec->spec; 839 struct cs_spec *spec = codec->spec;
845 struct auto_pin_cfg *cfg = &spec->autocfg; 840 struct auto_pin_cfg *cfg = &spec->autocfg;
846 hda_nid_t nid; 841 hda_nid_t nid;
847 unsigned int caps, present; 842 unsigned int present;
848 843
849 nid = cfg->input_pins[spec->automic_idx]; 844 nid = cfg->input_pins[spec->automic_idx];
850 caps = snd_hda_query_pin_caps(codec, nid); 845 present = snd_hda_jack_detect(codec, nid);
851 if (caps & AC_PINCAP_TRIG_REQ) 846 if (present)
852 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
853 present = snd_hda_codec_read(codec, nid, 0,
854 AC_VERB_GET_PIN_SENSE, 0);
855 if (present & AC_PINSENSE_PRESENCE)
856 change_cur_input(codec, spec->automic_idx, 0); 847 change_cur_input(codec, spec->automic_idx, 0);
857 else { 848 else {
858 unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ? 849 unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ?
@@ -947,7 +938,7 @@ static void init_input(struct hda_codec *codec)
947 coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */ 938 coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */
948 if (is_active_pin(codec, CS_DMIC1_PIN_NID)) 939 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
949 coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0 940 coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0
950 * No effect if SPDIF_OUT2 is slected in 941 * No effect if SPDIF_OUT2 is selected in
951 * IDX_SPDIF_CTL. 942 * IDX_SPDIF_CTL.
952 */ 943 */
953 cs_vendor_coef_set(codec, IDX_ADC_CFG, coef); 944 cs_vendor_coef_set(codec, IDX_ADC_CFG, coef);
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 780e1a72114a..a45c1169762b 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -66,7 +66,7 @@ struct cmi_spec {
66 66
67 struct hda_pcm pcm_rec[2]; /* PCM information */ 67 struct hda_pcm pcm_rec[2]; /* PCM information */
68 68
69 /* pin deafault configuration */ 69 /* pin default configuration */
70 hda_nid_t pin_nid[NUM_PINS]; 70 hda_nid_t pin_nid[NUM_PINS];
71 unsigned int def_conf[NUM_PINS]; 71 unsigned int def_conf[NUM_PINS];
72 unsigned int pin_def_confs; 72 unsigned int pin_def_confs;
@@ -197,8 +197,8 @@ static struct snd_kcontrol_new cmi9880_basic_mixer[] = {
197 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT), 197 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT),
198 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT), 198 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT),
199 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT), 199 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT),
200 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x23, 0, HDA_OUTPUT), 200 HDA_CODEC_VOLUME("Beep Playback Volume", 0x23, 0, HDA_OUTPUT),
201 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x23, 0, HDA_OUTPUT), 201 HDA_CODEC_MUTE("Beep Playback Switch", 0x23, 0, HDA_OUTPUT),
202 { } /* end */ 202 { } /* end */
203}; 203};
204 204
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 905859d4f4df..a09c03c3f62b 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -397,9 +397,7 @@ static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
397 for (i = 0; i < spec->jacks.used; i++) { 397 for (i = 0; i < spec->jacks.used; i++) {
398 if (jacks->nid == nid) { 398 if (jacks->nid == nid) {
399 unsigned int present; 399 unsigned int present;
400 present = snd_hda_codec_read(codec, nid, 0, 400 present = snd_hda_jack_detect(codec, nid);
401 AC_VERB_GET_PIN_SENSE, 0) &
402 AC_PINSENSE_PRESENCE;
403 401
404 present = (present) ? jacks->type : 0 ; 402 present = (present) ? jacks->type : 0 ;
405 403
@@ -750,8 +748,7 @@ static void cxt5045_hp_automic(struct hda_codec *codec)
750 }; 748 };
751 unsigned int present; 749 unsigned int present;
752 750
753 present = snd_hda_codec_read(codec, 0x12, 0, 751 present = snd_hda_jack_detect(codec, 0x12);
754 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
755 if (present) 752 if (present)
756 snd_hda_sequence_write(codec, mic_jack_on); 753 snd_hda_sequence_write(codec, mic_jack_on);
757 else 754 else
@@ -765,8 +762,7 @@ static void cxt5045_hp_automute(struct hda_codec *codec)
765 struct conexant_spec *spec = codec->spec; 762 struct conexant_spec *spec = codec->spec;
766 unsigned int bits; 763 unsigned int bits;
767 764
768 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, 765 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
769 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
770 766
771 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 767 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
772 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 768 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
@@ -1175,9 +1171,10 @@ static int patch_cxt5045(struct hda_codec *codec)
1175 1171
1176 switch (codec->subsystem_id >> 16) { 1172 switch (codec->subsystem_id >> 16) {
1177 case 0x103c: 1173 case 0x103c:
1178 /* HP laptop has a really bad sound over 0dB on NID 0x17. 1174 case 0x1734:
1179 * Fix max PCM level to 0 dB 1175 /* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
1180 * (originall it has 0x2b steps with 0dB offset 0x14) 1176 * on NID 0x17. Fix max PCM level to 0 dB
1177 * (originally it has 0x2b steps with 0dB offset 0x14)
1181 */ 1178 */
1182 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 1179 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1183 (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 1180 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
@@ -1243,8 +1240,7 @@ static void cxt5047_hp_automute(struct hda_codec *codec)
1243 struct conexant_spec *spec = codec->spec; 1240 struct conexant_spec *spec = codec->spec;
1244 unsigned int bits; 1241 unsigned int bits;
1245 1242
1246 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, 1243 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1247 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1248 1244
1249 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 1245 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1250 /* See the note in cxt5047_hp_master_sw_put */ 1246 /* See the note in cxt5047_hp_master_sw_put */
@@ -1267,8 +1263,7 @@ static void cxt5047_hp_automic(struct hda_codec *codec)
1267 }; 1263 };
1268 unsigned int present; 1264 unsigned int present;
1269 1265
1270 present = snd_hda_codec_read(codec, 0x15, 0, 1266 present = snd_hda_jack_detect(codec, 0x15);
1271 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1272 if (present) 1267 if (present)
1273 snd_hda_sequence_write(codec, mic_jack_on); 1268 snd_hda_sequence_write(codec, mic_jack_on);
1274 else 1269 else
@@ -1415,16 +1410,7 @@ static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1415 .get = conexant_mux_enum_get, 1410 .get = conexant_mux_enum_get,
1416 .put = conexant_mux_enum_put, 1411 .put = conexant_mux_enum_put,
1417 }, 1412 },
1418 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 1413 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1420 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1421 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1422 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1423 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1425 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1426 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1427 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1428 1414
1429 { } /* end */ 1415 { } /* end */
1430}; 1416};
@@ -1621,9 +1607,7 @@ static void cxt5051_portb_automic(struct hda_codec *codec)
1621 1607
1622 if (spec->no_auto_mic) 1608 if (spec->no_auto_mic)
1623 return; 1609 return;
1624 present = snd_hda_codec_read(codec, 0x17, 0, 1610 present = snd_hda_jack_detect(codec, 0x17);
1625 AC_VERB_GET_PIN_SENSE, 0) &
1626 AC_PINSENSE_PRESENCE;
1627 snd_hda_codec_write(codec, 0x14, 0, 1611 snd_hda_codec_write(codec, 0x14, 0,
1628 AC_VERB_SET_CONNECT_SEL, 1612 AC_VERB_SET_CONNECT_SEL,
1629 present ? 0x01 : 0x00); 1613 present ? 0x01 : 0x00);
@@ -1638,9 +1622,7 @@ static void cxt5051_portc_automic(struct hda_codec *codec)
1638 1622
1639 if (spec->no_auto_mic) 1623 if (spec->no_auto_mic)
1640 return; 1624 return;
1641 present = snd_hda_codec_read(codec, 0x18, 0, 1625 present = snd_hda_jack_detect(codec, 0x18);
1642 AC_VERB_GET_PIN_SENSE, 0) &
1643 AC_PINSENSE_PRESENCE;
1644 if (present) 1626 if (present)
1645 spec->cur_adc_idx = 1; 1627 spec->cur_adc_idx = 1;
1646 else 1628 else
@@ -1661,9 +1643,7 @@ static void cxt5051_hp_automute(struct hda_codec *codec)
1661{ 1643{
1662 struct conexant_spec *spec = codec->spec; 1644 struct conexant_spec *spec = codec->spec;
1663 1645
1664 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0, 1646 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1665 AC_VERB_GET_PIN_SENSE, 0) &
1666 AC_PINSENSE_PRESENCE;
1667 cxt5051_update_speaker(codec); 1647 cxt5051_update_speaker(codec);
1668} 1648}
1669 1649
@@ -2011,8 +1991,47 @@ static void cxt5066_automic(struct hda_codec *codec)
2011 }; 1991 };
2012 unsigned int present; 1992 unsigned int present;
2013 1993
2014 present = snd_hda_codec_read(codec, 0x1a, 0, 1994 present = snd_hda_jack_detect(codec, 0x1a);
2015 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1995 if (present) {
1996 snd_printdd("CXT5066: external microphone detected\n");
1997 snd_hda_sequence_write(codec, ext_mic_present);
1998 } else {
1999 snd_printdd("CXT5066: external microphone absent\n");
2000 snd_hda_sequence_write(codec, ext_mic_absent);
2001 }
2002}
2003
2004/* toggle input of built-in digital mic and mic jack appropriately */
2005static void cxt5066_vostro_automic(struct hda_codec *codec)
2006{
2007 struct conexant_spec *spec = codec->spec;
2008 unsigned int present;
2009
2010 struct hda_verb ext_mic_present[] = {
2011 /* enable external mic, port B */
2012 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
2013
2014 /* switch to external mic input */
2015 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2016 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2017
2018 /* disable internal digital mic */
2019 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2020 {}
2021 };
2022 static struct hda_verb ext_mic_absent[] = {
2023 /* enable internal mic, port C */
2024 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2025
2026 /* switch to internal mic input */
2027 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2028
2029 /* disable external mic, port B */
2030 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2031 {}
2032 };
2033
2034 present = snd_hda_jack_detect(codec, 0x1a);
2016 if (present) { 2035 if (present) {
2017 snd_printdd("CXT5066: external microphone detected\n"); 2036 snd_printdd("CXT5066: external microphone detected\n");
2018 snd_hda_sequence_write(codec, ext_mic_present); 2037 snd_hda_sequence_write(codec, ext_mic_present);
@@ -2029,12 +2048,10 @@ static void cxt5066_hp_automute(struct hda_codec *codec)
2029 unsigned int portA, portD; 2048 unsigned int portA, portD;
2030 2049
2031 /* Port A */ 2050 /* Port A */
2032 portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0) 2051 portA = snd_hda_jack_detect(codec, 0x19);
2033 & AC_PINSENSE_PRESENCE;
2034 2052
2035 /* Port D */ 2053 /* Port D */
2036 portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) 2054 portD = snd_hda_jack_detect(codec, 0x1c);
2037 & AC_PINSENSE_PRESENCE) << 1;
2038 2055
2039 spec->hp_present = !!(portA | portD); 2056 spec->hp_present = !!(portA | portD);
2040 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 2057 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
@@ -2056,6 +2073,20 @@ static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2056 } 2073 }
2057} 2074}
2058 2075
2076/* unsolicited event for jack sensing */
2077static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2078{
2079 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2080 switch (res >> 26) {
2081 case CONEXANT_HP_EVENT:
2082 cxt5066_hp_automute(codec);
2083 break;
2084 case CONEXANT_MIC_EVENT:
2085 cxt5066_vostro_automic(codec);
2086 break;
2087 }
2088}
2089
2059static const struct hda_input_mux cxt5066_analog_mic_boost = { 2090static const struct hda_input_mux cxt5066_analog_mic_boost = {
2060 .num_items = 5, 2091 .num_items = 5,
2061 .items = { 2092 .items = {
@@ -2297,6 +2328,67 @@ static struct hda_verb cxt5066_init_verbs_olpc[] = {
2297 { } /* end */ 2328 { } /* end */
2298}; 2329};
2299 2330
2331static struct hda_verb cxt5066_init_verbs_vostro[] = {
2332 /* Port A: headphones */
2333 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2334 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2335
2336 /* Port B: external microphone */
2337 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2338
2339 /* Port C: unused */
2340 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2341
2342 /* Port D: unused */
2343 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2344
2345 /* Port E: unused, but has primary EAPD */
2346 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2347 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2348
2349 /* Port F: unused */
2350 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2351
2352 /* Port G: internal speakers */
2353 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2354 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2355
2356 /* DAC1 */
2357 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2358
2359 /* DAC2: unused */
2360 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2361
2362 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2363 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2364 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2365 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2366 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2367 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2368 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2369 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2370 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2371 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2372 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2373 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2374
2375 /* Digital microphone port */
2376 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2377
2378 /* Audio input selectors */
2379 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2380 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2381
2382 /* Disable SPDIF */
2383 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2384 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2385
2386 /* enable unsolicited events for Port A and B */
2387 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2388 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2389 { } /* end */
2390};
2391
2300static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 2392static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2301 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2393 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2302 { } /* end */ 2394 { } /* end */
@@ -2318,6 +2410,7 @@ enum {
2318 CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 2410 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2319 CXT5066_DELL_LAPTOP, /* Dell Laptop */ 2411 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2320 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 2412 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2413 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
2321 CXT5066_MODELS 2414 CXT5066_MODELS
2322}; 2415};
2323 2416
@@ -2325,6 +2418,7 @@ static const char *cxt5066_models[CXT5066_MODELS] = {
2325 [CXT5066_LAPTOP] = "laptop", 2418 [CXT5066_LAPTOP] = "laptop",
2326 [CXT5066_DELL_LAPTOP] = "dell-laptop", 2419 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2327 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 2420 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2421 [CXT5066_DELL_VOSTO] = "dell-vostro"
2328}; 2422};
2329 2423
2330static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 2424static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
@@ -2333,6 +2427,7 @@ static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2333 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 2427 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2334 CXT5066_DELL_LAPTOP), 2428 CXT5066_DELL_LAPTOP),
2335 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 2429 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2430 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
2336 {} 2431 {}
2337}; 2432};
2338 2433
@@ -2400,6 +2495,19 @@ static int patch_cxt5066(struct hda_codec *codec)
2400 /* input source automatically selected */ 2495 /* input source automatically selected */
2401 spec->input_mux = NULL; 2496 spec->input_mux = NULL;
2402 break; 2497 break;
2498 case CXT5066_DELL_VOSTO:
2499 codec->patch_ops.unsol_event = cxt5066_vostro_event;
2500 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2501 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2502 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2503 spec->port_d_mode = 0;
2504
2505 /* no S/PDIF out */
2506 spec->multiout.dig_out_nid = 0;
2507
2508 /* input source automatically selected */
2509 spec->input_mux = NULL;
2510 break;
2403 } 2511 }
2404 2512
2405 return 0; 2513 return 0;
@@ -2417,6 +2525,8 @@ static struct hda_codec_preset snd_hda_preset_conexant[] = {
2417 .patch = patch_cxt5051 }, 2525 .patch = patch_cxt5051 },
2418 { .id = 0x14f15066, .name = "CX20582 (Pebble)", 2526 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2419 .patch = patch_cxt5066 }, 2527 .patch = patch_cxt5066 },
2528 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
2529 .patch = patch_cxt5066 },
2420 {} /* terminator */ 2530 {} /* terminator */
2421}; 2531};
2422 2532
@@ -2424,6 +2534,7 @@ MODULE_ALIAS("snd-hda-codec-id:14f15045");
2424MODULE_ALIAS("snd-hda-codec-id:14f15047"); 2534MODULE_ALIAS("snd-hda-codec-id:14f15047");
2425MODULE_ALIAS("snd-hda-codec-id:14f15051"); 2535MODULE_ALIAS("snd-hda-codec-id:14f15051");
2426MODULE_ALIAS("snd-hda-codec-id:14f15066"); 2536MODULE_ALIAS("snd-hda-codec-id:14f15066");
2537MODULE_ALIAS("snd-hda-codec-id:14f15067");
2427 2538
2428MODULE_LICENSE("GPL"); 2539MODULE_LICENSE("GPL");
2429MODULE_DESCRIPTION("Conexant HD-audio codec"); 2540MODULE_DESCRIPTION("Conexant HD-audio codec");
diff --git a/sound/pci/hda/patch_intelhdmi.c b/sound/pci/hda/patch_intelhdmi.c
index 01a18ed475ac..928df59be5d8 100644
--- a/sound/pci/hda/patch_intelhdmi.c
+++ b/sound/pci/hda/patch_intelhdmi.c
@@ -33,15 +33,41 @@
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35 35
36static hda_nid_t cvt_nid; /* audio converter */ 36/*
37static hda_nid_t pin_nid; /* HDMI output pin */ 37 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
38 * could support two independent pipes, each of them can be connected to one or
39 * more ports (DVI, HDMI or DisplayPort).
40 *
41 * The HDA correspondence of pipes/ports are converter/pin nodes.
42 */
43#define INTEL_HDMI_CVTS 2
44#define INTEL_HDMI_PINS 3
38 45
39#define INTEL_HDMI_EVENT_TAG 0x08 46static char *intel_hdmi_pcm_names[INTEL_HDMI_CVTS] = {
47 "INTEL HDMI 0",
48 "INTEL HDMI 1",
49};
40 50
41struct intel_hdmi_spec { 51struct intel_hdmi_spec {
42 struct hda_multi_out multiout; 52 int num_cvts;
43 struct hda_pcm pcm_rec; 53 int num_pins;
44 struct hdmi_eld sink_eld; 54 hda_nid_t cvt[INTEL_HDMI_CVTS+1]; /* audio sources */
55 hda_nid_t pin[INTEL_HDMI_PINS+1]; /* audio sinks */
56
57 /*
58 * source connection for each pin
59 */
60 hda_nid_t pin_cvt[INTEL_HDMI_PINS+1];
61
62 /*
63 * HDMI sink attached to each pin
64 */
65 struct hdmi_eld sink_eld[INTEL_HDMI_PINS];
66
67 /*
68 * export one pcm per pipe
69 */
70 struct hda_pcm pcm_rec[INTEL_HDMI_CVTS];
45}; 71};
46 72
47struct hdmi_audio_infoframe { 73struct hdmi_audio_infoframe {
@@ -184,40 +210,186 @@ static struct cea_channel_speaker_allocation channel_allocations[] = {
184{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } }, 210{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
185}; 211};
186 212
213
214/*
215 * HDA/HDMI auto parsing
216 */
217
218static int hda_node_index(hda_nid_t *nids, hda_nid_t nid)
219{
220 int i;
221
222 for (i = 0; nids[i]; i++)
223 if (nids[i] == nid)
224 return i;
225
226 snd_printk(KERN_WARNING "HDMI: nid %d not registered\n", nid);
227 return -EINVAL;
228}
229
230static int intel_hdmi_read_pin_conn(struct hda_codec *codec, hda_nid_t pin_nid)
231{
232 struct intel_hdmi_spec *spec = codec->spec;
233 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
234 int conn_len, curr;
235 int index;
236
237 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
238 snd_printk(KERN_WARNING
239 "HDMI: pin %d wcaps %#x "
240 "does not support connection list\n",
241 pin_nid, get_wcaps(codec, pin_nid));
242 return -EINVAL;
243 }
244
245 conn_len = snd_hda_get_connections(codec, pin_nid, conn_list,
246 HDA_MAX_CONNECTIONS);
247 if (conn_len > 1)
248 curr = snd_hda_codec_read(codec, pin_nid, 0,
249 AC_VERB_GET_CONNECT_SEL, 0);
250 else
251 curr = 0;
252
253 index = hda_node_index(spec->pin, pin_nid);
254 if (index < 0)
255 return -EINVAL;
256
257 spec->pin_cvt[index] = conn_list[curr];
258
259 return 0;
260}
261
262static void hdmi_get_show_eld(struct hda_codec *codec, hda_nid_t pin_nid,
263 struct hdmi_eld *eld)
264{
265 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
266 snd_hdmi_show_eld(eld);
267}
268
269static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
270 struct hdmi_eld *eld)
271{
272 int present = snd_hda_pin_sense(codec, pin_nid);
273
274 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
275 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
276
277 if (present & AC_PINSENSE_ELDV)
278 hdmi_get_show_eld(codec, pin_nid, eld);
279}
280
281static int intel_hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
282{
283 struct intel_hdmi_spec *spec = codec->spec;
284
285 if (spec->num_pins >= INTEL_HDMI_PINS) {
286 snd_printk(KERN_WARNING
287 "HDMI: no space for pin %d \n", pin_nid);
288 return -EINVAL;
289 }
290
291 hdmi_present_sense(codec, pin_nid, &spec->sink_eld[spec->num_pins]);
292
293 spec->pin[spec->num_pins] = pin_nid;
294 spec->num_pins++;
295
296 /*
297 * It is assumed that converter nodes come first in the node list and
298 * hence have been registered and usable now.
299 */
300 return intel_hdmi_read_pin_conn(codec, pin_nid);
301}
302
303static int intel_hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid)
304{
305 struct intel_hdmi_spec *spec = codec->spec;
306
307 if (spec->num_cvts >= INTEL_HDMI_CVTS) {
308 snd_printk(KERN_WARNING
309 "HDMI: no space for converter %d \n", nid);
310 return -EINVAL;
311 }
312
313 spec->cvt[spec->num_cvts] = nid;
314 spec->num_cvts++;
315
316 return 0;
317}
318
319static int intel_hdmi_parse_codec(struct hda_codec *codec)
320{
321 hda_nid_t nid;
322 int i, nodes;
323
324 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
325 if (!nid || nodes < 0) {
326 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
327 return -EINVAL;
328 }
329
330 for (i = 0; i < nodes; i++, nid++) {
331 unsigned int caps;
332 unsigned int type;
333
334 caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
335 type = get_wcaps_type(caps);
336
337 if (!(caps & AC_WCAP_DIGITAL))
338 continue;
339
340 switch (type) {
341 case AC_WID_AUD_OUT:
342 if (intel_hdmi_add_cvt(codec, nid) < 0)
343 return -EINVAL;
344 break;
345 case AC_WID_PIN:
346 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
347 if (!(caps & AC_PINCAP_HDMI))
348 continue;
349 if (intel_hdmi_add_pin(codec, nid) < 0)
350 return -EINVAL;
351 break;
352 }
353 }
354
355 return 0;
356}
357
187/* 358/*
188 * HDMI routines 359 * HDMI routines
189 */ 360 */
190 361
191#ifdef BE_PARANOID 362#ifdef BE_PARANOID
192static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t nid, 363static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
193 int *packet_index, int *byte_index) 364 int *packet_index, int *byte_index)
194{ 365{
195 int val; 366 int val;
196 367
197 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_INDEX, 0); 368 val = snd_hda_codec_read(codec, pin_nid, 0,
369 AC_VERB_GET_HDMI_DIP_INDEX, 0);
198 370
199 *packet_index = val >> 5; 371 *packet_index = val >> 5;
200 *byte_index = val & 0x1f; 372 *byte_index = val & 0x1f;
201} 373}
202#endif 374#endif
203 375
204static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t nid, 376static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
205 int packet_index, int byte_index) 377 int packet_index, int byte_index)
206{ 378{
207 int val; 379 int val;
208 380
209 val = (packet_index << 5) | (byte_index & 0x1f); 381 val = (packet_index << 5) | (byte_index & 0x1f);
210 382
211 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); 383 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
212} 384}
213 385
214static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t nid, 386static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
215 unsigned char val) 387 unsigned char val)
216{ 388{
217 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); 389 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
218} 390}
219 391
220static void hdmi_enable_output(struct hda_codec *codec) 392static void hdmi_enable_output(struct hda_codec *codec, hda_nid_t pin_nid)
221{ 393{
222 /* Unmute */ 394 /* Unmute */
223 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) 395 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
@@ -231,7 +403,8 @@ static void hdmi_enable_output(struct hda_codec *codec)
231/* 403/*
232 * Enable Audio InfoFrame Transmission 404 * Enable Audio InfoFrame Transmission
233 */ 405 */
234static void hdmi_start_infoframe_trans(struct hda_codec *codec) 406static void hdmi_start_infoframe_trans(struct hda_codec *codec,
407 hda_nid_t pin_nid)
235{ 408{
236 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 409 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
237 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 410 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
@@ -241,59 +414,49 @@ static void hdmi_start_infoframe_trans(struct hda_codec *codec)
241/* 414/*
242 * Disable Audio InfoFrame Transmission 415 * Disable Audio InfoFrame Transmission
243 */ 416 */
244static void hdmi_stop_infoframe_trans(struct hda_codec *codec) 417static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
418 hda_nid_t pin_nid)
245{ 419{
246 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 420 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
247 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 421 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
248 AC_DIPXMIT_DISABLE); 422 AC_DIPXMIT_DISABLE);
249} 423}
250 424
251static int hdmi_get_channel_count(struct hda_codec *codec) 425static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t nid)
252{ 426{
253 return 1 + snd_hda_codec_read(codec, cvt_nid, 0, 427 return 1 + snd_hda_codec_read(codec, nid, 0,
254 AC_VERB_GET_CVT_CHAN_COUNT, 0); 428 AC_VERB_GET_CVT_CHAN_COUNT, 0);
255} 429}
256 430
257static void hdmi_set_channel_count(struct hda_codec *codec, int chs) 431static void hdmi_set_channel_count(struct hda_codec *codec,
432 hda_nid_t nid, int chs)
258{ 433{
259 snd_hda_codec_write(codec, cvt_nid, 0, 434 if (chs != hdmi_get_channel_count(codec, nid))
260 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); 435 snd_hda_codec_write(codec, nid, 0,
261 436 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
262 if (chs != hdmi_get_channel_count(codec))
263 snd_printd(KERN_INFO "HDMI channel count: expect %d, get %d\n",
264 chs, hdmi_get_channel_count(codec));
265} 437}
266 438
267static void hdmi_debug_channel_mapping(struct hda_codec *codec) 439static void hdmi_debug_channel_mapping(struct hda_codec *codec, hda_nid_t nid)
268{ 440{
269#ifdef CONFIG_SND_DEBUG_VERBOSE 441#ifdef CONFIG_SND_DEBUG_VERBOSE
270 int i; 442 int i;
271 int slot; 443 int slot;
272 444
273 for (i = 0; i < 8; i++) { 445 for (i = 0; i < 8; i++) {
274 slot = snd_hda_codec_read(codec, cvt_nid, 0, 446 slot = snd_hda_codec_read(codec, nid, 0,
275 AC_VERB_GET_HDMI_CHAN_SLOT, i); 447 AC_VERB_GET_HDMI_CHAN_SLOT, i);
276 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", 448 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
277 slot >> 4, slot & 0x7); 449 slot >> 4, slot & 0xf);
278 } 450 }
279#endif 451#endif
280} 452}
281 453
282static void hdmi_parse_eld(struct hda_codec *codec)
283{
284 struct intel_hdmi_spec *spec = codec->spec;
285 struct hdmi_eld *eld = &spec->sink_eld;
286
287 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
288 snd_hdmi_show_eld(eld);
289}
290
291 454
292/* 455/*
293 * Audio InfoFrame routines 456 * Audio InfoFrame routines
294 */ 457 */
295 458
296static void hdmi_debug_dip_size(struct hda_codec *codec) 459static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
297{ 460{
298#ifdef CONFIG_SND_DEBUG_VERBOSE 461#ifdef CONFIG_SND_DEBUG_VERBOSE
299 int i; 462 int i;
@@ -310,7 +473,7 @@ static void hdmi_debug_dip_size(struct hda_codec *codec)
310#endif 473#endif
311} 474}
312 475
313static void hdmi_clear_dip_buffers(struct hda_codec *codec) 476static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
314{ 477{
315#ifdef BE_PARANOID 478#ifdef BE_PARANOID
316 int i, j; 479 int i, j;
@@ -339,23 +502,35 @@ static void hdmi_clear_dip_buffers(struct hda_codec *codec)
339#endif 502#endif
340} 503}
341 504
342static void hdmi_fill_audio_infoframe(struct hda_codec *codec, 505static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *ai)
343 struct hdmi_audio_infoframe *ai)
344{ 506{
345 u8 *params = (u8 *)ai; 507 u8 *bytes = (u8 *)ai;
346 u8 sum = 0; 508 u8 sum = 0;
347 int i; 509 int i;
348 510
349 hdmi_debug_dip_size(codec); 511 ai->checksum = 0;
350 hdmi_clear_dip_buffers(codec); /* be paranoid */ 512
513 for (i = 0; i < sizeof(*ai); i++)
514 sum += bytes[i];
351 515
352 for (i = 0; i < sizeof(ai); i++)
353 sum += params[i];
354 ai->checksum = - sum; 516 ai->checksum = - sum;
517}
518
519static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
520 hda_nid_t pin_nid,
521 struct hdmi_audio_infoframe *ai)
522{
523 u8 *bytes = (u8 *)ai;
524 int i;
525
526 hdmi_debug_dip_size(codec, pin_nid);
527 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
528
529 hdmi_checksum_audio_infoframe(ai);
355 530
356 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 531 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
357 for (i = 0; i < sizeof(ai); i++) 532 for (i = 0; i < sizeof(*ai); i++)
358 hdmi_write_dip_byte(codec, pin_nid, params[i]); 533 hdmi_write_dip_byte(codec, pin_nid, bytes[i]);
359} 534}
360 535
361/* 536/*
@@ -386,11 +561,11 @@ static void init_channel_allocations(void)
386 * 561 *
387 * TODO: it could select the wrong CA from multiple candidates. 562 * TODO: it could select the wrong CA from multiple candidates.
388*/ 563*/
389static int hdmi_setup_channel_allocation(struct hda_codec *codec, 564static int hdmi_setup_channel_allocation(struct hda_codec *codec, hda_nid_t nid,
390 struct hdmi_audio_infoframe *ai) 565 struct hdmi_audio_infoframe *ai)
391{ 566{
392 struct intel_hdmi_spec *spec = codec->spec; 567 struct intel_hdmi_spec *spec = codec->spec;
393 struct hdmi_eld *eld = &spec->sink_eld; 568 struct hdmi_eld *eld;
394 int i; 569 int i;
395 int spk_mask = 0; 570 int spk_mask = 0;
396 int channels = 1 + (ai->CC02_CT47 & 0x7); 571 int channels = 1 + (ai->CC02_CT47 & 0x7);
@@ -402,6 +577,11 @@ static int hdmi_setup_channel_allocation(struct hda_codec *codec,
402 if (channels <= 2) 577 if (channels <= 2)
403 return 0; 578 return 0;
404 579
580 i = hda_node_index(spec->pin_cvt, nid);
581 if (i < 0)
582 return 0;
583 eld = &spec->sink_eld[i];
584
405 /* 585 /*
406 * HDMI sink's ELD info cannot always be retrieved for now, e.g. 586 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
407 * in console or for audio devices. Assume the highest speakers 587 * in console or for audio devices. Assume the highest speakers
@@ -439,8 +619,8 @@ static int hdmi_setup_channel_allocation(struct hda_codec *codec,
439 return ai->CA; 619 return ai->CA;
440} 620}
441 621
442static void hdmi_setup_channel_mapping(struct hda_codec *codec, 622static void hdmi_setup_channel_mapping(struct hda_codec *codec, hda_nid_t nid,
443 struct hdmi_audio_infoframe *ai) 623 struct hdmi_audio_infoframe *ai)
444{ 624{
445 int i; 625 int i;
446 626
@@ -453,17 +633,41 @@ static void hdmi_setup_channel_mapping(struct hda_codec *codec,
453 */ 633 */
454 634
455 for (i = 0; i < 8; i++) 635 for (i = 0; i < 8; i++)
456 snd_hda_codec_write(codec, cvt_nid, 0, 636 snd_hda_codec_write(codec, nid, 0,
457 AC_VERB_SET_HDMI_CHAN_SLOT, 637 AC_VERB_SET_HDMI_CHAN_SLOT,
458 (i << 4) | i); 638 (i << 4) | i);
459 639
460 hdmi_debug_channel_mapping(codec); 640 hdmi_debug_channel_mapping(codec, nid);
461} 641}
462 642
643static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
644 struct hdmi_audio_infoframe *ai)
645{
646 u8 *bytes = (u8 *)ai;
647 u8 val;
648 int i;
649
650 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
651 != AC_DIPXMIT_BEST)
652 return false;
653
654 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
655 for (i = 0; i < sizeof(*ai); i++) {
656 val = snd_hda_codec_read(codec, pin_nid, 0,
657 AC_VERB_GET_HDMI_DIP_DATA, 0);
658 if (val != bytes[i])
659 return false;
660 }
463 661
464static void hdmi_setup_audio_infoframe(struct hda_codec *codec, 662 return true;
663}
664
665static void hdmi_setup_audio_infoframe(struct hda_codec *codec, hda_nid_t nid,
465 struct snd_pcm_substream *substream) 666 struct snd_pcm_substream *substream)
466{ 667{
668 struct intel_hdmi_spec *spec = codec->spec;
669 hda_nid_t pin_nid;
670 int i;
467 struct hdmi_audio_infoframe ai = { 671 struct hdmi_audio_infoframe ai = {
468 .type = 0x84, 672 .type = 0x84,
469 .ver = 0x01, 673 .ver = 0x01,
@@ -471,11 +675,22 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
471 .CC02_CT47 = substream->runtime->channels - 1, 675 .CC02_CT47 = substream->runtime->channels - 1,
472 }; 676 };
473 677
474 hdmi_setup_channel_allocation(codec, &ai); 678 hdmi_setup_channel_allocation(codec, nid, &ai);
475 hdmi_setup_channel_mapping(codec, &ai); 679 hdmi_setup_channel_mapping(codec, nid, &ai);
476 680
477 hdmi_fill_audio_infoframe(codec, &ai); 681 for (i = 0; i < spec->num_pins; i++) {
478 hdmi_start_infoframe_trans(codec); 682 if (spec->pin_cvt[i] != nid)
683 continue;
684 if (!spec->sink_eld[i].monitor_present)
685 continue;
686
687 pin_nid = spec->pin[i];
688 if (!hdmi_infoframe_uptodate(codec, pin_nid, &ai)) {
689 hdmi_stop_infoframe_trans(codec, pin_nid);
690 hdmi_fill_audio_infoframe(codec, pin_nid, &ai);
691 hdmi_start_infoframe_trans(codec, pin_nid);
692 }
693 }
479} 694}
480 695
481 696
@@ -485,27 +700,39 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
485 700
486static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) 701static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
487{ 702{
703 struct intel_hdmi_spec *spec = codec->spec;
704 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
488 int pind = !!(res & AC_UNSOL_RES_PD); 705 int pind = !!(res & AC_UNSOL_RES_PD);
489 int eldv = !!(res & AC_UNSOL_RES_ELDV); 706 int eldv = !!(res & AC_UNSOL_RES_ELDV);
707 int index;
490 708
491 printk(KERN_INFO 709 printk(KERN_INFO
492 "HDMI hot plug event: Presence_Detect=%d ELD_Valid=%d\n", 710 "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
493 pind, eldv); 711 tag, pind, eldv);
712
713 index = hda_node_index(spec->pin, tag);
714 if (index < 0)
715 return;
716
717 spec->sink_eld[index].monitor_present = pind;
718 spec->sink_eld[index].eld_valid = eldv;
494 719
495 if (pind && eldv) { 720 if (pind && eldv) {
496 hdmi_parse_eld(codec); 721 hdmi_get_show_eld(codec, spec->pin[index], &spec->sink_eld[index]);
497 /* TODO: do real things about ELD */ 722 /* TODO: do real things about ELD */
498 } 723 }
499} 724}
500 725
501static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 726static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
502{ 727{
728 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
503 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 729 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
504 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); 730 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
505 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); 731 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
506 732
507 printk(KERN_INFO 733 printk(KERN_INFO
508 "HDMI content protection event: SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", 734 "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
735 tag,
509 subtag, 736 subtag,
510 cp_state, 737 cp_state,
511 cp_ready); 738 cp_ready);
@@ -520,10 +747,11 @@ static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
520 747
521static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res) 748static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
522{ 749{
750 struct intel_hdmi_spec *spec = codec->spec;
523 int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 751 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
524 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 752 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
525 753
526 if (tag != INTEL_HDMI_EVENT_TAG) { 754 if (hda_node_index(spec->pin, tag) < 0) {
527 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag); 755 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
528 return; 756 return;
529 } 757 }
@@ -538,24 +766,29 @@ static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
538 * Callbacks 766 * Callbacks
539 */ 767 */
540 768
541static int intel_hdmi_playback_pcm_open(struct hda_pcm_stream *hinfo, 769static void hdmi_setup_stream(struct hda_codec *codec, hda_nid_t nid,
542 struct hda_codec *codec, 770 u32 stream_tag, int format)
543 struct snd_pcm_substream *substream)
544{ 771{
545 struct intel_hdmi_spec *spec = codec->spec; 772 int tag;
546 773 int fmt;
547 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
548}
549 774
550static int intel_hdmi_playback_pcm_close(struct hda_pcm_stream *hinfo, 775 tag = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0) >> 4;
551 struct hda_codec *codec, 776 fmt = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_STREAM_FORMAT, 0);
552 struct snd_pcm_substream *substream)
553{
554 struct intel_hdmi_spec *spec = codec->spec;
555 777
556 hdmi_stop_infoframe_trans(codec); 778 snd_printdd("hdmi_setup_stream: "
779 "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n",
780 nid,
781 tag == stream_tag ? "" : "new-",
782 stream_tag,
783 fmt == format ? "" : "new-",
784 format);
557 785
558 return snd_hda_multi_out_dig_close(codec, &spec->multiout); 786 if (tag != stream_tag)
787 snd_hda_codec_write(codec, nid, 0,
788 AC_VERB_SET_CHANNEL_STREAMID, stream_tag << 4);
789 if (fmt != format)
790 snd_hda_codec_write(codec, nid, 0,
791 AC_VERB_SET_STREAM_FORMAT, format);
559} 792}
560 793
561static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 794static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -564,43 +797,53 @@ static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
564 unsigned int format, 797 unsigned int format,
565 struct snd_pcm_substream *substream) 798 struct snd_pcm_substream *substream)
566{ 799{
567 struct intel_hdmi_spec *spec = codec->spec; 800 hdmi_set_channel_count(codec, hinfo->nid,
568 801 substream->runtime->channels);
569 snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
570 format, substream);
571 802
572 hdmi_set_channel_count(codec, substream->runtime->channels); 803 hdmi_setup_audio_infoframe(codec, hinfo->nid, substream);
573 804
574 hdmi_setup_audio_infoframe(codec, substream); 805 hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
806 return 0;
807}
575 808
809static int intel_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
810 struct hda_codec *codec,
811 struct snd_pcm_substream *substream)
812{
576 return 0; 813 return 0;
577} 814}
578 815
579static struct hda_pcm_stream intel_hdmi_pcm_playback = { 816static struct hda_pcm_stream intel_hdmi_pcm_playback = {
580 .substreams = 1, 817 .substreams = 1,
581 .channels_min = 2, 818 .channels_min = 2,
582 .channels_max = 8,
583 .ops = { 819 .ops = {
584 .open = intel_hdmi_playback_pcm_open, 820 .prepare = intel_hdmi_playback_pcm_prepare,
585 .close = intel_hdmi_playback_pcm_close, 821 .cleanup = intel_hdmi_playback_pcm_cleanup,
586 .prepare = intel_hdmi_playback_pcm_prepare
587 }, 822 },
588}; 823};
589 824
590static int intel_hdmi_build_pcms(struct hda_codec *codec) 825static int intel_hdmi_build_pcms(struct hda_codec *codec)
591{ 826{
592 struct intel_hdmi_spec *spec = codec->spec; 827 struct intel_hdmi_spec *spec = codec->spec;
593 struct hda_pcm *info = &spec->pcm_rec; 828 struct hda_pcm *info = spec->pcm_rec;
829 int i;
594 830
595 codec->num_pcms = 1; 831 codec->num_pcms = spec->num_cvts;
596 codec->pcm_info = info; 832 codec->pcm_info = info;
597 833
598 /* NID to query formats and rates and setup streams */ 834 for (i = 0; i < codec->num_pcms; i++, info++) {
599 intel_hdmi_pcm_playback.nid = cvt_nid; 835 unsigned int chans;
600 836
601 info->name = "INTEL HDMI"; 837 chans = get_wcaps(codec, spec->cvt[i]);
602 info->pcm_type = HDA_PCM_TYPE_HDMI; 838 chans = get_wcaps_channels(chans);
603 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = intel_hdmi_pcm_playback; 839
840 info->name = intel_hdmi_pcm_names[i];
841 info->pcm_type = HDA_PCM_TYPE_HDMI;
842 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
843 intel_hdmi_pcm_playback;
844 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i];
845 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
846 }
604 847
605 return 0; 848 return 0;
606} 849}
@@ -609,29 +852,39 @@ static int intel_hdmi_build_controls(struct hda_codec *codec)
609{ 852{
610 struct intel_hdmi_spec *spec = codec->spec; 853 struct intel_hdmi_spec *spec = codec->spec;
611 int err; 854 int err;
855 int i;
612 856
613 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 857 for (i = 0; i < codec->num_pcms; i++) {
614 if (err < 0) 858 err = snd_hda_create_spdif_out_ctls(codec, spec->cvt[i]);
615 return err; 859 if (err < 0)
860 return err;
861 }
616 862
617 return 0; 863 return 0;
618} 864}
619 865
620static int intel_hdmi_init(struct hda_codec *codec) 866static int intel_hdmi_init(struct hda_codec *codec)
621{ 867{
622 hdmi_enable_output(codec); 868 struct intel_hdmi_spec *spec = codec->spec;
869 int i;
623 870
624 snd_hda_codec_write(codec, pin_nid, 0, 871 for (i = 0; spec->pin[i]; i++) {
625 AC_VERB_SET_UNSOLICITED_ENABLE, 872 hdmi_enable_output(codec, spec->pin[i]);
626 AC_USRSP_EN | INTEL_HDMI_EVENT_TAG); 873 snd_hda_codec_write(codec, spec->pin[i], 0,
874 AC_VERB_SET_UNSOLICITED_ENABLE,
875 AC_USRSP_EN | spec->pin[i]);
876 }
627 return 0; 877 return 0;
628} 878}
629 879
630static void intel_hdmi_free(struct hda_codec *codec) 880static void intel_hdmi_free(struct hda_codec *codec)
631{ 881{
632 struct intel_hdmi_spec *spec = codec->spec; 882 struct intel_hdmi_spec *spec = codec->spec;
883 int i;
884
885 for (i = 0; i < spec->num_pins; i++)
886 snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
633 887
634 snd_hda_eld_proc_free(codec, &spec->sink_eld);
635 kfree(spec); 888 kfree(spec);
636} 889}
637 890
@@ -643,49 +896,38 @@ static struct hda_codec_ops intel_hdmi_patch_ops = {
643 .unsol_event = intel_hdmi_unsol_event, 896 .unsol_event = intel_hdmi_unsol_event,
644}; 897};
645 898
646static int do_patch_intel_hdmi(struct hda_codec *codec) 899static int patch_intel_hdmi(struct hda_codec *codec)
647{ 900{
648 struct intel_hdmi_spec *spec; 901 struct intel_hdmi_spec *spec;
902 int i;
649 903
650 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 904 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
651 if (spec == NULL) 905 if (spec == NULL)
652 return -ENOMEM; 906 return -ENOMEM;
653 907
654 spec->multiout.num_dacs = 0; /* no analog */
655 spec->multiout.max_channels = 8;
656 spec->multiout.dig_out_nid = cvt_nid;
657
658 codec->spec = spec; 908 codec->spec = spec;
909 if (intel_hdmi_parse_codec(codec) < 0) {
910 codec->spec = NULL;
911 kfree(spec);
912 return -EINVAL;
913 }
659 codec->patch_ops = intel_hdmi_patch_ops; 914 codec->patch_ops = intel_hdmi_patch_ops;
660 915
661 snd_hda_eld_proc_new(codec, &spec->sink_eld); 916 for (i = 0; i < spec->num_pins; i++)
917 snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
662 918
663 init_channel_allocations(); 919 init_channel_allocations();
664 920
665 return 0; 921 return 0;
666} 922}
667 923
668static int patch_intel_hdmi(struct hda_codec *codec)
669{
670 cvt_nid = 0x02;
671 pin_nid = 0x03;
672 return do_patch_intel_hdmi(codec);
673}
674
675static int patch_intel_hdmi_ibexpeak(struct hda_codec *codec)
676{
677 cvt_nid = 0x02;
678 pin_nid = 0x04;
679 return do_patch_intel_hdmi(codec);
680}
681
682static struct hda_codec_preset snd_hda_preset_intelhdmi[] = { 924static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
683 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi }, 925 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi },
684 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi }, 926 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi },
685 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi }, 927 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi },
686 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi }, 928 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi },
687 { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi }, 929 { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi },
688 { .id = 0x80860054, .name = "Q57 DEVIBX", .patch = patch_intel_hdmi_ibexpeak }, 930 { .id = 0x80860054, .name = "Q57 DEVIBX", .patch = patch_intel_hdmi },
689 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi }, 931 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
690 {} /* terminator */ 932 {} /* terminator */
691}; 933};
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 70583719282b..db4a7367b625 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -961,18 +961,12 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
961static void alc_automute_pin(struct hda_codec *codec) 961static void alc_automute_pin(struct hda_codec *codec)
962{ 962{
963 struct alc_spec *spec = codec->spec; 963 struct alc_spec *spec = codec->spec;
964 unsigned int present, pincap;
965 unsigned int nid = spec->autocfg.hp_pins[0]; 964 unsigned int nid = spec->autocfg.hp_pins[0];
966 int i; 965 int i;
967 966
968 if (!nid) 967 if (!nid)
969 return; 968 return;
970 pincap = snd_hda_query_pin_caps(codec, nid); 969 spec->jack_present = snd_hda_jack_detect(codec, nid);
971 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
972 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
973 present = snd_hda_codec_read(codec, nid, 0,
974 AC_VERB_GET_PIN_SENSE, 0);
975 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
976 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) { 970 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
977 nid = spec->autocfg.speaker_pins[i]; 971 nid = spec->autocfg.speaker_pins[i];
978 if (!nid) 972 if (!nid)
@@ -1012,9 +1006,7 @@ static void alc_mic_automute(struct hda_codec *codec)
1012 1006
1013 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0]; 1007 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1014 1008
1015 present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0, 1009 present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1016 AC_VERB_GET_PIN_SENSE, 0);
1017 present &= AC_PINSENSE_PRESENCE;
1018 if (present) { 1010 if (present) {
1019 alive = &spec->ext_mic; 1011 alive = &spec->ext_mic;
1020 dead = &spec->int_mic; 1012 dead = &spec->int_mic;
@@ -1402,6 +1394,17 @@ static void alc_pick_fixup(struct hda_codec *codec,
1402 add_verb(codec->spec, fix->verbs); 1394 add_verb(codec->spec, fix->verbs);
1403} 1395}
1404 1396
1397static int alc_read_coef_idx(struct hda_codec *codec,
1398 unsigned int coef_idx)
1399{
1400 unsigned int val;
1401 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1402 coef_idx);
1403 val = snd_hda_codec_read(codec, 0x20, 0,
1404 AC_VERB_GET_PROC_COEF, 0);
1405 return val;
1406}
1407
1405/* 1408/*
1406 * ALC888 1409 * ALC888
1407 */ 1410 */
@@ -1513,7 +1516,7 @@ static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1513static void alc_automute_amp(struct hda_codec *codec) 1516static void alc_automute_amp(struct hda_codec *codec)
1514{ 1517{
1515 struct alc_spec *spec = codec->spec; 1518 struct alc_spec *spec = codec->spec;
1516 unsigned int val, mute, pincap; 1519 unsigned int mute;
1517 hda_nid_t nid; 1520 hda_nid_t nid;
1518 int i; 1521 int i;
1519 1522
@@ -1522,13 +1525,7 @@ static void alc_automute_amp(struct hda_codec *codec)
1522 nid = spec->autocfg.hp_pins[i]; 1525 nid = spec->autocfg.hp_pins[i];
1523 if (!nid) 1526 if (!nid)
1524 break; 1527 break;
1525 pincap = snd_hda_query_pin_caps(codec, nid); 1528 if (snd_hda_jack_detect(codec, nid)) {
1526 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1527 snd_hda_codec_read(codec, nid, 0,
1528 AC_VERB_SET_PIN_SENSE, 0);
1529 val = snd_hda_codec_read(codec, nid, 0,
1530 AC_VERB_GET_PIN_SENSE, 0);
1531 if (val & AC_PINSENSE_PRESENCE) {
1532 spec->jack_present = 1; 1529 spec->jack_present = 1;
1533 break; 1530 break;
1534 } 1531 }
@@ -1786,6 +1783,8 @@ static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1786 1783
1787 spec->autocfg.hp_pins[0] = 0x15; 1784 spec->autocfg.hp_pins[0] = 0x15;
1788 spec->autocfg.speaker_pins[0] = 0x14; 1785 spec->autocfg.speaker_pins[0] = 0x14;
1786 spec->autocfg.speaker_pins[1] = 0x16;
1787 spec->autocfg.speaker_pins[2] = 0x17;
1789} 1788}
1790 1789
1791static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec) 1790static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
@@ -2410,12 +2409,14 @@ static const char *alc_slave_sws[] = {
2410 2409
2411static void alc_free_kctls(struct hda_codec *codec); 2410static void alc_free_kctls(struct hda_codec *codec);
2412 2411
2412#ifdef CONFIG_SND_HDA_INPUT_BEEP
2413/* additional beep mixers; the actual parameters are overwritten at build */ 2413/* additional beep mixers; the actual parameters are overwritten at build */
2414static struct snd_kcontrol_new alc_beep_mixer[] = { 2414static struct snd_kcontrol_new alc_beep_mixer[] = {
2415 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), 2415 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2416 HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT), 2416 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2417 { } /* end */ 2417 { } /* end */
2418}; 2418};
2419#endif
2419 2420
2420static int alc_build_controls(struct hda_codec *codec) 2421static int alc_build_controls(struct hda_codec *codec)
2421{ 2422{
@@ -2452,6 +2453,7 @@ static int alc_build_controls(struct hda_codec *codec)
2452 return err; 2453 return err;
2453 } 2454 }
2454 2455
2456#ifdef CONFIG_SND_HDA_INPUT_BEEP
2455 /* create beep controls if needed */ 2457 /* create beep controls if needed */
2456 if (spec->beep_amp) { 2458 if (spec->beep_amp) {
2457 struct snd_kcontrol_new *knew; 2459 struct snd_kcontrol_new *knew;
@@ -2461,11 +2463,13 @@ static int alc_build_controls(struct hda_codec *codec)
2461 if (!kctl) 2463 if (!kctl)
2462 return -ENOMEM; 2464 return -ENOMEM;
2463 kctl->private_value = spec->beep_amp; 2465 kctl->private_value = spec->beep_amp;
2464 err = snd_hda_ctl_add(codec, kctl); 2466 err = snd_hda_ctl_add(codec,
2467 get_amp_nid_(spec->beep_amp), kctl);
2465 if (err < 0) 2468 if (err < 0)
2466 return err; 2469 return err;
2467 } 2470 }
2468 } 2471 }
2472#endif
2469 2473
2470 /* if we have no master control, let's create it */ 2474 /* if we have no master control, let's create it */
2471 if (!spec->no_analog && 2475 if (!spec->no_analog &&
@@ -2779,8 +2783,7 @@ static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2779 unsigned int present; 2783 unsigned int present;
2780 unsigned char bits; 2784 unsigned char bits;
2781 2785
2782 present = snd_hda_codec_read(codec, 0x18, 0, 2786 present = snd_hda_jack_detect(codec, 0x18);
2783 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2784 bits = present ? HDA_AMP_MUTE : 0; 2787 bits = present ? HDA_AMP_MUTE : 0;
2785 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); 2788 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2786} 2789}
@@ -3480,7 +3483,7 @@ static int alc_build_pcms(struct hda_codec *codec)
3480 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), 3483 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3481 "%s Analog", codec->chip_name); 3484 "%s Analog", codec->chip_name);
3482 info->name = spec->stream_name_analog; 3485 info->name = spec->stream_name_analog;
3483 3486
3484 if (spec->stream_analog_playback) { 3487 if (spec->stream_analog_playback) {
3485 if (snd_BUG_ON(!spec->multiout.dac_nids)) 3488 if (snd_BUG_ON(!spec->multiout.dac_nids))
3486 return -EINVAL; 3489 return -EINVAL;
@@ -4322,10 +4325,26 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
4322 knew->name = kstrdup(name, GFP_KERNEL); 4325 knew->name = kstrdup(name, GFP_KERNEL);
4323 if (!knew->name) 4326 if (!knew->name)
4324 return -ENOMEM; 4327 return -ENOMEM;
4328 if (get_amp_nid_(val))
4329 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
4325 knew->private_value = val; 4330 knew->private_value = val;
4326 return 0; 4331 return 0;
4327} 4332}
4328 4333
4334static int add_control_with_pfx(struct alc_spec *spec, int type,
4335 const char *pfx, const char *dir,
4336 const char *sfx, unsigned long val)
4337{
4338 char name[32];
4339 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4340 return add_control(spec, type, name, val);
4341}
4342
4343#define add_pb_vol_ctrl(spec, type, pfx, val) \
4344 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4345#define add_pb_sw_ctrl(spec, type, pfx, val) \
4346 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4347
4329#define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17) 4348#define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17)
4330#define alc880_fixed_pin_idx(nid) ((nid) - 0x14) 4349#define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
4331#define alc880_is_multi_pin(nid) ((nid) >= 0x18) 4350#define alc880_is_multi_pin(nid) ((nid) >= 0x18)
@@ -4379,7 +4398,6 @@ static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4379static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec, 4398static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4380 const struct auto_pin_cfg *cfg) 4399 const struct auto_pin_cfg *cfg)
4381{ 4400{
4382 char name[32];
4383 static const char *chname[4] = { 4401 static const char *chname[4] = {
4384 "Front", "Surround", NULL /*CLFE*/, "Side" 4402 "Front", "Surround", NULL /*CLFE*/, "Side"
4385 }; 4403 };
@@ -4392,26 +4410,26 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4392 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i])); 4410 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4393 if (i == 2) { 4411 if (i == 2) {
4394 /* Center/LFE */ 4412 /* Center/LFE */
4395 err = add_control(spec, ALC_CTL_WIDGET_VOL, 4413 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4396 "Center Playback Volume", 4414 "Center",
4397 HDA_COMPOSE_AMP_VAL(nid, 1, 0, 4415 HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4398 HDA_OUTPUT)); 4416 HDA_OUTPUT));
4399 if (err < 0) 4417 if (err < 0)
4400 return err; 4418 return err;
4401 err = add_control(spec, ALC_CTL_WIDGET_VOL, 4419 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4402 "LFE Playback Volume", 4420 "LFE",
4403 HDA_COMPOSE_AMP_VAL(nid, 2, 0, 4421 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4404 HDA_OUTPUT)); 4422 HDA_OUTPUT));
4405 if (err < 0) 4423 if (err < 0)
4406 return err; 4424 return err;
4407 err = add_control(spec, ALC_CTL_BIND_MUTE, 4425 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4408 "Center Playback Switch", 4426 "Center",
4409 HDA_COMPOSE_AMP_VAL(nid, 1, 2, 4427 HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4410 HDA_INPUT)); 4428 HDA_INPUT));
4411 if (err < 0) 4429 if (err < 0)
4412 return err; 4430 return err;
4413 err = add_control(spec, ALC_CTL_BIND_MUTE, 4431 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4414 "LFE Playback Switch", 4432 "LFE",
4415 HDA_COMPOSE_AMP_VAL(nid, 2, 2, 4433 HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4416 HDA_INPUT)); 4434 HDA_INPUT));
4417 if (err < 0) 4435 if (err < 0)
@@ -4423,14 +4441,12 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4423 pfx = "Speaker"; 4441 pfx = "Speaker";
4424 else 4442 else
4425 pfx = chname[i]; 4443 pfx = chname[i];
4426 sprintf(name, "%s Playback Volume", pfx); 4444 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4427 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4428 HDA_COMPOSE_AMP_VAL(nid, 3, 0, 4445 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4429 HDA_OUTPUT)); 4446 HDA_OUTPUT));
4430 if (err < 0) 4447 if (err < 0)
4431 return err; 4448 return err;
4432 sprintf(name, "%s Playback Switch", pfx); 4449 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4433 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4434 HDA_COMPOSE_AMP_VAL(nid, 3, 2, 4450 HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4435 HDA_INPUT)); 4451 HDA_INPUT));
4436 if (err < 0) 4452 if (err < 0)
@@ -4446,7 +4462,6 @@ static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4446{ 4462{
4447 hda_nid_t nid; 4463 hda_nid_t nid;
4448 int err; 4464 int err;
4449 char name[32];
4450 4465
4451 if (!pin) 4466 if (!pin)
4452 return 0; 4467 return 0;
@@ -4460,21 +4475,18 @@ static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4460 spec->multiout.extra_out_nid[0] = nid; 4475 spec->multiout.extra_out_nid[0] = nid;
4461 /* control HP volume/switch on the output mixer amp */ 4476 /* control HP volume/switch on the output mixer amp */
4462 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin)); 4477 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4463 sprintf(name, "%s Playback Volume", pfx); 4478 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4464 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4465 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT)); 4479 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4466 if (err < 0) 4480 if (err < 0)
4467 return err; 4481 return err;
4468 sprintf(name, "%s Playback Switch", pfx); 4482 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4469 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4470 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT)); 4483 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4471 if (err < 0) 4484 if (err < 0)
4472 return err; 4485 return err;
4473 } else if (alc880_is_multi_pin(pin)) { 4486 } else if (alc880_is_multi_pin(pin)) {
4474 /* set manual connection */ 4487 /* set manual connection */
4475 /* we have only a switch on HP-out PIN */ 4488 /* we have only a switch on HP-out PIN */
4476 sprintf(name, "%s Playback Switch", pfx); 4489 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4477 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4478 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 4490 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4479 if (err < 0) 4491 if (err < 0)
4480 return err; 4492 return err;
@@ -4487,16 +4499,13 @@ static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4487 const char *ctlname, 4499 const char *ctlname,
4488 int idx, hda_nid_t mix_nid) 4500 int idx, hda_nid_t mix_nid)
4489{ 4501{
4490 char name[32];
4491 int err; 4502 int err;
4492 4503
4493 sprintf(name, "%s Playback Volume", ctlname); 4504 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4494 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4495 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); 4505 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4496 if (err < 0) 4506 if (err < 0)
4497 return err; 4507 return err;
4498 sprintf(name, "%s Playback Switch", ctlname); 4508 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4499 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4500 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); 4509 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4501 if (err < 0) 4510 if (err < 0)
4502 return err; 4511 return err;
@@ -4773,8 +4782,12 @@ static void set_capture_mixer(struct hda_codec *codec)
4773 } 4782 }
4774} 4783}
4775 4784
4785#ifdef CONFIG_SND_HDA_INPUT_BEEP
4776#define set_beep_amp(spec, nid, idx, dir) \ 4786#define set_beep_amp(spec, nid, idx, dir) \
4777 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) 4787 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4788#else
4789#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4790#endif
4778 4791
4779/* 4792/*
4780 * OK, here we have finally the patch for ALC880 4793 * OK, here we have finally the patch for ALC880
@@ -5087,11 +5100,8 @@ static struct hda_verb alc260_hp_unsol_verbs[] = {
5087static void alc260_hp_automute(struct hda_codec *codec) 5100static void alc260_hp_automute(struct hda_codec *codec)
5088{ 5101{
5089 struct alc_spec *spec = codec->spec; 5102 struct alc_spec *spec = codec->spec;
5090 unsigned int present;
5091 5103
5092 present = snd_hda_codec_read(codec, 0x10, 0, 5104 spec->jack_present = snd_hda_jack_detect(codec, 0x10);
5093 AC_VERB_GET_PIN_SENSE, 0);
5094 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5095 alc260_hp_master_update(codec, 0x0f, 0x10, 0x11); 5105 alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5096} 5106}
5097 5107
@@ -5156,11 +5166,8 @@ static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5156static void alc260_hp_3013_automute(struct hda_codec *codec) 5166static void alc260_hp_3013_automute(struct hda_codec *codec)
5157{ 5167{
5158 struct alc_spec *spec = codec->spec; 5168 struct alc_spec *spec = codec->spec;
5159 unsigned int present;
5160 5169
5161 present = snd_hda_codec_read(codec, 0x15, 0, 5170 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
5162 AC_VERB_GET_PIN_SENSE, 0);
5163 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5164 alc260_hp_master_update(codec, 0x15, 0x10, 0x11); 5171 alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5165} 5172}
5166 5173
@@ -5173,12 +5180,8 @@ static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5173 5180
5174static void alc260_hp_3012_automute(struct hda_codec *codec) 5181static void alc260_hp_3012_automute(struct hda_codec *codec)
5175{ 5182{
5176 unsigned int present, bits; 5183 unsigned int bits = snd_hda_jack_detect(codec, 0x10) ? 0 : PIN_OUT;
5177
5178 present = snd_hda_codec_read(codec, 0x10, 0,
5179 AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5180 5184
5181 bits = present ? 0 : PIN_OUT;
5182 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 5185 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5183 bits); 5186 bits);
5184 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 5187 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
@@ -5748,8 +5751,7 @@ static void alc260_replacer_672v_automute(struct hda_codec *codec)
5748 unsigned int present; 5751 unsigned int present;
5749 5752
5750 /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */ 5753 /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5751 present = snd_hda_codec_read(codec, 0x0f, 0, 5754 present = snd_hda_jack_detect(codec, 0x0f);
5752 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5753 if (present) { 5755 if (present) {
5754 snd_hda_codec_write_cache(codec, 0x01, 0, 5756 snd_hda_codec_write_cache(codec, 0x01, 0,
5755 AC_VERB_SET_GPIO_DATA, 1); 5757 AC_VERB_SET_GPIO_DATA, 1);
@@ -5989,7 +5991,6 @@ static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5989{ 5991{
5990 hda_nid_t nid_vol; 5992 hda_nid_t nid_vol;
5991 unsigned long vol_val, sw_val; 5993 unsigned long vol_val, sw_val;
5992 char name[32];
5993 int err; 5994 int err;
5994 5995
5995 if (nid >= 0x0f && nid < 0x11) { 5996 if (nid >= 0x0f && nid < 0x11) {
@@ -6009,14 +6010,12 @@ static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
6009 6010
6010 if (!(*vol_bits & (1 << nid_vol))) { 6011 if (!(*vol_bits & (1 << nid_vol))) {
6011 /* first control for the volume widget */ 6012 /* first control for the volume widget */
6012 snprintf(name, sizeof(name), "%s Playback Volume", pfx); 6013 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
6013 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
6014 if (err < 0) 6014 if (err < 0)
6015 return err; 6015 return err;
6016 *vol_bits |= (1 << nid_vol); 6016 *vol_bits |= (1 << nid_vol);
6017 } 6017 }
6018 snprintf(name, sizeof(name), "%s Playback Switch", pfx); 6018 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6019 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
6020 if (err < 0) 6019 if (err < 0)
6021 return err; 6020 return err;
6022 return 1; 6021 return 1;
@@ -6619,7 +6618,7 @@ static struct hda_input_mux alc889A_mb31_capture_source = {
6619 /* Front Mic (0x01) unused */ 6618 /* Front Mic (0x01) unused */
6620 { "Line", 0x2 }, 6619 { "Line", 0x2 },
6621 /* Line 2 (0x03) unused */ 6620 /* Line 2 (0x03) unused */
6622 /* CD (0x04) unsused? */ 6621 /* CD (0x04) unused? */
6623 }, 6622 },
6624}; 6623};
6625 6624
@@ -7336,8 +7335,8 @@ static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7336 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT), 7335 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7337 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT), 7336 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7338 /* FIXME: this looks suspicious... 7337 /* FIXME: this looks suspicious...
7339 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT), 7338 HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
7340 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT), 7339 HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
7341 */ 7340 */
7342 { } /* end */ 7341 { } /* end */
7343}; 7342};
@@ -8184,12 +8183,8 @@ static void alc883_mitac_setup(struct hda_codec *codec)
8184/* 8183/*
8185static void alc883_mitac_mic_automute(struct hda_codec *codec) 8184static void alc883_mitac_mic_automute(struct hda_codec *codec)
8186{ 8185{
8187 unsigned int present; 8186 unsigned char bits = snd_hda_jack_detect(codec, 0x18) ? HDA_AMP_MUTE : 0;
8188 unsigned char bits;
8189 8187
8190 present = snd_hda_codec_read(codec, 0x18, 0,
8191 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8192 bits = present ? HDA_AMP_MUTE : 0;
8193 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); 8188 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8194} 8189}
8195*/ 8190*/
@@ -8411,10 +8406,8 @@ static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8411/* toggle front-jack and RCA according to the hp-jack state */ 8406/* toggle front-jack and RCA according to the hp-jack state */
8412static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec) 8407static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8413{ 8408{
8414 unsigned int present; 8409 unsigned int present = snd_hda_jack_detect(codec, 0x1b);
8415 8410
8416 present = snd_hda_codec_read(codec, 0x1b, 0,
8417 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8418 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8411 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8419 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8412 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8420 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8413 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
@@ -8424,10 +8417,8 @@ static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8424/* toggle RCA according to the front-jack state */ 8417/* toggle RCA according to the front-jack state */
8425static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec) 8418static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8426{ 8419{
8427 unsigned int present; 8420 unsigned int present = snd_hda_jack_detect(codec, 0x14);
8428 8421
8429 present = snd_hda_codec_read(codec, 0x14, 0,
8430 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8431 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8422 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8432 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8423 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8433} 8424}
@@ -8468,8 +8459,7 @@ static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8468{ 8459{
8469 unsigned int present; 8460 unsigned int present;
8470 8461
8471 present = snd_hda_codec_read(codec, 0x18, 0, 8462 present = snd_hda_jack_detect(codec, 0x18);
8472 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8473 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, 8463 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8474 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8464 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8475} 8465}
@@ -8520,24 +8510,16 @@ static void alc883_haier_w66_setup(struct hda_codec *codec)
8520 8510
8521static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec) 8511static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8522{ 8512{
8523 unsigned int present; 8513 int bits = snd_hda_jack_detect(codec, 0x14) ? HDA_AMP_MUTE : 0;
8524 unsigned char bits;
8525 8514
8526 present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8527 & AC_PINSENSE_PRESENCE;
8528 bits = present ? HDA_AMP_MUTE : 0;
8529 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8515 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8530 HDA_AMP_MUTE, bits); 8516 HDA_AMP_MUTE, bits);
8531} 8517}
8532 8518
8533static void alc883_lenovo_101e_all_automute(struct hda_codec *codec) 8519static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8534{ 8520{
8535 unsigned int present; 8521 int bits = snd_hda_jack_detect(codec, 0x1b) ? HDA_AMP_MUTE : 0;
8536 unsigned char bits;
8537 8522
8538 present = snd_hda_codec_read(codec, 0x1b, 0,
8539 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8540 bits = present ? HDA_AMP_MUTE : 0;
8541 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8523 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8542 HDA_AMP_MUTE, bits); 8524 HDA_AMP_MUTE, bits);
8543 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8525 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -8688,8 +8670,7 @@ static void alc889A_mb31_automute(struct hda_codec *codec)
8688 /* Mute only in 2ch or 4ch mode */ 8670 /* Mute only in 2ch or 4ch mode */
8689 if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0) 8671 if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8690 == 0x00) { 8672 == 0x00) {
8691 present = snd_hda_codec_read(codec, 0x15, 0, 8673 present = snd_hda_jack_detect(codec, 0x15);
8692 AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8693 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8674 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8694 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8675 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8695 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, 8676 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
@@ -10032,10 +10013,8 @@ static void alc262_hp_master_update(struct hda_codec *codec)
10032static void alc262_hp_bpc_automute(struct hda_codec *codec) 10013static void alc262_hp_bpc_automute(struct hda_codec *codec)
10033{ 10014{
10034 struct alc_spec *spec = codec->spec; 10015 struct alc_spec *spec = codec->spec;
10035 unsigned int presence; 10016
10036 presence = snd_hda_codec_read(codec, 0x1b, 0, 10017 spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10037 AC_VERB_GET_PIN_SENSE, 0);
10038 spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10039 alc262_hp_master_update(codec); 10018 alc262_hp_master_update(codec);
10040} 10019}
10041 10020
@@ -10049,10 +10028,8 @@ static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10049static void alc262_hp_wildwest_automute(struct hda_codec *codec) 10028static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10050{ 10029{
10051 struct alc_spec *spec = codec->spec; 10030 struct alc_spec *spec = codec->spec;
10052 unsigned int presence; 10031
10053 presence = snd_hda_codec_read(codec, 0x15, 0, 10032 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10054 AC_VERB_GET_PIN_SENSE, 0);
10055 spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10056 alc262_hp_master_update(codec); 10033 alc262_hp_master_update(codec);
10057} 10034}
10058 10035
@@ -10286,13 +10263,8 @@ static void alc262_hippo_automute(struct hda_codec *codec)
10286{ 10263{
10287 struct alc_spec *spec = codec->spec; 10264 struct alc_spec *spec = codec->spec;
10288 hda_nid_t hp_nid = spec->autocfg.hp_pins[0]; 10265 hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10289 unsigned int present;
10290 10266
10291 /* need to execute and sync at first */ 10267 spec->jack_present = snd_hda_jack_detect(codec, hp_nid);
10292 snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10293 present = snd_hda_codec_read(codec, hp_nid, 0,
10294 AC_VERB_GET_PIN_SENSE, 0);
10295 spec->jack_present = (present & 0x80000000) != 0;
10296 alc262_hippo_master_update(codec); 10268 alc262_hippo_master_update(codec);
10297} 10269}
10298 10270
@@ -10618,21 +10590,8 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10618 unsigned int mute; 10590 unsigned int mute;
10619 10591
10620 if (force || !spec->sense_updated) { 10592 if (force || !spec->sense_updated) {
10621 unsigned int present; 10593 spec->jack_present = snd_hda_jack_detect(codec, 0x14) ||
10622 /* need to execute and sync at first */ 10594 snd_hda_jack_detect(codec, 0x1b);
10623 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10624 /* check laptop HP jack */
10625 present = snd_hda_codec_read(codec, 0x14, 0,
10626 AC_VERB_GET_PIN_SENSE, 0);
10627 /* need to execute and sync at first */
10628 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10629 /* check docking HP jack */
10630 present |= snd_hda_codec_read(codec, 0x1b, 0,
10631 AC_VERB_GET_PIN_SENSE, 0);
10632 if (present & AC_PINSENSE_PRESENCE)
10633 spec->jack_present = 1;
10634 else
10635 spec->jack_present = 0;
10636 spec->sense_updated = 1; 10595 spec->sense_updated = 1;
10637 } 10596 }
10638 /* unmute internal speaker only if both HPs are unplugged and 10597 /* unmute internal speaker only if both HPs are unplugged and
@@ -10677,12 +10636,7 @@ static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10677 unsigned int mute; 10636 unsigned int mute;
10678 10637
10679 if (force || !spec->sense_updated) { 10638 if (force || !spec->sense_updated) {
10680 unsigned int present_int_hp; 10639 spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10681 /* need to execute and sync at first */
10682 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10683 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10684 AC_VERB_GET_PIN_SENSE, 0);
10685 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10686 spec->sense_updated = 1; 10640 spec->sense_updated = 1;
10687 } 10641 }
10688 if (spec->jack_present) { 10642 if (spec->jack_present) {
@@ -10874,12 +10828,7 @@ static void alc262_ultra_automute(struct hda_codec *codec)
10874 mute = 0; 10828 mute = 0;
10875 /* auto-mute only when HP is used as HP */ 10829 /* auto-mute only when HP is used as HP */
10876 if (!spec->cur_mux[0]) { 10830 if (!spec->cur_mux[0]) {
10877 unsigned int present; 10831 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10878 /* need to execute and sync at first */
10879 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10880 present = snd_hda_codec_read(codec, 0x15, 0,
10881 AC_VERB_GET_PIN_SENSE, 0);
10882 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10883 if (spec->jack_present) 10832 if (spec->jack_present)
10884 mute = HDA_AMP_MUTE; 10833 mute = HDA_AMP_MUTE;
10885 } 10834 }
@@ -10956,7 +10905,6 @@ static int alc262_check_volbit(hda_nid_t nid)
10956static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid, 10905static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10957 const char *pfx, int *vbits) 10906 const char *pfx, int *vbits)
10958{ 10907{
10959 char name[32];
10960 unsigned long val; 10908 unsigned long val;
10961 int vbit; 10909 int vbit;
10962 10910
@@ -10966,28 +10914,25 @@ static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10966 if (*vbits & vbit) /* a volume control for this mixer already there */ 10914 if (*vbits & vbit) /* a volume control for this mixer already there */
10967 return 0; 10915 return 0;
10968 *vbits |= vbit; 10916 *vbits |= vbit;
10969 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
10970 if (vbit == 2) 10917 if (vbit == 2)
10971 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT); 10918 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10972 else 10919 else
10973 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT); 10920 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10974 return add_control(spec, ALC_CTL_WIDGET_VOL, name, val); 10921 return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10975} 10922}
10976 10923
10977static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid, 10924static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10978 const char *pfx) 10925 const char *pfx)
10979{ 10926{
10980 char name[32];
10981 unsigned long val; 10927 unsigned long val;
10982 10928
10983 if (!nid) 10929 if (!nid)
10984 return 0; 10930 return 0;
10985 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
10986 if (nid == 0x16) 10931 if (nid == 0x16)
10987 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT); 10932 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10988 else 10933 else
10989 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); 10934 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10990 return add_control(spec, ALC_CTL_WIDGET_MUTE, name, val); 10935 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10991} 10936}
10992 10937
10993/* add playback controls from the parsed DAC table */ 10938/* add playback controls from the parsed DAC table */
@@ -11463,8 +11408,10 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
11463 SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06), 11408 SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11464 SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO), 11409 SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
11465 SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO), 11410 SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
11411#if 0 /* disable the quirk since model=auto works better in recent versions */
11466 SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO", 11412 SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11467 ALC262_SONY_ASSAMD), 11413 ALC262_SONY_ASSAMD),
11414#endif
11468 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", 11415 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11469 ALC262_TOSHIBA_RX1), 11416 ALC262_TOSHIBA_RX1),
11470 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06), 11417 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
@@ -11923,10 +11870,7 @@ static void alc268_acer_automute(struct hda_codec *codec, int force)
11923 unsigned int mute; 11870 unsigned int mute;
11924 11871
11925 if (force || !spec->sense_updated) { 11872 if (force || !spec->sense_updated) {
11926 unsigned int present; 11873 spec->jack_present = snd_hda_jack_detect(codec, 0x14);
11927 present = snd_hda_codec_read(codec, 0x14, 0,
11928 AC_VERB_GET_PIN_SENSE, 0);
11929 spec->jack_present = (present & 0x80000000) != 0;
11930 spec->sense_updated = 1; 11874 spec->sense_updated = 1;
11931 } 11875 }
11932 if (spec->jack_present) 11876 if (spec->jack_present)
@@ -12045,8 +11989,7 @@ static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12045 unsigned int present; 11989 unsigned int present;
12046 unsigned char bits; 11990 unsigned char bits;
12047 11991
12048 present = snd_hda_codec_read(codec, 0x15, 0, 11992 present = snd_hda_jack_detect(codec, 0x15);
12049 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12050 bits = present ? AMP_IN_MUTE(0) : 0; 11993 bits = present ? AMP_IN_MUTE(0) : 0;
12051 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0, 11994 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12052 AMP_IN_MUTE(0), bits); 11995 AMP_IN_MUTE(0), bits);
@@ -12327,11 +12270,9 @@ static struct snd_kcontrol_new alc268_test_mixer[] = {
12327static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid, 12270static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12328 const char *ctlname, int idx) 12271 const char *ctlname, int idx)
12329{ 12272{
12330 char name[32];
12331 hda_nid_t dac; 12273 hda_nid_t dac;
12332 int err; 12274 int err;
12333 12275
12334 sprintf(name, "%s Playback Volume", ctlname);
12335 switch (nid) { 12276 switch (nid) {
12336 case 0x14: 12277 case 0x14:
12337 case 0x16: 12278 case 0x16:
@@ -12345,7 +12286,7 @@ static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12345 } 12286 }
12346 if (spec->multiout.dac_nids[0] != dac && 12287 if (spec->multiout.dac_nids[0] != dac &&
12347 spec->multiout.dac_nids[1] != dac) { 12288 spec->multiout.dac_nids[1] != dac) {
12348 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 12289 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12349 HDA_COMPOSE_AMP_VAL(dac, 3, idx, 12290 HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12350 HDA_OUTPUT)); 12291 HDA_OUTPUT));
12351 if (err < 0) 12292 if (err < 0)
@@ -12353,12 +12294,11 @@ static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12353 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac; 12294 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12354 } 12295 }
12355 12296
12356 sprintf(name, "%s Playback Switch", ctlname);
12357 if (nid != 0x16) 12297 if (nid != 0x16)
12358 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 12298 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12359 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT)); 12299 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12360 else /* mono */ 12300 else /* mono */
12361 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 12301 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12362 HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT)); 12302 HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12363 if (err < 0) 12303 if (err < 0)
12364 return err; 12304 return err;
@@ -12388,8 +12328,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12388 12328
12389 nid = cfg->speaker_pins[0]; 12329 nid = cfg->speaker_pins[0];
12390 if (nid == 0x1d) { 12330 if (nid == 0x1d) {
12391 err = add_control(spec, ALC_CTL_WIDGET_VOL, 12331 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12392 "Speaker Playback Volume",
12393 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); 12332 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12394 if (err < 0) 12333 if (err < 0)
12395 return err; 12334 return err;
@@ -12407,8 +12346,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12407 12346
12408 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2]; 12347 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12409 if (nid == 0x16) { 12348 if (nid == 0x16) {
12410 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 12349 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12411 "Mono Playback Switch",
12412 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT)); 12350 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12413 if (err < 0) 12351 if (err < 0)
12414 return err; 12352 return err;
@@ -13034,8 +12972,7 @@ static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13034 unsigned int present; 12972 unsigned int present;
13035 unsigned char bits; 12973 unsigned char bits;
13036 12974
13037 present = snd_hda_codec_read(codec, 0x15, 0, 12975 present = snd_hda_jack_detect(codec, 0x15);
13038 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13039 bits = present ? AMP_IN_MUTE(0) : 0; 12976 bits = present ? AMP_IN_MUTE(0) : 0;
13040 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 12977 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13041 AMP_IN_MUTE(0), bits); 12978 AMP_IN_MUTE(0), bits);
@@ -13060,12 +12997,10 @@ static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13060 unsigned char bits; 12997 unsigned char bits;
13061 12998
13062 /* Check laptop headphone socket */ 12999 /* Check laptop headphone socket */
13063 present = snd_hda_codec_read(codec, 0x15, 0, 13000 present = snd_hda_jack_detect(codec, 0x15);
13064 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13065 13001
13066 /* Check port replicator headphone socket */ 13002 /* Check port replicator headphone socket */
13067 present |= snd_hda_codec_read(codec, 0x1a, 0, 13003 present |= snd_hda_jack_detect(codec, 0x1a);
13068 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13069 13004
13070 bits = present ? AMP_IN_MUTE(0) : 0; 13005 bits = present ? AMP_IN_MUTE(0) : 0;
13071 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13006 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
@@ -13089,11 +13024,8 @@ static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13089 unsigned int present_laptop; 13024 unsigned int present_laptop;
13090 unsigned int present_dock; 13025 unsigned int present_dock;
13091 13026
13092 present_laptop = snd_hda_codec_read(codec, 0x18, 0, 13027 present_laptop = snd_hda_jack_detect(codec, 0x18);
13093 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 13028 present_dock = snd_hda_jack_detect(codec, 0x1b);
13094
13095 present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13096 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13097 13029
13098 /* Laptop mic port overrides dock mic port, design decision */ 13030 /* Laptop mic port overrides dock mic port, design decision */
13099 if (present_dock) 13031 if (present_dock)
@@ -13178,8 +13110,7 @@ static void alc269_speaker_automute(struct hda_codec *codec)
13178 unsigned int present; 13110 unsigned int present;
13179 unsigned char bits; 13111 unsigned char bits;
13180 13112
13181 present = snd_hda_codec_read(codec, 0x15, 0, 13113 present = snd_hda_jack_detect(codec, 0x15);
13182 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13183 bits = present ? AMP_IN_MUTE(0) : 0; 13114 bits = present ? AMP_IN_MUTE(0) : 0;
13184 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13115 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13185 AMP_IN_MUTE(0), bits); 13116 AMP_IN_MUTE(0), bits);
@@ -13525,6 +13456,15 @@ static int patch_alc269(struct hda_codec *codec)
13525 13456
13526 alc_fix_pll_init(codec, 0x20, 0x04, 15); 13457 alc_fix_pll_init(codec, 0x20, 0x04, 15);
13527 13458
13459 if ((alc_read_coef_idx(codec, 0) & 0x00f0) == 0x0010){
13460 kfree(codec->chip_name);
13461 codec->chip_name = kstrdup("ALC259", GFP_KERNEL);
13462 if (!codec->chip_name) {
13463 alc_free(codec);
13464 return -ENOMEM;
13465 }
13466 }
13467
13528 board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST, 13468 board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13529 alc269_models, 13469 alc269_models,
13530 alc269_cfg_tbl); 13470 alc269_cfg_tbl);
@@ -14157,10 +14097,8 @@ static struct hda_verb alc861_toshiba_init_verbs[] = {
14157/* toggle speaker-output according to the hp-jack state */ 14097/* toggle speaker-output according to the hp-jack state */
14158static void alc861_toshiba_automute(struct hda_codec *codec) 14098static void alc861_toshiba_automute(struct hda_codec *codec)
14159{ 14099{
14160 unsigned int present; 14100 unsigned int present = snd_hda_jack_detect(codec, 0x0f);
14161 14101
14162 present = snd_hda_codec_read(codec, 0x0f, 0,
14163 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14164 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0, 14102 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14165 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 14103 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14166 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3, 14104 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
@@ -14260,9 +14198,7 @@ static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14260static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx, 14198static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14261 hda_nid_t nid, unsigned int chs) 14199 hda_nid_t nid, unsigned int chs)
14262{ 14200{
14263 char name[32]; 14201 return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14264 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
14265 return add_control(codec->spec, ALC_CTL_WIDGET_MUTE, name,
14266 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 14202 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14267} 14203}
14268 14204
@@ -14627,6 +14563,27 @@ static struct alc_config_preset alc861_presets[] = {
14627 }, 14563 },
14628}; 14564};
14629 14565
14566/* Pin config fixes */
14567enum {
14568 PINFIX_FSC_AMILO_PI1505,
14569};
14570
14571static struct alc_pincfg alc861_fsc_amilo_pi1505_pinfix[] = {
14572 { 0x0b, 0x0221101f }, /* HP */
14573 { 0x0f, 0x90170310 }, /* speaker */
14574 { }
14575};
14576
14577static const struct alc_fixup alc861_fixups[] = {
14578 [PINFIX_FSC_AMILO_PI1505] = {
14579 .pins = alc861_fsc_amilo_pi1505_pinfix
14580 },
14581};
14582
14583static struct snd_pci_quirk alc861_fixup_tbl[] = {
14584 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
14585 {}
14586};
14630 14587
14631static int patch_alc861(struct hda_codec *codec) 14588static int patch_alc861(struct hda_codec *codec)
14632{ 14589{
@@ -14650,6 +14607,8 @@ static int patch_alc861(struct hda_codec *codec)
14650 board_config = ALC861_AUTO; 14607 board_config = ALC861_AUTO;
14651 } 14608 }
14652 14609
14610 alc_pick_fixup(codec, alc861_fixup_tbl, alc861_fixups);
14611
14653 if (board_config == ALC861_AUTO) { 14612 if (board_config == ALC861_AUTO) {
14654 /* automatic parse from the BIOS config */ 14613 /* automatic parse from the BIOS config */
14655 err = alc861_parse_auto_config(codec); 14614 err = alc861_parse_auto_config(codec);
@@ -15067,9 +15026,9 @@ static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15067 unsigned int present; 15026 unsigned int present;
15068 unsigned char bits; 15027 unsigned char bits;
15069 15028
15070 present = snd_hda_codec_read(codec, 0x18, 0, 15029 present = snd_hda_jack_detect(codec, 0x18);
15071 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15072 bits = present ? HDA_AMP_MUTE : 0; 15030 bits = present ? HDA_AMP_MUTE : 0;
15031
15073 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, 15032 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15074 HDA_AMP_MUTE, bits); 15033 HDA_AMP_MUTE, bits);
15075} 15034}
@@ -15386,7 +15345,6 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15386static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec, 15345static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15387 const struct auto_pin_cfg *cfg) 15346 const struct auto_pin_cfg *cfg)
15388{ 15347{
15389 char name[32];
15390 static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"}; 15348 static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15391 hda_nid_t nid_v, nid_s; 15349 hda_nid_t nid_v, nid_s;
15392 int i, err; 15350 int i, err;
@@ -15403,26 +15361,26 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15403 15361
15404 if (i == 2) { 15362 if (i == 2) {
15405 /* Center/LFE */ 15363 /* Center/LFE */
15406 err = add_control(spec, ALC_CTL_WIDGET_VOL, 15364 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15407 "Center Playback Volume", 15365 "Center",
15408 HDA_COMPOSE_AMP_VAL(nid_v, 1, 0, 15366 HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15409 HDA_OUTPUT)); 15367 HDA_OUTPUT));
15410 if (err < 0) 15368 if (err < 0)
15411 return err; 15369 return err;
15412 err = add_control(spec, ALC_CTL_WIDGET_VOL, 15370 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15413 "LFE Playback Volume", 15371 "LFE",
15414 HDA_COMPOSE_AMP_VAL(nid_v, 2, 0, 15372 HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15415 HDA_OUTPUT)); 15373 HDA_OUTPUT));
15416 if (err < 0) 15374 if (err < 0)
15417 return err; 15375 return err;
15418 err = add_control(spec, ALC_CTL_BIND_MUTE, 15376 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15419 "Center Playback Switch", 15377 "Center",
15420 HDA_COMPOSE_AMP_VAL(nid_s, 1, 2, 15378 HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15421 HDA_INPUT)); 15379 HDA_INPUT));
15422 if (err < 0) 15380 if (err < 0)
15423 return err; 15381 return err;
15424 err = add_control(spec, ALC_CTL_BIND_MUTE, 15382 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15425 "LFE Playback Switch", 15383 "LFE",
15426 HDA_COMPOSE_AMP_VAL(nid_s, 2, 2, 15384 HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15427 HDA_INPUT)); 15385 HDA_INPUT));
15428 if (err < 0) 15386 if (err < 0)
@@ -15437,8 +15395,7 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15437 pfx = "PCM"; 15395 pfx = "PCM";
15438 } else 15396 } else
15439 pfx = chname[i]; 15397 pfx = chname[i];
15440 sprintf(name, "%s Playback Volume", pfx); 15398 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15441 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15442 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, 15399 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15443 HDA_OUTPUT)); 15400 HDA_OUTPUT));
15444 if (err < 0) 15401 if (err < 0)
@@ -15446,8 +15403,7 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15446 if (cfg->line_outs == 1 && 15403 if (cfg->line_outs == 1 &&
15447 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) 15404 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15448 pfx = "Speaker"; 15405 pfx = "Speaker";
15449 sprintf(name, "%s Playback Switch", pfx); 15406 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15450 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15451 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, 15407 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15452 HDA_INPUT)); 15408 HDA_INPUT));
15453 if (err < 0) 15409 if (err < 0)
@@ -15465,7 +15421,6 @@ static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15465{ 15421{
15466 hda_nid_t nid_v, nid_s; 15422 hda_nid_t nid_v, nid_s;
15467 int err; 15423 int err;
15468 char name[32];
15469 15424
15470 if (!pin) 15425 if (!pin)
15471 return 0; 15426 return 0;
@@ -15483,21 +15438,18 @@ static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15483 nid_s = alc861vd_idx_to_mixer_switch( 15438 nid_s = alc861vd_idx_to_mixer_switch(
15484 alc880_fixed_pin_idx(pin)); 15439 alc880_fixed_pin_idx(pin));
15485 15440
15486 sprintf(name, "%s Playback Volume", pfx); 15441 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15487 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15488 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT)); 15442 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15489 if (err < 0) 15443 if (err < 0)
15490 return err; 15444 return err;
15491 sprintf(name, "%s Playback Switch", pfx); 15445 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15492 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15493 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT)); 15446 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15494 if (err < 0) 15447 if (err < 0)
15495 return err; 15448 return err;
15496 } else if (alc880_is_multi_pin(pin)) { 15449 } else if (alc880_is_multi_pin(pin)) {
15497 /* set manual connection */ 15450 /* set manual connection */
15498 /* we have only a switch on HP-out PIN */ 15451 /* we have only a switch on HP-out PIN */
15499 sprintf(name, "%s Playback Switch", pfx); 15452 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15500 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15501 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 15453 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15502 if (err < 0) 15454 if (err < 0)
15503 return err; 15455 return err;
@@ -16387,9 +16339,9 @@ static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16387 unsigned int present; 16339 unsigned int present;
16388 unsigned char bits; 16340 unsigned char bits;
16389 16341
16390 present = snd_hda_codec_read(codec, 0x14, 0, 16342 present = snd_hda_jack_detect(codec, 0x14);
16391 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16392 bits = present ? HDA_AMP_MUTE : 0; 16343 bits = present ? HDA_AMP_MUTE : 0;
16344
16393 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 16345 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16394 HDA_AMP_MUTE, bits); 16346 HDA_AMP_MUTE, bits);
16395} 16347}
@@ -16399,9 +16351,9 @@ static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16399 unsigned int present; 16351 unsigned int present;
16400 unsigned char bits; 16352 unsigned char bits;
16401 16353
16402 present = snd_hda_codec_read(codec, 0x1b, 0, 16354 present = snd_hda_jack_detect(codec, 0x1b);
16403 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16404 bits = present ? HDA_AMP_MUTE : 0; 16355 bits = present ? HDA_AMP_MUTE : 0;
16356
16405 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 16357 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16406 HDA_AMP_MUTE, bits); 16358 HDA_AMP_MUTE, bits);
16407 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 16359 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -16460,9 +16412,7 @@ static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16460 unsigned int present; 16412 unsigned int present;
16461 unsigned char bits; 16413 unsigned char bits;
16462 16414
16463 present = snd_hda_codec_read(codec, 0x21, 0, 16415 present = snd_hda_jack_detect(codec, 0x21);
16464 AC_VERB_GET_PIN_SENSE, 0)
16465 & AC_PINSENSE_PRESENCE;
16466 bits = present ? HDA_AMP_MUTE : 0; 16416 bits = present ? HDA_AMP_MUTE : 0;
16467 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16417 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16468 AMP_IN_MUTE(0), bits); 16418 AMP_IN_MUTE(0), bits);
@@ -16475,9 +16425,7 @@ static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16475 unsigned int present; 16425 unsigned int present;
16476 unsigned char bits; 16426 unsigned char bits;
16477 16427
16478 present = snd_hda_codec_read(codec, 0x21, 0, 16428 present = snd_hda_jack_detect(codec, 0x21);
16479 AC_VERB_GET_PIN_SENSE, 0)
16480 & AC_PINSENSE_PRESENCE;
16481 bits = present ? HDA_AMP_MUTE : 0; 16429 bits = present ? HDA_AMP_MUTE : 0;
16482 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16430 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16483 AMP_IN_MUTE(0), bits); 16431 AMP_IN_MUTE(0), bits);
@@ -16494,9 +16442,7 @@ static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16494 unsigned int present; 16442 unsigned int present;
16495 unsigned char bits; 16443 unsigned char bits;
16496 16444
16497 present = snd_hda_codec_read(codec, 0x15, 0, 16445 present = snd_hda_jack_detect(codec, 0x15);
16498 AC_VERB_GET_PIN_SENSE, 0)
16499 & AC_PINSENSE_PRESENCE;
16500 bits = present ? HDA_AMP_MUTE : 0; 16446 bits = present ? HDA_AMP_MUTE : 0;
16501 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16447 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16502 AMP_IN_MUTE(0), bits); 16448 AMP_IN_MUTE(0), bits);
@@ -16513,9 +16459,7 @@ static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16513 unsigned int present; 16459 unsigned int present;
16514 unsigned char bits; 16460 unsigned char bits;
16515 16461
16516 present = snd_hda_codec_read(codec, 0x1b, 0, 16462 present = snd_hda_jack_detect(codec, 0x1b);
16517 AC_VERB_GET_PIN_SENSE, 0)
16518 & AC_PINSENSE_PRESENCE;
16519 bits = present ? 0 : PIN_OUT; 16463 bits = present ? 0 : PIN_OUT;
16520 snd_hda_codec_write(codec, 0x14, 0, 16464 snd_hda_codec_write(codec, 0x14, 0,
16521 AC_VERB_SET_PIN_WIDGET_CONTROL, bits); 16465 AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
@@ -16525,12 +16469,8 @@ static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16525{ 16469{
16526 unsigned int present1, present2; 16470 unsigned int present1, present2;
16527 16471
16528 present1 = snd_hda_codec_read(codec, 0x21, 0, 16472 present1 = snd_hda_jack_detect(codec, 0x21);
16529 AC_VERB_GET_PIN_SENSE, 0) 16473 present2 = snd_hda_jack_detect(codec, 0x15);
16530 & AC_PINSENSE_PRESENCE;
16531 present2 = snd_hda_codec_read(codec, 0x15, 0,
16532 AC_VERB_GET_PIN_SENSE, 0)
16533 & AC_PINSENSE_PRESENCE;
16534 16474
16535 if (present1 || present2) { 16475 if (present1 || present2) {
16536 snd_hda_codec_write_cache(codec, 0x14, 0, 16476 snd_hda_codec_write_cache(codec, 0x14, 0,
@@ -16545,12 +16485,8 @@ static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16545{ 16485{
16546 unsigned int present1, present2; 16486 unsigned int present1, present2;
16547 16487
16548 present1 = snd_hda_codec_read(codec, 0x1b, 0, 16488 present1 = snd_hda_jack_detect(codec, 0x1b);
16549 AC_VERB_GET_PIN_SENSE, 0) 16489 present2 = snd_hda_jack_detect(codec, 0x15);
16550 & AC_PINSENSE_PRESENCE;
16551 present2 = snd_hda_codec_read(codec, 0x15, 0,
16552 AC_VERB_GET_PIN_SENSE, 0)
16553 & AC_PINSENSE_PRESENCE;
16554 16490
16555 if (present1 || present2) { 16491 if (present1 || present2) {
16556 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16492 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
@@ -16710,9 +16646,7 @@ static void alc663_g71v_hp_automute(struct hda_codec *codec)
16710 unsigned int present; 16646 unsigned int present;
16711 unsigned char bits; 16647 unsigned char bits;
16712 16648
16713 present = snd_hda_codec_read(codec, 0x21, 0, 16649 present = snd_hda_jack_detect(codec, 0x21);
16714 AC_VERB_GET_PIN_SENSE, 0)
16715 & AC_PINSENSE_PRESENCE;
16716 bits = present ? HDA_AMP_MUTE : 0; 16650 bits = present ? HDA_AMP_MUTE : 0;
16717 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 16651 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16718 HDA_AMP_MUTE, bits); 16652 HDA_AMP_MUTE, bits);
@@ -16725,9 +16659,7 @@ static void alc663_g71v_front_automute(struct hda_codec *codec)
16725 unsigned int present; 16659 unsigned int present;
16726 unsigned char bits; 16660 unsigned char bits;
16727 16661
16728 present = snd_hda_codec_read(codec, 0x15, 0, 16662 present = snd_hda_jack_detect(codec, 0x15);
16729 AC_VERB_GET_PIN_SENSE, 0)
16730 & AC_PINSENSE_PRESENCE;
16731 bits = present ? HDA_AMP_MUTE : 0; 16663 bits = present ? HDA_AMP_MUTE : 0;
16732 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 16664 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16733 HDA_AMP_MUTE, bits); 16665 HDA_AMP_MUTE, bits);
@@ -17264,21 +17196,17 @@ static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17264 return 0; 17196 return 0;
17265} 17197}
17266 17198
17267static int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx, 17199static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17268 hda_nid_t nid, unsigned int chs) 17200 hda_nid_t nid, unsigned int chs)
17269{ 17201{
17270 char name[32]; 17202 return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17271 sprintf(name, "%s Playback Volume", pfx);
17272 return add_control(spec, ALC_CTL_WIDGET_VOL, name,
17273 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 17203 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17274} 17204}
17275 17205
17276static int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx, 17206static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17277 hda_nid_t nid, unsigned int chs) 17207 hda_nid_t nid, unsigned int chs)
17278{ 17208{
17279 char name[32]; 17209 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17280 sprintf(name, "%s Playback Switch", pfx);
17281 return add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17282 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT)); 17210 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17283} 17211}
17284 17212
@@ -17356,13 +17284,11 @@ static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17356 return 0; 17284 return 0;
17357 nid = alc662_look_for_dac(codec, pin); 17285 nid = alc662_look_for_dac(codec, pin);
17358 if (!nid) { 17286 if (!nid) {
17359 char name[32];
17360 /* the corresponding DAC is already occupied */ 17287 /* the corresponding DAC is already occupied */
17361 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) 17288 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17362 return 0; /* no way */ 17289 return 0; /* no way */
17363 /* create a switch only */ 17290 /* create a switch only */
17364 sprintf(name, "%s Playback Switch", pfx); 17291 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17365 return add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17366 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 17292 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17367 } 17293 }
17368 17294
@@ -17538,6 +17464,15 @@ static int patch_alc662(struct hda_codec *codec)
17538 17464
17539 alc_fix_pll_init(codec, 0x20, 0x04, 15); 17465 alc_fix_pll_init(codec, 0x20, 0x04, 15);
17540 17466
17467 if (alc_read_coef_idx(codec, 0)==0x8020){
17468 kfree(codec->chip_name);
17469 codec->chip_name = kstrdup("ALC661", GFP_KERNEL);
17470 if (!codec->chip_name) {
17471 alc_free(codec);
17472 return -ENOMEM;
17473 }
17474 }
17475
17541 board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST, 17476 board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17542 alc662_models, 17477 alc662_models,
17543 alc662_cfg_tbl); 17478 alc662_cfg_tbl);
@@ -17604,6 +17539,20 @@ static int patch_alc662(struct hda_codec *codec)
17604 return 0; 17539 return 0;
17605} 17540}
17606 17541
17542static int patch_alc888(struct hda_codec *codec)
17543{
17544 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
17545 kfree(codec->chip_name);
17546 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
17547 if (!codec->chip_name) {
17548 alc_free(codec);
17549 return -ENOMEM;
17550 }
17551 return patch_alc662(codec);
17552 }
17553 return patch_alc882(codec);
17554}
17555
17607/* 17556/*
17608 * patch entries 17557 * patch entries
17609 */ 17558 */
@@ -17635,8 +17584,9 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
17635 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, 17584 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17636 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", 17585 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17637 .patch = patch_alc882 }, 17586 .patch = patch_alc882 },
17638 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, 17587 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
17639 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, 17588 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17589 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
17640 {} /* terminator */ 17590 {} /* terminator */
17641}; 17591};
17642 17592
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 86de305fc9f2..6b0bc040c3b1 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -93,6 +93,7 @@ enum {
93 STAC_92HD83XXX_REF, 93 STAC_92HD83XXX_REF,
94 STAC_92HD83XXX_PWR_REF, 94 STAC_92HD83XXX_PWR_REF,
95 STAC_DELL_S14, 95 STAC_DELL_S14,
96 STAC_92HD83XXX_HP,
96 STAC_92HD83XXX_MODELS 97 STAC_92HD83XXX_MODELS
97}; 98};
98 99
@@ -1085,7 +1086,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1085 if (!spec->auto_mic && spec->num_dmuxes > 0 && 1086 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1086 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) { 1087 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1087 stac_dmux_mixer.count = spec->num_dmuxes; 1088 stac_dmux_mixer.count = spec->num_dmuxes;
1088 err = snd_hda_ctl_add(codec, 1089 err = snd_hda_ctl_add(codec, 0,
1089 snd_ctl_new1(&stac_dmux_mixer, codec)); 1090 snd_ctl_new1(&stac_dmux_mixer, codec));
1090 if (err < 0) 1091 if (err < 0)
1091 return err; 1092 return err;
@@ -1101,7 +1102,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1101 spec->spdif_mute = 1; 1102 spec->spdif_mute = 1;
1102 } 1103 }
1103 stac_smux_mixer.count = spec->num_smuxes; 1104 stac_smux_mixer.count = spec->num_smuxes;
1104 err = snd_hda_ctl_add(codec, 1105 err = snd_hda_ctl_add(codec, 0,
1105 snd_ctl_new1(&stac_smux_mixer, codec)); 1106 snd_ctl_new1(&stac_smux_mixer, codec));
1106 if (err < 0) 1107 if (err < 0)
1107 return err; 1108 return err;
@@ -1624,6 +1625,7 @@ static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1624 [STAC_92HD83XXX_REF] = "ref", 1625 [STAC_92HD83XXX_REF] = "ref",
1625 [STAC_92HD83XXX_PWR_REF] = "mic-ref", 1626 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1626 [STAC_DELL_S14] = "dell-s14", 1627 [STAC_DELL_S14] = "dell-s14",
1628 [STAC_92HD83XXX_HP] = "hp",
1627}; 1629};
1628 1630
1629static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = { 1631static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
@@ -1634,6 +1636,8 @@ static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1634 "DFI LanParty", STAC_92HD83XXX_REF), 1636 "DFI LanParty", STAC_92HD83XXX_REF),
1635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba, 1637 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1636 "unknown Dell", STAC_DELL_S14), 1638 "unknown Dell", STAC_DELL_S14),
1639 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1640 "HP", STAC_92HD83XXX_HP),
1637 {} /* terminator */ 1641 {} /* terminator */
1638}; 1642};
1639 1643
@@ -2648,6 +2652,7 @@ static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2648enum { 2652enum {
2649 STAC_CTL_WIDGET_VOL, 2653 STAC_CTL_WIDGET_VOL,
2650 STAC_CTL_WIDGET_MUTE, 2654 STAC_CTL_WIDGET_MUTE,
2655 STAC_CTL_WIDGET_MUTE_BEEP,
2651 STAC_CTL_WIDGET_MONO_MUX, 2656 STAC_CTL_WIDGET_MONO_MUX,
2652 STAC_CTL_WIDGET_HP_SWITCH, 2657 STAC_CTL_WIDGET_HP_SWITCH,
2653 STAC_CTL_WIDGET_IO_SWITCH, 2658 STAC_CTL_WIDGET_IO_SWITCH,
@@ -2658,6 +2663,7 @@ enum {
2658static struct snd_kcontrol_new stac92xx_control_templates[] = { 2663static struct snd_kcontrol_new stac92xx_control_templates[] = {
2659 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2664 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2660 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2665 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2666 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2661 STAC_MONO_MUX, 2667 STAC_MONO_MUX,
2662 STAC_CODEC_HP_SWITCH(NULL), 2668 STAC_CODEC_HP_SWITCH(NULL),
2663 STAC_CODEC_IO_SWITCH(NULL, 0), 2669 STAC_CODEC_IO_SWITCH(NULL, 0),
@@ -2669,7 +2675,8 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2669static struct snd_kcontrol_new * 2675static struct snd_kcontrol_new *
2670stac_control_new(struct sigmatel_spec *spec, 2676stac_control_new(struct sigmatel_spec *spec,
2671 struct snd_kcontrol_new *ktemp, 2677 struct snd_kcontrol_new *ktemp,
2672 const char *name) 2678 const char *name,
2679 hda_nid_t nid)
2673{ 2680{
2674 struct snd_kcontrol_new *knew; 2681 struct snd_kcontrol_new *knew;
2675 2682
@@ -2685,6 +2692,8 @@ stac_control_new(struct sigmatel_spec *spec,
2685 spec->kctls.alloced--; 2692 spec->kctls.alloced--;
2686 return NULL; 2693 return NULL;
2687 } 2694 }
2695 if (nid)
2696 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
2688 return knew; 2697 return knew;
2689} 2698}
2690 2699
@@ -2693,7 +2702,8 @@ static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2693 int idx, const char *name, 2702 int idx, const char *name,
2694 unsigned long val) 2703 unsigned long val)
2695{ 2704{
2696 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name); 2705 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2706 get_amp_nid_(val));
2697 if (!knew) 2707 if (!knew)
2698 return -ENOMEM; 2708 return -ENOMEM;
2699 knew->index = idx; 2709 knew->index = idx;
@@ -2764,7 +2774,7 @@ static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2764 if (!spec->num_adcs || imux->num_items <= 1) 2774 if (!spec->num_adcs || imux->num_items <= 1)
2765 return 0; /* no need for input source control */ 2775 return 0; /* no need for input source control */
2766 knew = stac_control_new(spec, &stac_input_src_temp, 2776 knew = stac_control_new(spec, &stac_input_src_temp,
2767 stac_input_src_temp.name); 2777 stac_input_src_temp.name, 0);
2768 if (!knew) 2778 if (!knew)
2769 return -ENOMEM; 2779 return -ENOMEM;
2770 knew->count = spec->num_adcs; 2780 knew->count = spec->num_adcs;
@@ -3221,12 +3231,15 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3221{ 3231{
3222 struct sigmatel_spec *spec = codec->spec; 3232 struct sigmatel_spec *spec = codec->spec;
3223 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT); 3233 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3224 int err; 3234 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3235
3236 if (spec->anabeep_nid == nid)
3237 type = STAC_CTL_WIDGET_MUTE;
3225 3238
3226 /* check for mute support for the the amp */ 3239 /* check for mute support for the the amp */
3227 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) { 3240 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3228 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, 3241 err = stac92xx_add_control(spec, type,
3229 "PC Beep Playback Switch", 3242 "Beep Playback Switch",
3230 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT)); 3243 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3231 if (err < 0) 3244 if (err < 0)
3232 return err; 3245 return err;
@@ -3235,7 +3248,7 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3235 /* check to see if there is volume support for the amp */ 3248 /* check to see if there is volume support for the amp */
3236 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) { 3249 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3237 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, 3250 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3238 "PC Beep Playback Volume", 3251 "Beep Playback Volume",
3239 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT)); 3252 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3240 if (err < 0) 3253 if (err < 0)
3241 return err; 3254 return err;
@@ -3258,12 +3271,7 @@ static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3258 struct snd_ctl_elem_value *ucontrol) 3271 struct snd_ctl_elem_value *ucontrol)
3259{ 3272{
3260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3273 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3261 int enabled = !!ucontrol->value.integer.value[0]; 3274 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3262 if (codec->beep->enabled != enabled) {
3263 codec->beep->enabled = enabled;
3264 return 1;
3265 }
3266 return 0;
3267} 3275}
3268 3276
3269static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = { 3277static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
@@ -3276,7 +3284,7 @@ static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3276static int stac92xx_beep_switch_ctl(struct hda_codec *codec) 3284static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3277{ 3285{
3278 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl, 3286 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3279 0, "PC Beep Playback Switch", 0); 3287 0, "Beep Playback Switch", 0);
3280} 3288}
3281#endif 3289#endif
3282 3290
@@ -3631,6 +3639,26 @@ static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3631 } 3639 }
3632} 3640}
3633 3641
3642static int is_dual_headphones(struct hda_codec *codec)
3643{
3644 struct sigmatel_spec *spec = codec->spec;
3645 int i, valid_hps;
3646
3647 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3648 spec->autocfg.hp_outs <= 1)
3649 return 0;
3650 valid_hps = 0;
3651 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3652 hda_nid_t nid = spec->autocfg.hp_pins[i];
3653 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3654 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3655 continue;
3656 valid_hps++;
3657 }
3658 return (valid_hps > 1);
3659}
3660
3661
3634static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in) 3662static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3635{ 3663{
3636 struct sigmatel_spec *spec = codec->spec; 3664 struct sigmatel_spec *spec = codec->spec;
@@ -3647,8 +3675,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3647 /* If we have no real line-out pin and multiple hp-outs, HPs should 3675 /* If we have no real line-out pin and multiple hp-outs, HPs should
3648 * be set up as multi-channel outputs. 3676 * be set up as multi-channel outputs.
3649 */ 3677 */
3650 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && 3678 if (is_dual_headphones(codec)) {
3651 spec->autocfg.hp_outs > 1) {
3652 /* Copy hp_outs to line_outs, backup line_outs in 3679 /* Copy hp_outs to line_outs, backup line_outs in
3653 * speaker_outs so that the following routines can handle 3680 * speaker_outs so that the following routines can handle
3654 * HP pins as primary outputs. 3681 * HP pins as primary outputs.
@@ -4329,6 +4356,28 @@ static void stac92xx_free_kctls(struct hda_codec *codec)
4329 snd_array_free(&spec->kctls); 4356 snd_array_free(&spec->kctls);
4330} 4357}
4331 4358
4359static void stac92xx_shutup(struct hda_codec *codec)
4360{
4361 struct sigmatel_spec *spec = codec->spec;
4362 int i;
4363 hda_nid_t nid;
4364
4365 /* reset each pin before powering down DAC/ADC to avoid click noise */
4366 nid = codec->start_nid;
4367 for (i = 0; i < codec->num_nodes; i++, nid++) {
4368 unsigned int wcaps = get_wcaps(codec, nid);
4369 unsigned int wid_type = get_wcaps_type(wcaps);
4370 if (wid_type == AC_WID_PIN)
4371 snd_hda_codec_read(codec, nid, 0,
4372 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4373 }
4374
4375 if (spec->eapd_mask)
4376 stac_gpio_set(codec, spec->gpio_mask,
4377 spec->gpio_dir, spec->gpio_data &
4378 ~spec->eapd_mask);
4379}
4380
4332static void stac92xx_free(struct hda_codec *codec) 4381static void stac92xx_free(struct hda_codec *codec)
4333{ 4382{
4334 struct sigmatel_spec *spec = codec->spec; 4383 struct sigmatel_spec *spec = codec->spec;
@@ -4336,6 +4385,7 @@ static void stac92xx_free(struct hda_codec *codec)
4336 if (! spec) 4385 if (! spec)
4337 return; 4386 return;
4338 4387
4388 stac92xx_shutup(codec);
4339 stac92xx_free_jacks(codec); 4389 stac92xx_free_jacks(codec);
4340 snd_array_free(&spec->events); 4390 snd_array_free(&spec->events);
4341 4391
@@ -4386,12 +4436,16 @@ static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4386 pin_ctl & ~flag); 4436 pin_ctl & ~flag);
4387} 4437}
4388 4438
4389static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) 4439static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4390{ 4440{
4391 if (!nid) 4441 if (!nid)
4392 return 0; 4442 return 0;
4393 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00) 4443 /* NOTE: we can't use snd_hda_jack_detect() here because STAC/IDT
4394 & (1 << 31)) 4444 * codecs behave wrongly when SET_PIN_SENSE is triggered, although
4445 * the pincap gives TRIG_REQ bit.
4446 */
4447 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0) &
4448 AC_PINSENSE_PRESENCE)
4395 return 1; 4449 return 1;
4396 return 0; 4450 return 0;
4397} 4451}
@@ -4791,28 +4845,28 @@ static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4791 4845
4792 return 0; 4846 return 0;
4793} 4847}
4794#endif
4795 4848
4796static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state) 4849static int idt92hd83xxx_hp_check_power_status(struct hda_codec *codec,
4850 hda_nid_t nid)
4797{ 4851{
4798 struct sigmatel_spec *spec = codec->spec; 4852 struct sigmatel_spec *spec = codec->spec;
4799 int i;
4800 hda_nid_t nid;
4801 4853
4802 /* reset each pin before powering down DAC/ADC to avoid click noise */ 4854 if (nid != 0x13)
4803 nid = codec->start_nid; 4855 return 0;
4804 for (i = 0; i < codec->num_nodes; i++, nid++) { 4856 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) & HDA_AMP_MUTE)
4805 unsigned int wcaps = get_wcaps(codec, nid); 4857 spec->gpio_data |= spec->gpio_led; /* mute LED on */
4806 unsigned int wid_type = get_wcaps_type(wcaps); 4858 else
4807 if (wid_type == AC_WID_PIN) 4859 spec->gpio_data &= ~spec->gpio_led; /* mute LED off */
4808 snd_hda_codec_read(codec, nid, 0, 4860 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
4809 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4810 }
4811 4861
4812 if (spec->eapd_mask) 4862 return 0;
4813 stac_gpio_set(codec, spec->gpio_mask, 4863}
4814 spec->gpio_dir, spec->gpio_data & 4864
4815 ~spec->eapd_mask); 4865#endif
4866
4867static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4868{
4869 stac92xx_shutup(codec);
4816 return 0; 4870 return 0;
4817} 4871}
4818#endif 4872#endif
@@ -4827,6 +4881,7 @@ static struct hda_codec_ops stac92xx_patch_ops = {
4827 .suspend = stac92xx_suspend, 4881 .suspend = stac92xx_suspend,
4828 .resume = stac92xx_resume, 4882 .resume = stac92xx_resume,
4829#endif 4883#endif
4884 .reboot_notify = stac92xx_shutup,
4830}; 4885};
4831 4886
4832static int patch_stac9200(struct hda_codec *codec) 4887static int patch_stac9200(struct hda_codec *codec)
@@ -5172,6 +5227,22 @@ again:
5172 break; 5227 break;
5173 } 5228 }
5174 5229
5230 codec->patch_ops = stac92xx_patch_ops;
5231
5232 if (spec->board_config == STAC_92HD83XXX_HP)
5233 spec->gpio_led = 0x01;
5234
5235#ifdef CONFIG_SND_HDA_POWER_SAVE
5236 if (spec->gpio_led) {
5237 spec->gpio_mask |= spec->gpio_led;
5238 spec->gpio_dir |= spec->gpio_led;
5239 spec->gpio_data |= spec->gpio_led;
5240 /* register check_power_status callback. */
5241 codec->patch_ops.check_power_status =
5242 idt92hd83xxx_hp_check_power_status;
5243 }
5244#endif
5245
5175 err = stac92xx_parse_auto_config(codec, 0x1d, 0); 5246 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5176 if (!err) { 5247 if (!err) {
5177 if (spec->board_config < 0) { 5248 if (spec->board_config < 0) {
@@ -5207,8 +5278,6 @@ again:
5207 snd_hda_codec_write_cache(codec, nid, 0, 5278 snd_hda_codec_write_cache(codec, nid, 0,
5208 AC_VERB_SET_CONNECT_SEL, num_dacs); 5279 AC_VERB_SET_CONNECT_SEL, num_dacs);
5209 5280
5210 codec->patch_ops = stac92xx_patch_ops;
5211
5212 codec->proc_widget_hook = stac92hd_proc_hook; 5281 codec->proc_widget_hook = stac92hd_proc_hook;
5213 5282
5214 return 0; 5283 return 0;
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index ee89db90c9b6..b70e26ad263f 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * Universal Interface for Intel High Definition Audio Codec 2 * Universal Interface for Intel High Definition Audio Codec
3 * 3 *
4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec 4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
5 * 5 *
6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com> 6 * (C) 2006-2009 VIA Technology, Inc.
7 * Takashi Iwai <tiwai@suse.de> 7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
8 * 8 *
9 * This driver is free software; you can redistribute it and/or modify 9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -22,21 +22,27 @@
22 */ 22 */
23 23
24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */ 24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
25/* */ 25/* */
26/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */ 26/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */ 27/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */ 28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ 29/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */ 30/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31/* 2007-09-17 Lydia Wang Add VT1708B codec support */ 31/* 2007-09-17 Lydia Wang Add VT1708B codec support */
32/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */ 32/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */ 33/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */ 34/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */ 35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36/* 2008-04-09 Lydia Wang Add Independent HP feature */ 36/* 2008-04-09 Lydia Wang Add Independent HP feature */
37/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */ 37/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */ 38/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39/* */ 39/* 2009-02-16 Logan Li Add support for VT1718S */
40/* 2009-03-13 Logan Li Add support for VT1716S */
41/* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42/* 2009-07-08 Lydia Wang Add support for VT2002P */
43/* 2009-07-21 Lydia Wang Add support for VT1812 */
44/* 2009-09-19 Lydia Wang Add support for VT1818S */
45/* */
40/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 46/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41 47
42 48
@@ -76,14 +82,6 @@
76#define VT1702_HP_NID 0x17 82#define VT1702_HP_NID 0x17
77#define VT1702_DIGOUT_NID 0x11 83#define VT1702_DIGOUT_NID 0x11
78 84
79#define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
80#define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
81#define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
82#define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
83#define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
84#define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
85#define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
86
87enum VIA_HDA_CODEC { 85enum VIA_HDA_CODEC {
88 UNKNOWN = -1, 86 UNKNOWN = -1,
89 VT1708, 87 VT1708,
@@ -92,12 +90,76 @@ enum VIA_HDA_CODEC {
92 VT1708B_8CH, 90 VT1708B_8CH,
93 VT1708B_4CH, 91 VT1708B_4CH,
94 VT1708S, 92 VT1708S,
93 VT1708BCE,
95 VT1702, 94 VT1702,
95 VT1718S,
96 VT1716S,
97 VT2002P,
98 VT1812,
96 CODEC_TYPES, 99 CODEC_TYPES,
97}; 100};
98 101
99static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) 102struct via_spec {
103 /* codec parameterization */
104 struct snd_kcontrol_new *mixers[6];
105 unsigned int num_mixers;
106
107 struct hda_verb *init_verbs[5];
108 unsigned int num_iverbs;
109
110 char *stream_name_analog;
111 struct hda_pcm_stream *stream_analog_playback;
112 struct hda_pcm_stream *stream_analog_capture;
113
114 char *stream_name_digital;
115 struct hda_pcm_stream *stream_digital_playback;
116 struct hda_pcm_stream *stream_digital_capture;
117
118 /* playback */
119 struct hda_multi_out multiout;
120 hda_nid_t slave_dig_outs[2];
121
122 /* capture */
123 unsigned int num_adc_nids;
124 hda_nid_t *adc_nids;
125 hda_nid_t mux_nids[3];
126 hda_nid_t dig_in_nid;
127 hda_nid_t dig_in_pin;
128
129 /* capture source */
130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
132
133 /* PCM information */
134 struct hda_pcm pcm_rec[3];
135
136 /* dynamic controls, init_verbs and input_mux */
137 struct auto_pin_cfg autocfg;
138 struct snd_array kctls;
139 struct hda_input_mux private_imux[2];
140 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
141
142 /* HP mode source */
143 const struct hda_input_mux *hp_mux;
144 unsigned int hp_independent_mode;
145 unsigned int hp_independent_mode_index;
146 unsigned int smart51_enabled;
147 unsigned int dmic_enabled;
148 enum VIA_HDA_CODEC codec_type;
149
150 /* work to check hp jack state */
151 struct hda_codec *codec;
152 struct delayed_work vt1708_hp_work;
153 int vt1708_jack_detectect;
154 int vt1708_hp_present;
155#ifdef CONFIG_SND_HDA_POWER_SAVE
156 struct hda_loopback_check loopback;
157#endif
158};
159
160static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
100{ 161{
162 u32 vendor_id = codec->vendor_id;
101 u16 ven_id = vendor_id >> 16; 163 u16 ven_id = vendor_id >> 16;
102 u16 dev_id = vendor_id & 0xffff; 164 u16 dev_id = vendor_id & 0xffff;
103 enum VIA_HDA_CODEC codec_type; 165 enum VIA_HDA_CODEC codec_type;
@@ -111,9 +173,11 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
111 codec_type = VT1709_10CH; 173 codec_type = VT1709_10CH;
112 else if (dev_id >= 0xe714 && dev_id <= 0xe717) 174 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
113 codec_type = VT1709_6CH; 175 codec_type = VT1709_6CH;
114 else if (dev_id >= 0xe720 && dev_id <= 0xe723) 176 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
115 codec_type = VT1708B_8CH; 177 codec_type = VT1708B_8CH;
116 else if (dev_id >= 0xe724 && dev_id <= 0xe727) 178 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
179 codec_type = VT1708BCE;
180 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
117 codec_type = VT1708B_4CH; 181 codec_type = VT1708B_4CH;
118 else if ((dev_id & 0xfff) == 0x397 182 else if ((dev_id & 0xfff) == 0x397
119 && (dev_id >> 12) < 8) 183 && (dev_id >> 12) < 8)
@@ -121,6 +185,19 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
121 else if ((dev_id & 0xfff) == 0x398 185 else if ((dev_id & 0xfff) == 0x398
122 && (dev_id >> 12) < 8) 186 && (dev_id >> 12) < 8)
123 codec_type = VT1702; 187 codec_type = VT1702;
188 else if ((dev_id & 0xfff) == 0x428
189 && (dev_id >> 12) < 8)
190 codec_type = VT1718S;
191 else if (dev_id == 0x0433 || dev_id == 0xa721)
192 codec_type = VT1716S;
193 else if (dev_id == 0x0441 || dev_id == 0x4441)
194 codec_type = VT1718S;
195 else if (dev_id == 0x0438 || dev_id == 0x4438)
196 codec_type = VT2002P;
197 else if (dev_id == 0x0448)
198 codec_type = VT1812;
199 else if (dev_id == 0x0440)
200 codec_type = VT1708S;
124 else 201 else
125 codec_type = UNKNOWN; 202 codec_type = UNKNOWN;
126 return codec_type; 203 return codec_type;
@@ -128,10 +205,16 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
128 205
129#define VIA_HP_EVENT 0x01 206#define VIA_HP_EVENT 0x01
130#define VIA_GPIO_EVENT 0x02 207#define VIA_GPIO_EVENT 0x02
208#define VIA_JACK_EVENT 0x04
209#define VIA_MONO_EVENT 0x08
210#define VIA_SPEAKER_EVENT 0x10
211#define VIA_BIND_HP_EVENT 0x20
131 212
132enum { 213enum {
133 VIA_CTL_WIDGET_VOL, 214 VIA_CTL_WIDGET_VOL,
134 VIA_CTL_WIDGET_MUTE, 215 VIA_CTL_WIDGET_MUTE,
216 VIA_CTL_WIDGET_ANALOG_MUTE,
217 VIA_CTL_WIDGET_BIND_PIN_MUTE,
135}; 218};
136 219
137enum { 220enum {
@@ -141,99 +224,162 @@ enum {
141 AUTO_SEQ_SIDE 224 AUTO_SEQ_SIDE
142}; 225};
143 226
144/* Some VT1708S based boards gets the micboost setting wrong, so we have 227static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
145 * to apply some brute-force and re-write the TLV's by software. */ 228static void set_jack_power_state(struct hda_codec *codec);
146static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag, 229static int is_aa_path_mute(struct hda_codec *codec);
147 unsigned int size, unsigned int __user *_tlv) 230
231static void vt1708_start_hp_work(struct via_spec *spec)
148{ 232{
149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 233 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
150 hda_nid_t nid = get_amp_nid(kcontrol); 234 return;
235 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
236 !spec->vt1708_jack_detectect);
237 if (!delayed_work_pending(&spec->vt1708_hp_work))
238 schedule_delayed_work(&spec->vt1708_hp_work,
239 msecs_to_jiffies(100));
240}
151 241
152 if (get_codec_type(codec->vendor_id) == VT1708S 242static void vt1708_stop_hp_work(struct via_spec *spec)
153 && (nid == 0x1a || nid == 0x1e)) { 243{
154 if (size < 4 * sizeof(unsigned int)) 244 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
155 return -ENOMEM; 245 return;
156 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */ 246 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
157 return -EFAULT; 247 && !is_aa_path_mute(spec->codec))
158 if (put_user(2 * sizeof(unsigned int), _tlv + 1)) 248 return;
159 return -EFAULT; 249 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
160 if (put_user(0, _tlv + 2)) /* offset = 0 */ 250 !spec->vt1708_jack_detectect);
161 return -EFAULT; 251 cancel_delayed_work(&spec->vt1708_hp_work);
162 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */ 252 flush_scheduled_work();
163 return -EFAULT;
164 }
165 return 0;
166} 253}
167 254
168static int mic_boost_volume_info(struct snd_kcontrol *kcontrol, 255
169 struct snd_ctl_elem_info *uinfo) 256static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
170{ 258{
259 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
172 hda_nid_t nid = get_amp_nid(kcontrol);
173 261
174 if (get_codec_type(codec->vendor_id) == VT1708S 262 set_jack_power_state(codec);
175 && (nid == 0x1a || nid == 0x1e)) { 263 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
176 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 264 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
177 uinfo->count = 2; 265 if (is_aa_path_mute(codec))
178 uinfo->value.integer.min = 0; 266 vt1708_start_hp_work(codec->spec);
179 uinfo->value.integer.max = 3; 267 else
268 vt1708_stop_hp_work(codec->spec);
180 } 269 }
181 return 0; 270 return change;
182} 271}
183 272
184static struct snd_kcontrol_new vt1708_control_templates[] = { 273/* modify .put = snd_hda_mixer_amp_switch_put */
185 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 274#define ANALOG_INPUT_MUTE \
186 HDA_CODEC_MUTE(NULL, 0, 0, 0), 275 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
187}; 276 .name = NULL, \
188 277 .index = 0, \
189 278 .info = snd_hda_mixer_amp_switch_info, \
190struct via_spec { 279 .get = snd_hda_mixer_amp_switch_get, \
191 /* codec parameterization */ 280 .put = analog_input_switch_put, \
192 struct snd_kcontrol_new *mixers[3]; 281 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
193 unsigned int num_mixers;
194 282
195 struct hda_verb *init_verbs[5]; 283static void via_hp_bind_automute(struct hda_codec *codec);
196 unsigned int num_iverbs;
197 284
198 char *stream_name_analog; 285static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
199 struct hda_pcm_stream *stream_analog_playback; 286 struct snd_ctl_elem_value *ucontrol)
200 struct hda_pcm_stream *stream_analog_capture; 287{
201 288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
202 char *stream_name_digital; 289 struct via_spec *spec = codec->spec;
203 struct hda_pcm_stream *stream_digital_playback; 290 int i;
204 struct hda_pcm_stream *stream_digital_capture; 291 int change = 0;
205
206 /* playback */
207 struct hda_multi_out multiout;
208 hda_nid_t slave_dig_outs[2];
209
210 /* capture */
211 unsigned int num_adc_nids;
212 hda_nid_t *adc_nids;
213 hda_nid_t mux_nids[3];
214 hda_nid_t dig_in_nid;
215 hda_nid_t dig_in_pin;
216 292
217 /* capture source */ 293 long *valp = ucontrol->value.integer.value;
218 const struct hda_input_mux *input_mux; 294 int lmute, rmute;
219 unsigned int cur_mux[3]; 295 if (strstr(kcontrol->id.name, "Switch") == NULL) {
296 snd_printd("Invalid control!\n");
297 return change;
298 }
299 change = snd_hda_mixer_amp_switch_put(kcontrol,
300 ucontrol);
301 /* Get mute value */
302 lmute = *valp ? 0 : HDA_AMP_MUTE;
303 valp++;
304 rmute = *valp ? 0 : HDA_AMP_MUTE;
305
306 /* Set hp pins */
307 if (!spec->hp_independent_mode) {
308 for (i = 0; i < spec->autocfg.hp_outs; i++) {
309 snd_hda_codec_amp_update(
310 codec, spec->autocfg.hp_pins[i],
311 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
312 lmute);
313 snd_hda_codec_amp_update(
314 codec, spec->autocfg.hp_pins[i],
315 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
316 rmute);
317 }
318 }
220 319
221 /* PCM information */ 320 if (!lmute && !rmute) {
222 struct hda_pcm pcm_rec[3]; 321 /* Line Outs */
322 for (i = 0; i < spec->autocfg.line_outs; i++)
323 snd_hda_codec_amp_stereo(
324 codec, spec->autocfg.line_out_pins[i],
325 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
326 /* Speakers */
327 for (i = 0; i < spec->autocfg.speaker_outs; i++)
328 snd_hda_codec_amp_stereo(
329 codec, spec->autocfg.speaker_pins[i],
330 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
331 /* unmute */
332 via_hp_bind_automute(codec);
223 333
224 /* dynamic controls, init_verbs and input_mux */ 334 } else {
225 struct auto_pin_cfg autocfg; 335 if (lmute) {
226 struct snd_array kctls; 336 /* Mute all left channels */
227 struct hda_input_mux private_imux[2]; 337 for (i = 1; i < spec->autocfg.line_outs; i++)
228 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 338 snd_hda_codec_amp_update(
339 codec,
340 spec->autocfg.line_out_pins[i],
341 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
342 lmute);
343 for (i = 0; i < spec->autocfg.speaker_outs; i++)
344 snd_hda_codec_amp_update(
345 codec,
346 spec->autocfg.speaker_pins[i],
347 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
348 lmute);
349 }
350 if (rmute) {
351 /* mute all right channels */
352 for (i = 1; i < spec->autocfg.line_outs; i++)
353 snd_hda_codec_amp_update(
354 codec,
355 spec->autocfg.line_out_pins[i],
356 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
357 rmute);
358 for (i = 0; i < spec->autocfg.speaker_outs; i++)
359 snd_hda_codec_amp_update(
360 codec,
361 spec->autocfg.speaker_pins[i],
362 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
363 rmute);
364 }
365 }
366 return change;
367}
229 368
230 /* HP mode source */ 369#define BIND_PIN_MUTE \
231 const struct hda_input_mux *hp_mux; 370 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
232 unsigned int hp_independent_mode; 371 .name = NULL, \
372 .index = 0, \
373 .info = snd_hda_mixer_amp_switch_info, \
374 .get = snd_hda_mixer_amp_switch_get, \
375 .put = bind_pin_switch_put, \
376 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
233 377
234#ifdef CONFIG_SND_HDA_POWER_SAVE 378static struct snd_kcontrol_new via_control_templates[] = {
235 struct hda_loopback_check loopback; 379 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
236#endif 380 HDA_CODEC_MUTE(NULL, 0, 0, 0),
381 ANALOG_INPUT_MUTE,
382 BIND_PIN_MUTE,
237}; 383};
238 384
239static hda_nid_t vt1708_adc_nids[2] = { 385static hda_nid_t vt1708_adc_nids[2] = {
@@ -261,6 +407,27 @@ static hda_nid_t vt1702_adc_nids[3] = {
261 0x12, 0x20, 0x1F 407 0x12, 0x20, 0x1F
262}; 408};
263 409
410static hda_nid_t vt1718S_adc_nids[2] = {
411 /* ADC1-2 */
412 0x10, 0x11
413};
414
415static hda_nid_t vt1716S_adc_nids[2] = {
416 /* ADC1-2 */
417 0x13, 0x14
418};
419
420static hda_nid_t vt2002P_adc_nids[2] = {
421 /* ADC1-2 */
422 0x10, 0x11
423};
424
425static hda_nid_t vt1812_adc_nids[2] = {
426 /* ADC1-2 */
427 0x10, 0x11
428};
429
430
264/* add dynamic controls */ 431/* add dynamic controls */
265static int via_add_control(struct via_spec *spec, int type, const char *name, 432static int via_add_control(struct via_spec *spec, int type, const char *name,
266 unsigned long val) 433 unsigned long val)
@@ -271,10 +438,12 @@ static int via_add_control(struct via_spec *spec, int type, const char *name,
271 knew = snd_array_new(&spec->kctls); 438 knew = snd_array_new(&spec->kctls);
272 if (!knew) 439 if (!knew)
273 return -ENOMEM; 440 return -ENOMEM;
274 *knew = vt1708_control_templates[type]; 441 *knew = via_control_templates[type];
275 knew->name = kstrdup(name, GFP_KERNEL); 442 knew->name = kstrdup(name, GFP_KERNEL);
276 if (!knew->name) 443 if (!knew->name)
277 return -ENOMEM; 444 return -ENOMEM;
445 if (get_amp_nid_(val))
446 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
278 knew->private_value = val; 447 knew->private_value = val;
279 return 0; 448 return 0;
280} 449}
@@ -293,8 +462,8 @@ static void via_free_kctls(struct hda_codec *codec)
293} 462}
294 463
295/* create input playback/capture controls for the given pin */ 464/* create input playback/capture controls for the given pin */
296static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin, 465static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
297 const char *ctlname, int idx, int mix_nid) 466 int idx, int mix_nid)
298{ 467{
299 char name[32]; 468 char name[32];
300 int err; 469 int err;
@@ -305,7 +474,7 @@ static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
305 if (err < 0) 474 if (err < 0)
306 return err; 475 return err;
307 sprintf(name, "%s Playback Switch", ctlname); 476 sprintf(name, "%s Playback Switch", ctlname);
308 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 477 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
309 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); 478 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
310 if (err < 0) 479 if (err < 0)
311 return err; 480 return err;
@@ -322,7 +491,7 @@ static void via_auto_set_output_and_unmute(struct hda_codec *codec,
322 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 491 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
323 AMP_OUT_UNMUTE); 492 AMP_OUT_UNMUTE);
324 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) 493 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
325 snd_hda_codec_write(codec, nid, 0, 494 snd_hda_codec_write(codec, nid, 0,
326 AC_VERB_SET_EAPD_BTLENABLE, 0x02); 495 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
327} 496}
328 497
@@ -343,10 +512,13 @@ static void via_auto_init_hp_out(struct hda_codec *codec)
343{ 512{
344 struct via_spec *spec = codec->spec; 513 struct via_spec *spec = codec->spec;
345 hda_nid_t pin; 514 hda_nid_t pin;
515 int i;
346 516
347 pin = spec->autocfg.hp_pins[0]; 517 for (i = 0; i < spec->autocfg.hp_outs; i++) {
348 if (pin) /* connect to front */ 518 pin = spec->autocfg.hp_pins[i];
349 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 519 if (pin) /* connect to front */
520 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
521 }
350} 522}
351 523
352static void via_auto_init_analog_input(struct hda_codec *codec) 524static void via_auto_init_analog_input(struct hda_codec *codec)
@@ -364,6 +536,502 @@ static void via_auto_init_analog_input(struct hda_codec *codec)
364 536
365 } 537 }
366} 538}
539
540static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
541
542static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
543 unsigned int *affected_parm)
544{
545 unsigned parm;
546 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
547 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
548 >> AC_DEFCFG_MISC_SHIFT
549 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
550 unsigned present = snd_hda_jack_detect(codec, nid);
551 struct via_spec *spec = codec->spec;
552 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
553 || ((no_presence || present)
554 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
555 *affected_parm = AC_PWRST_D0; /* if it's connected */
556 parm = AC_PWRST_D0;
557 } else
558 parm = AC_PWRST_D3;
559
560 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
561}
562
563static void set_jack_power_state(struct hda_codec *codec)
564{
565 struct via_spec *spec = codec->spec;
566 int imux_is_smixer;
567 unsigned int parm;
568
569 if (spec->codec_type == VT1702) {
570 imux_is_smixer = snd_hda_codec_read(
571 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
572 /* inputs */
573 /* PW 1/2/5 (14h/15h/18h) */
574 parm = AC_PWRST_D3;
575 set_pin_power_state(codec, 0x14, &parm);
576 set_pin_power_state(codec, 0x15, &parm);
577 set_pin_power_state(codec, 0x18, &parm);
578 if (imux_is_smixer)
579 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
580 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
581 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
582 parm);
583 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
584 parm);
585 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
586 parm);
587 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
588 parm);
589
590 /* outputs */
591 /* PW 3/4 (16h/17h) */
592 parm = AC_PWRST_D3;
593 set_pin_power_state(codec, 0x16, &parm);
594 set_pin_power_state(codec, 0x17, &parm);
595 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
596 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
597 imux_is_smixer ? AC_PWRST_D0 : parm);
598 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
599 parm);
600 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
601 parm);
602 } else if (spec->codec_type == VT1708B_8CH
603 || spec->codec_type == VT1708B_4CH
604 || spec->codec_type == VT1708S) {
605 /* SW0 (17h) = stereo mixer */
606 int is_8ch = spec->codec_type != VT1708B_4CH;
607 imux_is_smixer = snd_hda_codec_read(
608 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
609 == ((spec->codec_type == VT1708S) ? 5 : 0);
610 /* inputs */
611 /* PW 1/2/5 (1ah/1bh/1eh) */
612 parm = AC_PWRST_D3;
613 set_pin_power_state(codec, 0x1a, &parm);
614 set_pin_power_state(codec, 0x1b, &parm);
615 set_pin_power_state(codec, 0x1e, &parm);
616 if (imux_is_smixer)
617 parm = AC_PWRST_D0;
618 /* SW0 (17h), AIW 0/1 (13h/14h) */
619 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
620 parm);
621 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
622 parm);
623 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
624 parm);
625
626 /* outputs */
627 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
628 parm = AC_PWRST_D3;
629 set_pin_power_state(codec, 0x19, &parm);
630 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
631 parm);
632 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
633 parm);
634
635 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
636 if (is_8ch) {
637 parm = AC_PWRST_D3;
638 set_pin_power_state(codec, 0x22, &parm);
639 snd_hda_codec_write(codec, 0x26, 0,
640 AC_VERB_SET_POWER_STATE, parm);
641 snd_hda_codec_write(codec, 0x24, 0,
642 AC_VERB_SET_POWER_STATE, parm);
643 }
644
645 /* PW 3/4/7 (1ch/1dh/23h) */
646 parm = AC_PWRST_D3;
647 /* force to D0 for internal Speaker */
648 set_pin_power_state(codec, 0x1c, &parm);
649 set_pin_power_state(codec, 0x1d, &parm);
650 if (is_8ch)
651 set_pin_power_state(codec, 0x23, &parm);
652 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
653 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
654 imux_is_smixer ? AC_PWRST_D0 : parm);
655 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
656 parm);
657 if (is_8ch) {
658 snd_hda_codec_write(codec, 0x25, 0,
659 AC_VERB_SET_POWER_STATE, parm);
660 snd_hda_codec_write(codec, 0x27, 0,
661 AC_VERB_SET_POWER_STATE, parm);
662 }
663 } else if (spec->codec_type == VT1718S) {
664 /* MUX6 (1eh) = stereo mixer */
665 imux_is_smixer = snd_hda_codec_read(
666 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
667 /* inputs */
668 /* PW 5/6/7 (29h/2ah/2bh) */
669 parm = AC_PWRST_D3;
670 set_pin_power_state(codec, 0x29, &parm);
671 set_pin_power_state(codec, 0x2a, &parm);
672 set_pin_power_state(codec, 0x2b, &parm);
673 if (imux_is_smixer)
674 parm = AC_PWRST_D0;
675 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
676 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
677 parm);
678 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
679 parm);
680 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
681 parm);
682 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
683 parm);
684
685 /* outputs */
686 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
687 parm = AC_PWRST_D3;
688 set_pin_power_state(codec, 0x27, &parm);
689 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
690 parm);
691 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
692 parm);
693
694 /* PW2 (26h), AOW2 (ah) */
695 parm = AC_PWRST_D3;
696 set_pin_power_state(codec, 0x26, &parm);
697 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
698 parm);
699
700 /* PW0/1 (24h/25h) */
701 parm = AC_PWRST_D3;
702 set_pin_power_state(codec, 0x24, &parm);
703 set_pin_power_state(codec, 0x25, &parm);
704 if (!spec->hp_independent_mode) /* check for redirected HP */
705 set_pin_power_state(codec, 0x28, &parm);
706 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
707 parm);
708 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
709 parm);
710 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
711 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
712 imux_is_smixer ? AC_PWRST_D0 : parm);
713 if (spec->hp_independent_mode) {
714 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
715 parm = AC_PWRST_D3;
716 set_pin_power_state(codec, 0x28, &parm);
717 snd_hda_codec_write(codec, 0x1b, 0,
718 AC_VERB_SET_POWER_STATE, parm);
719 snd_hda_codec_write(codec, 0x34, 0,
720 AC_VERB_SET_POWER_STATE, parm);
721 snd_hda_codec_write(codec, 0xc, 0,
722 AC_VERB_SET_POWER_STATE, parm);
723 }
724 } else if (spec->codec_type == VT1716S) {
725 unsigned int mono_out, present;
726 /* SW0 (17h) = stereo mixer */
727 imux_is_smixer = snd_hda_codec_read(
728 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
729 /* inputs */
730 /* PW 1/2/5 (1ah/1bh/1eh) */
731 parm = AC_PWRST_D3;
732 set_pin_power_state(codec, 0x1a, &parm);
733 set_pin_power_state(codec, 0x1b, &parm);
734 set_pin_power_state(codec, 0x1e, &parm);
735 if (imux_is_smixer)
736 parm = AC_PWRST_D0;
737 /* SW0 (17h), AIW0(13h) */
738 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
739 parm);
740 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
741 parm);
742
743 parm = AC_PWRST_D3;
744 set_pin_power_state(codec, 0x1e, &parm);
745 /* PW11 (22h) */
746 if (spec->dmic_enabled)
747 set_pin_power_state(codec, 0x22, &parm);
748 else
749 snd_hda_codec_write(
750 codec, 0x22, 0,
751 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
752
753 /* SW2(26h), AIW1(14h) */
754 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
755 parm);
756 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
757 parm);
758
759 /* outputs */
760 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
761 parm = AC_PWRST_D3;
762 set_pin_power_state(codec, 0x19, &parm);
763 /* Smart 5.1 PW2(1bh) */
764 if (spec->smart51_enabled)
765 set_pin_power_state(codec, 0x1b, &parm);
766 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
767 parm);
768 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
769 parm);
770
771 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
772 parm = AC_PWRST_D3;
773 set_pin_power_state(codec, 0x23, &parm);
774 /* Smart 5.1 PW1(1ah) */
775 if (spec->smart51_enabled)
776 set_pin_power_state(codec, 0x1a, &parm);
777 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
778 parm);
779
780 /* Smart 5.1 PW5(1eh) */
781 if (spec->smart51_enabled)
782 set_pin_power_state(codec, 0x1e, &parm);
783 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
784 parm);
785
786 /* Mono out */
787 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
788 present = snd_hda_jack_detect(codec, 0x1c);
789 if (present)
790 mono_out = 0;
791 else {
792 present = snd_hda_jack_detect(codec, 0x1d);
793 if (!spec->hp_independent_mode && present)
794 mono_out = 0;
795 else
796 mono_out = 1;
797 }
798 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
799 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
800 parm);
801 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
802 parm);
803 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
804 parm);
805
806 /* PW 3/4 (1ch/1dh) */
807 parm = AC_PWRST_D3;
808 set_pin_power_state(codec, 0x1c, &parm);
809 set_pin_power_state(codec, 0x1d, &parm);
810 /* HP Independent Mode, power on AOW3 */
811 if (spec->hp_independent_mode)
812 snd_hda_codec_write(codec, 0x25, 0,
813 AC_VERB_SET_POWER_STATE, parm);
814
815 /* force to D0 for internal Speaker */
816 /* MW0 (16h), AOW0 (10h) */
817 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
818 imux_is_smixer ? AC_PWRST_D0 : parm);
819 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
820 mono_out ? AC_PWRST_D0 : parm);
821 } else if (spec->codec_type == VT2002P) {
822 unsigned int present;
823 /* MUX9 (1eh) = stereo mixer */
824 imux_is_smixer = snd_hda_codec_read(
825 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
826 /* inputs */
827 /* PW 5/6/7 (29h/2ah/2bh) */
828 parm = AC_PWRST_D3;
829 set_pin_power_state(codec, 0x29, &parm);
830 set_pin_power_state(codec, 0x2a, &parm);
831 set_pin_power_state(codec, 0x2b, &parm);
832 if (imux_is_smixer)
833 parm = AC_PWRST_D0;
834 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
835 snd_hda_codec_write(codec, 0x1e, 0,
836 AC_VERB_SET_POWER_STATE, parm);
837 snd_hda_codec_write(codec, 0x1f, 0,
838 AC_VERB_SET_POWER_STATE, parm);
839 snd_hda_codec_write(codec, 0x10, 0,
840 AC_VERB_SET_POWER_STATE, parm);
841 snd_hda_codec_write(codec, 0x11, 0,
842 AC_VERB_SET_POWER_STATE, parm);
843
844 /* outputs */
845 /* AOW0 (8h)*/
846 snd_hda_codec_write(codec, 0x8, 0,
847 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
848
849 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
850 parm = AC_PWRST_D3;
851 set_pin_power_state(codec, 0x26, &parm);
852 snd_hda_codec_write(codec, 0x1c, 0,
853 AC_VERB_SET_POWER_STATE, parm);
854 snd_hda_codec_write(codec, 0x37,
855 0, AC_VERB_SET_POWER_STATE, parm);
856
857 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
858 parm = AC_PWRST_D3;
859 set_pin_power_state(codec, 0x25, &parm);
860 snd_hda_codec_write(codec, 0x19, 0,
861 AC_VERB_SET_POWER_STATE, parm);
862 snd_hda_codec_write(codec, 0x35, 0,
863 AC_VERB_SET_POWER_STATE, parm);
864 if (spec->hp_independent_mode) {
865 snd_hda_codec_write(codec, 0x9, 0,
866 AC_VERB_SET_POWER_STATE, parm);
867 }
868
869 /* Class-D */
870 /* PW0 (24h), MW0(18h), MUX0(34h) */
871 present = snd_hda_jack_detect(codec, 0x25);
872 parm = AC_PWRST_D3;
873 set_pin_power_state(codec, 0x24, &parm);
874 if (present) {
875 snd_hda_codec_write(
876 codec, 0x18, 0,
877 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
878 snd_hda_codec_write(
879 codec, 0x34, 0,
880 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
881 } else {
882 snd_hda_codec_write(
883 codec, 0x18, 0,
884 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
885 snd_hda_codec_write(
886 codec, 0x34, 0,
887 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
888 }
889
890 /* Mono Out */
891 /* PW15 (31h), MW8(17h), MUX8(3bh) */
892 present = snd_hda_jack_detect(codec, 0x26);
893 parm = AC_PWRST_D3;
894 set_pin_power_state(codec, 0x31, &parm);
895 if (present) {
896 snd_hda_codec_write(
897 codec, 0x17, 0,
898 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
899 snd_hda_codec_write(
900 codec, 0x3b, 0,
901 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
902 } else {
903 snd_hda_codec_write(
904 codec, 0x17, 0,
905 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
906 snd_hda_codec_write(
907 codec, 0x3b, 0,
908 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
909 }
910
911 /* MW9 (21h) */
912 if (imux_is_smixer || !is_aa_path_mute(codec))
913 snd_hda_codec_write(
914 codec, 0x21, 0,
915 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
916 else
917 snd_hda_codec_write(
918 codec, 0x21, 0,
919 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
920 } else if (spec->codec_type == VT1812) {
921 unsigned int present;
922 /* MUX10 (1eh) = stereo mixer */
923 imux_is_smixer = snd_hda_codec_read(
924 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
925 /* inputs */
926 /* PW 5/6/7 (29h/2ah/2bh) */
927 parm = AC_PWRST_D3;
928 set_pin_power_state(codec, 0x29, &parm);
929 set_pin_power_state(codec, 0x2a, &parm);
930 set_pin_power_state(codec, 0x2b, &parm);
931 if (imux_is_smixer)
932 parm = AC_PWRST_D0;
933 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
934 snd_hda_codec_write(codec, 0x1e, 0,
935 AC_VERB_SET_POWER_STATE, parm);
936 snd_hda_codec_write(codec, 0x1f, 0,
937 AC_VERB_SET_POWER_STATE, parm);
938 snd_hda_codec_write(codec, 0x10, 0,
939 AC_VERB_SET_POWER_STATE, parm);
940 snd_hda_codec_write(codec, 0x11, 0,
941 AC_VERB_SET_POWER_STATE, parm);
942
943 /* outputs */
944 /* AOW0 (8h)*/
945 snd_hda_codec_write(codec, 0x8, 0,
946 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
947
948 /* PW4 (28h), MW4 (18h), MUX4(38h) */
949 parm = AC_PWRST_D3;
950 set_pin_power_state(codec, 0x28, &parm);
951 snd_hda_codec_write(codec, 0x18, 0,
952 AC_VERB_SET_POWER_STATE, parm);
953 snd_hda_codec_write(codec, 0x38, 0,
954 AC_VERB_SET_POWER_STATE, parm);
955
956 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
957 parm = AC_PWRST_D3;
958 set_pin_power_state(codec, 0x25, &parm);
959 snd_hda_codec_write(codec, 0x15, 0,
960 AC_VERB_SET_POWER_STATE, parm);
961 snd_hda_codec_write(codec, 0x35, 0,
962 AC_VERB_SET_POWER_STATE, parm);
963 if (spec->hp_independent_mode) {
964 snd_hda_codec_write(codec, 0x9, 0,
965 AC_VERB_SET_POWER_STATE, parm);
966 }
967
968 /* Internal Speaker */
969 /* PW0 (24h), MW0(14h), MUX0(34h) */
970 present = snd_hda_jack_detect(codec, 0x25);
971 parm = AC_PWRST_D3;
972 set_pin_power_state(codec, 0x24, &parm);
973 if (present) {
974 snd_hda_codec_write(codec, 0x14, 0,
975 AC_VERB_SET_POWER_STATE,
976 AC_PWRST_D3);
977 snd_hda_codec_write(codec, 0x34, 0,
978 AC_VERB_SET_POWER_STATE,
979 AC_PWRST_D3);
980 } else {
981 snd_hda_codec_write(codec, 0x14, 0,
982 AC_VERB_SET_POWER_STATE,
983 AC_PWRST_D0);
984 snd_hda_codec_write(codec, 0x34, 0,
985 AC_VERB_SET_POWER_STATE,
986 AC_PWRST_D0);
987 }
988 /* Mono Out */
989 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
990 present = snd_hda_jack_detect(codec, 0x28);
991 parm = AC_PWRST_D3;
992 set_pin_power_state(codec, 0x31, &parm);
993 if (present) {
994 snd_hda_codec_write(codec, 0x1c, 0,
995 AC_VERB_SET_POWER_STATE,
996 AC_PWRST_D3);
997 snd_hda_codec_write(codec, 0x3c, 0,
998 AC_VERB_SET_POWER_STATE,
999 AC_PWRST_D3);
1000 snd_hda_codec_write(codec, 0x3e, 0,
1001 AC_VERB_SET_POWER_STATE,
1002 AC_PWRST_D3);
1003 } else {
1004 snd_hda_codec_write(codec, 0x1c, 0,
1005 AC_VERB_SET_POWER_STATE,
1006 AC_PWRST_D0);
1007 snd_hda_codec_write(codec, 0x3c, 0,
1008 AC_VERB_SET_POWER_STATE,
1009 AC_PWRST_D0);
1010 snd_hda_codec_write(codec, 0x3e, 0,
1011 AC_VERB_SET_POWER_STATE,
1012 AC_PWRST_D0);
1013 }
1014
1015 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1016 parm = AC_PWRST_D3;
1017 set_pin_power_state(codec, 0x33, &parm);
1018 snd_hda_codec_write(codec, 0x1d, 0,
1019 AC_VERB_SET_POWER_STATE, parm);
1020 snd_hda_codec_write(codec, 0x3d, 0,
1021 AC_VERB_SET_POWER_STATE, parm);
1022
1023 /* MW9 (21h) */
1024 if (imux_is_smixer || !is_aa_path_mute(codec))
1025 snd_hda_codec_write(
1026 codec, 0x21, 0,
1027 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1028 else
1029 snd_hda_codec_write(
1030 codec, 0x21, 0,
1031 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1032 }
1033}
1034
367/* 1035/*
368 * input MUX handling 1036 * input MUX handling
369 */ 1037 */
@@ -395,6 +1063,14 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
395 1063
396 if (!spec->mux_nids[adc_idx]) 1064 if (!spec->mux_nids[adc_idx])
397 return -EINVAL; 1065 return -EINVAL;
1066 /* switch to D0 beofre change index */
1067 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1068 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1069 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1070 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1071 /* update jack power state */
1072 set_jack_power_state(codec);
1073
398 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 1074 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
399 spec->mux_nids[adc_idx], 1075 spec->mux_nids[adc_idx],
400 &spec->cur_mux[adc_idx]); 1076 &spec->cur_mux[adc_idx]);
@@ -413,16 +1089,74 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
413{ 1089{
414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
415 struct via_spec *spec = codec->spec; 1091 struct via_spec *spec = codec->spec;
416 hda_nid_t nid = spec->autocfg.hp_pins[0]; 1092 hda_nid_t nid;
417 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0, 1093 unsigned int pinsel;
418 AC_VERB_GET_CONNECT_SEL, 1094
419 0x00); 1095 switch (spec->codec_type) {
420 1096 case VT1718S:
1097 nid = 0x34;
1098 break;
1099 case VT2002P:
1100 nid = 0x35;
1101 break;
1102 case VT1812:
1103 nid = 0x3d;
1104 break;
1105 default:
1106 nid = spec->autocfg.hp_pins[0];
1107 break;
1108 }
1109 /* use !! to translate conn sel 2 for VT1718S */
1110 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1111 AC_VERB_GET_CONNECT_SEL,
1112 0x00);
421 ucontrol->value.enumerated.item[0] = pinsel; 1113 ucontrol->value.enumerated.item[0] = pinsel;
422 1114
423 return 0; 1115 return 0;
424} 1116}
425 1117
1118static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1119{
1120 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1121 if (ctl) {
1122 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1123 ctl->vd[0].access |= active
1124 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1125 snd_ctl_notify(codec->bus->card,
1126 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1127 }
1128}
1129
1130static int update_side_mute_status(struct hda_codec *codec)
1131{
1132 /* mute side channel */
1133 struct via_spec *spec = codec->spec;
1134 unsigned int parm = spec->hp_independent_mode
1135 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1136 hda_nid_t sw3;
1137
1138 switch (spec->codec_type) {
1139 case VT1708:
1140 sw3 = 0x1b;
1141 break;
1142 case VT1709_10CH:
1143 sw3 = 0x29;
1144 break;
1145 case VT1708B_8CH:
1146 case VT1708S:
1147 sw3 = 0x27;
1148 break;
1149 default:
1150 sw3 = 0;
1151 break;
1152 }
1153
1154 if (sw3)
1155 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1156 parm);
1157 return 0;
1158}
1159
426static int via_independent_hp_put(struct snd_kcontrol *kcontrol, 1160static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol) 1161 struct snd_ctl_elem_value *ucontrol)
428{ 1162{
@@ -430,47 +1164,46 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
430 struct via_spec *spec = codec->spec; 1164 struct via_spec *spec = codec->spec;
431 hda_nid_t nid = spec->autocfg.hp_pins[0]; 1165 hda_nid_t nid = spec->autocfg.hp_pins[0];
432 unsigned int pinsel = ucontrol->value.enumerated.item[0]; 1166 unsigned int pinsel = ucontrol->value.enumerated.item[0];
433 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0, 1167 /* Get Independent Mode index of headphone pin widget */
434 AC_VERB_GET_CONNECT_LIST, 0) & 0xff; 1168 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
435 1169 ? 1 : 0;
436 if (con_nid == spec->multiout.hp_nid) { 1170
437 if (pinsel == 0) { 1171 switch (spec->codec_type) {
438 if (!spec->hp_independent_mode) { 1172 case VT1718S:
439 if (spec->multiout.num_dacs > 1) 1173 nid = 0x34;
440 spec->multiout.num_dacs -= 1; 1174 pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
441 spec->hp_independent_mode = 1; 1175 spec->multiout.num_dacs = 4;
442 } 1176 break;
443 } else if (pinsel == 1) { 1177 case VT2002P:
444 if (spec->hp_independent_mode) { 1178 nid = 0x35;
445 if (spec->multiout.num_dacs > 1) 1179 break;
446 spec->multiout.num_dacs += 1; 1180 case VT1812:
447 spec->hp_independent_mode = 0; 1181 nid = 0x3d;
448 } 1182 break;
449 } 1183 default:
450 } else { 1184 nid = spec->autocfg.hp_pins[0];
451 if (pinsel == 0) { 1185 break;
452 if (spec->hp_independent_mode) { 1186 }
453 if (spec->multiout.num_dacs > 1) 1187 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
454 spec->multiout.num_dacs += 1; 1188
455 spec->hp_independent_mode = 0; 1189 if (spec->multiout.hp_nid && spec->multiout.hp_nid
456 } 1190 != spec->multiout.dac_nids[HDA_FRONT])
457 } else if (pinsel == 1) { 1191 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
458 if (!spec->hp_independent_mode) { 1192 0, 0, 0);
459 if (spec->multiout.num_dacs > 1) 1193
460 spec->multiout.num_dacs -= 1; 1194 update_side_mute_status(codec);
461 spec->hp_independent_mode = 1; 1195 /* update HP volume/swtich active state */
462 } 1196 if (spec->codec_type == VT1708S
463 } 1197 || spec->codec_type == VT1702
1198 || spec->codec_type == VT1718S
1199 || spec->codec_type == VT1716S
1200 || spec->codec_type == VT2002P
1201 || spec->codec_type == VT1812) {
1202 activate_ctl(codec, "Headphone Playback Volume",
1203 spec->hp_independent_mode);
1204 activate_ctl(codec, "Headphone Playback Switch",
1205 spec->hp_independent_mode);
464 } 1206 }
465 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
466 pinsel);
467
468 if (spec->multiout.hp_nid &&
469 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
470 snd_hda_codec_setup_stream(codec,
471 spec->multiout.hp_nid,
472 0, 0, 0);
473
474 return 0; 1207 return 0;
475} 1208}
476 1209
@@ -486,6 +1219,175 @@ static struct snd_kcontrol_new via_hp_mixer[] = {
486 { } /* end */ 1219 { } /* end */
487}; 1220};
488 1221
1222static void notify_aa_path_ctls(struct hda_codec *codec)
1223{
1224 int i;
1225 struct snd_ctl_elem_id id;
1226 const char *labels[] = {"Mic", "Front Mic", "Line"};
1227
1228 memset(&id, 0, sizeof(id));
1229 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1230 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1231 sprintf(id.name, "%s Playback Volume", labels[i]);
1232 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1233 &id);
1234 }
1235}
1236
1237static void mute_aa_path(struct hda_codec *codec, int mute)
1238{
1239 struct via_spec *spec = codec->spec;
1240 hda_nid_t nid_mixer;
1241 int start_idx;
1242 int end_idx;
1243 int i;
1244 /* get nid of MW0 and start & end index */
1245 switch (spec->codec_type) {
1246 case VT1708:
1247 nid_mixer = 0x17;
1248 start_idx = 2;
1249 end_idx = 4;
1250 break;
1251 case VT1709_10CH:
1252 case VT1709_6CH:
1253 nid_mixer = 0x18;
1254 start_idx = 2;
1255 end_idx = 4;
1256 break;
1257 case VT1708B_8CH:
1258 case VT1708B_4CH:
1259 case VT1708S:
1260 case VT1716S:
1261 nid_mixer = 0x16;
1262 start_idx = 2;
1263 end_idx = 4;
1264 break;
1265 default:
1266 return;
1267 }
1268 /* check AA path's mute status */
1269 for (i = start_idx; i <= end_idx; i++) {
1270 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1271 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1272 HDA_AMP_MUTE, val);
1273 }
1274}
1275static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1276{
1277 int res = 0;
1278 int index;
1279 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1280 if (pin == spec->autocfg.input_pins[index]) {
1281 res = 1;
1282 break;
1283 }
1284 }
1285 return res;
1286}
1287
1288static int via_smart51_info(struct snd_kcontrol *kcontrol,
1289 struct snd_ctl_elem_info *uinfo)
1290{
1291 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1292 uinfo->count = 1;
1293 uinfo->value.integer.min = 0;
1294 uinfo->value.integer.max = 1;
1295 return 0;
1296}
1297
1298static int via_smart51_get(struct snd_kcontrol *kcontrol,
1299 struct snd_ctl_elem_value *ucontrol)
1300{
1301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1302 struct via_spec *spec = codec->spec;
1303 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1304 int on = 1;
1305 int i;
1306
1307 for (i = 0; i < ARRAY_SIZE(index); i++) {
1308 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1309 if (nid) {
1310 int ctl =
1311 snd_hda_codec_read(codec, nid, 0,
1312 AC_VERB_GET_PIN_WIDGET_CONTROL,
1313 0);
1314 if (i == AUTO_PIN_FRONT_MIC
1315 && spec->hp_independent_mode
1316 && spec->codec_type != VT1718S)
1317 continue; /* ignore FMic for independent HP */
1318 if (ctl & AC_PINCTL_IN_EN
1319 && !(ctl & AC_PINCTL_OUT_EN))
1320 on = 0;
1321 }
1322 }
1323 *ucontrol->value.integer.value = on;
1324 return 0;
1325}
1326
1327static int via_smart51_put(struct snd_kcontrol *kcontrol,
1328 struct snd_ctl_elem_value *ucontrol)
1329{
1330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1331 struct via_spec *spec = codec->spec;
1332 int out_in = *ucontrol->value.integer.value
1333 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1334 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1335 int i;
1336
1337 for (i = 0; i < ARRAY_SIZE(index); i++) {
1338 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1339 if (i == AUTO_PIN_FRONT_MIC
1340 && spec->hp_independent_mode
1341 && spec->codec_type != VT1718S)
1342 continue; /* don't retask FMic for independent HP */
1343 if (nid) {
1344 unsigned int parm = snd_hda_codec_read(
1345 codec, nid, 0,
1346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1347 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1348 parm |= out_in;
1349 snd_hda_codec_write(codec, nid, 0,
1350 AC_VERB_SET_PIN_WIDGET_CONTROL,
1351 parm);
1352 if (out_in == AC_PINCTL_OUT_EN) {
1353 mute_aa_path(codec, 1);
1354 notify_aa_path_ctls(codec);
1355 }
1356 if (spec->codec_type == VT1718S)
1357 snd_hda_codec_amp_stereo(
1358 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1359 HDA_AMP_UNMUTE);
1360 }
1361 if (i == AUTO_PIN_FRONT_MIC) {
1362 if (spec->codec_type == VT1708S
1363 || spec->codec_type == VT1716S) {
1364 /* input = index 1 (AOW3) */
1365 snd_hda_codec_write(
1366 codec, nid, 0,
1367 AC_VERB_SET_CONNECT_SEL, 1);
1368 snd_hda_codec_amp_stereo(
1369 codec, nid, HDA_OUTPUT,
1370 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1371 }
1372 }
1373 }
1374 spec->smart51_enabled = *ucontrol->value.integer.value;
1375 set_jack_power_state(codec);
1376 return 1;
1377}
1378
1379static struct snd_kcontrol_new via_smart51_mixer[] = {
1380 {
1381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1382 .name = "Smart 5.1",
1383 .count = 1,
1384 .info = via_smart51_info,
1385 .get = via_smart51_get,
1386 .put = via_smart51_put,
1387 },
1388 {} /* end */
1389};
1390
489/* capture mixer elements */ 1391/* capture mixer elements */
490static struct snd_kcontrol_new vt1708_capture_mixer[] = { 1392static struct snd_kcontrol_new vt1708_capture_mixer[] = {
491 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), 1393 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
@@ -506,6 +1408,112 @@ static struct snd_kcontrol_new vt1708_capture_mixer[] = {
506 }, 1408 },
507 { } /* end */ 1409 { } /* end */
508}; 1410};
1411
1412/* check AA path's mute statue */
1413static int is_aa_path_mute(struct hda_codec *codec)
1414{
1415 int mute = 1;
1416 hda_nid_t nid_mixer;
1417 int start_idx;
1418 int end_idx;
1419 int i;
1420 struct via_spec *spec = codec->spec;
1421 /* get nid of MW0 and start & end index */
1422 switch (spec->codec_type) {
1423 case VT1708B_8CH:
1424 case VT1708B_4CH:
1425 case VT1708S:
1426 case VT1716S:
1427 nid_mixer = 0x16;
1428 start_idx = 2;
1429 end_idx = 4;
1430 break;
1431 case VT1702:
1432 nid_mixer = 0x1a;
1433 start_idx = 1;
1434 end_idx = 3;
1435 break;
1436 case VT1718S:
1437 nid_mixer = 0x21;
1438 start_idx = 1;
1439 end_idx = 3;
1440 break;
1441 case VT2002P:
1442 case VT1812:
1443 nid_mixer = 0x21;
1444 start_idx = 0;
1445 end_idx = 2;
1446 break;
1447 default:
1448 return 0;
1449 }
1450 /* check AA path's mute status */
1451 for (i = start_idx; i <= end_idx; i++) {
1452 unsigned int con_list = snd_hda_codec_read(
1453 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1454 int shift = 8 * (i % 4);
1455 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1456 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1457 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1458 /* check mute status while the pin is connected */
1459 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1460 HDA_INPUT, i) >> 7;
1461 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1462 HDA_INPUT, i) >> 7;
1463 if (!mute_l || !mute_r) {
1464 mute = 0;
1465 break;
1466 }
1467 }
1468 }
1469 return mute;
1470}
1471
1472/* enter/exit analog low-current mode */
1473static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1474{
1475 struct via_spec *spec = codec->spec;
1476 static int saved_stream_idle = 1; /* saved stream idle status */
1477 int enable = is_aa_path_mute(codec);
1478 unsigned int verb = 0;
1479 unsigned int parm = 0;
1480
1481 if (stream_idle == -1) /* stream status did not change */
1482 enable = enable && saved_stream_idle;
1483 else {
1484 enable = enable && stream_idle;
1485 saved_stream_idle = stream_idle;
1486 }
1487
1488 /* decide low current mode's verb & parameter */
1489 switch (spec->codec_type) {
1490 case VT1708B_8CH:
1491 case VT1708B_4CH:
1492 verb = 0xf70;
1493 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1494 break;
1495 case VT1708S:
1496 case VT1718S:
1497 case VT1716S:
1498 verb = 0xf73;
1499 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1500 break;
1501 case VT1702:
1502 verb = 0xf73;
1503 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1504 break;
1505 case VT2002P:
1506 case VT1812:
1507 verb = 0xf93;
1508 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1509 break;
1510 default:
1511 return; /* other codecs are not supported */
1512 }
1513 /* send verb */
1514 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1515}
1516
509/* 1517/*
510 * generic initialization of ADC, input mixers and output mixers 1518 * generic initialization of ADC, input mixers and output mixers
511 */ 1519 */
@@ -534,9 +1542,9 @@ static struct hda_verb vt1708_volume_init_verbs[] = {
534 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1542 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
535 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1543 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
536 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1544 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
537 1545
538 /* Setup default input to PW4 */ 1546 /* Setup default input MW0 to PW4 */
539 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, 1547 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
540 /* PW9 Output enable */ 1548 /* PW9 Output enable */
541 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 1549 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
542 { } 1550 { }
@@ -547,30 +1555,13 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
547 struct snd_pcm_substream *substream) 1555 struct snd_pcm_substream *substream)
548{ 1556{
549 struct via_spec *spec = codec->spec; 1557 struct via_spec *spec = codec->spec;
1558 int idle = substream->pstr->substream_opened == 1
1559 && substream->ref_count == 0;
1560 analog_low_current_mode(codec, idle);
550 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1561 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
551 hinfo); 1562 hinfo);
552} 1563}
553 1564
554static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
555 struct hda_codec *codec,
556 unsigned int stream_tag,
557 unsigned int format,
558 struct snd_pcm_substream *substream)
559{
560 struct via_spec *spec = codec->spec;
561 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
562 stream_tag, format, substream);
563}
564
565static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
566 struct hda_codec *codec,
567 struct snd_pcm_substream *substream)
568{
569 struct via_spec *spec = codec->spec;
570 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
571}
572
573
574static void playback_multi_pcm_prep_0(struct hda_codec *codec, 1565static void playback_multi_pcm_prep_0(struct hda_codec *codec,
575 unsigned int stream_tag, 1566 unsigned int stream_tag,
576 unsigned int format, 1567 unsigned int format,
@@ -615,8 +1606,8 @@ static void playback_multi_pcm_prep_0(struct hda_codec *codec,
615 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, 1606 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
616 0, format); 1607 0, format);
617 1608
618 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && 1609 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
619 !spec->hp_independent_mode) 1610 && !spec->hp_independent_mode)
620 /* headphone out will just decode front left/right (stereo) */ 1611 /* headphone out will just decode front left/right (stereo) */
621 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 1612 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
622 0, format); 1613 0, format);
@@ -658,7 +1649,7 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
658 snd_hda_codec_setup_stream(codec, mout->hp_nid, 1649 snd_hda_codec_setup_stream(codec, mout->hp_nid,
659 stream_tag, 0, format); 1650 stream_tag, 0, format);
660 } 1651 }
661 1652 vt1708_start_hp_work(spec);
662 return 0; 1653 return 0;
663} 1654}
664 1655
@@ -698,7 +1689,7 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
698 snd_hda_codec_setup_stream(codec, mout->hp_nid, 1689 snd_hda_codec_setup_stream(codec, mout->hp_nid,
699 0, 0, 0); 1690 0, 0, 0);
700 } 1691 }
701 1692 vt1708_stop_hp_work(spec);
702 return 0; 1693 return 0;
703} 1694}
704 1695
@@ -779,7 +1770,7 @@ static struct hda_pcm_stream vt1708_pcm_analog_playback = {
779}; 1770};
780 1771
781static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { 1772static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
782 .substreams = 1, 1773 .substreams = 2,
783 .channels_min = 2, 1774 .channels_min = 2,
784 .channels_max = 8, 1775 .channels_max = 8,
785 .nid = 0x10, /* NID to query formats and rates */ 1776 .nid = 0x10, /* NID to query formats and rates */
@@ -790,8 +1781,8 @@ static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
790 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1781 .formats = SNDRV_PCM_FMTBIT_S16_LE,
791 .ops = { 1782 .ops = {
792 .open = via_playback_pcm_open, 1783 .open = via_playback_pcm_open,
793 .prepare = via_playback_pcm_prepare, 1784 .prepare = via_playback_multi_pcm_prepare,
794 .cleanup = via_playback_pcm_cleanup 1785 .cleanup = via_playback_multi_pcm_cleanup
795 }, 1786 },
796}; 1787};
797 1788
@@ -853,6 +1844,11 @@ static int via_build_controls(struct hda_codec *codec)
853 if (err < 0) 1844 if (err < 0)
854 return err; 1845 return err;
855 } 1846 }
1847
1848 /* init power states */
1849 set_jack_power_state(codec);
1850 analog_low_current_mode(codec, 1);
1851
856 via_free_kctls(codec); /* no longer needed */ 1852 via_free_kctls(codec); /* no longer needed */
857 return 0; 1853 return 0;
858} 1854}
@@ -866,8 +1862,10 @@ static int via_build_pcms(struct hda_codec *codec)
866 codec->pcm_info = info; 1862 codec->pcm_info = info;
867 1863
868 info->name = spec->stream_name_analog; 1864 info->name = spec->stream_name_analog;
869 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback); 1865 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
870 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; 1866 *(spec->stream_analog_playback);
1867 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1868 spec->multiout.dac_nids[0];
871 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); 1869 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
872 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 1870 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
873 1871
@@ -904,20 +1902,58 @@ static void via_free(struct hda_codec *codec)
904 return; 1902 return;
905 1903
906 via_free_kctls(codec); 1904 via_free_kctls(codec);
1905 vt1708_stop_hp_work(spec);
907 kfree(codec->spec); 1906 kfree(codec->spec);
908} 1907}
909 1908
910/* mute internal speaker if HP is plugged */ 1909/* mute internal speaker if HP is plugged */
911static void via_hp_automute(struct hda_codec *codec) 1910static void via_hp_automute(struct hda_codec *codec)
912{ 1911{
913 unsigned int present; 1912 unsigned int present = 0;
914 struct via_spec *spec = codec->spec; 1913 struct via_spec *spec = codec->spec;
915 1914
916 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, 1915 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
917 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1916
918 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], 1917 if (!spec->hp_independent_mode) {
919 HDA_OUTPUT, 0, HDA_AMP_MUTE, 1918 struct snd_ctl_elem_id id;
920 present ? HDA_AMP_MUTE : 0); 1919 /* auto mute */
1920 snd_hda_codec_amp_stereo(
1921 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1922 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1923 /* notify change */
1924 memset(&id, 0, sizeof(id));
1925 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1926 strcpy(id.name, "Front Playback Switch");
1927 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1928 &id);
1929 }
1930}
1931
1932/* mute mono out if HP or Line out is plugged */
1933static void via_mono_automute(struct hda_codec *codec)
1934{
1935 unsigned int hp_present, lineout_present;
1936 struct via_spec *spec = codec->spec;
1937
1938 if (spec->codec_type != VT1716S)
1939 return;
1940
1941 lineout_present = snd_hda_jack_detect(codec,
1942 spec->autocfg.line_out_pins[0]);
1943
1944 /* Mute Mono Out if Line Out is plugged */
1945 if (lineout_present) {
1946 snd_hda_codec_amp_stereo(
1947 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1948 return;
1949 }
1950
1951 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1952
1953 if (!spec->hp_independent_mode)
1954 snd_hda_codec_amp_stereo(
1955 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1956 hp_present ? HDA_AMP_MUTE : 0);
921} 1957}
922 1958
923static void via_gpio_control(struct hda_codec *codec) 1959static void via_gpio_control(struct hda_codec *codec)
@@ -968,15 +2004,83 @@ static void via_gpio_control(struct hda_codec *codec)
968 } 2004 }
969} 2005}
970 2006
2007/* mute Internal-Speaker if HP is plugged */
2008static void via_speaker_automute(struct hda_codec *codec)
2009{
2010 unsigned int hp_present;
2011 struct via_spec *spec = codec->spec;
2012
2013 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2014 return;
2015
2016 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2017
2018 if (!spec->hp_independent_mode) {
2019 struct snd_ctl_elem_id id;
2020 snd_hda_codec_amp_stereo(
2021 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2022 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2023 /* notify change */
2024 memset(&id, 0, sizeof(id));
2025 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2026 strcpy(id.name, "Speaker Playback Switch");
2027 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2028 &id);
2029 }
2030}
2031
2032/* mute line-out and internal speaker if HP is plugged */
2033static void via_hp_bind_automute(struct hda_codec *codec)
2034{
2035 /* use long instead of int below just to avoid an internal compiler
2036 * error with gcc 4.0.x
2037 */
2038 unsigned long hp_present, present = 0;
2039 struct via_spec *spec = codec->spec;
2040 int i;
2041
2042 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2043 return;
2044
2045 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2046
2047 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2048
2049 if (!spec->hp_independent_mode) {
2050 /* Mute Line-Outs */
2051 for (i = 0; i < spec->autocfg.line_outs; i++)
2052 snd_hda_codec_amp_stereo(
2053 codec, spec->autocfg.line_out_pins[i],
2054 HDA_OUTPUT, 0,
2055 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2056 if (hp_present)
2057 present = hp_present;
2058 }
2059 /* Speakers */
2060 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2061 snd_hda_codec_amp_stereo(
2062 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2063 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2064}
2065
2066
971/* unsolicited event for jack sensing */ 2067/* unsolicited event for jack sensing */
972static void via_unsol_event(struct hda_codec *codec, 2068static void via_unsol_event(struct hda_codec *codec,
973 unsigned int res) 2069 unsigned int res)
974{ 2070{
975 res >>= 26; 2071 res >>= 26;
976 if (res == VIA_HP_EVENT) 2072 if (res & VIA_HP_EVENT)
977 via_hp_automute(codec); 2073 via_hp_automute(codec);
978 else if (res == VIA_GPIO_EVENT) 2074 if (res & VIA_GPIO_EVENT)
979 via_gpio_control(codec); 2075 via_gpio_control(codec);
2076 if (res & VIA_JACK_EVENT)
2077 set_jack_power_state(codec);
2078 if (res & VIA_MONO_EVENT)
2079 via_mono_automute(codec);
2080 if (res & VIA_SPEAKER_EVENT)
2081 via_speaker_automute(codec);
2082 if (res & VIA_BIND_HP_EVENT)
2083 via_hp_bind_automute(codec);
980} 2084}
981 2085
982static int via_init(struct hda_codec *codec) 2086static int via_init(struct hda_codec *codec)
@@ -986,6 +2090,10 @@ static int via_init(struct hda_codec *codec)
986 for (i = 0; i < spec->num_iverbs; i++) 2090 for (i = 0; i < spec->num_iverbs; i++)
987 snd_hda_sequence_write(codec, spec->init_verbs[i]); 2091 snd_hda_sequence_write(codec, spec->init_verbs[i]);
988 2092
2093 spec->codec_type = get_codec_type(codec);
2094 if (spec->codec_type == VT1708BCE)
2095 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2096 same */
989 /* Lydia Add for EAPD enable */ 2097 /* Lydia Add for EAPD enable */
990 if (!spec->dig_in_nid) { /* No Digital In connection */ 2098 if (!spec->dig_in_nid) { /* No Digital In connection */
991 if (spec->dig_in_pin) { 2099 if (spec->dig_in_pin) {
@@ -1003,8 +2111,17 @@ static int via_init(struct hda_codec *codec)
1003 if (spec->slave_dig_outs[0]) 2111 if (spec->slave_dig_outs[0])
1004 codec->slave_dig_outs = spec->slave_dig_outs; 2112 codec->slave_dig_outs = spec->slave_dig_outs;
1005 2113
1006 return 0; 2114 return 0;
2115}
2116
2117#ifdef SND_HDA_NEEDS_RESUME
2118static int via_suspend(struct hda_codec *codec, pm_message_t state)
2119{
2120 struct via_spec *spec = codec->spec;
2121 vt1708_stop_hp_work(spec);
2122 return 0;
1007} 2123}
2124#endif
1008 2125
1009#ifdef CONFIG_SND_HDA_POWER_SAVE 2126#ifdef CONFIG_SND_HDA_POWER_SAVE
1010static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) 2127static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
@@ -1021,6 +2138,9 @@ static struct hda_codec_ops via_patch_ops = {
1021 .build_pcms = via_build_pcms, 2138 .build_pcms = via_build_pcms,
1022 .init = via_init, 2139 .init = via_init,
1023 .free = via_free, 2140 .free = via_free,
2141#ifdef SND_HDA_NEEDS_RESUME
2142 .suspend = via_suspend,
2143#endif
1024#ifdef CONFIG_SND_HDA_POWER_SAVE 2144#ifdef CONFIG_SND_HDA_POWER_SAVE
1025 .check_power_status = via_check_power_status, 2145 .check_power_status = via_check_power_status,
1026#endif 2146#endif
@@ -1036,8 +2156,8 @@ static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1036 spec->multiout.num_dacs = cfg->line_outs; 2156 spec->multiout.num_dacs = cfg->line_outs;
1037 2157
1038 spec->multiout.dac_nids = spec->private_dac_nids; 2158 spec->multiout.dac_nids = spec->private_dac_nids;
1039 2159
1040 for(i = 0; i < 4; i++) { 2160 for (i = 0; i < 4; i++) {
1041 nid = cfg->line_out_pins[i]; 2161 nid = cfg->line_out_pins[i];
1042 if (nid) { 2162 if (nid) {
1043 /* config dac list */ 2163 /* config dac list */
@@ -1067,7 +2187,7 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1067{ 2187{
1068 char name[32]; 2188 char name[32];
1069 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2189 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1070 hda_nid_t nid, nid_vol = 0; 2190 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1071 int i, err; 2191 int i, err;
1072 2192
1073 for (i = 0; i <= AUTO_SEQ_SIDE; i++) { 2193 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
@@ -1075,9 +2195,8 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1075 2195
1076 if (!nid) 2196 if (!nid)
1077 continue; 2197 continue;
1078 2198
1079 if (i != AUTO_SEQ_FRONT) 2199 nid_vol = nid_vols[i];
1080 nid_vol = 0x18 + i;
1081 2200
1082 if (i == AUTO_SEQ_CENLFE) { 2201 if (i == AUTO_SEQ_CENLFE) {
1083 /* Center/LFE */ 2202 /* Center/LFE */
@@ -1105,21 +2224,21 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1105 HDA_OUTPUT)); 2224 HDA_OUTPUT));
1106 if (err < 0) 2225 if (err < 0)
1107 return err; 2226 return err;
1108 } else if (i == AUTO_SEQ_FRONT){ 2227 } else if (i == AUTO_SEQ_FRONT) {
1109 /* add control to mixer index 0 */ 2228 /* add control to mixer index 0 */
1110 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2229 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1111 "Master Front Playback Volume", 2230 "Master Front Playback Volume",
1112 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, 2231 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1113 HDA_INPUT)); 2232 HDA_INPUT));
1114 if (err < 0) 2233 if (err < 0)
1115 return err; 2234 return err;
1116 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2235 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1117 "Master Front Playback Switch", 2236 "Master Front Playback Switch",
1118 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, 2237 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1119 HDA_INPUT)); 2238 HDA_INPUT));
1120 if (err < 0) 2239 if (err < 0)
1121 return err; 2240 return err;
1122 2241
1123 /* add control to PW3 */ 2242 /* add control to PW3 */
1124 sprintf(name, "%s Playback Volume", chname[i]); 2243 sprintf(name, "%s Playback Volume", chname[i]);
1125 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2244 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
@@ -1178,6 +2297,7 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1178 return 0; 2297 return 0;
1179 2298
1180 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ 2299 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2300 spec->hp_independent_mode_index = 1;
1181 2301
1182 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2302 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1183 "Headphone Playback Volume", 2303 "Headphone Playback Volume",
@@ -1218,7 +2338,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1218 case 0x1d: /* Mic */ 2338 case 0x1d: /* Mic */
1219 idx = 2; 2339 idx = 2;
1220 break; 2340 break;
1221 2341
1222 case 0x1e: /* Line In */ 2342 case 0x1e: /* Line In */
1223 idx = 3; 2343 idx = 3;
1224 break; 2344 break;
@@ -1231,8 +2351,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1231 idx = 1; 2351 idx = 1;
1232 break; 2352 break;
1233 } 2353 }
1234 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 2354 err = via_new_analog_input(spec, labels[i], idx, 0x17);
1235 idx, 0x17);
1236 if (err < 0) 2355 if (err < 0)
1237 return err; 2356 return err;
1238 imux->items[imux->num_items].label = labels[i]; 2357 imux->items[imux->num_items].label = labels[i];
@@ -1260,16 +2379,60 @@ static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1260 def_conf = snd_hda_codec_get_pincfg(codec, nid); 2379 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1261 seqassoc = (unsigned char) get_defcfg_association(def_conf); 2380 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1262 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); 2381 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1263 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) { 2382 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
1264 if (seqassoc == 0xff) { 2383 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
1265 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); 2384 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1266 snd_hda_codec_set_pincfg(codec, nid, def_conf); 2385 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1267 }
1268 } 2386 }
1269 2387
1270 return; 2388 return;
1271} 2389}
1272 2390
2391static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2392 struct snd_ctl_elem_value *ucontrol)
2393{
2394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2395 struct via_spec *spec = codec->spec;
2396
2397 if (spec->codec_type != VT1708)
2398 return 0;
2399 spec->vt1708_jack_detectect =
2400 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2401 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2402 return 0;
2403}
2404
2405static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2406 struct snd_ctl_elem_value *ucontrol)
2407{
2408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2409 struct via_spec *spec = codec->spec;
2410 int change;
2411
2412 if (spec->codec_type != VT1708)
2413 return 0;
2414 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2415 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2416 == !spec->vt1708_jack_detectect;
2417 if (spec->vt1708_jack_detectect) {
2418 mute_aa_path(codec, 1);
2419 notify_aa_path_ctls(codec);
2420 }
2421 return change;
2422}
2423
2424static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2425 {
2426 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2427 .name = "Jack Detect",
2428 .count = 1,
2429 .info = snd_ctl_boolean_mono_info,
2430 .get = vt1708_jack_detectect_get,
2431 .put = vt1708_jack_detectect_put,
2432 },
2433 {} /* end */
2434};
2435
1273static int vt1708_parse_auto_config(struct hda_codec *codec) 2436static int vt1708_parse_auto_config(struct hda_codec *codec)
1274{ 2437{
1275 struct via_spec *spec = codec->spec; 2438 struct via_spec *spec = codec->spec;
@@ -1297,6 +2460,10 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1297 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg); 2460 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1298 if (err < 0) 2461 if (err < 0)
1299 return err; 2462 return err;
2463 /* add jack detect on/off control */
2464 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2465 if (err < 0)
2466 return err;
1300 2467
1301 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 2468 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1302 2469
@@ -1316,19 +2483,44 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1316 if (spec->hp_mux) 2483 if (spec->hp_mux)
1317 spec->mixers[spec->num_mixers++] = via_hp_mixer; 2484 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1318 2485
2486 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
1319 return 1; 2487 return 1;
1320} 2488}
1321 2489
1322/* init callback for auto-configuration model -- overriding the default init */ 2490/* init callback for auto-configuration model -- overriding the default init */
1323static int via_auto_init(struct hda_codec *codec) 2491static int via_auto_init(struct hda_codec *codec)
1324{ 2492{
2493 struct via_spec *spec = codec->spec;
2494
1325 via_init(codec); 2495 via_init(codec);
1326 via_auto_init_multi_out(codec); 2496 via_auto_init_multi_out(codec);
1327 via_auto_init_hp_out(codec); 2497 via_auto_init_hp_out(codec);
1328 via_auto_init_analog_input(codec); 2498 via_auto_init_analog_input(codec);
2499 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2500 via_hp_bind_automute(codec);
2501 } else {
2502 via_hp_automute(codec);
2503 via_speaker_automute(codec);
2504 }
2505
1329 return 0; 2506 return 0;
1330} 2507}
1331 2508
2509static void vt1708_update_hp_jack_state(struct work_struct *work)
2510{
2511 struct via_spec *spec = container_of(work, struct via_spec,
2512 vt1708_hp_work.work);
2513 if (spec->codec_type != VT1708)
2514 return;
2515 /* if jack state toggled */
2516 if (spec->vt1708_hp_present
2517 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2518 spec->vt1708_hp_present ^= 1;
2519 via_hp_automute(spec->codec);
2520 }
2521 vt1708_start_hp_work(spec);
2522}
2523
1332static int get_mux_nids(struct hda_codec *codec) 2524static int get_mux_nids(struct hda_codec *codec)
1333{ 2525{
1334 struct via_spec *spec = codec->spec; 2526 struct via_spec *spec = codec->spec;
@@ -1378,7 +2570,7 @@ static int patch_vt1708(struct hda_codec *codec)
1378 "from BIOS. Using genenic mode...\n"); 2570 "from BIOS. Using genenic mode...\n");
1379 } 2571 }
1380 2572
1381 2573
1382 spec->stream_name_analog = "VT1708 Analog"; 2574 spec->stream_name_analog = "VT1708 Analog";
1383 spec->stream_analog_playback = &vt1708_pcm_analog_playback; 2575 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1384 /* disable 32bit format on VT1708 */ 2576 /* disable 32bit format on VT1708 */
@@ -1390,7 +2582,7 @@ static int patch_vt1708(struct hda_codec *codec)
1390 spec->stream_digital_playback = &vt1708_pcm_digital_playback; 2582 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1391 spec->stream_digital_capture = &vt1708_pcm_digital_capture; 2583 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1392 2584
1393 2585
1394 if (!spec->adc_nids && spec->input_mux) { 2586 if (!spec->adc_nids && spec->input_mux) {
1395 spec->adc_nids = vt1708_adc_nids; 2587 spec->adc_nids = vt1708_adc_nids;
1396 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); 2588 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
@@ -1405,7 +2597,8 @@ static int patch_vt1708(struct hda_codec *codec)
1405#ifdef CONFIG_SND_HDA_POWER_SAVE 2597#ifdef CONFIG_SND_HDA_POWER_SAVE
1406 spec->loopback.amplist = vt1708_loopbacks; 2598 spec->loopback.amplist = vt1708_loopbacks;
1407#endif 2599#endif
1408 2600 spec->codec = codec;
2601 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
1409 return 0; 2602 return 0;
1410} 2603}
1411 2604
@@ -1433,7 +2626,8 @@ static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1433}; 2626};
1434 2627
1435static struct hda_verb vt1709_uniwill_init_verbs[] = { 2628static struct hda_verb vt1709_uniwill_init_verbs[] = {
1436 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 2629 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2630 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
1437 { } 2631 { }
1438}; 2632};
1439 2633
@@ -1473,8 +2667,8 @@ static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1473 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 2667 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1474 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 2668 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1475 2669
1476 /* Set input of PW4 as AOW4 */ 2670 /* Set input of PW4 as MW0 */
1477 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, 2671 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1478 /* PW9 Output enable */ 2672 /* PW9 Output enable */
1479 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 2673 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1480 { } 2674 { }
@@ -1487,8 +2681,8 @@ static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1487 .nid = 0x10, /* NID to query formats and rates */ 2681 .nid = 0x10, /* NID to query formats and rates */
1488 .ops = { 2682 .ops = {
1489 .open = via_playback_pcm_open, 2683 .open = via_playback_pcm_open,
1490 .prepare = via_playback_pcm_prepare, 2684 .prepare = via_playback_multi_pcm_prepare,
1491 .cleanup = via_playback_pcm_cleanup 2685 .cleanup = via_playback_multi_pcm_cleanup,
1492 }, 2686 },
1493}; 2687};
1494 2688
@@ -1499,8 +2693,8 @@ static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1499 .nid = 0x10, /* NID to query formats and rates */ 2693 .nid = 0x10, /* NID to query formats and rates */
1500 .ops = { 2694 .ops = {
1501 .open = via_playback_pcm_open, 2695 .open = via_playback_pcm_open,
1502 .prepare = via_playback_pcm_prepare, 2696 .prepare = via_playback_multi_pcm_prepare,
1503 .cleanup = via_playback_pcm_cleanup 2697 .cleanup = via_playback_multi_pcm_cleanup,
1504 }, 2698 },
1505}; 2699};
1506 2700
@@ -1575,11 +2769,11 @@ static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1575 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ 2769 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1576 2770
1577 } else if (cfg->line_outs == 3) { /* 6 channels */ 2771 } else if (cfg->line_outs == 3) { /* 6 channels */
1578 for(i = 0; i < cfg->line_outs; i++) { 2772 for (i = 0; i < cfg->line_outs; i++) {
1579 nid = cfg->line_out_pins[i]; 2773 nid = cfg->line_out_pins[i];
1580 if (nid) { 2774 if (nid) {
1581 /* config dac list */ 2775 /* config dac list */
1582 switch(i) { 2776 switch (i) {
1583 case AUTO_SEQ_FRONT: 2777 case AUTO_SEQ_FRONT:
1584 /* AOW0 */ 2778 /* AOW0 */
1585 spec->multiout.dac_nids[i] = 0x10; 2779 spec->multiout.dac_nids[i] = 0x10;
@@ -1608,56 +2802,58 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1608{ 2802{
1609 char name[32]; 2803 char name[32];
1610 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2804 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1611 hda_nid_t nid = 0; 2805 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
1612 int i, err; 2806 int i, err;
1613 2807
1614 for (i = 0; i <= AUTO_SEQ_SIDE; i++) { 2808 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1615 nid = cfg->line_out_pins[i]; 2809 nid = cfg->line_out_pins[i];
1616 2810
1617 if (!nid) 2811 if (!nid)
1618 continue; 2812 continue;
1619 2813
2814 nid_vol = nid_vols[i];
2815
1620 if (i == AUTO_SEQ_CENLFE) { 2816 if (i == AUTO_SEQ_CENLFE) {
1621 /* Center/LFE */ 2817 /* Center/LFE */
1622 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2818 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1623 "Center Playback Volume", 2819 "Center Playback Volume",
1624 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, 2820 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1625 HDA_OUTPUT)); 2821 HDA_OUTPUT));
1626 if (err < 0) 2822 if (err < 0)
1627 return err; 2823 return err;
1628 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2824 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1629 "LFE Playback Volume", 2825 "LFE Playback Volume",
1630 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, 2826 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1631 HDA_OUTPUT)); 2827 HDA_OUTPUT));
1632 if (err < 0) 2828 if (err < 0)
1633 return err; 2829 return err;
1634 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2830 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1635 "Center Playback Switch", 2831 "Center Playback Switch",
1636 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, 2832 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1637 HDA_OUTPUT)); 2833 HDA_OUTPUT));
1638 if (err < 0) 2834 if (err < 0)
1639 return err; 2835 return err;
1640 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2836 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1641 "LFE Playback Switch", 2837 "LFE Playback Switch",
1642 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, 2838 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1643 HDA_OUTPUT)); 2839 HDA_OUTPUT));
1644 if (err < 0) 2840 if (err < 0)
1645 return err; 2841 return err;
1646 } else if (i == AUTO_SEQ_FRONT){ 2842 } else if (i == AUTO_SEQ_FRONT) {
1647 /* add control to mixer index 0 */ 2843 /* ADD control to mixer index 0 */
1648 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2844 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1649 "Master Front Playback Volume", 2845 "Master Front Playback Volume",
1650 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, 2846 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1651 HDA_INPUT)); 2847 HDA_INPUT));
1652 if (err < 0) 2848 if (err < 0)
1653 return err; 2849 return err;
1654 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2850 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1655 "Master Front Playback Switch", 2851 "Master Front Playback Switch",
1656 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, 2852 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1657 HDA_INPUT)); 2853 HDA_INPUT));
1658 if (err < 0) 2854 if (err < 0)
1659 return err; 2855 return err;
1660 2856
1661 /* add control to PW3 */ 2857 /* add control to PW3 */
1662 sprintf(name, "%s Playback Volume", chname[i]); 2858 sprintf(name, "%s Playback Volume", chname[i]);
1663 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2859 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
@@ -1674,26 +2870,26 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1674 } else if (i == AUTO_SEQ_SURROUND) { 2870 } else if (i == AUTO_SEQ_SURROUND) {
1675 sprintf(name, "%s Playback Volume", chname[i]); 2871 sprintf(name, "%s Playback Volume", chname[i]);
1676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2872 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1677 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 2873 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1678 HDA_OUTPUT)); 2874 HDA_OUTPUT));
1679 if (err < 0) 2875 if (err < 0)
1680 return err; 2876 return err;
1681 sprintf(name, "%s Playback Switch", chname[i]); 2877 sprintf(name, "%s Playback Switch", chname[i]);
1682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 2878 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1683 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 2879 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1684 HDA_OUTPUT)); 2880 HDA_OUTPUT));
1685 if (err < 0) 2881 if (err < 0)
1686 return err; 2882 return err;
1687 } else if (i == AUTO_SEQ_SIDE) { 2883 } else if (i == AUTO_SEQ_SIDE) {
1688 sprintf(name, "%s Playback Volume", chname[i]); 2884 sprintf(name, "%s Playback Volume", chname[i]);
1689 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2885 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1690 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 2886 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1691 HDA_OUTPUT)); 2887 HDA_OUTPUT));
1692 if (err < 0) 2888 if (err < 0)
1693 return err; 2889 return err;
1694 sprintf(name, "%s Playback Switch", chname[i]); 2890 sprintf(name, "%s Playback Switch", chname[i]);
1695 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 2891 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1696 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 2892 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1697 HDA_OUTPUT)); 2893 HDA_OUTPUT));
1698 if (err < 0) 2894 if (err < 0)
1699 return err; 2895 return err;
@@ -1714,6 +2910,7 @@ static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1714 spec->multiout.hp_nid = VT1709_HP_DAC_NID; 2910 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1715 else if (spec->multiout.num_dacs == 3) /* 6 channels */ 2911 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1716 spec->multiout.hp_nid = 0; 2912 spec->multiout.hp_nid = 0;
2913 spec->hp_independent_mode_index = 1;
1717 2914
1718 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2915 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1719 "Headphone Playback Volume", 2916 "Headphone Playback Volume",
@@ -1752,7 +2949,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1752 case 0x1d: /* Mic */ 2949 case 0x1d: /* Mic */
1753 idx = 2; 2950 idx = 2;
1754 break; 2951 break;
1755 2952
1756 case 0x1e: /* Line In */ 2953 case 0x1e: /* Line In */
1757 idx = 3; 2954 idx = 3;
1758 break; 2955 break;
@@ -1765,8 +2962,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1765 idx = 1; 2962 idx = 1;
1766 break; 2963 break;
1767 } 2964 }
1768 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 2965 err = via_new_analog_input(spec, labels[i], idx, 0x18);
1769 idx, 0x18);
1770 if (err < 0) 2966 if (err < 0)
1771 return err; 2967 return err;
1772 imux->items[imux->num_items].label = labels[i]; 2968 imux->items[imux->num_items].label = labels[i];
@@ -1816,6 +3012,7 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
1816 if (spec->hp_mux) 3012 if (spec->hp_mux)
1817 spec->mixers[spec->num_mixers++] = via_hp_mixer; 3013 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1818 3014
3015 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
1819 return 1; 3016 return 1;
1820} 3017}
1821 3018
@@ -1861,7 +3058,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1861 spec->stream_digital_playback = &vt1709_pcm_digital_playback; 3058 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1862 spec->stream_digital_capture = &vt1709_pcm_digital_capture; 3059 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1863 3060
1864 3061
1865 if (!spec->adc_nids && spec->input_mux) { 3062 if (!spec->adc_nids && spec->input_mux) {
1866 spec->adc_nids = vt1709_adc_nids; 3063 spec->adc_nids = vt1709_adc_nids;
1867 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 3064 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
@@ -1955,7 +3152,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1955 spec->stream_digital_playback = &vt1709_pcm_digital_playback; 3152 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1956 spec->stream_digital_capture = &vt1709_pcm_digital_capture; 3153 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1957 3154
1958 3155
1959 if (!spec->adc_nids && spec->input_mux) { 3156 if (!spec->adc_nids && spec->input_mux) {
1960 spec->adc_nids = vt1709_adc_nids; 3157 spec->adc_nids = vt1709_adc_nids;
1961 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 3158 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
@@ -2024,7 +3221,7 @@ static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2024 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 3221 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2025 3222
2026 /* Setup default input to PW4 */ 3223 /* Setup default input to PW4 */
2027 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, 3224 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2028 /* PW9 Output enable */ 3225 /* PW9 Output enable */
2029 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 3226 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2030 /* PW10 Input enable */ 3227 /* PW10 Input enable */
@@ -2068,10 +3265,29 @@ static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2068}; 3265};
2069 3266
2070static struct hda_verb vt1708B_uniwill_init_verbs[] = { 3267static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2071 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 3268 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3269 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3270 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3271 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3272 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3273 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3274 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3275 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3276 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2072 { } 3277 { }
2073}; 3278};
2074 3279
3280static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3281 struct hda_codec *codec,
3282 struct snd_pcm_substream *substream)
3283{
3284 int idle = substream->pstr->substream_opened == 1
3285 && substream->ref_count == 0;
3286
3287 analog_low_current_mode(codec, idle);
3288 return 0;
3289}
3290
2075static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { 3291static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2076 .substreams = 2, 3292 .substreams = 2,
2077 .channels_min = 2, 3293 .channels_min = 2,
@@ -2080,7 +3296,8 @@ static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2080 .ops = { 3296 .ops = {
2081 .open = via_playback_pcm_open, 3297 .open = via_playback_pcm_open,
2082 .prepare = via_playback_multi_pcm_prepare, 3298 .prepare = via_playback_multi_pcm_prepare,
2083 .cleanup = via_playback_multi_pcm_cleanup 3299 .cleanup = via_playback_multi_pcm_cleanup,
3300 .close = via_pcm_open_close
2084 }, 3301 },
2085}; 3302};
2086 3303
@@ -2102,8 +3319,10 @@ static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2102 .channels_max = 2, 3319 .channels_max = 2,
2103 .nid = 0x13, /* NID to query formats and rates */ 3320 .nid = 0x13, /* NID to query formats and rates */
2104 .ops = { 3321 .ops = {
3322 .open = via_pcm_open_close,
2105 .prepare = via_capture_pcm_prepare, 3323 .prepare = via_capture_pcm_prepare,
2106 .cleanup = via_capture_pcm_cleanup 3324 .cleanup = via_capture_pcm_cleanup,
3325 .close = via_pcm_open_close
2107 }, 3326 },
2108}; 3327};
2109 3328
@@ -2260,6 +3479,7 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2260 return 0; 3479 return 0;
2261 3480
2262 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ 3481 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3482 spec->hp_independent_mode_index = 1;
2263 3483
2264 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 3484 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2265 "Headphone Playback Volume", 3485 "Headphone Playback Volume",
@@ -2313,8 +3533,7 @@ static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2313 idx = 1; 3533 idx = 1;
2314 break; 3534 break;
2315 } 3535 }
2316 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 3536 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2317 idx, 0x16);
2318 if (err < 0) 3537 if (err < 0)
2319 return err; 3538 return err;
2320 imux->items[imux->num_items].label = labels[i]; 3539 imux->items[imux->num_items].label = labels[i];
@@ -2364,6 +3583,7 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
2364 if (spec->hp_mux) 3583 if (spec->hp_mux)
2365 spec->mixers[spec->num_mixers++] = via_hp_mixer; 3584 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2366 3585
3586 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2367 return 1; 3587 return 1;
2368} 3588}
2369 3589
@@ -2376,12 +3596,14 @@ static struct hda_amp_list vt1708B_loopbacks[] = {
2376 { } /* end */ 3596 { } /* end */
2377}; 3597};
2378#endif 3598#endif
2379 3599static int patch_vt1708S(struct hda_codec *codec);
2380static int patch_vt1708B_8ch(struct hda_codec *codec) 3600static int patch_vt1708B_8ch(struct hda_codec *codec)
2381{ 3601{
2382 struct via_spec *spec; 3602 struct via_spec *spec;
2383 int err; 3603 int err;
2384 3604
3605 if (get_codec_type(codec) == VT1708BCE)
3606 return patch_vt1708S(codec);
2385 /* create a codec specific record */ 3607 /* create a codec specific record */
2386 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3608 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2387 if (spec == NULL) 3609 if (spec == NULL)
@@ -2483,29 +3705,15 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
2483 3705
2484/* Patch for VT1708S */ 3706/* Patch for VT1708S */
2485 3707
2486/* VT1708S software backdoor based override for buggy hardware micboost
2487 * setting */
2488#define MIC_BOOST_VOLUME(xname, nid) { \
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2490 .name = xname, \
2491 .index = 0, \
2492 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2493 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2494 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2495 .info = mic_boost_volume_info, \
2496 .get = snd_hda_mixer_amp_volume_get, \
2497 .put = snd_hda_mixer_amp_volume_put, \
2498 .tlv = { .c = mic_boost_tlv }, \
2499 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2500
2501/* capture mixer elements */ 3708/* capture mixer elements */
2502static struct snd_kcontrol_new vt1708S_capture_mixer[] = { 3709static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2503 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), 3710 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2504 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), 3711 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2505 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), 3712 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2506 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), 3713 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2507 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A), 3714 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
2508 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E), 3715 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3716 HDA_INPUT),
2509 { 3717 {
2510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3718 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2511 /* The multiple "Capture Source" controls confuse alsamixer 3719 /* The multiple "Capture Source" controls confuse alsamixer
@@ -2542,11 +3750,21 @@ static struct hda_verb vt1708S_volume_init_verbs[] = {
2542 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 3750 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2543 /* Enable Mic Boost Volume backdoor */ 3751 /* Enable Mic Boost Volume backdoor */
2544 {0x1, 0xf98, 0x1}, 3752 {0x1, 0xf98, 0x1},
3753 /* don't bybass mixer */
3754 {0x1, 0xf88, 0xc0},
2545 { } 3755 { }
2546}; 3756};
2547 3757
2548static struct hda_verb vt1708S_uniwill_init_verbs[] = { 3758static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2549 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 3759 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3760 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3761 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3762 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3763 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3764 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3765 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3766 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3767 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2550 { } 3768 { }
2551}; 3769};
2552 3770
@@ -2557,8 +3775,9 @@ static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2557 .nid = 0x10, /* NID to query formats and rates */ 3775 .nid = 0x10, /* NID to query formats and rates */
2558 .ops = { 3776 .ops = {
2559 .open = via_playback_pcm_open, 3777 .open = via_playback_pcm_open,
2560 .prepare = via_playback_pcm_prepare, 3778 .prepare = via_playback_multi_pcm_prepare,
2561 .cleanup = via_playback_pcm_cleanup 3779 .cleanup = via_playback_multi_pcm_cleanup,
3780 .close = via_pcm_open_close
2562 }, 3781 },
2563}; 3782};
2564 3783
@@ -2568,8 +3787,10 @@ static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2568 .channels_max = 2, 3787 .channels_max = 2,
2569 .nid = 0x13, /* NID to query formats and rates */ 3788 .nid = 0x13, /* NID to query formats and rates */
2570 .ops = { 3789 .ops = {
3790 .open = via_pcm_open_close,
2571 .prepare = via_capture_pcm_prepare, 3791 .prepare = via_capture_pcm_prepare,
2572 .cleanup = via_capture_pcm_cleanup 3792 .cleanup = via_capture_pcm_cleanup,
3793 .close = via_pcm_open_close
2573 }, 3794 },
2574}; 3795};
2575 3796
@@ -2726,6 +3947,7 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2726 return 0; 3947 return 0;
2727 3948
2728 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ 3949 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3950 spec->hp_independent_mode_index = 1;
2729 3951
2730 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 3952 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2731 "Headphone Playback Volume", 3953 "Headphone Playback Volume",
@@ -2780,8 +4002,7 @@ static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2780 idx = 1; 4002 idx = 1;
2781 break; 4003 break;
2782 } 4004 }
2783 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 4005 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2784 idx, 0x16);
2785 if (err < 0) 4006 if (err < 0)
2786 return err; 4007 return err;
2787 imux->items[imux->num_items].label = labels[i]; 4008 imux->items[imux->num_items].label = labels[i];
@@ -2852,6 +4073,7 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec)
2852 if (spec->hp_mux) 4073 if (spec->hp_mux)
2853 spec->mixers[spec->num_mixers++] = via_hp_mixer; 4074 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2854 4075
4076 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2855 return 1; 4077 return 1;
2856} 4078}
2857 4079
@@ -2865,6 +4087,16 @@ static struct hda_amp_list vt1708S_loopbacks[] = {
2865}; 4087};
2866#endif 4088#endif
2867 4089
4090static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4091 int offset, int num_steps, int step_size)
4092{
4093 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4094 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4095 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4096 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4097 (0 << AC_AMPCAP_MUTE_SHIFT));
4098}
4099
2868static int patch_vt1708S(struct hda_codec *codec) 4100static int patch_vt1708S(struct hda_codec *codec)
2869{ 4101{
2870 struct via_spec *spec; 4102 struct via_spec *spec;
@@ -2890,17 +4122,25 @@ static int patch_vt1708S(struct hda_codec *codec)
2890 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; 4122 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2891 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; 4123 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2892 4124
2893 spec->stream_name_analog = "VT1708S Analog"; 4125 if (codec->vendor_id == 0x11060440)
4126 spec->stream_name_analog = "VT1818S Analog";
4127 else
4128 spec->stream_name_analog = "VT1708S Analog";
2894 spec->stream_analog_playback = &vt1708S_pcm_analog_playback; 4129 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2895 spec->stream_analog_capture = &vt1708S_pcm_analog_capture; 4130 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2896 4131
2897 spec->stream_name_digital = "VT1708S Digital"; 4132 if (codec->vendor_id == 0x11060440)
4133 spec->stream_name_digital = "VT1818S Digital";
4134 else
4135 spec->stream_name_digital = "VT1708S Digital";
2898 spec->stream_digital_playback = &vt1708S_pcm_digital_playback; 4136 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2899 4137
2900 if (!spec->adc_nids && spec->input_mux) { 4138 if (!spec->adc_nids && spec->input_mux) {
2901 spec->adc_nids = vt1708S_adc_nids; 4139 spec->adc_nids = vt1708S_adc_nids;
2902 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); 4140 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2903 get_mux_nids(codec); 4141 get_mux_nids(codec);
4142 override_mic_boost(codec, 0x1a, 0, 3, 40);
4143 override_mic_boost(codec, 0x1e, 0, 3, 40);
2904 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; 4144 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2905 spec->num_mixers++; 4145 spec->num_mixers++;
2906 } 4146 }
@@ -2913,6 +4153,16 @@ static int patch_vt1708S(struct hda_codec *codec)
2913 spec->loopback.amplist = vt1708S_loopbacks; 4153 spec->loopback.amplist = vt1708S_loopbacks;
2914#endif 4154#endif
2915 4155
4156 /* correct names for VT1708BCE */
4157 if (get_codec_type(codec) == VT1708BCE) {
4158 kfree(codec->chip_name);
4159 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4160 snprintf(codec->bus->card->mixername,
4161 sizeof(codec->bus->card->mixername),
4162 "%s %s", codec->vendor_name, codec->chip_name);
4163 spec->stream_name_analog = "VT1708BCE Analog";
4164 spec->stream_name_digital = "VT1708BCE Digital";
4165 }
2916 return 0; 4166 return 0;
2917} 4167}
2918 4168
@@ -2967,12 +4217,20 @@ static struct hda_verb vt1702_volume_init_verbs[] = {
2967 /* PW6 PW7 Output enable */ 4217 /* PW6 PW7 Output enable */
2968 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 4218 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2969 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 4219 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4220 /* mixer enable */
4221 {0x1, 0xF88, 0x3},
4222 /* GPIO 0~2 */
4223 {0x1, 0xF82, 0x3F},
2970 { } 4224 { }
2971}; 4225};
2972 4226
2973static struct hda_verb vt1702_uniwill_init_verbs[] = { 4227static struct hda_verb vt1702_uniwill_init_verbs[] = {
2974 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT}, 4228 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
2975 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 4229 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4230 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4231 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4232 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4233 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2976 { } 4234 { }
2977}; 4235};
2978 4236
@@ -2984,7 +4242,8 @@ static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2984 .ops = { 4242 .ops = {
2985 .open = via_playback_pcm_open, 4243 .open = via_playback_pcm_open,
2986 .prepare = via_playback_multi_pcm_prepare, 4244 .prepare = via_playback_multi_pcm_prepare,
2987 .cleanup = via_playback_multi_pcm_cleanup 4245 .cleanup = via_playback_multi_pcm_cleanup,
4246 .close = via_pcm_open_close
2988 }, 4247 },
2989}; 4248};
2990 4249
@@ -2994,8 +4253,10 @@ static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2994 .channels_max = 2, 4253 .channels_max = 2,
2995 .nid = 0x12, /* NID to query formats and rates */ 4254 .nid = 0x12, /* NID to query formats and rates */
2996 .ops = { 4255 .ops = {
4256 .open = via_pcm_open_close,
2997 .prepare = via_capture_pcm_prepare, 4257 .prepare = via_capture_pcm_prepare,
2998 .cleanup = via_capture_pcm_cleanup 4258 .cleanup = via_capture_pcm_cleanup,
4259 .close = via_pcm_open_close
2999 }, 4260 },
3000}; 4261};
3001 4262
@@ -3065,12 +4326,13 @@ static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3065 4326
3066static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) 4327static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3067{ 4328{
3068 int err; 4329 int err, i;
3069 4330 struct hda_input_mux *imux;
4331 static const char *texts[] = { "ON", "OFF", NULL};
3070 if (!pin) 4332 if (!pin)
3071 return 0; 4333 return 0;
3072
3073 spec->multiout.hp_nid = 0x1D; 4334 spec->multiout.hp_nid = 0x1D;
4335 spec->hp_independent_mode_index = 0;
3074 4336
3075 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 4337 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3076 "Headphone Playback Volume", 4338 "Headphone Playback Volume",
@@ -3084,8 +4346,18 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3084 if (err < 0) 4346 if (err < 0)
3085 return err; 4347 return err;
3086 4348
3087 create_hp_imux(spec); 4349 imux = &spec->private_imux[1];
3088 4350
4351 /* for hp mode select */
4352 i = 0;
4353 while (texts[i] != NULL) {
4354 imux->items[imux->num_items].label = texts[i];
4355 imux->items[imux->num_items].index = i;
4356 imux->num_items++;
4357 i++;
4358 }
4359
4360 spec->hp_mux = &spec->private_imux[1];
3089 return 0; 4361 return 0;
3090} 4362}
3091 4363
@@ -3121,8 +4393,7 @@ static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3121 idx = 3; 4393 idx = 3;
3122 break; 4394 break;
3123 } 4395 }
3124 err = via_new_analog_input(spec, cfg->input_pins[i], 4396 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
3125 labels[i], idx, 0x1A);
3126 if (err < 0) 4397 if (err < 0)
3127 return err; 4398 return err;
3128 imux->items[imux->num_items].label = labels[i]; 4399 imux->items[imux->num_items].label = labels[i];
@@ -3152,6 +4423,12 @@ static int vt1702_parse_auto_config(struct hda_codec *codec)
3152 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); 4423 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3153 if (err < 0) 4424 if (err < 0)
3154 return err; 4425 return err;
4426 /* limit AA path volume to 0 dB */
4427 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4428 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4429 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4430 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4431 (1 << AC_AMPCAP_MUTE_SHIFT));
3155 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg); 4432 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3156 if (err < 0) 4433 if (err < 0)
3157 return err; 4434 return err;
@@ -3185,8 +4462,6 @@ static int patch_vt1702(struct hda_codec *codec)
3185{ 4462{
3186 struct via_spec *spec; 4463 struct via_spec *spec;
3187 int err; 4464 int err;
3188 unsigned int response;
3189 unsigned char control;
3190 4465
3191 /* create a codec specific record */ 4466 /* create a codec specific record */
3192 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4467 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -3231,17 +4506,1638 @@ static int patch_vt1702(struct hda_codec *codec)
3231 spec->loopback.amplist = vt1702_loopbacks; 4506 spec->loopback.amplist = vt1702_loopbacks;
3232#endif 4507#endif
3233 4508
3234 /* Open backdoor */ 4509 return 0;
3235 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0); 4510}
3236 control = (unsigned char)(response & 0xff); 4511
3237 control |= 0x3; 4512/* Patch for VT1718S */
3238 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control); 4513
4514/* capture mixer elements */
4515static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4516 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4517 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4518 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4519 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4520 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4521 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4522 HDA_INPUT),
4523 {
4524 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4525 /* The multiple "Capture Source" controls confuse alsamixer
4526 * So call somewhat different..
4527 */
4528 .name = "Input Source",
4529 .count = 2,
4530 .info = via_mux_enum_info,
4531 .get = via_mux_enum_get,
4532 .put = via_mux_enum_put,
4533 },
4534 { } /* end */
4535};
4536
4537static struct hda_verb vt1718S_volume_init_verbs[] = {
4538 /*
4539 * Unmute ADC0-1 and set the default input to mic-in
4540 */
4541 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4542 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4543
4544
4545 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4546 * mixer widget
4547 */
4548 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4549 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4550 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4551 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4552 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4553 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4554
4555 /* Setup default input of Front HP to MW9 */
4556 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4557 /* PW9 PW10 Output enable */
4558 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4559 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4560 /* PW11 Input enable */
4561 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4562 /* Enable Boost Volume backdoor */
4563 {0x1, 0xf88, 0x8},
4564 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4565 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4566 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4567 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4568 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4569 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4570 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4571 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4572 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4573 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4574 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4575 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4576 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4577 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4578 /* Unmute MW4's index 0 */
4579 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4580 { }
4581};
4582
4583
4584static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4585 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4586 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4587 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4588 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4589 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4590 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4591 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4592 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4593 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4594 { }
4595};
4596
4597static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4598 .substreams = 2,
4599 .channels_min = 2,
4600 .channels_max = 10,
4601 .nid = 0x8, /* NID to query formats and rates */
4602 .ops = {
4603 .open = via_playback_pcm_open,
4604 .prepare = via_playback_multi_pcm_prepare,
4605 .cleanup = via_playback_multi_pcm_cleanup,
4606 .close = via_pcm_open_close,
4607 },
4608};
4609
4610static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4611 .substreams = 2,
4612 .channels_min = 2,
4613 .channels_max = 2,
4614 .nid = 0x10, /* NID to query formats and rates */
4615 .ops = {
4616 .open = via_pcm_open_close,
4617 .prepare = via_capture_pcm_prepare,
4618 .cleanup = via_capture_pcm_cleanup,
4619 .close = via_pcm_open_close,
4620 },
4621};
4622
4623static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4624 .substreams = 2,
4625 .channels_min = 2,
4626 .channels_max = 2,
4627 /* NID is set in via_build_pcms */
4628 .ops = {
4629 .open = via_dig_playback_pcm_open,
4630 .close = via_dig_playback_pcm_close,
4631 .prepare = via_dig_playback_pcm_prepare,
4632 .cleanup = via_dig_playback_pcm_cleanup
4633 },
4634};
4635
4636static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4637 .substreams = 1,
4638 .channels_min = 2,
4639 .channels_max = 2,
4640};
4641
4642/* fill in the dac_nids table from the parsed pin configuration */
4643static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4644 const struct auto_pin_cfg *cfg)
4645{
4646 int i;
4647 hda_nid_t nid;
4648
4649 spec->multiout.num_dacs = cfg->line_outs;
4650
4651 spec->multiout.dac_nids = spec->private_dac_nids;
4652
4653 for (i = 0; i < 4; i++) {
4654 nid = cfg->line_out_pins[i];
4655 if (nid) {
4656 /* config dac list */
4657 switch (i) {
4658 case AUTO_SEQ_FRONT:
4659 spec->multiout.dac_nids[i] = 0x8;
4660 break;
4661 case AUTO_SEQ_CENLFE:
4662 spec->multiout.dac_nids[i] = 0xa;
4663 break;
4664 case AUTO_SEQ_SURROUND:
4665 spec->multiout.dac_nids[i] = 0x9;
4666 break;
4667 case AUTO_SEQ_SIDE:
4668 spec->multiout.dac_nids[i] = 0xb;
4669 break;
4670 }
4671 }
4672 }
4673
4674 return 0;
4675}
4676
4677/* add playback controls from the parsed DAC table */
4678static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4679 const struct auto_pin_cfg *cfg)
4680{
4681 char name[32];
4682 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4683 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4684 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4685 hda_nid_t nid, nid_vol, nid_mute = 0;
4686 int i, err;
4687
4688 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4689 nid = cfg->line_out_pins[i];
4690
4691 if (!nid)
4692 continue;
4693 nid_vol = nid_vols[i];
4694 nid_mute = nid_mutes[i];
4695
4696 if (i == AUTO_SEQ_CENLFE) {
4697 /* Center/LFE */
4698 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4699 "Center Playback Volume",
4700 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4701 HDA_OUTPUT));
4702 if (err < 0)
4703 return err;
4704 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4705 "LFE Playback Volume",
4706 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4707 HDA_OUTPUT));
4708 if (err < 0)
4709 return err;
4710 err = via_add_control(
4711 spec, VIA_CTL_WIDGET_MUTE,
4712 "Center Playback Switch",
4713 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4714 HDA_OUTPUT));
4715 if (err < 0)
4716 return err;
4717 err = via_add_control(
4718 spec, VIA_CTL_WIDGET_MUTE,
4719 "LFE Playback Switch",
4720 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4721 HDA_OUTPUT));
4722 if (err < 0)
4723 return err;
4724 } else if (i == AUTO_SEQ_FRONT) {
4725 /* Front */
4726 sprintf(name, "%s Playback Volume", chname[i]);
4727 err = via_add_control(
4728 spec, VIA_CTL_WIDGET_VOL, name,
4729 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4730 if (err < 0)
4731 return err;
4732 sprintf(name, "%s Playback Switch", chname[i]);
4733 err = via_add_control(
4734 spec, VIA_CTL_WIDGET_MUTE, name,
4735 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4736 HDA_OUTPUT));
4737 if (err < 0)
4738 return err;
4739 } else {
4740 sprintf(name, "%s Playback Volume", chname[i]);
4741 err = via_add_control(
4742 spec, VIA_CTL_WIDGET_VOL, name,
4743 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4744 if (err < 0)
4745 return err;
4746 sprintf(name, "%s Playback Switch", chname[i]);
4747 err = via_add_control(
4748 spec, VIA_CTL_WIDGET_MUTE, name,
4749 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4750 HDA_OUTPUT));
4751 if (err < 0)
4752 return err;
4753 }
4754 }
4755 return 0;
4756}
4757
4758static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4759{
4760 int err;
4761
4762 if (!pin)
4763 return 0;
4764
4765 spec->multiout.hp_nid = 0xc; /* AOW4 */
4766 spec->hp_independent_mode_index = 1;
4767
4768 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4769 "Headphone Playback Volume",
4770 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4771 if (err < 0)
4772 return err;
4773
4774 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4775 "Headphone Playback Switch",
4776 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4777 if (err < 0)
4778 return err;
4779
4780 create_hp_imux(spec);
4781 return 0;
4782}
4783
4784/* create playback/capture controls for input pins */
4785static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4786 const struct auto_pin_cfg *cfg)
4787{
4788 static char *labels[] = {
4789 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4790 };
4791 struct hda_input_mux *imux = &spec->private_imux[0];
4792 int i, err, idx = 0;
4793
4794 /* for internal loopback recording select */
4795 imux->items[imux->num_items].label = "Stereo Mixer";
4796 imux->items[imux->num_items].index = 5;
4797 imux->num_items++;
4798
4799 for (i = 0; i < AUTO_PIN_LAST; i++) {
4800 if (!cfg->input_pins[i])
4801 continue;
4802
4803 switch (cfg->input_pins[i]) {
4804 case 0x2b: /* Mic */
4805 idx = 1;
4806 break;
4807
4808 case 0x2a: /* Line In */
4809 idx = 2;
4810 break;
4811
4812 case 0x29: /* Front Mic */
4813 idx = 3;
4814 break;
4815
4816 case 0x2c: /* CD */
4817 idx = 0;
4818 break;
4819 }
4820 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4821 if (err < 0)
4822 return err;
4823 imux->items[imux->num_items].label = labels[i];
4824 imux->items[imux->num_items].index = idx;
4825 imux->num_items++;
4826 }
4827 return 0;
4828}
4829
4830static int vt1718S_parse_auto_config(struct hda_codec *codec)
4831{
4832 struct via_spec *spec = codec->spec;
4833 int err;
4834
4835 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4836
4837 if (err < 0)
4838 return err;
4839 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4840 if (err < 0)
4841 return err;
4842 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4843 return 0; /* can't find valid BIOS pin config */
4844
4845 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4846 if (err < 0)
4847 return err;
4848 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4849 if (err < 0)
4850 return err;
4851 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4852 if (err < 0)
4853 return err;
4854
4855 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4856
4857 fill_dig_outs(codec);
4858
4859 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4860 spec->dig_in_nid = 0x13;
4861
4862 if (spec->kctls.list)
4863 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4864
4865 spec->input_mux = &spec->private_imux[0];
4866
4867 if (spec->hp_mux)
4868 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4869
4870 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4871
4872 return 1;
4873}
4874
4875#ifdef CONFIG_SND_HDA_POWER_SAVE
4876static struct hda_amp_list vt1718S_loopbacks[] = {
4877 { 0x21, HDA_INPUT, 1 },
4878 { 0x21, HDA_INPUT, 2 },
4879 { 0x21, HDA_INPUT, 3 },
4880 { 0x21, HDA_INPUT, 4 },
4881 { } /* end */
4882};
4883#endif
4884
4885static int patch_vt1718S(struct hda_codec *codec)
4886{
4887 struct via_spec *spec;
4888 int err;
3239 4889
3240 /* Enable GPIO 0&1 for volume&mute control */ 4890 /* create a codec specific record */
3241 /* Enable GPIO 2 for DMIC-DATA */ 4891 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3242 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0); 4892 if (spec == NULL)
3243 control = (unsigned char)((response >> 16) & 0x3f); 4893 return -ENOMEM;
3244 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control); 4894
4895 codec->spec = spec;
4896
4897 /* automatic parse from the BIOS config */
4898 err = vt1718S_parse_auto_config(codec);
4899 if (err < 0) {
4900 via_free(codec);
4901 return err;
4902 } else if (!err) {
4903 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4904 "from BIOS. Using genenic mode...\n");
4905 }
4906
4907 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4908 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4909
4910 if (codec->vendor_id == 0x11060441)
4911 spec->stream_name_analog = "VT2020 Analog";
4912 else if (codec->vendor_id == 0x11064441)
4913 spec->stream_name_analog = "VT1828S Analog";
4914 else
4915 spec->stream_name_analog = "VT1718S Analog";
4916 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4917 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4918
4919 if (codec->vendor_id == 0x11060441)
4920 spec->stream_name_digital = "VT2020 Digital";
4921 else if (codec->vendor_id == 0x11064441)
4922 spec->stream_name_digital = "VT1828S Digital";
4923 else
4924 spec->stream_name_digital = "VT1718S Digital";
4925 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4926 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4927 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4928
4929 if (!spec->adc_nids && spec->input_mux) {
4930 spec->adc_nids = vt1718S_adc_nids;
4931 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4932 get_mux_nids(codec);
4933 override_mic_boost(codec, 0x2b, 0, 3, 40);
4934 override_mic_boost(codec, 0x29, 0, 3, 40);
4935 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4936 spec->num_mixers++;
4937 }
4938
4939 codec->patch_ops = via_patch_ops;
4940
4941 codec->patch_ops.init = via_auto_init;
4942 codec->patch_ops.unsol_event = via_unsol_event;
4943
4944#ifdef CONFIG_SND_HDA_POWER_SAVE
4945 spec->loopback.amplist = vt1718S_loopbacks;
4946#endif
4947
4948 return 0;
4949}
4950
4951/* Patch for VT1716S */
4952
4953static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4954 struct snd_ctl_elem_info *uinfo)
4955{
4956 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4957 uinfo->count = 1;
4958 uinfo->value.integer.min = 0;
4959 uinfo->value.integer.max = 1;
4960 return 0;
4961}
4962
4963static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4964 struct snd_ctl_elem_value *ucontrol)
4965{
4966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4967 int index = 0;
4968
4969 index = snd_hda_codec_read(codec, 0x26, 0,
4970 AC_VERB_GET_CONNECT_SEL, 0);
4971 if (index != -1)
4972 *ucontrol->value.integer.value = index;
4973
4974 return 0;
4975}
4976
4977static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4978 struct snd_ctl_elem_value *ucontrol)
4979{
4980 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4981 struct via_spec *spec = codec->spec;
4982 int index = *ucontrol->value.integer.value;
4983
4984 snd_hda_codec_write(codec, 0x26, 0,
4985 AC_VERB_SET_CONNECT_SEL, index);
4986 spec->dmic_enabled = index;
4987 set_jack_power_state(codec);
4988
4989 return 1;
4990}
4991
4992/* capture mixer elements */
4993static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4994 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4995 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4996 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4997 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4998 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4999 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5000 HDA_INPUT),
5001 {
5002 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5003 .name = "Input Source",
5004 .count = 1,
5005 .info = via_mux_enum_info,
5006 .get = via_mux_enum_get,
5007 .put = via_mux_enum_put,
5008 },
5009 { } /* end */
5010};
5011
5012static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5013 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5014 {
5015 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5016 .name = "Digital Mic Capture Switch",
5017 .count = 1,
5018 .info = vt1716s_dmic_info,
5019 .get = vt1716s_dmic_get,
5020 .put = vt1716s_dmic_put,
5021 },
5022 {} /* end */
5023};
5024
5025
5026/* mono-out mixer elements */
5027static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5028 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5029 { } /* end */
5030};
5031
5032static struct hda_verb vt1716S_volume_init_verbs[] = {
5033 /*
5034 * Unmute ADC0-1 and set the default input to mic-in
5035 */
5036 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5037 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5038
5039
5040 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5041 * mixer widget
5042 */
5043 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5044 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5045 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5046 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5049
5050 /* MUX Indices: Stereo Mixer = 5 */
5051 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5052
5053 /* Setup default input of PW4 to MW0 */
5054 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5055
5056 /* Setup default input of SW1 as MW0 */
5057 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5058
5059 /* Setup default input of SW4 as AOW0 */
5060 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5061
5062 /* PW9 PW10 Output enable */
5063 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5064 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5065
5066 /* Unmute SW1, PW12 */
5067 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5068 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5069 /* PW12 Output enable */
5070 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5071 /* Enable Boost Volume backdoor */
5072 {0x1, 0xf8a, 0x80},
5073 /* don't bybass mixer */
5074 {0x1, 0xf88, 0xc0},
5075 /* Enable mono output */
5076 {0x1, 0xf90, 0x08},
5077 { }
5078};
5079
5080
5081static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5082 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5083 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5084 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5085 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5086 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5087 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5088 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5089 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5090 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5091 { }
5092};
5093
5094static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5095 .substreams = 2,
5096 .channels_min = 2,
5097 .channels_max = 6,
5098 .nid = 0x10, /* NID to query formats and rates */
5099 .ops = {
5100 .open = via_playback_pcm_open,
5101 .prepare = via_playback_multi_pcm_prepare,
5102 .cleanup = via_playback_multi_pcm_cleanup,
5103 .close = via_pcm_open_close,
5104 },
5105};
5106
5107static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5108 .substreams = 2,
5109 .channels_min = 2,
5110 .channels_max = 2,
5111 .nid = 0x13, /* NID to query formats and rates */
5112 .ops = {
5113 .open = via_pcm_open_close,
5114 .prepare = via_capture_pcm_prepare,
5115 .cleanup = via_capture_pcm_cleanup,
5116 .close = via_pcm_open_close,
5117 },
5118};
5119
5120static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5121 .substreams = 2,
5122 .channels_min = 2,
5123 .channels_max = 2,
5124 /* NID is set in via_build_pcms */
5125 .ops = {
5126 .open = via_dig_playback_pcm_open,
5127 .close = via_dig_playback_pcm_close,
5128 .prepare = via_dig_playback_pcm_prepare,
5129 .cleanup = via_dig_playback_pcm_cleanup
5130 },
5131};
5132
5133/* fill in the dac_nids table from the parsed pin configuration */
5134static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5135 const struct auto_pin_cfg *cfg)
5136{ int i;
5137 hda_nid_t nid;
5138
5139 spec->multiout.num_dacs = cfg->line_outs;
5140
5141 spec->multiout.dac_nids = spec->private_dac_nids;
5142
5143 for (i = 0; i < 3; i++) {
5144 nid = cfg->line_out_pins[i];
5145 if (nid) {
5146 /* config dac list */
5147 switch (i) {
5148 case AUTO_SEQ_FRONT:
5149 spec->multiout.dac_nids[i] = 0x10;
5150 break;
5151 case AUTO_SEQ_CENLFE:
5152 spec->multiout.dac_nids[i] = 0x25;
5153 break;
5154 case AUTO_SEQ_SURROUND:
5155 spec->multiout.dac_nids[i] = 0x11;
5156 break;
5157 }
5158 }
5159 }
5160
5161 return 0;
5162}
5163
5164/* add playback controls from the parsed DAC table */
5165static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5166 const struct auto_pin_cfg *cfg)
5167{
5168 char name[32];
5169 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5170 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5171 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5172 hda_nid_t nid, nid_vol, nid_mute;
5173 int i, err;
5174
5175 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5176 nid = cfg->line_out_pins[i];
5177
5178 if (!nid)
5179 continue;
5180
5181 nid_vol = nid_vols[i];
5182 nid_mute = nid_mutes[i];
5183
5184 if (i == AUTO_SEQ_CENLFE) {
5185 err = via_add_control(
5186 spec, VIA_CTL_WIDGET_VOL,
5187 "Center Playback Volume",
5188 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5189 if (err < 0)
5190 return err;
5191 err = via_add_control(
5192 spec, VIA_CTL_WIDGET_VOL,
5193 "LFE Playback Volume",
5194 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5195 if (err < 0)
5196 return err;
5197 err = via_add_control(
5198 spec, VIA_CTL_WIDGET_MUTE,
5199 "Center Playback Switch",
5200 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5201 HDA_OUTPUT));
5202 if (err < 0)
5203 return err;
5204 err = via_add_control(
5205 spec, VIA_CTL_WIDGET_MUTE,
5206 "LFE Playback Switch",
5207 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5208 HDA_OUTPUT));
5209 if (err < 0)
5210 return err;
5211 } else if (i == AUTO_SEQ_FRONT) {
5212
5213 err = via_add_control(
5214 spec, VIA_CTL_WIDGET_VOL,
5215 "Master Front Playback Volume",
5216 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5217 if (err < 0)
5218 return err;
5219 err = via_add_control(
5220 spec, VIA_CTL_WIDGET_MUTE,
5221 "Master Front Playback Switch",
5222 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5223 if (err < 0)
5224 return err;
5225
5226 sprintf(name, "%s Playback Volume", chname[i]);
5227 err = via_add_control(
5228 spec, VIA_CTL_WIDGET_VOL, name,
5229 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5230 if (err < 0)
5231 return err;
5232 sprintf(name, "%s Playback Switch", chname[i]);
5233 err = via_add_control(
5234 spec, VIA_CTL_WIDGET_MUTE, name,
5235 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5236 HDA_OUTPUT));
5237 if (err < 0)
5238 return err;
5239 } else {
5240 sprintf(name, "%s Playback Volume", chname[i]);
5241 err = via_add_control(
5242 spec, VIA_CTL_WIDGET_VOL, name,
5243 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5244 if (err < 0)
5245 return err;
5246 sprintf(name, "%s Playback Switch", chname[i]);
5247 err = via_add_control(
5248 spec, VIA_CTL_WIDGET_MUTE, name,
5249 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5250 HDA_OUTPUT));
5251 if (err < 0)
5252 return err;
5253 }
5254 }
5255 return 0;
5256}
5257
5258static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5259{
5260 int err;
5261
5262 if (!pin)
5263 return 0;
5264
5265 spec->multiout.hp_nid = 0x25; /* AOW3 */
5266 spec->hp_independent_mode_index = 1;
5267
5268 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5269 "Headphone Playback Volume",
5270 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5271 if (err < 0)
5272 return err;
5273
5274 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5275 "Headphone Playback Switch",
5276 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5277 if (err < 0)
5278 return err;
5279
5280 create_hp_imux(spec);
5281 return 0;
5282}
5283
5284/* create playback/capture controls for input pins */
5285static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5286 const struct auto_pin_cfg *cfg)
5287{
5288 static char *labels[] = {
5289 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5290 };
5291 struct hda_input_mux *imux = &spec->private_imux[0];
5292 int i, err, idx = 0;
5293
5294 /* for internal loopback recording select */
5295 imux->items[imux->num_items].label = "Stereo Mixer";
5296 imux->items[imux->num_items].index = 5;
5297 imux->num_items++;
5298
5299 for (i = 0; i < AUTO_PIN_LAST; i++) {
5300 if (!cfg->input_pins[i])
5301 continue;
5302
5303 switch (cfg->input_pins[i]) {
5304 case 0x1a: /* Mic */
5305 idx = 2;
5306 break;
5307
5308 case 0x1b: /* Line In */
5309 idx = 3;
5310 break;
5311
5312 case 0x1e: /* Front Mic */
5313 idx = 4;
5314 break;
5315
5316 case 0x1f: /* CD */
5317 idx = 1;
5318 break;
5319 }
5320 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5321 if (err < 0)
5322 return err;
5323 imux->items[imux->num_items].label = labels[i];
5324 imux->items[imux->num_items].index = idx-1;
5325 imux->num_items++;
5326 }
5327 return 0;
5328}
5329
5330static int vt1716S_parse_auto_config(struct hda_codec *codec)
5331{
5332 struct via_spec *spec = codec->spec;
5333 int err;
5334
5335 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5336 if (err < 0)
5337 return err;
5338 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5339 if (err < 0)
5340 return err;
5341 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5342 return 0; /* can't find valid BIOS pin config */
5343
5344 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5345 if (err < 0)
5346 return err;
5347 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5348 if (err < 0)
5349 return err;
5350 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5351 if (err < 0)
5352 return err;
5353
5354 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5355
5356 fill_dig_outs(codec);
5357
5358 if (spec->kctls.list)
5359 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5360
5361 spec->input_mux = &spec->private_imux[0];
5362
5363 if (spec->hp_mux)
5364 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5365
5366 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
5367
5368 return 1;
5369}
5370
5371#ifdef CONFIG_SND_HDA_POWER_SAVE
5372static struct hda_amp_list vt1716S_loopbacks[] = {
5373 { 0x16, HDA_INPUT, 1 },
5374 { 0x16, HDA_INPUT, 2 },
5375 { 0x16, HDA_INPUT, 3 },
5376 { 0x16, HDA_INPUT, 4 },
5377 { } /* end */
5378};
5379#endif
5380
5381static int patch_vt1716S(struct hda_codec *codec)
5382{
5383 struct via_spec *spec;
5384 int err;
5385
5386 /* create a codec specific record */
5387 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5388 if (spec == NULL)
5389 return -ENOMEM;
5390
5391 codec->spec = spec;
5392
5393 /* automatic parse from the BIOS config */
5394 err = vt1716S_parse_auto_config(codec);
5395 if (err < 0) {
5396 via_free(codec);
5397 return err;
5398 } else if (!err) {
5399 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5400 "from BIOS. Using genenic mode...\n");
5401 }
5402
5403 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5404 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5405
5406 spec->stream_name_analog = "VT1716S Analog";
5407 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5408 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5409
5410 spec->stream_name_digital = "VT1716S Digital";
5411 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5412
5413 if (!spec->adc_nids && spec->input_mux) {
5414 spec->adc_nids = vt1716S_adc_nids;
5415 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5416 get_mux_nids(codec);
5417 override_mic_boost(codec, 0x1a, 0, 3, 40);
5418 override_mic_boost(codec, 0x1e, 0, 3, 40);
5419 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5420 spec->num_mixers++;
5421 }
5422
5423 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5424 spec->num_mixers++;
5425
5426 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5427
5428 codec->patch_ops = via_patch_ops;
5429
5430 codec->patch_ops.init = via_auto_init;
5431 codec->patch_ops.unsol_event = via_unsol_event;
5432
5433#ifdef CONFIG_SND_HDA_POWER_SAVE
5434 spec->loopback.amplist = vt1716S_loopbacks;
5435#endif
5436
5437 return 0;
5438}
5439
5440/* for vt2002P */
5441
5442/* capture mixer elements */
5443static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5444 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5445 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5446 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5447 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5448 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5449 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5450 HDA_INPUT),
5451 {
5452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5453 /* The multiple "Capture Source" controls confuse alsamixer
5454 * So call somewhat different..
5455 */
5456 /* .name = "Capture Source", */
5457 .name = "Input Source",
5458 .count = 2,
5459 .info = via_mux_enum_info,
5460 .get = via_mux_enum_get,
5461 .put = via_mux_enum_put,
5462 },
5463 { } /* end */
5464};
5465
5466static struct hda_verb vt2002P_volume_init_verbs[] = {
5467 /*
5468 * Unmute ADC0-1 and set the default input to mic-in
5469 */
5470 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5471 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5472
5473
5474 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5475 * mixer widget
5476 */
5477 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5478 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5479 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5480 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5481 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5482 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5483
5484 /* MUX Indices: Mic = 0 */
5485 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5486 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5487
5488 /* PW9 Output enable */
5489 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5490
5491 /* Enable Boost Volume backdoor */
5492 {0x1, 0xfb9, 0x24},
5493
5494 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5495 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5496 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5497 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5498 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5499 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5501 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5502 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5503
5504 /* set MUX0/1/4/8 = 0 (AOW0) */
5505 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5506 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5507 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5508 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5509
5510 /* set PW0 index=0 (MW0) */
5511 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5512
5513 /* Enable AOW0 to MW9 */
5514 {0x1, 0xfb8, 0x88},
5515 { }
5516};
5517
5518
5519static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5520 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5521 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5522 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5523 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5524 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5525 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5526 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5527 { }
5528};
5529
5530static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5531 .substreams = 2,
5532 .channels_min = 2,
5533 .channels_max = 2,
5534 .nid = 0x8, /* NID to query formats and rates */
5535 .ops = {
5536 .open = via_playback_pcm_open,
5537 .prepare = via_playback_multi_pcm_prepare,
5538 .cleanup = via_playback_multi_pcm_cleanup,
5539 .close = via_pcm_open_close,
5540 },
5541};
5542
5543static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5544 .substreams = 2,
5545 .channels_min = 2,
5546 .channels_max = 2,
5547 .nid = 0x10, /* NID to query formats and rates */
5548 .ops = {
5549 .open = via_pcm_open_close,
5550 .prepare = via_capture_pcm_prepare,
5551 .cleanup = via_capture_pcm_cleanup,
5552 .close = via_pcm_open_close,
5553 },
5554};
5555
5556static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5557 .substreams = 1,
5558 .channels_min = 2,
5559 .channels_max = 2,
5560 /* NID is set in via_build_pcms */
5561 .ops = {
5562 .open = via_dig_playback_pcm_open,
5563 .close = via_dig_playback_pcm_close,
5564 .prepare = via_dig_playback_pcm_prepare,
5565 .cleanup = via_dig_playback_pcm_cleanup
5566 },
5567};
5568
5569/* fill in the dac_nids table from the parsed pin configuration */
5570static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5571 const struct auto_pin_cfg *cfg)
5572{
5573 spec->multiout.num_dacs = 1;
5574 spec->multiout.dac_nids = spec->private_dac_nids;
5575 if (cfg->line_out_pins[0])
5576 spec->multiout.dac_nids[0] = 0x8;
5577 return 0;
5578}
5579
5580/* add playback controls from the parsed DAC table */
5581static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5582 const struct auto_pin_cfg *cfg)
5583{
5584 int err;
5585
5586 if (!cfg->line_out_pins[0])
5587 return -1;
5588
5589
5590 /* Line-Out: PortE */
5591 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5592 "Master Front Playback Volume",
5593 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5594 if (err < 0)
5595 return err;
5596 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5597 "Master Front Playback Switch",
5598 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5599 if (err < 0)
5600 return err;
5601
5602 return 0;
5603}
5604
5605static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5606{
5607 int err;
5608
5609 if (!pin)
5610 return 0;
5611
5612 spec->multiout.hp_nid = 0x9;
5613 spec->hp_independent_mode_index = 1;
5614
5615 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5616 "Headphone Playback Volume",
5617 HDA_COMPOSE_AMP_VAL(
5618 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5619 if (err < 0)
5620 return err;
5621
5622 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5623 "Headphone Playback Switch",
5624 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5625 if (err < 0)
5626 return err;
5627
5628 create_hp_imux(spec);
5629 return 0;
5630}
5631
5632/* create playback/capture controls for input pins */
5633static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5634 const struct auto_pin_cfg *cfg)
5635{
5636 static char *labels[] = {
5637 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5638 };
5639 struct hda_input_mux *imux = &spec->private_imux[0];
5640 int i, err, idx = 0;
5641
5642 for (i = 0; i < AUTO_PIN_LAST; i++) {
5643 if (!cfg->input_pins[i])
5644 continue;
5645
5646 switch (cfg->input_pins[i]) {
5647 case 0x2b: /* Mic */
5648 idx = 0;
5649 break;
5650
5651 case 0x2a: /* Line In */
5652 idx = 1;
5653 break;
5654
5655 case 0x29: /* Front Mic */
5656 idx = 2;
5657 break;
5658 }
5659 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5660 if (err < 0)
5661 return err;
5662 imux->items[imux->num_items].label = labels[i];
5663 imux->items[imux->num_items].index = idx;
5664 imux->num_items++;
5665 }
5666
5667 /* build volume/mute control of loopback */
5668 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5669 if (err < 0)
5670 return err;
5671
5672 /* for internal loopback recording select */
5673 imux->items[imux->num_items].label = "Stereo Mixer";
5674 imux->items[imux->num_items].index = 3;
5675 imux->num_items++;
5676
5677 /* for digital mic select */
5678 imux->items[imux->num_items].label = "Digital Mic";
5679 imux->items[imux->num_items].index = 4;
5680 imux->num_items++;
5681
5682 return 0;
5683}
5684
5685static int vt2002P_parse_auto_config(struct hda_codec *codec)
5686{
5687 struct via_spec *spec = codec->spec;
5688 int err;
5689
5690
5691 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5692 if (err < 0)
5693 return err;
5694
5695 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5696 if (err < 0)
5697 return err;
5698
5699 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5700 return 0; /* can't find valid BIOS pin config */
5701
5702 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5703 if (err < 0)
5704 return err;
5705 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5706 if (err < 0)
5707 return err;
5708 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5709 if (err < 0)
5710 return err;
5711
5712 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5713
5714 fill_dig_outs(codec);
5715
5716 if (spec->kctls.list)
5717 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5718
5719 spec->input_mux = &spec->private_imux[0];
5720
5721 if (spec->hp_mux)
5722 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5723
5724 return 1;
5725}
5726
5727#ifdef CONFIG_SND_HDA_POWER_SAVE
5728static struct hda_amp_list vt2002P_loopbacks[] = {
5729 { 0x21, HDA_INPUT, 0 },
5730 { 0x21, HDA_INPUT, 1 },
5731 { 0x21, HDA_INPUT, 2 },
5732 { } /* end */
5733};
5734#endif
5735
5736
5737/* patch for vt2002P */
5738static int patch_vt2002P(struct hda_codec *codec)
5739{
5740 struct via_spec *spec;
5741 int err;
5742
5743 /* create a codec specific record */
5744 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5745 if (spec == NULL)
5746 return -ENOMEM;
5747
5748 codec->spec = spec;
5749
5750 /* automatic parse from the BIOS config */
5751 err = vt2002P_parse_auto_config(codec);
5752 if (err < 0) {
5753 via_free(codec);
5754 return err;
5755 } else if (!err) {
5756 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5757 "from BIOS. Using genenic mode...\n");
5758 }
5759
5760 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5761 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5762
5763 spec->stream_name_analog = "VT2002P Analog";
5764 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5765 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5766
5767 spec->stream_name_digital = "VT2002P Digital";
5768 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5769
5770 if (!spec->adc_nids && spec->input_mux) {
5771 spec->adc_nids = vt2002P_adc_nids;
5772 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5773 get_mux_nids(codec);
5774 override_mic_boost(codec, 0x2b, 0, 3, 40);
5775 override_mic_boost(codec, 0x29, 0, 3, 40);
5776 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5777 spec->num_mixers++;
5778 }
5779
5780 codec->patch_ops = via_patch_ops;
5781
5782 codec->patch_ops.init = via_auto_init;
5783 codec->patch_ops.unsol_event = via_unsol_event;
5784
5785#ifdef CONFIG_SND_HDA_POWER_SAVE
5786 spec->loopback.amplist = vt2002P_loopbacks;
5787#endif
5788
5789 return 0;
5790}
5791
5792/* for vt1812 */
5793
5794/* capture mixer elements */
5795static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5796 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5797 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5798 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5799 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5800 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5801 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5802 HDA_INPUT),
5803 {
5804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5805 /* The multiple "Capture Source" controls confuse alsamixer
5806 * So call somewhat different..
5807 */
5808 .name = "Input Source",
5809 .count = 2,
5810 .info = via_mux_enum_info,
5811 .get = via_mux_enum_get,
5812 .put = via_mux_enum_put,
5813 },
5814 { } /* end */
5815};
5816
5817static struct hda_verb vt1812_volume_init_verbs[] = {
5818 /*
5819 * Unmute ADC0-1 and set the default input to mic-in
5820 */
5821 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5822 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5823
5824
5825 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5826 * mixer widget
5827 */
5828 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5829 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5830 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5831 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5832 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5833 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5834
5835 /* MUX Indices: Mic = 0 */
5836 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5837 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5838
5839 /* PW9 Output enable */
5840 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5841
5842 /* Enable Boost Volume backdoor */
5843 {0x1, 0xfb9, 0x24},
5844
5845 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5848 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5849 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5850 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5852 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5853 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5854 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5855 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5856
5857 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5858 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5859 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5860 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5861 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5862 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5863
5864 /* Enable AOW0 to MW9 */
5865 {0x1, 0xfb8, 0xa8},
5866 { }
5867};
5868
5869
5870static struct hda_verb vt1812_uniwill_init_verbs[] = {
5871 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5872 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5873 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5874 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5875 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5876 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5877 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5878 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5879 { }
5880};
5881
5882static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5883 .substreams = 2,
5884 .channels_min = 2,
5885 .channels_max = 2,
5886 .nid = 0x8, /* NID to query formats and rates */
5887 .ops = {
5888 .open = via_playback_pcm_open,
5889 .prepare = via_playback_multi_pcm_prepare,
5890 .cleanup = via_playback_multi_pcm_cleanup,
5891 .close = via_pcm_open_close,
5892 },
5893};
5894
5895static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5896 .substreams = 2,
5897 .channels_min = 2,
5898 .channels_max = 2,
5899 .nid = 0x10, /* NID to query formats and rates */
5900 .ops = {
5901 .open = via_pcm_open_close,
5902 .prepare = via_capture_pcm_prepare,
5903 .cleanup = via_capture_pcm_cleanup,
5904 .close = via_pcm_open_close,
5905 },
5906};
5907
5908static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5909 .substreams = 1,
5910 .channels_min = 2,
5911 .channels_max = 2,
5912 /* NID is set in via_build_pcms */
5913 .ops = {
5914 .open = via_dig_playback_pcm_open,
5915 .close = via_dig_playback_pcm_close,
5916 .prepare = via_dig_playback_pcm_prepare,
5917 .cleanup = via_dig_playback_pcm_cleanup
5918 },
5919};
5920/* fill in the dac_nids table from the parsed pin configuration */
5921static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5922 const struct auto_pin_cfg *cfg)
5923{
5924 spec->multiout.num_dacs = 1;
5925 spec->multiout.dac_nids = spec->private_dac_nids;
5926 if (cfg->line_out_pins[0])
5927 spec->multiout.dac_nids[0] = 0x8;
5928 return 0;
5929}
5930
5931
5932/* add playback controls from the parsed DAC table */
5933static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5934 const struct auto_pin_cfg *cfg)
5935{
5936 int err;
5937
5938 if (!cfg->line_out_pins[0])
5939 return -1;
5940
5941 /* Line-Out: PortE */
5942 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5943 "Master Front Playback Volume",
5944 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5945 if (err < 0)
5946 return err;
5947 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5948 "Master Front Playback Switch",
5949 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5950 if (err < 0)
5951 return err;
5952
5953 return 0;
5954}
5955
5956static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5957{
5958 int err;
5959
5960 if (!pin)
5961 return 0;
5962
5963 spec->multiout.hp_nid = 0x9;
5964 spec->hp_independent_mode_index = 1;
5965
5966
5967 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5968 "Headphone Playback Volume",
5969 HDA_COMPOSE_AMP_VAL(
5970 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5971 if (err < 0)
5972 return err;
5973
5974 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5975 "Headphone Playback Switch",
5976 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5977 if (err < 0)
5978 return err;
5979
5980 create_hp_imux(spec);
5981 return 0;
5982}
5983
5984/* create playback/capture controls for input pins */
5985static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
5986 const struct auto_pin_cfg *cfg)
5987{
5988 static char *labels[] = {
5989 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5990 };
5991 struct hda_input_mux *imux = &spec->private_imux[0];
5992 int i, err, idx = 0;
5993
5994 for (i = 0; i < AUTO_PIN_LAST; i++) {
5995 if (!cfg->input_pins[i])
5996 continue;
5997
5998 switch (cfg->input_pins[i]) {
5999 case 0x2b: /* Mic */
6000 idx = 0;
6001 break;
6002
6003 case 0x2a: /* Line In */
6004 idx = 1;
6005 break;
6006
6007 case 0x29: /* Front Mic */
6008 idx = 2;
6009 break;
6010 }
6011 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6012 if (err < 0)
6013 return err;
6014 imux->items[imux->num_items].label = labels[i];
6015 imux->items[imux->num_items].index = idx;
6016 imux->num_items++;
6017 }
6018 /* build volume/mute control of loopback */
6019 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6020 if (err < 0)
6021 return err;
6022
6023 /* for internal loopback recording select */
6024 imux->items[imux->num_items].label = "Stereo Mixer";
6025 imux->items[imux->num_items].index = 5;
6026 imux->num_items++;
6027
6028 /* for digital mic select */
6029 imux->items[imux->num_items].label = "Digital Mic";
6030 imux->items[imux->num_items].index = 6;
6031 imux->num_items++;
6032
6033 return 0;
6034}
6035
6036static int vt1812_parse_auto_config(struct hda_codec *codec)
6037{
6038 struct via_spec *spec = codec->spec;
6039 int err;
6040
6041
6042 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6043 if (err < 0)
6044 return err;
6045 fill_dig_outs(codec);
6046 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6047 if (err < 0)
6048 return err;
6049
6050 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6051 return 0; /* can't find valid BIOS pin config */
6052
6053 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6054 if (err < 0)
6055 return err;
6056 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6057 if (err < 0)
6058 return err;
6059 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6060 if (err < 0)
6061 return err;
6062
6063 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6064
6065 fill_dig_outs(codec);
6066
6067 if (spec->kctls.list)
6068 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6069
6070 spec->input_mux = &spec->private_imux[0];
6071
6072 if (spec->hp_mux)
6073 spec->mixers[spec->num_mixers++] = via_hp_mixer;
6074
6075 return 1;
6076}
6077
6078#ifdef CONFIG_SND_HDA_POWER_SAVE
6079static struct hda_amp_list vt1812_loopbacks[] = {
6080 { 0x21, HDA_INPUT, 0 },
6081 { 0x21, HDA_INPUT, 1 },
6082 { 0x21, HDA_INPUT, 2 },
6083 { } /* end */
6084};
6085#endif
6086
6087
6088/* patch for vt1812 */
6089static int patch_vt1812(struct hda_codec *codec)
6090{
6091 struct via_spec *spec;
6092 int err;
6093
6094 /* create a codec specific record */
6095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6096 if (spec == NULL)
6097 return -ENOMEM;
6098
6099 codec->spec = spec;
6100
6101 /* automatic parse from the BIOS config */
6102 err = vt1812_parse_auto_config(codec);
6103 if (err < 0) {
6104 via_free(codec);
6105 return err;
6106 } else if (!err) {
6107 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6108 "from BIOS. Using genenic mode...\n");
6109 }
6110
6111
6112 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6113 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6114
6115 spec->stream_name_analog = "VT1812 Analog";
6116 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6117 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6118
6119 spec->stream_name_digital = "VT1812 Digital";
6120 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6121
6122
6123 if (!spec->adc_nids && spec->input_mux) {
6124 spec->adc_nids = vt1812_adc_nids;
6125 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6126 get_mux_nids(codec);
6127 override_mic_boost(codec, 0x2b, 0, 3, 40);
6128 override_mic_boost(codec, 0x29, 0, 3, 40);
6129 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6130 spec->num_mixers++;
6131 }
6132
6133 codec->patch_ops = via_patch_ops;
6134
6135 codec->patch_ops.init = via_auto_init;
6136 codec->patch_ops.unsol_event = via_unsol_event;
6137
6138#ifdef CONFIG_SND_HDA_POWER_SAVE
6139 spec->loopback.amplist = vt1812_loopbacks;
6140#endif
3245 6141
3246 return 0; 6142 return 0;
3247} 6143}
@@ -3318,6 +6214,23 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
3318 .patch = patch_vt1702}, 6214 .patch = patch_vt1702},
3319 { .id = 0x11067398, .name = "VT1702", 6215 { .id = 0x11067398, .name = "VT1702",
3320 .patch = patch_vt1702}, 6216 .patch = patch_vt1702},
6217 { .id = 0x11060428, .name = "VT1718S",
6218 .patch = patch_vt1718S},
6219 { .id = 0x11064428, .name = "VT1718S",
6220 .patch = patch_vt1718S},
6221 { .id = 0x11060441, .name = "VT2020",
6222 .patch = patch_vt1718S},
6223 { .id = 0x11064441, .name = "VT1828S",
6224 .patch = patch_vt1718S},
6225 { .id = 0x11060433, .name = "VT1716S",
6226 .patch = patch_vt1716S},
6227 { .id = 0x1106a721, .name = "VT1716S",
6228 .patch = patch_vt1716S},
6229 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6230 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6231 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6232 { .id = 0x11060440, .name = "VT1818S",
6233 .patch = patch_vt1708S},
3321 {} /* terminator */ 6234 {} /* terminator */
3322}; 6235};
3323 6236
diff --git a/sound/pci/ice1712/Makefile b/sound/pci/ice1712/Makefile
index 536eae2ccf94..f7ce33f00ea5 100644
--- a/sound/pci/ice1712/Makefile
+++ b/sound/pci/ice1712/Makefile
@@ -5,7 +5,7 @@
5 5
6snd-ice17xx-ak4xxx-objs := ak4xxx.o 6snd-ice17xx-ak4xxx-objs := ak4xxx.o
7snd-ice1712-objs := ice1712.o delta.o hoontech.o ews.o 7snd-ice1712-objs := ice1712.o delta.o hoontech.o ews.o
8snd-ice1724-objs := ice1724.o amp.o revo.o aureon.o vt1720_mobo.o pontis.o prodigy192.o prodigy_hifi.o juli.o phase.o wtm.o se.o maya44.o 8snd-ice1724-objs := ice1724.o amp.o revo.o aureon.o vt1720_mobo.o pontis.o prodigy192.o prodigy_hifi.o juli.o phase.o wtm.o se.o maya44.o quartet.o
9 9
10# Toplevel Module Dependency 10# Toplevel Module Dependency
11obj-$(CONFIG_SND_ICE1712) += snd-ice1712.o snd-ice17xx-ak4xxx.o 11obj-$(CONFIG_SND_ICE1712) += snd-ice1712.o snd-ice17xx-ak4xxx.o
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index d74033a2cfbe..c7cff6f8168a 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -298,6 +298,16 @@ static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
298 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */ 298 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
299} 299}
300 300
301static unsigned int snd_ice1712_get_gpio_dir(struct snd_ice1712 *ice)
302{
303 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION);
304}
305
306static unsigned int snd_ice1712_get_gpio_mask(struct snd_ice1712 *ice)
307{
308 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK);
309}
310
301static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data) 311static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
302{ 312{
303 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data); 313 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
@@ -2557,7 +2567,9 @@ static int __devinit snd_ice1712_create(struct snd_card *card,
2557 mutex_init(&ice->i2c_mutex); 2567 mutex_init(&ice->i2c_mutex);
2558 mutex_init(&ice->open_mutex); 2568 mutex_init(&ice->open_mutex);
2559 ice->gpio.set_mask = snd_ice1712_set_gpio_mask; 2569 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2570 ice->gpio.get_mask = snd_ice1712_get_gpio_mask;
2560 ice->gpio.set_dir = snd_ice1712_set_gpio_dir; 2571 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2572 ice->gpio.get_dir = snd_ice1712_get_gpio_dir;
2561 ice->gpio.set_data = snd_ice1712_set_gpio_data; 2573 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2562 ice->gpio.get_data = snd_ice1712_get_gpio_data; 2574 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2563 2575
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index d063149e7047..0da778a69ef8 100644
--- a/sound/pci/ice1712/ice1712.h
+++ b/sound/pci/ice1712/ice1712.h
@@ -359,7 +359,9 @@ struct snd_ice1712 {
359 unsigned int saved[2]; /* for ewx_i2c */ 359 unsigned int saved[2]; /* for ewx_i2c */
360 /* operators */ 360 /* operators */
361 void (*set_mask)(struct snd_ice1712 *ice, unsigned int data); 361 void (*set_mask)(struct snd_ice1712 *ice, unsigned int data);
362 unsigned int (*get_mask)(struct snd_ice1712 *ice);
362 void (*set_dir)(struct snd_ice1712 *ice, unsigned int data); 363 void (*set_dir)(struct snd_ice1712 *ice, unsigned int data);
364 unsigned int (*get_dir)(struct snd_ice1712 *ice);
363 void (*set_data)(struct snd_ice1712 *ice, unsigned int data); 365 void (*set_data)(struct snd_ice1712 *ice, unsigned int data);
364 unsigned int (*get_data)(struct snd_ice1712 *ice); 366 unsigned int (*get_data)(struct snd_ice1712 *ice);
365 /* misc operators - move to another place? */ 367 /* misc operators - move to another place? */
@@ -377,8 +379,11 @@ struct snd_ice1712 {
377 unsigned int (*get_rate)(struct snd_ice1712 *ice); 379 unsigned int (*get_rate)(struct snd_ice1712 *ice);
378 void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate); 380 void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate);
379 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate); 381 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate);
380 void (*set_spdif_clock)(struct snd_ice1712 *ice); 382 int (*set_spdif_clock)(struct snd_ice1712 *ice, int type);
381 383 int (*get_spdif_master_type)(struct snd_ice1712 *ice);
384 char **ext_clock_names;
385 int ext_clock_count;
386 void (*pro_open)(struct snd_ice1712 *, struct snd_pcm_substream *);
382#ifdef CONFIG_PM 387#ifdef CONFIG_PM
383 int (*pm_suspend)(struct snd_ice1712 *); 388 int (*pm_suspend)(struct snd_ice1712 *);
384 int (*pm_resume)(struct snd_ice1712 *); 389 int (*pm_resume)(struct snd_ice1712 *);
@@ -399,6 +404,11 @@ static inline void snd_ice1712_gpio_set_dir(struct snd_ice1712 *ice, unsigned in
399 ice->gpio.set_dir(ice, bits); 404 ice->gpio.set_dir(ice, bits);
400} 405}
401 406
407static inline unsigned int snd_ice1712_gpio_get_dir(struct snd_ice1712 *ice)
408{
409 return ice->gpio.get_dir(ice);
410}
411
402static inline void snd_ice1712_gpio_set_mask(struct snd_ice1712 *ice, unsigned int bits) 412static inline void snd_ice1712_gpio_set_mask(struct snd_ice1712 *ice, unsigned int bits)
403{ 413{
404 ice->gpio.set_mask(ice, bits); 414 ice->gpio.set_mask(ice, bits);
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 10fc92c05574..ae29073eea93 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -53,6 +53,7 @@
53#include "phase.h" 53#include "phase.h"
54#include "wtm.h" 54#include "wtm.h"
55#include "se.h" 55#include "se.h"
56#include "quartet.h"
56 57
57MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 58MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
58MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)"); 59MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
@@ -70,6 +71,7 @@ MODULE_SUPPORTED_DEVICE("{"
70 PHASE_DEVICE_DESC 71 PHASE_DEVICE_DESC
71 WTM_DEVICE_DESC 72 WTM_DEVICE_DESC
72 SE_DEVICE_DESC 73 SE_DEVICE_DESC
74 QTET_DEVICE_DESC
73 "{VIA,VT1720}," 75 "{VIA,VT1720},"
74 "{VIA,VT1724}," 76 "{VIA,VT1724},"
75 "{ICEnsemble,Generic ICE1724}," 77 "{ICEnsemble,Generic ICE1724},"
@@ -104,6 +106,8 @@ static int PRO_RATE_LOCKED;
104static int PRO_RATE_RESET = 1; 106static int PRO_RATE_RESET = 1;
105static unsigned int PRO_RATE_DEFAULT = 44100; 107static unsigned int PRO_RATE_DEFAULT = 44100;
106 108
109static char *ext_clock_names[1] = { "IEC958 In" };
110
107/* 111/*
108 * Basic I/O 112 * Basic I/O
109 */ 113 */
@@ -118,9 +122,12 @@ static inline int stdclock_is_spdif_master(struct snd_ice1712 *ice)
118 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0; 122 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
119} 123}
120 124
125/*
126 * locking rate makes sense only for internal clock mode
127 */
121static inline int is_pro_rate_locked(struct snd_ice1712 *ice) 128static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
122{ 129{
123 return ice->is_spdif_master(ice) || PRO_RATE_LOCKED; 130 return (!ice->is_spdif_master(ice)) && PRO_RATE_LOCKED;
124} 131}
125 132
126/* 133/*
@@ -196,6 +203,12 @@ static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
196 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */ 203 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
197} 204}
198 205
206/* get gpio direction 0 = read, 1 = write */
207static unsigned int snd_vt1724_get_gpio_dir(struct snd_ice1712 *ice)
208{
209 return inl(ICEREG1724(ice, GPIO_DIRECTION));
210}
211
199/* set the gpio mask (0 = writable) */ 212/* set the gpio mask (0 = writable) */
200static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data) 213static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
201{ 214{
@@ -205,6 +218,17 @@ static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
205 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */ 218 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
206} 219}
207 220
221static unsigned int snd_vt1724_get_gpio_mask(struct snd_ice1712 *ice)
222{
223 unsigned int mask;
224 if (!ice->vt1720)
225 mask = (unsigned int)inb(ICEREG1724(ice, GPIO_WRITE_MASK_22));
226 else
227 mask = 0;
228 mask = (mask << 16) | inw(ICEREG1724(ice, GPIO_WRITE_MASK));
229 return mask;
230}
231
208static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data) 232static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
209{ 233{
210 outw(data, ICEREG1724(ice, GPIO_DATA)); 234 outw(data, ICEREG1724(ice, GPIO_DATA));
@@ -651,16 +675,22 @@ static int snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
651 return ((rate == ice->cur_rate) && !force) ? 0 : -EBUSY; 675 return ((rate == ice->cur_rate) && !force) ? 0 : -EBUSY;
652 } 676 }
653 if (!force && is_pro_rate_locked(ice)) { 677 if (!force && is_pro_rate_locked(ice)) {
678 /* comparing required and current rate - makes sense for
679 * internal clock only */
654 spin_unlock_irqrestore(&ice->reg_lock, flags); 680 spin_unlock_irqrestore(&ice->reg_lock, flags);
655 return (rate == ice->cur_rate) ? 0 : -EBUSY; 681 return (rate == ice->cur_rate) ? 0 : -EBUSY;
656 } 682 }
657 683
658 old_rate = ice->get_rate(ice); 684 if (force || !ice->is_spdif_master(ice)) {
659 if (force || (old_rate != rate)) 685 /* force means the rate was switched by ucontrol, otherwise
660 ice->set_rate(ice, rate); 686 * setting clock rate for internal clock mode */
661 else if (rate == ice->cur_rate) { 687 old_rate = ice->get_rate(ice);
662 spin_unlock_irqrestore(&ice->reg_lock, flags); 688 if (force || (old_rate != rate))
663 return 0; 689 ice->set_rate(ice, rate);
690 else if (rate == ice->cur_rate) {
691 spin_unlock_irqrestore(&ice->reg_lock, flags);
692 return 0;
693 }
664 } 694 }
665 695
666 ice->cur_rate = rate; 696 ice->cur_rate = rate;
@@ -1016,6 +1046,8 @@ static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
1016 VT1724_BUFFER_ALIGN); 1046 VT1724_BUFFER_ALIGN);
1017 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1047 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1018 VT1724_BUFFER_ALIGN); 1048 VT1724_BUFFER_ALIGN);
1049 if (ice->pro_open)
1050 ice->pro_open(ice, substream);
1019 return 0; 1051 return 0;
1020} 1052}
1021 1053
@@ -1034,6 +1066,8 @@ static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
1034 VT1724_BUFFER_ALIGN); 1066 VT1724_BUFFER_ALIGN);
1035 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1067 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1036 VT1724_BUFFER_ALIGN); 1068 VT1724_BUFFER_ALIGN);
1069 if (ice->pro_open)
1070 ice->pro_open(ice, substream);
1037 return 0; 1071 return 0;
1038} 1072}
1039 1073
@@ -1787,15 +1821,21 @@ static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1787 struct snd_ctl_elem_info *uinfo) 1821 struct snd_ctl_elem_info *uinfo)
1788{ 1822{
1789 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1823 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1790 1824 int hw_rates_count = ice->hw_rates->count;
1791 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1825 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1792 uinfo->count = 1; 1826 uinfo->count = 1;
1793 uinfo->value.enumerated.items = ice->hw_rates->count + 1; 1827
1828 uinfo->value.enumerated.items = hw_rates_count + ice->ext_clock_count;
1829 /* upper limit - keep at top */
1794 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1830 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1795 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1831 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1796 if (uinfo->value.enumerated.item == uinfo->value.enumerated.items - 1) 1832 if (uinfo->value.enumerated.item >= hw_rates_count)
1797 strcpy(uinfo->value.enumerated.name, "IEC958 Input"); 1833 /* ext_clock items */
1834 strcpy(uinfo->value.enumerated.name,
1835 ice->ext_clock_names[
1836 uinfo->value.enumerated.item - hw_rates_count]);
1798 else 1837 else
1838 /* int clock items */
1799 sprintf(uinfo->value.enumerated.name, "%d", 1839 sprintf(uinfo->value.enumerated.name, "%d",
1800 ice->hw_rates->list[uinfo->value.enumerated.item]); 1840 ice->hw_rates->list[uinfo->value.enumerated.item]);
1801 return 0; 1841 return 0;
@@ -1809,7 +1849,8 @@ static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1809 1849
1810 spin_lock_irq(&ice->reg_lock); 1850 spin_lock_irq(&ice->reg_lock);
1811 if (ice->is_spdif_master(ice)) { 1851 if (ice->is_spdif_master(ice)) {
1812 ucontrol->value.enumerated.item[0] = ice->hw_rates->count; 1852 ucontrol->value.enumerated.item[0] = ice->hw_rates->count +
1853 ice->get_spdif_master_type(ice);
1813 } else { 1854 } else {
1814 rate = ice->get_rate(ice); 1855 rate = ice->get_rate(ice);
1815 ucontrol->value.enumerated.item[0] = 0; 1856 ucontrol->value.enumerated.item[0] = 0;
@@ -1824,8 +1865,14 @@ static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1824 return 0; 1865 return 0;
1825} 1866}
1826 1867
1868static int stdclock_get_spdif_master_type(struct snd_ice1712 *ice)
1869{
1870 /* standard external clock - only single type - SPDIF IN */
1871 return 0;
1872}
1873
1827/* setting clock to external - SPDIF */ 1874/* setting clock to external - SPDIF */
1828static void stdclock_set_spdif_clock(struct snd_ice1712 *ice) 1875static int stdclock_set_spdif_clock(struct snd_ice1712 *ice, int type)
1829{ 1876{
1830 unsigned char oval; 1877 unsigned char oval;
1831 unsigned char i2s_oval; 1878 unsigned char i2s_oval;
@@ -1834,27 +1881,30 @@ static void stdclock_set_spdif_clock(struct snd_ice1712 *ice)
1834 /* setting 256fs */ 1881 /* setting 256fs */
1835 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT)); 1882 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1836 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT)); 1883 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT));
1884 return 0;
1837} 1885}
1838 1886
1887
1839static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol, 1888static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1840 struct snd_ctl_elem_value *ucontrol) 1889 struct snd_ctl_elem_value *ucontrol)
1841{ 1890{
1842 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1891 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1843 unsigned int old_rate, new_rate; 1892 unsigned int old_rate, new_rate;
1844 unsigned int item = ucontrol->value.enumerated.item[0]; 1893 unsigned int item = ucontrol->value.enumerated.item[0];
1845 unsigned int spdif = ice->hw_rates->count; 1894 unsigned int first_ext_clock = ice->hw_rates->count;
1846 1895
1847 if (item > spdif) 1896 if (item > first_ext_clock + ice->ext_clock_count - 1)
1848 return -EINVAL; 1897 return -EINVAL;
1849 1898
1899 /* if rate = 0 => external clock */
1850 spin_lock_irq(&ice->reg_lock); 1900 spin_lock_irq(&ice->reg_lock);
1851 if (ice->is_spdif_master(ice)) 1901 if (ice->is_spdif_master(ice))
1852 old_rate = 0; 1902 old_rate = 0;
1853 else 1903 else
1854 old_rate = ice->get_rate(ice); 1904 old_rate = ice->get_rate(ice);
1855 if (item == spdif) { 1905 if (item >= first_ext_clock) {
1856 /* switching to external clock via SPDIF */ 1906 /* switching to external clock */
1857 ice->set_spdif_clock(ice); 1907 ice->set_spdif_clock(ice, item - first_ext_clock);
1858 new_rate = 0; 1908 new_rate = 0;
1859 } else { 1909 } else {
1860 /* internal on-card clock */ 1910 /* internal on-card clock */
@@ -1866,7 +1916,7 @@ static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1866 } 1916 }
1867 spin_unlock_irq(&ice->reg_lock); 1917 spin_unlock_irq(&ice->reg_lock);
1868 1918
1869 /* the first reset to the SPDIF master mode? */ 1919 /* the first switch to the ext. clock mode? */
1870 if (old_rate != new_rate && !new_rate) { 1920 if (old_rate != new_rate && !new_rate) {
1871 /* notify akm chips as well */ 1921 /* notify akm chips as well */
1872 unsigned int i; 1922 unsigned int i;
@@ -2136,6 +2186,7 @@ static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2136 snd_vt1724_phase_cards, 2186 snd_vt1724_phase_cards,
2137 snd_vt1724_wtm_cards, 2187 snd_vt1724_wtm_cards,
2138 snd_vt1724_se_cards, 2188 snd_vt1724_se_cards,
2189 snd_vt1724_qtet_cards,
2139 NULL, 2190 NULL,
2140}; 2191};
2141 2192
@@ -2434,7 +2485,9 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2434 mutex_init(&ice->open_mutex); 2485 mutex_init(&ice->open_mutex);
2435 mutex_init(&ice->i2c_mutex); 2486 mutex_init(&ice->i2c_mutex);
2436 ice->gpio.set_mask = snd_vt1724_set_gpio_mask; 2487 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2488 ice->gpio.get_mask = snd_vt1724_get_gpio_mask;
2437 ice->gpio.set_dir = snd_vt1724_set_gpio_dir; 2489 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2490 ice->gpio.get_dir = snd_vt1724_get_gpio_dir;
2438 ice->gpio.set_data = snd_vt1724_set_gpio_data; 2491 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2439 ice->gpio.get_data = snd_vt1724_get_gpio_data; 2492 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2440 ice->card = card; 2493 ice->card = card;
@@ -2522,6 +2575,9 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2522 return err; 2575 return err;
2523 } 2576 }
2524 2577
2578 /* field init before calling chip_init */
2579 ice->ext_clock_count = 0;
2580
2525 for (tbl = card_tables; *tbl; tbl++) { 2581 for (tbl = card_tables; *tbl; tbl++) {
2526 for (c = *tbl; c->subvendor; c++) { 2582 for (c = *tbl; c->subvendor; c++) {
2527 if (c->subvendor == ice->eeprom.subvendor) { 2583 if (c->subvendor == ice->eeprom.subvendor) {
@@ -2560,6 +2616,13 @@ __found:
2560 ice->set_mclk = stdclock_set_mclk; 2616 ice->set_mclk = stdclock_set_mclk;
2561 if (!ice->set_spdif_clock) 2617 if (!ice->set_spdif_clock)
2562 ice->set_spdif_clock = stdclock_set_spdif_clock; 2618 ice->set_spdif_clock = stdclock_set_spdif_clock;
2619 if (!ice->get_spdif_master_type)
2620 ice->get_spdif_master_type = stdclock_get_spdif_master_type;
2621 if (!ice->ext_clock_names)
2622 ice->ext_clock_names = ext_clock_names;
2623 if (!ice->ext_clock_count)
2624 ice->ext_clock_count = ARRAY_SIZE(ext_clock_names);
2625
2563 if (!ice->hw_rates) 2626 if (!ice->hw_rates)
2564 set_std_hw_rates(ice); 2627 set_std_hw_rates(ice);
2565 2628
@@ -2719,7 +2782,7 @@ static int snd_vt1724_resume(struct pci_dev *pci)
2719 2782
2720 if (ice->pm_saved_is_spdif_master) { 2783 if (ice->pm_saved_is_spdif_master) {
2721 /* switching to external clock via SPDIF */ 2784 /* switching to external clock via SPDIF */
2722 ice->set_spdif_clock(ice); 2785 ice->set_spdif_clock(ice, 0);
2723 } else { 2786 } else {
2724 /* internal on-card clock */ 2787 /* internal on-card clock */
2725 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1); 2788 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index fd948bfd9aef..98bc3b7681b5 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -380,7 +380,7 @@ static struct snd_kcontrol_new juli_mute_controls[] __devinitdata = {
380 * inputs) are fed from Xilinx. 380 * inputs) are fed from Xilinx.
381 * 381 *
382 * I even checked traces on board and coded a support in driver for 382 * I even checked traces on board and coded a support in driver for
383 * an alternative possiblity - the unused I2S ICE output channels 383 * an alternative possibility - the unused I2S ICE output channels
384 * switched to HW-IN/SPDIF-IN and providing the monitoring signal to 384 * switched to HW-IN/SPDIF-IN and providing the monitoring signal to
385 * the DAC - to no avail. The I2S outputs seem to be unconnected. 385 * the DAC - to no avail. The I2S outputs seem to be unconnected.
386 * 386 *
@@ -412,25 +412,6 @@ static struct snd_kcontrol_new juli_mute_controls[] __devinitdata = {
412 }, 412 },
413}; 413};
414 414
415
416static void ak4358_proc_regs_read(struct snd_info_entry *entry,
417 struct snd_info_buffer *buffer)
418{
419 struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
420 int reg, val;
421 for (reg = 0; reg <= 0xf; reg++) {
422 val = snd_akm4xxx_get(ice->akm, 0, reg);
423 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
424 }
425}
426
427static void ak4358_proc_init(struct snd_ice1712 *ice)
428{
429 struct snd_info_entry *entry;
430 if (!snd_card_proc_new(ice->card, "ak4358_codec", &entry))
431 snd_info_set_text_ops(entry, ice, ak4358_proc_regs_read);
432}
433
434static char *slave_vols[] __devinitdata = { 415static char *slave_vols[] __devinitdata = {
435 PCM_VOLUME, 416 PCM_VOLUME,
436 MONITOR_AN_IN_VOLUME, 417 MONITOR_AN_IN_VOLUME,
@@ -496,14 +477,37 @@ static int __devinit juli_add_controls(struct snd_ice1712 *ice)
496 /* only capture SPDIF over AK4114 */ 477 /* only capture SPDIF over AK4114 */
497 err = snd_ak4114_build(spec->ak4114, NULL, 478 err = snd_ak4114_build(spec->ak4114, NULL,
498 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 479 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
499
500 ak4358_proc_init(ice);
501 if (err < 0) 480 if (err < 0)
502 return err; 481 return err;
503 return 0; 482 return 0;
504} 483}
505 484
506/* 485/*
486 * suspend/resume
487 * */
488
489#ifdef CONFIG_PM
490static int juli_resume(struct snd_ice1712 *ice)
491{
492 struct snd_akm4xxx *ak = ice->akm;
493 struct juli_spec *spec = ice->spec;
494 /* akm4358 un-reset, un-mute */
495 snd_akm4xxx_reset(ak, 0);
496 /* reinit ak4114 */
497 snd_ak4114_reinit(spec->ak4114);
498 return 0;
499}
500
501static int juli_suspend(struct snd_ice1712 *ice)
502{
503 struct snd_akm4xxx *ak = ice->akm;
504 /* akm4358 reset and soft-mute */
505 snd_akm4xxx_reset(ak, 1);
506 return 0;
507}
508#endif
509
510/*
507 * initialize the chip 511 * initialize the chip
508 */ 512 */
509 513
@@ -550,13 +554,14 @@ static inline unsigned char juli_set_mclk(struct snd_ice1712 *ice,
550} 554}
551 555
552/* setting clock to external - SPDIF */ 556/* setting clock to external - SPDIF */
553static void juli_set_spdif_clock(struct snd_ice1712 *ice) 557static int juli_set_spdif_clock(struct snd_ice1712 *ice, int type)
554{ 558{
555 unsigned int old; 559 unsigned int old;
556 old = ice->gpio.get_data(ice); 560 old = ice->gpio.get_data(ice);
557 /* external clock (= 0), multiply 1x, 48kHz */ 561 /* external clock (= 0), multiply 1x, 48kHz */
558 ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X | 562 ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X |
559 GPIO_FREQ_48KHZ); 563 GPIO_FREQ_48KHZ);
564 return 0;
560} 565}
561 566
562/* Called when ak4114 detects change in the input SPDIF stream */ 567/* Called when ak4114 detects change in the input SPDIF stream */
@@ -646,6 +651,13 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
646 ice->set_spdif_clock = juli_set_spdif_clock; 651 ice->set_spdif_clock = juli_set_spdif_clock;
647 652
648 ice->spdif.ops.open = juli_spdif_in_open; 653 ice->spdif.ops.open = juli_spdif_in_open;
654
655#ifdef CONFIG_PM
656 ice->pm_resume = juli_resume;
657 ice->pm_suspend = juli_suspend;
658 ice->pm_suspend_enabled = 1;
659#endif
660
649 return 0; 661 return 0;
650} 662}
651 663
diff --git a/sound/pci/ice1712/quartet.c b/sound/pci/ice1712/quartet.c
new file mode 100644
index 000000000000..1948632787e6
--- /dev/null
+++ b/sound/pci/ice1712/quartet.c
@@ -0,0 +1,1130 @@
1/*
2 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
3 *
4 * Lowlevel functions for Infrasonic Quartet
5 *
6 * Copyright (c) 2009 Pavel Hofman <pavel.hofman@ivitera.com>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program 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 this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <asm/io.h>
26#include <linux/delay.h>
27#include <linux/interrupt.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <sound/core.h>
31#include <sound/tlv.h>
32#include <sound/info.h>
33
34#include "ice1712.h"
35#include "envy24ht.h"
36#include <sound/ak4113.h>
37#include "quartet.h"
38
39struct qtet_spec {
40 struct ak4113 *ak4113;
41 unsigned int scr; /* system control register */
42 unsigned int mcr; /* monitoring control register */
43 unsigned int cpld; /* cpld register */
44};
45
46struct qtet_kcontrol_private {
47 unsigned int bit;
48 void (*set_register)(struct snd_ice1712 *ice, unsigned int val);
49 unsigned int (*get_register)(struct snd_ice1712 *ice);
50 unsigned char *texts[2];
51};
52
53enum {
54 IN12_SEL = 0,
55 IN34_SEL,
56 AIN34_SEL,
57 COAX_OUT,
58 IN12_MON12,
59 IN12_MON34,
60 IN34_MON12,
61 IN34_MON34,
62 OUT12_MON34,
63 OUT34_MON12,
64};
65
66static char *ext_clock_names[3] = {"IEC958 In", "Word Clock 1xFS",
67 "Word Clock 256xFS"};
68
69/* chip address on I2C bus */
70#define AK4113_ADDR 0x26 /* S/PDIF receiver */
71
72/* chip address on SPI bus */
73#define AK4620_ADDR 0x02 /* ADC/DAC */
74
75
76/*
77 * GPIO pins
78 */
79
80/* GPIO0 - O - DATA0, def. 0 */
81#define GPIO_D0 (1<<0)
82/* GPIO1 - I/O - DATA1, Jack Detect Input0 (0:present, 1:missing), def. 1 */
83#define GPIO_D1_JACKDTC0 (1<<1)
84/* GPIO2 - I/O - DATA2, Jack Detect Input1 (0:present, 1:missing), def. 1 */
85#define GPIO_D2_JACKDTC1 (1<<2)
86/* GPIO3 - I/O - DATA3, def. 1 */
87#define GPIO_D3 (1<<3)
88/* GPIO4 - I/O - DATA4, SPI CDTO, def. 1 */
89#define GPIO_D4_SPI_CDTO (1<<4)
90/* GPIO5 - I/O - DATA5, SPI CCLK, def. 1 */
91#define GPIO_D5_SPI_CCLK (1<<5)
92/* GPIO6 - I/O - DATA6, Cable Detect Input (0:detected, 1:not detected */
93#define GPIO_D6_CD (1<<6)
94/* GPIO7 - I/O - DATA7, Device Detect Input (0:detected, 1:not detected */
95#define GPIO_D7_DD (1<<7)
96/* GPIO8 - O - CPLD Chip Select, def. 1 */
97#define GPIO_CPLD_CSN (1<<8)
98/* GPIO9 - O - CPLD register read/write (0:write, 1:read), def. 0 */
99#define GPIO_CPLD_RW (1<<9)
100/* GPIO10 - O - SPI Chip Select for CODEC#0, def. 1 */
101#define GPIO_SPI_CSN0 (1<<10)
102/* GPIO11 - O - SPI Chip Select for CODEC#1, def. 1 */
103#define GPIO_SPI_CSN1 (1<<11)
104/* GPIO12 - O - Ex. Register Output Enable (0:enable, 1:disable), def. 1,
105 * init 0 */
106#define GPIO_EX_GPIOE (1<<12)
107/* GPIO13 - O - Ex. Register0 Chip Select for System Control Register,
108 * def. 1 */
109#define GPIO_SCR (1<<13)
110/* GPIO14 - O - Ex. Register1 Chip Select for Monitor Control Register,
111 * def. 1 */
112#define GPIO_MCR (1<<14)
113
114#define GPIO_SPI_ALL (GPIO_D4_SPI_CDTO | GPIO_D5_SPI_CCLK |\
115 GPIO_SPI_CSN0 | GPIO_SPI_CSN1)
116
117#define GPIO_DATA_MASK (GPIO_D0 | GPIO_D1_JACKDTC0 | \
118 GPIO_D2_JACKDTC1 | GPIO_D3 | \
119 GPIO_D4_SPI_CDTO | GPIO_D5_SPI_CCLK | \
120 GPIO_D6_CD | GPIO_D7_DD)
121
122/* System Control Register GPIO_SCR data bits */
123/* Mic/Line select relay (0:line, 1:mic) */
124#define SCR_RELAY GPIO_D0
125/* Phantom power drive control (0:5V, 1:48V) */
126#define SCR_PHP_V GPIO_D1_JACKDTC0
127/* H/W mute control (0:Normal, 1:Mute) */
128#define SCR_MUTE GPIO_D2_JACKDTC1
129/* Phantom power control (0:Phantom on, 1:off) */
130#define SCR_PHP GPIO_D3
131/* Analog input 1/2 Source Select */
132#define SCR_AIN12_SEL0 GPIO_D4_SPI_CDTO
133#define SCR_AIN12_SEL1 GPIO_D5_SPI_CCLK
134/* Analog input 3/4 Source Select (0:line, 1:hi-z) */
135#define SCR_AIN34_SEL GPIO_D6_CD
136/* Codec Power Down (0:power down, 1:normal) */
137#define SCR_CODEC_PDN GPIO_D7_DD
138
139#define SCR_AIN12_LINE (0)
140#define SCR_AIN12_MIC (SCR_AIN12_SEL0)
141#define SCR_AIN12_LOWCUT (SCR_AIN12_SEL1 | SCR_AIN12_SEL0)
142
143/* Monitor Control Register GPIO_MCR data bits */
144/* Input 1/2 to Monitor 1/2 (0:off, 1:on) */
145#define MCR_IN12_MON12 GPIO_D0
146/* Input 1/2 to Monitor 3/4 (0:off, 1:on) */
147#define MCR_IN12_MON34 GPIO_D1_JACKDTC0
148/* Input 3/4 to Monitor 1/2 (0:off, 1:on) */
149#define MCR_IN34_MON12 GPIO_D2_JACKDTC1
150/* Input 3/4 to Monitor 3/4 (0:off, 1:on) */
151#define MCR_IN34_MON34 GPIO_D3
152/* Output to Monitor 1/2 (0:off, 1:on) */
153#define MCR_OUT34_MON12 GPIO_D4_SPI_CDTO
154/* Output to Monitor 3/4 (0:off, 1:on) */
155#define MCR_OUT12_MON34 GPIO_D5_SPI_CCLK
156
157/* CPLD Register DATA bits */
158/* Clock Rate Select */
159#define CPLD_CKS0 GPIO_D0
160#define CPLD_CKS1 GPIO_D1_JACKDTC0
161#define CPLD_CKS2 GPIO_D2_JACKDTC1
162/* Sync Source Select (0:Internal, 1:External) */
163#define CPLD_SYNC_SEL GPIO_D3
164/* Word Clock FS Select (0:FS, 1:256FS) */
165#define CPLD_WORD_SEL GPIO_D4_SPI_CDTO
166/* Coaxial Output Source (IS-Link) (0:SPDIF, 1:I2S) */
167#define CPLD_COAX_OUT GPIO_D5_SPI_CCLK
168/* Input 1/2 Source Select (0:Analog12, 1:An34) */
169#define CPLD_IN12_SEL GPIO_D6_CD
170/* Input 3/4 Source Select (0:Analog34, 1:Digital In) */
171#define CPLD_IN34_SEL GPIO_D7_DD
172
173/* internal clock (CPLD_SYNC_SEL = 0) options */
174#define CPLD_CKS_44100HZ (0)
175#define CPLD_CKS_48000HZ (CPLD_CKS0)
176#define CPLD_CKS_88200HZ (CPLD_CKS1)
177#define CPLD_CKS_96000HZ (CPLD_CKS1 | CPLD_CKS0)
178#define CPLD_CKS_176400HZ (CPLD_CKS2)
179#define CPLD_CKS_192000HZ (CPLD_CKS2 | CPLD_CKS0)
180
181#define CPLD_CKS_MASK (CPLD_CKS0 | CPLD_CKS1 | CPLD_CKS2)
182
183/* external clock (CPLD_SYNC_SEL = 1) options */
184/* external clock - SPDIF */
185#define CPLD_EXT_SPDIF (0 | CPLD_SYNC_SEL)
186/* external clock - WordClock 1xfs */
187#define CPLD_EXT_WORDCLOCK_1FS (CPLD_CKS1 | CPLD_SYNC_SEL)
188/* external clock - WordClock 256xfs */
189#define CPLD_EXT_WORDCLOCK_256FS (CPLD_CKS1 | CPLD_WORD_SEL |\
190 CPLD_SYNC_SEL)
191
192#define EXT_SPDIF_TYPE 0
193#define EXT_WORDCLOCK_1FS_TYPE 1
194#define EXT_WORDCLOCK_256FS_TYPE 2
195
196#define AK4620_DFS0 (1<<0)
197#define AK4620_DFS1 (1<<1)
198#define AK4620_CKS0 (1<<2)
199#define AK4620_CKS1 (1<<3)
200/* Clock and Format Control register */
201#define AK4620_DFS_REG 0x02
202
203/* Deem and Volume Control register */
204#define AK4620_DEEMVOL_REG 0x03
205#define AK4620_SMUTE (1<<7)
206
207/*
208 * Conversion from int value to its binary form. Used for debugging.
209 * The output buffer must be allocated prior to calling the function.
210 */
211static char *get_binary(char *buffer, int value)
212{
213 int i, j, pos;
214 pos = 0;
215 for (i = 0; i < 4; ++i) {
216 for (j = 0; j < 8; ++j) {
217 if (value & (1 << (31-(i*8 + j))))
218 buffer[pos] = '1';
219 else
220 buffer[pos] = '0';
221 pos++;
222 }
223 if (i < 3) {
224 buffer[pos] = ' ';
225 pos++;
226 }
227 }
228 buffer[pos] = '\0';
229 return buffer;
230}
231
232/*
233 * Initial setup of the conversion array GPIO <-> rate
234 */
235static unsigned int qtet_rates[] = {
236 44100, 48000, 88200,
237 96000, 176400, 192000,
238};
239
240static unsigned int cks_vals[] = {
241 CPLD_CKS_44100HZ, CPLD_CKS_48000HZ, CPLD_CKS_88200HZ,
242 CPLD_CKS_96000HZ, CPLD_CKS_176400HZ, CPLD_CKS_192000HZ,
243};
244
245static struct snd_pcm_hw_constraint_list qtet_rates_info = {
246 .count = ARRAY_SIZE(qtet_rates),
247 .list = qtet_rates,
248 .mask = 0,
249};
250
251static void qtet_ak4113_write(void *private_data, unsigned char reg,
252 unsigned char val)
253{
254 snd_vt1724_write_i2c((struct snd_ice1712 *)private_data, AK4113_ADDR,
255 reg, val);
256}
257
258static unsigned char qtet_ak4113_read(void *private_data, unsigned char reg)
259{
260 return snd_vt1724_read_i2c((struct snd_ice1712 *)private_data,
261 AK4113_ADDR, reg);
262}
263
264
265/*
266 * AK4620 section
267 */
268
269/*
270 * Write data to addr register of ak4620
271 */
272static void qtet_akm_write(struct snd_akm4xxx *ak, int chip,
273 unsigned char addr, unsigned char data)
274{
275 unsigned int tmp, orig_dir;
276 int idx;
277 unsigned int addrdata;
278 struct snd_ice1712 *ice = ak->private_data[0];
279
280 if (snd_BUG_ON(chip < 0 || chip >= 4))
281 return;
282 /*printk(KERN_DEBUG "Writing to AK4620: chip=%d, addr=0x%x,
283 data=0x%x\n", chip, addr, data);*/
284 orig_dir = ice->gpio.get_dir(ice);
285 ice->gpio.set_dir(ice, orig_dir | GPIO_SPI_ALL);
286 /* set mask - only SPI bits */
287 ice->gpio.set_mask(ice, ~GPIO_SPI_ALL);
288
289 tmp = ice->gpio.get_data(ice);
290 /* high all */
291 tmp |= GPIO_SPI_ALL;
292 ice->gpio.set_data(ice, tmp);
293 udelay(100);
294 /* drop chip select */
295 if (chip)
296 /* CODEC 1 */
297 tmp &= ~GPIO_SPI_CSN1;
298 else
299 tmp &= ~GPIO_SPI_CSN0;
300 ice->gpio.set_data(ice, tmp);
301 udelay(100);
302
303 /* build I2C address + data byte */
304 addrdata = (AK4620_ADDR << 6) | 0x20 | (addr & 0x1f);
305 addrdata = (addrdata << 8) | data;
306 for (idx = 15; idx >= 0; idx--) {
307 /* drop clock */
308 tmp &= ~GPIO_D5_SPI_CCLK;
309 ice->gpio.set_data(ice, tmp);
310 udelay(100);
311 /* set data */
312 if (addrdata & (1 << idx))
313 tmp |= GPIO_D4_SPI_CDTO;
314 else
315 tmp &= ~GPIO_D4_SPI_CDTO;
316 ice->gpio.set_data(ice, tmp);
317 udelay(100);
318 /* raise clock */
319 tmp |= GPIO_D5_SPI_CCLK;
320 ice->gpio.set_data(ice, tmp);
321 udelay(100);
322 }
323 /* all back to 1 */
324 tmp |= GPIO_SPI_ALL;
325 ice->gpio.set_data(ice, tmp);
326 udelay(100);
327
328 /* return all gpios to non-writable */
329 ice->gpio.set_mask(ice, 0xffffff);
330 /* restore GPIOs direction */
331 ice->gpio.set_dir(ice, orig_dir);
332}
333
334static void qtet_akm_set_regs(struct snd_akm4xxx *ak, unsigned char addr,
335 unsigned char mask, unsigned char value)
336{
337 unsigned char tmp;
338 int chip;
339 for (chip = 0; chip < ak->num_chips; chip++) {
340 tmp = snd_akm4xxx_get(ak, chip, addr);
341 /* clear the bits */
342 tmp &= ~mask;
343 /* set the new bits */
344 tmp |= value;
345 snd_akm4xxx_write(ak, chip, addr, tmp);
346 }
347}
348
349/*
350 * change the rate of AK4620
351 */
352static void qtet_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
353{
354 unsigned char ak4620_dfs;
355
356 if (rate == 0) /* no hint - S/PDIF input is master or the new spdif
357 input rate undetected, simply return */
358 return;
359
360 /* adjust DFS on codecs - see datasheet */
361 if (rate > 108000)
362 ak4620_dfs = AK4620_DFS1 | AK4620_CKS1;
363 else if (rate > 54000)
364 ak4620_dfs = AK4620_DFS0 | AK4620_CKS0;
365 else
366 ak4620_dfs = 0;
367
368 /* set new value */
369 qtet_akm_set_regs(ak, AK4620_DFS_REG, AK4620_DFS0 | AK4620_DFS1 |
370 AK4620_CKS0 | AK4620_CKS1, ak4620_dfs);
371}
372
373#define AK_CONTROL(xname, xch) { .name = xname, .num_channels = xch }
374
375#define PCM_12_PLAYBACK_VOLUME "PCM 1/2 Playback Volume"
376#define PCM_34_PLAYBACK_VOLUME "PCM 3/4 Playback Volume"
377#define PCM_12_CAPTURE_VOLUME "PCM 1/2 Capture Volume"
378#define PCM_34_CAPTURE_VOLUME "PCM 3/4 Capture Volume"
379
380static const struct snd_akm4xxx_dac_channel qtet_dac[] = {
381 AK_CONTROL(PCM_12_PLAYBACK_VOLUME, 2),
382 AK_CONTROL(PCM_34_PLAYBACK_VOLUME, 2),
383};
384
385static const struct snd_akm4xxx_adc_channel qtet_adc[] = {
386 AK_CONTROL(PCM_12_CAPTURE_VOLUME, 2),
387 AK_CONTROL(PCM_34_CAPTURE_VOLUME, 2),
388};
389
390static struct snd_akm4xxx akm_qtet_dac __devinitdata = {
391 .type = SND_AK4620,
392 .num_dacs = 4, /* DAC1 - Output 12
393 */
394 .num_adcs = 4, /* ADC1 - Input 12
395 */
396 .ops = {
397 .write = qtet_akm_write,
398 .set_rate_val = qtet_akm_set_rate_val,
399 },
400 .dac_info = qtet_dac,
401 .adc_info = qtet_adc,
402};
403
404/* Communication routines with the CPLD */
405
406
407/* Writes data to external register reg, both reg and data are
408 * GPIO representations */
409static void reg_write(struct snd_ice1712 *ice, unsigned int reg,
410 unsigned int data)
411{
412 unsigned int tmp;
413
414 mutex_lock(&ice->gpio_mutex);
415 /* set direction of used GPIOs*/
416 /* all outputs */
417 tmp = 0x00ffff;
418 ice->gpio.set_dir(ice, tmp);
419 /* mask - writable bits */
420 ice->gpio.set_mask(ice, ~(tmp));
421 /* write the data */
422 tmp = ice->gpio.get_data(ice);
423 tmp &= ~GPIO_DATA_MASK;
424 tmp |= data;
425 ice->gpio.set_data(ice, tmp);
426 udelay(100);
427 /* drop output enable */
428 tmp &= ~GPIO_EX_GPIOE;
429 ice->gpio.set_data(ice, tmp);
430 udelay(100);
431 /* drop the register gpio */
432 tmp &= ~reg;
433 ice->gpio.set_data(ice, tmp);
434 udelay(100);
435 /* raise the register GPIO */
436 tmp |= reg;
437 ice->gpio.set_data(ice, tmp);
438 udelay(100);
439
440 /* raise all data gpios */
441 tmp |= GPIO_DATA_MASK;
442 ice->gpio.set_data(ice, tmp);
443 /* mask - immutable bits */
444 ice->gpio.set_mask(ice, 0xffffff);
445 /* outputs only 8-15 */
446 ice->gpio.set_dir(ice, 0x00ff00);
447 mutex_unlock(&ice->gpio_mutex);
448}
449
450static unsigned int get_scr(struct snd_ice1712 *ice)
451{
452 struct qtet_spec *spec = ice->spec;
453 return spec->scr;
454}
455
456static unsigned int get_mcr(struct snd_ice1712 *ice)
457{
458 struct qtet_spec *spec = ice->spec;
459 return spec->mcr;
460}
461
462static unsigned int get_cpld(struct snd_ice1712 *ice)
463{
464 struct qtet_spec *spec = ice->spec;
465 return spec->cpld;
466}
467
468static void set_scr(struct snd_ice1712 *ice, unsigned int val)
469{
470 struct qtet_spec *spec = ice->spec;
471 reg_write(ice, GPIO_SCR, val);
472 spec->scr = val;
473}
474
475static void set_mcr(struct snd_ice1712 *ice, unsigned int val)
476{
477 struct qtet_spec *spec = ice->spec;
478 reg_write(ice, GPIO_MCR, val);
479 spec->mcr = val;
480}
481
482static void set_cpld(struct snd_ice1712 *ice, unsigned int val)
483{
484 struct qtet_spec *spec = ice->spec;
485 reg_write(ice, GPIO_CPLD_CSN, val);
486 spec->cpld = val;
487}
488#ifdef CONFIG_PROC_FS
489static void proc_regs_read(struct snd_info_entry *entry,
490 struct snd_info_buffer *buffer)
491{
492 struct snd_ice1712 *ice = entry->private_data;
493 char bin_buffer[36];
494
495 snd_iprintf(buffer, "SCR: %s\n", get_binary(bin_buffer,
496 get_scr(ice)));
497 snd_iprintf(buffer, "MCR: %s\n", get_binary(bin_buffer,
498 get_mcr(ice)));
499 snd_iprintf(buffer, "CPLD: %s\n", get_binary(bin_buffer,
500 get_cpld(ice)));
501}
502
503static void proc_init(struct snd_ice1712 *ice)
504{
505 struct snd_info_entry *entry;
506 if (!snd_card_proc_new(ice->card, "quartet", &entry))
507 snd_info_set_text_ops(entry, ice, proc_regs_read);
508}
509#else /* !CONFIG_PROC_FS */
510static void proc_init(struct snd_ice1712 *ice) {}
511#endif
512
513static int qtet_mute_get(struct snd_kcontrol *kcontrol,
514 struct snd_ctl_elem_value *ucontrol)
515{
516 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
517 unsigned int val;
518 val = get_scr(ice) & SCR_MUTE;
519 ucontrol->value.integer.value[0] = (val) ? 0 : 1;
520 return 0;
521}
522
523static int qtet_mute_put(struct snd_kcontrol *kcontrol,
524 struct snd_ctl_elem_value *ucontrol)
525{
526 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
527 unsigned int old, new, smute;
528 old = get_scr(ice) & SCR_MUTE;
529 if (ucontrol->value.integer.value[0]) {
530 /* unmute */
531 new = 0;
532 /* un-smuting DAC */
533 smute = 0;
534 } else {
535 /* mute */
536 new = SCR_MUTE;
537 /* smuting DAC */
538 smute = AK4620_SMUTE;
539 }
540 if (old != new) {
541 struct snd_akm4xxx *ak = ice->akm;
542 set_scr(ice, (get_scr(ice) & ~SCR_MUTE) | new);
543 /* set smute */
544 qtet_akm_set_regs(ak, AK4620_DEEMVOL_REG, AK4620_SMUTE, smute);
545 return 1;
546 }
547 /* no change */
548 return 0;
549}
550
551static int qtet_ain12_enum_info(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_info *uinfo)
553{
554 static char *texts[3] = {"Line In 1/2", "Mic", "Mic + Low-cut"};
555 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
556 uinfo->count = 1;
557 uinfo->value.enumerated.items = ARRAY_SIZE(texts);
558
559 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
560 uinfo->value.enumerated.item =
561 uinfo->value.enumerated.items - 1;
562 strcpy(uinfo->value.enumerated.name,
563 texts[uinfo->value.enumerated.item]);
564
565 return 0;
566}
567
568static int qtet_ain12_sw_get(struct snd_kcontrol *kcontrol,
569 struct snd_ctl_elem_value *ucontrol)
570{
571 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
572 unsigned int val, result;
573 val = get_scr(ice) & (SCR_AIN12_SEL1 | SCR_AIN12_SEL0);
574 switch (val) {
575 case SCR_AIN12_LINE:
576 result = 0;
577 break;
578 case SCR_AIN12_MIC:
579 result = 1;
580 break;
581 case SCR_AIN12_LOWCUT:
582 result = 2;
583 break;
584 default:
585 /* BUG - no other combinations allowed */
586 snd_BUG();
587 result = 0;
588 }
589 ucontrol->value.integer.value[0] = result;
590 return 0;
591}
592
593static int qtet_ain12_sw_put(struct snd_kcontrol *kcontrol,
594 struct snd_ctl_elem_value *ucontrol)
595{
596 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
597 unsigned int old, new, tmp, masked_old;
598 old = new = get_scr(ice);
599 masked_old = old & (SCR_AIN12_SEL1 | SCR_AIN12_SEL0);
600 tmp = ucontrol->value.integer.value[0];
601 if (tmp == 2)
602 tmp = 3; /* binary 10 is not supported */
603 tmp <<= 4; /* shifting to SCR_AIN12_SEL0 */
604 if (tmp != masked_old) {
605 /* change requested */
606 switch (tmp) {
607 case SCR_AIN12_LINE:
608 new = old & ~(SCR_AIN12_SEL1 | SCR_AIN12_SEL0);
609 set_scr(ice, new);
610 /* turn off relay */
611 new &= ~SCR_RELAY;
612 set_scr(ice, new);
613 break;
614 case SCR_AIN12_MIC:
615 /* turn on relay */
616 new = old | SCR_RELAY;
617 set_scr(ice, new);
618 new = (new & ~SCR_AIN12_SEL1) | SCR_AIN12_SEL0;
619 set_scr(ice, new);
620 break;
621 case SCR_AIN12_LOWCUT:
622 /* turn on relay */
623 new = old | SCR_RELAY;
624 set_scr(ice, new);
625 new |= SCR_AIN12_SEL1 | SCR_AIN12_SEL0;
626 set_scr(ice, new);
627 break;
628 default:
629 snd_BUG();
630 }
631 return 1;
632 }
633 /* no change */
634 return 0;
635}
636
637static int qtet_php_get(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_value *ucontrol)
639{
640 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
641 unsigned int val;
642 /* if phantom voltage =48V, phantom on */
643 val = get_scr(ice) & SCR_PHP_V;
644 ucontrol->value.integer.value[0] = val ? 1 : 0;
645 return 0;
646}
647
648static int qtet_php_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
652 unsigned int old, new;
653 old = new = get_scr(ice);
654 if (ucontrol->value.integer.value[0] /* phantom on requested */
655 && (~old & SCR_PHP_V)) /* 0 = voltage 5V */ {
656 /* is off, turn on */
657 /* turn voltage on first, = 1 */
658 new = old | SCR_PHP_V;
659 set_scr(ice, new);
660 /* turn phantom on, = 0 */
661 new &= ~SCR_PHP;
662 set_scr(ice, new);
663 } else if (!ucontrol->value.integer.value[0] && (old & SCR_PHP_V)) {
664 /* phantom off requested and 1 = voltage 48V */
665 /* is on, turn off */
666 /* turn voltage off first, = 0 */
667 new = old & ~SCR_PHP_V;
668 set_scr(ice, new);
669 /* turn phantom off, = 1 */
670 new |= SCR_PHP;
671 set_scr(ice, new);
672 }
673 if (old != new)
674 return 1;
675 /* no change */
676 return 0;
677}
678
679#define PRIV_SW(xid, xbit, xreg) [xid] = {.bit = xbit,\
680 .set_register = set_##xreg,\
681 .get_register = get_##xreg, }
682
683
684#define PRIV_ENUM2(xid, xbit, xreg, xtext1, xtext2) [xid] = {.bit = xbit,\
685 .set_register = set_##xreg,\
686 .get_register = get_##xreg,\
687 .texts = {xtext1, xtext2} }
688
689static struct qtet_kcontrol_private qtet_privates[] = {
690 PRIV_ENUM2(IN12_SEL, CPLD_IN12_SEL, cpld, "An In 1/2", "An In 3/4"),
691 PRIV_ENUM2(IN34_SEL, CPLD_IN34_SEL, cpld, "An In 3/4", "IEC958 In"),
692 PRIV_ENUM2(AIN34_SEL, SCR_AIN34_SEL, scr, "Line In 3/4", "Hi-Z"),
693 PRIV_ENUM2(COAX_OUT, CPLD_COAX_OUT, cpld, "IEC958", "I2S"),
694 PRIV_SW(IN12_MON12, MCR_IN12_MON12, mcr),
695 PRIV_SW(IN12_MON34, MCR_IN12_MON34, mcr),
696 PRIV_SW(IN34_MON12, MCR_IN34_MON12, mcr),
697 PRIV_SW(IN34_MON34, MCR_IN34_MON34, mcr),
698 PRIV_SW(OUT12_MON34, MCR_OUT12_MON34, mcr),
699 PRIV_SW(OUT34_MON12, MCR_OUT34_MON12, mcr),
700};
701
702static int qtet_enum_info(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_info *uinfo)
704{
705 struct qtet_kcontrol_private private =
706 qtet_privates[kcontrol->private_value];
707 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
708 uinfo->count = 1;
709 uinfo->value.enumerated.items = ARRAY_SIZE(private.texts);
710
711 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
712 uinfo->value.enumerated.item =
713 uinfo->value.enumerated.items - 1;
714 strcpy(uinfo->value.enumerated.name,
715 private.texts[uinfo->value.enumerated.item]);
716
717 return 0;
718}
719
720static int qtet_sw_get(struct snd_kcontrol *kcontrol,
721 struct snd_ctl_elem_value *ucontrol)
722{
723 struct qtet_kcontrol_private private =
724 qtet_privates[kcontrol->private_value];
725 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
726 ucontrol->value.integer.value[0] =
727 (private.get_register(ice) & private.bit) ? 1 : 0;
728 return 0;
729}
730
731static int qtet_sw_put(struct snd_kcontrol *kcontrol,
732 struct snd_ctl_elem_value *ucontrol)
733{
734 struct qtet_kcontrol_private private =
735 qtet_privates[kcontrol->private_value];
736 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
737 unsigned int old, new;
738 old = private.get_register(ice);
739 if (ucontrol->value.integer.value[0])
740 new = old | private.bit;
741 else
742 new = old & ~private.bit;
743 if (old != new) {
744 private.set_register(ice, new);
745 return 1;
746 }
747 /* no change */
748 return 0;
749}
750
751#define qtet_sw_info snd_ctl_boolean_mono_info
752
753#define QTET_CONTROL(xname, xtype, xpriv) \
754 {.iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
755 .name = xname,\
756 .info = qtet_##xtype##_info,\
757 .get = qtet_sw_get,\
758 .put = qtet_sw_put,\
759 .private_value = xpriv }
760
761static struct snd_kcontrol_new qtet_controls[] __devinitdata = {
762 {
763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764 .name = "Master Playback Switch",
765 .info = qtet_sw_info,
766 .get = qtet_mute_get,
767 .put = qtet_mute_put,
768 .private_value = 0
769 },
770 {
771 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
772 .name = "Phantom Power",
773 .info = qtet_sw_info,
774 .get = qtet_php_get,
775 .put = qtet_php_put,
776 .private_value = 0
777 },
778 {
779 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
780 .name = "Analog In 1/2 Capture Switch",
781 .info = qtet_ain12_enum_info,
782 .get = qtet_ain12_sw_get,
783 .put = qtet_ain12_sw_put,
784 .private_value = 0
785 },
786 QTET_CONTROL("Analog In 3/4 Capture Switch", enum, AIN34_SEL),
787 QTET_CONTROL("PCM In 1/2 Capture Switch", enum, IN12_SEL),
788 QTET_CONTROL("PCM In 3/4 Capture Switch", enum, IN34_SEL),
789 QTET_CONTROL("Coax Output Source", enum, COAX_OUT),
790 QTET_CONTROL("Analog In 1/2 to Monitor 1/2", sw, IN12_MON12),
791 QTET_CONTROL("Analog In 1/2 to Monitor 3/4", sw, IN12_MON34),
792 QTET_CONTROL("Analog In 3/4 to Monitor 1/2", sw, IN34_MON12),
793 QTET_CONTROL("Analog In 3/4 to Monitor 3/4", sw, IN34_MON34),
794 QTET_CONTROL("Output 1/2 to Monitor 3/4", sw, OUT12_MON34),
795 QTET_CONTROL("Output 3/4 to Monitor 1/2", sw, OUT34_MON12),
796};
797
798static char *slave_vols[] __devinitdata = {
799 PCM_12_PLAYBACK_VOLUME,
800 PCM_34_PLAYBACK_VOLUME,
801 NULL
802};
803
804static __devinitdata
805DECLARE_TLV_DB_SCALE(qtet_master_db_scale, -6350, 50, 1);
806
807static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card,
808 const char *name)
809{
810 struct snd_ctl_elem_id sid;
811 memset(&sid, 0, sizeof(sid));
812 /* FIXME: strcpy is bad. */
813 strcpy(sid.name, name);
814 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
815 return snd_ctl_find_id(card, &sid);
816}
817
818static void __devinit add_slaves(struct snd_card *card,
819 struct snd_kcontrol *master, char **list)
820{
821 for (; *list; list++) {
822 struct snd_kcontrol *slave = ctl_find(card, *list);
823 if (slave)
824 snd_ctl_add_slave(master, slave);
825 }
826}
827
828static int __devinit qtet_add_controls(struct snd_ice1712 *ice)
829{
830 struct qtet_spec *spec = ice->spec;
831 int err, i;
832 struct snd_kcontrol *vmaster;
833 err = snd_ice1712_akm4xxx_build_controls(ice);
834 if (err < 0)
835 return err;
836 for (i = 0; i < ARRAY_SIZE(qtet_controls); i++) {
837 err = snd_ctl_add(ice->card,
838 snd_ctl_new1(&qtet_controls[i], ice));
839 if (err < 0)
840 return err;
841 }
842
843 /* Create virtual master control */
844 vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
845 qtet_master_db_scale);
846 if (!vmaster)
847 return -ENOMEM;
848 add_slaves(ice->card, vmaster, slave_vols);
849 err = snd_ctl_add(ice->card, vmaster);
850 if (err < 0)
851 return err;
852 /* only capture SPDIF over AK4113 */
853 err = snd_ak4113_build(spec->ak4113,
854 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
855 if (err < 0)
856 return err;
857 return 0;
858}
859
860static inline int qtet_is_spdif_master(struct snd_ice1712 *ice)
861{
862 /* CPLD_SYNC_SEL: 0 = internal, 1 = external (i.e. spdif master) */
863 return (get_cpld(ice) & CPLD_SYNC_SEL) ? 1 : 0;
864}
865
866static unsigned int qtet_get_rate(struct snd_ice1712 *ice)
867{
868 int i;
869 unsigned char result;
870
871 result = get_cpld(ice) & CPLD_CKS_MASK;
872 for (i = 0; i < ARRAY_SIZE(cks_vals); i++)
873 if (cks_vals[i] == result)
874 return qtet_rates[i];
875 return 0;
876}
877
878static int get_cks_val(int rate)
879{
880 int i;
881 for (i = 0; i < ARRAY_SIZE(qtet_rates); i++)
882 if (qtet_rates[i] == rate)
883 return cks_vals[i];
884 return 0;
885}
886
887/* setting new rate */
888static void qtet_set_rate(struct snd_ice1712 *ice, unsigned int rate)
889{
890 unsigned int new;
891 unsigned char val;
892 /* switching ice1724 to external clock - supplied by ext. circuits */
893 val = inb(ICEMT1724(ice, RATE));
894 outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
895
896 new = (get_cpld(ice) & ~CPLD_CKS_MASK) | get_cks_val(rate);
897 /* switch to internal clock, drop CPLD_SYNC_SEL */
898 new &= ~CPLD_SYNC_SEL;
899 /* printk(KERN_DEBUG "QT - set_rate: old %x, new %x\n",
900 get_cpld(ice), new); */
901 set_cpld(ice, new);
902}
903
904static inline unsigned char qtet_set_mclk(struct snd_ice1712 *ice,
905 unsigned int rate)
906{
907 /* no change in master clock */
908 return 0;
909}
910
911/* setting clock to external - SPDIF */
912static int qtet_set_spdif_clock(struct snd_ice1712 *ice, int type)
913{
914 unsigned int old, new;
915
916 old = new = get_cpld(ice);
917 new &= ~(CPLD_CKS_MASK | CPLD_WORD_SEL);
918 switch (type) {
919 case EXT_SPDIF_TYPE:
920 new |= CPLD_EXT_SPDIF;
921 break;
922 case EXT_WORDCLOCK_1FS_TYPE:
923 new |= CPLD_EXT_WORDCLOCK_1FS;
924 break;
925 case EXT_WORDCLOCK_256FS_TYPE:
926 new |= CPLD_EXT_WORDCLOCK_256FS;
927 break;
928 default:
929 snd_BUG();
930 }
931 if (old != new) {
932 set_cpld(ice, new);
933 /* changed */
934 return 1;
935 }
936 return 0;
937}
938
939static int qtet_get_spdif_master_type(struct snd_ice1712 *ice)
940{
941 unsigned int val;
942 int result;
943 val = get_cpld(ice);
944 /* checking only rate/clock-related bits */
945 val &= (CPLD_CKS_MASK | CPLD_WORD_SEL | CPLD_SYNC_SEL);
946 if (!(val & CPLD_SYNC_SEL)) {
947 /* switched to internal clock, is not any external type */
948 result = -1;
949 } else {
950 switch (val) {
951 case (CPLD_EXT_SPDIF):
952 result = EXT_SPDIF_TYPE;
953 break;
954 case (CPLD_EXT_WORDCLOCK_1FS):
955 result = EXT_WORDCLOCK_1FS_TYPE;
956 break;
957 case (CPLD_EXT_WORDCLOCK_256FS):
958 result = EXT_WORDCLOCK_256FS_TYPE;
959 break;
960 default:
961 /* undefined combination of external clock setup */
962 snd_BUG();
963 result = 0;
964 }
965 }
966 return result;
967}
968
969/* Called when ak4113 detects change in the input SPDIF stream */
970static void qtet_ak4113_change(struct ak4113 *ak4113, unsigned char c0,
971 unsigned char c1)
972{
973 struct snd_ice1712 *ice = ak4113->change_callback_private;
974 int rate;
975 if ((qtet_get_spdif_master_type(ice) == EXT_SPDIF_TYPE) &&
976 c1) {
977 /* only for SPDIF master mode, rate was changed */
978 rate = snd_ak4113_external_rate(ak4113);
979 /* printk(KERN_DEBUG "ak4113 - input rate changed to %d\n",
980 rate); */
981 qtet_akm_set_rate_val(ice->akm, rate);
982 }
983}
984
985/*
986 * If clock slaved to SPDIF-IN, setting runtime rate
987 * to the detected external rate
988 */
989static void qtet_spdif_in_open(struct snd_ice1712 *ice,
990 struct snd_pcm_substream *substream)
991{
992 struct qtet_spec *spec = ice->spec;
993 struct snd_pcm_runtime *runtime = substream->runtime;
994 int rate;
995
996 if (qtet_get_spdif_master_type(ice) != EXT_SPDIF_TYPE)
997 /* not external SPDIF, no rate limitation */
998 return;
999 /* only external SPDIF can detect incoming sample rate */
1000 rate = snd_ak4113_external_rate(spec->ak4113);
1001 if (rate >= runtime->hw.rate_min && rate <= runtime->hw.rate_max) {
1002 runtime->hw.rate_min = rate;
1003 runtime->hw.rate_max = rate;
1004 }
1005}
1006
1007/*
1008 * initialize the chip
1009 */
1010static int __devinit qtet_init(struct snd_ice1712 *ice)
1011{
1012 static const unsigned char ak4113_init_vals[] = {
1013 /* AK4113_REG_PWRDN */ AK4113_RST | AK4113_PWN |
1014 AK4113_OCKS0 | AK4113_OCKS1,
1015 /* AK4113_REQ_FORMAT */ AK4113_DIF_I24I2S | AK4113_VTX |
1016 AK4113_DEM_OFF | AK4113_DEAU,
1017 /* AK4113_REG_IO0 */ AK4113_OPS2 | AK4113_TXE |
1018 AK4113_XTL_24_576M,
1019 /* AK4113_REG_IO1 */ AK4113_EFH_1024LRCLK | AK4113_IPS(0),
1020 /* AK4113_REG_INT0_MASK */ 0,
1021 /* AK4113_REG_INT1_MASK */ 0,
1022 /* AK4113_REG_DATDTS */ 0,
1023 };
1024 int err;
1025 struct qtet_spec *spec;
1026 struct snd_akm4xxx *ak;
1027 unsigned char val;
1028
1029 /* switching ice1724 to external clock - supplied by ext. circuits */
1030 val = inb(ICEMT1724(ice, RATE));
1031 outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1032
1033 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1034 if (!spec)
1035 return -ENOMEM;
1036 /* qtet is clocked by Xilinx array */
1037 ice->hw_rates = &qtet_rates_info;
1038 ice->is_spdif_master = qtet_is_spdif_master;
1039 ice->get_rate = qtet_get_rate;
1040 ice->set_rate = qtet_set_rate;
1041 ice->set_mclk = qtet_set_mclk;
1042 ice->set_spdif_clock = qtet_set_spdif_clock;
1043 ice->get_spdif_master_type = qtet_get_spdif_master_type;
1044 ice->ext_clock_names = ext_clock_names;
1045 ice->ext_clock_count = ARRAY_SIZE(ext_clock_names);
1046 /* since Qtet can detect correct SPDIF-in rate, all streams can be
1047 * limited to this specific rate */
1048 ice->spdif.ops.open = ice->pro_open = qtet_spdif_in_open;
1049 ice->spec = spec;
1050
1051 /* Mute Off */
1052 /* SCR Initialize*/
1053 /* keep codec power down first */
1054 set_scr(ice, SCR_PHP);
1055 udelay(1);
1056 /* codec power up */
1057 set_scr(ice, SCR_PHP | SCR_CODEC_PDN);
1058
1059 /* MCR Initialize */
1060 set_mcr(ice, 0);
1061
1062 /* CPLD Initialize */
1063 set_cpld(ice, 0);
1064
1065
1066 ice->num_total_dacs = 2;
1067 ice->num_total_adcs = 2;
1068
1069 ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
1070 ak = ice->akm;
1071 if (!ak)
1072 return -ENOMEM;
1073 /* only one codec with two chips */
1074 ice->akm_codecs = 1;
1075 err = snd_ice1712_akm4xxx_init(ak, &akm_qtet_dac, NULL, ice);
1076 if (err < 0)
1077 return err;
1078 err = snd_ak4113_create(ice->card,
1079 qtet_ak4113_read,
1080 qtet_ak4113_write,
1081 ak4113_init_vals,
1082 ice, &spec->ak4113);
1083 if (err < 0)
1084 return err;
1085 /* callback for codecs rate setting */
1086 spec->ak4113->change_callback = qtet_ak4113_change;
1087 spec->ak4113->change_callback_private = ice;
1088 /* AK41143 in Quartet can detect external rate correctly
1089 * (i.e. check_flags = 0) */
1090 spec->ak4113->check_flags = 0;
1091
1092 proc_init(ice);
1093
1094 qtet_set_rate(ice, 44100);
1095 return 0;
1096}
1097
1098static unsigned char qtet_eeprom[] __devinitdata = {
1099 [ICE_EEP2_SYSCONF] = 0x28, /* clock 256(24MHz), mpu401, 1xADC,
1100 1xDACs, SPDIF in */
1101 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
1102 [ICE_EEP2_I2S] = 0x78, /* 96k, 24bit, 192k */
1103 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, in, out-ext */
1104 [ICE_EEP2_GPIO_DIR] = 0x00, /* 0-7 inputs, switched to output
1105 only during output operations */
1106 [ICE_EEP2_GPIO_DIR1] = 0xff, /* 8-15 outputs */
1107 [ICE_EEP2_GPIO_DIR2] = 0x00,
1108 [ICE_EEP2_GPIO_MASK] = 0xff, /* changed only for OUT operations */
1109 [ICE_EEP2_GPIO_MASK1] = 0x00,
1110 [ICE_EEP2_GPIO_MASK2] = 0xff,
1111
1112 [ICE_EEP2_GPIO_STATE] = 0x00, /* inputs */
1113 [ICE_EEP2_GPIO_STATE1] = 0x7d, /* all 1, but GPIO_CPLD_RW
1114 and GPIO15 always zero */
1115 [ICE_EEP2_GPIO_STATE2] = 0x00, /* inputs */
1116};
1117
1118/* entry point */
1119struct snd_ice1712_card_info snd_vt1724_qtet_cards[] __devinitdata = {
1120 {
1121 .subvendor = VT1724_SUBDEVICE_QTET,
1122 .name = "Infrasonic Quartet",
1123 .model = "quartet",
1124 .chip_init = qtet_init,
1125 .build_controls = qtet_add_controls,
1126 .eeprom_size = sizeof(qtet_eeprom),
1127 .eeprom_data = qtet_eeprom,
1128 },
1129 { } /* terminator */
1130};
diff --git a/sound/pci/ice1712/quartet.h b/sound/pci/ice1712/quartet.h
new file mode 100644
index 000000000000..80809b72439a
--- /dev/null
+++ b/sound/pci/ice1712/quartet.h
@@ -0,0 +1,10 @@
1#ifndef __SOUND_QTET_H
2#define __SOUND_QTET_H
3
4#define QTET_DEVICE_DESC "{Infrasonic,Quartet},"
5
6#define VT1724_SUBDEVICE_QTET 0x30305349 /* Infrasonic Quartet */
7
8extern struct snd_ice1712_card_info snd_vt1724_qtet_cards[];
9
10#endif /* __SOUND_QTET_H */
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index aac20fb4aad2..b990143636f1 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -2063,6 +2063,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
2063 .type = AC97_TUNE_HP_ONLY 2063 .type = AC97_TUNE_HP_ONLY
2064 }, 2064 },
2065 { 2065 {
2066 .subvendor = 0x161f,
2067 .subdevice = 0x203a,
2068 .name = "Gateway 4525GZ", /* AD1981B */
2069 .type = AC97_TUNE_INV_EAPD
2070 },
2071 {
2066 .subvendor = 0x1734, 2072 .subvendor = 0x1734,
2067 .subdevice = 0x0088, 2073 .subdevice = 0x0088,
2068 .name = "Fujitsu-Siemens D1522", /* AD1981 */ 2074 .name = "Fujitsu-Siemens D1522", /* AD1981 */
diff --git a/sound/pci/oxygen/Makefile b/sound/pci/oxygen/Makefile
index 4ba07d42fd1d..389941cf6100 100644
--- a/sound/pci/oxygen/Makefile
+++ b/sound/pci/oxygen/Makefile
@@ -1,7 +1,8 @@
1snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o 1snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o
2snd-hifier-objs := hifier.o 2snd-hifier-objs := hifier.o
3snd-oxygen-objs := oxygen.o 3snd-oxygen-objs := oxygen.o
4snd-virtuoso-objs := virtuoso.o 4snd-virtuoso-objs := virtuoso.o xonar_lib.o \
5 xonar_pcm179x.o xonar_cs43xx.o xonar_hdmi.o
5 6
6obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o 7obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o
7obj-$(CONFIG_SND_HIFIER) += snd-hifier.o 8obj-$(CONFIG_SND_HIFIER) += snd-hifier.o
diff --git a/sound/pci/oxygen/cs2000.h b/sound/pci/oxygen/cs2000.h
new file mode 100644
index 000000000000..c3501bdb5edc
--- /dev/null
+++ b/sound/pci/oxygen/cs2000.h
@@ -0,0 +1,83 @@
1#ifndef CS2000_H_INCLUDED
2#define CS2000_H_INCLUDED
3
4#define CS2000_DEV_ID 0x01
5#define CS2000_DEV_CTRL 0x02
6#define CS2000_DEV_CFG_1 0x03
7#define CS2000_DEV_CFG_2 0x04
8#define CS2000_GLOBAL_CFG 0x05
9#define CS2000_RATIO_0 0x06 /* 32 bits, big endian */
10#define CS2000_RATIO_1 0x0a
11#define CS2000_RATIO_2 0x0e
12#define CS2000_RATIO_3 0x12
13#define CS2000_FUN_CFG_1 0x16
14#define CS2000_FUN_CFG_2 0x17
15#define CS2000_FUN_CFG_3 0x1e
16
17/* DEV_ID */
18#define CS2000_DEVICE_MASK 0xf8
19#define CS2000_REVISION_MASK 0x07
20
21/* DEV_CTRL */
22#define CS2000_UNLOCK 0x80
23#define CS2000_AUX_OUT_DIS 0x02
24#define CS2000_CLK_OUT_DIS 0x01
25
26/* DEV_CFG_1 */
27#define CS2000_R_MOD_SEL_MASK 0xe0
28#define CS2000_R_MOD_SEL_1 0x00
29#define CS2000_R_MOD_SEL_2 0x20
30#define CS2000_R_MOD_SEL_4 0x40
31#define CS2000_R_MOD_SEL_8 0x60
32#define CS2000_R_MOD_SEL_1_2 0x80
33#define CS2000_R_MOD_SEL_1_4 0xa0
34#define CS2000_R_MOD_SEL_1_8 0xc0
35#define CS2000_R_MOD_SEL_1_16 0xe0
36#define CS2000_R_SEL_MASK 0x18
37#define CS2000_R_SEL_SHIFT 3
38#define CS2000_AUX_OUT_SRC_MASK 0x06
39#define CS2000_AUX_OUT_SRC_REF_CLK 0x00
40#define CS2000_AUX_OUT_SRC_CLK_IN 0x02
41#define CS2000_AUX_OUT_SRC_CLK_OUT 0x04
42#define CS2000_AUX_OUT_SRC_PLL_LOCK 0x06
43#define CS2000_EN_DEV_CFG_1 0x01
44
45/* DEV_CFG_2 */
46#define CS2000_LOCK_CLK_MASK 0x06
47#define CS2000_LOCK_CLK_SHIFT 1
48#define CS2000_FRAC_N_SRC_MASK 0x01
49#define CS2000_FRAC_N_SRC_STATIC 0x00
50#define CS2000_FRAC_N_SRC_DYNAMIC 0x01
51
52/* GLOBAL_CFG */
53#define CS2000_FREEZE 0x08
54#define CS2000_EN_DEV_CFG_2 0x01
55
56/* FUN_CFG_1 */
57#define CS2000_CLK_SKIP_EN 0x80
58#define CS2000_AUX_LOCK_CFG_MASK 0x40
59#define CS2000_AUX_LOCK_CFG_PP_HIGH 0x00
60#define CS2000_AUX_LOCK_CFG_OD_LOW 0x40
61#define CS2000_REF_CLK_DIV_MASK 0x18
62#define CS2000_REF_CLK_DIV_4 0x00
63#define CS2000_REF_CLK_DIV_2 0x08
64#define CS2000_REF_CLK_DIV_1 0x10
65
66/* FUN_CFG_2 */
67#define CS2000_CLK_OUT_UNL 0x10
68#define CS2000_L_F_RATIO_CFG_MASK 0x08
69#define CS2000_L_F_RATIO_CFG_20_12 0x00
70#define CS2000_L_F_RATIO_CFG_12_20 0x08
71
72/* FUN_CFG_3 */
73#define CS2000_CLK_IN_BW_MASK 0x70
74#define CS2000_CLK_IN_BW_1 0x00
75#define CS2000_CLK_IN_BW_2 0x10
76#define CS2000_CLK_IN_BW_4 0x20
77#define CS2000_CLK_IN_BW_8 0x30
78#define CS2000_CLK_IN_BW_16 0x40
79#define CS2000_CLK_IN_BW_32 0x50
80#define CS2000_CLK_IN_BW_64 0x60
81#define CS2000_CLK_IN_BW_128 0x70
82
83#endif
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
index 84ef13183419..e3c229b63311 100644
--- a/sound/pci/oxygen/hifier.c
+++ b/sound/pci/oxygen/hifier.c
@@ -17,6 +17,12 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20/*
21 * CMI8788:
22 *
23 * SPI 0 -> AK4396
24 */
25
20#include <linux/delay.h> 26#include <linux/delay.h>
21#include <linux/pci.h> 27#include <linux/pci.h>
22#include <sound/control.h> 28#include <sound/control.h>
@@ -51,23 +57,28 @@ static struct pci_device_id hifier_ids[] __devinitdata = {
51MODULE_DEVICE_TABLE(pci, hifier_ids); 57MODULE_DEVICE_TABLE(pci, hifier_ids);
52 58
53struct hifier_data { 59struct hifier_data {
54 u8 ak4396_ctl2; 60 u8 ak4396_regs[5];
55}; 61};
56 62
57static void ak4396_write(struct oxygen *chip, u8 reg, u8 value) 63static void ak4396_write(struct oxygen *chip, u8 reg, u8 value)
58{ 64{
65 struct hifier_data *data = chip->model_data;
66
59 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | 67 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
60 OXYGEN_SPI_DATA_LENGTH_2 | 68 OXYGEN_SPI_DATA_LENGTH_2 |
61 OXYGEN_SPI_CLOCK_160 | 69 OXYGEN_SPI_CLOCK_160 |
62 (0 << OXYGEN_SPI_CODEC_SHIFT) | 70 (0 << OXYGEN_SPI_CODEC_SHIFT) |
63 OXYGEN_SPI_CEN_LATCH_CLOCK_HI, 71 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
64 AK4396_WRITE | (reg << 8) | value); 72 AK4396_WRITE | (reg << 8) | value);
73 data->ak4396_regs[reg] = value;
65} 74}
66 75
67static void update_ak4396_volume(struct oxygen *chip) 76static void ak4396_write_cached(struct oxygen *chip, u8 reg, u8 value)
68{ 77{
69 ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]); 78 struct hifier_data *data = chip->model_data;
70 ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]); 79
80 if (value != data->ak4396_regs[reg])
81 ak4396_write(chip, reg, value);
71} 82}
72 83
73static void hifier_registers_init(struct oxygen *chip) 84static void hifier_registers_init(struct oxygen *chip)
@@ -75,16 +86,19 @@ static void hifier_registers_init(struct oxygen *chip)
75 struct hifier_data *data = chip->model_data; 86 struct hifier_data *data = chip->model_data;
76 87
77 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 88 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
78 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2); 89 ak4396_write(chip, AK4396_CONTROL_2,
90 data->ak4396_regs[AK4396_CONTROL_2]);
79 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM); 91 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
80 update_ak4396_volume(chip); 92 ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
93 ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
81} 94}
82 95
83static void hifier_init(struct oxygen *chip) 96static void hifier_init(struct oxygen *chip)
84{ 97{
85 struct hifier_data *data = chip->model_data; 98 struct hifier_data *data = chip->model_data;
86 99
87 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; 100 data->ak4396_regs[AK4396_CONTROL_2] =
101 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
88 hifier_registers_init(chip); 102 hifier_registers_init(chip);
89 103
90 snd_component_add(chip->card, "AK4396"); 104 snd_component_add(chip->card, "AK4396");
@@ -106,20 +120,29 @@ static void set_ak4396_params(struct oxygen *chip,
106 struct hifier_data *data = chip->model_data; 120 struct hifier_data *data = chip->model_data;
107 u8 value; 121 u8 value;
108 122
109 value = data->ak4396_ctl2 & ~AK4396_DFS_MASK; 123 value = data->ak4396_regs[AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
110 if (params_rate(params) <= 54000) 124 if (params_rate(params) <= 54000)
111 value |= AK4396_DFS_NORMAL; 125 value |= AK4396_DFS_NORMAL;
112 else if (params_rate(params) <= 108000) 126 else if (params_rate(params) <= 108000)
113 value |= AK4396_DFS_DOUBLE; 127 value |= AK4396_DFS_DOUBLE;
114 else 128 else
115 value |= AK4396_DFS_QUAD; 129 value |= AK4396_DFS_QUAD;
116 data->ak4396_ctl2 = value;
117 130
118 msleep(1); /* wait for the new MCLK to become stable */ 131 msleep(1); /* wait for the new MCLK to become stable */
119 132
120 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB); 133 if (value != data->ak4396_regs[AK4396_CONTROL_2]) {
121 ak4396_write(chip, AK4396_CONTROL_2, value); 134 ak4396_write(chip, AK4396_CONTROL_1,
122 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 135 AK4396_DIF_24_MSB);
136 ak4396_write(chip, AK4396_CONTROL_2, value);
137 ak4396_write(chip, AK4396_CONTROL_1,
138 AK4396_DIF_24_MSB | AK4396_RSTN);
139 }
140}
141
142static void update_ak4396_volume(struct oxygen *chip)
143{
144 ak4396_write_cached(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
145 ak4396_write_cached(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
123} 146}
124 147
125static void update_ak4396_mute(struct oxygen *chip) 148static void update_ak4396_mute(struct oxygen *chip)
@@ -127,11 +150,10 @@ static void update_ak4396_mute(struct oxygen *chip)
127 struct hifier_data *data = chip->model_data; 150 struct hifier_data *data = chip->model_data;
128 u8 value; 151 u8 value;
129 152
130 value = data->ak4396_ctl2 & ~AK4396_SMUTE; 153 value = data->ak4396_regs[AK4396_CONTROL_2] & ~AK4396_SMUTE;
131 if (chip->dac_mute) 154 if (chip->dac_mute)
132 value |= AK4396_SMUTE; 155 value |= AK4396_SMUTE;
133 data->ak4396_ctl2 = value; 156 ak4396_write_cached(chip, AK4396_CONTROL_2, value);
134 ak4396_write(chip, AK4396_CONTROL_2, value);
135} 157}
136 158
137static void set_cs5340_params(struct oxygen *chip, 159static void set_cs5340_params(struct oxygen *chip,
@@ -141,21 +163,14 @@ static void set_cs5340_params(struct oxygen *chip,
141 163
142static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 164static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
143 165
144static int hifier_control_filter(struct snd_kcontrol_new *template)
145{
146 if (!strcmp(template->name, "Stereo Upmixing"))
147 return 1; /* stereo only - we don't need upmixing */
148 return 0;
149}
150
151static const struct oxygen_model model_hifier = { 166static const struct oxygen_model model_hifier = {
152 .shortname = "C-Media CMI8787", 167 .shortname = "C-Media CMI8787",
153 .longname = "C-Media Oxygen HD Audio", 168 .longname = "C-Media Oxygen HD Audio",
154 .chip = "CMI8788", 169 .chip = "CMI8788",
155 .init = hifier_init, 170 .init = hifier_init,
156 .control_filter = hifier_control_filter,
157 .cleanup = hifier_cleanup, 171 .cleanup = hifier_cleanup,
158 .resume = hifier_resume, 172 .resume = hifier_resume,
173 .get_i2s_mclk = oxygen_default_i2s_mclk,
159 .set_dac_params = set_ak4396_params, 174 .set_dac_params = set_ak4396_params,
160 .set_adc_params = set_cs5340_params, 175 .set_adc_params = set_cs5340_params,
161 .update_dac_volume = update_ak4396_volume, 176 .update_dac_volume = update_ak4396_volume,
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 72db4c39007f..acbedebcffd9 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -18,6 +18,8 @@
18 */ 18 */
19 19
20/* 20/*
21 * CMI8788:
22 *
21 * SPI 0 -> 1st AK4396 (front) 23 * SPI 0 -> 1st AK4396 (front)
22 * SPI 1 -> 2nd AK4396 (surround) 24 * SPI 1 -> 2nd AK4396 (surround)
23 * SPI 2 -> 3rd AK4396 (center/LFE) 25 * SPI 2 -> 3rd AK4396 (center/LFE)
@@ -27,6 +29,10 @@
27 * GPIO 0 -> DFS0 of AK5385 29 * GPIO 0 -> DFS0 of AK5385
28 * GPIO 1 -> DFS1 of AK5385 30 * GPIO 1 -> DFS1 of AK5385
29 * GPIO 8 -> enable headphone amplifier on HT-Omega models 31 * GPIO 8 -> enable headphone amplifier on HT-Omega models
32 *
33 * CM9780:
34 *
35 * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input
30 */ 36 */
31 37
32#include <linux/delay.h> 38#include <linux/delay.h>
@@ -91,8 +97,8 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
91#define GPIO_CLARO_HP 0x0100 97#define GPIO_CLARO_HP 0x0100
92 98
93struct generic_data { 99struct generic_data {
94 u8 ak4396_ctl2; 100 u8 ak4396_regs[4][5];
95 u16 saved_wm8785_registers[2]; 101 u16 wm8785_regs[3];
96}; 102};
97 103
98static void ak4396_write(struct oxygen *chip, unsigned int codec, 104static void ak4396_write(struct oxygen *chip, unsigned int codec,
@@ -102,12 +108,24 @@ static void ak4396_write(struct oxygen *chip, unsigned int codec,
102 static const u8 codec_spi_map[4] = { 108 static const u8 codec_spi_map[4] = {
103 0, 1, 2, 4 109 0, 1, 2, 4
104 }; 110 };
111 struct generic_data *data = chip->model_data;
112
105 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | 113 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
106 OXYGEN_SPI_DATA_LENGTH_2 | 114 OXYGEN_SPI_DATA_LENGTH_2 |
107 OXYGEN_SPI_CLOCK_160 | 115 OXYGEN_SPI_CLOCK_160 |
108 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | 116 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
109 OXYGEN_SPI_CEN_LATCH_CLOCK_HI, 117 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
110 AK4396_WRITE | (reg << 8) | value); 118 AK4396_WRITE | (reg << 8) | value);
119 data->ak4396_regs[codec][reg] = value;
120}
121
122static void ak4396_write_cached(struct oxygen *chip, unsigned int codec,
123 u8 reg, u8 value)
124{
125 struct generic_data *data = chip->model_data;
126
127 if (value != data->ak4396_regs[codec][reg])
128 ak4396_write(chip, codec, reg, value);
111} 129}
112 130
113static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value) 131static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
@@ -120,20 +138,8 @@ static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
120 (3 << OXYGEN_SPI_CODEC_SHIFT) | 138 (3 << OXYGEN_SPI_CODEC_SHIFT) |
121 OXYGEN_SPI_CEN_LATCH_CLOCK_LO, 139 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
122 (reg << 9) | value); 140 (reg << 9) | value);
123 if (reg < ARRAY_SIZE(data->saved_wm8785_registers)) 141 if (reg < ARRAY_SIZE(data->wm8785_regs))
124 data->saved_wm8785_registers[reg] = value; 142 data->wm8785_regs[reg] = value;
125}
126
127static void update_ak4396_volume(struct oxygen *chip)
128{
129 unsigned int i;
130
131 for (i = 0; i < 4; ++i) {
132 ak4396_write(chip, i,
133 AK4396_LCH_ATT, chip->dac_volume[i * 2]);
134 ak4396_write(chip, i,
135 AK4396_RCH_ATT, chip->dac_volume[i * 2 + 1]);
136 }
137} 143}
138 144
139static void ak4396_registers_init(struct oxygen *chip) 145static void ak4396_registers_init(struct oxygen *chip)
@@ -142,21 +148,25 @@ static void ak4396_registers_init(struct oxygen *chip)
142 unsigned int i; 148 unsigned int i;
143 149
144 for (i = 0; i < 4; ++i) { 150 for (i = 0; i < 4; ++i) {
145 ak4396_write(chip, i, 151 ak4396_write(chip, i, AK4396_CONTROL_1,
146 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 152 AK4396_DIF_24_MSB | AK4396_RSTN);
147 ak4396_write(chip, i, 153 ak4396_write(chip, i, AK4396_CONTROL_2,
148 AK4396_CONTROL_2, data->ak4396_ctl2); 154 data->ak4396_regs[0][AK4396_CONTROL_2]);
149 ak4396_write(chip, i, 155 ak4396_write(chip, i, AK4396_CONTROL_3,
150 AK4396_CONTROL_3, AK4396_PCM); 156 AK4396_PCM);
157 ak4396_write(chip, i, AK4396_LCH_ATT,
158 chip->dac_volume[i * 2]);
159 ak4396_write(chip, i, AK4396_RCH_ATT,
160 chip->dac_volume[i * 2 + 1]);
151 } 161 }
152 update_ak4396_volume(chip);
153} 162}
154 163
155static void ak4396_init(struct oxygen *chip) 164static void ak4396_init(struct oxygen *chip)
156{ 165{
157 struct generic_data *data = chip->model_data; 166 struct generic_data *data = chip->model_data;
158 167
159 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; 168 data->ak4396_regs[0][AK4396_CONTROL_2] =
169 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
160 ak4396_registers_init(chip); 170 ak4396_registers_init(chip);
161 snd_component_add(chip->card, "AK4396"); 171 snd_component_add(chip->card, "AK4396");
162} 172}
@@ -173,17 +183,17 @@ static void wm8785_registers_init(struct oxygen *chip)
173 struct generic_data *data = chip->model_data; 183 struct generic_data *data = chip->model_data;
174 184
175 wm8785_write(chip, WM8785_R7, 0); 185 wm8785_write(chip, WM8785_R7, 0);
176 wm8785_write(chip, WM8785_R0, data->saved_wm8785_registers[0]); 186 wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]);
177 wm8785_write(chip, WM8785_R1, data->saved_wm8785_registers[1]); 187 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
178} 188}
179 189
180static void wm8785_init(struct oxygen *chip) 190static void wm8785_init(struct oxygen *chip)
181{ 191{
182 struct generic_data *data = chip->model_data; 192 struct generic_data *data = chip->model_data;
183 193
184 data->saved_wm8785_registers[0] = WM8785_MCR_SLAVE | 194 data->wm8785_regs[0] =
185 WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST; 195 WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST;
186 data->saved_wm8785_registers[1] = WM8785_WL_24; 196 data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL;
187 wm8785_registers_init(chip); 197 wm8785_registers_init(chip);
188 snd_component_add(chip->card, "WM8785"); 198 snd_component_add(chip->card, "WM8785");
189} 199}
@@ -264,24 +274,36 @@ static void set_ak4396_params(struct oxygen *chip,
264 unsigned int i; 274 unsigned int i;
265 u8 value; 275 u8 value;
266 276
267 value = data->ak4396_ctl2 & ~AK4396_DFS_MASK; 277 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
268 if (params_rate(params) <= 54000) 278 if (params_rate(params) <= 54000)
269 value |= AK4396_DFS_NORMAL; 279 value |= AK4396_DFS_NORMAL;
270 else if (params_rate(params) <= 108000) 280 else if (params_rate(params) <= 108000)
271 value |= AK4396_DFS_DOUBLE; 281 value |= AK4396_DFS_DOUBLE;
272 else 282 else
273 value |= AK4396_DFS_QUAD; 283 value |= AK4396_DFS_QUAD;
274 data->ak4396_ctl2 = value;
275 284
276 msleep(1); /* wait for the new MCLK to become stable */ 285 msleep(1); /* wait for the new MCLK to become stable */
277 286
287 if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) {
288 for (i = 0; i < 4; ++i) {
289 ak4396_write(chip, i, AK4396_CONTROL_1,
290 AK4396_DIF_24_MSB);
291 ak4396_write(chip, i, AK4396_CONTROL_2, value);
292 ak4396_write(chip, i, AK4396_CONTROL_1,
293 AK4396_DIF_24_MSB | AK4396_RSTN);
294 }
295 }
296}
297
298static void update_ak4396_volume(struct oxygen *chip)
299{
300 unsigned int i;
301
278 for (i = 0; i < 4; ++i) { 302 for (i = 0; i < 4; ++i) {
279 ak4396_write(chip, i, 303 ak4396_write_cached(chip, i, AK4396_LCH_ATT,
280 AK4396_CONTROL_1, AK4396_DIF_24_MSB); 304 chip->dac_volume[i * 2]);
281 ak4396_write(chip, i, 305 ak4396_write_cached(chip, i, AK4396_RCH_ATT,
282 AK4396_CONTROL_2, value); 306 chip->dac_volume[i * 2 + 1]);
283 ak4396_write(chip, i,
284 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
285 } 307 }
286} 308}
287 309
@@ -291,21 +313,19 @@ static void update_ak4396_mute(struct oxygen *chip)
291 unsigned int i; 313 unsigned int i;
292 u8 value; 314 u8 value;
293 315
294 value = data->ak4396_ctl2 & ~AK4396_SMUTE; 316 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE;
295 if (chip->dac_mute) 317 if (chip->dac_mute)
296 value |= AK4396_SMUTE; 318 value |= AK4396_SMUTE;
297 data->ak4396_ctl2 = value;
298 for (i = 0; i < 4; ++i) 319 for (i = 0; i < 4; ++i)
299 ak4396_write(chip, i, AK4396_CONTROL_2, value); 320 ak4396_write_cached(chip, i, AK4396_CONTROL_2, value);
300} 321}
301 322
302static void set_wm8785_params(struct oxygen *chip, 323static void set_wm8785_params(struct oxygen *chip,
303 struct snd_pcm_hw_params *params) 324 struct snd_pcm_hw_params *params)
304{ 325{
326 struct generic_data *data = chip->model_data;
305 unsigned int value; 327 unsigned int value;
306 328
307 wm8785_write(chip, WM8785_R7, 0);
308
309 value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST; 329 value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST;
310 if (params_rate(params) <= 48000) 330 if (params_rate(params) <= 48000)
311 value |= WM8785_OSR_SINGLE; 331 value |= WM8785_OSR_SINGLE;
@@ -313,13 +333,11 @@ static void set_wm8785_params(struct oxygen *chip,
313 value |= WM8785_OSR_DOUBLE; 333 value |= WM8785_OSR_DOUBLE;
314 else 334 else
315 value |= WM8785_OSR_QUAD; 335 value |= WM8785_OSR_QUAD;
316 wm8785_write(chip, WM8785_R0, value); 336 if (value != data->wm8785_regs[0]) {
317 337 wm8785_write(chip, WM8785_R7, 0);
318 if (snd_pcm_format_width(params_format(params)) <= 16) 338 wm8785_write(chip, WM8785_R0, value);
319 value = WM8785_WL_16; 339 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
320 else 340 }
321 value = WM8785_WL_24;
322 wm8785_write(chip, WM8785_R1, value);
323} 341}
324 342
325static void set_ak5385_params(struct oxygen *chip, 343static void set_ak5385_params(struct oxygen *chip,
@@ -337,6 +355,134 @@ static void set_ak5385_params(struct oxygen *chip,
337 value, GPIO_AK5385_DFS_MASK); 355 value, GPIO_AK5385_DFS_MASK);
338} 356}
339 357
358static int rolloff_info(struct snd_kcontrol *ctl,
359 struct snd_ctl_elem_info *info)
360{
361 static const char *const names[2] = {
362 "Sharp Roll-off", "Slow Roll-off"
363 };
364
365 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
366 info->count = 1;
367 info->value.enumerated.items = 2;
368 if (info->value.enumerated.item >= 2)
369 info->value.enumerated.item = 1;
370 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
371 return 0;
372}
373
374static int rolloff_get(struct snd_kcontrol *ctl,
375 struct snd_ctl_elem_value *value)
376{
377 struct oxygen *chip = ctl->private_data;
378 struct generic_data *data = chip->model_data;
379
380 value->value.enumerated.item[0] =
381 (data->ak4396_regs[0][AK4396_CONTROL_2] & AK4396_SLOW) != 0;
382 return 0;
383}
384
385static int rolloff_put(struct snd_kcontrol *ctl,
386 struct snd_ctl_elem_value *value)
387{
388 struct oxygen *chip = ctl->private_data;
389 struct generic_data *data = chip->model_data;
390 unsigned int i;
391 int changed;
392 u8 reg;
393
394 mutex_lock(&chip->mutex);
395 reg = data->ak4396_regs[0][AK4396_CONTROL_2];
396 if (value->value.enumerated.item[0])
397 reg |= AK4396_SLOW;
398 else
399 reg &= ~AK4396_SLOW;
400 changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2];
401 if (changed) {
402 for (i = 0; i < 4; ++i)
403 ak4396_write(chip, i, AK4396_CONTROL_2, reg);
404 }
405 mutex_unlock(&chip->mutex);
406 return changed;
407}
408
409static const struct snd_kcontrol_new rolloff_control = {
410 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
411 .name = "DAC Filter Playback Enum",
412 .info = rolloff_info,
413 .get = rolloff_get,
414 .put = rolloff_put,
415};
416
417static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
418{
419 static const char *const names[2] = {
420 "None", "High-pass Filter"
421 };
422
423 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
424 info->count = 1;
425 info->value.enumerated.items = 2;
426 if (info->value.enumerated.item >= 2)
427 info->value.enumerated.item = 1;
428 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
429 return 0;
430}
431
432static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
433{
434 struct oxygen *chip = ctl->private_data;
435 struct generic_data *data = chip->model_data;
436
437 value->value.enumerated.item[0] =
438 (data->wm8785_regs[WM8785_R2] & WM8785_HPFR) != 0;
439 return 0;
440}
441
442static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
443{
444 struct oxygen *chip = ctl->private_data;
445 struct generic_data *data = chip->model_data;
446 unsigned int reg;
447 int changed;
448
449 mutex_lock(&chip->mutex);
450 reg = data->wm8785_regs[WM8785_R2] & ~(WM8785_HPFR | WM8785_HPFL);
451 if (value->value.enumerated.item[0])
452 reg |= WM8785_HPFR | WM8785_HPFL;
453 changed = reg != data->wm8785_regs[WM8785_R2];
454 if (changed)
455 wm8785_write(chip, WM8785_R2, reg);
456 mutex_unlock(&chip->mutex);
457 return changed;
458}
459
460static const struct snd_kcontrol_new hpf_control = {
461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
462 .name = "ADC Filter Capture Enum",
463 .info = hpf_info,
464 .get = hpf_get,
465 .put = hpf_put,
466};
467
468static int generic_mixer_init(struct oxygen *chip)
469{
470 return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
471}
472
473static int generic_wm8785_mixer_init(struct oxygen *chip)
474{
475 int err;
476
477 err = generic_mixer_init(chip);
478 if (err < 0)
479 return err;
480 err = snd_ctl_add(chip->card, snd_ctl_new1(&hpf_control, chip));
481 if (err < 0)
482 return err;
483 return 0;
484}
485
340static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 486static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
341 487
342static const struct oxygen_model model_generic = { 488static const struct oxygen_model model_generic = {
@@ -344,8 +490,10 @@ static const struct oxygen_model model_generic = {
344 .longname = "C-Media Oxygen HD Audio", 490 .longname = "C-Media Oxygen HD Audio",
345 .chip = "CMI8788", 491 .chip = "CMI8788",
346 .init = generic_init, 492 .init = generic_init,
493 .mixer_init = generic_wm8785_mixer_init,
347 .cleanup = generic_cleanup, 494 .cleanup = generic_cleanup,
348 .resume = generic_resume, 495 .resume = generic_resume,
496 .get_i2s_mclk = oxygen_default_i2s_mclk,
349 .set_dac_params = set_ak4396_params, 497 .set_dac_params = set_ak4396_params,
350 .set_adc_params = set_wm8785_params, 498 .set_adc_params = set_wm8785_params,
351 .update_dac_volume = update_ak4396_volume, 499 .update_dac_volume = update_ak4396_volume,
@@ -374,6 +522,7 @@ static int __devinit get_oxygen_model(struct oxygen *chip,
374 switch (id->driver_data) { 522 switch (id->driver_data) {
375 case MODEL_MERIDIAN: 523 case MODEL_MERIDIAN:
376 chip->model.init = meridian_init; 524 chip->model.init = meridian_init;
525 chip->model.mixer_init = generic_mixer_init;
377 chip->model.resume = meridian_resume; 526 chip->model.resume = meridian_resume;
378 chip->model.set_adc_params = set_ak5385_params; 527 chip->model.set_adc_params = set_ak5385_params;
379 chip->model.device_config = PLAYBACK_0_TO_I2S | 528 chip->model.device_config = PLAYBACK_0_TO_I2S |
@@ -389,6 +538,7 @@ static int __devinit get_oxygen_model(struct oxygen *chip,
389 break; 538 break;
390 case MODEL_CLARO_HALO: 539 case MODEL_CLARO_HALO:
391 chip->model.init = claro_halo_init; 540 chip->model.init = claro_halo_init;
541 chip->model.mixer_init = generic_mixer_init;
392 chip->model.cleanup = claro_cleanup; 542 chip->model.cleanup = claro_cleanup;
393 chip->model.suspend = claro_suspend; 543 chip->model.suspend = claro_suspend;
394 chip->model.resume = claro_resume; 544 chip->model.resume = claro_resume;
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index bd615dbffadb..6147216af744 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -78,12 +78,15 @@ struct oxygen_model {
78 void (*resume)(struct oxygen *chip); 78 void (*resume)(struct oxygen *chip);
79 void (*pcm_hardware_filter)(unsigned int channel, 79 void (*pcm_hardware_filter)(unsigned int channel,
80 struct snd_pcm_hardware *hardware); 80 struct snd_pcm_hardware *hardware);
81 unsigned int (*get_i2s_mclk)(struct oxygen *chip, unsigned int channel,
82 struct snd_pcm_hw_params *hw_params);
81 void (*set_dac_params)(struct oxygen *chip, 83 void (*set_dac_params)(struct oxygen *chip,
82 struct snd_pcm_hw_params *params); 84 struct snd_pcm_hw_params *params);
83 void (*set_adc_params)(struct oxygen *chip, 85 void (*set_adc_params)(struct oxygen *chip,
84 struct snd_pcm_hw_params *params); 86 struct snd_pcm_hw_params *params);
85 void (*update_dac_volume)(struct oxygen *chip); 87 void (*update_dac_volume)(struct oxygen *chip);
86 void (*update_dac_mute)(struct oxygen *chip); 88 void (*update_dac_mute)(struct oxygen *chip);
89 void (*update_center_lfe_mix)(struct oxygen *chip, bool mixed);
87 void (*gpio_changed)(struct oxygen *chip); 90 void (*gpio_changed)(struct oxygen *chip);
88 void (*uart_input)(struct oxygen *chip); 91 void (*uart_input)(struct oxygen *chip);
89 void (*ac97_switch)(struct oxygen *chip, 92 void (*ac97_switch)(struct oxygen *chip,
@@ -162,6 +165,8 @@ void oxygen_update_spdif_source(struct oxygen *chip);
162/* oxygen_pcm.c */ 165/* oxygen_pcm.c */
163 166
164int oxygen_pcm_init(struct oxygen *chip); 167int oxygen_pcm_init(struct oxygen *chip);
168unsigned int oxygen_default_i2s_mclk(struct oxygen *chip, unsigned int channel,
169 struct snd_pcm_hw_params *hw_params);
165 170
166/* oxygen_io.c */ 171/* oxygen_io.c */
167 172
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 9a8936e20744..9c5e6450eebb 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -278,7 +278,11 @@ oxygen_search_pci_id(struct oxygen *chip, const struct pci_device_id ids[])
278static void oxygen_restore_eeprom(struct oxygen *chip, 278static void oxygen_restore_eeprom(struct oxygen *chip,
279 const struct pci_device_id *id) 279 const struct pci_device_id *id)
280{ 280{
281 if (oxygen_read_eeprom(chip, 0) != OXYGEN_EEPROM_ID) { 281 u16 eeprom_id;
282
283 eeprom_id = oxygen_read_eeprom(chip, 0);
284 if (eeprom_id != OXYGEN_EEPROM_ID &&
285 (eeprom_id != 0xffff || id->subdevice != 0x8788)) {
282 /* 286 /*
283 * This function gets called only when a known card model has 287 * This function gets called only when a known card model has
284 * been detected, i.e., we know there is a valid subsystem 288 * been detected, i.e., we know there is a valid subsystem
@@ -303,6 +307,28 @@ static void oxygen_restore_eeprom(struct oxygen *chip,
303 } 307 }
304} 308}
305 309
310static void pci_bridge_magic(void)
311{
312 struct pci_dev *pci = NULL;
313 u32 tmp;
314
315 for (;;) {
316 /* If there is any Pericom PI7C9X110 PCI-E/PCI bridge ... */
317 pci = pci_get_device(0x12d8, 0xe110, pci);
318 if (!pci)
319 break;
320 /*
321 * ... configure its secondary internal arbiter to park to
322 * the secondary port, instead of to the last master.
323 */
324 if (!pci_read_config_dword(pci, 0x40, &tmp)) {
325 tmp |= 1;
326 pci_write_config_dword(pci, 0x40, tmp);
327 }
328 /* Why? Try asking C-Media. */
329 }
330}
331
306static void oxygen_init(struct oxygen *chip) 332static void oxygen_init(struct oxygen *chip)
307{ 333{
308 unsigned int i; 334 unsigned int i;
@@ -581,6 +607,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
581 snd_card_set_dev(card, &pci->dev); 607 snd_card_set_dev(card, &pci->dev);
582 card->private_free = oxygen_card_free; 608 card->private_free = oxygen_card_free;
583 609
610 pci_bridge_magic();
584 oxygen_init(chip); 611 oxygen_init(chip);
585 chip->model.init(chip); 612 chip->model.init(chip);
586 613
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 5401c547c4e3..f375b8a27862 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -99,11 +99,15 @@ static int dac_mute_put(struct snd_kcontrol *ctl,
99 99
100static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) 100static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
101{ 101{
102 static const char *const names[3] = { 102 static const char *const names[5] = {
103 "Front", "Front+Surround", "Front+Surround+Back" 103 "Front",
104 "Front+Surround",
105 "Front+Surround+Back",
106 "Front+Surround+Center/LFE",
107 "Front+Surround+Center/LFE+Back",
104 }; 108 };
105 struct oxygen *chip = ctl->private_data; 109 struct oxygen *chip = ctl->private_data;
106 unsigned int count = 2 + (chip->model.dac_channels == 8); 110 unsigned int count = chip->model.update_center_lfe_mix ? 5 : 3;
107 111
108 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 112 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
109 info->count = 1; 113 info->count = 1;
@@ -127,7 +131,7 @@ static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
127void oxygen_update_dac_routing(struct oxygen *chip) 131void oxygen_update_dac_routing(struct oxygen *chip)
128{ 132{
129 /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */ 133 /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */
130 static const unsigned int reg_values[3] = { 134 static const unsigned int reg_values[5] = {
131 /* stereo -> front */ 135 /* stereo -> front */
132 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | 136 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
133 (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | 137 (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
@@ -143,6 +147,16 @@ void oxygen_update_dac_routing(struct oxygen *chip)
143 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | 147 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
144 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | 148 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
145 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), 149 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
150 /* stereo -> front+surround+center/LFE */
151 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
152 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
153 (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
154 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
155 /* stereo -> front+surround+center/LFE+back */
156 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
157 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
158 (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
159 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
146 }; 160 };
147 u8 channels; 161 u8 channels;
148 unsigned int reg_value; 162 unsigned int reg_value;
@@ -167,22 +181,23 @@ void oxygen_update_dac_routing(struct oxygen *chip)
167 OXYGEN_PLAY_DAC1_SOURCE_MASK | 181 OXYGEN_PLAY_DAC1_SOURCE_MASK |
168 OXYGEN_PLAY_DAC2_SOURCE_MASK | 182 OXYGEN_PLAY_DAC2_SOURCE_MASK |
169 OXYGEN_PLAY_DAC3_SOURCE_MASK); 183 OXYGEN_PLAY_DAC3_SOURCE_MASK);
184 if (chip->model.update_center_lfe_mix)
185 chip->model.update_center_lfe_mix(chip, chip->dac_routing > 2);
170} 186}
171 187
172static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 188static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
173{ 189{
174 struct oxygen *chip = ctl->private_data; 190 struct oxygen *chip = ctl->private_data;
175 unsigned int count = 2 + (chip->model.dac_channels == 8); 191 unsigned int count = chip->model.update_center_lfe_mix ? 5 : 3;
176 int changed; 192 int changed;
177 193
194 if (value->value.enumerated.item[0] >= count)
195 return -EINVAL;
178 mutex_lock(&chip->mutex); 196 mutex_lock(&chip->mutex);
179 changed = value->value.enumerated.item[0] != chip->dac_routing; 197 changed = value->value.enumerated.item[0] != chip->dac_routing;
180 if (changed) { 198 if (changed) {
181 chip->dac_routing = min(value->value.enumerated.item[0], 199 chip->dac_routing = value->value.enumerated.item[0];
182 count - 1);
183 spin_lock_irq(&chip->reg_lock);
184 oxygen_update_dac_routing(chip); 200 oxygen_update_dac_routing(chip);
185 spin_unlock_irq(&chip->reg_lock);
186 } 201 }
187 mutex_unlock(&chip->mutex); 202 mutex_unlock(&chip->mutex);
188 return changed; 203 return changed;
@@ -790,7 +805,7 @@ static const struct {
790 .controls = { 805 .controls = {
791 { 806 {
792 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
793 .name = "Analog Input Monitor Switch", 808 .name = "Analog Input Monitor Playback Switch",
794 .info = snd_ctl_boolean_mono_info, 809 .info = snd_ctl_boolean_mono_info,
795 .get = monitor_get, 810 .get = monitor_get,
796 .put = monitor_put, 811 .put = monitor_put,
@@ -798,7 +813,7 @@ static const struct {
798 }, 813 },
799 { 814 {
800 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 815 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
801 .name = "Analog Input Monitor Volume", 816 .name = "Analog Input Monitor Playback Volume",
802 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 817 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
803 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 818 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
804 .info = monitor_volume_info, 819 .info = monitor_volume_info,
@@ -815,7 +830,7 @@ static const struct {
815 .controls = { 830 .controls = {
816 { 831 {
817 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 832 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
818 .name = "Analog Input Monitor Switch", 833 .name = "Analog Input Monitor Playback Switch",
819 .info = snd_ctl_boolean_mono_info, 834 .info = snd_ctl_boolean_mono_info,
820 .get = monitor_get, 835 .get = monitor_get,
821 .put = monitor_put, 836 .put = monitor_put,
@@ -823,7 +838,7 @@ static const struct {
823 }, 838 },
824 { 839 {
825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 840 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
826 .name = "Analog Input Monitor Volume", 841 .name = "Analog Input Monitor Playback Volume",
827 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 842 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
828 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 843 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
829 .info = monitor_volume_info, 844 .info = monitor_volume_info,
@@ -840,7 +855,7 @@ static const struct {
840 .controls = { 855 .controls = {
841 { 856 {
842 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 857 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
843 .name = "Analog Input Monitor Switch", 858 .name = "Analog Input Monitor Playback Switch",
844 .index = 1, 859 .index = 1,
845 .info = snd_ctl_boolean_mono_info, 860 .info = snd_ctl_boolean_mono_info,
846 .get = monitor_get, 861 .get = monitor_get,
@@ -849,7 +864,7 @@ static const struct {
849 }, 864 },
850 { 865 {
851 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
852 .name = "Analog Input Monitor Volume", 867 .name = "Analog Input Monitor Playback Volume",
853 .index = 1, 868 .index = 1,
854 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 869 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
855 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 870 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
@@ -867,7 +882,7 @@ static const struct {
867 .controls = { 882 .controls = {
868 { 883 {
869 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
870 .name = "Digital Input Monitor Switch", 885 .name = "Digital Input Monitor Playback Switch",
871 .info = snd_ctl_boolean_mono_info, 886 .info = snd_ctl_boolean_mono_info,
872 .get = monitor_get, 887 .get = monitor_get,
873 .put = monitor_put, 888 .put = monitor_put,
@@ -875,7 +890,7 @@ static const struct {
875 }, 890 },
876 { 891 {
877 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 892 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
878 .name = "Digital Input Monitor Volume", 893 .name = "Digital Input Monitor Playback Volume",
879 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 894 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
880 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 895 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
881 .info = monitor_volume_info, 896 .info = monitor_volume_info,
@@ -954,6 +969,9 @@ static int add_controls(struct oxygen *chip,
954 if (err == 1) 969 if (err == 1)
955 continue; 970 continue;
956 } 971 }
972 if (!strcmp(template.name, "Stereo Upmixing") &&
973 chip->model.dac_channels == 2)
974 continue;
957 if (!strcmp(template.name, "Master Playback Volume") && 975 if (!strcmp(template.name, "Master Playback Volume") &&
958 chip->model.dac_tlv) { 976 chip->model.dac_tlv) {
959 template.tlv.p = chip->model.dac_tlv; 977 template.tlv.p = chip->model.dac_tlv;
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index ef2345d82b86..9dff6954c397 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -271,13 +271,16 @@ static unsigned int oxygen_rate(struct snd_pcm_hw_params *hw_params)
271 } 271 }
272} 272}
273 273
274static unsigned int oxygen_i2s_mclk(struct snd_pcm_hw_params *hw_params) 274unsigned int oxygen_default_i2s_mclk(struct oxygen *chip,
275 unsigned int channel,
276 struct snd_pcm_hw_params *hw_params)
275{ 277{
276 if (params_rate(hw_params) <= 96000) 278 if (params_rate(hw_params) <= 96000)
277 return OXYGEN_I2S_MCLK_256; 279 return OXYGEN_I2S_MCLK_256;
278 else 280 else
279 return OXYGEN_I2S_MCLK_128; 281 return OXYGEN_I2S_MCLK_128;
280} 282}
283EXPORT_SYMBOL(oxygen_default_i2s_mclk);
281 284
282static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params) 285static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params)
283{ 286{
@@ -354,7 +357,7 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
354 OXYGEN_REC_FORMAT_A_MASK); 357 OXYGEN_REC_FORMAT_A_MASK);
355 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, 358 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT,
356 oxygen_rate(hw_params) | 359 oxygen_rate(hw_params) |
357 oxygen_i2s_mclk(hw_params) | 360 chip->model.get_i2s_mclk(chip, PCM_A, hw_params) |
358 chip->model.adc_i2s_format | 361 chip->model.adc_i2s_format |
359 oxygen_i2s_bits(hw_params), 362 oxygen_i2s_bits(hw_params),
360 OXYGEN_I2S_RATE_MASK | 363 OXYGEN_I2S_RATE_MASK |
@@ -390,7 +393,8 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
390 if (!is_ac97) 393 if (!is_ac97)
391 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT, 394 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT,
392 oxygen_rate(hw_params) | 395 oxygen_rate(hw_params) |
393 oxygen_i2s_mclk(hw_params) | 396 chip->model.get_i2s_mclk(chip, PCM_B,
397 hw_params) |
394 chip->model.adc_i2s_format | 398 chip->model.adc_i2s_format |
395 oxygen_i2s_bits(hw_params), 399 oxygen_i2s_bits(hw_params),
396 OXYGEN_I2S_RATE_MASK | 400 OXYGEN_I2S_RATE_MASK |
@@ -435,6 +439,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream,
435 if (err < 0) 439 if (err < 0)
436 return err; 440 return err;
437 441
442 mutex_lock(&chip->mutex);
438 spin_lock_irq(&chip->reg_lock); 443 spin_lock_irq(&chip->reg_lock);
439 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, 444 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
440 OXYGEN_SPDIF_OUT_ENABLE); 445 OXYGEN_SPDIF_OUT_ENABLE);
@@ -446,6 +451,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream,
446 OXYGEN_SPDIF_OUT_RATE_MASK); 451 OXYGEN_SPDIF_OUT_RATE_MASK);
447 oxygen_update_spdif_source(chip); 452 oxygen_update_spdif_source(chip);
448 spin_unlock_irq(&chip->reg_lock); 453 spin_unlock_irq(&chip->reg_lock);
454 mutex_unlock(&chip->mutex);
449 return 0; 455 return 0;
450} 456}
451 457
@@ -459,6 +465,7 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
459 if (err < 0) 465 if (err < 0)
460 return err; 466 return err;
461 467
468 mutex_lock(&chip->mutex);
462 spin_lock_irq(&chip->reg_lock); 469 spin_lock_irq(&chip->reg_lock);
463 oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS, 470 oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS,
464 oxygen_play_channels(hw_params), 471 oxygen_play_channels(hw_params),
@@ -469,18 +476,18 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
469 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, 476 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
470 oxygen_rate(hw_params) | 477 oxygen_rate(hw_params) |
471 chip->model.dac_i2s_format | 478 chip->model.dac_i2s_format |
472 oxygen_i2s_mclk(hw_params) | 479 chip->model.get_i2s_mclk(chip, PCM_MULTICH,
480 hw_params) |
473 oxygen_i2s_bits(hw_params), 481 oxygen_i2s_bits(hw_params),
474 OXYGEN_I2S_RATE_MASK | 482 OXYGEN_I2S_RATE_MASK |
475 OXYGEN_I2S_FORMAT_MASK | 483 OXYGEN_I2S_FORMAT_MASK |
476 OXYGEN_I2S_MCLK_MASK | 484 OXYGEN_I2S_MCLK_MASK |
477 OXYGEN_I2S_BITS_MASK); 485 OXYGEN_I2S_BITS_MASK);
478 oxygen_update_dac_routing(chip);
479 oxygen_update_spdif_source(chip); 486 oxygen_update_spdif_source(chip);
480 spin_unlock_irq(&chip->reg_lock); 487 spin_unlock_irq(&chip->reg_lock);
481 488
482 mutex_lock(&chip->mutex);
483 chip->model.set_dac_params(chip, hw_params); 489 chip->model.set_dac_params(chip, hw_params);
490 oxygen_update_dac_routing(chip);
484 mutex_unlock(&chip->mutex); 491 mutex_unlock(&chip->mutex);
485 return 0; 492 return 0;
486} 493}
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index 6ebcb6bdd712..6accaf9580b2 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -17,145 +17,12 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20/*
21 * Xonar D2/D2X
22 * ------------
23 *
24 * CMI8788:
25 *
26 * SPI 0 -> 1st PCM1796 (front)
27 * SPI 1 -> 2nd PCM1796 (surround)
28 * SPI 2 -> 3rd PCM1796 (center/LFE)
29 * SPI 4 -> 4th PCM1796 (back)
30 *
31 * GPIO 2 -> M0 of CS5381
32 * GPIO 3 -> M1 of CS5381
33 * GPIO 5 <- external power present (D2X only)
34 * GPIO 7 -> ALT
35 * GPIO 8 -> enable output to speakers
36 */
37
38/*
39 * Xonar D1/DX
40 * -----------
41 *
42 * CMI8788:
43 *
44 * I²C <-> CS4398 (front)
45 * <-> CS4362A (surround, center/LFE, back)
46 *
47 * GPI 0 <- external power present (DX only)
48 *
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)
54 *
55 * CS4398:
56 *
57 * AD0 <- 1
58 * AD1 <- 1
59 *
60 * CS4362A:
61 *
62 * AD0 <- 0
63 */
64
65/*
66 * Xonar HDAV1.3 (Deluxe)
67 * ----------------------
68 *
69 * CMI8788:
70 *
71 * I²C <-> PCM1796 (front)
72 *
73 * GPI 0 <- external power present
74 *
75 * GPIO 0 -> enable output to speakers
76 * GPIO 2 -> M0 of CS5381
77 * GPIO 3 -> M1 of CS5381
78 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
79 *
80 * TXD -> HDMI controller
81 * RXD <- HDMI controller
82 *
83 * PCM1796 front: AD1,0 <- 0,0
84 *
85 * no daughterboard
86 * ----------------
87 *
88 * GPIO 4 <- 1
89 *
90 * H6 daughterboard
91 * ----------------
92 *
93 * GPIO 4 <- 0
94 * GPIO 5 <- 0
95 *
96 * I²C <-> PCM1796 (surround)
97 * <-> PCM1796 (center/LFE)
98 * <-> PCM1796 (back)
99 *
100 * PCM1796 surround: AD1,0 <- 0,1
101 * PCM1796 center/LFE: AD1,0 <- 1,0
102 * PCM1796 back: AD1,0 <- 1,1
103 *
104 * unknown daughterboard
105 * ---------------------
106 *
107 * GPIO 4 <- 0
108 * GPIO 5 <- 1
109 *
110 * I²C <-> CS4362A (surround, center/LFE, back)
111 *
112 * CS4362A: AD0 <- 0
113 */
114
115/*
116 * Xonar Essence ST (Deluxe)/STX
117 * -----------------------------
118 *
119 * CMI8788:
120 *
121 * I²C <-> PCM1792A
122 *
123 * GPI 0 <- external power present
124 *
125 * GPIO 0 -> enable output to speakers
126 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
127 * GPIO 2 -> M0 of CS5381
128 * GPIO 3 -> M1 of CS5381
129 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
130 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
131 *
132 * PCM1792A:
133 *
134 * AD0 <- 0
135 *
136 * H6 daughterboard
137 * ----------------
138 *
139 * GPIO 4 <- 0
140 * GPIO 5 <- 0
141 */
142
143#include <linux/pci.h> 20#include <linux/pci.h>
144#include <linux/delay.h> 21#include <linux/delay.h>
145#include <linux/mutex.h>
146#include <sound/ac97_codec.h>
147#include <sound/asoundef.h>
148#include <sound/control.h>
149#include <sound/core.h> 22#include <sound/core.h>
150#include <sound/initval.h> 23#include <sound/initval.h>
151#include <sound/pcm.h> 24#include <sound/pcm.h>
152#include <sound/pcm_params.h> 25#include "xonar.h"
153#include <sound/tlv.h>
154#include "oxygen.h"
155#include "cm9780.h"
156#include "pcm1796.h"
157#include "cs4398.h"
158#include "cs4362a.h"
159 26
160MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 27MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
161MODULE_DESCRIPTION("Asus AVx00 driver"); 28MODULE_DESCRIPTION("Asus AVx00 driver");
@@ -173,972 +40,28 @@ MODULE_PARM_DESC(id, "ID string");
173module_param_array(enable, bool, NULL, 0444); 40module_param_array(enable, bool, NULL, 0444);
174MODULE_PARM_DESC(enable, "enable card"); 41MODULE_PARM_DESC(enable, "enable card");
175 42
176enum {
177 MODEL_D2,
178 MODEL_D2X,
179 MODEL_D1,
180 MODEL_DX,
181 MODEL_HDAV, /* without daughterboard */
182 MODEL_HDAV_H6, /* with H6 daughterboard */
183 MODEL_ST,
184 MODEL_ST_H6,
185 MODEL_STX,
186};
187
188static struct pci_device_id xonar_ids[] __devinitdata = { 43static struct pci_device_id xonar_ids[] __devinitdata = {
189 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 }, 44 { OXYGEN_PCI_SUBID(0x1043, 0x8269) },
190 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX }, 45 { OXYGEN_PCI_SUBID(0x1043, 0x8275) },
191 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X }, 46 { OXYGEN_PCI_SUBID(0x1043, 0x82b7) },
192 { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV }, 47 { OXYGEN_PCI_SUBID(0x1043, 0x8314) },
193 { OXYGEN_PCI_SUBID(0x1043, 0x8327), .driver_data = MODEL_DX }, 48 { OXYGEN_PCI_SUBID(0x1043, 0x8327) },
194 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 }, 49 { OXYGEN_PCI_SUBID(0x1043, 0x834f) },
195 { OXYGEN_PCI_SUBID(0x1043, 0x835c), .driver_data = MODEL_STX }, 50 { OXYGEN_PCI_SUBID(0x1043, 0x835c) },
196 { OXYGEN_PCI_SUBID(0x1043, 0x835d), .driver_data = MODEL_ST }, 51 { OXYGEN_PCI_SUBID(0x1043, 0x835d) },
197 { OXYGEN_PCI_SUBID_BROKEN_EEPROM }, 52 { OXYGEN_PCI_SUBID_BROKEN_EEPROM },
198 { } 53 { }
199}; 54};
200MODULE_DEVICE_TABLE(pci, xonar_ids); 55MODULE_DEVICE_TABLE(pci, xonar_ids);
201 56
202
203#define GPIO_CS53x1_M_MASK 0x000c
204#define GPIO_CS53x1_M_SINGLE 0x0000
205#define GPIO_CS53x1_M_DOUBLE 0x0004
206#define GPIO_CS53x1_M_QUAD 0x0008
207
208#define GPIO_D2X_EXT_POWER 0x0020
209#define GPIO_D2_ALT 0x0080
210#define GPIO_D2_OUTPUT_ENABLE 0x0100
211
212#define GPI_DX_EXT_POWER 0x01
213#define GPIO_DX_OUTPUT_ENABLE 0x0001
214#define GPIO_DX_FRONT_PANEL 0x0002
215#define GPIO_DX_INPUT_ROUTE 0x0100
216
217#define GPIO_DB_MASK 0x0030
218#define GPIO_DB_H6 0x0000
219#define GPIO_DB_XX 0x0020
220
221#define GPIO_ST_HP_REAR 0x0002
222#define GPIO_ST_HP 0x0080
223
224#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */
225#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
226#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
227
228struct xonar_data {
229 unsigned int anti_pop_delay;
230 unsigned int dacs;
231 u16 output_enable_bit;
232 u8 ext_power_reg;
233 u8 ext_power_int_reg;
234 u8 ext_power_bit;
235 u8 has_power;
236 u8 pcm1796_oversampling;
237 u8 cs4398_fm;
238 u8 cs4362a_fm;
239 u8 hdmi_params[5];
240};
241
242static void xonar_gpio_changed(struct oxygen *chip);
243
244static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
245 u8 reg, u8 value)
246{
247 /* maps ALSA channel pair number to SPI output */
248 static const u8 codec_map[4] = {
249 0, 1, 2, 4
250 };
251 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
252 OXYGEN_SPI_DATA_LENGTH_2 |
253 OXYGEN_SPI_CLOCK_160 |
254 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
255 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
256 (reg << 8) | value);
257}
258
259static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
260 u8 reg, u8 value)
261{
262 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
263}
264
265static void pcm1796_write(struct oxygen *chip, unsigned int codec,
266 u8 reg, u8 value)
267{
268 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
269 OXYGEN_FUNCTION_SPI)
270 pcm1796_write_spi(chip, codec, reg, value);
271 else
272 pcm1796_write_i2c(chip, codec, reg, value);
273}
274
275static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
276{
277 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
278}
279
280static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
281{
282 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
283}
284
285static void hdmi_write_command(struct oxygen *chip, u8 command,
286 unsigned int count, const u8 *params)
287{
288 unsigned int i;
289 u8 checksum;
290
291 oxygen_write_uart(chip, 0xfb);
292 oxygen_write_uart(chip, 0xef);
293 oxygen_write_uart(chip, command);
294 oxygen_write_uart(chip, count);
295 for (i = 0; i < count; ++i)
296 oxygen_write_uart(chip, params[i]);
297 checksum = 0xfb + 0xef + command + count;
298 for (i = 0; i < count; ++i)
299 checksum += params[i];
300 oxygen_write_uart(chip, checksum);
301}
302
303static void xonar_enable_output(struct oxygen *chip)
304{
305 struct xonar_data *data = chip->model_data;
306
307 msleep(data->anti_pop_delay);
308 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
309}
310
311static void xonar_common_init(struct oxygen *chip)
312{
313 struct xonar_data *data = chip->model_data;
314
315 if (data->ext_power_reg) {
316 oxygen_set_bits8(chip, data->ext_power_int_reg,
317 data->ext_power_bit);
318 chip->interrupt_mask |= OXYGEN_INT_GPIO;
319 chip->model.gpio_changed = xonar_gpio_changed;
320 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
321 & data->ext_power_bit);
322 }
323 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
324 GPIO_CS53x1_M_MASK | data->output_enable_bit);
325 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
326 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
327 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
328 xonar_enable_output(chip);
329}
330
331static void update_pcm1796_volume(struct oxygen *chip)
332{
333 struct xonar_data *data = chip->model_data;
334 unsigned int i;
335
336 for (i = 0; i < data->dacs; ++i) {
337 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]);
338 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]);
339 }
340}
341
342static void update_pcm1796_mute(struct oxygen *chip)
343{
344 struct xonar_data *data = chip->model_data;
345 unsigned int i;
346 u8 value;
347
348 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
349 if (chip->dac_mute)
350 value |= PCM1796_MUTE;
351 for (i = 0; i < data->dacs; ++i)
352 pcm1796_write(chip, i, 18, value);
353}
354
355static void pcm1796_init(struct oxygen *chip)
356{
357 struct xonar_data *data = chip->model_data;
358 unsigned int i;
359
360 for (i = 0; i < data->dacs; ++i) {
361 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
362 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
363 pcm1796_write(chip, i, 21, 0);
364 }
365 update_pcm1796_mute(chip); /* set ATLD before ATL/ATR */
366 update_pcm1796_volume(chip);
367}
368
369static void xonar_d2_init(struct oxygen *chip)
370{
371 struct xonar_data *data = chip->model_data;
372
373 data->anti_pop_delay = 300;
374 data->dacs = 4;
375 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
376 data->pcm1796_oversampling = PCM1796_OS_64;
377
378 pcm1796_init(chip);
379
380 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
381 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
382
383 xonar_common_init(chip);
384
385 snd_component_add(chip->card, "PCM1796");
386 snd_component_add(chip->card, "CS5381");
387}
388
389static void xonar_d2x_init(struct oxygen *chip)
390{
391 struct xonar_data *data = chip->model_data;
392
393 data->ext_power_reg = OXYGEN_GPIO_DATA;
394 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
395 data->ext_power_bit = GPIO_D2X_EXT_POWER;
396 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
397
398 xonar_d2_init(chip);
399}
400
401static void update_cs4362a_volumes(struct oxygen *chip)
402{
403 u8 mute;
404
405 mute = chip->dac_mute ? CS4362A_MUTE : 0;
406 cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
407 cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
408 cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
409 cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
410 cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
411 cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
412}
413
414static void update_cs43xx_volume(struct oxygen *chip)
415{
416 cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
417 cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
418 update_cs4362a_volumes(chip);
419}
420
421static void update_cs43xx_mute(struct oxygen *chip)
422{
423 u8 reg;
424
425 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
426 if (chip->dac_mute)
427 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
428 cs4398_write(chip, 4, reg);
429 update_cs4362a_volumes(chip);
430}
431
432static void cs43xx_init(struct oxygen *chip)
433{
434 struct xonar_data *data = chip->model_data;
435
436 /* set CPEN (control port mode) and power down */
437 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
438 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
439 /* configure */
440 cs4398_write(chip, 2, data->cs4398_fm);
441 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
442 cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP |
443 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP);
444 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
445 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
446 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
447 cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE);
448 cs4362a_write(chip, 0x05, 0);
449 cs4362a_write(chip, 0x06, data->cs4362a_fm);
450 cs4362a_write(chip, 0x09, data->cs4362a_fm);
451 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
452 update_cs43xx_volume(chip);
453 update_cs43xx_mute(chip);
454 /* clear power down */
455 cs4398_write(chip, 8, CS4398_CPEN);
456 cs4362a_write(chip, 0x01, CS4362A_CPEN);
457}
458
459static void xonar_d1_init(struct oxygen *chip)
460{
461 struct xonar_data *data = chip->model_data;
462
463 data->anti_pop_delay = 800;
464 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
465 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
466 data->cs4362a_fm = CS4362A_FM_SINGLE |
467 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
468
469 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
470 OXYGEN_2WIRE_LENGTH_8 |
471 OXYGEN_2WIRE_INTERRUPT_MASK |
472 OXYGEN_2WIRE_SPEED_FAST);
473
474 cs43xx_init(chip);
475
476 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
477 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
478 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
479 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
480
481 xonar_common_init(chip);
482
483 snd_component_add(chip->card, "CS4398");
484 snd_component_add(chip->card, "CS4362A");
485 snd_component_add(chip->card, "CS5361");
486}
487
488static void xonar_dx_init(struct oxygen *chip)
489{
490 struct xonar_data *data = chip->model_data;
491
492 data->ext_power_reg = OXYGEN_GPI_DATA;
493 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
494 data->ext_power_bit = GPI_DX_EXT_POWER;
495
496 xonar_d1_init(chip);
497}
498
499static void xonar_hdav_init(struct oxygen *chip)
500{
501 struct xonar_data *data = chip->model_data;
502 u8 param;
503
504 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
505 OXYGEN_2WIRE_LENGTH_8 |
506 OXYGEN_2WIRE_INTERRUPT_MASK |
507 OXYGEN_2WIRE_SPEED_FAST);
508
509 data->anti_pop_delay = 100;
510 data->dacs = chip->model.private_data == MODEL_HDAV_H6 ? 4 : 1;
511 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
512 data->ext_power_reg = OXYGEN_GPI_DATA;
513 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
514 data->ext_power_bit = GPI_DX_EXT_POWER;
515 data->pcm1796_oversampling = PCM1796_OS_64;
516
517 pcm1796_init(chip);
518
519 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DX_INPUT_ROUTE);
520 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_DX_INPUT_ROUTE);
521
522 oxygen_reset_uart(chip);
523 param = 0;
524 hdmi_write_command(chip, 0x61, 1, &param);
525 param = 1;
526 hdmi_write_command(chip, 0x74, 1, &param);
527 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
528 data->hdmi_params[4] = 1;
529 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
530
531 xonar_common_init(chip);
532
533 snd_component_add(chip->card, "PCM1796");
534 snd_component_add(chip->card, "CS5381");
535}
536
537static void xonar_st_init(struct oxygen *chip)
538{
539 struct xonar_data *data = chip->model_data;
540
541 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
542 OXYGEN_2WIRE_LENGTH_8 |
543 OXYGEN_2WIRE_INTERRUPT_MASK |
544 OXYGEN_2WIRE_SPEED_FAST);
545
546 if (chip->model.private_data == MODEL_ST_H6)
547 chip->model.dac_channels = 8;
548 data->anti_pop_delay = 100;
549 data->dacs = chip->model.private_data == MODEL_ST_H6 ? 4 : 1;
550 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
551 data->pcm1796_oversampling = PCM1796_OS_64;
552
553 pcm1796_init(chip);
554
555 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
556 GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
557 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
558 GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
559
560 xonar_common_init(chip);
561
562 snd_component_add(chip->card, "PCM1792A");
563 snd_component_add(chip->card, "CS5381");
564}
565
566static void xonar_stx_init(struct oxygen *chip)
567{
568 struct xonar_data *data = chip->model_data;
569
570 data->ext_power_reg = OXYGEN_GPI_DATA;
571 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
572 data->ext_power_bit = GPI_DX_EXT_POWER;
573
574 xonar_st_init(chip);
575}
576
577static void xonar_disable_output(struct oxygen *chip)
578{
579 struct xonar_data *data = chip->model_data;
580
581 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
582}
583
584static void xonar_d2_cleanup(struct oxygen *chip)
585{
586 xonar_disable_output(chip);
587}
588
589static void xonar_d1_cleanup(struct oxygen *chip)
590{
591 xonar_disable_output(chip);
592 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
593 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
594}
595
596static void xonar_hdav_cleanup(struct oxygen *chip)
597{
598 u8 param = 0;
599
600 hdmi_write_command(chip, 0x74, 1, &param);
601 xonar_disable_output(chip);
602}
603
604static void xonar_st_cleanup(struct oxygen *chip)
605{
606 xonar_disable_output(chip);
607}
608
609static void xonar_d2_suspend(struct oxygen *chip)
610{
611 xonar_d2_cleanup(chip);
612}
613
614static void xonar_d1_suspend(struct oxygen *chip)
615{
616 xonar_d1_cleanup(chip);
617}
618
619static void xonar_hdav_suspend(struct oxygen *chip)
620{
621 xonar_hdav_cleanup(chip);
622 msleep(2);
623}
624
625static void xonar_st_suspend(struct oxygen *chip)
626{
627 xonar_st_cleanup(chip);
628}
629
630static void xonar_d2_resume(struct oxygen *chip)
631{
632 pcm1796_init(chip);
633 xonar_enable_output(chip);
634}
635
636static void xonar_d1_resume(struct oxygen *chip)
637{
638 oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
639 msleep(1);
640 cs43xx_init(chip);
641 xonar_enable_output(chip);
642}
643
644static void xonar_hdav_resume(struct oxygen *chip)
645{
646 struct xonar_data *data = chip->model_data;
647 u8 param;
648
649 oxygen_reset_uart(chip);
650 param = 0;
651 hdmi_write_command(chip, 0x61, 1, &param);
652 param = 1;
653 hdmi_write_command(chip, 0x74, 1, &param);
654 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
655 pcm1796_init(chip);
656 xonar_enable_output(chip);
657}
658
659static void xonar_st_resume(struct oxygen *chip)
660{
661 pcm1796_init(chip);
662 xonar_enable_output(chip);
663}
664
665static void xonar_hdav_pcm_hardware_filter(unsigned int channel,
666 struct snd_pcm_hardware *hardware)
667{
668 if (channel == PCM_MULTICH) {
669 hardware->rates = SNDRV_PCM_RATE_44100 |
670 SNDRV_PCM_RATE_48000 |
671 SNDRV_PCM_RATE_96000 |
672 SNDRV_PCM_RATE_192000;
673 hardware->rate_min = 44100;
674 }
675}
676
677static void set_pcm1796_params(struct oxygen *chip,
678 struct snd_pcm_hw_params *params)
679{
680 struct xonar_data *data = chip->model_data;
681 unsigned int i;
682
683 data->pcm1796_oversampling =
684 params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
685 for (i = 0; i < data->dacs; ++i)
686 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
687}
688
689static void set_cs53x1_params(struct oxygen *chip,
690 struct snd_pcm_hw_params *params)
691{
692 unsigned int value;
693
694 if (params_rate(params) <= 54000)
695 value = GPIO_CS53x1_M_SINGLE;
696 else if (params_rate(params) <= 108000)
697 value = GPIO_CS53x1_M_DOUBLE;
698 else
699 value = GPIO_CS53x1_M_QUAD;
700 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
701 value, GPIO_CS53x1_M_MASK);
702}
703
704static void set_cs43xx_params(struct oxygen *chip,
705 struct snd_pcm_hw_params *params)
706{
707 struct xonar_data *data = chip->model_data;
708
709 data->cs4398_fm = CS4398_DEM_NONE | CS4398_DIF_LJUST;
710 data->cs4362a_fm = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
711 if (params_rate(params) <= 50000) {
712 data->cs4398_fm |= CS4398_FM_SINGLE;
713 data->cs4362a_fm |= CS4362A_FM_SINGLE;
714 } else if (params_rate(params) <= 100000) {
715 data->cs4398_fm |= CS4398_FM_DOUBLE;
716 data->cs4362a_fm |= CS4362A_FM_DOUBLE;
717 } else {
718 data->cs4398_fm |= CS4398_FM_QUAD;
719 data->cs4362a_fm |= CS4362A_FM_QUAD;
720 }
721 cs4398_write(chip, 2, data->cs4398_fm);
722 cs4362a_write(chip, 0x06, data->cs4362a_fm);
723 cs4362a_write(chip, 0x09, data->cs4362a_fm);
724 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
725}
726
727static void set_hdmi_params(struct oxygen *chip,
728 struct snd_pcm_hw_params *params)
729{
730 struct xonar_data *data = chip->model_data;
731
732 data->hdmi_params[0] = 0; /* 1 = non-audio */
733 switch (params_rate(params)) {
734 case 44100:
735 data->hdmi_params[1] = IEC958_AES3_CON_FS_44100;
736 break;
737 case 48000:
738 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
739 break;
740 default: /* 96000 */
741 data->hdmi_params[1] = IEC958_AES3_CON_FS_96000;
742 break;
743 case 192000:
744 data->hdmi_params[1] = IEC958_AES3_CON_FS_192000;
745 break;
746 }
747 data->hdmi_params[2] = params_channels(params) / 2 - 1;
748 if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
749 data->hdmi_params[3] = 0;
750 else
751 data->hdmi_params[3] = 0xc0;
752 data->hdmi_params[4] = 1; /* ? */
753 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
754}
755
756static void set_hdav_params(struct oxygen *chip,
757 struct snd_pcm_hw_params *params)
758{
759 set_pcm1796_params(chip, params);
760 set_hdmi_params(chip, params);
761}
762
763static void xonar_gpio_changed(struct oxygen *chip)
764{
765 struct xonar_data *data = chip->model_data;
766 u8 has_power;
767
768 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
769 & data->ext_power_bit);
770 if (has_power != data->has_power) {
771 data->has_power = has_power;
772 if (has_power) {
773 snd_printk(KERN_NOTICE "power restored\n");
774 } else {
775 snd_printk(KERN_CRIT
776 "Hey! Don't unplug the power cable!\n");
777 /* TODO: stop PCMs */
778 }
779 }
780}
781
782static void xonar_hdav_uart_input(struct oxygen *chip)
783{
784 if (chip->uart_input_count >= 2 &&
785 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
786 chip->uart_input[chip->uart_input_count - 1] == 'K') {
787 printk(KERN_DEBUG "message from Xonar HDAV HDMI chip received:\n");
788 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
789 chip->uart_input, chip->uart_input_count);
790 chip->uart_input_count = 0;
791 }
792}
793
794static int gpio_bit_switch_get(struct snd_kcontrol *ctl,
795 struct snd_ctl_elem_value *value)
796{
797 struct oxygen *chip = ctl->private_data;
798 u16 bit = ctl->private_value;
799
800 value->value.integer.value[0] =
801 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
802 return 0;
803}
804
805static int gpio_bit_switch_put(struct snd_kcontrol *ctl,
806 struct snd_ctl_elem_value *value)
807{
808 struct oxygen *chip = ctl->private_data;
809 u16 bit = ctl->private_value;
810 u16 old_bits, new_bits;
811 int changed;
812
813 spin_lock_irq(&chip->reg_lock);
814 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
815 if (value->value.integer.value[0])
816 new_bits = old_bits | bit;
817 else
818 new_bits = old_bits & ~bit;
819 changed = new_bits != old_bits;
820 if (changed)
821 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
822 spin_unlock_irq(&chip->reg_lock);
823 return changed;
824}
825
826static const struct snd_kcontrol_new alt_switch = {
827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
828 .name = "Analog Loopback Switch",
829 .info = snd_ctl_boolean_mono_info,
830 .get = gpio_bit_switch_get,
831 .put = gpio_bit_switch_put,
832 .private_value = GPIO_D2_ALT,
833};
834
835static const struct snd_kcontrol_new front_panel_switch = {
836 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
837 .name = "Front Panel Switch",
838 .info = snd_ctl_boolean_mono_info,
839 .get = gpio_bit_switch_get,
840 .put = gpio_bit_switch_put,
841 .private_value = GPIO_DX_FRONT_PANEL,
842};
843
844static int st_output_switch_info(struct snd_kcontrol *ctl,
845 struct snd_ctl_elem_info *info)
846{
847 static const char *const names[3] = {
848 "Speakers", "Headphones", "FP Headphones"
849 };
850
851 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
852 info->count = 1;
853 info->value.enumerated.items = 3;
854 if (info->value.enumerated.item >= 3)
855 info->value.enumerated.item = 2;
856 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
857 return 0;
858}
859
860static int st_output_switch_get(struct snd_kcontrol *ctl,
861 struct snd_ctl_elem_value *value)
862{
863 struct oxygen *chip = ctl->private_data;
864 u16 gpio;
865
866 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
867 if (!(gpio & GPIO_ST_HP))
868 value->value.enumerated.item[0] = 0;
869 else if (gpio & GPIO_ST_HP_REAR)
870 value->value.enumerated.item[0] = 1;
871 else
872 value->value.enumerated.item[0] = 2;
873 return 0;
874}
875
876
877static int st_output_switch_put(struct snd_kcontrol *ctl,
878 struct snd_ctl_elem_value *value)
879{
880 struct oxygen *chip = ctl->private_data;
881 u16 gpio_old, gpio;
882
883 mutex_lock(&chip->mutex);
884 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
885 gpio = gpio_old;
886 switch (value->value.enumerated.item[0]) {
887 case 0:
888 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
889 break;
890 case 1:
891 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
892 break;
893 case 2:
894 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
895 break;
896 }
897 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
898 mutex_unlock(&chip->mutex);
899 return gpio != gpio_old;
900}
901
902static const struct snd_kcontrol_new st_output_switch = {
903 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
904 .name = "Analog Output",
905 .info = st_output_switch_info,
906 .get = st_output_switch_get,
907 .put = st_output_switch_put,
908};
909
910static void xonar_line_mic_ac97_switch(struct oxygen *chip,
911 unsigned int reg, unsigned int mute)
912{
913 if (reg == AC97_LINE) {
914 spin_lock_irq(&chip->reg_lock);
915 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
916 mute ? GPIO_DX_INPUT_ROUTE : 0,
917 GPIO_DX_INPUT_ROUTE);
918 spin_unlock_irq(&chip->reg_lock);
919 }
920}
921
922static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
923static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0);
924
925static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
926{
927 if (!strncmp(template->name, "CD Capture ", 11))
928 /* CD in is actually connected to the video in pin */
929 template->private_value ^= AC97_CD ^ AC97_VIDEO;
930 return 0;
931}
932
933static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
934{
935 if (!strncmp(template->name, "CD Capture ", 11))
936 return 1; /* no CD input */
937 return 0;
938}
939
940static int xonar_st_control_filter(struct snd_kcontrol_new *template)
941{
942 if (!strncmp(template->name, "CD Capture ", 11))
943 return 1; /* no CD input */
944 if (!strcmp(template->name, "Stereo Upmixing"))
945 return 1; /* stereo only - we don't need upmixing */
946 return 0;
947}
948
949static int xonar_d2_mixer_init(struct oxygen *chip)
950{
951 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
952}
953
954static int xonar_d1_mixer_init(struct oxygen *chip)
955{
956 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
957}
958
959static int xonar_st_mixer_init(struct oxygen *chip)
960{
961 return snd_ctl_add(chip->card, snd_ctl_new1(&st_output_switch, chip));
962}
963
964static const struct oxygen_model model_xonar_d2 = {
965 .longname = "Asus Virtuoso 200",
966 .chip = "AV200",
967 .init = xonar_d2_init,
968 .control_filter = xonar_d2_control_filter,
969 .mixer_init = xonar_d2_mixer_init,
970 .cleanup = xonar_d2_cleanup,
971 .suspend = xonar_d2_suspend,
972 .resume = xonar_d2_resume,
973 .set_dac_params = set_pcm1796_params,
974 .set_adc_params = set_cs53x1_params,
975 .update_dac_volume = update_pcm1796_volume,
976 .update_dac_mute = update_pcm1796_mute,
977 .dac_tlv = pcm1796_db_scale,
978 .model_data_size = sizeof(struct xonar_data),
979 .device_config = PLAYBACK_0_TO_I2S |
980 PLAYBACK_1_TO_SPDIF |
981 CAPTURE_0_FROM_I2S_2 |
982 CAPTURE_1_FROM_SPDIF |
983 MIDI_OUTPUT |
984 MIDI_INPUT,
985 .dac_channels = 8,
986 .dac_volume_min = 255 - 2*60,
987 .dac_volume_max = 255,
988 .misc_flags = OXYGEN_MISC_MIDI,
989 .function_flags = OXYGEN_FUNCTION_SPI |
990 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
991 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
992 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
993};
994
995static const struct oxygen_model model_xonar_d1 = {
996 .longname = "Asus Virtuoso 100",
997 .chip = "AV200",
998 .init = xonar_d1_init,
999 .control_filter = xonar_d1_control_filter,
1000 .mixer_init = xonar_d1_mixer_init,
1001 .cleanup = xonar_d1_cleanup,
1002 .suspend = xonar_d1_suspend,
1003 .resume = xonar_d1_resume,
1004 .set_dac_params = set_cs43xx_params,
1005 .set_adc_params = set_cs53x1_params,
1006 .update_dac_volume = update_cs43xx_volume,
1007 .update_dac_mute = update_cs43xx_mute,
1008 .ac97_switch = xonar_line_mic_ac97_switch,
1009 .dac_tlv = cs4362a_db_scale,
1010 .model_data_size = sizeof(struct xonar_data),
1011 .device_config = PLAYBACK_0_TO_I2S |
1012 PLAYBACK_1_TO_SPDIF |
1013 CAPTURE_0_FROM_I2S_2,
1014 .dac_channels = 8,
1015 .dac_volume_min = 127 - 60,
1016 .dac_volume_max = 127,
1017 .function_flags = OXYGEN_FUNCTION_2WIRE,
1018 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1019 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1020};
1021
1022static const struct oxygen_model model_xonar_hdav = {
1023 .longname = "Asus Virtuoso 200",
1024 .chip = "AV200",
1025 .init = xonar_hdav_init,
1026 .cleanup = xonar_hdav_cleanup,
1027 .suspend = xonar_hdav_suspend,
1028 .resume = xonar_hdav_resume,
1029 .pcm_hardware_filter = xonar_hdav_pcm_hardware_filter,
1030 .set_dac_params = set_hdav_params,
1031 .set_adc_params = set_cs53x1_params,
1032 .update_dac_volume = update_pcm1796_volume,
1033 .update_dac_mute = update_pcm1796_mute,
1034 .uart_input = xonar_hdav_uart_input,
1035 .ac97_switch = xonar_line_mic_ac97_switch,
1036 .dac_tlv = pcm1796_db_scale,
1037 .model_data_size = sizeof(struct xonar_data),
1038 .device_config = PLAYBACK_0_TO_I2S |
1039 PLAYBACK_1_TO_SPDIF |
1040 CAPTURE_0_FROM_I2S_2 |
1041 CAPTURE_1_FROM_SPDIF,
1042 .dac_channels = 8,
1043 .dac_volume_min = 255 - 2*60,
1044 .dac_volume_max = 255,
1045 .misc_flags = OXYGEN_MISC_MIDI,
1046 .function_flags = OXYGEN_FUNCTION_2WIRE,
1047 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1048 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1049};
1050
1051static const struct oxygen_model model_xonar_st = {
1052 .longname = "Asus Virtuoso 100",
1053 .chip = "AV200",
1054 .init = xonar_st_init,
1055 .control_filter = xonar_st_control_filter,
1056 .mixer_init = xonar_st_mixer_init,
1057 .cleanup = xonar_st_cleanup,
1058 .suspend = xonar_st_suspend,
1059 .resume = xonar_st_resume,
1060 .set_dac_params = set_pcm1796_params,
1061 .set_adc_params = set_cs53x1_params,
1062 .update_dac_volume = update_pcm1796_volume,
1063 .update_dac_mute = update_pcm1796_mute,
1064 .ac97_switch = xonar_line_mic_ac97_switch,
1065 .dac_tlv = pcm1796_db_scale,
1066 .model_data_size = sizeof(struct xonar_data),
1067 .device_config = PLAYBACK_0_TO_I2S |
1068 PLAYBACK_1_TO_SPDIF |
1069 CAPTURE_0_FROM_I2S_2,
1070 .dac_channels = 2,
1071 .dac_volume_min = 255 - 2*60,
1072 .dac_volume_max = 255,
1073 .function_flags = OXYGEN_FUNCTION_2WIRE,
1074 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1075 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1076};
1077
1078static int __devinit get_xonar_model(struct oxygen *chip, 57static int __devinit get_xonar_model(struct oxygen *chip,
1079 const struct pci_device_id *id) 58 const struct pci_device_id *id)
1080{ 59{
1081 static const struct oxygen_model *const models[] = { 60 if (get_xonar_pcm179x_model(chip, id) >= 0)
1082 [MODEL_D1] = &model_xonar_d1, 61 return 0;
1083 [MODEL_DX] = &model_xonar_d1, 62 if (get_xonar_cs43xx_model(chip, id) >= 0)
1084 [MODEL_D2] = &model_xonar_d2, 63 return 0;
1085 [MODEL_D2X] = &model_xonar_d2, 64 return -EINVAL;
1086 [MODEL_HDAV] = &model_xonar_hdav,
1087 [MODEL_ST] = &model_xonar_st,
1088 [MODEL_STX] = &model_xonar_st,
1089 };
1090 static const char *const names[] = {
1091 [MODEL_D1] = "Xonar D1",
1092 [MODEL_DX] = "Xonar DX",
1093 [MODEL_D2] = "Xonar D2",
1094 [MODEL_D2X] = "Xonar D2X",
1095 [MODEL_HDAV] = "Xonar HDAV1.3",
1096 [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6",
1097 [MODEL_ST] = "Xonar Essence ST",
1098 [MODEL_ST_H6] = "Xonar Essence ST+H6",
1099 [MODEL_STX] = "Xonar Essence STX",
1100 };
1101 unsigned int model = id->driver_data;
1102
1103 if (model >= ARRAY_SIZE(models) || !models[model])
1104 return -EINVAL;
1105 chip->model = *models[model];
1106
1107 switch (model) {
1108 case MODEL_D2X:
1109 chip->model.init = xonar_d2x_init;
1110 break;
1111 case MODEL_DX:
1112 chip->model.init = xonar_dx_init;
1113 break;
1114 case MODEL_HDAV:
1115 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1116 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1117 case GPIO_DB_H6:
1118 model = MODEL_HDAV_H6;
1119 break;
1120 case GPIO_DB_XX:
1121 snd_printk(KERN_ERR "unknown daughterboard\n");
1122 return -ENODEV;
1123 }
1124 break;
1125 case MODEL_ST:
1126 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1127 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1128 case GPIO_DB_H6:
1129 model = MODEL_ST_H6;
1130 break;
1131 }
1132 break;
1133 case MODEL_STX:
1134 chip->model.init = xonar_stx_init;
1135 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1136 break;
1137 }
1138
1139 chip->model.shortname = names[model];
1140 chip->model.private_data = model;
1141 return 0;
1142} 65}
1143 66
1144static int __devinit xonar_probe(struct pci_dev *pci, 67static int __devinit xonar_probe(struct pci_dev *pci,
diff --git a/sound/pci/oxygen/xonar.h b/sound/pci/oxygen/xonar.h
new file mode 100644
index 000000000000..89b3ed814d64
--- /dev/null
+++ b/sound/pci/oxygen/xonar.h
@@ -0,0 +1,50 @@
1#ifndef XONAR_H_INCLUDED
2#define XONAR_H_INCLUDED
3
4#include "oxygen.h"
5
6struct xonar_generic {
7 unsigned int anti_pop_delay;
8 u16 output_enable_bit;
9 u8 ext_power_reg;
10 u8 ext_power_int_reg;
11 u8 ext_power_bit;
12 u8 has_power;
13};
14
15struct xonar_hdmi {
16 u8 params[5];
17};
18
19/* generic helper functions */
20
21void xonar_enable_output(struct oxygen *chip);
22void xonar_disable_output(struct oxygen *chip);
23void xonar_init_ext_power(struct oxygen *chip);
24void xonar_init_cs53x1(struct oxygen *chip);
25void xonar_set_cs53x1_params(struct oxygen *chip,
26 struct snd_pcm_hw_params *params);
27int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl,
28 struct snd_ctl_elem_value *value);
29int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,
30 struct snd_ctl_elem_value *value);
31
32/* model-specific card drivers */
33
34int get_xonar_pcm179x_model(struct oxygen *chip,
35 const struct pci_device_id *id);
36int get_xonar_cs43xx_model(struct oxygen *chip,
37 const struct pci_device_id *id);
38
39/* HDMI helper functions */
40
41void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *data);
42void xonar_hdmi_cleanup(struct oxygen *chip);
43void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi);
44void xonar_hdmi_pcm_hardware_filter(unsigned int channel,
45 struct snd_pcm_hardware *hardware);
46void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi,
47 struct snd_pcm_hw_params *params);
48void xonar_hdmi_uart_input(struct oxygen *chip);
49
50#endif
diff --git a/sound/pci/oxygen/xonar_cs43xx.c b/sound/pci/oxygen/xonar_cs43xx.c
new file mode 100644
index 000000000000..16c226bfcd2b
--- /dev/null
+++ b/sound/pci/oxygen/xonar_cs43xx.c
@@ -0,0 +1,434 @@
1/*
2 * card driver for models with CS4398/CS4362A DACs (Xonar D1/DX)
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * Xonar D1/DX
21 * -----------
22 *
23 * CMI8788:
24 *
25 * I²C <-> CS4398 (front)
26 * <-> CS4362A (surround, center/LFE, back)
27 *
28 * GPI 0 <- external power present (DX only)
29 *
30 * GPIO 0 -> enable output to speakers
31 * GPIO 1 -> enable front panel I/O
32 * GPIO 2 -> M0 of CS5361
33 * GPIO 3 -> M1 of CS5361
34 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
35 *
36 * CS4398:
37 *
38 * AD0 <- 1
39 * AD1 <- 1
40 *
41 * CS4362A:
42 *
43 * AD0 <- 0
44 *
45 * CM9780:
46 *
47 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5361 input
48 */
49
50#include <linux/pci.h>
51#include <linux/delay.h>
52#include <sound/ac97_codec.h>
53#include <sound/control.h>
54#include <sound/core.h>
55#include <sound/pcm.h>
56#include <sound/pcm_params.h>
57#include <sound/tlv.h>
58#include "xonar.h"
59#include "cs4398.h"
60#include "cs4362a.h"
61
62#define GPI_EXT_POWER 0x01
63#define GPIO_D1_OUTPUT_ENABLE 0x0001
64#define GPIO_D1_FRONT_PANEL 0x0002
65#define GPIO_D1_INPUT_ROUTE 0x0100
66
67#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
68#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
69
70struct xonar_cs43xx {
71 struct xonar_generic generic;
72 u8 cs4398_regs[8];
73 u8 cs4362a_regs[15];
74};
75
76static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
77{
78 struct xonar_cs43xx *data = chip->model_data;
79
80 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
81 if (reg < ARRAY_SIZE(data->cs4398_regs))
82 data->cs4398_regs[reg] = value;
83}
84
85static void cs4398_write_cached(struct oxygen *chip, u8 reg, u8 value)
86{
87 struct xonar_cs43xx *data = chip->model_data;
88
89 if (value != data->cs4398_regs[reg])
90 cs4398_write(chip, reg, value);
91}
92
93static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
94{
95 struct xonar_cs43xx *data = chip->model_data;
96
97 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
98 if (reg < ARRAY_SIZE(data->cs4362a_regs))
99 data->cs4362a_regs[reg] = value;
100}
101
102static void cs4362a_write_cached(struct oxygen *chip, u8 reg, u8 value)
103{
104 struct xonar_cs43xx *data = chip->model_data;
105
106 if (value != data->cs4362a_regs[reg])
107 cs4362a_write(chip, reg, value);
108}
109
110static void cs43xx_registers_init(struct oxygen *chip)
111{
112 struct xonar_cs43xx *data = chip->model_data;
113 unsigned int i;
114
115 /* set CPEN (control port mode) and power down */
116 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
117 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
118 /* configure */
119 cs4398_write(chip, 2, data->cs4398_regs[2]);
120 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
121 cs4398_write(chip, 4, data->cs4398_regs[4]);
122 cs4398_write(chip, 5, data->cs4398_regs[5]);
123 cs4398_write(chip, 6, data->cs4398_regs[6]);
124 cs4398_write(chip, 7, data->cs4398_regs[7]);
125 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
126 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
127 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
128 cs4362a_write(chip, 0x04, data->cs4362a_regs[0x04]);
129 cs4362a_write(chip, 0x05, 0);
130 for (i = 6; i <= 14; ++i)
131 cs4362a_write(chip, i, data->cs4362a_regs[i]);
132 /* clear power down */
133 cs4398_write(chip, 8, CS4398_CPEN);
134 cs4362a_write(chip, 0x01, CS4362A_CPEN);
135}
136
137static void xonar_d1_init(struct oxygen *chip)
138{
139 struct xonar_cs43xx *data = chip->model_data;
140
141 data->generic.anti_pop_delay = 800;
142 data->generic.output_enable_bit = GPIO_D1_OUTPUT_ENABLE;
143 data->cs4398_regs[2] =
144 CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
145 data->cs4398_regs[4] = CS4398_MUTEP_LOW |
146 CS4398_MUTE_B | CS4398_MUTE_A | CS4398_PAMUTE;
147 data->cs4398_regs[5] = 60 * 2;
148 data->cs4398_regs[6] = 60 * 2;
149 data->cs4398_regs[7] = CS4398_RMP_DN | CS4398_RMP_UP |
150 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP;
151 data->cs4362a_regs[4] = CS4362A_RMP_DN | CS4362A_DEM_NONE;
152 data->cs4362a_regs[6] = CS4362A_FM_SINGLE |
153 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
154 data->cs4362a_regs[7] = 60 | CS4362A_MUTE;
155 data->cs4362a_regs[8] = 60 | CS4362A_MUTE;
156 data->cs4362a_regs[9] = data->cs4362a_regs[6];
157 data->cs4362a_regs[10] = 60 | CS4362A_MUTE;
158 data->cs4362a_regs[11] = 60 | CS4362A_MUTE;
159 data->cs4362a_regs[12] = data->cs4362a_regs[6];
160 data->cs4362a_regs[13] = 60 | CS4362A_MUTE;
161 data->cs4362a_regs[14] = 60 | CS4362A_MUTE;
162
163 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
164 OXYGEN_2WIRE_LENGTH_8 |
165 OXYGEN_2WIRE_INTERRUPT_MASK |
166 OXYGEN_2WIRE_SPEED_FAST);
167
168 cs43xx_registers_init(chip);
169
170 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
171 GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE);
172 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
173 GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE);
174
175 xonar_init_cs53x1(chip);
176 xonar_enable_output(chip);
177
178 snd_component_add(chip->card, "CS4398");
179 snd_component_add(chip->card, "CS4362A");
180 snd_component_add(chip->card, "CS5361");
181}
182
183static void xonar_dx_init(struct oxygen *chip)
184{
185 struct xonar_cs43xx *data = chip->model_data;
186
187 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
188 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
189 data->generic.ext_power_bit = GPI_EXT_POWER;
190 xonar_init_ext_power(chip);
191 xonar_d1_init(chip);
192}
193
194static void xonar_d1_cleanup(struct oxygen *chip)
195{
196 xonar_disable_output(chip);
197 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
198 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
199}
200
201static void xonar_d1_suspend(struct oxygen *chip)
202{
203 xonar_d1_cleanup(chip);
204}
205
206static void xonar_d1_resume(struct oxygen *chip)
207{
208 oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
209 msleep(1);
210 cs43xx_registers_init(chip);
211 xonar_enable_output(chip);
212}
213
214static void set_cs43xx_params(struct oxygen *chip,
215 struct snd_pcm_hw_params *params)
216{
217 struct xonar_cs43xx *data = chip->model_data;
218 u8 cs4398_fm, cs4362a_fm;
219
220 if (params_rate(params) <= 50000) {
221 cs4398_fm = CS4398_FM_SINGLE;
222 cs4362a_fm = CS4362A_FM_SINGLE;
223 } else if (params_rate(params) <= 100000) {
224 cs4398_fm = CS4398_FM_DOUBLE;
225 cs4362a_fm = CS4362A_FM_DOUBLE;
226 } else {
227 cs4398_fm = CS4398_FM_QUAD;
228 cs4362a_fm = CS4362A_FM_QUAD;
229 }
230 cs4398_fm |= CS4398_DEM_NONE | CS4398_DIF_LJUST;
231 cs4398_write_cached(chip, 2, cs4398_fm);
232 cs4362a_fm |= data->cs4362a_regs[6] & ~CS4362A_FM_MASK;
233 cs4362a_write_cached(chip, 6, cs4362a_fm);
234 cs4362a_write_cached(chip, 12, cs4362a_fm);
235 cs4362a_fm &= CS4362A_FM_MASK;
236 cs4362a_fm |= data->cs4362a_regs[9] & ~CS4362A_FM_MASK;
237 cs4362a_write_cached(chip, 9, cs4362a_fm);
238}
239
240static void update_cs4362a_volumes(struct oxygen *chip)
241{
242 unsigned int i;
243 u8 mute;
244
245 mute = chip->dac_mute ? CS4362A_MUTE : 0;
246 for (i = 0; i < 6; ++i)
247 cs4362a_write_cached(chip, 7 + i + i / 2,
248 (127 - chip->dac_volume[2 + i]) | mute);
249}
250
251static void update_cs43xx_volume(struct oxygen *chip)
252{
253 cs4398_write_cached(chip, 5, (127 - chip->dac_volume[0]) * 2);
254 cs4398_write_cached(chip, 6, (127 - chip->dac_volume[1]) * 2);
255 update_cs4362a_volumes(chip);
256}
257
258static void update_cs43xx_mute(struct oxygen *chip)
259{
260 u8 reg;
261
262 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
263 if (chip->dac_mute)
264 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
265 cs4398_write_cached(chip, 4, reg);
266 update_cs4362a_volumes(chip);
267}
268
269static void update_cs43xx_center_lfe_mix(struct oxygen *chip, bool mixed)
270{
271 struct xonar_cs43xx *data = chip->model_data;
272 u8 reg;
273
274 reg = data->cs4362a_regs[9] & ~CS4362A_ATAPI_MASK;
275 if (mixed)
276 reg |= CS4362A_ATAPI_B_LR | CS4362A_ATAPI_A_LR;
277 else
278 reg |= CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
279 cs4362a_write_cached(chip, 9, reg);
280}
281
282static const struct snd_kcontrol_new front_panel_switch = {
283 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
284 .name = "Front Panel Switch",
285 .info = snd_ctl_boolean_mono_info,
286 .get = xonar_gpio_bit_switch_get,
287 .put = xonar_gpio_bit_switch_put,
288 .private_value = GPIO_D1_FRONT_PANEL,
289};
290
291static int rolloff_info(struct snd_kcontrol *ctl,
292 struct snd_ctl_elem_info *info)
293{
294 static const char *const names[2] = {
295 "Fast Roll-off", "Slow Roll-off"
296 };
297
298 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
299 info->count = 1;
300 info->value.enumerated.items = 2;
301 if (info->value.enumerated.item >= 2)
302 info->value.enumerated.item = 1;
303 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
304 return 0;
305}
306
307static int rolloff_get(struct snd_kcontrol *ctl,
308 struct snd_ctl_elem_value *value)
309{
310 struct oxygen *chip = ctl->private_data;
311 struct xonar_cs43xx *data = chip->model_data;
312
313 value->value.enumerated.item[0] =
314 (data->cs4398_regs[7] & CS4398_FILT_SEL) != 0;
315 return 0;
316}
317
318static int rolloff_put(struct snd_kcontrol *ctl,
319 struct snd_ctl_elem_value *value)
320{
321 struct oxygen *chip = ctl->private_data;
322 struct xonar_cs43xx *data = chip->model_data;
323 int changed;
324 u8 reg;
325
326 mutex_lock(&chip->mutex);
327 reg = data->cs4398_regs[7];
328 if (value->value.enumerated.item[0])
329 reg |= CS4398_FILT_SEL;
330 else
331 reg &= ~CS4398_FILT_SEL;
332 changed = reg != data->cs4398_regs[7];
333 if (changed) {
334 cs4398_write(chip, 7, reg);
335 if (reg & CS4398_FILT_SEL)
336 reg = data->cs4362a_regs[0x04] | CS4362A_FILT_SEL;
337 else
338 reg = data->cs4362a_regs[0x04] & ~CS4362A_FILT_SEL;
339 cs4362a_write(chip, 0x04, reg);
340 }
341 mutex_unlock(&chip->mutex);
342 return changed;
343}
344
345static const struct snd_kcontrol_new rolloff_control = {
346 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
347 .name = "DAC Filter Playback Enum",
348 .info = rolloff_info,
349 .get = rolloff_get,
350 .put = rolloff_put,
351};
352
353static void xonar_d1_line_mic_ac97_switch(struct oxygen *chip,
354 unsigned int reg, unsigned int mute)
355{
356 if (reg == AC97_LINE) {
357 spin_lock_irq(&chip->reg_lock);
358 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
359 mute ? GPIO_D1_INPUT_ROUTE : 0,
360 GPIO_D1_INPUT_ROUTE);
361 spin_unlock_irq(&chip->reg_lock);
362 }
363}
364
365static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0);
366
367static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
368{
369 if (!strncmp(template->name, "CD Capture ", 11))
370 return 1; /* no CD input */
371 return 0;
372}
373
374static int xonar_d1_mixer_init(struct oxygen *chip)
375{
376 int err;
377
378 err = snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
379 if (err < 0)
380 return err;
381 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
382 if (err < 0)
383 return err;
384 return 0;
385}
386
387static const struct oxygen_model model_xonar_d1 = {
388 .longname = "Asus Virtuoso 100",
389 .chip = "AV200",
390 .init = xonar_d1_init,
391 .control_filter = xonar_d1_control_filter,
392 .mixer_init = xonar_d1_mixer_init,
393 .cleanup = xonar_d1_cleanup,
394 .suspend = xonar_d1_suspend,
395 .resume = xonar_d1_resume,
396 .get_i2s_mclk = oxygen_default_i2s_mclk,
397 .set_dac_params = set_cs43xx_params,
398 .set_adc_params = xonar_set_cs53x1_params,
399 .update_dac_volume = update_cs43xx_volume,
400 .update_dac_mute = update_cs43xx_mute,
401 .update_center_lfe_mix = update_cs43xx_center_lfe_mix,
402 .ac97_switch = xonar_d1_line_mic_ac97_switch,
403 .dac_tlv = cs4362a_db_scale,
404 .model_data_size = sizeof(struct xonar_cs43xx),
405 .device_config = PLAYBACK_0_TO_I2S |
406 PLAYBACK_1_TO_SPDIF |
407 CAPTURE_0_FROM_I2S_2,
408 .dac_channels = 8,
409 .dac_volume_min = 127 - 60,
410 .dac_volume_max = 127,
411 .function_flags = OXYGEN_FUNCTION_2WIRE,
412 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
413 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
414};
415
416int __devinit get_xonar_cs43xx_model(struct oxygen *chip,
417 const struct pci_device_id *id)
418{
419 switch (id->subdevice) {
420 case 0x834f:
421 chip->model = model_xonar_d1;
422 chip->model.shortname = "Xonar D1";
423 break;
424 case 0x8275:
425 case 0x8327:
426 chip->model = model_xonar_d1;
427 chip->model.shortname = "Xonar DX";
428 chip->model.init = xonar_dx_init;
429 break;
430 default:
431 return -EINVAL;
432 }
433 return 0;
434}
diff --git a/sound/pci/oxygen/xonar_hdmi.c b/sound/pci/oxygen/xonar_hdmi.c
new file mode 100644
index 000000000000..b12db1f1cea9
--- /dev/null
+++ b/sound/pci/oxygen/xonar_hdmi.c
@@ -0,0 +1,128 @@
1/*
2 * helper functions for HDMI models (Xonar HDAV1.3)
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/pci.h>
20#include <linux/delay.h>
21#include <sound/asoundef.h>
22#include <sound/control.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/tlv.h>
27#include "xonar.h"
28
29static void hdmi_write_command(struct oxygen *chip, u8 command,
30 unsigned int count, const u8 *params)
31{
32 unsigned int i;
33 u8 checksum;
34
35 oxygen_write_uart(chip, 0xfb);
36 oxygen_write_uart(chip, 0xef);
37 oxygen_write_uart(chip, command);
38 oxygen_write_uart(chip, count);
39 for (i = 0; i < count; ++i)
40 oxygen_write_uart(chip, params[i]);
41 checksum = 0xfb + 0xef + command + count;
42 for (i = 0; i < count; ++i)
43 checksum += params[i];
44 oxygen_write_uart(chip, checksum);
45}
46
47static void xonar_hdmi_init_commands(struct oxygen *chip,
48 struct xonar_hdmi *hdmi)
49{
50 u8 param;
51
52 oxygen_reset_uart(chip);
53 param = 0;
54 hdmi_write_command(chip, 0x61, 1, &param);
55 param = 1;
56 hdmi_write_command(chip, 0x74, 1, &param);
57 hdmi_write_command(chip, 0x54, 5, hdmi->params);
58}
59
60void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *hdmi)
61{
62 hdmi->params[1] = IEC958_AES3_CON_FS_48000;
63 hdmi->params[4] = 1;
64 xonar_hdmi_init_commands(chip, hdmi);
65}
66
67void xonar_hdmi_cleanup(struct oxygen *chip)
68{
69 u8 param = 0;
70
71 hdmi_write_command(chip, 0x74, 1, &param);
72}
73
74void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi)
75{
76 xonar_hdmi_init_commands(chip, hdmi);
77}
78
79void xonar_hdmi_pcm_hardware_filter(unsigned int channel,
80 struct snd_pcm_hardware *hardware)
81{
82 if (channel == PCM_MULTICH) {
83 hardware->rates = SNDRV_PCM_RATE_44100 |
84 SNDRV_PCM_RATE_48000 |
85 SNDRV_PCM_RATE_96000 |
86 SNDRV_PCM_RATE_192000;
87 hardware->rate_min = 44100;
88 }
89}
90
91void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi,
92 struct snd_pcm_hw_params *params)
93{
94 hdmi->params[0] = 0; /* 1 = non-audio */
95 switch (params_rate(params)) {
96 case 44100:
97 hdmi->params[1] = IEC958_AES3_CON_FS_44100;
98 break;
99 case 48000:
100 hdmi->params[1] = IEC958_AES3_CON_FS_48000;
101 break;
102 default: /* 96000 */
103 hdmi->params[1] = IEC958_AES3_CON_FS_96000;
104 break;
105 case 192000:
106 hdmi->params[1] = IEC958_AES3_CON_FS_192000;
107 break;
108 }
109 hdmi->params[2] = params_channels(params) / 2 - 1;
110 if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
111 hdmi->params[3] = 0;
112 else
113 hdmi->params[3] = 0xc0;
114 hdmi->params[4] = 1; /* ? */
115 hdmi_write_command(chip, 0x54, 5, hdmi->params);
116}
117
118void xonar_hdmi_uart_input(struct oxygen *chip)
119{
120 if (chip->uart_input_count >= 2 &&
121 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
122 chip->uart_input[chip->uart_input_count - 1] == 'K') {
123 printk(KERN_DEBUG "message from HDMI chip received:\n");
124 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
125 chip->uart_input, chip->uart_input_count);
126 chip->uart_input_count = 0;
127 }
128}
diff --git a/sound/pci/oxygen/xonar_lib.c b/sound/pci/oxygen/xonar_lib.c
new file mode 100644
index 000000000000..b3ff71316653
--- /dev/null
+++ b/sound/pci/oxygen/xonar_lib.c
@@ -0,0 +1,132 @@
1/*
2 * helper functions for Asus Xonar cards
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/delay.h>
20#include <sound/core.h>
21#include <sound/control.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include "xonar.h"
25
26
27#define GPIO_CS53x1_M_MASK 0x000c
28#define GPIO_CS53x1_M_SINGLE 0x0000
29#define GPIO_CS53x1_M_DOUBLE 0x0004
30#define GPIO_CS53x1_M_QUAD 0x0008
31
32
33void xonar_enable_output(struct oxygen *chip)
34{
35 struct xonar_generic *data = chip->model_data;
36
37 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit);
38 msleep(data->anti_pop_delay);
39 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
40}
41
42void xonar_disable_output(struct oxygen *chip)
43{
44 struct xonar_generic *data = chip->model_data;
45
46 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
47}
48
49static void xonar_ext_power_gpio_changed(struct oxygen *chip)
50{
51 struct xonar_generic *data = chip->model_data;
52 u8 has_power;
53
54 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
55 & data->ext_power_bit);
56 if (has_power != data->has_power) {
57 data->has_power = has_power;
58 if (has_power) {
59 snd_printk(KERN_NOTICE "power restored\n");
60 } else {
61 snd_printk(KERN_CRIT
62 "Hey! Don't unplug the power cable!\n");
63 /* TODO: stop PCMs */
64 }
65 }
66}
67
68void xonar_init_ext_power(struct oxygen *chip)
69{
70 struct xonar_generic *data = chip->model_data;
71
72 oxygen_set_bits8(chip, data->ext_power_int_reg,
73 data->ext_power_bit);
74 chip->interrupt_mask |= OXYGEN_INT_GPIO;
75 chip->model.gpio_changed = xonar_ext_power_gpio_changed;
76 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
77 & data->ext_power_bit);
78}
79
80void xonar_init_cs53x1(struct oxygen *chip)
81{
82 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK);
83 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
84 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
85}
86
87void xonar_set_cs53x1_params(struct oxygen *chip,
88 struct snd_pcm_hw_params *params)
89{
90 unsigned int value;
91
92 if (params_rate(params) <= 54000)
93 value = GPIO_CS53x1_M_SINGLE;
94 else if (params_rate(params) <= 108000)
95 value = GPIO_CS53x1_M_DOUBLE;
96 else
97 value = GPIO_CS53x1_M_QUAD;
98 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
99 value, GPIO_CS53x1_M_MASK);
100}
101
102int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl,
103 struct snd_ctl_elem_value *value)
104{
105 struct oxygen *chip = ctl->private_data;
106 u16 bit = ctl->private_value;
107
108 value->value.integer.value[0] =
109 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
110 return 0;
111}
112
113int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,
114 struct snd_ctl_elem_value *value)
115{
116 struct oxygen *chip = ctl->private_data;
117 u16 bit = ctl->private_value;
118 u16 old_bits, new_bits;
119 int changed;
120
121 spin_lock_irq(&chip->reg_lock);
122 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
123 if (value->value.integer.value[0])
124 new_bits = old_bits | bit;
125 else
126 new_bits = old_bits & ~bit;
127 changed = new_bits != old_bits;
128 if (changed)
129 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
130 spin_unlock_irq(&chip->reg_lock);
131 return changed;
132}
diff --git a/sound/pci/oxygen/xonar_pcm179x.c b/sound/pci/oxygen/xonar_pcm179x.c
new file mode 100644
index 000000000000..ba18fb546b4f
--- /dev/null
+++ b/sound/pci/oxygen/xonar_pcm179x.c
@@ -0,0 +1,1115 @@
1/*
2 * card driver for models with PCM1796 DACs (Xonar D2/D2X/HDAV1.3/ST/STX)
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * Xonar D2/D2X
21 * ------------
22 *
23 * CMI8788:
24 *
25 * SPI 0 -> 1st PCM1796 (front)
26 * SPI 1 -> 2nd PCM1796 (surround)
27 * SPI 2 -> 3rd PCM1796 (center/LFE)
28 * SPI 4 -> 4th PCM1796 (back)
29 *
30 * GPIO 2 -> M0 of CS5381
31 * GPIO 3 -> M1 of CS5381
32 * GPIO 5 <- external power present (D2X only)
33 * GPIO 7 -> ALT
34 * GPIO 8 -> enable output to speakers
35 *
36 * CM9780:
37 *
38 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
39 */
40
41/*
42 * Xonar HDAV1.3 (Deluxe)
43 * ----------------------
44 *
45 * CMI8788:
46 *
47 * I²C <-> PCM1796 (front)
48 *
49 * GPI 0 <- external power present
50 *
51 * GPIO 0 -> enable output to speakers
52 * GPIO 2 -> M0 of CS5381
53 * GPIO 3 -> M1 of CS5381
54 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
55 *
56 * TXD -> HDMI controller
57 * RXD <- HDMI controller
58 *
59 * PCM1796 front: AD1,0 <- 0,0
60 *
61 * CM9780:
62 *
63 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
64 *
65 * no daughterboard
66 * ----------------
67 *
68 * GPIO 4 <- 1
69 *
70 * H6 daughterboard
71 * ----------------
72 *
73 * GPIO 4 <- 0
74 * GPIO 5 <- 0
75 *
76 * I²C <-> PCM1796 (surround)
77 * <-> PCM1796 (center/LFE)
78 * <-> PCM1796 (back)
79 *
80 * PCM1796 surround: AD1,0 <- 0,1
81 * PCM1796 center/LFE: AD1,0 <- 1,0
82 * PCM1796 back: AD1,0 <- 1,1
83 *
84 * unknown daughterboard
85 * ---------------------
86 *
87 * GPIO 4 <- 0
88 * GPIO 5 <- 1
89 *
90 * I²C <-> CS4362A (surround, center/LFE, back)
91 *
92 * CS4362A: AD0 <- 0
93 */
94
95/*
96 * Xonar Essence ST (Deluxe)/STX
97 * -----------------------------
98 *
99 * CMI8788:
100 *
101 * I²C <-> PCM1792A
102 * <-> CS2000 (ST only)
103 *
104 * ADC1 MCLK -> REF_CLK of CS2000 (ST only)
105 *
106 * GPI 0 <- external power present (STX only)
107 *
108 * GPIO 0 -> enable output to speakers
109 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
110 * GPIO 2 -> M0 of CS5381
111 * GPIO 3 -> M1 of CS5381
112 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
113 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
114 *
115 * PCM1792A:
116 *
117 * AD1,0 <- 0,0
118 * SCK <- CLK_OUT of CS2000 (ST only)
119 *
120 * CS2000:
121 *
122 * AD0 <- 0
123 *
124 * CM9780:
125 *
126 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
127 *
128 * H6 daughterboard
129 * ----------------
130 *
131 * GPIO 4 <- 0
132 * GPIO 5 <- 0
133 */
134
135#include <linux/pci.h>
136#include <linux/delay.h>
137#include <linux/mutex.h>
138#include <sound/ac97_codec.h>
139#include <sound/control.h>
140#include <sound/core.h>
141#include <sound/pcm.h>
142#include <sound/pcm_params.h>
143#include <sound/tlv.h>
144#include "xonar.h"
145#include "cm9780.h"
146#include "pcm1796.h"
147#include "cs2000.h"
148
149
150#define GPIO_D2X_EXT_POWER 0x0020
151#define GPIO_D2_ALT 0x0080
152#define GPIO_D2_OUTPUT_ENABLE 0x0100
153
154#define GPI_EXT_POWER 0x01
155#define GPIO_INPUT_ROUTE 0x0100
156
157#define GPIO_HDAV_OUTPUT_ENABLE 0x0001
158
159#define GPIO_DB_MASK 0x0030
160#define GPIO_DB_H6 0x0000
161
162#define GPIO_ST_OUTPUT_ENABLE 0x0001
163#define GPIO_ST_HP_REAR 0x0002
164#define GPIO_ST_HP 0x0080
165
166#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
167#define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
168
169#define PCM1796_REG_BASE 16
170
171
172struct xonar_pcm179x {
173 struct xonar_generic generic;
174 unsigned int dacs;
175 u8 pcm1796_regs[4][5];
176 unsigned int current_rate;
177 bool os_128;
178 bool hp_active;
179 s8 hp_gain_offset;
180 bool has_cs2000;
181 u8 cs2000_fun_cfg_1;
182};
183
184struct xonar_hdav {
185 struct xonar_pcm179x pcm179x;
186 struct xonar_hdmi hdmi;
187};
188
189
190static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
191 u8 reg, u8 value)
192{
193 /* maps ALSA channel pair number to SPI output */
194 static const u8 codec_map[4] = {
195 0, 1, 2, 4
196 };
197 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
198 OXYGEN_SPI_DATA_LENGTH_2 |
199 OXYGEN_SPI_CLOCK_160 |
200 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
201 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
202 (reg << 8) | value);
203}
204
205static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
206 u8 reg, u8 value)
207{
208 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
209}
210
211static void pcm1796_write(struct oxygen *chip, unsigned int codec,
212 u8 reg, u8 value)
213{
214 struct xonar_pcm179x *data = chip->model_data;
215
216 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
217 OXYGEN_FUNCTION_SPI)
218 pcm1796_write_spi(chip, codec, reg, value);
219 else
220 pcm1796_write_i2c(chip, codec, reg, value);
221 if ((unsigned int)(reg - PCM1796_REG_BASE)
222 < ARRAY_SIZE(data->pcm1796_regs[codec]))
223 data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
224}
225
226static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
227 u8 reg, u8 value)
228{
229 struct xonar_pcm179x *data = chip->model_data;
230
231 if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
232 pcm1796_write(chip, codec, reg, value);
233}
234
235static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
236{
237 struct xonar_pcm179x *data = chip->model_data;
238
239 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
240 if (reg == CS2000_FUN_CFG_1)
241 data->cs2000_fun_cfg_1 = value;
242}
243
244static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
245{
246 struct xonar_pcm179x *data = chip->model_data;
247
248 if (reg != CS2000_FUN_CFG_1 ||
249 value != data->cs2000_fun_cfg_1)
250 cs2000_write(chip, reg, value);
251}
252
253static void pcm1796_registers_init(struct oxygen *chip)
254{
255 struct xonar_pcm179x *data = chip->model_data;
256 unsigned int i;
257 s8 gain_offset;
258
259 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
260 for (i = 0; i < data->dacs; ++i) {
261 /* set ATLD before ATL/ATR */
262 pcm1796_write(chip, i, 18,
263 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
264 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
265 + gain_offset);
266 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
267 + gain_offset);
268 pcm1796_write(chip, i, 19,
269 data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
270 pcm1796_write(chip, i, 20,
271 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
272 pcm1796_write(chip, i, 21, 0);
273 }
274}
275
276static void pcm1796_init(struct oxygen *chip)
277{
278 struct xonar_pcm179x *data = chip->model_data;
279
280 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
281 PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
282 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
283 PCM1796_FLT_SHARP | PCM1796_ATS_1;
284 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64;
285 pcm1796_registers_init(chip);
286 data->current_rate = 48000;
287}
288
289static void xonar_d2_init(struct oxygen *chip)
290{
291 struct xonar_pcm179x *data = chip->model_data;
292
293 data->generic.anti_pop_delay = 300;
294 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
295 data->dacs = 4;
296
297 pcm1796_init(chip);
298
299 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
300 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
301
302 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
303
304 xonar_init_cs53x1(chip);
305 xonar_enable_output(chip);
306
307 snd_component_add(chip->card, "PCM1796");
308 snd_component_add(chip->card, "CS5381");
309}
310
311static void xonar_d2x_init(struct oxygen *chip)
312{
313 struct xonar_pcm179x *data = chip->model_data;
314
315 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
316 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
317 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
318 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
319 xonar_init_ext_power(chip);
320 xonar_d2_init(chip);
321}
322
323static void xonar_hdav_init(struct oxygen *chip)
324{
325 struct xonar_hdav *data = chip->model_data;
326
327 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
328 OXYGEN_2WIRE_LENGTH_8 |
329 OXYGEN_2WIRE_INTERRUPT_MASK |
330 OXYGEN_2WIRE_SPEED_FAST);
331
332 data->pcm179x.generic.anti_pop_delay = 100;
333 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
334 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
335 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
336 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
337 data->pcm179x.dacs = chip->model.private_data ? 4 : 1;
338
339 pcm1796_init(chip);
340
341 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_INPUT_ROUTE);
342 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
343
344 xonar_init_cs53x1(chip);
345 xonar_init_ext_power(chip);
346 xonar_hdmi_init(chip, &data->hdmi);
347 xonar_enable_output(chip);
348
349 snd_component_add(chip->card, "PCM1796");
350 snd_component_add(chip->card, "CS5381");
351}
352
353static void xonar_st_init_i2c(struct oxygen *chip)
354{
355 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
356 OXYGEN_2WIRE_LENGTH_8 |
357 OXYGEN_2WIRE_INTERRUPT_MASK |
358 OXYGEN_2WIRE_SPEED_FAST);
359}
360
361static void xonar_st_init_common(struct oxygen *chip)
362{
363 struct xonar_pcm179x *data = chip->model_data;
364
365 data->generic.anti_pop_delay = 100;
366 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
367 data->dacs = chip->model.private_data ? 4 : 1;
368 data->hp_gain_offset = 2*-18;
369
370 pcm1796_init(chip);
371
372 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
373 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
374 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
375 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
376
377 xonar_init_cs53x1(chip);
378 xonar_enable_output(chip);
379
380 snd_component_add(chip->card, "PCM1792A");
381 snd_component_add(chip->card, "CS5381");
382}
383
384static void cs2000_registers_init(struct oxygen *chip)
385{
386 struct xonar_pcm179x *data = chip->model_data;
387
388 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
389 cs2000_write(chip, CS2000_DEV_CTRL, 0);
390 cs2000_write(chip, CS2000_DEV_CFG_1,
391 CS2000_R_MOD_SEL_1 |
392 (0 << CS2000_R_SEL_SHIFT) |
393 CS2000_AUX_OUT_SRC_REF_CLK |
394 CS2000_EN_DEV_CFG_1);
395 cs2000_write(chip, CS2000_DEV_CFG_2,
396 (0 << CS2000_LOCK_CLK_SHIFT) |
397 CS2000_FRAC_N_SRC_STATIC);
398 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
399 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
400 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
401 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
402 cs2000_write(chip, CS2000_FUN_CFG_1, data->cs2000_fun_cfg_1);
403 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
404 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
405}
406
407static void xonar_st_init(struct oxygen *chip)
408{
409 struct xonar_pcm179x *data = chip->model_data;
410
411 data->has_cs2000 = 1;
412 data->cs2000_fun_cfg_1 = CS2000_REF_CLK_DIV_1;
413
414 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
415 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S |
416 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
417 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
418
419 xonar_st_init_i2c(chip);
420 cs2000_registers_init(chip);
421 xonar_st_init_common(chip);
422
423 snd_component_add(chip->card, "CS2000");
424}
425
426static void xonar_stx_init(struct oxygen *chip)
427{
428 struct xonar_pcm179x *data = chip->model_data;
429
430 xonar_st_init_i2c(chip);
431 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
432 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
433 data->generic.ext_power_bit = GPI_EXT_POWER;
434 xonar_init_ext_power(chip);
435 xonar_st_init_common(chip);
436}
437
438static void xonar_d2_cleanup(struct oxygen *chip)
439{
440 xonar_disable_output(chip);
441}
442
443static void xonar_hdav_cleanup(struct oxygen *chip)
444{
445 xonar_hdmi_cleanup(chip);
446 xonar_disable_output(chip);
447 msleep(2);
448}
449
450static void xonar_st_cleanup(struct oxygen *chip)
451{
452 xonar_disable_output(chip);
453}
454
455static void xonar_d2_suspend(struct oxygen *chip)
456{
457 xonar_d2_cleanup(chip);
458}
459
460static void xonar_hdav_suspend(struct oxygen *chip)
461{
462 xonar_hdav_cleanup(chip);
463}
464
465static void xonar_st_suspend(struct oxygen *chip)
466{
467 xonar_st_cleanup(chip);
468}
469
470static void xonar_d2_resume(struct oxygen *chip)
471{
472 pcm1796_registers_init(chip);
473 xonar_enable_output(chip);
474}
475
476static void xonar_hdav_resume(struct oxygen *chip)
477{
478 struct xonar_hdav *data = chip->model_data;
479
480 pcm1796_registers_init(chip);
481 xonar_hdmi_resume(chip, &data->hdmi);
482 xonar_enable_output(chip);
483}
484
485static void xonar_stx_resume(struct oxygen *chip)
486{
487 pcm1796_registers_init(chip);
488 xonar_enable_output(chip);
489}
490
491static void xonar_st_resume(struct oxygen *chip)
492{
493 cs2000_registers_init(chip);
494 xonar_stx_resume(chip);
495}
496
497static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
498{
499 struct xonar_pcm179x *data = chip->model_data;
500
501 if (rate <= 32000)
502 return OXYGEN_I2S_MCLK_512;
503 else if (rate <= 48000 && data->os_128)
504 return OXYGEN_I2S_MCLK_512;
505 else if (rate <= 96000)
506 return OXYGEN_I2S_MCLK_256;
507 else
508 return OXYGEN_I2S_MCLK_128;
509}
510
511static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
512 unsigned int channel,
513 struct snd_pcm_hw_params *params)
514{
515 if (channel == PCM_MULTICH)
516 return mclk_from_rate(chip, params_rate(params));
517 else
518 return oxygen_default_i2s_mclk(chip, channel, params);
519}
520
521static void update_pcm1796_oversampling(struct oxygen *chip)
522{
523 struct xonar_pcm179x *data = chip->model_data;
524 unsigned int i;
525 u8 reg;
526
527 if (data->current_rate <= 32000)
528 reg = PCM1796_OS_128;
529 else if (data->current_rate <= 48000 && data->os_128)
530 reg = PCM1796_OS_128;
531 else if (data->current_rate <= 96000 || data->os_128)
532 reg = PCM1796_OS_64;
533 else
534 reg = PCM1796_OS_32;
535 for (i = 0; i < data->dacs; ++i)
536 pcm1796_write_cached(chip, i, 20, reg);
537}
538
539static void set_pcm1796_params(struct oxygen *chip,
540 struct snd_pcm_hw_params *params)
541{
542 struct xonar_pcm179x *data = chip->model_data;
543
544 data->current_rate = params_rate(params);
545 update_pcm1796_oversampling(chip);
546}
547
548static void update_pcm1796_volume(struct oxygen *chip)
549{
550 struct xonar_pcm179x *data = chip->model_data;
551 unsigned int i;
552 s8 gain_offset;
553
554 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
555 for (i = 0; i < data->dacs; ++i) {
556 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
557 + gain_offset);
558 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
559 + gain_offset);
560 }
561}
562
563static void update_pcm1796_mute(struct oxygen *chip)
564{
565 struct xonar_pcm179x *data = chip->model_data;
566 unsigned int i;
567 u8 value;
568
569 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
570 if (chip->dac_mute)
571 value |= PCM1796_MUTE;
572 for (i = 0; i < data->dacs; ++i)
573 pcm1796_write_cached(chip, i, 18, value);
574}
575
576static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
577{
578 struct xonar_pcm179x *data = chip->model_data;
579 u8 rate_mclk, reg;
580
581 switch (rate) {
582 /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */
583 case 32000:
584 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
585 break;
586 case 44100:
587 if (data->os_128)
588 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
589 else
590 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128;
591 break;
592 default: /* 48000 */
593 if (data->os_128)
594 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
595 else
596 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128;
597 break;
598 case 64000:
599 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
600 break;
601 case 88200:
602 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
603 break;
604 case 96000:
605 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
606 break;
607 case 176400:
608 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
609 break;
610 case 192000:
611 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
612 break;
613 }
614 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
615 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
616 if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128)
617 reg = CS2000_REF_CLK_DIV_1;
618 else
619 reg = CS2000_REF_CLK_DIV_2;
620 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
621}
622
623static void set_st_params(struct oxygen *chip,
624 struct snd_pcm_hw_params *params)
625{
626 update_cs2000_rate(chip, params_rate(params));
627 set_pcm1796_params(chip, params);
628}
629
630static void set_hdav_params(struct oxygen *chip,
631 struct snd_pcm_hw_params *params)
632{
633 struct xonar_hdav *data = chip->model_data;
634
635 set_pcm1796_params(chip, params);
636 xonar_set_hdmi_params(chip, &data->hdmi, params);
637}
638
639static const struct snd_kcontrol_new alt_switch = {
640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
641 .name = "Analog Loopback Switch",
642 .info = snd_ctl_boolean_mono_info,
643 .get = xonar_gpio_bit_switch_get,
644 .put = xonar_gpio_bit_switch_put,
645 .private_value = GPIO_D2_ALT,
646};
647
648static int rolloff_info(struct snd_kcontrol *ctl,
649 struct snd_ctl_elem_info *info)
650{
651 static const char *const names[2] = {
652 "Sharp Roll-off", "Slow Roll-off"
653 };
654
655 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
656 info->count = 1;
657 info->value.enumerated.items = 2;
658 if (info->value.enumerated.item >= 2)
659 info->value.enumerated.item = 1;
660 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
661 return 0;
662}
663
664static int rolloff_get(struct snd_kcontrol *ctl,
665 struct snd_ctl_elem_value *value)
666{
667 struct oxygen *chip = ctl->private_data;
668 struct xonar_pcm179x *data = chip->model_data;
669
670 value->value.enumerated.item[0] =
671 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
672 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
673 return 0;
674}
675
676static int rolloff_put(struct snd_kcontrol *ctl,
677 struct snd_ctl_elem_value *value)
678{
679 struct oxygen *chip = ctl->private_data;
680 struct xonar_pcm179x *data = chip->model_data;
681 unsigned int i;
682 int changed;
683 u8 reg;
684
685 mutex_lock(&chip->mutex);
686 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
687 reg &= ~PCM1796_FLT_MASK;
688 if (!value->value.enumerated.item[0])
689 reg |= PCM1796_FLT_SHARP;
690 else
691 reg |= PCM1796_FLT_SLOW;
692 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
693 if (changed) {
694 for (i = 0; i < data->dacs; ++i)
695 pcm1796_write(chip, i, 19, reg);
696 }
697 mutex_unlock(&chip->mutex);
698 return changed;
699}
700
701static const struct snd_kcontrol_new rolloff_control = {
702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
703 .name = "DAC Filter Playback Enum",
704 .info = rolloff_info,
705 .get = rolloff_get,
706 .put = rolloff_put,
707};
708
709static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
710{
711 static const char *const names[2] = { "64x", "128x" };
712
713 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
714 info->count = 1;
715 info->value.enumerated.items = 2;
716 if (info->value.enumerated.item >= 2)
717 info->value.enumerated.item = 1;
718 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
719 return 0;
720}
721
722static int os_128_get(struct snd_kcontrol *ctl,
723 struct snd_ctl_elem_value *value)
724{
725 struct oxygen *chip = ctl->private_data;
726 struct xonar_pcm179x *data = chip->model_data;
727
728 value->value.enumerated.item[0] = data->os_128;
729 return 0;
730}
731
732static int os_128_put(struct snd_kcontrol *ctl,
733 struct snd_ctl_elem_value *value)
734{
735 struct oxygen *chip = ctl->private_data;
736 struct xonar_pcm179x *data = chip->model_data;
737 int changed;
738
739 mutex_lock(&chip->mutex);
740 changed = value->value.enumerated.item[0] != data->os_128;
741 if (changed) {
742 data->os_128 = value->value.enumerated.item[0];
743 if (data->has_cs2000)
744 update_cs2000_rate(chip, data->current_rate);
745 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
746 mclk_from_rate(chip, data->current_rate),
747 OXYGEN_I2S_MCLK_MASK);
748 update_pcm1796_oversampling(chip);
749 }
750 mutex_unlock(&chip->mutex);
751 return changed;
752}
753
754static const struct snd_kcontrol_new os_128_control = {
755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
756 .name = "DAC Oversampling Playback Enum",
757 .info = os_128_info,
758 .get = os_128_get,
759 .put = os_128_put,
760};
761
762static int st_output_switch_info(struct snd_kcontrol *ctl,
763 struct snd_ctl_elem_info *info)
764{
765 static const char *const names[3] = {
766 "Speakers", "Headphones", "FP Headphones"
767 };
768
769 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
770 info->count = 1;
771 info->value.enumerated.items = 3;
772 if (info->value.enumerated.item >= 3)
773 info->value.enumerated.item = 2;
774 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
775 return 0;
776}
777
778static int st_output_switch_get(struct snd_kcontrol *ctl,
779 struct snd_ctl_elem_value *value)
780{
781 struct oxygen *chip = ctl->private_data;
782 u16 gpio;
783
784 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
785 if (!(gpio & GPIO_ST_HP))
786 value->value.enumerated.item[0] = 0;
787 else if (gpio & GPIO_ST_HP_REAR)
788 value->value.enumerated.item[0] = 1;
789 else
790 value->value.enumerated.item[0] = 2;
791 return 0;
792}
793
794
795static int st_output_switch_put(struct snd_kcontrol *ctl,
796 struct snd_ctl_elem_value *value)
797{
798 struct oxygen *chip = ctl->private_data;
799 struct xonar_pcm179x *data = chip->model_data;
800 u16 gpio_old, gpio;
801
802 mutex_lock(&chip->mutex);
803 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
804 gpio = gpio_old;
805 switch (value->value.enumerated.item[0]) {
806 case 0:
807 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
808 break;
809 case 1:
810 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
811 break;
812 case 2:
813 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
814 break;
815 }
816 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
817 data->hp_active = gpio & GPIO_ST_HP;
818 update_pcm1796_volume(chip);
819 mutex_unlock(&chip->mutex);
820 return gpio != gpio_old;
821}
822
823static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
824 struct snd_ctl_elem_info *info)
825{
826 static const char *const names[3] = {
827 "< 64 ohms", "64-300 ohms", "300-600 ohms"
828 };
829
830 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
831 info->count = 1;
832 info->value.enumerated.items = 3;
833 if (info->value.enumerated.item > 2)
834 info->value.enumerated.item = 2;
835 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
836 return 0;
837}
838
839static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
840 struct snd_ctl_elem_value *value)
841{
842 struct oxygen *chip = ctl->private_data;
843 struct xonar_pcm179x *data = chip->model_data;
844
845 mutex_lock(&chip->mutex);
846 if (data->hp_gain_offset < 2*-6)
847 value->value.enumerated.item[0] = 0;
848 else if (data->hp_gain_offset < 0)
849 value->value.enumerated.item[0] = 1;
850 else
851 value->value.enumerated.item[0] = 2;
852 mutex_unlock(&chip->mutex);
853 return 0;
854}
855
856
857static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
858 struct snd_ctl_elem_value *value)
859{
860 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
861 struct oxygen *chip = ctl->private_data;
862 struct xonar_pcm179x *data = chip->model_data;
863 s8 offset;
864 int changed;
865
866 if (value->value.enumerated.item[0] > 2)
867 return -EINVAL;
868 offset = offsets[value->value.enumerated.item[0]];
869 mutex_lock(&chip->mutex);
870 changed = offset != data->hp_gain_offset;
871 if (changed) {
872 data->hp_gain_offset = offset;
873 update_pcm1796_volume(chip);
874 }
875 mutex_unlock(&chip->mutex);
876 return changed;
877}
878
879static const struct snd_kcontrol_new st_controls[] = {
880 {
881 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
882 .name = "Analog Output",
883 .info = st_output_switch_info,
884 .get = st_output_switch_get,
885 .put = st_output_switch_put,
886 },
887 {
888 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
889 .name = "Headphones Impedance Playback Enum",
890 .info = st_hp_volume_offset_info,
891 .get = st_hp_volume_offset_get,
892 .put = st_hp_volume_offset_put,
893 },
894};
895
896static void xonar_line_mic_ac97_switch(struct oxygen *chip,
897 unsigned int reg, unsigned int mute)
898{
899 if (reg == AC97_LINE) {
900 spin_lock_irq(&chip->reg_lock);
901 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
902 mute ? GPIO_INPUT_ROUTE : 0,
903 GPIO_INPUT_ROUTE);
904 spin_unlock_irq(&chip->reg_lock);
905 }
906}
907
908static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
909
910static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
911{
912 if (!strncmp(template->name, "CD Capture ", 11))
913 /* CD in is actually connected to the video in pin */
914 template->private_value ^= AC97_CD ^ AC97_VIDEO;
915 return 0;
916}
917
918static int xonar_st_control_filter(struct snd_kcontrol_new *template)
919{
920 if (!strncmp(template->name, "CD Capture ", 11))
921 return 1; /* no CD input */
922 return 0;
923}
924
925static int add_pcm1796_controls(struct oxygen *chip)
926{
927 int err;
928
929 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
930 if (err < 0)
931 return err;
932 err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip));
933 if (err < 0)
934 return err;
935 return 0;
936}
937
938static int xonar_d2_mixer_init(struct oxygen *chip)
939{
940 int err;
941
942 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
943 if (err < 0)
944 return err;
945 err = add_pcm1796_controls(chip);
946 if (err < 0)
947 return err;
948 return 0;
949}
950
951static int xonar_hdav_mixer_init(struct oxygen *chip)
952{
953 return add_pcm1796_controls(chip);
954}
955
956static int xonar_st_mixer_init(struct oxygen *chip)
957{
958 unsigned int i;
959 int err;
960
961 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
962 err = snd_ctl_add(chip->card,
963 snd_ctl_new1(&st_controls[i], chip));
964 if (err < 0)
965 return err;
966 }
967 err = add_pcm1796_controls(chip);
968 if (err < 0)
969 return err;
970 return 0;
971}
972
973static const struct oxygen_model model_xonar_d2 = {
974 .longname = "Asus Virtuoso 200",
975 .chip = "AV200",
976 .init = xonar_d2_init,
977 .control_filter = xonar_d2_control_filter,
978 .mixer_init = xonar_d2_mixer_init,
979 .cleanup = xonar_d2_cleanup,
980 .suspend = xonar_d2_suspend,
981 .resume = xonar_d2_resume,
982 .get_i2s_mclk = get_pcm1796_i2s_mclk,
983 .set_dac_params = set_pcm1796_params,
984 .set_adc_params = xonar_set_cs53x1_params,
985 .update_dac_volume = update_pcm1796_volume,
986 .update_dac_mute = update_pcm1796_mute,
987 .dac_tlv = pcm1796_db_scale,
988 .model_data_size = sizeof(struct xonar_pcm179x),
989 .device_config = PLAYBACK_0_TO_I2S |
990 PLAYBACK_1_TO_SPDIF |
991 CAPTURE_0_FROM_I2S_2 |
992 CAPTURE_1_FROM_SPDIF |
993 MIDI_OUTPUT |
994 MIDI_INPUT,
995 .dac_channels = 8,
996 .dac_volume_min = 255 - 2*60,
997 .dac_volume_max = 255,
998 .misc_flags = OXYGEN_MISC_MIDI,
999 .function_flags = OXYGEN_FUNCTION_SPI |
1000 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
1001 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1002 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1003};
1004
1005static const struct oxygen_model model_xonar_hdav = {
1006 .longname = "Asus Virtuoso 200",
1007 .chip = "AV200",
1008 .init = xonar_hdav_init,
1009 .mixer_init = xonar_hdav_mixer_init,
1010 .cleanup = xonar_hdav_cleanup,
1011 .suspend = xonar_hdav_suspend,
1012 .resume = xonar_hdav_resume,
1013 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
1014 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1015 .set_dac_params = set_hdav_params,
1016 .set_adc_params = xonar_set_cs53x1_params,
1017 .update_dac_volume = update_pcm1796_volume,
1018 .update_dac_mute = update_pcm1796_mute,
1019 .uart_input = xonar_hdmi_uart_input,
1020 .ac97_switch = xonar_line_mic_ac97_switch,
1021 .dac_tlv = pcm1796_db_scale,
1022 .model_data_size = sizeof(struct xonar_hdav),
1023 .device_config = PLAYBACK_0_TO_I2S |
1024 PLAYBACK_1_TO_SPDIF |
1025 CAPTURE_0_FROM_I2S_2 |
1026 CAPTURE_1_FROM_SPDIF,
1027 .dac_channels = 8,
1028 .dac_volume_min = 255 - 2*60,
1029 .dac_volume_max = 255,
1030 .misc_flags = OXYGEN_MISC_MIDI,
1031 .function_flags = OXYGEN_FUNCTION_2WIRE,
1032 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1033 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1034};
1035
1036static const struct oxygen_model model_xonar_st = {
1037 .longname = "Asus Virtuoso 100",
1038 .chip = "AV200",
1039 .init = xonar_st_init,
1040 .control_filter = xonar_st_control_filter,
1041 .mixer_init = xonar_st_mixer_init,
1042 .cleanup = xonar_st_cleanup,
1043 .suspend = xonar_st_suspend,
1044 .resume = xonar_st_resume,
1045 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1046 .set_dac_params = set_st_params,
1047 .set_adc_params = xonar_set_cs53x1_params,
1048 .update_dac_volume = update_pcm1796_volume,
1049 .update_dac_mute = update_pcm1796_mute,
1050 .ac97_switch = xonar_line_mic_ac97_switch,
1051 .dac_tlv = pcm1796_db_scale,
1052 .model_data_size = sizeof(struct xonar_pcm179x),
1053 .device_config = PLAYBACK_0_TO_I2S |
1054 PLAYBACK_1_TO_SPDIF |
1055 CAPTURE_0_FROM_I2S_2,
1056 .dac_channels = 2,
1057 .dac_volume_min = 255 - 2*60,
1058 .dac_volume_max = 255,
1059 .function_flags = OXYGEN_FUNCTION_2WIRE,
1060 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1061 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1062};
1063
1064int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1065 const struct pci_device_id *id)
1066{
1067 switch (id->subdevice) {
1068 case 0x8269:
1069 chip->model = model_xonar_d2;
1070 chip->model.shortname = "Xonar D2";
1071 break;
1072 case 0x82b7:
1073 chip->model = model_xonar_d2;
1074 chip->model.shortname = "Xonar D2X";
1075 chip->model.init = xonar_d2x_init;
1076 break;
1077 case 0x8314:
1078 chip->model = model_xonar_hdav;
1079 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1080 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1081 default:
1082 chip->model.shortname = "Xonar HDAV1.3";
1083 break;
1084 case GPIO_DB_H6:
1085 chip->model.shortname = "Xonar HDAV1.3+H6";
1086 chip->model.private_data = 1;
1087 break;
1088 }
1089 break;
1090 case 0x835d:
1091 chip->model = model_xonar_st;
1092 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1093 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1094 default:
1095 chip->model.shortname = "Xonar ST";
1096 break;
1097 case GPIO_DB_H6:
1098 chip->model.shortname = "Xonar ST+H6";
1099 chip->model.dac_channels = 8;
1100 chip->model.private_data = 1;
1101 break;
1102 }
1103 break;
1104 case 0x835c:
1105 chip->model = model_xonar_st;
1106 chip->model.shortname = "Xonar STX";
1107 chip->model.init = xonar_stx_init;
1108 chip->model.resume = xonar_stx_resume;
1109 chip->model.set_dac_params = set_pcm1796_params;
1110 break;
1111 default:
1112 return -EINVAL;
1113 }
1114 return 0;
1115}
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 0dce331a2a3b..a1b10d1a384d 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -3017,7 +3017,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
3017 insel = "Coaxial"; 3017 insel = "Coaxial";
3018 break; 3018 break;
3019 default: 3019 default:
3020 insel = "Unkown"; 3020 insel = "Unknown";
3021 } 3021 }
3022 3022
3023 switch (hdspm->control_register & HDSPM_SyncRefMask) { 3023 switch (hdspm->control_register & HDSPM_SyncRefMask) {
@@ -3028,7 +3028,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
3028 syncref = "MADI"; 3028 syncref = "MADI";
3029 break; 3029 break;
3030 default: 3030 default:
3031 syncref = "Unkown"; 3031 syncref = "Unknown";
3032 } 3032 }
3033 snd_iprintf(buffer, "Inputsel = %s, SyncRef = %s\n", insel, 3033 snd_iprintf(buffer, "Inputsel = %s, SyncRef = %s\n", insel,
3034 syncref); 3034 syncref);
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf.c b/sound/pcmcia/pdaudiocf/pdaudiocf.c
index 64b859925c0b..7717e01fc071 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf.c
@@ -131,7 +131,7 @@ static int snd_pdacf_probe(struct pcmcia_device *link)
131 return err; 131 return err;
132 } 132 }
133 133
134 snd_card_set_dev(card, &handle_to_dev(link)); 134 snd_card_set_dev(card, &link->dev);
135 135
136 pdacf->index = i; 136 pdacf->index = i;
137 card_list[i] = card; 137 card_list[i] = card;
@@ -142,12 +142,10 @@ static int snd_pdacf_probe(struct pcmcia_device *link)
142 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 142 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
143 link->io.NumPorts1 = 16; 143 link->io.NumPorts1 = 16;
144 144
145 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT | IRQ_FORCED_PULSE; 145 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_FORCED_PULSE;
146 // link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 146 // link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
147 147
148 link->irq.IRQInfo1 = 0 /* | IRQ_LEVEL_ID */;
149 link->irq.Handler = pdacf_interrupt; 148 link->irq.Handler = pdacf_interrupt;
150 link->irq.Instance = pdacf;
151 link->conf.Attributes = CONF_ENABLE_IRQ; 149 link->conf.Attributes = CONF_ENABLE_IRQ;
152 link->conf.IntType = INT_MEMORY_AND_IO; 150 link->conf.IntType = INT_MEMORY_AND_IO;
153 link->conf.ConfigIndex = 1; 151 link->conf.ConfigIndex = 1;
diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c
index 1492744ad67f..7be3b3357045 100644
--- a/sound/pcmcia/vx/vxpocket.c
+++ b/sound/pcmcia/vx/vxpocket.c
@@ -161,11 +161,9 @@ static int snd_vxpocket_new(struct snd_card *card, int ibl,
161 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 161 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
162 link->io.NumPorts1 = 16; 162 link->io.NumPorts1 = 16;
163 163
164 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 164 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
165 165
166 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
167 link->irq.Handler = &snd_vx_irq_handler; 166 link->irq.Handler = &snd_vx_irq_handler;
168 link->irq.Instance = chip;
169 167
170 link->conf.Attributes = CONF_ENABLE_IRQ; 168 link->conf.Attributes = CONF_ENABLE_IRQ;
171 link->conf.IntType = INT_MEMORY_AND_IO; 169 link->conf.IntType = INT_MEMORY_AND_IO;
@@ -244,7 +242,7 @@ static int vxpocket_config(struct pcmcia_device *link)
244 if (ret) 242 if (ret)
245 goto failed; 243 goto failed;
246 244
247 chip->dev = &handle_to_dev(link); 245 chip->dev = &link->dev;
248 snd_card_set_dev(chip->card, chip->dev); 246 snd_card_set_dev(chip->card, chip->dev);
249 247
250 if (snd_vxpocket_assign_resources(chip, link->io.BasePort1, link->irq.AssignedIRQ) < 0) 248 if (snd_vxpocket_assign_resources(chip, link->io.BasePort1, link->irq.AssignedIRQ) < 0)
diff --git a/sound/ppc/awacs.c b/sound/ppc/awacs.c
index 2cc0eda4f20e..2e156467b814 100644
--- a/sound/ppc/awacs.c
+++ b/sound/ppc/awacs.c
@@ -479,7 +479,7 @@ static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
479 479
480static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __devinitdata = { 480static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __devinitdata = {
481 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 481 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
482 .name = "PC Speaker Playback Volume", 482 .name = "Speaker Playback Volume",
483 .info = snd_pmac_awacs_info_volume_amp, 483 .info = snd_pmac_awacs_info_volume_amp,
484 .get = snd_pmac_awacs_get_volume_amp, 484 .get = snd_pmac_awacs_get_volume_amp,
485 .put = snd_pmac_awacs_put_volume_amp, 485 .put = snd_pmac_awacs_put_volume_amp,
@@ -525,7 +525,7 @@ static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __devinitdata = {
525 525
526static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __devinitdata = { 526static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __devinitdata = {
527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
528 .name = "PC Speaker Playback Switch", 528 .name = "Speaker Playback Switch",
529 .info = snd_pmac_boolean_stereo_info, 529 .info = snd_pmac_boolean_stereo_info,
530 .get = snd_pmac_awacs_get_switch_amp, 530 .get = snd_pmac_awacs_get_switch_amp,
531 .put = snd_pmac_awacs_put_switch_amp, 531 .put = snd_pmac_awacs_put_switch_amp,
@@ -696,17 +696,17 @@ static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __devinitdata
696}; 696};
697 697
698static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __devinitdata = { 698static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __devinitdata = {
699 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1), 699 AWACS_VOLUME("Speaker Playback Volume", 4, 6, 1),
700}; 700};
701 701
702static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __devinitdata = 702static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __devinitdata =
703AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1); 703AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
704 704
705static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __devinitdata = 705static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __devinitdata =
706AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 1); 706AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_PAROUT1, 1);
707 707
708static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __devinitdata = 708static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __devinitdata =
709AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0); 709AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
710 710
711 711
712/* 712/*
diff --git a/sound/ppc/burgundy.c b/sound/ppc/burgundy.c
index 16ed240e423c..0accfe49735b 100644
--- a/sound/ppc/burgundy.c
+++ b/sound/ppc/burgundy.c
@@ -505,7 +505,7 @@ static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac[] __devinitdata = {
505 MASK_ADDR_BURGUNDY_GAINLINE, 1, 0), 505 MASK_ADDR_BURGUNDY_GAINLINE, 1, 0),
506 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0, 506 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0,
507 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0), 507 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
508 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0, 508 BURGUNDY_VOLUME_B("Speaker Playback Volume", 0,
509 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1), 509 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
510 BURGUNDY_VOLUME_B("Line out Playback Volume", 0, 510 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
511 MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1), 511 MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1),
@@ -527,7 +527,7 @@ static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac[] __devinitdata = {
527 MASK_ADDR_BURGUNDY_VOLMIC, 16), 527 MASK_ADDR_BURGUNDY_VOLMIC, 16),
528 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0, 528 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
529 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0), 529 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
530 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0, 530 BURGUNDY_VOLUME_B("Speaker Playback Volume", 0,
531 MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1), 531 MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1),
532 BURGUNDY_VOLUME_B("Line out Playback Volume", 0, 532 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
533 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1), 533 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
@@ -549,11 +549,11 @@ BURGUNDY_SWITCH_B("Master Playback Switch", 0,
549 BURGUNDY_OUTPUT_INTERN 549 BURGUNDY_OUTPUT_INTERN
550 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 550 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
551static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __devinitdata = 551static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __devinitdata =
552BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0, 552BURGUNDY_SWITCH_B("Speaker Playback Switch", 0,
553 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 553 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
554 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 554 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
555static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __devinitdata = 555static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __devinitdata =
556BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0, 556BURGUNDY_SWITCH_B("Speaker Playback Switch", 0,
557 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 557 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
558 BURGUNDY_OUTPUT_INTERN, 0, 0); 558 BURGUNDY_OUTPUT_INTERN, 0, 0);
559static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __devinitdata = 559static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __devinitdata =
diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c
index 08e584d1453a..789f44f4ac78 100644
--- a/sound/ppc/tumbler.c
+++ b/sound/ppc/tumbler.c
@@ -905,7 +905,7 @@ static struct snd_kcontrol_new tumbler_hp_sw __devinitdata = {
905}; 905};
906static struct snd_kcontrol_new tumbler_speaker_sw __devinitdata = { 906static struct snd_kcontrol_new tumbler_speaker_sw __devinitdata = {
907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
908 .name = "PC Speaker Playback Switch", 908 .name = "Speaker Playback Switch",
909 .info = snd_pmac_boolean_mono_info, 909 .info = snd_pmac_boolean_mono_info,
910 .get = tumbler_get_mute_switch, 910 .get = tumbler_get_mute_switch,
911 .put = tumbler_put_mute_switch, 911 .put = tumbler_put_mute_switch,
diff --git a/sound/sh/Kconfig b/sound/sh/Kconfig
index aed0f90c3919..61139f3c1614 100644
--- a/sound/sh/Kconfig
+++ b/sound/sh/Kconfig
@@ -19,5 +19,13 @@ config SND_AICA
19 help 19 help
20 ALSA Sound driver for the SEGA Dreamcast console. 20 ALSA Sound driver for the SEGA Dreamcast console.
21 21
22config SND_SH_DAC_AUDIO
23 tristate "SuperH DAC audio support"
24 depends on SND
25 depends on CPU_SH3 && HIGH_RES_TIMERS
26 select SND_PCM
27 help
28 Say Y here to include support for the on-chip DAC.
29
22endif # SND_SUPERH 30endif # SND_SUPERH
23 31
diff --git a/sound/sh/Makefile b/sound/sh/Makefile
index 8fdcb6e26f00..7d09b5188cf7 100644
--- a/sound/sh/Makefile
+++ b/sound/sh/Makefile
@@ -3,6 +3,8 @@
3# 3#
4 4
5snd-aica-objs := aica.o 5snd-aica-objs := aica.o
6snd-sh_dac_audio-objs := sh_dac_audio.o
6 7
7# Toplevel Module Dependency 8# Toplevel Module Dependency
8obj-$(CONFIG_SND_AICA) += snd-aica.o 9obj-$(CONFIG_SND_AICA) += snd-aica.o
10obj-$(CONFIG_SND_SH_DAC_AUDIO) += snd-sh_dac_audio.o
diff --git a/sound/sh/sh_dac_audio.c b/sound/sh/sh_dac_audio.c
new file mode 100644
index 000000000000..76d9ad27d91c
--- /dev/null
+++ b/sound/sh/sh_dac_audio.c
@@ -0,0 +1,453 @@
1/*
2 * sh_dac_audio.c - SuperH DAC audio driver for ALSA
3 *
4 * Copyright (c) 2009 by Rafael Ignacio Zurita <rizurita@yahoo.com>
5 *
6 *
7 * Based on sh_dac_audio.c (Copyright (C) 2004, 2005 by Andriy Skulysh)
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program 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 this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <linux/hrtimer.h>
26#include <linux/interrupt.h>
27#include <linux/io.h>
28#include <linux/platform_device.h>
29#include <sound/core.h>
30#include <sound/initval.h>
31#include <sound/pcm.h>
32#include <sound/sh_dac_audio.h>
33#include <asm/clock.h>
34#include <asm/hd64461.h>
35#include <mach/hp6xx.h>
36#include <cpu/dac.h>
37
38MODULE_AUTHOR("Rafael Ignacio Zurita <rizurita@yahoo.com>");
39MODULE_DESCRIPTION("SuperH DAC audio driver");
40MODULE_LICENSE("GPL");
41MODULE_SUPPORTED_DEVICE("{{SuperH DAC audio support}}");
42
43/* Module Parameters */
44static int index = SNDRV_DEFAULT_IDX1;
45static char *id = SNDRV_DEFAULT_STR1;
46module_param(index, int, 0444);
47MODULE_PARM_DESC(index, "Index value for SuperH DAC audio.");
48module_param(id, charp, 0444);
49MODULE_PARM_DESC(id, "ID string for SuperH DAC audio.");
50
51/* main struct */
52struct snd_sh_dac {
53 struct snd_card *card;
54 struct snd_pcm_substream *substream;
55 struct hrtimer hrtimer;
56 ktime_t wakeups_per_second;
57
58 int rate;
59 int empty;
60 char *data_buffer, *buffer_begin, *buffer_end;
61 int processed; /* bytes proccesed, to compare with period_size */
62 int buffer_size;
63 struct dac_audio_pdata *pdata;
64};
65
66
67static void dac_audio_start_timer(struct snd_sh_dac *chip)
68{
69 hrtimer_start(&chip->hrtimer, chip->wakeups_per_second,
70 HRTIMER_MODE_REL);
71}
72
73static void dac_audio_stop_timer(struct snd_sh_dac *chip)
74{
75 hrtimer_cancel(&chip->hrtimer);
76}
77
78static void dac_audio_reset(struct snd_sh_dac *chip)
79{
80 dac_audio_stop_timer(chip);
81 chip->buffer_begin = chip->buffer_end = chip->data_buffer;
82 chip->processed = 0;
83 chip->empty = 1;
84}
85
86static void dac_audio_set_rate(struct snd_sh_dac *chip)
87{
88 chip->wakeups_per_second = ktime_set(0, 1000000000 / chip->rate);
89}
90
91
92/* PCM INTERFACE */
93
94static struct snd_pcm_hardware snd_sh_dac_pcm_hw = {
95 .info = (SNDRV_PCM_INFO_MMAP |
96 SNDRV_PCM_INFO_MMAP_VALID |
97 SNDRV_PCM_INFO_INTERLEAVED |
98 SNDRV_PCM_INFO_HALF_DUPLEX),
99 .formats = SNDRV_PCM_FMTBIT_U8,
100 .rates = SNDRV_PCM_RATE_8000,
101 .rate_min = 8000,
102 .rate_max = 8000,
103 .channels_min = 1,
104 .channels_max = 1,
105 .buffer_bytes_max = (48*1024),
106 .period_bytes_min = 1,
107 .period_bytes_max = (48*1024),
108 .periods_min = 1,
109 .periods_max = 1024,
110};
111
112static int snd_sh_dac_pcm_open(struct snd_pcm_substream *substream)
113{
114 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
115 struct snd_pcm_runtime *runtime = substream->runtime;
116
117 runtime->hw = snd_sh_dac_pcm_hw;
118
119 chip->substream = substream;
120 chip->buffer_begin = chip->buffer_end = chip->data_buffer;
121 chip->processed = 0;
122 chip->empty = 1;
123
124 chip->pdata->start(chip->pdata);
125
126 return 0;
127}
128
129static int snd_sh_dac_pcm_close(struct snd_pcm_substream *substream)
130{
131 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
132
133 chip->substream = NULL;
134
135 dac_audio_stop_timer(chip);
136 chip->pdata->stop(chip->pdata);
137
138 return 0;
139}
140
141static int snd_sh_dac_pcm_hw_params(struct snd_pcm_substream *substream,
142 struct snd_pcm_hw_params *hw_params)
143{
144 return snd_pcm_lib_malloc_pages(substream,
145 params_buffer_bytes(hw_params));
146}
147
148static int snd_sh_dac_pcm_hw_free(struct snd_pcm_substream *substream)
149{
150 return snd_pcm_lib_free_pages(substream);
151}
152
153static int snd_sh_dac_pcm_prepare(struct snd_pcm_substream *substream)
154{
155 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
156 struct snd_pcm_runtime *runtime = chip->substream->runtime;
157
158 chip->buffer_size = runtime->buffer_size;
159 memset(chip->data_buffer, 0, chip->pdata->buffer_size);
160
161 return 0;
162}
163
164static int snd_sh_dac_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
165{
166 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
167
168 switch (cmd) {
169 case SNDRV_PCM_TRIGGER_START:
170 dac_audio_start_timer(chip);
171 break;
172 case SNDRV_PCM_TRIGGER_STOP:
173 chip->buffer_begin = chip->buffer_end = chip->data_buffer;
174 chip->processed = 0;
175 chip->empty = 1;
176 dac_audio_stop_timer(chip);
177 break;
178 default:
179 return -EINVAL;
180 }
181
182 return 0;
183}
184
185static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream, int channel,
186 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
187{
188 /* channel is not used (interleaved data) */
189 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
190 struct snd_pcm_runtime *runtime = substream->runtime;
191 ssize_t b_count = frames_to_bytes(runtime , count);
192 ssize_t b_pos = frames_to_bytes(runtime , pos);
193
194 if (count < 0)
195 return -EINVAL;
196
197 if (!count)
198 return 0;
199
200 memcpy_toio(chip->data_buffer + b_pos, src, b_count);
201 chip->buffer_end = chip->data_buffer + b_pos + b_count;
202
203 if (chip->empty) {
204 chip->empty = 0;
205 dac_audio_start_timer(chip);
206 }
207
208 return 0;
209}
210
211static int snd_sh_dac_pcm_silence(struct snd_pcm_substream *substream,
212 int channel, snd_pcm_uframes_t pos,
213 snd_pcm_uframes_t count)
214{
215 /* channel is not used (interleaved data) */
216 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
217 struct snd_pcm_runtime *runtime = substream->runtime;
218 ssize_t b_count = frames_to_bytes(runtime , count);
219 ssize_t b_pos = frames_to_bytes(runtime , pos);
220
221 if (count < 0)
222 return -EINVAL;
223
224 if (!count)
225 return 0;
226
227 memset_io(chip->data_buffer + b_pos, 0, b_count);
228 chip->buffer_end = chip->data_buffer + b_pos + b_count;
229
230 if (chip->empty) {
231 chip->empty = 0;
232 dac_audio_start_timer(chip);
233 }
234
235 return 0;
236}
237
238static
239snd_pcm_uframes_t snd_sh_dac_pcm_pointer(struct snd_pcm_substream *substream)
240{
241 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
242 int pointer = chip->buffer_begin - chip->data_buffer;
243
244 return pointer;
245}
246
247/* pcm ops */
248static struct snd_pcm_ops snd_sh_dac_pcm_ops = {
249 .open = snd_sh_dac_pcm_open,
250 .close = snd_sh_dac_pcm_close,
251 .ioctl = snd_pcm_lib_ioctl,
252 .hw_params = snd_sh_dac_pcm_hw_params,
253 .hw_free = snd_sh_dac_pcm_hw_free,
254 .prepare = snd_sh_dac_pcm_prepare,
255 .trigger = snd_sh_dac_pcm_trigger,
256 .pointer = snd_sh_dac_pcm_pointer,
257 .copy = snd_sh_dac_pcm_copy,
258 .silence = snd_sh_dac_pcm_silence,
259 .mmap = snd_pcm_lib_mmap_iomem,
260};
261
262static int __devinit snd_sh_dac_pcm(struct snd_sh_dac *chip, int device)
263{
264 int err;
265 struct snd_pcm *pcm;
266
267 /* device should be always 0 for us */
268 err = snd_pcm_new(chip->card, "SH_DAC PCM", device, 1, 0, &pcm);
269 if (err < 0)
270 return err;
271
272 pcm->private_data = chip;
273 strcpy(pcm->name, "SH_DAC PCM");
274 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sh_dac_pcm_ops);
275
276 /* buffer size=48K */
277 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
278 snd_dma_continuous_data(GFP_KERNEL),
279 48 * 1024,
280 48 * 1024);
281
282 return 0;
283}
284/* END OF PCM INTERFACE */
285
286
287/* driver .remove -- destructor */
288static int snd_sh_dac_remove(struct platform_device *devptr)
289{
290 snd_card_free(platform_get_drvdata(devptr));
291 platform_set_drvdata(devptr, NULL);
292
293 return 0;
294}
295
296/* free -- it has been defined by create */
297static int snd_sh_dac_free(struct snd_sh_dac *chip)
298{
299 /* release the data */
300 kfree(chip->data_buffer);
301 kfree(chip);
302
303 return 0;
304}
305
306static int snd_sh_dac_dev_free(struct snd_device *device)
307{
308 struct snd_sh_dac *chip = device->device_data;
309
310 return snd_sh_dac_free(chip);
311}
312
313static enum hrtimer_restart sh_dac_audio_timer(struct hrtimer *handle)
314{
315 struct snd_sh_dac *chip = container_of(handle, struct snd_sh_dac,
316 hrtimer);
317 struct snd_pcm_runtime *runtime = chip->substream->runtime;
318 ssize_t b_ps = frames_to_bytes(runtime, runtime->period_size);
319
320 if (!chip->empty) {
321 sh_dac_output(*chip->buffer_begin, chip->pdata->channel);
322 chip->buffer_begin++;
323
324 chip->processed++;
325 if (chip->processed >= b_ps) {
326 chip->processed -= b_ps;
327 snd_pcm_period_elapsed(chip->substream);
328 }
329
330 if (chip->buffer_begin == (chip->data_buffer +
331 chip->buffer_size - 1))
332 chip->buffer_begin = chip->data_buffer;
333
334 if (chip->buffer_begin == chip->buffer_end)
335 chip->empty = 1;
336
337 }
338
339 if (!chip->empty)
340 hrtimer_start(&chip->hrtimer, chip->wakeups_per_second,
341 HRTIMER_MODE_REL);
342
343 return HRTIMER_NORESTART;
344}
345
346/* create -- chip-specific constructor for the cards components */
347static int __devinit snd_sh_dac_create(struct snd_card *card,
348 struct platform_device *devptr,
349 struct snd_sh_dac **rchip)
350{
351 struct snd_sh_dac *chip;
352 int err;
353
354 static struct snd_device_ops ops = {
355 .dev_free = snd_sh_dac_dev_free,
356 };
357
358 *rchip = NULL;
359
360 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
361 if (chip == NULL)
362 return -ENOMEM;
363
364 chip->card = card;
365
366 hrtimer_init(&chip->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
367 chip->hrtimer.function = sh_dac_audio_timer;
368
369 dac_audio_reset(chip);
370 chip->rate = 8000;
371 dac_audio_set_rate(chip);
372
373 chip->pdata = devptr->dev.platform_data;
374
375 chip->data_buffer = kmalloc(chip->pdata->buffer_size, GFP_KERNEL);
376 if (chip->data_buffer == NULL) {
377 kfree(chip);
378 return -ENOMEM;
379 }
380
381 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
382 if (err < 0) {
383 snd_sh_dac_free(chip);
384 return err;
385 }
386
387 *rchip = chip;
388
389 return 0;
390}
391
392/* driver .probe -- constructor */
393static int __devinit snd_sh_dac_probe(struct platform_device *devptr)
394{
395 struct snd_sh_dac *chip;
396 struct snd_card *card;
397 int err;
398
399 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
400 if (err < 0) {
401 snd_printk(KERN_ERR "cannot allocate the card\n");
402 return err;
403 }
404
405 err = snd_sh_dac_create(card, devptr, &chip);
406 if (err < 0)
407 goto probe_error;
408
409 err = snd_sh_dac_pcm(chip, 0);
410 if (err < 0)
411 goto probe_error;
412
413 strcpy(card->driver, "snd_sh_dac");
414 strcpy(card->shortname, "SuperH DAC audio driver");
415 printk(KERN_INFO "%s %s", card->longname, card->shortname);
416
417 err = snd_card_register(card);
418 if (err < 0)
419 goto probe_error;
420
421 snd_printk("ALSA driver for SuperH DAC audio");
422
423 platform_set_drvdata(devptr, card);
424 return 0;
425
426probe_error:
427 snd_card_free(card);
428 return err;
429}
430
431/*
432 * "driver" definition
433 */
434static struct platform_driver driver = {
435 .probe = snd_sh_dac_probe,
436 .remove = snd_sh_dac_remove,
437 .driver = {
438 .name = "dac_audio",
439 },
440};
441
442static int __init sh_dac_init(void)
443{
444 return platform_driver_register(&driver);
445}
446
447static void __exit sh_dac_exit(void)
448{
449 platform_driver_unregister(&driver);
450}
451
452module_init(sh_dac_init);
453module_exit(sh_dac_exit);
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 0c5eac01bf2e..1470141d4167 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,4 +1,4 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o 1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o
2 2
3obj-$(CONFIG_SND_SOC) += snd-soc-core.o 3obj-$(CONFIG_SND_SOC) += snd-soc-core.o
4obj-$(CONFIG_SND_SOC) += codecs/ 4obj-$(CONFIG_SND_SOC) += codecs/
diff --git a/sound/soc/atmel/playpaq_wm8510.c b/sound/soc/atmel/playpaq_wm8510.c
index 9eb610c2ba91..9df4c68ef000 100644
--- a/sound/soc/atmel/playpaq_wm8510.c
+++ b/sound/soc/atmel/playpaq_wm8510.c
@@ -268,7 +268,7 @@ static int playpaq_wm8510_hw_params(struct snd_pcm_substream *substream,
268#endif /* CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE */ 268#endif /* CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE */
269 269
270 270
271 ret = snd_soc_dai_set_pll(codec_dai, 0, 271 ret = snd_soc_dai_set_pll(codec_dai, 0, 0,
272 clk_get_rate(CODEC_CLK), pll_out); 272 clk_get_rate(CODEC_CLK), pll_out);
273 if (ret < 0) { 273 if (ret < 0) {
274 pr_warning("playpaq_wm8510: Failed to set CODEC DAI PLL (%d)\n", 274 pr_warning("playpaq_wm8510: Failed to set CODEC DAI PLL (%d)\n",
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index 885ba012557e..e028744c32ce 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -207,7 +207,7 @@ static int __init at91sam9g20ek_init(void)
207 struct clk *pllb; 207 struct clk *pllb;
208 int ret; 208 int ret;
209 209
210 if (!machine_is_at91sam9g20ek()) 210 if (!(machine_is_at91sam9g20ek() || machine_is_at91sam9g20ek_2mmc()))
211 return -ENODEV; 211 return -ENODEV;
212 212
213 /* 213 /*
diff --git a/sound/soc/au1x/dbdma2.c b/sound/soc/au1x/dbdma2.c
index 594c6c5b7838..19e4d37eba1c 100644
--- a/sound/soc/au1x/dbdma2.c
+++ b/sound/soc/au1x/dbdma2.c
@@ -2,7 +2,7 @@
2 * Au12x0/Au1550 PSC ALSA ASoC audio support. 2 * Au12x0/Au1550 PSC ALSA ASoC audio support.
3 * 3 *
4 * (c) 2007-2008 MSC Vertriebsges.m.b.H., 4 * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
5 * Manuel Lauss <mano@roarinelk.homelinux.net> 5 * Manuel Lauss <manuel.lauss@gmail.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License version 2 as
@@ -333,6 +333,30 @@ static int au1xpsc_pcm_new(struct snd_card *card,
333 333
334static int au1xpsc_pcm_probe(struct platform_device *pdev) 334static int au1xpsc_pcm_probe(struct platform_device *pdev)
335{ 335{
336 if (!au1xpsc_audio_pcmdma[PCM_TX] || !au1xpsc_audio_pcmdma[PCM_RX])
337 return -ENODEV;
338
339 return 0;
340}
341
342static int au1xpsc_pcm_remove(struct platform_device *pdev)
343{
344 return 0;
345}
346
347/* au1xpsc audio platform */
348struct snd_soc_platform au1xpsc_soc_platform = {
349 .name = "au1xpsc-pcm-dbdma",
350 .probe = au1xpsc_pcm_probe,
351 .remove = au1xpsc_pcm_remove,
352 .pcm_ops = &au1xpsc_pcm_ops,
353 .pcm_new = au1xpsc_pcm_new,
354 .pcm_free = au1xpsc_pcm_free_dma_buffers,
355};
356EXPORT_SYMBOL_GPL(au1xpsc_soc_platform);
357
358static int __devinit au1xpsc_pcm_drvprobe(struct platform_device *pdev)
359{
336 struct resource *r; 360 struct resource *r;
337 int ret; 361 int ret;
338 362
@@ -365,7 +389,9 @@ static int au1xpsc_pcm_probe(struct platform_device *pdev)
365 } 389 }
366 (au1xpsc_audio_pcmdma[PCM_RX])->ddma_id = r->start; 390 (au1xpsc_audio_pcmdma[PCM_RX])->ddma_id = r->start;
367 391
368 return 0; 392 ret = snd_soc_register_platform(&au1xpsc_soc_platform);
393 if (!ret)
394 return ret;
369 395
370out2: 396out2:
371 kfree(au1xpsc_audio_pcmdma[PCM_RX]); 397 kfree(au1xpsc_audio_pcmdma[PCM_RX]);
@@ -376,10 +402,12 @@ out1:
376 return ret; 402 return ret;
377} 403}
378 404
379static int au1xpsc_pcm_remove(struct platform_device *pdev) 405static int __devexit au1xpsc_pcm_drvremove(struct platform_device *pdev)
380{ 406{
381 int i; 407 int i;
382 408
409 snd_soc_unregister_platform(&au1xpsc_soc_platform);
410
383 for (i = 0; i < 2; i++) { 411 for (i = 0; i < 2; i++) {
384 if (au1xpsc_audio_pcmdma[i]) { 412 if (au1xpsc_audio_pcmdma[i]) {
385 au1x_pcm_dbdma_free(au1xpsc_audio_pcmdma[i]); 413 au1x_pcm_dbdma_free(au1xpsc_audio_pcmdma[i]);
@@ -391,32 +419,81 @@ static int au1xpsc_pcm_remove(struct platform_device *pdev)
391 return 0; 419 return 0;
392} 420}
393 421
394/* au1xpsc audio platform */ 422static struct platform_driver au1xpsc_pcm_driver = {
395struct snd_soc_platform au1xpsc_soc_platform = { 423 .driver = {
396 .name = "au1xpsc-pcm-dbdma", 424 .name = "au1xpsc-pcm",
397 .probe = au1xpsc_pcm_probe, 425 .owner = THIS_MODULE,
398 .remove = au1xpsc_pcm_remove, 426 },
399 .pcm_ops = &au1xpsc_pcm_ops, 427 .probe = au1xpsc_pcm_drvprobe,
400 .pcm_new = au1xpsc_pcm_new, 428 .remove = __devexit_p(au1xpsc_pcm_drvremove),
401 .pcm_free = au1xpsc_pcm_free_dma_buffers,
402}; 429};
403EXPORT_SYMBOL_GPL(au1xpsc_soc_platform);
404 430
405static int __init au1xpsc_audio_dbdma_init(void) 431static int __init au1xpsc_audio_dbdma_load(void)
406{ 432{
407 au1xpsc_audio_pcmdma[PCM_TX] = NULL; 433 au1xpsc_audio_pcmdma[PCM_TX] = NULL;
408 au1xpsc_audio_pcmdma[PCM_RX] = NULL; 434 au1xpsc_audio_pcmdma[PCM_RX] = NULL;
409 return snd_soc_register_platform(&au1xpsc_soc_platform); 435 return platform_driver_register(&au1xpsc_pcm_driver);
410} 436}
411 437
412static void __exit au1xpsc_audio_dbdma_exit(void) 438static void __exit au1xpsc_audio_dbdma_unload(void)
413{ 439{
414 snd_soc_unregister_platform(&au1xpsc_soc_platform); 440 platform_driver_unregister(&au1xpsc_pcm_driver);
415} 441}
416 442
417module_init(au1xpsc_audio_dbdma_init); 443module_init(au1xpsc_audio_dbdma_load);
418module_exit(au1xpsc_audio_dbdma_exit); 444module_exit(au1xpsc_audio_dbdma_unload);
445
446
447struct platform_device *au1xpsc_pcm_add(struct platform_device *pdev)
448{
449 struct resource *res, *r;
450 struct platform_device *pd;
451 int id[2];
452 int ret;
453
454 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
455 if (!r)
456 return NULL;
457 id[0] = r->start;
458
459 r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
460 if (!r)
461 return NULL;
462 id[1] = r->start;
463
464 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
465 if (!res)
466 return NULL;
467
468 res[0].start = res[0].end = id[0];
469 res[1].start = res[1].end = id[1];
470 res[0].flags = res[1].flags = IORESOURCE_DMA;
471
472 pd = platform_device_alloc("au1xpsc-pcm", -1);
473 if (!pd)
474 goto out;
475
476 pd->resource = res;
477 pd->num_resources = 2;
478
479 ret = platform_device_add(pd);
480 if (!ret)
481 return pd;
482
483 platform_device_put(pd);
484out:
485 kfree(res);
486 return NULL;
487}
488EXPORT_SYMBOL_GPL(au1xpsc_pcm_add);
489
490void au1xpsc_pcm_destroy(struct platform_device *dmapd)
491{
492 if (dmapd)
493 platform_device_unregister(dmapd);
494}
495EXPORT_SYMBOL_GPL(au1xpsc_pcm_destroy);
419 496
420MODULE_LICENSE("GPL"); 497MODULE_LICENSE("GPL");
421MODULE_DESCRIPTION("Au12x0/Au1550 PSC Audio DMA driver"); 498MODULE_DESCRIPTION("Au12x0/Au1550 PSC Audio DMA driver");
422MODULE_AUTHOR("Manuel Lauss <mano@roarinelk.homelinux.net>"); 499MODULE_AUTHOR("Manuel Lauss");
diff --git a/sound/soc/au1x/psc-ac97.c b/sound/soc/au1x/psc-ac97.c
index a521aa90ddee..340311d7fed5 100644
--- a/sound/soc/au1x/psc-ac97.c
+++ b/sound/soc/au1x/psc-ac97.c
@@ -61,7 +61,8 @@ static unsigned short au1xpsc_ac97_read(struct snd_ac97 *ac97,
61{ 61{
62 /* FIXME */ 62 /* FIXME */
63 struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata; 63 struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata;
64 unsigned short data, retry, tmo; 64 unsigned short retry, tmo;
65 unsigned long data;
65 66
66 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata)); 67 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
67 au_sync(); 68 au_sync();
@@ -74,20 +75,26 @@ static unsigned short au1xpsc_ac97_read(struct snd_ac97 *ac97,
74 AC97_CDC(pscdata)); 75 AC97_CDC(pscdata));
75 au_sync(); 76 au_sync();
76 77
77 tmo = 2000; 78 tmo = 20;
78 while ((!(au_readl(AC97_EVNT(pscdata)) & PSC_AC97EVNT_CD)) 79 do {
79 && --tmo) 80 udelay(21);
80 udelay(2); 81 if (au_readl(AC97_EVNT(pscdata)) & PSC_AC97EVNT_CD)
82 break;
83 } while (--tmo);
81 84
82 data = au_readl(AC97_CDC(pscdata)) & 0xffff; 85 data = au_readl(AC97_CDC(pscdata));
83 86
84 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata)); 87 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
85 au_sync(); 88 au_sync();
86 89
87 mutex_unlock(&pscdata->lock); 90 mutex_unlock(&pscdata->lock);
91
92 if (reg != ((data >> 16) & 0x7f))
93 tmo = 1; /* wrong register, try again */
94
88 } while (--retry && !tmo); 95 } while (--retry && !tmo);
89 96
90 return retry ? data : 0xffff; 97 return retry ? data & 0xffff : 0xffff;
91} 98}
92 99
93/* AC97 controller writes to codec register */ 100/* AC97 controller writes to codec register */
@@ -109,10 +116,12 @@ static void au1xpsc_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
109 AC97_CDC(pscdata)); 116 AC97_CDC(pscdata));
110 au_sync(); 117 au_sync();
111 118
112 tmo = 2000; 119 tmo = 20;
113 while ((!(au_readl(AC97_EVNT(pscdata)) & PSC_AC97EVNT_CD)) 120 do {
114 && --tmo) 121 udelay(21);
115 udelay(2); 122 if (au_readl(AC97_EVNT(pscdata)) & PSC_AC97EVNT_CD)
123 break;
124 } while (--tmo);
116 125
117 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata)); 126 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
118 au_sync(); 127 au_sync();
@@ -195,7 +204,7 @@ static int au1xpsc_ac97_hw_params(struct snd_pcm_substream *substream,
195 /* FIXME */ 204 /* FIXME */
196 struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata; 205 struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata;
197 unsigned long r, ro, stat; 206 unsigned long r, ro, stat;
198 int chans, stype = SUBSTREAM_TYPE(substream); 207 int chans, t, stype = SUBSTREAM_TYPE(substream);
199 208
200 chans = params_channels(params); 209 chans = params_channels(params);
201 210
@@ -237,8 +246,12 @@ static int au1xpsc_ac97_hw_params(struct snd_pcm_substream *substream,
237 au_sync(); 246 au_sync();
238 247
239 /* ...wait for it... */ 248 /* ...wait for it... */
240 while (au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_DR) 249 t = 100;
241 asm volatile ("nop"); 250 while ((au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_DR) && --t)
251 msleep(1);
252
253 if (!t)
254 printk(KERN_ERR "PSC-AC97: can't disable!\n");
242 255
243 /* ...write config... */ 256 /* ...write config... */
244 au_writel(r, AC97_CFG(pscdata)); 257 au_writel(r, AC97_CFG(pscdata));
@@ -249,8 +262,12 @@ static int au1xpsc_ac97_hw_params(struct snd_pcm_substream *substream,
249 au_sync(); 262 au_sync();
250 263
251 /* ...and wait for ready bit */ 264 /* ...and wait for ready bit */
252 while (!(au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_DR)) 265 t = 100;
253 asm volatile ("nop"); 266 while ((!(au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_DR)) && --t)
267 msleep(1);
268
269 if (!t)
270 printk(KERN_ERR "PSC-AC97: can't enable!\n");
254 271
255 mutex_unlock(&pscdata->lock); 272 mutex_unlock(&pscdata->lock);
256 273
@@ -300,19 +317,55 @@ static int au1xpsc_ac97_trigger(struct snd_pcm_substream *substream,
300static int au1xpsc_ac97_probe(struct platform_device *pdev, 317static int au1xpsc_ac97_probe(struct platform_device *pdev,
301 struct snd_soc_dai *dai) 318 struct snd_soc_dai *dai)
302{ 319{
320 return au1xpsc_ac97_workdata ? 0 : -ENODEV;
321}
322
323static void au1xpsc_ac97_remove(struct platform_device *pdev,
324 struct snd_soc_dai *dai)
325{
326}
327
328static struct snd_soc_dai_ops au1xpsc_ac97_dai_ops = {
329 .trigger = au1xpsc_ac97_trigger,
330 .hw_params = au1xpsc_ac97_hw_params,
331};
332
333struct snd_soc_dai au1xpsc_ac97_dai = {
334 .name = "au1xpsc_ac97",
335 .ac97_control = 1,
336 .probe = au1xpsc_ac97_probe,
337 .remove = au1xpsc_ac97_remove,
338 .playback = {
339 .rates = AC97_RATES,
340 .formats = AC97_FMTS,
341 .channels_min = 2,
342 .channels_max = 2,
343 },
344 .capture = {
345 .rates = AC97_RATES,
346 .formats = AC97_FMTS,
347 .channels_min = 2,
348 .channels_max = 2,
349 },
350 .ops = &au1xpsc_ac97_dai_ops,
351};
352EXPORT_SYMBOL_GPL(au1xpsc_ac97_dai);
353
354static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev)
355{
303 int ret; 356 int ret;
304 struct resource *r; 357 struct resource *r;
305 unsigned long sel; 358 unsigned long sel;
359 struct au1xpsc_audio_data *wd;
306 360
307 if (au1xpsc_ac97_workdata) 361 if (au1xpsc_ac97_workdata)
308 return -EBUSY; 362 return -EBUSY;
309 363
310 au1xpsc_ac97_workdata = 364 wd = kzalloc(sizeof(struct au1xpsc_audio_data), GFP_KERNEL);
311 kzalloc(sizeof(struct au1xpsc_audio_data), GFP_KERNEL); 365 if (!wd)
312 if (!au1xpsc_ac97_workdata)
313 return -ENOMEM; 366 return -ENOMEM;
314 367
315 mutex_init(&au1xpsc_ac97_workdata->lock); 368 mutex_init(&wd->lock);
316 369
317 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 370 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
318 if (!r) { 371 if (!r) {
@@ -321,81 +374,95 @@ static int au1xpsc_ac97_probe(struct platform_device *pdev,
321 } 374 }
322 375
323 ret = -EBUSY; 376 ret = -EBUSY;
324 au1xpsc_ac97_workdata->ioarea = 377 wd->ioarea = request_mem_region(r->start, r->end - r->start + 1,
325 request_mem_region(r->start, r->end - r->start + 1,
326 "au1xpsc_ac97"); 378 "au1xpsc_ac97");
327 if (!au1xpsc_ac97_workdata->ioarea) 379 if (!wd->ioarea)
328 goto out0; 380 goto out0;
329 381
330 au1xpsc_ac97_workdata->mmio = ioremap(r->start, 0xffff); 382 wd->mmio = ioremap(r->start, 0xffff);
331 if (!au1xpsc_ac97_workdata->mmio) 383 if (!wd->mmio)
332 goto out1; 384 goto out1;
333 385
334 /* configuration: max dma trigger threshold, enable ac97 */ 386 /* configuration: max dma trigger threshold, enable ac97 */
335 au1xpsc_ac97_workdata->cfg = PSC_AC97CFG_RT_FIFO8 | 387 wd->cfg = PSC_AC97CFG_RT_FIFO8 | PSC_AC97CFG_TT_FIFO8 |
336 PSC_AC97CFG_TT_FIFO8 | 388 PSC_AC97CFG_DE_ENABLE;
337 PSC_AC97CFG_DE_ENABLE;
338 389
339 /* preserve PSC clock source set up by platform (dev.platform_data 390 /* preserve PSC clock source set up by platform */
340 * is already occupied by soc layer) 391 sel = au_readl(PSC_SEL(wd)) & PSC_SEL_CLK_MASK;
341 */ 392 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
342 sel = au_readl(PSC_SEL(au1xpsc_ac97_workdata)) & PSC_SEL_CLK_MASK;
343 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata));
344 au_sync(); 393 au_sync();
345 au_writel(0, PSC_SEL(au1xpsc_ac97_workdata)); 394 au_writel(0, PSC_SEL(wd));
346 au_sync(); 395 au_sync();
347 au_writel(PSC_SEL_PS_AC97MODE | sel, PSC_SEL(au1xpsc_ac97_workdata)); 396 au_writel(PSC_SEL_PS_AC97MODE | sel, PSC_SEL(wd));
348 au_sync(); 397 au_sync();
349 /* next up: cold reset. Dont check for PSC-ready now since
350 * there may not be any codec clock yet.
351 */
352 398
353 return 0; 399 ret = snd_soc_register_dai(&au1xpsc_ac97_dai);
400 if (ret)
401 goto out1;
354 402
403 wd->dmapd = au1xpsc_pcm_add(pdev);
404 if (wd->dmapd) {
405 platform_set_drvdata(pdev, wd);
406 au1xpsc_ac97_workdata = wd; /* MDEV */
407 return 0;
408 }
409
410 snd_soc_unregister_dai(&au1xpsc_ac97_dai);
355out1: 411out1:
356 release_resource(au1xpsc_ac97_workdata->ioarea); 412 release_resource(wd->ioarea);
357 kfree(au1xpsc_ac97_workdata->ioarea); 413 kfree(wd->ioarea);
358out0: 414out0:
359 kfree(au1xpsc_ac97_workdata); 415 kfree(wd);
360 au1xpsc_ac97_workdata = NULL;
361 return ret; 416 return ret;
362} 417}
363 418
364static void au1xpsc_ac97_remove(struct platform_device *pdev, 419static int __devexit au1xpsc_ac97_drvremove(struct platform_device *pdev)
365 struct snd_soc_dai *dai)
366{ 420{
421 struct au1xpsc_audio_data *wd = platform_get_drvdata(pdev);
422
423 if (wd->dmapd)
424 au1xpsc_pcm_destroy(wd->dmapd);
425
426 snd_soc_unregister_dai(&au1xpsc_ac97_dai);
427
367 /* disable PSC completely */ 428 /* disable PSC completely */
368 au_writel(0, AC97_CFG(au1xpsc_ac97_workdata)); 429 au_writel(0, AC97_CFG(wd));
369 au_sync(); 430 au_sync();
370 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata)); 431 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
371 au_sync(); 432 au_sync();
372 433
373 iounmap(au1xpsc_ac97_workdata->mmio); 434 iounmap(wd->mmio);
374 release_resource(au1xpsc_ac97_workdata->ioarea); 435 release_resource(wd->ioarea);
375 kfree(au1xpsc_ac97_workdata->ioarea); 436 kfree(wd->ioarea);
376 kfree(au1xpsc_ac97_workdata); 437 kfree(wd);
377 au1xpsc_ac97_workdata = NULL; 438
439 au1xpsc_ac97_workdata = NULL; /* MDEV */
440
441 return 0;
378} 442}
379 443
380static int au1xpsc_ac97_suspend(struct snd_soc_dai *dai) 444#ifdef CONFIG_PM
445static int au1xpsc_ac97_drvsuspend(struct device *dev)
381{ 446{
447 struct au1xpsc_audio_data *wd = dev_get_drvdata(dev);
448
382 /* save interesting registers and disable PSC */ 449 /* save interesting registers and disable PSC */
383 au1xpsc_ac97_workdata->pm[0] = 450 wd->pm[0] = au_readl(PSC_SEL(wd));
384 au_readl(PSC_SEL(au1xpsc_ac97_workdata));
385 451
386 au_writel(0, AC97_CFG(au1xpsc_ac97_workdata)); 452 au_writel(0, AC97_CFG(wd));
387 au_sync(); 453 au_sync();
388 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata)); 454 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
389 au_sync(); 455 au_sync();
390 456
391 return 0; 457 return 0;
392} 458}
393 459
394static int au1xpsc_ac97_resume(struct snd_soc_dai *dai) 460static int au1xpsc_ac97_drvresume(struct device *dev)
395{ 461{
462 struct au1xpsc_audio_data *wd = dev_get_drvdata(dev);
463
396 /* restore PSC clock config */ 464 /* restore PSC clock config */
397 au_writel(au1xpsc_ac97_workdata->pm[0] | PSC_SEL_PS_AC97MODE, 465 au_writel(wd->pm[0] | PSC_SEL_PS_AC97MODE, PSC_SEL(wd));
398 PSC_SEL(au1xpsc_ac97_workdata));
399 au_sync(); 466 au_sync();
400 467
401 /* after this point the ac97 core will cold-reset the codec. 468 /* after this point the ac97 core will cold-reset the codec.
@@ -405,48 +472,44 @@ static int au1xpsc_ac97_resume(struct snd_soc_dai *dai)
405 return 0; 472 return 0;
406} 473}
407 474
408static struct snd_soc_dai_ops au1xpsc_ac97_dai_ops = { 475static struct dev_pm_ops au1xpscac97_pmops = {
409 .trigger = au1xpsc_ac97_trigger, 476 .suspend = au1xpsc_ac97_drvsuspend,
410 .hw_params = au1xpsc_ac97_hw_params, 477 .resume = au1xpsc_ac97_drvresume,
411}; 478};
412 479
413struct snd_soc_dai au1xpsc_ac97_dai = { 480#define AU1XPSCAC97_PMOPS &au1xpscac97_pmops
414 .name = "au1xpsc_ac97", 481
415 .ac97_control = 1, 482#else
416 .probe = au1xpsc_ac97_probe, 483
417 .remove = au1xpsc_ac97_remove, 484#define AU1XPSCAC97_PMOPS NULL
418 .suspend = au1xpsc_ac97_suspend, 485
419 .resume = au1xpsc_ac97_resume, 486#endif
420 .playback = { 487
421 .rates = AC97_RATES, 488static struct platform_driver au1xpsc_ac97_driver = {
422 .formats = AC97_FMTS, 489 .driver = {
423 .channels_min = 2, 490 .name = "au1xpsc_ac97",
424 .channels_max = 2, 491 .owner = THIS_MODULE,
425 }, 492 .pm = AU1XPSCAC97_PMOPS,
426 .capture = {
427 .rates = AC97_RATES,
428 .formats = AC97_FMTS,
429 .channels_min = 2,
430 .channels_max = 2,
431 }, 493 },
432 .ops = &au1xpsc_ac97_dai_ops, 494 .probe = au1xpsc_ac97_drvprobe,
495 .remove = __devexit_p(au1xpsc_ac97_drvremove),
433}; 496};
434EXPORT_SYMBOL_GPL(au1xpsc_ac97_dai);
435 497
436static int __init au1xpsc_ac97_init(void) 498static int __init au1xpsc_ac97_load(void)
437{ 499{
438 au1xpsc_ac97_workdata = NULL; 500 au1xpsc_ac97_workdata = NULL;
439 return snd_soc_register_dai(&au1xpsc_ac97_dai); 501 return platform_driver_register(&au1xpsc_ac97_driver);
440} 502}
441 503
442static void __exit au1xpsc_ac97_exit(void) 504static void __exit au1xpsc_ac97_unload(void)
443{ 505{
444 snd_soc_unregister_dai(&au1xpsc_ac97_dai); 506 platform_driver_unregister(&au1xpsc_ac97_driver);
445} 507}
446 508
447module_init(au1xpsc_ac97_init); 509module_init(au1xpsc_ac97_load);
448module_exit(au1xpsc_ac97_exit); 510module_exit(au1xpsc_ac97_unload);
449 511
450MODULE_LICENSE("GPL"); 512MODULE_LICENSE("GPL");
451MODULE_DESCRIPTION("Au12x0/Au1550 PSC AC97 ALSA ASoC audio driver"); 513MODULE_DESCRIPTION("Au12x0/Au1550 PSC AC97 ALSA ASoC audio driver");
452MODULE_AUTHOR("Manuel Lauss <manuel.lauss@gmail.com>"); 514MODULE_AUTHOR("Manuel Lauss");
515
diff --git a/sound/soc/au1x/psc-i2s.c b/sound/soc/au1x/psc-i2s.c
index bb589327ee32..0cf2ca61c776 100644
--- a/sound/soc/au1x/psc-i2s.c
+++ b/sound/soc/au1x/psc-i2s.c
@@ -2,7 +2,7 @@
2 * Au12x0/Au1550 PSC ALSA ASoC audio support. 2 * Au12x0/Au1550 PSC ALSA ASoC audio support.
3 * 3 *
4 * (c) 2007-2008 MSC Vertriebsges.m.b.H., 4 * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
5 * Manuel Lauss <mano@roarinelk.homelinux.net> 5 * Manuel Lauss <manuel.lauss@gmail.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License version 2 as
@@ -265,16 +265,52 @@ static int au1xpsc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
265static int au1xpsc_i2s_probe(struct platform_device *pdev, 265static int au1xpsc_i2s_probe(struct platform_device *pdev,
266 struct snd_soc_dai *dai) 266 struct snd_soc_dai *dai)
267{ 267{
268 return au1xpsc_i2s_workdata ? 0 : -ENODEV;
269}
270
271static void au1xpsc_i2s_remove(struct platform_device *pdev,
272 struct snd_soc_dai *dai)
273{
274}
275
276static struct snd_soc_dai_ops au1xpsc_i2s_dai_ops = {
277 .trigger = au1xpsc_i2s_trigger,
278 .hw_params = au1xpsc_i2s_hw_params,
279 .set_fmt = au1xpsc_i2s_set_fmt,
280};
281
282struct snd_soc_dai au1xpsc_i2s_dai = {
283 .name = "au1xpsc_i2s",
284 .probe = au1xpsc_i2s_probe,
285 .remove = au1xpsc_i2s_remove,
286 .playback = {
287 .rates = AU1XPSC_I2S_RATES,
288 .formats = AU1XPSC_I2S_FMTS,
289 .channels_min = 2,
290 .channels_max = 8, /* 2 without external help */
291 },
292 .capture = {
293 .rates = AU1XPSC_I2S_RATES,
294 .formats = AU1XPSC_I2S_FMTS,
295 .channels_min = 2,
296 .channels_max = 8, /* 2 without external help */
297 },
298 .ops = &au1xpsc_i2s_dai_ops,
299};
300EXPORT_SYMBOL(au1xpsc_i2s_dai);
301
302static int __init au1xpsc_i2s_drvprobe(struct platform_device *pdev)
303{
268 struct resource *r; 304 struct resource *r;
269 unsigned long sel; 305 unsigned long sel;
270 int ret; 306 int ret;
307 struct au1xpsc_audio_data *wd;
271 308
272 if (au1xpsc_i2s_workdata) 309 if (au1xpsc_i2s_workdata)
273 return -EBUSY; 310 return -EBUSY;
274 311
275 au1xpsc_i2s_workdata = 312 wd = kzalloc(sizeof(struct au1xpsc_audio_data), GFP_KERNEL);
276 kzalloc(sizeof(struct au1xpsc_audio_data), GFP_KERNEL); 313 if (!wd)
277 if (!au1xpsc_i2s_workdata)
278 return -ENOMEM; 314 return -ENOMEM;
279 315
280 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 316 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -284,131 +320,146 @@ static int au1xpsc_i2s_probe(struct platform_device *pdev,
284 } 320 }
285 321
286 ret = -EBUSY; 322 ret = -EBUSY;
287 au1xpsc_i2s_workdata->ioarea = 323 wd->ioarea = request_mem_region(r->start, r->end - r->start + 1,
288 request_mem_region(r->start, r->end - r->start + 1,
289 "au1xpsc_i2s"); 324 "au1xpsc_i2s");
290 if (!au1xpsc_i2s_workdata->ioarea) 325 if (!wd->ioarea)
291 goto out0; 326 goto out0;
292 327
293 au1xpsc_i2s_workdata->mmio = ioremap(r->start, 0xffff); 328 wd->mmio = ioremap(r->start, 0xffff);
294 if (!au1xpsc_i2s_workdata->mmio) 329 if (!wd->mmio)
295 goto out1; 330 goto out1;
296 331
297 /* preserve PSC clock source set up by platform (dev.platform_data 332 /* preserve PSC clock source set up by platform (dev.platform_data
298 * is already occupied by soc layer) 333 * is already occupied by soc layer)
299 */ 334 */
300 sel = au_readl(PSC_SEL(au1xpsc_i2s_workdata)) & PSC_SEL_CLK_MASK; 335 sel = au_readl(PSC_SEL(wd)) & PSC_SEL_CLK_MASK;
301 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_i2s_workdata)); 336 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
302 au_sync(); 337 au_sync();
303 au_writel(PSC_SEL_PS_I2SMODE | sel, PSC_SEL(au1xpsc_i2s_workdata)); 338 au_writel(PSC_SEL_PS_I2SMODE | sel, PSC_SEL(wd));
304 au_writel(0, I2S_CFG(au1xpsc_i2s_workdata)); 339 au_writel(0, I2S_CFG(wd));
305 au_sync(); 340 au_sync();
306 341
307 /* preconfigure: set max rx/tx fifo depths */ 342 /* preconfigure: set max rx/tx fifo depths */
308 au1xpsc_i2s_workdata->cfg |= 343 wd->cfg |= PSC_I2SCFG_RT_FIFO8 | PSC_I2SCFG_TT_FIFO8;
309 PSC_I2SCFG_RT_FIFO8 | PSC_I2SCFG_TT_FIFO8;
310 344
311 /* don't wait for I2S core to become ready now; clocks may not 345 /* don't wait for I2S core to become ready now; clocks may not
312 * be running yet; depending on clock input for PSC a wait might 346 * be running yet; depending on clock input for PSC a wait might
313 * time out. 347 * time out.
314 */ 348 */
315 349
316 return 0; 350 ret = snd_soc_register_dai(&au1xpsc_i2s_dai);
351 if (ret)
352 goto out1;
317 353
354 /* finally add the DMA device for this PSC */
355 wd->dmapd = au1xpsc_pcm_add(pdev);
356 if (wd->dmapd) {
357 platform_set_drvdata(pdev, wd);
358 au1xpsc_i2s_workdata = wd;
359 return 0;
360 }
361
362 snd_soc_unregister_dai(&au1xpsc_i2s_dai);
318out1: 363out1:
319 release_resource(au1xpsc_i2s_workdata->ioarea); 364 release_resource(wd->ioarea);
320 kfree(au1xpsc_i2s_workdata->ioarea); 365 kfree(wd->ioarea);
321out0: 366out0:
322 kfree(au1xpsc_i2s_workdata); 367 kfree(wd);
323 au1xpsc_i2s_workdata = NULL;
324 return ret; 368 return ret;
325} 369}
326 370
327static void au1xpsc_i2s_remove(struct platform_device *pdev, 371static int __devexit au1xpsc_i2s_drvremove(struct platform_device *pdev)
328 struct snd_soc_dai *dai)
329{ 372{
330 au_writel(0, I2S_CFG(au1xpsc_i2s_workdata)); 373 struct au1xpsc_audio_data *wd = platform_get_drvdata(pdev);
374
375 if (wd->dmapd)
376 au1xpsc_pcm_destroy(wd->dmapd);
377
378 snd_soc_unregister_dai(&au1xpsc_i2s_dai);
379
380 au_writel(0, I2S_CFG(wd));
331 au_sync(); 381 au_sync();
332 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_i2s_workdata)); 382 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
333 au_sync(); 383 au_sync();
334 384
335 iounmap(au1xpsc_i2s_workdata->mmio); 385 iounmap(wd->mmio);
336 release_resource(au1xpsc_i2s_workdata->ioarea); 386 release_resource(wd->ioarea);
337 kfree(au1xpsc_i2s_workdata->ioarea); 387 kfree(wd->ioarea);
338 kfree(au1xpsc_i2s_workdata); 388 kfree(wd);
339 au1xpsc_i2s_workdata = NULL; 389
390 au1xpsc_i2s_workdata = NULL; /* MDEV */
391
392 return 0;
340} 393}
341 394
342static int au1xpsc_i2s_suspend(struct snd_soc_dai *cpu_dai) 395#ifdef CONFIG_PM
396static int au1xpsc_i2s_drvsuspend(struct device *dev)
343{ 397{
398 struct au1xpsc_audio_data *wd = dev_get_drvdata(dev);
399
344 /* save interesting register and disable PSC */ 400 /* save interesting register and disable PSC */
345 au1xpsc_i2s_workdata->pm[0] = 401 wd->pm[0] = au_readl(PSC_SEL(wd));
346 au_readl(PSC_SEL(au1xpsc_i2s_workdata));
347 402
348 au_writel(0, I2S_CFG(au1xpsc_i2s_workdata)); 403 au_writel(0, I2S_CFG(wd));
349 au_sync(); 404 au_sync();
350 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_i2s_workdata)); 405 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
351 au_sync(); 406 au_sync();
352 407
353 return 0; 408 return 0;
354} 409}
355 410
356static int au1xpsc_i2s_resume(struct snd_soc_dai *cpu_dai) 411static int au1xpsc_i2s_drvresume(struct device *dev)
357{ 412{
413 struct au1xpsc_audio_data *wd = dev_get_drvdata(dev);
414
358 /* select I2S mode and PSC clock */ 415 /* select I2S mode and PSC clock */
359 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_i2s_workdata)); 416 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
360 au_sync(); 417 au_sync();
361 au_writel(0, PSC_SEL(au1xpsc_i2s_workdata)); 418 au_writel(0, PSC_SEL(wd));
362 au_sync(); 419 au_sync();
363 au_writel(au1xpsc_i2s_workdata->pm[0], 420 au_writel(wd->pm[0], PSC_SEL(wd));
364 PSC_SEL(au1xpsc_i2s_workdata));
365 au_sync(); 421 au_sync();
366 422
367 return 0; 423 return 0;
368} 424}
369 425
370static struct snd_soc_dai_ops au1xpsc_i2s_dai_ops = { 426static struct dev_pm_ops au1xpsci2s_pmops = {
371 .trigger = au1xpsc_i2s_trigger, 427 .suspend = au1xpsc_i2s_drvsuspend,
372 .hw_params = au1xpsc_i2s_hw_params, 428 .resume = au1xpsc_i2s_drvresume,
373 .set_fmt = au1xpsc_i2s_set_fmt,
374}; 429};
375 430
376struct snd_soc_dai au1xpsc_i2s_dai = { 431#define AU1XPSCI2S_PMOPS &au1xpsci2s_pmops
377 .name = "au1xpsc_i2s", 432
378 .probe = au1xpsc_i2s_probe, 433#else
379 .remove = au1xpsc_i2s_remove, 434
380 .suspend = au1xpsc_i2s_suspend, 435#define AU1XPSCI2S_PMOPS NULL
381 .resume = au1xpsc_i2s_resume, 436
382 .playback = { 437#endif
383 .rates = AU1XPSC_I2S_RATES, 438
384 .formats = AU1XPSC_I2S_FMTS, 439static struct platform_driver au1xpsc_i2s_driver = {
385 .channels_min = 2, 440 .driver = {
386 .channels_max = 8, /* 2 without external help */ 441 .name = "au1xpsc_i2s",
387 }, 442 .owner = THIS_MODULE,
388 .capture = { 443 .pm = AU1XPSCI2S_PMOPS,
389 .rates = AU1XPSC_I2S_RATES,
390 .formats = AU1XPSC_I2S_FMTS,
391 .channels_min = 2,
392 .channels_max = 8, /* 2 without external help */
393 }, 444 },
394 .ops = &au1xpsc_i2s_dai_ops, 445 .probe = au1xpsc_i2s_drvprobe,
446 .remove = __devexit_p(au1xpsc_i2s_drvremove),
395}; 447};
396EXPORT_SYMBOL(au1xpsc_i2s_dai);
397 448
398static int __init au1xpsc_i2s_init(void) 449static int __init au1xpsc_i2s_load(void)
399{ 450{
400 au1xpsc_i2s_workdata = NULL; 451 au1xpsc_i2s_workdata = NULL;
401 return snd_soc_register_dai(&au1xpsc_i2s_dai); 452 return platform_driver_register(&au1xpsc_i2s_driver);
402} 453}
403 454
404static void __exit au1xpsc_i2s_exit(void) 455static void __exit au1xpsc_i2s_unload(void)
405{ 456{
406 snd_soc_unregister_dai(&au1xpsc_i2s_dai); 457 platform_driver_unregister(&au1xpsc_i2s_driver);
407} 458}
408 459
409module_init(au1xpsc_i2s_init); 460module_init(au1xpsc_i2s_load);
410module_exit(au1xpsc_i2s_exit); 461module_exit(au1xpsc_i2s_unload);
411 462
412MODULE_LICENSE("GPL"); 463MODULE_LICENSE("GPL");
413MODULE_DESCRIPTION("Au12x0/Au1550 PSC I2S ALSA ASoC audio driver"); 464MODULE_DESCRIPTION("Au12x0/Au1550 PSC I2S ALSA ASoC audio driver");
414MODULE_AUTHOR("Manuel Lauss <mano@roarinelk.homelinux.net>"); 465MODULE_AUTHOR("Manuel Lauss");
diff --git a/sound/soc/au1x/psc.h b/sound/soc/au1x/psc.h
index 3f474e8ed4f6..32d3807d3f5a 100644
--- a/sound/soc/au1x/psc.h
+++ b/sound/soc/au1x/psc.h
@@ -2,7 +2,7 @@
2 * Au12x0/Au1550 PSC ALSA ASoC audio support. 2 * Au12x0/Au1550 PSC ALSA ASoC audio support.
3 * 3 *
4 * (c) 2007-2008 MSC Vertriebsges.m.b.H., 4 * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
5 * Manuel Lauss <mano@roarinelk.homelinux.net> 5 * Manuel Lauss <manuel.lauss@gmail.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License version 2 as
@@ -21,6 +21,10 @@ extern struct snd_soc_dai au1xpsc_i2s_dai;
21extern struct snd_soc_platform au1xpsc_soc_platform; 21extern struct snd_soc_platform au1xpsc_soc_platform;
22extern struct snd_ac97_bus_ops soc_ac97_ops; 22extern struct snd_ac97_bus_ops soc_ac97_ops;
23 23
24/* DBDMA helpers */
25extern struct platform_device *au1xpsc_pcm_add(struct platform_device *pdev);
26extern void au1xpsc_pcm_destroy(struct platform_device *dmapd);
27
24struct au1xpsc_audio_data { 28struct au1xpsc_audio_data {
25 void __iomem *mmio; 29 void __iomem *mmio;
26 30
@@ -30,6 +34,7 @@ struct au1xpsc_audio_data {
30 unsigned long pm[2]; 34 unsigned long pm[2];
31 struct resource *ioarea; 35 struct resource *ioarea;
32 struct mutex lock; 36 struct mutex lock;
37 struct platform_device *dmapd;
33}; 38};
34 39
35#define PCM_TX 0 40#define PCM_TX 0
diff --git a/sound/soc/blackfin/bf5xx-ad1836.c b/sound/soc/blackfin/bf5xx-ad1836.c
index cd361e304b0f..0f45a3f56be8 100644
--- a/sound/soc/blackfin/bf5xx-ad1836.c
+++ b/sound/soc/blackfin/bf5xx-ad1836.c
@@ -52,6 +52,7 @@ static int bf5xx_ad1836_hw_params(struct snd_pcm_substream *substream,
52 struct snd_soc_pcm_runtime *rtd = substream->private_data; 52 struct snd_soc_pcm_runtime *rtd = substream->private_data;
53 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; 53 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
54 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 54 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
55 unsigned int channel_map[] = {0, 4, 1, 5, 2, 6, 3, 7};
55 int ret = 0; 56 int ret = 0;
56 /* set cpu DAI configuration */ 57 /* set cpu DAI configuration */
57 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A | 58 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
@@ -65,6 +66,12 @@ static int bf5xx_ad1836_hw_params(struct snd_pcm_substream *substream,
65 if (ret < 0) 66 if (ret < 0)
66 return ret; 67 return ret;
67 68
69 /* set cpu DAI channel mapping */
70 ret = snd_soc_dai_set_channel_map(cpu_dai, ARRAY_SIZE(channel_map),
71 channel_map, ARRAY_SIZE(channel_map), channel_map);
72 if (ret < 0)
73 return ret;
74
68 return 0; 75 return 0;
69} 76}
70 77
diff --git a/sound/soc/blackfin/bf5xx-ad1938.c b/sound/soc/blackfin/bf5xx-ad1938.c
index 08269e91810c..2ef1e5013b8c 100644
--- a/sound/soc/blackfin/bf5xx-ad1938.c
+++ b/sound/soc/blackfin/bf5xx-ad1938.c
@@ -61,6 +61,7 @@ static int bf5xx_ad1938_hw_params(struct snd_pcm_substream *substream,
61 struct snd_soc_pcm_runtime *rtd = substream->private_data; 61 struct snd_soc_pcm_runtime *rtd = substream->private_data;
62 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; 62 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
63 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 63 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
64 unsigned int channel_map[] = {0, 1, 2, 3, 4, 5, 6, 7};
64 int ret = 0; 65 int ret = 0;
65 /* set cpu DAI configuration */ 66 /* set cpu DAI configuration */
66 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A | 67 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
@@ -75,7 +76,13 @@ static int bf5xx_ad1938_hw_params(struct snd_pcm_substream *substream,
75 return ret; 76 return ret;
76 77
77 /* set codec DAI slots, 8 channels, all channels are enabled */ 78 /* set codec DAI slots, 8 channels, all channels are enabled */
78 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xFF, 8); 79 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xFF, 0xFF, 8, 32);
80 if (ret < 0)
81 return ret;
82
83 /* set cpu DAI channel mapping */
84 ret = snd_soc_dai_set_channel_map(cpu_dai, ARRAY_SIZE(channel_map),
85 channel_map, ARRAY_SIZE(channel_map), channel_map);
79 if (ret < 0) 86 if (ret < 0)
80 return ret; 87 return ret;
81 88
diff --git a/sound/soc/blackfin/bf5xx-i2s.c b/sound/soc/blackfin/bf5xx-i2s.c
index 084b68884ada..3e6ada0dd1c4 100644
--- a/sound/soc/blackfin/bf5xx-i2s.c
+++ b/sound/soc/blackfin/bf5xx-i2s.c
@@ -49,7 +49,6 @@ struct bf5xx_i2s_port {
49 u16 rcr1; 49 u16 rcr1;
50 u16 tcr2; 50 u16 tcr2;
51 u16 rcr2; 51 u16 rcr2;
52 int counter;
53 int configured; 52 int configured;
54}; 53};
55 54
@@ -133,16 +132,6 @@ static int bf5xx_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
133 return ret; 132 return ret;
134} 133}
135 134
136static int bf5xx_i2s_startup(struct snd_pcm_substream *substream,
137 struct snd_soc_dai *dai)
138{
139 pr_debug("%s enter\n", __func__);
140
141 /*this counter is used for counting how many pcm streams are opened*/
142 bf5xx_i2s.counter++;
143 return 0;
144}
145
146static int bf5xx_i2s_hw_params(struct snd_pcm_substream *substream, 135static int bf5xx_i2s_hw_params(struct snd_pcm_substream *substream,
147 struct snd_pcm_hw_params *params, 136 struct snd_pcm_hw_params *params,
148 struct snd_soc_dai *dai) 137 struct snd_soc_dai *dai)
@@ -201,9 +190,8 @@ static void bf5xx_i2s_shutdown(struct snd_pcm_substream *substream,
201 struct snd_soc_dai *dai) 190 struct snd_soc_dai *dai)
202{ 191{
203 pr_debug("%s enter\n", __func__); 192 pr_debug("%s enter\n", __func__);
204 bf5xx_i2s.counter--;
205 /* No active stream, SPORT is allowed to be configured again. */ 193 /* No active stream, SPORT is allowed to be configured again. */
206 if (!bf5xx_i2s.counter) 194 if (!dai->active)
207 bf5xx_i2s.configured = 0; 195 bf5xx_i2s.configured = 0;
208} 196}
209 197
@@ -284,7 +272,6 @@ static int bf5xx_i2s_resume(struct snd_soc_dai *dai)
284 SNDRV_PCM_FMTBIT_S32_LE) 272 SNDRV_PCM_FMTBIT_S32_LE)
285 273
286static struct snd_soc_dai_ops bf5xx_i2s_dai_ops = { 274static struct snd_soc_dai_ops bf5xx_i2s_dai_ops = {
287 .startup = bf5xx_i2s_startup,
288 .shutdown = bf5xx_i2s_shutdown, 275 .shutdown = bf5xx_i2s_shutdown,
289 .hw_params = bf5xx_i2s_hw_params, 276 .hw_params = bf5xx_i2s_hw_params,
290 .set_fmt = bf5xx_i2s_set_dai_fmt, 277 .set_fmt = bf5xx_i2s_set_dai_fmt,
diff --git a/sound/soc/blackfin/bf5xx-tdm-pcm.c b/sound/soc/blackfin/bf5xx-tdm-pcm.c
index ccb5e823bd18..a8c73cbbd685 100644
--- a/sound/soc/blackfin/bf5xx-tdm-pcm.c
+++ b/sound/soc/blackfin/bf5xx-tdm-pcm.c
@@ -43,7 +43,7 @@
43#include "bf5xx-tdm.h" 43#include "bf5xx-tdm.h"
44#include "bf5xx-sport.h" 44#include "bf5xx-sport.h"
45 45
46#define PCM_BUFFER_MAX 0x10000 46#define PCM_BUFFER_MAX 0x8000
47#define FRAGMENT_SIZE_MIN (4*1024) 47#define FRAGMENT_SIZE_MIN (4*1024)
48#define FRAGMENTS_MIN 2 48#define FRAGMENTS_MIN 2
49#define FRAGMENTS_MAX 32 49#define FRAGMENTS_MAX 32
@@ -177,6 +177,9 @@ out:
177static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel, 177static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel,
178 snd_pcm_uframes_t pos, void *buf, snd_pcm_uframes_t count) 178 snd_pcm_uframes_t pos, void *buf, snd_pcm_uframes_t count)
179{ 179{
180 struct snd_pcm_runtime *runtime = substream->runtime;
181 struct sport_device *sport = runtime->private_data;
182 struct bf5xx_tdm_port *tdm_port = sport->private_data;
180 unsigned int *src; 183 unsigned int *src;
181 unsigned int *dst; 184 unsigned int *dst;
182 int i; 185 int i;
@@ -188,7 +191,7 @@ static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel,
188 dst += pos * 8; 191 dst += pos * 8;
189 while (count--) { 192 while (count--) {
190 for (i = 0; i < substream->runtime->channels; i++) 193 for (i = 0; i < substream->runtime->channels; i++)
191 *(dst + i) = *src++; 194 *(dst + tdm_port->tx_map[i]) = *src++;
192 dst += 8; 195 dst += 8;
193 } 196 }
194 } else { 197 } else {
@@ -198,7 +201,7 @@ static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel,
198 src += pos * 8; 201 src += pos * 8;
199 while (count--) { 202 while (count--) {
200 for (i = 0; i < substream->runtime->channels; i++) 203 for (i = 0; i < substream->runtime->channels; i++)
201 *dst++ = *(src+i); 204 *dst++ = *(src + tdm_port->rx_map[i]);
202 src += 8; 205 src += 8;
203 } 206 }
204 } 207 }
diff --git a/sound/soc/blackfin/bf5xx-tdm.c b/sound/soc/blackfin/bf5xx-tdm.c
index ff546e91a22e..4b360124083e 100644
--- a/sound/soc/blackfin/bf5xx-tdm.c
+++ b/sound/soc/blackfin/bf5xx-tdm.c
@@ -46,14 +46,6 @@
46#include "bf5xx-sport.h" 46#include "bf5xx-sport.h"
47#include "bf5xx-tdm.h" 47#include "bf5xx-tdm.h"
48 48
49struct bf5xx_tdm_port {
50 u16 tcr1;
51 u16 rcr1;
52 u16 tcr2;
53 u16 rcr2;
54 int configured;
55};
56
57static struct bf5xx_tdm_port bf5xx_tdm; 49static struct bf5xx_tdm_port bf5xx_tdm;
58static int sport_num = CONFIG_SND_BF5XX_SPORT_NUM; 50static int sport_num = CONFIG_SND_BF5XX_SPORT_NUM;
59 51
@@ -181,6 +173,40 @@ static void bf5xx_tdm_shutdown(struct snd_pcm_substream *substream,
181 bf5xx_tdm.configured = 0; 173 bf5xx_tdm.configured = 0;
182} 174}
183 175
176static int bf5xx_tdm_set_channel_map(struct snd_soc_dai *dai,
177 unsigned int tx_num, unsigned int *tx_slot,
178 unsigned int rx_num, unsigned int *rx_slot)
179{
180 int i;
181 unsigned int slot;
182 unsigned int tx_mapped = 0, rx_mapped = 0;
183
184 if ((tx_num > BFIN_TDM_DAI_MAX_SLOTS) ||
185 (rx_num > BFIN_TDM_DAI_MAX_SLOTS))
186 return -EINVAL;
187
188 for (i = 0; i < tx_num; i++) {
189 slot = tx_slot[i];
190 if ((slot < BFIN_TDM_DAI_MAX_SLOTS) &&
191 (!(tx_mapped & (1 << slot)))) {
192 bf5xx_tdm.tx_map[i] = slot;
193 tx_mapped |= 1 << slot;
194 } else
195 return -EINVAL;
196 }
197 for (i = 0; i < rx_num; i++) {
198 slot = rx_slot[i];
199 if ((slot < BFIN_TDM_DAI_MAX_SLOTS) &&
200 (!(rx_mapped & (1 << slot)))) {
201 bf5xx_tdm.rx_map[i] = slot;
202 rx_mapped |= 1 << slot;
203 } else
204 return -EINVAL;
205 }
206
207 return 0;
208}
209
184#ifdef CONFIG_PM 210#ifdef CONFIG_PM
185static int bf5xx_tdm_suspend(struct snd_soc_dai *dai) 211static int bf5xx_tdm_suspend(struct snd_soc_dai *dai)
186{ 212{
@@ -235,6 +261,7 @@ static struct snd_soc_dai_ops bf5xx_tdm_dai_ops = {
235 .hw_params = bf5xx_tdm_hw_params, 261 .hw_params = bf5xx_tdm_hw_params,
236 .set_fmt = bf5xx_tdm_set_dai_fmt, 262 .set_fmt = bf5xx_tdm_set_dai_fmt,
237 .shutdown = bf5xx_tdm_shutdown, 263 .shutdown = bf5xx_tdm_shutdown,
264 .set_channel_map = bf5xx_tdm_set_channel_map,
238}; 265};
239 266
240struct snd_soc_dai bf5xx_tdm_dai = { 267struct snd_soc_dai bf5xx_tdm_dai = {
@@ -300,6 +327,8 @@ static int __devinit bfin_tdm_probe(struct platform_device *pdev)
300 pr_err("Failed to register DAI: %d\n", ret); 327 pr_err("Failed to register DAI: %d\n", ret);
301 goto sport_config_err; 328 goto sport_config_err;
302 } 329 }
330
331 sport_handle->private_data = &bf5xx_tdm;
303 return 0; 332 return 0;
304 333
305sport_config_err: 334sport_config_err:
diff --git a/sound/soc/blackfin/bf5xx-tdm.h b/sound/soc/blackfin/bf5xx-tdm.h
index 618ec3d90cd4..04189a18c1ba 100644
--- a/sound/soc/blackfin/bf5xx-tdm.h
+++ b/sound/soc/blackfin/bf5xx-tdm.h
@@ -9,6 +9,17 @@
9#ifndef _BF5XX_TDM_H 9#ifndef _BF5XX_TDM_H
10#define _BF5XX_TDM_H 10#define _BF5XX_TDM_H
11 11
12#define BFIN_TDM_DAI_MAX_SLOTS 8
13struct bf5xx_tdm_port {
14 u16 tcr1;
15 u16 rcr1;
16 u16 tcr2;
17 u16 rcr2;
18 unsigned int tx_map[BFIN_TDM_DAI_MAX_SLOTS];
19 unsigned int rx_map[BFIN_TDM_DAI_MAX_SLOTS];
20 int configured;
21};
22
12extern struct snd_soc_dai bf5xx_tdm_dai; 23extern struct snd_soc_dai bf5xx_tdm_dai;
13 24
14#endif 25#endif
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 0edca93af3b0..52b005f8fed4 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -15,10 +15,12 @@ config SND_SOC_ALL_CODECS
15 select SND_SOC_AD1836 if SPI_MASTER 15 select SND_SOC_AD1836 if SPI_MASTER
16 select SND_SOC_AD1938 if SPI_MASTER 16 select SND_SOC_AD1938 if SPI_MASTER
17 select SND_SOC_AD1980 if SND_SOC_AC97_BUS 17 select SND_SOC_AD1980 if SND_SOC_AC97_BUS
18 select SND_SOC_ADS117X
18 select SND_SOC_AD73311 if I2C 19 select SND_SOC_AD73311 if I2C
19 select SND_SOC_AK4104 if SPI_MASTER 20 select SND_SOC_AK4104 if SPI_MASTER
20 select SND_SOC_AK4535 if I2C 21 select SND_SOC_AK4535 if I2C
21 select SND_SOC_AK4642 if I2C 22 select SND_SOC_AK4642 if I2C
23 select SND_SOC_AK4671 if I2C
22 select SND_SOC_CS4270 if I2C 24 select SND_SOC_CS4270 if I2C
23 select SND_SOC_MAX9877 if I2C 25 select SND_SOC_MAX9877 if I2C
24 select SND_SOC_PCM3008 26 select SND_SOC_PCM3008
@@ -28,6 +30,8 @@ config SND_SOC_ALL_CODECS
28 select SND_SOC_TLV320AIC23 if I2C 30 select SND_SOC_TLV320AIC23 if I2C
29 select SND_SOC_TLV320AIC26 if SPI_MASTER 31 select SND_SOC_TLV320AIC26 if SPI_MASTER
30 select SND_SOC_TLV320AIC3X if I2C 32 select SND_SOC_TLV320AIC3X if I2C
33 select SND_SOC_TPA6130A2 if I2C
34 select SND_SOC_TLV320DAC33 if I2C
31 select SND_SOC_TWL4030 if TWL4030_CORE 35 select SND_SOC_TWL4030 if TWL4030_CORE
32 select SND_SOC_UDA134X 36 select SND_SOC_UDA134X
33 select SND_SOC_UDA1380 if I2C 37 select SND_SOC_UDA1380 if I2C
@@ -36,6 +40,8 @@ config SND_SOC_ALL_CODECS
36 select SND_SOC_WM8510 if SND_SOC_I2C_AND_SPI 40 select SND_SOC_WM8510 if SND_SOC_I2C_AND_SPI
37 select SND_SOC_WM8523 if I2C 41 select SND_SOC_WM8523 if I2C
38 select SND_SOC_WM8580 if I2C 42 select SND_SOC_WM8580 if I2C
43 select SND_SOC_WM8711 if SND_SOC_I2C_AND_SPI
44 select SND_SOC_WM8727
39 select SND_SOC_WM8728 if SND_SOC_I2C_AND_SPI 45 select SND_SOC_WM8728 if SND_SOC_I2C_AND_SPI
40 select SND_SOC_WM8731 if SND_SOC_I2C_AND_SPI 46 select SND_SOC_WM8731 if SND_SOC_I2C_AND_SPI
41 select SND_SOC_WM8750 if SND_SOC_I2C_AND_SPI 47 select SND_SOC_WM8750 if SND_SOC_I2C_AND_SPI
@@ -86,6 +92,9 @@ config SND_SOC_AD1980
86 92
87config SND_SOC_AD73311 93config SND_SOC_AD73311
88 tristate 94 tristate
95
96config SND_SOC_ADS117X
97 tristate
89 98
90config SND_SOC_AK4104 99config SND_SOC_AK4104
91 tristate 100 tristate
@@ -96,6 +105,9 @@ config SND_SOC_AK4535
96config SND_SOC_AK4642 105config SND_SOC_AK4642
97 tristate 106 tristate
98 107
108config SND_SOC_AK4671
109 tristate
110
99# Cirrus Logic CS4270 Codec 111# Cirrus Logic CS4270 Codec
100config SND_SOC_CS4270 112config SND_SOC_CS4270
101 tristate 113 tristate
@@ -136,7 +148,11 @@ config SND_SOC_TLV320AIC26
136config SND_SOC_TLV320AIC3X 148config SND_SOC_TLV320AIC3X
137 tristate 149 tristate
138 150
151config SND_SOC_TLV320DAC33
152 tristate
153
139config SND_SOC_TWL4030 154config SND_SOC_TWL4030
155 select TWL4030_CODEC
140 tristate 156 tristate
141 157
142config SND_SOC_UDA134X 158config SND_SOC_UDA134X
@@ -160,6 +176,12 @@ config SND_SOC_WM8523
160config SND_SOC_WM8580 176config SND_SOC_WM8580
161 tristate 177 tristate
162 178
179config SND_SOC_WM8711
180 tristate
181
182config SND_SOC_WM8727
183 tristate
184
163config SND_SOC_WM8728 185config SND_SOC_WM8728
164 tristate 186 tristate
165 187
@@ -220,3 +242,6 @@ config SND_SOC_WM9713
220# Amp 242# Amp
221config SND_SOC_MAX9877 243config SND_SOC_MAX9877
222 tristate 244 tristate
245
246config SND_SOC_TPA6130A2
247 tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index fb4af28486ba..dbaecb133ac7 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -3,9 +3,11 @@ snd-soc-ad1836-objs := ad1836.o
3snd-soc-ad1938-objs := ad1938.o 3snd-soc-ad1938-objs := ad1938.o
4snd-soc-ad1980-objs := ad1980.o 4snd-soc-ad1980-objs := ad1980.o
5snd-soc-ad73311-objs := ad73311.o 5snd-soc-ad73311-objs := ad73311.o
6snd-soc-ads117x-objs := ads117x.o
6snd-soc-ak4104-objs := ak4104.o 7snd-soc-ak4104-objs := ak4104.o
7snd-soc-ak4535-objs := ak4535.o 8snd-soc-ak4535-objs := ak4535.o
8snd-soc-ak4642-objs := ak4642.o 9snd-soc-ak4642-objs := ak4642.o
10snd-soc-ak4671-objs := ak4671.o
9snd-soc-cs4270-objs := cs4270.o 11snd-soc-cs4270-objs := cs4270.o
10snd-soc-cx20442-objs := cx20442.o 12snd-soc-cx20442-objs := cx20442.o
11snd-soc-l3-objs := l3.o 13snd-soc-l3-objs := l3.o
@@ -16,6 +18,7 @@ snd-soc-stac9766-objs := stac9766.o
16snd-soc-tlv320aic23-objs := tlv320aic23.o 18snd-soc-tlv320aic23-objs := tlv320aic23.o
17snd-soc-tlv320aic26-objs := tlv320aic26.o 19snd-soc-tlv320aic26-objs := tlv320aic26.o
18snd-soc-tlv320aic3x-objs := tlv320aic3x.o 20snd-soc-tlv320aic3x-objs := tlv320aic3x.o
21snd-soc-tlv320dac33-objs := tlv320dac33.o
19snd-soc-twl4030-objs := twl4030.o 22snd-soc-twl4030-objs := twl4030.o
20snd-soc-uda134x-objs := uda134x.o 23snd-soc-uda134x-objs := uda134x.o
21snd-soc-uda1380-objs := uda1380.o 24snd-soc-uda1380-objs := uda1380.o
@@ -24,6 +27,8 @@ snd-soc-wm8400-objs := wm8400.o
24snd-soc-wm8510-objs := wm8510.o 27snd-soc-wm8510-objs := wm8510.o
25snd-soc-wm8523-objs := wm8523.o 28snd-soc-wm8523-objs := wm8523.o
26snd-soc-wm8580-objs := wm8580.o 29snd-soc-wm8580-objs := wm8580.o
30snd-soc-wm8711-objs := wm8711.o
31snd-soc-wm8727-objs := wm8727.o
27snd-soc-wm8728-objs := wm8728.o 32snd-soc-wm8728-objs := wm8728.o
28snd-soc-wm8731-objs := wm8731.o 33snd-soc-wm8731-objs := wm8731.o
29snd-soc-wm8750-objs := wm8750.o 34snd-soc-wm8750-objs := wm8750.o
@@ -47,15 +52,18 @@ snd-soc-wm-hubs-objs := wm_hubs.o
47 52
48# Amp 53# Amp
49snd-soc-max9877-objs := max9877.o 54snd-soc-max9877-objs := max9877.o
55snd-soc-tpa6130a2-objs := tpa6130a2.o
50 56
51obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o 57obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o
52obj-$(CONFIG_SND_SOC_AD1836) += snd-soc-ad1836.o 58obj-$(CONFIG_SND_SOC_AD1836) += snd-soc-ad1836.o
53obj-$(CONFIG_SND_SOC_AD1938) += snd-soc-ad1938.o 59obj-$(CONFIG_SND_SOC_AD1938) += snd-soc-ad1938.o
54obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o 60obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o
55obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o 61obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
62obj-$(CONFIG_SND_SOC_ADS117X) += snd-soc-ads117x.o
56obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o 63obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o
57obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o 64obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o
58obj-$(CONFIG_SND_SOC_AK4642) += snd-soc-ak4642.o 65obj-$(CONFIG_SND_SOC_AK4642) += snd-soc-ak4642.o
66obj-$(CONFIG_SND_SOC_AK4671) += snd-soc-ak4671.o
59obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 67obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
60obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o 68obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o
61obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o 69obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
@@ -66,6 +74,7 @@ obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
66obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o 74obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
67obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o 75obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o
68obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o 76obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
77obj-$(CONFIG_SND_SOC_TLV320DAC33) += snd-soc-tlv320dac33.o
69obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o 78obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o
70obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o 79obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o
71obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o 80obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o
@@ -74,6 +83,8 @@ obj-$(CONFIG_SND_SOC_WM8400) += snd-soc-wm8400.o
74obj-$(CONFIG_SND_SOC_WM8510) += snd-soc-wm8510.o 83obj-$(CONFIG_SND_SOC_WM8510) += snd-soc-wm8510.o
75obj-$(CONFIG_SND_SOC_WM8523) += snd-soc-wm8523.o 84obj-$(CONFIG_SND_SOC_WM8523) += snd-soc-wm8523.o
76obj-$(CONFIG_SND_SOC_WM8580) += snd-soc-wm8580.o 85obj-$(CONFIG_SND_SOC_WM8580) += snd-soc-wm8580.o
86obj-$(CONFIG_SND_SOC_WM8711) += snd-soc-wm8711.o
87obj-$(CONFIG_SND_SOC_WM8727) += snd-soc-wm8727.o
77obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o 88obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o
78obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o 89obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o
79obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o 90obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o
@@ -97,3 +108,4 @@ obj-$(CONFIG_SND_SOC_WM_HUBS) += snd-soc-wm-hubs.o
97 108
98# Amp 109# Amp
99obj-$(CONFIG_SND_SOC_MAX9877) += snd-soc-max9877.o 110obj-$(CONFIG_SND_SOC_MAX9877) += snd-soc-max9877.o
111obj-$(CONFIG_SND_SOC_TPA6130A2) += snd-soc-tpa6130a2.o
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index 932299bb5d1e..69bd0acc81c8 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -117,9 +117,6 @@ static int ac97_soc_probe(struct platform_device *pdev)
117 if (ret < 0) 117 if (ret < 0)
118 goto bus_err; 118 goto bus_err;
119 119
120 ret = snd_soc_init_card(socdev);
121 if (ret < 0)
122 goto bus_err;
123 return 0; 120 return 0;
124 121
125bus_err: 122bus_err:
diff --git a/sound/soc/codecs/ad1836.c b/sound/soc/codecs/ad1836.c
index c48485f2c55d..2c18e3d1b71e 100644
--- a/sound/soc/codecs/ad1836.c
+++ b/sound/soc/codecs/ad1836.c
@@ -385,19 +385,7 @@ static int ad1836_probe(struct platform_device *pdev)
385 snd_soc_dapm_new_controls(codec, ad1836_dapm_widgets, 385 snd_soc_dapm_new_controls(codec, ad1836_dapm_widgets,
386 ARRAY_SIZE(ad1836_dapm_widgets)); 386 ARRAY_SIZE(ad1836_dapm_widgets));
387 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 387 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
388 snd_soc_dapm_new_widgets(codec);
389 388
390 ret = snd_soc_init_card(socdev);
391 if (ret < 0) {
392 dev_err(codec->dev, "failed to register card: %d\n", ret);
393 goto card_err;
394 }
395
396 return ret;
397
398card_err:
399 snd_soc_free_pcms(socdev);
400 snd_soc_dapm_free(socdev);
401pcm_err: 389pcm_err:
402 return ret; 390 return ret;
403} 391}
diff --git a/sound/soc/codecs/ad1938.c b/sound/soc/codecs/ad1938.c
index 34b30efc3cb0..5d489186c05b 100644
--- a/sound/soc/codecs/ad1938.c
+++ b/sound/soc/codecs/ad1938.c
@@ -592,21 +592,9 @@ static int ad1938_probe(struct platform_device *pdev)
592 snd_soc_dapm_new_controls(codec, ad1938_dapm_widgets, 592 snd_soc_dapm_new_controls(codec, ad1938_dapm_widgets,
593 ARRAY_SIZE(ad1938_dapm_widgets)); 593 ARRAY_SIZE(ad1938_dapm_widgets));
594 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 594 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
595 snd_soc_dapm_new_widgets(codec);
596 595
597 ad1938_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 596 ad1938_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
598 597
599 ret = snd_soc_init_card(socdev);
600 if (ret < 0) {
601 dev_err(codec->dev, "failed to register card: %d\n", ret);
602 goto card_err;
603 }
604
605 return ret;
606
607card_err:
608 snd_soc_free_pcms(socdev);
609 snd_soc_dapm_free(socdev);
610pcm_err: 598pcm_err:
611 return ret; 599 return ret;
612} 600}
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index d7440a982d22..39c0f7584e65 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -257,11 +257,6 @@ static int ad1980_soc_probe(struct platform_device *pdev)
257 257
258 snd_soc_add_controls(codec, ad1980_snd_ac97_controls, 258 snd_soc_add_controls(codec, ad1980_snd_ac97_controls,
259 ARRAY_SIZE(ad1980_snd_ac97_controls)); 259 ARRAY_SIZE(ad1980_snd_ac97_controls));
260 ret = snd_soc_init_card(socdev);
261 if (ret < 0) {
262 printk(KERN_ERR "ad1980: failed to register card\n");
263 goto reset_err;
264 }
265 260
266 return 0; 261 return 0;
267 262
diff --git a/sound/soc/codecs/ad73311.c b/sound/soc/codecs/ad73311.c
index e61dac5e7b8f..d2fcc601722c 100644
--- a/sound/soc/codecs/ad73311.c
+++ b/sound/soc/codecs/ad73311.c
@@ -64,16 +64,8 @@ static int ad73311_soc_probe(struct platform_device *pdev)
64 goto pcm_err; 64 goto pcm_err;
65 } 65 }
66 66
67 ret = snd_soc_init_card(socdev);
68 if (ret < 0) {
69 printk(KERN_ERR "ad73311: failed to register card\n");
70 goto register_err;
71 }
72
73 return ret; 67 return ret;
74 68
75register_err:
76 snd_soc_free_pcms(socdev);
77pcm_err: 69pcm_err:
78 kfree(socdev->card->codec); 70 kfree(socdev->card->codec);
79 socdev->card->codec = NULL; 71 socdev->card->codec = NULL;
diff --git a/sound/soc/codecs/ads117x.c b/sound/soc/codecs/ads117x.c
new file mode 100644
index 000000000000..cc96411ca3e6
--- /dev/null
+++ b/sound/soc/codecs/ads117x.c
@@ -0,0 +1,123 @@
1/*
2 * ads117x.c -- Driver for ads1174/8 ADC chips
3 *
4 * Copyright 2009 ShotSpotter Inc.
5 * Author: Graeme Gregory <gg@slimlogic.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/device.h>
16#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/initval.h>
19#include <sound/soc.h>
20
21#include "ads117x.h"
22
23#define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000)
24
25#define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
26
27struct snd_soc_dai ads117x_dai = {
28/* ADC */
29 .name = "ADS117X ADC",
30 .id = 1,
31 .capture = {
32 .stream_name = "Capture",
33 .channels_min = 1,
34 .channels_max = 32,
35 .rates = ADS117X_RATES,
36 .formats = ADS117X_FORMATS,},
37};
38EXPORT_SYMBOL_GPL(ads117x_dai);
39
40static int ads117x_probe(struct platform_device *pdev)
41{
42 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
43 struct snd_soc_codec *codec;
44 int ret;
45
46 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
47 if (codec == NULL)
48 return -ENOMEM;
49
50 socdev->card->codec = codec;
51 mutex_init(&codec->mutex);
52 INIT_LIST_HEAD(&codec->dapm_widgets);
53 INIT_LIST_HEAD(&codec->dapm_paths);
54 codec->name = "ADS117X";
55 codec->owner = THIS_MODULE;
56 codec->dai = &ads117x_dai;
57 codec->num_dai = 1;
58
59 /* register pcms */
60 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
61 if (ret < 0) {
62 printk(KERN_ERR "ads117x: failed to create pcms\n");
63 kfree(codec);
64 return ret;
65 }
66
67 return 0;
68}
69
70static int ads117x_remove(struct platform_device *pdev)
71{
72 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
73 struct snd_soc_codec *codec = socdev->card->codec;
74
75 snd_soc_free_pcms(socdev);
76 kfree(codec);
77
78 return 0;
79}
80
81struct snd_soc_codec_device soc_codec_dev_ads117x = {
82 .probe = ads117x_probe,
83 .remove = ads117x_remove,
84};
85EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x);
86
87static __devinit int ads117x_platform_probe(struct platform_device *pdev)
88{
89 ads117x_dai.dev = &pdev->dev;
90 return snd_soc_register_dai(&ads117x_dai);
91}
92
93static int __devexit ads117x_platform_remove(struct platform_device *pdev)
94{
95 snd_soc_unregister_dai(&ads117x_dai);
96 return 0;
97}
98
99static struct platform_driver ads117x_codec_driver = {
100 .driver = {
101 .name = "ads117x",
102 .owner = THIS_MODULE,
103 },
104
105 .probe = ads117x_platform_probe,
106 .remove = __devexit_p(ads117x_platform_remove),
107};
108
109static int __init ads117x_init(void)
110{
111 return platform_driver_register(&ads117x_codec_driver);
112}
113module_init(ads117x_init);
114
115static void __exit ads117x_exit(void)
116{
117 platform_driver_unregister(&ads117x_codec_driver);
118}
119module_exit(ads117x_exit);
120
121MODULE_DESCRIPTION("ASoC ads117x driver");
122MODULE_AUTHOR("Graeme Gregory");
123MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ads117x.h b/sound/soc/codecs/ads117x.h
new file mode 100644
index 000000000000..dbcf50ec9bd1
--- /dev/null
+++ b/sound/soc/codecs/ads117x.h
@@ -0,0 +1,13 @@
1/*
2 * ads117x.h -- Driver for ads1174/8 ADC chips
3 *
4 * Copyright 2009 ShotSpotter Inc.
5 * Author: Graeme Gregory <gg@slimlogic.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12extern struct snd_soc_dai ads117x_dai;
13extern struct snd_soc_codec_device soc_codec_dev_ads117x;
diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c
index 4d47bc4f7428..3a14c6fc4f5e 100644
--- a/sound/soc/codecs/ak4104.c
+++ b/sound/soc/codecs/ak4104.c
@@ -313,14 +313,6 @@ static int ak4104_probe(struct platform_device *pdev)
313 return ret; 313 return ret;
314 } 314 }
315 315
316 /* Register the socdev */
317 ret = snd_soc_init_card(socdev);
318 if (ret < 0) {
319 dev_err(codec->dev, "failed to register card\n");
320 snd_soc_free_pcms(socdev);
321 return ret;
322 }
323
324 return 0; 316 return 0;
325} 317}
326 318
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
index 0abec0d29a96..ff966567e2ba 100644
--- a/sound/soc/codecs/ak4535.c
+++ b/sound/soc/codecs/ak4535.c
@@ -294,7 +294,6 @@ static int ak4535_add_widgets(struct snd_soc_codec *codec)
294 294
295 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 295 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
296 296
297 snd_soc_dapm_new_widgets(codec);
298 return 0; 297 return 0;
299} 298}
300 299
@@ -485,17 +484,9 @@ static int ak4535_init(struct snd_soc_device *socdev)
485 snd_soc_add_controls(codec, ak4535_snd_controls, 484 snd_soc_add_controls(codec, ak4535_snd_controls,
486 ARRAY_SIZE(ak4535_snd_controls)); 485 ARRAY_SIZE(ak4535_snd_controls));
487 ak4535_add_widgets(codec); 486 ak4535_add_widgets(codec);
488 ret = snd_soc_init_card(socdev);
489 if (ret < 0) {
490 printk(KERN_ERR "ak4535: failed to register card\n");
491 goto card_err;
492 }
493 487
494 return ret; 488 return ret;
495 489
496card_err:
497 snd_soc_free_pcms(socdev);
498 snd_soc_dapm_free(socdev);
499pcm_err: 490pcm_err:
500 kfree(codec->reg_cache); 491 kfree(codec->reg_cache);
501 492
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index e057c7b578df..b69861d52161 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -442,18 +442,9 @@ static int ak4642_probe(struct platform_device *pdev)
442 goto pcm_err; 442 goto pcm_err;
443 } 443 }
444 444
445 ret = snd_soc_init_card(socdev);
446 if (ret < 0) {
447 printk(KERN_ERR "ak4642: failed to register card\n");
448 goto card_err;
449 }
450
451 dev_info(&pdev->dev, "AK4642 Audio Codec %s", AK4642_VERSION); 445 dev_info(&pdev->dev, "AK4642 Audio Codec %s", AK4642_VERSION);
452 return ret; 446 return ret;
453 447
454card_err:
455 snd_soc_free_pcms(socdev);
456 snd_soc_dapm_free(socdev);
457pcm_err: 448pcm_err:
458 return ret; 449 return ret;
459 450
diff --git a/sound/soc/codecs/ak4671.c b/sound/soc/codecs/ak4671.c
new file mode 100644
index 000000000000..82fca284d007
--- /dev/null
+++ b/sound/soc/codecs/ak4671.c
@@ -0,0 +1,815 @@
1/*
2 * ak4671.c -- audio driver for AK4671
3 *
4 * Copyright (C) 2009 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/i2c.h>
17#include <linux/delay.h>
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20#include <sound/initval.h>
21#include <sound/tlv.h>
22
23#include "ak4671.h"
24
25static struct snd_soc_codec *ak4671_codec;
26
27/* codec private data */
28struct ak4671_priv {
29 struct snd_soc_codec codec;
30 u8 reg_cache[AK4671_CACHEREGNUM];
31};
32
33/* ak4671 register cache & default register settings */
34static const u8 ak4671_reg[AK4671_CACHEREGNUM] = {
35 0x00, /* AK4671_AD_DA_POWER_MANAGEMENT (0x00) */
36 0xf6, /* AK4671_PLL_MODE_SELECT0 (0x01) */
37 0x00, /* AK4671_PLL_MODE_SELECT1 (0x02) */
38 0x02, /* AK4671_FORMAT_SELECT (0x03) */
39 0x00, /* AK4671_MIC_SIGNAL_SELECT (0x04) */
40 0x55, /* AK4671_MIC_AMP_GAIN (0x05) */
41 0x00, /* AK4671_MIXING_POWER_MANAGEMENT0 (0x06) */
42 0x00, /* AK4671_MIXING_POWER_MANAGEMENT1 (0x07) */
43 0xb5, /* AK4671_OUTPUT_VOLUME_CONTROL (0x08) */
44 0x00, /* AK4671_LOUT1_SIGNAL_SELECT (0x09) */
45 0x00, /* AK4671_ROUT1_SIGNAL_SELECT (0x0a) */
46 0x00, /* AK4671_LOUT2_SIGNAL_SELECT (0x0b) */
47 0x00, /* AK4671_ROUT2_SIGNAL_SELECT (0x0c) */
48 0x00, /* AK4671_LOUT3_SIGNAL_SELECT (0x0d) */
49 0x00, /* AK4671_ROUT3_SIGNAL_SELECT (0x0e) */
50 0x00, /* AK4671_LOUT1_POWER_MANAGERMENT (0x0f) */
51 0x00, /* AK4671_LOUT2_POWER_MANAGERMENT (0x10) */
52 0x80, /* AK4671_LOUT3_POWER_MANAGERMENT (0x11) */
53 0x91, /* AK4671_LCH_INPUT_VOLUME_CONTROL (0x12) */
54 0x91, /* AK4671_RCH_INPUT_VOLUME_CONTROL (0x13) */
55 0xe1, /* AK4671_ALC_REFERENCE_SELECT (0x14) */
56 0x00, /* AK4671_DIGITAL_MIXING_CONTROL (0x15) */
57 0x00, /* AK4671_ALC_TIMER_SELECT (0x16) */
58 0x00, /* AK4671_ALC_MODE_CONTROL (0x17) */
59 0x02, /* AK4671_MODE_CONTROL1 (0x18) */
60 0x01, /* AK4671_MODE_CONTROL2 (0x19) */
61 0x18, /* AK4671_LCH_OUTPUT_VOLUME_CONTROL (0x1a) */
62 0x18, /* AK4671_RCH_OUTPUT_VOLUME_CONTROL (0x1b) */
63 0x00, /* AK4671_SIDETONE_A_CONTROL (0x1c) */
64 0x02, /* AK4671_DIGITAL_FILTER_SELECT (0x1d) */
65 0x00, /* AK4671_FIL3_COEFFICIENT0 (0x1e) */
66 0x00, /* AK4671_FIL3_COEFFICIENT1 (0x1f) */
67 0x00, /* AK4671_FIL3_COEFFICIENT2 (0x20) */
68 0x00, /* AK4671_FIL3_COEFFICIENT3 (0x21) */
69 0x00, /* AK4671_EQ_COEFFICIENT0 (0x22) */
70 0x00, /* AK4671_EQ_COEFFICIENT1 (0x23) */
71 0x00, /* AK4671_EQ_COEFFICIENT2 (0x24) */
72 0x00, /* AK4671_EQ_COEFFICIENT3 (0x25) */
73 0x00, /* AK4671_EQ_COEFFICIENT4 (0x26) */
74 0x00, /* AK4671_EQ_COEFFICIENT5 (0x27) */
75 0xa9, /* AK4671_FIL1_COEFFICIENT0 (0x28) */
76 0x1f, /* AK4671_FIL1_COEFFICIENT1 (0x29) */
77 0xad, /* AK4671_FIL1_COEFFICIENT2 (0x2a) */
78 0x20, /* AK4671_FIL1_COEFFICIENT3 (0x2b) */
79 0x00, /* AK4671_FIL2_COEFFICIENT0 (0x2c) */
80 0x00, /* AK4671_FIL2_COEFFICIENT1 (0x2d) */
81 0x00, /* AK4671_FIL2_COEFFICIENT2 (0x2e) */
82 0x00, /* AK4671_FIL2_COEFFICIENT3 (0x2f) */
83 0x00, /* AK4671_DIGITAL_FILTER_SELECT2 (0x30) */
84 0x00, /* this register not used */
85 0x00, /* AK4671_E1_COEFFICIENT0 (0x32) */
86 0x00, /* AK4671_E1_COEFFICIENT1 (0x33) */
87 0x00, /* AK4671_E1_COEFFICIENT2 (0x34) */
88 0x00, /* AK4671_E1_COEFFICIENT3 (0x35) */
89 0x00, /* AK4671_E1_COEFFICIENT4 (0x36) */
90 0x00, /* AK4671_E1_COEFFICIENT5 (0x37) */
91 0x00, /* AK4671_E2_COEFFICIENT0 (0x38) */
92 0x00, /* AK4671_E2_COEFFICIENT1 (0x39) */
93 0x00, /* AK4671_E2_COEFFICIENT2 (0x3a) */
94 0x00, /* AK4671_E2_COEFFICIENT3 (0x3b) */
95 0x00, /* AK4671_E2_COEFFICIENT4 (0x3c) */
96 0x00, /* AK4671_E2_COEFFICIENT5 (0x3d) */
97 0x00, /* AK4671_E3_COEFFICIENT0 (0x3e) */
98 0x00, /* AK4671_E3_COEFFICIENT1 (0x3f) */
99 0x00, /* AK4671_E3_COEFFICIENT2 (0x40) */
100 0x00, /* AK4671_E3_COEFFICIENT3 (0x41) */
101 0x00, /* AK4671_E3_COEFFICIENT4 (0x42) */
102 0x00, /* AK4671_E3_COEFFICIENT5 (0x43) */
103 0x00, /* AK4671_E4_COEFFICIENT0 (0x44) */
104 0x00, /* AK4671_E4_COEFFICIENT1 (0x45) */
105 0x00, /* AK4671_E4_COEFFICIENT2 (0x46) */
106 0x00, /* AK4671_E4_COEFFICIENT3 (0x47) */
107 0x00, /* AK4671_E4_COEFFICIENT4 (0x48) */
108 0x00, /* AK4671_E4_COEFFICIENT5 (0x49) */
109 0x00, /* AK4671_E5_COEFFICIENT0 (0x4a) */
110 0x00, /* AK4671_E5_COEFFICIENT1 (0x4b) */
111 0x00, /* AK4671_E5_COEFFICIENT2 (0x4c) */
112 0x00, /* AK4671_E5_COEFFICIENT3 (0x4d) */
113 0x00, /* AK4671_E5_COEFFICIENT4 (0x4e) */
114 0x00, /* AK4671_E5_COEFFICIENT5 (0x4f) */
115 0x88, /* AK4671_EQ_CONTROL_250HZ_100HZ (0x50) */
116 0x88, /* AK4671_EQ_CONTROL_3500HZ_1KHZ (0x51) */
117 0x08, /* AK4671_EQ_CONTRO_10KHZ (0x52) */
118 0x00, /* AK4671_PCM_IF_CONTROL0 (0x53) */
119 0x00, /* AK4671_PCM_IF_CONTROL1 (0x54) */
120 0x00, /* AK4671_PCM_IF_CONTROL2 (0x55) */
121 0x18, /* AK4671_DIGITAL_VOLUME_B_CONTROL (0x56) */
122 0x18, /* AK4671_DIGITAL_VOLUME_C_CONTROL (0x57) */
123 0x00, /* AK4671_SIDETONE_VOLUME_CONTROL (0x58) */
124 0x00, /* AK4671_DIGITAL_MIXING_CONTROL2 (0x59) */
125 0x00, /* AK4671_SAR_ADC_CONTROL (0x5a) */
126};
127
128/*
129 * LOUT1/ROUT1 output volume control:
130 * from -24 to 6 dB in 6 dB steps (mute instead of -30 dB)
131 */
132static DECLARE_TLV_DB_SCALE(out1_tlv, -3000, 600, 1);
133
134/*
135 * LOUT2/ROUT2 output volume control:
136 * from -33 to 6 dB in 3 dB steps (mute instead of -33 dB)
137 */
138static DECLARE_TLV_DB_SCALE(out2_tlv, -3300, 300, 1);
139
140/*
141 * LOUT3/ROUT3 output volume control:
142 * from -6 to 3 dB in 3 dB steps
143 */
144static DECLARE_TLV_DB_SCALE(out3_tlv, -600, 300, 0);
145
146/*
147 * Mic amp gain control:
148 * from -15 to 30 dB in 3 dB steps
149 * REVISIT: The actual min value(0x01) is -12 dB and the reg value 0x00 is not
150 * available
151 */
152static DECLARE_TLV_DB_SCALE(mic_amp_tlv, -1500, 300, 0);
153
154static const struct snd_kcontrol_new ak4671_snd_controls[] = {
155 /* Common playback gain controls */
156 SOC_SINGLE_TLV("Line Output1 Playback Volume",
157 AK4671_OUTPUT_VOLUME_CONTROL, 0, 0x6, 0, out1_tlv),
158 SOC_SINGLE_TLV("Headphone Output2 Playback Volume",
159 AK4671_OUTPUT_VOLUME_CONTROL, 4, 0xd, 0, out2_tlv),
160 SOC_SINGLE_TLV("Line Output3 Playback Volume",
161 AK4671_LOUT3_POWER_MANAGERMENT, 6, 0x3, 0, out3_tlv),
162
163 /* Common capture gain controls */
164 SOC_DOUBLE_TLV("Mic Amp Capture Volume",
165 AK4671_MIC_AMP_GAIN, 0, 4, 0xf, 0, mic_amp_tlv),
166};
167
168/* event handlers */
169static int ak4671_out2_event(struct snd_soc_dapm_widget *w,
170 struct snd_kcontrol *kcontrol, int event)
171{
172 struct snd_soc_codec *codec = w->codec;
173 u8 reg;
174
175 switch (event) {
176 case SND_SOC_DAPM_POST_PMU:
177 reg = snd_soc_read(codec, AK4671_LOUT2_POWER_MANAGERMENT);
178 reg |= AK4671_MUTEN;
179 snd_soc_write(codec, AK4671_LOUT2_POWER_MANAGERMENT, reg);
180 break;
181 case SND_SOC_DAPM_PRE_PMD:
182 reg = snd_soc_read(codec, AK4671_LOUT2_POWER_MANAGERMENT);
183 reg &= ~AK4671_MUTEN;
184 snd_soc_write(codec, AK4671_LOUT2_POWER_MANAGERMENT, reg);
185 break;
186 }
187
188 return 0;
189}
190
191/* Output Mixers */
192static const struct snd_kcontrol_new ak4671_lout1_mixer_controls[] = {
193 SOC_DAPM_SINGLE("DACL", AK4671_LOUT1_SIGNAL_SELECT, 0, 1, 0),
194 SOC_DAPM_SINGLE("LINL1", AK4671_LOUT1_SIGNAL_SELECT, 1, 1, 0),
195 SOC_DAPM_SINGLE("LINL2", AK4671_LOUT1_SIGNAL_SELECT, 2, 1, 0),
196 SOC_DAPM_SINGLE("LINL3", AK4671_LOUT1_SIGNAL_SELECT, 3, 1, 0),
197 SOC_DAPM_SINGLE("LINL4", AK4671_LOUT1_SIGNAL_SELECT, 4, 1, 0),
198 SOC_DAPM_SINGLE("LOOPL", AK4671_LOUT1_SIGNAL_SELECT, 5, 1, 0),
199};
200
201static const struct snd_kcontrol_new ak4671_rout1_mixer_controls[] = {
202 SOC_DAPM_SINGLE("DACR", AK4671_ROUT1_SIGNAL_SELECT, 0, 1, 0),
203 SOC_DAPM_SINGLE("RINR1", AK4671_ROUT1_SIGNAL_SELECT, 1, 1, 0),
204 SOC_DAPM_SINGLE("RINR2", AK4671_ROUT1_SIGNAL_SELECT, 2, 1, 0),
205 SOC_DAPM_SINGLE("RINR3", AK4671_ROUT1_SIGNAL_SELECT, 3, 1, 0),
206 SOC_DAPM_SINGLE("RINR4", AK4671_ROUT1_SIGNAL_SELECT, 4, 1, 0),
207 SOC_DAPM_SINGLE("LOOPR", AK4671_ROUT1_SIGNAL_SELECT, 5, 1, 0),
208};
209
210static const struct snd_kcontrol_new ak4671_lout2_mixer_controls[] = {
211 SOC_DAPM_SINGLE("DACHL", AK4671_LOUT2_SIGNAL_SELECT, 0, 1, 0),
212 SOC_DAPM_SINGLE("LINH1", AK4671_LOUT2_SIGNAL_SELECT, 1, 1, 0),
213 SOC_DAPM_SINGLE("LINH2", AK4671_LOUT2_SIGNAL_SELECT, 2, 1, 0),
214 SOC_DAPM_SINGLE("LINH3", AK4671_LOUT2_SIGNAL_SELECT, 3, 1, 0),
215 SOC_DAPM_SINGLE("LINH4", AK4671_LOUT2_SIGNAL_SELECT, 4, 1, 0),
216 SOC_DAPM_SINGLE("LOOPHL", AK4671_LOUT2_SIGNAL_SELECT, 5, 1, 0),
217};
218
219static const struct snd_kcontrol_new ak4671_rout2_mixer_controls[] = {
220 SOC_DAPM_SINGLE("DACHR", AK4671_ROUT2_SIGNAL_SELECT, 0, 1, 0),
221 SOC_DAPM_SINGLE("RINH1", AK4671_ROUT2_SIGNAL_SELECT, 1, 1, 0),
222 SOC_DAPM_SINGLE("RINH2", AK4671_ROUT2_SIGNAL_SELECT, 2, 1, 0),
223 SOC_DAPM_SINGLE("RINH3", AK4671_ROUT2_SIGNAL_SELECT, 3, 1, 0),
224 SOC_DAPM_SINGLE("RINH4", AK4671_ROUT2_SIGNAL_SELECT, 4, 1, 0),
225 SOC_DAPM_SINGLE("LOOPHR", AK4671_ROUT2_SIGNAL_SELECT, 5, 1, 0),
226};
227
228static const struct snd_kcontrol_new ak4671_lout3_mixer_controls[] = {
229 SOC_DAPM_SINGLE("DACSL", AK4671_LOUT3_SIGNAL_SELECT, 0, 1, 0),
230 SOC_DAPM_SINGLE("LINS1", AK4671_LOUT3_SIGNAL_SELECT, 1, 1, 0),
231 SOC_DAPM_SINGLE("LINS2", AK4671_LOUT3_SIGNAL_SELECT, 2, 1, 0),
232 SOC_DAPM_SINGLE("LINS3", AK4671_LOUT3_SIGNAL_SELECT, 3, 1, 0),
233 SOC_DAPM_SINGLE("LINS4", AK4671_LOUT3_SIGNAL_SELECT, 4, 1, 0),
234 SOC_DAPM_SINGLE("LOOPSL", AK4671_LOUT3_SIGNAL_SELECT, 5, 1, 0),
235};
236
237static const struct snd_kcontrol_new ak4671_rout3_mixer_controls[] = {
238 SOC_DAPM_SINGLE("DACSR", AK4671_ROUT3_SIGNAL_SELECT, 0, 1, 0),
239 SOC_DAPM_SINGLE("RINS1", AK4671_ROUT3_SIGNAL_SELECT, 1, 1, 0),
240 SOC_DAPM_SINGLE("RINS2", AK4671_ROUT3_SIGNAL_SELECT, 2, 1, 0),
241 SOC_DAPM_SINGLE("RINS3", AK4671_ROUT3_SIGNAL_SELECT, 3, 1, 0),
242 SOC_DAPM_SINGLE("RINS4", AK4671_ROUT3_SIGNAL_SELECT, 4, 1, 0),
243 SOC_DAPM_SINGLE("LOOPSR", AK4671_ROUT3_SIGNAL_SELECT, 5, 1, 0),
244};
245
246/* Input MUXs */
247static const char *ak4671_lin_mux_texts[] =
248 {"LIN1", "LIN2", "LIN3", "LIN4"};
249static const struct soc_enum ak4671_lin_mux_enum =
250 SOC_ENUM_SINGLE(AK4671_MIC_SIGNAL_SELECT, 0,
251 ARRAY_SIZE(ak4671_lin_mux_texts),
252 ak4671_lin_mux_texts);
253static const struct snd_kcontrol_new ak4671_lin_mux_control =
254 SOC_DAPM_ENUM("Route", ak4671_lin_mux_enum);
255
256static const char *ak4671_rin_mux_texts[] =
257 {"RIN1", "RIN2", "RIN3", "RIN4"};
258static const struct soc_enum ak4671_rin_mux_enum =
259 SOC_ENUM_SINGLE(AK4671_MIC_SIGNAL_SELECT, 2,
260 ARRAY_SIZE(ak4671_rin_mux_texts),
261 ak4671_rin_mux_texts);
262static const struct snd_kcontrol_new ak4671_rin_mux_control =
263 SOC_DAPM_ENUM("Route", ak4671_rin_mux_enum);
264
265static const struct snd_soc_dapm_widget ak4671_dapm_widgets[] = {
266 /* Inputs */
267 SND_SOC_DAPM_INPUT("LIN1"),
268 SND_SOC_DAPM_INPUT("RIN1"),
269 SND_SOC_DAPM_INPUT("LIN2"),
270 SND_SOC_DAPM_INPUT("RIN2"),
271 SND_SOC_DAPM_INPUT("LIN3"),
272 SND_SOC_DAPM_INPUT("RIN3"),
273 SND_SOC_DAPM_INPUT("LIN4"),
274 SND_SOC_DAPM_INPUT("RIN4"),
275
276 /* Outputs */
277 SND_SOC_DAPM_OUTPUT("LOUT1"),
278 SND_SOC_DAPM_OUTPUT("ROUT1"),
279 SND_SOC_DAPM_OUTPUT("LOUT2"),
280 SND_SOC_DAPM_OUTPUT("ROUT2"),
281 SND_SOC_DAPM_OUTPUT("LOUT3"),
282 SND_SOC_DAPM_OUTPUT("ROUT3"),
283
284 /* DAC */
285 SND_SOC_DAPM_DAC("DAC Left", "Left HiFi Playback",
286 AK4671_AD_DA_POWER_MANAGEMENT, 6, 0),
287 SND_SOC_DAPM_DAC("DAC Right", "Right HiFi Playback",
288 AK4671_AD_DA_POWER_MANAGEMENT, 7, 0),
289
290 /* ADC */
291 SND_SOC_DAPM_ADC("ADC Left", "Left HiFi Capture",
292 AK4671_AD_DA_POWER_MANAGEMENT, 4, 0),
293 SND_SOC_DAPM_ADC("ADC Right", "Right HiFi Capture",
294 AK4671_AD_DA_POWER_MANAGEMENT, 5, 0),
295
296 /* PGA */
297 SND_SOC_DAPM_PGA("LOUT2 Mix Amp",
298 AK4671_LOUT2_POWER_MANAGERMENT, 5, 0, NULL, 0),
299 SND_SOC_DAPM_PGA("ROUT2 Mix Amp",
300 AK4671_LOUT2_POWER_MANAGERMENT, 6, 0, NULL, 0),
301
302 SND_SOC_DAPM_PGA("LIN1 Mixing Circuit",
303 AK4671_MIXING_POWER_MANAGEMENT1, 0, 0, NULL, 0),
304 SND_SOC_DAPM_PGA("RIN1 Mixing Circuit",
305 AK4671_MIXING_POWER_MANAGEMENT1, 1, 0, NULL, 0),
306 SND_SOC_DAPM_PGA("LIN2 Mixing Circuit",
307 AK4671_MIXING_POWER_MANAGEMENT1, 2, 0, NULL, 0),
308 SND_SOC_DAPM_PGA("RIN2 Mixing Circuit",
309 AK4671_MIXING_POWER_MANAGEMENT1, 3, 0, NULL, 0),
310 SND_SOC_DAPM_PGA("LIN3 Mixing Circuit",
311 AK4671_MIXING_POWER_MANAGEMENT1, 4, 0, NULL, 0),
312 SND_SOC_DAPM_PGA("RIN3 Mixing Circuit",
313 AK4671_MIXING_POWER_MANAGEMENT1, 5, 0, NULL, 0),
314 SND_SOC_DAPM_PGA("LIN4 Mixing Circuit",
315 AK4671_MIXING_POWER_MANAGEMENT1, 6, 0, NULL, 0),
316 SND_SOC_DAPM_PGA("RIN4 Mixing Circuit",
317 AK4671_MIXING_POWER_MANAGEMENT1, 7, 0, NULL, 0),
318
319 /* Output Mixers */
320 SND_SOC_DAPM_MIXER("LOUT1 Mixer", AK4671_LOUT1_POWER_MANAGERMENT, 0, 0,
321 &ak4671_lout1_mixer_controls[0],
322 ARRAY_SIZE(ak4671_lout1_mixer_controls)),
323 SND_SOC_DAPM_MIXER("ROUT1 Mixer", AK4671_LOUT1_POWER_MANAGERMENT, 1, 0,
324 &ak4671_rout1_mixer_controls[0],
325 ARRAY_SIZE(ak4671_rout1_mixer_controls)),
326 SND_SOC_DAPM_MIXER_E("LOUT2 Mixer", AK4671_LOUT2_POWER_MANAGERMENT,
327 0, 0, &ak4671_lout2_mixer_controls[0],
328 ARRAY_SIZE(ak4671_lout2_mixer_controls),
329 ak4671_out2_event,
330 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_PRE_PMD),
331 SND_SOC_DAPM_MIXER_E("ROUT2 Mixer", AK4671_LOUT2_POWER_MANAGERMENT,
332 1, 0, &ak4671_rout2_mixer_controls[0],
333 ARRAY_SIZE(ak4671_rout2_mixer_controls),
334 ak4671_out2_event,
335 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_PRE_PMD),
336 SND_SOC_DAPM_MIXER("LOUT3 Mixer", AK4671_LOUT3_POWER_MANAGERMENT, 0, 0,
337 &ak4671_lout3_mixer_controls[0],
338 ARRAY_SIZE(ak4671_lout3_mixer_controls)),
339 SND_SOC_DAPM_MIXER("ROUT3 Mixer", AK4671_LOUT3_POWER_MANAGERMENT, 1, 0,
340 &ak4671_rout3_mixer_controls[0],
341 ARRAY_SIZE(ak4671_rout3_mixer_controls)),
342
343 /* Input MUXs */
344 SND_SOC_DAPM_MUX("LIN MUX", AK4671_AD_DA_POWER_MANAGEMENT, 2, 0,
345 &ak4671_lin_mux_control),
346 SND_SOC_DAPM_MUX("RIN MUX", AK4671_AD_DA_POWER_MANAGEMENT, 3, 0,
347 &ak4671_rin_mux_control),
348
349 /* Mic Power */
350 SND_SOC_DAPM_MICBIAS("Mic Bias", AK4671_AD_DA_POWER_MANAGEMENT, 1, 0),
351
352 /* Supply */
353 SND_SOC_DAPM_SUPPLY("PMPLL", AK4671_PLL_MODE_SELECT1, 0, 0, NULL, 0),
354};
355
356static const struct snd_soc_dapm_route intercon[] = {
357 {"DAC Left", "NULL", "PMPLL"},
358 {"DAC Right", "NULL", "PMPLL"},
359 {"ADC Left", "NULL", "PMPLL"},
360 {"ADC Right", "NULL", "PMPLL"},
361
362 /* Outputs */
363 {"LOUT1", "NULL", "LOUT1 Mixer"},
364 {"ROUT1", "NULL", "ROUT1 Mixer"},
365 {"LOUT2", "NULL", "LOUT2 Mix Amp"},
366 {"ROUT2", "NULL", "ROUT2 Mix Amp"},
367 {"LOUT3", "NULL", "LOUT3 Mixer"},
368 {"ROUT3", "NULL", "ROUT3 Mixer"},
369
370 {"LOUT1 Mixer", "DACL", "DAC Left"},
371 {"ROUT1 Mixer", "DACR", "DAC Right"},
372 {"LOUT2 Mixer", "DACHL", "DAC Left"},
373 {"ROUT2 Mixer", "DACHR", "DAC Right"},
374 {"LOUT2 Mix Amp", "NULL", "LOUT2 Mixer"},
375 {"ROUT2 Mix Amp", "NULL", "ROUT2 Mixer"},
376 {"LOUT3 Mixer", "DACSL", "DAC Left"},
377 {"ROUT3 Mixer", "DACSR", "DAC Right"},
378
379 /* Inputs */
380 {"LIN MUX", "LIN1", "LIN1"},
381 {"LIN MUX", "LIN2", "LIN2"},
382 {"LIN MUX", "LIN3", "LIN3"},
383 {"LIN MUX", "LIN4", "LIN4"},
384
385 {"RIN MUX", "RIN1", "RIN1"},
386 {"RIN MUX", "RIN2", "RIN2"},
387 {"RIN MUX", "RIN3", "RIN3"},
388 {"RIN MUX", "RIN4", "RIN4"},
389
390 {"LIN1", NULL, "Mic Bias"},
391 {"RIN1", NULL, "Mic Bias"},
392 {"LIN2", NULL, "Mic Bias"},
393 {"RIN2", NULL, "Mic Bias"},
394
395 {"ADC Left", "NULL", "LIN MUX"},
396 {"ADC Right", "NULL", "RIN MUX"},
397
398 /* Analog Loops */
399 {"LIN1 Mixing Circuit", "NULL", "LIN1"},
400 {"RIN1 Mixing Circuit", "NULL", "RIN1"},
401 {"LIN2 Mixing Circuit", "NULL", "LIN2"},
402 {"RIN2 Mixing Circuit", "NULL", "RIN2"},
403 {"LIN3 Mixing Circuit", "NULL", "LIN3"},
404 {"RIN3 Mixing Circuit", "NULL", "RIN3"},
405 {"LIN4 Mixing Circuit", "NULL", "LIN4"},
406 {"RIN4 Mixing Circuit", "NULL", "RIN4"},
407
408 {"LOUT1 Mixer", "LINL1", "LIN1 Mixing Circuit"},
409 {"ROUT1 Mixer", "RINR1", "RIN1 Mixing Circuit"},
410 {"LOUT2 Mixer", "LINH1", "LIN1 Mixing Circuit"},
411 {"ROUT2 Mixer", "RINH1", "RIN1 Mixing Circuit"},
412 {"LOUT3 Mixer", "LINS1", "LIN1 Mixing Circuit"},
413 {"ROUT3 Mixer", "RINS1", "RIN1 Mixing Circuit"},
414
415 {"LOUT1 Mixer", "LINL2", "LIN2 Mixing Circuit"},
416 {"ROUT1 Mixer", "RINR2", "RIN2 Mixing Circuit"},
417 {"LOUT2 Mixer", "LINH2", "LIN2 Mixing Circuit"},
418 {"ROUT2 Mixer", "RINH2", "RIN2 Mixing Circuit"},
419 {"LOUT3 Mixer", "LINS2", "LIN2 Mixing Circuit"},
420 {"ROUT3 Mixer", "RINS2", "RIN2 Mixing Circuit"},
421
422 {"LOUT1 Mixer", "LINL3", "LIN3 Mixing Circuit"},
423 {"ROUT1 Mixer", "RINR3", "RIN3 Mixing Circuit"},
424 {"LOUT2 Mixer", "LINH3", "LIN3 Mixing Circuit"},
425 {"ROUT2 Mixer", "RINH3", "RIN3 Mixing Circuit"},
426 {"LOUT3 Mixer", "LINS3", "LIN3 Mixing Circuit"},
427 {"ROUT3 Mixer", "RINS3", "RIN3 Mixing Circuit"},
428
429 {"LOUT1 Mixer", "LINL4", "LIN4 Mixing Circuit"},
430 {"ROUT1 Mixer", "RINR4", "RIN4 Mixing Circuit"},
431 {"LOUT2 Mixer", "LINH4", "LIN4 Mixing Circuit"},
432 {"ROUT2 Mixer", "RINH4", "RIN4 Mixing Circuit"},
433 {"LOUT3 Mixer", "LINS4", "LIN4 Mixing Circuit"},
434 {"ROUT3 Mixer", "RINS4", "RIN4 Mixing Circuit"},
435};
436
437static int ak4671_add_widgets(struct snd_soc_codec *codec)
438{
439 snd_soc_dapm_new_controls(codec, ak4671_dapm_widgets,
440 ARRAY_SIZE(ak4671_dapm_widgets));
441
442 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
443
444 return 0;
445}
446
447static int ak4671_hw_params(struct snd_pcm_substream *substream,
448 struct snd_pcm_hw_params *params,
449 struct snd_soc_dai *dai)
450{
451 struct snd_soc_codec *codec = dai->codec;
452 u8 fs;
453
454 fs = snd_soc_read(codec, AK4671_PLL_MODE_SELECT0);
455 fs &= ~AK4671_FS;
456
457 switch (params_rate(params)) {
458 case 8000:
459 fs |= AK4671_FS_8KHZ;
460 break;
461 case 12000:
462 fs |= AK4671_FS_12KHZ;
463 break;
464 case 16000:
465 fs |= AK4671_FS_16KHZ;
466 break;
467 case 24000:
468 fs |= AK4671_FS_24KHZ;
469 break;
470 case 11025:
471 fs |= AK4671_FS_11_025KHZ;
472 break;
473 case 22050:
474 fs |= AK4671_FS_22_05KHZ;
475 break;
476 case 32000:
477 fs |= AK4671_FS_32KHZ;
478 break;
479 case 44100:
480 fs |= AK4671_FS_44_1KHZ;
481 break;
482 case 48000:
483 fs |= AK4671_FS_48KHZ;
484 break;
485 default:
486 return -EINVAL;
487 }
488
489 snd_soc_write(codec, AK4671_PLL_MODE_SELECT0, fs);
490
491 return 0;
492}
493
494static int ak4671_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
495 unsigned int freq, int dir)
496{
497 struct snd_soc_codec *codec = dai->codec;
498 u8 pll;
499
500 pll = snd_soc_read(codec, AK4671_PLL_MODE_SELECT0);
501 pll &= ~AK4671_PLL;
502
503 switch (freq) {
504 case 11289600:
505 pll |= AK4671_PLL_11_2896MHZ;
506 break;
507 case 12000000:
508 pll |= AK4671_PLL_12MHZ;
509 break;
510 case 12288000:
511 pll |= AK4671_PLL_12_288MHZ;
512 break;
513 case 13000000:
514 pll |= AK4671_PLL_13MHZ;
515 break;
516 case 13500000:
517 pll |= AK4671_PLL_13_5MHZ;
518 break;
519 case 19200000:
520 pll |= AK4671_PLL_19_2MHZ;
521 break;
522 case 24000000:
523 pll |= AK4671_PLL_24MHZ;
524 break;
525 case 26000000:
526 pll |= AK4671_PLL_26MHZ;
527 break;
528 case 27000000:
529 pll |= AK4671_PLL_27MHZ;
530 break;
531 default:
532 return -EINVAL;
533 }
534
535 snd_soc_write(codec, AK4671_PLL_MODE_SELECT0, pll);
536
537 return 0;
538}
539
540static int ak4671_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
541{
542 struct snd_soc_codec *codec = dai->codec;
543 u8 mode;
544 u8 format;
545
546 /* set master/slave audio interface */
547 mode = snd_soc_read(codec, AK4671_PLL_MODE_SELECT1);
548
549 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
550 case SND_SOC_DAIFMT_CBM_CFM:
551 mode |= AK4671_M_S;
552 break;
553 case SND_SOC_DAIFMT_CBM_CFS:
554 mode &= ~(AK4671_M_S);
555 break;
556 default:
557 return -EINVAL;
558 }
559
560 /* interface format */
561 format = snd_soc_read(codec, AK4671_FORMAT_SELECT);
562 format &= ~AK4671_DIF;
563
564 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
565 case SND_SOC_DAIFMT_I2S:
566 format |= AK4671_DIF_I2S_MODE;
567 break;
568 case SND_SOC_DAIFMT_LEFT_J:
569 format |= AK4671_DIF_MSB_MODE;
570 break;
571 case SND_SOC_DAIFMT_DSP_A:
572 format |= AK4671_DIF_DSP_MODE;
573 format |= AK4671_BCKP;
574 format |= AK4671_MSBS;
575 break;
576 default:
577 return -EINVAL;
578 }
579
580 /* set mode and format */
581 snd_soc_write(codec, AK4671_PLL_MODE_SELECT1, mode);
582 snd_soc_write(codec, AK4671_FORMAT_SELECT, format);
583
584 return 0;
585}
586
587static int ak4671_set_bias_level(struct snd_soc_codec *codec,
588 enum snd_soc_bias_level level)
589{
590 u8 reg;
591
592 switch (level) {
593 case SND_SOC_BIAS_ON:
594 case SND_SOC_BIAS_PREPARE:
595 case SND_SOC_BIAS_STANDBY:
596 reg = snd_soc_read(codec, AK4671_AD_DA_POWER_MANAGEMENT);
597 snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT,
598 reg | AK4671_PMVCM);
599 break;
600 case SND_SOC_BIAS_OFF:
601 snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, 0x00);
602 break;
603 }
604 codec->bias_level = level;
605 return 0;
606}
607
608#define AK4671_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
609 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
610 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
611 SNDRV_PCM_RATE_48000)
612
613#define AK4671_FORMATS SNDRV_PCM_FMTBIT_S16_LE
614
615static struct snd_soc_dai_ops ak4671_dai_ops = {
616 .hw_params = ak4671_hw_params,
617 .set_sysclk = ak4671_set_dai_sysclk,
618 .set_fmt = ak4671_set_dai_fmt,
619};
620
621struct snd_soc_dai ak4671_dai = {
622 .name = "AK4671",
623 .playback = {
624 .stream_name = "Playback",
625 .channels_min = 1,
626 .channels_max = 2,
627 .rates = AK4671_RATES,
628 .formats = AK4671_FORMATS,},
629 .capture = {
630 .stream_name = "Capture",
631 .channels_min = 1,
632 .channels_max = 2,
633 .rates = AK4671_RATES,
634 .formats = AK4671_FORMATS,},
635 .ops = &ak4671_dai_ops,
636};
637EXPORT_SYMBOL_GPL(ak4671_dai);
638
639static int ak4671_probe(struct platform_device *pdev)
640{
641 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
642 struct snd_soc_codec *codec;
643 int ret = 0;
644
645 if (ak4671_codec == NULL) {
646 dev_err(&pdev->dev, "Codec device not registered\n");
647 return -ENODEV;
648 }
649
650 socdev->card->codec = ak4671_codec;
651 codec = ak4671_codec;
652
653 /* register pcms */
654 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
655 if (ret < 0) {
656 dev_err(codec->dev, "failed to create pcms: %d\n", ret);
657 goto pcm_err;
658 }
659
660 snd_soc_add_controls(codec, ak4671_snd_controls,
661 ARRAY_SIZE(ak4671_snd_controls));
662 ak4671_add_widgets(codec);
663
664 ak4671_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
665
666 return ret;
667
668pcm_err:
669 return ret;
670}
671
672static int ak4671_remove(struct platform_device *pdev)
673{
674 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
675
676 snd_soc_free_pcms(socdev);
677 snd_soc_dapm_free(socdev);
678
679 return 0;
680}
681
682struct snd_soc_codec_device soc_codec_dev_ak4671 = {
683 .probe = ak4671_probe,
684 .remove = ak4671_remove,
685};
686EXPORT_SYMBOL_GPL(soc_codec_dev_ak4671);
687
688static int ak4671_register(struct ak4671_priv *ak4671,
689 enum snd_soc_control_type control)
690{
691 int ret;
692 struct snd_soc_codec *codec = &ak4671->codec;
693
694 if (ak4671_codec) {
695 dev_err(codec->dev, "Another AK4671 is registered\n");
696 ret = -EINVAL;
697 goto err;
698 }
699
700 mutex_init(&codec->mutex);
701 INIT_LIST_HEAD(&codec->dapm_widgets);
702 INIT_LIST_HEAD(&codec->dapm_paths);
703
704 codec->private_data = ak4671;
705 codec->name = "AK4671";
706 codec->owner = THIS_MODULE;
707 codec->bias_level = SND_SOC_BIAS_OFF;
708 codec->set_bias_level = ak4671_set_bias_level;
709 codec->dai = &ak4671_dai;
710 codec->num_dai = 1;
711 codec->reg_cache_size = AK4671_CACHEREGNUM;
712 codec->reg_cache = &ak4671->reg_cache;
713
714 memcpy(codec->reg_cache, ak4671_reg, sizeof(ak4671_reg));
715
716 ret = snd_soc_codec_set_cache_io(codec, 8, 8, control);
717 if (ret < 0) {
718 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
719 goto err;
720 }
721
722 ak4671_dai.dev = codec->dev;
723 ak4671_codec = codec;
724
725 ret = snd_soc_register_codec(codec);
726 if (ret != 0) {
727 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
728 goto err;
729 }
730
731 ret = snd_soc_register_dai(&ak4671_dai);
732 if (ret != 0) {
733 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
734 goto err_codec;
735 }
736
737 return 0;
738
739err_codec:
740 snd_soc_unregister_codec(codec);
741err:
742 kfree(ak4671);
743 return ret;
744}
745
746static void ak4671_unregister(struct ak4671_priv *ak4671)
747{
748 ak4671_set_bias_level(&ak4671->codec, SND_SOC_BIAS_OFF);
749 snd_soc_unregister_dai(&ak4671_dai);
750 snd_soc_unregister_codec(&ak4671->codec);
751 kfree(ak4671);
752 ak4671_codec = NULL;
753}
754
755static int __devinit ak4671_i2c_probe(struct i2c_client *client,
756 const struct i2c_device_id *id)
757{
758 struct ak4671_priv *ak4671;
759 struct snd_soc_codec *codec;
760
761 ak4671 = kzalloc(sizeof(struct ak4671_priv), GFP_KERNEL);
762 if (ak4671 == NULL)
763 return -ENOMEM;
764
765 codec = &ak4671->codec;
766 codec->hw_write = (hw_write_t)i2c_master_send;
767
768 i2c_set_clientdata(client, ak4671);
769 codec->control_data = client;
770
771 codec->dev = &client->dev;
772
773 return ak4671_register(ak4671, SND_SOC_I2C);
774}
775
776static __devexit int ak4671_i2c_remove(struct i2c_client *client)
777{
778 struct ak4671_priv *ak4671 = i2c_get_clientdata(client);
779
780 ak4671_unregister(ak4671);
781
782 return 0;
783}
784
785static const struct i2c_device_id ak4671_i2c_id[] = {
786 { "ak4671", 0 },
787 { }
788};
789MODULE_DEVICE_TABLE(i2c, ak4671_i2c_id);
790
791static struct i2c_driver ak4671_i2c_driver = {
792 .driver = {
793 .name = "ak4671",
794 .owner = THIS_MODULE,
795 },
796 .probe = ak4671_i2c_probe,
797 .remove = __devexit_p(ak4671_i2c_remove),
798 .id_table = ak4671_i2c_id,
799};
800
801static int __init ak4671_modinit(void)
802{
803 return i2c_add_driver(&ak4671_i2c_driver);
804}
805module_init(ak4671_modinit);
806
807static void __exit ak4671_exit(void)
808{
809 i2c_del_driver(&ak4671_i2c_driver);
810}
811module_exit(ak4671_exit);
812
813MODULE_DESCRIPTION("ASoC AK4671 codec driver");
814MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
815MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ak4671.h b/sound/soc/codecs/ak4671.h
new file mode 100644
index 000000000000..e2fad964e88b
--- /dev/null
+++ b/sound/soc/codecs/ak4671.h
@@ -0,0 +1,156 @@
1/*
2 * ak4671.h -- audio driver for AK4671
3 *
4 * Copyright (C) 2009 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#ifndef _AK4671_H
15#define _AK4671_H
16
17#define AK4671_AD_DA_POWER_MANAGEMENT 0x00
18#define AK4671_PLL_MODE_SELECT0 0x01
19#define AK4671_PLL_MODE_SELECT1 0x02
20#define AK4671_FORMAT_SELECT 0x03
21#define AK4671_MIC_SIGNAL_SELECT 0x04
22#define AK4671_MIC_AMP_GAIN 0x05
23#define AK4671_MIXING_POWER_MANAGEMENT0 0x06
24#define AK4671_MIXING_POWER_MANAGEMENT1 0x07
25#define AK4671_OUTPUT_VOLUME_CONTROL 0x08
26#define AK4671_LOUT1_SIGNAL_SELECT 0x09
27#define AK4671_ROUT1_SIGNAL_SELECT 0x0a
28#define AK4671_LOUT2_SIGNAL_SELECT 0x0b
29#define AK4671_ROUT2_SIGNAL_SELECT 0x0c
30#define AK4671_LOUT3_SIGNAL_SELECT 0x0d
31#define AK4671_ROUT3_SIGNAL_SELECT 0x0e
32#define AK4671_LOUT1_POWER_MANAGERMENT 0x0f
33#define AK4671_LOUT2_POWER_MANAGERMENT 0x10
34#define AK4671_LOUT3_POWER_MANAGERMENT 0x11
35#define AK4671_LCH_INPUT_VOLUME_CONTROL 0x12
36#define AK4671_RCH_INPUT_VOLUME_CONTROL 0x13
37#define AK4671_ALC_REFERENCE_SELECT 0x14
38#define AK4671_DIGITAL_MIXING_CONTROL 0x15
39#define AK4671_ALC_TIMER_SELECT 0x16
40#define AK4671_ALC_MODE_CONTROL 0x17
41#define AK4671_MODE_CONTROL1 0x18
42#define AK4671_MODE_CONTROL2 0x19
43#define AK4671_LCH_OUTPUT_VOLUME_CONTROL 0x1a
44#define AK4671_RCH_OUTPUT_VOLUME_CONTROL 0x1b
45#define AK4671_SIDETONE_A_CONTROL 0x1c
46#define AK4671_DIGITAL_FILTER_SELECT 0x1d
47#define AK4671_FIL3_COEFFICIENT0 0x1e
48#define AK4671_FIL3_COEFFICIENT1 0x1f
49#define AK4671_FIL3_COEFFICIENT2 0x20
50#define AK4671_FIL3_COEFFICIENT3 0x21
51#define AK4671_EQ_COEFFICIENT0 0x22
52#define AK4671_EQ_COEFFICIENT1 0x23
53#define AK4671_EQ_COEFFICIENT2 0x24
54#define AK4671_EQ_COEFFICIENT3 0x25
55#define AK4671_EQ_COEFFICIENT4 0x26
56#define AK4671_EQ_COEFFICIENT5 0x27
57#define AK4671_FIL1_COEFFICIENT0 0x28
58#define AK4671_FIL1_COEFFICIENT1 0x29
59#define AK4671_FIL1_COEFFICIENT2 0x2a
60#define AK4671_FIL1_COEFFICIENT3 0x2b
61#define AK4671_FIL2_COEFFICIENT0 0x2c
62#define AK4671_FIL2_COEFFICIENT1 0x2d
63#define AK4671_FIL2_COEFFICIENT2 0x2e
64#define AK4671_FIL2_COEFFICIENT3 0x2f
65#define AK4671_DIGITAL_FILTER_SELECT2 0x30
66#define AK4671_E1_COEFFICIENT0 0x32
67#define AK4671_E1_COEFFICIENT1 0x33
68#define AK4671_E1_COEFFICIENT2 0x34
69#define AK4671_E1_COEFFICIENT3 0x35
70#define AK4671_E1_COEFFICIENT4 0x36
71#define AK4671_E1_COEFFICIENT5 0x37
72#define AK4671_E2_COEFFICIENT0 0x38
73#define AK4671_E2_COEFFICIENT1 0x39
74#define AK4671_E2_COEFFICIENT2 0x3a
75#define AK4671_E2_COEFFICIENT3 0x3b
76#define AK4671_E2_COEFFICIENT4 0x3c
77#define AK4671_E2_COEFFICIENT5 0x3d
78#define AK4671_E3_COEFFICIENT0 0x3e
79#define AK4671_E3_COEFFICIENT1 0x3f
80#define AK4671_E3_COEFFICIENT2 0x40
81#define AK4671_E3_COEFFICIENT3 0x41
82#define AK4671_E3_COEFFICIENT4 0x42
83#define AK4671_E3_COEFFICIENT5 0x43
84#define AK4671_E4_COEFFICIENT0 0x44
85#define AK4671_E4_COEFFICIENT1 0x45
86#define AK4671_E4_COEFFICIENT2 0x46
87#define AK4671_E4_COEFFICIENT3 0x47
88#define AK4671_E4_COEFFICIENT4 0x48
89#define AK4671_E4_COEFFICIENT5 0x49
90#define AK4671_E5_COEFFICIENT0 0x4a
91#define AK4671_E5_COEFFICIENT1 0x4b
92#define AK4671_E5_COEFFICIENT2 0x4c
93#define AK4671_E5_COEFFICIENT3 0x4d
94#define AK4671_E5_COEFFICIENT4 0x4e
95#define AK4671_E5_COEFFICIENT5 0x4f
96#define AK4671_EQ_CONTROL_250HZ_100HZ 0x50
97#define AK4671_EQ_CONTROL_3500HZ_1KHZ 0x51
98#define AK4671_EQ_CONTRO_10KHZ 0x52
99#define AK4671_PCM_IF_CONTROL0 0x53
100#define AK4671_PCM_IF_CONTROL1 0x54
101#define AK4671_PCM_IF_CONTROL2 0x55
102#define AK4671_DIGITAL_VOLUME_B_CONTROL 0x56
103#define AK4671_DIGITAL_VOLUME_C_CONTROL 0x57
104#define AK4671_SIDETONE_VOLUME_CONTROL 0x58
105#define AK4671_DIGITAL_MIXING_CONTROL2 0x59
106#define AK4671_SAR_ADC_CONTROL 0x5a
107
108#define AK4671_CACHEREGNUM (AK4671_SAR_ADC_CONTROL + 1)
109
110/* Bitfield Definitions */
111
112/* AK4671_AD_DA_POWER_MANAGEMENT (0x00) Fields */
113#define AK4671_PMVCM 0x01
114
115/* AK4671_PLL_MODE_SELECT0 (0x01) Fields */
116#define AK4671_PLL 0x0f
117#define AK4671_PLL_11_2896MHZ (4 << 0)
118#define AK4671_PLL_12_288MHZ (5 << 0)
119#define AK4671_PLL_12MHZ (6 << 0)
120#define AK4671_PLL_24MHZ (7 << 0)
121#define AK4671_PLL_19_2MHZ (8 << 0)
122#define AK4671_PLL_13_5MHZ (12 << 0)
123#define AK4671_PLL_27MHZ (13 << 0)
124#define AK4671_PLL_13MHZ (14 << 0)
125#define AK4671_PLL_26MHZ (15 << 0)
126#define AK4671_FS 0xf0
127#define AK4671_FS_8KHZ (0 << 4)
128#define AK4671_FS_12KHZ (1 << 4)
129#define AK4671_FS_16KHZ (2 << 4)
130#define AK4671_FS_24KHZ (3 << 4)
131#define AK4671_FS_11_025KHZ (5 << 4)
132#define AK4671_FS_22_05KHZ (7 << 4)
133#define AK4671_FS_32KHZ (10 << 4)
134#define AK4671_FS_48KHZ (11 << 4)
135#define AK4671_FS_44_1KHZ (15 << 4)
136
137/* AK4671_PLL_MODE_SELECT1 (0x02) Fields */
138#define AK4671_PMPLL 0x01
139#define AK4671_M_S 0x02
140
141/* AK4671_FORMAT_SELECT (0x03) Fields */
142#define AK4671_DIF 0x03
143#define AK4671_DIF_DSP_MODE (0 << 0)
144#define AK4671_DIF_MSB_MODE (2 << 0)
145#define AK4671_DIF_I2S_MODE (3 << 0)
146#define AK4671_BCKP 0x04
147#define AK4671_MSBS 0x08
148#define AK4671_SDOD 0x10
149
150/* AK4671_LOUT2_POWER_MANAGEMENT (0x10) Fields */
151#define AK4671_MUTEN 0x04
152
153extern struct snd_soc_dai ak4671_dai;
154extern struct snd_soc_codec_device soc_codec_dev_ak4671;
155
156#endif
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index ca1e24a8f12a..ffe122d1cd76 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -520,6 +520,7 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = {
520 SOC_SINGLE("Digital Sidetone Switch", CS4270_FORMAT, 5, 1, 0), 520 SOC_SINGLE("Digital Sidetone Switch", CS4270_FORMAT, 5, 1, 0),
521 SOC_SINGLE("Soft Ramp Switch", CS4270_TRANS, 6, 1, 0), 521 SOC_SINGLE("Soft Ramp Switch", CS4270_TRANS, 6, 1, 0),
522 SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0), 522 SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0),
523 SOC_SINGLE("De-emphasis filter", CS4270_TRANS, 0, 1, 0),
523 SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1), 524 SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1),
524 SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0), 525 SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0),
525 SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 1), 526 SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 1),
@@ -598,13 +599,6 @@ static int cs4270_probe(struct platform_device *pdev)
598 goto error_free_pcms; 599 goto error_free_pcms;
599 } 600 }
600 601
601 /* And finally, register the socdev */
602 ret = snd_soc_init_card(socdev);
603 if (ret < 0) {
604 dev_err(codec->dev, "failed to register card\n");
605 goto error_free_pcms;
606 }
607
608 return 0; 602 return 0;
609 603
610error_free_pcms: 604error_free_pcms:
@@ -802,22 +796,6 @@ MODULE_DEVICE_TABLE(i2c, cs4270_id);
802 * and all registers are written back to the hardware when resuming. 796 * and all registers are written back to the hardware when resuming.
803 */ 797 */
804 798
805static int cs4270_i2c_suspend(struct i2c_client *client, pm_message_t mesg)
806{
807 struct cs4270_private *cs4270 = i2c_get_clientdata(client);
808 struct snd_soc_codec *codec = &cs4270->codec;
809
810 return snd_soc_suspend_device(codec->dev);
811}
812
813static int cs4270_i2c_resume(struct i2c_client *client)
814{
815 struct cs4270_private *cs4270 = i2c_get_clientdata(client);
816 struct snd_soc_codec *codec = &cs4270->codec;
817
818 return snd_soc_resume_device(codec->dev);
819}
820
821static int cs4270_soc_suspend(struct platform_device *pdev, pm_message_t mesg) 799static int cs4270_soc_suspend(struct platform_device *pdev, pm_message_t mesg)
822{ 800{
823 struct snd_soc_codec *codec = cs4270_codec; 801 struct snd_soc_codec *codec = cs4270_codec;
@@ -853,8 +831,6 @@ static int cs4270_soc_resume(struct platform_device *pdev)
853 return snd_soc_write(codec, CS4270_PWRCTL, reg); 831 return snd_soc_write(codec, CS4270_PWRCTL, reg);
854} 832}
855#else 833#else
856#define cs4270_i2c_suspend NULL
857#define cs4270_i2c_resume NULL
858#define cs4270_soc_suspend NULL 834#define cs4270_soc_suspend NULL
859#define cs4270_soc_resume NULL 835#define cs4270_soc_resume NULL
860#endif /* CONFIG_PM */ 836#endif /* CONFIG_PM */
@@ -873,8 +849,6 @@ static struct i2c_driver cs4270_i2c_driver = {
873 .id_table = cs4270_id, 849 .id_table = cs4270_id,
874 .probe = cs4270_i2c_probe, 850 .probe = cs4270_i2c_probe,
875 .remove = cs4270_i2c_remove, 851 .remove = cs4270_i2c_remove,
876 .suspend = cs4270_i2c_suspend,
877 .resume = cs4270_i2c_resume,
878}; 852};
879 853
880/* 854/*
diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c
index 38eac9c866e1..e000cdfec1ec 100644
--- a/sound/soc/codecs/cx20442.c
+++ b/sound/soc/codecs/cx20442.c
@@ -93,7 +93,6 @@ static int cx20442_add_widgets(struct snd_soc_codec *codec)
93 snd_soc_dapm_add_routes(codec, cx20442_audio_map, 93 snd_soc_dapm_add_routes(codec, cx20442_audio_map,
94 ARRAY_SIZE(cx20442_audio_map)); 94 ARRAY_SIZE(cx20442_audio_map));
95 95
96 snd_soc_dapm_new_widgets(codec);
97 return 0; 96 return 0;
98} 97}
99 98
@@ -355,17 +354,6 @@ static int cx20442_codec_probe(struct platform_device *pdev)
355 354
356 cx20442_add_widgets(codec); 355 cx20442_add_widgets(codec);
357 356
358 ret = snd_soc_init_card(socdev);
359 if (ret < 0) {
360 dev_err(&pdev->dev, "failed to register card\n");
361 goto card_err;
362 }
363
364 return ret;
365
366card_err:
367 snd_soc_free_pcms(socdev);
368 snd_soc_dapm_free(socdev);
369pcm_err: 357pcm_err:
370 return ret; 358 return ret;
371} 359}
diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c
index 5cda9e6b5a74..2afcd0a8669d 100644
--- a/sound/soc/codecs/pcm3008.c
+++ b/sound/soc/codecs/pcm3008.c
@@ -90,13 +90,6 @@ static int pcm3008_soc_probe(struct platform_device *pdev)
90 goto pcm_err; 90 goto pcm_err;
91 } 91 }
92 92
93 /* Register Card. */
94 ret = snd_soc_init_card(socdev);
95 if (ret < 0) {
96 printk(KERN_ERR "pcm3008: failed to register card\n");
97 goto card_err;
98 }
99
100 /* DEM1 DEM0 DE-EMPHASIS_MODE 93 /* DEM1 DEM0 DE-EMPHASIS_MODE
101 * Low Low De-emphasis 44.1 kHz ON 94 * Low Low De-emphasis 44.1 kHz ON
102 * Low High De-emphasis OFF 95 * Low High De-emphasis OFF
@@ -136,8 +129,6 @@ static int pcm3008_soc_probe(struct platform_device *pdev)
136 129
137gpio_err: 130gpio_err:
138 pcm3008_gpio_free(setup); 131 pcm3008_gpio_free(setup);
139card_err:
140 snd_soc_free_pcms(socdev);
141pcm_err: 132pcm_err:
142 kfree(socdev->card->codec); 133 kfree(socdev->card->codec);
143 134
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
index c550750c79c0..d2ff1cde6883 100644
--- a/sound/soc/codecs/ssm2602.c
+++ b/sound/soc/codecs/ssm2602.c
@@ -210,7 +210,6 @@ static int ssm2602_add_widgets(struct snd_soc_codec *codec)
210 210
211 snd_soc_dapm_add_routes(codec, audio_conn, ARRAY_SIZE(audio_conn)); 211 snd_soc_dapm_add_routes(codec, audio_conn, ARRAY_SIZE(audio_conn));
212 212
213 snd_soc_dapm_new_widgets(codec);
214 return 0; 213 return 0;
215} 214}
216 215
@@ -613,17 +612,9 @@ static int ssm2602_init(struct snd_soc_device *socdev)
613 snd_soc_add_controls(codec, ssm2602_snd_controls, 612 snd_soc_add_controls(codec, ssm2602_snd_controls,
614 ARRAY_SIZE(ssm2602_snd_controls)); 613 ARRAY_SIZE(ssm2602_snd_controls));
615 ssm2602_add_widgets(codec); 614 ssm2602_add_widgets(codec);
616 ret = snd_soc_init_card(socdev);
617 if (ret < 0) {
618 pr_err("ssm2602: failed to register card\n");
619 goto card_err;
620 }
621 615
622 return ret; 616 return ret;
623 617
624card_err:
625 snd_soc_free_pcms(socdev);
626 snd_soc_dapm_free(socdev);
627pcm_err: 618pcm_err:
628 kfree(codec->reg_cache); 619 kfree(codec->reg_cache);
629 return ret; 620 return ret;
diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c
index befc6488c39a..bbc72c2ddfca 100644
--- a/sound/soc/codecs/stac9766.c
+++ b/sound/soc/codecs/stac9766.c
@@ -418,9 +418,6 @@ static int stac9766_codec_probe(struct platform_device *pdev)
418 snd_soc_add_controls(codec, stac9766_snd_ac97_controls, 418 snd_soc_add_controls(codec, stac9766_snd_ac97_controls,
419 ARRAY_SIZE(stac9766_snd_ac97_controls)); 419 ARRAY_SIZE(stac9766_snd_ac97_controls));
420 420
421 ret = snd_soc_init_card(socdev);
422 if (ret < 0)
423 goto reset_err;
424 return 0; 421 return 0;
425 422
426reset_err: 423reset_err:
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index 90a0264f7538..a9dc5fb54774 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -85,7 +85,7 @@ static int tlv320aic23_write(struct snd_soc_codec *codec, unsigned int reg,
85 * of data into val 85 * of data into val
86 */ 86 */
87 87
88 if ((reg < 0 || reg > 9) && (reg != 15)) { 88 if (reg > 9 && reg != 15) {
89 printk(KERN_WARNING "%s Invalid register R%u\n", __func__, reg); 89 printk(KERN_WARNING "%s Invalid register R%u\n", __func__, reg);
90 return -1; 90 return -1;
91 } 91 }
@@ -395,7 +395,6 @@ static int tlv320aic23_add_widgets(struct snd_soc_codec *codec)
395 /* set up audio path interconnects */ 395 /* set up audio path interconnects */
396 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 396 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
397 397
398 snd_soc_dapm_new_widgets(codec);
399 return 0; 398 return 0;
400} 399}
401 400
@@ -706,17 +705,9 @@ static int tlv320aic23_init(struct snd_soc_device *socdev)
706 snd_soc_add_controls(codec, tlv320aic23_snd_controls, 705 snd_soc_add_controls(codec, tlv320aic23_snd_controls,
707 ARRAY_SIZE(tlv320aic23_snd_controls)); 706 ARRAY_SIZE(tlv320aic23_snd_controls));
708 tlv320aic23_add_widgets(codec); 707 tlv320aic23_add_widgets(codec);
709 ret = snd_soc_init_card(socdev);
710 if (ret < 0) {
711 printk(KERN_ERR "tlv320aic23: failed to register card\n");
712 goto card_err;
713 }
714 708
715 return ret; 709 return ret;
716 710
717card_err:
718 snd_soc_free_pcms(socdev);
719 snd_soc_dapm_free(socdev);
720pcm_err: 711pcm_err:
721 kfree(codec->reg_cache); 712 kfree(codec->reg_cache);
722 return ret; 713 return ret;
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index 3387d9e736ea..357b609196e3 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -356,18 +356,7 @@ static int aic26_probe(struct platform_device *pdev)
356 ARRAY_SIZE(aic26_snd_controls)); 356 ARRAY_SIZE(aic26_snd_controls));
357 WARN_ON(err < 0); 357 WARN_ON(err < 0);
358 358
359 /* CODEC is setup, we can register the card now */
360 dev_dbg(&pdev->dev, "Registering card\n");
361 ret = snd_soc_init_card(socdev);
362 if (ret < 0) {
363 dev_err(&pdev->dev, "aic26: failed to register card\n");
364 goto card_err;
365 }
366 return 0; 359 return 0;
367
368 card_err:
369 snd_soc_free_pcms(socdev);
370 return ret;
371} 360}
372 361
373static int aic26_remove(struct platform_device *pdev) 362static int aic26_remove(struct platform_device *pdev)
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 3395cf945d56..2b4dc2b0b017 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -753,7 +753,6 @@ static int aic3x_add_widgets(struct snd_soc_codec *codec)
753 /* set up audio path interconnects */ 753 /* set up audio path interconnects */
754 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 754 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
755 755
756 snd_soc_dapm_new_widgets(codec);
757 return 0; 756 return 0;
758} 757}
759 758
@@ -1405,18 +1404,8 @@ static int aic3x_probe(struct platform_device *pdev)
1405 1404
1406 aic3x_add_widgets(codec); 1405 aic3x_add_widgets(codec);
1407 1406
1408 ret = snd_soc_init_card(socdev);
1409 if (ret < 0) {
1410 printk(KERN_ERR "aic3x: failed to register card\n");
1411 goto card_err;
1412 }
1413
1414 return ret; 1407 return ret;
1415 1408
1416card_err:
1417 snd_soc_free_pcms(socdev);
1418 snd_soc_dapm_free(socdev);
1419
1420pcm_err: 1409pcm_err:
1421 kfree(codec->reg_cache); 1410 kfree(codec->reg_cache);
1422 return ret; 1411 return ret;
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
new file mode 100644
index 000000000000..9c8903dbe647
--- /dev/null
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -0,0 +1,1229 @@
1/*
2 * ALSA SoC Texas Instruments TLV320DAC33 codec driver
3 *
4 * Author: Peter Ujfalusi <peter.ujfalusi@nokia.com>
5 *
6 * Copyright: (C) 2009 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * 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/module.h>
25#include <linux/moduleparam.h>
26#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/pm.h>
29#include <linux/i2c.h>
30#include <linux/platform_device.h>
31#include <linux/interrupt.h>
32#include <linux/gpio.h>
33#include <sound/core.h>
34#include <sound/pcm.h>
35#include <sound/pcm_params.h>
36#include <sound/soc.h>
37#include <sound/soc-dapm.h>
38#include <sound/initval.h>
39#include <sound/tlv.h>
40
41#include <sound/tlv320dac33-plat.h>
42#include "tlv320dac33.h"
43
44#define DAC33_BUFFER_SIZE_BYTES 24576 /* bytes, 12288 16 bit words,
45 * 6144 stereo */
46#define DAC33_BUFFER_SIZE_SAMPLES 6144
47
48#define NSAMPLE_MAX 5700
49
50#define LATENCY_TIME_MS 20
51
52static struct snd_soc_codec *tlv320dac33_codec;
53
54enum dac33_state {
55 DAC33_IDLE = 0,
56 DAC33_PREFILL,
57 DAC33_PLAYBACK,
58 DAC33_FLUSH,
59};
60
61struct tlv320dac33_priv {
62 struct mutex mutex;
63 struct workqueue_struct *dac33_wq;
64 struct work_struct work;
65 struct snd_soc_codec codec;
66 int power_gpio;
67 int chip_power;
68 int irq;
69 unsigned int refclk;
70
71 unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */
72 unsigned int nsample_min; /* nsample should not be lower than
73 * this */
74 unsigned int nsample_max; /* nsample should not be higher than
75 * this */
76 unsigned int nsample_switch; /* Use FIFO or bypass FIFO switch */
77 unsigned int nsample; /* burst read amount from host */
78
79 enum dac33_state state;
80};
81
82static const u8 dac33_reg[DAC33_CACHEREGNUM] = {
830x00, 0x00, 0x00, 0x00, /* 0x00 - 0x03 */
840x00, 0x00, 0x00, 0x00, /* 0x04 - 0x07 */
850x00, 0x00, 0x00, 0x00, /* 0x08 - 0x0b */
860x00, 0x00, 0x00, 0x00, /* 0x0c - 0x0f */
870x00, 0x00, 0x00, 0x00, /* 0x10 - 0x13 */
880x00, 0x00, 0x00, 0x00, /* 0x14 - 0x17 */
890x00, 0x00, 0x00, 0x00, /* 0x18 - 0x1b */
900x00, 0x00, 0x00, 0x00, /* 0x1c - 0x1f */
910x00, 0x00, 0x00, 0x00, /* 0x20 - 0x23 */
920x00, 0x00, 0x00, 0x00, /* 0x24 - 0x27 */
930x00, 0x00, 0x00, 0x00, /* 0x28 - 0x2b */
940x00, 0x00, 0x00, 0x80, /* 0x2c - 0x2f */
950x80, 0x00, 0x00, 0x00, /* 0x30 - 0x33 */
960x00, 0x00, 0x00, 0x00, /* 0x34 - 0x37 */
970x00, 0x00, /* 0x38 - 0x39 */
98/* Registers 0x3a - 0x3f are reserved */
99 0x00, 0x00, /* 0x3a - 0x3b */
1000x00, 0x00, 0x00, 0x00, /* 0x3c - 0x3f */
101
1020x00, 0x00, 0x00, 0x00, /* 0x40 - 0x43 */
1030x00, 0x80, /* 0x44 - 0x45 */
104/* Registers 0x46 - 0x47 are reserved */
105 0x80, 0x80, /* 0x46 - 0x47 */
106
1070x80, 0x00, 0x00, /* 0x48 - 0x4a */
108/* Registers 0x4b - 0x7c are reserved */
109 0x00, /* 0x4b */
1100x00, 0x00, 0x00, 0x00, /* 0x4c - 0x4f */
1110x00, 0x00, 0x00, 0x00, /* 0x50 - 0x53 */
1120x00, 0x00, 0x00, 0x00, /* 0x54 - 0x57 */
1130x00, 0x00, 0x00, 0x00, /* 0x58 - 0x5b */
1140x00, 0x00, 0x00, 0x00, /* 0x5c - 0x5f */
1150x00, 0x00, 0x00, 0x00, /* 0x60 - 0x63 */
1160x00, 0x00, 0x00, 0x00, /* 0x64 - 0x67 */
1170x00, 0x00, 0x00, 0x00, /* 0x68 - 0x6b */
1180x00, 0x00, 0x00, 0x00, /* 0x6c - 0x6f */
1190x00, 0x00, 0x00, 0x00, /* 0x70 - 0x73 */
1200x00, 0x00, 0x00, 0x00, /* 0x74 - 0x77 */
1210x00, 0x00, 0x00, 0x00, /* 0x78 - 0x7b */
1220x00, /* 0x7c */
123
124 0xda, 0x33, 0x03, /* 0x7d - 0x7f */
125};
126
127/* Register read and write */
128static inline unsigned int dac33_read_reg_cache(struct snd_soc_codec *codec,
129 unsigned reg)
130{
131 u8 *cache = codec->reg_cache;
132 if (reg >= DAC33_CACHEREGNUM)
133 return 0;
134
135 return cache[reg];
136}
137
138static inline void dac33_write_reg_cache(struct snd_soc_codec *codec,
139 u8 reg, u8 value)
140{
141 u8 *cache = codec->reg_cache;
142 if (reg >= DAC33_CACHEREGNUM)
143 return;
144
145 cache[reg] = value;
146}
147
148static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
149 u8 *value)
150{
151 struct tlv320dac33_priv *dac33 = codec->private_data;
152 int val;
153
154 *value = reg & 0xff;
155
156 /* If powered off, return the cached value */
157 if (dac33->chip_power) {
158 val = i2c_smbus_read_byte_data(codec->control_data, value[0]);
159 if (val < 0) {
160 dev_err(codec->dev, "Read failed (%d)\n", val);
161 value[0] = dac33_read_reg_cache(codec, reg);
162 } else {
163 value[0] = val;
164 dac33_write_reg_cache(codec, reg, val);
165 }
166 } else {
167 value[0] = dac33_read_reg_cache(codec, reg);
168 }
169
170 return 0;
171}
172
173static int dac33_write(struct snd_soc_codec *codec, unsigned int reg,
174 unsigned int value)
175{
176 struct tlv320dac33_priv *dac33 = codec->private_data;
177 u8 data[2];
178 int ret = 0;
179
180 /*
181 * data is
182 * D15..D8 dac33 register offset
183 * D7...D0 register data
184 */
185 data[0] = reg & 0xff;
186 data[1] = value & 0xff;
187
188 dac33_write_reg_cache(codec, data[0], data[1]);
189 if (dac33->chip_power) {
190 ret = codec->hw_write(codec->control_data, data, 2);
191 if (ret != 2)
192 dev_err(codec->dev, "Write failed (%d)\n", ret);
193 else
194 ret = 0;
195 }
196
197 return ret;
198}
199
200static int dac33_write_locked(struct snd_soc_codec *codec, unsigned int reg,
201 unsigned int value)
202{
203 struct tlv320dac33_priv *dac33 = codec->private_data;
204 int ret;
205
206 mutex_lock(&dac33->mutex);
207 ret = dac33_write(codec, reg, value);
208 mutex_unlock(&dac33->mutex);
209
210 return ret;
211}
212
213#define DAC33_I2C_ADDR_AUTOINC 0x80
214static int dac33_write16(struct snd_soc_codec *codec, unsigned int reg,
215 unsigned int value)
216{
217 struct tlv320dac33_priv *dac33 = codec->private_data;
218 u8 data[3];
219 int ret = 0;
220
221 /*
222 * data is
223 * D23..D16 dac33 register offset
224 * D15..D8 register data MSB
225 * D7...D0 register data LSB
226 */
227 data[0] = reg & 0xff;
228 data[1] = (value >> 8) & 0xff;
229 data[2] = value & 0xff;
230
231 dac33_write_reg_cache(codec, data[0], data[1]);
232 dac33_write_reg_cache(codec, data[0] + 1, data[2]);
233
234 if (dac33->chip_power) {
235 /* We need to set autoincrement mode for 16 bit writes */
236 data[0] |= DAC33_I2C_ADDR_AUTOINC;
237 ret = codec->hw_write(codec->control_data, data, 3);
238 if (ret != 3)
239 dev_err(codec->dev, "Write failed (%d)\n", ret);
240 else
241 ret = 0;
242 }
243
244 return ret;
245}
246
247static void dac33_restore_regs(struct snd_soc_codec *codec)
248{
249 struct tlv320dac33_priv *dac33 = codec->private_data;
250 u8 *cache = codec->reg_cache;
251 u8 data[2];
252 int i, ret;
253
254 if (!dac33->chip_power)
255 return;
256
257 for (i = DAC33_PWR_CTRL; i <= DAC33_INTP_CTRL_B; i++) {
258 data[0] = i;
259 data[1] = cache[i];
260 /* Skip the read only registers */
261 if ((i >= DAC33_INT_OSC_STATUS &&
262 i <= DAC33_INT_OSC_FREQ_RAT_READ_B) ||
263 (i >= DAC33_FIFO_WPTR_MSB && i <= DAC33_FIFO_IRQ_FLAG) ||
264 i == DAC33_DAC_STATUS_FLAGS ||
265 i == DAC33_SRC_EST_REF_CLK_RATIO_A ||
266 i == DAC33_SRC_EST_REF_CLK_RATIO_B)
267 continue;
268 ret = codec->hw_write(codec->control_data, data, 2);
269 if (ret != 2)
270 dev_err(codec->dev, "Write failed (%d)\n", ret);
271 }
272 for (i = DAC33_LDAC_PWR_CTRL; i <= DAC33_LINEL_TO_LLO_VOL; i++) {
273 data[0] = i;
274 data[1] = cache[i];
275 ret = codec->hw_write(codec->control_data, data, 2);
276 if (ret != 2)
277 dev_err(codec->dev, "Write failed (%d)\n", ret);
278 }
279 for (i = DAC33_LINER_TO_RLO_VOL; i <= DAC33_OSC_TRIM; i++) {
280 data[0] = i;
281 data[1] = cache[i];
282 ret = codec->hw_write(codec->control_data, data, 2);
283 if (ret != 2)
284 dev_err(codec->dev, "Write failed (%d)\n", ret);
285 }
286}
287
288static inline void dac33_soft_power(struct snd_soc_codec *codec, int power)
289{
290 u8 reg;
291
292 reg = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
293 if (power)
294 reg |= DAC33_PDNALLB;
295 else
296 reg &= ~DAC33_PDNALLB;
297 dac33_write(codec, DAC33_PWR_CTRL, reg);
298}
299
300static void dac33_hard_power(struct snd_soc_codec *codec, int power)
301{
302 struct tlv320dac33_priv *dac33 = codec->private_data;
303
304 mutex_lock(&dac33->mutex);
305 if (power) {
306 if (dac33->power_gpio >= 0) {
307 gpio_set_value(dac33->power_gpio, 1);
308 dac33->chip_power = 1;
309 /* Restore registers */
310 dac33_restore_regs(codec);
311 }
312 dac33_soft_power(codec, 1);
313 } else {
314 dac33_soft_power(codec, 0);
315 if (dac33->power_gpio >= 0) {
316 gpio_set_value(dac33->power_gpio, 0);
317 dac33->chip_power = 0;
318 }
319 }
320 mutex_unlock(&dac33->mutex);
321
322}
323
324static int dac33_get_nsample(struct snd_kcontrol *kcontrol,
325 struct snd_ctl_elem_value *ucontrol)
326{
327 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
328 struct tlv320dac33_priv *dac33 = codec->private_data;
329
330 ucontrol->value.integer.value[0] = dac33->nsample;
331
332 return 0;
333}
334
335static int dac33_set_nsample(struct snd_kcontrol *kcontrol,
336 struct snd_ctl_elem_value *ucontrol)
337{
338 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
339 struct tlv320dac33_priv *dac33 = codec->private_data;
340 int ret = 0;
341
342 if (dac33->nsample == ucontrol->value.integer.value[0])
343 return 0;
344
345 if (ucontrol->value.integer.value[0] < dac33->nsample_min ||
346 ucontrol->value.integer.value[0] > dac33->nsample_max)
347 ret = -EINVAL;
348 else
349 dac33->nsample = ucontrol->value.integer.value[0];
350
351 return ret;
352}
353
354static int dac33_get_nsample_switch(struct snd_kcontrol *kcontrol,
355 struct snd_ctl_elem_value *ucontrol)
356{
357 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
358 struct tlv320dac33_priv *dac33 = codec->private_data;
359
360 ucontrol->value.integer.value[0] = dac33->nsample_switch;
361
362 return 0;
363}
364
365static int dac33_set_nsample_switch(struct snd_kcontrol *kcontrol,
366 struct snd_ctl_elem_value *ucontrol)
367{
368 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
369 struct tlv320dac33_priv *dac33 = codec->private_data;
370 int ret = 0;
371
372 if (dac33->nsample_switch == ucontrol->value.integer.value[0])
373 return 0;
374 /* Do not allow changes while stream is running*/
375 if (codec->active)
376 return -EPERM;
377
378 if (ucontrol->value.integer.value[0] < 0 ||
379 ucontrol->value.integer.value[0] > 1)
380 ret = -EINVAL;
381 else
382 dac33->nsample_switch = ucontrol->value.integer.value[0];
383
384 return ret;
385}
386
387/*
388 * DACL/R digital volume control:
389 * from 0 dB to -63.5 in 0.5 dB steps
390 * Need to be inverted later on:
391 * 0x00 == 0 dB
392 * 0x7f == -63.5 dB
393 */
394static DECLARE_TLV_DB_SCALE(dac_digivol_tlv, -6350, 50, 0);
395
396static const struct snd_kcontrol_new dac33_snd_controls[] = {
397 SOC_DOUBLE_R_TLV("DAC Digital Playback Volume",
398 DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL,
399 0, 0x7f, 1, dac_digivol_tlv),
400 SOC_DOUBLE_R("DAC Digital Playback Switch",
401 DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL, 7, 1, 1),
402 SOC_DOUBLE_R("Line to Line Out Volume",
403 DAC33_LINEL_TO_LLO_VOL, DAC33_LINER_TO_RLO_VOL, 0, 127, 1),
404};
405
406static const struct snd_kcontrol_new dac33_nsample_snd_controls[] = {
407 SOC_SINGLE_EXT("nSample", 0, 0, 5900, 0,
408 dac33_get_nsample, dac33_set_nsample),
409 SOC_SINGLE_EXT("nSample Switch", 0, 0, 1, 0,
410 dac33_get_nsample_switch, dac33_set_nsample_switch),
411};
412
413/* Analog bypass */
414static const struct snd_kcontrol_new dac33_dapm_abypassl_control =
415 SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1);
416
417static const struct snd_kcontrol_new dac33_dapm_abypassr_control =
418 SOC_DAPM_SINGLE("Switch", DAC33_LINER_TO_RLO_VOL, 7, 1, 1);
419
420static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = {
421 SND_SOC_DAPM_OUTPUT("LEFT_LO"),
422 SND_SOC_DAPM_OUTPUT("RIGHT_LO"),
423
424 SND_SOC_DAPM_INPUT("LINEL"),
425 SND_SOC_DAPM_INPUT("LINER"),
426
427 SND_SOC_DAPM_DAC("DACL", "Left Playback", DAC33_LDAC_PWR_CTRL, 2, 0),
428 SND_SOC_DAPM_DAC("DACR", "Right Playback", DAC33_RDAC_PWR_CTRL, 2, 0),
429
430 /* Analog bypass */
431 SND_SOC_DAPM_SWITCH("Analog Left Bypass", SND_SOC_NOPM, 0, 0,
432 &dac33_dapm_abypassl_control),
433 SND_SOC_DAPM_SWITCH("Analog Right Bypass", SND_SOC_NOPM, 0, 0,
434 &dac33_dapm_abypassr_control),
435
436 SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Left Amp Power",
437 DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0),
438 SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amp Power",
439 DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0),
440};
441
442static const struct snd_soc_dapm_route audio_map[] = {
443 /* Analog bypass */
444 {"Analog Left Bypass", "Switch", "LINEL"},
445 {"Analog Right Bypass", "Switch", "LINER"},
446
447 {"Output Left Amp Power", NULL, "DACL"},
448 {"Output Right Amp Power", NULL, "DACR"},
449
450 {"Output Left Amp Power", NULL, "Analog Left Bypass"},
451 {"Output Right Amp Power", NULL, "Analog Right Bypass"},
452
453 /* output */
454 {"LEFT_LO", NULL, "Output Left Amp Power"},
455 {"RIGHT_LO", NULL, "Output Right Amp Power"},
456};
457
458static int dac33_add_widgets(struct snd_soc_codec *codec)
459{
460 snd_soc_dapm_new_controls(codec, dac33_dapm_widgets,
461 ARRAY_SIZE(dac33_dapm_widgets));
462
463 /* set up audio path interconnects */
464 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
465
466 return 0;
467}
468
469static int dac33_set_bias_level(struct snd_soc_codec *codec,
470 enum snd_soc_bias_level level)
471{
472 switch (level) {
473 case SND_SOC_BIAS_ON:
474 dac33_soft_power(codec, 1);
475 break;
476 case SND_SOC_BIAS_PREPARE:
477 break;
478 case SND_SOC_BIAS_STANDBY:
479 if (codec->bias_level == SND_SOC_BIAS_OFF)
480 dac33_hard_power(codec, 1);
481 dac33_soft_power(codec, 0);
482 break;
483 case SND_SOC_BIAS_OFF:
484 dac33_hard_power(codec, 0);
485 break;
486 }
487 codec->bias_level = level;
488
489 return 0;
490}
491
492static void dac33_work(struct work_struct *work)
493{
494 struct snd_soc_codec *codec;
495 struct tlv320dac33_priv *dac33;
496 u8 reg;
497
498 dac33 = container_of(work, struct tlv320dac33_priv, work);
499 codec = &dac33->codec;
500
501 mutex_lock(&dac33->mutex);
502 switch (dac33->state) {
503 case DAC33_PREFILL:
504 dac33->state = DAC33_PLAYBACK;
505 dac33_write16(codec, DAC33_NSAMPLE_MSB,
506 DAC33_THRREG(dac33->nsample));
507 dac33_write16(codec, DAC33_PREFILL_MSB,
508 DAC33_THRREG(dac33->alarm_threshold));
509 break;
510 case DAC33_PLAYBACK:
511 dac33_write16(codec, DAC33_NSAMPLE_MSB,
512 DAC33_THRREG(dac33->nsample));
513 break;
514 case DAC33_IDLE:
515 break;
516 case DAC33_FLUSH:
517 dac33->state = DAC33_IDLE;
518 /* Mask all interrupts from dac33 */
519 dac33_write(codec, DAC33_FIFO_IRQ_MASK, 0);
520
521 /* flush fifo */
522 reg = dac33_read_reg_cache(codec, DAC33_FIFO_CTRL_A);
523 reg |= DAC33_FIFOFLUSH;
524 dac33_write(codec, DAC33_FIFO_CTRL_A, reg);
525 break;
526 }
527 mutex_unlock(&dac33->mutex);
528}
529
530static irqreturn_t dac33_interrupt_handler(int irq, void *dev)
531{
532 struct snd_soc_codec *codec = dev;
533 struct tlv320dac33_priv *dac33 = codec->private_data;
534
535 queue_work(dac33->dac33_wq, &dac33->work);
536
537 return IRQ_HANDLED;
538}
539
540static void dac33_shutdown(struct snd_pcm_substream *substream,
541 struct snd_soc_dai *dai)
542{
543 struct snd_soc_pcm_runtime *rtd = substream->private_data;
544 struct snd_soc_device *socdev = rtd->socdev;
545 struct snd_soc_codec *codec = socdev->card->codec;
546 struct tlv320dac33_priv *dac33 = codec->private_data;
547 unsigned int pwr_ctrl;
548
549 /* Stop pending workqueue */
550 if (dac33->nsample_switch)
551 cancel_work_sync(&dac33->work);
552
553 mutex_lock(&dac33->mutex);
554 pwr_ctrl = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
555 pwr_ctrl &= ~(DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB);
556 dac33_write(codec, DAC33_PWR_CTRL, pwr_ctrl);
557 mutex_unlock(&dac33->mutex);
558}
559
560static void dac33_oscwait(struct snd_soc_codec *codec)
561{
562 int timeout = 20;
563 u8 reg;
564
565 do {
566 msleep(1);
567 dac33_read(codec, DAC33_INT_OSC_STATUS, &reg);
568 } while (((reg & 0x03) != DAC33_OSCSTATUS_NORMAL) && timeout--);
569 if ((reg & 0x03) != DAC33_OSCSTATUS_NORMAL)
570 dev_err(codec->dev,
571 "internal oscillator calibration failed\n");
572}
573
574static int dac33_hw_params(struct snd_pcm_substream *substream,
575 struct snd_pcm_hw_params *params,
576 struct snd_soc_dai *dai)
577{
578 struct snd_soc_pcm_runtime *rtd = substream->private_data;
579 struct snd_soc_device *socdev = rtd->socdev;
580 struct snd_soc_codec *codec = socdev->card->codec;
581
582 /* Check parameters for validity */
583 switch (params_rate(params)) {
584 case 44100:
585 case 48000:
586 break;
587 default:
588 dev_err(codec->dev, "unsupported rate %d\n",
589 params_rate(params));
590 return -EINVAL;
591 }
592
593 switch (params_format(params)) {
594 case SNDRV_PCM_FORMAT_S16_LE:
595 break;
596 default:
597 dev_err(codec->dev, "unsupported format %d\n",
598 params_format(params));
599 return -EINVAL;
600 }
601
602 return 0;
603}
604
605#define CALC_OSCSET(rate, refclk) ( \
606 ((((rate * 10000) / refclk) * 4096) + 5000) / 10000)
607#define CALC_RATIOSET(rate, refclk) ( \
608 ((((refclk * 100000) / rate) * 16384) + 50000) / 100000)
609
610/*
611 * tlv320dac33 is strict on the sequence of the register writes, if the register
612 * writes happens in different order, than dac33 might end up in unknown state.
613 * Use the known, working sequence of register writes to initialize the dac33.
614 */
615static int dac33_prepare_chip(struct snd_pcm_substream *substream)
616{
617 struct snd_soc_pcm_runtime *rtd = substream->private_data;
618 struct snd_soc_device *socdev = rtd->socdev;
619 struct snd_soc_codec *codec = socdev->card->codec;
620 struct tlv320dac33_priv *dac33 = codec->private_data;
621 unsigned int oscset, ratioset, pwr_ctrl, reg_tmp;
622 u8 aictrl_a, fifoctrl_a;
623
624 switch (substream->runtime->rate) {
625 case 44100:
626 case 48000:
627 oscset = CALC_OSCSET(substream->runtime->rate, dac33->refclk);
628 ratioset = CALC_RATIOSET(substream->runtime->rate,
629 dac33->refclk);
630 break;
631 default:
632 dev_err(codec->dev, "unsupported rate %d\n",
633 substream->runtime->rate);
634 return -EINVAL;
635 }
636
637
638 aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
639 aictrl_a &= ~(DAC33_NCYCL_MASK | DAC33_WLEN_MASK);
640 fifoctrl_a = dac33_read_reg_cache(codec, DAC33_FIFO_CTRL_A);
641 fifoctrl_a &= ~DAC33_WIDTH;
642 switch (substream->runtime->format) {
643 case SNDRV_PCM_FORMAT_S16_LE:
644 aictrl_a |= (DAC33_NCYCL_16 | DAC33_WLEN_16);
645 fifoctrl_a |= DAC33_WIDTH;
646 break;
647 default:
648 dev_err(codec->dev, "unsupported format %d\n",
649 substream->runtime->format);
650 return -EINVAL;
651 }
652
653 mutex_lock(&dac33->mutex);
654 dac33_soft_power(codec, 1);
655
656 reg_tmp = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
657 dac33_write(codec, DAC33_INT_OSC_CTRL, reg_tmp);
658
659 /* Write registers 0x08 and 0x09 (MSB, LSB) */
660 dac33_write16(codec, DAC33_INT_OSC_FREQ_RAT_A, oscset);
661
662 /* calib time: 128 is a nice number ;) */
663 dac33_write(codec, DAC33_CALIB_TIME, 128);
664
665 /* adjustment treshold & step */
666 dac33_write(codec, DAC33_INT_OSC_CTRL_B, DAC33_ADJTHRSHLD(2) |
667 DAC33_ADJSTEP(1));
668
669 /* div=4 / gain=1 / div */
670 dac33_write(codec, DAC33_INT_OSC_CTRL_C, DAC33_REFDIV(4));
671
672 pwr_ctrl = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
673 pwr_ctrl |= DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB;
674 dac33_write(codec, DAC33_PWR_CTRL, pwr_ctrl);
675
676 dac33_oscwait(codec);
677
678 if (dac33->nsample_switch) {
679 /* 50-51 : ASRC Control registers */
680 dac33_write(codec, DAC33_ASRC_CTRL_A, (1 << 4)); /* div=2 */
681 dac33_write(codec, DAC33_ASRC_CTRL_B, 1); /* ??? */
682
683 /* Write registers 0x34 and 0x35 (MSB, LSB) */
684 dac33_write16(codec, DAC33_SRC_REF_CLK_RATIO_A, ratioset);
685
686 /* Set interrupts to high active */
687 dac33_write(codec, DAC33_INTP_CTRL_A, DAC33_INTPM_AHIGH);
688
689 dac33_write(codec, DAC33_FIFO_IRQ_MODE_B,
690 DAC33_ATM(DAC33_FIFO_IRQ_MODE_LEVEL));
691 dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT);
692 } else {
693 /* 50-51 : ASRC Control registers */
694 dac33_write(codec, DAC33_ASRC_CTRL_A, DAC33_SRCBYP);
695 dac33_write(codec, DAC33_ASRC_CTRL_B, 0); /* ??? */
696 }
697
698 if (dac33->nsample_switch)
699 fifoctrl_a &= ~DAC33_FBYPAS;
700 else
701 fifoctrl_a |= DAC33_FBYPAS;
702 dac33_write(codec, DAC33_FIFO_CTRL_A, fifoctrl_a);
703
704 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_A, aictrl_a);
705 reg_tmp = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
706 if (dac33->nsample_switch)
707 reg_tmp &= ~DAC33_BCLKON;
708 else
709 reg_tmp |= DAC33_BCLKON;
710 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_B, reg_tmp);
711
712 if (dac33->nsample_switch) {
713 /* 20: BCLK divide ratio */
714 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 3);
715
716 dac33_write16(codec, DAC33_ATHR_MSB,
717 DAC33_THRREG(dac33->alarm_threshold));
718 } else {
719 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 32);
720 }
721
722 mutex_unlock(&dac33->mutex);
723
724 return 0;
725}
726
727static void dac33_calculate_times(struct snd_pcm_substream *substream)
728{
729 struct snd_soc_pcm_runtime *rtd = substream->private_data;
730 struct snd_soc_device *socdev = rtd->socdev;
731 struct snd_soc_codec *codec = socdev->card->codec;
732 struct tlv320dac33_priv *dac33 = codec->private_data;
733 unsigned int nsample_limit;
734
735 /* Number of samples (16bit, stereo) in one period */
736 dac33->nsample_min = snd_pcm_lib_period_bytes(substream) / 4;
737
738 /* Number of samples (16bit, stereo) in ALSA buffer */
739 dac33->nsample_max = snd_pcm_lib_buffer_bytes(substream) / 4;
740 /* Subtract one period from the total */
741 dac33->nsample_max -= dac33->nsample_min;
742
743 /* Number of samples for LATENCY_TIME_MS / 2 */
744 dac33->alarm_threshold = substream->runtime->rate /
745 (1000 / (LATENCY_TIME_MS / 2));
746
747 /* Find and fix up the lowest nsmaple limit */
748 nsample_limit = substream->runtime->rate / (1000 / LATENCY_TIME_MS);
749
750 if (dac33->nsample_min < nsample_limit)
751 dac33->nsample_min = nsample_limit;
752
753 if (dac33->nsample < dac33->nsample_min)
754 dac33->nsample = dac33->nsample_min;
755
756 /*
757 * Find and fix up the highest nsmaple limit
758 * In order to not overflow the DAC33 buffer substract the
759 * alarm_threshold value from the size of the DAC33 buffer
760 */
761 nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - dac33->alarm_threshold;
762
763 if (dac33->nsample_max > nsample_limit)
764 dac33->nsample_max = nsample_limit;
765
766 if (dac33->nsample > dac33->nsample_max)
767 dac33->nsample = dac33->nsample_max;
768}
769
770static int dac33_pcm_prepare(struct snd_pcm_substream *substream,
771 struct snd_soc_dai *dai)
772{
773 dac33_calculate_times(substream);
774 dac33_prepare_chip(substream);
775
776 return 0;
777}
778
779static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
780 struct snd_soc_dai *dai)
781{
782 struct snd_soc_pcm_runtime *rtd = substream->private_data;
783 struct snd_soc_device *socdev = rtd->socdev;
784 struct snd_soc_codec *codec = socdev->card->codec;
785 struct tlv320dac33_priv *dac33 = codec->private_data;
786 int ret = 0;
787
788 switch (cmd) {
789 case SNDRV_PCM_TRIGGER_START:
790 case SNDRV_PCM_TRIGGER_RESUME:
791 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
792 if (dac33->nsample_switch) {
793 dac33->state = DAC33_PREFILL;
794 queue_work(dac33->dac33_wq, &dac33->work);
795 }
796 break;
797 case SNDRV_PCM_TRIGGER_STOP:
798 case SNDRV_PCM_TRIGGER_SUSPEND:
799 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
800 if (dac33->nsample_switch) {
801 dac33->state = DAC33_FLUSH;
802 queue_work(dac33->dac33_wq, &dac33->work);
803 }
804 break;
805 default:
806 ret = -EINVAL;
807 }
808
809 return ret;
810}
811
812static int dac33_set_dai_sysclk(struct snd_soc_dai *codec_dai,
813 int clk_id, unsigned int freq, int dir)
814{
815 struct snd_soc_codec *codec = codec_dai->codec;
816 struct tlv320dac33_priv *dac33 = codec->private_data;
817 u8 ioc_reg, asrcb_reg;
818
819 ioc_reg = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
820 asrcb_reg = dac33_read_reg_cache(codec, DAC33_ASRC_CTRL_B);
821 switch (clk_id) {
822 case TLV320DAC33_MCLK:
823 ioc_reg |= DAC33_REFSEL;
824 asrcb_reg |= DAC33_SRCREFSEL;
825 break;
826 case TLV320DAC33_SLEEPCLK:
827 ioc_reg &= ~DAC33_REFSEL;
828 asrcb_reg &= ~DAC33_SRCREFSEL;
829 break;
830 default:
831 dev_err(codec->dev, "Invalid clock ID (%d)\n", clk_id);
832 break;
833 }
834 dac33->refclk = freq;
835
836 dac33_write_reg_cache(codec, DAC33_INT_OSC_CTRL, ioc_reg);
837 dac33_write_reg_cache(codec, DAC33_ASRC_CTRL_B, asrcb_reg);
838
839 return 0;
840}
841
842static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai,
843 unsigned int fmt)
844{
845 struct snd_soc_codec *codec = codec_dai->codec;
846 u8 aictrl_a, aictrl_b;
847
848 aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
849 aictrl_b = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
850 /* set master/slave audio interface */
851 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
852 case SND_SOC_DAIFMT_CBM_CFM:
853 /* Codec Master */
854 aictrl_a |= (DAC33_MSBCLK | DAC33_MSWCLK);
855 break;
856 case SND_SOC_DAIFMT_CBS_CFS:
857 /* Codec Slave */
858 aictrl_a &= ~(DAC33_MSBCLK | DAC33_MSWCLK);
859 break;
860 default:
861 return -EINVAL;
862 }
863
864 aictrl_a &= ~DAC33_AFMT_MASK;
865 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
866 case SND_SOC_DAIFMT_I2S:
867 aictrl_a |= DAC33_AFMT_I2S;
868 break;
869 case SND_SOC_DAIFMT_DSP_A:
870 aictrl_a |= DAC33_AFMT_DSP;
871 aictrl_b &= ~DAC33_DATA_DELAY_MASK;
872 aictrl_b |= DAC33_DATA_DELAY(1); /* 1 bit delay */
873 break;
874 case SND_SOC_DAIFMT_DSP_B:
875 aictrl_a |= DAC33_AFMT_DSP;
876 aictrl_b &= ~DAC33_DATA_DELAY_MASK; /* No delay */
877 break;
878 case SND_SOC_DAIFMT_RIGHT_J:
879 aictrl_a |= DAC33_AFMT_RIGHT_J;
880 break;
881 case SND_SOC_DAIFMT_LEFT_J:
882 aictrl_a |= DAC33_AFMT_LEFT_J;
883 break;
884 default:
885 dev_err(codec->dev, "Unsupported format (%u)\n",
886 fmt & SND_SOC_DAIFMT_FORMAT_MASK);
887 return -EINVAL;
888 }
889
890 dac33_write_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A, aictrl_a);
891 dac33_write_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B, aictrl_b);
892
893 return 0;
894}
895
896static void dac33_init_chip(struct snd_soc_codec *codec)
897{
898 /* 44-46: DAC Control Registers */
899 /* A : DAC sample rate Fsref/1.5 */
900 dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(1));
901 /* B : DAC src=normal, not muted */
902 dac33_write(codec, DAC33_DAC_CTRL_B, DAC33_DACSRCR_RIGHT |
903 DAC33_DACSRCL_LEFT);
904 /* C : (defaults) */
905 dac33_write(codec, DAC33_DAC_CTRL_C, 0x00);
906
907 /* 64-65 : L&R DAC power control
908 Line In -> OUT 1V/V Gain, DAC -> OUT 4V/V Gain*/
909 dac33_write(codec, DAC33_LDAC_PWR_CTRL, DAC33_LROUT_GAIN(2));
910 dac33_write(codec, DAC33_RDAC_PWR_CTRL, DAC33_LROUT_GAIN(2));
911
912 /* 73 : volume soft stepping control,
913 clock source = internal osc (?) */
914 dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN);
915
916 /* 66 : LOP/LOM Modes */
917 dac33_write(codec, DAC33_OUT_AMP_CM_CTRL, 0xff);
918
919 /* 68 : LOM inverted from LOP */
920 dac33_write(codec, DAC33_OUT_AMP_CTRL, (3<<2));
921
922 dac33_write(codec, DAC33_PWR_CTRL, DAC33_PDNALLB);
923}
924
925static int dac33_soc_probe(struct platform_device *pdev)
926{
927 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
928 struct snd_soc_codec *codec;
929 struct tlv320dac33_priv *dac33;
930 int ret = 0;
931
932 BUG_ON(!tlv320dac33_codec);
933
934 codec = tlv320dac33_codec;
935 socdev->card->codec = codec;
936 dac33 = codec->private_data;
937
938 /* Power up the codec */
939 dac33_hard_power(codec, 1);
940 /* Set default configuration */
941 dac33_init_chip(codec);
942
943 /* register pcms */
944 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
945 if (ret < 0) {
946 dev_err(codec->dev, "failed to create pcms\n");
947 goto pcm_err;
948 }
949
950 snd_soc_add_controls(codec, dac33_snd_controls,
951 ARRAY_SIZE(dac33_snd_controls));
952 /* Only add the nSample controls, if we have valid IRQ number */
953 if (dac33->irq >= 0)
954 snd_soc_add_controls(codec, dac33_nsample_snd_controls,
955 ARRAY_SIZE(dac33_nsample_snd_controls));
956
957 dac33_add_widgets(codec);
958
959 /* power on device */
960 dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
961
962 return 0;
963
964pcm_err:
965 dac33_hard_power(codec, 0);
966 return ret;
967}
968
969static int dac33_soc_remove(struct platform_device *pdev)
970{
971 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
972 struct snd_soc_codec *codec = socdev->card->codec;
973
974 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
975
976 snd_soc_free_pcms(socdev);
977 snd_soc_dapm_free(socdev);
978
979 return 0;
980}
981
982static int dac33_soc_suspend(struct platform_device *pdev, pm_message_t state)
983{
984 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
985 struct snd_soc_codec *codec = socdev->card->codec;
986
987 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
988
989 return 0;
990}
991
992static int dac33_soc_resume(struct platform_device *pdev)
993{
994 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
995 struct snd_soc_codec *codec = socdev->card->codec;
996
997 dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
998 dac33_set_bias_level(codec, codec->suspend_bias_level);
999
1000 return 0;
1001}
1002
1003struct snd_soc_codec_device soc_codec_dev_tlv320dac33 = {
1004 .probe = dac33_soc_probe,
1005 .remove = dac33_soc_remove,
1006 .suspend = dac33_soc_suspend,
1007 .resume = dac33_soc_resume,
1008};
1009EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320dac33);
1010
1011#define DAC33_RATES (SNDRV_PCM_RATE_44100 | \
1012 SNDRV_PCM_RATE_48000)
1013#define DAC33_FORMATS SNDRV_PCM_FMTBIT_S16_LE
1014
1015static struct snd_soc_dai_ops dac33_dai_ops = {
1016 .shutdown = dac33_shutdown,
1017 .hw_params = dac33_hw_params,
1018 .prepare = dac33_pcm_prepare,
1019 .trigger = dac33_pcm_trigger,
1020 .set_sysclk = dac33_set_dai_sysclk,
1021 .set_fmt = dac33_set_dai_fmt,
1022};
1023
1024struct snd_soc_dai dac33_dai = {
1025 .name = "tlv320dac33",
1026 .playback = {
1027 .stream_name = "Playback",
1028 .channels_min = 2,
1029 .channels_max = 2,
1030 .rates = DAC33_RATES,
1031 .formats = DAC33_FORMATS,},
1032 .ops = &dac33_dai_ops,
1033};
1034EXPORT_SYMBOL_GPL(dac33_dai);
1035
1036static int dac33_i2c_probe(struct i2c_client *client,
1037 const struct i2c_device_id *id)
1038{
1039 struct tlv320dac33_platform_data *pdata;
1040 struct tlv320dac33_priv *dac33;
1041 struct snd_soc_codec *codec;
1042 int ret = 0;
1043
1044 if (client->dev.platform_data == NULL) {
1045 dev_err(&client->dev, "Platform data not set\n");
1046 return -ENODEV;
1047 }
1048 pdata = client->dev.platform_data;
1049
1050 dac33 = kzalloc(sizeof(struct tlv320dac33_priv), GFP_KERNEL);
1051 if (dac33 == NULL)
1052 return -ENOMEM;
1053
1054 codec = &dac33->codec;
1055 codec->private_data = dac33;
1056 codec->control_data = client;
1057
1058 mutex_init(&codec->mutex);
1059 mutex_init(&dac33->mutex);
1060 INIT_LIST_HEAD(&codec->dapm_widgets);
1061 INIT_LIST_HEAD(&codec->dapm_paths);
1062
1063 codec->name = "tlv320dac33";
1064 codec->owner = THIS_MODULE;
1065 codec->read = dac33_read_reg_cache;
1066 codec->write = dac33_write_locked;
1067 codec->hw_write = (hw_write_t) i2c_master_send;
1068 codec->bias_level = SND_SOC_BIAS_OFF;
1069 codec->set_bias_level = dac33_set_bias_level;
1070 codec->dai = &dac33_dai;
1071 codec->num_dai = 1;
1072 codec->reg_cache_size = ARRAY_SIZE(dac33_reg);
1073 codec->reg_cache = kmemdup(dac33_reg, ARRAY_SIZE(dac33_reg),
1074 GFP_KERNEL);
1075 if (codec->reg_cache == NULL) {
1076 ret = -ENOMEM;
1077 goto error_reg;
1078 }
1079
1080 i2c_set_clientdata(client, dac33);
1081
1082 dac33->power_gpio = pdata->power_gpio;
1083 dac33->irq = client->irq;
1084 dac33->nsample = NSAMPLE_MAX;
1085 /* Disable FIFO use by default */
1086 dac33->nsample_switch = 0;
1087
1088 tlv320dac33_codec = codec;
1089
1090 codec->dev = &client->dev;
1091 dac33_dai.dev = codec->dev;
1092
1093 /* Check if the reset GPIO number is valid and request it */
1094 if (dac33->power_gpio >= 0) {
1095 ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
1096 if (ret < 0) {
1097 dev_err(codec->dev,
1098 "Failed to request reset GPIO (%d)\n",
1099 dac33->power_gpio);
1100 snd_soc_unregister_dai(&dac33_dai);
1101 snd_soc_unregister_codec(codec);
1102 goto error_gpio;
1103 }
1104 gpio_direction_output(dac33->power_gpio, 0);
1105 } else {
1106 dac33->chip_power = 1;
1107 }
1108
1109 /* Check if the IRQ number is valid and request it */
1110 if (dac33->irq >= 0) {
1111 ret = request_irq(dac33->irq, dac33_interrupt_handler,
1112 IRQF_TRIGGER_RISING | IRQF_DISABLED,
1113 codec->name, codec);
1114 if (ret < 0) {
1115 dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
1116 dac33->irq, ret);
1117 dac33->irq = -1;
1118 }
1119 if (dac33->irq != -1) {
1120 /* Setup work queue */
1121 dac33->dac33_wq =
1122 create_singlethread_workqueue("tlv320dac33");
1123 if (dac33->dac33_wq == NULL) {
1124 free_irq(dac33->irq, &dac33->codec);
1125 ret = -ENOMEM;
1126 goto error_wq;
1127 }
1128
1129 INIT_WORK(&dac33->work, dac33_work);
1130 }
1131 }
1132
1133 ret = snd_soc_register_codec(codec);
1134 if (ret != 0) {
1135 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
1136 goto error_codec;
1137 }
1138
1139 ret = snd_soc_register_dai(&dac33_dai);
1140 if (ret != 0) {
1141 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
1142 snd_soc_unregister_codec(codec);
1143 goto error_codec;
1144 }
1145
1146 /* Shut down the codec for now */
1147 dac33_hard_power(codec, 0);
1148
1149 return ret;
1150
1151error_codec:
1152 if (dac33->irq >= 0) {
1153 free_irq(dac33->irq, &dac33->codec);
1154 destroy_workqueue(dac33->dac33_wq);
1155 }
1156error_wq:
1157 if (dac33->power_gpio >= 0)
1158 gpio_free(dac33->power_gpio);
1159error_gpio:
1160 kfree(codec->reg_cache);
1161error_reg:
1162 tlv320dac33_codec = NULL;
1163 kfree(dac33);
1164
1165 return ret;
1166}
1167
1168static int dac33_i2c_remove(struct i2c_client *client)
1169{
1170 struct tlv320dac33_priv *dac33;
1171
1172 dac33 = i2c_get_clientdata(client);
1173 dac33_hard_power(&dac33->codec, 0);
1174
1175 if (dac33->power_gpio >= 0)
1176 gpio_free(dac33->power_gpio);
1177 if (dac33->irq >= 0)
1178 free_irq(dac33->irq, &dac33->codec);
1179
1180 destroy_workqueue(dac33->dac33_wq);
1181 snd_soc_unregister_dai(&dac33_dai);
1182 snd_soc_unregister_codec(&dac33->codec);
1183 kfree(dac33->codec.reg_cache);
1184 kfree(dac33);
1185 tlv320dac33_codec = NULL;
1186
1187 return 0;
1188}
1189
1190static const struct i2c_device_id tlv320dac33_i2c_id[] = {
1191 {
1192 .name = "tlv320dac33",
1193 .driver_data = 0,
1194 },
1195 { },
1196};
1197
1198static struct i2c_driver tlv320dac33_i2c_driver = {
1199 .driver = {
1200 .name = "tlv320dac33",
1201 .owner = THIS_MODULE,
1202 },
1203 .probe = dac33_i2c_probe,
1204 .remove = __devexit_p(dac33_i2c_remove),
1205 .id_table = tlv320dac33_i2c_id,
1206};
1207
1208static int __init dac33_module_init(void)
1209{
1210 int r;
1211 r = i2c_add_driver(&tlv320dac33_i2c_driver);
1212 if (r < 0) {
1213 printk(KERN_ERR "DAC33: driver registration failed\n");
1214 return r;
1215 }
1216 return 0;
1217}
1218module_init(dac33_module_init);
1219
1220static void __exit dac33_module_exit(void)
1221{
1222 i2c_del_driver(&tlv320dac33_i2c_driver);
1223}
1224module_exit(dac33_module_exit);
1225
1226
1227MODULE_DESCRIPTION("ASoC TLV320DAC33 codec driver");
1228MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@nokia.com>");
1229MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/tlv320dac33.h b/sound/soc/codecs/tlv320dac33.h
new file mode 100644
index 000000000000..eb8ae07f0bd2
--- /dev/null
+++ b/sound/soc/codecs/tlv320dac33.h
@@ -0,0 +1,267 @@
1/*
2 * ALSA SoC Texas Instruments TLV320DAC33 codec driver
3 *
4 * Author: Peter Ujfalusi <peter.ujfalusi@nokia.com>
5 *
6 * Copyright: (C) 2009 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * 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 __TLV320DAC33_H
25#define __TLV320DAC33_H
26
27#define DAC33_PAGE_SELECT 0x00
28#define DAC33_PWR_CTRL 0x01
29#define DAC33_PLL_CTRL_A 0x02
30#define DAC33_PLL_CTRL_B 0x03
31#define DAC33_PLL_CTRL_C 0x04
32#define DAC33_PLL_CTRL_D 0x05
33#define DAC33_PLL_CTRL_E 0x06
34#define DAC33_INT_OSC_CTRL 0x07
35#define DAC33_INT_OSC_FREQ_RAT_A 0x08
36#define DAC33_INT_OSC_FREQ_RAT_B 0x09
37#define DAC33_INT_OSC_DAC_RATIO_SET 0x0A
38#define DAC33_CALIB_TIME 0x0B
39#define DAC33_INT_OSC_CTRL_B 0x0C
40#define DAC33_INT_OSC_CTRL_C 0x0D
41#define DAC33_INT_OSC_STATUS 0x0E
42#define DAC33_INT_OSC_DAC_RATIO_READ 0x0F
43#define DAC33_INT_OSC_FREQ_RAT_READ_A 0x10
44#define DAC33_INT_OSC_FREQ_RAT_READ_B 0x11
45#define DAC33_SER_AUDIOIF_CTRL_A 0x12
46#define DAC33_SER_AUDIOIF_CTRL_B 0x13
47#define DAC33_SER_AUDIOIF_CTRL_C 0x14
48#define DAC33_FIFO_CTRL_A 0x15
49#define DAC33_UTHR_MSB 0x16
50#define DAC33_UTHR_LSB 0x17
51#define DAC33_ATHR_MSB 0x18
52#define DAC33_ATHR_LSB 0x19
53#define DAC33_LTHR_MSB 0x1A
54#define DAC33_LTHR_LSB 0x1B
55#define DAC33_PREFILL_MSB 0x1C
56#define DAC33_PREFILL_LSB 0x1D
57#define DAC33_NSAMPLE_MSB 0x1E
58#define DAC33_NSAMPLE_LSB 0x1F
59#define DAC33_FIFO_WPTR_MSB 0x20
60#define DAC33_FIFO_WPTR_LSB 0x21
61#define DAC33_FIFO_RPTR_MSB 0x22
62#define DAC33_FIFO_RPTR_LSB 0x23
63#define DAC33_FIFO_DEPTH_MSB 0x24
64#define DAC33_FIFO_DEPTH_LSB 0x25
65#define DAC33_SAMPLES_REMAINING_MSB 0x26
66#define DAC33_SAMPLES_REMAINING_LSB 0x27
67#define DAC33_FIFO_IRQ_FLAG 0x28
68#define DAC33_FIFO_IRQ_MASK 0x29
69#define DAC33_FIFO_IRQ_MODE_A 0x2A
70#define DAC33_FIFO_IRQ_MODE_B 0x2B
71#define DAC33_DAC_CTRL_A 0x2C
72#define DAC33_DAC_CTRL_B 0x2D
73#define DAC33_DAC_CTRL_C 0x2E
74#define DAC33_LDAC_DIG_VOL_CTRL 0x2F
75#define DAC33_RDAC_DIG_VOL_CTRL 0x30
76#define DAC33_DAC_STATUS_FLAGS 0x31
77#define DAC33_ASRC_CTRL_A 0x32
78#define DAC33_ASRC_CTRL_B 0x33
79#define DAC33_SRC_REF_CLK_RATIO_A 0x34
80#define DAC33_SRC_REF_CLK_RATIO_B 0x35
81#define DAC33_SRC_EST_REF_CLK_RATIO_A 0x36
82#define DAC33_SRC_EST_REF_CLK_RATIO_B 0x37
83#define DAC33_INTP_CTRL_A 0x38
84#define DAC33_INTP_CTRL_B 0x39
85/* Registers 0x3A - 0x3F Reserved */
86#define DAC33_LDAC_PWR_CTRL 0x40
87#define DAC33_RDAC_PWR_CTRL 0x41
88#define DAC33_OUT_AMP_CM_CTRL 0x42
89#define DAC33_OUT_AMP_PWR_CTRL 0x43
90#define DAC33_OUT_AMP_CTRL 0x44
91#define DAC33_LINEL_TO_LLO_VOL 0x45
92/* Registers 0x45 - 0x47 Reserved */
93#define DAC33_LINER_TO_RLO_VOL 0x48
94#define DAC33_ANA_VOL_SOFT_STEP_CTRL 0x49
95#define DAC33_OSC_TRIM 0x4A
96/* Registers 0x4B - 0x7C Reserved */
97#define DAC33_DEVICE_ID_MSB 0x7D
98#define DAC33_DEVICE_ID_LSB 0x7E
99#define DAC33_DEVICE_REV_ID 0x7F
100
101#define DAC33_CACHEREGNUM 128
102
103/* Bit definitions */
104
105/* DAC33_PWR_CTRL (0x01) */
106#define DAC33_DACRPDNB (0x01 << 0)
107#define DAC33_DACLPDNB (0x01 << 1)
108#define DAC33_OSCPDNB (0x01 << 2)
109#define DAC33_PLLPDNB (0x01 << 3)
110#define DAC33_PDNALLB (0x01 << 4)
111#define DAC33_SOFT_RESET (0x01 << 7)
112
113/* DAC33_INT_OSC_CTRL (0x07) */
114#define DAC33_REFSEL (0x01 << 1)
115
116/* DAC33_INT_OSC_CTRL_B (0x0C) */
117#define DAC33_ADJSTEP(x) (x << 0)
118#define DAC33_ADJTHRSHLD(x) (x << 4)
119
120/* DAC33_INT_OSC_CTRL_C (0x0D) */
121#define DAC33_REFDIV(x) (x << 4)
122
123/* DAC33_INT_OSC_STATUS (0x0E) */
124#define DAC33_OSCSTATUS_IDLE_CALIB (0x00)
125#define DAC33_OSCSTATUS_NORMAL (0x01)
126#define DAC33_OSCSTATUS_ADJUSTMENT (0x03)
127#define DAC33_OSCSTATUS_NOT_USED (0x02)
128
129/* DAC33_SER_AUDIOIF_CTRL_A (0x12) */
130#define DAC33_MSWCLK (0x01 << 0)
131#define DAC33_MSBCLK (0x01 << 1)
132#define DAC33_AFMT_MASK (0x03 << 2)
133#define DAC33_AFMT_I2S (0x00 << 2)
134#define DAC33_AFMT_DSP (0x01 << 2)
135#define DAC33_AFMT_RIGHT_J (0x02 << 2)
136#define DAC33_AFMT_LEFT_J (0x03 << 2)
137#define DAC33_WLEN_MASK (0x03 << 4)
138#define DAC33_WLEN_16 (0x00 << 4)
139#define DAC33_WLEN_20 (0x01 << 4)
140#define DAC33_WLEN_24 (0x02 << 4)
141#define DAC33_WLEN_32 (0x03 << 4)
142#define DAC33_NCYCL_MASK (0x03 << 6)
143#define DAC33_NCYCL_16 (0x00 << 6)
144#define DAC33_NCYCL_20 (0x01 << 6)
145#define DAC33_NCYCL_24 (0x02 << 6)
146#define DAC33_NCYCL_32 (0x03 << 6)
147
148/* DAC33_SER_AUDIOIF_CTRL_B (0x13) */
149#define DAC33_DATA_DELAY_MASK (0x03 << 2)
150#define DAC33_DATA_DELAY(x) (x << 2)
151#define DAC33_BCLKON (0x01 << 5)
152
153/* DAC33_FIFO_CTRL_A (0x15) */
154#define DAC33_WIDTH (0x01 << 0)
155#define DAC33_FBYPAS (0x01 << 1)
156#define DAC33_FAUTO (0x01 << 2)
157#define DAC33_FIFOFLUSH (0x01 << 3)
158
159/*
160 * UTHR, ATHR, LTHR, PREFILL, NSAMPLE (0x16 - 0x1F)
161 * 13-bit values
162*/
163#define DAC33_THRREG(x) (((x) & 0x1FFF) << 3)
164
165/* DAC33_FIFO_IRQ_MASK (0x29) */
166#define DAC33_MNS (0x01 << 0)
167#define DAC33_MPS (0x01 << 1)
168#define DAC33_MAT (0x01 << 2)
169#define DAC33_MLT (0x01 << 3)
170#define DAC33_MUT (0x01 << 4)
171#define DAC33_MUF (0x01 << 5)
172#define DAC33_MOF (0x01 << 6)
173
174#define DAC33_FIFO_IRQ_MODE_MASK (0x03)
175#define DAC33_FIFO_IRQ_MODE_RISING (0x00)
176#define DAC33_FIFO_IRQ_MODE_FALLING (0x01)
177#define DAC33_FIFO_IRQ_MODE_LEVEL (0x02)
178#define DAC33_FIFO_IRQ_MODE_EDGE (0x03)
179
180/* DAC33_FIFO_IRQ_MODE_A (0x2A) */
181#define DAC33_UTM(x) (x << 0)
182#define DAC33_UFM(x) (x << 2)
183#define DAC33_OFM(x) (x << 4)
184
185/* DAC33_FIFO_IRQ_MODE_B (0x2B) */
186#define DAC33_NSM(x) (x << 0)
187#define DAC33_PSM(x) (x << 2)
188#define DAC33_ATM(x) (x << 4)
189#define DAC33_LTM(x) (x << 6)
190
191/* DAC33_DAC_CTRL_A (0x2C) */
192#define DAC33_DACRATE(x) (x << 0)
193#define DAC33_DACDUAL (0x01 << 4)
194#define DAC33_DACLKSEL_MASK (0x03 << 5)
195#define DAC33_DACLKSEL_INTSOC (0x00 << 5)
196#define DAC33_DACLKSEL_PLL (0x01 << 5)
197#define DAC33_DACLKSEL_MCLK (0x02 << 5)
198#define DAC33_DACLKSEL_BCLK (0x03 << 5)
199
200/* DAC33_DAC_CTRL_B (0x2D) */
201#define DAC33_DACSRCR_MASK (0x03 << 0)
202#define DAC33_DACSRCR_MUTE (0x00 << 0)
203#define DAC33_DACSRCR_RIGHT (0x01 << 0)
204#define DAC33_DACSRCR_LEFT (0x02 << 0)
205#define DAC33_DACSRCR_MONOMIX (0x03 << 0)
206#define DAC33_DACSRCL_MASK (0x03 << 2)
207#define DAC33_DACSRCL_MUTE (0x00 << 2)
208#define DAC33_DACSRCL_LEFT (0x01 << 2)
209#define DAC33_DACSRCL_RIGHT (0x02 << 2)
210#define DAC33_DACSRCL_MONOMIX (0x03 << 2)
211#define DAC33_DVOLSTEP_MASK (0x03 << 4)
212#define DAC33_DVOLSTEP_SS_PERFS (0x00 << 4)
213#define DAC33_DVOLSTEP_SS_PER2FS (0x01 << 4)
214#define DAC33_DVOLSTEP_SS_DISABLED (0x02 << 4)
215#define DAC33_DVOLCTRL_MASK (0x03 << 6)
216#define DAC33_DVOLCTRL_LR_INDEPENDENT1 (0x00 << 6)
217#define DAC33_DVOLCTRL_LR_RIGHT_CONTROL (0x01 << 6)
218#define DAC33_DVOLCTRL_LR_LEFT_CONTROL (0x02 << 6)
219#define DAC33_DVOLCTRL_LR_INDEPENDENT2 (0x03 << 6)
220
221/* DAC33_DAC_CTRL_C (0x2E) */
222#define DAC33_DEEMENR (0x01 << 0)
223#define DAC33_EFFENR (0x01 << 1)
224#define DAC33_DEEMENL (0x01 << 2)
225#define DAC33_EFFENL (0x01 << 3)
226#define DAC33_EN3D (0x01 << 4)
227#define DAC33_RESYNMUTE (0x01 << 5)
228#define DAC33_RESYNEN (0x01 << 6)
229
230/* DAC33_ASRC_CTRL_A (0x32) */
231#define DAC33_SRCBYP (0x01 << 0)
232#define DAC33_SRCLKSEL_MASK (0x03 << 1)
233#define DAC33_SRCLKSEL_INTSOC (0x00 << 1)
234#define DAC33_SRCLKSEL_PLL (0x01 << 1)
235#define DAC33_SRCLKSEL_MCLK (0x02 << 1)
236#define DAC33_SRCLKSEL_BCLK (0x03 << 1)
237#define DAC33_SRCLKDIV(x) (x << 3)
238
239/* DAC33_ASRC_CTRL_B (0x33) */
240#define DAC33_SRCSETUP(x) (x << 0)
241#define DAC33_SRCREFSEL (0x01 << 4)
242#define DAC33_SRCREFDIV(x) (x << 5)
243
244/* DAC33_INTP_CTRL_A (0x38) */
245#define DAC33_INTPSEL (0x01 << 0)
246#define DAC33_INTPM_MASK (0x03 << 1)
247#define DAC33_INTPM_ALOW_OPENDRAIN (0x00 << 1)
248#define DAC33_INTPM_ALOW (0x01 << 1)
249#define DAC33_INTPM_AHIGH (0x02 << 1)
250
251/* DAC33_LDAC_PWR_CTRL (0x40) */
252/* DAC33_RDAC_PWR_CTRL (0x41) */
253#define DAC33_DACLRNUM (0x01 << 2)
254#define DAC33_LROUT_GAIN(x) (x << 0)
255
256/* DAC33_ANA_VOL_SOFT_STEP_CTRL (0x49) */
257#define DAC33_VOLCLKSEL (0x01 << 0)
258#define DAC33_VOLCLKEN (0x01 << 1)
259#define DAC33_VOLBYPASS (0x01 << 2)
260
261#define TLV320DAC33_MCLK 0
262#define TLV320DAC33_SLEEPCLK 1
263
264extern struct snd_soc_dai dac33_dai;
265extern struct snd_soc_codec_device soc_codec_dev_tlv320dac33;
266
267#endif /* __TLV320DAC33_H */
diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
new file mode 100644
index 000000000000..6b650c1aa3d1
--- /dev/null
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -0,0 +1,463 @@
1/*
2 * ALSA SoC Texas Instruments TPA6130A2 headset stereo amplifier driver
3 *
4 * Copyright (C) Nokia Corporation
5 *
6 * Author: Peter Ujfalusi <peter.ujfalusi@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#include <linux/module.h>
24#include <linux/errno.h>
25#include <linux/device.h>
26#include <linux/i2c.h>
27#include <linux/gpio.h>
28#include <sound/tpa6130a2-plat.h>
29#include <sound/soc.h>
30#include <sound/soc-dapm.h>
31#include <sound/tlv.h>
32
33#include "tpa6130a2.h"
34
35static struct i2c_client *tpa6130a2_client;
36
37/* This struct is used to save the context */
38struct tpa6130a2_data {
39 struct mutex mutex;
40 unsigned char regs[TPA6130A2_CACHEREGNUM];
41 int power_gpio;
42 unsigned char power_state;
43};
44
45static int tpa6130a2_i2c_read(int reg)
46{
47 struct tpa6130a2_data *data;
48 int val;
49
50 BUG_ON(tpa6130a2_client == NULL);
51 data = i2c_get_clientdata(tpa6130a2_client);
52
53 /* If powered off, return the cached value */
54 if (data->power_state) {
55 val = i2c_smbus_read_byte_data(tpa6130a2_client, reg);
56 if (val < 0)
57 dev_err(&tpa6130a2_client->dev, "Read failed\n");
58 else
59 data->regs[reg] = val;
60 } else {
61 val = data->regs[reg];
62 }
63
64 return val;
65}
66
67static int tpa6130a2_i2c_write(int reg, u8 value)
68{
69 struct tpa6130a2_data *data;
70 int val = 0;
71
72 BUG_ON(tpa6130a2_client == NULL);
73 data = i2c_get_clientdata(tpa6130a2_client);
74
75 if (data->power_state) {
76 val = i2c_smbus_write_byte_data(tpa6130a2_client, reg, value);
77 if (val < 0)
78 dev_err(&tpa6130a2_client->dev, "Write failed\n");
79 }
80
81 /* Either powered on or off, we save the context */
82 data->regs[reg] = value;
83
84 return val;
85}
86
87static u8 tpa6130a2_read(int reg)
88{
89 struct tpa6130a2_data *data;
90
91 BUG_ON(tpa6130a2_client == NULL);
92 data = i2c_get_clientdata(tpa6130a2_client);
93
94 return data->regs[reg];
95}
96
97static void tpa6130a2_initialize(void)
98{
99 struct tpa6130a2_data *data;
100 int i;
101
102 BUG_ON(tpa6130a2_client == NULL);
103 data = i2c_get_clientdata(tpa6130a2_client);
104
105 for (i = 1; i < TPA6130A2_REG_VERSION; i++)
106 tpa6130a2_i2c_write(i, data->regs[i]);
107}
108
109static void tpa6130a2_power(int power)
110{
111 struct tpa6130a2_data *data;
112 u8 val;
113
114 BUG_ON(tpa6130a2_client == NULL);
115 data = i2c_get_clientdata(tpa6130a2_client);
116
117 mutex_lock(&data->mutex);
118 if (power) {
119 /* Power on */
120 if (data->power_gpio >= 0) {
121 gpio_set_value(data->power_gpio, 1);
122 data->power_state = 1;
123 tpa6130a2_initialize();
124 }
125 /* Clear SWS */
126 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
127 val &= ~TPA6130A2_SWS;
128 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
129 } else {
130 /* set SWS */
131 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
132 val |= TPA6130A2_SWS;
133 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
134 /* Power off */
135 if (data->power_gpio >= 0) {
136 gpio_set_value(data->power_gpio, 0);
137 data->power_state = 0;
138 }
139 }
140 mutex_unlock(&data->mutex);
141}
142
143static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol,
144 struct snd_ctl_elem_value *ucontrol)
145{
146 struct soc_mixer_control *mc =
147 (struct soc_mixer_control *)kcontrol->private_value;
148 struct tpa6130a2_data *data;
149 unsigned int reg = mc->reg;
150 unsigned int shift = mc->shift;
151 unsigned int mask = mc->max;
152 unsigned int invert = mc->invert;
153
154 BUG_ON(tpa6130a2_client == NULL);
155 data = i2c_get_clientdata(tpa6130a2_client);
156
157 mutex_lock(&data->mutex);
158
159 ucontrol->value.integer.value[0] =
160 (tpa6130a2_read(reg) >> shift) & mask;
161
162 if (invert)
163 ucontrol->value.integer.value[0] =
164 mask - ucontrol->value.integer.value[0];
165
166 mutex_unlock(&data->mutex);
167 return 0;
168}
169
170static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol,
171 struct snd_ctl_elem_value *ucontrol)
172{
173 struct soc_mixer_control *mc =
174 (struct soc_mixer_control *)kcontrol->private_value;
175 struct tpa6130a2_data *data;
176 unsigned int reg = mc->reg;
177 unsigned int shift = mc->shift;
178 unsigned int mask = mc->max;
179 unsigned int invert = mc->invert;
180 unsigned int val = (ucontrol->value.integer.value[0] & mask);
181 unsigned int val_reg;
182
183 BUG_ON(tpa6130a2_client == NULL);
184 data = i2c_get_clientdata(tpa6130a2_client);
185
186 if (invert)
187 val = mask - val;
188
189 mutex_lock(&data->mutex);
190
191 val_reg = tpa6130a2_read(reg);
192 if (((val_reg >> shift) & mask) == val) {
193 mutex_unlock(&data->mutex);
194 return 0;
195 }
196
197 val_reg &= ~(mask << shift);
198 val_reg |= val << shift;
199 tpa6130a2_i2c_write(reg, val_reg);
200
201 mutex_unlock(&data->mutex);
202
203 return 1;
204}
205
206/*
207 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
208 * down in gain.
209 */
210static const unsigned int tpa6130_tlv[] = {
211 TLV_DB_RANGE_HEAD(10),
212 0, 1, TLV_DB_SCALE_ITEM(-5950, 600, 0),
213 2, 3, TLV_DB_SCALE_ITEM(-5000, 250, 0),
214 4, 5, TLV_DB_SCALE_ITEM(-4550, 160, 0),
215 6, 7, TLV_DB_SCALE_ITEM(-4140, 190, 0),
216 8, 9, TLV_DB_SCALE_ITEM(-3650, 120, 0),
217 10, 11, TLV_DB_SCALE_ITEM(-3330, 160, 0),
218 12, 13, TLV_DB_SCALE_ITEM(-3040, 180, 0),
219 14, 20, TLV_DB_SCALE_ITEM(-2710, 110, 0),
220 21, 37, TLV_DB_SCALE_ITEM(-1960, 74, 0),
221 38, 63, TLV_DB_SCALE_ITEM(-720, 45, 0),
222};
223
224static const struct snd_kcontrol_new tpa6130a2_controls[] = {
225 SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume",
226 TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
227 tpa6130a2_get_reg, tpa6130a2_set_reg,
228 tpa6130_tlv),
229};
230
231/*
232 * Enable or disable channel (left or right)
233 * The bit number for mute and amplifier are the same per channel:
234 * bit 6: Right channel
235 * bit 7: Left channel
236 * in both registers.
237 */
238static void tpa6130a2_channel_enable(u8 channel, int enable)
239{
240 struct tpa6130a2_data *data;
241 u8 val;
242
243 BUG_ON(tpa6130a2_client == NULL);
244 data = i2c_get_clientdata(tpa6130a2_client);
245
246 if (enable) {
247 /* Enable channel */
248 /* Enable amplifier */
249 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
250 val |= channel;
251 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
252
253 /* Unmute channel */
254 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
255 val &= ~channel;
256 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
257 } else {
258 /* Disable channel */
259 /* Mute channel */
260 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
261 val |= channel;
262 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
263
264 /* Disable amplifier */
265 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
266 val &= ~channel;
267 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
268 }
269}
270
271static int tpa6130a2_left_event(struct snd_soc_dapm_widget *w,
272 struct snd_kcontrol *kcontrol, int event)
273{
274 switch (event) {
275 case SND_SOC_DAPM_POST_PMU:
276 tpa6130a2_channel_enable(TPA6130A2_HP_EN_L, 1);
277 break;
278 case SND_SOC_DAPM_POST_PMD:
279 tpa6130a2_channel_enable(TPA6130A2_HP_EN_L, 0);
280 break;
281 }
282 return 0;
283}
284
285static int tpa6130a2_right_event(struct snd_soc_dapm_widget *w,
286 struct snd_kcontrol *kcontrol, int event)
287{
288 switch (event) {
289 case SND_SOC_DAPM_POST_PMU:
290 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R, 1);
291 break;
292 case SND_SOC_DAPM_POST_PMD:
293 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R, 0);
294 break;
295 }
296 return 0;
297}
298
299static int tpa6130a2_supply_event(struct snd_soc_dapm_widget *w,
300 struct snd_kcontrol *kcontrol, int event)
301{
302 switch (event) {
303 case SND_SOC_DAPM_POST_PMU:
304 tpa6130a2_power(1);
305 break;
306 case SND_SOC_DAPM_POST_PMD:
307 tpa6130a2_power(0);
308 break;
309 }
310 return 0;
311}
312
313static const struct snd_soc_dapm_widget tpa6130a2_dapm_widgets[] = {
314 SND_SOC_DAPM_PGA_E("TPA6130A2 Left", SND_SOC_NOPM,
315 0, 0, NULL, 0, tpa6130a2_left_event,
316 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
317 SND_SOC_DAPM_PGA_E("TPA6130A2 Right", SND_SOC_NOPM,
318 0, 0, NULL, 0, tpa6130a2_right_event,
319 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
320 SND_SOC_DAPM_SUPPLY("TPA6130A2 Enable", SND_SOC_NOPM,
321 0, 0, tpa6130a2_supply_event,
322 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
323 /* Outputs */
324 SND_SOC_DAPM_HP("TPA6130A2 Headphone Left", NULL),
325 SND_SOC_DAPM_HP("TPA6130A2 Headphone Right", NULL),
326};
327
328static const struct snd_soc_dapm_route audio_map[] = {
329 {"TPA6130A2 Headphone Left", NULL, "TPA6130A2 Left"},
330 {"TPA6130A2 Headphone Right", NULL, "TPA6130A2 Right"},
331
332 {"TPA6130A2 Headphone Left", NULL, "TPA6130A2 Enable"},
333 {"TPA6130A2 Headphone Right", NULL, "TPA6130A2 Enable"},
334};
335
336int tpa6130a2_add_controls(struct snd_soc_codec *codec)
337{
338 snd_soc_dapm_new_controls(codec, tpa6130a2_dapm_widgets,
339 ARRAY_SIZE(tpa6130a2_dapm_widgets));
340
341 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
342
343 return snd_soc_add_controls(codec, tpa6130a2_controls,
344 ARRAY_SIZE(tpa6130a2_controls));
345
346}
347EXPORT_SYMBOL_GPL(tpa6130a2_add_controls);
348
349static int tpa6130a2_probe(struct i2c_client *client,
350 const struct i2c_device_id *id)
351{
352 struct device *dev;
353 struct tpa6130a2_data *data;
354 struct tpa6130a2_platform_data *pdata;
355 int ret;
356
357 dev = &client->dev;
358
359 if (client->dev.platform_data == NULL) {
360 dev_err(dev, "Platform data not set\n");
361 dump_stack();
362 return -ENODEV;
363 }
364
365 data = kzalloc(sizeof(*data), GFP_KERNEL);
366 if (data == NULL) {
367 dev_err(dev, "Can not allocate memory\n");
368 return -ENOMEM;
369 }
370
371 tpa6130a2_client = client;
372
373 i2c_set_clientdata(tpa6130a2_client, data);
374
375 pdata = client->dev.platform_data;
376 data->power_gpio = pdata->power_gpio;
377
378 mutex_init(&data->mutex);
379
380 /* Set default register values */
381 data->regs[TPA6130A2_REG_CONTROL] = TPA6130A2_SWS;
382 data->regs[TPA6130A2_REG_VOL_MUTE] = TPA6130A2_MUTE_R |
383 TPA6130A2_MUTE_L;
384
385 if (data->power_gpio >= 0) {
386 ret = gpio_request(data->power_gpio, "tpa6130a2 enable");
387 if (ret < 0) {
388 dev_err(dev, "Failed to request power GPIO (%d)\n",
389 data->power_gpio);
390 goto fail;
391 }
392 gpio_direction_output(data->power_gpio, 0);
393 } else {
394 data->power_state = 1;
395 tpa6130a2_initialize();
396 }
397
398 tpa6130a2_power(1);
399
400 /* Read version */
401 ret = tpa6130a2_i2c_read(TPA6130A2_REG_VERSION) &
402 TPA6130A2_VERSION_MASK;
403 if ((ret != 1) && (ret != 2))
404 dev_warn(dev, "UNTESTED version detected (%d)\n", ret);
405
406 /* Disable the chip */
407 tpa6130a2_power(0);
408
409 return 0;
410fail:
411 kfree(data);
412 i2c_set_clientdata(tpa6130a2_client, NULL);
413 tpa6130a2_client = NULL;
414
415 return ret;
416}
417
418static int tpa6130a2_remove(struct i2c_client *client)
419{
420 struct tpa6130a2_data *data = i2c_get_clientdata(client);
421
422 tpa6130a2_power(0);
423
424 if (data->power_gpio >= 0)
425 gpio_free(data->power_gpio);
426 kfree(data);
427 tpa6130a2_client = NULL;
428
429 return 0;
430}
431
432static const struct i2c_device_id tpa6130a2_id[] = {
433 { "tpa6130a2", 0 },
434 { }
435};
436MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
437
438static struct i2c_driver tpa6130a2_i2c_driver = {
439 .driver = {
440 .name = "tpa6130a2",
441 .owner = THIS_MODULE,
442 },
443 .probe = tpa6130a2_probe,
444 .remove = __devexit_p(tpa6130a2_remove),
445 .id_table = tpa6130a2_id,
446};
447
448static int __init tpa6130a2_init(void)
449{
450 return i2c_add_driver(&tpa6130a2_i2c_driver);
451}
452
453static void __exit tpa6130a2_exit(void)
454{
455 i2c_del_driver(&tpa6130a2_i2c_driver);
456}
457
458MODULE_AUTHOR("Peter Ujfalusi");
459MODULE_DESCRIPTION("TPA6130A2 Headphone amplifier driver");
460MODULE_LICENSE("GPL");
461
462module_init(tpa6130a2_init);
463module_exit(tpa6130a2_exit);
diff --git a/sound/soc/codecs/tpa6130a2.h b/sound/soc/codecs/tpa6130a2.h
new file mode 100644
index 000000000000..57e867fd86d1
--- /dev/null
+++ b/sound/soc/codecs/tpa6130a2.h
@@ -0,0 +1,61 @@
1/*
2 * ALSA SoC TPA6130A2 amplifier driver
3 *
4 * Copyright (C) Nokia Corporation
5 *
6 * Author: Peter Ujfalusi <peter.ujfalusi@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 __TPA6130A2_H__
25#define __TPA6130A2_H__
26
27/* Register addresses */
28#define TPA6130A2_REG_CONTROL 0x01
29#define TPA6130A2_REG_VOL_MUTE 0x02
30#define TPA6130A2_REG_OUT_IMPEDANCE 0x03
31#define TPA6130A2_REG_VERSION 0x04
32
33#define TPA6130A2_CACHEREGNUM (TPA6130A2_REG_VERSION + 1)
34
35/* Register bits */
36/* TPA6130A2_REG_CONTROL (0x01) */
37#define TPA6130A2_SWS (0x01 << 0)
38#define TPA6130A2_TERMAL (0x01 << 1)
39#define TPA6130A2_MODE(x) (x << 4)
40#define TPA6130A2_MODE_STEREO (0x00)
41#define TPA6130A2_MODE_DUAL_MONO (0x01)
42#define TPA6130A2_MODE_BRIDGE (0x02)
43#define TPA6130A2_MODE_MASK (0x03)
44#define TPA6130A2_HP_EN_R (0x01 << 6)
45#define TPA6130A2_HP_EN_L (0x01 << 7)
46
47/* TPA6130A2_REG_VOL_MUTE (0x02) */
48#define TPA6130A2_VOLUME(x) ((x & 0x3f) << 0)
49#define TPA6130A2_MUTE_R (0x01 << 6)
50#define TPA6130A2_MUTE_L (0x01 << 7)
51
52/* TPA6130A2_REG_OUT_IMPEDANCE (0x03) */
53#define TPA6130A2_HIZ_R (0x01 << 0)
54#define TPA6130A2_HIZ_L (0x01 << 1)
55
56/* TPA6130A2_REG_VERSION (0x04) */
57#define TPA6130A2_VERSION_MASK (0x0f)
58
59extern int tpa6130a2_add_controls(struct snd_soc_codec *codec);
60
61#endif /* __TPA6130A2_H__ */
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 4df7c6c61c76..5f1681f6ca76 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -120,9 +120,10 @@ static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = {
120 120
121/* codec private data */ 121/* codec private data */
122struct twl4030_priv { 122struct twl4030_priv {
123 unsigned int bypass_state; 123 struct snd_soc_codec codec;
124
124 unsigned int codec_powered; 125 unsigned int codec_powered;
125 unsigned int codec_muted; 126 unsigned int apll_enabled;
126 127
127 struct snd_pcm_substream *master_substream; 128 struct snd_pcm_substream *master_substream;
128 struct snd_pcm_substream *slave_substream; 129 struct snd_pcm_substream *slave_substream;
@@ -183,19 +184,20 @@ static int twl4030_write(struct snd_soc_codec *codec,
183static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable) 184static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
184{ 185{
185 struct twl4030_priv *twl4030 = codec->private_data; 186 struct twl4030_priv *twl4030 = codec->private_data;
186 u8 mode; 187 int mode;
187 188
188 if (enable == twl4030->codec_powered) 189 if (enable == twl4030->codec_powered)
189 return; 190 return;
190 191
191 mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE);
192 if (enable) 192 if (enable)
193 mode |= TWL4030_CODECPDZ; 193 mode = twl4030_codec_enable_resource(TWL4030_CODEC_RES_POWER);
194 else 194 else
195 mode &= ~TWL4030_CODECPDZ; 195 mode = twl4030_codec_disable_resource(TWL4030_CODEC_RES_POWER);
196 196
197 twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode); 197 if (mode >= 0) {
198 twl4030->codec_powered = enable; 198 twl4030_write_reg_cache(codec, TWL4030_REG_CODEC_MODE, mode);
199 twl4030->codec_powered = enable;
200 }
199 201
200 /* REVISIT: this delay is present in TI sample drivers */ 202 /* REVISIT: this delay is present in TI sample drivers */
201 /* but there seems to be no TRM requirement for it */ 203 /* but there seems to be no TRM requirement for it */
@@ -212,31 +214,30 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
212 214
213 /* set all audio section registers to reasonable defaults */ 215 /* set all audio section registers to reasonable defaults */
214 for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++) 216 for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++)
215 twl4030_write(codec, i, cache[i]); 217 if (i != TWL4030_REG_APLL_CTL)
218 twl4030_write(codec, i, cache[i]);
216 219
217} 220}
218 221
219static void twl4030_codec_mute(struct snd_soc_codec *codec, int mute) 222static void twl4030_apll_enable(struct snd_soc_codec *codec, int enable)
220{ 223{
221 struct twl4030_priv *twl4030 = codec->private_data; 224 struct twl4030_priv *twl4030 = codec->private_data;
222 u8 reg_val; 225 int status;
223 226
224 if (mute == twl4030->codec_muted) 227 if (enable == twl4030->apll_enabled)
225 return; 228 return;
226 229
227 if (mute) { 230 if (enable)
228 /* Disable PLL */
229 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_APLL_CTL);
230 reg_val &= ~TWL4030_APLL_EN;
231 twl4030_write(codec, TWL4030_REG_APLL_CTL, reg_val);
232 } else {
233 /* Enable PLL */ 231 /* Enable PLL */
234 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_APLL_CTL); 232 status = twl4030_codec_enable_resource(TWL4030_CODEC_RES_APLL);
235 reg_val |= TWL4030_APLL_EN; 233 else
236 twl4030_write(codec, TWL4030_REG_APLL_CTL, reg_val); 234 /* Disable PLL */
237 } 235 status = twl4030_codec_disable_resource(TWL4030_CODEC_RES_APLL);
236
237 if (status >= 0)
238 twl4030_write_reg_cache(codec, TWL4030_REG_APLL_CTL, status);
238 239
239 twl4030->codec_muted = mute; 240 twl4030->apll_enabled = enable;
240} 241}
241 242
242static void twl4030_power_up(struct snd_soc_codec *codec) 243static void twl4030_power_up(struct snd_soc_codec *codec)
@@ -613,6 +614,27 @@ static int handsfreerpga_event(struct snd_soc_dapm_widget *w,
613 return 0; 614 return 0;
614} 615}
615 616
617static int vibramux_event(struct snd_soc_dapm_widget *w,
618 struct snd_kcontrol *kcontrol, int event)
619{
620 twl4030_write(w->codec, TWL4030_REG_VIBRA_SET, 0xff);
621 return 0;
622}
623
624static int apll_event(struct snd_soc_dapm_widget *w,
625 struct snd_kcontrol *kcontrol, int event)
626{
627 switch (event) {
628 case SND_SOC_DAPM_PRE_PMU:
629 twl4030_apll_enable(w->codec, 1);
630 break;
631 case SND_SOC_DAPM_POST_PMD:
632 twl4030_apll_enable(w->codec, 0);
633 break;
634 }
635 return 0;
636}
637
616static void headset_ramp(struct snd_soc_codec *codec, int ramp) 638static void headset_ramp(struct snd_soc_codec *codec, int ramp)
617{ 639{
618 struct snd_soc_device *socdev = codec->socdev; 640 struct snd_soc_device *socdev = codec->socdev;
@@ -724,67 +746,6 @@ static int headsetrpga_event(struct snd_soc_dapm_widget *w,
724 return 0; 746 return 0;
725} 747}
726 748
727static int bypass_event(struct snd_soc_dapm_widget *w,
728 struct snd_kcontrol *kcontrol, int event)
729{
730 struct soc_mixer_control *m =
731 (struct soc_mixer_control *)w->kcontrols->private_value;
732 struct twl4030_priv *twl4030 = w->codec->private_data;
733 unsigned char reg, misc;
734
735 reg = twl4030_read_reg_cache(w->codec, m->reg);
736
737 /*
738 * bypass_state[0:3] - analog HiFi bypass
739 * bypass_state[4] - analog voice bypass
740 * bypass_state[5] - digital voice bypass
741 * bypass_state[6:7] - digital HiFi bypass
742 */
743 if (m->reg == TWL4030_REG_VSTPGA) {
744 /* Voice digital bypass */
745 if (reg)
746 twl4030->bypass_state |= (1 << 5);
747 else
748 twl4030->bypass_state &= ~(1 << 5);
749 } else if (m->reg <= TWL4030_REG_ARXR2_APGA_CTL) {
750 /* Analog bypass */
751 if (reg & (1 << m->shift))
752 twl4030->bypass_state |=
753 (1 << (m->reg - TWL4030_REG_ARXL1_APGA_CTL));
754 else
755 twl4030->bypass_state &=
756 ~(1 << (m->reg - TWL4030_REG_ARXL1_APGA_CTL));
757 } else if (m->reg == TWL4030_REG_VDL_APGA_CTL) {
758 /* Analog voice bypass */
759 if (reg & (1 << m->shift))
760 twl4030->bypass_state |= (1 << 4);
761 else
762 twl4030->bypass_state &= ~(1 << 4);
763 } else {
764 /* Digital bypass */
765 if (reg & (0x7 << m->shift))
766 twl4030->bypass_state |= (1 << (m->shift ? 7 : 6));
767 else
768 twl4030->bypass_state &= ~(1 << (m->shift ? 7 : 6));
769 }
770
771 /* Enable master analog loopback mode if any analog switch is enabled*/
772 misc = twl4030_read_reg_cache(w->codec, TWL4030_REG_MISC_SET_1);
773 if (twl4030->bypass_state & 0x1F)
774 misc |= TWL4030_FMLOOP_EN;
775 else
776 misc &= ~TWL4030_FMLOOP_EN;
777 twl4030_write(w->codec, TWL4030_REG_MISC_SET_1, misc);
778
779 if (w->codec->bias_level == SND_SOC_BIAS_STANDBY) {
780 if (twl4030->bypass_state)
781 twl4030_codec_mute(w->codec, 0);
782 else
783 twl4030_codec_mute(w->codec, 1);
784 }
785 return 0;
786}
787
788/* 749/*
789 * Some of the gain controls in TWL (mostly those which are associated with 750 * Some of the gain controls in TWL (mostly those which are associated with
790 * the outputs) are implemented in an interesting way: 751 * the outputs) are implemented in an interesting way:
@@ -1192,32 +1153,28 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
1192 SND_SOC_NOPM, 0, 0), 1153 SND_SOC_NOPM, 0, 0),
1193 1154
1194 /* Analog bypasses */ 1155 /* Analog bypasses */
1195 SND_SOC_DAPM_SWITCH_E("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0, 1156 SND_SOC_DAPM_SWITCH("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0,
1196 &twl4030_dapm_abypassr1_control, bypass_event, 1157 &twl4030_dapm_abypassr1_control),
1197 SND_SOC_DAPM_POST_REG), 1158 SND_SOC_DAPM_SWITCH("Left1 Analog Loopback", SND_SOC_NOPM, 0, 0,
1198 SND_SOC_DAPM_SWITCH_E("Left1 Analog Loopback", SND_SOC_NOPM, 0, 0, 1159 &twl4030_dapm_abypassl1_control),
1199 &twl4030_dapm_abypassl1_control, 1160 SND_SOC_DAPM_SWITCH("Right2 Analog Loopback", SND_SOC_NOPM, 0, 0,
1200 bypass_event, SND_SOC_DAPM_POST_REG), 1161 &twl4030_dapm_abypassr2_control),
1201 SND_SOC_DAPM_SWITCH_E("Right2 Analog Loopback", SND_SOC_NOPM, 0, 0, 1162 SND_SOC_DAPM_SWITCH("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0,
1202 &twl4030_dapm_abypassr2_control, 1163 &twl4030_dapm_abypassl2_control),
1203 bypass_event, SND_SOC_DAPM_POST_REG), 1164 SND_SOC_DAPM_SWITCH("Voice Analog Loopback", SND_SOC_NOPM, 0, 0,
1204 SND_SOC_DAPM_SWITCH_E("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0, 1165 &twl4030_dapm_abypassv_control),
1205 &twl4030_dapm_abypassl2_control, 1166
1206 bypass_event, SND_SOC_DAPM_POST_REG), 1167 /* Master analog loopback switch */
1207 SND_SOC_DAPM_SWITCH_E("Voice Analog Loopback", SND_SOC_NOPM, 0, 0, 1168 SND_SOC_DAPM_SUPPLY("FM Loop Enable", TWL4030_REG_MISC_SET_1, 5, 0,
1208 &twl4030_dapm_abypassv_control, 1169 NULL, 0),
1209 bypass_event, SND_SOC_DAPM_POST_REG),
1210 1170
1211 /* Digital bypasses */ 1171 /* Digital bypasses */
1212 SND_SOC_DAPM_SWITCH_E("Left Digital Loopback", SND_SOC_NOPM, 0, 0, 1172 SND_SOC_DAPM_SWITCH("Left Digital Loopback", SND_SOC_NOPM, 0, 0,
1213 &twl4030_dapm_dbypassl_control, bypass_event, 1173 &twl4030_dapm_dbypassl_control),
1214 SND_SOC_DAPM_POST_REG), 1174 SND_SOC_DAPM_SWITCH("Right Digital Loopback", SND_SOC_NOPM, 0, 0,
1215 SND_SOC_DAPM_SWITCH_E("Right Digital Loopback", SND_SOC_NOPM, 0, 0, 1175 &twl4030_dapm_dbypassr_control),
1216 &twl4030_dapm_dbypassr_control, bypass_event, 1176 SND_SOC_DAPM_SWITCH("Voice Digital Loopback", SND_SOC_NOPM, 0, 0,
1217 SND_SOC_DAPM_POST_REG), 1177 &twl4030_dapm_dbypassv_control),
1218 SND_SOC_DAPM_SWITCH_E("Voice Digital Loopback", SND_SOC_NOPM, 0, 0,
1219 &twl4030_dapm_dbypassv_control, bypass_event,
1220 SND_SOC_DAPM_POST_REG),
1221 1178
1222 /* Digital mixers, power control for the physical DACs */ 1179 /* Digital mixers, power control for the physical DACs */
1223 SND_SOC_DAPM_MIXER("Digital R1 Playback Mixer", 1180 SND_SOC_DAPM_MIXER("Digital R1 Playback Mixer",
@@ -1243,6 +1200,9 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
1243 SND_SOC_DAPM_MIXER("Analog Voice Playback Mixer", 1200 SND_SOC_DAPM_MIXER("Analog Voice Playback Mixer",
1244 TWL4030_REG_VDL_APGA_CTL, 0, 0, NULL, 0), 1201 TWL4030_REG_VDL_APGA_CTL, 0, 0, NULL, 0),
1245 1202
1203 SND_SOC_DAPM_SUPPLY("APLL Enable", SND_SOC_NOPM, 0, 0, apll_event,
1204 SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
1205
1246 /* Output MIXER controls */ 1206 /* Output MIXER controls */
1247 /* Earpiece */ 1207 /* Earpiece */
1248 SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0, 1208 SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
@@ -1308,8 +1268,9 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
1308 0, 0, NULL, 0, handsfreerpga_event, 1268 0, 0, NULL, 0, handsfreerpga_event,
1309 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD), 1269 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
1310 /* Vibra */ 1270 /* Vibra */
1311 SND_SOC_DAPM_MUX("Vibra Mux", TWL4030_REG_VIBRA_CTL, 0, 0, 1271 SND_SOC_DAPM_MUX_E("Vibra Mux", TWL4030_REG_VIBRA_CTL, 0, 0,
1312 &twl4030_dapm_vibra_control), 1272 &twl4030_dapm_vibra_control, vibramux_event,
1273 SND_SOC_DAPM_PRE_PMU),
1313 SND_SOC_DAPM_MUX("Vibra Route", SND_SOC_NOPM, 0, 0, 1274 SND_SOC_DAPM_MUX("Vibra Route", SND_SOC_NOPM, 0, 0,
1314 &twl4030_dapm_vibrapath_control), 1275 &twl4030_dapm_vibrapath_control),
1315 1276
@@ -1369,6 +1330,13 @@ static const struct snd_soc_dapm_route intercon[] = {
1369 {"Digital R2 Playback Mixer", NULL, "DAC Right2"}, 1330 {"Digital R2 Playback Mixer", NULL, "DAC Right2"},
1370 {"Digital Voice Playback Mixer", NULL, "DAC Voice"}, 1331 {"Digital Voice Playback Mixer", NULL, "DAC Voice"},
1371 1332
1333 /* Supply for the digital part (APLL) */
1334 {"Digital R1 Playback Mixer", NULL, "APLL Enable"},
1335 {"Digital L1 Playback Mixer", NULL, "APLL Enable"},
1336 {"Digital R2 Playback Mixer", NULL, "APLL Enable"},
1337 {"Digital L2 Playback Mixer", NULL, "APLL Enable"},
1338 {"Digital Voice Playback Mixer", NULL, "APLL Enable"},
1339
1372 {"Analog L1 Playback Mixer", NULL, "Digital L1 Playback Mixer"}, 1340 {"Analog L1 Playback Mixer", NULL, "Digital L1 Playback Mixer"},
1373 {"Analog R1 Playback Mixer", NULL, "Digital R1 Playback Mixer"}, 1341 {"Analog R1 Playback Mixer", NULL, "Digital R1 Playback Mixer"},
1374 {"Analog L2 Playback Mixer", NULL, "Digital L2 Playback Mixer"}, 1342 {"Analog L2 Playback Mixer", NULL, "Digital L2 Playback Mixer"},
@@ -1482,6 +1450,11 @@ static const struct snd_soc_dapm_route intercon[] = {
1482 {"ADC Virtual Left2", NULL, "TX2 Capture Route"}, 1450 {"ADC Virtual Left2", NULL, "TX2 Capture Route"},
1483 {"ADC Virtual Right2", NULL, "TX2 Capture Route"}, 1451 {"ADC Virtual Right2", NULL, "TX2 Capture Route"},
1484 1452
1453 {"ADC Virtual Left1", NULL, "APLL Enable"},
1454 {"ADC Virtual Right1", NULL, "APLL Enable"},
1455 {"ADC Virtual Left2", NULL, "APLL Enable"},
1456 {"ADC Virtual Right2", NULL, "APLL Enable"},
1457
1485 /* Analog bypass routes */ 1458 /* Analog bypass routes */
1486 {"Right1 Analog Loopback", "Switch", "Analog Right"}, 1459 {"Right1 Analog Loopback", "Switch", "Analog Right"},
1487 {"Left1 Analog Loopback", "Switch", "Analog Left"}, 1460 {"Left1 Analog Loopback", "Switch", "Analog Left"},
@@ -1489,6 +1462,13 @@ static const struct snd_soc_dapm_route intercon[] = {
1489 {"Left2 Analog Loopback", "Switch", "Analog Left"}, 1462 {"Left2 Analog Loopback", "Switch", "Analog Left"},
1490 {"Voice Analog Loopback", "Switch", "Analog Left"}, 1463 {"Voice Analog Loopback", "Switch", "Analog Left"},
1491 1464
1465 /* Supply for the Analog loopbacks */
1466 {"Right1 Analog Loopback", NULL, "FM Loop Enable"},
1467 {"Left1 Analog Loopback", NULL, "FM Loop Enable"},
1468 {"Right2 Analog Loopback", NULL, "FM Loop Enable"},
1469 {"Left2 Analog Loopback", NULL, "FM Loop Enable"},
1470 {"Voice Analog Loopback", NULL, "FM Loop Enable"},
1471
1492 {"Analog R1 Playback Mixer", NULL, "Right1 Analog Loopback"}, 1472 {"Analog R1 Playback Mixer", NULL, "Right1 Analog Loopback"},
1493 {"Analog L1 Playback Mixer", NULL, "Left1 Analog Loopback"}, 1473 {"Analog L1 Playback Mixer", NULL, "Left1 Analog Loopback"},
1494 {"Analog R2 Playback Mixer", NULL, "Right2 Analog Loopback"}, 1474 {"Analog R2 Playback Mixer", NULL, "Right2 Analog Loopback"},
@@ -1513,32 +1493,20 @@ static int twl4030_add_widgets(struct snd_soc_codec *codec)
1513 1493
1514 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 1494 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
1515 1495
1516 snd_soc_dapm_new_widgets(codec);
1517 return 0; 1496 return 0;
1518} 1497}
1519 1498
1520static int twl4030_set_bias_level(struct snd_soc_codec *codec, 1499static int twl4030_set_bias_level(struct snd_soc_codec *codec,
1521 enum snd_soc_bias_level level) 1500 enum snd_soc_bias_level level)
1522{ 1501{
1523 struct twl4030_priv *twl4030 = codec->private_data;
1524
1525 switch (level) { 1502 switch (level) {
1526 case SND_SOC_BIAS_ON: 1503 case SND_SOC_BIAS_ON:
1527 twl4030_codec_mute(codec, 0);
1528 break; 1504 break;
1529 case SND_SOC_BIAS_PREPARE: 1505 case SND_SOC_BIAS_PREPARE:
1530 twl4030_power_up(codec);
1531 if (twl4030->bypass_state)
1532 twl4030_codec_mute(codec, 0);
1533 else
1534 twl4030_codec_mute(codec, 1);
1535 break; 1506 break;
1536 case SND_SOC_BIAS_STANDBY: 1507 case SND_SOC_BIAS_STANDBY:
1537 twl4030_power_up(codec); 1508 if (codec->bias_level == SND_SOC_BIAS_OFF)
1538 if (twl4030->bypass_state) 1509 twl4030_power_up(codec);
1539 twl4030_codec_mute(codec, 0);
1540 else
1541 twl4030_codec_mute(codec, 1);
1542 break; 1510 break;
1543 case SND_SOC_BIAS_OFF: 1511 case SND_SOC_BIAS_OFF:
1544 twl4030_power_down(codec); 1512 twl4030_power_down(codec);
@@ -1785,29 +1753,23 @@ static int twl4030_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1785{ 1753{
1786 struct snd_soc_codec *codec = codec_dai->codec; 1754 struct snd_soc_codec *codec = codec_dai->codec;
1787 struct twl4030_priv *twl4030 = codec->private_data; 1755 struct twl4030_priv *twl4030 = codec->private_data;
1788 u8 infreq;
1789 1756
1790 switch (freq) { 1757 switch (freq) {
1791 case 19200000: 1758 case 19200000:
1792 infreq = TWL4030_APLL_INFREQ_19200KHZ;
1793 twl4030->sysclk = 19200;
1794 break;
1795 case 26000000: 1759 case 26000000:
1796 infreq = TWL4030_APLL_INFREQ_26000KHZ;
1797 twl4030->sysclk = 26000;
1798 break;
1799 case 38400000: 1760 case 38400000:
1800 infreq = TWL4030_APLL_INFREQ_38400KHZ;
1801 twl4030->sysclk = 38400;
1802 break; 1761 break;
1803 default: 1762 default:
1804 printk(KERN_ERR "TWL4030 set sysclk: unknown rate %d\n", 1763 dev_err(codec->dev, "Unsupported APLL mclk: %u\n", freq);
1805 freq);
1806 return -EINVAL; 1764 return -EINVAL;
1807 } 1765 }
1808 1766
1809 infreq |= TWL4030_APLL_EN; 1767 if ((freq / 1000) != twl4030->sysclk) {
1810 twl4030_write(codec, TWL4030_REG_APLL_CTL, infreq); 1768 dev_err(codec->dev,
1769 "Mismatch in APLL mclk: %u (configured: %u)\n",
1770 freq, twl4030->sysclk * 1000);
1771 return -EINVAL;
1772 }
1811 1773
1812 return 0; 1774 return 0;
1813} 1775}
@@ -1905,18 +1867,16 @@ static int twl4030_voice_startup(struct snd_pcm_substream *substream,
1905 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1867 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1906 struct snd_soc_device *socdev = rtd->socdev; 1868 struct snd_soc_device *socdev = rtd->socdev;
1907 struct snd_soc_codec *codec = socdev->card->codec; 1869 struct snd_soc_codec *codec = socdev->card->codec;
1908 u8 infreq; 1870 struct twl4030_priv *twl4030 = codec->private_data;
1909 u8 mode; 1871 u8 mode;
1910 1872
1911 /* If the system master clock is not 26MHz, the voice PCM interface is 1873 /* If the system master clock is not 26MHz, the voice PCM interface is
1912 * not avilable. 1874 * not avilable.
1913 */ 1875 */
1914 infreq = twl4030_read_reg_cache(codec, TWL4030_REG_APLL_CTL) 1876 if (twl4030->sysclk != 26000) {
1915 & TWL4030_APLL_INFREQ; 1877 dev_err(codec->dev, "The board is configured for %u Hz, while"
1916 1878 "the Voice interface needs 26MHz APLL mclk\n",
1917 if (infreq != TWL4030_APLL_INFREQ_26000KHZ) { 1879 twl4030->sysclk * 1000);
1918 printk(KERN_ERR "TWL4030 voice startup: "
1919 "MCLK is not 26MHz, call set_sysclk() on init\n");
1920 return -EINVAL; 1880 return -EINVAL;
1921 } 1881 }
1922 1882
@@ -1989,21 +1949,19 @@ static int twl4030_voice_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1989 int clk_id, unsigned int freq, int dir) 1949 int clk_id, unsigned int freq, int dir)
1990{ 1950{
1991 struct snd_soc_codec *codec = codec_dai->codec; 1951 struct snd_soc_codec *codec = codec_dai->codec;
1992 u8 infreq; 1952 struct twl4030_priv *twl4030 = codec->private_data;
1993 1953
1994 switch (freq) { 1954 if (freq != 26000000) {
1995 case 26000000: 1955 dev_err(codec->dev, "Unsupported APLL mclk: %u, the Voice"
1996 infreq = TWL4030_APLL_INFREQ_26000KHZ; 1956 "interface needs 26MHz APLL mclk\n", freq);
1997 break; 1957 return -EINVAL;
1998 default: 1958 }
1999 printk(KERN_ERR "TWL4030 voice set sysclk: unknown rate %d\n", 1959 if ((freq / 1000) != twl4030->sysclk) {
2000 freq); 1960 dev_err(codec->dev,
1961 "Mismatch in APLL mclk: %u (configured: %u)\n",
1962 freq, twl4030->sysclk * 1000);
2001 return -EINVAL; 1963 return -EINVAL;
2002 } 1964 }
2003
2004 infreq |= TWL4030_APLL_EN;
2005 twl4030_write(codec, TWL4030_REG_APLL_CTL, infreq);
2006
2007 return 0; 1965 return 0;
2008} 1966}
2009 1967
@@ -2121,7 +2079,7 @@ struct snd_soc_dai twl4030_dai[] = {
2121}; 2079};
2122EXPORT_SYMBOL_GPL(twl4030_dai); 2080EXPORT_SYMBOL_GPL(twl4030_dai);
2123 2081
2124static int twl4030_suspend(struct platform_device *pdev, pm_message_t state) 2082static int twl4030_soc_suspend(struct platform_device *pdev, pm_message_t state)
2125{ 2083{
2126 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 2084 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
2127 struct snd_soc_codec *codec = socdev->card->codec; 2085 struct snd_soc_codec *codec = socdev->card->codec;
@@ -2131,7 +2089,7 @@ static int twl4030_suspend(struct platform_device *pdev, pm_message_t state)
2131 return 0; 2089 return 0;
2132} 2090}
2133 2091
2134static int twl4030_resume(struct platform_device *pdev) 2092static int twl4030_soc_resume(struct platform_device *pdev)
2135{ 2093{
2136 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 2094 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
2137 struct snd_soc_codec *codec = socdev->card->codec; 2095 struct snd_soc_codec *codec = socdev->card->codec;
@@ -2141,147 +2099,181 @@ static int twl4030_resume(struct platform_device *pdev)
2141 return 0; 2099 return 0;
2142} 2100}
2143 2101
2144/* 2102static struct snd_soc_codec *twl4030_codec;
2145 * initialize the driver
2146 * register the mixer and dsp interfaces with the kernel
2147 */
2148 2103
2149static int twl4030_init(struct snd_soc_device *socdev) 2104static int twl4030_soc_probe(struct platform_device *pdev)
2150{ 2105{
2151 struct snd_soc_codec *codec = socdev->card->codec; 2106 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
2152 struct twl4030_setup_data *setup = socdev->codec_data; 2107 struct twl4030_setup_data *setup = socdev->codec_data;
2153 struct twl4030_priv *twl4030 = codec->private_data; 2108 struct snd_soc_codec *codec;
2154 int ret = 0; 2109 struct twl4030_priv *twl4030;
2110 int ret;
2155 2111
2156 printk(KERN_INFO "TWL4030 Audio Codec init \n"); 2112 BUG_ON(!twl4030_codec);
2157 2113
2158 codec->name = "twl4030"; 2114 codec = twl4030_codec;
2159 codec->owner = THIS_MODULE; 2115 twl4030 = codec->private_data;
2160 codec->read = twl4030_read_reg_cache; 2116 socdev->card->codec = codec;
2161 codec->write = twl4030_write;
2162 codec->set_bias_level = twl4030_set_bias_level;
2163 codec->dai = twl4030_dai;
2164 codec->num_dai = ARRAY_SIZE(twl4030_dai),
2165 codec->reg_cache_size = sizeof(twl4030_reg);
2166 codec->reg_cache = kmemdup(twl4030_reg, sizeof(twl4030_reg),
2167 GFP_KERNEL);
2168 if (codec->reg_cache == NULL)
2169 return -ENOMEM;
2170 2117
2171 /* Configuration for headset ramp delay from setup data */ 2118 /* Configuration for headset ramp delay from setup data */
2172 if (setup) { 2119 if (setup) {
2173 unsigned char hs_pop; 2120 unsigned char hs_pop;
2174 2121
2175 if (setup->sysclk) 2122 if (setup->sysclk != twl4030->sysclk)
2176 twl4030->sysclk = setup->sysclk; 2123 dev_warn(&pdev->dev,
2177 else 2124 "Mismatch in APLL mclk: %u (configured: %u)\n",
2178 twl4030->sysclk = 26000; 2125 setup->sysclk, twl4030->sysclk);
2179 2126
2180 hs_pop = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); 2127 hs_pop = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
2181 hs_pop &= ~TWL4030_RAMP_DELAY; 2128 hs_pop &= ~TWL4030_RAMP_DELAY;
2182 hs_pop |= (setup->ramp_delay_value << 2); 2129 hs_pop |= (setup->ramp_delay_value << 2);
2183 twl4030_write_reg_cache(codec, TWL4030_REG_HS_POPN_SET, hs_pop); 2130 twl4030_write_reg_cache(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
2184 } else {
2185 twl4030->sysclk = 26000;
2186 } 2131 }
2187 2132
2188 /* register pcms */ 2133 /* register pcms */
2189 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 2134 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
2190 if (ret < 0) { 2135 if (ret < 0) {
2191 printk(KERN_ERR "twl4030: failed to create pcms\n"); 2136 dev_err(&pdev->dev, "failed to create pcms\n");
2192 goto pcm_err; 2137 return ret;
2193 } 2138 }
2194 2139
2195 twl4030_init_chip(codec);
2196
2197 /* power on device */
2198 twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2199
2200 snd_soc_add_controls(codec, twl4030_snd_controls, 2140 snd_soc_add_controls(codec, twl4030_snd_controls,
2201 ARRAY_SIZE(twl4030_snd_controls)); 2141 ARRAY_SIZE(twl4030_snd_controls));
2202 twl4030_add_widgets(codec); 2142 twl4030_add_widgets(codec);
2203 2143
2204 ret = snd_soc_init_card(socdev); 2144 return 0;
2205 if (ret < 0) { 2145}
2206 printk(KERN_ERR "twl4030: failed to register card\n");
2207 goto card_err;
2208 }
2209 2146
2210 return ret; 2147static int twl4030_soc_remove(struct platform_device *pdev)
2148{
2149 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
2150 struct snd_soc_codec *codec = socdev->card->codec;
2211 2151
2212card_err: 2152 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
2213 snd_soc_free_pcms(socdev); 2153 snd_soc_free_pcms(socdev);
2214 snd_soc_dapm_free(socdev); 2154 snd_soc_dapm_free(socdev);
2215pcm_err: 2155 kfree(codec->private_data);
2216 kfree(codec->reg_cache); 2156 kfree(codec);
2217 return ret;
2218}
2219 2157
2220static struct snd_soc_device *twl4030_socdev; 2158 return 0;
2159}
2221 2160
2222static int twl4030_probe(struct platform_device *pdev) 2161static int __devinit twl4030_codec_probe(struct platform_device *pdev)
2223{ 2162{
2224 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 2163 struct twl4030_codec_audio_data *pdata = pdev->dev.platform_data;
2225 struct snd_soc_codec *codec; 2164 struct snd_soc_codec *codec;
2226 struct twl4030_priv *twl4030; 2165 struct twl4030_priv *twl4030;
2166 int ret;
2227 2167
2228 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 2168 if (!pdata) {
2229 if (codec == NULL) 2169 dev_err(&pdev->dev, "platform_data is missing\n");
2230 return -ENOMEM; 2170 return -EINVAL;
2171 }
2231 2172
2232 twl4030 = kzalloc(sizeof(struct twl4030_priv), GFP_KERNEL); 2173 twl4030 = kzalloc(sizeof(struct twl4030_priv), GFP_KERNEL);
2233 if (twl4030 == NULL) { 2174 if (twl4030 == NULL) {
2234 kfree(codec); 2175 dev_err(&pdev->dev, "Can not allocate memroy\n");
2235 return -ENOMEM; 2176 return -ENOMEM;
2236 } 2177 }
2237 2178
2179 codec = &twl4030->codec;
2238 codec->private_data = twl4030; 2180 codec->private_data = twl4030;
2239 socdev->card->codec = codec; 2181 codec->dev = &pdev->dev;
2182 twl4030_dai[0].dev = &pdev->dev;
2183 twl4030_dai[1].dev = &pdev->dev;
2184
2240 mutex_init(&codec->mutex); 2185 mutex_init(&codec->mutex);
2241 INIT_LIST_HEAD(&codec->dapm_widgets); 2186 INIT_LIST_HEAD(&codec->dapm_widgets);
2242 INIT_LIST_HEAD(&codec->dapm_paths); 2187 INIT_LIST_HEAD(&codec->dapm_paths);
2243 2188
2244 twl4030_socdev = socdev; 2189 codec->name = "twl4030";
2245 twl4030_init(socdev); 2190 codec->owner = THIS_MODULE;
2191 codec->read = twl4030_read_reg_cache;
2192 codec->write = twl4030_write;
2193 codec->set_bias_level = twl4030_set_bias_level;
2194 codec->dai = twl4030_dai;
2195 codec->num_dai = ARRAY_SIZE(twl4030_dai),
2196 codec->reg_cache_size = sizeof(twl4030_reg);
2197 codec->reg_cache = kmemdup(twl4030_reg, sizeof(twl4030_reg),
2198 GFP_KERNEL);
2199 if (codec->reg_cache == NULL) {
2200 ret = -ENOMEM;
2201 goto error_cache;
2202 }
2203
2204 platform_set_drvdata(pdev, twl4030);
2205 twl4030_codec = codec;
2206
2207 /* Set the defaults, and power up the codec */
2208 twl4030->sysclk = twl4030_codec_get_mclk() / 1000;
2209 twl4030_init_chip(codec);
2210 codec->bias_level = SND_SOC_BIAS_OFF;
2211 twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2212
2213 ret = snd_soc_register_codec(codec);
2214 if (ret != 0) {
2215 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
2216 goto error_codec;
2217 }
2218
2219 ret = snd_soc_register_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai));
2220 if (ret != 0) {
2221 dev_err(codec->dev, "Failed to register DAIs: %d\n", ret);
2222 snd_soc_unregister_codec(codec);
2223 goto error_codec;
2224 }
2246 2225
2247 return 0; 2226 return 0;
2227
2228error_codec:
2229 twl4030_power_down(codec);
2230 kfree(codec->reg_cache);
2231error_cache:
2232 kfree(twl4030);
2233 return ret;
2248} 2234}
2249 2235
2250static int twl4030_remove(struct platform_device *pdev) 2236static int __devexit twl4030_codec_remove(struct platform_device *pdev)
2251{ 2237{
2252 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 2238 struct twl4030_priv *twl4030 = platform_get_drvdata(pdev);
2253 struct snd_soc_codec *codec = socdev->card->codec;
2254 2239
2255 printk(KERN_INFO "TWL4030 Audio Codec remove\n"); 2240 kfree(twl4030);
2256 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
2257 snd_soc_free_pcms(socdev);
2258 snd_soc_dapm_free(socdev);
2259 kfree(codec->private_data);
2260 kfree(codec);
2261 2241
2242 twl4030_codec = NULL;
2262 return 0; 2243 return 0;
2263} 2244}
2264 2245
2265struct snd_soc_codec_device soc_codec_dev_twl4030 = { 2246MODULE_ALIAS("platform:twl4030_codec_audio");
2266 .probe = twl4030_probe, 2247
2267 .remove = twl4030_remove, 2248static struct platform_driver twl4030_codec_driver = {
2268 .suspend = twl4030_suspend, 2249 .probe = twl4030_codec_probe,
2269 .resume = twl4030_resume, 2250 .remove = __devexit_p(twl4030_codec_remove),
2251 .driver = {
2252 .name = "twl4030_codec_audio",
2253 .owner = THIS_MODULE,
2254 },
2270}; 2255};
2271EXPORT_SYMBOL_GPL(soc_codec_dev_twl4030);
2272 2256
2273static int __init twl4030_modinit(void) 2257static int __init twl4030_modinit(void)
2274{ 2258{
2275 return snd_soc_register_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai)); 2259 return platform_driver_register(&twl4030_codec_driver);
2276} 2260}
2277module_init(twl4030_modinit); 2261module_init(twl4030_modinit);
2278 2262
2279static void __exit twl4030_exit(void) 2263static void __exit twl4030_exit(void)
2280{ 2264{
2281 snd_soc_unregister_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai)); 2265 platform_driver_unregister(&twl4030_codec_driver);
2282} 2266}
2283module_exit(twl4030_exit); 2267module_exit(twl4030_exit);
2284 2268
2269struct snd_soc_codec_device soc_codec_dev_twl4030 = {
2270 .probe = twl4030_soc_probe,
2271 .remove = twl4030_soc_remove,
2272 .suspend = twl4030_soc_suspend,
2273 .resume = twl4030_soc_resume,
2274};
2275EXPORT_SYMBOL_GPL(soc_codec_dev_twl4030);
2276
2285MODULE_DESCRIPTION("ASoC TWL4030 codec driver"); 2277MODULE_DESCRIPTION("ASoC TWL4030 codec driver");
2286MODULE_AUTHOR("Steve Sakoman"); 2278MODULE_AUTHOR("Steve Sakoman");
2287MODULE_LICENSE("GPL"); 2279MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h
index 2b4bfa23f985..dd6396ec9c79 100644
--- a/sound/soc/codecs/twl4030.h
+++ b/sound/soc/codecs/twl4030.h
@@ -22,245 +22,13 @@
22#ifndef __TWL4030_AUDIO_H__ 22#ifndef __TWL4030_AUDIO_H__
23#define __TWL4030_AUDIO_H__ 23#define __TWL4030_AUDIO_H__
24 24
25#define TWL4030_REG_CODEC_MODE 0x1 25/* Register descriptions are here */
26#define TWL4030_REG_OPTION 0x2 26#include <linux/mfd/twl4030-codec.h>
27#define TWL4030_REG_UNKNOWN 0x3
28#define TWL4030_REG_MICBIAS_CTL 0x4
29#define TWL4030_REG_ANAMICL 0x5
30#define TWL4030_REG_ANAMICR 0x6
31#define TWL4030_REG_AVADC_CTL 0x7
32#define TWL4030_REG_ADCMICSEL 0x8
33#define TWL4030_REG_DIGMIXING 0x9
34#define TWL4030_REG_ATXL1PGA 0xA
35#define TWL4030_REG_ATXR1PGA 0xB
36#define TWL4030_REG_AVTXL2PGA 0xC
37#define TWL4030_REG_AVTXR2PGA 0xD
38#define TWL4030_REG_AUDIO_IF 0xE
39#define TWL4030_REG_VOICE_IF 0xF
40#define TWL4030_REG_ARXR1PGA 0x10
41#define TWL4030_REG_ARXL1PGA 0x11
42#define TWL4030_REG_ARXR2PGA 0x12
43#define TWL4030_REG_ARXL2PGA 0x13
44#define TWL4030_REG_VRXPGA 0x14
45#define TWL4030_REG_VSTPGA 0x15
46#define TWL4030_REG_VRX2ARXPGA 0x16
47#define TWL4030_REG_AVDAC_CTL 0x17
48#define TWL4030_REG_ARX2VTXPGA 0x18
49#define TWL4030_REG_ARXL1_APGA_CTL 0x19
50#define TWL4030_REG_ARXR1_APGA_CTL 0x1A
51#define TWL4030_REG_ARXL2_APGA_CTL 0x1B
52#define TWL4030_REG_ARXR2_APGA_CTL 0x1C
53#define TWL4030_REG_ATX2ARXPGA 0x1D
54#define TWL4030_REG_BT_IF 0x1E
55#define TWL4030_REG_BTPGA 0x1F
56#define TWL4030_REG_BTSTPGA 0x20
57#define TWL4030_REG_EAR_CTL 0x21
58#define TWL4030_REG_HS_SEL 0x22
59#define TWL4030_REG_HS_GAIN_SET 0x23
60#define TWL4030_REG_HS_POPN_SET 0x24
61#define TWL4030_REG_PREDL_CTL 0x25
62#define TWL4030_REG_PREDR_CTL 0x26
63#define TWL4030_REG_PRECKL_CTL 0x27
64#define TWL4030_REG_PRECKR_CTL 0x28
65#define TWL4030_REG_HFL_CTL 0x29
66#define TWL4030_REG_HFR_CTL 0x2A
67#define TWL4030_REG_ALC_CTL 0x2B
68#define TWL4030_REG_ALC_SET1 0x2C
69#define TWL4030_REG_ALC_SET2 0x2D
70#define TWL4030_REG_BOOST_CTL 0x2E
71#define TWL4030_REG_SOFTVOL_CTL 0x2F
72#define TWL4030_REG_DTMF_FREQSEL 0x30
73#define TWL4030_REG_DTMF_TONEXT1H 0x31
74#define TWL4030_REG_DTMF_TONEXT1L 0x32
75#define TWL4030_REG_DTMF_TONEXT2H 0x33
76#define TWL4030_REG_DTMF_TONEXT2L 0x34
77#define TWL4030_REG_DTMF_TONOFF 0x35
78#define TWL4030_REG_DTMF_WANONOFF 0x36
79#define TWL4030_REG_I2S_RX_SCRAMBLE_H 0x37
80#define TWL4030_REG_I2S_RX_SCRAMBLE_M 0x38
81#define TWL4030_REG_I2S_RX_SCRAMBLE_L 0x39
82#define TWL4030_REG_APLL_CTL 0x3A
83#define TWL4030_REG_DTMF_CTL 0x3B
84#define TWL4030_REG_DTMF_PGA_CTL2 0x3C
85#define TWL4030_REG_DTMF_PGA_CTL1 0x3D
86#define TWL4030_REG_MISC_SET_1 0x3E
87#define TWL4030_REG_PCMBTMUX 0x3F
88#define TWL4030_REG_RX_PATH_SEL 0x43
89#define TWL4030_REG_VDL_APGA_CTL 0x44
90#define TWL4030_REG_VIBRA_CTL 0x45
91#define TWL4030_REG_VIBRA_SET 0x46
92#define TWL4030_REG_VIBRA_PWM_SET 0x47
93#define TWL4030_REG_ANAMIC_GAIN 0x48
94#define TWL4030_REG_MISC_SET_2 0x49
95#define TWL4030_REG_SW_SHADOW 0x4A
96 27
28/* Sgadow register used by the audio driver */
29#define TWL4030_REG_SW_SHADOW 0x4A
97#define TWL4030_CACHEREGNUM (TWL4030_REG_SW_SHADOW + 1) 30#define TWL4030_CACHEREGNUM (TWL4030_REG_SW_SHADOW + 1)
98 31
99/* Bitfield Definitions */
100
101/* TWL4030_CODEC_MODE (0x01) Fields */
102
103#define TWL4030_APLL_RATE 0xF0
104#define TWL4030_APLL_RATE_8000 0x00
105#define TWL4030_APLL_RATE_11025 0x10
106#define TWL4030_APLL_RATE_12000 0x20
107#define TWL4030_APLL_RATE_16000 0x40
108#define TWL4030_APLL_RATE_22050 0x50
109#define TWL4030_APLL_RATE_24000 0x60
110#define TWL4030_APLL_RATE_32000 0x80
111#define TWL4030_APLL_RATE_44100 0x90
112#define TWL4030_APLL_RATE_48000 0xA0
113#define TWL4030_APLL_RATE_96000 0xE0
114#define TWL4030_SEL_16K 0x08
115#define TWL4030_CODECPDZ 0x02
116#define TWL4030_OPT_MODE 0x01
117#define TWL4030_OPTION_1 (1 << 0)
118#define TWL4030_OPTION_2 (0 << 0)
119
120/* TWL4030_OPTION (0x02) Fields */
121
122#define TWL4030_ATXL1_EN (1 << 0)
123#define TWL4030_ATXR1_EN (1 << 1)
124#define TWL4030_ATXL2_VTXL_EN (1 << 2)
125#define TWL4030_ATXR2_VTXR_EN (1 << 3)
126#define TWL4030_ARXL1_VRX_EN (1 << 4)
127#define TWL4030_ARXR1_EN (1 << 5)
128#define TWL4030_ARXL2_EN (1 << 6)
129#define TWL4030_ARXR2_EN (1 << 7)
130
131/* TWL4030_REG_MICBIAS_CTL (0x04) Fields */
132
133#define TWL4030_MICBIAS2_CTL 0x40
134#define TWL4030_MICBIAS1_CTL 0x20
135#define TWL4030_HSMICBIAS_EN 0x04
136#define TWL4030_MICBIAS2_EN 0x02
137#define TWL4030_MICBIAS1_EN 0x01
138
139/* ANAMICL (0x05) Fields */
140
141#define TWL4030_CNCL_OFFSET_START 0x80
142#define TWL4030_OFFSET_CNCL_SEL 0x60
143#define TWL4030_OFFSET_CNCL_SEL_ARX1 0x00
144#define TWL4030_OFFSET_CNCL_SEL_ARX2 0x20
145#define TWL4030_OFFSET_CNCL_SEL_VRX 0x40
146#define TWL4030_OFFSET_CNCL_SEL_ALL 0x60
147#define TWL4030_MICAMPL_EN 0x10
148#define TWL4030_CKMIC_EN 0x08
149#define TWL4030_AUXL_EN 0x04
150#define TWL4030_HSMIC_EN 0x02
151#define TWL4030_MAINMIC_EN 0x01
152
153/* ANAMICR (0x06) Fields */
154
155#define TWL4030_MICAMPR_EN 0x10
156#define TWL4030_AUXR_EN 0x04
157#define TWL4030_SUBMIC_EN 0x01
158
159/* AVADC_CTL (0x07) Fields */
160
161#define TWL4030_ADCL_EN 0x08
162#define TWL4030_AVADC_CLK_PRIORITY 0x04
163#define TWL4030_ADCR_EN 0x02
164
165/* TWL4030_REG_ADCMICSEL (0x08) Fields */
166
167#define TWL4030_DIGMIC1_EN 0x08
168#define TWL4030_TX2IN_SEL 0x04
169#define TWL4030_DIGMIC0_EN 0x02
170#define TWL4030_TX1IN_SEL 0x01
171
172/* AUDIO_IF (0x0E) Fields */
173
174#define TWL4030_AIF_SLAVE_EN 0x80
175#define TWL4030_DATA_WIDTH 0x60
176#define TWL4030_DATA_WIDTH_16S_16W 0x00
177#define TWL4030_DATA_WIDTH_32S_16W 0x40
178#define TWL4030_DATA_WIDTH_32S_24W 0x60
179#define TWL4030_AIF_FORMAT 0x18
180#define TWL4030_AIF_FORMAT_CODEC 0x00
181#define TWL4030_AIF_FORMAT_LEFT 0x08
182#define TWL4030_AIF_FORMAT_RIGHT 0x10
183#define TWL4030_AIF_FORMAT_TDM 0x18
184#define TWL4030_AIF_TRI_EN 0x04
185#define TWL4030_CLK256FS_EN 0x02
186#define TWL4030_AIF_EN 0x01
187
188/* VOICE_IF (0x0F) Fields */
189
190#define TWL4030_VIF_SLAVE_EN 0x80
191#define TWL4030_VIF_DIN_EN 0x40
192#define TWL4030_VIF_DOUT_EN 0x20
193#define TWL4030_VIF_SWAP 0x10
194#define TWL4030_VIF_FORMAT 0x08
195#define TWL4030_VIF_TRI_EN 0x04
196#define TWL4030_VIF_SUB_EN 0x02
197#define TWL4030_VIF_EN 0x01
198
199/* EAR_CTL (0x21) */
200#define TWL4030_EAR_GAIN 0x30
201
202/* HS_GAIN_SET (0x23) Fields */
203
204#define TWL4030_HSR_GAIN 0x0C
205#define TWL4030_HSR_GAIN_PWR_DOWN 0x00
206#define TWL4030_HSR_GAIN_PLUS_6DB 0x04
207#define TWL4030_HSR_GAIN_0DB 0x08
208#define TWL4030_HSR_GAIN_MINUS_6DB 0x0C
209#define TWL4030_HSL_GAIN 0x03
210#define TWL4030_HSL_GAIN_PWR_DOWN 0x00
211#define TWL4030_HSL_GAIN_PLUS_6DB 0x01
212#define TWL4030_HSL_GAIN_0DB 0x02
213#define TWL4030_HSL_GAIN_MINUS_6DB 0x03
214
215/* HS_POPN_SET (0x24) Fields */
216
217#define TWL4030_VMID_EN 0x40
218#define TWL4030_EXTMUTE 0x20
219#define TWL4030_RAMP_DELAY 0x1C
220#define TWL4030_RAMP_DELAY_20MS 0x00
221#define TWL4030_RAMP_DELAY_40MS 0x04
222#define TWL4030_RAMP_DELAY_81MS 0x08
223#define TWL4030_RAMP_DELAY_161MS 0x0C
224#define TWL4030_RAMP_DELAY_323MS 0x10
225#define TWL4030_RAMP_DELAY_645MS 0x14
226#define TWL4030_RAMP_DELAY_1291MS 0x18
227#define TWL4030_RAMP_DELAY_2581MS 0x1C
228#define TWL4030_RAMP_EN 0x02
229
230/* PREDL_CTL (0x25) */
231#define TWL4030_PREDL_GAIN 0x30
232
233/* PREDR_CTL (0x26) */
234#define TWL4030_PREDR_GAIN 0x30
235
236/* PRECKL_CTL (0x27) */
237#define TWL4030_PRECKL_GAIN 0x30
238
239/* PRECKR_CTL (0x28) */
240#define TWL4030_PRECKR_GAIN 0x30
241
242/* HFL_CTL (0x29, 0x2A) Fields */
243#define TWL4030_HF_CTL_HB_EN 0x04
244#define TWL4030_HF_CTL_LOOP_EN 0x08
245#define TWL4030_HF_CTL_RAMP_EN 0x10
246#define TWL4030_HF_CTL_REF_EN 0x20
247
248/* APLL_CTL (0x3A) Fields */
249
250#define TWL4030_APLL_EN 0x10
251#define TWL4030_APLL_INFREQ 0x0F
252#define TWL4030_APLL_INFREQ_19200KHZ 0x05
253#define TWL4030_APLL_INFREQ_26000KHZ 0x06
254#define TWL4030_APLL_INFREQ_38400KHZ 0x0F
255
256/* REG_MISC_SET_1 (0x3E) Fields */
257
258#define TWL4030_CLK64_EN 0x80
259#define TWL4030_SCRAMBLE_EN 0x40
260#define TWL4030_FMLOOP_EN 0x20
261#define TWL4030_SMOOTH_ANAVOL_EN 0x02
262#define TWL4030_DIGMIC_LR_SWAP_EN 0x01
263
264/* TWL4030_REG_SW_SHADOW (0x4A) Fields */ 32/* TWL4030_REG_SW_SHADOW (0x4A) Fields */
265#define TWL4030_HFL_EN 0x01 33#define TWL4030_HFL_EN 0x01
266#define TWL4030_HFR_EN 0x02 34#define TWL4030_HFR_EN 0x02
@@ -279,3 +47,5 @@ struct twl4030_setup_data {
279}; 47};
280 48
281#endif /* End of __TWL4030_AUDIO_H__ */ 49#endif /* End of __TWL4030_AUDIO_H__ */
50
51
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index c33b92edbded..3e99fe5131dd 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -101,7 +101,7 @@ static int uda134x_write(struct snd_soc_codec *codec, unsigned int reg,
101 pr_debug("%s reg: %02X, value:%02X\n", __func__, reg, value); 101 pr_debug("%s reg: %02X, value:%02X\n", __func__, reg, value);
102 102
103 if (reg >= UDA134X_REGS_NUM) { 103 if (reg >= UDA134X_REGS_NUM) {
104 printk(KERN_ERR "%s unkown register: reg: %u", 104 printk(KERN_ERR "%s unknown register: reg: %u",
105 __func__, reg); 105 __func__, reg);
106 return -EINVAL; 106 return -EINVAL;
107 } 107 }
@@ -552,7 +552,7 @@ static int uda134x_soc_probe(struct platform_device *pdev)
552 ARRAY_SIZE(uda1341_snd_controls)); 552 ARRAY_SIZE(uda1341_snd_controls));
553 break; 553 break;
554 default: 554 default:
555 printk(KERN_ERR "%s unkown codec type: %d", 555 printk(KERN_ERR "%s unknown codec type: %d",
556 __func__, pd->model); 556 __func__, pd->model);
557 return -EINVAL; 557 return -EINVAL;
558 } 558 }
@@ -562,17 +562,8 @@ static int uda134x_soc_probe(struct platform_device *pdev)
562 goto pcm_err; 562 goto pcm_err;
563 } 563 }
564 564
565 ret = snd_soc_init_card(socdev);
566 if (ret < 0) {
567 printk(KERN_ERR "UDA134X: failed to register card\n");
568 goto card_err;
569 }
570
571 return 0; 565 return 0;
572 566
573card_err:
574 snd_soc_free_pcms(socdev);
575 snd_soc_dapm_free(socdev);
576pcm_err: 567pcm_err:
577 kfree(codec->reg_cache); 568 kfree(codec->reg_cache);
578reg_err: 569reg_err:
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 92ec03442154..a2763c2e7348 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -378,7 +378,6 @@ static int uda1380_add_widgets(struct snd_soc_codec *codec)
378 378
379 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 379 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
380 380
381 snd_soc_dapm_new_widgets(codec);
382 return 0; 381 return 0;
383} 382}
384 383
@@ -713,17 +712,9 @@ static int uda1380_probe(struct platform_device *pdev)
713 snd_soc_add_controls(codec, uda1380_snd_controls, 712 snd_soc_add_controls(codec, uda1380_snd_controls,
714 ARRAY_SIZE(uda1380_snd_controls)); 713 ARRAY_SIZE(uda1380_snd_controls));
715 uda1380_add_widgets(codec); 714 uda1380_add_widgets(codec);
716 ret = snd_soc_init_card(socdev);
717 if (ret < 0) {
718 dev_err(codec->dev, "failed to register card: %d\n", ret);
719 goto card_err;
720 }
721 715
722 return ret; 716 return ret;
723 717
724card_err:
725 snd_soc_free_pcms(socdev);
726 snd_soc_dapm_free(socdev);
727pcm_err: 718pcm_err:
728 return ret; 719 return ret;
729} 720}
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index 593d5b9c9f03..f82125d9e85a 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -800,7 +800,7 @@ static int wm8350_add_widgets(struct snd_soc_codec *codec)
800 return ret; 800 return ret;
801 } 801 }
802 802
803 return snd_soc_dapm_new_widgets(codec); 803 return 0;
804} 804}
805 805
806static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai, 806static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai,
@@ -1101,7 +1101,7 @@ static inline int fll_factors(struct _fll_div *fll_div, unsigned int input,
1101} 1101}
1102 1102
1103static int wm8350_set_fll(struct snd_soc_dai *codec_dai, 1103static int wm8350_set_fll(struct snd_soc_dai *codec_dai,
1104 int pll_id, unsigned int freq_in, 1104 int pll_id, int source, unsigned int freq_in,
1105 unsigned int freq_out) 1105 unsigned int freq_out)
1106{ 1106{
1107 struct snd_soc_codec *codec = codec_dai->codec; 1107 struct snd_soc_codec *codec = codec_dai->codec;
@@ -1501,18 +1501,7 @@ static int wm8350_probe(struct platform_device *pdev)
1501 1501
1502 wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1502 wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1503 1503
1504 ret = snd_soc_init_card(socdev);
1505 if (ret < 0) {
1506 dev_err(&pdev->dev, "failed to register card\n");
1507 goto card_err;
1508 }
1509
1510 return 0; 1504 return 0;
1511
1512card_err:
1513 snd_soc_free_pcms(socdev);
1514 snd_soc_dapm_free(socdev);
1515 return ret;
1516} 1505}
1517 1506
1518static int wm8350_remove(struct platform_device *pdev) 1507static int wm8350_remove(struct platform_device *pdev)
@@ -1680,21 +1669,6 @@ static int __devexit wm8350_codec_remove(struct platform_device *pdev)
1680 return 0; 1669 return 0;
1681} 1670}
1682 1671
1683#ifdef CONFIG_PM
1684static int wm8350_codec_suspend(struct platform_device *pdev, pm_message_t m)
1685{
1686 return snd_soc_suspend_device(&pdev->dev);
1687}
1688
1689static int wm8350_codec_resume(struct platform_device *pdev)
1690{
1691 return snd_soc_resume_device(&pdev->dev);
1692}
1693#else
1694#define wm8350_codec_suspend NULL
1695#define wm8350_codec_resume NULL
1696#endif
1697
1698static struct platform_driver wm8350_codec_driver = { 1672static struct platform_driver wm8350_codec_driver = {
1699 .driver = { 1673 .driver = {
1700 .name = "wm8350-codec", 1674 .name = "wm8350-codec",
@@ -1702,8 +1676,6 @@ static struct platform_driver wm8350_codec_driver = {
1702 }, 1676 },
1703 .probe = wm8350_codec_probe, 1677 .probe = wm8350_codec_probe,
1704 .remove = __devexit_p(wm8350_codec_remove), 1678 .remove = __devexit_p(wm8350_codec_remove),
1705 .suspend = wm8350_codec_suspend,
1706 .resume = wm8350_codec_resume,
1707}; 1679};
1708 1680
1709static __init int wm8350_init(void) 1681static __init int wm8350_init(void)
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index b9ef4d915221..b432f4d4a324 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -915,7 +915,6 @@ static int wm8400_add_widgets(struct snd_soc_codec *codec)
915 915
916 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 916 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
917 917
918 snd_soc_dapm_new_widgets(codec);
919 return 0; 918 return 0;
920} 919}
921 920
@@ -1011,7 +1010,8 @@ static int fll_factors(struct wm8400_priv *wm8400, struct fll_factors *factors,
1011} 1010}
1012 1011
1013static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, 1012static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1014 unsigned int freq_in, unsigned int freq_out) 1013 int source, unsigned int freq_in,
1014 unsigned int freq_out)
1015{ 1015{
1016 struct snd_soc_codec *codec = codec_dai->codec; 1016 struct snd_soc_codec *codec = codec_dai->codec;
1017 struct wm8400_priv *wm8400 = codec->private_data; 1017 struct wm8400_priv *wm8400 = codec->private_data;
@@ -1399,17 +1399,6 @@ static int wm8400_probe(struct platform_device *pdev)
1399 wm8400_add_controls(codec); 1399 wm8400_add_controls(codec);
1400 wm8400_add_widgets(codec); 1400 wm8400_add_widgets(codec);
1401 1401
1402 ret = snd_soc_init_card(socdev);
1403 if (ret < 0) {
1404 dev_err(&pdev->dev, "failed to register card\n");
1405 goto card_err;
1406 }
1407
1408 return ret;
1409
1410card_err:
1411 snd_soc_free_pcms(socdev);
1412 snd_soc_dapm_free(socdev);
1413pcm_err: 1402pcm_err:
1414 return ret; 1403 return ret;
1415} 1404}
@@ -1558,21 +1547,6 @@ static int __exit wm8400_codec_remove(struct platform_device *dev)
1558 return 0; 1547 return 0;
1559} 1548}
1560 1549
1561#ifdef CONFIG_PM
1562static int wm8400_pdev_suspend(struct platform_device *pdev, pm_message_t msg)
1563{
1564 return snd_soc_suspend_device(&pdev->dev);
1565}
1566
1567static int wm8400_pdev_resume(struct platform_device *pdev)
1568{
1569 return snd_soc_resume_device(&pdev->dev);
1570}
1571#else
1572#define wm8400_pdev_suspend NULL
1573#define wm8400_pdev_resume NULL
1574#endif
1575
1576static struct platform_driver wm8400_codec_driver = { 1550static struct platform_driver wm8400_codec_driver = {
1577 .driver = { 1551 .driver = {
1578 .name = "wm8400-codec", 1552 .name = "wm8400-codec",
@@ -1580,8 +1554,6 @@ static struct platform_driver wm8400_codec_driver = {
1580 }, 1554 },
1581 .probe = wm8400_codec_probe, 1555 .probe = wm8400_codec_probe,
1582 .remove = __exit_p(wm8400_codec_remove), 1556 .remove = __exit_p(wm8400_codec_remove),
1583 .suspend = wm8400_pdev_suspend,
1584 .resume = wm8400_pdev_resume,
1585}; 1557};
1586 1558
1587static int __init wm8400_codec_init(void) 1559static int __init wm8400_codec_init(void)
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index 060d5d06ba95..265e68c75df8 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -219,7 +219,6 @@ static int wm8510_add_widgets(struct snd_soc_codec *codec)
219 219
220 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 220 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
221 221
222 snd_soc_dapm_new_widgets(codec);
223 return 0; 222 return 0;
224} 223}
225 224
@@ -271,8 +270,8 @@ static void pll_factors(unsigned int target, unsigned int source)
271 pll_div.k = K; 270 pll_div.k = K;
272} 271}
273 272
274static int wm8510_set_dai_pll(struct snd_soc_dai *codec_dai, 273static int wm8510_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
275 int pll_id, unsigned int freq_in, unsigned int freq_out) 274 int source, unsigned int freq_in, unsigned int freq_out)
276{ 275{
277 struct snd_soc_codec *codec = codec_dai->codec; 276 struct snd_soc_codec *codec = codec_dai->codec;
278 u16 reg; 277 u16 reg;
@@ -604,16 +603,9 @@ static int wm8510_init(struct snd_soc_device *socdev,
604 snd_soc_add_controls(codec, wm8510_snd_controls, 603 snd_soc_add_controls(codec, wm8510_snd_controls,
605 ARRAY_SIZE(wm8510_snd_controls)); 604 ARRAY_SIZE(wm8510_snd_controls));
606 wm8510_add_widgets(codec); 605 wm8510_add_widgets(codec);
607 ret = snd_soc_init_card(socdev); 606
608 if (ret < 0) {
609 printk(KERN_ERR "wm8510: failed to register card\n");
610 goto card_err;
611 }
612 return ret; 607 return ret;
613 608
614card_err:
615 snd_soc_free_pcms(socdev);
616 snd_soc_dapm_free(socdev);
617err: 609err:
618 kfree(codec->reg_cache); 610 kfree(codec->reg_cache);
619 return ret; 611 return ret;
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c
index 25870a4652fb..d3a61d7ea0c5 100644
--- a/sound/soc/codecs/wm8523.c
+++ b/sound/soc/codecs/wm8523.c
@@ -117,7 +117,6 @@ static int wm8523_add_widgets(struct snd_soc_codec *codec)
117 117
118 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 118 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
119 119
120 snd_soc_dapm_new_widgets(codec);
121 return 0; 120 return 0;
122} 121}
123 122
@@ -448,17 +447,9 @@ static int wm8523_probe(struct platform_device *pdev)
448 snd_soc_add_controls(codec, wm8523_snd_controls, 447 snd_soc_add_controls(codec, wm8523_snd_controls,
449 ARRAY_SIZE(wm8523_snd_controls)); 448 ARRAY_SIZE(wm8523_snd_controls));
450 wm8523_add_widgets(codec); 449 wm8523_add_widgets(codec);
451 ret = snd_soc_init_card(socdev);
452 if (ret < 0) {
453 dev_err(codec->dev, "failed to register card: %d\n", ret);
454 goto card_err;
455 }
456 450
457 return ret; 451 return ret;
458 452
459card_err:
460 snd_soc_free_pcms(socdev);
461 snd_soc_dapm_free(socdev);
462pcm_err: 453pcm_err:
463 return ret; 454 return ret;
464} 455}
@@ -638,21 +629,6 @@ static __devexit int wm8523_i2c_remove(struct i2c_client *client)
638 return 0; 629 return 0;
639} 630}
640 631
641#ifdef CONFIG_PM
642static int wm8523_i2c_suspend(struct i2c_client *i2c, pm_message_t msg)
643{
644 return snd_soc_suspend_device(&i2c->dev);
645}
646
647static int wm8523_i2c_resume(struct i2c_client *i2c)
648{
649 return snd_soc_resume_device(&i2c->dev);
650}
651#else
652#define wm8523_i2c_suspend NULL
653#define wm8523_i2c_resume NULL
654#endif
655
656static const struct i2c_device_id wm8523_i2c_id[] = { 632static const struct i2c_device_id wm8523_i2c_id[] = {
657 { "wm8523", 0 }, 633 { "wm8523", 0 },
658 { } 634 { }
@@ -666,8 +642,6 @@ static struct i2c_driver wm8523_i2c_driver = {
666 }, 642 },
667 .probe = wm8523_i2c_probe, 643 .probe = wm8523_i2c_probe,
668 .remove = __devexit_p(wm8523_i2c_remove), 644 .remove = __devexit_p(wm8523_i2c_remove),
669 .suspend = wm8523_i2c_suspend,
670 .resume = wm8523_i2c_resume,
671 .id_table = wm8523_i2c_id, 645 .id_table = wm8523_i2c_id,
672}; 646};
673#endif 647#endif
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 6bded8c78150..d077df6f5e75 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -315,7 +315,6 @@ static int wm8580_add_widgets(struct snd_soc_codec *codec)
315 315
316 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 316 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
317 317
318 snd_soc_dapm_new_widgets(codec);
319 return 0; 318 return 0;
320} 319}
321 320
@@ -407,8 +406,8 @@ static int pll_factors(struct _pll_div *pll_div, unsigned int target,
407 return 0; 406 return 0;
408} 407}
409 408
410static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai, 409static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
411 int pll_id, unsigned int freq_in, unsigned int freq_out) 410 int source, unsigned int freq_in, unsigned int freq_out)
412{ 411{
413 int offset; 412 int offset;
414 struct snd_soc_codec *codec = codec_dai->codec; 413 struct snd_soc_codec *codec = codec_dai->codec;
@@ -800,17 +799,9 @@ static int wm8580_probe(struct platform_device *pdev)
800 snd_soc_add_controls(codec, wm8580_snd_controls, 799 snd_soc_add_controls(codec, wm8580_snd_controls,
801 ARRAY_SIZE(wm8580_snd_controls)); 800 ARRAY_SIZE(wm8580_snd_controls));
802 wm8580_add_widgets(codec); 801 wm8580_add_widgets(codec);
803 ret = snd_soc_init_card(socdev);
804 if (ret < 0) {
805 dev_err(codec->dev, "failed to register card: %d\n", ret);
806 goto card_err;
807 }
808 802
809 return ret; 803 return ret;
810 804
811card_err:
812 snd_soc_free_pcms(socdev);
813 snd_soc_dapm_free(socdev);
814pcm_err: 805pcm_err:
815 return ret; 806 return ret;
816} 807}
@@ -961,21 +952,6 @@ static int wm8580_i2c_remove(struct i2c_client *client)
961 return 0; 952 return 0;
962} 953}
963 954
964#ifdef CONFIG_PM
965static int wm8580_i2c_suspend(struct i2c_client *client, pm_message_t msg)
966{
967 return snd_soc_suspend_device(&client->dev);
968}
969
970static int wm8580_i2c_resume(struct i2c_client *client)
971{
972 return snd_soc_resume_device(&client->dev);
973}
974#else
975#define wm8580_i2c_suspend NULL
976#define wm8580_i2c_resume NULL
977#endif
978
979static const struct i2c_device_id wm8580_i2c_id[] = { 955static const struct i2c_device_id wm8580_i2c_id[] = {
980 { "wm8580", 0 }, 956 { "wm8580", 0 },
981 { } 957 { }
@@ -989,8 +965,6 @@ static struct i2c_driver wm8580_i2c_driver = {
989 }, 965 },
990 .probe = wm8580_i2c_probe, 966 .probe = wm8580_i2c_probe,
991 .remove = wm8580_i2c_remove, 967 .remove = wm8580_i2c_remove,
992 .suspend = wm8580_i2c_suspend,
993 .resume = wm8580_i2c_resume,
994 .id_table = wm8580_i2c_id, 968 .id_table = wm8580_i2c_id,
995}; 969};
996#endif 970#endif
diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c
new file mode 100644
index 000000000000..24a35603bcf7
--- /dev/null
+++ b/sound/soc/codecs/wm8711.c
@@ -0,0 +1,633 @@
1/*
2 * wm8711.c -- WM8711 ALSA SoC Audio driver
3 *
4 * Copyright 2006 Wolfson Microelectronics
5 *
6 * Author: Mike Arthur <linux@wolfsonmicro.com>
7 *
8 * Based on wm8731.c by Richard Purdie
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/pm.h>
20#include <linux/i2c.h>
21#include <linux/platform_device.h>
22#include <linux/spi/spi.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/tlv.h>
29#include <sound/initval.h>
30
31#include "wm8711.h"
32
33static struct snd_soc_codec *wm8711_codec;
34
35/* codec private data */
36struct wm8711_priv {
37 struct snd_soc_codec codec;
38 u16 reg_cache[WM8711_CACHEREGNUM];
39 unsigned int sysclk;
40};
41
42/*
43 * wm8711 register cache
44 * We can't read the WM8711 register space when we are
45 * using 2 wire for device control, so we cache them instead.
46 * There is no point in caching the reset register
47 */
48static const u16 wm8711_reg[WM8711_CACHEREGNUM] = {
49 0x0079, 0x0079, 0x000a, 0x0008,
50 0x009f, 0x000a, 0x0000, 0x0000
51};
52
53#define wm8711_reset(c) snd_soc_write(c, WM8711_RESET, 0)
54
55static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
56
57static const struct snd_kcontrol_new wm8711_snd_controls[] = {
58
59SOC_DOUBLE_R_TLV("Master Playback Volume", WM8711_LOUT1V, WM8711_ROUT1V,
60 0, 127, 0, out_tlv),
61SOC_DOUBLE_R("Master Playback ZC Switch", WM8711_LOUT1V, WM8711_ROUT1V,
62 7, 1, 0),
63
64};
65
66/* Output Mixer */
67static const struct snd_kcontrol_new wm8711_output_mixer_controls[] = {
68SOC_DAPM_SINGLE("Line Bypass Switch", WM8711_APANA, 3, 1, 0),
69SOC_DAPM_SINGLE("HiFi Playback Switch", WM8711_APANA, 4, 1, 0),
70};
71
72static const struct snd_soc_dapm_widget wm8711_dapm_widgets[] = {
73SND_SOC_DAPM_MIXER("Output Mixer", WM8711_PWR, 4, 1,
74 &wm8711_output_mixer_controls[0],
75 ARRAY_SIZE(wm8711_output_mixer_controls)),
76SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8711_PWR, 3, 1),
77SND_SOC_DAPM_OUTPUT("LOUT"),
78SND_SOC_DAPM_OUTPUT("LHPOUT"),
79SND_SOC_DAPM_OUTPUT("ROUT"),
80SND_SOC_DAPM_OUTPUT("RHPOUT"),
81};
82
83static const struct snd_soc_dapm_route intercon[] = {
84 /* output mixer */
85 {"Output Mixer", "Line Bypass Switch", "Line Input"},
86 {"Output Mixer", "HiFi Playback Switch", "DAC"},
87
88 /* outputs */
89 {"RHPOUT", NULL, "Output Mixer"},
90 {"ROUT", NULL, "Output Mixer"},
91 {"LHPOUT", NULL, "Output Mixer"},
92 {"LOUT", NULL, "Output Mixer"},
93};
94
95static int wm8711_add_widgets(struct snd_soc_codec *codec)
96{
97 snd_soc_dapm_new_controls(codec, wm8711_dapm_widgets,
98 ARRAY_SIZE(wm8711_dapm_widgets));
99
100 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
101
102 return 0;
103}
104
105struct _coeff_div {
106 u32 mclk;
107 u32 rate;
108 u16 fs;
109 u8 sr:4;
110 u8 bosr:1;
111 u8 usb:1;
112};
113
114/* codec mclk clock divider coefficients */
115static const struct _coeff_div coeff_div[] = {
116 /* 48k */
117 {12288000, 48000, 256, 0x0, 0x0, 0x0},
118 {18432000, 48000, 384, 0x0, 0x1, 0x0},
119 {12000000, 48000, 250, 0x0, 0x0, 0x1},
120
121 /* 32k */
122 {12288000, 32000, 384, 0x6, 0x0, 0x0},
123 {18432000, 32000, 576, 0x6, 0x1, 0x0},
124 {12000000, 32000, 375, 0x6, 0x0, 0x1},
125
126 /* 8k */
127 {12288000, 8000, 1536, 0x3, 0x0, 0x0},
128 {18432000, 8000, 2304, 0x3, 0x1, 0x0},
129 {11289600, 8000, 1408, 0xb, 0x0, 0x0},
130 {16934400, 8000, 2112, 0xb, 0x1, 0x0},
131 {12000000, 8000, 1500, 0x3, 0x0, 0x1},
132
133 /* 96k */
134 {12288000, 96000, 128, 0x7, 0x0, 0x0},
135 {18432000, 96000, 192, 0x7, 0x1, 0x0},
136 {12000000, 96000, 125, 0x7, 0x0, 0x1},
137
138 /* 44.1k */
139 {11289600, 44100, 256, 0x8, 0x0, 0x0},
140 {16934400, 44100, 384, 0x8, 0x1, 0x0},
141 {12000000, 44100, 272, 0x8, 0x1, 0x1},
142
143 /* 88.2k */
144 {11289600, 88200, 128, 0xf, 0x0, 0x0},
145 {16934400, 88200, 192, 0xf, 0x1, 0x0},
146 {12000000, 88200, 136, 0xf, 0x1, 0x1},
147};
148
149static inline int get_coeff(int mclk, int rate)
150{
151 int i;
152
153 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
154 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
155 return i;
156 }
157 return 0;
158}
159
160static int wm8711_hw_params(struct snd_pcm_substream *substream,
161 struct snd_pcm_hw_params *params,
162 struct snd_soc_dai *dai)
163{
164 struct snd_soc_codec *codec = dai->codec;
165 struct wm8711_priv *wm8711 = codec->private_data;
166 u16 iface = snd_soc_read(codec, WM8711_IFACE) & 0xfffc;
167 int i = get_coeff(wm8711->sysclk, params_rate(params));
168 u16 srate = (coeff_div[i].sr << 2) |
169 (coeff_div[i].bosr << 1) | coeff_div[i].usb;
170
171 snd_soc_write(codec, WM8711_SRATE, srate);
172
173 /* bit size */
174 switch (params_format(params)) {
175 case SNDRV_PCM_FORMAT_S16_LE:
176 break;
177 case SNDRV_PCM_FORMAT_S20_3LE:
178 iface |= 0x0004;
179 break;
180 case SNDRV_PCM_FORMAT_S24_LE:
181 iface |= 0x0008;
182 break;
183 }
184
185 snd_soc_write(codec, WM8711_IFACE, iface);
186 return 0;
187}
188
189static int wm8711_pcm_prepare(struct snd_pcm_substream *substream,
190 struct snd_soc_dai *dai)
191{
192 struct snd_soc_codec *codec = dai->codec;
193
194 /* set active */
195 snd_soc_write(codec, WM8711_ACTIVE, 0x0001);
196
197 return 0;
198}
199
200static void wm8711_shutdown(struct snd_pcm_substream *substream,
201 struct snd_soc_dai *dai)
202{
203 struct snd_soc_codec *codec = dai->codec;
204
205 /* deactivate */
206 if (!codec->active) {
207 udelay(50);
208 snd_soc_write(codec, WM8711_ACTIVE, 0x0);
209 }
210}
211
212static int wm8711_mute(struct snd_soc_dai *dai, int mute)
213{
214 struct snd_soc_codec *codec = dai->codec;
215 u16 mute_reg = snd_soc_read(codec, WM8711_APDIGI) & 0xfff7;
216
217 if (mute)
218 snd_soc_write(codec, WM8711_APDIGI, mute_reg | 0x8);
219 else
220 snd_soc_write(codec, WM8711_APDIGI, mute_reg);
221
222 return 0;
223}
224
225static int wm8711_set_dai_sysclk(struct snd_soc_dai *codec_dai,
226 int clk_id, unsigned int freq, int dir)
227{
228 struct snd_soc_codec *codec = codec_dai->codec;
229 struct wm8711_priv *wm8711 = codec->private_data;
230
231 switch (freq) {
232 case 11289600:
233 case 12000000:
234 case 12288000:
235 case 16934400:
236 case 18432000:
237 wm8711->sysclk = freq;
238 return 0;
239 }
240 return -EINVAL;
241}
242
243static int wm8711_set_dai_fmt(struct snd_soc_dai *codec_dai,
244 unsigned int fmt)
245{
246 struct snd_soc_codec *codec = codec_dai->codec;
247 u16 iface = 0;
248
249 /* set master/slave audio interface */
250 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
251 case SND_SOC_DAIFMT_CBM_CFM:
252 iface |= 0x0040;
253 break;
254 case SND_SOC_DAIFMT_CBS_CFS:
255 break;
256 default:
257 return -EINVAL;
258 }
259
260 /* interface format */
261 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
262 case SND_SOC_DAIFMT_I2S:
263 iface |= 0x0002;
264 break;
265 case SND_SOC_DAIFMT_RIGHT_J:
266 break;
267 case SND_SOC_DAIFMT_LEFT_J:
268 iface |= 0x0001;
269 break;
270 case SND_SOC_DAIFMT_DSP_A:
271 iface |= 0x0003;
272 break;
273 case SND_SOC_DAIFMT_DSP_B:
274 iface |= 0x0013;
275 break;
276 default:
277 return -EINVAL;
278 }
279
280 /* clock inversion */
281 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
282 case SND_SOC_DAIFMT_NB_NF:
283 break;
284 case SND_SOC_DAIFMT_IB_IF:
285 iface |= 0x0090;
286 break;
287 case SND_SOC_DAIFMT_IB_NF:
288 iface |= 0x0080;
289 break;
290 case SND_SOC_DAIFMT_NB_IF:
291 iface |= 0x0010;
292 break;
293 default:
294 return -EINVAL;
295 }
296
297 /* set iface */
298 snd_soc_write(codec, WM8711_IFACE, iface);
299 return 0;
300}
301
302
303static int wm8711_set_bias_level(struct snd_soc_codec *codec,
304 enum snd_soc_bias_level level)
305{
306 u16 reg = snd_soc_read(codec, WM8711_PWR) & 0xff7f;
307
308 switch (level) {
309 case SND_SOC_BIAS_ON:
310 snd_soc_write(codec, WM8711_PWR, reg);
311 break;
312 case SND_SOC_BIAS_PREPARE:
313 break;
314 case SND_SOC_BIAS_STANDBY:
315 snd_soc_write(codec, WM8711_PWR, reg | 0x0040);
316 break;
317 case SND_SOC_BIAS_OFF:
318 snd_soc_write(codec, WM8711_ACTIVE, 0x0);
319 snd_soc_write(codec, WM8711_PWR, 0xffff);
320 break;
321 }
322 codec->bias_level = level;
323 return 0;
324}
325
326#define WM8711_RATES SNDRV_PCM_RATE_8000_96000
327
328#define WM8711_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
329 SNDRV_PCM_FMTBIT_S24_LE)
330
331static struct snd_soc_dai_ops wm8711_ops = {
332 .prepare = wm8711_pcm_prepare,
333 .hw_params = wm8711_hw_params,
334 .shutdown = wm8711_shutdown,
335 .digital_mute = wm8711_mute,
336 .set_sysclk = wm8711_set_dai_sysclk,
337 .set_fmt = wm8711_set_dai_fmt,
338};
339
340struct snd_soc_dai wm8711_dai = {
341 .name = "WM8711",
342 .playback = {
343 .stream_name = "Playback",
344 .channels_min = 1,
345 .channels_max = 2,
346 .rates = WM8711_RATES,
347 .formats = WM8711_FORMATS,
348 },
349 .ops = &wm8711_ops,
350};
351EXPORT_SYMBOL_GPL(wm8711_dai);
352
353static int wm8711_suspend(struct platform_device *pdev, pm_message_t state)
354{
355 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
356 struct snd_soc_codec *codec = socdev->card->codec;
357
358 snd_soc_write(codec, WM8711_ACTIVE, 0x0);
359 wm8711_set_bias_level(codec, SND_SOC_BIAS_OFF);
360 return 0;
361}
362
363static int wm8711_resume(struct platform_device *pdev)
364{
365 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
366 struct snd_soc_codec *codec = socdev->card->codec;
367 int i;
368 u8 data[2];
369 u16 *cache = codec->reg_cache;
370
371 /* Sync reg_cache with the hardware */
372 for (i = 0; i < ARRAY_SIZE(wm8711_reg); i++) {
373 data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
374 data[1] = cache[i] & 0x00ff;
375 codec->hw_write(codec->control_data, data, 2);
376 }
377 wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
378 wm8711_set_bias_level(codec, codec->suspend_bias_level);
379 return 0;
380}
381
382static int wm8711_probe(struct platform_device *pdev)
383{
384 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
385 struct snd_soc_codec *codec;
386 int ret = 0;
387
388 if (wm8711_codec == NULL) {
389 dev_err(&pdev->dev, "Codec device not registered\n");
390 return -ENODEV;
391 }
392
393 socdev->card->codec = wm8711_codec;
394 codec = wm8711_codec;
395
396 /* register pcms */
397 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
398 if (ret < 0) {
399 dev_err(codec->dev, "failed to create pcms: %d\n", ret);
400 goto pcm_err;
401 }
402
403 snd_soc_add_controls(codec, wm8711_snd_controls,
404 ARRAY_SIZE(wm8711_snd_controls));
405 wm8711_add_widgets(codec);
406
407 return ret;
408
409pcm_err:
410 return ret;
411}
412
413/* power down chip */
414static int wm8711_remove(struct platform_device *pdev)
415{
416 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
417
418 snd_soc_free_pcms(socdev);
419 snd_soc_dapm_free(socdev);
420
421 return 0;
422}
423
424struct snd_soc_codec_device soc_codec_dev_wm8711 = {
425 .probe = wm8711_probe,
426 .remove = wm8711_remove,
427 .suspend = wm8711_suspend,
428 .resume = wm8711_resume,
429};
430EXPORT_SYMBOL_GPL(soc_codec_dev_wm8711);
431
432static int wm8711_register(struct wm8711_priv *wm8711,
433 enum snd_soc_control_type control)
434{
435 int ret;
436 struct snd_soc_codec *codec = &wm8711->codec;
437 u16 reg;
438
439 if (wm8711_codec) {
440 dev_err(codec->dev, "Another WM8711 is registered\n");
441 return -EINVAL;
442 }
443
444 mutex_init(&codec->mutex);
445 INIT_LIST_HEAD(&codec->dapm_widgets);
446 INIT_LIST_HEAD(&codec->dapm_paths);
447
448 codec->private_data = wm8711;
449 codec->name = "WM8711";
450 codec->owner = THIS_MODULE;
451 codec->bias_level = SND_SOC_BIAS_OFF;
452 codec->set_bias_level = wm8711_set_bias_level;
453 codec->dai = &wm8711_dai;
454 codec->num_dai = 1;
455 codec->reg_cache_size = WM8711_CACHEREGNUM;
456 codec->reg_cache = &wm8711->reg_cache;
457
458 memcpy(codec->reg_cache, wm8711_reg, sizeof(wm8711_reg));
459
460 ret = snd_soc_codec_set_cache_io(codec, 7, 9, control);
461 if (ret < 0) {
462 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
463 goto err;
464 }
465
466 ret = wm8711_reset(codec);
467 if (ret < 0) {
468 dev_err(codec->dev, "Failed to issue reset\n");
469 goto err;
470 }
471
472 wm8711_dai.dev = codec->dev;
473
474 wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
475
476 /* Latch the update bits */
477 reg = snd_soc_read(codec, WM8711_LOUT1V);
478 snd_soc_write(codec, WM8711_LOUT1V, reg | 0x0100);
479 reg = snd_soc_read(codec, WM8711_ROUT1V);
480 snd_soc_write(codec, WM8711_ROUT1V, reg | 0x0100);
481
482 wm8711_codec = codec;
483
484 ret = snd_soc_register_codec(codec);
485 if (ret != 0) {
486 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
487 goto err;
488 }
489
490 ret = snd_soc_register_dai(&wm8711_dai);
491 if (ret != 0) {
492 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
493 goto err_codec;
494 }
495
496 return 0;
497
498err_codec:
499 snd_soc_unregister_codec(codec);
500err:
501 kfree(wm8711);
502 return ret;
503}
504
505static void wm8711_unregister(struct wm8711_priv *wm8711)
506{
507 wm8711_set_bias_level(&wm8711->codec, SND_SOC_BIAS_OFF);
508 snd_soc_unregister_dai(&wm8711_dai);
509 snd_soc_unregister_codec(&wm8711->codec);
510 kfree(wm8711);
511 wm8711_codec = NULL;
512}
513
514#if defined(CONFIG_SPI_MASTER)
515static int __devinit wm8711_spi_probe(struct spi_device *spi)
516{
517 struct snd_soc_codec *codec;
518 struct wm8711_priv *wm8711;
519
520 wm8711 = kzalloc(sizeof(struct wm8711_priv), GFP_KERNEL);
521 if (wm8711 == NULL)
522 return -ENOMEM;
523
524 codec = &wm8711->codec;
525 codec->control_data = spi;
526 codec->dev = &spi->dev;
527
528 dev_set_drvdata(&spi->dev, wm8711);
529
530 return wm8711_register(wm8711, SND_SOC_SPI);
531}
532
533static int __devexit wm8711_spi_remove(struct spi_device *spi)
534{
535 struct wm8711_priv *wm8711 = dev_get_drvdata(&spi->dev);
536
537 wm8711_unregister(wm8711);
538
539 return 0;
540}
541
542static struct spi_driver wm8711_spi_driver = {
543 .driver = {
544 .name = "wm8711",
545 .bus = &spi_bus_type,
546 .owner = THIS_MODULE,
547 },
548 .probe = wm8711_spi_probe,
549 .remove = __devexit_p(wm8711_spi_remove),
550};
551#endif /* CONFIG_SPI_MASTER */
552
553#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
554static __devinit int wm8711_i2c_probe(struct i2c_client *i2c,
555 const struct i2c_device_id *id)
556{
557 struct wm8711_priv *wm8711;
558 struct snd_soc_codec *codec;
559
560 wm8711 = kzalloc(sizeof(struct wm8711_priv), GFP_KERNEL);
561 if (wm8711 == NULL)
562 return -ENOMEM;
563
564 codec = &wm8711->codec;
565 codec->hw_write = (hw_write_t)i2c_master_send;
566
567 i2c_set_clientdata(i2c, wm8711);
568 codec->control_data = i2c;
569
570 codec->dev = &i2c->dev;
571
572 return wm8711_register(wm8711, SND_SOC_I2C);
573}
574
575static __devexit int wm8711_i2c_remove(struct i2c_client *client)
576{
577 struct wm8711_priv *wm8711 = i2c_get_clientdata(client);
578 wm8711_unregister(wm8711);
579 return 0;
580}
581
582static const struct i2c_device_id wm8711_i2c_id[] = {
583 { "wm8711", 0 },
584 { }
585};
586MODULE_DEVICE_TABLE(i2c, wm8711_i2c_id);
587
588static struct i2c_driver wm8711_i2c_driver = {
589 .driver = {
590 .name = "WM8711 I2C Codec",
591 .owner = THIS_MODULE,
592 },
593 .probe = wm8711_i2c_probe,
594 .remove = __devexit_p(wm8711_i2c_remove),
595 .id_table = wm8711_i2c_id,
596};
597#endif
598
599static int __init wm8711_modinit(void)
600{
601 int ret;
602#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
603 ret = i2c_add_driver(&wm8711_i2c_driver);
604 if (ret != 0) {
605 printk(KERN_ERR "Failed to register WM8711 I2C driver: %d\n",
606 ret);
607 }
608#endif
609#if defined(CONFIG_SPI_MASTER)
610 ret = spi_register_driver(&wm8711_spi_driver);
611 if (ret != 0) {
612 printk(KERN_ERR "Failed to register WM8711 SPI driver: %d\n",
613 ret);
614 }
615#endif
616 return 0;
617}
618module_init(wm8711_modinit);
619
620static void __exit wm8711_exit(void)
621{
622#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
623 i2c_del_driver(&wm8711_i2c_driver);
624#endif
625#if defined(CONFIG_SPI_MASTER)
626 spi_unregister_driver(&wm8711_spi_driver);
627#endif
628}
629module_exit(wm8711_exit);
630
631MODULE_DESCRIPTION("ASoC WM8711 driver");
632MODULE_AUTHOR("Mike Arthur");
633MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8711.h b/sound/soc/codecs/wm8711.h
new file mode 100644
index 000000000000..381e84a43816
--- /dev/null
+++ b/sound/soc/codecs/wm8711.h
@@ -0,0 +1,42 @@
1/*
2 * wm8711.h -- WM8711 Soc Audio driver
3 *
4 * Copyright 2006 Wolfson Microelectronics
5 *
6 * Author: Mike Arthur <linux@wolfsonmicro.com>
7 *
8 * Based on wm8731.h
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#ifndef _WM8711_H
16#define _WM8711_H
17
18/* WM8711 register space */
19
20#define WM8711_LOUT1V 0x02
21#define WM8711_ROUT1V 0x03
22#define WM8711_APANA 0x04
23#define WM8711_APDIGI 0x05
24#define WM8711_PWR 0x06
25#define WM8711_IFACE 0x07
26#define WM8711_SRATE 0x08
27#define WM8711_ACTIVE 0x09
28#define WM8711_RESET 0x0f
29
30#define WM8711_CACHEREGNUM 8
31
32#define WM8711_SYSCLK 0
33#define WM8711_DAI 0
34
35struct wm8711_setup_data {
36 unsigned short i2c_address;
37};
38
39extern struct snd_soc_dai wm8711_dai;
40extern struct snd_soc_codec_device soc_codec_dev_wm8711;
41
42#endif
diff --git a/sound/soc/codecs/wm8727.c b/sound/soc/codecs/wm8727.c
new file mode 100644
index 000000000000..d8ffbd641d71
--- /dev/null
+++ b/sound/soc/codecs/wm8727.c
@@ -0,0 +1,135 @@
1/*
2 * wm8727.c
3 *
4 * Created on: 15-Oct-2009
5 * Author: neil.jones@imgtec.com
6 *
7 * Copyright (C) 2009 Imagination Technologies Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/device.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/ac97_codec.h>
22#include <sound/initval.h>
23#include <sound/soc.h>
24
25#include "wm8727.h"
26/*
27 * Note this is a simple chip with no configuration interface, sample rate is
28 * determined automatically by examining the Master clock and Bit clock ratios
29 */
30#define WM8727_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
31 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
32 SNDRV_PCM_RATE_192000)
33
34
35struct snd_soc_dai wm8727_dai = {
36 .name = "WM8727",
37 .playback = {
38 .stream_name = "Playback",
39 .channels_min = 2,
40 .channels_max = 2,
41 .rates = WM8727_RATES,
42 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
43 },
44};
45EXPORT_SYMBOL_GPL(wm8727_dai);
46
47static int wm8727_soc_probe(struct platform_device *pdev)
48{
49 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
50 struct snd_soc_codec *codec;
51 int ret = 0;
52
53 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
54 if (codec == NULL)
55 return -ENOMEM;
56 mutex_init(&codec->mutex);
57 codec->name = "WM8727";
58 codec->owner = THIS_MODULE;
59 codec->dai = &wm8727_dai;
60 codec->num_dai = 1;
61 socdev->card->codec = codec;
62 INIT_LIST_HEAD(&codec->dapm_widgets);
63 INIT_LIST_HEAD(&codec->dapm_paths);
64
65 /* register pcms */
66 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
67 if (ret < 0) {
68 printk(KERN_ERR "wm8727: failed to create pcms\n");
69 goto pcm_err;
70 }
71
72 return ret;
73
74pcm_err:
75 kfree(socdev->card->codec);
76 socdev->card->codec = NULL;
77 return ret;
78}
79
80static int wm8727_soc_remove(struct platform_device *pdev)
81{
82 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
83 struct snd_soc_codec *codec = socdev->card->codec;
84
85 if (codec == NULL)
86 return 0;
87 snd_soc_free_pcms(socdev);
88 kfree(codec);
89 return 0;
90}
91
92struct snd_soc_codec_device soc_codec_dev_wm8727 = {
93 .probe = wm8727_soc_probe,
94 .remove = wm8727_soc_remove,
95};
96EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
97
98
99static __devinit int wm8727_platform_probe(struct platform_device *pdev)
100{
101 wm8727_dai.dev = &pdev->dev;
102 return snd_soc_register_dai(&wm8727_dai);
103}
104
105static int __devexit wm8727_platform_remove(struct platform_device *pdev)
106{
107 snd_soc_unregister_dai(&wm8727_dai);
108 return 0;
109}
110
111static struct platform_driver wm8727_codec_driver = {
112 .driver = {
113 .name = "wm8727-codec",
114 .owner = THIS_MODULE,
115 },
116
117 .probe = wm8727_platform_probe,
118 .remove = __devexit_p(wm8727_platform_remove),
119};
120
121static int __init wm8727_init(void)
122{
123 return platform_driver_register(&wm8727_codec_driver);
124}
125module_init(wm8727_init);
126
127static void __exit wm8727_exit(void)
128{
129 platform_driver_unregister(&wm8727_codec_driver);
130}
131module_exit(wm8727_exit);
132
133MODULE_DESCRIPTION("ASoC wm8727 driver");
134MODULE_AUTHOR("Neil Jones");
135MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8727.h b/sound/soc/codecs/wm8727.h
new file mode 100644
index 000000000000..ee19aa71bcdc
--- /dev/null
+++ b/sound/soc/codecs/wm8727.h
@@ -0,0 +1,21 @@
1/*
2 * wm8727.h
3 *
4 * Created on: 15-Oct-2009
5 * Author: neil.jones@imgtec.com
6 *
7 * Copyright (C) 2009 Imagination Technologies Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15#ifndef WM8727_H_
16#define WM8727_H_
17
18extern struct snd_soc_dai wm8727_dai;
19extern struct snd_soc_codec_device soc_codec_dev_wm8727;
20
21#endif /* WM8727_H_ */
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index 16e969a762c3..3fb653ba363a 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -74,8 +74,6 @@ static int wm8728_add_widgets(struct snd_soc_codec *codec)
74 74
75 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 75 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
76 76
77 snd_soc_dapm_new_widgets(codec);
78
79 return 0; 77 return 0;
80} 78}
81 79
@@ -287,17 +285,9 @@ static int wm8728_init(struct snd_soc_device *socdev,
287 snd_soc_add_controls(codec, wm8728_snd_controls, 285 snd_soc_add_controls(codec, wm8728_snd_controls,
288 ARRAY_SIZE(wm8728_snd_controls)); 286 ARRAY_SIZE(wm8728_snd_controls));
289 wm8728_add_widgets(codec); 287 wm8728_add_widgets(codec);
290 ret = snd_soc_init_card(socdev);
291 if (ret < 0) {
292 printk(KERN_ERR "wm8728: failed to register card\n");
293 goto card_err;
294 }
295 288
296 return ret; 289 return ret;
297 290
298card_err:
299 snd_soc_free_pcms(socdev);
300 snd_soc_dapm_free(socdev);
301err: 291err:
302 kfree(codec->reg_cache); 292 kfree(codec->reg_cache);
303 return ret; 293 return ret;
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index d3fd4f28d96e..3a497810f939 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -19,6 +19,7 @@
19#include <linux/pm.h> 19#include <linux/pm.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/regulator/consumer.h>
22#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
23#include <sound/core.h> 24#include <sound/core.h>
24#include <sound/pcm.h> 25#include <sound/pcm.h>
@@ -33,9 +34,18 @@
33static struct snd_soc_codec *wm8731_codec; 34static struct snd_soc_codec *wm8731_codec;
34struct snd_soc_codec_device soc_codec_dev_wm8731; 35struct snd_soc_codec_device soc_codec_dev_wm8731;
35 36
37#define WM8731_NUM_SUPPLIES 4
38static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {
39 "AVDD",
40 "HPVDD",
41 "DCVDD",
42 "DBVDD",
43};
44
36/* codec private data */ 45/* codec private data */
37struct wm8731_priv { 46struct wm8731_priv {
38 struct snd_soc_codec codec; 47 struct snd_soc_codec codec;
48 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES];
39 u16 reg_cache[WM8731_CACHEREGNUM]; 49 u16 reg_cache[WM8731_CACHEREGNUM];
40 unsigned int sysclk; 50 unsigned int sysclk;
41}; 51};
@@ -149,7 +159,6 @@ static int wm8731_add_widgets(struct snd_soc_codec *codec)
149 159
150 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 160 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
151 161
152 snd_soc_dapm_new_widgets(codec);
153 return 0; 162 return 0;
154} 163}
155 164
@@ -422,9 +431,12 @@ static int wm8731_suspend(struct platform_device *pdev, pm_message_t state)
422{ 431{
423 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 432 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
424 struct snd_soc_codec *codec = socdev->card->codec; 433 struct snd_soc_codec *codec = socdev->card->codec;
434 struct wm8731_priv *wm8731 = codec->private_data;
425 435
426 snd_soc_write(codec, WM8731_ACTIVE, 0x0); 436 snd_soc_write(codec, WM8731_ACTIVE, 0x0);
427 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); 437 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
438 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies),
439 wm8731->supplies);
428 return 0; 440 return 0;
429} 441}
430 442
@@ -432,10 +444,16 @@ static int wm8731_resume(struct platform_device *pdev)
432{ 444{
433 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 445 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
434 struct snd_soc_codec *codec = socdev->card->codec; 446 struct snd_soc_codec *codec = socdev->card->codec;
435 int i; 447 struct wm8731_priv *wm8731 = codec->private_data;
448 int i, ret;
436 u8 data[2]; 449 u8 data[2];
437 u16 *cache = codec->reg_cache; 450 u16 *cache = codec->reg_cache;
438 451
452 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
453 wm8731->supplies);
454 if (ret != 0)
455 return ret;
456
439 /* Sync reg_cache with the hardware */ 457 /* Sync reg_cache with the hardware */
440 for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) { 458 for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) {
441 data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001); 459 data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
@@ -444,6 +462,7 @@ static int wm8731_resume(struct platform_device *pdev)
444 } 462 }
445 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 463 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
446 wm8731_set_bias_level(codec, codec->suspend_bias_level); 464 wm8731_set_bias_level(codec, codec->suspend_bias_level);
465
447 return 0; 466 return 0;
448} 467}
449#else 468#else
@@ -475,17 +494,9 @@ static int wm8731_probe(struct platform_device *pdev)
475 snd_soc_add_controls(codec, wm8731_snd_controls, 494 snd_soc_add_controls(codec, wm8731_snd_controls,
476 ARRAY_SIZE(wm8731_snd_controls)); 495 ARRAY_SIZE(wm8731_snd_controls));
477 wm8731_add_widgets(codec); 496 wm8731_add_widgets(codec);
478 ret = snd_soc_init_card(socdev);
479 if (ret < 0) {
480 dev_err(codec->dev, "failed to register card: %d\n", ret);
481 goto card_err;
482 }
483 497
484 return ret; 498 return ret;
485 499
486card_err:
487 snd_soc_free_pcms(socdev);
488 snd_soc_dapm_free(socdev);
489pcm_err: 500pcm_err:
490 return ret; 501 return ret;
491} 502}
@@ -512,7 +523,7 @@ EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731);
512static int wm8731_register(struct wm8731_priv *wm8731, 523static int wm8731_register(struct wm8731_priv *wm8731,
513 enum snd_soc_control_type control) 524 enum snd_soc_control_type control)
514{ 525{
515 int ret; 526 int ret, i;
516 struct snd_soc_codec *codec = &wm8731->codec; 527 struct snd_soc_codec *codec = &wm8731->codec;
517 528
518 if (wm8731_codec) { 529 if (wm8731_codec) {
@@ -543,10 +554,27 @@ static int wm8731_register(struct wm8731_priv *wm8731,
543 goto err; 554 goto err;
544 } 555 }
545 556
557 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++)
558 wm8731->supplies[i].supply = wm8731_supply_names[i];
559
560 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8731->supplies),
561 wm8731->supplies);
562 if (ret != 0) {
563 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
564 goto err;
565 }
566
567 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
568 wm8731->supplies);
569 if (ret != 0) {
570 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
571 goto err_regulator_get;
572 }
573
546 ret = wm8731_reset(codec); 574 ret = wm8731_reset(codec);
547 if (ret < 0) { 575 if (ret < 0) {
548 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); 576 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
549 goto err; 577 goto err_regulator_enable;
550 } 578 }
551 579
552 wm8731_dai.dev = codec->dev; 580 wm8731_dai.dev = codec->dev;
@@ -567,7 +595,7 @@ static int wm8731_register(struct wm8731_priv *wm8731,
567 ret = snd_soc_register_codec(codec); 595 ret = snd_soc_register_codec(codec);
568 if (ret != 0) { 596 if (ret != 0) {
569 dev_err(codec->dev, "Failed to register codec: %d\n", ret); 597 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
570 goto err; 598 goto err_regulator_enable;
571 } 599 }
572 600
573 ret = snd_soc_register_dai(&wm8731_dai); 601 ret = snd_soc_register_dai(&wm8731_dai);
@@ -581,6 +609,10 @@ static int wm8731_register(struct wm8731_priv *wm8731,
581 609
582err_codec: 610err_codec:
583 snd_soc_unregister_codec(codec); 611 snd_soc_unregister_codec(codec);
612err_regulator_enable:
613 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
614err_regulator_get:
615 regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
584err: 616err:
585 kfree(wm8731); 617 kfree(wm8731);
586 return ret; 618 return ret;
@@ -591,6 +623,8 @@ static void wm8731_unregister(struct wm8731_priv *wm8731)
591 wm8731_set_bias_level(&wm8731->codec, SND_SOC_BIAS_OFF); 623 wm8731_set_bias_level(&wm8731->codec, SND_SOC_BIAS_OFF);
592 snd_soc_unregister_dai(&wm8731_dai); 624 snd_soc_unregister_dai(&wm8731_dai);
593 snd_soc_unregister_codec(&wm8731->codec); 625 snd_soc_unregister_codec(&wm8731->codec);
626 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
627 regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
594 kfree(wm8731); 628 kfree(wm8731);
595 wm8731_codec = NULL; 629 wm8731_codec = NULL;
596} 630}
@@ -623,21 +657,6 @@ static int __devexit wm8731_spi_remove(struct spi_device *spi)
623 return 0; 657 return 0;
624} 658}
625 659
626#ifdef CONFIG_PM
627static int wm8731_spi_suspend(struct spi_device *spi, pm_message_t msg)
628{
629 return snd_soc_suspend_device(&spi->dev);
630}
631
632static int wm8731_spi_resume(struct spi_device *spi)
633{
634 return snd_soc_resume_device(&spi->dev);
635}
636#else
637#define wm8731_spi_suspend NULL
638#define wm8731_spi_resume NULL
639#endif
640
641static struct spi_driver wm8731_spi_driver = { 660static struct spi_driver wm8731_spi_driver = {
642 .driver = { 661 .driver = {
643 .name = "wm8731", 662 .name = "wm8731",
@@ -645,8 +664,6 @@ static struct spi_driver wm8731_spi_driver = {
645 .owner = THIS_MODULE, 664 .owner = THIS_MODULE,
646 }, 665 },
647 .probe = wm8731_spi_probe, 666 .probe = wm8731_spi_probe,
648 .suspend = wm8731_spi_suspend,
649 .resume = wm8731_spi_resume,
650 .remove = __devexit_p(wm8731_spi_remove), 667 .remove = __devexit_p(wm8731_spi_remove),
651}; 668};
652#endif /* CONFIG_SPI_MASTER */ 669#endif /* CONFIG_SPI_MASTER */
@@ -679,21 +696,6 @@ static __devexit int wm8731_i2c_remove(struct i2c_client *client)
679 return 0; 696 return 0;
680} 697}
681 698
682#ifdef CONFIG_PM
683static int wm8731_i2c_suspend(struct i2c_client *i2c, pm_message_t msg)
684{
685 return snd_soc_suspend_device(&i2c->dev);
686}
687
688static int wm8731_i2c_resume(struct i2c_client *i2c)
689{
690 return snd_soc_resume_device(&i2c->dev);
691}
692#else
693#define wm8731_i2c_suspend NULL
694#define wm8731_i2c_resume NULL
695#endif
696
697static const struct i2c_device_id wm8731_i2c_id[] = { 699static const struct i2c_device_id wm8731_i2c_id[] = {
698 { "wm8731", 0 }, 700 { "wm8731", 0 },
699 { } 701 { }
@@ -707,8 +709,6 @@ static struct i2c_driver wm8731_i2c_driver = {
707 }, 709 },
708 .probe = wm8731_i2c_probe, 710 .probe = wm8731_i2c_probe,
709 .remove = __devexit_p(wm8731_i2c_remove), 711 .remove = __devexit_p(wm8731_i2c_remove),
710 .suspend = wm8731_i2c_suspend,
711 .resume = wm8731_i2c_resume,
712 .id_table = wm8731_i2c_id, 712 .id_table = wm8731_i2c_id,
713}; 713};
714#endif 714#endif
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 4ba1e7e93fb4..475c67ac7818 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -403,7 +403,6 @@ static int wm8750_add_widgets(struct snd_soc_codec *codec)
403 403
404 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 404 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
405 405
406 snd_soc_dapm_new_widgets(codec);
407 return 0; 406 return 0;
408} 407}
409 408
@@ -772,16 +771,8 @@ static int wm8750_init(struct snd_soc_device *socdev,
772 snd_soc_add_controls(codec, wm8750_snd_controls, 771 snd_soc_add_controls(codec, wm8750_snd_controls,
773 ARRAY_SIZE(wm8750_snd_controls)); 772 ARRAY_SIZE(wm8750_snd_controls));
774 wm8750_add_widgets(codec); 773 wm8750_add_widgets(codec);
775 ret = snd_soc_init_card(socdev);
776 if (ret < 0) {
777 printk(KERN_ERR "wm8750: failed to register card\n");
778 goto card_err;
779 }
780 return ret; 774 return ret;
781 775
782card_err:
783 snd_soc_free_pcms(socdev);
784 snd_soc_dapm_free(socdev);
785err: 776err:
786 kfree(codec->reg_cache); 777 kfree(codec->reg_cache);
787 return ret; 778 return ret;
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index 5ad677ce80da..d6850dacda29 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -673,7 +673,6 @@ static int wm8753_add_widgets(struct snd_soc_codec *codec)
673 673
674 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 674 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
675 675
676 snd_soc_dapm_new_widgets(codec);
677 return 0; 676 return 0;
678} 677}
679 678
@@ -724,8 +723,8 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int target,
724 pll_div->k = K; 723 pll_div->k = K;
725} 724}
726 725
727static int wm8753_set_dai_pll(struct snd_soc_dai *codec_dai, 726static int wm8753_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
728 int pll_id, unsigned int freq_in, unsigned int freq_out) 727 int source, unsigned int freq_in, unsigned int freq_out)
729{ 728{
730 u16 reg, enable; 729 u16 reg, enable;
731 int offset; 730 int offset;
@@ -1583,18 +1582,9 @@ static int wm8753_probe(struct platform_device *pdev)
1583 snd_soc_add_controls(codec, wm8753_snd_controls, 1582 snd_soc_add_controls(codec, wm8753_snd_controls,
1584 ARRAY_SIZE(wm8753_snd_controls)); 1583 ARRAY_SIZE(wm8753_snd_controls));
1585 wm8753_add_widgets(codec); 1584 wm8753_add_widgets(codec);
1586 ret = snd_soc_init_card(socdev);
1587 if (ret < 0) {
1588 printk(KERN_ERR "wm8753: failed to register card\n");
1589 goto card_err;
1590 }
1591 1585
1592 return 0; 1586 return 0;
1593 1587
1594card_err:
1595 snd_soc_free_pcms(socdev);
1596 snd_soc_dapm_free(socdev);
1597
1598pcm_err: 1588pcm_err:
1599 return ret; 1589 return ret;
1600} 1590}
@@ -1767,21 +1757,6 @@ static int wm8753_i2c_remove(struct i2c_client *client)
1767 return 0; 1757 return 0;
1768} 1758}
1769 1759
1770#ifdef CONFIG_PM
1771static int wm8753_i2c_suspend(struct i2c_client *client, pm_message_t msg)
1772{
1773 return snd_soc_suspend_device(&client->dev);
1774}
1775
1776static int wm8753_i2c_resume(struct i2c_client *client)
1777{
1778 return snd_soc_resume_device(&client->dev);
1779}
1780#else
1781#define wm8753_i2c_suspend NULL
1782#define wm8753_i2c_resume NULL
1783#endif
1784
1785static const struct i2c_device_id wm8753_i2c_id[] = { 1760static const struct i2c_device_id wm8753_i2c_id[] = {
1786 { "wm8753", 0 }, 1761 { "wm8753", 0 },
1787 { } 1762 { }
@@ -1795,8 +1770,6 @@ static struct i2c_driver wm8753_i2c_driver = {
1795 }, 1770 },
1796 .probe = wm8753_i2c_probe, 1771 .probe = wm8753_i2c_probe,
1797 .remove = wm8753_i2c_remove, 1772 .remove = wm8753_i2c_remove,
1798 .suspend = wm8753_i2c_suspend,
1799 .resume = wm8753_i2c_resume,
1800 .id_table = wm8753_i2c_id, 1773 .id_table = wm8753_i2c_id,
1801}; 1774};
1802#endif 1775#endif
@@ -1852,22 +1825,6 @@ static int __devexit wm8753_spi_remove(struct spi_device *spi)
1852 return 0; 1825 return 0;
1853} 1826}
1854 1827
1855#ifdef CONFIG_PM
1856static int wm8753_spi_suspend(struct spi_device *spi, pm_message_t msg)
1857{
1858 return snd_soc_suspend_device(&spi->dev);
1859}
1860
1861static int wm8753_spi_resume(struct spi_device *spi)
1862{
1863 return snd_soc_resume_device(&spi->dev);
1864}
1865
1866#else
1867#define wm8753_spi_suspend NULL
1868#define wm8753_spi_resume NULL
1869#endif
1870
1871static struct spi_driver wm8753_spi_driver = { 1828static struct spi_driver wm8753_spi_driver = {
1872 .driver = { 1829 .driver = {
1873 .name = "wm8753", 1830 .name = "wm8753",
@@ -1876,8 +1833,6 @@ static struct spi_driver wm8753_spi_driver = {
1876 }, 1833 },
1877 .probe = wm8753_spi_probe, 1834 .probe = wm8753_spi_probe,
1878 .remove = __devexit_p(wm8753_spi_remove), 1835 .remove = __devexit_p(wm8753_spi_remove),
1879 .suspend = wm8753_spi_suspend,
1880 .resume = wm8753_spi_resume,
1881}; 1836};
1882#endif 1837#endif
1883 1838
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index a9829aa26e53..ab2c0da18091 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -447,17 +447,8 @@ static int wm8776_probe(struct platform_device *pdev)
447 ARRAY_SIZE(wm8776_dapm_widgets)); 447 ARRAY_SIZE(wm8776_dapm_widgets));
448 snd_soc_dapm_add_routes(codec, routes, ARRAY_SIZE(routes)); 448 snd_soc_dapm_add_routes(codec, routes, ARRAY_SIZE(routes));
449 449
450 ret = snd_soc_init_card(socdev);
451 if (ret < 0) {
452 dev_err(codec->dev, "failed to register card: %d\n", ret);
453 goto card_err;
454 }
455
456 return ret; 450 return ret;
457 451
458card_err:
459 snd_soc_free_pcms(socdev);
460 snd_soc_dapm_free(socdev);
461pcm_err: 452pcm_err:
462 return ret; 453 return ret;
463} 454}
@@ -616,21 +607,6 @@ static int __devexit wm8776_spi_remove(struct spi_device *spi)
616 return 0; 607 return 0;
617} 608}
618 609
619#ifdef CONFIG_PM
620static int wm8776_spi_suspend(struct spi_device *spi, pm_message_t msg)
621{
622 return snd_soc_suspend_device(&spi->dev);
623}
624
625static int wm8776_spi_resume(struct spi_device *spi)
626{
627 return snd_soc_resume_device(&spi->dev);
628}
629#else
630#define wm8776_spi_suspend NULL
631#define wm8776_spi_resume NULL
632#endif
633
634static struct spi_driver wm8776_spi_driver = { 610static struct spi_driver wm8776_spi_driver = {
635 .driver = { 611 .driver = {
636 .name = "wm8776", 612 .name = "wm8776",
@@ -638,8 +614,6 @@ static struct spi_driver wm8776_spi_driver = {
638 .owner = THIS_MODULE, 614 .owner = THIS_MODULE,
639 }, 615 },
640 .probe = wm8776_spi_probe, 616 .probe = wm8776_spi_probe,
641 .suspend = wm8776_spi_suspend,
642 .resume = wm8776_spi_resume,
643 .remove = __devexit_p(wm8776_spi_remove), 617 .remove = __devexit_p(wm8776_spi_remove),
644}; 618};
645#endif /* CONFIG_SPI_MASTER */ 619#endif /* CONFIG_SPI_MASTER */
@@ -673,21 +647,6 @@ static __devexit int wm8776_i2c_remove(struct i2c_client *client)
673 return 0; 647 return 0;
674} 648}
675 649
676#ifdef CONFIG_PM
677static int wm8776_i2c_suspend(struct i2c_client *i2c, pm_message_t msg)
678{
679 return snd_soc_suspend_device(&i2c->dev);
680}
681
682static int wm8776_i2c_resume(struct i2c_client *i2c)
683{
684 return snd_soc_resume_device(&i2c->dev);
685}
686#else
687#define wm8776_i2c_suspend NULL
688#define wm8776_i2c_resume NULL
689#endif
690
691static const struct i2c_device_id wm8776_i2c_id[] = { 650static const struct i2c_device_id wm8776_i2c_id[] = {
692 { "wm8776", 0 }, 651 { "wm8776", 0 },
693 { } 652 { }
@@ -701,8 +660,6 @@ static struct i2c_driver wm8776_i2c_driver = {
701 }, 660 },
702 .probe = wm8776_i2c_probe, 661 .probe = wm8776_i2c_probe,
703 .remove = __devexit_p(wm8776_i2c_remove), 662 .remove = __devexit_p(wm8776_i2c_remove),
704 .suspend = wm8776_i2c_suspend,
705 .resume = wm8776_i2c_resume,
706 .id_table = wm8776_i2c_id, 663 .id_table = wm8776_i2c_id,
707}; 664};
708#endif 665#endif
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index 5e9c855c0036..c9438dd62df3 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -618,8 +618,6 @@ static int wm8900_add_widgets(struct snd_soc_codec *codec)
618 618
619 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 619 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
620 620
621 snd_soc_dapm_new_widgets(codec);
622
623 return 0; 621 return 0;
624} 622}
625 623
@@ -814,8 +812,8 @@ reenable:
814 return 0; 812 return 0;
815} 813}
816 814
817static int wm8900_set_dai_pll(struct snd_soc_dai *codec_dai, 815static int wm8900_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
818 int pll_id, unsigned int freq_in, unsigned int freq_out) 816 int source, unsigned int freq_in, unsigned int freq_out)
819{ 817{
820 return wm8900_set_fll(codec_dai->codec, pll_id, freq_in, freq_out); 818 return wm8900_set_fll(codec_dai->codec, pll_id, freq_in, freq_out);
821} 819}
@@ -1312,21 +1310,6 @@ static __devexit int wm8900_i2c_remove(struct i2c_client *client)
1312 return 0; 1310 return 0;
1313} 1311}
1314 1312
1315#ifdef CONFIG_PM
1316static int wm8900_i2c_suspend(struct i2c_client *client, pm_message_t msg)
1317{
1318 return snd_soc_suspend_device(&client->dev);
1319}
1320
1321static int wm8900_i2c_resume(struct i2c_client *client)
1322{
1323 return snd_soc_resume_device(&client->dev);
1324}
1325#else
1326#define wm8900_i2c_suspend NULL
1327#define wm8900_i2c_resume NULL
1328#endif
1329
1330static const struct i2c_device_id wm8900_i2c_id[] = { 1313static const struct i2c_device_id wm8900_i2c_id[] = {
1331 { "wm8900", 0 }, 1314 { "wm8900", 0 },
1332 { } 1315 { }
@@ -1340,8 +1323,6 @@ static struct i2c_driver wm8900_i2c_driver = {
1340 }, 1323 },
1341 .probe = wm8900_i2c_probe, 1324 .probe = wm8900_i2c_probe,
1342 .remove = __devexit_p(wm8900_i2c_remove), 1325 .remove = __devexit_p(wm8900_i2c_remove),
1343 .suspend = wm8900_i2c_suspend,
1344 .resume = wm8900_i2c_resume,
1345 .id_table = wm8900_i2c_id, 1326 .id_table = wm8900_i2c_id,
1346}; 1327};
1347 1328
@@ -1370,17 +1351,6 @@ static int wm8900_probe(struct platform_device *pdev)
1370 ARRAY_SIZE(wm8900_snd_controls)); 1351 ARRAY_SIZE(wm8900_snd_controls));
1371 wm8900_add_widgets(codec); 1352 wm8900_add_widgets(codec);
1372 1353
1373 ret = snd_soc_init_card(socdev);
1374 if (ret < 0) {
1375 dev_err(&pdev->dev, "Failed to register card\n");
1376 goto card_err;
1377 }
1378
1379 return ret;
1380
1381card_err:
1382 snd_soc_free_pcms(socdev);
1383 snd_soc_dapm_free(socdev);
1384pcm_err: 1354pcm_err:
1385 return ret; 1355 return ret;
1386} 1356}
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index fe1307b500cf..ce5515e3f2b0 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -607,7 +607,7 @@ SOC_SINGLE("Right Input PGA Common Mode Switch", WM8903_ANALOGUE_RIGHT_INPUT_1,
607SOC_SINGLE("DRC Switch", WM8903_DRC_0, 15, 1, 0), 607SOC_SINGLE("DRC Switch", WM8903_DRC_0, 15, 1, 0),
608SOC_ENUM("DRC Compressor Slope R0", drc_slope_r0), 608SOC_ENUM("DRC Compressor Slope R0", drc_slope_r0),
609SOC_ENUM("DRC Compressor Slope R1", drc_slope_r1), 609SOC_ENUM("DRC Compressor Slope R1", drc_slope_r1),
610SOC_SINGLE_TLV("DRC Compressor Threashold Volume", WM8903_DRC_3, 5, 124, 1, 610SOC_SINGLE_TLV("DRC Compressor Threshold Volume", WM8903_DRC_3, 5, 124, 1,
611 drc_tlv_thresh), 611 drc_tlv_thresh),
612SOC_SINGLE_TLV("DRC Volume", WM8903_DRC_3, 0, 30, 1, drc_tlv_amp), 612SOC_SINGLE_TLV("DRC Volume", WM8903_DRC_3, 0, 30, 1, drc_tlv_amp),
613SOC_SINGLE_TLV("DRC Minimum Gain Volume", WM8903_DRC_1, 2, 3, 1, drc_tlv_min), 613SOC_SINGLE_TLV("DRC Minimum Gain Volume", WM8903_DRC_1, 2, 3, 1, drc_tlv_min),
@@ -617,11 +617,11 @@ SOC_ENUM("DRC Decay Rate", drc_decay),
617SOC_ENUM("DRC FF Delay", drc_ff_delay), 617SOC_ENUM("DRC FF Delay", drc_ff_delay),
618SOC_SINGLE("DRC Anticlip Switch", WM8903_DRC_0, 1, 1, 0), 618SOC_SINGLE("DRC Anticlip Switch", WM8903_DRC_0, 1, 1, 0),
619SOC_SINGLE("DRC QR Switch", WM8903_DRC_0, 2, 1, 0), 619SOC_SINGLE("DRC QR Switch", WM8903_DRC_0, 2, 1, 0),
620SOC_SINGLE_TLV("DRC QR Threashold Volume", WM8903_DRC_0, 6, 3, 0, drc_tlv_max), 620SOC_SINGLE_TLV("DRC QR Threshold Volume", WM8903_DRC_0, 6, 3, 0, drc_tlv_max),
621SOC_ENUM("DRC QR Decay Rate", drc_qr_decay), 621SOC_ENUM("DRC QR Decay Rate", drc_qr_decay),
622SOC_SINGLE("DRC Smoothing Switch", WM8903_DRC_0, 3, 1, 0), 622SOC_SINGLE("DRC Smoothing Switch", WM8903_DRC_0, 3, 1, 0),
623SOC_SINGLE("DRC Smoothing Hysteresis Switch", WM8903_DRC_0, 0, 1, 0), 623SOC_SINGLE("DRC Smoothing Hysteresis Switch", WM8903_DRC_0, 0, 1, 0),
624SOC_ENUM("DRC Smoothing Threashold", drc_smoothing), 624SOC_ENUM("DRC Smoothing Threshold", drc_smoothing),
625SOC_SINGLE_TLV("DRC Startup Volume", WM8903_DRC_0, 6, 18, 0, drc_tlv_startup), 625SOC_SINGLE_TLV("DRC Startup Volume", WM8903_DRC_0, 6, 18, 0, drc_tlv_startup),
626 626
627SOC_DOUBLE_R_TLV("Digital Capture Volume", WM8903_ADC_DIGITAL_VOLUME_LEFT, 627SOC_DOUBLE_R_TLV("Digital Capture Volume", WM8903_ADC_DIGITAL_VOLUME_LEFT,
@@ -919,8 +919,6 @@ static int wm8903_add_widgets(struct snd_soc_codec *codec)
919 919
920 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 920 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
921 921
922 snd_soc_dapm_new_widgets(codec);
923
924 return 0; 922 return 0;
925} 923}
926 924
@@ -1655,21 +1653,6 @@ static __devexit int wm8903_i2c_remove(struct i2c_client *client)
1655 return 0; 1653 return 0;
1656} 1654}
1657 1655
1658#ifdef CONFIG_PM
1659static int wm8903_i2c_suspend(struct i2c_client *client, pm_message_t msg)
1660{
1661 return snd_soc_suspend_device(&client->dev);
1662}
1663
1664static int wm8903_i2c_resume(struct i2c_client *client)
1665{
1666 return snd_soc_resume_device(&client->dev);
1667}
1668#else
1669#define wm8903_i2c_suspend NULL
1670#define wm8903_i2c_resume NULL
1671#endif
1672
1673/* i2c codec control layer */ 1656/* i2c codec control layer */
1674static const struct i2c_device_id wm8903_i2c_id[] = { 1657static const struct i2c_device_id wm8903_i2c_id[] = {
1675 { "wm8903", 0 }, 1658 { "wm8903", 0 },
@@ -1684,8 +1667,6 @@ static struct i2c_driver wm8903_i2c_driver = {
1684 }, 1667 },
1685 .probe = wm8903_i2c_probe, 1668 .probe = wm8903_i2c_probe,
1686 .remove = __devexit_p(wm8903_i2c_remove), 1669 .remove = __devexit_p(wm8903_i2c_remove),
1687 .suspend = wm8903_i2c_suspend,
1688 .resume = wm8903_i2c_resume,
1689 .id_table = wm8903_i2c_id, 1670 .id_table = wm8903_i2c_id,
1690}; 1671};
1691 1672
@@ -1712,17 +1693,8 @@ static int wm8903_probe(struct platform_device *pdev)
1712 ARRAY_SIZE(wm8903_snd_controls)); 1693 ARRAY_SIZE(wm8903_snd_controls));
1713 wm8903_add_widgets(socdev->card->codec); 1694 wm8903_add_widgets(socdev->card->codec);
1714 1695
1715 ret = snd_soc_init_card(socdev);
1716 if (ret < 0) {
1717 dev_err(&pdev->dev, "wm8903: failed to register card\n");
1718 goto card_err;
1719 }
1720
1721 return ret; 1696 return ret;
1722 1697
1723card_err:
1724 snd_soc_free_pcms(socdev);
1725 snd_soc_dapm_free(socdev);
1726err: 1698err:
1727 return ret; 1699 return ret;
1728} 1700}
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index 1ef2454c5205..3d850b97037a 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -298,7 +298,6 @@ static int wm8940_add_widgets(struct snd_soc_codec *codec)
298 ret = snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 298 ret = snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
299 if (ret) 299 if (ret)
300 goto error_ret; 300 goto error_ret;
301 ret = snd_soc_dapm_new_widgets(codec);
302 301
303error_ret: 302error_ret:
304 return ret; 303 return ret;
@@ -536,8 +535,8 @@ static void pll_factors(unsigned int target, unsigned int source)
536} 535}
537 536
538/* Untested at the moment */ 537/* Untested at the moment */
539static int wm8940_set_dai_pll(struct snd_soc_dai *codec_dai, 538static int wm8940_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
540 int pll_id, unsigned int freq_in, unsigned int freq_out) 539 int source, unsigned int freq_in, unsigned int freq_out)
541{ 540{
542 struct snd_soc_codec *codec = codec_dai->codec; 541 struct snd_soc_codec *codec = codec_dai->codec;
543 u16 reg; 542 u16 reg;
@@ -731,12 +730,6 @@ static int wm8940_probe(struct platform_device *pdev)
731 if (ret) 730 if (ret)
732 goto error_free_pcms; 731 goto error_free_pcms;
733 732
734 ret = snd_soc_init_card(socdev);
735 if (ret < 0) {
736 dev_err(codec->dev, "failed to register card: %d\n", ret);
737 goto error_free_pcms;
738 }
739
740 return ret; 733 return ret;
741 734
742error_free_pcms: 735error_free_pcms:
@@ -877,21 +870,6 @@ static int __devexit wm8940_i2c_remove(struct i2c_client *client)
877 return 0; 870 return 0;
878} 871}
879 872
880#ifdef CONFIG_PM
881static int wm8940_i2c_suspend(struct i2c_client *client, pm_message_t msg)
882{
883 return snd_soc_suspend_device(&client->dev);
884}
885
886static int wm8940_i2c_resume(struct i2c_client *client)
887{
888 return snd_soc_resume_device(&client->dev);
889}
890#else
891#define wm8940_i2c_suspend NULL
892#define wm8940_i2c_resume NULL
893#endif
894
895static const struct i2c_device_id wm8940_i2c_id[] = { 873static const struct i2c_device_id wm8940_i2c_id[] = {
896 { "wm8940", 0 }, 874 { "wm8940", 0 },
897 { } 875 { }
@@ -905,8 +883,6 @@ static struct i2c_driver wm8940_i2c_driver = {
905 }, 883 },
906 .probe = wm8940_i2c_probe, 884 .probe = wm8940_i2c_probe,
907 .remove = __devexit_p(wm8940_i2c_remove), 885 .remove = __devexit_p(wm8940_i2c_remove),
908 .suspend = wm8940_i2c_suspend,
909 .resume = wm8940_i2c_resume,
910 .id_table = wm8940_i2c_id, 886 .id_table = wm8940_i2c_id,
911}; 887};
912 888
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index f59703be61c8..d07bcc1e1c60 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -307,7 +307,6 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
307 307
308 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 308 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
309 309
310 snd_soc_dapm_new_widgets(codec);
311 return 0; 310 return 0;
312} 311}
313 312
@@ -540,8 +539,8 @@ static int pll_factors(unsigned int source, unsigned int target,
540 return 0; 539 return 0;
541} 540}
542 541
543static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, 542static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
544 int pll_id, unsigned int freq_in, unsigned int freq_out) 543 int source, unsigned int freq_in, unsigned int freq_out)
545{ 544{
546 struct snd_soc_codec *codec = codec_dai->codec; 545 struct snd_soc_codec *codec = codec_dai->codec;
547 u16 reg; 546 u16 reg;
@@ -713,17 +712,9 @@ static int wm8960_probe(struct platform_device *pdev)
713 snd_soc_add_controls(codec, wm8960_snd_controls, 712 snd_soc_add_controls(codec, wm8960_snd_controls,
714 ARRAY_SIZE(wm8960_snd_controls)); 713 ARRAY_SIZE(wm8960_snd_controls));
715 wm8960_add_widgets(codec); 714 wm8960_add_widgets(codec);
716 ret = snd_soc_init_card(socdev);
717 if (ret < 0) {
718 dev_err(codec->dev, "failed to register card: %d\n", ret);
719 goto card_err;
720 }
721 715
722 return ret; 716 return ret;
723 717
724card_err:
725 snd_soc_free_pcms(socdev);
726 snd_soc_dapm_free(socdev);
727pcm_err: 718pcm_err:
728 return ret; 719 return ret;
729} 720}
@@ -883,21 +874,6 @@ static __devexit int wm8960_i2c_remove(struct i2c_client *client)
883 return 0; 874 return 0;
884} 875}
885 876
886#ifdef CONFIG_PM
887static int wm8960_i2c_suspend(struct i2c_client *client, pm_message_t msg)
888{
889 return snd_soc_suspend_device(&client->dev);
890}
891
892static int wm8960_i2c_resume(struct i2c_client *client)
893{
894 return snd_soc_resume_device(&client->dev);
895}
896#else
897#define wm8960_i2c_suspend NULL
898#define wm8960_i2c_resume NULL
899#endif
900
901static const struct i2c_device_id wm8960_i2c_id[] = { 877static const struct i2c_device_id wm8960_i2c_id[] = {
902 { "wm8960", 0 }, 878 { "wm8960", 0 },
903 { } 879 { }
@@ -911,8 +887,6 @@ static struct i2c_driver wm8960_i2c_driver = {
911 }, 887 },
912 .probe = wm8960_i2c_probe, 888 .probe = wm8960_i2c_probe,
913 .remove = __devexit_p(wm8960_i2c_remove), 889 .remove = __devexit_p(wm8960_i2c_remove),
914 .suspend = wm8960_i2c_suspend,
915 .resume = wm8960_i2c_resume,
916 .id_table = wm8960_i2c_id, 890 .id_table = wm8960_i2c_id,
917}; 891};
918 892
diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c
index 503032085899..a8007d58813f 100644
--- a/sound/soc/codecs/wm8961.c
+++ b/sound/soc/codecs/wm8961.c
@@ -986,19 +986,9 @@ static int wm8961_probe(struct platform_device *pdev)
986 snd_soc_dapm_new_controls(codec, wm8961_dapm_widgets, 986 snd_soc_dapm_new_controls(codec, wm8961_dapm_widgets,
987 ARRAY_SIZE(wm8961_dapm_widgets)); 987 ARRAY_SIZE(wm8961_dapm_widgets));
988 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 988 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
989 snd_soc_dapm_new_widgets(codec);
990
991 ret = snd_soc_init_card(socdev);
992 if (ret < 0) {
993 dev_err(codec->dev, "failed to register card: %d\n", ret);
994 goto card_err;
995 }
996 989
997 return ret; 990 return ret;
998 991
999card_err:
1000 snd_soc_free_pcms(socdev);
1001 snd_soc_dapm_free(socdev);
1002pcm_err: 992pcm_err:
1003 return ret; 993 return ret;
1004} 994}
@@ -1206,21 +1196,6 @@ static __devexit int wm8961_i2c_remove(struct i2c_client *client)
1206 return 0; 1196 return 0;
1207} 1197}
1208 1198
1209#ifdef CONFIG_PM
1210static int wm8961_i2c_suspend(struct i2c_client *client, pm_message_t state)
1211{
1212 return snd_soc_suspend_device(&client->dev);
1213}
1214
1215static int wm8961_i2c_resume(struct i2c_client *client)
1216{
1217 return snd_soc_resume_device(&client->dev);
1218}
1219#else
1220#define wm8961_i2c_suspend NULL
1221#define wm8961_i2c_resume NULL
1222#endif
1223
1224static const struct i2c_device_id wm8961_i2c_id[] = { 1199static const struct i2c_device_id wm8961_i2c_id[] = {
1225 { "wm8961", 0 }, 1200 { "wm8961", 0 },
1226 { } 1201 { }
@@ -1234,8 +1209,6 @@ static struct i2c_driver wm8961_i2c_driver = {
1234 }, 1209 },
1235 .probe = wm8961_i2c_probe, 1210 .probe = wm8961_i2c_probe,
1236 .remove = __devexit_p(wm8961_i2c_remove), 1211 .remove = __devexit_p(wm8961_i2c_remove),
1237 .suspend = wm8961_i2c_suspend,
1238 .resume = wm8961_i2c_resume,
1239 .id_table = wm8961_i2c_id, 1212 .id_table = wm8961_i2c_id,
1240}; 1213};
1241 1214
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
index d66efb0546ea..d9540d55fc89 100644
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -338,8 +338,6 @@ static int wm8971_add_widgets(struct snd_soc_codec *codec)
338 338
339 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 339 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
340 340
341 snd_soc_dapm_new_widgets(codec);
342
343 return 0; 341 return 0;
344} 342}
345 343
@@ -703,16 +701,9 @@ static int wm8971_init(struct snd_soc_device *socdev,
703 snd_soc_add_controls(codec, wm8971_snd_controls, 701 snd_soc_add_controls(codec, wm8971_snd_controls,
704 ARRAY_SIZE(wm8971_snd_controls)); 702 ARRAY_SIZE(wm8971_snd_controls));
705 wm8971_add_widgets(codec); 703 wm8971_add_widgets(codec);
706 ret = snd_soc_init_card(socdev); 704
707 if (ret < 0) {
708 printk(KERN_ERR "wm8971: failed to register card\n");
709 goto card_err;
710 }
711 return ret; 705 return ret;
712 706
713card_err:
714 snd_soc_free_pcms(socdev);
715 snd_soc_dapm_free(socdev);
716err: 707err:
717 kfree(codec->reg_cache); 708 kfree(codec->reg_cache);
718 return ret; 709 return ret;
diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c
index 98d663afc97d..81c57b5c591c 100644
--- a/sound/soc/codecs/wm8974.c
+++ b/sound/soc/codecs/wm8974.c
@@ -276,41 +276,42 @@ static int wm8974_add_widgets(struct snd_soc_codec *codec)
276 276
277 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 277 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
278 278
279 snd_soc_dapm_new_widgets(codec);
280 return 0; 279 return 0;
281} 280}
282 281
283struct pll_ { 282struct pll_ {
284 unsigned int pre_div:4; /* prescale - 1 */ 283 unsigned int pre_div:1;
285 unsigned int n:4; 284 unsigned int n:4;
286 unsigned int k; 285 unsigned int k;
287}; 286};
288 287
289static struct pll_ pll_div;
290
291/* The size in bits of the pll divide multiplied by 10 288/* The size in bits of the pll divide multiplied by 10
292 * to allow rounding later */ 289 * to allow rounding later */
293#define FIXED_PLL_SIZE ((1 << 24) * 10) 290#define FIXED_PLL_SIZE ((1 << 24) * 10)
294 291
295static void pll_factors(unsigned int target, unsigned int source) 292static void pll_factors(struct pll_ *pll_div,
293 unsigned int target, unsigned int source)
296{ 294{
297 unsigned long long Kpart; 295 unsigned long long Kpart;
298 unsigned int K, Ndiv, Nmod; 296 unsigned int K, Ndiv, Nmod;
299 297
298 /* There is a fixed divide by 4 in the output path */
299 target *= 4;
300
300 Ndiv = target / source; 301 Ndiv = target / source;
301 if (Ndiv < 6) { 302 if (Ndiv < 6) {
302 source >>= 1; 303 source /= 2;
303 pll_div.pre_div = 1; 304 pll_div->pre_div = 1;
304 Ndiv = target / source; 305 Ndiv = target / source;
305 } else 306 } else
306 pll_div.pre_div = 0; 307 pll_div->pre_div = 0;
307 308
308 if ((Ndiv < 6) || (Ndiv > 12)) 309 if ((Ndiv < 6) || (Ndiv > 12))
309 printk(KERN_WARNING 310 printk(KERN_WARNING
310 "WM8974 N value %u outwith recommended range!\n", 311 "WM8974 N value %u outwith recommended range!\n",
311 Ndiv); 312 Ndiv);
312 313
313 pll_div.n = Ndiv; 314 pll_div->n = Ndiv;
314 Nmod = target % source; 315 Nmod = target % source;
315 Kpart = FIXED_PLL_SIZE * (long long)Nmod; 316 Kpart = FIXED_PLL_SIZE * (long long)Nmod;
316 317
@@ -325,13 +326,14 @@ static void pll_factors(unsigned int target, unsigned int source)
325 /* Move down to proper range now rounding is done */ 326 /* Move down to proper range now rounding is done */
326 K /= 10; 327 K /= 10;
327 328
328 pll_div.k = K; 329 pll_div->k = K;
329} 330}
330 331
331static int wm8974_set_dai_pll(struct snd_soc_dai *codec_dai, 332static int wm8974_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
332 int pll_id, unsigned int freq_in, unsigned int freq_out) 333 int source, unsigned int freq_in, unsigned int freq_out)
333{ 334{
334 struct snd_soc_codec *codec = codec_dai->codec; 335 struct snd_soc_codec *codec = codec_dai->codec;
336 struct pll_ pll_div;
335 u16 reg; 337 u16 reg;
336 338
337 if (freq_in == 0 || freq_out == 0) { 339 if (freq_in == 0 || freq_out == 0) {
@@ -345,7 +347,7 @@ static int wm8974_set_dai_pll(struct snd_soc_dai *codec_dai,
345 return 0; 347 return 0;
346 } 348 }
347 349
348 pll_factors(freq_out*4, freq_in); 350 pll_factors(&pll_div, freq_out, freq_in);
349 351
350 snd_soc_write(codec, WM8974_PLLN, (pll_div.pre_div << 4) | pll_div.n); 352 snd_soc_write(codec, WM8974_PLLN, (pll_div.pre_div << 4) | pll_div.n);
351 snd_soc_write(codec, WM8974_PLLK1, pll_div.k >> 18); 353 snd_soc_write(codec, WM8974_PLLK1, pll_div.k >> 18);
@@ -638,17 +640,9 @@ static int wm8974_probe(struct platform_device *pdev)
638 snd_soc_add_controls(codec, wm8974_snd_controls, 640 snd_soc_add_controls(codec, wm8974_snd_controls,
639 ARRAY_SIZE(wm8974_snd_controls)); 641 ARRAY_SIZE(wm8974_snd_controls));
640 wm8974_add_widgets(codec); 642 wm8974_add_widgets(codec);
641 ret = snd_soc_init_card(socdev);
642 if (ret < 0) {
643 dev_err(codec->dev, "failed to register card: %d\n", ret);
644 goto card_err;
645 }
646 643
647 return ret; 644 return ret;
648 645
649card_err:
650 snd_soc_free_pcms(socdev);
651 snd_soc_dapm_free(socdev);
652pcm_err: 646pcm_err:
653 return ret; 647 return ret;
654} 648}
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index 3f530f8a972a..2862e4dced27 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -790,19 +790,9 @@ static int wm8988_probe(struct platform_device *pdev)
790 snd_soc_dapm_new_controls(codec, wm8988_dapm_widgets, 790 snd_soc_dapm_new_controls(codec, wm8988_dapm_widgets,
791 ARRAY_SIZE(wm8988_dapm_widgets)); 791 ARRAY_SIZE(wm8988_dapm_widgets));
792 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 792 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
793 snd_soc_dapm_new_widgets(codec);
794
795 ret = snd_soc_init_card(socdev);
796 if (ret < 0) {
797 dev_err(codec->dev, "failed to register card: %d\n", ret);
798 goto card_err;
799 }
800 793
801 return ret; 794 return ret;
802 795
803card_err:
804 snd_soc_free_pcms(socdev);
805 snd_soc_dapm_free(socdev);
806pcm_err: 796pcm_err:
807 return ret; 797 return ret;
808} 798}
@@ -944,21 +934,6 @@ static int wm8988_i2c_remove(struct i2c_client *client)
944 return 0; 934 return 0;
945} 935}
946 936
947#ifdef CONFIG_PM
948static int wm8988_i2c_suspend(struct i2c_client *client, pm_message_t msg)
949{
950 return snd_soc_suspend_device(&client->dev);
951}
952
953static int wm8988_i2c_resume(struct i2c_client *client)
954{
955 return snd_soc_resume_device(&client->dev);
956}
957#else
958#define wm8988_i2c_suspend NULL
959#define wm8988_i2c_resume NULL
960#endif
961
962static const struct i2c_device_id wm8988_i2c_id[] = { 937static const struct i2c_device_id wm8988_i2c_id[] = {
963 { "wm8988", 0 }, 938 { "wm8988", 0 },
964 { } 939 { }
@@ -972,8 +947,6 @@ static struct i2c_driver wm8988_i2c_driver = {
972 }, 947 },
973 .probe = wm8988_i2c_probe, 948 .probe = wm8988_i2c_probe,
974 .remove = wm8988_i2c_remove, 949 .remove = wm8988_i2c_remove,
975 .suspend = wm8988_i2c_suspend,
976 .resume = wm8988_i2c_resume,
977 .id_table = wm8988_i2c_id, 950 .id_table = wm8988_i2c_id,
978}; 951};
979#endif 952#endif
@@ -1006,21 +979,6 @@ static int __devexit wm8988_spi_remove(struct spi_device *spi)
1006 return 0; 979 return 0;
1007} 980}
1008 981
1009#ifdef CONFIG_PM
1010static int wm8988_spi_suspend(struct spi_device *spi, pm_message_t msg)
1011{
1012 return snd_soc_suspend_device(&spi->dev);
1013}
1014
1015static int wm8988_spi_resume(struct spi_device *spi)
1016{
1017 return snd_soc_resume_device(&spi->dev);
1018}
1019#else
1020#define wm8988_spi_suspend NULL
1021#define wm8988_spi_resume NULL
1022#endif
1023
1024static struct spi_driver wm8988_spi_driver = { 982static struct spi_driver wm8988_spi_driver = {
1025 .driver = { 983 .driver = {
1026 .name = "wm8988", 984 .name = "wm8988",
@@ -1029,8 +987,6 @@ static struct spi_driver wm8988_spi_driver = {
1029 }, 987 },
1030 .probe = wm8988_spi_probe, 988 .probe = wm8988_spi_probe,
1031 .remove = __devexit_p(wm8988_spi_remove), 989 .remove = __devexit_p(wm8988_spi_remove),
1032 .suspend = wm8988_spi_suspend,
1033 .resume = wm8988_spi_resume,
1034}; 990};
1035#endif 991#endif
1036 992
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index 2d702db4131d..341481e0e830 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -920,7 +920,6 @@ static int wm8990_add_widgets(struct snd_soc_codec *codec)
920 /* set up the WM8990 audio map */ 920 /* set up the WM8990 audio map */
921 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 921 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
922 922
923 snd_soc_dapm_new_widgets(codec);
924 return 0; 923 return 0;
925} 924}
926 925
@@ -972,8 +971,8 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int target,
972 pll_div->k = K; 971 pll_div->k = K;
973} 972}
974 973
975static int wm8990_set_dai_pll(struct snd_soc_dai *codec_dai, 974static int wm8990_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
976 int pll_id, unsigned int freq_in, unsigned int freq_out) 975 int source, unsigned int freq_in, unsigned int freq_out)
977{ 976{
978 u16 reg; 977 u16 reg;
979 struct snd_soc_codec *codec = codec_dai->codec; 978 struct snd_soc_codec *codec = codec_dai->codec;
@@ -1409,16 +1408,9 @@ static int wm8990_init(struct snd_soc_device *socdev)
1409 snd_soc_add_controls(codec, wm8990_snd_controls, 1408 snd_soc_add_controls(codec, wm8990_snd_controls,
1410 ARRAY_SIZE(wm8990_snd_controls)); 1409 ARRAY_SIZE(wm8990_snd_controls));
1411 wm8990_add_widgets(codec); 1410 wm8990_add_widgets(codec);
1412 ret = snd_soc_init_card(socdev); 1411
1413 if (ret < 0) {
1414 printk(KERN_ERR "wm8990: failed to register card\n");
1415 goto card_err;
1416 }
1417 return ret; 1412 return ret;
1418 1413
1419card_err:
1420 snd_soc_free_pcms(socdev);
1421 snd_soc_dapm_free(socdev);
1422pcm_err: 1414pcm_err:
1423 kfree(codec->reg_cache); 1415 kfree(codec->reg_cache);
1424 return ret; 1416 return ret;
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index d9987999e92c..2981afae842c 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -422,7 +422,7 @@ static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
422 return 0; 422 return 0;
423} 423}
424 424
425static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, 425static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
426 unsigned int Fref, unsigned int Fout) 426 unsigned int Fref, unsigned int Fout)
427{ 427{
428 struct snd_soc_codec *codec = dai->codec; 428 struct snd_soc_codec *codec = dai->codec;
@@ -689,7 +689,7 @@ SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8993_DIGITAL_SIDE_TONE,
689 689
690SOC_SINGLE("DRC Switch", WM8993_DRC_CONTROL_1, 15, 1, 0), 690SOC_SINGLE("DRC Switch", WM8993_DRC_CONTROL_1, 15, 1, 0),
691SOC_ENUM("DRC Path", drc_path), 691SOC_ENUM("DRC Path", drc_path),
692SOC_SINGLE_TLV("DRC Compressor Threashold Volume", WM8993_DRC_CONTROL_2, 692SOC_SINGLE_TLV("DRC Compressor Threshold Volume", WM8993_DRC_CONTROL_2,
693 2, 60, 1, drc_comp_threash), 693 2, 60, 1, drc_comp_threash),
694SOC_SINGLE_TLV("DRC Compressor Amplitude Volume", WM8993_DRC_CONTROL_3, 694SOC_SINGLE_TLV("DRC Compressor Amplitude Volume", WM8993_DRC_CONTROL_3,
695 11, 30, 1, drc_comp_amp), 695 11, 30, 1, drc_comp_amp),
@@ -709,7 +709,7 @@ SOC_SINGLE_TLV("DRC Quick Release Volume", WM8993_DRC_CONTROL_3, 2, 3, 0,
709SOC_ENUM("DRC Quick Release Rate", drc_qr_rate), 709SOC_ENUM("DRC Quick Release Rate", drc_qr_rate),
710SOC_SINGLE("DRC Smoothing Switch", WM8993_DRC_CONTROL_1, 11, 1, 0), 710SOC_SINGLE("DRC Smoothing Switch", WM8993_DRC_CONTROL_1, 11, 1, 0),
711SOC_SINGLE("DRC Smoothing Hysteresis Switch", WM8993_DRC_CONTROL_1, 8, 1, 0), 711SOC_SINGLE("DRC Smoothing Hysteresis Switch", WM8993_DRC_CONTROL_1, 8, 1, 0),
712SOC_ENUM("DRC Smoothing Hysteresis Threashold", drc_smooth), 712SOC_ENUM("DRC Smoothing Hysteresis Threshold", drc_smooth),
713SOC_SINGLE_TLV("DRC Startup Volume", WM8993_DRC_CONTROL_4, 8, 18, 0, 713SOC_SINGLE_TLV("DRC Startup Volume", WM8993_DRC_CONTROL_4, 8, 18, 0,
714 drc_startup_tlv), 714 drc_startup_tlv),
715 715
@@ -1464,19 +1464,8 @@ static int wm8993_probe(struct platform_device *pdev)
1464 wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff, 1464 wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff,
1465 wm8993->pdata.lineout2_diff); 1465 wm8993->pdata.lineout2_diff);
1466 1466
1467 snd_soc_dapm_new_widgets(codec);
1468
1469 ret = snd_soc_init_card(socdev);
1470 if (ret < 0) {
1471 dev_err(codec->dev, "failed to register card\n");
1472 goto card_err;
1473 }
1474
1475 return ret; 1467 return ret;
1476 1468
1477card_err:
1478 snd_soc_free_pcms(socdev);
1479 snd_soc_dapm_free(socdev);
1480err: 1469err:
1481 return ret; 1470 return ret;
1482} 1471}
@@ -1572,33 +1561,15 @@ static int wm8993_i2c_probe(struct i2c_client *i2c,
1572 /* Use automatic clock configuration */ 1561 /* Use automatic clock configuration */
1573 snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0); 1562 snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0);
1574 1563
1575 if (!wm8993->pdata.lineout1_diff) 1564 wm_hubs_handle_analogue_pdata(codec, wm8993->pdata.lineout1_diff,
1576 snd_soc_update_bits(codec, WM8993_LINE_MIXER1, 1565 wm8993->pdata.lineout2_diff,
1577 WM8993_LINEOUT1_MODE, 1566 wm8993->pdata.lineout1fb,
1578 WM8993_LINEOUT1_MODE); 1567 wm8993->pdata.lineout2fb,
1579 if (!wm8993->pdata.lineout2_diff) 1568 wm8993->pdata.jd_scthr,
1580 snd_soc_update_bits(codec, WM8993_LINE_MIXER2, 1569 wm8993->pdata.jd_thr,
1581 WM8993_LINEOUT2_MODE, 1570 wm8993->pdata.micbias1_lvl,
1582 WM8993_LINEOUT2_MODE); 1571 wm8993->pdata.micbias2_lvl);
1583 1572
1584 if (wm8993->pdata.lineout1fb)
1585 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
1586 WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
1587
1588 if (wm8993->pdata.lineout2fb)
1589 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
1590 WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
1591
1592 /* Apply the microphone bias/detection configuration - the
1593 * platform data is directly applicable to the register. */
1594 snd_soc_update_bits(codec, WM8993_MICBIAS,
1595 WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
1596 WM8993_MICB1_LVL | WM8993_MICB2_LVL,
1597 wm8993->pdata.jd_scthr << WM8993_JD_SCTHR_SHIFT |
1598 wm8993->pdata.jd_thr << WM8993_JD_THR_SHIFT |
1599 wm8993->pdata.micbias1_lvl |
1600 wm8993->pdata.micbias1_lvl << 1);
1601
1602 ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1573 ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1603 if (ret != 0) 1574 if (ret != 0)
1604 goto err; 1575 goto err;
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index 686e5aa97206..c468497314ba 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -1262,19 +1262,9 @@ static int wm9081_probe(struct platform_device *pdev)
1262 snd_soc_dapm_new_controls(codec, wm9081_dapm_widgets, 1262 snd_soc_dapm_new_controls(codec, wm9081_dapm_widgets,
1263 ARRAY_SIZE(wm9081_dapm_widgets)); 1263 ARRAY_SIZE(wm9081_dapm_widgets));
1264 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 1264 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
1265 snd_soc_dapm_new_widgets(codec);
1266
1267 ret = snd_soc_init_card(socdev);
1268 if (ret < 0) {
1269 dev_err(codec->dev, "failed to register card: %d\n", ret);
1270 goto card_err;
1271 }
1272 1265
1273 return ret; 1266 return ret;
1274 1267
1275card_err:
1276 snd_soc_free_pcms(socdev);
1277 snd_soc_dapm_free(socdev);
1278pcm_err: 1268pcm_err:
1279 return ret; 1269 return ret;
1280} 1270}
@@ -1452,21 +1442,6 @@ static __devexit int wm9081_i2c_remove(struct i2c_client *client)
1452 return 0; 1442 return 0;
1453} 1443}
1454 1444
1455#ifdef CONFIG_PM
1456static int wm9081_i2c_suspend(struct i2c_client *client, pm_message_t msg)
1457{
1458 return snd_soc_suspend_device(&client->dev);
1459}
1460
1461static int wm9081_i2c_resume(struct i2c_client *client)
1462{
1463 return snd_soc_resume_device(&client->dev);
1464}
1465#else
1466#define wm9081_i2c_suspend NULL
1467#define wm9081_i2c_resume NULL
1468#endif
1469
1470static const struct i2c_device_id wm9081_i2c_id[] = { 1445static const struct i2c_device_id wm9081_i2c_id[] = {
1471 { "wm9081", 0 }, 1446 { "wm9081", 0 },
1472 { } 1447 { }
@@ -1480,8 +1455,6 @@ static struct i2c_driver wm9081_i2c_driver = {
1480 }, 1455 },
1481 .probe = wm9081_i2c_probe, 1456 .probe = wm9081_i2c_probe,
1482 .remove = __devexit_p(wm9081_i2c_remove), 1457 .remove = __devexit_p(wm9081_i2c_remove),
1483 .suspend = wm9081_i2c_suspend,
1484 .resume = wm9081_i2c_resume,
1485 .id_table = wm9081_i2c_id, 1458 .id_table = wm9081_i2c_id,
1486}; 1459};
1487 1460
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index e7d2840d9e59..ec54c6da9856 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -205,7 +205,6 @@ static int wm9705_add_widgets(struct snd_soc_codec *codec)
205 snd_soc_dapm_new_controls(codec, wm9705_dapm_widgets, 205 snd_soc_dapm_new_controls(codec, wm9705_dapm_widgets,
206 ARRAY_SIZE(wm9705_dapm_widgets)); 206 ARRAY_SIZE(wm9705_dapm_widgets));
207 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 207 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
208 snd_soc_dapm_new_widgets(codec);
209 208
210 return 0; 209 return 0;
211} 210}
@@ -403,12 +402,6 @@ static int wm9705_soc_probe(struct platform_device *pdev)
403 ARRAY_SIZE(wm9705_snd_ac97_controls)); 402 ARRAY_SIZE(wm9705_snd_ac97_controls));
404 wm9705_add_widgets(codec); 403 wm9705_add_widgets(codec);
405 404
406 ret = snd_soc_init_card(socdev);
407 if (ret < 0) {
408 printk(KERN_ERR "wm9705: failed to register card\n");
409 goto reset_err;
410 }
411
412 return 0; 405 return 0;
413 406
414reset_err: 407reset_err:
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index 1fd4e88f50cf..0ac1215dcd9b 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -436,7 +436,6 @@ static int wm9712_add_widgets(struct snd_soc_codec *codec)
436 436
437 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 437 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
438 438
439 snd_soc_dapm_new_widgets(codec);
440 return 0; 439 return 0;
441} 440}
442 441
@@ -695,17 +694,11 @@ static int wm9712_soc_probe(struct platform_device *pdev)
695 snd_soc_add_controls(codec, wm9712_snd_ac97_controls, 694 snd_soc_add_controls(codec, wm9712_snd_ac97_controls,
696 ARRAY_SIZE(wm9712_snd_ac97_controls)); 695 ARRAY_SIZE(wm9712_snd_ac97_controls));
697 wm9712_add_widgets(codec); 696 wm9712_add_widgets(codec);
698 ret = snd_soc_init_card(socdev);
699 if (ret < 0) {
700 printk(KERN_ERR "wm9712: failed to register card\n");
701 goto reset_err;
702 }
703 697
704 return 0; 698 return 0;
705 699
706reset_err: 700reset_err:
707 snd_soc_free_pcms(socdev); 701 snd_soc_free_pcms(socdev);
708
709pcm_err: 702pcm_err:
710 snd_soc_free_ac97_codec(codec); 703 snd_soc_free_ac97_codec(codec);
711 704
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index abed37acf787..c58aab375edb 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -165,9 +165,9 @@ SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1),
165SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 165SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
166SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1), 166SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1),
167 167
168SOC_SINGLE("PC Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1), 168SOC_SINGLE("Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1),
169SOC_SINGLE("PC Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1), 169SOC_SINGLE("Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1),
170SOC_SINGLE("PC Beep Playback Mono Volume", AC97_AUX, 4, 7, 1), 170SOC_SINGLE("Beep Playback Mono Volume", AC97_AUX, 4, 7, 1),
171 171
172SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1), 172SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1),
173SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1), 173SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1),
@@ -266,7 +266,7 @@ static int mixer_event(struct snd_soc_dapm_widget *w,
266 266
267/* Left Headphone Mixers */ 267/* Left Headphone Mixers */
268static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = { 268static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = {
269SOC_DAPM_SINGLE("PC Beep Playback Switch", HPL_MIXER, 5, 1, 0), 269SOC_DAPM_SINGLE("Beep Playback Switch", HPL_MIXER, 5, 1, 0),
270SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0), 270SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0),
271SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0), 271SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0),
272SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0), 272SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0),
@@ -276,7 +276,7 @@ SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER, 0, 1, 0),
276 276
277/* Right Headphone Mixers */ 277/* Right Headphone Mixers */
278static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = { 278static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = {
279SOC_DAPM_SINGLE("PC Beep Playback Switch", HPR_MIXER, 5, 1, 0), 279SOC_DAPM_SINGLE("Beep Playback Switch", HPR_MIXER, 5, 1, 0),
280SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0), 280SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0),
281SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0), 281SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0),
282SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0), 282SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0),
@@ -294,7 +294,7 @@ SOC_DAPM_ENUM("Route", wm9713_enum[0]);
294 294
295/* Speaker Mixer */ 295/* Speaker Mixer */
296static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = { 296static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = {
297SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 11, 1, 1), 297SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 11, 1, 1),
298SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 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), 299SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1),
300SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1), 300SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1),
@@ -304,7 +304,7 @@ SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1),
304 304
305/* Mono Mixer */ 305/* Mono Mixer */
306static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = { 306static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = {
307SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 7, 1, 1), 307SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 7, 1, 1),
308SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 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), 309SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1),
310SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1), 310SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1),
@@ -463,7 +463,7 @@ SND_SOC_DAPM_VMID("VMID"),
463 463
464static const struct snd_soc_dapm_route audio_map[] = { 464static const struct snd_soc_dapm_route audio_map[] = {
465 /* left HP mixer */ 465 /* left HP mixer */
466 {"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"}, 466 {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"},
467 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"}, 467 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
468 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"}, 468 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
469 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"}, 469 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
@@ -472,7 +472,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
472 {"Left HP Mixer", NULL, "Capture Headphone Mux"}, 472 {"Left HP Mixer", NULL, "Capture Headphone Mux"},
473 473
474 /* right HP mixer */ 474 /* right HP mixer */
475 {"Right HP Mixer", "PC Beep Playback Switch", "PCBEEP"}, 475 {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"},
476 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"}, 476 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
477 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"}, 477 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
478 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"}, 478 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
@@ -491,7 +491,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
491 {"Capture Mixer", NULL, "Right Capture Source"}, 491 {"Capture Mixer", NULL, "Right Capture Source"},
492 492
493 /* speaker mixer */ 493 /* speaker mixer */
494 {"Speaker Mixer", "PC Beep Playback Switch", "PCBEEP"}, 494 {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"},
495 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"}, 495 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
496 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"}, 496 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
497 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"}, 497 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
@@ -499,7 +499,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
499 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"}, 499 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
500 500
501 /* mono mixer */ 501 /* mono mixer */
502 {"Mono Mixer", "PC Beep Playback Switch", "PCBEEP"}, 502 {"Mono Mixer", "Beep Playback Switch", "PCBEEP"},
503 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"}, 503 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
504 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"}, 504 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
505 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"}, 505 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
@@ -625,7 +625,6 @@ static int wm9713_add_widgets(struct snd_soc_codec *codec)
625 625
626 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 626 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
627 627
628 snd_soc_dapm_new_widgets(codec);
629 return 0; 628 return 0;
630} 629}
631 630
@@ -800,8 +799,8 @@ static int wm9713_set_pll(struct snd_soc_codec *codec,
800 return 0; 799 return 0;
801} 800}
802 801
803static int wm9713_set_dai_pll(struct snd_soc_dai *codec_dai, 802static int wm9713_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
804 int pll_id, unsigned int freq_in, unsigned int freq_out) 803 int source, unsigned int freq_in, unsigned int freq_out)
805{ 804{
806 struct snd_soc_codec *codec = codec_dai->codec; 805 struct snd_soc_codec *codec = codec_dai->codec;
807 return wm9713_set_pll(codec, pll_id, freq_in, freq_out); 806 return wm9713_set_pll(codec, pll_id, freq_in, freq_out);
@@ -1247,14 +1246,11 @@ static int wm9713_soc_probe(struct platform_device *pdev)
1247 snd_soc_add_controls(codec, wm9713_snd_ac97_controls, 1246 snd_soc_add_controls(codec, wm9713_snd_ac97_controls,
1248 ARRAY_SIZE(wm9713_snd_ac97_controls)); 1247 ARRAY_SIZE(wm9713_snd_ac97_controls));
1249 wm9713_add_widgets(codec); 1248 wm9713_add_widgets(codec);
1250 ret = snd_soc_init_card(socdev); 1249
1251 if (ret < 0)
1252 goto reset_err;
1253 return 0; 1250 return 0;
1254 1251
1255reset_err: 1252reset_err:
1256 snd_soc_free_pcms(socdev); 1253 snd_soc_free_pcms(socdev);
1257
1258pcm_err: 1254pcm_err:
1259 snd_soc_free_ac97_codec(codec); 1255 snd_soc_free_ac97_codec(codec);
1260 1256
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index e542027eea89..d73c30536a2c 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -438,11 +438,11 @@ static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = {
438SND_SOC_DAPM_INPUT("IN1LN"), 438SND_SOC_DAPM_INPUT("IN1LN"),
439SND_SOC_DAPM_INPUT("IN1LP"), 439SND_SOC_DAPM_INPUT("IN1LP"),
440SND_SOC_DAPM_INPUT("IN2LN"), 440SND_SOC_DAPM_INPUT("IN2LN"),
441SND_SOC_DAPM_INPUT("IN2LP/VXRN"), 441SND_SOC_DAPM_INPUT("IN2LP:VXRN"),
442SND_SOC_DAPM_INPUT("IN1RN"), 442SND_SOC_DAPM_INPUT("IN1RN"),
443SND_SOC_DAPM_INPUT("IN1RP"), 443SND_SOC_DAPM_INPUT("IN1RP"),
444SND_SOC_DAPM_INPUT("IN2RN"), 444SND_SOC_DAPM_INPUT("IN2RN"),
445SND_SOC_DAPM_INPUT("IN2RP/VXRP"), 445SND_SOC_DAPM_INPUT("IN2RP:VXRP"),
446 446
447SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0), 447SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0),
448SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0), 448SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0),
@@ -537,14 +537,14 @@ static const struct snd_soc_dapm_route analogue_routes[] = {
537 { "IN1R PGA", "IN1RP Switch", "IN1RP" }, 537 { "IN1R PGA", "IN1RP Switch", "IN1RP" },
538 { "IN1R PGA", "IN1RN Switch", "IN1RN" }, 538 { "IN1R PGA", "IN1RN Switch", "IN1RN" },
539 539
540 { "IN2L PGA", "IN2LP Switch", "IN2LP/VXRN" }, 540 { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
541 { "IN2L PGA", "IN2LN Switch", "IN2LN" }, 541 { "IN2L PGA", "IN2LN Switch", "IN2LN" },
542 542
543 { "IN2R PGA", "IN2RP Switch", "IN2RP/VXRP" }, 543 { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
544 { "IN2R PGA", "IN2RN Switch", "IN2RN" }, 544 { "IN2R PGA", "IN2RN Switch", "IN2RN" },
545 545
546 { "Direct Voice", NULL, "IN2LP/VXRN" }, 546 { "Direct Voice", NULL, "IN2LP:VXRN" },
547 { "Direct Voice", NULL, "IN2RP/VXRP" }, 547 { "Direct Voice", NULL, "IN2RP:VXRP" },
548 548
549 { "MIXINL", "IN1L Switch", "IN1L PGA" }, 549 { "MIXINL", "IN1L Switch", "IN1L PGA" },
550 { "MIXINL", "IN2L Switch", "IN2L PGA" }, 550 { "MIXINL", "IN2L Switch", "IN2L PGA" },
@@ -565,7 +565,7 @@ static const struct snd_soc_dapm_route analogue_routes[] = {
565 { "Left Output Mixer", "Right Input Switch", "MIXINR" }, 565 { "Left Output Mixer", "Right Input Switch", "MIXINR" },
566 { "Left Output Mixer", "IN2RN Switch", "IN2RN" }, 566 { "Left Output Mixer", "IN2RN Switch", "IN2RN" },
567 { "Left Output Mixer", "IN2LN Switch", "IN2LN" }, 567 { "Left Output Mixer", "IN2LN Switch", "IN2LN" },
568 { "Left Output Mixer", "IN2LP Switch", "IN2LP/VXRN" }, 568 { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" },
569 { "Left Output Mixer", "IN1L Switch", "IN1L PGA" }, 569 { "Left Output Mixer", "IN1L Switch", "IN1L PGA" },
570 { "Left Output Mixer", "IN1R Switch", "IN1R PGA" }, 570 { "Left Output Mixer", "IN1R Switch", "IN1R PGA" },
571 571
@@ -573,7 +573,7 @@ static const struct snd_soc_dapm_route analogue_routes[] = {
573 { "Right Output Mixer", "Right Input Switch", "MIXINR" }, 573 { "Right Output Mixer", "Right Input Switch", "MIXINR" },
574 { "Right Output Mixer", "IN2LN Switch", "IN2LN" }, 574 { "Right Output Mixer", "IN2LN Switch", "IN2LN" },
575 { "Right Output Mixer", "IN2RN Switch", "IN2RN" }, 575 { "Right Output Mixer", "IN2RN Switch", "IN2RN" },
576 { "Right Output Mixer", "IN2RP Switch", "IN2RP/VXRP" }, 576 { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" },
577 { "Right Output Mixer", "IN1L Switch", "IN1L PGA" }, 577 { "Right Output Mixer", "IN1L Switch", "IN1L PGA" },
578 { "Right Output Mixer", "IN1R Switch", "IN1R PGA" }, 578 { "Right Output Mixer", "IN1R Switch", "IN1R PGA" },
579 579
@@ -738,6 +738,41 @@ int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
738} 738}
739EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes); 739EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes);
740 740
741int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *codec,
742 int lineout1_diff, int lineout2_diff,
743 int lineout1fb, int lineout2fb,
744 int jd_scthr, int jd_thr, int micbias1_lvl,
745 int micbias2_lvl)
746{
747 if (!lineout1_diff)
748 snd_soc_update_bits(codec, WM8993_LINE_MIXER1,
749 WM8993_LINEOUT1_MODE,
750 WM8993_LINEOUT1_MODE);
751 if (!lineout2_diff)
752 snd_soc_update_bits(codec, WM8993_LINE_MIXER2,
753 WM8993_LINEOUT2_MODE,
754 WM8993_LINEOUT2_MODE);
755
756 if (lineout1fb)
757 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
758 WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
759
760 if (lineout2fb)
761 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
762 WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
763
764 snd_soc_update_bits(codec, WM8993_MICBIAS,
765 WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
766 WM8993_MICB1_LVL | WM8993_MICB2_LVL,
767 jd_scthr << WM8993_JD_SCTHR_SHIFT |
768 jd_thr << WM8993_JD_THR_SHIFT |
769 micbias1_lvl |
770 micbias2_lvl << WM8993_MICB2_LVL_SHIFT);
771
772 return 0;
773}
774EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata);
775
741MODULE_DESCRIPTION("Shared support for Wolfson hubs products"); 776MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
742MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 777MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
743MODULE_LICENSE("GPL"); 778MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm_hubs.h b/sound/soc/codecs/wm_hubs.h
index ec09cb6a2939..36d3fba1de8b 100644
--- a/sound/soc/codecs/wm_hubs.h
+++ b/sound/soc/codecs/wm_hubs.h
@@ -20,5 +20,10 @@ extern const unsigned int wm_hubs_spkmix_tlv[];
20 20
21extern int wm_hubs_add_analogue_controls(struct snd_soc_codec *); 21extern int wm_hubs_add_analogue_controls(struct snd_soc_codec *);
22extern int wm_hubs_add_analogue_routes(struct snd_soc_codec *, int, int); 22extern int wm_hubs_add_analogue_routes(struct snd_soc_codec *, int, int);
23extern int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *,
24 int lineout1_diff, int lineout2_diff,
25 int lineout1fb, int lineout2fb,
26 int jd_scthr, int jd_thr,
27 int micbias1_lvl, int micbias2_lvl);
23 28
24#endif 29#endif
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
index 4dfd4ad9d90e..047ee39418c0 100644
--- a/sound/soc/davinci/Kconfig
+++ b/sound/soc/davinci/Kconfig
@@ -13,9 +13,9 @@ config SND_DAVINCI_SOC_MCASP
13 tristate 13 tristate
14 14
15config SND_DAVINCI_SOC_EVM 15config SND_DAVINCI_SOC_EVM
16 tristate "SoC Audio support for DaVinci DM6446 or DM355 EVM" 16 tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM"
17 depends on SND_DAVINCI_SOC 17 depends on SND_DAVINCI_SOC
18 depends on MACH_DAVINCI_EVM || MACH_DAVINCI_DM355_EVM 18 depends on MACH_DAVINCI_EVM || MACH_DAVINCI_DM355_EVM || MACH_DAVINCI_DM365_EVM
19 select SND_DAVINCI_SOC_I2S 19 select SND_DAVINCI_SOC_I2S
20 select SND_SOC_TLV320AIC3X 20 select SND_SOC_TLV320AIC3X
21 help 21 help
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index 67414f659405..7ccbe6684fc2 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -45,7 +45,8 @@ static int evm_hw_params(struct snd_pcm_substream *substream,
45 unsigned sysclk; 45 unsigned sysclk;
46 46
47 /* ASP1 on DM355 EVM is clocked by an external oscillator */ 47 /* ASP1 on DM355 EVM is clocked by an external oscillator */
48 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm()) 48 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
49 machine_is_davinci_dm365_evm())
49 sysclk = 27000000; 50 sysclk = 27000000;
50 51
51 /* ASP0 in DM6446 EVM is clocked by U55, as configured by 52 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
@@ -176,7 +177,7 @@ static struct snd_soc_dai_link da8xx_evm_dai = {
176 .ops = &evm_ops, 177 .ops = &evm_ops,
177}; 178};
178 179
179/* davinci-evm audio machine driver */ 180/* davinci dm6446, dm355 or dm365 evm audio machine driver */
180static struct snd_soc_card snd_soc_card_evm = { 181static struct snd_soc_card snd_soc_card_evm = {
181 .name = "DaVinci EVM", 182 .name = "DaVinci EVM",
182 .platform = &davinci_soc_platform, 183 .platform = &davinci_soc_platform,
@@ -243,7 +244,7 @@ static int __init evm_init(void)
243 int index; 244 int index;
244 int ret; 245 int ret;
245 246
246 if (machine_is_davinci_evm()) { 247 if (machine_is_davinci_evm() || machine_is_davinci_dm365_evm()) {
247 evm_snd_dev_data = &evm_snd_devdata; 248 evm_snd_dev_data = &evm_snd_devdata;
248 index = 0; 249 index = 0;
249 } else if (machine_is_davinci_dm355_evm()) { 250 } else if (machine_is_davinci_dm355_evm()) {
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
index 4ae707048021..6362ca05506e 100644
--- a/sound/soc/davinci/davinci-i2s.c
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -97,12 +97,24 @@ enum {
97 DAVINCI_MCBSP_WORD_32, 97 DAVINCI_MCBSP_WORD_32,
98}; 98};
99 99
100static const unsigned char data_type[SNDRV_PCM_FORMAT_S32_LE + 1] = {
101 [SNDRV_PCM_FORMAT_S8] = 1,
102 [SNDRV_PCM_FORMAT_S16_LE] = 2,
103 [SNDRV_PCM_FORMAT_S32_LE] = 4,
104};
105
106static const unsigned char asp_word_length[SNDRV_PCM_FORMAT_S32_LE + 1] = {
107 [SNDRV_PCM_FORMAT_S8] = DAVINCI_MCBSP_WORD_8,
108 [SNDRV_PCM_FORMAT_S16_LE] = DAVINCI_MCBSP_WORD_16,
109 [SNDRV_PCM_FORMAT_S32_LE] = DAVINCI_MCBSP_WORD_32,
110};
111
112static const unsigned char double_fmt[SNDRV_PCM_FORMAT_S32_LE + 1] = {
113 [SNDRV_PCM_FORMAT_S8] = SNDRV_PCM_FORMAT_S16_LE,
114 [SNDRV_PCM_FORMAT_S16_LE] = SNDRV_PCM_FORMAT_S32_LE,
115};
116
100struct davinci_mcbsp_dev { 117struct davinci_mcbsp_dev {
101 /*
102 * dma_params must be first because rtd->dai->cpu_dai->private_data
103 * is cast to a pointer of an array of struct davinci_pcm_dma_params in
104 * davinci_pcm_open.
105 */
106 struct davinci_pcm_dma_params dma_params[2]; 118 struct davinci_pcm_dma_params dma_params[2];
107 void __iomem *base; 119 void __iomem *base;
108#define MOD_DSP_A 0 120#define MOD_DSP_A 0
@@ -110,6 +122,27 @@ struct davinci_mcbsp_dev {
110 int mode; 122 int mode;
111 u32 pcr; 123 u32 pcr;
112 struct clk *clk; 124 struct clk *clk;
125 /*
126 * Combining both channels into 1 element will at least double the
127 * amount of time between servicing the dma channel, increase
128 * effiency, and reduce the chance of overrun/underrun. But,
129 * it will result in the left & right channels being swapped.
130 *
131 * If relabeling the left and right channels is not possible,
132 * you may want to let the codec know to swap them back.
133 *
134 * It may allow x10 the amount of time to service dma requests,
135 * if the codec is master and is using an unnecessarily fast bit clock
136 * (ie. tlvaic23b), independent of the sample rate. So, having an
137 * entire frame at once means it can be serviced at the sample rate
138 * instead of the bit clock rate.
139 *
140 * In the now unlikely case that an underrun still
141 * occurs, both the left and right samples will be repeated
142 * so that no pops are heard, and the left and right channels
143 * won't end up being swapped because of the underrun.
144 */
145 unsigned enable_channel_combine:1;
113}; 146};
114 147
115static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev, 148static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev,
@@ -349,6 +382,8 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
349 int mcbsp_word_length; 382 int mcbsp_word_length;
350 unsigned int rcr, xcr, srgr; 383 unsigned int rcr, xcr, srgr;
351 u32 spcr; 384 u32 spcr;
385 snd_pcm_format_t fmt;
386 unsigned element_cnt = 1;
352 387
353 /* general line settings */ 388 /* general line settings */
354 spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); 389 spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
@@ -378,27 +413,24 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
378 xcr |= DAVINCI_MCBSP_XCR_XDATDLY(1); 413 xcr |= DAVINCI_MCBSP_XCR_XDATDLY(1);
379 } 414 }
380 /* Determine xfer data type */ 415 /* Determine xfer data type */
381 switch (params_format(params)) { 416 fmt = params_format(params);
382 case SNDRV_PCM_FORMAT_S8: 417 if ((fmt > SNDRV_PCM_FORMAT_S32_LE) || !data_type[fmt]) {
383 dma_params->data_type = 1;
384 mcbsp_word_length = DAVINCI_MCBSP_WORD_8;
385 break;
386 case SNDRV_PCM_FORMAT_S16_LE:
387 dma_params->data_type = 2;
388 mcbsp_word_length = DAVINCI_MCBSP_WORD_16;
389 break;
390 case SNDRV_PCM_FORMAT_S32_LE:
391 dma_params->data_type = 4;
392 mcbsp_word_length = DAVINCI_MCBSP_WORD_32;
393 break;
394 default:
395 printk(KERN_WARNING "davinci-i2s: unsupported PCM format\n"); 418 printk(KERN_WARNING "davinci-i2s: unsupported PCM format\n");
396 return -EINVAL; 419 return -EINVAL;
397 } 420 }
398 421
399 dma_params->acnt = dma_params->data_type; 422 if (params_channels(params) == 2) {
400 rcr |= DAVINCI_MCBSP_RCR_RFRLEN1(1); 423 element_cnt = 2;
401 xcr |= DAVINCI_MCBSP_XCR_XFRLEN1(1); 424 if (double_fmt[fmt] && dev->enable_channel_combine) {
425 element_cnt = 1;
426 fmt = double_fmt[fmt];
427 }
428 }
429 dma_params->acnt = dma_params->data_type = data_type[fmt];
430 dma_params->fifo_level = 0;
431 mcbsp_word_length = asp_word_length[fmt];
432 rcr |= DAVINCI_MCBSP_RCR_RFRLEN1(element_cnt - 1);
433 xcr |= DAVINCI_MCBSP_XCR_XFRLEN1(element_cnt - 1);
402 434
403 rcr |= DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) | 435 rcr |= DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) |
404 DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length); 436 DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length);
@@ -513,7 +545,13 @@ static int davinci_i2s_probe(struct platform_device *pdev)
513 ret = -ENOMEM; 545 ret = -ENOMEM;
514 goto err_release_region; 546 goto err_release_region;
515 } 547 }
516 548 if (pdata) {
549 dev->enable_channel_combine = pdata->enable_channel_combine;
550 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].sram_size =
551 pdata->sram_size_playback;
552 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].sram_size =
553 pdata->sram_size_capture;
554 }
517 dev->clk = clk_get(&pdev->dev, NULL); 555 dev->clk = clk_get(&pdev->dev, NULL);
518 if (IS_ERR(dev->clk)) { 556 if (IS_ERR(dev->clk)) {
519 ret = -ENODEV; 557 ret = -ENODEV;
@@ -547,6 +585,7 @@ static int davinci_i2s_probe(struct platform_device *pdev)
547 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start; 585 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start;
548 586
549 davinci_i2s_dai.private_data = dev; 587 davinci_i2s_dai.private_data = dev;
588 davinci_i2s_dai.dma_data = dev->dma_params;
550 ret = snd_soc_register_dai(&davinci_i2s_dai); 589 ret = snd_soc_register_dai(&davinci_i2s_dai);
551 if (ret != 0) 590 if (ret != 0)
552 goto err_free_mem; 591 goto err_free_mem;
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 5d1f98a4c978..0a302e1080d9 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -714,16 +714,13 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
714 struct davinci_pcm_dma_params *dma_params = 714 struct davinci_pcm_dma_params *dma_params =
715 &dev->dma_params[substream->stream]; 715 &dev->dma_params[substream->stream];
716 int word_length; 716 int word_length;
717 u8 numevt; 717 u8 fifo_level;
718 718
719 davinci_hw_common_param(dev, substream->stream); 719 davinci_hw_common_param(dev, substream->stream);
720 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 720 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
721 numevt = dev->txnumevt; 721 fifo_level = dev->txnumevt;
722 else 722 else
723 numevt = dev->rxnumevt; 723 fifo_level = dev->rxnumevt;
724
725 if (!numevt)
726 numevt = 1;
727 724
728 if (dev->op_mode == DAVINCI_MCASP_DIT_MODE) 725 if (dev->op_mode == DAVINCI_MCASP_DIT_MODE)
729 davinci_hw_dit_param(dev); 726 davinci_hw_dit_param(dev);
@@ -751,12 +748,12 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
751 return -EINVAL; 748 return -EINVAL;
752 } 749 }
753 750
754 if (dev->version == MCASP_VERSION_2) { 751 if (dev->version == MCASP_VERSION_2 && !fifo_level)
755 dma_params->data_type *= numevt; 752 dma_params->acnt = 4;
756 dma_params->acnt = 4 * numevt; 753 else
757 } else
758 dma_params->acnt = dma_params->data_type; 754 dma_params->acnt = dma_params->data_type;
759 755
756 dma_params->fifo_level = fifo_level;
760 davinci_config_channel_size(dev, word_length); 757 davinci_config_channel_size(dev, word_length);
761 758
762 return 0; 759 return 0;
@@ -907,6 +904,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
907 904
908 dma_data->channel = res->start; 905 dma_data->channel = res->start;
909 davinci_mcasp_dai[pdata->op_mode].private_data = dev; 906 davinci_mcasp_dai[pdata->op_mode].private_data = dev;
907 davinci_mcasp_dai[pdata->op_mode].dma_data = dev->dma_params;
910 davinci_mcasp_dai[pdata->op_mode].dev = &pdev->dev; 908 davinci_mcasp_dai[pdata->op_mode].dev = &pdev->dev;
911 ret = snd_soc_register_dai(&davinci_mcasp_dai[pdata->op_mode]); 909 ret = snd_soc_register_dai(&davinci_mcasp_dai[pdata->op_mode]);
912 910
diff --git a/sound/soc/davinci/davinci-mcasp.h b/sound/soc/davinci/davinci-mcasp.h
index 9d179cc88f7b..582c9249ef09 100644
--- a/sound/soc/davinci/davinci-mcasp.h
+++ b/sound/soc/davinci/davinci-mcasp.h
@@ -39,11 +39,6 @@ enum {
39}; 39};
40 40
41struct davinci_audio_dev { 41struct davinci_audio_dev {
42 /*
43 * dma_params must be first because rtd->dai->cpu_dai->private_data
44 * is cast to a pointer of an array of struct davinci_pcm_dma_params in
45 * davinci_pcm_open.
46 */
47 struct davinci_pcm_dma_params dma_params[2]; 42 struct davinci_pcm_dma_params dma_params[2];
48 void __iomem *base; 43 void __iomem *base;
49 int sample_rate; 44 int sample_rate;
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
index c73a915f233f..ad4d7f47a86b 100644
--- a/sound/soc/davinci/davinci-pcm.c
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com> 4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> 5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 * added SRAM ping/pong (C) 2008 Troy Kisky <troy.kisky@boundarydevices.com>
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * 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 * it under the terms of the GNU General Public License version 2 as
@@ -23,10 +24,29 @@
23 24
24#include <asm/dma.h> 25#include <asm/dma.h>
25#include <mach/edma.h> 26#include <mach/edma.h>
27#include <mach/sram.h>
26 28
27#include "davinci-pcm.h" 29#include "davinci-pcm.h"
28 30
29static struct snd_pcm_hardware davinci_pcm_hardware = { 31#ifdef DEBUG
32static void print_buf_info(int slot, char *name)
33{
34 struct edmacc_param p;
35 if (slot < 0)
36 return;
37 edma_read_slot(slot, &p);
38 printk(KERN_DEBUG "%s: 0x%x, opt=%x, src=%x, a_b_cnt=%x dst=%x\n",
39 name, slot, p.opt, p.src, p.a_b_cnt, p.dst);
40 printk(KERN_DEBUG " src_dst_bidx=%x link_bcntrld=%x src_dst_cidx=%x ccnt=%x\n",
41 p.src_dst_bidx, p.link_bcntrld, p.src_dst_cidx, p.ccnt);
42}
43#else
44static void print_buf_info(int slot, char *name)
45{
46}
47#endif
48
49static struct snd_pcm_hardware pcm_hardware_playback = {
30 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | 50 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
31 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | 51 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
32 SNDRV_PCM_INFO_PAUSE), 52 SNDRV_PCM_INFO_PAUSE),
@@ -48,102 +68,432 @@ static struct snd_pcm_hardware davinci_pcm_hardware = {
48 .fifo_size = 0, 68 .fifo_size = 0,
49}; 69};
50 70
71static struct snd_pcm_hardware pcm_hardware_capture = {
72 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
73 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
74 SNDRV_PCM_INFO_PAUSE),
75 .formats = (SNDRV_PCM_FMTBIT_S16_LE),
76 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
77 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
78 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
79 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
80 SNDRV_PCM_RATE_KNOT),
81 .rate_min = 8000,
82 .rate_max = 96000,
83 .channels_min = 2,
84 .channels_max = 2,
85 .buffer_bytes_max = 128 * 1024,
86 .period_bytes_min = 32,
87 .period_bytes_max = 8 * 1024,
88 .periods_min = 16,
89 .periods_max = 255,
90 .fifo_size = 0,
91};
92
93/*
94 * How ping/pong works....
95 *
96 * Playback:
97 * ram_params - copys 2*ping_size from start of SDRAM to iram,
98 * links to ram_link2
99 * ram_link2 - copys rest of SDRAM to iram in ping_size units,
100 * links to ram_link
101 * ram_link - copys entire SDRAM to iram in ping_size uints,
102 * links to self
103 *
104 * asp_params - same as asp_link[0]
105 * asp_link[0] - copys from lower half of iram to asp port
106 * links to asp_link[1], triggers iram copy event on completion
107 * asp_link[1] - copys from upper half of iram to asp port
108 * links to asp_link[0], triggers iram copy event on completion
109 * triggers interrupt only needed to let upper SOC levels update position
110 * in stream on completion
111 *
112 * When playback is started:
113 * ram_params started
114 * asp_params started
115 *
116 * Capture:
117 * ram_params - same as ram_link,
118 * links to ram_link
119 * ram_link - same as playback
120 * links to self
121 *
122 * asp_params - same as playback
123 * asp_link[0] - same as playback
124 * asp_link[1] - same as playback
125 *
126 * When capture is started:
127 * asp_params started
128 */
51struct davinci_runtime_data { 129struct davinci_runtime_data {
52 spinlock_t lock; 130 spinlock_t lock;
53 int period; /* current DMA period */ 131 int period; /* current DMA period */
54 int master_lch; /* Master DMA channel */ 132 int asp_channel; /* Master DMA channel */
55 int slave_lch; /* linked parameter RAM reload slot */ 133 int asp_link[2]; /* asp parameter link channel, ping/pong */
56 struct davinci_pcm_dma_params *params; /* DMA params */ 134 struct davinci_pcm_dma_params *params; /* DMA params */
135 int ram_channel;
136 int ram_link;
137 int ram_link2;
138 struct edmacc_param asp_params;
139 struct edmacc_param ram_params;
57}; 140};
58 141
142/*
143 * Not used with ping/pong
144 */
59static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream) 145static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
60{ 146{
61 struct davinci_runtime_data *prtd = substream->runtime->private_data; 147 struct davinci_runtime_data *prtd = substream->runtime->private_data;
62 struct snd_pcm_runtime *runtime = substream->runtime; 148 struct snd_pcm_runtime *runtime = substream->runtime;
63 int lch = prtd->slave_lch; 149 int link = prtd->asp_link[0];
64 unsigned int period_size; 150 unsigned int period_size;
65 unsigned int dma_offset; 151 unsigned int dma_offset;
66 dma_addr_t dma_pos; 152 dma_addr_t dma_pos;
67 dma_addr_t src, dst; 153 dma_addr_t src, dst;
68 unsigned short src_bidx, dst_bidx; 154 unsigned short src_bidx, dst_bidx;
155 unsigned short src_cidx, dst_cidx;
69 unsigned int data_type; 156 unsigned int data_type;
70 unsigned short acnt; 157 unsigned short acnt;
71 unsigned int count; 158 unsigned int count;
159 unsigned int fifo_level;
72 160
73 period_size = snd_pcm_lib_period_bytes(substream); 161 period_size = snd_pcm_lib_period_bytes(substream);
74 dma_offset = prtd->period * period_size; 162 dma_offset = prtd->period * period_size;
75 dma_pos = runtime->dma_addr + dma_offset; 163 dma_pos = runtime->dma_addr + dma_offset;
164 fifo_level = prtd->params->fifo_level;
76 165
77 pr_debug("davinci_pcm: audio_set_dma_params_play channel = %d " 166 pr_debug("davinci_pcm: audio_set_dma_params_play channel = %d "
78 "dma_ptr = %x period_size=%x\n", lch, dma_pos, period_size); 167 "dma_ptr = %x period_size=%x\n", link, dma_pos, period_size);
79 168
80 data_type = prtd->params->data_type; 169 data_type = prtd->params->data_type;
81 count = period_size / data_type; 170 count = period_size / data_type;
171 if (fifo_level)
172 count /= fifo_level;
82 173
83 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 174 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
84 src = dma_pos; 175 src = dma_pos;
85 dst = prtd->params->dma_addr; 176 dst = prtd->params->dma_addr;
86 src_bidx = data_type; 177 src_bidx = data_type;
87 dst_bidx = 0; 178 dst_bidx = 0;
179 src_cidx = data_type * fifo_level;
180 dst_cidx = 0;
88 } else { 181 } else {
89 src = prtd->params->dma_addr; 182 src = prtd->params->dma_addr;
90 dst = dma_pos; 183 dst = dma_pos;
91 src_bidx = 0; 184 src_bidx = 0;
92 dst_bidx = data_type; 185 dst_bidx = data_type;
186 src_cidx = 0;
187 dst_cidx = data_type * fifo_level;
93 } 188 }
94 189
95 acnt = prtd->params->acnt; 190 acnt = prtd->params->acnt;
96 edma_set_src(lch, src, INCR, W8BIT); 191 edma_set_src(link, src, INCR, W8BIT);
97 edma_set_dest(lch, dst, INCR, W8BIT); 192 edma_set_dest(link, dst, INCR, W8BIT);
98 edma_set_src_index(lch, src_bidx, 0); 193
99 edma_set_dest_index(lch, dst_bidx, 0); 194 edma_set_src_index(link, src_bidx, src_cidx);
100 edma_set_transfer_params(lch, acnt, count, 1, 0, ASYNC); 195 edma_set_dest_index(link, dst_bidx, dst_cidx);
196
197 if (!fifo_level)
198 edma_set_transfer_params(link, acnt, count, 1, 0, ASYNC);
199 else
200 edma_set_transfer_params(link, acnt, fifo_level, count,
201 fifo_level, ABSYNC);
101 202
102 prtd->period++; 203 prtd->period++;
103 if (unlikely(prtd->period >= runtime->periods)) 204 if (unlikely(prtd->period >= runtime->periods))
104 prtd->period = 0; 205 prtd->period = 0;
105} 206}
106 207
107static void davinci_pcm_dma_irq(unsigned lch, u16 ch_status, void *data) 208static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data)
108{ 209{
109 struct snd_pcm_substream *substream = data; 210 struct snd_pcm_substream *substream = data;
110 struct davinci_runtime_data *prtd = substream->runtime->private_data; 211 struct davinci_runtime_data *prtd = substream->runtime->private_data;
111 212
112 pr_debug("davinci_pcm: lch=%d, status=0x%x\n", lch, ch_status); 213 print_buf_info(prtd->ram_channel, "i ram_channel");
214 pr_debug("davinci_pcm: link=%d, status=0x%x\n", link, ch_status);
113 215
114 if (unlikely(ch_status != DMA_COMPLETE)) 216 if (unlikely(ch_status != DMA_COMPLETE))
115 return; 217 return;
116 218
117 if (snd_pcm_running(substream)) { 219 if (snd_pcm_running(substream)) {
220 if (prtd->ram_channel < 0) {
221 /* No ping/pong must fix up link dma data*/
222 spin_lock(&prtd->lock);
223 davinci_pcm_enqueue_dma(substream);
224 spin_unlock(&prtd->lock);
225 }
118 snd_pcm_period_elapsed(substream); 226 snd_pcm_period_elapsed(substream);
227 }
228}
229
230static int allocate_sram(struct snd_pcm_substream *substream, unsigned size,
231 struct snd_pcm_hardware *ppcm)
232{
233 struct snd_dma_buffer *buf = &substream->dma_buffer;
234 struct snd_dma_buffer *iram_dma = NULL;
235 dma_addr_t iram_phys = 0;
236 void *iram_virt = NULL;
237
238 if (buf->private_data || !size)
239 return 0;
240
241 ppcm->period_bytes_max = size;
242 iram_virt = sram_alloc(size, &iram_phys);
243 if (!iram_virt)
244 goto exit1;
245 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL);
246 if (!iram_dma)
247 goto exit2;
248 iram_dma->area = iram_virt;
249 iram_dma->addr = iram_phys;
250 memset(iram_dma->area, 0, size);
251 iram_dma->bytes = size;
252 buf->private_data = iram_dma;
253 return 0;
254exit2:
255 if (iram_virt)
256 sram_free(iram_virt, size);
257exit1:
258 return -ENOMEM;
259}
260
261/*
262 * Only used with ping/pong.
263 * This is called after runtime->dma_addr, period_bytes and data_type are valid
264 */
265static int ping_pong_dma_setup(struct snd_pcm_substream *substream)
266{
267 unsigned short ram_src_cidx, ram_dst_cidx;
268 struct snd_pcm_runtime *runtime = substream->runtime;
269 struct davinci_runtime_data *prtd = runtime->private_data;
270 struct snd_dma_buffer *iram_dma =
271 (struct snd_dma_buffer *)substream->dma_buffer.private_data;
272 struct davinci_pcm_dma_params *params = prtd->params;
273 unsigned int data_type = params->data_type;
274 unsigned int acnt = params->acnt;
275 /* divide by 2 for ping/pong */
276 unsigned int ping_size = snd_pcm_lib_period_bytes(substream) >> 1;
277 int link = prtd->asp_link[1];
278 unsigned int fifo_level = prtd->params->fifo_level;
279 unsigned int count;
280 if ((data_type == 0) || (data_type > 4)) {
281 printk(KERN_ERR "%s: data_type=%i\n", __func__, data_type);
282 return -EINVAL;
283 }
284 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
285 dma_addr_t asp_src_pong = iram_dma->addr + ping_size;
286 ram_src_cidx = ping_size;
287 ram_dst_cidx = -ping_size;
288 edma_set_src(link, asp_src_pong, INCR, W8BIT);
289
290 link = prtd->asp_link[0];
291 edma_set_src_index(link, data_type, data_type * fifo_level);
292 link = prtd->asp_link[1];
293 edma_set_src_index(link, data_type, data_type * fifo_level);
294
295 link = prtd->ram_link;
296 edma_set_src(link, runtime->dma_addr, INCR, W32BIT);
297 } else {
298 dma_addr_t asp_dst_pong = iram_dma->addr + ping_size;
299 ram_src_cidx = -ping_size;
300 ram_dst_cidx = ping_size;
301 edma_set_dest(link, asp_dst_pong, INCR, W8BIT);
302
303 link = prtd->asp_link[0];
304 edma_set_dest_index(link, data_type, data_type * fifo_level);
305 link = prtd->asp_link[1];
306 edma_set_dest_index(link, data_type, data_type * fifo_level);
307
308 link = prtd->ram_link;
309 edma_set_dest(link, runtime->dma_addr, INCR, W32BIT);
310 }
119 311
120 spin_lock(&prtd->lock); 312 if (!fifo_level) {
121 davinci_pcm_enqueue_dma(substream); 313 count = ping_size / data_type;
122 spin_unlock(&prtd->lock); 314 edma_set_transfer_params(prtd->asp_link[0], acnt, count,
315 1, 0, ASYNC);
316 edma_set_transfer_params(prtd->asp_link[1], acnt, count,
317 1, 0, ASYNC);
318 } else {
319 count = ping_size / (data_type * fifo_level);
320 edma_set_transfer_params(prtd->asp_link[0], acnt, fifo_level,
321 count, fifo_level, ABSYNC);
322 edma_set_transfer_params(prtd->asp_link[1], acnt, fifo_level,
323 count, fifo_level, ABSYNC);
123 } 324 }
325
326 link = prtd->ram_link;
327 edma_set_src_index(link, ping_size, ram_src_cidx);
328 edma_set_dest_index(link, ping_size, ram_dst_cidx);
329 edma_set_transfer_params(link, ping_size, 2,
330 runtime->periods, 2, ASYNC);
331
332 /* init master params */
333 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
334 edma_read_slot(prtd->ram_link, &prtd->ram_params);
335 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
336 struct edmacc_param p_ram;
337 /* Copy entire iram buffer before playback started */
338 prtd->ram_params.a_b_cnt = (1 << 16) | (ping_size << 1);
339 /* 0 dst_bidx */
340 prtd->ram_params.src_dst_bidx = (ping_size << 1);
341 /* 0 dst_cidx */
342 prtd->ram_params.src_dst_cidx = (ping_size << 1);
343 prtd->ram_params.ccnt = 1;
344
345 /* Skip 1st period */
346 edma_read_slot(prtd->ram_link, &p_ram);
347 p_ram.src += (ping_size << 1);
348 p_ram.ccnt -= 1;
349 edma_write_slot(prtd->ram_link2, &p_ram);
350 /*
351 * When 1st started, ram -> iram dma channel will fill the
352 * entire iram. Then, whenever a ping/pong asp buffer finishes,
353 * 1/2 iram will be filled.
354 */
355 prtd->ram_params.link_bcntrld =
356 EDMA_CHAN_SLOT(prtd->ram_link2) << 5;
357 }
358 return 0;
359}
360
361/* 1 asp tx or rx channel using 2 parameter channels
362 * 1 ram to/from iram channel using 1 parameter channel
363 *
364 * Playback
365 * ram copy channel kicks off first,
366 * 1st ram copy of entire iram buffer completion kicks off asp channel
367 * asp tcc always kicks off ram copy of 1/2 iram buffer
368 *
369 * Record
370 * asp channel starts, tcc kicks off ram copy
371 */
372static int request_ping_pong(struct snd_pcm_substream *substream,
373 struct davinci_runtime_data *prtd,
374 struct snd_dma_buffer *iram_dma)
375{
376 dma_addr_t asp_src_ping;
377 dma_addr_t asp_dst_ping;
378 int link;
379 struct davinci_pcm_dma_params *params = prtd->params;
380
381 /* Request ram master channel */
382 link = prtd->ram_channel = edma_alloc_channel(EDMA_CHANNEL_ANY,
383 davinci_pcm_dma_irq, substream,
384 EVENTQ_1);
385 if (link < 0)
386 goto exit1;
387
388 /* Request ram link channel */
389 link = prtd->ram_link = edma_alloc_slot(
390 EDMA_CTLR(prtd->ram_channel), EDMA_SLOT_ANY);
391 if (link < 0)
392 goto exit2;
393
394 link = prtd->asp_link[1] = edma_alloc_slot(
395 EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
396 if (link < 0)
397 goto exit3;
398
399 prtd->ram_link2 = -1;
400 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
401 link = prtd->ram_link2 = edma_alloc_slot(
402 EDMA_CTLR(prtd->ram_channel), EDMA_SLOT_ANY);
403 if (link < 0)
404 goto exit4;
405 }
406 /* circle ping-pong buffers */
407 edma_link(prtd->asp_link[0], prtd->asp_link[1]);
408 edma_link(prtd->asp_link[1], prtd->asp_link[0]);
409 /* circle ram buffers */
410 edma_link(prtd->ram_link, prtd->ram_link);
411
412 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
413 asp_src_ping = iram_dma->addr;
414 asp_dst_ping = params->dma_addr; /* fifo */
415 } else {
416 asp_src_ping = params->dma_addr; /* fifo */
417 asp_dst_ping = iram_dma->addr;
418 }
419 /* ping */
420 link = prtd->asp_link[0];
421 edma_set_src(link, asp_src_ping, INCR, W16BIT);
422 edma_set_dest(link, asp_dst_ping, INCR, W16BIT);
423 edma_set_src_index(link, 0, 0);
424 edma_set_dest_index(link, 0, 0);
425
426 edma_read_slot(link, &prtd->asp_params);
427 prtd->asp_params.opt &= ~(TCCMODE | EDMA_TCC(0x3f) | TCINTEN);
428 prtd->asp_params.opt |= TCCHEN | EDMA_TCC(prtd->ram_channel & 0x3f);
429 edma_write_slot(link, &prtd->asp_params);
430
431 /* pong */
432 link = prtd->asp_link[1];
433 edma_set_src(link, asp_src_ping, INCR, W16BIT);
434 edma_set_dest(link, asp_dst_ping, INCR, W16BIT);
435 edma_set_src_index(link, 0, 0);
436 edma_set_dest_index(link, 0, 0);
437
438 edma_read_slot(link, &prtd->asp_params);
439 prtd->asp_params.opt &= ~(TCCMODE | EDMA_TCC(0x3f));
440 /* interrupt after every pong completion */
441 prtd->asp_params.opt |= TCINTEN | TCCHEN |
442 EDMA_TCC(EDMA_CHAN_SLOT(prtd->ram_channel));
443 edma_write_slot(link, &prtd->asp_params);
444
445 /* ram */
446 link = prtd->ram_link;
447 edma_set_src(link, iram_dma->addr, INCR, W32BIT);
448 edma_set_dest(link, iram_dma->addr, INCR, W32BIT);
449 pr_debug("%s: audio dma channels/slots in use for ram:%u %u %u,"
450 "for asp:%u %u %u\n", __func__,
451 prtd->ram_channel, prtd->ram_link, prtd->ram_link2,
452 prtd->asp_channel, prtd->asp_link[0],
453 prtd->asp_link[1]);
454 return 0;
455exit4:
456 edma_free_channel(prtd->asp_link[1]);
457 prtd->asp_link[1] = -1;
458exit3:
459 edma_free_channel(prtd->ram_link);
460 prtd->ram_link = -1;
461exit2:
462 edma_free_channel(prtd->ram_channel);
463 prtd->ram_channel = -1;
464exit1:
465 return link;
124} 466}
125 467
126static int davinci_pcm_dma_request(struct snd_pcm_substream *substream) 468static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
127{ 469{
470 struct snd_dma_buffer *iram_dma;
128 struct davinci_runtime_data *prtd = substream->runtime->private_data; 471 struct davinci_runtime_data *prtd = substream->runtime->private_data;
129 struct edmacc_param p_ram; 472 struct davinci_pcm_dma_params *params = prtd->params;
130 int ret; 473 int link;
131 474
132 /* Request master DMA channel */ 475 if (!params)
133 ret = edma_alloc_channel(prtd->params->channel, 476 return -ENODEV;
134 davinci_pcm_dma_irq, substream,
135 EVENTQ_0);
136 if (ret < 0)
137 return ret;
138 prtd->master_lch = ret;
139 477
140 /* Request parameter RAM reload slot */ 478 /* Request asp master DMA channel */
141 ret = edma_alloc_slot(EDMA_CTLR(prtd->master_lch), EDMA_SLOT_ANY); 479 link = prtd->asp_channel = edma_alloc_channel(params->channel,
142 if (ret < 0) { 480 davinci_pcm_dma_irq, substream, EVENTQ_0);
143 edma_free_channel(prtd->master_lch); 481 if (link < 0)
144 return ret; 482 goto exit1;
483
484 /* Request asp link channels */
485 link = prtd->asp_link[0] = edma_alloc_slot(
486 EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
487 if (link < 0)
488 goto exit2;
489
490 iram_dma = (struct snd_dma_buffer *)substream->dma_buffer.private_data;
491 if (iram_dma) {
492 if (request_ping_pong(substream, prtd, iram_dma) == 0)
493 return 0;
494 printk(KERN_WARNING "%s: dma channel allocation failed,"
495 "not using sram\n", __func__);
145 } 496 }
146 prtd->slave_lch = ret;
147 497
148 /* Issue transfer completion IRQ when the channel completes a 498 /* Issue transfer completion IRQ when the channel completes a
149 * transfer, then always reload from the same slot (by a kind 499 * transfer, then always reload from the same slot (by a kind
@@ -154,12 +504,17 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
154 * the buffer and its length (ccnt) ... use it as a template 504 * the buffer and its length (ccnt) ... use it as a template
155 * so davinci_pcm_enqueue_dma() takes less time in IRQ. 505 * so davinci_pcm_enqueue_dma() takes less time in IRQ.
156 */ 506 */
157 edma_read_slot(prtd->slave_lch, &p_ram); 507 edma_read_slot(link, &prtd->asp_params);
158 p_ram.opt |= TCINTEN | EDMA_TCC(EDMA_CHAN_SLOT(prtd->master_lch)); 508 prtd->asp_params.opt |= TCINTEN |
159 p_ram.link_bcntrld = EDMA_CHAN_SLOT(prtd->slave_lch) << 5; 509 EDMA_TCC(EDMA_CHAN_SLOT(prtd->asp_channel));
160 edma_write_slot(prtd->slave_lch, &p_ram); 510 prtd->asp_params.link_bcntrld = EDMA_CHAN_SLOT(link) << 5;
161 511 edma_write_slot(link, &prtd->asp_params);
162 return 0; 512 return 0;
513exit2:
514 edma_free_channel(prtd->asp_channel);
515 prtd->asp_channel = -1;
516exit1:
517 return link;
163} 518}
164 519
165static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 520static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -173,12 +528,12 @@ static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
173 case SNDRV_PCM_TRIGGER_START: 528 case SNDRV_PCM_TRIGGER_START:
174 case SNDRV_PCM_TRIGGER_RESUME: 529 case SNDRV_PCM_TRIGGER_RESUME:
175 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 530 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
176 edma_start(prtd->master_lch); 531 edma_resume(prtd->asp_channel);
177 break; 532 break;
178 case SNDRV_PCM_TRIGGER_STOP: 533 case SNDRV_PCM_TRIGGER_STOP:
179 case SNDRV_PCM_TRIGGER_SUSPEND: 534 case SNDRV_PCM_TRIGGER_SUSPEND:
180 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 535 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
181 edma_stop(prtd->master_lch); 536 edma_pause(prtd->asp_channel);
182 break; 537 break;
183 default: 538 default:
184 ret = -EINVAL; 539 ret = -EINVAL;
@@ -193,15 +548,37 @@ static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
193static int davinci_pcm_prepare(struct snd_pcm_substream *substream) 548static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
194{ 549{
195 struct davinci_runtime_data *prtd = substream->runtime->private_data; 550 struct davinci_runtime_data *prtd = substream->runtime->private_data;
196 struct edmacc_param temp;
197 551
552 if (prtd->ram_channel >= 0) {
553 int ret = ping_pong_dma_setup(substream);
554 if (ret < 0)
555 return ret;
556
557 edma_write_slot(prtd->ram_channel, &prtd->ram_params);
558 edma_write_slot(prtd->asp_channel, &prtd->asp_params);
559
560 print_buf_info(prtd->ram_channel, "ram_channel");
561 print_buf_info(prtd->ram_link, "ram_link");
562 print_buf_info(prtd->ram_link2, "ram_link2");
563 print_buf_info(prtd->asp_channel, "asp_channel");
564 print_buf_info(prtd->asp_link[0], "asp_link[0]");
565 print_buf_info(prtd->asp_link[1], "asp_link[1]");
566
567 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
568 /* copy 1st iram buffer */
569 edma_start(prtd->ram_channel);
570 }
571 edma_start(prtd->asp_channel);
572 return 0;
573 }
198 prtd->period = 0; 574 prtd->period = 0;
199 davinci_pcm_enqueue_dma(substream); 575 davinci_pcm_enqueue_dma(substream);
200 576
201 /* Copy self-linked parameter RAM entry into master channel */ 577 /* Copy self-linked parameter RAM entry into master channel */
202 edma_read_slot(prtd->slave_lch, &temp); 578 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
203 edma_write_slot(prtd->master_lch, &temp); 579 edma_write_slot(prtd->asp_channel, &prtd->asp_params);
204 davinci_pcm_enqueue_dma(substream); 580 davinci_pcm_enqueue_dma(substream);
581 edma_start(prtd->asp_channel);
205 582
206 return 0; 583 return 0;
207} 584}
@@ -212,20 +589,53 @@ davinci_pcm_pointer(struct snd_pcm_substream *substream)
212 struct snd_pcm_runtime *runtime = substream->runtime; 589 struct snd_pcm_runtime *runtime = substream->runtime;
213 struct davinci_runtime_data *prtd = runtime->private_data; 590 struct davinci_runtime_data *prtd = runtime->private_data;
214 unsigned int offset; 591 unsigned int offset;
215 dma_addr_t count; 592 int asp_count;
216 dma_addr_t src, dst; 593 dma_addr_t asp_src, asp_dst;
217 594
218 spin_lock(&prtd->lock); 595 spin_lock(&prtd->lock);
219 596 if (prtd->ram_channel >= 0) {
220 edma_get_position(prtd->master_lch, &src, &dst); 597 int ram_count;
221 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 598 int mod_ram;
222 count = src - runtime->dma_addr; 599 dma_addr_t ram_src, ram_dst;
223 else 600 unsigned int period_size = snd_pcm_lib_period_bytes(substream);
224 count = dst - runtime->dma_addr; 601 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
225 602 /* reading ram before asp should be safe
603 * as long as the asp transfers less than a ping size
604 * of bytes between the 2 reads
605 */
606 edma_get_position(prtd->ram_channel,
607 &ram_src, &ram_dst);
608 edma_get_position(prtd->asp_channel,
609 &asp_src, &asp_dst);
610 asp_count = asp_src - prtd->asp_params.src;
611 ram_count = ram_src - prtd->ram_params.src;
612 mod_ram = ram_count % period_size;
613 mod_ram -= asp_count;
614 if (mod_ram < 0)
615 mod_ram += period_size;
616 else if (mod_ram == 0) {
617 if (snd_pcm_running(substream))
618 mod_ram += period_size;
619 }
620 ram_count -= mod_ram;
621 if (ram_count < 0)
622 ram_count += period_size * runtime->periods;
623 } else {
624 edma_get_position(prtd->ram_channel,
625 &ram_src, &ram_dst);
626 ram_count = ram_dst - prtd->ram_params.dst;
627 }
628 asp_count = ram_count;
629 } else {
630 edma_get_position(prtd->asp_channel, &asp_src, &asp_dst);
631 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
632 asp_count = asp_src - runtime->dma_addr;
633 else
634 asp_count = asp_dst - runtime->dma_addr;
635 }
226 spin_unlock(&prtd->lock); 636 spin_unlock(&prtd->lock);
227 637
228 offset = bytes_to_frames(runtime, count); 638 offset = bytes_to_frames(runtime, asp_count);
229 if (offset >= runtime->buffer_size) 639 if (offset >= runtime->buffer_size)
230 offset = 0; 640 offset = 0;
231 641
@@ -236,14 +646,19 @@ static int davinci_pcm_open(struct snd_pcm_substream *substream)
236{ 646{
237 struct snd_pcm_runtime *runtime = substream->runtime; 647 struct snd_pcm_runtime *runtime = substream->runtime;
238 struct davinci_runtime_data *prtd; 648 struct davinci_runtime_data *prtd;
649 struct snd_pcm_hardware *ppcm;
239 int ret = 0; 650 int ret = 0;
240 struct snd_soc_pcm_runtime *rtd = substream->private_data; 651 struct snd_soc_pcm_runtime *rtd = substream->private_data;
241 struct davinci_pcm_dma_params *pa = rtd->dai->cpu_dai->private_data; 652 struct davinci_pcm_dma_params *pa = rtd->dai->cpu_dai->dma_data;
242 struct davinci_pcm_dma_params *params = &pa[substream->stream]; 653 struct davinci_pcm_dma_params *params;
243 if (!params) 654 if (!pa)
244 return -ENODEV; 655 return -ENODEV;
656 params = &pa[substream->stream];
245 657
246 snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware); 658 ppcm = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
659 &pcm_hardware_playback : &pcm_hardware_capture;
660 allocate_sram(substream, params->sram_size, ppcm);
661 snd_soc_set_runtime_hwparams(substream, ppcm);
247 /* ensure that buffer size is a multiple of period size */ 662 /* ensure that buffer size is a multiple of period size */
248 ret = snd_pcm_hw_constraint_integer(runtime, 663 ret = snd_pcm_hw_constraint_integer(runtime,
249 SNDRV_PCM_HW_PARAM_PERIODS); 664 SNDRV_PCM_HW_PARAM_PERIODS);
@@ -256,6 +671,11 @@ static int davinci_pcm_open(struct snd_pcm_substream *substream)
256 671
257 spin_lock_init(&prtd->lock); 672 spin_lock_init(&prtd->lock);
258 prtd->params = params; 673 prtd->params = params;
674 prtd->asp_channel = -1;
675 prtd->asp_link[0] = prtd->asp_link[1] = -1;
676 prtd->ram_channel = -1;
677 prtd->ram_link = -1;
678 prtd->ram_link2 = -1;
259 679
260 runtime->private_data = prtd; 680 runtime->private_data = prtd;
261 681
@@ -273,10 +693,29 @@ static int davinci_pcm_close(struct snd_pcm_substream *substream)
273 struct snd_pcm_runtime *runtime = substream->runtime; 693 struct snd_pcm_runtime *runtime = substream->runtime;
274 struct davinci_runtime_data *prtd = runtime->private_data; 694 struct davinci_runtime_data *prtd = runtime->private_data;
275 695
276 edma_unlink(prtd->slave_lch); 696 if (prtd->ram_channel >= 0)
277 697 edma_stop(prtd->ram_channel);
278 edma_free_slot(prtd->slave_lch); 698 if (prtd->asp_channel >= 0)
279 edma_free_channel(prtd->master_lch); 699 edma_stop(prtd->asp_channel);
700 if (prtd->asp_link[0] >= 0)
701 edma_unlink(prtd->asp_link[0]);
702 if (prtd->asp_link[1] >= 0)
703 edma_unlink(prtd->asp_link[1]);
704 if (prtd->ram_link >= 0)
705 edma_unlink(prtd->ram_link);
706
707 if (prtd->asp_link[0] >= 0)
708 edma_free_slot(prtd->asp_link[0]);
709 if (prtd->asp_link[1] >= 0)
710 edma_free_slot(prtd->asp_link[1]);
711 if (prtd->asp_channel >= 0)
712 edma_free_channel(prtd->asp_channel);
713 if (prtd->ram_link >= 0)
714 edma_free_slot(prtd->ram_link);
715 if (prtd->ram_link2 >= 0)
716 edma_free_slot(prtd->ram_link2);
717 if (prtd->ram_channel >= 0)
718 edma_free_channel(prtd->ram_channel);
280 719
281 kfree(prtd); 720 kfree(prtd);
282 721
@@ -318,11 +757,11 @@ static struct snd_pcm_ops davinci_pcm_ops = {
318 .mmap = davinci_pcm_mmap, 757 .mmap = davinci_pcm_mmap,
319}; 758};
320 759
321static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream) 760static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream,
761 size_t size)
322{ 762{
323 struct snd_pcm_substream *substream = pcm->streams[stream].substream; 763 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
324 struct snd_dma_buffer *buf = &substream->dma_buffer; 764 struct snd_dma_buffer *buf = &substream->dma_buffer;
325 size_t size = davinci_pcm_hardware.buffer_bytes_max;
326 765
327 buf->dev.type = SNDRV_DMA_TYPE_DEV; 766 buf->dev.type = SNDRV_DMA_TYPE_DEV;
328 buf->dev.dev = pcm->card->dev; 767 buf->dev.dev = pcm->card->dev;
@@ -347,6 +786,7 @@ static void davinci_pcm_free(struct snd_pcm *pcm)
347 int stream; 786 int stream;
348 787
349 for (stream = 0; stream < 2; stream++) { 788 for (stream = 0; stream < 2; stream++) {
789 struct snd_dma_buffer *iram_dma;
350 substream = pcm->streams[stream].substream; 790 substream = pcm->streams[stream].substream;
351 if (!substream) 791 if (!substream)
352 continue; 792 continue;
@@ -358,6 +798,11 @@ static void davinci_pcm_free(struct snd_pcm *pcm)
358 dma_free_writecombine(pcm->card->dev, buf->bytes, 798 dma_free_writecombine(pcm->card->dev, buf->bytes,
359 buf->area, buf->addr); 799 buf->area, buf->addr);
360 buf->area = NULL; 800 buf->area = NULL;
801 iram_dma = (struct snd_dma_buffer *)buf->private_data;
802 if (iram_dma) {
803 sram_free(iram_dma->area, iram_dma->bytes);
804 kfree(iram_dma);
805 }
361 } 806 }
362} 807}
363 808
@@ -375,14 +820,16 @@ static int davinci_pcm_new(struct snd_card *card,
375 820
376 if (dai->playback.channels_min) { 821 if (dai->playback.channels_min) {
377 ret = davinci_pcm_preallocate_dma_buffer(pcm, 822 ret = davinci_pcm_preallocate_dma_buffer(pcm,
378 SNDRV_PCM_STREAM_PLAYBACK); 823 SNDRV_PCM_STREAM_PLAYBACK,
824 pcm_hardware_playback.buffer_bytes_max);
379 if (ret) 825 if (ret)
380 return ret; 826 return ret;
381 } 827 }
382 828
383 if (dai->capture.channels_min) { 829 if (dai->capture.channels_min) {
384 ret = davinci_pcm_preallocate_dma_buffer(pcm, 830 ret = davinci_pcm_preallocate_dma_buffer(pcm,
385 SNDRV_PCM_STREAM_CAPTURE); 831 SNDRV_PCM_STREAM_CAPTURE,
832 pcm_hardware_capture.buffer_bytes_max);
386 if (ret) 833 if (ret)
387 return ret; 834 return ret;
388 } 835 }
diff --git a/sound/soc/davinci/davinci-pcm.h b/sound/soc/davinci/davinci-pcm.h
index 8746606efc89..0764944cf10f 100644
--- a/sound/soc/davinci/davinci-pcm.h
+++ b/sound/soc/davinci/davinci-pcm.h
@@ -20,9 +20,11 @@ struct davinci_pcm_dma_params {
20 int channel; /* sync dma channel ID */ 20 int channel; /* sync dma channel ID */
21 unsigned short acnt; 21 unsigned short acnt;
22 dma_addr_t dma_addr; /* device physical address for DMA */ 22 dma_addr_t dma_addr; /* device physical address for DMA */
23 unsigned sram_size;
23 enum dma_event_q eventq_no; /* event queue number */ 24 enum dma_event_q eventq_no; /* event queue number */
24 unsigned char data_type; /* xfer data type */ 25 unsigned char data_type; /* xfer data type */
25 unsigned char convert_mono_stereo; 26 unsigned char convert_mono_stereo;
27 unsigned int fifo_level;
26}; 28};
27 29
28 30
diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
index 6096d22283e6..30ed568afb2e 100644
--- a/sound/soc/fsl/mpc5200_dma.c
+++ b/sound/soc/fsl/mpc5200_dma.c
@@ -58,47 +58,15 @@ static void psc_dma_bcom_enqueue_next_buffer(struct psc_dma_stream *s)
58 /* Prepare and enqueue the next buffer descriptor */ 58 /* Prepare and enqueue the next buffer descriptor */
59 bd = bcom_prepare_next_buffer(s->bcom_task); 59 bd = bcom_prepare_next_buffer(s->bcom_task);
60 bd->status = s->period_bytes; 60 bd->status = s->period_bytes;
61 bd->data[0] = s->period_next_pt; 61 bd->data[0] = s->runtime->dma_addr + (s->period_next * s->period_bytes);
62 bcom_submit_next_buffer(s->bcom_task, NULL); 62 bcom_submit_next_buffer(s->bcom_task, NULL);
63 63
64 /* Update for next period */ 64 /* Update for next period */
65 s->period_next_pt += s->period_bytes; 65 s->period_next = (s->period_next + 1) % s->runtime->periods;
66 if (s->period_next_pt >= s->period_end)
67 s->period_next_pt = s->period_start;
68}
69
70static void psc_dma_bcom_enqueue_tx(struct psc_dma_stream *s)
71{
72 if (s->appl_ptr > s->runtime->control->appl_ptr) {
73 /*
74 * In this case s->runtime->control->appl_ptr has wrapped around.
75 * Play the data to the end of the boundary, then wrap our own
76 * appl_ptr back around.
77 */
78 while (s->appl_ptr < s->runtime->boundary) {
79 if (bcom_queue_full(s->bcom_task))
80 return;
81
82 s->appl_ptr += s->period_size;
83
84 psc_dma_bcom_enqueue_next_buffer(s);
85 }
86 s->appl_ptr -= s->runtime->boundary;
87 }
88
89 while (s->appl_ptr < s->runtime->control->appl_ptr) {
90
91 if (bcom_queue_full(s->bcom_task))
92 return;
93
94 s->appl_ptr += s->period_size;
95
96 psc_dma_bcom_enqueue_next_buffer(s);
97 }
98} 66}
99 67
100/* Bestcomm DMA irq handler */ 68/* Bestcomm DMA irq handler */
101static irqreturn_t psc_dma_bcom_irq_tx(int irq, void *_psc_dma_stream) 69static irqreturn_t psc_dma_bcom_irq(int irq, void *_psc_dma_stream)
102{ 70{
103 struct psc_dma_stream *s = _psc_dma_stream; 71 struct psc_dma_stream *s = _psc_dma_stream;
104 72
@@ -108,34 +76,8 @@ static irqreturn_t psc_dma_bcom_irq_tx(int irq, void *_psc_dma_stream)
108 while (bcom_buffer_done(s->bcom_task)) { 76 while (bcom_buffer_done(s->bcom_task)) {
109 bcom_retrieve_buffer(s->bcom_task, NULL, NULL); 77 bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
110 78
111 s->period_current_pt += s->period_bytes; 79 s->period_current = (s->period_current+1) % s->runtime->periods;
112 if (s->period_current_pt >= s->period_end) 80 s->period_count++;
113 s->period_current_pt = s->period_start;
114 }
115 psc_dma_bcom_enqueue_tx(s);
116 spin_unlock(&s->psc_dma->lock);
117
118 /* If the stream is active, then also inform the PCM middle layer
119 * of the period finished event. */
120 if (s->active)
121 snd_pcm_period_elapsed(s->stream);
122
123 return IRQ_HANDLED;
124}
125
126static irqreturn_t psc_dma_bcom_irq_rx(int irq, void *_psc_dma_stream)
127{
128 struct psc_dma_stream *s = _psc_dma_stream;
129
130 spin_lock(&s->psc_dma->lock);
131 /* For each finished period, dequeue the completed period buffer
132 * and enqueue a new one in it's place. */
133 while (bcom_buffer_done(s->bcom_task)) {
134 bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
135
136 s->period_current_pt += s->period_bytes;
137 if (s->period_current_pt >= s->period_end)
138 s->period_current_pt = s->period_start;
139 81
140 psc_dma_bcom_enqueue_next_buffer(s); 82 psc_dma_bcom_enqueue_next_buffer(s);
141 } 83 }
@@ -166,54 +108,38 @@ static int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd)
166 struct snd_soc_pcm_runtime *rtd = substream->private_data; 108 struct snd_soc_pcm_runtime *rtd = substream->private_data;
167 struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data; 109 struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
168 struct snd_pcm_runtime *runtime = substream->runtime; 110 struct snd_pcm_runtime *runtime = substream->runtime;
169 struct psc_dma_stream *s; 111 struct psc_dma_stream *s = to_psc_dma_stream(substream, psc_dma);
170 struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs; 112 struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
171 u16 imr; 113 u16 imr;
172 unsigned long flags; 114 unsigned long flags;
173 int i; 115 int i;
174 116
175 if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
176 s = &psc_dma->capture;
177 else
178 s = &psc_dma->playback;
179
180 dev_dbg(psc_dma->dev, "psc_dma_trigger(substream=%p, cmd=%i)"
181 " stream_id=%i\n",
182 substream, cmd, substream->pstr->stream);
183
184 switch (cmd) { 117 switch (cmd) {
185 case SNDRV_PCM_TRIGGER_START: 118 case SNDRV_PCM_TRIGGER_START:
119 dev_dbg(psc_dma->dev, "START: stream=%i fbits=%u ps=%u #p=%u\n",
120 substream->pstr->stream, runtime->frame_bits,
121 (int)runtime->period_size, runtime->periods);
186 s->period_bytes = frames_to_bytes(runtime, 122 s->period_bytes = frames_to_bytes(runtime,
187 runtime->period_size); 123 runtime->period_size);
188 s->period_start = virt_to_phys(runtime->dma_area); 124 s->period_next = 0;
189 s->period_end = s->period_start + 125 s->period_current = 0;
190 (s->period_bytes * runtime->periods);
191 s->period_next_pt = s->period_start;
192 s->period_current_pt = s->period_start;
193 s->period_size = runtime->period_size;
194 s->active = 1; 126 s->active = 1;
195 127 s->period_count = 0;
196 /* track appl_ptr so that we have a better chance of detecting
197 * end of stream and not over running it.
198 */
199 s->runtime = runtime; 128 s->runtime = runtime;
200 s->appl_ptr = s->runtime->control->appl_ptr -
201 (runtime->period_size * runtime->periods);
202 129
203 /* Fill up the bestcomm bd queue and enable DMA. 130 /* Fill up the bestcomm bd queue and enable DMA.
204 * This will begin filling the PSC's fifo. 131 * This will begin filling the PSC's fifo.
205 */ 132 */
206 spin_lock_irqsave(&psc_dma->lock, flags); 133 spin_lock_irqsave(&psc_dma->lock, flags);
207 134
208 if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE) { 135 if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
209 bcom_gen_bd_rx_reset(s->bcom_task); 136 bcom_gen_bd_rx_reset(s->bcom_task);
210 for (i = 0; i < runtime->periods; i++) 137 else
211 if (!bcom_queue_full(s->bcom_task))
212 psc_dma_bcom_enqueue_next_buffer(s);
213 } else {
214 bcom_gen_bd_tx_reset(s->bcom_task); 138 bcom_gen_bd_tx_reset(s->bcom_task);
215 psc_dma_bcom_enqueue_tx(s); 139
216 } 140 for (i = 0; i < runtime->periods; i++)
141 if (!bcom_queue_full(s->bcom_task))
142 psc_dma_bcom_enqueue_next_buffer(s);
217 143
218 bcom_enable(s->bcom_task); 144 bcom_enable(s->bcom_task);
219 spin_unlock_irqrestore(&psc_dma->lock, flags); 145 spin_unlock_irqrestore(&psc_dma->lock, flags);
@@ -223,6 +149,8 @@ static int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd)
223 break; 149 break;
224 150
225 case SNDRV_PCM_TRIGGER_STOP: 151 case SNDRV_PCM_TRIGGER_STOP:
152 dev_dbg(psc_dma->dev, "STOP: stream=%i periods_count=%i\n",
153 substream->pstr->stream, s->period_count);
226 s->active = 0; 154 s->active = 0;
227 155
228 spin_lock_irqsave(&psc_dma->lock, flags); 156 spin_lock_irqsave(&psc_dma->lock, flags);
@@ -236,7 +164,8 @@ static int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd)
236 break; 164 break;
237 165
238 default: 166 default:
239 dev_dbg(psc_dma->dev, "invalid command\n"); 167 dev_dbg(psc_dma->dev, "unhandled trigger: stream=%i cmd=%i\n",
168 substream->pstr->stream, cmd);
240 return -EINVAL; 169 return -EINVAL;
241 } 170 }
242 171
@@ -343,7 +272,7 @@ psc_dma_pointer(struct snd_pcm_substream *substream)
343 else 272 else
344 s = &psc_dma->playback; 273 s = &psc_dma->playback;
345 274
346 count = s->period_current_pt - s->period_start; 275 count = s->period_current * s->period_bytes;
347 276
348 return bytes_to_frames(substream->runtime, count); 277 return bytes_to_frames(substream->runtime, count);
349} 278}
@@ -532,11 +461,9 @@ int mpc5200_audio_dma_create(struct of_device *op)
532 461
533 rc = request_irq(psc_dma->irq, &psc_dma_status_irq, IRQF_SHARED, 462 rc = request_irq(psc_dma->irq, &psc_dma_status_irq, IRQF_SHARED,
534 "psc-dma-status", psc_dma); 463 "psc-dma-status", psc_dma);
535 rc |= request_irq(psc_dma->capture.irq, 464 rc |= request_irq(psc_dma->capture.irq, &psc_dma_bcom_irq, IRQF_SHARED,
536 &psc_dma_bcom_irq_rx, IRQF_SHARED,
537 "psc-dma-capture", &psc_dma->capture); 465 "psc-dma-capture", &psc_dma->capture);
538 rc |= request_irq(psc_dma->playback.irq, 466 rc |= request_irq(psc_dma->playback.irq, &psc_dma_bcom_irq, IRQF_SHARED,
539 &psc_dma_bcom_irq_tx, IRQF_SHARED,
540 "psc-dma-playback", &psc_dma->playback); 467 "psc-dma-playback", &psc_dma->playback);
541 if (rc) { 468 if (rc) {
542 ret = -ENODEV; 469 ret = -ENODEV;
diff --git a/sound/soc/fsl/mpc5200_dma.h b/sound/soc/fsl/mpc5200_dma.h
index 8d396bb9d9fe..22208b373fb9 100644
--- a/sound/soc/fsl/mpc5200_dma.h
+++ b/sound/soc/fsl/mpc5200_dma.h
@@ -13,26 +13,25 @@
13 * @psc_dma: pointer back to parent psc_dma data structure 13 * @psc_dma: pointer back to parent psc_dma data structure
14 * @bcom_task: bestcomm task structure 14 * @bcom_task: bestcomm task structure
15 * @irq: irq number for bestcomm task 15 * @irq: irq number for bestcomm task
16 * @period_start: physical address of start of DMA region
17 * @period_end: physical address of end of DMA region 16 * @period_end: physical address of end of DMA region
18 * @period_next_pt: physical address of next DMA buffer to enqueue 17 * @period_next_pt: physical address of next DMA buffer to enqueue
19 * @period_bytes: size of DMA period in bytes 18 * @period_bytes: size of DMA period in bytes
19 * @ac97_slot_bits: Enable bits for turning on the correct AC97 slot
20 */ 20 */
21struct psc_dma_stream { 21struct psc_dma_stream {
22 struct snd_pcm_runtime *runtime; 22 struct snd_pcm_runtime *runtime;
23 snd_pcm_uframes_t appl_ptr;
24
25 int active; 23 int active;
26 struct psc_dma *psc_dma; 24 struct psc_dma *psc_dma;
27 struct bcom_task *bcom_task; 25 struct bcom_task *bcom_task;
28 int irq; 26 int irq;
29 struct snd_pcm_substream *stream; 27 struct snd_pcm_substream *stream;
30 dma_addr_t period_start; 28 int period_next;
31 dma_addr_t period_end; 29 int period_current;
32 dma_addr_t period_next_pt;
33 dma_addr_t period_current_pt;
34 int period_bytes; 30 int period_bytes;
35 int period_size; 31 int period_count;
32
33 /* AC97 state */
34 u32 ac97_slot_bits;
36}; 35};
37 36
38/** 37/**
@@ -73,6 +72,15 @@ struct psc_dma {
73 } stats; 72 } stats;
74}; 73};
75 74
75/* Utility for retrieving psc_dma_stream structure from a substream */
76inline struct psc_dma_stream *
77to_psc_dma_stream(struct snd_pcm_substream *substream, struct psc_dma *psc_dma)
78{
79 if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
80 return &psc_dma->capture;
81 return &psc_dma->playback;
82}
83
76int mpc5200_audio_dma_create(struct of_device *op); 84int mpc5200_audio_dma_create(struct of_device *op);
77int mpc5200_audio_dma_destroy(struct of_device *op); 85int mpc5200_audio_dma_destroy(struct of_device *op);
78 86
diff --git a/sound/soc/fsl/mpc5200_psc_ac97.c b/sound/soc/fsl/mpc5200_psc_ac97.c
index c4ae3e096bb9..3dbc7f7cd7b9 100644
--- a/sound/soc/fsl/mpc5200_psc_ac97.c
+++ b/sound/soc/fsl/mpc5200_psc_ac97.c
@@ -130,6 +130,7 @@ static int psc_ac97_hw_analog_params(struct snd_pcm_substream *substream,
130 struct snd_soc_dai *cpu_dai) 130 struct snd_soc_dai *cpu_dai)
131{ 131{
132 struct psc_dma *psc_dma = cpu_dai->private_data; 132 struct psc_dma *psc_dma = cpu_dai->private_data;
133 struct psc_dma_stream *s = to_psc_dma_stream(substream, psc_dma);
133 134
134 dev_dbg(psc_dma->dev, "%s(substream=%p) p_size=%i p_bytes=%i" 135 dev_dbg(psc_dma->dev, "%s(substream=%p) p_size=%i p_bytes=%i"
135 " periods=%i buffer_size=%i buffer_bytes=%i channels=%i" 136 " periods=%i buffer_size=%i buffer_bytes=%i channels=%i"
@@ -140,20 +141,10 @@ static int psc_ac97_hw_analog_params(struct snd_pcm_substream *substream,
140 params_channels(params), params_rate(params), 141 params_channels(params), params_rate(params),
141 params_format(params)); 142 params_format(params));
142 143
143 144 /* Determine the set of enable bits to turn on */
144 if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE) { 145 s->ac97_slot_bits = (params_channels(params) == 1) ? 0x100 : 0x300;
145 if (params_channels(params) == 1) 146 if (substream->pstr->stream != SNDRV_PCM_STREAM_CAPTURE)
146 psc_dma->slots |= 0x00000100; 147 s->ac97_slot_bits <<= 16;
147 else
148 psc_dma->slots |= 0x00000300;
149 } else {
150 if (params_channels(params) == 1)
151 psc_dma->slots |= 0x01000000;
152 else
153 psc_dma->slots |= 0x03000000;
154 }
155 out_be32(&psc_dma->psc_regs->ac97_slots, psc_dma->slots);
156
157 return 0; 148 return 0;
158} 149}
159 150
@@ -163,6 +154,8 @@ static int psc_ac97_hw_digital_params(struct snd_pcm_substream *substream,
163{ 154{
164 struct psc_dma *psc_dma = cpu_dai->private_data; 155 struct psc_dma *psc_dma = cpu_dai->private_data;
165 156
157 dev_dbg(psc_dma->dev, "%s(substream=%p)\n", __func__, substream);
158
166 if (params_channels(params) == 1) 159 if (params_channels(params) == 1)
167 out_be32(&psc_dma->psc_regs->ac97_slots, 0x01000000); 160 out_be32(&psc_dma->psc_regs->ac97_slots, 0x01000000);
168 else 161 else
@@ -176,14 +169,24 @@ static int psc_ac97_trigger(struct snd_pcm_substream *substream, int cmd,
176{ 169{
177 struct snd_soc_pcm_runtime *rtd = substream->private_data; 170 struct snd_soc_pcm_runtime *rtd = substream->private_data;
178 struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data; 171 struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
172 struct psc_dma_stream *s = to_psc_dma_stream(substream, psc_dma);
179 173
180 switch (cmd) { 174 switch (cmd) {
175 case SNDRV_PCM_TRIGGER_START:
176 dev_dbg(psc_dma->dev, "AC97 START: stream=%i\n",
177 substream->pstr->stream);
178
179 /* Set the slot enable bits */
180 psc_dma->slots |= s->ac97_slot_bits;
181 out_be32(&psc_dma->psc_regs->ac97_slots, psc_dma->slots);
182 break;
183
181 case SNDRV_PCM_TRIGGER_STOP: 184 case SNDRV_PCM_TRIGGER_STOP:
182 if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE) 185 dev_dbg(psc_dma->dev, "AC97 STOP: stream=%i\n",
183 psc_dma->slots &= 0xFFFF0000; 186 substream->pstr->stream);
184 else
185 psc_dma->slots &= 0x0000FFFF;
186 187
188 /* Clear the slot enable bits */
189 psc_dma->slots &= ~(s->ac97_slot_bits);
187 out_be32(&psc_dma->psc_regs->ac97_slots, psc_dma->slots); 190 out_be32(&psc_dma->psc_regs->ac97_slots, psc_dma->slots);
188 break; 191 break;
189 } 192 }
diff --git a/sound/soc/imx/mx27vis_wm8974.c b/sound/soc/imx/mx27vis_wm8974.c
index e4dcb539108a..0267d2d91685 100644
--- a/sound/soc/imx/mx27vis_wm8974.c
+++ b/sound/soc/imx/mx27vis_wm8974.c
@@ -157,7 +157,7 @@ static int mx27vis_hifi_hw_params(struct snd_pcm_substream *substream,
157 157
158 158
159 /* codec PLL input is 25 MHz */ 159 /* codec PLL input is 25 MHz */
160 ret = codec_dai->ops->set_pll(codec_dai, IGNORED_ARG, 160 ret = codec_dai->ops->set_pll(codec_dai, IGNORED_ARG, IGNORED_ARG,
161 25000000, pll_out); 161 25000000, pll_out);
162 if (ret < 0) { 162 if (ret < 0) {
163 printk(KERN_ERR "Error when setting PLL input\n"); 163 printk(KERN_ERR "Error when setting PLL input\n");
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index 653a362425df..61952aa6cd5a 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -43,12 +43,13 @@ config SND_OMAP_SOC_OSK5912
43 Say Y if you want to add support for SoC audio on osk5912. 43 Say Y if you want to add support for SoC audio on osk5912.
44 44
45config SND_OMAP_SOC_OVERO 45config SND_OMAP_SOC_OVERO
46 tristate "SoC Audio support for Gumstix Overo" 46 tristate "SoC Audio support for Gumstix Overo and CompuLab CM-T35"
47 depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OVERO 47 depends on TWL4030_CORE && SND_OMAP_SOC && (MACH_OVERO || MACH_CM_T35)
48 select SND_OMAP_SOC_MCBSP 48 select SND_OMAP_SOC_MCBSP
49 select SND_SOC_TWL4030 49 select SND_SOC_TWL4030
50 help 50 help
51 Say Y if you want to add support for SoC audio on the Gumstix Overo. 51 Say Y if you want to add support for SoC audio on the
52 Gumstix Overo or CompuLab CM-T35
52 53
53config SND_OMAP_SOC_OMAP2EVM 54config SND_OMAP_SOC_OMAP2EVM
54 tristate "SoC Audio support for OMAP2EVM board" 55 tristate "SoC Audio support for OMAP2EVM board"
@@ -66,6 +67,15 @@ config SND_OMAP_SOC_OMAP3EVM
66 help 67 help
67 Say Y if you want to add support for SoC audio on the omap3evm board. 68 Say Y if you want to add support for SoC audio on the omap3evm board.
68 69
70config SND_OMAP_SOC_AM3517EVM
71 tristate "SoC Audio support for OMAP3517 / AM3517 EVM"
72 depends on SND_OMAP_SOC && MACH_OMAP3517EVM && I2C
73 select SND_OMAP_SOC_MCBSP
74 select SND_SOC_TLV320AIC23
75 help
76 Say Y if you want to add support for SoC audio on the OMAP3517 / AM3517
77 EVM.
78
69config SND_OMAP_SOC_SDP3430 79config SND_OMAP_SOC_SDP3430
70 tristate "SoC Audio support for Texas Instruments SDP3430" 80 tristate "SoC Audio support for Texas Instruments SDP3430"
71 depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP_3430SDP 81 depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP_3430SDP
@@ -99,3 +109,10 @@ config SND_OMAP_SOC_ZOOM2
99 help 109 help
100 Say Y if you want to add support for Soc audio on Zoom2 board. 110 Say Y if you want to add support for Soc audio on Zoom2 board.
101 111
112config SND_OMAP_SOC_IGEP0020
113 tristate "SoC Audio support for IGEP v2"
114 depends on TWL4030_CORE && SND_OMAP_SOC && MACH_IGEP0020
115 select SND_OMAP_SOC_MCBSP
116 select SND_SOC_TWL4030
117 help
118 Say Y if you want to add support for Soc audio on IGEP v2 board.
diff --git a/sound/soc/omap/Makefile b/sound/soc/omap/Makefile
index 02d69471dcb5..d49458a29bb7 100644
--- a/sound/soc/omap/Makefile
+++ b/sound/soc/omap/Makefile
@@ -12,10 +12,12 @@ snd-soc-osk5912-objs := osk5912.o
12snd-soc-overo-objs := overo.o 12snd-soc-overo-objs := overo.o
13snd-soc-omap2evm-objs := omap2evm.o 13snd-soc-omap2evm-objs := omap2evm.o
14snd-soc-omap3evm-objs := omap3evm.o 14snd-soc-omap3evm-objs := omap3evm.o
15snd-soc-am3517evm-objs := am3517evm.o
15snd-soc-sdp3430-objs := sdp3430.o 16snd-soc-sdp3430-objs := sdp3430.o
16snd-soc-omap3pandora-objs := omap3pandora.o 17snd-soc-omap3pandora-objs := omap3pandora.o
17snd-soc-omap3beagle-objs := omap3beagle.o 18snd-soc-omap3beagle-objs := omap3beagle.o
18snd-soc-zoom2-objs := zoom2.o 19snd-soc-zoom2-objs := zoom2.o
20snd-soc-igep0020-objs := igep0020.o
19 21
20obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o 22obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o
21obj-$(CONFIG_SND_OMAP_SOC_AMS_DELTA) += snd-soc-ams-delta.o 23obj-$(CONFIG_SND_OMAP_SOC_AMS_DELTA) += snd-soc-ams-delta.o
@@ -23,7 +25,9 @@ obj-$(CONFIG_SND_OMAP_SOC_OSK5912) += snd-soc-osk5912.o
23obj-$(CONFIG_SND_OMAP_SOC_OVERO) += snd-soc-overo.o 25obj-$(CONFIG_SND_OMAP_SOC_OVERO) += snd-soc-overo.o
24obj-$(CONFIG_MACH_OMAP2EVM) += snd-soc-omap2evm.o 26obj-$(CONFIG_MACH_OMAP2EVM) += snd-soc-omap2evm.o
25obj-$(CONFIG_MACH_OMAP3EVM) += snd-soc-omap3evm.o 27obj-$(CONFIG_MACH_OMAP3EVM) += snd-soc-omap3evm.o
28obj-$(CONFIG_MACH_OMAP3517EVM) += snd-soc-am3517evm.o
26obj-$(CONFIG_SND_OMAP_SOC_SDP3430) += snd-soc-sdp3430.o 29obj-$(CONFIG_SND_OMAP_SOC_SDP3430) += snd-soc-sdp3430.o
27obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o 30obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o
28obj-$(CONFIG_SND_OMAP_SOC_OMAP3_BEAGLE) += snd-soc-omap3beagle.o 31obj-$(CONFIG_SND_OMAP_SOC_OMAP3_BEAGLE) += snd-soc-omap3beagle.o
29obj-$(CONFIG_SND_OMAP_SOC_ZOOM2) += snd-soc-zoom2.o 32obj-$(CONFIG_SND_OMAP_SOC_ZOOM2) += snd-soc-zoom2.o
33obj-$(CONFIG_SND_OMAP_SOC_IGEP0020) += snd-soc-igep0020.o
diff --git a/sound/soc/omap/am3517evm.c b/sound/soc/omap/am3517evm.c
new file mode 100644
index 000000000000..135901b2ea11
--- /dev/null
+++ b/sound/soc/omap/am3517evm.c
@@ -0,0 +1,202 @@
1/*
2 * am3517evm.c -- ALSA SoC support for OMAP3517 / AM3517 EVM
3 *
4 * Author: Anuj Aggarwal <anuj.aggarwal@ti.com>
5 *
6 * Based on sound/soc/omap/beagle.c by Steve Sakoman
7 *
8 * Copyright (C) 2009 Texas Instruments Incorporated
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 as published by the
12 * Free Software Foundation version 2.
13 *
14 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
15 * whether express or implied; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 */
19
20#include <linux/clk.h>
21#include <linux/platform_device.h>
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26
27#include <asm/mach-types.h>
28#include <mach/hardware.h>
29#include <mach/gpio.h>
30#include <plat/mcbsp.h>
31
32#include "omap-mcbsp.h"
33#include "omap-pcm.h"
34
35#include "../codecs/tlv320aic23.h"
36
37#define CODEC_CLOCK 12000000
38
39static int am3517evm_hw_params(struct snd_pcm_substream *substream,
40 struct snd_pcm_hw_params *params)
41{
42 struct snd_soc_pcm_runtime *rtd = substream->private_data;
43 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
44 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
45 int ret;
46
47 /* Set codec DAI configuration */
48 ret = snd_soc_dai_set_fmt(codec_dai,
49 SND_SOC_DAIFMT_DSP_B |
50 SND_SOC_DAIFMT_NB_NF |
51 SND_SOC_DAIFMT_CBM_CFM);
52 if (ret < 0) {
53 printk(KERN_ERR "can't set codec DAI configuration\n");
54 return ret;
55 }
56
57 /* Set cpu DAI configuration */
58 ret = snd_soc_dai_set_fmt(cpu_dai,
59 SND_SOC_DAIFMT_DSP_B |
60 SND_SOC_DAIFMT_NB_NF |
61 SND_SOC_DAIFMT_CBM_CFM);
62 if (ret < 0) {
63 printk(KERN_ERR "can't set cpu DAI configuration\n");
64 return ret;
65 }
66
67 /* Set the codec system clock for DAC and ADC */
68 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
69 CODEC_CLOCK, SND_SOC_CLOCK_IN);
70 if (ret < 0) {
71 printk(KERN_ERR "can't set codec system clock\n");
72 return ret;
73 }
74
75 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_CLKR_SRC_CLKX, 0,
76 SND_SOC_CLOCK_IN);
77 if (ret < 0) {
78 printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_CLKR_SRC_CLKX\n");
79 return ret;
80 }
81
82 snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_FSR_SRC_FSX, 0,
83 SND_SOC_CLOCK_IN);
84 if (ret < 0) {
85 printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_FSR_SRC_FSX\n");
86 return ret;
87 }
88
89 return 0;
90}
91
92static struct snd_soc_ops am3517evm_ops = {
93 .hw_params = am3517evm_hw_params,
94};
95
96/* am3517evm machine dapm widgets */
97static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
98 SND_SOC_DAPM_HP("Line Out", NULL),
99 SND_SOC_DAPM_LINE("Line In", NULL),
100 SND_SOC_DAPM_MIC("Mic In", NULL),
101};
102
103static const struct snd_soc_dapm_route audio_map[] = {
104 /* Line Out connected to LLOUT, RLOUT */
105 {"Line Out", NULL, "LOUT"},
106 {"Line Out", NULL, "ROUT"},
107
108 {"LLINEIN", NULL, "Line In"},
109 {"RLINEIN", NULL, "Line In"},
110
111 {"MICIN", NULL, "Mic In"},
112};
113
114static int am3517evm_aic23_init(struct snd_soc_codec *codec)
115{
116 /* Add am3517-evm specific widgets */
117 snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets,
118 ARRAY_SIZE(tlv320aic23_dapm_widgets));
119
120 /* Set up davinci-evm specific audio path audio_map */
121 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
122
123 /* always connected */
124 snd_soc_dapm_enable_pin(codec, "Line Out");
125 snd_soc_dapm_enable_pin(codec, "Line In");
126 snd_soc_dapm_enable_pin(codec, "Mic In");
127
128 snd_soc_dapm_sync(codec);
129
130 return 0;
131}
132
133/* Digital audio interface glue - connects codec <--> CPU */
134static struct snd_soc_dai_link am3517evm_dai = {
135 .name = "TLV320AIC23",
136 .stream_name = "AIC23",
137 .cpu_dai = &omap_mcbsp_dai[0],
138 .codec_dai = &tlv320aic23_dai,
139 .init = am3517evm_aic23_init,
140 .ops = &am3517evm_ops,
141};
142
143/* Audio machine driver */
144static struct snd_soc_card snd_soc_am3517evm = {
145 .name = "am3517evm",
146 .platform = &omap_soc_platform,
147 .dai_link = &am3517evm_dai,
148 .num_links = 1,
149};
150
151/* Audio subsystem */
152static struct snd_soc_device am3517evm_snd_devdata = {
153 .card = &snd_soc_am3517evm,
154 .codec_dev = &soc_codec_dev_tlv320aic23,
155};
156
157static struct platform_device *am3517evm_snd_device;
158
159static int __init am3517evm_soc_init(void)
160{
161 int ret;
162
163 if (!machine_is_omap3517evm()) {
164 pr_err("Not OMAP3517 / AM3517 EVM!\n");
165 return -ENODEV;
166 }
167 pr_info("OMAP3517 / AM3517 EVM SoC init\n");
168
169 am3517evm_snd_device = platform_device_alloc("soc-audio", -1);
170 if (!am3517evm_snd_device) {
171 printk(KERN_ERR "Platform device allocation failed\n");
172 return -ENOMEM;
173 }
174
175 platform_set_drvdata(am3517evm_snd_device, &am3517evm_snd_devdata);
176 am3517evm_snd_devdata.dev = &am3517evm_snd_device->dev;
177 *(unsigned int *)am3517evm_dai.cpu_dai->private_data = 0; /* McBSP1 */
178
179 ret = platform_device_add(am3517evm_snd_device);
180 if (ret)
181 goto err1;
182
183 return 0;
184
185err1:
186 printk(KERN_ERR "Unable to add platform device\n");
187 platform_device_put(am3517evm_snd_device);
188
189 return ret;
190}
191
192static void __exit am3517evm_soc_exit(void)
193{
194 platform_device_unregister(am3517evm_snd_device);
195}
196
197module_init(am3517evm_soc_init);
198module_exit(am3517evm_soc_exit);
199
200MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
201MODULE_DESCRIPTION("ALSA SoC OMAP3517 / AM3517 EVM");
202MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/omap/ams-delta.c b/sound/soc/omap/ams-delta.c
index 5a5166ac7279..b0f618e44840 100644
--- a/sound/soc/omap/ams-delta.c
+++ b/sound/soc/omap/ams-delta.c
@@ -31,8 +31,8 @@
31 31
32#include <asm/mach-types.h> 32#include <asm/mach-types.h>
33 33
34#include <mach/board-ams-delta.h> 34#include <plat/board-ams-delta.h>
35#include <mach/mcbsp.h> 35#include <plat/mcbsp.h>
36 36
37#include "omap-mcbsp.h" 37#include "omap-mcbsp.h"
38#include "omap-pcm.h" 38#include "omap-pcm.h"
@@ -40,7 +40,7 @@
40 40
41 41
42/* Board specific DAPM widgets */ 42/* Board specific DAPM widgets */
43 const struct snd_soc_dapm_widget ams_delta_dapm_widgets[] = { 43static const struct snd_soc_dapm_widget ams_delta_dapm_widgets[] = {
44 /* Handset */ 44 /* Handset */
45 SND_SOC_DAPM_MIC("Mouthpiece", NULL), 45 SND_SOC_DAPM_MIC("Mouthpiece", NULL),
46 SND_SOC_DAPM_HP("Earpiece", NULL), 46 SND_SOC_DAPM_HP("Earpiece", NULL),
@@ -81,7 +81,7 @@ static const char *ams_delta_audio_mode[] =
81 (1 << AMS_DELTA_SPEAKER)) 81 (1 << AMS_DELTA_SPEAKER))
82#define AMS_DELTA_SPEAKERPHONE (AMS_DELTA_HANDSFREE | (1 << AMS_DELTA_AGC)) 82#define AMS_DELTA_SPEAKERPHONE (AMS_DELTA_HANDSFREE | (1 << AMS_DELTA_AGC))
83 83
84unsigned short ams_delta_audio_mode_pins[] = { 84static const unsigned short ams_delta_audio_mode_pins[] = {
85 AMS_DELTA_MIXED, 85 AMS_DELTA_MIXED,
86 AMS_DELTA_HANDSET, 86 AMS_DELTA_HANDSET,
87 AMS_DELTA_HANDSFREE, 87 AMS_DELTA_HANDSFREE,
diff --git a/sound/soc/omap/igep0020.c b/sound/soc/omap/igep0020.c
new file mode 100644
index 000000000000..3583c429f9be
--- /dev/null
+++ b/sound/soc/omap/igep0020.c
@@ -0,0 +1,148 @@
1/*
2 * igep0020.c -- SoC audio for IGEP v2
3 *
4 * Based on sound/soc/omap/overo.c by Steve Sakoman
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/clk.h>
23#include <linux/platform_device.h>
24#include <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28
29#include <asm/mach-types.h>
30#include <mach/hardware.h>
31#include <mach/gpio.h>
32#include <plat/mcbsp.h>
33
34#include "omap-mcbsp.h"
35#include "omap-pcm.h"
36#include "../codecs/twl4030.h"
37
38static int igep2_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
40{
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
42 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
44 int ret;
45
46 /* Set codec DAI configuration */
47 ret = snd_soc_dai_set_fmt(codec_dai,
48 SND_SOC_DAIFMT_I2S |
49 SND_SOC_DAIFMT_NB_NF |
50 SND_SOC_DAIFMT_CBM_CFM);
51 if (ret < 0) {
52 printk(KERN_ERR "can't set codec DAI configuration\n");
53 return ret;
54 }
55
56 /* Set cpu DAI configuration */
57 ret = snd_soc_dai_set_fmt(cpu_dai,
58 SND_SOC_DAIFMT_I2S |
59 SND_SOC_DAIFMT_NB_NF |
60 SND_SOC_DAIFMT_CBM_CFM);
61 if (ret < 0) {
62 printk(KERN_ERR "can't set cpu DAI configuration\n");
63 return ret;
64 }
65
66 /* Set the codec system clock for DAC and ADC */
67 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
68 SND_SOC_CLOCK_IN);
69 if (ret < 0) {
70 printk(KERN_ERR "can't set codec system clock\n");
71 return ret;
72 }
73
74 return 0;
75}
76
77static struct snd_soc_ops igep2_ops = {
78 .hw_params = igep2_hw_params,
79};
80
81/* Digital audio interface glue - connects codec <--> CPU */
82static struct snd_soc_dai_link igep2_dai = {
83 .name = "TWL4030",
84 .stream_name = "TWL4030",
85 .cpu_dai = &omap_mcbsp_dai[0],
86 .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
87 .ops = &igep2_ops,
88};
89
90/* Audio machine driver */
91static struct snd_soc_card snd_soc_card_igep2 = {
92 .name = "igep2",
93 .platform = &omap_soc_platform,
94 .dai_link = &igep2_dai,
95 .num_links = 1,
96};
97
98/* Audio subsystem */
99static struct snd_soc_device igep2_snd_devdata = {
100 .card = &snd_soc_card_igep2,
101 .codec_dev = &soc_codec_dev_twl4030,
102};
103
104static struct platform_device *igep2_snd_device;
105
106static int __init igep2_soc_init(void)
107{
108 int ret;
109
110 if (!machine_is_igep0020()) {
111 pr_debug("Not IGEP v2!\n");
112 return -ENODEV;
113 }
114 printk(KERN_INFO "IGEP v2 SoC init\n");
115
116 igep2_snd_device = platform_device_alloc("soc-audio", -1);
117 if (!igep2_snd_device) {
118 printk(KERN_ERR "Platform device allocation failed\n");
119 return -ENOMEM;
120 }
121
122 platform_set_drvdata(igep2_snd_device, &igep2_snd_devdata);
123 igep2_snd_devdata.dev = &igep2_snd_device->dev;
124 *(unsigned int *)igep2_dai.cpu_dai->private_data = 1; /* McBSP2 */
125
126 ret = platform_device_add(igep2_snd_device);
127 if (ret)
128 goto err1;
129
130 return 0;
131
132err1:
133 printk(KERN_ERR "Unable to add platform device\n");
134 platform_device_put(igep2_snd_device);
135
136 return ret;
137}
138module_init(igep2_soc_init);
139
140static void __exit igep2_soc_exit(void)
141{
142 platform_device_unregister(igep2_snd_device);
143}
144module_exit(igep2_soc_exit);
145
146MODULE_AUTHOR("Enric Balletbo i Serra <eballetbo@iseebcn.com>");
147MODULE_DESCRIPTION("ALSA SoC IGEP v2");
148MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
index 0a505938e42b..08e09d72790f 100644
--- a/sound/soc/omap/n810.c
+++ b/sound/soc/omap/n810.c
@@ -32,7 +32,7 @@
32#include <asm/mach-types.h> 32#include <asm/mach-types.h>
33#include <mach/hardware.h> 33#include <mach/hardware.h>
34#include <linux/gpio.h> 34#include <linux/gpio.h>
35#include <mach/mcbsp.h> 35#include <plat/mcbsp.h>
36 36
37#include "omap-mcbsp.h" 37#include "omap-mcbsp.h"
38#include "omap-pcm.h" 38#include "omap-pcm.h"
diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c
index 3341f49402ca..6bbbd2ab0ee7 100644
--- a/sound/soc/omap/omap-mcbsp.c
+++ b/sound/soc/omap/omap-mcbsp.c
@@ -31,9 +31,9 @@
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include <sound/soc.h> 32#include <sound/soc.h>
33 33
34#include <mach/control.h> 34#include <plat/control.h>
35#include <mach/dma.h> 35#include <plat/dma.h>
36#include <mach/mcbsp.h> 36#include <plat/mcbsp.h>
37#include "omap-mcbsp.h" 37#include "omap-mcbsp.h"
38#include "omap-pcm.h" 38#include "omap-pcm.h"
39 39
@@ -49,6 +49,8 @@ struct omap_mcbsp_data {
49 */ 49 */
50 int active; 50 int active;
51 int configured; 51 int configured;
52 unsigned int in_freq;
53 int clk_div;
52}; 54};
53 55
54#define to_mcbsp(priv) container_of((priv), struct omap_mcbsp_data, bus_id) 56#define to_mcbsp(priv) container_of((priv), struct omap_mcbsp_data, bus_id)
@@ -257,7 +259,7 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
257 int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id; 259 int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id;
258 int wlen, channels, wpf, sync_mode = OMAP_DMA_SYNC_ELEMENT; 260 int wlen, channels, wpf, sync_mode = OMAP_DMA_SYNC_ELEMENT;
259 unsigned long port; 261 unsigned long port;
260 unsigned int format; 262 unsigned int format, div, framesize, master;
261 263
262 if (cpu_class_is_omap1()) { 264 if (cpu_class_is_omap1()) {
263 dma = omap1_dma_reqs[bus_id][substream->stream]; 265 dma = omap1_dma_reqs[bus_id][substream->stream];
@@ -294,28 +296,19 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
294 296
295 format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK; 297 format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK;
296 wpf = channels = params_channels(params); 298 wpf = channels = params_channels(params);
297 switch (channels) { 299 if (channels == 2 && format == SND_SOC_DAIFMT_I2S) {
298 case 2: 300 /* Use dual-phase frames */
299 if (format == SND_SOC_DAIFMT_I2S) { 301 regs->rcr2 |= RPHASE;
300 /* Use dual-phase frames */ 302 regs->xcr2 |= XPHASE;
301 regs->rcr2 |= RPHASE; 303 /* Set 1 word per (McBSP) frame for phase1 and phase2 */
302 regs->xcr2 |= XPHASE; 304 wpf--;
303 /* Set 1 word per (McBSP) frame for phase1 and phase2 */ 305 regs->rcr2 |= RFRLEN2(wpf - 1);
304 wpf--; 306 regs->xcr2 |= XFRLEN2(wpf - 1);
305 regs->rcr2 |= RFRLEN2(wpf - 1);
306 regs->xcr2 |= XFRLEN2(wpf - 1);
307 }
308 case 1:
309 case 4:
310 /* Set word per (McBSP) frame for phase1 */
311 regs->rcr1 |= RFRLEN1(wpf - 1);
312 regs->xcr1 |= XFRLEN1(wpf - 1);
313 break;
314 default:
315 /* Unsupported number of channels */
316 return -EINVAL;
317 } 307 }
318 308
309 regs->rcr1 |= RFRLEN1(wpf - 1);
310 regs->xcr1 |= XFRLEN1(wpf - 1);
311
319 switch (params_format(params)) { 312 switch (params_format(params)) {
320 case SNDRV_PCM_FORMAT_S16_LE: 313 case SNDRV_PCM_FORMAT_S16_LE:
321 /* Set word lengths */ 314 /* Set word lengths */
@@ -330,15 +323,30 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
330 return -EINVAL; 323 return -EINVAL;
331 } 324 }
332 325
326 /* In McBSP master modes, FRAME (i.e. sample rate) is generated
327 * by _counting_ BCLKs. Calculate frame size in BCLKs */
328 master = mcbsp_data->fmt & SND_SOC_DAIFMT_MASTER_MASK;
329 if (master == SND_SOC_DAIFMT_CBS_CFS) {
330 div = mcbsp_data->clk_div ? mcbsp_data->clk_div : 1;
331 framesize = (mcbsp_data->in_freq / div) / params_rate(params);
332
333 if (framesize < wlen * channels) {
334 printk(KERN_ERR "%s: not enough bandwidth for desired rate and "
335 "channels\n", __func__);
336 return -EINVAL;
337 }
338 } else
339 framesize = wlen * channels;
340
333 /* Set FS period and length in terms of bit clock periods */ 341 /* Set FS period and length in terms of bit clock periods */
334 switch (format) { 342 switch (format) {
335 case SND_SOC_DAIFMT_I2S: 343 case SND_SOC_DAIFMT_I2S:
336 regs->srgr2 |= FPER(wlen * channels - 1); 344 regs->srgr2 |= FPER(framesize - 1);
337 regs->srgr1 |= FWID(wlen - 1); 345 regs->srgr1 |= FWID((framesize >> 1) - 1);
338 break; 346 break;
339 case SND_SOC_DAIFMT_DSP_A: 347 case SND_SOC_DAIFMT_DSP_A:
340 case SND_SOC_DAIFMT_DSP_B: 348 case SND_SOC_DAIFMT_DSP_B:
341 regs->srgr2 |= FPER(wlen * channels - 1); 349 regs->srgr2 |= FPER(framesize - 1);
342 regs->srgr1 |= FWID(0); 350 regs->srgr1 |= FWID(0);
343 break; 351 break;
344 } 352 }
@@ -454,6 +462,7 @@ static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
454 if (div_id != OMAP_MCBSP_CLKGDV) 462 if (div_id != OMAP_MCBSP_CLKGDV)
455 return -ENODEV; 463 return -ENODEV;
456 464
465 mcbsp_data->clk_div = div;
457 regs->srgr1 |= CLKGDV(div - 1); 466 regs->srgr1 |= CLKGDV(div - 1);
458 467
459 return 0; 468 return 0;
@@ -554,6 +563,8 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
554 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs; 563 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
555 int err = 0; 564 int err = 0;
556 565
566 mcbsp_data->in_freq = freq;
567
557 switch (clk_id) { 568 switch (clk_id) {
558 case OMAP_MCBSP_SYSCLK_CLK: 569 case OMAP_MCBSP_SYSCLK_CLK:
559 regs->srgr2 |= CLKSM; 570 regs->srgr2 |= CLKSM;
@@ -598,13 +609,13 @@ static struct snd_soc_dai_ops omap_mcbsp_dai_ops = {
598 .id = (link_id), \ 609 .id = (link_id), \
599 .playback = { \ 610 .playback = { \
600 .channels_min = 1, \ 611 .channels_min = 1, \
601 .channels_max = 4, \ 612 .channels_max = 16, \
602 .rates = OMAP_MCBSP_RATES, \ 613 .rates = OMAP_MCBSP_RATES, \
603 .formats = SNDRV_PCM_FMTBIT_S16_LE, \ 614 .formats = SNDRV_PCM_FMTBIT_S16_LE, \
604 }, \ 615 }, \
605 .capture = { \ 616 .capture = { \
606 .channels_min = 1, \ 617 .channels_min = 1, \
607 .channels_max = 4, \ 618 .channels_max = 16, \
608 .rates = OMAP_MCBSP_RATES, \ 619 .rates = OMAP_MCBSP_RATES, \
609 .formats = SNDRV_PCM_FMTBIT_S16_LE, \ 620 .formats = SNDRV_PCM_FMTBIT_S16_LE, \
610 }, \ 621 }, \
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c
index 6a829eef2a4f..9db2770e9640 100644
--- a/sound/soc/omap/omap-pcm.c
+++ b/sound/soc/omap/omap-pcm.c
@@ -28,7 +28,7 @@
28#include <sound/pcm_params.h> 28#include <sound/pcm_params.h>
29#include <sound/soc.h> 29#include <sound/soc.h>
30 30
31#include <mach/dma.h> 31#include <plat/dma.h>
32#include "omap-pcm.h" 32#include "omap-pcm.h"
33 33
34static const struct snd_pcm_hardware omap_pcm_hardware = { 34static const struct snd_pcm_hardware omap_pcm_hardware = {
diff --git a/sound/soc/omap/omap2evm.c b/sound/soc/omap/omap2evm.c
index 027e1a40f8a1..c7adea38274c 100644
--- a/sound/soc/omap/omap2evm.c
+++ b/sound/soc/omap/omap2evm.c
@@ -31,7 +31,7 @@
31#include <asm/mach-types.h> 31#include <asm/mach-types.h>
32#include <mach/hardware.h> 32#include <mach/hardware.h>
33#include <mach/gpio.h> 33#include <mach/gpio.h>
34#include <mach/mcbsp.h> 34#include <plat/mcbsp.h>
35 35
36#include "omap-mcbsp.h" 36#include "omap-mcbsp.h"
37#include "omap-pcm.h" 37#include "omap-pcm.h"
diff --git a/sound/soc/omap/omap3beagle.c b/sound/soc/omap/omap3beagle.c
index b0cff9f33b7e..d88ad5ca526c 100644
--- a/sound/soc/omap/omap3beagle.c
+++ b/sound/soc/omap/omap3beagle.c
@@ -29,7 +29,7 @@
29#include <asm/mach-types.h> 29#include <asm/mach-types.h>
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31#include <mach/gpio.h> 31#include <mach/gpio.h>
32#include <mach/mcbsp.h> 32#include <plat/mcbsp.h>
33 33
34#include "omap-mcbsp.h" 34#include "omap-mcbsp.h"
35#include "omap-pcm.h" 35#include "omap-pcm.h"
diff --git a/sound/soc/omap/omap3evm.c b/sound/soc/omap/omap3evm.c
index 13aa380de162..dfcb344092e4 100644
--- a/sound/soc/omap/omap3evm.c
+++ b/sound/soc/omap/omap3evm.c
@@ -27,7 +27,7 @@
27#include <asm/mach-types.h> 27#include <asm/mach-types.h>
28#include <mach/hardware.h> 28#include <mach/hardware.h>
29#include <mach/gpio.h> 29#include <mach/gpio.h>
30#include <mach/mcbsp.h> 30#include <plat/mcbsp.h>
31 31
32#include "omap-mcbsp.h" 32#include "omap-mcbsp.h"
33#include "omap-pcm.h" 33#include "omap-pcm.h"
@@ -93,10 +93,17 @@ static struct snd_soc_card snd_soc_omap3evm = {
93 .num_links = 1, 93 .num_links = 1,
94}; 94};
95 95
96/* twl4030 setup */
97static struct twl4030_setup_data twl4030_setup = {
98 .ramp_delay_value = 4,
99 .sysclk = 26000,
100};
101
96/* Audio subsystem */ 102/* Audio subsystem */
97static struct snd_soc_device omap3evm_snd_devdata = { 103static struct snd_soc_device omap3evm_snd_devdata = {
98 .card = &snd_soc_omap3evm, 104 .card = &snd_soc_omap3evm,
99 .codec_dev = &soc_codec_dev_twl4030, 105 .codec_dev = &soc_codec_dev_twl4030,
106 .codec_data = &twl4030_setup,
100}; 107};
101 108
102static struct platform_device *omap3evm_snd_device; 109static struct platform_device *omap3evm_snd_device;
diff --git a/sound/soc/omap/omap3pandora.c b/sound/soc/omap/omap3pandora.c
index 0cd06f5dd356..71b2c161158d 100644
--- a/sound/soc/omap/omap3pandora.c
+++ b/sound/soc/omap/omap3pandora.c
@@ -40,9 +40,12 @@
40 40
41#define PREFIX "ASoC omap3pandora: " 41#define PREFIX "ASoC omap3pandora: "
42 42
43static int omap3pandora_cmn_hw_params(struct snd_soc_dai *codec_dai, 43static int omap3pandora_cmn_hw_params(struct snd_pcm_substream *substream,
44 struct snd_soc_dai *cpu_dai, unsigned int fmt) 44 struct snd_pcm_hw_params *params, unsigned int fmt)
45{ 45{
46 struct snd_soc_pcm_runtime *rtd = substream->private_data;
47 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
48 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
46 int ret; 49 int ret;
47 50
48 /* Set codec DAI configuration */ 51 /* Set codec DAI configuration */
@@ -68,8 +71,9 @@ static int omap3pandora_cmn_hw_params(struct snd_soc_dai *codec_dai,
68 } 71 }
69 72
70 /* Set McBSP clock to external */ 73 /* Set McBSP clock to external */
71 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_EXT, 0, 74 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_EXT,
72 SND_SOC_CLOCK_IN); 75 256 * params_rate(params),
76 SND_SOC_CLOCK_IN);
73 if (ret < 0) { 77 if (ret < 0) {
74 pr_err(PREFIX "can't set cpu system clock\n"); 78 pr_err(PREFIX "can't set cpu system clock\n");
75 return ret; 79 return ret;
@@ -87,11 +91,7 @@ static int omap3pandora_cmn_hw_params(struct snd_soc_dai *codec_dai,
87static int omap3pandora_out_hw_params(struct snd_pcm_substream *substream, 91static int omap3pandora_out_hw_params(struct snd_pcm_substream *substream,
88 struct snd_pcm_hw_params *params) 92 struct snd_pcm_hw_params *params)
89{ 93{
90 struct snd_soc_pcm_runtime *rtd = substream->private_data; 94 return omap3pandora_cmn_hw_params(substream, params,
91 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
92 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
93
94 return omap3pandora_cmn_hw_params(codec_dai, cpu_dai,
95 SND_SOC_DAIFMT_I2S | 95 SND_SOC_DAIFMT_I2S |
96 SND_SOC_DAIFMT_IB_NF | 96 SND_SOC_DAIFMT_IB_NF |
97 SND_SOC_DAIFMT_CBS_CFS); 97 SND_SOC_DAIFMT_CBS_CFS);
@@ -100,11 +100,7 @@ static int omap3pandora_out_hw_params(struct snd_pcm_substream *substream,
100static int omap3pandora_in_hw_params(struct snd_pcm_substream *substream, 100static int omap3pandora_in_hw_params(struct snd_pcm_substream *substream,
101 struct snd_pcm_hw_params *params) 101 struct snd_pcm_hw_params *params)
102{ 102{
103 struct snd_soc_pcm_runtime *rtd = substream->private_data; 103 return omap3pandora_cmn_hw_params(substream, params,
104 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
105 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
106
107 return omap3pandora_cmn_hw_params(codec_dai, cpu_dai,
108 SND_SOC_DAIFMT_I2S | 104 SND_SOC_DAIFMT_I2S |
109 SND_SOC_DAIFMT_NB_NF | 105 SND_SOC_DAIFMT_NB_NF |
110 SND_SOC_DAIFMT_CBS_CFS); 106 SND_SOC_DAIFMT_CBS_CFS);
diff --git a/sound/soc/omap/osk5912.c b/sound/soc/omap/osk5912.c
index a4e149b7f0eb..498ca2e03519 100644
--- a/sound/soc/omap/osk5912.c
+++ b/sound/soc/omap/osk5912.c
@@ -31,7 +31,7 @@
31#include <asm/mach-types.h> 31#include <asm/mach-types.h>
32#include <mach/hardware.h> 32#include <mach/hardware.h>
33#include <linux/gpio.h> 33#include <linux/gpio.h>
34#include <mach/mcbsp.h> 34#include <plat/mcbsp.h>
35 35
36#include "omap-mcbsp.h" 36#include "omap-mcbsp.h"
37#include "omap-pcm.h" 37#include "omap-pcm.h"
diff --git a/sound/soc/omap/overo.c b/sound/soc/omap/overo.c
index ec4f8fd8b3a2..c25f5276ad6f 100644
--- a/sound/soc/omap/overo.c
+++ b/sound/soc/omap/overo.c
@@ -29,7 +29,7 @@
29#include <asm/mach-types.h> 29#include <asm/mach-types.h>
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31#include <mach/gpio.h> 31#include <mach/gpio.h>
32#include <mach/mcbsp.h> 32#include <plat/mcbsp.h>
33 33
34#include "omap-mcbsp.h" 34#include "omap-mcbsp.h"
35#include "omap-pcm.h" 35#include "omap-pcm.h"
@@ -107,8 +107,8 @@ static int __init overo_soc_init(void)
107{ 107{
108 int ret; 108 int ret;
109 109
110 if (!machine_is_overo()) { 110 if (!(machine_is_overo() || machine_is_cm_t35())) {
111 pr_debug("Not Overo!\n"); 111 pr_debug("Incomatible machine!\n");
112 return -ENODEV; 112 return -ENODEV;
113 } 113 }
114 printk(KERN_INFO "overo SoC init\n"); 114 printk(KERN_INFO "overo SoC init\n");
diff --git a/sound/soc/omap/sdp3430.c b/sound/soc/omap/sdp3430.c
index 4a3f62d1f295..c071f9603a38 100644
--- a/sound/soc/omap/sdp3430.c
+++ b/sound/soc/omap/sdp3430.c
@@ -34,7 +34,7 @@
34#include <asm/mach-types.h> 34#include <asm/mach-types.h>
35#include <mach/hardware.h> 35#include <mach/hardware.h>
36#include <mach/gpio.h> 36#include <mach/gpio.h>
37#include <mach/mcbsp.h> 37#include <plat/mcbsp.h>
38 38
39#include "omap-mcbsp.h" 39#include "omap-mcbsp.h"
40#include "omap-pcm.h" 40#include "omap-pcm.h"
diff --git a/sound/soc/omap/zoom2.c b/sound/soc/omap/zoom2.c
index f90b45f56220..f90a2ac888cf 100644
--- a/sound/soc/omap/zoom2.c
+++ b/sound/soc/omap/zoom2.c
@@ -29,7 +29,7 @@
29#include <asm/mach-types.h> 29#include <asm/mach-types.h>
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31#include <mach/gpio.h> 31#include <mach/gpio.h>
32#include <mach/mcbsp.h> 32#include <plat/mcbsp.h>
33 33
34#include "omap-mcbsp.h" 34#include "omap-mcbsp.h"
35#include "omap-pcm.h" 35#include "omap-pcm.h"
diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig
index dcb3181bb340..376e14a9c273 100644
--- a/sound/soc/pxa/Kconfig
+++ b/sound/soc/pxa/Kconfig
@@ -90,7 +90,8 @@ config SND_PXA2XX_SOC_E800
90 90
91config SND_PXA2XX_SOC_EM_X270 91config SND_PXA2XX_SOC_EM_X270
92 tristate "SoC Audio support for CompuLab EM-x270, eXeda and CM-X300" 92 tristate "SoC Audio support for CompuLab EM-x270, eXeda and CM-X300"
93 depends on SND_PXA2XX_SOC && MACH_EM_X270 93 depends on SND_PXA2XX_SOC && (MACH_EM_X270 || MACH_EXEDA || \
94 MACH_CM_X300)
94 select SND_PXA2XX_SOC_AC97 95 select SND_PXA2XX_SOC_AC97
95 select SND_SOC_WM9712 96 select SND_SOC_WM9712
96 help 97 help
@@ -117,6 +118,15 @@ config SND_SOC_ZYLONITE
117 Say Y if you want to add support for SoC audio on the 118 Say Y if you want to add support for SoC audio on the
118 Marvell Zylonite reference platform. 119 Marvell Zylonite reference platform.
119 120
121config SND_SOC_RAUMFELD
122 tristate "SoC Audio support Raumfeld audio adapter"
123 depends on SND_PXA2XX_SOC && (MACH_RAUMFELD_SPEAKER || MACH_RAUMFELD_CONNECTOR)
124 select SND_PXA_SOC_SSP
125 select SND_SOC_CS4270
126 select SND_SOC_AK4104
127 help
128 Say Y if you want to add support for SoC audio on Raumfeld devices
129
120config SND_PXA2XX_SOC_MAGICIAN 130config SND_PXA2XX_SOC_MAGICIAN
121 tristate "SoC Audio support for HTC Magician" 131 tristate "SoC Audio support for HTC Magician"
122 depends on SND_PXA2XX_SOC && MACH_MAGICIAN 132 depends on SND_PXA2XX_SOC && MACH_MAGICIAN
diff --git a/sound/soc/pxa/Makefile b/sound/soc/pxa/Makefile
index 6e096b480335..f3e08fd40ca2 100644
--- a/sound/soc/pxa/Makefile
+++ b/sound/soc/pxa/Makefile
@@ -23,6 +23,7 @@ snd-soc-zylonite-objs := zylonite.o
23snd-soc-magician-objs := magician.o 23snd-soc-magician-objs := magician.o
24snd-soc-mioa701-objs := mioa701_wm9713.o 24snd-soc-mioa701-objs := mioa701_wm9713.o
25snd-soc-imote2-objs := imote2.o 25snd-soc-imote2-objs := imote2.o
26snd-soc-raumfeld-objs := raumfeld.o
26 27
27obj-$(CONFIG_SND_PXA2XX_SOC_CORGI) += snd-soc-corgi.o 28obj-$(CONFIG_SND_PXA2XX_SOC_CORGI) += snd-soc-corgi.o
28obj-$(CONFIG_SND_PXA2XX_SOC_POODLE) += snd-soc-poodle.o 29obj-$(CONFIG_SND_PXA2XX_SOC_POODLE) += snd-soc-poodle.o
@@ -37,3 +38,4 @@ obj-$(CONFIG_SND_PXA2XX_SOC_MAGICIAN) += snd-soc-magician.o
37obj-$(CONFIG_SND_PXA2XX_SOC_MIOA701) += snd-soc-mioa701.o 38obj-$(CONFIG_SND_PXA2XX_SOC_MIOA701) += snd-soc-mioa701.o
38obj-$(CONFIG_SND_SOC_ZYLONITE) += snd-soc-zylonite.o 39obj-$(CONFIG_SND_SOC_ZYLONITE) += snd-soc-zylonite.o
39obj-$(CONFIG_SND_PXA2XX_SOC_IMOTE2) += snd-soc-imote2.o 40obj-$(CONFIG_SND_PXA2XX_SOC_IMOTE2) += snd-soc-imote2.o
41obj-$(CONFIG_SND_SOC_RAUMFELD) += snd-soc-raumfeld.o
diff --git a/sound/soc/pxa/magician.c b/sound/soc/pxa/magician.c
index 9f7c61e23daf..4c8d99a8d386 100644
--- a/sound/soc/pxa/magician.c
+++ b/sound/soc/pxa/magician.c
@@ -213,7 +213,7 @@ static int magician_playback_hw_params(struct snd_pcm_substream *substream,
213 return ret; 213 return ret;
214 214
215 /* set SSP audio pll clock */ 215 /* set SSP audio pll clock */
216 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, acps); 216 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, acps);
217 if (ret < 0) 217 if (ret < 0)
218 return ret; 218 return ret;
219 219
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c
index d11a6d7e384a..3bd7712f029b 100644
--- a/sound/soc/pxa/pxa-ssp.c
+++ b/sound/soc/pxa/pxa-ssp.c
@@ -305,8 +305,8 @@ static int pxa_ssp_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
305/* 305/*
306 * Configure the PLL frequency pxa27x and (afaik - pxa320 only) 306 * Configure the PLL frequency pxa27x and (afaik - pxa320 only)
307 */ 307 */
308static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, 308static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
309 int pll_id, unsigned int freq_in, unsigned int freq_out) 309 int source, unsigned int freq_in, unsigned int freq_out)
310{ 310{
311 struct ssp_priv *priv = cpu_dai->private_data; 311 struct ssp_priv *priv = cpu_dai->private_data;
312 struct ssp_device *ssp = priv->dev.ssp; 312 struct ssp_device *ssp = priv->dev.ssp;
@@ -760,13 +760,13 @@ struct snd_soc_dai pxa_ssp_dai[] = {
760 .resume = pxa_ssp_resume, 760 .resume = pxa_ssp_resume,
761 .playback = { 761 .playback = {
762 .channels_min = 1, 762 .channels_min = 1,
763 .channels_max = 2, 763 .channels_max = 8,
764 .rates = PXA_SSP_RATES, 764 .rates = PXA_SSP_RATES,
765 .formats = PXA_SSP_FORMATS, 765 .formats = PXA_SSP_FORMATS,
766 }, 766 },
767 .capture = { 767 .capture = {
768 .channels_min = 1, 768 .channels_min = 1,
769 .channels_max = 2, 769 .channels_max = 8,
770 .rates = PXA_SSP_RATES, 770 .rates = PXA_SSP_RATES,
771 .formats = PXA_SSP_FORMATS, 771 .formats = PXA_SSP_FORMATS,
772 }, 772 },
@@ -780,13 +780,13 @@ struct snd_soc_dai pxa_ssp_dai[] = {
780 .resume = pxa_ssp_resume, 780 .resume = pxa_ssp_resume,
781 .playback = { 781 .playback = {
782 .channels_min = 1, 782 .channels_min = 1,
783 .channels_max = 2, 783 .channels_max = 8,
784 .rates = PXA_SSP_RATES, 784 .rates = PXA_SSP_RATES,
785 .formats = PXA_SSP_FORMATS, 785 .formats = PXA_SSP_FORMATS,
786 }, 786 },
787 .capture = { 787 .capture = {
788 .channels_min = 1, 788 .channels_min = 1,
789 .channels_max = 2, 789 .channels_max = 8,
790 .rates = PXA_SSP_RATES, 790 .rates = PXA_SSP_RATES,
791 .formats = PXA_SSP_FORMATS, 791 .formats = PXA_SSP_FORMATS,
792 }, 792 },
@@ -801,13 +801,13 @@ struct snd_soc_dai pxa_ssp_dai[] = {
801 .resume = pxa_ssp_resume, 801 .resume = pxa_ssp_resume,
802 .playback = { 802 .playback = {
803 .channels_min = 1, 803 .channels_min = 1,
804 .channels_max = 2, 804 .channels_max = 8,
805 .rates = PXA_SSP_RATES, 805 .rates = PXA_SSP_RATES,
806 .formats = PXA_SSP_FORMATS, 806 .formats = PXA_SSP_FORMATS,
807 }, 807 },
808 .capture = { 808 .capture = {
809 .channels_min = 1, 809 .channels_min = 1,
810 .channels_max = 2, 810 .channels_max = 8,
811 .rates = PXA_SSP_RATES, 811 .rates = PXA_SSP_RATES,
812 .formats = PXA_SSP_FORMATS, 812 .formats = PXA_SSP_FORMATS,
813 }, 813 },
@@ -822,13 +822,13 @@ struct snd_soc_dai pxa_ssp_dai[] = {
822 .resume = pxa_ssp_resume, 822 .resume = pxa_ssp_resume,
823 .playback = { 823 .playback = {
824 .channels_min = 1, 824 .channels_min = 1,
825 .channels_max = 2, 825 .channels_max = 8,
826 .rates = PXA_SSP_RATES, 826 .rates = PXA_SSP_RATES,
827 .formats = PXA_SSP_FORMATS, 827 .formats = PXA_SSP_FORMATS,
828 }, 828 },
829 .capture = { 829 .capture = {
830 .channels_min = 1, 830 .channels_min = 1,
831 .channels_max = 2, 831 .channels_max = 8,
832 .rates = PXA_SSP_RATES, 832 .rates = PXA_SSP_RATES,
833 .formats = PXA_SSP_FORMATS, 833 .formats = PXA_SSP_FORMATS,
834 }, 834 },
diff --git a/sound/soc/pxa/raumfeld.c b/sound/soc/pxa/raumfeld.c
new file mode 100644
index 000000000000..acfce1c0f1c9
--- /dev/null
+++ b/sound/soc/pxa/raumfeld.c
@@ -0,0 +1,335 @@
1/*
2 * raumfeld_audio.c -- SoC audio for Raumfeld audio devices
3 *
4 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
5 *
6 * based on code from:
7 *
8 * Wolfson Microelectronics PLC.
9 * Openedhand Ltd.
10 * Liam Girdwood <lrg@slimlogic.co.uk>
11 * Richard Purdie <richard@openedhand.com>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18
19#include <linux/module.h>
20#include <linux/i2c.h>
21#include <linux/delay.h>
22#include <linux/gpio.h>
23#include <sound/pcm.h>
24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26
27#include <asm/mach-types.h>
28
29#include "../codecs/cs4270.h"
30#include "../codecs/ak4104.h"
31#include "pxa2xx-pcm.h"
32#include "pxa-ssp.h"
33
34#define GPIO_SPDIF_RESET (38)
35#define GPIO_MCLK_RESET (111)
36#define GPIO_CODEC_RESET (120)
37
38static struct i2c_client *max9486_client;
39static struct i2c_board_info max9486_hwmon_info = {
40 I2C_BOARD_INFO("max9485", 0x63),
41};
42
43#define MAX9485_MCLK_FREQ_112896 0x22
44#define MAX9485_MCLK_FREQ_122880 0x23
45
46static void set_max9485_clk(char clk)
47{
48 i2c_master_send(max9486_client, &clk, 1);
49}
50
51static void raumfeld_enable_audio(bool en)
52{
53 if (en) {
54 gpio_set_value(GPIO_MCLK_RESET, 1);
55
56 /* wait some time to let the clocks become stable */
57 msleep(100);
58
59 gpio_set_value(GPIO_SPDIF_RESET, 1);
60 gpio_set_value(GPIO_CODEC_RESET, 1);
61 } else {
62 gpio_set_value(GPIO_MCLK_RESET, 0);
63 gpio_set_value(GPIO_SPDIF_RESET, 0);
64 gpio_set_value(GPIO_CODEC_RESET, 0);
65 }
66}
67
68/* CS4270 */
69static int raumfeld_cs4270_startup(struct snd_pcm_substream *substream)
70{
71 struct snd_soc_pcm_runtime *rtd = substream->private_data;
72 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
73
74 set_max9485_clk(MAX9485_MCLK_FREQ_112896);
75
76 return snd_soc_dai_set_sysclk(codec_dai, 0, 11289600, 0);
77}
78
79static int raumfeld_cs4270_hw_params(struct snd_pcm_substream *substream,
80 struct snd_pcm_hw_params *params)
81{
82 struct snd_soc_pcm_runtime *rtd = substream->private_data;
83 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
84 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
85 unsigned int fmt, clk = 0;
86 int ret = 0;
87
88 switch (params_rate(params)) {
89 case 8000:
90 case 16000:
91 case 48000:
92 case 96000:
93 set_max9485_clk(MAX9485_MCLK_FREQ_122880);
94 clk = 12288000;
95 break;
96 case 11025:
97 case 22050:
98 case 44100:
99 case 88200:
100 set_max9485_clk(MAX9485_MCLK_FREQ_112896);
101 clk = 11289600;
102 break;
103 }
104
105 fmt = SND_SOC_DAIFMT_I2S |
106 SND_SOC_DAIFMT_NB_NF |
107 SND_SOC_DAIFMT_CBS_CFS;
108
109 /* setup the CODEC DAI */
110 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
111 if (ret < 0)
112 return ret;
113
114 ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk, 0);
115 if (ret < 0)
116 return ret;
117
118 /* setup the CPU DAI */
119 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, clk);
120 if (ret < 0)
121 return ret;
122
123 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
124 if (ret < 0)
125 return ret;
126
127 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_DIV_SCR, 4);
128 if (ret < 0)
129 return ret;
130
131 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_EXT, 0, 1);
132 if (ret < 0)
133 return ret;
134
135 return 0;
136}
137
138static struct snd_soc_ops raumfeld_cs4270_ops = {
139 .startup = raumfeld_cs4270_startup,
140 .hw_params = raumfeld_cs4270_hw_params,
141};
142
143static int raumfeld_line_suspend(struct platform_device *pdev, pm_message_t state)
144{
145 raumfeld_enable_audio(false);
146 return 0;
147}
148
149static int raumfeld_line_resume(struct platform_device *pdev)
150{
151 raumfeld_enable_audio(true);
152 return 0;
153}
154
155static struct snd_soc_dai_link raumfeld_line_dai = {
156 .name = "CS4270",
157 .stream_name = "CS4270",
158 .cpu_dai = &pxa_ssp_dai[PXA_DAI_SSP1],
159 .codec_dai = &cs4270_dai,
160 .ops = &raumfeld_cs4270_ops,
161};
162
163static struct snd_soc_card snd_soc_line_raumfeld = {
164 .name = "Raumfeld analog",
165 .platform = &pxa2xx_soc_platform,
166 .dai_link = &raumfeld_line_dai,
167 .suspend_post = raumfeld_line_suspend,
168 .resume_pre = raumfeld_line_resume,
169 .num_links = 1,
170};
171
172
173/* AK4104 */
174
175static int raumfeld_ak4104_hw_params(struct snd_pcm_substream *substream,
176 struct snd_pcm_hw_params *params)
177{
178 struct snd_soc_pcm_runtime *rtd = substream->private_data;
179 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
180 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
181 int fmt, ret = 0, clk = 0;
182
183 switch (params_rate(params)) {
184 case 8000:
185 case 16000:
186 case 48000:
187 case 96000:
188 set_max9485_clk(MAX9485_MCLK_FREQ_122880);
189 clk = 12288000;
190 break;
191 case 11025:
192 case 22050:
193 case 44100:
194 case 88200:
195 set_max9485_clk(MAX9485_MCLK_FREQ_112896);
196 clk = 11289600;
197 break;
198 }
199
200 fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF;
201
202 /* setup the CODEC DAI */
203 ret = snd_soc_dai_set_fmt(codec_dai, fmt | SND_SOC_DAIFMT_CBS_CFS);
204 if (ret < 0)
205 return ret;
206
207 /* setup the CPU DAI */
208 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, clk);
209 if (ret < 0)
210 return ret;
211
212 ret = snd_soc_dai_set_fmt(cpu_dai, fmt | SND_SOC_DAIFMT_CBS_CFS);
213 if (ret < 0)
214 return ret;
215
216 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_DIV_SCR, 4);
217 if (ret < 0)
218 return ret;
219
220 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_EXT, 0, 1);
221 if (ret < 0)
222 return ret;
223
224 return 0;
225}
226
227static struct snd_soc_ops raumfeld_ak4104_ops = {
228 .hw_params = raumfeld_ak4104_hw_params,
229};
230
231static struct snd_soc_dai_link raumfeld_spdif_dai = {
232 .name = "ak4104",
233 .stream_name = "Playback",
234 .cpu_dai = &pxa_ssp_dai[PXA_DAI_SSP2],
235 .codec_dai = &ak4104_dai,
236 .ops = &raumfeld_ak4104_ops,
237};
238
239static struct snd_soc_card snd_soc_spdif_raumfeld = {
240 .name = "Raumfeld S/PDIF",
241 .platform = &pxa2xx_soc_platform,
242 .dai_link = &raumfeld_spdif_dai,
243 .num_links = 1
244};
245
246/* raumfeld_audio audio subsystem */
247static struct snd_soc_device raumfeld_line_devdata = {
248 .card = &snd_soc_line_raumfeld,
249 .codec_dev = &soc_codec_device_cs4270,
250};
251
252static struct snd_soc_device raumfeld_spdif_devdata = {
253 .card = &snd_soc_spdif_raumfeld,
254 .codec_dev = &soc_codec_device_ak4104,
255};
256
257static struct platform_device *raumfeld_audio_line_device;
258static struct platform_device *raumfeld_audio_spdif_device;
259
260static int __init raumfeld_audio_init(void)
261{
262 int ret;
263
264 if (!machine_is_raumfeld_speaker() &&
265 !machine_is_raumfeld_connector())
266 return 0;
267
268 max9486_client = i2c_new_device(i2c_get_adapter(0),
269 &max9486_hwmon_info);
270
271 if (!max9486_client)
272 return -ENOMEM;
273
274 set_max9485_clk(MAX9485_MCLK_FREQ_122880);
275
276 /* LINE */
277 raumfeld_audio_line_device = platform_device_alloc("soc-audio", 0);
278 if (!raumfeld_audio_line_device)
279 return -ENOMEM;
280
281 platform_set_drvdata(raumfeld_audio_line_device,
282 &raumfeld_line_devdata);
283 raumfeld_line_devdata.dev = &raumfeld_audio_line_device->dev;
284 ret = platform_device_add(raumfeld_audio_line_device);
285 if (ret)
286 platform_device_put(raumfeld_audio_line_device);
287
288 /* no S/PDIF on Speakers */
289 if (machine_is_raumfeld_speaker())
290 return ret;
291
292 /* S/PDIF */
293 raumfeld_audio_spdif_device = platform_device_alloc("soc-audio", 1);
294 if (!raumfeld_audio_spdif_device) {
295 platform_device_put(raumfeld_audio_line_device);
296 return -ENOMEM;
297 }
298
299 platform_set_drvdata(raumfeld_audio_spdif_device,
300 &raumfeld_spdif_devdata);
301 raumfeld_spdif_devdata.dev = &raumfeld_audio_spdif_device->dev;
302 ret = platform_device_add(raumfeld_audio_spdif_device);
303 if (ret) {
304 platform_device_put(raumfeld_audio_line_device);
305 platform_device_put(raumfeld_audio_spdif_device);
306 }
307
308 raumfeld_enable_audio(true);
309
310 return ret;
311}
312
313static void __exit raumfeld_audio_exit(void)
314{
315 raumfeld_enable_audio(false);
316
317 platform_device_unregister(raumfeld_audio_line_device);
318
319 if (machine_is_raumfeld_connector())
320 platform_device_unregister(raumfeld_audio_spdif_device);
321
322 i2c_unregister_device(max9486_client);
323
324 gpio_free(GPIO_MCLK_RESET);
325 gpio_free(GPIO_CODEC_RESET);
326 gpio_free(GPIO_SPDIF_RESET);
327}
328
329module_init(raumfeld_audio_init);
330module_exit(raumfeld_audio_exit);
331
332/* Module information */
333MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
334MODULE_DESCRIPTION("Raumfeld audio SoC");
335MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/zylonite.c b/sound/soc/pxa/zylonite.c
index 9a386b4c4ed1..dd678ae24398 100644
--- a/sound/soc/pxa/zylonite.c
+++ b/sound/soc/pxa/zylonite.c
@@ -74,7 +74,8 @@ static const struct snd_soc_dapm_route audio_map[] = {
74static int zylonite_wm9713_init(struct snd_soc_codec *codec) 74static int zylonite_wm9713_init(struct snd_soc_codec *codec)
75{ 75{
76 if (clk_pout) 76 if (clk_pout)
77 snd_soc_dai_set_pll(&codec->dai[0], 0, clk_get_rate(pout), 0); 77 snd_soc_dai_set_pll(&codec->dai[0], 0, 0,
78 clk_get_rate(pout), 0);
78 79
79 snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets, 80 snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets,
80 ARRAY_SIZE(zylonite_dapm_widgets)); 81 ARRAY_SIZE(zylonite_dapm_widgets));
@@ -128,7 +129,7 @@ static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
128 if (ret < 0) 129 if (ret < 0)
129 return ret; 130 return ret;
130 131
131 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, pll_out); 132 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, pll_out);
132 if (ret < 0) 133 if (ret < 0)
133 return ret; 134 return ret;
134 135
diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig
index 923428fc1adb..b489f1ae103d 100644
--- a/sound/soc/s3c24xx/Kconfig
+++ b/sound/soc/s3c24xx/Kconfig
@@ -24,6 +24,9 @@ config SND_S3C64XX_SOC_I2S
24 select SND_S3C_I2SV2_SOC 24 select SND_S3C_I2SV2_SOC
25 select S3C64XX_DMA 25 select S3C64XX_DMA
26 26
27config SND_S3C_SOC_PCM
28 tristate
29
27config SND_S3C2443_SOC_AC97 30config SND_S3C2443_SOC_AC97
28 tristate 31 tristate
29 select S3C2410_DMA 32 select S3C2410_DMA
@@ -56,6 +59,15 @@ config SND_S3C24XX_SOC_JIVE_WM8750
56 help 59 help
57 Sat Y if you want to add support for SoC audio on the Jive. 60 Sat Y if you want to add support for SoC audio on the Jive.
58 61
62config SND_S3C64XX_SOC_WM8580
63 tristate "SoC I2S Audio support for WM8580 on SMDK64XX"
64 depends on SND_S3C24XX_SOC && (MACH_SMDK6400 || MACH_SMDK6410)
65 depends on BROKEN
66 select SND_SOC_WM8580
67 select SND_S3C64XX_SOC_I2S
68 help
69 Sat Y if you want to add support for SoC audio on the SMDK64XX.
70
59config SND_S3C24XX_SOC_SMDK2443_WM9710 71config SND_S3C24XX_SOC_SMDK2443_WM9710
60 tristate "SoC AC97 Audio support for SMDK2443 - WM9710" 72 tristate "SoC AC97 Audio support for SMDK2443 - WM9710"
61 depends on SND_S3C24XX_SOC && MACH_SMDK2443 73 depends on SND_S3C24XX_SOC && MACH_SMDK2443
diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile
index 99f5a7dd3fc6..b744657733d7 100644
--- a/sound/soc/s3c24xx/Makefile
+++ b/sound/soc/s3c24xx/Makefile
@@ -1,10 +1,11 @@
1# S3c24XX Platform Support 1# S3c24XX Platform Support
2snd-soc-s3c24xx-objs := s3c24xx-pcm.o 2snd-soc-s3c24xx-objs := s3c-dma.o
3snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o 3snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o
4snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o 4snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o
5snd-soc-s3c64xx-i2s-objs := s3c64xx-i2s.o 5snd-soc-s3c64xx-i2s-objs := s3c64xx-i2s.o
6snd-soc-s3c2443-ac97-objs := s3c2443-ac97.o 6snd-soc-s3c2443-ac97-objs := s3c2443-ac97.o
7snd-soc-s3c-i2s-v2-objs := s3c-i2s-v2.o 7snd-soc-s3c-i2s-v2-objs := s3c-i2s-v2.o
8snd-soc-s3c-pcm-objs := s3c-pcm.o
8 9
9obj-$(CONFIG_SND_S3C24XX_SOC) += snd-soc-s3c24xx.o 10obj-$(CONFIG_SND_S3C24XX_SOC) += snd-soc-s3c24xx.o
10obj-$(CONFIG_SND_S3C24XX_SOC_I2S) += snd-soc-s3c24xx-i2s.o 11obj-$(CONFIG_SND_S3C24XX_SOC_I2S) += snd-soc-s3c24xx-i2s.o
@@ -12,6 +13,7 @@ obj-$(CONFIG_SND_S3C2443_SOC_AC97) += snd-soc-s3c2443-ac97.o
12obj-$(CONFIG_SND_S3C2412_SOC_I2S) += snd-soc-s3c2412-i2s.o 13obj-$(CONFIG_SND_S3C2412_SOC_I2S) += snd-soc-s3c2412-i2s.o
13obj-$(CONFIG_SND_S3C64XX_SOC_I2S) += snd-soc-s3c64xx-i2s.o 14obj-$(CONFIG_SND_S3C64XX_SOC_I2S) += snd-soc-s3c64xx-i2s.o
14obj-$(CONFIG_SND_S3C_I2SV2_SOC) += snd-soc-s3c-i2s-v2.o 15obj-$(CONFIG_SND_S3C_I2SV2_SOC) += snd-soc-s3c-i2s-v2.o
16obj-$(CONFIG_SND_S3C_SOC_PCM) += snd-soc-s3c-pcm.o
15 17
16# S3C24XX Machine Support 18# S3C24XX Machine Support
17snd-soc-jive-wm8750-objs := jive_wm8750.o 19snd-soc-jive-wm8750-objs := jive_wm8750.o
@@ -23,6 +25,7 @@ snd-soc-s3c24xx-uda134x-objs := s3c24xx_uda134x.o
23snd-soc-s3c24xx-simtec-objs := s3c24xx_simtec.o 25snd-soc-s3c24xx-simtec-objs := s3c24xx_simtec.o
24snd-soc-s3c24xx-simtec-hermes-objs := s3c24xx_simtec_hermes.o 26snd-soc-s3c24xx-simtec-hermes-objs := s3c24xx_simtec_hermes.o
25snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o 27snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o
28snd-soc-smdk64xx-wm8580-objs := smdk64xx_wm8580.o
26 29
27obj-$(CONFIG_SND_S3C24XX_SOC_JIVE_WM8750) += snd-soc-jive-wm8750.o 30obj-$(CONFIG_SND_S3C24XX_SOC_JIVE_WM8750) += snd-soc-jive-wm8750.o
28obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o 31obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o
@@ -33,4 +36,5 @@ obj-$(CONFIG_SND_S3C24XX_SOC_S3C24XX_UDA134X) += snd-soc-s3c24xx-uda134x.o
33obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC) += snd-soc-s3c24xx-simtec.o 36obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC) += snd-soc-s3c24xx-simtec.o
34obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_HERMES) += snd-soc-s3c24xx-simtec-hermes.o 37obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_HERMES) += snd-soc-s3c24xx-simtec-hermes.o
35obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o 38obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o
39obj-$(CONFIG_SND_S3C64XX_SOC_WM8580) += snd-soc-smdk64xx-wm8580.o
36 40
diff --git a/sound/soc/s3c24xx/jive_wm8750.c b/sound/soc/s3c24xx/jive_wm8750.c
index 93e6c87b7399..59dc2c6b56d9 100644
--- a/sound/soc/s3c24xx/jive_wm8750.c
+++ b/sound/soc/s3c24xx/jive_wm8750.c
@@ -25,7 +25,7 @@
25 25
26#include <asm/mach-types.h> 26#include <asm/mach-types.h>
27 27
28#include "s3c24xx-pcm.h" 28#include "s3c-dma.h"
29#include "s3c2412-i2s.h" 29#include "s3c2412-i2s.h"
30 30
31#include "../codecs/wm8750.h" 31#include "../codecs/wm8750.h"
diff --git a/sound/soc/s3c24xx/ln2440sbc_alc650.c b/sound/soc/s3c24xx/ln2440sbc_alc650.c
index 12c71482d258..d00d359a03e6 100644
--- a/sound/soc/s3c24xx/ln2440sbc_alc650.c
+++ b/sound/soc/s3c24xx/ln2440sbc_alc650.c
@@ -24,7 +24,7 @@
24#include <sound/soc-dapm.h> 24#include <sound/soc-dapm.h>
25 25
26#include "../codecs/ac97.h" 26#include "../codecs/ac97.h"
27#include "s3c24xx-pcm.h" 27#include "s3c-dma.h"
28#include "s3c24xx-ac97.h" 28#include "s3c24xx-ac97.h"
29 29
30static struct snd_soc_card ln2440sbc; 30static struct snd_soc_card ln2440sbc;
diff --git a/sound/soc/s3c24xx/neo1973_gta02_wm8753.c b/sound/soc/s3c24xx/neo1973_gta02_wm8753.c
index 0c52e36ddd87..dea83d30a5c9 100644
--- a/sound/soc/s3c24xx/neo1973_gta02_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_gta02_wm8753.c
@@ -32,7 +32,7 @@
32#include <asm/io.h> 32#include <asm/io.h>
33#include <mach/gta02.h> 33#include <mach/gta02.h>
34#include "../codecs/wm8753.h" 34#include "../codecs/wm8753.h"
35#include "s3c24xx-pcm.h" 35#include "s3c-dma.h"
36#include "s3c24xx-i2s.h" 36#include "s3c24xx-i2s.h"
37 37
38static struct snd_soc_card neo1973_gta02; 38static struct snd_soc_card neo1973_gta02;
@@ -119,7 +119,7 @@ static int neo1973_gta02_hifi_hw_params(struct snd_pcm_substream *substream,
119 return ret; 119 return ret;
120 120
121 /* codec PLL input is PCLK/4 */ 121 /* codec PLL input is PCLK/4 */
122 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 122 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0,
123 iis_clkrate / 4, pll_out); 123 iis_clkrate / 4, pll_out);
124 if (ret < 0) 124 if (ret < 0)
125 return ret; 125 return ret;
@@ -133,7 +133,7 @@ static int neo1973_gta02_hifi_hw_free(struct snd_pcm_substream *substream)
133 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 133 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
134 134
135 /* disable the PLL */ 135 /* disable the PLL */
136 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0); 136 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0);
137} 137}
138 138
139/* 139/*
@@ -183,7 +183,7 @@ static int neo1973_gta02_voice_hw_params(
183 return ret; 183 return ret;
184 184
185 /* configue and enable PLL for 12.288MHz output */ 185 /* configue and enable PLL for 12.288MHz output */
186 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 186 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0,
187 iis_clkrate / 4, 12288000); 187 iis_clkrate / 4, 12288000);
188 if (ret < 0) 188 if (ret < 0)
189 return ret; 189 return ret;
@@ -197,7 +197,7 @@ static int neo1973_gta02_voice_hw_free(struct snd_pcm_substream *substream)
197 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 197 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
198 198
199 /* disable the PLL */ 199 /* disable the PLL */
200 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0); 200 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
201} 201}
202 202
203static struct snd_soc_ops neo1973_gta02_voice_ops = { 203static struct snd_soc_ops neo1973_gta02_voice_ops = {
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index 906709e6dd5f..0cb4f86f6d1e 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -29,7 +29,6 @@
29#include <mach/regs-clock.h> 29#include <mach/regs-clock.h>
30#include <mach/regs-gpio.h> 30#include <mach/regs-gpio.h>
31#include <mach/hardware.h> 31#include <mach/hardware.h>
32#include <plat/audio.h>
33#include <linux/io.h> 32#include <linux/io.h>
34#include <mach/spi-gpio.h> 33#include <mach/spi-gpio.h>
35 34
@@ -37,7 +36,7 @@
37 36
38#include "../codecs/wm8753.h" 37#include "../codecs/wm8753.h"
39#include "lm4857.h" 38#include "lm4857.h"
40#include "s3c24xx-pcm.h" 39#include "s3c-dma.h"
41#include "s3c24xx-i2s.h" 40#include "s3c24xx-i2s.h"
42 41
43/* define the scenarios */ 42/* define the scenarios */
@@ -137,7 +136,7 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
137 return ret; 136 return ret;
138 137
139 /* codec PLL input is PCLK/4 */ 138 /* codec PLL input is PCLK/4 */
140 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 139 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0,
141 iis_clkrate / 4, pll_out); 140 iis_clkrate / 4, pll_out);
142 if (ret < 0) 141 if (ret < 0)
143 return ret; 142 return ret;
@@ -153,7 +152,7 @@ static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
153 pr_debug("Entered %s\n", __func__); 152 pr_debug("Entered %s\n", __func__);
154 153
155 /* disable the PLL */ 154 /* disable the PLL */
156 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0); 155 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0);
157} 156}
158 157
159/* 158/*
@@ -203,7 +202,7 @@ static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
203 return ret; 202 return ret;
204 203
205 /* configue and enable PLL for 12.288MHz output */ 204 /* configue and enable PLL for 12.288MHz output */
206 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 205 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0,
207 iis_clkrate / 4, 12288000); 206 iis_clkrate / 4, 12288000);
208 if (ret < 0) 207 if (ret < 0)
209 return ret; 208 return ret;
@@ -219,7 +218,7 @@ static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
219 pr_debug("Entered %s\n", __func__); 218 pr_debug("Entered %s\n", __func__);
220 219
221 /* disable the PLL */ 220 /* disable the PLL */
222 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0); 221 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
223} 222}
224 223
225static struct snd_soc_ops neo1973_voice_ops = { 224static struct snd_soc_ops neo1973_voice_ops = {
diff --git a/sound/soc/s3c24xx/s3c24xx-pcm.c b/sound/soc/s3c24xx/s3c-dma.c
index 1f35c6fcf5fd..7725e26d6c91 100644
--- a/sound/soc/s3c24xx/s3c24xx-pcm.c
+++ b/sound/soc/s3c24xx/s3c-dma.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * s3c24xx-pcm.c -- ALSA Soc Audio Layer 2 * s3c-dma.c -- ALSA Soc Audio Layer
3 * 3 *
4 * (c) 2006 Wolfson Microelectronics PLC. 4 * (c) 2006 Wolfson Microelectronics PLC.
5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com 5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
@@ -29,11 +29,10 @@
29#include <asm/dma.h> 29#include <asm/dma.h>
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31#include <mach/dma.h> 31#include <mach/dma.h>
32#include <plat/audio.h>
33 32
34#include "s3c24xx-pcm.h" 33#include "s3c-dma.h"
35 34
36static const struct snd_pcm_hardware s3c24xx_pcm_hardware = { 35static const struct snd_pcm_hardware s3c_dma_hardware = {
37 .info = SNDRV_PCM_INFO_INTERLEAVED | 36 .info = SNDRV_PCM_INFO_INTERLEAVED |
38 SNDRV_PCM_INFO_BLOCK_TRANSFER | 37 SNDRV_PCM_INFO_BLOCK_TRANSFER |
39 SNDRV_PCM_INFO_MMAP | 38 SNDRV_PCM_INFO_MMAP |
@@ -63,15 +62,15 @@ struct s3c24xx_runtime_data {
63 dma_addr_t dma_start; 62 dma_addr_t dma_start;
64 dma_addr_t dma_pos; 63 dma_addr_t dma_pos;
65 dma_addr_t dma_end; 64 dma_addr_t dma_end;
66 struct s3c24xx_pcm_dma_params *params; 65 struct s3c_dma_params *params;
67}; 66};
68 67
69/* s3c24xx_pcm_enqueue 68/* s3c_dma_enqueue
70 * 69 *
71 * place a dma buffer onto the queue for the dma system 70 * place a dma buffer onto the queue for the dma system
72 * to handle. 71 * to handle.
73*/ 72*/
74static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream) 73static void s3c_dma_enqueue(struct snd_pcm_substream *substream)
75{ 74{
76 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 75 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
77 dma_addr_t pos = prtd->dma_pos; 76 dma_addr_t pos = prtd->dma_pos;
@@ -80,12 +79,13 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
80 79
81 pr_debug("Entered %s\n", __func__); 80 pr_debug("Entered %s\n", __func__);
82 81
83 if (s3c_dma_has_circular()) { 82 if (s3c_dma_has_circular())
84 limit = (prtd->dma_end - prtd->dma_start) / prtd->dma_period; 83 limit = (prtd->dma_end - prtd->dma_start) / prtd->dma_period;
85 } else 84 else
86 limit = prtd->dma_limit; 85 limit = prtd->dma_limit;
87 86
88 pr_debug("%s: loaded %d, limit %d\n", __func__, prtd->dma_loaded, limit); 87 pr_debug("%s: loaded %d, limit %d\n",
88 __func__, prtd->dma_loaded, limit);
89 89
90 while (prtd->dma_loaded < limit) { 90 while (prtd->dma_loaded < limit) {
91 unsigned long len = prtd->dma_period; 91 unsigned long len = prtd->dma_period;
@@ -133,19 +133,19 @@ static void s3c24xx_audio_buffdone(struct s3c2410_dma_chan *channel,
133 spin_lock(&prtd->lock); 133 spin_lock(&prtd->lock);
134 if (prtd->state & ST_RUNNING && !s3c_dma_has_circular()) { 134 if (prtd->state & ST_RUNNING && !s3c_dma_has_circular()) {
135 prtd->dma_loaded--; 135 prtd->dma_loaded--;
136 s3c24xx_pcm_enqueue(substream); 136 s3c_dma_enqueue(substream);
137 } 137 }
138 138
139 spin_unlock(&prtd->lock); 139 spin_unlock(&prtd->lock);
140} 140}
141 141
142static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream, 142static int s3c_dma_hw_params(struct snd_pcm_substream *substream,
143 struct snd_pcm_hw_params *params) 143 struct snd_pcm_hw_params *params)
144{ 144{
145 struct snd_pcm_runtime *runtime = substream->runtime; 145 struct snd_pcm_runtime *runtime = substream->runtime;
146 struct s3c24xx_runtime_data *prtd = runtime->private_data; 146 struct s3c24xx_runtime_data *prtd = runtime->private_data;
147 struct snd_soc_pcm_runtime *rtd = substream->private_data; 147 struct snd_soc_pcm_runtime *rtd = substream->private_data;
148 struct s3c24xx_pcm_dma_params *dma = rtd->dai->cpu_dai->dma_data; 148 struct s3c_dma_params *dma = rtd->dai->cpu_dai->dma_data;
149 unsigned long totbytes = params_buffer_bytes(params); 149 unsigned long totbytes = params_buffer_bytes(params);
150 int ret = 0; 150 int ret = 0;
151 151
@@ -198,7 +198,7 @@ static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream,
198 return 0; 198 return 0;
199} 199}
200 200
201static int s3c24xx_pcm_hw_free(struct snd_pcm_substream *substream) 201static int s3c_dma_hw_free(struct snd_pcm_substream *substream)
202{ 202{
203 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 203 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
204 204
@@ -215,7 +215,7 @@ static int s3c24xx_pcm_hw_free(struct snd_pcm_substream *substream)
215 return 0; 215 return 0;
216} 216}
217 217
218static int s3c24xx_pcm_prepare(struct snd_pcm_substream *substream) 218static int s3c_dma_prepare(struct snd_pcm_substream *substream)
219{ 219{
220 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 220 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
221 int ret = 0; 221 int ret = 0;
@@ -248,12 +248,12 @@ static int s3c24xx_pcm_prepare(struct snd_pcm_substream *substream)
248 prtd->dma_pos = prtd->dma_start; 248 prtd->dma_pos = prtd->dma_start;
249 249
250 /* enqueue dma buffers */ 250 /* enqueue dma buffers */
251 s3c24xx_pcm_enqueue(substream); 251 s3c_dma_enqueue(substream);
252 252
253 return ret; 253 return ret;
254} 254}
255 255
256static int s3c24xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 256static int s3c_dma_trigger(struct snd_pcm_substream *substream, int cmd)
257{ 257{
258 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 258 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
259 int ret = 0; 259 int ret = 0;
@@ -288,7 +288,7 @@ static int s3c24xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
288} 288}
289 289
290static snd_pcm_uframes_t 290static snd_pcm_uframes_t
291s3c24xx_pcm_pointer(struct snd_pcm_substream *substream) 291s3c_dma_pointer(struct snd_pcm_substream *substream)
292{ 292{
293 struct snd_pcm_runtime *runtime = substream->runtime; 293 struct snd_pcm_runtime *runtime = substream->runtime;
294 struct s3c24xx_runtime_data *prtd = runtime->private_data; 294 struct s3c24xx_runtime_data *prtd = runtime->private_data;
@@ -323,7 +323,7 @@ s3c24xx_pcm_pointer(struct snd_pcm_substream *substream)
323 return bytes_to_frames(substream->runtime, res); 323 return bytes_to_frames(substream->runtime, res);
324} 324}
325 325
326static int s3c24xx_pcm_open(struct snd_pcm_substream *substream) 326static int s3c_dma_open(struct snd_pcm_substream *substream)
327{ 327{
328 struct snd_pcm_runtime *runtime = substream->runtime; 328 struct snd_pcm_runtime *runtime = substream->runtime;
329 struct s3c24xx_runtime_data *prtd; 329 struct s3c24xx_runtime_data *prtd;
@@ -331,7 +331,7 @@ static int s3c24xx_pcm_open(struct snd_pcm_substream *substream)
331 pr_debug("Entered %s\n", __func__); 331 pr_debug("Entered %s\n", __func__);
332 332
333 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 333 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
334 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware); 334 snd_soc_set_runtime_hwparams(substream, &s3c_dma_hardware);
335 335
336 prtd = kzalloc(sizeof(struct s3c24xx_runtime_data), GFP_KERNEL); 336 prtd = kzalloc(sizeof(struct s3c24xx_runtime_data), GFP_KERNEL);
337 if (prtd == NULL) 337 if (prtd == NULL)
@@ -343,7 +343,7 @@ static int s3c24xx_pcm_open(struct snd_pcm_substream *substream)
343 return 0; 343 return 0;
344} 344}
345 345
346static int s3c24xx_pcm_close(struct snd_pcm_substream *substream) 346static int s3c_dma_close(struct snd_pcm_substream *substream)
347{ 347{
348 struct snd_pcm_runtime *runtime = substream->runtime; 348 struct snd_pcm_runtime *runtime = substream->runtime;
349 struct s3c24xx_runtime_data *prtd = runtime->private_data; 349 struct s3c24xx_runtime_data *prtd = runtime->private_data;
@@ -351,14 +351,14 @@ static int s3c24xx_pcm_close(struct snd_pcm_substream *substream)
351 pr_debug("Entered %s\n", __func__); 351 pr_debug("Entered %s\n", __func__);
352 352
353 if (!prtd) 353 if (!prtd)
354 pr_debug("s3c24xx_pcm_close called with prtd == NULL\n"); 354 pr_debug("s3c_dma_close called with prtd == NULL\n");
355 355
356 kfree(prtd); 356 kfree(prtd);
357 357
358 return 0; 358 return 0;
359} 359}
360 360
361static int s3c24xx_pcm_mmap(struct snd_pcm_substream *substream, 361static int s3c_dma_mmap(struct snd_pcm_substream *substream,
362 struct vm_area_struct *vma) 362 struct vm_area_struct *vma)
363{ 363{
364 struct snd_pcm_runtime *runtime = substream->runtime; 364 struct snd_pcm_runtime *runtime = substream->runtime;
@@ -371,23 +371,23 @@ static int s3c24xx_pcm_mmap(struct snd_pcm_substream *substream,
371 runtime->dma_bytes); 371 runtime->dma_bytes);
372} 372}
373 373
374static struct snd_pcm_ops s3c24xx_pcm_ops = { 374static struct snd_pcm_ops s3c_dma_ops = {
375 .open = s3c24xx_pcm_open, 375 .open = s3c_dma_open,
376 .close = s3c24xx_pcm_close, 376 .close = s3c_dma_close,
377 .ioctl = snd_pcm_lib_ioctl, 377 .ioctl = snd_pcm_lib_ioctl,
378 .hw_params = s3c24xx_pcm_hw_params, 378 .hw_params = s3c_dma_hw_params,
379 .hw_free = s3c24xx_pcm_hw_free, 379 .hw_free = s3c_dma_hw_free,
380 .prepare = s3c24xx_pcm_prepare, 380 .prepare = s3c_dma_prepare,
381 .trigger = s3c24xx_pcm_trigger, 381 .trigger = s3c_dma_trigger,
382 .pointer = s3c24xx_pcm_pointer, 382 .pointer = s3c_dma_pointer,
383 .mmap = s3c24xx_pcm_mmap, 383 .mmap = s3c_dma_mmap,
384}; 384};
385 385
386static int s3c24xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream) 386static int s3c_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
387{ 387{
388 struct snd_pcm_substream *substream = pcm->streams[stream].substream; 388 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
389 struct snd_dma_buffer *buf = &substream->dma_buffer; 389 struct snd_dma_buffer *buf = &substream->dma_buffer;
390 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max; 390 size_t size = s3c_dma_hardware.buffer_bytes_max;
391 391
392 pr_debug("Entered %s\n", __func__); 392 pr_debug("Entered %s\n", __func__);
393 393
@@ -402,7 +402,7 @@ static int s3c24xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
402 return 0; 402 return 0;
403} 403}
404 404
405static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm) 405static void s3c_dma_free_dma_buffers(struct snd_pcm *pcm)
406{ 406{
407 struct snd_pcm_substream *substream; 407 struct snd_pcm_substream *substream;
408 struct snd_dma_buffer *buf; 408 struct snd_dma_buffer *buf;
@@ -425,9 +425,9 @@ static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
425 } 425 }
426} 426}
427 427
428static u64 s3c24xx_pcm_dmamask = DMA_BIT_MASK(32); 428static u64 s3c_dma_mask = DMA_BIT_MASK(32);
429 429
430static int s3c24xx_pcm_new(struct snd_card *card, 430static int s3c_dma_new(struct snd_card *card,
431 struct snd_soc_dai *dai, struct snd_pcm *pcm) 431 struct snd_soc_dai *dai, struct snd_pcm *pcm)
432{ 432{
433 int ret = 0; 433 int ret = 0;
@@ -435,19 +435,19 @@ static int s3c24xx_pcm_new(struct snd_card *card,
435 pr_debug("Entered %s\n", __func__); 435 pr_debug("Entered %s\n", __func__);
436 436
437 if (!card->dev->dma_mask) 437 if (!card->dev->dma_mask)
438 card->dev->dma_mask = &s3c24xx_pcm_dmamask; 438 card->dev->dma_mask = &s3c_dma_mask;
439 if (!card->dev->coherent_dma_mask) 439 if (!card->dev->coherent_dma_mask)
440 card->dev->coherent_dma_mask = 0xffffffff; 440 card->dev->coherent_dma_mask = 0xffffffff;
441 441
442 if (dai->playback.channels_min) { 442 if (dai->playback.channels_min) {
443 ret = s3c24xx_pcm_preallocate_dma_buffer(pcm, 443 ret = s3c_preallocate_dma_buffer(pcm,
444 SNDRV_PCM_STREAM_PLAYBACK); 444 SNDRV_PCM_STREAM_PLAYBACK);
445 if (ret) 445 if (ret)
446 goto out; 446 goto out;
447 } 447 }
448 448
449 if (dai->capture.channels_min) { 449 if (dai->capture.channels_min) {
450 ret = s3c24xx_pcm_preallocate_dma_buffer(pcm, 450 ret = s3c_preallocate_dma_buffer(pcm,
451 SNDRV_PCM_STREAM_CAPTURE); 451 SNDRV_PCM_STREAM_CAPTURE);
452 if (ret) 452 if (ret)
453 goto out; 453 goto out;
@@ -458,9 +458,9 @@ static int s3c24xx_pcm_new(struct snd_card *card,
458 458
459struct snd_soc_platform s3c24xx_soc_platform = { 459struct snd_soc_platform s3c24xx_soc_platform = {
460 .name = "s3c24xx-audio", 460 .name = "s3c24xx-audio",
461 .pcm_ops = &s3c24xx_pcm_ops, 461 .pcm_ops = &s3c_dma_ops,
462 .pcm_new = s3c24xx_pcm_new, 462 .pcm_new = s3c_dma_new,
463 .pcm_free = s3c24xx_pcm_free_dma_buffers, 463 .pcm_free = s3c_dma_free_dma_buffers,
464}; 464};
465EXPORT_SYMBOL_GPL(s3c24xx_soc_platform); 465EXPORT_SYMBOL_GPL(s3c24xx_soc_platform);
466 466
@@ -477,5 +477,5 @@ static void __exit s3c24xx_soc_platform_exit(void)
477module_exit(s3c24xx_soc_platform_exit); 477module_exit(s3c24xx_soc_platform_exit);
478 478
479MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 479MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
480MODULE_DESCRIPTION("Samsung S3C24XX PCM DMA module"); 480MODULE_DESCRIPTION("Samsung S3C Audio DMA module");
481MODULE_LICENSE("GPL"); 481MODULE_LICENSE("GPL");
diff --git a/sound/soc/s3c24xx/s3c24xx-pcm.h b/sound/soc/s3c24xx/s3c-dma.h
index 0088c79822ea..69bb6bf6fc1c 100644
--- a/sound/soc/s3c24xx/s3c24xx-pcm.h
+++ b/sound/soc/s3c24xx/s3c-dma.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * s3c24xx-pcm.h -- 2 * s3c-dma.h --
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the 5 * under the terms of the GNU General Public License as published by the
@@ -9,13 +9,13 @@
9 * ALSA PCM interface for the Samsung S3C24xx CPU 9 * ALSA PCM interface for the Samsung S3C24xx CPU
10 */ 10 */
11 11
12#ifndef _S3C24XX_PCM_H 12#ifndef _S3C_AUDIO_H
13#define _S3C24XX_PCM_H 13#define _S3C_AUDIO_H
14 14
15#define ST_RUNNING (1<<0) 15#define ST_RUNNING (1<<0)
16#define ST_OPENED (1<<1) 16#define ST_OPENED (1<<1)
17 17
18struct s3c24xx_pcm_dma_params { 18struct s3c_dma_params {
19 struct s3c2410_dma_client *client; /* stream identifier */ 19 struct s3c2410_dma_client *client; /* stream identifier */
20 int channel; /* Channel ID */ 20 int channel; /* Channel ID */
21 dma_addr_t dma_addr; 21 dma_addr_t dma_addr;
diff --git a/sound/soc/s3c24xx/s3c-i2s-v2.c b/sound/soc/s3c24xx/s3c-i2s-v2.c
index 9bc4aa35caab..e994d8374fe6 100644
--- a/sound/soc/s3c24xx/s3c-i2s-v2.c
+++ b/sound/soc/s3c24xx/s3c-i2s-v2.c
@@ -32,11 +32,10 @@
32 32
33#include <plat/regs-s3c2412-iis.h> 33#include <plat/regs-s3c2412-iis.h>
34 34
35#include <plat/audio.h>
36#include <mach/dma.h> 35#include <mach/dma.h>
37 36
38#include "s3c-i2s-v2.h" 37#include "s3c-i2s-v2.h"
39#include "s3c24xx-pcm.h" 38#include "s3c-dma.h"
40 39
41#undef S3C_IIS_V2_SUPPORTED 40#undef S3C_IIS_V2_SUPPORTED
42 41
@@ -312,12 +311,15 @@ static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
312 311
313 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 312 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
314 case SND_SOC_DAIFMT_RIGHT_J: 313 case SND_SOC_DAIFMT_RIGHT_J:
314 iismod |= S3C2412_IISMOD_LR_RLOW;
315 iismod |= S3C2412_IISMOD_SDF_MSB; 315 iismod |= S3C2412_IISMOD_SDF_MSB;
316 break; 316 break;
317 case SND_SOC_DAIFMT_LEFT_J: 317 case SND_SOC_DAIFMT_LEFT_J:
318 iismod |= S3C2412_IISMOD_LR_RLOW;
318 iismod |= S3C2412_IISMOD_SDF_LSB; 319 iismod |= S3C2412_IISMOD_SDF_LSB;
319 break; 320 break;
320 case SND_SOC_DAIFMT_I2S: 321 case SND_SOC_DAIFMT_I2S:
322 iismod &= ~S3C2412_IISMOD_LR_RLOW;
321 iismod |= S3C2412_IISMOD_SDF_IIS; 323 iismod |= S3C2412_IISMOD_SDF_IIS;
322 break; 324 break;
323 default: 325 default:
@@ -392,7 +394,7 @@ static int s3c2412_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
392 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); 394 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
393 unsigned long irqs; 395 unsigned long irqs;
394 int ret = 0; 396 int ret = 0;
395 int channel = ((struct s3c24xx_pcm_dma_params *) 397 int channel = ((struct s3c_dma_params *)
396 rtd->dai->cpu_dai->dma_data)->channel; 398 rtd->dai->cpu_dai->dma_data)->channel;
397 399
398 pr_debug("Entered %s\n", __func__); 400 pr_debug("Entered %s\n", __func__);
@@ -467,6 +469,31 @@ static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
467 469
468 switch (div_id) { 470 switch (div_id) {
469 case S3C_I2SV2_DIV_BCLK: 471 case S3C_I2SV2_DIV_BCLK:
472 if (div > 3) {
473 /* convert value to bit field */
474
475 switch (div) {
476 case 16:
477 div = S3C2412_IISMOD_BCLK_16FS;
478 break;
479
480 case 32:
481 div = S3C2412_IISMOD_BCLK_32FS;
482 break;
483
484 case 24:
485 div = S3C2412_IISMOD_BCLK_24FS;
486 break;
487
488 case 48:
489 div = S3C2412_IISMOD_BCLK_48FS;
490 break;
491
492 default:
493 return -EINVAL;
494 }
495 }
496
470 reg = readl(i2s->regs + S3C2412_IISMOD); 497 reg = readl(i2s->regs + S3C2412_IISMOD);
471 reg &= ~S3C2412_IISMOD_BCLK_MASK; 498 reg &= ~S3C2412_IISMOD_BCLK_MASK;
472 writel(reg | div, i2s->regs + S3C2412_IISMOD); 499 writel(reg | div, i2s->regs + S3C2412_IISMOD);
@@ -626,7 +653,7 @@ int s3c_i2sv2_probe(struct platform_device *pdev,
626 } 653 }
627 654
628 i2s->iis_pclk = clk_get(dev, "iis"); 655 i2s->iis_pclk = clk_get(dev, "iis");
629 if (i2s->iis_pclk == NULL) { 656 if (IS_ERR(i2s->iis_pclk)) {
630 dev_err(dev, "failed to get iis_clock\n"); 657 dev_err(dev, "failed to get iis_clock\n");
631 iounmap(i2s->regs); 658 iounmap(i2s->regs);
632 return -ENOENT; 659 return -ENOENT;
diff --git a/sound/soc/s3c24xx/s3c-i2s-v2.h b/sound/soc/s3c24xx/s3c-i2s-v2.h
index f66854a77fb2..ecf8eaaed1db 100644
--- a/sound/soc/s3c24xx/s3c-i2s-v2.h
+++ b/sound/soc/s3c24xx/s3c-i2s-v2.h
@@ -49,8 +49,8 @@ struct s3c_i2sv2_info {
49 49
50 unsigned char master; 50 unsigned char master;
51 51
52 struct s3c24xx_pcm_dma_params *dma_playback; 52 struct s3c_dma_params *dma_playback;
53 struct s3c24xx_pcm_dma_params *dma_capture; 53 struct s3c_dma_params *dma_capture;
54 54
55 u32 suspend_iismod; 55 u32 suspend_iismod;
56 u32 suspend_iiscon; 56 u32 suspend_iiscon;
diff --git a/sound/soc/s3c24xx/s3c-pcm.c b/sound/soc/s3c24xx/s3c-pcm.c
new file mode 100644
index 000000000000..9e61a7c2d9ac
--- /dev/null
+++ b/sound/soc/s3c24xx/s3c-pcm.c
@@ -0,0 +1,552 @@
1/* sound/soc/s3c24xx/s3c-pcm.c
2 *
3 * ALSA SoC Audio Layer - S3C PCM-Controller driver
4 *
5 * Copyright (c) 2009 Samsung Electronics Co. Ltd
6 * Author: Jaswinder Singh <jassi.brar@samsung.com>
7 * based upon I2S drivers by Ben Dooks.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/device.h>
17#include <linux/delay.h>
18#include <linux/clk.h>
19#include <linux/kernel.h>
20#include <linux/gpio.h>
21#include <linux/io.h>
22
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/initval.h>
27#include <sound/soc.h>
28
29#include <plat/audio.h>
30#include <plat/dma.h>
31
32#include "s3c-dma.h"
33#include "s3c-pcm.h"
34
35static struct s3c2410_dma_client s3c_pcm_dma_client_out = {
36 .name = "PCM Stereo out"
37};
38
39static struct s3c2410_dma_client s3c_pcm_dma_client_in = {
40 .name = "PCM Stereo in"
41};
42
43static struct s3c_dma_params s3c_pcm_stereo_out[] = {
44 [0] = {
45 .client = &s3c_pcm_dma_client_out,
46 .dma_size = 4,
47 },
48 [1] = {
49 .client = &s3c_pcm_dma_client_out,
50 .dma_size = 4,
51 },
52};
53
54static struct s3c_dma_params s3c_pcm_stereo_in[] = {
55 [0] = {
56 .client = &s3c_pcm_dma_client_in,
57 .dma_size = 4,
58 },
59 [1] = {
60 .client = &s3c_pcm_dma_client_in,
61 .dma_size = 4,
62 },
63};
64
65static struct s3c_pcm_info s3c_pcm[2];
66
67static inline struct s3c_pcm_info *to_info(struct snd_soc_dai *cpu_dai)
68{
69 return cpu_dai->private_data;
70}
71
72static void s3c_pcm_snd_txctrl(struct s3c_pcm_info *pcm, int on)
73{
74 void __iomem *regs = pcm->regs;
75 u32 ctl, clkctl;
76
77 clkctl = readl(regs + S3C_PCM_CLKCTL);
78 ctl = readl(regs + S3C_PCM_CTL);
79 ctl &= ~(S3C_PCM_CTL_TXDIPSTICK_MASK
80 << S3C_PCM_CTL_TXDIPSTICK_SHIFT);
81
82 if (on) {
83 ctl |= S3C_PCM_CTL_TXDMA_EN;
84 ctl |= S3C_PCM_CTL_TXFIFO_EN;
85 ctl |= S3C_PCM_CTL_ENABLE;
86 ctl |= (0x20<<S3C_PCM_CTL_TXDIPSTICK_SHIFT);
87 clkctl |= S3C_PCM_CLKCTL_SERCLK_EN;
88 } else {
89 ctl &= ~S3C_PCM_CTL_TXDMA_EN;
90 ctl &= ~S3C_PCM_CTL_TXFIFO_EN;
91
92 if (!(ctl & S3C_PCM_CTL_RXFIFO_EN)) {
93 ctl &= ~S3C_PCM_CTL_ENABLE;
94 if (!pcm->idleclk)
95 clkctl |= S3C_PCM_CLKCTL_SERCLK_EN;
96 }
97 }
98
99 writel(clkctl, regs + S3C_PCM_CLKCTL);
100 writel(ctl, regs + S3C_PCM_CTL);
101}
102
103static void s3c_pcm_snd_rxctrl(struct s3c_pcm_info *pcm, int on)
104{
105 void __iomem *regs = pcm->regs;
106 u32 ctl, clkctl;
107
108 ctl = readl(regs + S3C_PCM_CTL);
109 clkctl = readl(regs + S3C_PCM_CLKCTL);
110
111 if (on) {
112 ctl |= S3C_PCM_CTL_RXDMA_EN;
113 ctl |= S3C_PCM_CTL_RXFIFO_EN;
114 ctl |= S3C_PCM_CTL_ENABLE;
115 clkctl |= S3C_PCM_CLKCTL_SERCLK_EN;
116 } else {
117 ctl &= ~S3C_PCM_CTL_RXDMA_EN;
118 ctl &= ~S3C_PCM_CTL_RXFIFO_EN;
119
120 if (!(ctl & S3C_PCM_CTL_TXFIFO_EN)) {
121 ctl &= ~S3C_PCM_CTL_ENABLE;
122 if (!pcm->idleclk)
123 clkctl |= S3C_PCM_CLKCTL_SERCLK_EN;
124 }
125 }
126
127 writel(clkctl, regs + S3C_PCM_CLKCTL);
128 writel(ctl, regs + S3C_PCM_CTL);
129}
130
131static int s3c_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
132 struct snd_soc_dai *dai)
133{
134 struct snd_soc_pcm_runtime *rtd = substream->private_data;
135 struct s3c_pcm_info *pcm = to_info(rtd->dai->cpu_dai);
136 unsigned long flags;
137
138 dev_dbg(pcm->dev, "Entered %s\n", __func__);
139
140 switch (cmd) {
141 case SNDRV_PCM_TRIGGER_START:
142 case SNDRV_PCM_TRIGGER_RESUME:
143 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
144 spin_lock_irqsave(&pcm->lock, flags);
145
146 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
147 s3c_pcm_snd_rxctrl(pcm, 1);
148 else
149 s3c_pcm_snd_txctrl(pcm, 1);
150
151 spin_unlock_irqrestore(&pcm->lock, flags);
152 break;
153
154 case SNDRV_PCM_TRIGGER_STOP:
155 case SNDRV_PCM_TRIGGER_SUSPEND:
156 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
157 spin_lock_irqsave(&pcm->lock, flags);
158
159 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
160 s3c_pcm_snd_rxctrl(pcm, 0);
161 else
162 s3c_pcm_snd_txctrl(pcm, 0);
163
164 spin_unlock_irqrestore(&pcm->lock, flags);
165 break;
166
167 default:
168 return -EINVAL;
169 }
170
171 return 0;
172}
173
174static int s3c_pcm_hw_params(struct snd_pcm_substream *substream,
175 struct snd_pcm_hw_params *params,
176 struct snd_soc_dai *socdai)
177{
178 struct snd_soc_pcm_runtime *rtd = substream->private_data;
179 struct snd_soc_dai_link *dai = rtd->dai;
180 struct s3c_pcm_info *pcm = to_info(dai->cpu_dai);
181 void __iomem *regs = pcm->regs;
182 struct clk *clk;
183 int sclk_div, sync_div;
184 unsigned long flags;
185 u32 clkctl;
186
187 dev_dbg(pcm->dev, "Entered %s\n", __func__);
188
189 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
190 dai->cpu_dai->dma_data = pcm->dma_playback;
191 else
192 dai->cpu_dai->dma_data = pcm->dma_capture;
193
194 /* Strictly check for sample size */
195 switch (params_format(params)) {
196 case SNDRV_PCM_FORMAT_S16_LE:
197 break;
198 default:
199 return -EINVAL;
200 }
201
202 spin_lock_irqsave(&pcm->lock, flags);
203
204 /* Get hold of the PCMSOURCE_CLK */
205 clkctl = readl(regs + S3C_PCM_CLKCTL);
206 if (clkctl & S3C_PCM_CLKCTL_SERCLKSEL_PCLK)
207 clk = pcm->pclk;
208 else
209 clk = pcm->cclk;
210
211 /* Set the SCLK divider */
212 sclk_div = clk_get_rate(clk) / pcm->sclk_per_fs /
213 params_rate(params) / 2 - 1;
214
215 clkctl &= ~(S3C_PCM_CLKCTL_SCLKDIV_MASK
216 << S3C_PCM_CLKCTL_SCLKDIV_SHIFT);
217 clkctl |= ((sclk_div & S3C_PCM_CLKCTL_SCLKDIV_MASK)
218 << S3C_PCM_CLKCTL_SCLKDIV_SHIFT);
219
220 /* Set the SYNC divider */
221 sync_div = pcm->sclk_per_fs - 1;
222
223 clkctl &= ~(S3C_PCM_CLKCTL_SYNCDIV_MASK
224 << S3C_PCM_CLKCTL_SYNCDIV_SHIFT);
225 clkctl |= ((sync_div & S3C_PCM_CLKCTL_SYNCDIV_MASK)
226 << S3C_PCM_CLKCTL_SYNCDIV_SHIFT);
227
228 writel(clkctl, regs + S3C_PCM_CLKCTL);
229
230 spin_unlock_irqrestore(&pcm->lock, flags);
231
232 dev_dbg(pcm->dev, "PCMSOURCE_CLK-%lu SCLK=%ufs \
233 SCLK_DIV=%d SYNC_DIV=%d\n",
234 clk_get_rate(clk), pcm->sclk_per_fs,
235 sclk_div, sync_div);
236
237 return 0;
238}
239
240static int s3c_pcm_set_fmt(struct snd_soc_dai *cpu_dai,
241 unsigned int fmt)
242{
243 struct s3c_pcm_info *pcm = to_info(cpu_dai);
244 void __iomem *regs = pcm->regs;
245 unsigned long flags;
246 int ret = 0;
247 u32 ctl;
248
249 dev_dbg(pcm->dev, "Entered %s\n", __func__);
250
251 spin_lock_irqsave(&pcm->lock, flags);
252
253 ctl = readl(regs + S3C_PCM_CTL);
254
255 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
256 case SND_SOC_DAIFMT_NB_NF:
257 /* Nothing to do, NB_NF by default */
258 break;
259 default:
260 dev_err(pcm->dev, "Unsupported clock inversion!\n");
261 ret = -EINVAL;
262 goto exit;
263 }
264
265 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
266 case SND_SOC_DAIFMT_CBS_CFS:
267 /* Nothing to do, Master by default */
268 break;
269 default:
270 dev_err(pcm->dev, "Unsupported master/slave format!\n");
271 ret = -EINVAL;
272 goto exit;
273 }
274
275 switch (fmt & SND_SOC_DAIFMT_CLOCK_MASK) {
276 case SND_SOC_DAIFMT_CONT:
277 pcm->idleclk = 1;
278 break;
279 case SND_SOC_DAIFMT_GATED:
280 pcm->idleclk = 0;
281 break;
282 default:
283 dev_err(pcm->dev, "Invalid Clock gating request!\n");
284 ret = -EINVAL;
285 goto exit;
286 }
287
288 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
289 case SND_SOC_DAIFMT_DSP_A:
290 ctl |= S3C_PCM_CTL_TXMSB_AFTER_FSYNC;
291 ctl |= S3C_PCM_CTL_RXMSB_AFTER_FSYNC;
292 break;
293 case SND_SOC_DAIFMT_DSP_B:
294 ctl &= ~S3C_PCM_CTL_TXMSB_AFTER_FSYNC;
295 ctl &= ~S3C_PCM_CTL_RXMSB_AFTER_FSYNC;
296 break;
297 default:
298 dev_err(pcm->dev, "Unsupported data format!\n");
299 ret = -EINVAL;
300 goto exit;
301 }
302
303 writel(ctl, regs + S3C_PCM_CTL);
304
305exit:
306 spin_unlock_irqrestore(&pcm->lock, flags);
307
308 return ret;
309}
310
311static int s3c_pcm_set_clkdiv(struct snd_soc_dai *cpu_dai,
312 int div_id, int div)
313{
314 struct s3c_pcm_info *pcm = to_info(cpu_dai);
315
316 switch (div_id) {
317 case S3C_PCM_SCLK_PER_FS:
318 pcm->sclk_per_fs = div;
319 break;
320
321 default:
322 return -EINVAL;
323 }
324
325 return 0;
326}
327
328static int s3c_pcm_set_sysclk(struct snd_soc_dai *cpu_dai,
329 int clk_id, unsigned int freq, int dir)
330{
331 struct s3c_pcm_info *pcm = to_info(cpu_dai);
332 void __iomem *regs = pcm->regs;
333 u32 clkctl = readl(regs + S3C_PCM_CLKCTL);
334
335 switch (clk_id) {
336 case S3C_PCM_CLKSRC_PCLK:
337 clkctl |= S3C_PCM_CLKCTL_SERCLKSEL_PCLK;
338 break;
339
340 case S3C_PCM_CLKSRC_MUX:
341 clkctl &= ~S3C_PCM_CLKCTL_SERCLKSEL_PCLK;
342
343 if (clk_get_rate(pcm->cclk) != freq)
344 clk_set_rate(pcm->cclk, freq);
345
346 break;
347
348 default:
349 return -EINVAL;
350 }
351
352 writel(clkctl, regs + S3C_PCM_CLKCTL);
353
354 return 0;
355}
356
357static struct snd_soc_dai_ops s3c_pcm_dai_ops = {
358 .set_sysclk = s3c_pcm_set_sysclk,
359 .set_clkdiv = s3c_pcm_set_clkdiv,
360 .trigger = s3c_pcm_trigger,
361 .hw_params = s3c_pcm_hw_params,
362 .set_fmt = s3c_pcm_set_fmt,
363};
364
365#define S3C_PCM_RATES SNDRV_PCM_RATE_8000_96000
366
367#define S3C_PCM_DECLARE(n) \
368{ \
369 .name = "samsung-pcm", \
370 .id = (n), \
371 .symmetric_rates = 1, \
372 .ops = &s3c_pcm_dai_ops, \
373 .playback = { \
374 .channels_min = 2, \
375 .channels_max = 2, \
376 .rates = S3C_PCM_RATES, \
377 .formats = SNDRV_PCM_FMTBIT_S16_LE, \
378 }, \
379 .capture = { \
380 .channels_min = 2, \
381 .channels_max = 2, \
382 .rates = S3C_PCM_RATES, \
383 .formats = SNDRV_PCM_FMTBIT_S16_LE, \
384 }, \
385}
386
387struct snd_soc_dai s3c_pcm_dai[] = {
388 S3C_PCM_DECLARE(0),
389 S3C_PCM_DECLARE(1),
390};
391EXPORT_SYMBOL_GPL(s3c_pcm_dai);
392
393static __devinit int s3c_pcm_dev_probe(struct platform_device *pdev)
394{
395 struct s3c_pcm_info *pcm;
396 struct snd_soc_dai *dai;
397 struct resource *mem_res, *dmatx_res, *dmarx_res;
398 struct s3c_audio_pdata *pcm_pdata;
399 int ret;
400
401 /* Check for valid device index */
402 if ((pdev->id < 0) || pdev->id >= ARRAY_SIZE(s3c_pcm)) {
403 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
404 return -EINVAL;
405 }
406
407 pcm_pdata = pdev->dev.platform_data;
408
409 /* Check for availability of necessary resource */
410 dmatx_res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
411 if (!dmatx_res) {
412 dev_err(&pdev->dev, "Unable to get PCM-TX dma resource\n");
413 return -ENXIO;
414 }
415
416 dmarx_res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
417 if (!dmarx_res) {
418 dev_err(&pdev->dev, "Unable to get PCM-RX dma resource\n");
419 return -ENXIO;
420 }
421
422 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
423 if (!mem_res) {
424 dev_err(&pdev->dev, "Unable to get register resource\n");
425 return -ENXIO;
426 }
427
428 if (pcm_pdata && pcm_pdata->cfg_gpio && pcm_pdata->cfg_gpio(pdev)) {
429 dev_err(&pdev->dev, "Unable to configure gpio\n");
430 return -EINVAL;
431 }
432
433 pcm = &s3c_pcm[pdev->id];
434 pcm->dev = &pdev->dev;
435
436 spin_lock_init(&pcm->lock);
437
438 dai = &s3c_pcm_dai[pdev->id];
439 dai->dev = &pdev->dev;
440
441 /* Default is 128fs */
442 pcm->sclk_per_fs = 128;
443
444 pcm->cclk = clk_get(&pdev->dev, "audio-bus");
445 if (IS_ERR(pcm->cclk)) {
446 dev_err(&pdev->dev, "failed to get audio-bus\n");
447 ret = PTR_ERR(pcm->cclk);
448 goto err1;
449 }
450 clk_enable(pcm->cclk);
451
452 /* record our pcm structure for later use in the callbacks */
453 dai->private_data = pcm;
454
455 if (!request_mem_region(mem_res->start,
456 resource_size(mem_res), "samsung-pcm")) {
457 dev_err(&pdev->dev, "Unable to request register region\n");
458 ret = -EBUSY;
459 goto err2;
460 }
461
462 pcm->regs = ioremap(mem_res->start, 0x100);
463 if (pcm->regs == NULL) {
464 dev_err(&pdev->dev, "cannot ioremap registers\n");
465 ret = -ENXIO;
466 goto err3;
467 }
468
469 pcm->pclk = clk_get(&pdev->dev, "pcm");
470 if (IS_ERR(pcm->pclk)) {
471 dev_err(&pdev->dev, "failed to get pcm_clock\n");
472 ret = -ENOENT;
473 goto err4;
474 }
475 clk_enable(pcm->pclk);
476
477 ret = snd_soc_register_dai(dai);
478 if (ret != 0) {
479 dev_err(&pdev->dev, "failed to get pcm_clock\n");
480 goto err5;
481 }
482
483 s3c_pcm_stereo_in[pdev->id].dma_addr = mem_res->start
484 + S3C_PCM_RXFIFO;
485 s3c_pcm_stereo_out[pdev->id].dma_addr = mem_res->start
486 + S3C_PCM_TXFIFO;
487
488 s3c_pcm_stereo_in[pdev->id].channel = dmarx_res->start;
489 s3c_pcm_stereo_out[pdev->id].channel = dmatx_res->start;
490
491 pcm->dma_capture = &s3c_pcm_stereo_in[pdev->id];
492 pcm->dma_playback = &s3c_pcm_stereo_out[pdev->id];
493
494 return 0;
495
496err5:
497 clk_disable(pcm->pclk);
498 clk_put(pcm->pclk);
499err4:
500 iounmap(pcm->regs);
501err3:
502 release_mem_region(mem_res->start, resource_size(mem_res));
503err2:
504 clk_disable(pcm->cclk);
505 clk_put(pcm->cclk);
506err1:
507 return ret;
508}
509
510static __devexit int s3c_pcm_dev_remove(struct platform_device *pdev)
511{
512 struct s3c_pcm_info *pcm = &s3c_pcm[pdev->id];
513 struct resource *mem_res;
514
515 iounmap(pcm->regs);
516
517 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
518 release_mem_region(mem_res->start, resource_size(mem_res));
519
520 clk_disable(pcm->cclk);
521 clk_disable(pcm->pclk);
522 clk_put(pcm->pclk);
523 clk_put(pcm->cclk);
524
525 return 0;
526}
527
528static struct platform_driver s3c_pcm_driver = {
529 .probe = s3c_pcm_dev_probe,
530 .remove = s3c_pcm_dev_remove,
531 .driver = {
532 .name = "samsung-pcm",
533 .owner = THIS_MODULE,
534 },
535};
536
537static int __init s3c_pcm_init(void)
538{
539 return platform_driver_register(&s3c_pcm_driver);
540}
541module_init(s3c_pcm_init);
542
543static void __exit s3c_pcm_exit(void)
544{
545 platform_driver_unregister(&s3c_pcm_driver);
546}
547module_exit(s3c_pcm_exit);
548
549/* Module information */
550MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
551MODULE_DESCRIPTION("S3C PCM Controller Driver");
552MODULE_LICENSE("GPL");
diff --git a/sound/soc/s3c24xx/s3c-pcm.h b/sound/soc/s3c24xx/s3c-pcm.h
new file mode 100644
index 000000000000..69ff9971692f
--- /dev/null
+++ b/sound/soc/s3c24xx/s3c-pcm.h
@@ -0,0 +1,123 @@
1/* sound/soc/s3c24xx/s3c-pcm.h
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation.
6 *
7 */
8
9#ifndef __S3C_PCM_H
10#define __S3C_PCM_H __FILE__
11
12/*Register Offsets */
13#define S3C_PCM_CTL (0x00)
14#define S3C_PCM_CLKCTL (0x04)
15#define S3C_PCM_TXFIFO (0x08)
16#define S3C_PCM_RXFIFO (0x0C)
17#define S3C_PCM_IRQCTL (0x10)
18#define S3C_PCM_IRQSTAT (0x14)
19#define S3C_PCM_FIFOSTAT (0x18)
20#define S3C_PCM_CLRINT (0x20)
21
22/* PCM_CTL Bit-Fields */
23#define S3C_PCM_CTL_TXDIPSTICK_MASK (0x3f)
24#define S3C_PCM_CTL_TXDIPSTICK_SHIFT (13)
25#define S3C_PCM_CTL_RXDIPSTICK_MSK (0x3f<<7)
26#define S3C_PCM_CTL_TXDMA_EN (0x1<<6)
27#define S3C_PCM_CTL_RXDMA_EN (0x1<<5)
28#define S3C_PCM_CTL_TXMSB_AFTER_FSYNC (0x1<<4)
29#define S3C_PCM_CTL_RXMSB_AFTER_FSYNC (0x1<<3)
30#define S3C_PCM_CTL_TXFIFO_EN (0x1<<2)
31#define S3C_PCM_CTL_RXFIFO_EN (0x1<<1)
32#define S3C_PCM_CTL_ENABLE (0x1<<0)
33
34/* PCM_CLKCTL Bit-Fields */
35#define S3C_PCM_CLKCTL_SERCLK_EN (0x1<<19)
36#define S3C_PCM_CLKCTL_SERCLKSEL_PCLK (0x1<<18)
37#define S3C_PCM_CLKCTL_SCLKDIV_MASK (0x1ff)
38#define S3C_PCM_CLKCTL_SYNCDIV_MASK (0x1ff)
39#define S3C_PCM_CLKCTL_SCLKDIV_SHIFT (9)
40#define S3C_PCM_CLKCTL_SYNCDIV_SHIFT (0)
41
42/* PCM_TXFIFO Bit-Fields */
43#define S3C_PCM_TXFIFO_DVALID (0x1<<16)
44#define S3C_PCM_TXFIFO_DATA_MSK (0xffff<<0)
45
46/* PCM_RXFIFO Bit-Fields */
47#define S3C_PCM_RXFIFO_DVALID (0x1<<16)
48#define S3C_PCM_RXFIFO_DATA_MSK (0xffff<<0)
49
50/* PCM_IRQCTL Bit-Fields */
51#define S3C_PCM_IRQCTL_IRQEN (0x1<<14)
52#define S3C_PCM_IRQCTL_WRDEN (0x1<<12)
53#define S3C_PCM_IRQCTL_TXEMPTYEN (0x1<<11)
54#define S3C_PCM_IRQCTL_TXALMSTEMPTYEN (0x1<<10)
55#define S3C_PCM_IRQCTL_TXFULLEN (0x1<<9)
56#define S3C_PCM_IRQCTL_TXALMSTFULLEN (0x1<<8)
57#define S3C_PCM_IRQCTL_TXSTARVEN (0x1<<7)
58#define S3C_PCM_IRQCTL_TXERROVRFLEN (0x1<<6)
59#define S3C_PCM_IRQCTL_RXEMPTEN (0x1<<5)
60#define S3C_PCM_IRQCTL_RXALMSTEMPTEN (0x1<<4)
61#define S3C_PCM_IRQCTL_RXFULLEN (0x1<<3)
62#define S3C_PCM_IRQCTL_RXALMSTFULLEN (0x1<<2)
63#define S3C_PCM_IRQCTL_RXSTARVEN (0x1<<1)
64#define S3C_PCM_IRQCTL_RXERROVRFLEN (0x1<<0)
65
66/* PCM_IRQSTAT Bit-Fields */
67#define S3C_PCM_IRQSTAT_IRQPND (0x1<<13)
68#define S3C_PCM_IRQSTAT_WRD_XFER (0x1<<12)
69#define S3C_PCM_IRQSTAT_TXEMPTY (0x1<<11)
70#define S3C_PCM_IRQSTAT_TXALMSTEMPTY (0x1<<10)
71#define S3C_PCM_IRQSTAT_TXFULL (0x1<<9)
72#define S3C_PCM_IRQSTAT_TXALMSTFULL (0x1<<8)
73#define S3C_PCM_IRQSTAT_TXSTARV (0x1<<7)
74#define S3C_PCM_IRQSTAT_TXERROVRFL (0x1<<6)
75#define S3C_PCM_IRQSTAT_RXEMPT (0x1<<5)
76#define S3C_PCM_IRQSTAT_RXALMSTEMPT (0x1<<4)
77#define S3C_PCM_IRQSTAT_RXFULL (0x1<<3)
78#define S3C_PCM_IRQSTAT_RXALMSTFULL (0x1<<2)
79#define S3C_PCM_IRQSTAT_RXSTARV (0x1<<1)
80#define S3C_PCM_IRQSTAT_RXERROVRFL (0x1<<0)
81
82/* PCM_FIFOSTAT Bit-Fields */
83#define S3C_PCM_FIFOSTAT_TXCNT_MSK (0x3f<<14)
84#define S3C_PCM_FIFOSTAT_TXFIFOEMPTY (0x1<<13)
85#define S3C_PCM_FIFOSTAT_TXFIFOALMSTEMPTY (0x1<<12)
86#define S3C_PCM_FIFOSTAT_TXFIFOFULL (0x1<<11)
87#define S3C_PCM_FIFOSTAT_TXFIFOALMSTFULL (0x1<<10)
88#define S3C_PCM_FIFOSTAT_RXCNT_MSK (0x3f<<4)
89#define S3C_PCM_FIFOSTAT_RXFIFOEMPTY (0x1<<3)
90#define S3C_PCM_FIFOSTAT_RXFIFOALMSTEMPTY (0x1<<2)
91#define S3C_PCM_FIFOSTAT_RXFIFOFULL (0x1<<1)
92#define S3C_PCM_FIFOSTAT_RXFIFOALMSTFULL (0x1<<0)
93
94#define S3C_PCM_CLKSRC_PCLK 0
95#define S3C_PCM_CLKSRC_MUX 1
96
97#define S3C_PCM_SCLK_PER_FS 0
98
99/**
100 * struct s3c_pcm_info - S3C PCM Controller information
101 * @dev: The parent device passed to use from the probe.
102 * @regs: The pointer to the device register block.
103 * @dma_playback: DMA information for playback channel.
104 * @dma_capture: DMA information for capture channel.
105 */
106struct s3c_pcm_info {
107 spinlock_t lock;
108 struct device *dev;
109 void __iomem *regs;
110
111 unsigned int sclk_per_fs;
112
113 /* Whether to keep PCMSCLK enabled even when idle(no active xfer) */
114 unsigned int idleclk;
115
116 struct clk *pclk;
117 struct clk *cclk;
118
119 struct s3c_dma_params *dma_playback;
120 struct s3c_dma_params *dma_capture;
121};
122
123#endif /* __S3C_PCM_H */
diff --git a/sound/soc/s3c24xx/s3c2412-i2s.c b/sound/soc/s3c24xx/s3c2412-i2s.c
index a587ec40b449..359e59346ba2 100644
--- a/sound/soc/s3c24xx/s3c2412-i2s.c
+++ b/sound/soc/s3c24xx/s3c2412-i2s.c
@@ -34,11 +34,10 @@
34 34
35#include <plat/regs-s3c2412-iis.h> 35#include <plat/regs-s3c2412-iis.h>
36 36
37#include <plat/audio.h>
38#include <mach/regs-gpio.h> 37#include <mach/regs-gpio.h>
39#include <mach/dma.h> 38#include <mach/dma.h>
40 39
41#include "s3c24xx-pcm.h" 40#include "s3c-dma.h"
42#include "s3c2412-i2s.h" 41#include "s3c2412-i2s.h"
43 42
44#define S3C2412_I2S_DEBUG 0 43#define S3C2412_I2S_DEBUG 0
@@ -51,14 +50,14 @@ static struct s3c2410_dma_client s3c2412_dma_client_in = {
51 .name = "I2S PCM Stereo in" 50 .name = "I2S PCM Stereo in"
52}; 51};
53 52
54static struct s3c24xx_pcm_dma_params s3c2412_i2s_pcm_stereo_out = { 53static struct s3c_dma_params s3c2412_i2s_pcm_stereo_out = {
55 .client = &s3c2412_dma_client_out, 54 .client = &s3c2412_dma_client_out,
56 .channel = DMACH_I2S_OUT, 55 .channel = DMACH_I2S_OUT,
57 .dma_addr = S3C2410_PA_IIS + S3C2412_IISTXD, 56 .dma_addr = S3C2410_PA_IIS + S3C2412_IISTXD,
58 .dma_size = 4, 57 .dma_size = 4,
59}; 58};
60 59
61static struct s3c24xx_pcm_dma_params s3c2412_i2s_pcm_stereo_in = { 60static struct s3c_dma_params s3c2412_i2s_pcm_stereo_in = {
62 .client = &s3c2412_dma_client_in, 61 .client = &s3c2412_dma_client_in,
63 .channel = DMACH_I2S_IN, 62 .channel = DMACH_I2S_IN,
64 .dma_addr = S3C2410_PA_IIS + S3C2412_IISRXD, 63 .dma_addr = S3C2410_PA_IIS + S3C2412_IISRXD,
diff --git a/sound/soc/s3c24xx/s3c2443-ac97.c b/sound/soc/s3c24xx/s3c2443-ac97.c
index fc1beb0930b9..0191e3acb0b4 100644
--- a/sound/soc/s3c24xx/s3c2443-ac97.c
+++ b/sound/soc/s3c24xx/s3c2443-ac97.c
@@ -32,11 +32,10 @@
32#include <plat/regs-ac97.h> 32#include <plat/regs-ac97.h>
33#include <mach/regs-gpio.h> 33#include <mach/regs-gpio.h>
34#include <mach/regs-clock.h> 34#include <mach/regs-clock.h>
35#include <plat/audio.h>
36#include <asm/dma.h> 35#include <asm/dma.h>
37#include <mach/dma.h> 36#include <mach/dma.h>
38 37
39#include "s3c24xx-pcm.h" 38#include "s3c-dma.h"
40#include "s3c24xx-ac97.h" 39#include "s3c24xx-ac97.h"
41 40
42struct s3c24xx_ac97_info { 41struct s3c24xx_ac97_info {
@@ -189,21 +188,21 @@ static struct s3c2410_dma_client s3c2443_dma_client_micin = {
189 .name = "AC97 Mic Mono in" 188 .name = "AC97 Mic Mono in"
190}; 189};
191 190
192static struct s3c24xx_pcm_dma_params s3c2443_ac97_pcm_stereo_out = { 191static struct s3c_dma_params s3c2443_ac97_pcm_stereo_out = {
193 .client = &s3c2443_dma_client_out, 192 .client = &s3c2443_dma_client_out,
194 .channel = DMACH_PCM_OUT, 193 .channel = DMACH_PCM_OUT,
195 .dma_addr = S3C2440_PA_AC97 + S3C_AC97_PCM_DATA, 194 .dma_addr = S3C2440_PA_AC97 + S3C_AC97_PCM_DATA,
196 .dma_size = 4, 195 .dma_size = 4,
197}; 196};
198 197
199static struct s3c24xx_pcm_dma_params s3c2443_ac97_pcm_stereo_in = { 198static struct s3c_dma_params s3c2443_ac97_pcm_stereo_in = {
200 .client = &s3c2443_dma_client_in, 199 .client = &s3c2443_dma_client_in,
201 .channel = DMACH_PCM_IN, 200 .channel = DMACH_PCM_IN,
202 .dma_addr = S3C2440_PA_AC97 + S3C_AC97_PCM_DATA, 201 .dma_addr = S3C2440_PA_AC97 + S3C_AC97_PCM_DATA,
203 .dma_size = 4, 202 .dma_size = 4,
204}; 203};
205 204
206static struct s3c24xx_pcm_dma_params s3c2443_ac97_mic_mono_in = { 205static struct s3c_dma_params s3c2443_ac97_mic_mono_in = {
207 .client = &s3c2443_dma_client_micin, 206 .client = &s3c2443_dma_client_micin,
208 .channel = DMACH_MIC_IN, 207 .channel = DMACH_MIC_IN,
209 .dma_addr = S3C2440_PA_AC97 + S3C_AC97_MIC_DATA, 208 .dma_addr = S3C2440_PA_AC97 + S3C_AC97_MIC_DATA,
@@ -291,7 +290,7 @@ static int s3c2443_ac97_trigger(struct snd_pcm_substream *substream, int cmd,
291{ 290{
292 u32 ac_glbctrl; 291 u32 ac_glbctrl;
293 struct snd_soc_pcm_runtime *rtd = substream->private_data; 292 struct snd_soc_pcm_runtime *rtd = substream->private_data;
294 int channel = ((struct s3c24xx_pcm_dma_params *) 293 int channel = ((struct s3c_dma_params *)
295 rtd->dai->cpu_dai->dma_data)->channel; 294 rtd->dai->cpu_dai->dma_data)->channel;
296 295
297 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL); 296 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL);
@@ -340,7 +339,7 @@ static int s3c2443_ac97_mic_trigger(struct snd_pcm_substream *substream,
340{ 339{
341 u32 ac_glbctrl; 340 u32 ac_glbctrl;
342 struct snd_soc_pcm_runtime *rtd = substream->private_data; 341 struct snd_soc_pcm_runtime *rtd = substream->private_data;
343 int channel = ((struct s3c24xx_pcm_dma_params *) 342 int channel = ((struct s3c_dma_params *)
344 rtd->dai->cpu_dai->dma_data)->channel; 343 rtd->dai->cpu_dai->dma_data)->channel;
345 344
346 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL); 345 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL);
diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.c b/sound/soc/s3c24xx/s3c24xx-i2s.c
index 40e2c4790f0d..0bc5950b9f02 100644
--- a/sound/soc/s3c24xx/s3c24xx-i2s.c
+++ b/sound/soc/s3c24xx/s3c24xx-i2s.c
@@ -32,13 +32,13 @@
32#include <mach/hardware.h> 32#include <mach/hardware.h>
33#include <mach/regs-gpio.h> 33#include <mach/regs-gpio.h>
34#include <mach/regs-clock.h> 34#include <mach/regs-clock.h>
35#include <plat/audio.h> 35
36#include <asm/dma.h> 36#include <asm/dma.h>
37#include <mach/dma.h> 37#include <mach/dma.h>
38 38
39#include <plat/regs-iis.h> 39#include <plat/regs-iis.h>
40 40
41#include "s3c24xx-pcm.h" 41#include "s3c-dma.h"
42#include "s3c24xx-i2s.h" 42#include "s3c24xx-i2s.h"
43 43
44static struct s3c2410_dma_client s3c24xx_dma_client_out = { 44static struct s3c2410_dma_client s3c24xx_dma_client_out = {
@@ -49,14 +49,14 @@ static struct s3c2410_dma_client s3c24xx_dma_client_in = {
49 .name = "I2S PCM Stereo in" 49 .name = "I2S PCM Stereo in"
50}; 50};
51 51
52static struct s3c24xx_pcm_dma_params s3c24xx_i2s_pcm_stereo_out = { 52static struct s3c_dma_params s3c24xx_i2s_pcm_stereo_out = {
53 .client = &s3c24xx_dma_client_out, 53 .client = &s3c24xx_dma_client_out,
54 .channel = DMACH_I2S_OUT, 54 .channel = DMACH_I2S_OUT,
55 .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO, 55 .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO,
56 .dma_size = 2, 56 .dma_size = 2,
57}; 57};
58 58
59static struct s3c24xx_pcm_dma_params s3c24xx_i2s_pcm_stereo_in = { 59static struct s3c_dma_params s3c24xx_i2s_pcm_stereo_in = {
60 .client = &s3c24xx_dma_client_in, 60 .client = &s3c24xx_dma_client_in,
61 .channel = DMACH_I2S_IN, 61 .channel = DMACH_I2S_IN,
62 .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO, 62 .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO,
@@ -258,12 +258,12 @@ static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
258 switch (params_format(params)) { 258 switch (params_format(params)) {
259 case SNDRV_PCM_FORMAT_S8: 259 case SNDRV_PCM_FORMAT_S8:
260 iismod &= ~S3C2410_IISMOD_16BIT; 260 iismod &= ~S3C2410_IISMOD_16BIT;
261 ((struct s3c24xx_pcm_dma_params *) 261 ((struct s3c_dma_params *)
262 rtd->dai->cpu_dai->dma_data)->dma_size = 1; 262 rtd->dai->cpu_dai->dma_data)->dma_size = 1;
263 break; 263 break;
264 case SNDRV_PCM_FORMAT_S16_LE: 264 case SNDRV_PCM_FORMAT_S16_LE:
265 iismod |= S3C2410_IISMOD_16BIT; 265 iismod |= S3C2410_IISMOD_16BIT;
266 ((struct s3c24xx_pcm_dma_params *) 266 ((struct s3c_dma_params *)
267 rtd->dai->cpu_dai->dma_data)->dma_size = 2; 267 rtd->dai->cpu_dai->dma_data)->dma_size = 2;
268 break; 268 break;
269 default: 269 default:
@@ -280,7 +280,7 @@ static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
280{ 280{
281 int ret = 0; 281 int ret = 0;
282 struct snd_soc_pcm_runtime *rtd = substream->private_data; 282 struct snd_soc_pcm_runtime *rtd = substream->private_data;
283 int channel = ((struct s3c24xx_pcm_dma_params *) 283 int channel = ((struct s3c_dma_params *)
284 rtd->dai->cpu_dai->dma_data)->channel; 284 rtd->dai->cpu_dai->dma_data)->channel;
285 285
286 pr_debug("Entered %s\n", __func__); 286 pr_debug("Entered %s\n", __func__);
diff --git a/sound/soc/s3c24xx/s3c24xx_simtec.c b/sound/soc/s3c24xx/s3c24xx_simtec.c
index 1966e0d5652d..d441c3b64631 100644
--- a/sound/soc/s3c24xx/s3c24xx_simtec.c
+++ b/sound/soc/s3c24xx/s3c24xx_simtec.c
@@ -21,7 +21,7 @@
21 21
22#include <plat/audio-simtec.h> 22#include <plat/audio-simtec.h>
23 23
24#include "s3c24xx-pcm.h" 24#include "s3c-dma.h"
25#include "s3c24xx-i2s.h" 25#include "s3c24xx-i2s.h"
26#include "s3c24xx_simtec.h" 26#include "s3c24xx_simtec.h"
27 27
@@ -270,7 +270,7 @@ static int attach_gpio_amp(struct device *dev,
270 gpio_direction_output(pd->amp_gain[1], 0); 270 gpio_direction_output(pd->amp_gain[1], 0);
271 } 271 }
272 272
273 /* note, curently we assume GPA0 isn't valid amp */ 273 /* note, currently we assume GPA0 isn't valid amp */
274 if (pdata->amp_gpio > 0) { 274 if (pdata->amp_gpio > 0) {
275 ret = gpio_request(pd->amp_gpio, "gpio-amp"); 275 ret = gpio_request(pd->amp_gpio, "gpio-amp");
276 if (ret) { 276 if (ret) {
diff --git a/sound/soc/s3c24xx/s3c24xx_simtec_hermes.c b/sound/soc/s3c24xx/s3c24xx_simtec_hermes.c
index 8346bd96eaf5..bdf8951af8e3 100644
--- a/sound/soc/s3c24xx/s3c24xx_simtec_hermes.c
+++ b/sound/soc/s3c24xx/s3c24xx_simtec_hermes.c
@@ -18,7 +18,7 @@
18 18
19#include <plat/audio-simtec.h> 19#include <plat/audio-simtec.h>
20 20
21#include "s3c24xx-pcm.h" 21#include "s3c-dma.h"
22#include "s3c24xx-i2s.h" 22#include "s3c24xx-i2s.h"
23#include "s3c24xx_simtec.h" 23#include "s3c24xx_simtec.h"
24 24
diff --git a/sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c b/sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c
index 25797e096175..185c0acb5ce6 100644
--- a/sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c
+++ b/sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c
@@ -18,7 +18,7 @@
18 18
19#include <plat/audio-simtec.h> 19#include <plat/audio-simtec.h>
20 20
21#include "s3c24xx-pcm.h" 21#include "s3c-dma.h"
22#include "s3c24xx-i2s.h" 22#include "s3c24xx-i2s.h"
23#include "s3c24xx_simtec.h" 23#include "s3c24xx_simtec.h"
24 24
diff --git a/sound/soc/s3c24xx/s3c24xx_uda134x.c b/sound/soc/s3c24xx/s3c24xx_uda134x.c
index c215d32d6322..052d59659c29 100644
--- a/sound/soc/s3c24xx/s3c24xx_uda134x.c
+++ b/sound/soc/s3c24xx/s3c24xx_uda134x.c
@@ -24,7 +24,7 @@
24 24
25#include <plat/regs-iis.h> 25#include <plat/regs-iis.h>
26 26
27#include "s3c24xx-pcm.h" 27#include "s3c-dma.h"
28#include "s3c24xx-i2s.h" 28#include "s3c24xx-i2s.h"
29#include "../codecs/uda134x.h" 29#include "../codecs/uda134x.h"
30 30
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s.c b/sound/soc/s3c24xx/s3c64xx-i2s.c
index 105a77eeded0..cc7edb5f792d 100644
--- a/sound/soc/s3c24xx/s3c64xx-i2s.c
+++ b/sound/soc/s3c24xx/s3c64xx-i2s.c
@@ -31,12 +31,11 @@
31#include <plat/gpio-bank-d.h> 31#include <plat/gpio-bank-d.h>
32#include <plat/gpio-bank-e.h> 32#include <plat/gpio-bank-e.h>
33#include <plat/gpio-cfg.h> 33#include <plat/gpio-cfg.h>
34#include <plat/audio.h>
35 34
36#include <mach/map.h> 35#include <mach/map.h>
37#include <mach/dma.h> 36#include <mach/dma.h>
38 37
39#include "s3c24xx-pcm.h" 38#include "s3c-dma.h"
40#include "s3c64xx-i2s.h" 39#include "s3c64xx-i2s.h"
41 40
42static struct s3c2410_dma_client s3c64xx_dma_client_out = { 41static struct s3c2410_dma_client s3c64xx_dma_client_out = {
@@ -47,7 +46,7 @@ static struct s3c2410_dma_client s3c64xx_dma_client_in = {
47 .name = "I2S PCM Stereo in" 46 .name = "I2S PCM Stereo in"
48}; 47};
49 48
50static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_out[2] = { 49static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[2] = {
51 [0] = { 50 [0] = {
52 .channel = DMACH_I2S0_OUT, 51 .channel = DMACH_I2S0_OUT,
53 .client = &s3c64xx_dma_client_out, 52 .client = &s3c64xx_dma_client_out,
@@ -62,7 +61,7 @@ static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_out[2] = {
62 }, 61 },
63}; 62};
64 63
65static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_in[2] = { 64static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[2] = {
66 [0] = { 65 [0] = {
67 .channel = DMACH_I2S0_IN, 66 .channel = DMACH_I2S0_IN,
68 .client = &s3c64xx_dma_client_in, 67 .client = &s3c64xx_dma_client_in,
@@ -99,6 +98,19 @@ static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
99 iismod |= S3C64XX_IISMOD_IMS_SYSMUX; 98 iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
100 break; 99 break;
101 100
101 case S3C64XX_CLKSRC_CDCLK:
102 switch (dir) {
103 case SND_SOC_CLOCK_IN:
104 iismod |= S3C64XX_IISMOD_CDCLKCON;
105 break;
106 case SND_SOC_CLOCK_OUT:
107 iismod &= ~S3C64XX_IISMOD_CDCLKCON;
108 break;
109 default:
110 return -EINVAL;
111 }
112 break;
113
102 default: 114 default:
103 return -EINVAL; 115 return -EINVAL;
104 } 116 }
@@ -111,8 +123,12 @@ static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
111struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai) 123struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
112{ 124{
113 struct s3c_i2sv2_info *i2s = to_info(dai); 125 struct s3c_i2sv2_info *i2s = to_info(dai);
126 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
114 127
115 return i2s->iis_cclk; 128 if (iismod & S3C64XX_IISMOD_IMS_SYSMUX)
129 return i2s->iis_cclk;
130 else
131 return i2s->iis_pclk;
116} 132}
117EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock); 133EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
118 134
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s.h b/sound/soc/s3c24xx/s3c64xx-i2s.h
index 02148cee2613..abe7253b55fc 100644
--- a/sound/soc/s3c24xx/s3c64xx-i2s.h
+++ b/sound/soc/s3c24xx/s3c64xx-i2s.h
@@ -25,6 +25,7 @@ struct clk;
25 25
26#define S3C64XX_CLKSRC_PCLK (0) 26#define S3C64XX_CLKSRC_PCLK (0)
27#define S3C64XX_CLKSRC_MUX (1) 27#define S3C64XX_CLKSRC_MUX (1)
28#define S3C64XX_CLKSRC_CDCLK (2)
28 29
29extern struct snd_soc_dai s3c64xx_i2s_dai[]; 30extern struct snd_soc_dai s3c64xx_i2s_dai[];
30 31
diff --git a/sound/soc/s3c24xx/smdk2443_wm9710.c b/sound/soc/s3c24xx/smdk2443_wm9710.c
index a2a4f5323c17..12b783b12fcb 100644
--- a/sound/soc/s3c24xx/smdk2443_wm9710.c
+++ b/sound/soc/s3c24xx/smdk2443_wm9710.c
@@ -20,7 +20,7 @@
20#include <sound/soc-dapm.h> 20#include <sound/soc-dapm.h>
21 21
22#include "../codecs/ac97.h" 22#include "../codecs/ac97.h"
23#include "s3c24xx-pcm.h" 23#include "s3c-dma.h"
24#include "s3c24xx-ac97.h" 24#include "s3c24xx-ac97.h"
25 25
26static struct snd_soc_card smdk2443; 26static struct snd_soc_card smdk2443;
diff --git a/sound/soc/s3c24xx/smdk64xx_wm8580.c b/sound/soc/s3c24xx/smdk64xx_wm8580.c
new file mode 100644
index 000000000000..efe4901213a3
--- /dev/null
+++ b/sound/soc/s3c24xx/smdk64xx_wm8580.c
@@ -0,0 +1,268 @@
1/*
2 * smdk64xx_wm8580.c
3 *
4 * Copyright (c) 2009 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassi.brar@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/platform_device.h>
14#include <linux/clk.h>
15#include <sound/core.h>
16#include <sound/pcm.h>
17#include <sound/pcm_params.h>
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20
21#include "../codecs/wm8580.h"
22#include "s3c-dma.h"
23#include "s3c64xx-i2s.h"
24
25#define S3C64XX_I2S_V4 2
26
27/* SMDK64XX has a 12MHZ crystal attached to WM8580 */
28#define SMDK64XX_WM8580_FREQ 12000000
29
30static int smdk64xx_hw_params(struct snd_pcm_substream *substream,
31 struct snd_pcm_hw_params *params)
32{
33 struct snd_soc_pcm_runtime *rtd = substream->private_data;
34 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
35 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
36 unsigned int pll_out;
37 int bfs, rfs, ret;
38
39 switch (params_format(params)) {
40 case SNDRV_PCM_FORMAT_U8:
41 case SNDRV_PCM_FORMAT_S8:
42 bfs = 16;
43 break;
44 case SNDRV_PCM_FORMAT_U16_LE:
45 case SNDRV_PCM_FORMAT_S16_LE:
46 bfs = 32;
47 break;
48 default:
49 return -EINVAL;
50 }
51
52 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
53 * This criterion can't be met if we request PLL output
54 * as {8000x256, 64000x256, 11025x256}Hz.
55 * As a wayout, we rather change rfs to a minimum value that
56 * results in (params_rate(params) * rfs), and itself, acceptable
57 * to both - the CODEC and the CPU.
58 */
59 switch (params_rate(params)) {
60 case 16000:
61 case 22050:
62 case 32000:
63 case 44100:
64 case 48000:
65 case 88200:
66 case 96000:
67 rfs = 256;
68 break;
69 case 64000:
70 rfs = 384;
71 break;
72 case 8000:
73 case 11025:
74 rfs = 512;
75 break;
76 default:
77 return -EINVAL;
78 }
79 pll_out = params_rate(params) * rfs;
80
81 /* Set the Codec DAI configuration */
82 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
83 | SND_SOC_DAIFMT_NB_NF
84 | SND_SOC_DAIFMT_CBM_CFM);
85 if (ret < 0)
86 return ret;
87
88 /* Set the AP DAI configuration */
89 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
90 | SND_SOC_DAIFMT_NB_NF
91 | SND_SOC_DAIFMT_CBM_CFM);
92 if (ret < 0)
93 return ret;
94
95 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_CDCLK,
96 0, SND_SOC_CLOCK_IN);
97 if (ret < 0)
98 return ret;
99
100 /* We use PCLK for basic ops in SoC-Slave mode */
101 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
102 0, SND_SOC_CLOCK_IN);
103 if (ret < 0)
104 return ret;
105
106 /* Set WM8580 to drive MCLK from its PLLA */
107 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
108 WM8580_CLKSRC_PLLA);
109 if (ret < 0)
110 return ret;
111
112 /* Explicitly set WM8580-DAC to source from MCLK */
113 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_DAC_CLKSEL,
114 WM8580_CLKSRC_MCLK);
115 if (ret < 0)
116 return ret;
117
118 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
119 SMDK64XX_WM8580_FREQ, pll_out);
120 if (ret < 0)
121 return ret;
122
123 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_BCLK, bfs);
124 if (ret < 0)
125 return ret;
126
127 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, rfs);
128 if (ret < 0)
129 return ret;
130
131 return 0;
132}
133
134/*
135 * SMDK64XX WM8580 DAI operations.
136 */
137static struct snd_soc_ops smdk64xx_ops = {
138 .hw_params = smdk64xx_hw_params,
139};
140
141/* SMDK64xx Playback widgets */
142static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
143 SND_SOC_DAPM_HP("Front-L/R", NULL),
144 SND_SOC_DAPM_HP("Center/Sub", NULL),
145 SND_SOC_DAPM_HP("Rear-L/R", NULL),
146};
147
148/* SMDK64xx Capture widgets */
149static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
150 SND_SOC_DAPM_MIC("MicIn", NULL),
151 SND_SOC_DAPM_LINE("LineIn", NULL),
152};
153
154/* SMDK-PAIFTX connections */
155static const struct snd_soc_dapm_route audio_map_tx[] = {
156 /* MicIn feeds AINL */
157 {"AINL", NULL, "MicIn"},
158
159 /* LineIn feeds AINL/R */
160 {"AINL", NULL, "LineIn"},
161 {"AINR", NULL, "LineIn"},
162};
163
164/* SMDK-PAIFRX connections */
165static const struct snd_soc_dapm_route audio_map_rx[] = {
166 /* Front Left/Right are fed VOUT1L/R */
167 {"Front-L/R", NULL, "VOUT1L"},
168 {"Front-L/R", NULL, "VOUT1R"},
169
170 /* Center/Sub are fed VOUT2L/R */
171 {"Center/Sub", NULL, "VOUT2L"},
172 {"Center/Sub", NULL, "VOUT2R"},
173
174 /* Rear Left/Right are fed VOUT3L/R */
175 {"Rear-L/R", NULL, "VOUT3L"},
176 {"Rear-L/R", NULL, "VOUT3R"},
177};
178
179static int smdk64xx_wm8580_init_paiftx(struct snd_soc_codec *codec)
180{
181 /* Add smdk64xx specific Capture widgets */
182 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_cpt,
183 ARRAY_SIZE(wm8580_dapm_widgets_cpt));
184
185 /* Set up PAIFTX audio path */
186 snd_soc_dapm_add_routes(codec, audio_map_tx, ARRAY_SIZE(audio_map_tx));
187
188 /* Enabling the microphone requires the fitting of a 0R
189 * resistor to connect the line from the microphone jack.
190 */
191 snd_soc_dapm_disable_pin(codec, "MicIn");
192
193 /* signal a DAPM event */
194 snd_soc_dapm_sync(codec);
195
196 return 0;
197}
198
199static int smdk64xx_wm8580_init_paifrx(struct snd_soc_codec *codec)
200{
201 /* Add smdk64xx specific Playback widgets */
202 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_pbk,
203 ARRAY_SIZE(wm8580_dapm_widgets_pbk));
204
205 /* Set up PAIFRX audio path */
206 snd_soc_dapm_add_routes(codec, audio_map_rx, ARRAY_SIZE(audio_map_rx));
207
208 /* signal a DAPM event */
209 snd_soc_dapm_sync(codec);
210
211 return 0;
212}
213
214static struct snd_soc_dai_link smdk64xx_dai[] = {
215{ /* Primary Playback i/f */
216 .name = "WM8580 PAIF RX",
217 .stream_name = "Playback",
218 .cpu_dai = &s3c64xx_i2s_dai[S3C64XX_I2S_V4],
219 .codec_dai = &wm8580_dai[WM8580_DAI_PAIFRX],
220 .init = smdk64xx_wm8580_init_paifrx,
221 .ops = &smdk64xx_ops,
222},
223{ /* Primary Capture i/f */
224 .name = "WM8580 PAIF TX",
225 .stream_name = "Capture",
226 .cpu_dai = &s3c64xx_i2s_dai[S3C64XX_I2S_V4],
227 .codec_dai = &wm8580_dai[WM8580_DAI_PAIFTX],
228 .init = smdk64xx_wm8580_init_paiftx,
229 .ops = &smdk64xx_ops,
230},
231};
232
233static struct snd_soc_card smdk64xx = {
234 .name = "smdk64xx",
235 .platform = &s3c24xx_soc_platform,
236 .dai_link = smdk64xx_dai,
237 .num_links = ARRAY_SIZE(smdk64xx_dai),
238};
239
240static struct snd_soc_device smdk64xx_snd_devdata = {
241 .card = &smdk64xx,
242 .codec_dev = &soc_codec_dev_wm8580,
243};
244
245static struct platform_device *smdk64xx_snd_device;
246
247static int __init smdk64xx_audio_init(void)
248{
249 int ret;
250
251 smdk64xx_snd_device = platform_device_alloc("soc-audio", -1);
252 if (!smdk64xx_snd_device)
253 return -ENOMEM;
254
255 platform_set_drvdata(smdk64xx_snd_device, &smdk64xx_snd_devdata);
256 smdk64xx_snd_devdata.dev = &smdk64xx_snd_device->dev;
257 ret = platform_device_add(smdk64xx_snd_device);
258
259 if (ret)
260 platform_device_put(smdk64xx_snd_device);
261
262 return ret;
263}
264module_init(smdk64xx_audio_init);
265
266MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
267MODULE_DESCRIPTION("ALSA SoC SMDK64XX WM8580");
268MODULE_LICENSE("GPL");
diff --git a/sound/soc/s6000/s6000-pcm.c b/sound/soc/s6000/s6000-pcm.c
index 83b8028e209d..1d61109e09fa 100644
--- a/sound/soc/s6000/s6000-pcm.c
+++ b/sound/soc/s6000/s6000-pcm.c
@@ -196,7 +196,7 @@ static int s6000_pcm_start(struct snd_pcm_substream *substream)
196 0 /* destination skip after chunk (impossible) */, 196 0 /* destination skip after chunk (impossible) */,
197 4 /* 16 byte burst size */, 197 4 /* 16 byte burst size */,
198 -1 /* don't conserve bandwidth */, 198 -1 /* don't conserve bandwidth */,
199 0 /* low watermark irq descriptor theshold */, 199 0 /* low watermark irq descriptor threshold */,
200 0 /* disable hardware timestamps */, 200 0 /* disable hardware timestamps */,
201 1 /* enable channel */); 201 1 /* enable channel */);
202 202
@@ -423,7 +423,7 @@ static void s6000_pcm_free(struct snd_pcm *pcm)
423 snd_pcm_lib_preallocate_free_for_all(pcm); 423 snd_pcm_lib_preallocate_free_for_all(pcm);
424} 424}
425 425
426static u64 s6000_pcm_dmamask = DMA_32BIT_MASK; 426static u64 s6000_pcm_dmamask = DMA_BIT_MASK(32);
427 427
428static int s6000_pcm_new(struct snd_card *card, 428static int s6000_pcm_new(struct snd_card *card,
429 struct snd_soc_dai *dai, struct snd_pcm *pcm) 429 struct snd_soc_dai *dai, struct snd_pcm *pcm)
@@ -435,7 +435,7 @@ static int s6000_pcm_new(struct snd_card *card,
435 if (!card->dev->dma_mask) 435 if (!card->dev->dma_mask)
436 card->dev->dma_mask = &s6000_pcm_dmamask; 436 card->dev->dma_mask = &s6000_pcm_dmamask;
437 if (!card->dev->coherent_dma_mask) 437 if (!card->dev->coherent_dma_mask)
438 card->dev->coherent_dma_mask = DMA_32BIT_MASK; 438 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
439 439
440 if (params->dma_in) { 440 if (params->dma_in) {
441 s6dmac_disable_chan(DMA_MASK_DMAC(params->dma_in), 441 s6dmac_disable_chan(DMA_MASK_DMAC(params->dma_in),
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index 9154b4363db3..9e6976586554 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -23,7 +23,6 @@ config SND_SOC_SH4_SSI
23config SND_SOC_SH4_FSI 23config SND_SOC_SH4_FSI
24 tristate "SH4 FSI support" 24 tristate "SH4 FSI support"
25 depends on CPU_SUBTYPE_SH7724 25 depends on CPU_SUBTYPE_SH7724
26 select SH_DMA
27 help 26 help
28 This option enables FSI sound support 27 This option enables FSI sound support
29 28
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 44123248b630..9c49c11c43ce 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -17,7 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/list.h> 19#include <linux/list.h>
20#include <linux/clk.h> 20#include <linux/pm_runtime.h>
21#include <linux/io.h> 21#include <linux/io.h>
22#include <sound/core.h> 22#include <sound/core.h>
23#include <sound/pcm.h> 23#include <sound/pcm.h>
@@ -26,8 +26,6 @@
26#include <sound/pcm_params.h> 26#include <sound/pcm_params.h>
27#include <sound/sh_fsi.h> 27#include <sound/sh_fsi.h>
28#include <asm/atomic.h> 28#include <asm/atomic.h>
29#include <asm/dma.h>
30#include <asm/dma-sh.h>
31 29
32#define DO_FMT 0x0000 30#define DO_FMT 0x0000
33#define DOFF_CTL 0x0004 31#define DOFF_CTL 0x0004
@@ -97,7 +95,6 @@ struct fsi_priv {
97 95
98 int fifo_max; 96 int fifo_max;
99 int chan; 97 int chan;
100 int dma_chan;
101 98
102 int byte_offset; 99 int byte_offset;
103 int period_len; 100 int period_len;
@@ -108,7 +105,6 @@ struct fsi_priv {
108struct fsi_master { 105struct fsi_master {
109 void __iomem *base; 106 void __iomem *base;
110 int irq; 107 int irq;
111 struct clk *clk;
112 struct fsi_priv fsia; 108 struct fsi_priv fsia;
113 struct fsi_priv fsib; 109 struct fsi_priv fsib;
114 struct sh_fsi_platform_info *info; 110 struct sh_fsi_platform_info *info;
@@ -308,62 +304,6 @@ static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play)
308 return residue; 304 return residue;
309} 305}
310 306
311static int fsi_get_residue(struct fsi_priv *fsi, int is_play)
312{
313 int residue;
314 int width;
315 struct snd_pcm_runtime *runtime;
316
317 runtime = fsi->substream->runtime;
318
319 /* get 1 channel data width */
320 width = frames_to_bytes(runtime, 1) / fsi->chan;
321
322 if (2 == width)
323 residue = fsi_get_fifo_residue(fsi, is_play);
324 else
325 residue = get_dma_residue(fsi->dma_chan);
326
327 return residue;
328}
329
330/************************************************************************
331
332
333 basic dma function
334
335
336************************************************************************/
337#define PORTA_DMA 0
338#define PORTB_DMA 1
339
340static int fsi_get_dma_chan(void)
341{
342 if (0 != request_dma(PORTA_DMA, "fsia"))
343 return -EIO;
344
345 if (0 != request_dma(PORTB_DMA, "fsib")) {
346 free_dma(PORTA_DMA);
347 return -EIO;
348 }
349
350 master->fsia.dma_chan = PORTA_DMA;
351 master->fsib.dma_chan = PORTB_DMA;
352
353 return 0;
354}
355
356static void fsi_free_dma_chan(void)
357{
358 dma_wait_for_completion(PORTA_DMA);
359 dma_wait_for_completion(PORTB_DMA);
360 free_dma(PORTA_DMA);
361 free_dma(PORTB_DMA);
362
363 master->fsia.dma_chan = -1;
364 master->fsib.dma_chan = -1;
365}
366
367/************************************************************************ 307/************************************************************************
368 308
369 309
@@ -435,44 +375,6 @@ static void fsi_soft_all_reset(void)
435 mdelay(10); 375 mdelay(10);
436} 376}
437 377
438static void fsi_16data_push(struct fsi_priv *fsi,
439 struct snd_pcm_runtime *runtime,
440 int send)
441{
442 u16 *dma_start;
443 u32 snd;
444 int i;
445
446 /* get dma start position for FSI */
447 dma_start = (u16 *)runtime->dma_area;
448 dma_start += fsi->byte_offset / 2;
449
450 /*
451 * soft dma
452 * FSI can not use DMA when 16bpp
453 */
454 for (i = 0; i < send; i++) {
455 snd = (u32)dma_start[i];
456 fsi_reg_write(fsi, DODT, snd << 8);
457 }
458}
459
460static void fsi_32data_push(struct fsi_priv *fsi,
461 struct snd_pcm_runtime *runtime,
462 int send)
463{
464 u32 *dma_start;
465
466 /* get dma start position for FSI */
467 dma_start = (u32 *)runtime->dma_area;
468 dma_start += fsi->byte_offset / 4;
469
470 dma_wait_for_completion(fsi->dma_chan);
471 dma_configure_channel(fsi->dma_chan, (SM_INC|0x400|TS_32|TM_BUR));
472 dma_write(fsi->dma_chan, (u32)dma_start,
473 (u32)(fsi->base + DODT), send * 4);
474}
475
476/* playback interrupt */ 378/* playback interrupt */
477static int fsi_data_push(struct fsi_priv *fsi) 379static int fsi_data_push(struct fsi_priv *fsi)
478{ 380{
@@ -481,6 +383,8 @@ static int fsi_data_push(struct fsi_priv *fsi)
481 int send; 383 int send;
482 int fifo_free; 384 int fifo_free;
483 int width; 385 int width;
386 u8 *start;
387 int i;
484 388
485 if (!fsi || 389 if (!fsi ||
486 !fsi->substream || 390 !fsi->substream ||
@@ -515,12 +419,22 @@ static int fsi_data_push(struct fsi_priv *fsi)
515 if (fifo_free < send) 419 if (fifo_free < send)
516 send = fifo_free; 420 send = fifo_free;
517 421
518 if (2 == width) 422 start = runtime->dma_area;
519 fsi_16data_push(fsi, runtime, send); 423 start += fsi->byte_offset;
520 else if (4 == width) 424
521 fsi_32data_push(fsi, runtime, send); 425 switch (width) {
522 else 426 case 2:
427 for (i = 0; i < send; i++)
428 fsi_reg_write(fsi, DODT,
429 ((u32)*((u16 *)start + i) << 8));
430 break;
431 case 4:
432 for (i = 0; i < send; i++)
433 fsi_reg_write(fsi, DODT, *((u32 *)start + i));
434 break;
435 default:
523 return -EINVAL; 436 return -EINVAL;
437 }
524 438
525 fsi->byte_offset += send * width; 439 fsi->byte_offset += send * width;
526 440
@@ -532,6 +446,75 @@ static int fsi_data_push(struct fsi_priv *fsi)
532 return 0; 446 return 0;
533} 447}
534 448
449static int fsi_data_pop(struct fsi_priv *fsi)
450{
451 struct snd_pcm_runtime *runtime;
452 struct snd_pcm_substream *substream = NULL;
453 int free;
454 int fifo_fill;
455 int width;
456 u8 *start;
457 int i;
458
459 if (!fsi ||
460 !fsi->substream ||
461 !fsi->substream->runtime)
462 return -EINVAL;
463
464 runtime = fsi->substream->runtime;
465
466 /* FSI FIFO has limit.
467 * So, this driver can not send periods data at a time
468 */
469 if (fsi->byte_offset >=
470 fsi->period_len * (fsi->periods + 1)) {
471
472 substream = fsi->substream;
473 fsi->periods = (fsi->periods + 1) % runtime->periods;
474
475 if (0 == fsi->periods)
476 fsi->byte_offset = 0;
477 }
478
479 /* get 1 channel data width */
480 width = frames_to_bytes(runtime, 1) / fsi->chan;
481
482 /* get free space for alsa */
483 free = (fsi->buffer_len - fsi->byte_offset) / width;
484
485 /* get recv size */
486 fifo_fill = fsi_get_fifo_residue(fsi, 0);
487
488 if (free < fifo_fill)
489 fifo_fill = free;
490
491 start = runtime->dma_area;
492 start += fsi->byte_offset;
493
494 switch (width) {
495 case 2:
496 for (i = 0; i < fifo_fill; i++)
497 *((u16 *)start + i) =
498 (u16)(fsi_reg_read(fsi, DIDT) >> 8);
499 break;
500 case 4:
501 for (i = 0; i < fifo_fill; i++)
502 *((u32 *)start + i) = fsi_reg_read(fsi, DIDT);
503 break;
504 default:
505 return -EINVAL;
506 }
507
508 fsi->byte_offset += fifo_fill * width;
509
510 fsi_irq_enable(fsi, 0);
511
512 if (substream)
513 snd_pcm_period_elapsed(substream);
514
515 return 0;
516}
517
535static irqreturn_t fsi_interrupt(int irq, void *data) 518static irqreturn_t fsi_interrupt(int irq, void *data)
536{ 519{
537 u32 status = fsi_master_read(SOFT_RST) & ~0x00000010; 520 u32 status = fsi_master_read(SOFT_RST) & ~0x00000010;
@@ -545,6 +528,10 @@ static irqreturn_t fsi_interrupt(int irq, void *data)
545 fsi_data_push(&master->fsia); 528 fsi_data_push(&master->fsia);
546 if (int_st & INT_B_OUT) 529 if (int_st & INT_B_OUT)
547 fsi_data_push(&master->fsib); 530 fsi_data_push(&master->fsib);
531 if (int_st & INT_A_IN)
532 fsi_data_pop(&master->fsia);
533 if (int_st & INT_B_IN)
534 fsi_data_pop(&master->fsib);
548 535
549 fsi_master_write(INT_ST, 0x0000000); 536 fsi_master_write(INT_ST, 0x0000000);
550 537
@@ -571,7 +558,7 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
571 int is_master; 558 int is_master;
572 int ret = 0; 559 int ret = 0;
573 560
574 clk_enable(master->clk); 561 pm_runtime_get_sync(dai->dev);
575 562
576 /* CKG1 */ 563 /* CKG1 */
577 data = is_play ? (1 << 0) : (1 << 4); 564 data = is_play ? (1 << 0) : (1 << 4);
@@ -664,8 +651,6 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
664 } 651 }
665 652
666 fsi_reg_write(fsi, reg, data); 653 fsi_reg_write(fsi, reg, data);
667 dev_dbg(dai->dev, "use %s format (%d channel) use %d DMAC\n",
668 msg, fsi->chan, fsi->dma_chan);
669 654
670 /* 655 /*
671 * clear clk reset if master mode 656 * clear clk reset if master mode
@@ -688,7 +673,7 @@ static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
688 fsi_irq_disable(fsi, is_play); 673 fsi_irq_disable(fsi, is_play);
689 fsi_clk_ctrl(fsi, 0); 674 fsi_clk_ctrl(fsi, 0);
690 675
691 clk_disable(master->clk); 676 pm_runtime_put_sync(dai->dev);
692} 677}
693 678
694static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, 679static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
@@ -699,16 +684,12 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
699 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 684 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
700 int ret = 0; 685 int ret = 0;
701 686
702 /* capture not supported */
703 if (!is_play)
704 return -ENODEV;
705
706 switch (cmd) { 687 switch (cmd) {
707 case SNDRV_PCM_TRIGGER_START: 688 case SNDRV_PCM_TRIGGER_START:
708 fsi_stream_push(fsi, substream, 689 fsi_stream_push(fsi, substream,
709 frames_to_bytes(runtime, runtime->buffer_size), 690 frames_to_bytes(runtime, runtime->buffer_size),
710 frames_to_bytes(runtime, runtime->period_size)); 691 frames_to_bytes(runtime, runtime->period_size));
711 ret = fsi_data_push(fsi); 692 ret = is_play ? fsi_data_push(fsi) : fsi_data_pop(fsi);
712 break; 693 break;
713 case SNDRV_PCM_TRIGGER_STOP: 694 case SNDRV_PCM_TRIGGER_STOP:
714 fsi_irq_disable(fsi, is_play); 695 fsi_irq_disable(fsi, is_play);
@@ -780,10 +761,9 @@ static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
780{ 761{
781 struct snd_pcm_runtime *runtime = substream->runtime; 762 struct snd_pcm_runtime *runtime = substream->runtime;
782 struct fsi_priv *fsi = fsi_get(substream); 763 struct fsi_priv *fsi = fsi_get(substream);
783 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
784 long location; 764 long location;
785 765
786 location = (fsi->byte_offset - 1) - fsi_get_residue(fsi, is_play); 766 location = (fsi->byte_offset - 1);
787 if (location < 0) 767 if (location < 0)
788 location = 0; 768 location = 0;
789 769
@@ -845,7 +825,12 @@ struct snd_soc_dai fsi_soc_dai[] = {
845 .channels_min = 1, 825 .channels_min = 1,
846 .channels_max = 8, 826 .channels_max = 8,
847 }, 827 },
848 /* capture not supported */ 828 .capture = {
829 .rates = FSI_RATES,
830 .formats = FSI_FMTS,
831 .channels_min = 1,
832 .channels_max = 8,
833 },
849 .ops = &fsi_dai_ops, 834 .ops = &fsi_dai_ops,
850 }, 835 },
851 { 836 {
@@ -857,7 +842,12 @@ struct snd_soc_dai fsi_soc_dai[] = {
857 .channels_min = 1, 842 .channels_min = 1,
858 .channels_max = 8, 843 .channels_max = 8,
859 }, 844 },
860 /* capture not supported */ 845 .capture = {
846 .rates = FSI_RATES,
847 .formats = FSI_FMTS,
848 .channels_min = 1,
849 .channels_max = 8,
850 },
861 .ops = &fsi_dai_ops, 851 .ops = &fsi_dai_ops,
862 }, 852 },
863}; 853};
@@ -881,7 +871,6 @@ EXPORT_SYMBOL_GPL(fsi_soc_platform);
881static int fsi_probe(struct platform_device *pdev) 871static int fsi_probe(struct platform_device *pdev)
882{ 872{
883 struct resource *res; 873 struct resource *res;
884 char clk_name[8];
885 unsigned int irq; 874 unsigned int irq;
886 int ret; 875 int ret;
887 876
@@ -912,23 +901,8 @@ static int fsi_probe(struct platform_device *pdev)
912 master->fsia.base = master->base; 901 master->fsia.base = master->base;
913 master->fsib.base = master->base + 0x40; 902 master->fsib.base = master->base + 0x40;
914 903
915 master->fsia.dma_chan = -1; 904 pm_runtime_enable(&pdev->dev);
916 master->fsib.dma_chan = -1; 905 pm_runtime_resume(&pdev->dev);
917
918 ret = fsi_get_dma_chan();
919 if (ret < 0) {
920 dev_err(&pdev->dev, "cannot get dma api\n");
921 goto exit_iounmap;
922 }
923
924 /* FSI is based on SPU mstp */
925 snprintf(clk_name, sizeof(clk_name), "spu%d", pdev->id);
926 master->clk = clk_get(NULL, clk_name);
927 if (IS_ERR(master->clk)) {
928 dev_err(&pdev->dev, "cannot get %s mstp\n", clk_name);
929 ret = -EIO;
930 goto exit_free_dma;
931 }
932 906
933 fsi_soc_dai[0].dev = &pdev->dev; 907 fsi_soc_dai[0].dev = &pdev->dev;
934 fsi_soc_dai[1].dev = &pdev->dev; 908 fsi_soc_dai[1].dev = &pdev->dev;
@@ -938,7 +912,7 @@ static int fsi_probe(struct platform_device *pdev)
938 ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED, "fsi", master); 912 ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED, "fsi", master);
939 if (ret) { 913 if (ret) {
940 dev_err(&pdev->dev, "irq request err\n"); 914 dev_err(&pdev->dev, "irq request err\n");
941 goto exit_free_dma; 915 goto exit_iounmap;
942 } 916 }
943 917
944 ret = snd_soc_register_platform(&fsi_soc_platform); 918 ret = snd_soc_register_platform(&fsi_soc_platform);
@@ -951,10 +925,9 @@ static int fsi_probe(struct platform_device *pdev)
951 925
952exit_free_irq: 926exit_free_irq:
953 free_irq(irq, master); 927 free_irq(irq, master);
954exit_free_dma:
955 fsi_free_dma_chan();
956exit_iounmap: 928exit_iounmap:
957 iounmap(master->base); 929 iounmap(master->base);
930 pm_runtime_disable(&pdev->dev);
958exit_kfree: 931exit_kfree:
959 kfree(master); 932 kfree(master);
960 master = NULL; 933 master = NULL;
@@ -967,9 +940,7 @@ static int fsi_remove(struct platform_device *pdev)
967 snd_soc_unregister_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai)); 940 snd_soc_unregister_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai));
968 snd_soc_unregister_platform(&fsi_soc_platform); 941 snd_soc_unregister_platform(&fsi_soc_platform);
969 942
970 clk_put(master->clk); 943 pm_runtime_disable(&pdev->dev);
971
972 fsi_free_dma_chan();
973 944
974 free_irq(master->irq, master); 945 free_irq(master->irq, master);
975 946
@@ -979,9 +950,27 @@ static int fsi_remove(struct platform_device *pdev)
979 return 0; 950 return 0;
980} 951}
981 952
953static int fsi_runtime_nop(struct device *dev)
954{
955 /* Runtime PM callback shared between ->runtime_suspend()
956 * and ->runtime_resume(). Simply returns success.
957 *
958 * This driver re-initializes all registers after
959 * pm_runtime_get_sync() anyway so there is no need
960 * to save and restore registers here.
961 */
962 return 0;
963}
964
965static struct dev_pm_ops fsi_pm_ops = {
966 .runtime_suspend = fsi_runtime_nop,
967 .runtime_resume = fsi_runtime_nop,
968};
969
982static struct platform_driver fsi_driver = { 970static struct platform_driver fsi_driver = {
983 .driver = { 971 .driver = {
984 .name = "sh_fsi", 972 .name = "sh_fsi",
973 .pm = &fsi_pm_ops,
985 }, 974 },
986 .probe = fsi_probe, 975 .probe = fsi_probe,
987 .remove = fsi_remove, 976 .remove = fsi_remove,
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index c8ceddc2a26c..d2505e8b06c9 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -77,6 +77,35 @@ static int snd_soc_7_9_spi_write(void *control_data, const char *data,
77#define snd_soc_7_9_spi_write NULL 77#define snd_soc_7_9_spi_write NULL
78#endif 78#endif
79 79
80static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
81 unsigned int value)
82{
83 u8 *cache = codec->reg_cache;
84 u8 data[2];
85
86 BUG_ON(codec->volatile_register);
87
88 data[0] = reg & 0xff;
89 data[1] = value & 0xff;
90
91 if (reg < codec->reg_cache_size)
92 cache[reg] = value;
93
94 if (codec->hw_write(codec->control_data, data, 2) == 2)
95 return 0;
96 else
97 return -EIO;
98}
99
100static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
101 unsigned int reg)
102{
103 u8 *cache = codec->reg_cache;
104 if (reg >= codec->reg_cache_size)
105 return -1;
106 return cache[reg];
107}
108
80static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, 109static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
81 unsigned int value) 110 unsigned int value)
82{ 111{
@@ -150,9 +179,20 @@ static struct {
150 unsigned int (*read)(struct snd_soc_codec *, unsigned int); 179 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
151 unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); 180 unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int);
152} io_types[] = { 181} io_types[] = {
153 { 7, 9, snd_soc_7_9_write, snd_soc_7_9_spi_write, snd_soc_7_9_read }, 182 {
154 { 8, 16, snd_soc_8_16_write, NULL, snd_soc_8_16_read, 183 .addr_bits = 7, .data_bits = 9,
155 snd_soc_8_16_read_i2c }, 184 .write = snd_soc_7_9_write, .read = snd_soc_7_9_read,
185 .spi_write = snd_soc_7_9_spi_write
186 },
187 {
188 .addr_bits = 8, .data_bits = 8,
189 .write = snd_soc_8_8_write, .read = snd_soc_8_8_read,
190 },
191 {
192 .addr_bits = 8, .data_bits = 16,
193 .write = snd_soc_8_16_write, .read = snd_soc_8_16_read,
194 .i2c_read = snd_soc_8_16_read_i2c,
195 },
156}; 196};
157 197
158/** 198/**
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 0a1b2f64bbee..ef8f28284cb9 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -37,7 +37,6 @@
37#include <sound/initval.h> 37#include <sound/initval.h>
38 38
39static DEFINE_MUTEX(pcm_mutex); 39static DEFINE_MUTEX(pcm_mutex);
40static DEFINE_MUTEX(io_mutex);
41static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); 40static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
42 41
43#ifdef CONFIG_DEBUG_FS 42#ifdef CONFIG_DEBUG_FS
@@ -81,6 +80,173 @@ static int run_delayed_work(struct delayed_work *dwork)
81 return ret; 80 return ret;
82} 81}
83 82
83/* codec register dump */
84static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
85{
86 int i, step = 1, count = 0;
87
88 if (!codec->reg_cache_size)
89 return 0;
90
91 if (codec->reg_cache_step)
92 step = codec->reg_cache_step;
93
94 count += sprintf(buf, "%s registers\n", codec->name);
95 for (i = 0; i < codec->reg_cache_size; i += step) {
96 if (codec->readable_register && !codec->readable_register(i))
97 continue;
98
99 count += sprintf(buf + count, "%2x: ", i);
100 if (count >= PAGE_SIZE - 1)
101 break;
102
103 if (codec->display_register)
104 count += codec->display_register(codec, buf + count,
105 PAGE_SIZE - count, i);
106 else
107 count += snprintf(buf + count, PAGE_SIZE - count,
108 "%4x", codec->read(codec, i));
109
110 if (count >= PAGE_SIZE - 1)
111 break;
112
113 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
114 if (count >= PAGE_SIZE - 1)
115 break;
116 }
117
118 /* Truncate count; min() would cause a warning */
119 if (count >= PAGE_SIZE)
120 count = PAGE_SIZE - 1;
121
122 return count;
123}
124static ssize_t codec_reg_show(struct device *dev,
125 struct device_attribute *attr, char *buf)
126{
127 struct snd_soc_device *devdata = dev_get_drvdata(dev);
128 return soc_codec_reg_show(devdata->card->codec, buf);
129}
130
131static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
132
133#ifdef CONFIG_DEBUG_FS
134static int codec_reg_open_file(struct inode *inode, struct file *file)
135{
136 file->private_data = inode->i_private;
137 return 0;
138}
139
140static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
141 size_t count, loff_t *ppos)
142{
143 ssize_t ret;
144 struct snd_soc_codec *codec = file->private_data;
145 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
146 if (!buf)
147 return -ENOMEM;
148 ret = soc_codec_reg_show(codec, buf);
149 if (ret >= 0)
150 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
151 kfree(buf);
152 return ret;
153}
154
155static ssize_t codec_reg_write_file(struct file *file,
156 const char __user *user_buf, size_t count, loff_t *ppos)
157{
158 char buf[32];
159 int buf_size;
160 char *start = buf;
161 unsigned long reg, value;
162 int step = 1;
163 struct snd_soc_codec *codec = file->private_data;
164
165 buf_size = min(count, (sizeof(buf)-1));
166 if (copy_from_user(buf, user_buf, buf_size))
167 return -EFAULT;
168 buf[buf_size] = 0;
169
170 if (codec->reg_cache_step)
171 step = codec->reg_cache_step;
172
173 while (*start == ' ')
174 start++;
175 reg = simple_strtoul(start, &start, 16);
176 if ((reg >= codec->reg_cache_size) || (reg % step))
177 return -EINVAL;
178 while (*start == ' ')
179 start++;
180 if (strict_strtoul(start, 16, &value))
181 return -EINVAL;
182 codec->write(codec, reg, value);
183 return buf_size;
184}
185
186static const struct file_operations codec_reg_fops = {
187 .open = codec_reg_open_file,
188 .read = codec_reg_read_file,
189 .write = codec_reg_write_file,
190};
191
192static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
193{
194 char codec_root[128];
195
196 if (codec->dev)
197 snprintf(codec_root, sizeof(codec_root),
198 "%s.%s", codec->name, dev_name(codec->dev));
199 else
200 snprintf(codec_root, sizeof(codec_root),
201 "%s", codec->name);
202
203 codec->debugfs_codec_root = debugfs_create_dir(codec_root,
204 debugfs_root);
205 if (!codec->debugfs_codec_root) {
206 printk(KERN_WARNING
207 "ASoC: Failed to create codec debugfs directory\n");
208 return;
209 }
210
211 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
212 codec->debugfs_codec_root,
213 codec, &codec_reg_fops);
214 if (!codec->debugfs_reg)
215 printk(KERN_WARNING
216 "ASoC: Failed to create codec register debugfs file\n");
217
218 codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0744,
219 codec->debugfs_codec_root,
220 &codec->pop_time);
221 if (!codec->debugfs_pop_time)
222 printk(KERN_WARNING
223 "Failed to create pop time debugfs file\n");
224
225 codec->debugfs_dapm = debugfs_create_dir("dapm",
226 codec->debugfs_codec_root);
227 if (!codec->debugfs_dapm)
228 printk(KERN_WARNING
229 "Failed to create DAPM debugfs directory\n");
230
231 snd_soc_dapm_debugfs_init(codec);
232}
233
234static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
235{
236 debugfs_remove_recursive(codec->debugfs_codec_root);
237}
238
239#else
240
241static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
242{
243}
244
245static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
246{
247}
248#endif
249
84#ifdef CONFIG_SND_SOC_AC97_BUS 250#ifdef CONFIG_SND_SOC_AC97_BUS
85/* unregister ac97 codec */ 251/* unregister ac97 codec */
86static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) 252static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
@@ -790,45 +956,6 @@ static int soc_resume(struct device *dev)
790 956
791 return 0; 957 return 0;
792} 958}
793
794/**
795 * snd_soc_suspend_device: Notify core of device suspend
796 *
797 * @dev: Device being suspended.
798 *
799 * In order to ensure that the entire audio subsystem is suspended in a
800 * coordinated fashion ASoC devices should suspend themselves when
801 * called by ASoC. When the standard kernel suspend process asks the
802 * device to suspend it should call this function to initiate a suspend
803 * of the entire ASoC card.
804 *
805 * \note Currently this function is stubbed out.
806 */
807int snd_soc_suspend_device(struct device *dev)
808{
809 return 0;
810}
811EXPORT_SYMBOL_GPL(snd_soc_suspend_device);
812
813/**
814 * snd_soc_resume_device: Notify core of device resume
815 *
816 * @dev: Device being resumed.
817 *
818 * In order to ensure that the entire audio subsystem is resumed in a
819 * coordinated fashion ASoC devices should resume themselves when called
820 * by ASoC. When the standard kernel resume process asks the device
821 * to resume it should call this function. Once all the components of
822 * the card have notified that they are ready to be resumed the card
823 * will be resumed.
824 *
825 * \note Currently this function is stubbed out.
826 */
827int snd_soc_resume_device(struct device *dev)
828{
829 return 0;
830}
831EXPORT_SYMBOL_GPL(snd_soc_resume_device);
832#else 959#else
833#define soc_suspend NULL 960#define soc_suspend NULL
834#define soc_resume NULL 961#define soc_resume NULL
@@ -843,6 +970,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
843 struct platform_device, 970 struct platform_device,
844 dev); 971 dev);
845 struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev; 972 struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
973 struct snd_soc_codec *codec;
846 struct snd_soc_platform *platform; 974 struct snd_soc_platform *platform;
847 struct snd_soc_dai *dai; 975 struct snd_soc_dai *dai;
848 int i, found, ret, ac97; 976 int i, found, ret, ac97;
@@ -931,6 +1059,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
931 if (ret < 0) 1059 if (ret < 0)
932 goto cpu_dai_err; 1060 goto cpu_dai_err;
933 } 1061 }
1062 codec = card->codec;
934 1063
935 if (platform->probe) { 1064 if (platform->probe) {
936 ret = platform->probe(pdev); 1065 ret = platform->probe(pdev);
@@ -945,10 +1074,69 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
945 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); 1074 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
946#endif 1075#endif
947 1076
1077 for (i = 0; i < card->num_links; i++) {
1078 if (card->dai_link[i].init) {
1079 ret = card->dai_link[i].init(codec);
1080 if (ret < 0) {
1081 printk(KERN_ERR "asoc: failed to init %s\n",
1082 card->dai_link[i].stream_name);
1083 continue;
1084 }
1085 }
1086 if (card->dai_link[i].codec_dai->ac97_control)
1087 ac97 = 1;
1088 }
1089
1090 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1091 "%s", card->name);
1092 snprintf(codec->card->longname, sizeof(codec->card->longname),
1093 "%s (%s)", card->name, codec->name);
1094
1095 /* Make sure all DAPM widgets are instantiated */
1096 snd_soc_dapm_new_widgets(codec);
1097
1098 ret = snd_card_register(codec->card);
1099 if (ret < 0) {
1100 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1101 codec->name);
1102 goto card_err;
1103 }
1104
1105 mutex_lock(&codec->mutex);
1106#ifdef CONFIG_SND_SOC_AC97_BUS
1107 /* Only instantiate AC97 if not already done by the adaptor
1108 * for the generic AC97 subsystem.
1109 */
1110 if (ac97 && strcmp(codec->name, "AC97") != 0) {
1111 ret = soc_ac97_dev_register(codec);
1112 if (ret < 0) {
1113 printk(KERN_ERR "asoc: AC97 device register failed\n");
1114 snd_card_free(codec->card);
1115 mutex_unlock(&codec->mutex);
1116 goto card_err;
1117 }
1118 }
1119#endif
1120
1121 ret = snd_soc_dapm_sys_add(card->socdev->dev);
1122 if (ret < 0)
1123 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1124
1125 ret = device_create_file(card->socdev->dev, &dev_attr_codec_reg);
1126 if (ret < 0)
1127 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1128
1129 soc_init_codec_debugfs(codec);
1130 mutex_unlock(&codec->mutex);
1131
948 card->instantiated = 1; 1132 card->instantiated = 1;
949 1133
950 return; 1134 return;
951 1135
1136card_err:
1137 if (platform->remove)
1138 platform->remove(pdev);
1139
952platform_err: 1140platform_err:
953 if (codec_dev->remove) 1141 if (codec_dev->remove)
954 codec_dev->remove(pdev); 1142 codec_dev->remove(pdev);
@@ -1151,157 +1339,6 @@ int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg)
1151} 1339}
1152EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); 1340EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1153 1341
1154/* codec register dump */
1155static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
1156{
1157 int i, step = 1, count = 0;
1158
1159 if (!codec->reg_cache_size)
1160 return 0;
1161
1162 if (codec->reg_cache_step)
1163 step = codec->reg_cache_step;
1164
1165 count += sprintf(buf, "%s registers\n", codec->name);
1166 for (i = 0; i < codec->reg_cache_size; i += step) {
1167 if (codec->readable_register && !codec->readable_register(i))
1168 continue;
1169
1170 count += sprintf(buf + count, "%2x: ", i);
1171 if (count >= PAGE_SIZE - 1)
1172 break;
1173
1174 if (codec->display_register)
1175 count += codec->display_register(codec, buf + count,
1176 PAGE_SIZE - count, i);
1177 else
1178 count += snprintf(buf + count, PAGE_SIZE - count,
1179 "%4x", codec->read(codec, i));
1180
1181 if (count >= PAGE_SIZE - 1)
1182 break;
1183
1184 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
1185 if (count >= PAGE_SIZE - 1)
1186 break;
1187 }
1188
1189 /* Truncate count; min() would cause a warning */
1190 if (count >= PAGE_SIZE)
1191 count = PAGE_SIZE - 1;
1192
1193 return count;
1194}
1195static ssize_t codec_reg_show(struct device *dev,
1196 struct device_attribute *attr, char *buf)
1197{
1198 struct snd_soc_device *devdata = dev_get_drvdata(dev);
1199 return soc_codec_reg_show(devdata->card->codec, buf);
1200}
1201
1202static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
1203
1204#ifdef CONFIG_DEBUG_FS
1205static int codec_reg_open_file(struct inode *inode, struct file *file)
1206{
1207 file->private_data = inode->i_private;
1208 return 0;
1209}
1210
1211static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
1212 size_t count, loff_t *ppos)
1213{
1214 ssize_t ret;
1215 struct snd_soc_codec *codec = file->private_data;
1216 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1217 if (!buf)
1218 return -ENOMEM;
1219 ret = soc_codec_reg_show(codec, buf);
1220 if (ret >= 0)
1221 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1222 kfree(buf);
1223 return ret;
1224}
1225
1226static ssize_t codec_reg_write_file(struct file *file,
1227 const char __user *user_buf, size_t count, loff_t *ppos)
1228{
1229 char buf[32];
1230 int buf_size;
1231 char *start = buf;
1232 unsigned long reg, value;
1233 int step = 1;
1234 struct snd_soc_codec *codec = file->private_data;
1235
1236 buf_size = min(count, (sizeof(buf)-1));
1237 if (copy_from_user(buf, user_buf, buf_size))
1238 return -EFAULT;
1239 buf[buf_size] = 0;
1240
1241 if (codec->reg_cache_step)
1242 step = codec->reg_cache_step;
1243
1244 while (*start == ' ')
1245 start++;
1246 reg = simple_strtoul(start, &start, 16);
1247 if ((reg >= codec->reg_cache_size) || (reg % step))
1248 return -EINVAL;
1249 while (*start == ' ')
1250 start++;
1251 if (strict_strtoul(start, 16, &value))
1252 return -EINVAL;
1253 codec->write(codec, reg, value);
1254 return buf_size;
1255}
1256
1257static const struct file_operations codec_reg_fops = {
1258 .open = codec_reg_open_file,
1259 .read = codec_reg_read_file,
1260 .write = codec_reg_write_file,
1261};
1262
1263static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
1264{
1265 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
1266 debugfs_root, codec,
1267 &codec_reg_fops);
1268 if (!codec->debugfs_reg)
1269 printk(KERN_WARNING
1270 "ASoC: Failed to create codec register debugfs file\n");
1271
1272 codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0744,
1273 debugfs_root,
1274 &codec->pop_time);
1275 if (!codec->debugfs_pop_time)
1276 printk(KERN_WARNING
1277 "Failed to create pop time debugfs file\n");
1278
1279 codec->debugfs_dapm = debugfs_create_dir("dapm", debugfs_root);
1280 if (!codec->debugfs_dapm)
1281 printk(KERN_WARNING
1282 "Failed to create DAPM debugfs directory\n");
1283
1284 snd_soc_dapm_debugfs_init(codec);
1285}
1286
1287static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
1288{
1289 debugfs_remove_recursive(codec->debugfs_dapm);
1290 debugfs_remove(codec->debugfs_pop_time);
1291 debugfs_remove(codec->debugfs_reg);
1292}
1293
1294#else
1295
1296static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
1297{
1298}
1299
1300static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
1301{
1302}
1303#endif
1304
1305/** 1342/**
1306 * snd_soc_new_ac97_codec - initailise AC97 device 1343 * snd_soc_new_ac97_codec - initailise AC97 device
1307 * @codec: audio codec 1344 * @codec: audio codec
@@ -1369,19 +1406,41 @@ int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1369 int change; 1406 int change;
1370 unsigned int old, new; 1407 unsigned int old, new;
1371 1408
1372 mutex_lock(&io_mutex);
1373 old = snd_soc_read(codec, reg); 1409 old = snd_soc_read(codec, reg);
1374 new = (old & ~mask) | value; 1410 new = (old & ~mask) | value;
1375 change = old != new; 1411 change = old != new;
1376 if (change) 1412 if (change)
1377 snd_soc_write(codec, reg, new); 1413 snd_soc_write(codec, reg, new);
1378 1414
1379 mutex_unlock(&io_mutex);
1380 return change; 1415 return change;
1381} 1416}
1382EXPORT_SYMBOL_GPL(snd_soc_update_bits); 1417EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1383 1418
1384/** 1419/**
1420 * snd_soc_update_bits_locked - update codec register bits
1421 * @codec: audio codec
1422 * @reg: codec register
1423 * @mask: register mask
1424 * @value: new value
1425 *
1426 * Writes new register value, and takes the codec mutex.
1427 *
1428 * Returns 1 for change else 0.
1429 */
1430static int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1431 unsigned short reg, unsigned int mask,
1432 unsigned int value)
1433{
1434 int change;
1435
1436 mutex_lock(&codec->mutex);
1437 change = snd_soc_update_bits(codec, reg, mask, value);
1438 mutex_unlock(&codec->mutex);
1439
1440 return change;
1441}
1442
1443/**
1385 * snd_soc_test_bits - test register for change 1444 * snd_soc_test_bits - test register for change
1386 * @codec: audio codec 1445 * @codec: audio codec
1387 * @reg: codec register 1446 * @reg: codec register
@@ -1399,11 +1458,9 @@ int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1399 int change; 1458 int change;
1400 unsigned int old, new; 1459 unsigned int old, new;
1401 1460
1402 mutex_lock(&io_mutex);
1403 old = snd_soc_read(codec, reg); 1461 old = snd_soc_read(codec, reg);
1404 new = (old & ~mask) | value; 1462 new = (old & ~mask) | value;
1405 change = old != new; 1463 change = old != new;
1406 mutex_unlock(&io_mutex);
1407 1464
1408 return change; 1465 return change;
1409} 1466}
@@ -1450,89 +1507,16 @@ int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1450 mutex_unlock(&codec->mutex); 1507 mutex_unlock(&codec->mutex);
1451 return ret; 1508 return ret;
1452 } 1509 }
1453 }
1454
1455 mutex_unlock(&codec->mutex);
1456 return ret;
1457}
1458EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1459
1460/**
1461 * snd_soc_init_card - register sound card
1462 * @socdev: the SoC audio device
1463 *
1464 * Register a SoC sound card. Also registers an AC97 device if the
1465 * codec is AC97 for ad hoc devices.
1466 *
1467 * Returns 0 for success, else error.
1468 */
1469int snd_soc_init_card(struct snd_soc_device *socdev)
1470{
1471 struct snd_soc_card *card = socdev->card;
1472 struct snd_soc_codec *codec = card->codec;
1473 int ret = 0, i, ac97 = 0, err = 0;
1474
1475 for (i = 0; i < card->num_links; i++) {
1476 if (card->dai_link[i].init) {
1477 err = card->dai_link[i].init(codec);
1478 if (err < 0) {
1479 printk(KERN_ERR "asoc: failed to init %s\n",
1480 card->dai_link[i].stream_name);
1481 continue;
1482 }
1483 }
1484 if (card->dai_link[i].codec_dai->ac97_control) { 1510 if (card->dai_link[i].codec_dai->ac97_control) {
1485 ac97 = 1;
1486 snd_ac97_dev_add_pdata(codec->ac97, 1511 snd_ac97_dev_add_pdata(codec->ac97,
1487 card->dai_link[i].cpu_dai->ac97_pdata); 1512 card->dai_link[i].cpu_dai->ac97_pdata);
1488 } 1513 }
1489 } 1514 }
1490 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1491 "%s", card->name);
1492 snprintf(codec->card->longname, sizeof(codec->card->longname),
1493 "%s (%s)", card->name, codec->name);
1494
1495 /* Make sure all DAPM widgets are instantiated */
1496 snd_soc_dapm_new_widgets(codec);
1497
1498 ret = snd_card_register(codec->card);
1499 if (ret < 0) {
1500 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1501 codec->name);
1502 goto out;
1503 }
1504
1505 mutex_lock(&codec->mutex);
1506#ifdef CONFIG_SND_SOC_AC97_BUS
1507 /* Only instantiate AC97 if not already done by the adaptor
1508 * for the generic AC97 subsystem.
1509 */
1510 if (ac97 && strcmp(codec->name, "AC97") != 0) {
1511 ret = soc_ac97_dev_register(codec);
1512 if (ret < 0) {
1513 printk(KERN_ERR "asoc: AC97 device register failed\n");
1514 snd_card_free(codec->card);
1515 mutex_unlock(&codec->mutex);
1516 goto out;
1517 }
1518 }
1519#endif
1520
1521 err = snd_soc_dapm_sys_add(socdev->dev);
1522 if (err < 0)
1523 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1524
1525 err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1526 if (err < 0)
1527 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1528 1515
1529 soc_init_codec_debugfs(codec);
1530 mutex_unlock(&codec->mutex); 1516 mutex_unlock(&codec->mutex);
1531
1532out:
1533 return ret; 1517 return ret;
1534} 1518}
1535EXPORT_SYMBOL_GPL(snd_soc_init_card); 1519EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1536 1520
1537/** 1521/**
1538 * snd_soc_free_pcms - free sound card and pcms 1522 * snd_soc_free_pcms - free sound card and pcms
@@ -1734,7 +1718,7 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1734 mask |= (bitmask - 1) << e->shift_r; 1718 mask |= (bitmask - 1) << e->shift_r;
1735 } 1719 }
1736 1720
1737 return snd_soc_update_bits(codec, e->reg, mask, val); 1721 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
1738} 1722}
1739EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); 1723EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1740 1724
@@ -1808,7 +1792,7 @@ int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
1808 mask |= e->mask << e->shift_r; 1792 mask |= e->mask << e->shift_r;
1809 } 1793 }
1810 1794
1811 return snd_soc_update_bits(codec, e->reg, mask, val); 1795 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
1812} 1796}
1813EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); 1797EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
1814 1798
@@ -1969,7 +1953,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1969 val_mask |= mask << rshift; 1953 val_mask |= mask << rshift;
1970 val |= val2 << rshift; 1954 val |= val2 << rshift;
1971 } 1955 }
1972 return snd_soc_update_bits(codec, reg, val_mask, val); 1956 return snd_soc_update_bits_locked(codec, reg, val_mask, val);
1973} 1957}
1974EXPORT_SYMBOL_GPL(snd_soc_put_volsw); 1958EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1975 1959
@@ -2075,11 +2059,11 @@ int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
2075 val = val << shift; 2059 val = val << shift;
2076 val2 = val2 << shift; 2060 val2 = val2 << shift;
2077 2061
2078 err = snd_soc_update_bits(codec, reg, val_mask, val); 2062 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2079 if (err < 0) 2063 if (err < 0)
2080 return err; 2064 return err;
2081 2065
2082 err = snd_soc_update_bits(codec, reg2, val_mask, val2); 2066 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2083 return err; 2067 return err;
2084} 2068}
2085EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r); 2069EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
@@ -2158,7 +2142,7 @@ int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2158 val = (ucontrol->value.integer.value[0]+min) & 0xff; 2142 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2159 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; 2143 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2160 2144
2161 return snd_soc_update_bits(codec, reg, 0xffff, val); 2145 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2162} 2146}
2163EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); 2147EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2164 2148
@@ -2205,16 +2189,18 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2205 * snd_soc_dai_set_pll - configure DAI PLL. 2189 * snd_soc_dai_set_pll - configure DAI PLL.
2206 * @dai: DAI 2190 * @dai: DAI
2207 * @pll_id: DAI specific PLL ID 2191 * @pll_id: DAI specific PLL ID
2192 * @source: DAI specific source for the PLL
2208 * @freq_in: PLL input clock frequency in Hz 2193 * @freq_in: PLL input clock frequency in Hz
2209 * @freq_out: requested PLL output clock frequency in Hz 2194 * @freq_out: requested PLL output clock frequency in Hz
2210 * 2195 *
2211 * Configures and enables PLL to generate output clock based on input clock. 2196 * Configures and enables PLL to generate output clock based on input clock.
2212 */ 2197 */
2213int snd_soc_dai_set_pll(struct snd_soc_dai *dai, 2198int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2214 int pll_id, unsigned int freq_in, unsigned int freq_out) 2199 unsigned int freq_in, unsigned int freq_out)
2215{ 2200{
2216 if (dai->ops && dai->ops->set_pll) 2201 if (dai->ops && dai->ops->set_pll)
2217 return dai->ops->set_pll(dai, pll_id, freq_in, freq_out); 2202 return dai->ops->set_pll(dai, pll_id, source,
2203 freq_in, freq_out);
2218 else 2204 else
2219 return -EINVAL; 2205 return -EINVAL;
2220} 2206}
@@ -2259,6 +2245,30 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2259EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 2245EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2260 2246
2261/** 2247/**
2248 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2249 * @dai: DAI
2250 * @tx_num: how many TX channels
2251 * @tx_slot: pointer to an array which imply the TX slot number channel
2252 * 0~num-1 uses
2253 * @rx_num: how many RX channels
2254 * @rx_slot: pointer to an array which imply the RX slot number channel
2255 * 0~num-1 uses
2256 *
2257 * configure the relationship between channel number and TDM slot number.
2258 */
2259int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2260 unsigned int tx_num, unsigned int *tx_slot,
2261 unsigned int rx_num, unsigned int *rx_slot)
2262{
2263 if (dai->ops && dai->ops->set_channel_map)
2264 return dai->ops->set_channel_map(dai, tx_num, tx_slot,
2265 rx_num, rx_slot);
2266 else
2267 return -EINVAL;
2268}
2269EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2270
2271/**
2262 * snd_soc_dai_set_tristate - configure DAI system or master clock. 2272 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2263 * @dai: DAI 2273 * @dai: DAI
2264 * @tristate: tristate enable 2274 * @tristate: tristate enable
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 66d4c165f99b..0d294ef72590 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -719,6 +719,10 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
719 719
720 /* Check if one of our outputs is connected */ 720 /* Check if one of our outputs is connected */
721 list_for_each_entry(path, &w->sinks, list_source) { 721 list_for_each_entry(path, &w->sinks, list_source) {
722 if (path->connected &&
723 !path->connected(path->source, path->sink))
724 continue;
725
722 if (path->sink && path->sink->power_check && 726 if (path->sink && path->sink->power_check &&
723 path->sink->power_check(path->sink)) { 727 path->sink->power_check(path->sink)) {
724 power = 1; 728 power = 1;
@@ -1152,6 +1156,9 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1152 w->active ? "active" : "inactive"); 1156 w->active ? "active" : "inactive");
1153 1157
1154 list_for_each_entry(p, &w->sources, list_sink) { 1158 list_for_each_entry(p, &w->sources, list_sink) {
1159 if (p->connected && !p->connected(w, p->sink))
1160 continue;
1161
1155 if (p->connect) 1162 if (p->connect)
1156 ret += snprintf(buf + ret, PAGE_SIZE - ret, 1163 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1157 " in %s %s\n", 1164 " in %s %s\n",
@@ -1159,6 +1166,9 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1159 p->source->name); 1166 p->source->name);
1160 } 1167 }
1161 list_for_each_entry(p, &w->sinks, list_source) { 1168 list_for_each_entry(p, &w->sinks, list_source) {
1169 if (p->connected && !p->connected(w, p->sink))
1170 continue;
1171
1162 if (p->connect) 1172 if (p->connect)
1163 ret += snprintf(buf + ret, PAGE_SIZE - ret, 1173 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1164 " out %s %s\n", 1174 " out %s %s\n",
@@ -1206,8 +1216,8 @@ void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec)
1206 1216
1207/* test and update the power status of a mux widget */ 1217/* test and update the power status of a mux widget */
1208static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget, 1218static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1209 struct snd_kcontrol *kcontrol, int mask, 1219 struct snd_kcontrol *kcontrol, int change,
1210 int mux, int val, struct soc_enum *e) 1220 int mux, struct soc_enum *e)
1211{ 1221{
1212 struct snd_soc_dapm_path *path; 1222 struct snd_soc_dapm_path *path;
1213 int found = 0; 1223 int found = 0;
@@ -1216,7 +1226,7 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1216 widget->id != snd_soc_dapm_value_mux) 1226 widget->id != snd_soc_dapm_value_mux)
1217 return -ENODEV; 1227 return -ENODEV;
1218 1228
1219 if (!snd_soc_test_bits(widget->codec, e->reg, mask, val)) 1229 if (!change)
1220 return 0; 1230 return 0;
1221 1231
1222 /* find dapm widget path assoc with kcontrol */ 1232 /* find dapm widget path assoc with kcontrol */
@@ -1401,10 +1411,13 @@ int snd_soc_dapm_sync(struct snd_soc_codec *codec)
1401EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); 1411EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1402 1412
1403static int snd_soc_dapm_add_route(struct snd_soc_codec *codec, 1413static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1404 const char *sink, const char *control, const char *source) 1414 const struct snd_soc_dapm_route *route)
1405{ 1415{
1406 struct snd_soc_dapm_path *path; 1416 struct snd_soc_dapm_path *path;
1407 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; 1417 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1418 const char *sink = route->sink;
1419 const char *control = route->control;
1420 const char *source = route->source;
1408 int ret = 0; 1421 int ret = 0;
1409 1422
1410 /* find src and dest widgets */ 1423 /* find src and dest widgets */
@@ -1428,6 +1441,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1428 1441
1429 path->source = wsource; 1442 path->source = wsource;
1430 path->sink = wsink; 1443 path->sink = wsink;
1444 path->connected = route->connected;
1431 INIT_LIST_HEAD(&path->list); 1445 INIT_LIST_HEAD(&path->list);
1432 INIT_LIST_HEAD(&path->list_source); 1446 INIT_LIST_HEAD(&path->list_source);
1433 INIT_LIST_HEAD(&path->list_sink); 1447 INIT_LIST_HEAD(&path->list_sink);
@@ -1528,8 +1542,7 @@ int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
1528 int i, ret; 1542 int i, ret;
1529 1543
1530 for (i = 0; i < num; i++) { 1544 for (i = 0; i < num; i++) {
1531 ret = snd_soc_dapm_add_route(codec, route->sink, 1545 ret = snd_soc_dapm_add_route(codec, route);
1532 route->control, route->source);
1533 if (ret < 0) { 1546 if (ret < 0) {
1534 printk(KERN_ERR "Failed to add route %s->%s\n", 1547 printk(KERN_ERR "Failed to add route %s->%s\n",
1535 route->source, 1548 route->source,
@@ -1766,7 +1779,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1766{ 1779{
1767 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); 1780 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1768 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 1781 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1769 unsigned int val, mux; 1782 unsigned int val, mux, change;
1770 unsigned int mask, bitmask; 1783 unsigned int mask, bitmask;
1771 int ret = 0; 1784 int ret = 0;
1772 1785
@@ -1786,20 +1799,21 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1786 1799
1787 mutex_lock(&widget->codec->mutex); 1800 mutex_lock(&widget->codec->mutex);
1788 widget->value = val; 1801 widget->value = val;
1789 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e); 1802 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1790 if (widget->event) { 1803 dapm_mux_update_power(widget, kcontrol, change, mux, e);
1791 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { 1804
1792 ret = widget->event(widget, 1805 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1793 kcontrol, SND_SOC_DAPM_PRE_REG); 1806 ret = widget->event(widget,
1794 if (ret < 0) 1807 kcontrol, SND_SOC_DAPM_PRE_REG);
1795 goto out; 1808 if (ret < 0)
1796 } 1809 goto out;
1797 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); 1810 }
1798 if (widget->event_flags & SND_SOC_DAPM_POST_REG) 1811
1799 ret = widget->event(widget, 1812 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1800 kcontrol, SND_SOC_DAPM_POST_REG); 1813
1801 } else 1814 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1802 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); 1815 ret = widget->event(widget,
1816 kcontrol, SND_SOC_DAPM_POST_REG);
1803 1817
1804out: 1818out:
1805 mutex_unlock(&widget->codec->mutex); 1819 mutex_unlock(&widget->codec->mutex);
@@ -1808,6 +1822,54 @@ out:
1808EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); 1822EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1809 1823
1810/** 1824/**
1825 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
1826 * @kcontrol: mixer control
1827 * @ucontrol: control element information
1828 *
1829 * Returns 0 for success.
1830 */
1831int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
1832 struct snd_ctl_elem_value *ucontrol)
1833{
1834 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1835
1836 ucontrol->value.enumerated.item[0] = widget->value;
1837
1838 return 0;
1839}
1840EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
1841
1842/**
1843 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
1844 * @kcontrol: mixer control
1845 * @ucontrol: control element information
1846 *
1847 * Returns 0 for success.
1848 */
1849int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
1850 struct snd_ctl_elem_value *ucontrol)
1851{
1852 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1853 struct soc_enum *e =
1854 (struct soc_enum *)kcontrol->private_value;
1855 int change;
1856 int ret = 0;
1857
1858 if (ucontrol->value.enumerated.item[0] >= e->max)
1859 return -EINVAL;
1860
1861 mutex_lock(&widget->codec->mutex);
1862
1863 change = widget->value != ucontrol->value.enumerated.item[0];
1864 widget->value = ucontrol->value.enumerated.item[0];
1865 dapm_mux_update_power(widget, kcontrol, change, widget->value, e);
1866
1867 mutex_unlock(&widget->codec->mutex);
1868 return ret;
1869}
1870EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
1871
1872/**
1811 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get 1873 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1812 * callback 1874 * callback
1813 * @kcontrol: mixer control 1875 * @kcontrol: mixer control
@@ -1865,7 +1927,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1865{ 1927{
1866 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); 1928 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1867 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 1929 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1868 unsigned int val, mux; 1930 unsigned int val, mux, change;
1869 unsigned int mask; 1931 unsigned int mask;
1870 int ret = 0; 1932 int ret = 0;
1871 1933
@@ -1883,20 +1945,21 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1883 1945
1884 mutex_lock(&widget->codec->mutex); 1946 mutex_lock(&widget->codec->mutex);
1885 widget->value = val; 1947 widget->value = val;
1886 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e); 1948 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1887 if (widget->event) { 1949 dapm_mux_update_power(widget, kcontrol, change, mux, e);
1888 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { 1950
1889 ret = widget->event(widget, 1951 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1890 kcontrol, SND_SOC_DAPM_PRE_REG); 1952 ret = widget->event(widget,
1891 if (ret < 0) 1953 kcontrol, SND_SOC_DAPM_PRE_REG);
1892 goto out; 1954 if (ret < 0)
1893 } 1955 goto out;
1894 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); 1956 }
1895 if (widget->event_flags & SND_SOC_DAPM_POST_REG) 1957
1896 ret = widget->event(widget, 1958 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1897 kcontrol, SND_SOC_DAPM_POST_REG); 1959
1898 } else 1960 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1899 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); 1961 ret = widget->event(widget,
1962 kcontrol, SND_SOC_DAPM_POST_REG);
1900 1963
1901out: 1964out:
1902 mutex_unlock(&widget->codec->mutex); 1965 mutex_unlock(&widget->codec->mutex);
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index 1d455ab79490..3c07a94c2e30 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(snd_soc_jack_new);
58 */ 58 */
59void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) 59void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
60{ 60{
61 struct snd_soc_codec *codec = jack->card->codec; 61 struct snd_soc_codec *codec;
62 struct snd_soc_jack_pin *pin; 62 struct snd_soc_jack_pin *pin;
63 int enable; 63 int enable;
64 int oldstatus; 64 int oldstatus;
@@ -67,6 +67,7 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
67 WARN_ON_ONCE(!jack); 67 WARN_ON_ONCE(!jack);
68 return; 68 return;
69 } 69 }
70 codec = jack->card->codec;
70 71
71 mutex_lock(&codec->mutex); 72 mutex_lock(&codec->mutex);
72 73
@@ -162,6 +163,9 @@ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio)
162 else 163 else
163 report = 0; 164 report = 0;
164 165
166 if (gpio->jack_status_check)
167 report = gpio->jack_status_check();
168
165 snd_soc_jack_report(jack, report, gpio->report); 169 snd_soc_jack_report(jack, report, gpio->report);
166} 170}
167 171
diff --git a/sound/soc/soc-utils.c b/sound/soc/soc-utils.c
new file mode 100644
index 000000000000..1d07b931f3d8
--- /dev/null
+++ b/sound/soc/soc-utils.c
@@ -0,0 +1,74 @@
1/*
2 * soc-util.c -- ALSA SoC Audio Layer utility functions
3 *
4 * Copyright 2009 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 * Liam Girdwood <lrg@slimlogic.co.uk>
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 as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15
16#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/pcm_params.h>
19#include <sound/soc.h>
20
21int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots)
22{
23 return sample_size * channels * tdm_slots;
24}
25EXPORT_SYMBOL_GPL(snd_soc_calc_frame_size);
26
27int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params)
28{
29 int sample_size;
30
31 switch (params_format(params)) {
32 case SNDRV_PCM_FORMAT_S16_LE:
33 case SNDRV_PCM_FORMAT_S16_BE:
34 sample_size = 16;
35 break;
36 case SNDRV_PCM_FORMAT_S20_3LE:
37 case SNDRV_PCM_FORMAT_S20_3BE:
38 sample_size = 20;
39 break;
40 case SNDRV_PCM_FORMAT_S24_LE:
41 case SNDRV_PCM_FORMAT_S24_BE:
42 sample_size = 24;
43 break;
44 case SNDRV_PCM_FORMAT_S32_LE:
45 case SNDRV_PCM_FORMAT_S32_BE:
46 sample_size = 32;
47 break;
48 default:
49 return -ENOTSUPP;
50 }
51
52 return snd_soc_calc_frame_size(sample_size, params_channels(params),
53 1);
54}
55EXPORT_SYMBOL_GPL(snd_soc_params_to_frame_size);
56
57int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots)
58{
59 return fs * snd_soc_calc_frame_size(sample_size, channels, tdm_slots);
60}
61EXPORT_SYMBOL_GPL(snd_soc_calc_bclk);
62
63int snd_soc_params_to_bclk(struct snd_pcm_hw_params *params)
64{
65 int ret;
66
67 ret = snd_soc_params_to_frame_size(params);
68
69 if (ret > 0)
70 return ret * params_rate(params);
71 else
72 return ret;
73}
74EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk);
diff --git a/sound/sound_core.c b/sound/sound_core.c
index 49c998186592..dbca7c909a31 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -353,7 +353,7 @@ static struct sound_unit *chains[SOUND_STEP];
353 * @dev: device pointer 353 * @dev: device pointer
354 * 354 *
355 * Allocate a special sound device by minor number from the sound 355 * Allocate a special sound device by minor number from the sound
356 * subsystem. The allocated number is returned on succes. On failure 356 * subsystem. The allocated number is returned on success. On failure
357 * a negative error code is returned. 357 * a negative error code is returned.
358 */ 358 */
359 359
diff --git a/sound/synth/emux/soundfont.c b/sound/synth/emux/soundfont.c
index 63c8f45c0c22..67c91230c197 100644
--- a/sound/synth/emux/soundfont.c
+++ b/sound/synth/emux/soundfont.c
@@ -374,7 +374,7 @@ sf_zone_new(struct snd_sf_list *sflist, struct snd_soundfont *sf)
374 374
375 375
376/* 376/*
377 * increment sample couter 377 * increment sample counter
378 */ 378 */
379static void 379static void
380set_sample_counter(struct snd_sf_list *sflist, struct snd_soundfont *sf, 380set_sample_counter(struct snd_sf_list *sflist, struct snd_soundfont *sf,
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index 8db0374e10d5..b074a594c595 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -2893,7 +2893,9 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
2893 if ((altsd->bInterfaceClass == USB_CLASS_AUDIO || 2893 if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
2894 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) && 2894 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
2895 altsd->bInterfaceSubClass == USB_SUBCLASS_MIDI_STREAMING) { 2895 altsd->bInterfaceSubClass == USB_SUBCLASS_MIDI_STREAMING) {
2896 if (snd_usb_create_midi_interface(chip, iface, NULL) < 0) { 2896 int err = snd_usbmidi_create(chip->card, iface,
2897 &chip->midi_list, NULL);
2898 if (err < 0) {
2897 snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n", dev->devnum, ctrlif, j); 2899 snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n", dev->devnum, ctrlif, j);
2898 continue; 2900 continue;
2899 } 2901 }
@@ -3038,12 +3040,11 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
3038 .type = QUIRK_MIDI_FIXED_ENDPOINT, 3040 .type = QUIRK_MIDI_FIXED_ENDPOINT,
3039 .data = &uaxx_ep 3041 .data = &uaxx_ep
3040 }; 3042 };
3041 if (chip->usb_id == USB_ID(0x0582, 0x002b)) 3043 const struct snd_usb_audio_quirk *quirk =
3042 return snd_usb_create_midi_interface(chip, iface, 3044 chip->usb_id == USB_ID(0x0582, 0x002b)
3043 &ua700_quirk); 3045 ? &ua700_quirk : &uaxx_quirk;
3044 else 3046 return snd_usbmidi_create(chip->card, iface,
3045 return snd_usb_create_midi_interface(chip, iface, 3047 &chip->midi_list, quirk);
3046 &uaxx_quirk);
3047 } 3048 }
3048 3049
3049 if (altsd->bNumEndpoints != 1) 3050 if (altsd->bNumEndpoints != 1)
@@ -3370,6 +3371,13 @@ static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
3370 return 0; /* keep this altsetting */ 3371 return 0; /* keep this altsetting */
3371} 3372}
3372 3373
3374static int create_any_midi_quirk(struct snd_usb_audio *chip,
3375 struct usb_interface *intf,
3376 const struct snd_usb_audio_quirk *quirk)
3377{
3378 return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
3379}
3380
3373/* 3381/*
3374 * audio-interface quirks 3382 * audio-interface quirks
3375 * 3383 *
@@ -3387,14 +3395,14 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3387 static const quirk_func_t quirk_funcs[] = { 3395 static const quirk_func_t quirk_funcs[] = {
3388 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk, 3396 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
3389 [QUIRK_COMPOSITE] = create_composite_quirk, 3397 [QUIRK_COMPOSITE] = create_composite_quirk,
3390 [QUIRK_MIDI_STANDARD_INTERFACE] = snd_usb_create_midi_interface, 3398 [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
3391 [QUIRK_MIDI_FIXED_ENDPOINT] = snd_usb_create_midi_interface, 3399 [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
3392 [QUIRK_MIDI_YAMAHA] = snd_usb_create_midi_interface, 3400 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
3393 [QUIRK_MIDI_MIDIMAN] = snd_usb_create_midi_interface, 3401 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
3394 [QUIRK_MIDI_NOVATION] = snd_usb_create_midi_interface, 3402 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
3395 [QUIRK_MIDI_FASTLANE] = snd_usb_create_midi_interface, 3403 [QUIRK_MIDI_FASTLANE] = create_any_midi_quirk,
3396 [QUIRK_MIDI_EMAGIC] = snd_usb_create_midi_interface, 3404 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
3397 [QUIRK_MIDI_CME] = snd_usb_create_midi_interface, 3405 [QUIRK_MIDI_CME] = create_any_midi_quirk,
3398 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, 3406 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
3399 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 3407 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
3400 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, 3408 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk,
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index e9a3a9dca15c..40ba8115fb81 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -132,7 +132,6 @@ struct snd_usb_audio {
132 int pcm_devs; 132 int pcm_devs;
133 133
134 struct list_head midi_list; /* list of midi interfaces */ 134 struct list_head midi_list; /* list of midi interfaces */
135 int next_midi_device;
136 135
137 struct list_head mixer_list; /* list of mixer interfaces */ 136 struct list_head mixer_list; /* list of mixer interfaces */
138}; 137};
@@ -227,8 +226,10 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
227 int ignore_error); 226 int ignore_error);
228void snd_usb_mixer_disconnect(struct list_head *p); 227void snd_usb_mixer_disconnect(struct list_head *p);
229 228
230int snd_usb_create_midi_interface(struct snd_usb_audio *chip, struct usb_interface *iface, 229int snd_usbmidi_create(struct snd_card *card,
231 const struct snd_usb_audio_quirk *quirk); 230 struct usb_interface *iface,
231 struct list_head *midi_list,
232 const struct snd_usb_audio_quirk *quirk);
232void snd_usbmidi_input_stop(struct list_head* p); 233void snd_usbmidi_input_stop(struct list_head* p);
233void snd_usbmidi_input_start(struct list_head* p); 234void snd_usbmidi_input_start(struct list_head* p);
234void snd_usbmidi_disconnect(struct list_head *p); 235void snd_usbmidi_disconnect(struct list_head *p);
diff --git a/sound/usb/usbmidi.c b/sound/usb/usbmidi.c
index 0eff19ceb7e1..6e89b8368d9a 100644
--- a/sound/usb/usbmidi.c
+++ b/sound/usb/usbmidi.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * usbmidi.c - ALSA USB MIDI driver 2 * usbmidi.c - ALSA USB MIDI driver
3 * 3 *
4 * Copyright (c) 2002-2007 Clemens Ladisch 4 * Copyright (c) 2002-2009 Clemens Ladisch
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Based on the OSS usb-midi driver by NAGANO Daisuke, 7 * Based on the OSS usb-midi driver by NAGANO Daisuke,
@@ -47,6 +47,7 @@
47#include <linux/usb.h> 47#include <linux/usb.h>
48#include <linux/wait.h> 48#include <linux/wait.h>
49#include <sound/core.h> 49#include <sound/core.h>
50#include <sound/control.h>
50#include <sound/rawmidi.h> 51#include <sound/rawmidi.h>
51#include <sound/asequencer.h> 52#include <sound/asequencer.h>
52#include "usbaudio.h" 53#include "usbaudio.h"
@@ -101,7 +102,8 @@ struct usb_protocol_ops {
101}; 102};
102 103
103struct snd_usb_midi { 104struct snd_usb_midi {
104 struct snd_usb_audio *chip; 105 struct usb_device *dev;
106 struct snd_card *card;
105 struct usb_interface *iface; 107 struct usb_interface *iface;
106 const struct snd_usb_audio_quirk *quirk; 108 const struct snd_usb_audio_quirk *quirk;
107 struct snd_rawmidi *rmidi; 109 struct snd_rawmidi *rmidi;
@@ -109,13 +111,19 @@ struct snd_usb_midi {
109 struct list_head list; 111 struct list_head list;
110 struct timer_list error_timer; 112 struct timer_list error_timer;
111 spinlock_t disc_lock; 113 spinlock_t disc_lock;
114 struct mutex mutex;
115 u32 usb_id;
116 int next_midi_device;
112 117
113 struct snd_usb_midi_endpoint { 118 struct snd_usb_midi_endpoint {
114 struct snd_usb_midi_out_endpoint *out; 119 struct snd_usb_midi_out_endpoint *out;
115 struct snd_usb_midi_in_endpoint *in; 120 struct snd_usb_midi_in_endpoint *in;
116 } endpoints[MIDI_MAX_ENDPOINTS]; 121 } endpoints[MIDI_MAX_ENDPOINTS];
117 unsigned long input_triggered; 122 unsigned long input_triggered;
123 unsigned int opened;
118 unsigned char disconnected; 124 unsigned char disconnected;
125
126 struct snd_kcontrol *roland_load_ctl;
119}; 127};
120 128
121struct snd_usb_midi_out_endpoint { 129struct snd_usb_midi_out_endpoint {
@@ -255,7 +263,7 @@ static void snd_usbmidi_in_urb_complete(struct urb* urb)
255 } 263 }
256 } 264 }
257 265
258 urb->dev = ep->umidi->chip->dev; 266 urb->dev = ep->umidi->dev;
259 snd_usbmidi_submit_urb(urb, GFP_ATOMIC); 267 snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
260} 268}
261 269
@@ -296,7 +304,7 @@ static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep)
296 unsigned long flags; 304 unsigned long flags;
297 305
298 spin_lock_irqsave(&ep->buffer_lock, flags); 306 spin_lock_irqsave(&ep->buffer_lock, flags);
299 if (ep->umidi->chip->shutdown) { 307 if (ep->umidi->disconnected) {
300 spin_unlock_irqrestore(&ep->buffer_lock, flags); 308 spin_unlock_irqrestore(&ep->buffer_lock, flags);
301 return; 309 return;
302 } 310 }
@@ -312,7 +320,7 @@ static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep)
312 320
313 dump_urb("sending", urb->transfer_buffer, 321 dump_urb("sending", urb->transfer_buffer,
314 urb->transfer_buffer_length); 322 urb->transfer_buffer_length);
315 urb->dev = ep->umidi->chip->dev; 323 urb->dev = ep->umidi->dev;
316 if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0) 324 if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0)
317 break; 325 break;
318 ep->active_urbs |= 1 << urb_index; 326 ep->active_urbs |= 1 << urb_index;
@@ -349,7 +357,7 @@ static void snd_usbmidi_error_timer(unsigned long data)
349 if (in && in->error_resubmit) { 357 if (in && in->error_resubmit) {
350 in->error_resubmit = 0; 358 in->error_resubmit = 0;
351 for (j = 0; j < INPUT_URBS; ++j) { 359 for (j = 0; j < INPUT_URBS; ++j) {
352 in->urbs[j]->dev = umidi->chip->dev; 360 in->urbs[j]->dev = umidi->dev;
353 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC); 361 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC);
354 } 362 }
355 } 363 }
@@ -369,7 +377,7 @@ static int send_bulk_static_data(struct snd_usb_midi_out_endpoint* ep,
369 return -ENOMEM; 377 return -ENOMEM;
370 dump_urb("sending", buf, len); 378 dump_urb("sending", buf, len);
371 if (ep->urbs[0].urb) 379 if (ep->urbs[0].urb)
372 err = usb_bulk_msg(ep->umidi->chip->dev, ep->urbs[0].urb->pipe, 380 err = usb_bulk_msg(ep->umidi->dev, ep->urbs[0].urb->pipe,
373 buf, len, NULL, 250); 381 buf, len, NULL, 250);
374 kfree(buf); 382 kfree(buf);
375 return err; 383 return err;
@@ -724,8 +732,7 @@ static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
724 732
725 if (!ep->ports[0].active) 733 if (!ep->ports[0].active)
726 return; 734 return;
727 count = snd_usb_get_speed(ep->umidi->chip->dev) == USB_SPEED_HIGH 735 count = snd_usb_get_speed(ep->umidi->dev) == USB_SPEED_HIGH ? 1 : 2;
728 ? 1 : 2;
729 count = snd_rawmidi_transmit(ep->ports[0].substream, 736 count = snd_rawmidi_transmit(ep->ports[0].substream,
730 urb->transfer_buffer, 737 urb->transfer_buffer,
731 count); 738 count);
@@ -879,6 +886,50 @@ static struct usb_protocol_ops snd_usbmidi_emagic_ops = {
879}; 886};
880 887
881 888
889static void update_roland_altsetting(struct snd_usb_midi* umidi)
890{
891 struct usb_interface *intf;
892 struct usb_host_interface *hostif;
893 struct usb_interface_descriptor *intfd;
894 int is_light_load;
895
896 intf = umidi->iface;
897 is_light_load = intf->cur_altsetting != intf->altsetting;
898 if (umidi->roland_load_ctl->private_value == is_light_load)
899 return;
900 hostif = &intf->altsetting[umidi->roland_load_ctl->private_value];
901 intfd = get_iface_desc(hostif);
902 snd_usbmidi_input_stop(&umidi->list);
903 usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
904 intfd->bAlternateSetting);
905 snd_usbmidi_input_start(&umidi->list);
906}
907
908static void substream_open(struct snd_rawmidi_substream *substream, int open)
909{
910 struct snd_usb_midi* umidi = substream->rmidi->private_data;
911 struct snd_kcontrol *ctl;
912
913 mutex_lock(&umidi->mutex);
914 if (open) {
915 if (umidi->opened++ == 0 && umidi->roland_load_ctl) {
916 ctl = umidi->roland_load_ctl;
917 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
918 snd_ctl_notify(umidi->card,
919 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
920 update_roland_altsetting(umidi);
921 }
922 } else {
923 if (--umidi->opened == 0 && umidi->roland_load_ctl) {
924 ctl = umidi->roland_load_ctl;
925 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
926 snd_ctl_notify(umidi->card,
927 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
928 }
929 }
930 mutex_unlock(&umidi->mutex);
931}
932
882static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream) 933static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
883{ 934{
884 struct snd_usb_midi* umidi = substream->rmidi->private_data; 935 struct snd_usb_midi* umidi = substream->rmidi->private_data;
@@ -898,11 +949,13 @@ static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
898 } 949 }
899 substream->runtime->private_data = port; 950 substream->runtime->private_data = port;
900 port->state = STATE_UNKNOWN; 951 port->state = STATE_UNKNOWN;
952 substream_open(substream, 1);
901 return 0; 953 return 0;
902} 954}
903 955
904static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream) 956static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream)
905{ 957{
958 substream_open(substream, 0);
906 return 0; 959 return 0;
907} 960}
908 961
@@ -912,7 +965,7 @@ static void snd_usbmidi_output_trigger(struct snd_rawmidi_substream *substream,
912 965
913 port->active = up; 966 port->active = up;
914 if (up) { 967 if (up) {
915 if (port->ep->umidi->chip->shutdown) { 968 if (port->ep->umidi->disconnected) {
916 /* gobble up remaining bytes to prevent wait in 969 /* gobble up remaining bytes to prevent wait in
917 * snd_rawmidi_drain_output */ 970 * snd_rawmidi_drain_output */
918 while (!snd_rawmidi_transmit_empty(substream)) 971 while (!snd_rawmidi_transmit_empty(substream))
@@ -954,11 +1007,13 @@ static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream)
954 1007
955static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream) 1008static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream)
956{ 1009{
1010 substream_open(substream, 1);
957 return 0; 1011 return 0;
958} 1012}
959 1013
960static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream) 1014static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream)
961{ 1015{
1016 substream_open(substream, 0);
962 return 0; 1017 return 0;
963} 1018}
964 1019
@@ -988,7 +1043,7 @@ static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
988static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb, 1043static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb,
989 unsigned int buffer_length) 1044 unsigned int buffer_length)
990{ 1045{
991 usb_buffer_free(umidi->chip->dev, buffer_length, 1046 usb_buffer_free(umidi->dev, buffer_length,
992 urb->transfer_buffer, urb->transfer_dma); 1047 urb->transfer_buffer, urb->transfer_dma);
993 usb_free_urb(urb); 1048 usb_free_urb(urb);
994} 1049}
@@ -1035,24 +1090,24 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
1035 } 1090 }
1036 } 1091 }
1037 if (ep_info->in_interval) 1092 if (ep_info->in_interval)
1038 pipe = usb_rcvintpipe(umidi->chip->dev, ep_info->in_ep); 1093 pipe = usb_rcvintpipe(umidi->dev, ep_info->in_ep);
1039 else 1094 else
1040 pipe = usb_rcvbulkpipe(umidi->chip->dev, ep_info->in_ep); 1095 pipe = usb_rcvbulkpipe(umidi->dev, ep_info->in_ep);
1041 length = usb_maxpacket(umidi->chip->dev, pipe, 0); 1096 length = usb_maxpacket(umidi->dev, pipe, 0);
1042 for (i = 0; i < INPUT_URBS; ++i) { 1097 for (i = 0; i < INPUT_URBS; ++i) {
1043 buffer = usb_buffer_alloc(umidi->chip->dev, length, GFP_KERNEL, 1098 buffer = usb_buffer_alloc(umidi->dev, length, GFP_KERNEL,
1044 &ep->urbs[i]->transfer_dma); 1099 &ep->urbs[i]->transfer_dma);
1045 if (!buffer) { 1100 if (!buffer) {
1046 snd_usbmidi_in_endpoint_delete(ep); 1101 snd_usbmidi_in_endpoint_delete(ep);
1047 return -ENOMEM; 1102 return -ENOMEM;
1048 } 1103 }
1049 if (ep_info->in_interval) 1104 if (ep_info->in_interval)
1050 usb_fill_int_urb(ep->urbs[i], umidi->chip->dev, 1105 usb_fill_int_urb(ep->urbs[i], umidi->dev,
1051 pipe, buffer, length, 1106 pipe, buffer, length,
1052 snd_usbmidi_in_urb_complete, 1107 snd_usbmidi_in_urb_complete,
1053 ep, ep_info->in_interval); 1108 ep, ep_info->in_interval);
1054 else 1109 else
1055 usb_fill_bulk_urb(ep->urbs[i], umidi->chip->dev, 1110 usb_fill_bulk_urb(ep->urbs[i], umidi->dev,
1056 pipe, buffer, length, 1111 pipe, buffer, length,
1057 snd_usbmidi_in_urb_complete, ep); 1112 snd_usbmidi_in_urb_complete, ep);
1058 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 1113 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
@@ -1062,15 +1117,6 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
1062 return 0; 1117 return 0;
1063} 1118}
1064 1119
1065static unsigned int snd_usbmidi_count_bits(unsigned int x)
1066{
1067 unsigned int bits;
1068
1069 for (bits = 0; x; ++bits)
1070 x &= x - 1;
1071 return bits;
1072}
1073
1074/* 1120/*
1075 * Frees an output endpoint. 1121 * Frees an output endpoint.
1076 * May be called when ep hasn't been initialized completely. 1122 * May be called when ep hasn't been initialized completely.
@@ -1113,15 +1159,15 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1113 ep->urbs[i].ep = ep; 1159 ep->urbs[i].ep = ep;
1114 } 1160 }
1115 if (ep_info->out_interval) 1161 if (ep_info->out_interval)
1116 pipe = usb_sndintpipe(umidi->chip->dev, ep_info->out_ep); 1162 pipe = usb_sndintpipe(umidi->dev, ep_info->out_ep);
1117 else 1163 else
1118 pipe = usb_sndbulkpipe(umidi->chip->dev, ep_info->out_ep); 1164 pipe = usb_sndbulkpipe(umidi->dev, ep_info->out_ep);
1119 if (umidi->chip->usb_id == USB_ID(0x0a92, 0x1020)) /* ESI M4U */ 1165 if (umidi->usb_id == USB_ID(0x0a92, 0x1020)) /* ESI M4U */
1120 ep->max_transfer = 4; 1166 ep->max_transfer = 4;
1121 else 1167 else
1122 ep->max_transfer = usb_maxpacket(umidi->chip->dev, pipe, 1); 1168 ep->max_transfer = usb_maxpacket(umidi->dev, pipe, 1);
1123 for (i = 0; i < OUTPUT_URBS; ++i) { 1169 for (i = 0; i < OUTPUT_URBS; ++i) {
1124 buffer = usb_buffer_alloc(umidi->chip->dev, 1170 buffer = usb_buffer_alloc(umidi->dev,
1125 ep->max_transfer, GFP_KERNEL, 1171 ep->max_transfer, GFP_KERNEL,
1126 &ep->urbs[i].urb->transfer_dma); 1172 &ep->urbs[i].urb->transfer_dma);
1127 if (!buffer) { 1173 if (!buffer) {
@@ -1129,12 +1175,12 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1129 return -ENOMEM; 1175 return -ENOMEM;
1130 } 1176 }
1131 if (ep_info->out_interval) 1177 if (ep_info->out_interval)
1132 usb_fill_int_urb(ep->urbs[i].urb, umidi->chip->dev, 1178 usb_fill_int_urb(ep->urbs[i].urb, umidi->dev,
1133 pipe, buffer, ep->max_transfer, 1179 pipe, buffer, ep->max_transfer,
1134 snd_usbmidi_out_urb_complete, 1180 snd_usbmidi_out_urb_complete,
1135 &ep->urbs[i], ep_info->out_interval); 1181 &ep->urbs[i], ep_info->out_interval);
1136 else 1182 else
1137 usb_fill_bulk_urb(ep->urbs[i].urb, umidi->chip->dev, 1183 usb_fill_bulk_urb(ep->urbs[i].urb, umidi->dev,
1138 pipe, buffer, ep->max_transfer, 1184 pipe, buffer, ep->max_transfer,
1139 snd_usbmidi_out_urb_complete, 1185 snd_usbmidi_out_urb_complete,
1140 &ep->urbs[i]); 1186 &ep->urbs[i]);
@@ -1172,6 +1218,7 @@ static void snd_usbmidi_free(struct snd_usb_midi* umidi)
1172 if (ep->in) 1218 if (ep->in)
1173 snd_usbmidi_in_endpoint_delete(ep->in); 1219 snd_usbmidi_in_endpoint_delete(ep->in);
1174 } 1220 }
1221 mutex_destroy(&umidi->mutex);
1175 kfree(umidi); 1222 kfree(umidi);
1176} 1223}
1177 1224
@@ -1367,7 +1414,7 @@ static struct port_info *find_port_info(struct snd_usb_midi* umidi, int number)
1367 int i; 1414 int i;
1368 1415
1369 for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) { 1416 for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) {
1370 if (snd_usbmidi_port_info[i].id == umidi->chip->usb_id && 1417 if (snd_usbmidi_port_info[i].id == umidi->usb_id &&
1371 snd_usbmidi_port_info[i].port == number) 1418 snd_usbmidi_port_info[i].port == number)
1372 return &snd_usbmidi_port_info[i]; 1419 return &snd_usbmidi_port_info[i];
1373 } 1420 }
@@ -1405,7 +1452,7 @@ static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
1405 port_info = find_port_info(umidi, number); 1452 port_info = find_port_info(umidi, number);
1406 name_format = port_info ? port_info->name : "%s MIDI %d"; 1453 name_format = port_info ? port_info->name : "%s MIDI %d";
1407 snprintf(substream->name, sizeof(substream->name), 1454 snprintf(substream->name, sizeof(substream->name),
1408 name_format, umidi->chip->card->shortname, number + 1); 1455 name_format, umidi->card->shortname, number + 1);
1409 1456
1410 *rsubstream = substream; 1457 *rsubstream = substream;
1411} 1458}
@@ -1503,7 +1550,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1503 endpoints[epidx].out_ep = usb_endpoint_num(ep); 1550 endpoints[epidx].out_ep = usb_endpoint_num(ep);
1504 if (usb_endpoint_xfer_int(ep)) 1551 if (usb_endpoint_xfer_int(ep))
1505 endpoints[epidx].out_interval = ep->bInterval; 1552 endpoints[epidx].out_interval = ep->bInterval;
1506 else if (snd_usb_get_speed(umidi->chip->dev) == USB_SPEED_LOW) 1553 else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
1507 /* 1554 /*
1508 * Low speed bulk transfers don't exist, so 1555 * Low speed bulk transfers don't exist, so
1509 * force interrupt transfers for devices like 1556 * force interrupt transfers for devices like
@@ -1523,7 +1570,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1523 endpoints[epidx].in_ep = usb_endpoint_num(ep); 1570 endpoints[epidx].in_ep = usb_endpoint_num(ep);
1524 if (usb_endpoint_xfer_int(ep)) 1571 if (usb_endpoint_xfer_int(ep))
1525 endpoints[epidx].in_interval = ep->bInterval; 1572 endpoints[epidx].in_interval = ep->bInterval;
1526 else if (snd_usb_get_speed(umidi->chip->dev) == USB_SPEED_LOW) 1573 else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
1527 endpoints[epidx].in_interval = 1; 1574 endpoints[epidx].in_interval = 1;
1528 endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1; 1575 endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
1529 snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n", 1576 snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
@@ -1533,6 +1580,52 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1533 return 0; 1580 return 0;
1534} 1581}
1535 1582
1583static int roland_load_info(struct snd_kcontrol *kcontrol,
1584 struct snd_ctl_elem_info *info)
1585{
1586 static const char *const names[] = { "High Load", "Light Load" };
1587
1588 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1589 info->count = 1;
1590 info->value.enumerated.items = 2;
1591 if (info->value.enumerated.item > 1)
1592 info->value.enumerated.item = 1;
1593 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
1594 return 0;
1595}
1596
1597static int roland_load_get(struct snd_kcontrol *kcontrol,
1598 struct snd_ctl_elem_value *value)
1599{
1600 value->value.enumerated.item[0] = kcontrol->private_value;
1601 return 0;
1602}
1603
1604static int roland_load_put(struct snd_kcontrol *kcontrol,
1605 struct snd_ctl_elem_value *value)
1606{
1607 struct snd_usb_midi* umidi = kcontrol->private_data;
1608 int changed;
1609
1610 if (value->value.enumerated.item[0] > 1)
1611 return -EINVAL;
1612 mutex_lock(&umidi->mutex);
1613 changed = value->value.enumerated.item[0] != kcontrol->private_value;
1614 if (changed)
1615 kcontrol->private_value = value->value.enumerated.item[0];
1616 mutex_unlock(&umidi->mutex);
1617 return changed;
1618}
1619
1620static struct snd_kcontrol_new roland_load_ctl = {
1621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1622 .name = "MIDI Input Mode",
1623 .info = roland_load_info,
1624 .get = roland_load_get,
1625 .put = roland_load_put,
1626 .private_value = 1,
1627};
1628
1536/* 1629/*
1537 * On Roland devices, use the second alternate setting to be able to use 1630 * On Roland devices, use the second alternate setting to be able to use
1538 * the interrupt input endpoint. 1631 * the interrupt input endpoint.
@@ -1556,8 +1649,12 @@ static void snd_usbmidi_switch_roland_altsetting(struct snd_usb_midi* umidi)
1556 1649
1557 snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n", 1650 snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n",
1558 intfd->bAlternateSetting); 1651 intfd->bAlternateSetting);
1559 usb_set_interface(umidi->chip->dev, intfd->bInterfaceNumber, 1652 usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
1560 intfd->bAlternateSetting); 1653 intfd->bAlternateSetting);
1654
1655 umidi->roland_load_ctl = snd_ctl_new1(&roland_load_ctl, umidi);
1656 if (snd_ctl_add(umidi->card, umidi->roland_load_ctl) < 0)
1657 umidi->roland_load_ctl = NULL;
1561} 1658}
1562 1659
1563/* 1660/*
@@ -1573,7 +1670,7 @@ static int snd_usbmidi_detect_endpoints(struct snd_usb_midi* umidi,
1573 struct usb_endpoint_descriptor* epd; 1670 struct usb_endpoint_descriptor* epd;
1574 int i, out_eps = 0, in_eps = 0; 1671 int i, out_eps = 0, in_eps = 0;
1575 1672
1576 if (USB_ID_VENDOR(umidi->chip->usb_id) == 0x0582) 1673 if (USB_ID_VENDOR(umidi->usb_id) == 0x0582)
1577 snd_usbmidi_switch_roland_altsetting(umidi); 1674 snd_usbmidi_switch_roland_altsetting(umidi);
1578 1675
1579 if (endpoint[0].out_ep || endpoint[0].in_ep) 1676 if (endpoint[0].out_ep || endpoint[0].in_ep)
@@ -1760,12 +1857,12 @@ static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
1760 struct snd_rawmidi *rmidi; 1857 struct snd_rawmidi *rmidi;
1761 int err; 1858 int err;
1762 1859
1763 err = snd_rawmidi_new(umidi->chip->card, "USB MIDI", 1860 err = snd_rawmidi_new(umidi->card, "USB MIDI",
1764 umidi->chip->next_midi_device++, 1861 umidi->next_midi_device++,
1765 out_ports, in_ports, &rmidi); 1862 out_ports, in_ports, &rmidi);
1766 if (err < 0) 1863 if (err < 0)
1767 return err; 1864 return err;
1768 strcpy(rmidi->name, umidi->chip->card->shortname); 1865 strcpy(rmidi->name, umidi->card->shortname);
1769 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | 1866 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
1770 SNDRV_RAWMIDI_INFO_INPUT | 1867 SNDRV_RAWMIDI_INFO_INPUT |
1771 SNDRV_RAWMIDI_INFO_DUPLEX; 1868 SNDRV_RAWMIDI_INFO_DUPLEX;
@@ -1804,7 +1901,7 @@ static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep)
1804 return; 1901 return;
1805 for (i = 0; i < INPUT_URBS; ++i) { 1902 for (i = 0; i < INPUT_URBS; ++i) {
1806 struct urb* urb = ep->urbs[i]; 1903 struct urb* urb = ep->urbs[i];
1807 urb->dev = ep->umidi->chip->dev; 1904 urb->dev = ep->umidi->dev;
1808 snd_usbmidi_submit_urb(urb, GFP_KERNEL); 1905 snd_usbmidi_submit_urb(urb, GFP_KERNEL);
1809 } 1906 }
1810} 1907}
@@ -1825,9 +1922,10 @@ void snd_usbmidi_input_start(struct list_head* p)
1825/* 1922/*
1826 * Creates and registers everything needed for a MIDI streaming interface. 1923 * Creates and registers everything needed for a MIDI streaming interface.
1827 */ 1924 */
1828int snd_usb_create_midi_interface(struct snd_usb_audio* chip, 1925int snd_usbmidi_create(struct snd_card *card,
1829 struct usb_interface* iface, 1926 struct usb_interface* iface,
1830 const struct snd_usb_audio_quirk* quirk) 1927 struct list_head *midi_list,
1928 const struct snd_usb_audio_quirk* quirk)
1831{ 1929{
1832 struct snd_usb_midi* umidi; 1930 struct snd_usb_midi* umidi;
1833 struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS]; 1931 struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
@@ -1837,12 +1935,16 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1837 umidi = kzalloc(sizeof(*umidi), GFP_KERNEL); 1935 umidi = kzalloc(sizeof(*umidi), GFP_KERNEL);
1838 if (!umidi) 1936 if (!umidi)
1839 return -ENOMEM; 1937 return -ENOMEM;
1840 umidi->chip = chip; 1938 umidi->dev = interface_to_usbdev(iface);
1939 umidi->card = card;
1841 umidi->iface = iface; 1940 umidi->iface = iface;
1842 umidi->quirk = quirk; 1941 umidi->quirk = quirk;
1843 umidi->usb_protocol_ops = &snd_usbmidi_standard_ops; 1942 umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
1844 init_timer(&umidi->error_timer); 1943 init_timer(&umidi->error_timer);
1845 spin_lock_init(&umidi->disc_lock); 1944 spin_lock_init(&umidi->disc_lock);
1945 mutex_init(&umidi->mutex);
1946 umidi->usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
1947 le16_to_cpu(umidi->dev->descriptor.idProduct));
1846 umidi->error_timer.function = snd_usbmidi_error_timer; 1948 umidi->error_timer.function = snd_usbmidi_error_timer;
1847 umidi->error_timer.data = (unsigned long)umidi; 1949 umidi->error_timer.data = (unsigned long)umidi;
1848 1950
@@ -1851,7 +1953,7 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1851 switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) { 1953 switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
1852 case QUIRK_MIDI_STANDARD_INTERFACE: 1954 case QUIRK_MIDI_STANDARD_INTERFACE:
1853 err = snd_usbmidi_get_ms_info(umidi, endpoints); 1955 err = snd_usbmidi_get_ms_info(umidi, endpoints);
1854 if (chip->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */ 1956 if (umidi->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */
1855 umidi->usb_protocol_ops = 1957 umidi->usb_protocol_ops =
1856 &snd_usbmidi_maudio_broken_running_status_ops; 1958 &snd_usbmidi_maudio_broken_running_status_ops;
1857 break; 1959 break;
@@ -1887,7 +1989,7 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1887 * interface 0, so we have to make sure that the USB core looks 1989 * interface 0, so we have to make sure that the USB core looks
1888 * again at interface 0 by calling usb_set_interface() on it. 1990 * again at interface 0 by calling usb_set_interface() on it.
1889 */ 1991 */
1890 usb_set_interface(umidi->chip->dev, 0, 0); 1992 usb_set_interface(umidi->dev, 0, 0);
1891 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 1993 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
1892 break; 1994 break;
1893 case QUIRK_MIDI_EMAGIC: 1995 case QUIRK_MIDI_EMAGIC:
@@ -1914,8 +2016,8 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1914 out_ports = 0; 2016 out_ports = 0;
1915 in_ports = 0; 2017 in_ports = 0;
1916 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) { 2018 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
1917 out_ports += snd_usbmidi_count_bits(endpoints[i].out_cables); 2019 out_ports += hweight16(endpoints[i].out_cables);
1918 in_ports += snd_usbmidi_count_bits(endpoints[i].in_cables); 2020 in_ports += hweight16(endpoints[i].in_cables);
1919 } 2021 }
1920 err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports); 2022 err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
1921 if (err < 0) { 2023 if (err < 0) {
@@ -1933,14 +2035,14 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1933 return err; 2035 return err;
1934 } 2036 }
1935 2037
1936 list_add(&umidi->list, &umidi->chip->midi_list); 2038 list_add_tail(&umidi->list, midi_list);
1937 2039
1938 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) 2040 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
1939 snd_usbmidi_input_start_ep(umidi->endpoints[i].in); 2041 snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
1940 return 0; 2042 return 0;
1941} 2043}
1942 2044
1943EXPORT_SYMBOL(snd_usb_create_midi_interface); 2045EXPORT_SYMBOL(snd_usbmidi_create);
1944EXPORT_SYMBOL(snd_usbmidi_input_stop); 2046EXPORT_SYMBOL(snd_usbmidi_input_stop);
1945EXPORT_SYMBOL(snd_usbmidi_input_start); 2047EXPORT_SYMBOL(snd_usbmidi_input_start);
1946EXPORT_SYMBOL(snd_usbmidi_disconnect); 2048EXPORT_SYMBOL(snd_usbmidi_disconnect);
diff --git a/sound/usb/usbmixer_maps.c b/sound/usb/usbmixer_maps.c
index 3e5d66cf1f5a..77c35885e21c 100644
--- a/sound/usb/usbmixer_maps.c
+++ b/sound/usb/usbmixer_maps.c
@@ -277,6 +277,22 @@ static struct usbmix_name_map scratch_live_map[] = {
277 { 0 } /* terminator */ 277 { 0 } /* terminator */
278}; 278};
279 279
280/* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+"
281 * most importand difference is SU[8], it should be set to "Capture Source"
282 * to make alsamixer and PA working properly.
283 * FIXME: or mp3plus_map should use "Capture Source" too,
284 * so this maps can be merget
285 */
286static struct usbmix_name_map hercules_usb51_map[] = {
287 { 8, "Capture Source" }, /* SU, default "PCM Capture Source" */
288 { 9, "Master Playback" }, /* FU, default "Speaker Playback" */
289 { 10, "Mic Boost", 7 }, /* FU, default "Auto Gain Input" */
290 { 11, "Line Capture" }, /* FU, default "PCM Capture" */
291 { 13, "Mic Bypass Playback" }, /* FU, default "Mic Playback" */
292 { 14, "Line Bypass Playback" }, /* FU, default "Line Playback" */
293 { 0 } /* terminator */
294};
295
280/* 296/*
281 * Control map entries 297 * Control map entries
282 */ 298 */
@@ -316,6 +332,13 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
316 .ignore_ctl_error = 1, 332 .ignore_ctl_error = 1,
317 }, 333 },
318 { 334 {
335 /* Hercules Gamesurround Muse Pocket LT
336 * (USB 5.1 Channel Audio Adapter)
337 */
338 .id = USB_ID(0x06f8, 0xc000),
339 .map = hercules_usb51_map,
340 },
341 {
319 .id = USB_ID(0x08bb, 0x2702), 342 .id = USB_ID(0x08bb, 0x2702),
320 .map = linex_map, 343 .map = linex_map,
321 .ignore_ctl_error = 1, 344 .ignore_ctl_error = 1,
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
index f6f201eb24ce..a892bda03df9 100644
--- a/sound/usb/usbquirks.h
+++ b/sound/usb/usbquirks.h
@@ -1563,6 +1563,29 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1563 } 1563 }
1564 } 1564 }
1565}, 1565},
1566{
1567 /* has ID 0x00ea when not in Advanced Driver mode */
1568 USB_DEVICE_VENDOR_SPEC(0x0582, 0x00e9),
1569 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1570 /* .vendor_name = "Roland", */
1571 /* .product_name = "UA-1G", */
1572 .ifnum = QUIRK_ANY_INTERFACE,
1573 .type = QUIRK_COMPOSITE,
1574 .data = (const struct snd_usb_audio_quirk[]) {
1575 {
1576 .ifnum = 0,
1577 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1578 },
1579 {
1580 .ifnum = 1,
1581 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1582 },
1583 {
1584 .ifnum = -1
1585 }
1586 }
1587 }
1588},
1566 1589
1567/* Guillemot devices */ 1590/* Guillemot devices */
1568{ 1591{
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 99f33766cd51..f71cd28eca6b 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -59,11 +59,33 @@ static int us122l_create_usbmidi(struct snd_card *card)
59 .type = QUIRK_MIDI_US122L, 59 .type = QUIRK_MIDI_US122L,
60 .data = &quirk_data 60 .data = &quirk_data
61 }; 61 };
62 struct usb_device *dev = US122L(card)->chip.dev; 62 struct usb_device *dev = US122L(card)->dev;
63 struct usb_interface *iface = usb_ifnum_to_if(dev, 1); 63 struct usb_interface *iface = usb_ifnum_to_if(dev, 1);
64 64
65 return snd_usb_create_midi_interface(&US122L(card)->chip, 65 return snd_usbmidi_create(card, iface,
66 iface, &quirk); 66 &US122L(card)->midi_list, &quirk);
67}
68
69static int us144_create_usbmidi(struct snd_card *card)
70{
71 static struct snd_usb_midi_endpoint_info quirk_data = {
72 .out_ep = 4,
73 .in_ep = 3,
74 .out_cables = 0x001,
75 .in_cables = 0x001
76 };
77 static struct snd_usb_audio_quirk quirk = {
78 .vendor_name = "US144",
79 .product_name = NAME_ALLCAPS,
80 .ifnum = 0,
81 .type = QUIRK_MIDI_US122L,
82 .data = &quirk_data
83 };
84 struct usb_device *dev = US122L(card)->dev;
85 struct usb_interface *iface = usb_ifnum_to_if(dev, 0);
86
87 return snd_usbmidi_create(card, iface,
88 &US122L(card)->midi_list, &quirk);
67} 89}
68 90
69/* 91/*
@@ -171,7 +193,12 @@ static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file)
171 193
172 if (!us122l->first) 194 if (!us122l->first)
173 us122l->first = file; 195 us122l->first = file;
174 iface = usb_ifnum_to_if(us122l->chip.dev, 1); 196
197 if (us122l->dev->descriptor.idProduct == USB_ID_US144) {
198 iface = usb_ifnum_to_if(us122l->dev, 0);
199 usb_autopm_get_interface(iface);
200 }
201 iface = usb_ifnum_to_if(us122l->dev, 1);
175 usb_autopm_get_interface(iface); 202 usb_autopm_get_interface(iface);
176 return 0; 203 return 0;
177} 204}
@@ -179,8 +206,14 @@ static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file)
179static int usb_stream_hwdep_release(struct snd_hwdep *hw, struct file *file) 206static int usb_stream_hwdep_release(struct snd_hwdep *hw, struct file *file)
180{ 207{
181 struct us122l *us122l = hw->private_data; 208 struct us122l *us122l = hw->private_data;
182 struct usb_interface *iface = usb_ifnum_to_if(us122l->chip.dev, 1); 209 struct usb_interface *iface;
183 snd_printdd(KERN_DEBUG "%p %p\n", hw, file); 210 snd_printdd(KERN_DEBUG "%p %p\n", hw, file);
211
212 if (us122l->dev->descriptor.idProduct == USB_ID_US144) {
213 iface = usb_ifnum_to_if(us122l->dev, 0);
214 usb_autopm_put_interface(iface);
215 }
216 iface = usb_ifnum_to_if(us122l->dev, 1);
184 usb_autopm_put_interface(iface); 217 usb_autopm_put_interface(iface);
185 if (us122l->first == file) 218 if (us122l->first == file)
186 us122l->first = NULL; 219 us122l->first = NULL;
@@ -264,7 +297,7 @@ static unsigned int usb_stream_hwdep_poll(struct snd_hwdep *hw,
264static void us122l_stop(struct us122l *us122l) 297static void us122l_stop(struct us122l *us122l)
265{ 298{
266 struct list_head *p; 299 struct list_head *p;
267 list_for_each(p, &us122l->chip.midi_list) 300 list_for_each(p, &us122l->midi_list)
268 snd_usbmidi_input_stop(p); 301 snd_usbmidi_input_stop(p);
269 302
270 usb_stream_stop(&us122l->sk); 303 usb_stream_stop(&us122l->sk);
@@ -297,7 +330,7 @@ static bool us122l_start(struct us122l *us122l,
297 unsigned use_packsize = 0; 330 unsigned use_packsize = 0;
298 bool success = false; 331 bool success = false;
299 332
300 if (us122l->chip.dev->speed == USB_SPEED_HIGH) { 333 if (us122l->dev->speed == USB_SPEED_HIGH) {
301 /* The us-122l's descriptor defaults to iso max_packsize 78, 334 /* The us-122l's descriptor defaults to iso max_packsize 78,
302 which isn't needed for samplerates <= 48000. 335 which isn't needed for samplerates <= 48000.
303 Lets save some memory: 336 Lets save some memory:
@@ -314,11 +347,11 @@ static bool us122l_start(struct us122l *us122l,
314 break; 347 break;
315 } 348 }
316 } 349 }
317 if (!usb_stream_new(&us122l->sk, us122l->chip.dev, 1, 2, 350 if (!usb_stream_new(&us122l->sk, us122l->dev, 1, 2,
318 rate, use_packsize, period_frames, 6)) 351 rate, use_packsize, period_frames, 6))
319 goto out; 352 goto out;
320 353
321 err = us122l_set_sample_rate(us122l->chip.dev, rate); 354 err = us122l_set_sample_rate(us122l->dev, rate);
322 if (err < 0) { 355 if (err < 0) {
323 us122l_stop(us122l); 356 us122l_stop(us122l);
324 snd_printk(KERN_ERR "us122l_set_sample_rate error \n"); 357 snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
@@ -330,7 +363,7 @@ static bool us122l_start(struct us122l *us122l,
330 snd_printk(KERN_ERR "us122l_start error %i \n", err); 363 snd_printk(KERN_ERR "us122l_start error %i \n", err);
331 goto out; 364 goto out;
332 } 365 }
333 list_for_each(p, &us122l->chip.midi_list) 366 list_for_each(p, &us122l->midi_list)
334 snd_usbmidi_input_start(p); 367 snd_usbmidi_input_start(p);
335 success = true; 368 success = true;
336out: 369out:
@@ -357,7 +390,7 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
357 err = -ENXIO; 390 err = -ENXIO;
358 goto free; 391 goto free;
359 } 392 }
360 high_speed = us122l->chip.dev->speed == USB_SPEED_HIGH; 393 high_speed = us122l->dev->speed == USB_SPEED_HIGH;
361 if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000 && 394 if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000 &&
362 (!high_speed || 395 (!high_speed ||
363 (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) || 396 (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) ||
@@ -417,7 +450,7 @@ static int usb_stream_hwdep_new(struct snd_card *card)
417{ 450{
418 int err; 451 int err;
419 struct snd_hwdep *hw; 452 struct snd_hwdep *hw;
420 struct usb_device *dev = US122L(card)->chip.dev; 453 struct usb_device *dev = US122L(card)->dev;
421 454
422 err = snd_hwdep_new(card, SND_USB_STREAM_ID, 0, &hw); 455 err = snd_hwdep_new(card, SND_USB_STREAM_ID, 0, &hw);
423 if (err < 0) 456 if (err < 0)
@@ -443,19 +476,29 @@ static bool us122l_create_card(struct snd_card *card)
443 int err; 476 int err;
444 struct us122l *us122l = US122L(card); 477 struct us122l *us122l = US122L(card);
445 478
446 err = usb_set_interface(us122l->chip.dev, 1, 1); 479 if (us122l->dev->descriptor.idProduct == USB_ID_US144) {
480 err = usb_set_interface(us122l->dev, 0, 1);
481 if (err) {
482 snd_printk(KERN_ERR "usb_set_interface error \n");
483 return false;
484 }
485 }
486 err = usb_set_interface(us122l->dev, 1, 1);
447 if (err) { 487 if (err) {
448 snd_printk(KERN_ERR "usb_set_interface error \n"); 488 snd_printk(KERN_ERR "usb_set_interface error \n");
449 return false; 489 return false;
450 } 490 }
451 491
452 pt_info_set(us122l->chip.dev, 0x11); 492 pt_info_set(us122l->dev, 0x11);
453 pt_info_set(us122l->chip.dev, 0x10); 493 pt_info_set(us122l->dev, 0x10);
454 494
455 if (!us122l_start(us122l, 44100, 256)) 495 if (!us122l_start(us122l, 44100, 256))
456 return false; 496 return false;
457 497
458 err = us122l_create_usbmidi(card); 498 if (us122l->dev->descriptor.idProduct == USB_ID_US144)
499 err = us144_create_usbmidi(card);
500 else
501 err = us122l_create_usbmidi(card);
459 if (err < 0) { 502 if (err < 0) {
460 snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err); 503 snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err);
461 us122l_stop(us122l); 504 us122l_stop(us122l);
@@ -465,7 +508,7 @@ static bool us122l_create_card(struct snd_card *card)
465 if (err < 0) { 508 if (err < 0) {
466/* release the midi resources */ 509/* release the midi resources */
467 struct list_head *p; 510 struct list_head *p;
468 list_for_each(p, &us122l->chip.midi_list) 511 list_for_each(p, &us122l->midi_list)
469 snd_usbmidi_disconnect(p); 512 snd_usbmidi_disconnect(p);
470 513
471 us122l_stop(us122l); 514 us122l_stop(us122l);
@@ -477,7 +520,7 @@ static bool us122l_create_card(struct snd_card *card)
477static void snd_us122l_free(struct snd_card *card) 520static void snd_us122l_free(struct snd_card *card)
478{ 521{
479 struct us122l *us122l = US122L(card); 522 struct us122l *us122l = US122L(card);
480 int index = us122l->chip.index; 523 int index = us122l->card_index;
481 if (index >= 0 && index < SNDRV_CARDS) 524 if (index >= 0 && index < SNDRV_CARDS)
482 snd_us122l_card_used[index] = 0; 525 snd_us122l_card_used[index] = 0;
483} 526}
@@ -497,13 +540,12 @@ static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
497 sizeof(struct us122l), &card); 540 sizeof(struct us122l), &card);
498 if (err < 0) 541 if (err < 0)
499 return err; 542 return err;
500 snd_us122l_card_used[US122L(card)->chip.index = dev] = 1; 543 snd_us122l_card_used[US122L(card)->card_index = dev] = 1;
501 card->private_free = snd_us122l_free; 544 card->private_free = snd_us122l_free;
502 US122L(card)->chip.dev = device; 545 US122L(card)->dev = device;
503 US122L(card)->chip.card = card;
504 mutex_init(&US122L(card)->mutex); 546 mutex_init(&US122L(card)->mutex);
505 init_waitqueue_head(&US122L(card)->sk.sleep); 547 init_waitqueue_head(&US122L(card)->sk.sleep);
506 INIT_LIST_HEAD(&US122L(card)->chip.midi_list); 548 INIT_LIST_HEAD(&US122L(card)->midi_list);
507 strcpy(card->driver, "USB "NAME_ALLCAPS""); 549 strcpy(card->driver, "USB "NAME_ALLCAPS"");
508 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS""); 550 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
509 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)", 551 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
@@ -511,8 +553,8 @@ static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
511 le16_to_cpu(device->descriptor.idVendor), 553 le16_to_cpu(device->descriptor.idVendor),
512 le16_to_cpu(device->descriptor.idProduct), 554 le16_to_cpu(device->descriptor.idProduct),
513 0, 555 0,
514 US122L(card)->chip.dev->bus->busnum, 556 US122L(card)->dev->bus->busnum,
515 US122L(card)->chip.dev->devnum 557 US122L(card)->dev->devnum
516 ); 558 );
517 *cardp = card; 559 *cardp = card;
518 return 0; 560 return 0;
@@ -542,6 +584,7 @@ static int us122l_usb_probe(struct usb_interface *intf,
542 return err; 584 return err;
543 } 585 }
544 586
587 usb_get_intf(usb_ifnum_to_if(device, 0));
545 usb_get_dev(device); 588 usb_get_dev(device);
546 *cardp = card; 589 *cardp = card;
547 return 0; 590 return 0;
@@ -550,9 +593,16 @@ static int us122l_usb_probe(struct usb_interface *intf,
550static int snd_us122l_probe(struct usb_interface *intf, 593static int snd_us122l_probe(struct usb_interface *intf,
551 const struct usb_device_id *id) 594 const struct usb_device_id *id)
552{ 595{
596 struct usb_device *device = interface_to_usbdev(intf);
553 struct snd_card *card; 597 struct snd_card *card;
554 int err; 598 int err;
555 599
600 if (device->descriptor.idProduct == USB_ID_US144
601 && device->speed == USB_SPEED_HIGH) {
602 snd_printk(KERN_ERR "disable ehci-hcd to run US-144 \n");
603 return -ENODEV;
604 }
605
556 snd_printdd(KERN_DEBUG"%p:%i\n", 606 snd_printdd(KERN_DEBUG"%p:%i\n",
557 intf, intf->cur_altsetting->desc.bInterfaceNumber); 607 intf, intf->cur_altsetting->desc.bInterfaceNumber);
558 if (intf->cur_altsetting->desc.bInterfaceNumber != 1) 608 if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
@@ -584,15 +634,15 @@ static void snd_us122l_disconnect(struct usb_interface *intf)
584 mutex_lock(&us122l->mutex); 634 mutex_lock(&us122l->mutex);
585 us122l_stop(us122l); 635 us122l_stop(us122l);
586 mutex_unlock(&us122l->mutex); 636 mutex_unlock(&us122l->mutex);
587 us122l->chip.shutdown = 1;
588 637
589/* release the midi resources */ 638/* release the midi resources */
590 list_for_each(p, &us122l->chip.midi_list) { 639 list_for_each(p, &us122l->midi_list) {
591 snd_usbmidi_disconnect(p); 640 snd_usbmidi_disconnect(p);
592 } 641 }
593 642
594 usb_put_intf(intf); 643 usb_put_intf(usb_ifnum_to_if(us122l->dev, 0));
595 usb_put_dev(us122l->chip.dev); 644 usb_put_intf(usb_ifnum_to_if(us122l->dev, 1));
645 usb_put_dev(us122l->dev);
596 646
597 while (atomic_read(&us122l->mmap_count)) 647 while (atomic_read(&us122l->mmap_count))
598 msleep(500); 648 msleep(500);
@@ -615,7 +665,7 @@ static int snd_us122l_suspend(struct usb_interface *intf, pm_message_t message)
615 if (!us122l) 665 if (!us122l)
616 return 0; 666 return 0;
617 667
618 list_for_each(p, &us122l->chip.midi_list) 668 list_for_each(p, &us122l->midi_list)
619 snd_usbmidi_input_stop(p); 669 snd_usbmidi_input_stop(p);
620 670
621 mutex_lock(&us122l->mutex); 671 mutex_lock(&us122l->mutex);
@@ -642,16 +692,23 @@ static int snd_us122l_resume(struct usb_interface *intf)
642 692
643 mutex_lock(&us122l->mutex); 693 mutex_lock(&us122l->mutex);
644 /* needed, doesn't restart without: */ 694 /* needed, doesn't restart without: */
645 err = usb_set_interface(us122l->chip.dev, 1, 1); 695 if (us122l->dev->descriptor.idProduct == USB_ID_US144) {
696 err = usb_set_interface(us122l->dev, 0, 1);
697 if (err) {
698 snd_printk(KERN_ERR "usb_set_interface error \n");
699 goto unlock;
700 }
701 }
702 err = usb_set_interface(us122l->dev, 1, 1);
646 if (err) { 703 if (err) {
647 snd_printk(KERN_ERR "usb_set_interface error \n"); 704 snd_printk(KERN_ERR "usb_set_interface error \n");
648 goto unlock; 705 goto unlock;
649 } 706 }
650 707
651 pt_info_set(us122l->chip.dev, 0x11); 708 pt_info_set(us122l->dev, 0x11);
652 pt_info_set(us122l->chip.dev, 0x10); 709 pt_info_set(us122l->dev, 0x10);
653 710
654 err = us122l_set_sample_rate(us122l->chip.dev, 711 err = us122l_set_sample_rate(us122l->dev,
655 us122l->sk.s->cfg.sample_rate); 712 us122l->sk.s->cfg.sample_rate);
656 if (err < 0) { 713 if (err < 0) {
657 snd_printk(KERN_ERR "us122l_set_sample_rate error \n"); 714 snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
@@ -661,7 +718,7 @@ static int snd_us122l_resume(struct usb_interface *intf)
661 if (err) 718 if (err)
662 goto unlock; 719 goto unlock;
663 720
664 list_for_each(p, &us122l->chip.midi_list) 721 list_for_each(p, &us122l->midi_list)
665 snd_usbmidi_input_start(p); 722 snd_usbmidi_input_start(p);
666unlock: 723unlock:
667 mutex_unlock(&us122l->mutex); 724 mutex_unlock(&us122l->mutex);
@@ -675,11 +732,11 @@ static struct usb_device_id snd_us122l_usb_id_table[] = {
675 .idVendor = 0x0644, 732 .idVendor = 0x0644,
676 .idProduct = USB_ID_US122L 733 .idProduct = USB_ID_US122L
677 }, 734 },
678/* { */ /* US-144 maybe works when @USB1.1. Untested. */ 735 { /* US-144 only works at USB1.1! Disable module ehci-hcd. */
679/* .match_flags = USB_DEVICE_ID_MATCH_DEVICE, */ 736 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
680/* .idVendor = 0x0644, */ 737 .idVendor = 0x0644,
681/* .idProduct = USB_ID_US144 */ 738 .idProduct = USB_ID_US144
682/* }, */ 739 },
683 { /* terminator */ } 740 { /* terminator */ }
684}; 741};
685 742
diff --git a/sound/usb/usx2y/us122l.h b/sound/usb/usx2y/us122l.h
index 3d10c4b2a0f5..4daf1982e821 100644
--- a/sound/usb/usx2y/us122l.h
+++ b/sound/usb/usx2y/us122l.h
@@ -3,7 +3,8 @@
3 3
4 4
5struct us122l { 5struct us122l {
6 struct snd_usb_audio chip; 6 struct usb_device *dev;
7 int card_index;
7 int stride; 8 int stride;
8 struct usb_stream_kernel sk; 9 struct usb_stream_kernel sk;
9 10
@@ -12,6 +13,7 @@ struct us122l {
12 unsigned second_periods_polled; 13 unsigned second_periods_polled;
13 struct file *master; 14 struct file *master;
14 struct file *slave; 15 struct file *slave;
16 struct list_head midi_list;
15 17
16 atomic_t mmap_count; 18 atomic_t mmap_count;
17}; 19};
diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c
index 52e04b2f35d3..1879b72c40f8 100644
--- a/sound/usb/usx2y/usX2Yhwdep.c
+++ b/sound/usb/usx2y/usX2Yhwdep.c
@@ -114,7 +114,7 @@ static int snd_usX2Y_hwdep_dsp_status(struct snd_hwdep *hw,
114 struct usX2Ydev *us428 = hw->private_data; 114 struct usX2Ydev *us428 = hw->private_data;
115 int id = -1; 115 int id = -1;
116 116
117 switch (le16_to_cpu(us428->chip.dev->descriptor.idProduct)) { 117 switch (le16_to_cpu(us428->dev->descriptor.idProduct)) {
118 case USB_ID_US122: 118 case USB_ID_US122:
119 id = USX2Y_TYPE_122; 119 id = USX2Y_TYPE_122;
120 break; 120 break;
@@ -164,14 +164,14 @@ static int usX2Y_create_usbmidi(struct snd_card *card)
164 .type = QUIRK_MIDI_FIXED_ENDPOINT, 164 .type = QUIRK_MIDI_FIXED_ENDPOINT,
165 .data = &quirk_data_2 165 .data = &quirk_data_2
166 }; 166 };
167 struct usb_device *dev = usX2Y(card)->chip.dev; 167 struct usb_device *dev = usX2Y(card)->dev;
168 struct usb_interface *iface = usb_ifnum_to_if(dev, 0); 168 struct usb_interface *iface = usb_ifnum_to_if(dev, 0);
169 struct snd_usb_audio_quirk *quirk = 169 struct snd_usb_audio_quirk *quirk =
170 le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ? 170 le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ?
171 &quirk_2 : &quirk_1; 171 &quirk_2 : &quirk_1;
172 172
173 snd_printdd("usX2Y_create_usbmidi \n"); 173 snd_printdd("usX2Y_create_usbmidi \n");
174 return snd_usb_create_midi_interface(&usX2Y(card)->chip, iface, quirk); 174 return snd_usbmidi_create(card, iface, &usX2Y(card)->midi_list, quirk);
175} 175}
176 176
177static int usX2Y_create_alsa_devices(struct snd_card *card) 177static int usX2Y_create_alsa_devices(struct snd_card *card)
@@ -202,7 +202,7 @@ static int snd_usX2Y_hwdep_dsp_load(struct snd_hwdep *hw,
202 snd_printdd( "dsp_load %s\n", dsp->name); 202 snd_printdd( "dsp_load %s\n", dsp->name);
203 203
204 if (access_ok(VERIFY_READ, dsp->image, dsp->length)) { 204 if (access_ok(VERIFY_READ, dsp->image, dsp->length)) {
205 struct usb_device* dev = priv->chip.dev; 205 struct usb_device* dev = priv->dev;
206 char *buf; 206 char *buf;
207 207
208 buf = memdup_user(dsp->image, dsp->length); 208 buf = memdup_user(dsp->image, dsp->length);
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index cb4bb8373ca2..c42350eed2eb 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -239,8 +239,8 @@ static void i_usX2Y_In04Int(struct urb *urb)
239 for (j = 0; j < URBS_AsyncSeq && !err; ++j) 239 for (j = 0; j < URBS_AsyncSeq && !err; ++j)
240 if (0 == usX2Y->AS04.urb[j]->status) { 240 if (0 == usX2Y->AS04.urb[j]->status) {
241 struct us428_p4out *p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost. 241 struct us428_p4out *p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost.
242 usb_fill_bulk_urb(usX2Y->AS04.urb[j], usX2Y->chip.dev, 242 usb_fill_bulk_urb(usX2Y->AS04.urb[j], usX2Y->dev,
243 usb_sndbulkpipe(usX2Y->chip.dev, 0x04), &p4out->val.vol, 243 usb_sndbulkpipe(usX2Y->dev, 0x04), &p4out->val.vol,
244 p4out->type == eLT_Light ? sizeof(struct us428_lights) : 5, 244 p4out->type == eLT_Light ? sizeof(struct us428_lights) : 5,
245 i_usX2Y_Out04Int, usX2Y); 245 i_usX2Y_Out04Int, usX2Y);
246 err = usb_submit_urb(usX2Y->AS04.urb[j], GFP_ATOMIC); 246 err = usb_submit_urb(usX2Y->AS04.urb[j], GFP_ATOMIC);
@@ -253,7 +253,7 @@ static void i_usX2Y_In04Int(struct urb *urb)
253 if (err) 253 if (err)
254 snd_printk(KERN_ERR "In04Int() usb_submit_urb err=%i\n", err); 254 snd_printk(KERN_ERR "In04Int() usb_submit_urb err=%i\n", err);
255 255
256 urb->dev = usX2Y->chip.dev; 256 urb->dev = usX2Y->dev;
257 usb_submit_urb(urb, GFP_ATOMIC); 257 usb_submit_urb(urb, GFP_ATOMIC);
258} 258}
259 259
@@ -273,8 +273,8 @@ int usX2Y_AsyncSeq04_init(struct usX2Ydev *usX2Y)
273 err = -ENOMEM; 273 err = -ENOMEM;
274 break; 274 break;
275 } 275 }
276 usb_fill_bulk_urb( usX2Y->AS04.urb[i], usX2Y->chip.dev, 276 usb_fill_bulk_urb( usX2Y->AS04.urb[i], usX2Y->dev,
277 usb_sndbulkpipe(usX2Y->chip.dev, 0x04), 277 usb_sndbulkpipe(usX2Y->dev, 0x04),
278 usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0, 278 usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0,
279 i_usX2Y_Out04Int, usX2Y 279 i_usX2Y_Out04Int, usX2Y
280 ); 280 );
@@ -293,7 +293,7 @@ int usX2Y_In04_init(struct usX2Ydev *usX2Y)
293 } 293 }
294 294
295 init_waitqueue_head(&usX2Y->In04WaitQueue); 295 init_waitqueue_head(&usX2Y->In04WaitQueue);
296 usb_fill_int_urb(usX2Y->In04urb, usX2Y->chip.dev, usb_rcvintpipe(usX2Y->chip.dev, 0x4), 296 usb_fill_int_urb(usX2Y->In04urb, usX2Y->dev, usb_rcvintpipe(usX2Y->dev, 0x4),
297 usX2Y->In04Buf, 21, 297 usX2Y->In04Buf, 21,
298 i_usX2Y_In04Int, usX2Y, 298 i_usX2Y_In04Int, usX2Y,
299 10); 299 10);
@@ -348,13 +348,12 @@ static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
348 sizeof(struct usX2Ydev), &card); 348 sizeof(struct usX2Ydev), &card);
349 if (err < 0) 349 if (err < 0)
350 return err; 350 return err;
351 snd_usX2Y_card_used[usX2Y(card)->chip.index = dev] = 1; 351 snd_usX2Y_card_used[usX2Y(card)->card_index = dev] = 1;
352 card->private_free = snd_usX2Y_card_private_free; 352 card->private_free = snd_usX2Y_card_private_free;
353 usX2Y(card)->chip.dev = device; 353 usX2Y(card)->dev = device;
354 usX2Y(card)->chip.card = card;
355 init_waitqueue_head(&usX2Y(card)->prepare_wait_queue); 354 init_waitqueue_head(&usX2Y(card)->prepare_wait_queue);
356 mutex_init(&usX2Y(card)->prepare_mutex); 355 mutex_init(&usX2Y(card)->prepare_mutex);
357 INIT_LIST_HEAD(&usX2Y(card)->chip.midi_list); 356 INIT_LIST_HEAD(&usX2Y(card)->midi_list);
358 strcpy(card->driver, "USB "NAME_ALLCAPS""); 357 strcpy(card->driver, "USB "NAME_ALLCAPS"");
359 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS""); 358 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
360 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)", 359 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
@@ -362,7 +361,7 @@ static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
362 le16_to_cpu(device->descriptor.idVendor), 361 le16_to_cpu(device->descriptor.idVendor),
363 le16_to_cpu(device->descriptor.idProduct), 362 le16_to_cpu(device->descriptor.idProduct),
364 0,//us428(card)->usbmidi.ifnum, 363 0,//us428(card)->usbmidi.ifnum,
365 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum 364 usX2Y(card)->dev->bus->busnum, usX2Y(card)->dev->devnum
366 ); 365 );
367 *cardp = card; 366 *cardp = card;
368 return 0; 367 return 0;
@@ -432,8 +431,8 @@ static void snd_usX2Y_card_private_free(struct snd_card *card)
432 usb_free_urb(usX2Y(card)->In04urb); 431 usb_free_urb(usX2Y(card)->In04urb);
433 if (usX2Y(card)->us428ctls_sharedmem) 432 if (usX2Y(card)->us428ctls_sharedmem)
434 snd_free_pages(usX2Y(card)->us428ctls_sharedmem, sizeof(*usX2Y(card)->us428ctls_sharedmem)); 433 snd_free_pages(usX2Y(card)->us428ctls_sharedmem, sizeof(*usX2Y(card)->us428ctls_sharedmem));
435 if (usX2Y(card)->chip.index >= 0 && usX2Y(card)->chip.index < SNDRV_CARDS) 434 if (usX2Y(card)->card_index >= 0 && usX2Y(card)->card_index < SNDRV_CARDS)
436 snd_usX2Y_card_used[usX2Y(card)->chip.index] = 0; 435 snd_usX2Y_card_used[usX2Y(card)->card_index] = 0;
437} 436}
438 437
439/* 438/*
@@ -445,13 +444,12 @@ static void usX2Y_usb_disconnect(struct usb_device *device, void* ptr)
445 struct snd_card *card = ptr; 444 struct snd_card *card = ptr;
446 struct usX2Ydev *usX2Y = usX2Y(card); 445 struct usX2Ydev *usX2Y = usX2Y(card);
447 struct list_head *p; 446 struct list_head *p;
448 usX2Y->chip.shutdown = 1;
449 usX2Y->chip_status = USX2Y_STAT_CHIP_HUP; 447 usX2Y->chip_status = USX2Y_STAT_CHIP_HUP;
450 usX2Y_unlinkSeq(&usX2Y->AS04); 448 usX2Y_unlinkSeq(&usX2Y->AS04);
451 usb_kill_urb(usX2Y->In04urb); 449 usb_kill_urb(usX2Y->In04urb);
452 snd_card_disconnect(card); 450 snd_card_disconnect(card);
453 /* release the midi resources */ 451 /* release the midi resources */
454 list_for_each(p, &usX2Y->chip.midi_list) { 452 list_for_each(p, &usX2Y->midi_list) {
455 snd_usbmidi_disconnect(p); 453 snd_usbmidi_disconnect(p);
456 } 454 }
457 if (usX2Y->us428ctls_sharedmem) 455 if (usX2Y->us428ctls_sharedmem)
diff --git a/sound/usb/usx2y/usbusx2y.h b/sound/usb/usx2y/usbusx2y.h
index 456b5fdbc339..1d174cea352b 100644
--- a/sound/usb/usx2y/usbusx2y.h
+++ b/sound/usb/usx2y/usbusx2y.h
@@ -22,7 +22,8 @@ struct snd_usX2Y_urbSeq {
22#include "usx2yhwdeppcm.h" 22#include "usx2yhwdeppcm.h"
23 23
24struct usX2Ydev { 24struct usX2Ydev {
25 struct snd_usb_audio chip; 25 struct usb_device *dev;
26 int card_index;
26 int stride; 27 int stride;
27 struct urb *In04urb; 28 struct urb *In04urb;
28 void *In04Buf; 29 void *In04Buf;
@@ -42,6 +43,9 @@ struct usX2Ydev {
42 struct snd_usX2Y_substream *subs[4]; 43 struct snd_usX2Y_substream *subs[4];
43 struct snd_usX2Y_substream * volatile prepare_subs; 44 struct snd_usX2Y_substream * volatile prepare_subs;
44 wait_queue_head_t prepare_wait_queue; 45 wait_queue_head_t prepare_wait_queue;
46 struct list_head midi_list;
47 struct list_head pcm_list;
48 int pcm_devs;
45}; 49};
46 50
47 51
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index 9efd27f6b52f..74a67a85aa81 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -199,7 +199,7 @@ static int usX2Y_urb_submit(struct snd_usX2Y_substream *subs, struct urb *urb, i
199 return -ENODEV; 199 return -ENODEV;
200 urb->start_frame = (frame + NRURBS * nr_of_packs()); // let hcd do rollover sanity checks 200 urb->start_frame = (frame + NRURBS * nr_of_packs()); // let hcd do rollover sanity checks
201 urb->hcpriv = NULL; 201 urb->hcpriv = NULL;
202 urb->dev = subs->usX2Y->chip.dev; /* we need to set this at each time */ 202 urb->dev = subs->usX2Y->dev; /* we need to set this at each time */
203 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 203 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
204 snd_printk(KERN_ERR "usb_submit_urb() returned %i\n", err); 204 snd_printk(KERN_ERR "usb_submit_urb() returned %i\n", err);
205 return err; 205 return err;
@@ -300,7 +300,7 @@ static void usX2Y_error_sequence(struct usX2Ydev *usX2Y,
300"Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n" 300"Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n"
301"Most propably some urb of usb-frame %i is still missing.\n" 301"Most propably some urb of usb-frame %i is still missing.\n"
302"Cause could be too long delays in usb-hcd interrupt handling.\n", 302"Cause could be too long delays in usb-hcd interrupt handling.\n",
303 usb_get_current_frame_number(usX2Y->chip.dev), 303 usb_get_current_frame_number(usX2Y->dev),
304 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", 304 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
305 usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame); 305 usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame);
306 usX2Y_clients_stop(usX2Y); 306 usX2Y_clients_stop(usX2Y);
@@ -313,7 +313,7 @@ static void i_usX2Y_urb_complete(struct urb *urb)
313 313
314 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) { 314 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) {
315 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n", 315 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n",
316 usb_get_current_frame_number(usX2Y->chip.dev), 316 usb_get_current_frame_number(usX2Y->dev),
317 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", 317 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
318 urb->status, urb->start_frame); 318 urb->status, urb->start_frame);
319 return; 319 return;
@@ -424,7 +424,7 @@ static int usX2Y_urbs_allocate(struct snd_usX2Y_substream *subs)
424 int i; 424 int i;
425 unsigned int pipe; 425 unsigned int pipe;
426 int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; 426 int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
427 struct usb_device *dev = subs->usX2Y->chip.dev; 427 struct usb_device *dev = subs->usX2Y->dev;
428 428
429 pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) : 429 pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) :
430 usb_rcvisocpipe(dev, subs->endpoint); 430 usb_rcvisocpipe(dev, subs->endpoint);
@@ -500,7 +500,7 @@ static int usX2Y_urbs_start(struct snd_usX2Y_substream *subs)
500 unsigned long pack; 500 unsigned long pack;
501 if (0 == i) 501 if (0 == i)
502 atomic_set(&subs->state, state_STARTING3); 502 atomic_set(&subs->state, state_STARTING3);
503 urb->dev = usX2Y->chip.dev; 503 urb->dev = usX2Y->dev;
504 urb->transfer_flags = URB_ISO_ASAP; 504 urb->transfer_flags = URB_ISO_ASAP;
505 for (pack = 0; pack < nr_of_packs(); pack++) { 505 for (pack = 0; pack < nr_of_packs(); pack++) {
506 urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack; 506 urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack;
@@ -692,7 +692,7 @@ static int usX2Y_rate_set(struct usX2Ydev *usX2Y, int rate)
692 } 692 }
693 ((char*)(usbdata + i))[0] = ra[i].c1; 693 ((char*)(usbdata + i))[0] = ra[i].c1;
694 ((char*)(usbdata + i))[1] = ra[i].c2; 694 ((char*)(usbdata + i))[1] = ra[i].c2;
695 usb_fill_bulk_urb(us->urb[i], usX2Y->chip.dev, usb_sndbulkpipe(usX2Y->chip.dev, 4), 695 usb_fill_bulk_urb(us->urb[i], usX2Y->dev, usb_sndbulkpipe(usX2Y->dev, 4),
696 usbdata + i, 2, i_usX2Y_04Int, usX2Y); 696 usbdata + i, 2, i_usX2Y_04Int, usX2Y);
697#ifdef OLD_USB 697#ifdef OLD_USB
698 us->urb[i]->transfer_flags = USB_QUEUE_BULK; 698 us->urb[i]->transfer_flags = USB_QUEUE_BULK;
@@ -740,17 +740,17 @@ static int usX2Y_format_set(struct usX2Ydev *usX2Y, snd_pcm_format_t format)
740 alternate = 1; 740 alternate = 1;
741 usX2Y->stride = 4; 741 usX2Y->stride = 4;
742 } 742 }
743 list_for_each(p, &usX2Y->chip.midi_list) { 743 list_for_each(p, &usX2Y->midi_list) {
744 snd_usbmidi_input_stop(p); 744 snd_usbmidi_input_stop(p);
745 } 745 }
746 usb_kill_urb(usX2Y->In04urb); 746 usb_kill_urb(usX2Y->In04urb);
747 if ((err = usb_set_interface(usX2Y->chip.dev, 0, alternate))) { 747 if ((err = usb_set_interface(usX2Y->dev, 0, alternate))) {
748 snd_printk(KERN_ERR "usb_set_interface error \n"); 748 snd_printk(KERN_ERR "usb_set_interface error \n");
749 return err; 749 return err;
750 } 750 }
751 usX2Y->In04urb->dev = usX2Y->chip.dev; 751 usX2Y->In04urb->dev = usX2Y->dev;
752 err = usb_submit_urb(usX2Y->In04urb, GFP_KERNEL); 752 err = usb_submit_urb(usX2Y->In04urb, GFP_KERNEL);
753 list_for_each(p, &usX2Y->chip.midi_list) { 753 list_for_each(p, &usX2Y->midi_list) {
754 snd_usbmidi_input_start(p); 754 snd_usbmidi_input_start(p);
755 } 755 }
756 usX2Y->format = format; 756 usX2Y->format = format;
@@ -955,7 +955,7 @@ static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint,
955 struct snd_pcm *pcm; 955 struct snd_pcm *pcm;
956 int err, i; 956 int err, i;
957 struct snd_usX2Y_substream **usX2Y_substream = 957 struct snd_usX2Y_substream **usX2Y_substream =
958 usX2Y(card)->subs + 2 * usX2Y(card)->chip.pcm_devs; 958 usX2Y(card)->subs + 2 * usX2Y(card)->pcm_devs;
959 959
960 for (i = playback_endpoint ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE; 960 for (i = playback_endpoint ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
961 i <= SNDRV_PCM_STREAM_CAPTURE; ++i) { 961 i <= SNDRV_PCM_STREAM_CAPTURE; ++i) {
@@ -971,7 +971,7 @@ static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint,
971 usX2Y_substream[SNDRV_PCM_STREAM_PLAYBACK]->endpoint = playback_endpoint; 971 usX2Y_substream[SNDRV_PCM_STREAM_PLAYBACK]->endpoint = playback_endpoint;
972 usX2Y_substream[SNDRV_PCM_STREAM_CAPTURE]->endpoint = capture_endpoint; 972 usX2Y_substream[SNDRV_PCM_STREAM_CAPTURE]->endpoint = capture_endpoint;
973 973
974 err = snd_pcm_new(card, NAME_ALLCAPS" Audio", usX2Y(card)->chip.pcm_devs, 974 err = snd_pcm_new(card, NAME_ALLCAPS" Audio", usX2Y(card)->pcm_devs,
975 playback_endpoint ? 1 : 0, 1, 975 playback_endpoint ? 1 : 0, 1,
976 &pcm); 976 &pcm);
977 if (err < 0) { 977 if (err < 0) {
@@ -987,7 +987,7 @@ static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint,
987 pcm->private_free = snd_usX2Y_pcm_private_free; 987 pcm->private_free = snd_usX2Y_pcm_private_free;
988 pcm->info_flags = 0; 988 pcm->info_flags = 0;
989 989
990 sprintf(pcm->name, NAME_ALLCAPS" Audio #%d", usX2Y(card)->chip.pcm_devs); 990 sprintf(pcm->name, NAME_ALLCAPS" Audio #%d", usX2Y(card)->pcm_devs);
991 991
992 if ((playback_endpoint && 992 if ((playback_endpoint &&
993 0 > (err = snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, 993 0 > (err = snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
@@ -1001,7 +1001,7 @@ static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint,
1001 snd_usX2Y_pcm_private_free(pcm); 1001 snd_usX2Y_pcm_private_free(pcm);
1002 return err; 1002 return err;
1003 } 1003 }
1004 usX2Y(card)->chip.pcm_devs++; 1004 usX2Y(card)->pcm_devs++;
1005 1005
1006 return 0; 1006 return 0;
1007} 1007}
@@ -1013,14 +1013,14 @@ int usX2Y_audio_create(struct snd_card *card)
1013{ 1013{
1014 int err = 0; 1014 int err = 0;
1015 1015
1016 INIT_LIST_HEAD(&usX2Y(card)->chip.pcm_list); 1016 INIT_LIST_HEAD(&usX2Y(card)->pcm_list);
1017 1017
1018 if (0 > (err = usX2Y_audio_stream_new(card, 0xA, 0x8))) 1018 if (0 > (err = usX2Y_audio_stream_new(card, 0xA, 0x8)))
1019 return err; 1019 return err;
1020 if (le16_to_cpu(usX2Y(card)->chip.dev->descriptor.idProduct) == USB_ID_US428) 1020 if (le16_to_cpu(usX2Y(card)->dev->descriptor.idProduct) == USB_ID_US428)
1021 if (0 > (err = usX2Y_audio_stream_new(card, 0, 0xA))) 1021 if (0 > (err = usX2Y_audio_stream_new(card, 0, 0xA)))
1022 return err; 1022 return err;
1023 if (le16_to_cpu(usX2Y(card)->chip.dev->descriptor.idProduct) != USB_ID_US122) 1023 if (le16_to_cpu(usX2Y(card)->dev->descriptor.idProduct) != USB_ID_US122)
1024 err = usX2Y_rate_set(usX2Y(card), 44100); // Lets us428 recognize output-volume settings, disturbs us122. 1024 err = usX2Y_rate_set(usX2Y(card), 44100); // Lets us428 recognize output-volume settings, disturbs us122.
1025 return err; 1025 return err;
1026} 1026}
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index 4b2304c2e02d..9ed6c3956ca7 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -234,7 +234,7 @@ static void i_usX2Y_usbpcm_urb_complete(struct urb *urb)
234 234
235 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) { 235 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) {
236 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n", 236 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n",
237 usb_get_current_frame_number(usX2Y->chip.dev), 237 usb_get_current_frame_number(usX2Y->dev),
238 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", 238 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
239 urb->status, urb->start_frame); 239 urb->status, urb->start_frame);
240 return; 240 return;
@@ -318,7 +318,7 @@ static int usX2Y_usbpcm_urbs_allocate(struct snd_usX2Y_substream *subs)
318 int i; 318 int i;
319 unsigned int pipe; 319 unsigned int pipe;
320 int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; 320 int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
321 struct usb_device *dev = subs->usX2Y->chip.dev; 321 struct usb_device *dev = subs->usX2Y->dev;
322 322
323 pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) : 323 pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) :
324 usb_rcvisocpipe(dev, subs->endpoint); 324 usb_rcvisocpipe(dev, subs->endpoint);
@@ -441,7 +441,7 @@ static int usX2Y_usbpcm_urbs_start(struct snd_usX2Y_substream *subs)
441 unsigned long pack; 441 unsigned long pack;
442 if (0 == u) 442 if (0 == u)
443 atomic_set(&subs->state, state_STARTING3); 443 atomic_set(&subs->state, state_STARTING3);
444 urb->dev = usX2Y->chip.dev; 444 urb->dev = usX2Y->dev;
445 urb->transfer_flags = URB_ISO_ASAP; 445 urb->transfer_flags = URB_ISO_ASAP;
446 for (pack = 0; pack < nr_of_packs(); pack++) { 446 for (pack = 0; pack < nr_of_packs(); pack++) {
447 urb->iso_frame_desc[pack].offset = subs->maxpacksize * (pack + u * nr_of_packs()); 447 urb->iso_frame_desc[pack].offset = subs->maxpacksize * (pack + u * nr_of_packs());
@@ -741,7 +741,7 @@ int usX2Y_hwdep_pcm_new(struct snd_card *card)
741 int err; 741 int err;
742 struct snd_hwdep *hw; 742 struct snd_hwdep *hw;
743 struct snd_pcm *pcm; 743 struct snd_pcm *pcm;
744 struct usb_device *dev = usX2Y(card)->chip.dev; 744 struct usb_device *dev = usX2Y(card)->dev;
745 if (1 != nr_of_packs()) 745 if (1 != nr_of_packs())
746 return 0; 746 return 0;
747 747