aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-12-11 16:20:50 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-11 16:20:50 -0500
commitbae41e45b7400496b9bf0c70c6004419d9987819 (patch)
treecf22a65d119da1c414dbc79518857800fbe7a24b
parent7ef58b32f571bffb7763c6252ad7527562081f34 (diff)
parent6e1d7a51392f06899bd7b693f28ac60fa1e00032 (diff)
Merge tag 'sound-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound updates from Takashi Iwai: "This became a fairly large pull request. In addition to the usual driver updates / fixes, there have been a high amount of cleanups in ASoC area, as well as control API helpers and kernel documentations fixes touching through the whole tree. In the driver side, the biggest changes are the support for new Intel SoC found on new x86 machines, and the updates of FireWire dice and oxfw drivers. Some remarkable items are below: ALSA core: - PCM mmap code cleanup, removal of arch-dependent codes - PCM xrun injection support - PCM hwptr tracepoint support - Refactoring of snd_pcm_action(), simplification of PCM locking - Robustified sequecner auto-load functionality - New control API helpers and lots of cleanups along with them - Lots of kerneldoc fixes and cleanups USB-audio: - The mixer resume code was largely rewritten, and the devices with quirks are resumed properly. - New hardware support: Focusrite Scarlett, Digidesign Mbox1, Denon/Marantz DACs, Zoom R16/24 FireWire: - DICE driver updates with better duplex and sync support, including MIDI support - New OXFW driver for Oxford Semiconductor FW970/971 chipset, including the previous LaCie Speakers device. Fullduplex and MIDI support included as well as DICE driver. HD-audio: - Refactoring the driver-caps quirk handling in snd-hda-intel - More consistent control names representing the topology better - Fixups: HP mute LED with ALC268 codec, Ideapad S210 built-in mic fix, ASUS Z99He laptop EAPD ASoC: - Conversion of AC'97 drivers to use regmap, bringing us closer to the removal of the ASoC level I/O code - Clean up a lot of old drivers that were open coding things that have subsequently been implemented in the core - Some DAPM performance improvements - Removal of the now seldom used CODEC mutex - Lots of updates for the newer Intel SoC support, including support for the DSP and some Cherrytrail and Braswell machine drivers - Support for Samsung boards using rt5631 as the CODEC - Removal of the obsolete AFEB9260 machine driver - Driver support for the TI TS3A227E headset driver used in some Chrombeooks Others: - ASIHPI driver update and cleanups - Lots of dev_*() printk conversions - Lots of trivial cleanups for the codes spotted by Coccinelle" * tag 'sound-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (594 commits) ALSA: pcxhr: NULL dereference on probe failure ALSA: lola: NULL dereference on probe failure ALSA: hda - Add "eapd" model string for AD1986A codec ALSA: hda - Add EAPD fixup for ASUS Z99He laptop ALSA: oxfw: Add hwdep interface ALSA: oxfw: Add support for capture/playback MIDI messages ALSA: oxfw: add support for capturing PCM samples ALSA: oxfw: Add support AMDTP in-stream ALSA: oxfw: Add support for Behringer/Mackie devices ALSA: oxfw: Change the way to start stream ALSA: oxfw: Add proc interface for debugging purpose ALSA: oxfw: Change the way to make PCM rules/constraints ALSA: oxfw: Add support for AV/C stream format command to get/set supported stream formation ALSA: oxfw: Change the way to name card ALSA: dice: Add support for MIDI capture/playback ALSA: dice: Add support for capturing PCM samples ALSA: dice: Support for non SYT-Match sampling clock source mode ALSA: dice: Add support for duplex streams with synchronization ALSA: dice: Change the way to start stream ALSA: jack: Add dummy snd_jack_set_key() definition ...
-rw-r--r--Documentation/DocBook/alsa-driver-api.tmpl31
-rw-r--r--Documentation/DocBook/writing-an-alsa-driver.tmpl23
-rw-r--r--Documentation/devicetree/bindings/sound/arndale.txt24
-rw-r--r--Documentation/devicetree/bindings/sound/davinci-mcasp-audio.txt2
-rw-r--r--Documentation/devicetree/bindings/sound/eukrea-tlv320.txt15
-rw-r--r--Documentation/devicetree/bindings/sound/fsl,esai.txt44
-rw-r--r--Documentation/devicetree/bindings/sound/fsl,spdif.txt37
-rw-r--r--Documentation/devicetree/bindings/sound/fsl-sai.txt66
-rw-r--r--Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt61
-rw-r--r--Documentation/devicetree/bindings/sound/imx-audio-spdif.txt22
-rw-r--r--Documentation/devicetree/bindings/sound/imx-audio-wm8962.txt45
-rw-r--r--Documentation/devicetree/bindings/sound/imx-audmux.txt22
-rw-r--r--Documentation/devicetree/bindings/sound/max98090.txt2
-rw-r--r--Documentation/devicetree/bindings/sound/renesas,fsi.txt9
-rw-r--r--Documentation/devicetree/bindings/sound/renesas,rsnd.txt10
-rw-r--r--Documentation/devicetree/bindings/sound/rt5631.txt48
-rw-r--r--Documentation/devicetree/bindings/sound/rt5677.txt17
-rw-r--r--Documentation/devicetree/bindings/sound/samsung-i2s.txt15
-rw-r--r--Documentation/devicetree/bindings/sound/sgtl5000.txt13
-rw-r--r--Documentation/devicetree/bindings/sound/ts3a227e.txt26
-rw-r--r--Documentation/devicetree/bindings/sound/wm8960.txt31
-rw-r--r--Documentation/sound/alsa/ControlNames.txt32
-rw-r--r--Documentation/sound/alsa/HD-Audio-Models.txt8
-rw-r--r--Documentation/sound/alsa/Procfile.txt17
-rw-r--r--MAINTAINERS6
-rw-r--r--arch/arm/mach-pxa/spitz.c9
-rw-r--r--arch/x86/include/asm/platform_sst_audio.h62
-rw-r--r--drivers/media/pci/saa7134/saa7134-alsa.c4
-rw-r--r--include/linux/mfd/arizona/core.h1
-rw-r--r--include/linux/mfd/davinci_voicecodec.h7
-rw-r--r--include/linux/platform_data/asoc-s3c.h1
-rw-r--r--include/sound/compress_driver.h5
-rw-r--r--include/sound/jack.h26
-rw-r--r--include/sound/pcm.h254
-rw-r--r--include/sound/rcar_snd.h8
-rw-r--r--include/sound/rt5645.h4
-rw-r--r--include/sound/rt5677.h10
-rw-r--r--include/sound/seq_kernel.h4
-rw-r--r--include/sound/soc-dai.h7
-rw-r--r--include/sound/soc-dapm.h9
-rw-r--r--include/sound/soc.h116
-rw-r--r--include/sound/uda134x.h12
-rw-r--r--include/trace/events/asoc.h25
-rw-r--r--include/uapi/sound/asound.h3
-rw-r--r--include/uapi/sound/compress_offload.h17
-rw-r--r--include/uapi/sound/firewire.h3
-rw-r--r--include/uapi/sound/hdspm.h12
-rw-r--r--sound/aoa/codecs/onyx.c8
-rw-r--r--sound/aoa/codecs/tas.c10
-rw-r--r--sound/aoa/soundbus/i2sbus/core.c6
-rw-r--r--sound/arm/pxa2xx-pcm-lib.c4
-rw-r--r--sound/atmel/abdac.c18
-rw-r--r--sound/atmel/ac97c.c12
-rw-r--r--sound/core/Makefile3
-rw-r--r--sound/core/control.c71
-rw-r--r--sound/core/init.c33
-rw-r--r--sound/core/pcm.c48
-rw-r--r--sound/core/pcm_lib.c148
-rw-r--r--sound/core/pcm_native.c214
-rw-r--r--sound/core/pcm_trace.h110
-rw-r--r--sound/core/seq/oss/seq_oss_init.c9
-rw-r--r--sound/core/seq/seq.c5
-rw-r--r--sound/core/seq/seq_device.c103
-rw-r--r--sound/core/sgbuf.c3
-rw-r--r--sound/core/sound.c9
-rw-r--r--sound/drivers/mts64.c18
-rw-r--r--sound/drivers/virmidi.c21
-rw-r--r--sound/drivers/vx/vx_core.c10
-rw-r--r--sound/drivers/vx/vx_mixer.c35
-rw-r--r--sound/firewire/Kconfig26
-rw-r--r--sound/firewire/Makefile7
-rw-r--r--sound/firewire/amdtp.c8
-rw-r--r--sound/firewire/amdtp.h24
-rw-r--r--sound/firewire/bebob/bebob.h4
-rw-r--r--sound/firewire/bebob/bebob_focusrite.c10
-rw-r--r--sound/firewire/bebob/bebob_maudio.c59
-rw-r--r--sound/firewire/bebob/bebob_terratec.c4
-rw-r--r--sound/firewire/bebob/bebob_yamaha.c2
-rw-r--r--sound/firewire/cmp.c2
-rw-r--r--sound/firewire/dice.c1511
-rw-r--r--sound/firewire/dice/Makefile3
-rw-r--r--sound/firewire/dice/dice-hwdep.c190
-rw-r--r--sound/firewire/dice/dice-interface.h (renamed from sound/firewire/dice-interface.h)0
-rw-r--r--sound/firewire/dice/dice-midi.c157
-rw-r--r--sound/firewire/dice/dice-pcm.c422
-rw-r--r--sound/firewire/dice/dice-proc.c252
-rw-r--r--sound/firewire/dice/dice-stream.c407
-rw-r--r--sound/firewire/dice/dice-transaction.c382
-rw-r--r--sound/firewire/dice/dice.c361
-rw-r--r--sound/firewire/dice/dice.h189
-rw-r--r--sound/firewire/isight.c10
-rw-r--r--sound/firewire/oxfw/Makefile3
-rw-r--r--sound/firewire/oxfw/oxfw-command.c153
-rw-r--r--sound/firewire/oxfw/oxfw-control.c283
-rw-r--r--sound/firewire/oxfw/oxfw-hwdep.c190
-rw-r--r--sound/firewire/oxfw/oxfw-midi.c207
-rw-r--r--sound/firewire/oxfw/oxfw-pcm.c424
-rw-r--r--sound/firewire/oxfw/oxfw-proc.c113
-rw-r--r--sound/firewire/oxfw/oxfw-stream.c685
-rw-r--r--sound/firewire/oxfw/oxfw.c317
-rw-r--r--sound/firewire/oxfw/oxfw.h146
-rw-r--r--sound/firewire/speakers.c792
-rw-r--r--sound/i2c/other/ak4xxx-adda.c26
-rw-r--r--sound/isa/ad1816a/ad1816a_lib.c10
-rw-r--r--sound/isa/es1688/es1688_lib.c13
-rw-r--r--sound/isa/es18xx.c78
-rw-r--r--sound/isa/msnd/msnd_pinnacle_mixer.c11
-rw-r--r--sound/isa/sb/emu8000_synth.c3
-rw-r--r--sound/isa/sb/sb16_main.c10
-rw-r--r--sound/isa/sb/sb_common.c3
-rw-r--r--sound/isa/sb/sb_mixer.c31
-rw-r--r--sound/isa/wss/wss_lib.c16
-rw-r--r--sound/mips/sgio2audio.c11
-rw-r--r--sound/oss/uart401.c11
-rw-r--r--sound/parisc/harmony.c12
-rw-r--r--sound/pci/ac97/ac97_codec.c10
-rw-r--r--sound/pci/ac97/ac97_patch.c198
-rw-r--r--sound/pci/ac97/ac97_patch.h2
-rw-r--r--sound/pci/asihpi/asihpi.c377
-rw-r--r--sound/pci/asihpi/hpi.h16
-rw-r--r--sound/pci/asihpi/hpi6205.c43
-rw-r--r--sound/pci/asihpi/hpi_internal.h20
-rw-r--r--sound/pci/asihpi/hpicmn.c107
-rw-r--r--sound/pci/asihpi/hpicmn.h19
-rw-r--r--sound/pci/asihpi/hpimsginit.c30
-rw-r--r--sound/pci/asihpi/hpimsgx.c15
-rw-r--r--sound/pci/asihpi/hpioctl.c126
-rw-r--r--sound/pci/asihpi/hpios.h8
-rw-r--r--sound/pci/atiixp.c4
-rw-r--r--sound/pci/atiixp_modem.c4
-rw-r--r--sound/pci/au88x0/au88x0.c35
-rw-r--r--sound/pci/au88x0/au88x0.h4
-rw-r--r--sound/pci/au88x0/au88x0_a3d.c21
-rw-r--r--sound/pci/au88x0/au88x0_core.c102
-rw-r--r--sound/pci/au88x0/au88x0_eq.c3
-rw-r--r--sound/pci/au88x0/au88x0_game.c3
-rw-r--r--sound/pci/au88x0/au88x0_mpu401.c2
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c8
-rw-r--r--sound/pci/au88x0/au88x0_synth.c17
-rw-r--r--sound/pci/aw2/aw2-alsa.c13
-rw-r--r--sound/pci/azt3328.c13
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c40
-rw-r--r--sound/pci/ctxfi/ctatc.c10
-rw-r--r--sound/pci/ctxfi/ctdaio.c30
-rw-r--r--sound/pci/ctxfi/cttimer.c4
-rw-r--r--sound/pci/echoaudio/darla20_dsp.c5
-rw-r--r--sound/pci/echoaudio/darla24_dsp.c13
-rw-r--r--sound/pci/echoaudio/echo3g_dsp.c5
-rw-r--r--sound/pci/echoaudio/echoaudio.c145
-rw-r--r--sound/pci/echoaudio/echoaudio.h31
-rw-r--r--sound/pci/echoaudio/echoaudio_3g.c27
-rw-r--r--sound/pci/echoaudio/echoaudio_dsp.c109
-rw-r--r--sound/pci/echoaudio/echoaudio_gml.c11
-rw-r--r--sound/pci/echoaudio/gina20_dsp.c9
-rw-r--r--sound/pci/echoaudio/gina24_dsp.c30
-rw-r--r--sound/pci/echoaudio/indigo_dsp.c11
-rw-r--r--sound/pci/echoaudio/indigo_express_dsp.c6
-rw-r--r--sound/pci/echoaudio/indigodj_dsp.c11
-rw-r--r--sound/pci/echoaudio/indigodjx_dsp.c5
-rw-r--r--sound/pci/echoaudio/indigoio_dsp.c8
-rw-r--r--sound/pci/echoaudio/indigoiox_dsp.c5
-rw-r--r--sound/pci/echoaudio/layla20_dsp.c28
-rw-r--r--sound/pci/echoaudio/layla24_dsp.c26
-rw-r--r--sound/pci/echoaudio/mia_dsp.c15
-rw-r--r--sound/pci/echoaudio/midi.c23
-rw-r--r--sound/pci/echoaudio/mona_dsp.c29
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c9
-rw-r--r--sound/pci/emu10k1/emu10k1x.c2
-rw-r--r--sound/pci/emu10k1/emufx.c3
-rw-r--r--sound/pci/emu10k1/emumixer.c58
-rw-r--r--sound/pci/emu10k1/p16v.c20
-rw-r--r--sound/pci/es1938.c10
-rw-r--r--sound/pci/es1968.c15
-rw-r--r--sound/pci/fm801.c10
-rw-r--r--sound/pci/hda/hda_auto_parser.c66
-rw-r--r--sound/pci/hda/hda_beep.c38
-rw-r--r--sound/pci/hda/hda_codec.c298
-rw-r--r--sound/pci/hda/hda_eld.c2
-rw-r--r--sound/pci/hda/hda_generic.c181
-rw-r--r--sound/pci/hda/hda_intel.c150
-rw-r--r--sound/pci/hda/hda_jack.c60
-rw-r--r--sound/pci/hda/hda_jack.h5
-rw-r--r--sound/pci/hda/hda_priv.h16
-rw-r--r--sound/pci/hda/hda_sysfs.c35
-rw-r--r--sound/pci/hda/patch_analog.c2
-rw-r--r--sound/pci/hda/patch_ca0132.c11
-rw-r--r--sound/pci/hda/patch_realtek.c109
-rw-r--r--sound/pci/ice1712/aureon.c46
-rw-r--r--sound/pci/ice1712/ews.c16
-rw-r--r--sound/pci/ice1712/hoontech.c6
-rw-r--r--sound/pci/ice1712/ice1712.c52
-rw-r--r--sound/pci/ice1712/ice1724.c18
-rw-r--r--sound/pci/ice1712/juli.c5
-rw-r--r--sound/pci/ice1712/maya44.c20
-rw-r--r--sound/pci/ice1712/phase.c12
-rw-r--r--sound/pci/ice1712/pontis.c8
-rw-r--r--sound/pci/ice1712/prodigy192.c22
-rw-r--r--sound/pci/ice1712/prodigy_hifi.c11
-rw-r--r--sound/pci/ice1712/quartet.c32
-rw-r--r--sound/pci/ice1712/revo.c4
-rw-r--r--sound/pci/ice1712/se.c9
-rw-r--r--sound/pci/korg1212/korg1212.c26
-rw-r--r--sound/pci/lola/lola.c2
-rw-r--r--sound/pci/lola/lola_mixer.c3
-rw-r--r--sound/pci/lx6464es/lx_defs.h2
-rw-r--r--sound/pci/mixart/mixart_hwdep.c9
-rw-r--r--sound/pci/pcxhr/pcxhr.c54
-rw-r--r--sound/pci/pcxhr/pcxhr_core.c10
-rw-r--r--sound/pci/pcxhr/pcxhr_mixer.c18
-rw-r--r--sound/pci/rme32.c34
-rw-r--r--sound/pci/rme96.c62
-rw-r--r--sound/pci/rme9652/hdsp.c178
-rw-r--r--sound/pci/rme9652/hdspm.c84
-rw-r--r--sound/pci/rme9652/rme9652.c58
-rw-r--r--sound/pci/sonicvibes.c10
-rw-r--r--sound/pci/trident/trident_main.c3
-rw-r--r--sound/pci/via82xx.c10
-rw-r--r--sound/pci/vx222/vx222_ops.c5
-rw-r--r--sound/pcmcia/vx/vxpocket.c1
-rw-r--r--sound/ppc/pmac.c3
-rw-r--r--sound/ppc/tumbler.c11
-rw-r--r--sound/soc/Makefile6
-rw-r--r--sound/soc/atmel/Kconfig9
-rw-r--r--sound/soc/atmel/Makefile1
-rw-r--r--sound/soc/atmel/atmel-pcm-dma.c4
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c5
-rw-r--r--sound/soc/atmel/snd-soc-afeb9260.c151
-rw-r--r--sound/soc/au1x/ac97c.c2
-rw-r--r--sound/soc/au1x/psc-ac97.c2
-rw-r--r--sound/soc/blackfin/bf5xx-ac97.c2
-rw-r--r--sound/soc/blackfin/bf5xx-ad1980.c2
-rw-r--r--sound/soc/cirrus/Kconfig3
-rw-r--r--sound/soc/cirrus/ep93xx-ac97.c2
-rw-r--r--sound/soc/codecs/Kconfig47
-rw-r--r--sound/soc/codecs/Makefile10
-rw-r--r--sound/soc/codecs/ab8500-codec.c32
-rw-r--r--sound/soc/codecs/ac97.c18
-rw-r--r--sound/soc/codecs/ad193x.c14
-rw-r--r--sound/soc/codecs/ad1980.c212
-rw-r--r--sound/soc/codecs/ad1980.h26
-rw-r--r--sound/soc/codecs/adau1373.c6
-rw-r--r--sound/soc/codecs/adau1701.c86
-rw-r--r--sound/soc/codecs/adau1761.c25
-rw-r--r--sound/soc/codecs/adau1781.c33
-rw-r--r--sound/soc/codecs/adau17x1.c71
-rw-r--r--sound/soc/codecs/adau17x1.h10
-rw-r--r--sound/soc/codecs/adav80x.c4
-rw-r--r--sound/soc/codecs/ak4535.c31
-rw-r--r--sound/soc/codecs/ak4641.c33
-rw-r--r--sound/soc/codecs/ak4642.c16
-rw-r--r--sound/soc/codecs/ak4671.c13
-rw-r--r--sound/soc/codecs/alc5623.c22
-rw-r--r--sound/soc/codecs/alc5632.c22
-rw-r--r--sound/soc/codecs/arizona.c34
-rw-r--r--sound/soc/codecs/cq93vc.c33
-rw-r--r--sound/soc/codecs/cs4265.c2
-rw-r--r--sound/soc/codecs/cs4271-i2c.c62
-rw-r--r--sound/soc/codecs/cs4271-spi.c55
-rw-r--r--sound/soc/codecs/cs4271.c155
-rw-r--r--sound/soc/codecs/cs4271.h11
-rw-r--r--sound/soc/codecs/cs42l51.c6
-rw-r--r--sound/soc/codecs/cs42l73.c6
-rw-r--r--sound/soc/codecs/hdmi.c2
-rw-r--r--sound/soc/codecs/lm49453.c8
-rw-r--r--sound/soc/codecs/max98088.c31
-rw-r--r--sound/soc/codecs/max98090.c201
-rw-r--r--sound/soc/codecs/max98090.h8
-rw-r--r--sound/soc/codecs/max98095.c23
-rw-r--r--sound/soc/codecs/max9850.c22
-rw-r--r--sound/soc/codecs/rt286.c231
-rw-r--r--sound/soc/codecs/rt5631.c38
-rw-r--r--sound/soc/codecs/rt5645.c200
-rw-r--r--sound/soc/codecs/rt5645.h19
-rw-r--r--sound/soc/codecs/rt5670.c136
-rw-r--r--sound/soc/codecs/rt5670.h6
-rw-r--r--sound/soc/codecs/rt5677-spi.c130
-rw-r--r--sound/soc/codecs/rt5677-spi.h21
-rw-r--r--sound/soc/codecs/rt5677.c1198
-rw-r--r--sound/soc/codecs/rt5677.h162
-rw-r--r--sound/soc/codecs/sgtl5000.c111
-rw-r--r--sound/soc/codecs/sigmadsp-i2c.c81
-rw-r--r--sound/soc/codecs/sigmadsp-regmap.c46
-rw-r--r--sound/soc/codecs/sigmadsp.c711
-rw-r--r--sound/soc/codecs/sigmadsp.h59
-rw-r--r--sound/soc/codecs/sirf-audio-codec.c6
-rw-r--r--sound/soc/codecs/sn95031.c15
-rw-r--r--sound/soc/codecs/ssm4567.c128
-rw-r--r--sound/soc/codecs/sta32x.c21
-rw-r--r--sound/soc/codecs/sta350.c21
-rw-r--r--sound/soc/codecs/sta529.c35
-rw-r--r--sound/soc/codecs/stac9766.c60
-rw-r--r--sound/soc/codecs/tas2552.c10
-rw-r--r--sound/soc/codecs/tfa9879.c328
-rw-r--r--sound/soc/codecs/tfa9879.h202
-rw-r--r--sound/soc/codecs/tlv320aic23.c21
-rw-r--r--sound/soc/codecs/tlv320aic31xx.c31
-rw-r--r--sound/soc/codecs/tlv320aic32x4.c24
-rw-r--r--sound/soc/codecs/tlv320aic3x.c228
-rw-r--r--sound/soc/codecs/tlv320aic3x.h1
-rw-r--r--sound/soc/codecs/tlv320dac33.c2
-rw-r--r--sound/soc/codecs/ts3a227e.c314
-rw-r--r--sound/soc/codecs/ts3a227e.h17
-rw-r--r--sound/soc/codecs/twl4030.c2
-rw-r--r--sound/soc/codecs/twl6040.c23
-rw-r--r--sound/soc/codecs/uda134x.c32
-rw-r--r--sound/soc/codecs/uda1380.c20
-rw-r--r--sound/soc/codecs/wl1273.c10
-rw-r--r--sound/soc/codecs/wm5102.c18
-rw-r--r--sound/soc/codecs/wm8350.c21
-rw-r--r--sound/soc/codecs/wm8400.c34
-rw-r--r--sound/soc/codecs/wm8510.c26
-rw-r--r--sound/soc/codecs/wm8523.c29
-rw-r--r--sound/soc/codecs/wm8580.c4
-rw-r--r--sound/soc/codecs/wm8711.c27
-rw-r--r--sound/soc/codecs/wm8728.c34
-rw-r--r--sound/soc/codecs/wm8731.c37
-rw-r--r--sound/soc/codecs/wm8737.c49
-rw-r--r--sound/soc/codecs/wm8750.c25
-rw-r--r--sound/soc/codecs/wm8776.c31
-rw-r--r--sound/soc/codecs/wm8804.c3
-rw-r--r--sound/soc/codecs/wm8900.c8
-rw-r--r--sound/soc/codecs/wm8903.c43
-rw-r--r--sound/soc/codecs/wm8940.c22
-rw-r--r--sound/soc/codecs/wm8955.c33
-rw-r--r--sound/soc/codecs/wm8958-dsp2.c12
-rw-r--r--sound/soc/codecs/wm8960.c113
-rw-r--r--sound/soc/codecs/wm8961.c34
-rw-r--r--sound/soc/codecs/wm8962.c11
-rw-r--r--sound/soc/codecs/wm8974.c25
-rw-r--r--sound/soc/codecs/wm8978.c10
-rw-r--r--sound/soc/codecs/wm8983.c27
-rw-r--r--sound/soc/codecs/wm8985.c28
-rw-r--r--sound/soc/codecs/wm8988.c27
-rw-r--r--sound/soc/codecs/wm8990.c24
-rw-r--r--sound/soc/codecs/wm8991.c32
-rw-r--r--sound/soc/codecs/wm8993.c12
-rw-r--r--sound/soc/codecs/wm8994.c4
-rw-r--r--sound/soc/codecs/wm8994.h2
-rw-r--r--sound/soc/codecs/wm8995.c17
-rw-r--r--sound/soc/codecs/wm9081.c7
-rw-r--r--sound/soc/codecs/wm9090.c32
-rw-r--r--sound/soc/codecs/wm9705.c46
-rw-r--r--sound/soc/codecs/wm9712.c219
-rw-r--r--sound/soc/codecs/wm9713.c230
-rw-r--r--sound/soc/codecs/wm_adsp.c97
-rw-r--r--sound/soc/davinci/davinci-mcasp.c339
-rw-r--r--sound/soc/davinci/davinci-mcasp.h17
-rw-r--r--sound/soc/dwc/designware_i2s.c46
-rw-r--r--sound/soc/fsl/eukrea-tlv320.c5
-rw-r--r--sound/soc/fsl/fsl-asoc-card.c19
-rw-r--r--sound/soc/fsl/fsl_dma.c9
-rw-r--r--sound/soc/fsl/fsl_esai.c12
-rw-r--r--sound/soc/fsl/fsl_ssi.c17
-rw-r--r--sound/soc/fsl/imx-sgtl5000.c6
-rw-r--r--sound/soc/fsl/imx-spdif.c3
-rw-r--r--sound/soc/fsl/imx-ssi.c2
-rw-r--r--sound/soc/fsl/imx-wm8962.c6
-rw-r--r--sound/soc/fsl/mpc5200_dma.c3
-rw-r--r--sound/soc/fsl/mpc5200_psc_ac97.c6
-rw-r--r--sound/soc/generic/simple-card.c160
-rw-r--r--sound/soc/intel/Kconfig44
-rw-r--r--sound/soc/intel/Makefile7
-rw-r--r--sound/soc/intel/broadwell.c64
-rw-r--r--sound/soc/intel/bytcr_dpcm_rt5640.c230
-rw-r--r--sound/soc/intel/cht_bsw_rt5672.c285
-rw-r--r--sound/soc/intel/haswell.c14
-rw-r--r--sound/soc/intel/sst-atom-controls.c1208
-rw-r--r--sound/soc/intel/sst-atom-controls.h428
-rw-r--r--sound/soc/intel/sst-baytrail-dsp.c24
-rw-r--r--sound/soc/intel/sst-dsp-priv.h136
-rw-r--r--sound/soc/intel/sst-dsp.c31
-rw-r--r--sound/soc/intel/sst-dsp.h28
-rw-r--r--sound/soc/intel/sst-firmware.c937
-rw-r--r--sound/soc/intel/sst-haswell-dsp.c295
-rw-r--r--sound/soc/intel/sst-haswell-ipc.c413
-rw-r--r--sound/soc/intel/sst-haswell-ipc.h25
-rw-r--r--sound/soc/intel/sst-haswell-pcm.c419
-rw-r--r--sound/soc/intel/sst-mfld-platform-compress.c8
-rw-r--r--sound/soc/intel/sst-mfld-platform-pcm.c154
-rw-r--r--sound/soc/intel/sst-mfld-platform.h5
-rw-r--r--sound/soc/intel/sst/Makefile7
-rw-r--r--sound/soc/intel/sst/sst.c437
-rw-r--r--sound/soc/intel/sst/sst.h546
-rw-r--r--sound/soc/intel/sst/sst_acpi.c383
-rw-r--r--sound/soc/intel/sst/sst_drv_interface.c686
-rw-r--r--sound/soc/intel/sst/sst_ipc.c373
-rw-r--r--sound/soc/intel/sst/sst_loader.c456
-rw-r--r--sound/soc/intel/sst/sst_pci.c209
-rw-r--r--sound/soc/intel/sst/sst_pvt.c449
-rw-r--r--sound/soc/intel/sst/sst_stream.c437
-rw-r--r--sound/soc/jz4740/qi_lb60.c11
-rw-r--r--sound/soc/mxs/mxs-saif.c2
-rw-r--r--sound/soc/mxs/mxs-sgtl5000.c7
-rw-r--r--sound/soc/nuc900/nuc900-ac97.c2
-rw-r--r--sound/soc/omap/Kconfig8
-rw-r--r--sound/soc/omap/mcbsp.c3
-rw-r--r--sound/soc/pxa/mioa701_wm9713.c7
-rw-r--r--sound/soc/pxa/pxa-ssp.c16
-rw-r--r--sound/soc/pxa/pxa2xx-ac97.c6
-rw-r--r--sound/soc/pxa/spitz.c52
-rw-r--r--sound/soc/rockchip/Kconfig9
-rw-r--r--sound/soc/samsung/Kconfig8
-rw-r--r--sound/soc/samsung/Makefile2
-rw-r--r--sound/soc/samsung/ac97.c4
-rw-r--r--sound/soc/samsung/arndale_rt5631.c150
-rw-r--r--sound/soc/samsung/i2s-regs.h10
-rw-r--r--sound/soc/samsung/i2s.c244
-rw-r--r--sound/soc/samsung/odroidx2_max98090.c4
-rw-r--r--sound/soc/sh/fsi.c9
-rw-r--r--sound/soc/sh/hac.c2
-rw-r--r--sound/soc/sh/rcar/adg.c2
-rw-r--r--sound/soc/sh/rcar/core.c236
-rw-r--r--sound/soc/sh/rcar/dvc.c215
-rw-r--r--sound/soc/sh/rcar/gen.c30
-rw-r--r--sound/soc/sh/rcar/rsnd.h92
-rw-r--r--sound/soc/sh/rcar/src.c101
-rw-r--r--sound/soc/sh/rcar/ssi.c233
-rw-r--r--sound/soc/soc-ac97.c256
-rw-r--r--sound/soc/soc-cache.c149
-rw-r--r--sound/soc/soc-compress.c11
-rw-r--r--sound/soc/soc-core.c1642
-rw-r--r--sound/soc/soc-dapm.c755
-rw-r--r--sound/soc/soc-jack.c11
-rw-r--r--sound/soc/soc-ops.c952
-rw-r--r--sound/soc/soc-pcm.c23
-rw-r--r--sound/soc/tegra/tegra20_ac97.c2
-rw-r--r--sound/soc/tegra/tegra_rt5640.c6
-rw-r--r--sound/soc/txx9/txx9aclc-ac97.c2
-rw-r--r--sound/soc/txx9/txx9aclc.c2
-rw-r--r--sound/soc/ux500/mop500.c8
-rw-r--r--sound/sparc/cs4231.c12
-rw-r--r--sound/usb/6fire/control.c22
-rw-r--r--sound/usb/6fire/firmware.c2
-rw-r--r--sound/usb/6fire/pcm.c17
-rw-r--r--sound/usb/Makefile1
-rw-r--r--sound/usb/card.c109
-rw-r--r--sound/usb/endpoint.c16
-rw-r--r--sound/usb/endpoint.h2
-rw-r--r--sound/usb/midi.c2
-rw-r--r--sound/usb/misc/ua101.c18
-rw-r--r--sound/usb/mixer.c241
-rw-r--r--sound/usb/mixer.h40
-rw-r--r--sound/usb/mixer_maps.c9
-rw-r--r--sound/usb/mixer_quirks.c920
-rw-r--r--sound/usb/mixer_scarlett.c1004
-rw-r--r--sound/usb/mixer_scarlett.h6
-rw-r--r--sound/usb/pcm.c5
-rw-r--r--sound/usb/quirks-table.h132
-rw-r--r--sound/usb/quirks.c72
-rw-r--r--sound/usb/quirks.h3
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c9
451 files changed, 27224 insertions, 11303 deletions
diff --git a/Documentation/DocBook/alsa-driver-api.tmpl b/Documentation/DocBook/alsa-driver-api.tmpl
index 0230a96f0564..71f9246127ec 100644
--- a/Documentation/DocBook/alsa-driver-api.tmpl
+++ b/Documentation/DocBook/alsa-driver-api.tmpl
@@ -57,6 +57,7 @@
57!Esound/core/pcm.c 57!Esound/core/pcm.c
58!Esound/core/pcm_lib.c 58!Esound/core/pcm_lib.c
59!Esound/core/pcm_native.c 59!Esound/core/pcm_native.c
60!Iinclude/sound/pcm.h
60 </sect1> 61 </sect1>
61 <sect1><title>PCM Format Helpers</title> 62 <sect1><title>PCM Format Helpers</title>
62!Esound/core/pcm_misc.c 63!Esound/core/pcm_misc.c
@@ -64,6 +65,10 @@
64 <sect1><title>PCM Memory Management</title> 65 <sect1><title>PCM Memory Management</title>
65!Esound/core/pcm_memory.c 66!Esound/core/pcm_memory.c
66 </sect1> 67 </sect1>
68 <sect1><title>PCM DMA Engine API</title>
69!Esound/core/pcm_dmaengine.c
70!Iinclude/sound/dmaengine_pcm.h
71 </sect1>
67 </chapter> 72 </chapter>
68 <chapter><title>Control/Mixer API</title> 73 <chapter><title>Control/Mixer API</title>
69 <sect1><title>General Control Interface</title> 74 <sect1><title>General Control Interface</title>
@@ -91,12 +96,38 @@
91!Esound/core/info.c 96!Esound/core/info.c
92 </sect1> 97 </sect1>
93 </chapter> 98 </chapter>
99 <chapter><title>Compress Offload</title>
100 <sect1><title>Compress Offload API</title>
101!Esound/core/compress_offload.c
102!Iinclude/uapi/sound/compress_offload.h
103!Iinclude/uapi/sound/compress_params.h
104!Iinclude/sound/compress_driver.h
105 </sect1>
106 </chapter>
107 <chapter><title>ASoC</title>
108 <sect1><title>ASoC Core API</title>
109!Iinclude/sound/soc.h
110!Esound/soc/soc-core.c
111!Esound/soc/soc-cache.c
112!Esound/soc/soc-devres.c
113!Esound/soc/soc-io.c
114!Esound/soc/soc-pcm.c
115 </sect1>
116 <sect1><title>ASoC DAPM API</title>
117!Esound/soc/soc-dapm.c
118 </sect1>
119 <sect1><title>ASoC DMA Engine API</title>
120!Esound/soc/soc-generic-dmaengine-pcm.c
121 </sect1>
122 </chapter>
94 <chapter><title>Miscellaneous Functions</title> 123 <chapter><title>Miscellaneous Functions</title>
95 <sect1><title>Hardware-Dependent Devices API</title> 124 <sect1><title>Hardware-Dependent Devices API</title>
96!Esound/core/hwdep.c 125!Esound/core/hwdep.c
97 </sect1> 126 </sect1>
98 <sect1><title>Jack Abstraction Layer API</title> 127 <sect1><title>Jack Abstraction Layer API</title>
128!Iinclude/sound/jack.h
99!Esound/core/jack.c 129!Esound/core/jack.c
130!Esound/soc/soc-jack.c
100 </sect1> 131 </sect1>
101 <sect1><title>ISA DMA Helpers</title> 132 <sect1><title>ISA DMA Helpers</title>
102!Esound/core/isadma.c 133!Esound/core/isadma.c
diff --git a/Documentation/DocBook/writing-an-alsa-driver.tmpl b/Documentation/DocBook/writing-an-alsa-driver.tmpl
index 784793df81ed..84ef6a90131c 100644
--- a/Documentation/DocBook/writing-an-alsa-driver.tmpl
+++ b/Documentation/DocBook/writing-an-alsa-driver.tmpl
@@ -3658,6 +3658,29 @@ struct _snd_pcm_runtime {
3658 </para> 3658 </para>
3659 3659
3660 <para> 3660 <para>
3661 The above callback can be simplified with a helper function,
3662 <function>snd_ctl_enum_info</function>. The final code
3663 looks like below.
3664 (You can pass ARRAY_SIZE(texts) instead of 4 in the third
3665 argument; it's a matter of taste.)
3666
3667 <informalexample>
3668 <programlisting>
3669<![CDATA[
3670 static int snd_myctl_enum_info(struct snd_kcontrol *kcontrol,
3671 struct snd_ctl_elem_info *uinfo)
3672 {
3673 static char *texts[4] = {
3674 "First", "Second", "Third", "Fourth"
3675 };
3676 return snd_ctl_enum_info(uinfo, 1, 4, texts);
3677 }
3678]]>
3679 </programlisting>
3680 </informalexample>
3681 </para>
3682
3683 <para>
3661 Some common info callbacks are available for your convenience: 3684 Some common info callbacks are available for your convenience:
3662 <function>snd_ctl_boolean_mono_info()</function> and 3685 <function>snd_ctl_boolean_mono_info()</function> and
3663 <function>snd_ctl_boolean_stereo_info()</function>. 3686 <function>snd_ctl_boolean_stereo_info()</function>.
diff --git a/Documentation/devicetree/bindings/sound/arndale.txt b/Documentation/devicetree/bindings/sound/arndale.txt
new file mode 100644
index 000000000000..0e76946385ae
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/arndale.txt
@@ -0,0 +1,24 @@
1Audio Binding for Arndale boards
2
3Required properties:
4- compatible : Can be the following,
5 "samsung,arndale-rt5631"
6
7- samsung,audio-cpu: The phandle of the Samsung I2S controller
8- samsung,audio-codec: The phandle of the audio codec
9
10Optional:
11- samsung,model: The name of the sound-card
12
13Arndale Boards has many audio daughter cards, one of them is
14rt5631/alc5631. Below example shows audio bindings for rt5631/
15alc5631 based codec.
16
17Example:
18
19sound {
20 compatible = "samsung,arndale-rt5631";
21
22 samsung,audio-cpu = <&i2s0>
23 samsung,audio-codec = <&rt5631>;
24};
diff --git a/Documentation/devicetree/bindings/sound/davinci-mcasp-audio.txt b/Documentation/devicetree/bindings/sound/davinci-mcasp-audio.txt
index 60ca07996458..46bc9829c71a 100644
--- a/Documentation/devicetree/bindings/sound/davinci-mcasp-audio.txt
+++ b/Documentation/devicetree/bindings/sound/davinci-mcasp-audio.txt
@@ -32,7 +32,7 @@ Optional properties:
32- rx-num-evt : FIFO levels. 32- rx-num-evt : FIFO levels.
33- sram-size-playback : size of sram to be allocated during playback 33- sram-size-playback : size of sram to be allocated during playback
34- sram-size-capture : size of sram to be allocated during capture 34- sram-size-capture : size of sram to be allocated during capture
35- interrupts : Interrupt numbers for McASP, currently not used by the driver 35- interrupts : Interrupt numbers for McASP
36- interrupt-names : Known interrupt names are "tx" and "rx" 36- interrupt-names : Known interrupt names are "tx" and "rx"
37- pinctrl-0: Should specify pin control group used for this controller. 37- pinctrl-0: Should specify pin control group used for this controller.
38- pinctrl-names: Should contain only one value - "default", for more details 38- pinctrl-names: Should contain only one value - "default", for more details
diff --git a/Documentation/devicetree/bindings/sound/eukrea-tlv320.txt b/Documentation/devicetree/bindings/sound/eukrea-tlv320.txt
index 0d7985c864af..6dfa88c4dc1e 100644
--- a/Documentation/devicetree/bindings/sound/eukrea-tlv320.txt
+++ b/Documentation/devicetree/bindings/sound/eukrea-tlv320.txt
@@ -1,11 +1,16 @@
1Audio complex for Eukrea boards with tlv320aic23 codec. 1Audio complex for Eukrea boards with tlv320aic23 codec.
2 2
3Required properties: 3Required properties:
4- compatible : "eukrea,asoc-tlv320" 4
5- eukrea,model : The user-visible name of this sound complex. 5 - compatible : "eukrea,asoc-tlv320"
6- ssi-controller : The phandle of the SSI controller. 6
7- fsl,mux-int-port : The internal port of the i.MX audio muxer (AUDMUX). 7 - eukrea,model : The user-visible name of this sound complex.
8- fsl,mux-ext-port : The external port of the i.MX audio muxer. 8
9 - ssi-controller : The phandle of the SSI controller.
10
11 - fsl,mux-int-port : The internal port of the i.MX audio muxer (AUDMUX).
12
13 - fsl,mux-ext-port : The external port of the i.MX audio muxer.
9 14
10Note: The AUDMUX port numbering should start at 1, which is consistent with 15Note: The AUDMUX port numbering should start at 1, which is consistent with
11hardware manual. 16hardware manual.
diff --git a/Documentation/devicetree/bindings/sound/fsl,esai.txt b/Documentation/devicetree/bindings/sound/fsl,esai.txt
index 52f5b6bf3e8e..d3b6b5f48010 100644
--- a/Documentation/devicetree/bindings/sound/fsl,esai.txt
+++ b/Documentation/devicetree/bindings/sound/fsl,esai.txt
@@ -7,37 +7,39 @@ other DSPs. It has up to six transmitters and four receivers.
7 7
8Required properties: 8Required properties:
9 9
10 - compatible : Compatible list, must contain "fsl,imx35-esai" or 10 - compatible : Compatible list, must contain "fsl,imx35-esai" or
11 "fsl,vf610-esai" 11 "fsl,vf610-esai"
12 12
13 - reg : Offset and length of the register set for the device. 13 - reg : Offset and length of the register set for the device.
14 14
15 - interrupts : Contains the spdif interrupt. 15 - interrupts : Contains the spdif interrupt.
16 16
17 - dmas : Generic dma devicetree binding as described in 17 - dmas : Generic dma devicetree binding as described in
18 Documentation/devicetree/bindings/dma/dma.txt. 18 Documentation/devicetree/bindings/dma/dma.txt.
19 19
20 - dma-names : Two dmas have to be defined, "tx" and "rx". 20 - dma-names : Two dmas have to be defined, "tx" and "rx".
21 21
22 - clocks: Contains an entry for each entry in clock-names. 22 - clocks : Contains an entry for each entry in clock-names.
23 23
24 - clock-names : Includes the following entries: 24 - clock-names : Includes the following entries:
25 "core" The core clock used to access registers 25 "core" The core clock used to access registers
26 "extal" The esai baud clock for esai controller used to derive 26 "extal" The esai baud clock for esai controller used to
27 HCK, SCK and FS. 27 derive HCK, SCK and FS.
28 "fsys" The system clock derived from ahb clock used to derive 28 "fsys" The system clock derived from ahb clock used to
29 HCK, SCK and FS. 29 derive HCK, SCK and FS.
30 30
31 - fsl,fifo-depth: The number of elements in the transmit and receive FIFOs. 31 - fsl,fifo-depth : The number of elements in the transmit and receive
32 This number is the maximum allowed value for TFCR[TFWM] or RFCR[RFWM]. 32 FIFOs. This number is the maximum allowed value for
33 TFCR[TFWM] or RFCR[RFWM].
33 34
34 - fsl,esai-synchronous: This is a boolean property. If present, indicating 35 - fsl,esai-synchronous: This is a boolean property. If present, indicating
35 that ESAI would work in the synchronous mode, which means all the settings 36 that ESAI would work in the synchronous mode, which
36 for Receiving would be duplicated from Transmition related registers. 37 means all the settings for Receiving would be
38 duplicated from Transmition related registers.
37 39
38 - big-endian : If this property is absent, the native endian mode will 40 - big-endian : If this property is absent, the native endian mode
39 be in use as default, or the big endian mode will be in use for all the 41 will be in use as default, or the big endian mode
40 device registers. 42 will be in use for all the device registers.
41 43
42Example: 44Example:
43 45
diff --git a/Documentation/devicetree/bindings/sound/fsl,spdif.txt b/Documentation/devicetree/bindings/sound/fsl,spdif.txt
index 3e9e82c8eab3..b5ee32ee3706 100644
--- a/Documentation/devicetree/bindings/sound/fsl,spdif.txt
+++ b/Documentation/devicetree/bindings/sound/fsl,spdif.txt
@@ -6,32 +6,31 @@ a fibre cable.
6 6
7Required properties: 7Required properties:
8 8
9 - compatible : Compatible list, must contain "fsl,imx35-spdif". 9 - compatible : Compatible list, must contain "fsl,imx35-spdif".
10 10
11 - reg : Offset and length of the register set for the device. 11 - reg : Offset and length of the register set for the device.
12 12
13 - interrupts : Contains the spdif interrupt. 13 - interrupts : Contains the spdif interrupt.
14 14
15 - dmas : Generic dma devicetree binding as described in 15 - dmas : Generic dma devicetree binding as described in
16 Documentation/devicetree/bindings/dma/dma.txt. 16 Documentation/devicetree/bindings/dma/dma.txt.
17 17
18 - dma-names : Two dmas have to be defined, "tx" and "rx". 18 - dma-names : Two dmas have to be defined, "tx" and "rx".
19 19
20 - clocks : Contains an entry for each entry in clock-names. 20 - clocks : Contains an entry for each entry in clock-names.
21 21
22 - clock-names : Includes the following entries: 22 - clock-names : Includes the following entries:
23 "core" The core clock of spdif controller 23 "core" The core clock of spdif controller.
24 "rxtx<0-7>" Clock source list for tx and rx clock. 24 "rxtx<0-7>" Clock source list for tx and rx clock.
25 This clock list should be identical to 25 This clock list should be identical to the source
26 the source list connecting to the spdif 26 list connecting to the spdif clock mux in "SPDIF
27 clock mux in "SPDIF Transceiver Clock 27 Transceiver Clock Diagram" of SoC reference manual.
28 Diagram" of SoC reference manual. It 28 It can also be referred to TxClk_Source bit of
29 can also be referred to TxClk_Source 29 register SPDIF_STC.
30 bit of register SPDIF_STC.
31 30
32 - big-endian : If this property is absent, the native endian mode will 31 - big-endian : If this property is absent, the native endian mode
33 be in use as default, or the big endian mode will be in use for all the 32 will be in use as default, or the big endian mode
34 device registers. 33 will be in use for all the device registers.
35 34
36Example: 35Example:
37 36
diff --git a/Documentation/devicetree/bindings/sound/fsl-sai.txt b/Documentation/devicetree/bindings/sound/fsl-sai.txt
index 4956b14d4b06..044e5d76e2dd 100644
--- a/Documentation/devicetree/bindings/sound/fsl-sai.txt
+++ b/Documentation/devicetree/bindings/sound/fsl-sai.txt
@@ -5,32 +5,48 @@ which provides a synchronous audio interface that supports fullduplex
5serial interfaces with frame synchronization such as I2S, AC97, TDM, and 5serial interfaces with frame synchronization such as I2S, AC97, TDM, and
6codec/DSP interfaces. 6codec/DSP interfaces.
7 7
8
9Required properties: 8Required properties:
10- compatible: Compatible list, contains "fsl,vf610-sai" or "fsl,imx6sx-sai". 9
11- reg: Offset and length of the register set for the device. 10 - compatible : Compatible list, contains "fsl,vf610-sai" or
12- clocks: Must contain an entry for each entry in clock-names. 11 "fsl,imx6sx-sai".
13- clock-names : Must include the "bus" for register access and "mclk1" "mclk2" 12
14 "mclk3" for bit clock and frame clock providing. 13 - reg : Offset and length of the register set for the device.
15- dmas : Generic dma devicetree binding as described in 14
16 Documentation/devicetree/bindings/dma/dma.txt. 15 - clocks : Must contain an entry for each entry in clock-names.
17- dma-names : Two dmas have to be defined, "tx" and "rx". 16
18- pinctrl-names: Must contain a "default" entry. 17 - clock-names : Must include the "bus" for register access and
19- pinctrl-NNN: One property must exist for each entry in pinctrl-names. 18 "mclk1", "mclk2", "mclk3" for bit clock and frame
20 See ../pinctrl/pinctrl-bindings.txt for details of the property values. 19 clock providing.
21- big-endian: Boolean property, required if all the FTM_PWM registers 20 - dmas : Generic dma devicetree binding as described in
22 are big-endian rather than little-endian. 21 Documentation/devicetree/bindings/dma/dma.txt.
23- lsb-first: Configures whether the LSB or the MSB is transmitted first for 22
24 the fifo data. If this property is absent, the MSB is transmitted first as 23 - dma-names : Two dmas have to be defined, "tx" and "rx".
25 default, or the LSB is transmitted first. 24
26- fsl,sai-synchronous-rx: This is a boolean property. If present, indicating 25 - pinctrl-names : Must contain a "default" entry.
27 that SAI will work in the synchronous mode (sync Tx with Rx) which means 26
28 both the transimitter and receiver will send and receive data by following 27 - pinctrl-NNN : One property must exist for each entry in
29 receiver's bit clocks and frame sync clocks. 28 pinctrl-names. See ../pinctrl/pinctrl-bindings.txt
30- fsl,sai-asynchronous: This is a boolean property. If present, indicating 29 for details of the property values.
31 that SAI will work in the asynchronous mode, which means both transimitter 30
32 and receiver will send and receive data by following their own bit clocks 31 - big-endian : Boolean property, required if all the FTM_PWM
33 and frame sync clocks separately. 32 registers are big-endian rather than little-endian.
33
34 - lsb-first : Configures whether the LSB or the MSB is transmitted
35 first for the fifo data. If this property is absent,
36 the MSB is transmitted first as default, or the LSB
37 is transmitted first.
38
39 - fsl,sai-synchronous-rx: This is a boolean property. If present, indicating
40 that SAI will work in the synchronous mode (sync Tx
41 with Rx) which means both the transimitter and the
42 receiver will send and receive data by following
43 receiver's bit clocks and frame sync clocks.
44
45 - fsl,sai-asynchronous: This is a boolean property. If present, indicating
46 that SAI will work in the asynchronous mode, which
47 means both transimitter and receiver will send and
48 receive data by following their own bit clocks and
49 frame sync clocks separately.
34 50
35Note: 51Note:
36- If both fsl,sai-asynchronous and fsl,sai-synchronous-rx are absent, the 52- If both fsl,sai-asynchronous and fsl,sai-synchronous-rx are absent, the
diff --git a/Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt b/Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt
index e4acdd891e49..2f89db88fd57 100644
--- a/Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt
+++ b/Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt
@@ -1,33 +1,40 @@
1Freescale i.MX audio complex with SGTL5000 codec 1Freescale i.MX audio complex with SGTL5000 codec
2 2
3Required properties: 3Required properties:
4- compatible : "fsl,imx-audio-sgtl5000" 4
5- model : The user-visible name of this sound complex 5 - compatible : "fsl,imx-audio-sgtl5000"
6- ssi-controller : The phandle of the i.MX SSI controller 6
7- audio-codec : The phandle of the SGTL5000 audio codec 7 - model : The user-visible name of this sound complex
8- audio-routing : A list of the connections between audio components. 8
9 Each entry is a pair of strings, the first being the connection's sink, 9 - ssi-controller : The phandle of the i.MX SSI controller
10 the second being the connection's source. Valid names could be power 10
11 supplies, SGTL5000 pins, and the jacks on the board: 11 - audio-codec : The phandle of the SGTL5000 audio codec
12 12
13 Power supplies: 13 - audio-routing : A list of the connections between audio components.
14 * Mic Bias 14 Each entry is a pair of strings, the first being the
15 15 connection's sink, the second being the connection's
16 SGTL5000 pins: 16 source. Valid names could be power supplies, SGTL5000
17 * MIC_IN 17 pins, and the jacks on the board:
18 * LINE_IN 18
19 * HP_OUT 19 Power supplies:
20 * LINE_OUT 20 * Mic Bias
21 21
22 Board connectors: 22 SGTL5000 pins:
23 * Mic Jack 23 * MIC_IN
24 * Line In Jack 24 * LINE_IN
25 * Headphone Jack 25 * HP_OUT
26 * Line Out Jack 26 * LINE_OUT
27 * Ext Spk 27
28 28 Board connectors:
29- mux-int-port : The internal port of the i.MX audio muxer (AUDMUX) 29 * Mic Jack
30- mux-ext-port : The external port of the i.MX audio muxer 30 * Line In Jack
31 * Headphone Jack
32 * Line Out Jack
33 * Ext Spk
34
35 - mux-int-port : The internal port of the i.MX audio muxer (AUDMUX)
36
37 - mux-ext-port : The external port of the i.MX audio muxer
31 38
32Note: The AUDMUX port numbering should start at 1, which is consistent with 39Note: The AUDMUX port numbering should start at 1, which is consistent with
33hardware manual. 40hardware manual.
diff --git a/Documentation/devicetree/bindings/sound/imx-audio-spdif.txt b/Documentation/devicetree/bindings/sound/imx-audio-spdif.txt
index 7d13479f9c3c..da84a442ccea 100644
--- a/Documentation/devicetree/bindings/sound/imx-audio-spdif.txt
+++ b/Documentation/devicetree/bindings/sound/imx-audio-spdif.txt
@@ -2,23 +2,25 @@ Freescale i.MX audio complex with S/PDIF transceiver
2 2
3Required properties: 3Required properties:
4 4
5 - compatible : "fsl,imx-audio-spdif" 5 - compatible : "fsl,imx-audio-spdif"
6 6
7 - model : The user-visible name of this sound complex 7 - model : The user-visible name of this sound complex
8 8
9 - spdif-controller : The phandle of the i.MX S/PDIF controller 9 - spdif-controller : The phandle of the i.MX S/PDIF controller
10 10
11 11
12Optional properties: 12Optional properties:
13 13
14 - spdif-out : This is a boolean property. If present, the transmitting 14 - spdif-out : This is a boolean property. If present, the
15 function of S/PDIF will be enabled, indicating there's a physical 15 transmitting function of S/PDIF will be enabled,
16 S/PDIF out connector/jack on the board or it's connecting to some 16 indicating there's a physical S/PDIF out connector
17 other IP block, such as an HDMI encoder/display-controller. 17 or jack on the board or it's connecting to some
18 other IP block, such as an HDMI encoder or
19 display-controller.
18 20
19 - spdif-in : This is a boolean property. If present, the receiving 21 - spdif-in : This is a boolean property. If present, the receiving
20 function of S/PDIF will be enabled, indicating there's a physical 22 function of S/PDIF will be enabled, indicating there
21 S/PDIF in connector/jack on the board. 23 is a physical S/PDIF in connector/jack on the board.
22 24
23* Note: At least one of these two properties should be set in the DT binding. 25* Note: At least one of these two properties should be set in the DT binding.
24 26
diff --git a/Documentation/devicetree/bindings/sound/imx-audio-wm8962.txt b/Documentation/devicetree/bindings/sound/imx-audio-wm8962.txt
index f49450a87890..acea71bee34f 100644
--- a/Documentation/devicetree/bindings/sound/imx-audio-wm8962.txt
+++ b/Documentation/devicetree/bindings/sound/imx-audio-wm8962.txt
@@ -1,25 +1,32 @@
1Freescale i.MX audio complex with WM8962 codec 1Freescale i.MX audio complex with WM8962 codec
2 2
3Required properties: 3Required properties:
4- compatible : "fsl,imx-audio-wm8962" 4
5- model : The user-visible name of this sound complex 5 - compatible : "fsl,imx-audio-wm8962"
6- ssi-controller : The phandle of the i.MX SSI controller 6
7- audio-codec : The phandle of the WM8962 audio codec 7 - model : The user-visible name of this sound complex
8- audio-routing : A list of the connections between audio components. 8
9 Each entry is a pair of strings, the first being the connection's sink, 9 - ssi-controller : The phandle of the i.MX SSI controller
10 the second being the connection's source. Valid names could be power 10
11 supplies, WM8962 pins, and the jacks on the board: 11 - audio-codec : The phandle of the WM8962 audio codec
12 12
13 Power supplies: 13 - audio-routing : A list of the connections between audio components.
14 * Mic Bias 14 Each entry is a pair of strings, the first being the
15 15 connection's sink, the second being the connection's
16 Board connectors: 16 source. Valid names could be power supplies, WM8962
17 * Mic Jack 17 pins, and the jacks on the board:
18 * Headphone Jack 18
19 * Ext Spk 19 Power supplies:
20 20 * Mic Bias
21- mux-int-port : The internal port of the i.MX audio muxer (AUDMUX) 21
22- mux-ext-port : The external port of the i.MX audio muxer 22 Board connectors:
23 * Mic Jack
24 * Headphone Jack
25 * Ext Spk
26
27 - mux-int-port : The internal port of the i.MX audio muxer (AUDMUX)
28
29 - mux-ext-port : The external port of the i.MX audio muxer
23 30
24Note: The AUDMUX port numbering should start at 1, which is consistent with 31Note: The AUDMUX port numbering should start at 1, which is consistent with
25hardware manual. 32hardware manual.
diff --git a/Documentation/devicetree/bindings/sound/imx-audmux.txt b/Documentation/devicetree/bindings/sound/imx-audmux.txt
index f88a00e54c63..b30a737e209e 100644
--- a/Documentation/devicetree/bindings/sound/imx-audmux.txt
+++ b/Documentation/devicetree/bindings/sound/imx-audmux.txt
@@ -1,18 +1,24 @@
1Freescale Digital Audio Mux (AUDMUX) device 1Freescale Digital Audio Mux (AUDMUX) device
2 2
3Required properties: 3Required properties:
4- compatible : "fsl,imx21-audmux" for AUDMUX version firstly used on i.MX21, 4
5 or "fsl,imx31-audmux" for the version firstly used on i.MX31. 5 - compatible : "fsl,imx21-audmux" for AUDMUX version firstly used
6- reg : Should contain AUDMUX registers location and length 6 on i.MX21, or "fsl,imx31-audmux" for the version
7 firstly used on i.MX31.
8
9 - reg : Should contain AUDMUX registers location and length.
7 10
8An initial configuration can be setup using child nodes. 11An initial configuration can be setup using child nodes.
9 12
10Required properties of optional child nodes: 13Required properties of optional child nodes:
11- fsl,audmux-port : Integer of the audmux port that is configured by this 14
12 child node. 15 - fsl,audmux-port : Integer of the audmux port that is configured by this
13- fsl,port-config : List of configuration options for the specific port. For 16 child node.
14 imx31-audmux and above, it is a list of tuples <ptcr pdcr>. For 17
15 imx21-audmux it is a list of pcr values. 18 - fsl,port-config : List of configuration options for the specific port.
19 For imx31-audmux and above, it is a list of tuples
20 <ptcr pdcr>. For imx21-audmux it is a list of pcr
21 values.
16 22
17Example: 23Example:
18 24
diff --git a/Documentation/devicetree/bindings/sound/max98090.txt b/Documentation/devicetree/bindings/sound/max98090.txt
index c454e67f54bb..aa802a274520 100644
--- a/Documentation/devicetree/bindings/sound/max98090.txt
+++ b/Documentation/devicetree/bindings/sound/max98090.txt
@@ -16,6 +16,8 @@ Optional properties:
16 16
17- clock-names: Should be "mclk" 17- clock-names: Should be "mclk"
18 18
19- maxim,dmic-freq: Frequency at which to clock DMIC
20
19Pins on the device (for linking into audio routes): 21Pins on the device (for linking into audio routes):
20 22
21 * MIC1 23 * MIC1
diff --git a/Documentation/devicetree/bindings/sound/renesas,fsi.txt b/Documentation/devicetree/bindings/sound/renesas,fsi.txt
index c5be003f413e..0d0ab51105b0 100644
--- a/Documentation/devicetree/bindings/sound/renesas,fsi.txt
+++ b/Documentation/devicetree/bindings/sound/renesas,fsi.txt
@@ -1,11 +1,16 @@
1Renesas FSI 1Renesas FSI
2 2
3Required properties: 3Required properties:
4- compatible : "renesas,sh_fsi2" or "renesas,sh_fsi" 4- compatible : "renesas,fsi2-<soctype>",
5 "renesas,sh_fsi2" or "renesas,sh_fsi" as
6 fallback.
7 Examples with soctypes are:
8 - "renesas,fsi2-r8a7740" (R-Mobile A1)
9 - "renesas,fsi2-sh73a0" (SH-Mobile AG5)
5- reg : Should contain the register physical address and length 10- reg : Should contain the register physical address and length
6- interrupts : Should contain FSI interrupt 11- interrupts : Should contain FSI interrupt
7 12
8- fsia,spdif-connection : FSI is connected by S/PDFI 13- fsia,spdif-connection : FSI is connected by S/PDIF
9- fsia,stream-mode-support : FSI supports 16bit stream mode. 14- fsia,stream-mode-support : FSI supports 16bit stream mode.
10- fsia,use-internal-clock : FSI uses internal clock when master mode. 15- fsia,use-internal-clock : FSI uses internal clock when master mode.
11 16
diff --git a/Documentation/devicetree/bindings/sound/renesas,rsnd.txt b/Documentation/devicetree/bindings/sound/renesas,rsnd.txt
index aa697abf337e..2dd690bc19cc 100644
--- a/Documentation/devicetree/bindings/sound/renesas,rsnd.txt
+++ b/Documentation/devicetree/bindings/sound/renesas,rsnd.txt
@@ -1,8 +1,12 @@
1Renesas R-Car sound 1Renesas R-Car sound
2 2
3Required properties: 3Required properties:
4- compatible : "renesas,rcar_sound-gen1" if generation1 4- compatible : "renesas,rcar_sound-<soctype>", fallbacks
5 "renesas,rcar_sound-gen1" if generation1, and
5 "renesas,rcar_sound-gen2" if generation2 6 "renesas,rcar_sound-gen2" if generation2
7 Examples with soctypes are:
8 - "renesas,rcar_sound-r8a7790" (R-Car H2)
9 - "renesas,rcar_sound-r8a7791" (R-Car M2-W)
6- reg : Should contain the register physical address. 10- reg : Should contain the register physical address.
7 required register is 11 required register is
8 SRU/ADG/SSI if generation1 12 SRU/ADG/SSI if generation1
@@ -35,9 +39,9 @@ DAI subnode properties:
35 39
36Example: 40Example:
37 41
38rcar_sound: rcar_sound@0xffd90000 { 42rcar_sound: rcar_sound@ec500000 {
39 #sound-dai-cells = <1>; 43 #sound-dai-cells = <1>;
40 compatible = "renesas,rcar_sound-gen2"; 44 compatible = "renesas,rcar_sound-r8a7791", "renesas,rcar_sound-gen2";
41 reg = <0 0xec500000 0 0x1000>, /* SCU */ 45 reg = <0 0xec500000 0 0x1000>, /* SCU */
42 <0 0xec5a0000 0 0x100>, /* ADG */ 46 <0 0xec5a0000 0 0x100>, /* ADG */
43 <0 0xec540000 0 0x1000>, /* SSIU */ 47 <0 0xec540000 0 0x1000>, /* SSIU */
diff --git a/Documentation/devicetree/bindings/sound/rt5631.txt b/Documentation/devicetree/bindings/sound/rt5631.txt
new file mode 100644
index 000000000000..92b986ca337b
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/rt5631.txt
@@ -0,0 +1,48 @@
1ALC5631/RT5631 audio CODEC
2
3This device supports I2C only.
4
5Required properties:
6
7 - compatible : "realtek,alc5631" or "realtek,rt5631"
8
9 - reg : the I2C address of the device.
10
11Pins on the device (for linking into audio routes):
12
13 * SPK_OUT_R_P
14 * SPK_OUT_R_N
15 * SPK_OUT_L_P
16 * SPK_OUT_L_N
17 * HP_OUT_L
18 * HP_OUT_R
19 * AUX_OUT2_LP
20 * AUX_OUT2_RN
21 * AUX_OUT1_LP
22 * AUX_OUT1_RN
23 * AUX_IN_L_JD
24 * AUX_IN_R_JD
25 * MONO_IN_P
26 * MONO_IN_N
27 * MIC1_P
28 * MIC1_N
29 * MIC2_P
30 * MIC2_N
31 * MONO_OUT_P
32 * MONO_OUT_N
33 * MICBIAS1
34 * MICBIAS2
35
36Example:
37
38alc5631: alc5631@1a {
39 compatible = "realtek,alc5631";
40 reg = <0x1a>;
41};
42
43or
44
45rt5631: rt5631@1a {
46 compatible = "realtek,rt5631";
47 reg = <0x1a>;
48};
diff --git a/Documentation/devicetree/bindings/sound/rt5677.txt b/Documentation/devicetree/bindings/sound/rt5677.txt
index 0701b834fc73..740ff771aa8b 100644
--- a/Documentation/devicetree/bindings/sound/rt5677.txt
+++ b/Documentation/devicetree/bindings/sound/rt5677.txt
@@ -27,6 +27,21 @@ Optional properties:
27 Boolean. Indicate MIC1/2 input and LOUT1/2/3 outputs are differential, 27 Boolean. Indicate MIC1/2 input and LOUT1/2/3 outputs are differential,
28 rather than single-ended. 28 rather than single-ended.
29 29
30- realtek,gpio-config
31 Array of six 8bit elements that configures GPIO.
32 0 - floating (reset value)
33 1 - pull down
34 2 - pull up
35
36- realtek,jd1-gpio
37 Configures GPIO Mic Jack detection 1.
38 Select 0 ~ 3 as OFF, GPIO1, GPIO2 and GPIO3 respectively.
39
40- realtek,jd2-gpio
41- realtek,jd3-gpio
42 Configures GPIO Mic Jack detection 2 and 3.
43 Select 0 ~ 3 as OFF, GPIO4, GPIO5 and GPIO6 respectively.
44
30Pins on the device (for linking into audio routes): 45Pins on the device (for linking into audio routes):
31 46
32 * IN1P 47 * IN1P
@@ -56,4 +71,6 @@ rt5677 {
56 realtek,pow-ldo2-gpio = 71 realtek,pow-ldo2-gpio =
57 <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>; 72 <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
58 realtek,in1-differential = "true"; 73 realtek,in1-differential = "true";
74 realtek,gpio-config = /bits/ 8 <0 0 0 0 0 2>; /* pull up GPIO6 */
75 realtek,jd2-gpio = <3>; /* Enables Jack detection for GPIO6 */
59}; 76};
diff --git a/Documentation/devicetree/bindings/sound/samsung-i2s.txt b/Documentation/devicetree/bindings/sound/samsung-i2s.txt
index 7386d444ada1..d188296bb6ec 100644
--- a/Documentation/devicetree/bindings/sound/samsung-i2s.txt
+++ b/Documentation/devicetree/bindings/sound/samsung-i2s.txt
@@ -6,10 +6,17 @@ Required SoC Specific Properties:
6 - samsung,s3c6410-i2s: for 8/16/24bit stereo I2S. 6 - samsung,s3c6410-i2s: for 8/16/24bit stereo I2S.
7 - samsung,s5pv210-i2s: for 8/16/24bit multichannel(5.1) I2S with 7 - samsung,s5pv210-i2s: for 8/16/24bit multichannel(5.1) I2S with
8 secondary fifo, s/w reset control and internal mux for root clk src. 8 secondary fifo, s/w reset control and internal mux for root clk src.
9 - samsung,exynos5420-i2s: for 8/16/24bit multichannel(7.1) I2S with 9 - samsung,exynos5420-i2s: for 8/16/24bit multichannel(5.1) I2S for
10 secondary fifo, s/w reset control, internal mux for root clk src and 10 playback, sterio channel capture, secondary fifo using internal
11 TDM support. TDM (Time division multiplexing) is to allow transfer of 11 or external dma, s/w reset control, internal mux for root clk src
12 multiple channel audio data on single data line. 12 and 7.1 channel TDM support for playback. TDM (Time division multiplexing)
13 is to allow transfer of multiple channel audio data on single data line.
14 - samsung,exynos7-i2s: with all the available features of exynos5 i2s,
15 exynos7 I2S has 7.1 channel TDM support for capture, secondary fifo
16 with only external dma and more no.of root clk sampling frequencies.
17 - samsung,exynos7-i2s1: I2S1 on previous samsung platforms supports
18 stereo channels. exynos7 i2s1 upgraded to 5.1 multichannel with
19 slightly modified bit offsets.
13 20
14- reg: physical base address of the controller and length of memory mapped 21- reg: physical base address of the controller and length of memory mapped
15 region. 22 region.
diff --git a/Documentation/devicetree/bindings/sound/sgtl5000.txt b/Documentation/devicetree/bindings/sound/sgtl5000.txt
index d556dcb8816b..0e5e4eb3ef1b 100644
--- a/Documentation/devicetree/bindings/sound/sgtl5000.txt
+++ b/Documentation/devicetree/bindings/sound/sgtl5000.txt
@@ -7,6 +7,17 @@ Required properties:
7 7
8- clocks : the clock provider of SYS_MCLK 8- clocks : the clock provider of SYS_MCLK
9 9
10- micbias-resistor-k-ohms : the bias resistor to be used in kOmhs
11 The resistor can take values of 2k, 4k or 8k.
12 If set to 0 it will be off.
13 If this node is not mentioned or if the value is unknown, then
14 micbias resistor is set to 4K.
15
16- micbias-voltage-m-volts : the bias voltage to be used in mVolts
17 The voltage can take values from 1.25V to 3V by 250mV steps
18 If this node is not mentionned or the value is unknown, then
19 the value is set to 1.25V.
20
10- VDDA-supply : the regulator provider of VDDA 21- VDDA-supply : the regulator provider of VDDA
11 22
12- VDDIO-supply: the regulator provider of VDDIO 23- VDDIO-supply: the regulator provider of VDDIO
@@ -21,6 +32,8 @@ codec: sgtl5000@0a {
21 compatible = "fsl,sgtl5000"; 32 compatible = "fsl,sgtl5000";
22 reg = <0x0a>; 33 reg = <0x0a>;
23 clocks = <&clks 150>; 34 clocks = <&clks 150>;
35 micbias-resistor-k-ohms = <2>;
36 micbias-voltage-m-volts = <2250>;
24 VDDA-supply = <&reg_3p3v>; 37 VDDA-supply = <&reg_3p3v>;
25 VDDIO-supply = <&reg_3p3v>; 38 VDDIO-supply = <&reg_3p3v>;
26}; 39};
diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.txt b/Documentation/devicetree/bindings/sound/ts3a227e.txt
new file mode 100644
index 000000000000..e8bf23eb1803
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/ts3a227e.txt
@@ -0,0 +1,26 @@
1Texas Instruments TS3A227E
2Autonomous Audio Accessory Detection and Configuration Switch
3
4The TS3A227E detect headsets of 3-ring and 4-ring standards and
5switches automatically to route the microphone correctly. It also
6handles key press detection in accordance with the Android audio
7headset specification v1.0.
8
9Required properties:
10
11 - compatible: Should contain "ti,ts3a227e".
12 - reg: The i2c address. Should contain <0x3b>.
13 - interrupt-parent: The parent interrupt controller
14 - interrupts: Interrupt number for /INT pin from the 227e
15
16
17Examples:
18
19 i2c {
20 ts3a227e@3b {
21 compatible = "ti,ts3a227e";
22 reg = <0x3b>;
23 interrupt-parent = <&gpio>;
24 interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
25 };
26 };
diff --git a/Documentation/devicetree/bindings/sound/wm8960.txt b/Documentation/devicetree/bindings/sound/wm8960.txt
new file mode 100644
index 000000000000..2deb8a3da9c5
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/wm8960.txt
@@ -0,0 +1,31 @@
1WM8960 audio CODEC
2
3This device supports I2C only.
4
5Required properties:
6
7 - compatible : "wlf,wm8960"
8
9 - reg : the I2C address of the device.
10
11Optional properties:
12 - wlf,shared-lrclk: This is a boolean property. If present, the LRCM bit of
13 R24 (Additional control 2) gets set, indicating that ADCLRC and DACLRC pins
14 will be disabled only when ADC (Left and Right) and DAC (Left and Right)
15 are disabled.
16 When wm8960 works on synchronize mode and DACLRC pin is used to supply
17 frame clock, it will no frame clock for captrue unless enable DAC to enable
18 DACLRC pin. If shared-lrclk is present, no need to enable DAC for captrue.
19
20 - wlf,capless: This is a boolean property. If present, OUT3 pin will be
21 enabled and disabled together with HP_L and HP_R pins in response to jack
22 detect events.
23
24Example:
25
26codec: wm8960@1a {
27 compatible = "wlf,wm8960";
28 reg = <0x1a>;
29
30 wlf,shared-lrclk;
31};
diff --git a/Documentation/sound/alsa/ControlNames.txt b/Documentation/sound/alsa/ControlNames.txt
index fea65bb6269e..79a6127863ca 100644
--- a/Documentation/sound/alsa/ControlNames.txt
+++ b/Documentation/sound/alsa/ControlNames.txt
@@ -1,6 +1,6 @@
1This document describes standard names of mixer controls. 1This document describes standard names of mixer controls.
2 2
3Syntax: SOURCE [DIRECTION] FUNCTION 3Syntax: [LOCATION] SOURCE [CHANNEL] [DIRECTION] FUNCTION
4 4
5DIRECTION: 5DIRECTION:
6 <nothing> (both directions) 6 <nothing> (both directions)
@@ -14,12 +14,29 @@ FUNCTION:
14 Volume 14 Volume
15 Route (route control, hardware specific) 15 Route (route control, hardware specific)
16 16
17CHANNEL:
18 <nothing> (channel independent, or applies to all channels)
19 Front
20 Surround (rear left/right in 4.0/5.1 surround)
21 CLFE
22 Center
23 LFE
24 Side (side left/right for 7.1 surround)
25
26LOCATION: (physical location of source)
27 Front
28 Rear
29 Dock (docking station)
30 Internal
31
17SOURCE: 32SOURCE:
18 Master 33 Master
19 Master Mono 34 Master Mono
20 Hardware Master 35 Hardware Master
21 Speaker (internal speaker) 36 Speaker (internal speaker)
37 Bass Speaker (internal LFE speaker)
22 Headphone 38 Headphone
39 Line Out
23 Beep (beep generator) 40 Beep (beep generator)
24 Phone 41 Phone
25 Phone Input 42 Phone Input
@@ -27,14 +44,14 @@ SOURCE:
27 Synth 44 Synth
28 FM 45 FM
29 Mic 46 Mic
30 Line 47 Headset Mic (mic part of combined headset jack - 4-pin headphone + mic)
48 Headphone Mic (mic part of either/or - 3-pin headphone or mic)
49 Line (input only, use "Line Out" for output)
31 CD 50 CD
32 Video 51 Video
33 Zoom Video 52 Zoom Video
34 Aux 53 Aux
35 PCM 54 PCM
36 PCM Front
37 PCM Rear
38 PCM Pan 55 PCM Pan
39 Loopback 56 Loopback
40 Analog Loopback (D/A -> A/D loopback) 57 Analog Loopback (D/A -> A/D loopback)
@@ -47,8 +64,13 @@ SOURCE:
47 Music 64 Music
48 I2S 65 I2S
49 IEC958 66 IEC958
67 HDMI
68 SPDIF (output only)
69 SPDIF In
70 Digital In
71 HDMI/DP (either HDMI or DisplayPort)
50 72
51Exceptions: 73Exceptions (deprecated):
52 [Digital] Capture Source 74 [Digital] Capture Source
53 [Digital] Capture Switch (aka input gain switch) 75 [Digital] Capture Switch (aka input gain switch)
54 [Digital] Capture Volume (aka input gain volume) 76 [Digital] Capture Volume (aka input gain volume)
diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt
index a5e754714344..5a3163cac6c3 100644
--- a/Documentation/sound/alsa/HD-Audio-Models.txt
+++ b/Documentation/sound/alsa/HD-Audio-Models.txt
@@ -113,14 +113,10 @@ AD1984
113 113
114AD1986A 114AD1986A
115======= 115=======
116 6stack 6-jack, separate surrounds (default)
117 3stack 3-stack, shared surrounds 116 3stack 3-stack, shared surrounds
118 laptop 2-channel only (FSC V2060, Samsung M50) 117 laptop 2-channel only (FSC V2060, Samsung M50)
119 laptop-eapd 2-channel with EAPD (ASUS A6J) 118 laptop-imic 2-channel with built-in mic
120 laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100) 119 eapd Turn on EAPD constantly
121 ultra 2-channel with EAPD (Samsung Ultra tablet PC)
122 samsung 2-channel with EAPD (Samsung R65)
123 samsung-p50 2-channel with HP-automute (Samsung P50)
124 120
125AD1988/AD1988B/AD1989A/AD1989B 121AD1988/AD1988B/AD1989A/AD1989B
126============================== 122==============================
diff --git a/Documentation/sound/alsa/Procfile.txt b/Documentation/sound/alsa/Procfile.txt
index 7fcd1ad96fcc..7f8a0d325905 100644
--- a/Documentation/sound/alsa/Procfile.txt
+++ b/Documentation/sound/alsa/Procfile.txt
@@ -101,10 +101,6 @@ card*/pcm*/xrun_debug
101 bit 0 = Enable XRUN/jiffies debug messages 101 bit 0 = Enable XRUN/jiffies debug messages
102 bit 1 = Show stack trace at XRUN / jiffies check 102 bit 1 = Show stack trace at XRUN / jiffies check
103 bit 2 = Enable additional jiffies check 103 bit 2 = Enable additional jiffies check
104 bit 3 = Log hwptr update at each period interrupt
105 bit 4 = Log hwptr update at each snd_pcm_update_hw_ptr()
106 bit 5 = Show last 10 positions on error
107 bit 6 = Do above only once
108 104
109 When the bit 0 is set, the driver will show the messages to 105 When the bit 0 is set, the driver will show the messages to
110 kernel log when an xrun is detected. The debug message is 106 kernel log when an xrun is detected. The debug message is
@@ -121,15 +117,6 @@ card*/pcm*/xrun_debug
121 buggy) hardware that doesn't give smooth pointer updates. 117 buggy) hardware that doesn't give smooth pointer updates.
122 This feature is enabled via the bit 2. 118 This feature is enabled via the bit 2.
123 119
124 Bits 3 and 4 are for logging the hwptr records. Note that
125 these will give flood of kernel messages.
126
127 When bit 5 is set, the driver logs the last 10 xrun errors and
128 the proc file shows each jiffies, position, period_size,
129 buffer_size, old_hw_ptr, and hw_ptr_base values.
130
131 When bit 6 is set, the full xrun log is shown only once.
132
133card*/pcm*/sub*/info 120card*/pcm*/sub*/info
134 The general information of this PCM sub-stream. 121 The general information of this PCM sub-stream.
135 122
@@ -146,6 +133,10 @@ card*/pcm*/sub*/sw_params
146card*/pcm*/sub*/prealloc 133card*/pcm*/sub*/prealloc
147 The buffer pre-allocation information. 134 The buffer pre-allocation information.
148 135
136card*/pcm*/sub*/xrun_injection
137 Triggers an XRUN to the running stream when any value is
138 written to this proc file. Used for fault injection.
139 This entry is write-only.
149 140
150AC97 Codec Information 141AC97 Codec Information
151---------------------- 142----------------------
diff --git a/MAINTAINERS b/MAINTAINERS
index 7bff8087fce7..132958a4e27c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6682,6 +6682,12 @@ S: Supported
6682F: drivers/gpu/drm/i2c/tda998x_drv.c 6682F: drivers/gpu/drm/i2c/tda998x_drv.c
6683F: include/drm/i2c/tda998x.h 6683F: include/drm/i2c/tda998x.h
6684 6684
6685NXP TFA9879 DRIVER
6686M: Peter Rosin <peda@axentia.se>
6687L: alsa-devel@alsa-project.org (moderated for non-subscribers)
6688S: Maintained
6689F: sound/soc/codecs/tfa9879*
6690
6685OMAP SUPPORT 6691OMAP SUPPORT
6686M: Tony Lindgren <tony@atomide.com> 6692M: Tony Lindgren <tony@atomide.com>
6687L: linux-omap@vger.kernel.org 6693L: linux-omap@vger.kernel.org
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 840c3a48e720..962a7f31f596 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -924,6 +924,14 @@ static inline void spitz_i2c_init(void) {}
924#endif 924#endif
925 925
926/****************************************************************************** 926/******************************************************************************
927 * Audio devices
928 ******************************************************************************/
929static inline void spitz_audio_init(void)
930{
931 platform_device_register_simple("spitz-audio", -1, NULL, 0);
932}
933
934/******************************************************************************
927 * Machine init 935 * Machine init
928 ******************************************************************************/ 936 ******************************************************************************/
929static void spitz_poweroff(void) 937static void spitz_poweroff(void)
@@ -970,6 +978,7 @@ static void __init spitz_init(void)
970 spitz_nor_init(); 978 spitz_nor_init();
971 spitz_nand_init(); 979 spitz_nand_init();
972 spitz_i2c_init(); 980 spitz_i2c_init();
981 spitz_audio_init();
973} 982}
974 983
975static void __init spitz_fixup(struct tag *tags, char **cmdline) 984static void __init spitz_fixup(struct tag *tags, char **cmdline)
diff --git a/arch/x86/include/asm/platform_sst_audio.h b/arch/x86/include/asm/platform_sst_audio.h
index 0a4e140315b6..7249e6d0902d 100644
--- a/arch/x86/include/asm/platform_sst_audio.h
+++ b/arch/x86/include/asm/platform_sst_audio.h
@@ -16,6 +16,9 @@
16 16
17#include <linux/sfi.h> 17#include <linux/sfi.h>
18 18
19#define MAX_NUM_STREAMS_MRFLD 25
20#define MAX_NUM_STREAMS MAX_NUM_STREAMS_MRFLD
21
19enum sst_audio_task_id_mrfld { 22enum sst_audio_task_id_mrfld {
20 SST_TASK_ID_NONE = 0, 23 SST_TASK_ID_NONE = 0,
21 SST_TASK_ID_SBA = 1, 24 SST_TASK_ID_SBA = 1,
@@ -73,6 +76,65 @@ struct sst_platform_data {
73 unsigned int strm_map_size; 76 unsigned int strm_map_size;
74}; 77};
75 78
79struct sst_info {
80 u32 iram_start;
81 u32 iram_end;
82 bool iram_use;
83 u32 dram_start;
84 u32 dram_end;
85 bool dram_use;
86 u32 imr_start;
87 u32 imr_end;
88 bool imr_use;
89 u32 mailbox_start;
90 bool use_elf;
91 bool lpe_viewpt_rqd;
92 unsigned int max_streams;
93 u32 dma_max_len;
94 u8 num_probes;
95};
96
97struct sst_lib_dnld_info {
98 unsigned int mod_base;
99 unsigned int mod_end;
100 unsigned int mod_table_offset;
101 unsigned int mod_table_size;
102 bool mod_ddr_dnld;
103};
104
105struct sst_res_info {
106 unsigned int shim_offset;
107 unsigned int shim_size;
108 unsigned int shim_phy_addr;
109 unsigned int ssp0_offset;
110 unsigned int ssp0_size;
111 unsigned int dma0_offset;
112 unsigned int dma0_size;
113 unsigned int dma1_offset;
114 unsigned int dma1_size;
115 unsigned int iram_offset;
116 unsigned int iram_size;
117 unsigned int dram_offset;
118 unsigned int dram_size;
119 unsigned int mbox_offset;
120 unsigned int mbox_size;
121 unsigned int acpi_lpe_res_index;
122 unsigned int acpi_ddr_index;
123 unsigned int acpi_ipc_irq_index;
124};
125
126struct sst_ipc_info {
127 int ipc_offset;
128 unsigned int mbox_recv_off;
129};
130
131struct sst_platform_info {
132 const struct sst_info *probe_data;
133 const struct sst_ipc_info *ipc_info;
134 const struct sst_res_info *res_info;
135 const struct sst_lib_dnld_info *lib_info;
136 const char *platform;
137};
76int add_sst_platform_device(void); 138int add_sst_platform_device(void);
77#endif 139#endif
78 140
diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
index 40569894c1c9..ac3cd74e824e 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -173,9 +173,7 @@ static void saa7134_irq_alsa_done(struct saa7134_dev *dev,
173 dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->dmasound.read_count, 173 dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->dmasound.read_count,
174 dev->dmasound.bufsize, dev->dmasound.blocks); 174 dev->dmasound.bufsize, dev->dmasound.blocks);
175 spin_unlock(&dev->slock); 175 spin_unlock(&dev->slock);
176 snd_pcm_stream_lock(dev->dmasound.substream); 176 snd_pcm_stop_xrun(dev->dmasound.substream);
177 snd_pcm_stop(dev->dmasound.substream,SNDRV_PCM_STATE_XRUN);
178 snd_pcm_stream_unlock(dev->dmasound.substream);
179 return; 177 return;
180 } 178 }
181 179
diff --git a/include/linux/mfd/arizona/core.h b/include/linux/mfd/arizona/core.h
index f34723f7663c..910e3aa1e965 100644
--- a/include/linux/mfd/arizona/core.h
+++ b/include/linux/mfd/arizona/core.h
@@ -141,6 +141,7 @@ struct arizona {
141 141
142 uint16_t dac_comp_coeff; 142 uint16_t dac_comp_coeff;
143 uint8_t dac_comp_enabled; 143 uint8_t dac_comp_enabled;
144 struct mutex dac_comp_lock;
144}; 145};
145 146
146int arizona_clk32k_enable(struct arizona *arizona); 147int arizona_clk32k_enable(struct arizona *arizona);
diff --git a/include/linux/mfd/davinci_voicecodec.h b/include/linux/mfd/davinci_voicecodec.h
index cb01496bfa49..8e1cdbef3dad 100644
--- a/include/linux/mfd/davinci_voicecodec.h
+++ b/include/linux/mfd/davinci_voicecodec.h
@@ -99,12 +99,6 @@ struct davinci_vcif {
99 dma_addr_t dma_rx_addr; 99 dma_addr_t dma_rx_addr;
100}; 100};
101 101
102struct cq93vc {
103 struct platform_device *pdev;
104 struct snd_soc_codec *codec;
105 u32 sysclk;
106};
107
108struct davinci_vc; 102struct davinci_vc;
109 103
110struct davinci_vc { 104struct davinci_vc {
@@ -122,7 +116,6 @@ struct davinci_vc {
122 116
123 /* Client devices */ 117 /* Client devices */
124 struct davinci_vcif davinci_vcif; 118 struct davinci_vcif davinci_vcif;
125 struct cq93vc cq93vc;
126}; 119};
127 120
128#endif 121#endif
diff --git a/include/linux/platform_data/asoc-s3c.h b/include/linux/platform_data/asoc-s3c.h
index a6591c693ebb..5e0bc779e6c5 100644
--- a/include/linux/platform_data/asoc-s3c.h
+++ b/include/linux/platform_data/asoc-s3c.h
@@ -27,6 +27,7 @@ struct samsung_i2s {
27#define QUIRK_NO_MUXPSR (1 << 2) 27#define QUIRK_NO_MUXPSR (1 << 2)
28#define QUIRK_NEED_RSTCLR (1 << 3) 28#define QUIRK_NEED_RSTCLR (1 << 3)
29#define QUIRK_SUPPORTS_TDM (1 << 4) 29#define QUIRK_SUPPORTS_TDM (1 << 4)
30#define QUIRK_SUPPORTS_IDMA (1 << 5)
30 /* Quirks of the I2S controller */ 31 /* Quirks of the I2S controller */
31 u32 quirks; 32 u32 quirks;
32 dma_addr_t idma_addr; 33 dma_addr_t idma_addr;
diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
index ae6c3b8ed2f5..396e8f73670a 100644
--- a/include/sound/compress_driver.h
+++ b/include/sound/compress_driver.h
@@ -42,12 +42,11 @@ struct snd_compr_ops;
42 * @buffer_size: size of the above buffer 42 * @buffer_size: size of the above buffer
43 * @fragment_size: size of buffer fragment in bytes 43 * @fragment_size: size of buffer fragment in bytes
44 * @fragments: number of such fragments 44 * @fragments: number of such fragments
45 * @hw_pointer: offset of last location in buffer where DSP copied data
46 * @app_pointer: offset of last location in buffer where app wrote data
47 * @total_bytes_available: cumulative number of bytes made available in 45 * @total_bytes_available: cumulative number of bytes made available in
48 * the ring buffer 46 * the ring buffer
49 * @total_bytes_transferred: cumulative bytes transferred by offload DSP 47 * @total_bytes_transferred: cumulative bytes transferred by offload DSP
50 * @sleep: poll sleep 48 * @sleep: poll sleep
49 * @private_data: driver private data pointer
51 */ 50 */
52struct snd_compr_runtime { 51struct snd_compr_runtime {
53 snd_pcm_state_t state; 52 snd_pcm_state_t state;
@@ -94,6 +93,8 @@ struct snd_compr_stream {
94 * This can be called in during stream creation only to set codec params 93 * This can be called in during stream creation only to set codec params
95 * and the stream properties 94 * and the stream properties
96 * @get_params: retrieve the codec parameters, mandatory 95 * @get_params: retrieve the codec parameters, mandatory
96 * @set_metadata: Set the metadata values for a stream
97 * @get_metadata: retreives the requested metadata values from stream
97 * @trigger: Trigger operations like start, pause, resume, drain, stop. 98 * @trigger: Trigger operations like start, pause, resume, drain, stop.
98 * This callback is mandatory 99 * This callback is mandatory
99 * @pointer: Retrieve current h/w pointer information. Mandatory 100 * @pointer: Retrieve current h/w pointer information. Mandatory
diff --git a/include/sound/jack.h b/include/sound/jack.h
index 58916573db58..218235030ebc 100644
--- a/include/sound/jack.h
+++ b/include/sound/jack.h
@@ -28,8 +28,23 @@
28struct input_dev; 28struct input_dev;
29 29
30/** 30/**
31 * Jack types which can be reported. These values are used as a 31 * enum snd_jack_types - Jack types which can be reported
32 * bitmask. 32 * @SND_JACK_HEADPHONE: Headphone
33 * @SND_JACK_MICROPHONE: Microphone
34 * @SND_JACK_HEADSET: Headset
35 * @SND_JACK_LINEOUT: Line out
36 * @SND_JACK_MECHANICAL: Mechanical switch
37 * @SND_JACK_VIDEOOUT: Video out
38 * @SND_JACK_AVOUT: AV (Audio Video) out
39 * @SND_JACK_LINEIN: Line in
40 * @SND_JACK_BTN_0: Button 0
41 * @SND_JACK_BTN_1: Button 1
42 * @SND_JACK_BTN_2: Button 2
43 * @SND_JACK_BTN_3: Button 3
44 * @SND_JACK_BTN_4: Button 4
45 * @SND_JACK_BTN_5: Button 5
46 *
47 * These values are used as a bitmask.
33 * 48 *
34 * Note that this must be kept in sync with the lookup table in 49 * Note that this must be kept in sync with the lookup table in
35 * sound/core/jack.c. 50 * sound/core/jack.c.
@@ -90,6 +105,13 @@ static inline void snd_jack_set_parent(struct snd_jack *jack,
90{ 105{
91} 106}
92 107
108static inline int snd_jack_set_key(struct snd_jack *jack,
109 enum snd_jack_types type,
110 int keytype)
111{
112 return 0;
113}
114
93static inline void snd_jack_report(struct snd_jack *jack, int status) 115static inline void snd_jack_report(struct snd_jack *jack, int status)
94{ 116{
95} 117}
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 8bb00a27e219..1e7f74acc2ec 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -418,7 +418,10 @@ struct snd_pcm_substream {
418 struct snd_info_entry *proc_status_entry; 418 struct snd_info_entry *proc_status_entry;
419 struct snd_info_entry *proc_prealloc_entry; 419 struct snd_info_entry *proc_prealloc_entry;
420 struct snd_info_entry *proc_prealloc_max_entry; 420 struct snd_info_entry *proc_prealloc_max_entry;
421#ifdef CONFIG_SND_PCM_XRUN_DEBUG
422 struct snd_info_entry *proc_xrun_injection_entry;
421#endif 423#endif
424#endif /* CONFIG_SND_VERBOSE_PROCFS */
422 /* misc flags */ 425 /* misc flags */
423 unsigned int hw_opened: 1; 426 unsigned int hw_opened: 1;
424}; 427};
@@ -505,6 +508,7 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
505int snd_pcm_start(struct snd_pcm_substream *substream); 508int snd_pcm_start(struct snd_pcm_substream *substream);
506int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status); 509int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
507int snd_pcm_drain_done(struct snd_pcm_substream *substream); 510int snd_pcm_drain_done(struct snd_pcm_substream *substream);
511int snd_pcm_stop_xrun(struct snd_pcm_substream *substream);
508#ifdef CONFIG_PM 512#ifdef CONFIG_PM
509int snd_pcm_suspend(struct snd_pcm_substream *substream); 513int snd_pcm_suspend(struct snd_pcm_substream *substream);
510int snd_pcm_suspend_all(struct snd_pcm *pcm); 514int snd_pcm_suspend_all(struct snd_pcm *pcm);
@@ -535,6 +539,12 @@ snd_pcm_debug_name(struct snd_pcm_substream *substream, char *buf, size_t size)
535 * PCM library 539 * PCM library
536 */ 540 */
537 541
542/**
543 * snd_pcm_stream_linked - Check whether the substream is linked with others
544 * @substream: substream to check
545 *
546 * Returns true if the given substream is being linked with others.
547 */
538static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream) 548static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
539{ 549{
540 return substream->group != &substream->self_group; 550 return substream->group != &substream->self_group;
@@ -545,6 +555,16 @@ void snd_pcm_stream_unlock(struct snd_pcm_substream *substream);
545void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream); 555void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream);
546void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream); 556void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream);
547unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream); 557unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream);
558
559/**
560 * snd_pcm_stream_lock_irqsave - Lock the PCM stream
561 * @substream: PCM substream
562 * @flags: irq flags
563 *
564 * This locks the PCM stream like snd_pcm_stream_lock() but with the local
565 * IRQ (only when nonatomic is false). In nonatomic case, this is identical
566 * as snd_pcm_stream_lock().
567 */
548#define snd_pcm_stream_lock_irqsave(substream, flags) \ 568#define snd_pcm_stream_lock_irqsave(substream, flags) \
549 do { \ 569 do { \
550 typecheck(unsigned long, flags); \ 570 typecheck(unsigned long, flags); \
@@ -553,9 +573,25 @@ unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream);
553void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream, 573void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
554 unsigned long flags); 574 unsigned long flags);
555 575
576/**
577 * snd_pcm_group_for_each_entry - iterate over the linked substreams
578 * @s: the iterator
579 * @substream: the substream
580 *
581 * Iterate over the all linked substreams to the given @substream.
582 * When @substream isn't linked with any others, this gives returns @substream
583 * itself once.
584 */
556#define snd_pcm_group_for_each_entry(s, substream) \ 585#define snd_pcm_group_for_each_entry(s, substream) \
557 list_for_each_entry(s, &substream->group->substreams, link_list) 586 list_for_each_entry(s, &substream->group->substreams, link_list)
558 587
588/**
589 * snd_pcm_running - Check whether the substream is in a running state
590 * @substream: substream to check
591 *
592 * Returns true if the given substream is in the state RUNNING, or in the
593 * state DRAINING for playback.
594 */
559static inline int snd_pcm_running(struct snd_pcm_substream *substream) 595static inline int snd_pcm_running(struct snd_pcm_substream *substream)
560{ 596{
561 return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING || 597 return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
@@ -563,45 +599,81 @@ static inline int snd_pcm_running(struct snd_pcm_substream *substream)
563 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)); 599 substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
564} 600}
565 601
602/**
603 * bytes_to_samples - Unit conversion of the size from bytes to samples
604 * @runtime: PCM runtime instance
605 * @size: size in bytes
606 */
566static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size) 607static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
567{ 608{
568 return size * 8 / runtime->sample_bits; 609 return size * 8 / runtime->sample_bits;
569} 610}
570 611
612/**
613 * bytes_to_frames - Unit conversion of the size from bytes to frames
614 * @runtime: PCM runtime instance
615 * @size: size in bytes
616 */
571static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size) 617static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
572{ 618{
573 return size * 8 / runtime->frame_bits; 619 return size * 8 / runtime->frame_bits;
574} 620}
575 621
622/**
623 * samples_to_bytes - Unit conversion of the size from samples to bytes
624 * @runtime: PCM runtime instance
625 * @size: size in samples
626 */
576static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size) 627static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
577{ 628{
578 return size * runtime->sample_bits / 8; 629 return size * runtime->sample_bits / 8;
579} 630}
580 631
632/**
633 * frames_to_bytes - Unit conversion of the size from frames to bytes
634 * @runtime: PCM runtime instance
635 * @size: size in frames
636 */
581static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size) 637static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
582{ 638{
583 return size * runtime->frame_bits / 8; 639 return size * runtime->frame_bits / 8;
584} 640}
585 641
642/**
643 * frame_aligned - Check whether the byte size is aligned to frames
644 * @runtime: PCM runtime instance
645 * @bytes: size in bytes
646 */
586static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes) 647static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
587{ 648{
588 return bytes % runtime->byte_align == 0; 649 return bytes % runtime->byte_align == 0;
589} 650}
590 651
652/**
653 * snd_pcm_lib_buffer_bytes - Get the buffer size of the current PCM in bytes
654 * @substream: PCM substream
655 */
591static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream) 656static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
592{ 657{
593 struct snd_pcm_runtime *runtime = substream->runtime; 658 struct snd_pcm_runtime *runtime = substream->runtime;
594 return frames_to_bytes(runtime, runtime->buffer_size); 659 return frames_to_bytes(runtime, runtime->buffer_size);
595} 660}
596 661
662/**
663 * snd_pcm_lib_period_bytes - Get the period size of the current PCM in bytes
664 * @substream: PCM substream
665 */
597static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream) 666static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
598{ 667{
599 struct snd_pcm_runtime *runtime = substream->runtime; 668 struct snd_pcm_runtime *runtime = substream->runtime;
600 return frames_to_bytes(runtime, runtime->period_size); 669 return frames_to_bytes(runtime, runtime->period_size);
601} 670}
602 671
603/* 672/**
604 * result is: 0 ... (boundary - 1) 673 * snd_pcm_playback_avail - Get the available (writable) space for playback
674 * @runtime: PCM runtime instance
675 *
676 * Result is between 0 ... (boundary - 1)
605 */ 677 */
606static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime) 678static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
607{ 679{
@@ -613,8 +685,11 @@ static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *r
613 return avail; 685 return avail;
614} 686}
615 687
616/* 688/**
617 * result is: 0 ... (boundary - 1) 689 * snd_pcm_playback_avail - Get the available (readable) space for capture
690 * @runtime: PCM runtime instance
691 *
692 * Result is between 0 ... (boundary - 1)
618 */ 693 */
619static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime) 694static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
620{ 695{
@@ -624,11 +699,19 @@ static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *ru
624 return avail; 699 return avail;
625} 700}
626 701
702/**
703 * snd_pcm_playback_hw_avail - Get the queued space for playback
704 * @runtime: PCM runtime instance
705 */
627static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime) 706static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
628{ 707{
629 return runtime->buffer_size - snd_pcm_playback_avail(runtime); 708 return runtime->buffer_size - snd_pcm_playback_avail(runtime);
630} 709}
631 710
711/**
712 * snd_pcm_capture_hw_avail - Get the free space for capture
713 * @runtime: PCM runtime instance
714 */
632static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime) 715static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
633{ 716{
634 return runtime->buffer_size - snd_pcm_capture_avail(runtime); 717 return runtime->buffer_size - snd_pcm_capture_avail(runtime);
@@ -708,6 +791,20 @@ static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
708 return snd_pcm_capture_avail(runtime) == 0; 791 return snd_pcm_capture_avail(runtime) == 0;
709} 792}
710 793
794/**
795 * snd_pcm_trigger_done - Mark the master substream
796 * @substream: the pcm substream instance
797 * @master: the linked master substream
798 *
799 * When multiple substreams of the same card are linked and the hardware
800 * supports the single-shot operation, the driver calls this in the loop
801 * in snd_pcm_group_for_each_entry() for marking the substream as "done".
802 * Then most of trigger operations are performed only to the given master
803 * substream.
804 *
805 * The trigger_master mark is cleared at timestamp updates at the end
806 * of trigger operations.
807 */
711static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream, 808static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
712 struct snd_pcm_substream *master) 809 struct snd_pcm_substream *master)
713{ 810{
@@ -750,18 +847,59 @@ static inline const struct snd_interval *hw_param_interval_c(const struct snd_pc
750 return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]; 847 return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
751} 848}
752 849
753#define params_channels(p) \ 850/**
754 (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_CHANNELS)->min) 851 * params_channels - Get the number of channels from the hw params
755#define params_rate(p) \ 852 * @p: hw params
756 (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_RATE)->min) 853 */
757#define params_period_size(p) \ 854static inline unsigned int params_channels(const struct snd_pcm_hw_params *p)
758 (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min) 855{
759#define params_periods(p) \ 856 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_CHANNELS)->min;
760 (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_PERIODS)->min) 857}
761#define params_buffer_size(p) \ 858
762 (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min) 859/**
763#define params_buffer_bytes(p) \ 860 * params_channels - Get the sample rate from the hw params
764 (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min) 861 * @p: hw params
862 */
863static inline unsigned int params_rate(const struct snd_pcm_hw_params *p)
864{
865 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_RATE)->min;
866}
867
868/**
869 * params_channels - Get the period size (in frames) from the hw params
870 * @p: hw params
871 */
872static inline unsigned int params_period_size(const struct snd_pcm_hw_params *p)
873{
874 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min;
875}
876
877/**
878 * params_channels - Get the number of periods from the hw params
879 * @p: hw params
880 */
881static inline unsigned int params_periods(const struct snd_pcm_hw_params *p)
882{
883 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIODS)->min;
884}
885
886/**
887 * params_channels - Get the buffer size (in frames) from the hw params
888 * @p: hw params
889 */
890static inline unsigned int params_buffer_size(const struct snd_pcm_hw_params *p)
891{
892 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min;
893}
894
895/**
896 * params_channels - Get the buffer size (in bytes) from the hw params
897 * @p: hw params
898 */
899static inline unsigned int params_buffer_bytes(const struct snd_pcm_hw_params *p)
900{
901 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min;
902}
765 903
766int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v); 904int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
767void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c); 905void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
@@ -883,6 +1021,14 @@ unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
883unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a, 1021unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
884 unsigned int rates_b); 1022 unsigned int rates_b);
885 1023
1024/**
1025 * snd_pcm_set_runtime_buffer - Set the PCM runtime buffer
1026 * @substream: PCM substream to set
1027 * @bufp: the buffer information, NULL to clear
1028 *
1029 * Copy the buffer information to runtime->dma_buffer when @bufp is non-NULL.
1030 * Otherwise it clears the current buffer information.
1031 */
886static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream, 1032static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
887 struct snd_dma_buffer *bufp) 1033 struct snd_dma_buffer *bufp)
888{ 1034{
@@ -908,6 +1054,11 @@ void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream);
908void snd_pcm_timer_init(struct snd_pcm_substream *substream); 1054void snd_pcm_timer_init(struct snd_pcm_substream *substream);
909void snd_pcm_timer_done(struct snd_pcm_substream *substream); 1055void snd_pcm_timer_done(struct snd_pcm_substream *substream);
910 1056
1057/**
1058 * snd_pcm_gettime - Fill the timespec depending on the timestamp mode
1059 * @runtime: PCM runtime instance
1060 * @tv: timespec to fill
1061 */
911static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime, 1062static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
912 struct timespec *tv) 1063 struct timespec *tv)
913{ 1064{
@@ -944,7 +1095,6 @@ int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
944int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream); 1095int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream);
945struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream, 1096struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
946 unsigned long offset); 1097 unsigned long offset);
947#if 0 /* for kernel-doc */
948/** 1098/**
949 * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer 1099 * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer
950 * @substream: the substream to allocate the buffer to 1100 * @substream: the substream to allocate the buffer to
@@ -957,8 +1107,13 @@ struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
957 * Return: 1 if the buffer was changed, 0 if not changed, or a negative error 1107 * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
958 * code. 1108 * code.
959 */ 1109 */
960static int snd_pcm_lib_alloc_vmalloc_buffer 1110static inline int snd_pcm_lib_alloc_vmalloc_buffer
961 (struct snd_pcm_substream *substream, size_t size); 1111 (struct snd_pcm_substream *substream, size_t size)
1112{
1113 return _snd_pcm_lib_alloc_vmalloc_buffer(substream, size,
1114 GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
1115}
1116
962/** 1117/**
963 * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer 1118 * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer
964 * @substream: the substream to allocate the buffer to 1119 * @substream: the substream to allocate the buffer to
@@ -970,15 +1125,12 @@ static int snd_pcm_lib_alloc_vmalloc_buffer
970 * Return: 1 if the buffer was changed, 0 if not changed, or a negative error 1125 * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
971 * code. 1126 * code.
972 */ 1127 */
973static int snd_pcm_lib_alloc_vmalloc_32_buffer 1128static inline int snd_pcm_lib_alloc_vmalloc_32_buffer
974 (struct snd_pcm_substream *substream, size_t size); 1129 (struct snd_pcm_substream *substream, size_t size)
975#endif 1130{
976#define snd_pcm_lib_alloc_vmalloc_buffer(subs, size) \ 1131 return _snd_pcm_lib_alloc_vmalloc_buffer(substream, size,
977 _snd_pcm_lib_alloc_vmalloc_buffer \ 1132 GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
978 (subs, size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO) 1133}
979#define snd_pcm_lib_alloc_vmalloc_32_buffer(subs, size) \
980 _snd_pcm_lib_alloc_vmalloc_buffer \
981 (subs, size, GFP_KERNEL | GFP_DMA32 | __GFP_ZERO)
982 1134
983#define snd_pcm_get_dma_buf(substream) ((substream)->runtime->dma_buffer_p) 1135#define snd_pcm_get_dma_buf(substream) ((substream)->runtime->dma_buffer_p)
984 1136
@@ -998,18 +1150,35 @@ struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
998#define snd_pcm_sgbuf_ops_page NULL 1150#define snd_pcm_sgbuf_ops_page NULL
999#endif /* SND_DMA_SGBUF */ 1151#endif /* SND_DMA_SGBUF */
1000 1152
1153/**
1154 * snd_pcm_sgbuf_get_addr - Get the DMA address at the corresponding offset
1155 * @substream: PCM substream
1156 * @ofs: byte offset
1157 */
1001static inline dma_addr_t 1158static inline dma_addr_t
1002snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs) 1159snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
1003{ 1160{
1004 return snd_sgbuf_get_addr(snd_pcm_get_dma_buf(substream), ofs); 1161 return snd_sgbuf_get_addr(snd_pcm_get_dma_buf(substream), ofs);
1005} 1162}
1006 1163
1164/**
1165 * snd_pcm_sgbuf_get_ptr - Get the virtual address at the corresponding offset
1166 * @substream: PCM substream
1167 * @ofs: byte offset
1168 */
1007static inline void * 1169static inline void *
1008snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs) 1170snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
1009{ 1171{
1010 return snd_sgbuf_get_ptr(snd_pcm_get_dma_buf(substream), ofs); 1172 return snd_sgbuf_get_ptr(snd_pcm_get_dma_buf(substream), ofs);
1011} 1173}
1012 1174
1175/**
1176 * snd_pcm_sgbuf_chunk_size - Compute the max size that fits within the contig.
1177 * page from the given size
1178 * @substream: PCM substream
1179 * @ofs: byte offset
1180 * @size: byte size to examine
1181 */
1013static inline unsigned int 1182static inline unsigned int
1014snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream, 1183snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
1015 unsigned int ofs, unsigned int size) 1184 unsigned int ofs, unsigned int size)
@@ -1017,13 +1186,24 @@ snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
1017 return snd_sgbuf_get_chunk_size(snd_pcm_get_dma_buf(substream), ofs, size); 1186 return snd_sgbuf_get_chunk_size(snd_pcm_get_dma_buf(substream), ofs, size);
1018} 1187}
1019 1188
1020/* handle mmap counter - PCM mmap callback should handle this counter properly */ 1189/**
1190 * snd_pcm_mmap_data_open - increase the mmap counter
1191 * @area: VMA
1192 *
1193 * PCM mmap callback should handle this counter properly
1194 */
1021static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area) 1195static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
1022{ 1196{
1023 struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data; 1197 struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
1024 atomic_inc(&substream->mmap_count); 1198 atomic_inc(&substream->mmap_count);
1025} 1199}
1026 1200
1201/**
1202 * snd_pcm_mmap_data_close - decrease the mmap counter
1203 * @area: VMA
1204 *
1205 * PCM mmap callback should handle this counter properly
1206 */
1027static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area) 1207static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
1028{ 1208{
1029 struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data; 1209 struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
@@ -1043,6 +1223,11 @@ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_s
1043 1223
1044#define snd_pcm_lib_mmap_vmalloc NULL 1224#define snd_pcm_lib_mmap_vmalloc NULL
1045 1225
1226/**
1227 * snd_pcm_limit_isa_dma_size - Get the max size fitting with ISA DMA transfer
1228 * @dma: DMA number
1229 * @max: pointer to store the max size
1230 */
1046static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max) 1231static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
1047{ 1232{
1048 *max = dma < 4 ? 64 * 1024 : 128 * 1024; 1233 *max = dma < 4 ? 64 * 1024 : 128 * 1024;
@@ -1095,7 +1280,11 @@ struct snd_pcm_chmap {
1095 void *private_data; /* optional: private data pointer */ 1280 void *private_data; /* optional: private data pointer */
1096}; 1281};
1097 1282
1098/* get the PCM substream assigned to the given chmap info */ 1283/**
1284 * snd_pcm_chmap_substream - get the PCM substream assigned to the given chmap info
1285 * @info: chmap information
1286 * @idx: the substream number index
1287 */
1099static inline struct snd_pcm_substream * 1288static inline struct snd_pcm_substream *
1100snd_pcm_chmap_substream(struct snd_pcm_chmap *info, unsigned int idx) 1289snd_pcm_chmap_substream(struct snd_pcm_chmap *info, unsigned int idx)
1101{ 1290{
@@ -1122,7 +1311,10 @@ int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
1122 unsigned long private_value, 1311 unsigned long private_value,
1123 struct snd_pcm_chmap **info_ret); 1312 struct snd_pcm_chmap **info_ret);
1124 1313
1125/* Strong-typed conversion of pcm_format to bitwise */ 1314/**
1315 * pcm_format_to_bits - Strong-typed conversion of pcm_format to bitwise
1316 * @pcm_format: PCM format
1317 */
1126static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format) 1318static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
1127{ 1319{
1128 return 1ULL << (__force int) pcm_format; 1320 return 1ULL << (__force int) pcm_format;
diff --git a/include/sound/rcar_snd.h b/include/sound/rcar_snd.h
index d76412b84b48..83284cae464c 100644
--- a/include/sound/rcar_snd.h
+++ b/include/sound/rcar_snd.h
@@ -36,14 +36,14 @@
36#define RSND_SSI_CLK_PIN_SHARE (1 << 31) 36#define RSND_SSI_CLK_PIN_SHARE (1 << 31)
37#define RSND_SSI_NO_BUSIF (1 << 30) /* SSI+DMA without BUSIF */ 37#define RSND_SSI_NO_BUSIF (1 << 30) /* SSI+DMA without BUSIF */
38 38
39#define RSND_SSI(_dma_id, _pio_irq, _flags) \ 39#define RSND_SSI(_dma_id, _irq, _flags) \
40{ .dma_id = _dma_id, .pio_irq = _pio_irq, .flags = _flags } 40{ .dma_id = _dma_id, .irq = _irq, .flags = _flags }
41#define RSND_SSI_UNUSED \ 41#define RSND_SSI_UNUSED \
42{ .dma_id = -1, .pio_irq = -1, .flags = 0 } 42{ .dma_id = -1, .irq = -1, .flags = 0 }
43 43
44struct rsnd_ssi_platform_info { 44struct rsnd_ssi_platform_info {
45 int dma_id; 45 int dma_id;
46 int pio_irq; 46 int irq;
47 u32 flags; 47 u32 flags;
48}; 48};
49 49
diff --git a/include/sound/rt5645.h b/include/sound/rt5645.h
index a5352712194b..120d9610054e 100644
--- a/include/sound/rt5645.h
+++ b/include/sound/rt5645.h
@@ -23,6 +23,10 @@ struct rt5645_platform_data {
23 23
24 unsigned int hp_det_gpio; 24 unsigned int hp_det_gpio;
25 bool gpio_hp_det_active_high; 25 bool gpio_hp_det_active_high;
26
27 /* true if codec's jd function is used */
28 bool en_jd_func;
29 unsigned int jd_mode;
26}; 30};
27 31
28#endif 32#endif
diff --git a/include/sound/rt5677.h b/include/sound/rt5677.h
index 082670e3a353..d9eb7d861cd0 100644
--- a/include/sound/rt5677.h
+++ b/include/sound/rt5677.h
@@ -27,6 +27,16 @@ struct rt5677_platform_data {
27 bool lout3_diff; 27 bool lout3_diff;
28 /* DMIC2 clock source selection */ 28 /* DMIC2 clock source selection */
29 enum rt5677_dmic2_clk dmic2_clk_pin; 29 enum rt5677_dmic2_clk dmic2_clk_pin;
30
31 /* configures GPIO, 0 - floating, 1 - pulldown, 2 - pullup */
32 u8 gpio_config[6];
33
34 /* jd1 can select 0 ~ 3 as OFF, GPIO1, GPIO2 and GPIO3 respectively */
35 unsigned int jd1_gpio;
36 /* jd2 and jd3 can select 0 ~ 3 as
37 OFF, GPIO4, GPIO5 and GPIO6 respectively */
38 unsigned int jd2_gpio;
39 unsigned int jd3_gpio;
30}; 40};
31 41
32#endif 42#endif
diff --git a/include/sound/seq_kernel.h b/include/sound/seq_kernel.h
index 2398521f0998..eea5400fe373 100644
--- a/include/sound/seq_kernel.h
+++ b/include/sound/seq_kernel.h
@@ -108,9 +108,13 @@ int snd_seq_event_port_detach(int client, int port);
108#ifdef CONFIG_MODULES 108#ifdef CONFIG_MODULES
109void snd_seq_autoload_lock(void); 109void snd_seq_autoload_lock(void);
110void snd_seq_autoload_unlock(void); 110void snd_seq_autoload_unlock(void);
111void snd_seq_autoload_init(void);
112#define snd_seq_autoload_exit() snd_seq_autoload_lock()
111#else 113#else
112#define snd_seq_autoload_lock() 114#define snd_seq_autoload_lock()
113#define snd_seq_autoload_unlock() 115#define snd_seq_autoload_unlock()
116#define snd_seq_autoload_init()
117#define snd_seq_autoload_exit()
114#endif 118#endif
115 119
116#endif /* __SOUND_SEQ_KERNEL_H */ 120#endif /* __SOUND_SEQ_KERNEL_H */
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index e8b3080d196a..2df96b1384c7 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -206,7 +206,6 @@ struct snd_soc_dai_driver {
206 /* DAI description */ 206 /* DAI description */
207 const char *name; 207 const char *name;
208 unsigned int id; 208 unsigned int id;
209 int ac97_control;
210 unsigned int base; 209 unsigned int base;
211 210
212 /* DAI driver callbacks */ 211 /* DAI driver callbacks */
@@ -216,6 +215,8 @@ struct snd_soc_dai_driver {
216 int (*resume)(struct snd_soc_dai *dai); 215 int (*resume)(struct snd_soc_dai *dai);
217 /* compress dai */ 216 /* compress dai */
218 bool compress_dai; 217 bool compress_dai;
218 /* DAI is also used for the control bus */
219 bool bus_control;
219 220
220 /* ops */ 221 /* ops */
221 const struct snd_soc_dai_ops *ops; 222 const struct snd_soc_dai_ops *ops;
@@ -241,7 +242,6 @@ struct snd_soc_dai {
241 const char *name; 242 const char *name;
242 int id; 243 int id;
243 struct device *dev; 244 struct device *dev;
244 void *ac97_pdata; /* platform_data for the ac97 codec */
245 245
246 /* driver ops */ 246 /* driver ops */
247 struct snd_soc_dai_driver *driver; 247 struct snd_soc_dai_driver *driver;
@@ -268,7 +268,6 @@ struct snd_soc_dai {
268 unsigned int sample_bits; 268 unsigned int sample_bits;
269 269
270 /* parent platform/codec */ 270 /* parent platform/codec */
271 struct snd_soc_platform *platform;
272 struct snd_soc_codec *codec; 271 struct snd_soc_codec *codec;
273 struct snd_soc_component *component; 272 struct snd_soc_component *component;
274 273
@@ -276,8 +275,6 @@ struct snd_soc_dai {
276 unsigned int tx_mask; 275 unsigned int tx_mask;
277 unsigned int rx_mask; 276 unsigned int rx_mask;
278 277
279 struct snd_soc_card *card;
280
281 struct list_head list; 278 struct list_head list;
282}; 279};
283 280
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 3a4d7da67b8d..89823cfe6f04 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -435,7 +435,7 @@ void snd_soc_dapm_auto_nc_pins(struct snd_soc_card *card);
435unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol); 435unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol);
436 436
437/* Mostly internal - should not normally be used */ 437/* Mostly internal - should not normally be used */
438void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm); 438void dapm_mark_endpoints_dirty(struct snd_soc_card *card);
439 439
440/* dapm path query */ 440/* dapm path query */
441int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, 441int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
@@ -508,9 +508,9 @@ struct snd_soc_dapm_path {
508 508
509 /* status */ 509 /* status */
510 u32 connect:1; /* source and sink widgets are connected */ 510 u32 connect:1; /* source and sink widgets are connected */
511 u32 walked:1; /* path has been walked */
512 u32 walking:1; /* path is in the process of being walked */ 511 u32 walking:1; /* path is in the process of being walked */
513 u32 weak:1; /* path ignored for power management */ 512 u32 weak:1; /* path ignored for power management */
513 u32 is_supply:1; /* At least one of the connected widgets is a supply */
514 514
515 int (*connected)(struct snd_soc_dapm_widget *source, 515 int (*connected)(struct snd_soc_dapm_widget *source,
516 struct snd_soc_dapm_widget *sink); 516 struct snd_soc_dapm_widget *sink);
@@ -544,11 +544,13 @@ struct snd_soc_dapm_widget {
544 unsigned char active:1; /* active stream on DAC, ADC's */ 544 unsigned char active:1; /* active stream on DAC, ADC's */
545 unsigned char connected:1; /* connected codec pin */ 545 unsigned char connected:1; /* connected codec pin */
546 unsigned char new:1; /* cnew complete */ 546 unsigned char new:1; /* cnew complete */
547 unsigned char ext:1; /* has external widgets */
548 unsigned char force:1; /* force state */ 547 unsigned char force:1; /* force state */
549 unsigned char ignore_suspend:1; /* kept enabled over suspend */ 548 unsigned char ignore_suspend:1; /* kept enabled over suspend */
550 unsigned char new_power:1; /* power from this run */ 549 unsigned char new_power:1; /* power from this run */
551 unsigned char power_checked:1; /* power checked this run */ 550 unsigned char power_checked:1; /* power checked this run */
551 unsigned char is_supply:1; /* Widget is a supply type widget */
552 unsigned char is_sink:1; /* Widget is a sink type widget */
553 unsigned char is_source:1; /* Widget is a source type widget */
552 int subseq; /* sort within widget type */ 554 int subseq; /* sort within widget type */
553 555
554 int (*power_check)(struct snd_soc_dapm_widget *w); 556 int (*power_check)(struct snd_soc_dapm_widget *w);
@@ -567,6 +569,7 @@ struct snd_soc_dapm_widget {
567 struct list_head sinks; 569 struct list_head sinks;
568 570
569 /* used during DAPM updates */ 571 /* used during DAPM updates */
572 struct list_head work_list;
570 struct list_head power_list; 573 struct list_head power_list;
571 struct list_head dirty; 574 struct list_head dirty;
572 int inputs; 575 int inputs;
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 7ba7130037a0..b4fca9aed2a2 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -36,6 +36,11 @@
36 {.reg = xreg, .rreg = xreg, .shift = shift_left, \ 36 {.reg = xreg, .rreg = xreg, .shift = shift_left, \
37 .rshift = shift_right, .max = xmax, .platform_max = xmax, \ 37 .rshift = shift_right, .max = xmax, .platform_max = xmax, \
38 .invert = xinvert, .autodisable = xautodisable}) 38 .invert = xinvert, .autodisable = xautodisable})
39#define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, xinvert, xautodisable) \
40 ((unsigned long)&(struct soc_mixer_control) \
41 {.reg = xreg, .rreg = xreg, .shift = shift_left, \
42 .rshift = shift_right, .min = xmin, .max = xmax, .platform_max = xmax, \
43 .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable})
39#define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \ 44#define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \
40 SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable) 45 SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable)
41#define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \ 46#define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
@@ -171,11 +176,9 @@
171 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 176 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
172 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 177 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
173 .tlv.p = (tlv_array), \ 178 .tlv.p = (tlv_array), \
174 .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \ 179 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
175 .put = snd_soc_put_volsw_s8, \ 180 .put = snd_soc_put_volsw, \
176 .private_value = (unsigned long)&(struct soc_mixer_control) \ 181 .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) }
177 {.reg = xreg, .min = xmin, .max = xmax, \
178 .platform_max = xmax} }
179#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \ 182#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
180{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 183{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
181 .items = xitems, .texts = xtexts, \ 184 .items = xitems, .texts = xtexts, \
@@ -366,8 +369,6 @@ struct snd_soc_jack_gpio;
366 369
367typedef int (*hw_write_t)(void *,const char* ,int); 370typedef int (*hw_write_t)(void *,const char* ,int);
368 371
369extern struct snd_ac97_bus_ops *soc_ac97_ops;
370
371enum snd_soc_pcm_subclass { 372enum snd_soc_pcm_subclass {
372 SND_SOC_PCM_CLASS_PCM = 0, 373 SND_SOC_PCM_CLASS_PCM = 0,
373 SND_SOC_PCM_CLASS_BE = 1, 374 SND_SOC_PCM_CLASS_BE = 1,
@@ -409,13 +410,9 @@ int devm_snd_soc_register_component(struct device *dev,
409 const struct snd_soc_component_driver *cmpnt_drv, 410 const struct snd_soc_component_driver *cmpnt_drv,
410 struct snd_soc_dai_driver *dai_drv, int num_dai); 411 struct snd_soc_dai_driver *dai_drv, int num_dai);
411void snd_soc_unregister_component(struct device *dev); 412void snd_soc_unregister_component(struct device *dev);
412int snd_soc_cache_sync(struct snd_soc_codec *codec);
413int snd_soc_cache_init(struct snd_soc_codec *codec); 413int snd_soc_cache_init(struct snd_soc_codec *codec);
414int snd_soc_cache_exit(struct snd_soc_codec *codec); 414int snd_soc_cache_exit(struct snd_soc_codec *codec);
415int snd_soc_cache_write(struct snd_soc_codec *codec, 415
416 unsigned int reg, unsigned int value);
417int snd_soc_cache_read(struct snd_soc_codec *codec,
418 unsigned int reg, unsigned int *value);
419int snd_soc_platform_read(struct snd_soc_platform *platform, 416int snd_soc_platform_read(struct snd_soc_platform *platform,
420 unsigned int reg); 417 unsigned int reg);
421int snd_soc_platform_write(struct snd_soc_platform *platform, 418int snd_soc_platform_write(struct snd_soc_platform *platform,
@@ -500,14 +497,28 @@ int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
500int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned int reg, 497int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned int reg,
501 unsigned int mask, unsigned int value); 498 unsigned int mask, unsigned int value);
502 499
503int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, 500#ifdef CONFIG_SND_SOC_AC97_BUS
504 struct snd_ac97_bus_ops *ops, int num); 501struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec);
505void snd_soc_free_ac97_codec(struct snd_soc_codec *codec); 502void snd_soc_free_ac97_codec(struct snd_ac97 *ac97);
506 503
507int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops); 504int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
508int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops, 505int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
509 struct platform_device *pdev); 506 struct platform_device *pdev);
510 507
508extern struct snd_ac97_bus_ops *soc_ac97_ops;
509#else
510static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
511 struct platform_device *pdev)
512{
513 return 0;
514}
515
516static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
517{
518 return 0;
519}
520#endif
521
511/* 522/*
512 *Controls 523 *Controls
513 */ 524 */
@@ -545,12 +556,6 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
545 struct snd_ctl_elem_value *ucontrol); 556 struct snd_ctl_elem_value *ucontrol);
546int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, 557int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol); 558 struct snd_ctl_elem_value *ucontrol);
548int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
549 struct snd_ctl_elem_info *uinfo);
550int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
551 struct snd_ctl_elem_value *ucontrol);
552int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
553 struct snd_ctl_elem_value *ucontrol);
554int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, 559int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
555 struct snd_ctl_elem_info *uinfo); 560 struct snd_ctl_elem_info *uinfo);
556int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, 561int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
@@ -780,24 +785,18 @@ struct snd_soc_codec {
780 struct device *dev; 785 struct device *dev;
781 const struct snd_soc_codec_driver *driver; 786 const struct snd_soc_codec_driver *driver;
782 787
783 struct mutex mutex;
784 struct list_head list; 788 struct list_head list;
785 struct list_head card_list; 789 struct list_head card_list;
786 790
787 /* runtime */ 791 /* runtime */
788 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
789 unsigned int cache_bypass:1; /* Suppress access to the cache */ 792 unsigned int cache_bypass:1; /* Suppress access to the cache */
790 unsigned int suspended:1; /* Codec is in suspend PM state */ 793 unsigned int suspended:1; /* Codec is in suspend PM state */
791 unsigned int ac97_registered:1; /* Codec has been AC97 registered */
792 unsigned int ac97_created:1; /* Codec has been created by SoC */
793 unsigned int cache_init:1; /* codec cache has been initialized */ 794 unsigned int cache_init:1; /* codec cache has been initialized */
794 u32 cache_sync; /* Cache needs to be synced to hardware */
795 795
796 /* codec IO */ 796 /* codec IO */
797 void *control_data; /* codec control (i2c/3wire) data */ 797 void *control_data; /* codec control (i2c/3wire) data */
798 hw_write_t hw_write; 798 hw_write_t hw_write;
799 void *reg_cache; 799 void *reg_cache;
800 struct mutex cache_rw_mutex;
801 800
802 /* component */ 801 /* component */
803 struct snd_soc_component component; 802 struct snd_soc_component component;
@@ -860,8 +859,6 @@ struct snd_soc_platform_driver {
860 859
861 int (*probe)(struct snd_soc_platform *); 860 int (*probe)(struct snd_soc_platform *);
862 int (*remove)(struct snd_soc_platform *); 861 int (*remove)(struct snd_soc_platform *);
863 int (*suspend)(struct snd_soc_dai *dai);
864 int (*resume)(struct snd_soc_dai *dai);
865 struct snd_soc_component_driver component_driver; 862 struct snd_soc_component_driver component_driver;
866 863
867 /* pcm creation and destruction */ 864 /* pcm creation and destruction */
@@ -886,7 +883,7 @@ struct snd_soc_platform_driver {
886 883
887struct snd_soc_dai_link_component { 884struct snd_soc_dai_link_component {
888 const char *name; 885 const char *name;
889 const struct device_node *of_node; 886 struct device_node *of_node;
890 const char *dai_name; 887 const char *dai_name;
891}; 888};
892 889
@@ -894,8 +891,6 @@ struct snd_soc_platform {
894 struct device *dev; 891 struct device *dev;
895 const struct snd_soc_platform_driver *driver; 892 const struct snd_soc_platform_driver *driver;
896 893
897 unsigned int suspended:1; /* platform is suspended */
898
899 struct list_head list; 894 struct list_head list;
900 895
901 struct snd_soc_component component; 896 struct snd_soc_component component;
@@ -990,7 +985,7 @@ struct snd_soc_codec_conf {
990 * DT/OF node, but not both. 985 * DT/OF node, but not both.
991 */ 986 */
992 const char *dev_name; 987 const char *dev_name;
993 const struct device_node *of_node; 988 struct device_node *of_node;
994 989
995 /* 990 /*
996 * optional map of kcontrol, widget and path name prefixes that are 991 * optional map of kcontrol, widget and path name prefixes that are
@@ -1007,7 +1002,7 @@ struct snd_soc_aux_dev {
1007 * DT/OF node, but not both. 1002 * DT/OF node, but not both.
1008 */ 1003 */
1009 const char *codec_name; 1004 const char *codec_name;
1010 const struct device_node *codec_of_node; 1005 struct device_node *codec_of_node;
1011 1006
1012 /* codec/machine specific init - e.g. add machine controls */ 1007 /* codec/machine specific init - e.g. add machine controls */
1013 int (*init)(struct snd_soc_component *component); 1008 int (*init)(struct snd_soc_component *component);
@@ -1264,6 +1259,17 @@ unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
1264int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg, 1259int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg,
1265 unsigned int val); 1260 unsigned int val);
1266 1261
1262/**
1263 * snd_soc_cache_sync() - Sync the register cache with the hardware
1264 * @codec: CODEC to sync
1265 *
1266 * Note: This function will call regcache_sync()
1267 */
1268static inline int snd_soc_cache_sync(struct snd_soc_codec *codec)
1269{
1270 return regcache_sync(codec->component.regmap);
1271}
1272
1267/* component IO */ 1273/* component IO */
1268int snd_soc_component_read(struct snd_soc_component *component, 1274int snd_soc_component_read(struct snd_soc_component *component,
1269 unsigned int reg, unsigned int *val); 1275 unsigned int reg, unsigned int *val);
@@ -1277,6 +1283,45 @@ void snd_soc_component_async_complete(struct snd_soc_component *component);
1277int snd_soc_component_test_bits(struct snd_soc_component *component, 1283int snd_soc_component_test_bits(struct snd_soc_component *component,
1278 unsigned int reg, unsigned int mask, unsigned int value); 1284 unsigned int reg, unsigned int mask, unsigned int value);
1279 1285
1286#ifdef CONFIG_REGMAP
1287
1288void snd_soc_component_init_regmap(struct snd_soc_component *component,
1289 struct regmap *regmap);
1290void snd_soc_component_exit_regmap(struct snd_soc_component *component);
1291
1292/**
1293 * snd_soc_codec_init_regmap() - Initialize regmap instance for the CODEC
1294 * @codec: The CODEC for which to initialize the regmap instance
1295 * @regmap: The regmap instance that should be used by the CODEC
1296 *
1297 * This function allows deferred assignment of the regmap instance that is
1298 * associated with the CODEC. Only use this if the regmap instance is not yet
1299 * ready when the CODEC is registered. The function must also be called before
1300 * the first IO attempt of the CODEC.
1301 */
1302static inline void snd_soc_codec_init_regmap(struct snd_soc_codec *codec,
1303 struct regmap *regmap)
1304{
1305 snd_soc_component_init_regmap(&codec->component, regmap);
1306}
1307
1308/**
1309 * snd_soc_codec_exit_regmap() - De-initialize regmap instance for the CODEC
1310 * @codec: The CODEC for which to de-initialize the regmap instance
1311 *
1312 * Calls regmap_exit() on the regmap instance associated to the CODEC and
1313 * removes the regmap instance from the CODEC.
1314 *
1315 * This function should only be used if snd_soc_codec_init_regmap() was used to
1316 * initialize the regmap instance.
1317 */
1318static inline void snd_soc_codec_exit_regmap(struct snd_soc_codec *codec)
1319{
1320 snd_soc_component_exit_regmap(&codec->component);
1321}
1322
1323#endif
1324
1280/* device driver data */ 1325/* device driver data */
1281 1326
1282static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card, 1327static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
@@ -1451,6 +1496,9 @@ unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
1451 struct device_node **framemaster); 1496 struct device_node **framemaster);
1452int snd_soc_of_get_dai_name(struct device_node *of_node, 1497int snd_soc_of_get_dai_name(struct device_node *of_node,
1453 const char **dai_name); 1498 const char **dai_name);
1499int snd_soc_of_get_dai_link_codecs(struct device *dev,
1500 struct device_node *of_node,
1501 struct snd_soc_dai_link *dai_link);
1454 1502
1455#include <sound/soc-dai.h> 1503#include <sound/soc-dai.h>
1456 1504
diff --git a/include/sound/uda134x.h b/include/sound/uda134x.h
index e475659bd3be..509efb050176 100644
--- a/include/sound/uda134x.h
+++ b/include/sound/uda134x.h
@@ -18,18 +18,6 @@ struct uda134x_platform_data {
18 struct l3_pins l3; 18 struct l3_pins l3;
19 void (*power) (int); 19 void (*power) (int);
20 int model; 20 int model;
21 /*
22 ALSA SOC usually puts the device in standby mode when it's not used
23 for sometime. If you unset is_powered_on_standby the driver will
24 turn off the ADC/DAC when this callback is invoked and turn it back
25 on when needed. Unfortunately this will result in a very light bump
26 (it can be audible only with good earphones). If this bothers you
27 set is_powered_on_standby, you will have slightly higher power
28 consumption. Please note that sending the L3 command for ADC is
29 enough to make the bump, so it doesn't make difference if you
30 completely take off power from the codec.
31 */
32 int is_powered_on_standby;
33#define UDA134X_UDA1340 1 21#define UDA134X_UDA1340 1
34#define UDA134X_UDA1341 2 22#define UDA134X_UDA1341 2
35#define UDA134X_UDA1344 3 23#define UDA134X_UDA1344 3
diff --git a/include/trace/events/asoc.h b/include/trace/events/asoc.h
index b04ee7e5a466..88cf39d96d0f 100644
--- a/include/trace/events/asoc.h
+++ b/include/trace/events/asoc.h
@@ -288,31 +288,6 @@ TRACE_EVENT(snd_soc_jack_notify,
288 TP_printk("jack=%s %x", __get_str(name), (int)__entry->val) 288 TP_printk("jack=%s %x", __get_str(name), (int)__entry->val)
289); 289);
290 290
291TRACE_EVENT(snd_soc_cache_sync,
292
293 TP_PROTO(struct snd_soc_codec *codec, const char *type,
294 const char *status),
295
296 TP_ARGS(codec, type, status),
297
298 TP_STRUCT__entry(
299 __string( name, codec->component.name)
300 __string( status, status )
301 __string( type, type )
302 __field( int, id )
303 ),
304
305 TP_fast_assign(
306 __assign_str(name, codec->component.name);
307 __assign_str(status, status);
308 __assign_str(type, type);
309 __entry->id = codec->component.id;
310 ),
311
312 TP_printk("codec=%s.%d type=%s status=%s", __get_str(name),
313 (int)__entry->id, __get_str(type), __get_str(status))
314);
315
316#endif /* _TRACE_ASOC_H */ 291#endif /* _TRACE_ASOC_H */
317 292
318/* This part must be outside protection */ 293/* This part must be outside protection */
diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index 941d32f007dc..1f23cd635957 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -96,9 +96,10 @@ enum {
96 SNDRV_HWDEP_IFACE_FW_DICE, /* TC DICE FireWire device */ 96 SNDRV_HWDEP_IFACE_FW_DICE, /* TC DICE FireWire device */
97 SNDRV_HWDEP_IFACE_FW_FIREWORKS, /* Echo Audio Fireworks based device */ 97 SNDRV_HWDEP_IFACE_FW_FIREWORKS, /* Echo Audio Fireworks based device */
98 SNDRV_HWDEP_IFACE_FW_BEBOB, /* BridgeCo BeBoB based device */ 98 SNDRV_HWDEP_IFACE_FW_BEBOB, /* BridgeCo BeBoB based device */
99 SNDRV_HWDEP_IFACE_FW_OXFW, /* Oxford OXFW970/971 based device */
99 100
100 /* Don't forget to change the following: */ 101 /* Don't forget to change the following: */
101 SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_BEBOB 102 SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_OXFW
102}; 103};
103 104
104struct snd_hwdep_info { 105struct snd_hwdep_info {
diff --git a/include/uapi/sound/compress_offload.h b/include/uapi/sound/compress_offload.h
index 1964026b5e09..22ed8cb7800b 100644
--- a/include/uapi/sound/compress_offload.h
+++ b/include/uapi/sound/compress_offload.h
@@ -32,7 +32,7 @@
32 32
33#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 2) 33#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 2)
34/** 34/**
35 * struct snd_compressed_buffer: compressed buffer 35 * struct snd_compressed_buffer - compressed buffer
36 * @fragment_size: size of buffer fragment in bytes 36 * @fragment_size: size of buffer fragment in bytes
37 * @fragments: number of such fragments 37 * @fragments: number of such fragments
38 */ 38 */
@@ -42,7 +42,7 @@ struct snd_compressed_buffer {
42} __attribute__((packed, aligned(4))); 42} __attribute__((packed, aligned(4)));
43 43
44/** 44/**
45 * struct snd_compr_params: compressed stream params 45 * struct snd_compr_params - compressed stream params
46 * @buffer: buffer description 46 * @buffer: buffer description
47 * @codec: codec parameters 47 * @codec: codec parameters
48 * @no_wake_mode: dont wake on fragment elapsed 48 * @no_wake_mode: dont wake on fragment elapsed
@@ -54,7 +54,7 @@ struct snd_compr_params {
54} __attribute__((packed, aligned(4))); 54} __attribute__((packed, aligned(4)));
55 55
56/** 56/**
57 * struct snd_compr_tstamp: timestamp descriptor 57 * struct snd_compr_tstamp - timestamp descriptor
58 * @byte_offset: Byte offset in ring buffer to DSP 58 * @byte_offset: Byte offset in ring buffer to DSP
59 * @copied_total: Total number of bytes copied from/to ring buffer to/by DSP 59 * @copied_total: Total number of bytes copied from/to ring buffer to/by DSP
60 * @pcm_frames: Frames decoded or encoded by DSP. This field will evolve by 60 * @pcm_frames: Frames decoded or encoded by DSP. This field will evolve by
@@ -73,7 +73,7 @@ struct snd_compr_tstamp {
73} __attribute__((packed, aligned(4))); 73} __attribute__((packed, aligned(4)));
74 74
75/** 75/**
76 * struct snd_compr_avail: avail descriptor 76 * struct snd_compr_avail - avail descriptor
77 * @avail: Number of bytes available in ring buffer for writing/reading 77 * @avail: Number of bytes available in ring buffer for writing/reading
78 * @tstamp: timestamp infomation 78 * @tstamp: timestamp infomation
79 */ 79 */
@@ -88,7 +88,7 @@ enum snd_compr_direction {
88}; 88};
89 89
90/** 90/**
91 * struct snd_compr_caps: caps descriptor 91 * struct snd_compr_caps - caps descriptor
92 * @codecs: pointer to array of codecs 92 * @codecs: pointer to array of codecs
93 * @direction: direction supported. Of type snd_compr_direction 93 * @direction: direction supported. Of type snd_compr_direction
94 * @min_fragment_size: minimum fragment supported by DSP 94 * @min_fragment_size: minimum fragment supported by DSP
@@ -110,7 +110,7 @@ struct snd_compr_caps {
110} __attribute__((packed, aligned(4))); 110} __attribute__((packed, aligned(4)));
111 111
112/** 112/**
113 * struct snd_compr_codec_caps: query capability of codec 113 * struct snd_compr_codec_caps - query capability of codec
114 * @codec: codec for which capability is queried 114 * @codec: codec for which capability is queried
115 * @num_descriptors: number of codec descriptors 115 * @num_descriptors: number of codec descriptors
116 * @descriptor: array of codec capability descriptor 116 * @descriptor: array of codec capability descriptor
@@ -122,18 +122,19 @@ struct snd_compr_codec_caps {
122} __attribute__((packed, aligned(4))); 122} __attribute__((packed, aligned(4)));
123 123
124/** 124/**
125 * enum sndrv_compress_encoder
125 * @SNDRV_COMPRESS_ENCODER_PADDING: no of samples appended by the encoder at the 126 * @SNDRV_COMPRESS_ENCODER_PADDING: no of samples appended by the encoder at the
126 * end of the track 127 * end of the track
127 * @SNDRV_COMPRESS_ENCODER_DELAY: no of samples inserted by the encoder at the 128 * @SNDRV_COMPRESS_ENCODER_DELAY: no of samples inserted by the encoder at the
128 * beginning of the track 129 * beginning of the track
129 */ 130 */
130enum { 131enum sndrv_compress_encoder {
131 SNDRV_COMPRESS_ENCODER_PADDING = 1, 132 SNDRV_COMPRESS_ENCODER_PADDING = 1,
132 SNDRV_COMPRESS_ENCODER_DELAY = 2, 133 SNDRV_COMPRESS_ENCODER_DELAY = 2,
133}; 134};
134 135
135/** 136/**
136 * struct snd_compr_metadata: compressed stream metadata 137 * struct snd_compr_metadata - compressed stream metadata
137 * @key: key id 138 * @key: key id
138 * @value: key value 139 * @value: key value
139 */ 140 */
diff --git a/include/uapi/sound/firewire.h b/include/uapi/sound/firewire.h
index af4bd136c75d..49122df3b56b 100644
--- a/include/uapi/sound/firewire.h
+++ b/include/uapi/sound/firewire.h
@@ -55,7 +55,8 @@ union snd_firewire_event {
55#define SNDRV_FIREWIRE_TYPE_DICE 1 55#define SNDRV_FIREWIRE_TYPE_DICE 1
56#define SNDRV_FIREWIRE_TYPE_FIREWORKS 2 56#define SNDRV_FIREWIRE_TYPE_FIREWORKS 2
57#define SNDRV_FIREWIRE_TYPE_BEBOB 3 57#define SNDRV_FIREWIRE_TYPE_BEBOB 3
58/* AV/C, RME, MOTU, ... */ 58#define SNDRV_FIREWIRE_TYPE_OXFW 4
59/* RME, MOTU, ... */
59 60
60struct snd_firewire_get_info { 61struct snd_firewire_get_info {
61 unsigned int type; /* SNDRV_FIREWIRE_TYPE_xxx */ 62 unsigned int type; /* SNDRV_FIREWIRE_TYPE_xxx */
diff --git a/include/uapi/sound/hdspm.h b/include/uapi/sound/hdspm.h
index d956c3593f65..b357f1a5e29c 100644
--- a/include/uapi/sound/hdspm.h
+++ b/include/uapi/sound/hdspm.h
@@ -74,14 +74,14 @@ struct hdspm_config {
74#define SNDRV_HDSPM_IOCTL_GET_CONFIG \ 74#define SNDRV_HDSPM_IOCTL_GET_CONFIG \
75 _IOR('H', 0x41, struct hdspm_config) 75 _IOR('H', 0x41, struct hdspm_config)
76 76
77/** 77/*
78 * If there's a TCO (TimeCode Option) board installed, 78 * If there's a TCO (TimeCode Option) board installed,
79 * there are further options and status data available. 79 * there are further options and status data available.
80 * The hdspm_ltc structure contains the current SMPTE 80 * The hdspm_ltc structure contains the current SMPTE
81 * timecode and some status information and can be 81 * timecode and some status information and can be
82 * obtained via SNDRV_HDSPM_IOCTL_GET_LTC or in the 82 * obtained via SNDRV_HDSPM_IOCTL_GET_LTC or in the
83 * hdspm_status struct. 83 * hdspm_status struct.
84 **/ 84 */
85 85
86enum hdspm_ltc_format { 86enum hdspm_ltc_format {
87 format_invalid, 87 format_invalid,
@@ -113,11 +113,11 @@ struct hdspm_ltc {
113 113
114#define SNDRV_HDSPM_IOCTL_GET_LTC _IOR('H', 0x46, struct hdspm_ltc) 114#define SNDRV_HDSPM_IOCTL_GET_LTC _IOR('H', 0x46, struct hdspm_ltc)
115 115
116/** 116/*
117 * The status data reflects the device's current state 117 * The status data reflects the device's current state
118 * as determined by the card's configuration and 118 * as determined by the card's configuration and
119 * connection status. 119 * connection status.
120 **/ 120 */
121 121
122enum hdspm_sync { 122enum hdspm_sync {
123 hdspm_sync_no_lock = 0, 123 hdspm_sync_no_lock = 0,
@@ -171,9 +171,9 @@ struct hdspm_status {
171#define SNDRV_HDSPM_IOCTL_GET_STATUS \ 171#define SNDRV_HDSPM_IOCTL_GET_STATUS \
172 _IOR('H', 0x47, struct hdspm_status) 172 _IOR('H', 0x47, struct hdspm_status)
173 173
174/** 174/*
175 * Get information about the card and its add-ons. 175 * Get information about the card and its add-ons.
176 **/ 176 */
177 177
178#define HDSPM_ADDON_TCO 1 178#define HDSPM_ADDON_TCO 1
179 179
diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
index 401107b85d30..23c371ecfb6b 100644
--- a/sound/aoa/codecs/onyx.c
+++ b/sound/aoa/codecs/onyx.c
@@ -243,13 +243,7 @@ static int onyx_snd_capture_source_info(struct snd_kcontrol *kcontrol,
243{ 243{
244 static const char * const texts[] = { "Line-In", "Microphone" }; 244 static const char * const texts[] = { "Line-In", "Microphone" };
245 245
246 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 246 return snd_ctl_enum_info(uinfo, 1, 2, texts);
247 uinfo->count = 1;
248 uinfo->value.enumerated.items = 2;
249 if (uinfo->value.enumerated.item > 1)
250 uinfo->value.enumerated.item = 1;
251 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
252 return 0;
253} 247}
254 248
255static int onyx_snd_capture_source_get(struct snd_kcontrol *kcontrol, 249static int onyx_snd_capture_source_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c
index cf3c6303b7e3..364c7c4416e8 100644
--- a/sound/aoa/codecs/tas.c
+++ b/sound/aoa/codecs/tas.c
@@ -478,15 +478,9 @@ static struct snd_kcontrol_new drc_switch_control = {
478static int tas_snd_capture_source_info(struct snd_kcontrol *kcontrol, 478static int tas_snd_capture_source_info(struct snd_kcontrol *kcontrol,
479 struct snd_ctl_elem_info *uinfo) 479 struct snd_ctl_elem_info *uinfo)
480{ 480{
481 static char *texts[] = { "Line-In", "Microphone" }; 481 static const char * const texts[] = { "Line-In", "Microphone" };
482 482
483 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 483 return snd_ctl_enum_info(uinfo, 1, 2, texts);
484 uinfo->count = 1;
485 uinfo->value.enumerated.items = 2;
486 if (uinfo->value.enumerated.item > 1)
487 uinfo->value.enumerated.item = 1;
488 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
489 return 0;
490} 484}
491 485
492static int tas_snd_capture_source_get(struct snd_kcontrol *kcontrol, 486static int tas_snd_capture_source_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
index a80d5ea87ccd..4e2b4fbf2496 100644
--- a/sound/aoa/soundbus/i2sbus/core.c
+++ b/sound/aoa/soundbus/i2sbus/core.c
@@ -79,8 +79,7 @@ static void i2sbus_release_dev(struct device *dev)
79 if (i2sdev->out.dbdma) iounmap(i2sdev->out.dbdma); 79 if (i2sdev->out.dbdma) iounmap(i2sdev->out.dbdma);
80 if (i2sdev->in.dbdma) iounmap(i2sdev->in.dbdma); 80 if (i2sdev->in.dbdma) iounmap(i2sdev->in.dbdma);
81 for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) 81 for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
82 if (i2sdev->allocated_resource[i]) 82 release_and_free_resource(i2sdev->allocated_resource[i]);
83 release_and_free_resource(i2sdev->allocated_resource[i]);
84 free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring); 83 free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring);
85 free_dbdma_descriptor_ring(i2sdev, &i2sdev->in.dbdma_ring); 84 free_dbdma_descriptor_ring(i2sdev, &i2sdev->in.dbdma_ring);
86 for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) 85 for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
@@ -323,8 +322,7 @@ static int i2sbus_add_dev(struct macio_dev *macio,
323 if (dev->out.dbdma) iounmap(dev->out.dbdma); 322 if (dev->out.dbdma) iounmap(dev->out.dbdma);
324 if (dev->in.dbdma) iounmap(dev->in.dbdma); 323 if (dev->in.dbdma) iounmap(dev->in.dbdma);
325 for (i=0;i<3;i++) 324 for (i=0;i<3;i++)
326 if (dev->allocated_resource[i]) 325 release_and_free_resource(dev->allocated_resource[i]);
327 release_and_free_resource(dev->allocated_resource[i]);
328 mutex_destroy(&dev->lock); 326 mutex_destroy(&dev->lock);
329 kfree(dev); 327 kfree(dev);
330 return 0; 328 return 0;
diff --git a/sound/arm/pxa2xx-pcm-lib.c b/sound/arm/pxa2xx-pcm-lib.c
index a61d7a9a995e..01f8fdc42b1b 100644
--- a/sound/arm/pxa2xx-pcm-lib.c
+++ b/sound/arm/pxa2xx-pcm-lib.c
@@ -200,9 +200,7 @@ void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id)
200 } else { 200 } else {
201 printk(KERN_ERR "DMA error on channel %d (DCSR=%#x)\n", 201 printk(KERN_ERR "DMA error on channel %d (DCSR=%#x)\n",
202 dma_ch, dcsr); 202 dma_ch, dcsr);
203 snd_pcm_stream_lock(substream); 203 snd_pcm_stop_xrun(substream);
204 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
205 snd_pcm_stream_unlock(substream);
206 } 204 }
207} 205}
208EXPORT_SYMBOL(pxa2xx_pcm_dma_irq); 206EXPORT_SYMBOL(pxa2xx_pcm_dma_irq);
diff --git a/sound/atmel/abdac.c b/sound/atmel/abdac.c
index 31061e3521d4..023140504104 100644
--- a/sound/atmel/abdac.c
+++ b/sound/atmel/abdac.c
@@ -242,7 +242,7 @@ static int atmel_abdac_trigger(struct snd_pcm_substream *substream, int cmd)
242 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */ 242 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
243 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */ 243 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
244 case SNDRV_PCM_TRIGGER_START: 244 case SNDRV_PCM_TRIGGER_START:
245 clk_enable(dac->sample_clk); 245 clk_prepare_enable(dac->sample_clk);
246 retval = dw_dma_cyclic_start(dac->dma.chan); 246 retval = dw_dma_cyclic_start(dac->dma.chan);
247 if (retval) 247 if (retval)
248 goto out; 248 goto out;
@@ -254,7 +254,7 @@ static int atmel_abdac_trigger(struct snd_pcm_substream *substream, int cmd)
254 dw_dma_cyclic_stop(dac->dma.chan); 254 dw_dma_cyclic_stop(dac->dma.chan);
255 dac_writel(dac, DATA, 0); 255 dac_writel(dac, DATA, 0);
256 dac_writel(dac, CTRL, 0); 256 dac_writel(dac, CTRL, 0);
257 clk_disable(dac->sample_clk); 257 clk_disable_unprepare(dac->sample_clk);
258 break; 258 break;
259 default: 259 default:
260 retval = -EINVAL; 260 retval = -EINVAL;
@@ -429,7 +429,7 @@ static int atmel_abdac_probe(struct platform_device *pdev)
429 retval = PTR_ERR(sample_clk); 429 retval = PTR_ERR(sample_clk);
430 goto out_put_pclk; 430 goto out_put_pclk;
431 } 431 }
432 clk_enable(pclk); 432 clk_prepare_enable(pclk);
433 433
434 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1, 434 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
435 SNDRV_DEFAULT_STR1, THIS_MODULE, 435 SNDRV_DEFAULT_STR1, THIS_MODULE,
@@ -528,7 +528,7 @@ out_free_card:
528 snd_card_free(card); 528 snd_card_free(card);
529out_put_sample_clk: 529out_put_sample_clk:
530 clk_put(sample_clk); 530 clk_put(sample_clk);
531 clk_disable(pclk); 531 clk_disable_unprepare(pclk);
532out_put_pclk: 532out_put_pclk:
533 clk_put(pclk); 533 clk_put(pclk);
534 return retval; 534 return retval;
@@ -541,8 +541,8 @@ static int atmel_abdac_suspend(struct device *pdev)
541 struct atmel_abdac *dac = card->private_data; 541 struct atmel_abdac *dac = card->private_data;
542 542
543 dw_dma_cyclic_stop(dac->dma.chan); 543 dw_dma_cyclic_stop(dac->dma.chan);
544 clk_disable(dac->sample_clk); 544 clk_disable_unprepare(dac->sample_clk);
545 clk_disable(dac->pclk); 545 clk_disable_unprepare(dac->pclk);
546 546
547 return 0; 547 return 0;
548} 548}
@@ -552,8 +552,8 @@ static int atmel_abdac_resume(struct device *pdev)
552 struct snd_card *card = dev_get_drvdata(pdev); 552 struct snd_card *card = dev_get_drvdata(pdev);
553 struct atmel_abdac *dac = card->private_data; 553 struct atmel_abdac *dac = card->private_data;
554 554
555 clk_enable(dac->pclk); 555 clk_prepare_enable(dac->pclk);
556 clk_enable(dac->sample_clk); 556 clk_prepare_enable(dac->sample_clk);
557 if (test_bit(DMA_READY, &dac->flags)) 557 if (test_bit(DMA_READY, &dac->flags))
558 dw_dma_cyclic_start(dac->dma.chan); 558 dw_dma_cyclic_start(dac->dma.chan);
559 559
@@ -572,7 +572,7 @@ static int atmel_abdac_remove(struct platform_device *pdev)
572 struct atmel_abdac *dac = get_dac(card); 572 struct atmel_abdac *dac = get_dac(card);
573 573
574 clk_put(dac->sample_clk); 574 clk_put(dac->sample_clk);
575 clk_disable(dac->pclk); 575 clk_disable_unprepare(dac->pclk);
576 clk_put(dac->pclk); 576 clk_put(dac->pclk);
577 577
578 dma_release_channel(dac->dma.chan); 578 dma_release_channel(dac->dma.chan);
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
index b59427d5a697..cb44c74c9702 100644
--- a/sound/atmel/ac97c.c
+++ b/sound/atmel/ac97c.c
@@ -773,7 +773,7 @@ static int atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
773 return err; 773 return err;
774 } 774 }
775 retval = snd_pcm_new(chip->card, chip->card->shortname, 775 retval = snd_pcm_new(chip->card, chip->card->shortname,
776 chip->pdev->id, playback, capture, &pcm); 776 0, playback, capture, &pcm);
777 if (retval) 777 if (retval)
778 return retval; 778 return retval;
779 779
@@ -944,7 +944,7 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
944 dev_dbg(&pdev->dev, "no peripheral clock\n"); 944 dev_dbg(&pdev->dev, "no peripheral clock\n");
945 return PTR_ERR(pclk); 945 return PTR_ERR(pclk);
946 } 946 }
947 clk_enable(pclk); 947 clk_prepare_enable(pclk);
948 948
949 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1, 949 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
950 SNDRV_DEFAULT_STR1, THIS_MODULE, 950 SNDRV_DEFAULT_STR1, THIS_MODULE,
@@ -1122,7 +1122,7 @@ err_ioremap:
1122err_request_irq: 1122err_request_irq:
1123 snd_card_free(card); 1123 snd_card_free(card);
1124err_snd_card_new: 1124err_snd_card_new:
1125 clk_disable(pclk); 1125 clk_disable_unprepare(pclk);
1126 clk_put(pclk); 1126 clk_put(pclk);
1127 return retval; 1127 return retval;
1128} 1128}
@@ -1139,7 +1139,7 @@ static int atmel_ac97c_suspend(struct device *pdev)
1139 if (test_bit(DMA_TX_READY, &chip->flags)) 1139 if (test_bit(DMA_TX_READY, &chip->flags))
1140 dw_dma_cyclic_stop(chip->dma.tx_chan); 1140 dw_dma_cyclic_stop(chip->dma.tx_chan);
1141 } 1141 }
1142 clk_disable(chip->pclk); 1142 clk_disable_unprepare(chip->pclk);
1143 1143
1144 return 0; 1144 return 0;
1145} 1145}
@@ -1149,7 +1149,7 @@ static int atmel_ac97c_resume(struct device *pdev)
1149 struct snd_card *card = dev_get_drvdata(pdev); 1149 struct snd_card *card = dev_get_drvdata(pdev);
1150 struct atmel_ac97c *chip = card->private_data; 1150 struct atmel_ac97c *chip = card->private_data;
1151 1151
1152 clk_enable(chip->pclk); 1152 clk_prepare_enable(chip->pclk);
1153 if (cpu_is_at32ap7000()) { 1153 if (cpu_is_at32ap7000()) {
1154 if (test_bit(DMA_RX_READY, &chip->flags)) 1154 if (test_bit(DMA_RX_READY, &chip->flags))
1155 dw_dma_cyclic_start(chip->dma.rx_chan); 1155 dw_dma_cyclic_start(chip->dma.rx_chan);
@@ -1177,7 +1177,7 @@ static int atmel_ac97c_remove(struct platform_device *pdev)
1177 ac97c_writel(chip, COMR, 0); 1177 ac97c_writel(chip, COMR, 0);
1178 ac97c_writel(chip, MR, 0); 1178 ac97c_writel(chip, MR, 0);
1179 1179
1180 clk_disable(chip->pclk); 1180 clk_disable_unprepare(chip->pclk);
1181 clk_put(chip->pclk); 1181 clk_put(chip->pclk);
1182 iounmap(chip->regs); 1182 iounmap(chip->regs);
1183 free_irq(chip->irq, chip); 1183 free_irq(chip->irq, chip);
diff --git a/sound/core/Makefile b/sound/core/Makefile
index 394a38909f6b..4daf2f58261c 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -14,6 +14,9 @@ snd-pcm-y := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \
14 pcm_memory.o memalloc.o 14 pcm_memory.o memalloc.o
15snd-pcm-$(CONFIG_SND_DMA_SGBUF) += sgbuf.o 15snd-pcm-$(CONFIG_SND_DMA_SGBUF) += sgbuf.o
16 16
17# for trace-points
18CFLAGS_pcm_lib.o := -I$(src)
19
17snd-pcm-dmaengine-objs := pcm_dmaengine.o 20snd-pcm-dmaengine-objs := pcm_dmaengine.o
18 21
19snd-rawmidi-objs := rawmidi.o 22snd-rawmidi-objs := rawmidi.o
diff --git a/sound/core/control.c b/sound/core/control.c
index b9611344ff9e..bb96a467e88d 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -141,6 +141,16 @@ static int snd_ctl_release(struct inode *inode, struct file *file)
141 return 0; 141 return 0;
142} 142}
143 143
144/**
145 * snd_ctl_notify - Send notification to user-space for a control change
146 * @card: the card to send notification
147 * @mask: the event mask, SNDRV_CTL_EVENT_*
148 * @id: the ctl element id to send notification
149 *
150 * This function adds an event record with the given id and mask, appends
151 * to the list and wakes up the user-space for notification. This can be
152 * called in the atomic context.
153 */
144void snd_ctl_notify(struct snd_card *card, unsigned int mask, 154void snd_ctl_notify(struct snd_card *card, unsigned int mask,
145 struct snd_ctl_elem_id *id) 155 struct snd_ctl_elem_id *id)
146{ 156{
@@ -179,7 +189,6 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask,
179 } 189 }
180 read_unlock(&card->ctl_files_rwlock); 190 read_unlock(&card->ctl_files_rwlock);
181} 191}
182
183EXPORT_SYMBOL(snd_ctl_notify); 192EXPORT_SYMBOL(snd_ctl_notify);
184 193
185/** 194/**
@@ -261,7 +270,6 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
261 kctl.private_data = private_data; 270 kctl.private_data = private_data;
262 return snd_ctl_new(&kctl, access); 271 return snd_ctl_new(&kctl, access);
263} 272}
264
265EXPORT_SYMBOL(snd_ctl_new1); 273EXPORT_SYMBOL(snd_ctl_new1);
266 274
267/** 275/**
@@ -280,7 +288,6 @@ void snd_ctl_free_one(struct snd_kcontrol *kcontrol)
280 kfree(kcontrol); 288 kfree(kcontrol);
281 } 289 }
282} 290}
283
284EXPORT_SYMBOL(snd_ctl_free_one); 291EXPORT_SYMBOL(snd_ctl_free_one);
285 292
286static bool snd_ctl_remove_numid_conflict(struct snd_card *card, 293static bool snd_ctl_remove_numid_conflict(struct snd_card *card,
@@ -376,7 +383,6 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
376 snd_ctl_free_one(kcontrol); 383 snd_ctl_free_one(kcontrol);
377 return err; 384 return err;
378} 385}
379
380EXPORT_SYMBOL(snd_ctl_add); 386EXPORT_SYMBOL(snd_ctl_add);
381 387
382/** 388/**
@@ -471,7 +477,6 @@ int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol)
471 snd_ctl_free_one(kcontrol); 477 snd_ctl_free_one(kcontrol);
472 return 0; 478 return 0;
473} 479}
474
475EXPORT_SYMBOL(snd_ctl_remove); 480EXPORT_SYMBOL(snd_ctl_remove);
476 481
477/** 482/**
@@ -499,7 +504,6 @@ int snd_ctl_remove_id(struct snd_card *card, struct snd_ctl_elem_id *id)
499 up_write(&card->controls_rwsem); 504 up_write(&card->controls_rwsem);
500 return ret; 505 return ret;
501} 506}
502
503EXPORT_SYMBOL(snd_ctl_remove_id); 507EXPORT_SYMBOL(snd_ctl_remove_id);
504 508
505/** 509/**
@@ -568,7 +572,7 @@ int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id,
568 ret = -ENOENT; 572 ret = -ENOENT;
569 goto unlock; 573 goto unlock;
570 } 574 }
571 index_offset = snd_ctl_get_ioff(kctl, &kctl->id); 575 index_offset = snd_ctl_get_ioff(kctl, id);
572 vd = &kctl->vd[index_offset]; 576 vd = &kctl->vd[index_offset];
573 ret = 0; 577 ret = 0;
574 if (active) { 578 if (active) {
@@ -617,7 +621,6 @@ int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id,
617 up_write(&card->controls_rwsem); 621 up_write(&card->controls_rwsem);
618 return 0; 622 return 0;
619} 623}
620
621EXPORT_SYMBOL(snd_ctl_rename_id); 624EXPORT_SYMBOL(snd_ctl_rename_id);
622 625
623/** 626/**
@@ -645,7 +648,6 @@ struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numi
645 } 648 }
646 return NULL; 649 return NULL;
647} 650}
648
649EXPORT_SYMBOL(snd_ctl_find_numid); 651EXPORT_SYMBOL(snd_ctl_find_numid);
650 652
651/** 653/**
@@ -687,7 +689,6 @@ struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card,
687 } 689 }
688 return NULL; 690 return NULL;
689} 691}
690
691EXPORT_SYMBOL(snd_ctl_find_id); 692EXPORT_SYMBOL(snd_ctl_find_id);
692 693
693static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl, 694static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl,
@@ -1526,19 +1527,28 @@ static int _snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn, struct list_head *
1526 return 0; 1527 return 0;
1527} 1528}
1528 1529
1530/**
1531 * snd_ctl_register_ioctl - register the device-specific control-ioctls
1532 * @fcn: ioctl callback function
1533 *
1534 * called from each device manager like pcm.c, hwdep.c, etc.
1535 */
1529int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn) 1536int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn)
1530{ 1537{
1531 return _snd_ctl_register_ioctl(fcn, &snd_control_ioctls); 1538 return _snd_ctl_register_ioctl(fcn, &snd_control_ioctls);
1532} 1539}
1533
1534EXPORT_SYMBOL(snd_ctl_register_ioctl); 1540EXPORT_SYMBOL(snd_ctl_register_ioctl);
1535 1541
1536#ifdef CONFIG_COMPAT 1542#ifdef CONFIG_COMPAT
1543/**
1544 * snd_ctl_register_ioctl_compat - register the device-specific 32bit compat
1545 * control-ioctls
1546 * @fcn: ioctl callback function
1547 */
1537int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn) 1548int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn)
1538{ 1549{
1539 return _snd_ctl_register_ioctl(fcn, &snd_control_compat_ioctls); 1550 return _snd_ctl_register_ioctl(fcn, &snd_control_compat_ioctls);
1540} 1551}
1541
1542EXPORT_SYMBOL(snd_ctl_register_ioctl_compat); 1552EXPORT_SYMBOL(snd_ctl_register_ioctl_compat);
1543#endif 1553#endif
1544 1554
@@ -1566,19 +1576,26 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn,
1566 return -EINVAL; 1576 return -EINVAL;
1567} 1577}
1568 1578
1579/**
1580 * snd_ctl_unregister_ioctl - de-register the device-specific control-ioctls
1581 * @fcn: ioctl callback function to unregister
1582 */
1569int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn) 1583int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn)
1570{ 1584{
1571 return _snd_ctl_unregister_ioctl(fcn, &snd_control_ioctls); 1585 return _snd_ctl_unregister_ioctl(fcn, &snd_control_ioctls);
1572} 1586}
1573
1574EXPORT_SYMBOL(snd_ctl_unregister_ioctl); 1587EXPORT_SYMBOL(snd_ctl_unregister_ioctl);
1575 1588
1576#ifdef CONFIG_COMPAT 1589#ifdef CONFIG_COMPAT
1590/**
1591 * snd_ctl_unregister_ioctl - de-register the device-specific compat 32bit
1592 * control-ioctls
1593 * @fcn: ioctl callback function to unregister
1594 */
1577int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn) 1595int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn)
1578{ 1596{
1579 return _snd_ctl_unregister_ioctl(fcn, &snd_control_compat_ioctls); 1597 return _snd_ctl_unregister_ioctl(fcn, &snd_control_compat_ioctls);
1580} 1598}
1581
1582EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat); 1599EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat);
1583#endif 1600#endif
1584 1601
@@ -1702,6 +1719,16 @@ int snd_ctl_create(struct snd_card *card)
1702/* 1719/*
1703 * Frequently used control callbacks/helpers 1720 * Frequently used control callbacks/helpers
1704 */ 1721 */
1722
1723/**
1724 * snd_ctl_boolean_mono_info - Helper function for a standard boolean info
1725 * callback with a mono channel
1726 * @kcontrol: the kcontrol instance
1727 * @uinfo: info to store
1728 *
1729 * This is a function that can be used as info callback for a standard
1730 * boolean control with a single mono channel.
1731 */
1705int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol, 1732int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_info *uinfo) 1733 struct snd_ctl_elem_info *uinfo)
1707{ 1734{
@@ -1711,9 +1738,17 @@ int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
1711 uinfo->value.integer.max = 1; 1738 uinfo->value.integer.max = 1;
1712 return 0; 1739 return 0;
1713} 1740}
1714
1715EXPORT_SYMBOL(snd_ctl_boolean_mono_info); 1741EXPORT_SYMBOL(snd_ctl_boolean_mono_info);
1716 1742
1743/**
1744 * snd_ctl_boolean_stereo_info - Helper function for a standard boolean info
1745 * callback with stereo two channels
1746 * @kcontrol: the kcontrol instance
1747 * @uinfo: info to store
1748 *
1749 * This is a function that can be used as info callback for a standard
1750 * boolean control with stereo two channels.
1751 */
1717int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol, 1752int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
1718 struct snd_ctl_elem_info *uinfo) 1753 struct snd_ctl_elem_info *uinfo)
1719{ 1754{
@@ -1723,7 +1758,6 @@ int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
1723 uinfo->value.integer.max = 1; 1758 uinfo->value.integer.max = 1;
1724 return 0; 1759 return 0;
1725} 1760}
1726
1727EXPORT_SYMBOL(snd_ctl_boolean_stereo_info); 1761EXPORT_SYMBOL(snd_ctl_boolean_stereo_info);
1728 1762
1729/** 1763/**
@@ -1745,8 +1779,13 @@ int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
1745 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1779 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1746 info->count = channels; 1780 info->count = channels;
1747 info->value.enumerated.items = items; 1781 info->value.enumerated.items = items;
1782 if (!items)
1783 return 0;
1748 if (info->value.enumerated.item >= items) 1784 if (info->value.enumerated.item >= items)
1749 info->value.enumerated.item = items - 1; 1785 info->value.enumerated.item = items - 1;
1786 WARN(strlen(names[info->value.enumerated.item]) >= sizeof(info->value.enumerated.name),
1787 "ALSA: too long item name '%s'\n",
1788 names[info->value.enumerated.item]);
1750 strlcpy(info->value.enumerated.name, 1789 strlcpy(info->value.enumerated.name,
1751 names[info->value.enumerated.item], 1790 names[info->value.enumerated.item],
1752 sizeof(info->value.enumerated.name)); 1791 sizeof(info->value.enumerated.name));
diff --git a/sound/core/init.c b/sound/core/init.c
index 7bdfd19e24a8..074875d68c15 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -438,17 +438,6 @@ int snd_card_disconnect(struct snd_card *card)
438 438
439EXPORT_SYMBOL(snd_card_disconnect); 439EXPORT_SYMBOL(snd_card_disconnect);
440 440
441/**
442 * snd_card_free - frees given soundcard structure
443 * @card: soundcard structure
444 *
445 * This function releases the soundcard structure and the all assigned
446 * devices automatically. That is, you don't have to release the devices
447 * by yourself.
448 *
449 * Return: Zero. Frees all associated devices and frees the control
450 * interface associated to given soundcard.
451 */
452static int snd_card_do_free(struct snd_card *card) 441static int snd_card_do_free(struct snd_card *card)
453{ 442{
454#if IS_ENABLED(CONFIG_SND_MIXER_OSS) 443#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
@@ -469,6 +458,15 @@ static int snd_card_do_free(struct snd_card *card)
469 return 0; 458 return 0;
470} 459}
471 460
461/**
462 * snd_card_free_when_closed - Disconnect the card, free it later eventually
463 * @card: soundcard structure
464 *
465 * Unlike snd_card_free(), this function doesn't try to release the card
466 * resource immediately, but tries to disconnect at first. When the card
467 * is still in use, the function returns before freeing the resources.
468 * The card resources will be freed when the refcount gets to zero.
469 */
472int snd_card_free_when_closed(struct snd_card *card) 470int snd_card_free_when_closed(struct snd_card *card)
473{ 471{
474 int ret = snd_card_disconnect(card); 472 int ret = snd_card_disconnect(card);
@@ -479,6 +477,19 @@ int snd_card_free_when_closed(struct snd_card *card)
479} 477}
480EXPORT_SYMBOL(snd_card_free_when_closed); 478EXPORT_SYMBOL(snd_card_free_when_closed);
481 479
480/**
481 * snd_card_free - frees given soundcard structure
482 * @card: soundcard structure
483 *
484 * This function releases the soundcard structure and the all assigned
485 * devices automatically. That is, you don't have to release the devices
486 * by yourself.
487 *
488 * This function waits until the all resources are properly released.
489 *
490 * Return: Zero. Frees all associated devices and frees the control
491 * interface associated to given soundcard.
492 */
482int snd_card_free(struct snd_card *card) 493int snd_card_free(struct snd_card *card)
483{ 494{
484 struct completion released; 495 struct completion released;
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index c6ff94ab1ad6..cfc56c806964 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -220,6 +220,10 @@ static char *snd_pcm_format_names[] = {
220 FORMAT(DSD_U32_BE), 220 FORMAT(DSD_U32_BE),
221}; 221};
222 222
223/**
224 * snd_pcm_format_name - Return a name string for the given PCM format
225 * @format: PCM format
226 */
223const char *snd_pcm_format_name(snd_pcm_format_t format) 227const char *snd_pcm_format_name(snd_pcm_format_t format)
224{ 228{
225 if ((__force unsigned int)format >= ARRAY_SIZE(snd_pcm_format_names)) 229 if ((__force unsigned int)format >= ARRAY_SIZE(snd_pcm_format_names))
@@ -481,6 +485,19 @@ static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry,
481} 485}
482 486
483#ifdef CONFIG_SND_PCM_XRUN_DEBUG 487#ifdef CONFIG_SND_PCM_XRUN_DEBUG
488static void snd_pcm_xrun_injection_write(struct snd_info_entry *entry,
489 struct snd_info_buffer *buffer)
490{
491 struct snd_pcm_substream *substream = entry->private_data;
492 struct snd_pcm_runtime *runtime;
493
494 snd_pcm_stream_lock_irq(substream);
495 runtime = substream->runtime;
496 if (runtime && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
497 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
498 snd_pcm_stream_unlock_irq(substream);
499}
500
484static void snd_pcm_xrun_debug_read(struct snd_info_entry *entry, 501static void snd_pcm_xrun_debug_read(struct snd_info_entry *entry,
485 struct snd_info_buffer *buffer) 502 struct snd_info_buffer *buffer)
486{ 503{
@@ -612,6 +629,22 @@ static int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream)
612 } 629 }
613 substream->proc_status_entry = entry; 630 substream->proc_status_entry = entry;
614 631
632#ifdef CONFIG_SND_PCM_XRUN_DEBUG
633 entry = snd_info_create_card_entry(card, "xrun_injection",
634 substream->proc_root);
635 if (entry) {
636 entry->private_data = substream;
637 entry->c.text.read = NULL;
638 entry->c.text.write = snd_pcm_xrun_injection_write;
639 entry->mode = S_IFREG | S_IWUSR;
640 if (snd_info_register(entry) < 0) {
641 snd_info_free_entry(entry);
642 entry = NULL;
643 }
644 }
645 substream->proc_xrun_injection_entry = entry;
646#endif /* CONFIG_SND_PCM_XRUN_DEBUG */
647
615 return 0; 648 return 0;
616} 649}
617 650
@@ -625,6 +658,10 @@ static int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream)
625 substream->proc_sw_params_entry = NULL; 658 substream->proc_sw_params_entry = NULL;
626 snd_info_free_entry(substream->proc_status_entry); 659 snd_info_free_entry(substream->proc_status_entry);
627 substream->proc_status_entry = NULL; 660 substream->proc_status_entry = NULL;
661#ifdef CONFIG_SND_PCM_XRUN_DEBUG
662 snd_info_free_entry(substream->proc_xrun_injection_entry);
663 substream->proc_xrun_injection_entry = NULL;
664#endif
628 snd_info_free_entry(substream->proc_root); 665 snd_info_free_entry(substream->proc_root);
629 substream->proc_root = NULL; 666 substream->proc_root = NULL;
630 return 0; 667 return 0;
@@ -709,7 +746,6 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
709 } 746 }
710 return 0; 747 return 0;
711} 748}
712
713EXPORT_SYMBOL(snd_pcm_new_stream); 749EXPORT_SYMBOL(snd_pcm_new_stream);
714 750
715static int _snd_pcm_new(struct snd_card *card, const char *id, int device, 751static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
@@ -1157,6 +1193,15 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
1157 return 0; 1193 return 0;
1158} 1194}
1159 1195
1196/**
1197 * snd_pcm_notify - Add/remove the notify list
1198 * @notify: PCM notify list
1199 * @nfree: 0 = register, 1 = unregister
1200 *
1201 * This adds the given notifier to the global list so that the callback is
1202 * called for each registered PCM devices. This exists only for PCM OSS
1203 * emulation, so far.
1204 */
1160int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree) 1205int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
1161{ 1206{
1162 struct snd_pcm *pcm; 1207 struct snd_pcm *pcm;
@@ -1179,7 +1224,6 @@ int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
1179 mutex_unlock(&register_mutex); 1224 mutex_unlock(&register_mutex);
1180 return 0; 1225 return 0;
1181} 1226}
1182
1183EXPORT_SYMBOL(snd_pcm_notify); 1227EXPORT_SYMBOL(snd_pcm_notify);
1184 1228
1185#ifdef CONFIG_PROC_FS 1229#ifdef CONFIG_PROC_FS
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index dfc28542a007..ec9e7866177f 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -32,6 +32,15 @@
32#include <sound/pcm_params.h> 32#include <sound/pcm_params.h>
33#include <sound/timer.h> 33#include <sound/timer.h>
34 34
35#ifdef CONFIG_SND_PCM_XRUN_DEBUG
36#define CREATE_TRACE_POINTS
37#include "pcm_trace.h"
38#else
39#define trace_hwptr(substream, pos, in_interrupt)
40#define trace_xrun(substream)
41#define trace_hw_ptr_error(substream, reason)
42#endif
43
35/* 44/*
36 * fill ring buffer with silence 45 * fill ring buffer with silence
37 * runtime->silence_start: starting pointer to silence area 46 * runtime->silence_start: starting pointer to silence area
@@ -146,10 +155,6 @@ EXPORT_SYMBOL(snd_pcm_debug_name);
146#define XRUN_DEBUG_BASIC (1<<0) 155#define XRUN_DEBUG_BASIC (1<<0)
147#define XRUN_DEBUG_STACK (1<<1) /* dump also stack */ 156#define XRUN_DEBUG_STACK (1<<1) /* dump also stack */
148#define XRUN_DEBUG_JIFFIESCHECK (1<<2) /* do jiffies check */ 157#define XRUN_DEBUG_JIFFIESCHECK (1<<2) /* do jiffies check */
149#define XRUN_DEBUG_PERIODUPDATE (1<<3) /* full period update info */
150#define XRUN_DEBUG_HWPTRUPDATE (1<<4) /* full hwptr update info */
151#define XRUN_DEBUG_LOG (1<<5) /* show last 10 positions on err */
152#define XRUN_DEBUG_LOGONCE (1<<6) /* do above only once */
153 158
154#ifdef CONFIG_SND_PCM_XRUN_DEBUG 159#ifdef CONFIG_SND_PCM_XRUN_DEBUG
155 160
@@ -168,6 +173,7 @@ static void xrun(struct snd_pcm_substream *substream)
168{ 173{
169 struct snd_pcm_runtime *runtime = substream->runtime; 174 struct snd_pcm_runtime *runtime = substream->runtime;
170 175
176 trace_xrun(substream);
171 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) 177 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE)
172 snd_pcm_gettime(runtime, (struct timespec *)&runtime->status->tstamp); 178 snd_pcm_gettime(runtime, (struct timespec *)&runtime->status->tstamp);
173 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 179 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
@@ -180,97 +186,19 @@ static void xrun(struct snd_pcm_substream *substream)
180} 186}
181 187
182#ifdef CONFIG_SND_PCM_XRUN_DEBUG 188#ifdef CONFIG_SND_PCM_XRUN_DEBUG
183#define hw_ptr_error(substream, fmt, args...) \ 189#define hw_ptr_error(substream, in_interrupt, reason, fmt, args...) \
184 do { \ 190 do { \
191 trace_hw_ptr_error(substream, reason); \
185 if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { \ 192 if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { \
186 xrun_log_show(substream); \ 193 pr_err_ratelimited("ALSA: PCM: [%c] " reason ": " fmt, \
187 pr_err_ratelimited("ALSA: PCM: " fmt, ##args); \ 194 (in_interrupt) ? 'Q' : 'P', ##args); \
188 dump_stack_on_xrun(substream); \ 195 dump_stack_on_xrun(substream); \
189 } \ 196 } \
190 } while (0) 197 } while (0)
191 198
192#define XRUN_LOG_CNT 10
193
194struct hwptr_log_entry {
195 unsigned int in_interrupt;
196 unsigned long jiffies;
197 snd_pcm_uframes_t pos;
198 snd_pcm_uframes_t period_size;
199 snd_pcm_uframes_t buffer_size;
200 snd_pcm_uframes_t old_hw_ptr;
201 snd_pcm_uframes_t hw_ptr_base;
202};
203
204struct snd_pcm_hwptr_log {
205 unsigned int idx;
206 unsigned int hit: 1;
207 struct hwptr_log_entry entries[XRUN_LOG_CNT];
208};
209
210static void xrun_log(struct snd_pcm_substream *substream,
211 snd_pcm_uframes_t pos, int in_interrupt)
212{
213 struct snd_pcm_runtime *runtime = substream->runtime;
214 struct snd_pcm_hwptr_log *log = runtime->hwptr_log;
215 struct hwptr_log_entry *entry;
216
217 if (log == NULL) {
218 log = kzalloc(sizeof(*log), GFP_ATOMIC);
219 if (log == NULL)
220 return;
221 runtime->hwptr_log = log;
222 } else {
223 if (xrun_debug(substream, XRUN_DEBUG_LOGONCE) && log->hit)
224 return;
225 }
226 entry = &log->entries[log->idx];
227 entry->in_interrupt = in_interrupt;
228 entry->jiffies = jiffies;
229 entry->pos = pos;
230 entry->period_size = runtime->period_size;
231 entry->buffer_size = runtime->buffer_size;
232 entry->old_hw_ptr = runtime->status->hw_ptr;
233 entry->hw_ptr_base = runtime->hw_ptr_base;
234 log->idx = (log->idx + 1) % XRUN_LOG_CNT;
235}
236
237static void xrun_log_show(struct snd_pcm_substream *substream)
238{
239 struct snd_pcm_hwptr_log *log = substream->runtime->hwptr_log;
240 struct hwptr_log_entry *entry;
241 char name[16];
242 unsigned int idx;
243 int cnt;
244
245 if (log == NULL)
246 return;
247 if (xrun_debug(substream, XRUN_DEBUG_LOGONCE) && log->hit)
248 return;
249 snd_pcm_debug_name(substream, name, sizeof(name));
250 for (cnt = 0, idx = log->idx; cnt < XRUN_LOG_CNT; cnt++) {
251 entry = &log->entries[idx];
252 if (entry->period_size == 0)
253 break;
254 pr_info("hwptr log: %s: %sj=%lu, pos=%ld/%ld/%ld, "
255 "hwptr=%ld/%ld\n",
256 name, entry->in_interrupt ? "[Q] " : "",
257 entry->jiffies,
258 (unsigned long)entry->pos,
259 (unsigned long)entry->period_size,
260 (unsigned long)entry->buffer_size,
261 (unsigned long)entry->old_hw_ptr,
262 (unsigned long)entry->hw_ptr_base);
263 idx++;
264 idx %= XRUN_LOG_CNT;
265 }
266 log->hit = 1;
267}
268
269#else /* ! CONFIG_SND_PCM_XRUN_DEBUG */ 199#else /* ! CONFIG_SND_PCM_XRUN_DEBUG */
270 200
271#define hw_ptr_error(substream, fmt, args...) do { } while (0) 201#define hw_ptr_error(substream, fmt, args...) do { } while (0)
272#define xrun_log(substream, pos, in_interrupt) do { } while (0)
273#define xrun_log_show(substream) do { } while (0)
274 202
275#endif 203#endif
276 204
@@ -343,17 +271,15 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
343 if (printk_ratelimit()) { 271 if (printk_ratelimit()) {
344 char name[16]; 272 char name[16];
345 snd_pcm_debug_name(substream, name, sizeof(name)); 273 snd_pcm_debug_name(substream, name, sizeof(name));
346 xrun_log_show(substream);
347 pcm_err(substream->pcm, 274 pcm_err(substream->pcm,
348 "XRUN: %s, pos = %ld, buffer size = %ld, period size = %ld\n", 275 "BUG: %s, pos = %ld, buffer size = %ld, period size = %ld\n",
349 name, pos, runtime->buffer_size, 276 name, pos, runtime->buffer_size,
350 runtime->period_size); 277 runtime->period_size);
351 } 278 }
352 pos = 0; 279 pos = 0;
353 } 280 }
354 pos -= pos % runtime->min_align; 281 pos -= pos % runtime->min_align;
355 if (xrun_debug(substream, XRUN_DEBUG_LOG)) 282 trace_hwptr(substream, pos, in_interrupt);
356 xrun_log(substream, pos, in_interrupt);
357 hw_base = runtime->hw_ptr_base; 283 hw_base = runtime->hw_ptr_base;
358 new_hw_ptr = hw_base + pos; 284 new_hw_ptr = hw_base + pos;
359 if (in_interrupt) { 285 if (in_interrupt) {
@@ -388,22 +314,6 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
388 delta = new_hw_ptr - old_hw_ptr; 314 delta = new_hw_ptr - old_hw_ptr;
389 if (delta < 0) 315 if (delta < 0)
390 delta += runtime->boundary; 316 delta += runtime->boundary;
391 if (xrun_debug(substream, in_interrupt ?
392 XRUN_DEBUG_PERIODUPDATE : XRUN_DEBUG_HWPTRUPDATE)) {
393 char name[16];
394 snd_pcm_debug_name(substream, name, sizeof(name));
395 pcm_dbg(substream->pcm,
396 "%s_update: %s: pos=%u/%u/%u, hwptr=%ld/%ld/%ld/%ld\n",
397 in_interrupt ? "period" : "hwptr",
398 name,
399 (unsigned int)pos,
400 (unsigned int)runtime->period_size,
401 (unsigned int)runtime->buffer_size,
402 (unsigned long)delta,
403 (unsigned long)old_hw_ptr,
404 (unsigned long)new_hw_ptr,
405 (unsigned long)runtime->hw_ptr_base);
406 }
407 317
408 if (runtime->no_period_wakeup) { 318 if (runtime->no_period_wakeup) {
409 snd_pcm_sframes_t xrun_threshold; 319 snd_pcm_sframes_t xrun_threshold;
@@ -431,13 +341,10 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
431 341
432 /* something must be really wrong */ 342 /* something must be really wrong */
433 if (delta >= runtime->buffer_size + runtime->period_size) { 343 if (delta >= runtime->buffer_size + runtime->period_size) {
434 hw_ptr_error(substream, 344 hw_ptr_error(substream, in_interrupt, "Unexpected hw_ptr",
435 "Unexpected hw_pointer value %s" 345 "(stream=%i, pos=%ld, new_hw_ptr=%ld, old_hw_ptr=%ld)\n",
436 "(stream=%i, pos=%ld, new_hw_ptr=%ld, " 346 substream->stream, (long)pos,
437 "old_hw_ptr=%ld)\n", 347 (long)new_hw_ptr, (long)old_hw_ptr);
438 in_interrupt ? "[Q] " : "[P]",
439 substream->stream, (long)pos,
440 (long)new_hw_ptr, (long)old_hw_ptr);
441 return 0; 348 return 0;
442 } 349 }
443 350
@@ -474,11 +381,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
474 delta--; 381 delta--;
475 } 382 }
476 /* align hw_base to buffer_size */ 383 /* align hw_base to buffer_size */
477 hw_ptr_error(substream, 384 hw_ptr_error(substream, in_interrupt, "hw_ptr skipping",
478 "hw_ptr skipping! %s" 385 "(pos=%ld, delta=%ld, period=%ld, jdelta=%lu/%lu/%lu, hw_ptr=%ld/%ld)\n",
479 "(pos=%ld, delta=%ld, period=%ld, "
480 "jdelta=%lu/%lu/%lu, hw_ptr=%ld/%ld)\n",
481 in_interrupt ? "[Q] " : "",
482 (long)pos, (long)hdelta, 386 (long)pos, (long)hdelta,
483 (long)runtime->period_size, jdelta, 387 (long)runtime->period_size, jdelta,
484 ((hdelta * HZ) / runtime->rate), hw_base, 388 ((hdelta * HZ) / runtime->rate), hw_base,
@@ -490,11 +394,9 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
490 } 394 }
491 no_jiffies_check: 395 no_jiffies_check:
492 if (delta > runtime->period_size + runtime->period_size / 2) { 396 if (delta > runtime->period_size + runtime->period_size / 2) {
493 hw_ptr_error(substream, 397 hw_ptr_error(substream, in_interrupt,
494 "Lost interrupts? %s" 398 "Lost interrupts?",
495 "(stream=%i, delta=%ld, new_hw_ptr=%ld, " 399 "(stream=%i, delta=%ld, new_hw_ptr=%ld, old_hw_ptr=%ld)\n",
496 "old_hw_ptr=%ld)\n",
497 in_interrupt ? "[Q] " : "",
498 substream->stream, (long)delta, 400 substream->stream, (long)delta,
499 (long)new_hw_ptr, 401 (long)new_hw_ptr,
500 (long)old_hw_ptr); 402 (long)old_hw_ptr);
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 166d59cdc86b..095d9572ad2b 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -35,9 +35,6 @@
35#include <sound/timer.h> 35#include <sound/timer.h>
36#include <sound/minors.h> 36#include <sound/minors.h>
37#include <asm/io.h> 37#include <asm/io.h>
38#if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
39#include <dma-coherence.h>
40#endif
41 38
42/* 39/*
43 * Compatibility 40 * Compatibility
@@ -77,6 +74,14 @@ static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream);
77static DEFINE_RWLOCK(snd_pcm_link_rwlock); 74static DEFINE_RWLOCK(snd_pcm_link_rwlock);
78static DECLARE_RWSEM(snd_pcm_link_rwsem); 75static DECLARE_RWSEM(snd_pcm_link_rwsem);
79 76
77/**
78 * snd_pcm_stream_lock - Lock the PCM stream
79 * @substream: PCM substream
80 *
81 * This locks the PCM stream's spinlock or mutex depending on the nonatomic
82 * flag of the given substream. This also takes the global link rw lock
83 * (or rw sem), too, for avoiding the race with linked streams.
84 */
80void snd_pcm_stream_lock(struct snd_pcm_substream *substream) 85void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
81{ 86{
82 if (substream->pcm->nonatomic) { 87 if (substream->pcm->nonatomic) {
@@ -89,6 +94,12 @@ void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
89} 94}
90EXPORT_SYMBOL_GPL(snd_pcm_stream_lock); 95EXPORT_SYMBOL_GPL(snd_pcm_stream_lock);
91 96
97/**
98 * snd_pcm_stream_lock - Unlock the PCM stream
99 * @substream: PCM substream
100 *
101 * This unlocks the PCM stream that has been locked via snd_pcm_stream_lock().
102 */
92void snd_pcm_stream_unlock(struct snd_pcm_substream *substream) 103void snd_pcm_stream_unlock(struct snd_pcm_substream *substream)
93{ 104{
94 if (substream->pcm->nonatomic) { 105 if (substream->pcm->nonatomic) {
@@ -101,6 +112,14 @@ void snd_pcm_stream_unlock(struct snd_pcm_substream *substream)
101} 112}
102EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock); 113EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock);
103 114
115/**
116 * snd_pcm_stream_lock_irq - Lock the PCM stream
117 * @substream: PCM substream
118 *
119 * This locks the PCM stream like snd_pcm_stream_lock() and disables the local
120 * IRQ (only when nonatomic is false). In nonatomic case, this is identical
121 * as snd_pcm_stream_lock().
122 */
104void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream) 123void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
105{ 124{
106 if (!substream->pcm->nonatomic) 125 if (!substream->pcm->nonatomic)
@@ -109,6 +128,12 @@ void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
109} 128}
110EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq); 129EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq);
111 130
131/**
132 * snd_pcm_stream_unlock_irq - Unlock the PCM stream
133 * @substream: PCM substream
134 *
135 * This is a counter-part of snd_pcm_stream_lock_irq().
136 */
112void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream) 137void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream)
113{ 138{
114 snd_pcm_stream_unlock(substream); 139 snd_pcm_stream_unlock(substream);
@@ -127,6 +152,13 @@ unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream)
127} 152}
128EXPORT_SYMBOL_GPL(_snd_pcm_stream_lock_irqsave); 153EXPORT_SYMBOL_GPL(_snd_pcm_stream_lock_irqsave);
129 154
155/**
156 * snd_pcm_stream_unlock_irqrestore - Unlock the PCM stream
157 * @substream: PCM substream
158 * @flags: irq flags
159 *
160 * This is a counter-part of snd_pcm_stream_lock_irqsave().
161 */
130void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream, 162void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
131 unsigned long flags) 163 unsigned long flags)
132{ 164{
@@ -195,6 +227,21 @@ int snd_pcm_info_user(struct snd_pcm_substream *substream,
195 return err; 227 return err;
196} 228}
197 229
230static bool hw_support_mmap(struct snd_pcm_substream *substream)
231{
232 if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP))
233 return false;
234 /* check architectures that return -EINVAL from dma_mmap_coherent() */
235 /* FIXME: this should be some global flag */
236#if defined(CONFIG_C6X) || defined(CONFIG_FRV) || defined(CONFIG_MN10300) ||\
237 defined(CONFIG_PARISC) || defined(CONFIG_XTENSA)
238 if (!substream->ops->mmap &&
239 substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
240 return false;
241#endif
242 return true;
243}
244
198#undef RULES_DEBUG 245#undef RULES_DEBUG
199 246
200#ifdef RULES_DEBUG 247#ifdef RULES_DEBUG
@@ -372,8 +419,12 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
372 } 419 }
373 420
374 hw = &substream->runtime->hw; 421 hw = &substream->runtime->hw;
375 if (!params->info) 422 if (!params->info) {
376 params->info = hw->info & ~SNDRV_PCM_INFO_FIFO_IN_FRAMES; 423 params->info = hw->info & ~SNDRV_PCM_INFO_FIFO_IN_FRAMES;
424 if (!hw_support_mmap(substream))
425 params->info &= ~(SNDRV_PCM_INFO_MMAP |
426 SNDRV_PCM_INFO_MMAP_VALID);
427 }
377 if (!params->fifo_size) { 428 if (!params->fifo_size) {
378 m = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 429 m = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
379 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 430 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
@@ -849,14 +900,19 @@ static int snd_pcm_action_single(struct action_ops *ops,
849 return res; 900 return res;
850} 901}
851 902
852/* call in mutex-protected context */ 903/*
853static int snd_pcm_action_mutex(struct action_ops *ops, 904 * Note: call with stream lock
854 struct snd_pcm_substream *substream, 905 */
855 int state) 906static int snd_pcm_action(struct action_ops *ops,
907 struct snd_pcm_substream *substream,
908 int state)
856{ 909{
857 int res; 910 int res;
858 911
859 if (snd_pcm_stream_linked(substream)) { 912 if (!snd_pcm_stream_linked(substream))
913 return snd_pcm_action_single(ops, substream, state);
914
915 if (substream->pcm->nonatomic) {
860 if (!mutex_trylock(&substream->group->mutex)) { 916 if (!mutex_trylock(&substream->group->mutex)) {
861 mutex_unlock(&substream->self_group.mutex); 917 mutex_unlock(&substream->self_group.mutex);
862 mutex_lock(&substream->group->mutex); 918 mutex_lock(&substream->group->mutex);
@@ -865,24 +921,6 @@ static int snd_pcm_action_mutex(struct action_ops *ops,
865 res = snd_pcm_action_group(ops, substream, state, 1); 921 res = snd_pcm_action_group(ops, substream, state, 1);
866 mutex_unlock(&substream->group->mutex); 922 mutex_unlock(&substream->group->mutex);
867 } else { 923 } else {
868 res = snd_pcm_action_single(ops, substream, state);
869 }
870 return res;
871}
872
873/*
874 * Note: call with stream lock
875 */
876static int snd_pcm_action(struct action_ops *ops,
877 struct snd_pcm_substream *substream,
878 int state)
879{
880 int res;
881
882 if (substream->pcm->nonatomic)
883 return snd_pcm_action_mutex(ops, substream, state);
884
885 if (snd_pcm_stream_linked(substream)) {
886 if (!spin_trylock(&substream->group->lock)) { 924 if (!spin_trylock(&substream->group->lock)) {
887 spin_unlock(&substream->self_group.lock); 925 spin_unlock(&substream->self_group.lock);
888 spin_lock(&substream->group->lock); 926 spin_lock(&substream->group->lock);
@@ -890,34 +928,10 @@ static int snd_pcm_action(struct action_ops *ops,
890 } 928 }
891 res = snd_pcm_action_group(ops, substream, state, 1); 929 res = snd_pcm_action_group(ops, substream, state, 1);
892 spin_unlock(&substream->group->lock); 930 spin_unlock(&substream->group->lock);
893 } else {
894 res = snd_pcm_action_single(ops, substream, state);
895 } 931 }
896 return res; 932 return res;
897} 933}
898 934
899static int snd_pcm_action_lock_mutex(struct action_ops *ops,
900 struct snd_pcm_substream *substream,
901 int state)
902{
903 int res;
904
905 down_read(&snd_pcm_link_rwsem);
906 if (snd_pcm_stream_linked(substream)) {
907 mutex_lock(&substream->group->mutex);
908 mutex_lock(&substream->self_group.mutex);
909 res = snd_pcm_action_group(ops, substream, state, 1);
910 mutex_unlock(&substream->self_group.mutex);
911 mutex_unlock(&substream->group->mutex);
912 } else {
913 mutex_lock(&substream->self_group.mutex);
914 res = snd_pcm_action_single(ops, substream, state);
915 mutex_unlock(&substream->self_group.mutex);
916 }
917 up_read(&snd_pcm_link_rwsem);
918 return res;
919}
920
921/* 935/*
922 * Note: don't use any locks before 936 * Note: don't use any locks before
923 */ 937 */
@@ -927,22 +941,9 @@ static int snd_pcm_action_lock_irq(struct action_ops *ops,
927{ 941{
928 int res; 942 int res;
929 943
930 if (substream->pcm->nonatomic) 944 snd_pcm_stream_lock_irq(substream);
931 return snd_pcm_action_lock_mutex(ops, substream, state); 945 res = snd_pcm_action(ops, substream, state);
932 946 snd_pcm_stream_unlock_irq(substream);
933 read_lock_irq(&snd_pcm_link_rwlock);
934 if (snd_pcm_stream_linked(substream)) {
935 spin_lock(&substream->group->lock);
936 spin_lock(&substream->self_group.lock);
937 res = snd_pcm_action_group(ops, substream, state, 1);
938 spin_unlock(&substream->self_group.lock);
939 spin_unlock(&substream->group->lock);
940 } else {
941 spin_lock(&substream->self_group.lock);
942 res = snd_pcm_action_single(ops, substream, state);
943 spin_unlock(&substream->self_group.lock);
944 }
945 read_unlock_irq(&snd_pcm_link_rwlock);
946 return res; 947 return res;
947} 948}
948 949
@@ -1051,10 +1052,10 @@ static void snd_pcm_post_stop(struct snd_pcm_substream *substream, int state)
1051 struct snd_pcm_runtime *runtime = substream->runtime; 1052 struct snd_pcm_runtime *runtime = substream->runtime;
1052 if (runtime->status->state != state) { 1053 if (runtime->status->state != state) {
1053 snd_pcm_trigger_tstamp(substream); 1054 snd_pcm_trigger_tstamp(substream);
1055 runtime->status->state = state;
1054 if (substream->timer) 1056 if (substream->timer)
1055 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSTOP, 1057 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSTOP,
1056 &runtime->trigger_tstamp); 1058 &runtime->trigger_tstamp);
1057 runtime->status->state = state;
1058 } 1059 }
1059 wake_up(&runtime->sleep); 1060 wake_up(&runtime->sleep);
1060 wake_up(&runtime->tsleep); 1061 wake_up(&runtime->tsleep);
@@ -1097,6 +1098,28 @@ int snd_pcm_drain_done(struct snd_pcm_substream *substream)
1097 SNDRV_PCM_STATE_SETUP); 1098 SNDRV_PCM_STATE_SETUP);
1098} 1099}
1099 1100
1101/**
1102 * snd_pcm_stop_xrun - stop the running streams as XRUN
1103 * @substream: the PCM substream instance
1104 *
1105 * This stops the given running substream (and all linked substreams) as XRUN.
1106 * Unlike snd_pcm_stop(), this function takes the substream lock by itself.
1107 *
1108 * Return: Zero if successful, or a negative error code.
1109 */
1110int snd_pcm_stop_xrun(struct snd_pcm_substream *substream)
1111{
1112 unsigned long flags;
1113 int ret = 0;
1114
1115 snd_pcm_stream_lock_irqsave(substream, flags);
1116 if (snd_pcm_running(substream))
1117 ret = snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
1118 snd_pcm_stream_unlock_irqrestore(substream, flags);
1119 return ret;
1120}
1121EXPORT_SYMBOL_GPL(snd_pcm_stop_xrun);
1122
1100/* 1123/*
1101 * pause callbacks 1124 * pause callbacks
1102 */ 1125 */
@@ -1203,11 +1226,11 @@ static void snd_pcm_post_suspend(struct snd_pcm_substream *substream, int state)
1203{ 1226{
1204 struct snd_pcm_runtime *runtime = substream->runtime; 1227 struct snd_pcm_runtime *runtime = substream->runtime;
1205 snd_pcm_trigger_tstamp(substream); 1228 snd_pcm_trigger_tstamp(substream);
1229 runtime->status->suspended_state = runtime->status->state;
1230 runtime->status->state = SNDRV_PCM_STATE_SUSPENDED;
1206 if (substream->timer) 1231 if (substream->timer)
1207 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSUSPEND, 1232 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSUSPEND,
1208 &runtime->trigger_tstamp); 1233 &runtime->trigger_tstamp);
1209 runtime->status->suspended_state = runtime->status->state;
1210 runtime->status->state = SNDRV_PCM_STATE_SUSPENDED;
1211 wake_up(&runtime->sleep); 1234 wake_up(&runtime->sleep);
1212 wake_up(&runtime->tsleep); 1235 wake_up(&runtime->tsleep);
1213} 1236}
@@ -1310,10 +1333,10 @@ static void snd_pcm_post_resume(struct snd_pcm_substream *substream, int state)
1310{ 1333{
1311 struct snd_pcm_runtime *runtime = substream->runtime; 1334 struct snd_pcm_runtime *runtime = substream->runtime;
1312 snd_pcm_trigger_tstamp(substream); 1335 snd_pcm_trigger_tstamp(substream);
1336 runtime->status->state = runtime->status->suspended_state;
1313 if (substream->timer) 1337 if (substream->timer)
1314 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MRESUME, 1338 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MRESUME,
1315 &runtime->trigger_tstamp); 1339 &runtime->trigger_tstamp);
1316 runtime->status->state = runtime->status->suspended_state;
1317} 1340}
1318 1341
1319static struct action_ops snd_pcm_action_resume = { 1342static struct action_ops snd_pcm_action_resume = {
@@ -2070,7 +2093,7 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
2070 mask |= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED; 2093 mask |= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED;
2071 if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) 2094 if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED)
2072 mask |= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED; 2095 mask |= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED;
2073 if (hw->info & SNDRV_PCM_INFO_MMAP) { 2096 if (hw_support_mmap(substream)) {
2074 if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) 2097 if (hw->info & SNDRV_PCM_INFO_INTERLEAVED)
2075 mask |= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED; 2098 mask |= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED;
2076 if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) 2099 if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED)
@@ -3249,20 +3272,6 @@ static inline struct page *
3249snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs) 3272snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs)
3250{ 3273{
3251 void *vaddr = substream->runtime->dma_area + ofs; 3274 void *vaddr = substream->runtime->dma_area + ofs;
3252#if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3253 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
3254 return virt_to_page(CAC_ADDR(vaddr));
3255#endif
3256#if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3257 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV) {
3258 dma_addr_t addr = substream->runtime->dma_addr + ofs;
3259 addr -= get_dma_offset(substream->dma_buffer.dev.dev);
3260 /* assume dma_handle set via pfn_to_phys() in
3261 * mm/dma-noncoherent.c
3262 */
3263 return pfn_to_page(addr >> PAGE_SHIFT);
3264 }
3265#endif
3266 return virt_to_page(vaddr); 3275 return virt_to_page(vaddr);
3267} 3276}
3268 3277
@@ -3307,16 +3316,18 @@ static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = {
3307 .fault = snd_pcm_mmap_data_fault, 3316 .fault = snd_pcm_mmap_data_fault,
3308}; 3317};
3309 3318
3310#ifndef ARCH_HAS_DMA_MMAP_COHERENT
3311/* This should be defined / handled globally! */
3312#if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
3313#define ARCH_HAS_DMA_MMAP_COHERENT
3314#endif
3315#endif
3316
3317/* 3319/*
3318 * mmap the DMA buffer on RAM 3320 * mmap the DMA buffer on RAM
3319 */ 3321 */
3322
3323/**
3324 * snd_pcm_lib_default_mmap - Default PCM data mmap function
3325 * @substream: PCM substream
3326 * @area: VMA
3327 *
3328 * This is the default mmap handler for PCM data. When mmap pcm_ops is NULL,
3329 * this function is invoked implicitly.
3330 */
3320int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream, 3331int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
3321 struct vm_area_struct *area) 3332 struct vm_area_struct *area)
3322{ 3333{
@@ -3329,7 +3340,7 @@ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
3329 area->vm_end - area->vm_start, area->vm_page_prot); 3340 area->vm_end - area->vm_start, area->vm_page_prot);
3330 } 3341 }
3331#endif /* CONFIG_GENERIC_ALLOCATOR */ 3342#endif /* CONFIG_GENERIC_ALLOCATOR */
3332#ifdef ARCH_HAS_DMA_MMAP_COHERENT 3343#ifndef CONFIG_X86 /* for avoiding warnings arch/x86/mm/pat.c */
3333 if (!substream->ops->page && 3344 if (!substream->ops->page &&
3334 substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV) 3345 substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
3335 return dma_mmap_coherent(substream->dma_buffer.dev.dev, 3346 return dma_mmap_coherent(substream->dma_buffer.dev.dev,
@@ -3337,11 +3348,7 @@ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
3337 substream->runtime->dma_area, 3348 substream->runtime->dma_area,
3338 substream->runtime->dma_addr, 3349 substream->runtime->dma_addr,
3339 area->vm_end - area->vm_start); 3350 area->vm_end - area->vm_start);
3340#elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT) 3351#endif /* CONFIG_X86 */
3341 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV &&
3342 !plat_device_is_coherent(substream->dma_buffer.dev.dev))
3343 area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
3344#endif /* ARCH_HAS_DMA_MMAP_COHERENT */
3345 /* mmap with fault handler */ 3352 /* mmap with fault handler */
3346 area->vm_ops = &snd_pcm_vm_ops_data_fault; 3353 area->vm_ops = &snd_pcm_vm_ops_data_fault;
3347 return 0; 3354 return 0;
@@ -3352,6 +3359,15 @@ EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap);
3352 * mmap the DMA buffer on I/O memory area 3359 * mmap the DMA buffer on I/O memory area
3353 */ 3360 */
3354#if SNDRV_PCM_INFO_MMAP_IOMEM 3361#if SNDRV_PCM_INFO_MMAP_IOMEM
3362/**
3363 * snd_pcm_lib_mmap_iomem - Default PCM data mmap function for I/O mem
3364 * @substream: PCM substream
3365 * @area: VMA
3366 *
3367 * When your hardware uses the iomapped pages as the hardware buffer and
3368 * wants to mmap it, pass this function as mmap pcm_ops. Note that this
3369 * is supposed to work only on limited architectures.
3370 */
3355int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, 3371int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
3356 struct vm_area_struct *area) 3372 struct vm_area_struct *area)
3357{ 3373{
diff --git a/sound/core/pcm_trace.h b/sound/core/pcm_trace.h
new file mode 100644
index 000000000000..b63b654da5ff
--- /dev/null
+++ b/sound/core/pcm_trace.h
@@ -0,0 +1,110 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM snd_pcm
3#define TRACE_INCLUDE_FILE pcm_trace
4
5#if !defined(_PCM_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _PCM_TRACE_H
7
8#include <linux/tracepoint.h>
9
10TRACE_EVENT(hwptr,
11 TP_PROTO(struct snd_pcm_substream *substream, snd_pcm_uframes_t pos, bool irq),
12 TP_ARGS(substream, pos, irq),
13 TP_STRUCT__entry(
14 __field( bool, in_interrupt )
15 __field( unsigned int, card )
16 __field( unsigned int, device )
17 __field( unsigned int, number )
18 __field( unsigned int, stream )
19 __field( snd_pcm_uframes_t, pos )
20 __field( snd_pcm_uframes_t, period_size )
21 __field( snd_pcm_uframes_t, buffer_size )
22 __field( snd_pcm_uframes_t, old_hw_ptr )
23 __field( snd_pcm_uframes_t, hw_ptr_base )
24 ),
25 TP_fast_assign(
26 __entry->in_interrupt = (irq);
27 __entry->card = (substream)->pcm->card->number;
28 __entry->device = (substream)->pcm->device;
29 __entry->number = (substream)->number;
30 __entry->stream = (substream)->stream;
31 __entry->pos = (pos);
32 __entry->period_size = (substream)->runtime->period_size;
33 __entry->buffer_size = (substream)->runtime->buffer_size;
34 __entry->old_hw_ptr = (substream)->runtime->status->hw_ptr;
35 __entry->hw_ptr_base = (substream)->runtime->hw_ptr_base;
36 ),
37 TP_printk("pcmC%dD%d%c/sub%d: %s: pos=%lu, old=%lu, base=%lu, period=%lu, buf=%lu",
38 __entry->card, __entry->device,
39 __entry->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c',
40 __entry->number,
41 __entry->in_interrupt ? "IRQ" : "POS",
42 (unsigned long)__entry->pos,
43 (unsigned long)__entry->old_hw_ptr,
44 (unsigned long)__entry->hw_ptr_base,
45 (unsigned long)__entry->period_size,
46 (unsigned long)__entry->buffer_size)
47);
48
49TRACE_EVENT(xrun,
50 TP_PROTO(struct snd_pcm_substream *substream),
51 TP_ARGS(substream),
52 TP_STRUCT__entry(
53 __field( unsigned int, card )
54 __field( unsigned int, device )
55 __field( unsigned int, number )
56 __field( unsigned int, stream )
57 __field( snd_pcm_uframes_t, period_size )
58 __field( snd_pcm_uframes_t, buffer_size )
59 __field( snd_pcm_uframes_t, old_hw_ptr )
60 __field( snd_pcm_uframes_t, hw_ptr_base )
61 ),
62 TP_fast_assign(
63 __entry->card = (substream)->pcm->card->number;
64 __entry->device = (substream)->pcm->device;
65 __entry->number = (substream)->number;
66 __entry->stream = (substream)->stream;
67 __entry->period_size = (substream)->runtime->period_size;
68 __entry->buffer_size = (substream)->runtime->buffer_size;
69 __entry->old_hw_ptr = (substream)->runtime->status->hw_ptr;
70 __entry->hw_ptr_base = (substream)->runtime->hw_ptr_base;
71 ),
72 TP_printk("pcmC%dD%d%c/sub%d: XRUN: old=%lu, base=%lu, period=%lu, buf=%lu",
73 __entry->card, __entry->device,
74 __entry->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c',
75 __entry->number,
76 (unsigned long)__entry->old_hw_ptr,
77 (unsigned long)__entry->hw_ptr_base,
78 (unsigned long)__entry->period_size,
79 (unsigned long)__entry->buffer_size)
80);
81
82TRACE_EVENT(hw_ptr_error,
83 TP_PROTO(struct snd_pcm_substream *substream, const char *why),
84 TP_ARGS(substream, why),
85 TP_STRUCT__entry(
86 __field( unsigned int, card )
87 __field( unsigned int, device )
88 __field( unsigned int, number )
89 __field( unsigned int, stream )
90 __field( const char *, reason )
91 ),
92 TP_fast_assign(
93 __entry->card = (substream)->pcm->card->number;
94 __entry->device = (substream)->pcm->device;
95 __entry->number = (substream)->number;
96 __entry->stream = (substream)->stream;
97 __entry->reason = (why);
98 ),
99 TP_printk("pcmC%dD%d%c/sub%d: ERROR: %s",
100 __entry->card, __entry->device,
101 __entry->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c',
102 __entry->number, __entry->reason)
103);
104
105#endif /* _PCM_TRACE_H */
106
107/* This part must be outside protection */
108#undef TRACE_INCLUDE_PATH
109#define TRACE_INCLUDE_PATH .
110#include <trace/define_trace.h>
diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c
index b9184d20c39f..b0e32e161dd1 100644
--- a/sound/core/seq/oss/seq_oss_init.c
+++ b/sound/core/seq/oss/seq_oss_init.c
@@ -403,14 +403,11 @@ free_devinfo(void *private)
403{ 403{
404 struct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private; 404 struct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private;
405 405
406 if (dp->timer) 406 snd_seq_oss_timer_delete(dp->timer);
407 snd_seq_oss_timer_delete(dp->timer);
408 407
409 if (dp->writeq) 408 snd_seq_oss_writeq_delete(dp->writeq);
410 snd_seq_oss_writeq_delete(dp->writeq);
411 409
412 if (dp->readq) 410 snd_seq_oss_readq_delete(dp->readq);
413 snd_seq_oss_readq_delete(dp->readq);
414 411
415 kfree(dp); 412 kfree(dp);
416} 413}
diff --git a/sound/core/seq/seq.c b/sound/core/seq/seq.c
index 712110561082..7e0aabb808a6 100644
--- a/sound/core/seq/seq.c
+++ b/sound/core/seq/seq.c
@@ -86,7 +86,6 @@ static int __init alsa_seq_init(void)
86{ 86{
87 int err; 87 int err;
88 88
89 snd_seq_autoload_lock();
90 if ((err = client_init_data()) < 0) 89 if ((err = client_init_data()) < 0)
91 goto error; 90 goto error;
92 91
@@ -110,8 +109,8 @@ static int __init alsa_seq_init(void)
110 if ((err = snd_seq_system_client_init()) < 0) 109 if ((err = snd_seq_system_client_init()) < 0)
111 goto error; 110 goto error;
112 111
112 snd_seq_autoload_init();
113 error: 113 error:
114 snd_seq_autoload_unlock();
115 return err; 114 return err;
116} 115}
117 116
@@ -131,6 +130,8 @@ static void __exit alsa_seq_exit(void)
131 130
132 /* release event memory */ 131 /* release event memory */
133 snd_sequencer_memory_done(); 132 snd_sequencer_memory_done();
133
134 snd_seq_autoload_exit();
134} 135}
135 136
136module_init(alsa_seq_init) 137module_init(alsa_seq_init)
diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
index 91a786a783e1..0631bdadd12b 100644
--- a/sound/core/seq/seq_device.c
+++ b/sound/core/seq/seq_device.c
@@ -56,6 +56,7 @@ MODULE_LICENSE("GPL");
56#define DRIVER_LOADED (1<<0) 56#define DRIVER_LOADED (1<<0)
57#define DRIVER_REQUESTED (1<<1) 57#define DRIVER_REQUESTED (1<<1)
58#define DRIVER_LOCKED (1<<2) 58#define DRIVER_LOCKED (1<<2)
59#define DRIVER_REQUESTING (1<<3)
59 60
60struct ops_list { 61struct ops_list {
61 char id[ID_LEN]; /* driver id */ 62 char id[ID_LEN]; /* driver id */
@@ -127,42 +128,82 @@ static void snd_seq_device_info(struct snd_info_entry *entry,
127 128
128#ifdef CONFIG_MODULES 129#ifdef CONFIG_MODULES
129/* avoid auto-loading during module_init() */ 130/* avoid auto-loading during module_init() */
130static int snd_seq_in_init; 131static atomic_t snd_seq_in_init = ATOMIC_INIT(1); /* blocked as default */
131void snd_seq_autoload_lock(void) 132void snd_seq_autoload_lock(void)
132{ 133{
133 snd_seq_in_init++; 134 atomic_inc(&snd_seq_in_init);
134} 135}
135 136
136void snd_seq_autoload_unlock(void) 137void snd_seq_autoload_unlock(void)
137{ 138{
138 snd_seq_in_init--; 139 atomic_dec(&snd_seq_in_init);
139} 140}
140#endif
141 141
142void snd_seq_device_load_drivers(void) 142static void autoload_drivers(void)
143{ 143{
144#ifdef CONFIG_MODULES 144 /* avoid reentrance */
145 struct ops_list *ops; 145 if (atomic_inc_return(&snd_seq_in_init) == 1) {
146 struct ops_list *ops;
147
148 mutex_lock(&ops_mutex);
149 list_for_each_entry(ops, &opslist, list) {
150 if ((ops->driver & DRIVER_REQUESTING) &&
151 !(ops->driver & DRIVER_REQUESTED)) {
152 ops->used++;
153 mutex_unlock(&ops_mutex);
154 ops->driver |= DRIVER_REQUESTED;
155 request_module("snd-%s", ops->id);
156 mutex_lock(&ops_mutex);
157 ops->used--;
158 }
159 }
160 mutex_unlock(&ops_mutex);
161 }
162 atomic_dec(&snd_seq_in_init);
163}
146 164
147 /* Calling request_module during module_init() 165static void call_autoload(struct work_struct *work)
148 * may cause blocking. 166{
149 */ 167 autoload_drivers();
150 if (snd_seq_in_init) 168}
151 return;
152 169
153 mutex_lock(&ops_mutex); 170static DECLARE_WORK(autoload_work, call_autoload);
154 list_for_each_entry(ops, &opslist, list) { 171
155 if (! (ops->driver & DRIVER_LOADED) && 172static void try_autoload(struct ops_list *ops)
156 ! (ops->driver & DRIVER_REQUESTED)) { 173{
157 ops->used++; 174 if (!ops->driver) {
158 mutex_unlock(&ops_mutex); 175 ops->driver |= DRIVER_REQUESTING;
159 ops->driver |= DRIVER_REQUESTED; 176 schedule_work(&autoload_work);
160 request_module("snd-%s", ops->id);
161 mutex_lock(&ops_mutex);
162 ops->used--;
163 }
164 } 177 }
178}
179
180static void queue_autoload_drivers(void)
181{
182 struct ops_list *ops;
183
184 mutex_lock(&ops_mutex);
185 list_for_each_entry(ops, &opslist, list)
186 try_autoload(ops);
165 mutex_unlock(&ops_mutex); 187 mutex_unlock(&ops_mutex);
188}
189
190void snd_seq_autoload_init(void)
191{
192 atomic_dec(&snd_seq_in_init);
193#ifdef CONFIG_SND_SEQUENCER_MODULE
194 /* initial autoload only when snd-seq is a module */
195 queue_autoload_drivers();
196#endif
197}
198#else
199#define try_autoload(ops) /* NOP */
200#endif
201
202void snd_seq_device_load_drivers(void)
203{
204#ifdef CONFIG_MODULES
205 queue_autoload_drivers();
206 flush_work(&autoload_work);
166#endif 207#endif
167} 208}
168 209
@@ -214,13 +255,14 @@ int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize,
214 ops->num_devices++; 255 ops->num_devices++;
215 mutex_unlock(&ops->reg_mutex); 256 mutex_unlock(&ops->reg_mutex);
216 257
217 unlock_driver(ops);
218
219 if ((err = snd_device_new(card, SNDRV_DEV_SEQUENCER, dev, &dops)) < 0) { 258 if ((err = snd_device_new(card, SNDRV_DEV_SEQUENCER, dev, &dops)) < 0) {
220 snd_seq_device_free(dev); 259 snd_seq_device_free(dev);
221 return err; 260 return err;
222 } 261 }
223 262
263 try_autoload(ops);
264 unlock_driver(ops);
265
224 if (result) 266 if (result)
225 *result = dev; 267 *result = dev;
226 268
@@ -318,16 +360,12 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
318 entry->init_device == NULL || entry->free_device == NULL) 360 entry->init_device == NULL || entry->free_device == NULL)
319 return -EINVAL; 361 return -EINVAL;
320 362
321 snd_seq_autoload_lock();
322 ops = find_driver(id, 1); 363 ops = find_driver(id, 1);
323 if (ops == NULL) { 364 if (ops == NULL)
324 snd_seq_autoload_unlock();
325 return -ENOMEM; 365 return -ENOMEM;
326 }
327 if (ops->driver & DRIVER_LOADED) { 366 if (ops->driver & DRIVER_LOADED) {
328 pr_warn("ALSA: seq: driver_register: driver '%s' already exists\n", id); 367 pr_warn("ALSA: seq: driver_register: driver '%s' already exists\n", id);
329 unlock_driver(ops); 368 unlock_driver(ops);
330 snd_seq_autoload_unlock();
331 return -EBUSY; 369 return -EBUSY;
332 } 370 }
333 371
@@ -344,7 +382,6 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
344 mutex_unlock(&ops->reg_mutex); 382 mutex_unlock(&ops->reg_mutex);
345 383
346 unlock_driver(ops); 384 unlock_driver(ops);
347 snd_seq_autoload_unlock();
348 385
349 return 0; 386 return 0;
350} 387}
@@ -554,6 +591,9 @@ static int __init alsa_seq_device_init(void)
554 591
555static void __exit alsa_seq_device_exit(void) 592static void __exit alsa_seq_device_exit(void)
556{ 593{
594#ifdef CONFIG_MODULES
595 cancel_work_sync(&autoload_work);
596#endif
557 remove_drivers(); 597 remove_drivers();
558#ifdef CONFIG_PROC_FS 598#ifdef CONFIG_PROC_FS
559 snd_info_free_entry(info_entry); 599 snd_info_free_entry(info_entry);
@@ -570,6 +610,7 @@ EXPORT_SYMBOL(snd_seq_device_new);
570EXPORT_SYMBOL(snd_seq_device_register_driver); 610EXPORT_SYMBOL(snd_seq_device_register_driver);
571EXPORT_SYMBOL(snd_seq_device_unregister_driver); 611EXPORT_SYMBOL(snd_seq_device_unregister_driver);
572#ifdef CONFIG_MODULES 612#ifdef CONFIG_MODULES
613EXPORT_SYMBOL(snd_seq_autoload_init);
573EXPORT_SYMBOL(snd_seq_autoload_lock); 614EXPORT_SYMBOL(snd_seq_autoload_lock);
574EXPORT_SYMBOL(snd_seq_autoload_unlock); 615EXPORT_SYMBOL(snd_seq_autoload_unlock);
575#endif 616#endif
diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c
index 0a418503ec41..84fffabdd129 100644
--- a/sound/core/sgbuf.c
+++ b/sound/core/sgbuf.c
@@ -39,8 +39,7 @@ int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab)
39 if (! sgbuf) 39 if (! sgbuf)
40 return -EINVAL; 40 return -EINVAL;
41 41
42 if (dmab->area) 42 vunmap(dmab->area);
43 vunmap(dmab->area);
44 dmab->area = NULL; 43 dmab->area = NULL;
45 44
46 tmpb.dev.type = SNDRV_DMA_TYPE_DEV; 45 tmpb.dev.type = SNDRV_DMA_TYPE_DEV;
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 38ad1a0dd3f7..f1333060bf1c 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -355,8 +355,13 @@ int snd_unregister_device(int type, struct snd_card *card, int dev)
355 355
356EXPORT_SYMBOL(snd_unregister_device); 356EXPORT_SYMBOL(snd_unregister_device);
357 357
358/* get the assigned device to the given type and device number; 358/**
359 * the caller needs to release it via put_device() after using it 359 * snd_get_device - get the assigned device to the given type and device number
360 * @type: the device type, SNDRV_DEVICE_TYPE_XXX
361 * @card:the card instance
362 * @dev: the device index
363 *
364 * The caller needs to release it via put_device() after using it.
360 */ 365 */
361struct device *snd_get_device(int type, struct snd_card *card, int dev) 366struct device *snd_get_device(int type, struct snd_card *card, int dev)
362{ 367{
diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
index f5fd448dbc57..0388fbbd2c06 100644
--- a/sound/drivers/mts64.c
+++ b/sound/drivers/mts64.c
@@ -604,21 +604,11 @@ static struct snd_kcontrol_new mts64_ctl_smpte_time_frames = {
604static int snd_mts64_ctl_smpte_fps_info(struct snd_kcontrol *kctl, 604static int snd_mts64_ctl_smpte_fps_info(struct snd_kcontrol *kctl,
605 struct snd_ctl_elem_info *uinfo) 605 struct snd_ctl_elem_info *uinfo)
606{ 606{
607 static char *texts[5] = { "24", 607 static const char * const texts[5] = {
608 "25", 608 "24", "25", "29.97", "30D", "30"
609 "29.97", 609 };
610 "30D",
611 "30" };
612 610
613 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 611 return snd_ctl_enum_info(uinfo, 1, 5, texts);
614 uinfo->count = 1;
615 uinfo->value.enumerated.items = 5;
616 if (uinfo->value.enumerated.item > 4)
617 uinfo->value.enumerated.item = 4;
618 strcpy(uinfo->value.enumerated.name,
619 texts[uinfo->value.enumerated.item]);
620
621 return 0;
622} 612}
623 613
624static int snd_mts64_ctl_smpte_fps_get(struct snd_kcontrol *kctl, 614static int snd_mts64_ctl_smpte_fps_get(struct snd_kcontrol *kctl,
diff --git a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c
index b178724295f3..d28d8706443c 100644
--- a/sound/drivers/virmidi.c
+++ b/sound/drivers/virmidi.c
@@ -99,30 +99,33 @@ static int snd_virmidi_probe(struct platform_device *devptr)
99 99
100 if (midi_devs[dev] > MAX_MIDI_DEVICES) { 100 if (midi_devs[dev] > MAX_MIDI_DEVICES) {
101 snd_printk(KERN_WARNING 101 snd_printk(KERN_WARNING
102 "too much midi devices for virmidi %d: " 102 "too much midi devices for virmidi %d: force to use %d\n",
103 "force to use %d\n", dev, MAX_MIDI_DEVICES); 103 dev, MAX_MIDI_DEVICES);
104 midi_devs[dev] = MAX_MIDI_DEVICES; 104 midi_devs[dev] = MAX_MIDI_DEVICES;
105 } 105 }
106 for (idx = 0; idx < midi_devs[dev]; idx++) { 106 for (idx = 0; idx < midi_devs[dev]; idx++) {
107 struct snd_rawmidi *rmidi; 107 struct snd_rawmidi *rmidi;
108 struct snd_virmidi_dev *rdev; 108 struct snd_virmidi_dev *rdev;
109 if ((err = snd_virmidi_new(card, idx, &rmidi)) < 0) 109
110 err = snd_virmidi_new(card, idx, &rmidi);
111 if (err < 0)
110 goto __nodev; 112 goto __nodev;
111 rdev = rmidi->private_data; 113 rdev = rmidi->private_data;
112 vmidi->midi[idx] = rmidi; 114 vmidi->midi[idx] = rmidi;
113 strcpy(rmidi->name, "Virtual Raw MIDI"); 115 strcpy(rmidi->name, "Virtual Raw MIDI");
114 rdev->seq_mode = SNDRV_VIRMIDI_SEQ_DISPATCH; 116 rdev->seq_mode = SNDRV_VIRMIDI_SEQ_DISPATCH;
115 } 117 }
116 118
117 strcpy(card->driver, "VirMIDI"); 119 strcpy(card->driver, "VirMIDI");
118 strcpy(card->shortname, "VirMIDI"); 120 strcpy(card->shortname, "VirMIDI");
119 sprintf(card->longname, "Virtual MIDI Card %i", dev + 1); 121 sprintf(card->longname, "Virtual MIDI Card %i", dev + 1);
120 122
121 if ((err = snd_card_register(card)) == 0) { 123 err = snd_card_register(card);
124 if (!err) {
122 platform_set_drvdata(devptr, card); 125 platform_set_drvdata(devptr, card);
123 return 0; 126 return 0;
124 } 127 }
125 __nodev: 128__nodev:
126 snd_card_free(card); 129 snd_card_free(card);
127 return err; 130 return err;
128} 131}
@@ -157,13 +160,15 @@ static int __init alsa_card_virmidi_init(void)
157{ 160{
158 int i, cards, err; 161 int i, cards, err;
159 162
160 if ((err = platform_driver_register(&snd_virmidi_driver)) < 0) 163 err = platform_driver_register(&snd_virmidi_driver);
164 if (err < 0)
161 return err; 165 return err;
162 166
163 cards = 0; 167 cards = 0;
164 for (i = 0; i < SNDRV_CARDS; i++) { 168 for (i = 0; i < SNDRV_CARDS; i++) {
165 struct platform_device *device; 169 struct platform_device *device;
166 if (! enable[i]) 170
171 if (!enable[i])
167 continue; 172 continue;
168 device = platform_device_register_simple(SND_VIRMIDI_DRIVER, 173 device = platform_device_register_simple(SND_VIRMIDI_DRIVER,
169 i, NULL, 0); 174 i, NULL, 0);
diff --git a/sound/drivers/vx/vx_core.c b/sound/drivers/vx/vx_core.c
index e8cc16993903..fc05a37fd017 100644
--- a/sound/drivers/vx/vx_core.c
+++ b/sound/drivers/vx/vx_core.c
@@ -416,6 +416,7 @@ int vx_send_rih(struct vx_core *chip, int cmd)
416 416
417/** 417/**
418 * snd_vx_boot_xilinx - boot up the xilinx interface 418 * snd_vx_boot_xilinx - boot up the xilinx interface
419 * @chip: VX core instance
419 * @boot: the boot record to load 420 * @boot: the boot record to load
420 */ 421 */
421int snd_vx_load_boot_image(struct vx_core *chip, const struct firmware *boot) 422int snd_vx_load_boot_image(struct vx_core *chip, const struct firmware *boot)
@@ -538,6 +539,8 @@ EXPORT_SYMBOL(snd_vx_threaded_irq_handler);
538 539
539/** 540/**
540 * snd_vx_irq_handler - interrupt handler 541 * snd_vx_irq_handler - interrupt handler
542 * @irq: irq number
543 * @dev: VX core instance
541 */ 544 */
542irqreturn_t snd_vx_irq_handler(int irq, void *dev) 545irqreturn_t snd_vx_irq_handler(int irq, void *dev)
543{ 546{
@@ -649,6 +652,8 @@ static void vx_proc_init(struct vx_core *chip)
649 652
650/** 653/**
651 * snd_vx_dsp_boot - load the DSP boot 654 * snd_vx_dsp_boot - load the DSP boot
655 * @chip: VX core instance
656 * @boot: firmware data
652 */ 657 */
653int snd_vx_dsp_boot(struct vx_core *chip, const struct firmware *boot) 658int snd_vx_dsp_boot(struct vx_core *chip, const struct firmware *boot)
654{ 659{
@@ -669,6 +674,8 @@ EXPORT_SYMBOL(snd_vx_dsp_boot);
669 674
670/** 675/**
671 * snd_vx_dsp_load - load the DSP image 676 * snd_vx_dsp_load - load the DSP image
677 * @chip: VX core instance
678 * @dsp: firmware data
672 */ 679 */
673int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp) 680int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp)
674{ 681{
@@ -768,7 +775,10 @@ EXPORT_SYMBOL(snd_vx_resume);
768 775
769/** 776/**
770 * snd_vx_create - constructor for struct vx_core 777 * snd_vx_create - constructor for struct vx_core
778 * @card: card instance
771 * @hw: hardware specific record 779 * @hw: hardware specific record
780 * @ops: VX ops pointer
781 * @extra_size: extra byte size to allocate appending to chip
772 * 782 *
773 * this function allocates the instance and prepare for the hardware 783 * this function allocates the instance and prepare for the hardware
774 * initialization. 784 * initialization.
diff --git a/sound/drivers/vx/vx_mixer.c b/sound/drivers/vx/vx_mixer.c
index 3b6823fc0606..be9477e30739 100644
--- a/sound/drivers/vx/vx_mixer.c
+++ b/sound/drivers/vx/vx_mixer.c
@@ -471,30 +471,18 @@ static struct snd_kcontrol_new vx_control_output_level = {
471 */ 471 */
472static int vx_audio_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 472static int vx_audio_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
473{ 473{
474 static char *texts_mic[3] = { 474 static const char * const texts_mic[3] = {
475 "Digital", "Line", "Mic" 475 "Digital", "Line", "Mic"
476 }; 476 };
477 static char *texts_vx2[2] = { 477 static const char * const texts_vx2[2] = {
478 "Digital", "Analog" 478 "Digital", "Analog"
479 }; 479 };
480 struct vx_core *chip = snd_kcontrol_chip(kcontrol); 480 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
481 481
482 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 482 if (chip->type >= VX_TYPE_VXPOCKET)
483 uinfo->count = 1; 483 return snd_ctl_enum_info(uinfo, 1, 3, texts_mic);
484 if (chip->type >= VX_TYPE_VXPOCKET) { 484 else
485 uinfo->value.enumerated.items = 3; 485 return snd_ctl_enum_info(uinfo, 1, 2, texts_vx2);
486 if (uinfo->value.enumerated.item > 2)
487 uinfo->value.enumerated.item = 2;
488 strcpy(uinfo->value.enumerated.name,
489 texts_mic[uinfo->value.enumerated.item]);
490 } else {
491 uinfo->value.enumerated.items = 2;
492 if (uinfo->value.enumerated.item > 1)
493 uinfo->value.enumerated.item = 1;
494 strcpy(uinfo->value.enumerated.name,
495 texts_vx2[uinfo->value.enumerated.item]);
496 }
497 return 0;
498} 486}
499 487
500static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 488static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -539,18 +527,11 @@ static struct snd_kcontrol_new vx_control_audio_src = {
539 */ 527 */
540static int vx_clock_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 528static int vx_clock_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
541{ 529{
542 static char *texts[3] = { 530 static const char * const texts[3] = {
543 "Auto", "Internal", "External" 531 "Auto", "Internal", "External"
544 }; 532 };
545 533
546 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 534 return snd_ctl_enum_info(uinfo, 1, 3, texts);
547 uinfo->count = 1;
548 uinfo->value.enumerated.items = 3;
549 if (uinfo->value.enumerated.item > 2)
550 uinfo->value.enumerated.item = 2;
551 strcpy(uinfo->value.enumerated.name,
552 texts[uinfo->value.enumerated.item]);
553 return 0;
554} 535}
555 536
556static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 537static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/firewire/Kconfig b/sound/firewire/Kconfig
index 46dff64908c8..ecec547782b2 100644
--- a/sound/firewire/Kconfig
+++ b/sound/firewire/Kconfig
@@ -13,28 +13,34 @@ config SND_FIREWIRE_LIB
13 select SND_RAWMIDI 13 select SND_RAWMIDI
14 14
15config SND_DICE 15config SND_DICE
16 tristate "DICE-based DACs (EXPERIMENTAL)" 16 tristate "DICE-based DACs support"
17 select SND_HWDEP 17 select SND_HWDEP
18 select SND_FIREWIRE_LIB 18 select SND_FIREWIRE_LIB
19 help 19 help
20 Say Y here to include support for many DACs based on the DICE 20 Say Y here to include support for many DACs based on the DICE
21 chip family (DICE-II/Jr/Mini) from TC Applied Technologies. 21 chip family (DICE-II/Jr/Mini) which TC Applied Technologies produces.
22
23 At the moment, this driver supports playback only. If you
24 want to use devices that support capturing, use FFADO instead.
25 22
26 To compile this driver as a module, choose M here: the module 23 To compile this driver as a module, choose M here: the module
27 will be called snd-dice. 24 will be called snd-dice.
28 25
29config SND_FIREWIRE_SPEAKERS 26config SND_OXFW
30 tristate "FireWire speakers" 27 tristate "Oxford Semiconductor FW970/971 chipset support"
31 select SND_FIREWIRE_LIB 28 select SND_FIREWIRE_LIB
29 select SND_HWDEP
32 help 30 help
33 Say Y here to include support for the Griffin FireWave Surround 31 Say Y here to include support for FireWire devices based on
34 and the LaCie FireWire Speakers. 32 Oxford Semiconductor FW970/971 chipset.
33 * Griffin Firewave
34 * LaCie Firewire Speakers
35 * Behringer F-Control Audio 202
36 * Mackie(Loud) Onyx-i series (former models)
37 * Mackie(Loud) Onyx Satellite
38 * Mackie(Loud) Tapco Link.Firewire
39 * Mackie(Loud) d.2 pro/d.4 pro
40 * Mackie(Loud) U.420/U.420d
35 41
36 To compile this driver as a module, choose M here: the module 42 To compile this driver as a module, choose M here: the module
37 will be called snd-firewire-speakers. 43 will be called snd-oxfw.
38 44
39config SND_ISIGHT 45config SND_ISIGHT
40 tristate "Apple iSight microphone" 46 tristate "Apple iSight microphone"
diff --git a/sound/firewire/Makefile b/sound/firewire/Makefile
index fad8d49306ab..8b37f084b2ab 100644
--- a/sound/firewire/Makefile
+++ b/sound/firewire/Makefile
@@ -1,13 +1,12 @@
1snd-firewire-lib-objs := lib.o iso-resources.o packets-buffer.o \ 1snd-firewire-lib-objs := lib.o iso-resources.o packets-buffer.o \
2 fcp.o cmp.o amdtp.o 2 fcp.o cmp.o amdtp.o
3snd-dice-objs := dice.o 3snd-oxfw-objs := oxfw.o
4snd-firewire-speakers-objs := speakers.o
5snd-isight-objs := isight.o 4snd-isight-objs := isight.o
6snd-scs1x-objs := scs1x.o 5snd-scs1x-objs := scs1x.o
7 6
8obj-$(CONFIG_SND_FIREWIRE_LIB) += snd-firewire-lib.o 7obj-$(CONFIG_SND_FIREWIRE_LIB) += snd-firewire-lib.o
9obj-$(CONFIG_SND_DICE) += snd-dice.o 8obj-$(CONFIG_SND_DICE) += dice/
10obj-$(CONFIG_SND_FIREWIRE_SPEAKERS) += snd-firewire-speakers.o 9obj-$(CONFIG_SND_OXFW) += oxfw/
11obj-$(CONFIG_SND_ISIGHT) += snd-isight.o 10obj-$(CONFIG_SND_ISIGHT) += snd-isight.o
12obj-$(CONFIG_SND_SCS1X) += snd-scs1x.o 11obj-$(CONFIG_SND_SCS1X) += snd-scs1x.o
13obj-$(CONFIG_SND_FIREWORKS) += fireworks/ 12obj-$(CONFIG_SND_FIREWORKS) += fireworks/
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 95fc2eaf11dc..3badc70124ab 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -1006,11 +1006,7 @@ void amdtp_stream_pcm_abort(struct amdtp_stream *s)
1006 struct snd_pcm_substream *pcm; 1006 struct snd_pcm_substream *pcm;
1007 1007
1008 pcm = ACCESS_ONCE(s->pcm); 1008 pcm = ACCESS_ONCE(s->pcm);
1009 if (pcm) { 1009 if (pcm)
1010 snd_pcm_stream_lock_irq(pcm); 1010 snd_pcm_stop_xrun(pcm);
1011 if (snd_pcm_running(pcm))
1012 snd_pcm_stop(pcm, SNDRV_PCM_STATE_XRUN);
1013 snd_pcm_stream_unlock_irq(pcm);
1014 }
1015} 1011}
1016EXPORT_SYMBOL(amdtp_stream_pcm_abort); 1012EXPORT_SYMBOL(amdtp_stream_pcm_abort);
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index 4823c08196ac..e6e8926275b0 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -23,7 +23,7 @@
23 * corresponds to the end of event in the packet. Out of IEC 61883. 23 * corresponds to the end of event in the packet. Out of IEC 61883.
24 * @CIP_WRONG_DBS: Only for in-stream. The value of dbs is wrong in in-packets. 24 * @CIP_WRONG_DBS: Only for in-stream. The value of dbs is wrong in in-packets.
25 * The value of data_block_quadlets is used instead of reported value. 25 * The value of data_block_quadlets is used instead of reported value.
26 * @SKIP_DBC_ZERO_CHECK: Only for in-stream. Packets with zero in dbc is 26 * @CIP_SKIP_DBC_ZERO_CHECK: Only for in-stream. Packets with zero in dbc is
27 * skipped for detecting discontinuity. 27 * skipped for detecting discontinuity.
28 * @CIP_SKIP_INIT_DBC_CHECK: Only for in-stream. The value of dbc in first 28 * @CIP_SKIP_INIT_DBC_CHECK: Only for in-stream. The value of dbc in first
29 * packet is not continuous from an initial value. 29 * packet is not continuous from an initial value.
@@ -43,7 +43,27 @@ enum cip_flags {
43}; 43};
44 44
45/** 45/**
46 * enum cip_sfc - a stream's sample rate 46 * enum cip_sfc - supported Sampling Frequency Codes (SFCs)
47 * @CIP_SFC_32000: 32,000 data blocks
48 * @CIP_SFC_44100: 44,100 data blocks
49 * @CIP_SFC_48000: 48,000 data blocks
50 * @CIP_SFC_88200: 88,200 data blocks
51 * @CIP_SFC_96000: 96,000 data blocks
52 * @CIP_SFC_176400: 176,400 data blocks
53 * @CIP_SFC_192000: 192,000 data blocks
54 * @CIP_SFC_COUNT: the number of supported SFCs
55 *
56 * These values are used to show nominal Sampling Frequency Code in
57 * Format Dependent Field (FDF) of AMDTP packet header. In IEC 61883-6:2002,
58 * this code means the number of events per second. Actually the code
59 * represents the number of data blocks transferred per second in an AMDTP
60 * stream.
61 *
62 * In IEC 61883-6:2005, some extensions were added to support more types of
63 * data such as 'One Bit LInear Audio', therefore the meaning of SFC became
64 * different depending on the types.
65 *
66 * Currently our implementation is compatible with IEC 61883-6:2002.
47 */ 67 */
48enum cip_sfc { 68enum cip_sfc {
49 CIP_SFC_32000 = 0, 69 CIP_SFC_32000 = 0,
diff --git a/sound/firewire/bebob/bebob.h b/sound/firewire/bebob/bebob.h
index e13eef99c27a..dfbcd233178c 100644
--- a/sound/firewire/bebob/bebob.h
+++ b/sound/firewire/bebob/bebob.h
@@ -52,7 +52,7 @@ extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
52#define SND_BEBOB_CLOCK_INTERNAL "Internal" 52#define SND_BEBOB_CLOCK_INTERNAL "Internal"
53struct snd_bebob_clock_spec { 53struct snd_bebob_clock_spec {
54 unsigned int num; 54 unsigned int num;
55 char *const *labels; 55 const char *const *labels;
56 int (*get)(struct snd_bebob *bebob, unsigned int *id); 56 int (*get)(struct snd_bebob *bebob, unsigned int *id);
57}; 57};
58struct snd_bebob_rate_spec { 58struct snd_bebob_rate_spec {
@@ -61,7 +61,7 @@ struct snd_bebob_rate_spec {
61}; 61};
62struct snd_bebob_meter_spec { 62struct snd_bebob_meter_spec {
63 unsigned int num; 63 unsigned int num;
64 char *const *labels; 64 const char *const *labels;
65 int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size); 65 int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);
66}; 66};
67struct snd_bebob_spec { 67struct snd_bebob_spec {
diff --git a/sound/firewire/bebob/bebob_focusrite.c b/sound/firewire/bebob/bebob_focusrite.c
index 3b052ed0fbf5..fc67c1b7cb5b 100644
--- a/sound/firewire/bebob/bebob_focusrite.c
+++ b/sound/firewire/bebob/bebob_focusrite.c
@@ -103,10 +103,10 @@ saffire_write_quad(struct snd_bebob *bebob, u64 offset, u32 value)
103 &data, sizeof(__be32), 0); 103 &data, sizeof(__be32), 0);
104} 104}
105 105
106static char *const saffirepro_10_clk_src_labels[] = { 106static const char *const saffirepro_10_clk_src_labels[] = {
107 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF", "Word Clock" 107 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF", "Word Clock"
108}; 108};
109static char *const saffirepro_26_clk_src_labels[] = { 109static const char *const saffirepro_26_clk_src_labels[] = {
110 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF", "ADAT1", "ADAT2", "Word Clock" 110 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF", "ADAT1", "ADAT2", "Word Clock"
111}; 111};
112/* Value maps between registers and labels for SaffirePro 10/26. */ 112/* Value maps between registers and labels for SaffirePro 10/26. */
@@ -195,7 +195,7 @@ end:
195} 195}
196 196
197struct snd_bebob_spec saffire_le_spec; 197struct snd_bebob_spec saffire_le_spec;
198static char *const saffire_both_clk_src_labels[] = { 198static const char *const saffire_both_clk_src_labels[] = {
199 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF" 199 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF"
200}; 200};
201static int 201static int
@@ -210,12 +210,12 @@ saffire_both_clk_src_get(struct snd_bebob *bebob, unsigned int *id)
210 210
211 return err; 211 return err;
212}; 212};
213static char *const saffire_le_meter_labels[] = { 213static const char *const saffire_le_meter_labels[] = {
214 ANA_IN, ANA_IN, DIG_IN, 214 ANA_IN, ANA_IN, DIG_IN,
215 ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT, 215 ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT,
216 STM_IN, STM_IN 216 STM_IN, STM_IN
217}; 217};
218static char *const saffire_meter_labels[] = { 218static const char *const saffire_meter_labels[] = {
219 ANA_IN, ANA_IN, 219 ANA_IN, ANA_IN,
220 STM_IN, STM_IN, STM_IN, STM_IN, STM_IN, 220 STM_IN, STM_IN, STM_IN, STM_IN, STM_IN,
221}; 221};
diff --git a/sound/firewire/bebob/bebob_maudio.c b/sound/firewire/bebob/bebob_maudio.c
index 70faa3a32526..a422aaa3bb0c 100644
--- a/sound/firewire/bebob/bebob_maudio.c
+++ b/sound/firewire/bebob/bebob_maudio.c
@@ -340,7 +340,7 @@ end:
340} 340}
341 341
342/* Clock source control for special firmware */ 342/* Clock source control for special firmware */
343static char *const special_clk_labels[] = { 343static const char *const special_clk_labels[] = {
344 SND_BEBOB_CLOCK_INTERNAL " with Digital Mute", "Digital", 344 SND_BEBOB_CLOCK_INTERNAL " with Digital Mute", "Digital",
345 "Word Clock", SND_BEBOB_CLOCK_INTERNAL}; 345 "Word Clock", SND_BEBOB_CLOCK_INTERNAL};
346static int special_clk_get(struct snd_bebob *bebob, unsigned int *id) 346static int special_clk_get(struct snd_bebob *bebob, unsigned int *id)
@@ -352,17 +352,8 @@ static int special_clk_get(struct snd_bebob *bebob, unsigned int *id)
352static int special_clk_ctl_info(struct snd_kcontrol *kctl, 352static int special_clk_ctl_info(struct snd_kcontrol *kctl,
353 struct snd_ctl_elem_info *einf) 353 struct snd_ctl_elem_info *einf)
354{ 354{
355 einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 355 return snd_ctl_enum_info(einf, 1, ARRAY_SIZE(special_clk_labels),
356 einf->count = 1; 356 special_clk_labels);
357 einf->value.enumerated.items = ARRAY_SIZE(special_clk_labels);
358
359 if (einf->value.enumerated.item >= einf->value.enumerated.items)
360 einf->value.enumerated.item = einf->value.enumerated.items - 1;
361
362 strcpy(einf->value.enumerated.name,
363 special_clk_labels[einf->value.enumerated.item]);
364
365 return 0;
366} 357}
367static int special_clk_ctl_get(struct snd_kcontrol *kctl, 358static int special_clk_ctl_get(struct snd_kcontrol *kctl,
368 struct snd_ctl_elem_value *uval) 359 struct snd_ctl_elem_value *uval)
@@ -438,23 +429,15 @@ static struct snd_kcontrol_new special_sync_ctl = {
438}; 429};
439 430
440/* Digital input interface control for special firmware */ 431/* Digital input interface control for special firmware */
441static char *const special_dig_in_iface_labels[] = { 432static const char *const special_dig_in_iface_labels[] = {
442 "S/PDIF Optical", "S/PDIF Coaxial", "ADAT Optical" 433 "S/PDIF Optical", "S/PDIF Coaxial", "ADAT Optical"
443}; 434};
444static int special_dig_in_iface_ctl_info(struct snd_kcontrol *kctl, 435static int special_dig_in_iface_ctl_info(struct snd_kcontrol *kctl,
445 struct snd_ctl_elem_info *einf) 436 struct snd_ctl_elem_info *einf)
446{ 437{
447 einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 438 return snd_ctl_enum_info(einf, 1,
448 einf->count = 1; 439 ARRAY_SIZE(special_dig_in_iface_labels),
449 einf->value.enumerated.items = ARRAY_SIZE(special_dig_in_iface_labels); 440 special_dig_in_iface_labels);
450
451 if (einf->value.enumerated.item >= einf->value.enumerated.items)
452 einf->value.enumerated.item = einf->value.enumerated.items - 1;
453
454 strcpy(einf->value.enumerated.name,
455 special_dig_in_iface_labels[einf->value.enumerated.item]);
456
457 return 0;
458} 441}
459static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl, 442static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,
460 struct snd_ctl_elem_value *uval) 443 struct snd_ctl_elem_value *uval)
@@ -539,23 +522,15 @@ static struct snd_kcontrol_new special_dig_in_iface_ctl = {
539}; 522};
540 523
541/* Digital output interface control for special firmware */ 524/* Digital output interface control for special firmware */
542static char *const special_dig_out_iface_labels[] = { 525static const char *const special_dig_out_iface_labels[] = {
543 "S/PDIF Optical and Coaxial", "ADAT Optical" 526 "S/PDIF Optical and Coaxial", "ADAT Optical"
544}; 527};
545static int special_dig_out_iface_ctl_info(struct snd_kcontrol *kctl, 528static int special_dig_out_iface_ctl_info(struct snd_kcontrol *kctl,
546 struct snd_ctl_elem_info *einf) 529 struct snd_ctl_elem_info *einf)
547{ 530{
548 einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 531 return snd_ctl_enum_info(einf, 1,
549 einf->count = 1; 532 ARRAY_SIZE(special_dig_out_iface_labels),
550 einf->value.enumerated.items = ARRAY_SIZE(special_dig_out_iface_labels); 533 special_dig_out_iface_labels);
551
552 if (einf->value.enumerated.item >= einf->value.enumerated.items)
553 einf->value.enumerated.item = einf->value.enumerated.items - 1;
554
555 strcpy(einf->value.enumerated.name,
556 special_dig_out_iface_labels[einf->value.enumerated.item]);
557
558 return 0;
559} 534}
560static int special_dig_out_iface_ctl_get(struct snd_kcontrol *kctl, 535static int special_dig_out_iface_ctl_get(struct snd_kcontrol *kctl,
561 struct snd_ctl_elem_value *uval) 536 struct snd_ctl_elem_value *uval)
@@ -631,7 +606,7 @@ end:
631} 606}
632 607
633/* Hardware metering for special firmware */ 608/* Hardware metering for special firmware */
634static char *const special_meter_labels[] = { 609static const char *const special_meter_labels[] = {
635 ANA_IN, ANA_IN, ANA_IN, ANA_IN, 610 ANA_IN, ANA_IN, ANA_IN, ANA_IN,
636 SPDIF_IN, 611 SPDIF_IN,
637 ADAT_IN, ADAT_IN, ADAT_IN, ADAT_IN, 612 ADAT_IN, ADAT_IN, ADAT_IN, ADAT_IN,
@@ -671,30 +646,30 @@ end:
671} 646}
672 647
673/* last 4 bytes are omitted because it's clock info. */ 648/* last 4 bytes are omitted because it's clock info. */
674static char *const fw410_meter_labels[] = { 649static const char *const fw410_meter_labels[] = {
675 ANA_IN, DIG_IN, 650 ANA_IN, DIG_IN,
676 ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT, DIG_OUT, 651 ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT, DIG_OUT,
677 HP_OUT 652 HP_OUT
678}; 653};
679static char *const audiophile_meter_labels[] = { 654static const char *const audiophile_meter_labels[] = {
680 ANA_IN, DIG_IN, 655 ANA_IN, DIG_IN,
681 ANA_OUT, ANA_OUT, DIG_OUT, 656 ANA_OUT, ANA_OUT, DIG_OUT,
682 HP_OUT, AUX_OUT, 657 HP_OUT, AUX_OUT,
683}; 658};
684static char *const solo_meter_labels[] = { 659static const char *const solo_meter_labels[] = {
685 ANA_IN, DIG_IN, 660 ANA_IN, DIG_IN,
686 STRM_IN, STRM_IN, 661 STRM_IN, STRM_IN,
687 ANA_OUT, DIG_OUT 662 ANA_OUT, DIG_OUT
688}; 663};
689 664
690/* no clock info */ 665/* no clock info */
691static char *const ozonic_meter_labels[] = { 666static const char *const ozonic_meter_labels[] = {
692 ANA_IN, ANA_IN, 667 ANA_IN, ANA_IN,
693 STRM_IN, STRM_IN, 668 STRM_IN, STRM_IN,
694 ANA_OUT, ANA_OUT 669 ANA_OUT, ANA_OUT
695}; 670};
696/* TODO: need testers. these positions are based on authour's assumption */ 671/* TODO: need testers. these positions are based on authour's assumption */
697static char *const nrv10_meter_labels[] = { 672static const char *const nrv10_meter_labels[] = {
698 ANA_IN, ANA_IN, ANA_IN, ANA_IN, 673 ANA_IN, ANA_IN, ANA_IN, ANA_IN,
699 DIG_IN, 674 DIG_IN,
700 ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT, 675 ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT,
diff --git a/sound/firewire/bebob/bebob_terratec.c b/sound/firewire/bebob/bebob_terratec.c
index 9940611f2e1b..ad635004d699 100644
--- a/sound/firewire/bebob/bebob_terratec.c
+++ b/sound/firewire/bebob/bebob_terratec.c
@@ -8,7 +8,7 @@
8 8
9#include "./bebob.h" 9#include "./bebob.h"
10 10
11static char *const phase88_rack_clk_src_labels[] = { 11static const char *const phase88_rack_clk_src_labels[] = {
12 SND_BEBOB_CLOCK_INTERNAL, "Digital In", "Word Clock" 12 SND_BEBOB_CLOCK_INTERNAL, "Digital In", "Word Clock"
13}; 13};
14static int 14static int
@@ -34,7 +34,7 @@ end:
34 return err; 34 return err;
35} 35}
36 36
37static char *const phase24_series_clk_src_labels[] = { 37static const char *const phase24_series_clk_src_labels[] = {
38 SND_BEBOB_CLOCK_INTERNAL, "Digital In" 38 SND_BEBOB_CLOCK_INTERNAL, "Digital In"
39}; 39};
40static int 40static int
diff --git a/sound/firewire/bebob/bebob_yamaha.c b/sound/firewire/bebob/bebob_yamaha.c
index 9b7e798180ff..ef1fe3823a9c 100644
--- a/sound/firewire/bebob/bebob_yamaha.c
+++ b/sound/firewire/bebob/bebob_yamaha.c
@@ -28,7 +28,7 @@
28 * reccomend users to close ffado-mixer at 192.0kHz if mixer is needless. 28 * reccomend users to close ffado-mixer at 192.0kHz if mixer is needless.
29 */ 29 */
30 30
31static char *const clk_src_labels[] = {SND_BEBOB_CLOCK_INTERNAL, "SPDIF"}; 31static const char *const clk_src_labels[] = {SND_BEBOB_CLOCK_INTERNAL, "SPDIF"};
32static int 32static int
33clk_src_get(struct snd_bebob *bebob, unsigned int *id) 33clk_src_get(struct snd_bebob *bebob, unsigned int *id)
34{ 34{
diff --git a/sound/firewire/cmp.c b/sound/firewire/cmp.c
index ba8df5a1be39..ae3bc1940efa 100644
--- a/sound/firewire/cmp.c
+++ b/sound/firewire/cmp.c
@@ -114,6 +114,7 @@ static int pcr_modify(struct cmp_connection *c,
114 * cmp_connection_init - initializes a connection manager 114 * cmp_connection_init - initializes a connection manager
115 * @c: the connection manager to initialize 115 * @c: the connection manager to initialize
116 * @unit: a unit of the target device 116 * @unit: a unit of the target device
117 * @direction: input or output
117 * @pcr_index: the index of the iPCR/oPCR on the target device 118 * @pcr_index: the index of the iPCR/oPCR on the target device
118 */ 119 */
119int cmp_connection_init(struct cmp_connection *c, 120int cmp_connection_init(struct cmp_connection *c,
@@ -154,6 +155,7 @@ EXPORT_SYMBOL(cmp_connection_init);
154/** 155/**
155 * cmp_connection_check_used - check connection is already esablished or not 156 * cmp_connection_check_used - check connection is already esablished or not
156 * @c: the connection manager to be checked 157 * @c: the connection manager to be checked
158 * @used: the pointer to store the result of checking the connection
157 */ 159 */
158int cmp_connection_check_used(struct cmp_connection *c, bool *used) 160int cmp_connection_check_used(struct cmp_connection *c, bool *used)
159{ 161{
diff --git a/sound/firewire/dice.c b/sound/firewire/dice.c
deleted file mode 100644
index e3a04d69c853..000000000000
--- a/sound/firewire/dice.c
+++ /dev/null
@@ -1,1511 +0,0 @@
1/*
2 * TC Applied Technologies Digital Interface Communications Engine driver
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include <linux/compat.h>
9#include <linux/completion.h>
10#include <linux/delay.h>
11#include <linux/device.h>
12#include <linux/firewire.h>
13#include <linux/firewire-constants.h>
14#include <linux/jiffies.h>
15#include <linux/module.h>
16#include <linux/mod_devicetable.h>
17#include <linux/mutex.h>
18#include <linux/slab.h>
19#include <linux/spinlock.h>
20#include <linux/wait.h>
21#include <sound/control.h>
22#include <sound/core.h>
23#include <sound/firewire.h>
24#include <sound/hwdep.h>
25#include <sound/info.h>
26#include <sound/initval.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include "amdtp.h"
30#include "iso-resources.h"
31#include "lib.h"
32#include "dice-interface.h"
33
34
35struct dice {
36 struct snd_card *card;
37 struct fw_unit *unit;
38 spinlock_t lock;
39 struct mutex mutex;
40 unsigned int global_offset;
41 unsigned int rx_offset;
42 unsigned int clock_caps;
43 unsigned int rx_channels[3];
44 unsigned int rx_midi_ports[3];
45 struct fw_address_handler notification_handler;
46 int owner_generation;
47 int dev_lock_count; /* > 0 driver, < 0 userspace */
48 bool dev_lock_changed;
49 bool global_enabled;
50 struct completion clock_accepted;
51 wait_queue_head_t hwdep_wait;
52 u32 notification_bits;
53 struct fw_iso_resources resources;
54 struct amdtp_stream stream;
55};
56
57MODULE_DESCRIPTION("DICE driver");
58MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
59MODULE_LICENSE("GPL v2");
60
61static const unsigned int dice_rates[] = {
62 /* mode 0 */
63 [0] = 32000,
64 [1] = 44100,
65 [2] = 48000,
66 /* mode 1 */
67 [3] = 88200,
68 [4] = 96000,
69 /* mode 2 */
70 [5] = 176400,
71 [6] = 192000,
72};
73
74static unsigned int rate_to_index(unsigned int rate)
75{
76 unsigned int i;
77
78 for (i = 0; i < ARRAY_SIZE(dice_rates); ++i)
79 if (dice_rates[i] == rate)
80 return i;
81
82 return 0;
83}
84
85static unsigned int rate_index_to_mode(unsigned int rate_index)
86{
87 return ((int)rate_index - 1) / 2;
88}
89
90static void dice_lock_changed(struct dice *dice)
91{
92 dice->dev_lock_changed = true;
93 wake_up(&dice->hwdep_wait);
94}
95
96static int dice_try_lock(struct dice *dice)
97{
98 int err;
99
100 spin_lock_irq(&dice->lock);
101
102 if (dice->dev_lock_count < 0) {
103 err = -EBUSY;
104 goto out;
105 }
106
107 if (dice->dev_lock_count++ == 0)
108 dice_lock_changed(dice);
109 err = 0;
110
111out:
112 spin_unlock_irq(&dice->lock);
113
114 return err;
115}
116
117static void dice_unlock(struct dice *dice)
118{
119 spin_lock_irq(&dice->lock);
120
121 if (WARN_ON(dice->dev_lock_count <= 0))
122 goto out;
123
124 if (--dice->dev_lock_count == 0)
125 dice_lock_changed(dice);
126
127out:
128 spin_unlock_irq(&dice->lock);
129}
130
131static inline u64 global_address(struct dice *dice, unsigned int offset)
132{
133 return DICE_PRIVATE_SPACE + dice->global_offset + offset;
134}
135
136// TODO: rx index
137static inline u64 rx_address(struct dice *dice, unsigned int offset)
138{
139 return DICE_PRIVATE_SPACE + dice->rx_offset + offset;
140}
141
142static int dice_owner_set(struct dice *dice)
143{
144 struct fw_device *device = fw_parent_device(dice->unit);
145 __be64 *buffer;
146 int err, errors = 0;
147
148 buffer = kmalloc(2 * 8, GFP_KERNEL);
149 if (!buffer)
150 return -ENOMEM;
151
152 for (;;) {
153 buffer[0] = cpu_to_be64(OWNER_NO_OWNER);
154 buffer[1] = cpu_to_be64(
155 ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
156 dice->notification_handler.offset);
157
158 dice->owner_generation = device->generation;
159 smp_rmb(); /* node_id vs. generation */
160 err = snd_fw_transaction(dice->unit,
161 TCODE_LOCK_COMPARE_SWAP,
162 global_address(dice, GLOBAL_OWNER),
163 buffer, 2 * 8,
164 FW_FIXED_GENERATION |
165 dice->owner_generation);
166
167 if (err == 0) {
168 if (buffer[0] != cpu_to_be64(OWNER_NO_OWNER)) {
169 dev_err(&dice->unit->device,
170 "device is already in use\n");
171 err = -EBUSY;
172 }
173 break;
174 }
175 if (err != -EAGAIN || ++errors >= 3)
176 break;
177
178 msleep(20);
179 }
180
181 kfree(buffer);
182
183 return err;
184}
185
186static int dice_owner_update(struct dice *dice)
187{
188 struct fw_device *device = fw_parent_device(dice->unit);
189 __be64 *buffer;
190 int err;
191
192 if (dice->owner_generation == -1)
193 return 0;
194
195 buffer = kmalloc(2 * 8, GFP_KERNEL);
196 if (!buffer)
197 return -ENOMEM;
198
199 buffer[0] = cpu_to_be64(OWNER_NO_OWNER);
200 buffer[1] = cpu_to_be64(
201 ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
202 dice->notification_handler.offset);
203
204 dice->owner_generation = device->generation;
205 smp_rmb(); /* node_id vs. generation */
206 err = snd_fw_transaction(dice->unit, TCODE_LOCK_COMPARE_SWAP,
207 global_address(dice, GLOBAL_OWNER),
208 buffer, 2 * 8,
209 FW_FIXED_GENERATION | dice->owner_generation);
210
211 if (err == 0) {
212 if (buffer[0] != cpu_to_be64(OWNER_NO_OWNER)) {
213 dev_err(&dice->unit->device,
214 "device is already in use\n");
215 err = -EBUSY;
216 }
217 } else if (err == -EAGAIN) {
218 err = 0; /* try again later */
219 }
220
221 kfree(buffer);
222
223 if (err < 0)
224 dice->owner_generation = -1;
225
226 return err;
227}
228
229static void dice_owner_clear(struct dice *dice)
230{
231 struct fw_device *device = fw_parent_device(dice->unit);
232 __be64 *buffer;
233
234 buffer = kmalloc(2 * 8, GFP_KERNEL);
235 if (!buffer)
236 return;
237
238 buffer[0] = cpu_to_be64(
239 ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
240 dice->notification_handler.offset);
241 buffer[1] = cpu_to_be64(OWNER_NO_OWNER);
242 snd_fw_transaction(dice->unit, TCODE_LOCK_COMPARE_SWAP,
243 global_address(dice, GLOBAL_OWNER),
244 buffer, 2 * 8, FW_QUIET |
245 FW_FIXED_GENERATION | dice->owner_generation);
246
247 kfree(buffer);
248
249 dice->owner_generation = -1;
250}
251
252static int dice_enable_set(struct dice *dice)
253{
254 __be32 value;
255 int err;
256
257 value = cpu_to_be32(1);
258 err = snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
259 global_address(dice, GLOBAL_ENABLE),
260 &value, 4,
261 FW_FIXED_GENERATION | dice->owner_generation);
262 if (err < 0)
263 return err;
264
265 dice->global_enabled = true;
266
267 return 0;
268}
269
270static void dice_enable_clear(struct dice *dice)
271{
272 __be32 value;
273
274 if (!dice->global_enabled)
275 return;
276
277 value = 0;
278 snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
279 global_address(dice, GLOBAL_ENABLE),
280 &value, 4, FW_QUIET |
281 FW_FIXED_GENERATION | dice->owner_generation);
282
283 dice->global_enabled = false;
284}
285
286static void dice_notification(struct fw_card *card, struct fw_request *request,
287 int tcode, int destination, int source,
288 int generation, unsigned long long offset,
289 void *data, size_t length, void *callback_data)
290{
291 struct dice *dice = callback_data;
292 u32 bits;
293 unsigned long flags;
294
295 if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
296 fw_send_response(card, request, RCODE_TYPE_ERROR);
297 return;
298 }
299 if ((offset & 3) != 0) {
300 fw_send_response(card, request, RCODE_ADDRESS_ERROR);
301 return;
302 }
303
304 bits = be32_to_cpup(data);
305
306 spin_lock_irqsave(&dice->lock, flags);
307 dice->notification_bits |= bits;
308 spin_unlock_irqrestore(&dice->lock, flags);
309
310 fw_send_response(card, request, RCODE_COMPLETE);
311
312 if (bits & NOTIFY_CLOCK_ACCEPTED)
313 complete(&dice->clock_accepted);
314 wake_up(&dice->hwdep_wait);
315}
316
317static int dice_rate_constraint(struct snd_pcm_hw_params *params,
318 struct snd_pcm_hw_rule *rule)
319{
320 struct dice *dice = rule->private;
321 const struct snd_interval *channels =
322 hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS);
323 struct snd_interval *rate =
324 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
325 struct snd_interval allowed_rates = {
326 .min = UINT_MAX, .max = 0, .integer = 1
327 };
328 unsigned int i, mode;
329
330 for (i = 0; i < ARRAY_SIZE(dice_rates); ++i) {
331 mode = rate_index_to_mode(i);
332 if ((dice->clock_caps & (1 << i)) &&
333 snd_interval_test(channels, dice->rx_channels[mode])) {
334 allowed_rates.min = min(allowed_rates.min,
335 dice_rates[i]);
336 allowed_rates.max = max(allowed_rates.max,
337 dice_rates[i]);
338 }
339 }
340
341 return snd_interval_refine(rate, &allowed_rates);
342}
343
344static int dice_channels_constraint(struct snd_pcm_hw_params *params,
345 struct snd_pcm_hw_rule *rule)
346{
347 struct dice *dice = rule->private;
348 const struct snd_interval *rate =
349 hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE);
350 struct snd_interval *channels =
351 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
352 struct snd_interval allowed_channels = {
353 .min = UINT_MAX, .max = 0, .integer = 1
354 };
355 unsigned int i, mode;
356
357 for (i = 0; i < ARRAY_SIZE(dice_rates); ++i)
358 if ((dice->clock_caps & (1 << i)) &&
359 snd_interval_test(rate, dice_rates[i])) {
360 mode = rate_index_to_mode(i);
361 allowed_channels.min = min(allowed_channels.min,
362 dice->rx_channels[mode]);
363 allowed_channels.max = max(allowed_channels.max,
364 dice->rx_channels[mode]);
365 }
366
367 return snd_interval_refine(channels, &allowed_channels);
368}
369
370static int dice_open(struct snd_pcm_substream *substream)
371{
372 static const struct snd_pcm_hardware hardware = {
373 .info = SNDRV_PCM_INFO_MMAP |
374 SNDRV_PCM_INFO_MMAP_VALID |
375 SNDRV_PCM_INFO_BATCH |
376 SNDRV_PCM_INFO_INTERLEAVED |
377 SNDRV_PCM_INFO_BLOCK_TRANSFER,
378 .formats = AMDTP_OUT_PCM_FORMAT_BITS,
379 .channels_min = UINT_MAX,
380 .channels_max = 0,
381 .buffer_bytes_max = 16 * 1024 * 1024,
382 .period_bytes_min = 1,
383 .period_bytes_max = UINT_MAX,
384 .periods_min = 1,
385 .periods_max = UINT_MAX,
386 };
387 struct dice *dice = substream->private_data;
388 struct snd_pcm_runtime *runtime = substream->runtime;
389 unsigned int i;
390 int err;
391
392 err = dice_try_lock(dice);
393 if (err < 0)
394 goto error;
395
396 runtime->hw = hardware;
397
398 for (i = 0; i < ARRAY_SIZE(dice_rates); ++i)
399 if (dice->clock_caps & (1 << i))
400 runtime->hw.rates |=
401 snd_pcm_rate_to_rate_bit(dice_rates[i]);
402 snd_pcm_limit_hw_rates(runtime);
403
404 for (i = 0; i < 3; ++i)
405 if (dice->rx_channels[i]) {
406 runtime->hw.channels_min = min(runtime->hw.channels_min,
407 dice->rx_channels[i]);
408 runtime->hw.channels_max = max(runtime->hw.channels_max,
409 dice->rx_channels[i]);
410 }
411
412 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
413 dice_rate_constraint, dice,
414 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
415 if (err < 0)
416 goto err_lock;
417 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
418 dice_channels_constraint, dice,
419 SNDRV_PCM_HW_PARAM_RATE, -1);
420 if (err < 0)
421 goto err_lock;
422
423 err = amdtp_stream_add_pcm_hw_constraints(&dice->stream, runtime);
424 if (err < 0)
425 goto err_lock;
426
427 return 0;
428
429err_lock:
430 dice_unlock(dice);
431error:
432 return err;
433}
434
435static int dice_close(struct snd_pcm_substream *substream)
436{
437 struct dice *dice = substream->private_data;
438
439 dice_unlock(dice);
440
441 return 0;
442}
443
444static int dice_stream_start_packets(struct dice *dice)
445{
446 int err;
447
448 if (amdtp_stream_running(&dice->stream))
449 return 0;
450
451 err = amdtp_stream_start(&dice->stream, dice->resources.channel,
452 fw_parent_device(dice->unit)->max_speed);
453 if (err < 0)
454 return err;
455
456 err = dice_enable_set(dice);
457 if (err < 0) {
458 amdtp_stream_stop(&dice->stream);
459 return err;
460 }
461
462 return 0;
463}
464
465static int dice_stream_start(struct dice *dice)
466{
467 __be32 channel;
468 int err;
469
470 if (!dice->resources.allocated) {
471 err = fw_iso_resources_allocate(&dice->resources,
472 amdtp_stream_get_max_payload(&dice->stream),
473 fw_parent_device(dice->unit)->max_speed);
474 if (err < 0)
475 goto error;
476
477 channel = cpu_to_be32(dice->resources.channel);
478 err = snd_fw_transaction(dice->unit,
479 TCODE_WRITE_QUADLET_REQUEST,
480 rx_address(dice, RX_ISOCHRONOUS),
481 &channel, 4, 0);
482 if (err < 0)
483 goto err_resources;
484 }
485
486 err = dice_stream_start_packets(dice);
487 if (err < 0)
488 goto err_rx_channel;
489
490 return 0;
491
492err_rx_channel:
493 channel = cpu_to_be32((u32)-1);
494 snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
495 rx_address(dice, RX_ISOCHRONOUS), &channel, 4, 0);
496err_resources:
497 fw_iso_resources_free(&dice->resources);
498error:
499 return err;
500}
501
502static void dice_stream_stop_packets(struct dice *dice)
503{
504 if (amdtp_stream_running(&dice->stream)) {
505 dice_enable_clear(dice);
506 amdtp_stream_stop(&dice->stream);
507 }
508}
509
510static void dice_stream_stop(struct dice *dice)
511{
512 __be32 channel;
513
514 dice_stream_stop_packets(dice);
515
516 if (!dice->resources.allocated)
517 return;
518
519 channel = cpu_to_be32((u32)-1);
520 snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
521 rx_address(dice, RX_ISOCHRONOUS), &channel, 4, 0);
522
523 fw_iso_resources_free(&dice->resources);
524}
525
526static int dice_change_rate(struct dice *dice, unsigned int clock_rate)
527{
528 __be32 value;
529 int err;
530
531 reinit_completion(&dice->clock_accepted);
532
533 value = cpu_to_be32(clock_rate | CLOCK_SOURCE_ARX1);
534 err = snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
535 global_address(dice, GLOBAL_CLOCK_SELECT),
536 &value, 4, 0);
537 if (err < 0)
538 return err;
539
540 if (!wait_for_completion_timeout(&dice->clock_accepted,
541 msecs_to_jiffies(100)))
542 dev_warn(&dice->unit->device, "clock change timed out\n");
543
544 return 0;
545}
546
547static int dice_hw_params(struct snd_pcm_substream *substream,
548 struct snd_pcm_hw_params *hw_params)
549{
550 struct dice *dice = substream->private_data;
551 unsigned int rate_index, mode, rate, channels, i;
552 int err;
553
554 mutex_lock(&dice->mutex);
555 dice_stream_stop(dice);
556 mutex_unlock(&dice->mutex);
557
558 err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
559 params_buffer_bytes(hw_params));
560 if (err < 0)
561 return err;
562
563 rate = params_rate(hw_params);
564 rate_index = rate_to_index(rate);
565 err = dice_change_rate(dice, rate_index << CLOCK_RATE_SHIFT);
566 if (err < 0)
567 return err;
568
569 /*
570 * At 176.4/192.0 kHz, Dice has a quirk to transfer two PCM frames in
571 * one data block of AMDTP packet. Thus sampling transfer frequency is
572 * a half of PCM sampling frequency, i.e. PCM frames at 192.0 kHz are
573 * transferred on AMDTP packets at 96 kHz. Two successive samples of a
574 * channel are stored consecutively in the packet. This quirk is called
575 * as 'Dual Wire'.
576 * For this quirk, blocking mode is required and PCM buffer size should
577 * be aligned to SYT_INTERVAL.
578 */
579 channels = params_channels(hw_params);
580 if (rate_index > 4) {
581 if (channels > AMDTP_MAX_CHANNELS_FOR_PCM / 2) {
582 err = -ENOSYS;
583 return err;
584 }
585
586 rate /= 2;
587 channels *= 2;
588 dice->stream.double_pcm_frames = true;
589 } else {
590 dice->stream.double_pcm_frames = false;
591 }
592
593 mode = rate_index_to_mode(rate_index);
594 amdtp_stream_set_parameters(&dice->stream, rate, channels,
595 dice->rx_midi_ports[mode]);
596 if (rate_index > 4) {
597 channels /= 2;
598
599 for (i = 0; i < channels; i++) {
600 dice->stream.pcm_positions[i] = i * 2;
601 dice->stream.pcm_positions[i + channels] = i * 2 + 1;
602 }
603 }
604
605 amdtp_stream_set_pcm_format(&dice->stream,
606 params_format(hw_params));
607
608 return 0;
609}
610
611static int dice_hw_free(struct snd_pcm_substream *substream)
612{
613 struct dice *dice = substream->private_data;
614
615 mutex_lock(&dice->mutex);
616 dice_stream_stop(dice);
617 mutex_unlock(&dice->mutex);
618
619 return snd_pcm_lib_free_vmalloc_buffer(substream);
620}
621
622static int dice_prepare(struct snd_pcm_substream *substream)
623{
624 struct dice *dice = substream->private_data;
625 int err;
626
627 mutex_lock(&dice->mutex);
628
629 if (amdtp_streaming_error(&dice->stream))
630 dice_stream_stop_packets(dice);
631
632 err = dice_stream_start(dice);
633 if (err < 0) {
634 mutex_unlock(&dice->mutex);
635 return err;
636 }
637
638 mutex_unlock(&dice->mutex);
639
640 amdtp_stream_pcm_prepare(&dice->stream);
641
642 return 0;
643}
644
645static int dice_trigger(struct snd_pcm_substream *substream, int cmd)
646{
647 struct dice *dice = substream->private_data;
648 struct snd_pcm_substream *pcm;
649
650 switch (cmd) {
651 case SNDRV_PCM_TRIGGER_START:
652 pcm = substream;
653 break;
654 case SNDRV_PCM_TRIGGER_STOP:
655 pcm = NULL;
656 break;
657 default:
658 return -EINVAL;
659 }
660 amdtp_stream_pcm_trigger(&dice->stream, pcm);
661
662 return 0;
663}
664
665static snd_pcm_uframes_t dice_pointer(struct snd_pcm_substream *substream)
666{
667 struct dice *dice = substream->private_data;
668
669 return amdtp_stream_pcm_pointer(&dice->stream);
670}
671
672static int dice_create_pcm(struct dice *dice)
673{
674 static struct snd_pcm_ops ops = {
675 .open = dice_open,
676 .close = dice_close,
677 .ioctl = snd_pcm_lib_ioctl,
678 .hw_params = dice_hw_params,
679 .hw_free = dice_hw_free,
680 .prepare = dice_prepare,
681 .trigger = dice_trigger,
682 .pointer = dice_pointer,
683 .page = snd_pcm_lib_get_vmalloc_page,
684 .mmap = snd_pcm_lib_mmap_vmalloc,
685 };
686 struct snd_pcm *pcm;
687 int err;
688
689 err = snd_pcm_new(dice->card, "DICE", 0, 1, 0, &pcm);
690 if (err < 0)
691 return err;
692 pcm->private_data = dice;
693 strcpy(pcm->name, dice->card->shortname);
694 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->ops = &ops;
695
696 return 0;
697}
698
699static long dice_hwdep_read(struct snd_hwdep *hwdep, char __user *buf,
700 long count, loff_t *offset)
701{
702 struct dice *dice = hwdep->private_data;
703 DEFINE_WAIT(wait);
704 union snd_firewire_event event;
705
706 spin_lock_irq(&dice->lock);
707
708 while (!dice->dev_lock_changed && dice->notification_bits == 0) {
709 prepare_to_wait(&dice->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
710 spin_unlock_irq(&dice->lock);
711 schedule();
712 finish_wait(&dice->hwdep_wait, &wait);
713 if (signal_pending(current))
714 return -ERESTARTSYS;
715 spin_lock_irq(&dice->lock);
716 }
717
718 memset(&event, 0, sizeof(event));
719 if (dice->dev_lock_changed) {
720 event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
721 event.lock_status.status = dice->dev_lock_count > 0;
722 dice->dev_lock_changed = false;
723
724 count = min(count, (long)sizeof(event.lock_status));
725 } else {
726 event.dice_notification.type = SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION;
727 event.dice_notification.notification = dice->notification_bits;
728 dice->notification_bits = 0;
729
730 count = min(count, (long)sizeof(event.dice_notification));
731 }
732
733 spin_unlock_irq(&dice->lock);
734
735 if (copy_to_user(buf, &event, count))
736 return -EFAULT;
737
738 return count;
739}
740
741static unsigned int dice_hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
742 poll_table *wait)
743{
744 struct dice *dice = hwdep->private_data;
745 unsigned int events;
746
747 poll_wait(file, &dice->hwdep_wait, wait);
748
749 spin_lock_irq(&dice->lock);
750 if (dice->dev_lock_changed || dice->notification_bits != 0)
751 events = POLLIN | POLLRDNORM;
752 else
753 events = 0;
754 spin_unlock_irq(&dice->lock);
755
756 return events;
757}
758
759static int dice_hwdep_get_info(struct dice *dice, void __user *arg)
760{
761 struct fw_device *dev = fw_parent_device(dice->unit);
762 struct snd_firewire_get_info info;
763
764 memset(&info, 0, sizeof(info));
765 info.type = SNDRV_FIREWIRE_TYPE_DICE;
766 info.card = dev->card->index;
767 *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);
768 *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);
769 strlcpy(info.device_name, dev_name(&dev->device),
770 sizeof(info.device_name));
771
772 if (copy_to_user(arg, &info, sizeof(info)))
773 return -EFAULT;
774
775 return 0;
776}
777
778static int dice_hwdep_lock(struct dice *dice)
779{
780 int err;
781
782 spin_lock_irq(&dice->lock);
783
784 if (dice->dev_lock_count == 0) {
785 dice->dev_lock_count = -1;
786 err = 0;
787 } else {
788 err = -EBUSY;
789 }
790
791 spin_unlock_irq(&dice->lock);
792
793 return err;
794}
795
796static int dice_hwdep_unlock(struct dice *dice)
797{
798 int err;
799
800 spin_lock_irq(&dice->lock);
801
802 if (dice->dev_lock_count == -1) {
803 dice->dev_lock_count = 0;
804 err = 0;
805 } else {
806 err = -EBADFD;
807 }
808
809 spin_unlock_irq(&dice->lock);
810
811 return err;
812}
813
814static int dice_hwdep_release(struct snd_hwdep *hwdep, struct file *file)
815{
816 struct dice *dice = hwdep->private_data;
817
818 spin_lock_irq(&dice->lock);
819 if (dice->dev_lock_count == -1)
820 dice->dev_lock_count = 0;
821 spin_unlock_irq(&dice->lock);
822
823 return 0;
824}
825
826static int dice_hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,
827 unsigned int cmd, unsigned long arg)
828{
829 struct dice *dice = hwdep->private_data;
830
831 switch (cmd) {
832 case SNDRV_FIREWIRE_IOCTL_GET_INFO:
833 return dice_hwdep_get_info(dice, (void __user *)arg);
834 case SNDRV_FIREWIRE_IOCTL_LOCK:
835 return dice_hwdep_lock(dice);
836 case SNDRV_FIREWIRE_IOCTL_UNLOCK:
837 return dice_hwdep_unlock(dice);
838 default:
839 return -ENOIOCTLCMD;
840 }
841}
842
843#ifdef CONFIG_COMPAT
844static int dice_hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
845 unsigned int cmd, unsigned long arg)
846{
847 return dice_hwdep_ioctl(hwdep, file, cmd,
848 (unsigned long)compat_ptr(arg));
849}
850#else
851#define dice_hwdep_compat_ioctl NULL
852#endif
853
854static int dice_create_hwdep(struct dice *dice)
855{
856 static const struct snd_hwdep_ops ops = {
857 .read = dice_hwdep_read,
858 .release = dice_hwdep_release,
859 .poll = dice_hwdep_poll,
860 .ioctl = dice_hwdep_ioctl,
861 .ioctl_compat = dice_hwdep_compat_ioctl,
862 };
863 struct snd_hwdep *hwdep;
864 int err;
865
866 err = snd_hwdep_new(dice->card, "DICE", 0, &hwdep);
867 if (err < 0)
868 return err;
869 strcpy(hwdep->name, "DICE");
870 hwdep->iface = SNDRV_HWDEP_IFACE_FW_DICE;
871 hwdep->ops = ops;
872 hwdep->private_data = dice;
873 hwdep->exclusive = true;
874
875 return 0;
876}
877
878static int dice_proc_read_mem(struct dice *dice, void *buffer,
879 unsigned int offset_q, unsigned int quadlets)
880{
881 unsigned int i;
882 int err;
883
884 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
885 DICE_PRIVATE_SPACE + 4 * offset_q,
886 buffer, 4 * quadlets, 0);
887 if (err < 0)
888 return err;
889
890 for (i = 0; i < quadlets; ++i)
891 be32_to_cpus(&((u32 *)buffer)[i]);
892
893 return 0;
894}
895
896static const char *str_from_array(const char *const strs[], unsigned int count,
897 unsigned int i)
898{
899 if (i < count)
900 return strs[i];
901 else
902 return "(unknown)";
903}
904
905static void dice_proc_fixup_string(char *s, unsigned int size)
906{
907 unsigned int i;
908
909 for (i = 0; i < size; i += 4)
910 cpu_to_le32s((u32 *)(s + i));
911
912 for (i = 0; i < size - 2; ++i) {
913 if (s[i] == '\0')
914 return;
915 if (s[i] == '\\' && s[i + 1] == '\\') {
916 s[i + 2] = '\0';
917 return;
918 }
919 }
920 s[size - 1] = '\0';
921}
922
923static void dice_proc_read(struct snd_info_entry *entry,
924 struct snd_info_buffer *buffer)
925{
926 static const char *const section_names[5] = {
927 "global", "tx", "rx", "ext_sync", "unused2"
928 };
929 static const char *const clock_sources[] = {
930 "aes1", "aes2", "aes3", "aes4", "aes", "adat", "tdif",
931 "wc", "arx1", "arx2", "arx3", "arx4", "internal"
932 };
933 static const char *const rates[] = {
934 "32000", "44100", "48000", "88200", "96000", "176400", "192000",
935 "any low", "any mid", "any high", "none"
936 };
937 struct dice *dice = entry->private_data;
938 u32 sections[ARRAY_SIZE(section_names) * 2];
939 struct {
940 u32 number;
941 u32 size;
942 } tx_rx_header;
943 union {
944 struct {
945 u32 owner_hi, owner_lo;
946 u32 notification;
947 char nick_name[NICK_NAME_SIZE];
948 u32 clock_select;
949 u32 enable;
950 u32 status;
951 u32 extended_status;
952 u32 sample_rate;
953 u32 version;
954 u32 clock_caps;
955 char clock_source_names[CLOCK_SOURCE_NAMES_SIZE];
956 } global;
957 struct {
958 u32 iso;
959 u32 number_audio;
960 u32 number_midi;
961 u32 speed;
962 char names[TX_NAMES_SIZE];
963 u32 ac3_caps;
964 u32 ac3_enable;
965 } tx;
966 struct {
967 u32 iso;
968 u32 seq_start;
969 u32 number_audio;
970 u32 number_midi;
971 char names[RX_NAMES_SIZE];
972 u32 ac3_caps;
973 u32 ac3_enable;
974 } rx;
975 struct {
976 u32 clock_source;
977 u32 locked;
978 u32 rate;
979 u32 adat_user_data;
980 } ext_sync;
981 } buf;
982 unsigned int quadlets, stream, i;
983
984 if (dice_proc_read_mem(dice, sections, 0, ARRAY_SIZE(sections)) < 0)
985 return;
986 snd_iprintf(buffer, "sections:\n");
987 for (i = 0; i < ARRAY_SIZE(section_names); ++i)
988 snd_iprintf(buffer, " %s: offset %u, size %u\n",
989 section_names[i],
990 sections[i * 2], sections[i * 2 + 1]);
991
992 quadlets = min_t(u32, sections[1], sizeof(buf.global) / 4);
993 if (dice_proc_read_mem(dice, &buf.global, sections[0], quadlets) < 0)
994 return;
995 snd_iprintf(buffer, "global:\n");
996 snd_iprintf(buffer, " owner: %04x:%04x%08x\n",
997 buf.global.owner_hi >> 16,
998 buf.global.owner_hi & 0xffff, buf.global.owner_lo);
999 snd_iprintf(buffer, " notification: %08x\n", buf.global.notification);
1000 dice_proc_fixup_string(buf.global.nick_name, NICK_NAME_SIZE);
1001 snd_iprintf(buffer, " nick name: %s\n", buf.global.nick_name);
1002 snd_iprintf(buffer, " clock select: %s %s\n",
1003 str_from_array(clock_sources, ARRAY_SIZE(clock_sources),
1004 buf.global.clock_select & CLOCK_SOURCE_MASK),
1005 str_from_array(rates, ARRAY_SIZE(rates),
1006 (buf.global.clock_select & CLOCK_RATE_MASK)
1007 >> CLOCK_RATE_SHIFT));
1008 snd_iprintf(buffer, " enable: %u\n", buf.global.enable);
1009 snd_iprintf(buffer, " status: %slocked %s\n",
1010 buf.global.status & STATUS_SOURCE_LOCKED ? "" : "un",
1011 str_from_array(rates, ARRAY_SIZE(rates),
1012 (buf.global.status &
1013 STATUS_NOMINAL_RATE_MASK)
1014 >> CLOCK_RATE_SHIFT));
1015 snd_iprintf(buffer, " ext status: %08x\n", buf.global.extended_status);
1016 snd_iprintf(buffer, " sample rate: %u\n", buf.global.sample_rate);
1017 snd_iprintf(buffer, " version: %u.%u.%u.%u\n",
1018 (buf.global.version >> 24) & 0xff,
1019 (buf.global.version >> 16) & 0xff,
1020 (buf.global.version >> 8) & 0xff,
1021 (buf.global.version >> 0) & 0xff);
1022 if (quadlets >= 90) {
1023 snd_iprintf(buffer, " clock caps:");
1024 for (i = 0; i <= 6; ++i)
1025 if (buf.global.clock_caps & (1 << i))
1026 snd_iprintf(buffer, " %s", rates[i]);
1027 for (i = 0; i <= 12; ++i)
1028 if (buf.global.clock_caps & (1 << (16 + i)))
1029 snd_iprintf(buffer, " %s", clock_sources[i]);
1030 snd_iprintf(buffer, "\n");
1031 dice_proc_fixup_string(buf.global.clock_source_names,
1032 CLOCK_SOURCE_NAMES_SIZE);
1033 snd_iprintf(buffer, " clock source names: %s\n",
1034 buf.global.clock_source_names);
1035 }
1036
1037 if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
1038 return;
1039 quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);
1040 for (stream = 0; stream < tx_rx_header.number; ++stream) {
1041 if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
1042 stream * tx_rx_header.size,
1043 quadlets) < 0)
1044 break;
1045 snd_iprintf(buffer, "tx %u:\n", stream);
1046 snd_iprintf(buffer, " iso channel: %d\n", (int)buf.tx.iso);
1047 snd_iprintf(buffer, " audio channels: %u\n",
1048 buf.tx.number_audio);
1049 snd_iprintf(buffer, " midi ports: %u\n", buf.tx.number_midi);
1050 snd_iprintf(buffer, " speed: S%u\n", 100u << buf.tx.speed);
1051 if (quadlets >= 68) {
1052 dice_proc_fixup_string(buf.tx.names, TX_NAMES_SIZE);
1053 snd_iprintf(buffer, " names: %s\n", buf.tx.names);
1054 }
1055 if (quadlets >= 70) {
1056 snd_iprintf(buffer, " ac3 caps: %08x\n",
1057 buf.tx.ac3_caps);
1058 snd_iprintf(buffer, " ac3 enable: %08x\n",
1059 buf.tx.ac3_enable);
1060 }
1061 }
1062
1063 if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
1064 return;
1065 quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
1066 for (stream = 0; stream < tx_rx_header.number; ++stream) {
1067 if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
1068 stream * tx_rx_header.size,
1069 quadlets) < 0)
1070 break;
1071 snd_iprintf(buffer, "rx %u:\n", stream);
1072 snd_iprintf(buffer, " iso channel: %d\n", (int)buf.rx.iso);
1073 snd_iprintf(buffer, " sequence start: %u\n", buf.rx.seq_start);
1074 snd_iprintf(buffer, " audio channels: %u\n",
1075 buf.rx.number_audio);
1076 snd_iprintf(buffer, " midi ports: %u\n", buf.rx.number_midi);
1077 if (quadlets >= 68) {
1078 dice_proc_fixup_string(buf.rx.names, RX_NAMES_SIZE);
1079 snd_iprintf(buffer, " names: %s\n", buf.rx.names);
1080 }
1081 if (quadlets >= 70) {
1082 snd_iprintf(buffer, " ac3 caps: %08x\n",
1083 buf.rx.ac3_caps);
1084 snd_iprintf(buffer, " ac3 enable: %08x\n",
1085 buf.rx.ac3_enable);
1086 }
1087 }
1088
1089 quadlets = min_t(u32, sections[7], sizeof(buf.ext_sync) / 4);
1090 if (quadlets >= 4) {
1091 if (dice_proc_read_mem(dice, &buf.ext_sync,
1092 sections[6], 4) < 0)
1093 return;
1094 snd_iprintf(buffer, "ext status:\n");
1095 snd_iprintf(buffer, " clock source: %s\n",
1096 str_from_array(clock_sources,
1097 ARRAY_SIZE(clock_sources),
1098 buf.ext_sync.clock_source));
1099 snd_iprintf(buffer, " locked: %u\n", buf.ext_sync.locked);
1100 snd_iprintf(buffer, " rate: %s\n",
1101 str_from_array(rates, ARRAY_SIZE(rates),
1102 buf.ext_sync.rate));
1103 snd_iprintf(buffer, " adat user data: ");
1104 if (buf.ext_sync.adat_user_data & ADAT_USER_DATA_NO_DATA)
1105 snd_iprintf(buffer, "-\n");
1106 else
1107 snd_iprintf(buffer, "%x\n",
1108 buf.ext_sync.adat_user_data);
1109 }
1110}
1111
1112static void dice_create_proc(struct dice *dice)
1113{
1114 struct snd_info_entry *entry;
1115
1116 if (!snd_card_proc_new(dice->card, "dice", &entry))
1117 snd_info_set_text_ops(entry, dice, dice_proc_read);
1118}
1119
1120static void dice_card_free(struct snd_card *card)
1121{
1122 struct dice *dice = card->private_data;
1123
1124 amdtp_stream_destroy(&dice->stream);
1125 fw_core_remove_address_handler(&dice->notification_handler);
1126 mutex_destroy(&dice->mutex);
1127}
1128
1129#define OUI_WEISS 0x001c6a
1130
1131#define DICE_CATEGORY_ID 0x04
1132#define WEISS_CATEGORY_ID 0x00
1133
1134static int dice_interface_check(struct fw_unit *unit)
1135{
1136 static const int min_values[10] = {
1137 10, 0x64 / 4,
1138 10, 0x18 / 4,
1139 10, 0x18 / 4,
1140 0, 0,
1141 0, 0,
1142 };
1143 struct fw_device *device = fw_parent_device(unit);
1144 struct fw_csr_iterator it;
1145 int key, value, vendor = -1, model = -1, err;
1146 unsigned int category, i;
1147 __be32 pointers[ARRAY_SIZE(min_values)];
1148 __be32 tx_data[4];
1149 __be32 version;
1150
1151 /*
1152 * Check that GUID and unit directory are constructed according to DICE
1153 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
1154 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
1155 * ID, and a 22-bit serial number.
1156 */
1157 fw_csr_iterator_init(&it, unit->directory);
1158 while (fw_csr_iterator_next(&it, &key, &value)) {
1159 switch (key) {
1160 case CSR_SPECIFIER_ID:
1161 vendor = value;
1162 break;
1163 case CSR_MODEL:
1164 model = value;
1165 break;
1166 }
1167 }
1168 if (vendor == OUI_WEISS)
1169 category = WEISS_CATEGORY_ID;
1170 else
1171 category = DICE_CATEGORY_ID;
1172 if (device->config_rom[3] != ((vendor << 8) | category) ||
1173 device->config_rom[4] >> 22 != model)
1174 return -ENODEV;
1175
1176 /*
1177 * Check that the sub address spaces exist and are located inside the
1178 * private address space. The minimum values are chosen so that all
1179 * minimally required registers are included.
1180 */
1181 err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
1182 DICE_PRIVATE_SPACE,
1183 pointers, sizeof(pointers), 0);
1184 if (err < 0)
1185 return -ENODEV;
1186 for (i = 0; i < ARRAY_SIZE(pointers); ++i) {
1187 value = be32_to_cpu(pointers[i]);
1188 if (value < min_values[i] || value >= 0x40000)
1189 return -ENODEV;
1190 }
1191
1192 /* We support playback only. Let capture devices be handled by FFADO. */
1193 err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
1194 DICE_PRIVATE_SPACE +
1195 be32_to_cpu(pointers[2]) * 4,
1196 tx_data, sizeof(tx_data), 0);
1197 if (err < 0 || (tx_data[0] && tx_data[3]))
1198 return -ENODEV;
1199
1200 /*
1201 * Check that the implemented DICE driver specification major version
1202 * number matches.
1203 */
1204 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
1205 DICE_PRIVATE_SPACE +
1206 be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION,
1207 &version, 4, 0);
1208 if (err < 0)
1209 return -ENODEV;
1210 if ((version & cpu_to_be32(0xff000000)) != cpu_to_be32(0x01000000)) {
1211 dev_err(&unit->device,
1212 "unknown DICE version: 0x%08x\n", be32_to_cpu(version));
1213 return -ENODEV;
1214 }
1215
1216 return 0;
1217}
1218
1219static int highest_supported_mode_rate(struct dice *dice, unsigned int mode)
1220{
1221 int i;
1222
1223 for (i = ARRAY_SIZE(dice_rates) - 1; i >= 0; --i)
1224 if ((dice->clock_caps & (1 << i)) &&
1225 rate_index_to_mode(i) == mode)
1226 return i;
1227
1228 return -1;
1229}
1230
1231static int dice_read_mode_params(struct dice *dice, unsigned int mode)
1232{
1233 __be32 values[2];
1234 int rate_index, err;
1235
1236 rate_index = highest_supported_mode_rate(dice, mode);
1237 if (rate_index < 0) {
1238 dice->rx_channels[mode] = 0;
1239 dice->rx_midi_ports[mode] = 0;
1240 return 0;
1241 }
1242
1243 err = dice_change_rate(dice, rate_index << CLOCK_RATE_SHIFT);
1244 if (err < 0)
1245 return err;
1246
1247 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
1248 rx_address(dice, RX_NUMBER_AUDIO),
1249 values, 2 * 4, 0);
1250 if (err < 0)
1251 return err;
1252
1253 dice->rx_channels[mode] = be32_to_cpu(values[0]);
1254 dice->rx_midi_ports[mode] = be32_to_cpu(values[1]);
1255
1256 return 0;
1257}
1258
1259static int dice_read_params(struct dice *dice)
1260{
1261 __be32 pointers[6];
1262 __be32 value;
1263 int mode, err;
1264
1265 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
1266 DICE_PRIVATE_SPACE,
1267 pointers, sizeof(pointers), 0);
1268 if (err < 0)
1269 return err;
1270
1271 dice->global_offset = be32_to_cpu(pointers[0]) * 4;
1272 dice->rx_offset = be32_to_cpu(pointers[4]) * 4;
1273
1274 /* some very old firmwares don't tell about their clock support */
1275 if (be32_to_cpu(pointers[1]) * 4 >= GLOBAL_CLOCK_CAPABILITIES + 4) {
1276 err = snd_fw_transaction(
1277 dice->unit, TCODE_READ_QUADLET_REQUEST,
1278 global_address(dice, GLOBAL_CLOCK_CAPABILITIES),
1279 &value, 4, 0);
1280 if (err < 0)
1281 return err;
1282 dice->clock_caps = be32_to_cpu(value);
1283 } else {
1284 /* this should be supported by any device */
1285 dice->clock_caps = CLOCK_CAP_RATE_44100 |
1286 CLOCK_CAP_RATE_48000 |
1287 CLOCK_CAP_SOURCE_ARX1 |
1288 CLOCK_CAP_SOURCE_INTERNAL;
1289 }
1290
1291 for (mode = 2; mode >= 0; --mode) {
1292 err = dice_read_mode_params(dice, mode);
1293 if (err < 0)
1294 return err;
1295 }
1296
1297 return 0;
1298}
1299
1300static void dice_card_strings(struct dice *dice)
1301{
1302 struct snd_card *card = dice->card;
1303 struct fw_device *dev = fw_parent_device(dice->unit);
1304 char vendor[32], model[32];
1305 unsigned int i;
1306 int err;
1307
1308 strcpy(card->driver, "DICE");
1309
1310 strcpy(card->shortname, "DICE");
1311 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
1312 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
1313 global_address(dice, GLOBAL_NICK_NAME),
1314 card->shortname, sizeof(card->shortname), 0);
1315 if (err >= 0) {
1316 /* DICE strings are returned in "always-wrong" endianness */
1317 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
1318 for (i = 0; i < sizeof(card->shortname); i += 4)
1319 swab32s((u32 *)&card->shortname[i]);
1320 card->shortname[sizeof(card->shortname) - 1] = '\0';
1321 }
1322
1323 strcpy(vendor, "?");
1324 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
1325 strcpy(model, "?");
1326 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
1327 snprintf(card->longname, sizeof(card->longname),
1328 "%s %s (serial %u) at %s, S%d",
1329 vendor, model, dev->config_rom[4] & 0x3fffff,
1330 dev_name(&dice->unit->device), 100 << dev->max_speed);
1331
1332 strcpy(card->mixername, "DICE");
1333}
1334
1335static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
1336{
1337 struct snd_card *card;
1338 struct dice *dice;
1339 __be32 clock_sel;
1340 int err;
1341
1342 err = dice_interface_check(unit);
1343 if (err < 0)
1344 return err;
1345
1346 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
1347 sizeof(*dice), &card);
1348 if (err < 0)
1349 return err;
1350
1351 dice = card->private_data;
1352 dice->card = card;
1353 spin_lock_init(&dice->lock);
1354 mutex_init(&dice->mutex);
1355 dice->unit = unit;
1356 init_completion(&dice->clock_accepted);
1357 init_waitqueue_head(&dice->hwdep_wait);
1358
1359 dice->notification_handler.length = 4;
1360 dice->notification_handler.address_callback = dice_notification;
1361 dice->notification_handler.callback_data = dice;
1362 err = fw_core_add_address_handler(&dice->notification_handler,
1363 &fw_high_memory_region);
1364 if (err < 0)
1365 goto err_mutex;
1366
1367 err = dice_owner_set(dice);
1368 if (err < 0)
1369 goto err_notification_handler;
1370
1371 err = dice_read_params(dice);
1372 if (err < 0)
1373 goto err_owner;
1374
1375 err = fw_iso_resources_init(&dice->resources, unit);
1376 if (err < 0)
1377 goto err_owner;
1378 dice->resources.channels_mask = 0x00000000ffffffffuLL;
1379
1380 err = amdtp_stream_init(&dice->stream, unit, AMDTP_OUT_STREAM,
1381 CIP_BLOCKING);
1382 if (err < 0)
1383 goto err_resources;
1384
1385 card->private_free = dice_card_free;
1386
1387 dice_card_strings(dice);
1388
1389 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
1390 global_address(dice, GLOBAL_CLOCK_SELECT),
1391 &clock_sel, 4, 0);
1392 if (err < 0)
1393 goto error;
1394 clock_sel &= cpu_to_be32(~CLOCK_SOURCE_MASK);
1395 clock_sel |= cpu_to_be32(CLOCK_SOURCE_ARX1);
1396 err = snd_fw_transaction(unit, TCODE_WRITE_QUADLET_REQUEST,
1397 global_address(dice, GLOBAL_CLOCK_SELECT),
1398 &clock_sel, 4, 0);
1399 if (err < 0)
1400 goto error;
1401
1402 err = dice_create_pcm(dice);
1403 if (err < 0)
1404 goto error;
1405
1406 err = dice_create_hwdep(dice);
1407 if (err < 0)
1408 goto error;
1409
1410 dice_create_proc(dice);
1411
1412 err = snd_card_register(card);
1413 if (err < 0)
1414 goto error;
1415
1416 dev_set_drvdata(&unit->device, dice);
1417
1418 return 0;
1419
1420err_resources:
1421 fw_iso_resources_destroy(&dice->resources);
1422err_owner:
1423 dice_owner_clear(dice);
1424err_notification_handler:
1425 fw_core_remove_address_handler(&dice->notification_handler);
1426err_mutex:
1427 mutex_destroy(&dice->mutex);
1428error:
1429 snd_card_free(card);
1430 return err;
1431}
1432
1433static void dice_remove(struct fw_unit *unit)
1434{
1435 struct dice *dice = dev_get_drvdata(&unit->device);
1436
1437 amdtp_stream_pcm_abort(&dice->stream);
1438
1439 snd_card_disconnect(dice->card);
1440
1441 mutex_lock(&dice->mutex);
1442
1443 dice_stream_stop(dice);
1444 dice_owner_clear(dice);
1445
1446 mutex_unlock(&dice->mutex);
1447
1448 snd_card_free_when_closed(dice->card);
1449}
1450
1451static void dice_bus_reset(struct fw_unit *unit)
1452{
1453 struct dice *dice = dev_get_drvdata(&unit->device);
1454
1455 /*
1456 * On a bus reset, the DICE firmware disables streaming and then goes
1457 * off contemplating its own navel for hundreds of milliseconds before
1458 * it can react to any of our attempts to reenable streaming. This
1459 * means that we lose synchronization anyway, so we force our streams
1460 * to stop so that the application can restart them in an orderly
1461 * manner.
1462 */
1463 amdtp_stream_pcm_abort(&dice->stream);
1464
1465 mutex_lock(&dice->mutex);
1466
1467 dice->global_enabled = false;
1468 dice_stream_stop_packets(dice);
1469
1470 dice_owner_update(dice);
1471
1472 fw_iso_resources_update(&dice->resources);
1473
1474 mutex_unlock(&dice->mutex);
1475}
1476
1477#define DICE_INTERFACE 0x000001
1478
1479static const struct ieee1394_device_id dice_id_table[] = {
1480 {
1481 .match_flags = IEEE1394_MATCH_VERSION,
1482 .version = DICE_INTERFACE,
1483 },
1484 { }
1485};
1486MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
1487
1488static struct fw_driver dice_driver = {
1489 .driver = {
1490 .owner = THIS_MODULE,
1491 .name = KBUILD_MODNAME,
1492 .bus = &fw_bus_type,
1493 },
1494 .probe = dice_probe,
1495 .update = dice_bus_reset,
1496 .remove = dice_remove,
1497 .id_table = dice_id_table,
1498};
1499
1500static int __init alsa_dice_init(void)
1501{
1502 return driver_register(&dice_driver.driver);
1503}
1504
1505static void __exit alsa_dice_exit(void)
1506{
1507 driver_unregister(&dice_driver.driver);
1508}
1509
1510module_init(alsa_dice_init);
1511module_exit(alsa_dice_exit);
diff --git a/sound/firewire/dice/Makefile b/sound/firewire/dice/Makefile
new file mode 100644
index 000000000000..9ef228ef7baf
--- /dev/null
+++ b/sound/firewire/dice/Makefile
@@ -0,0 +1,3 @@
1snd-dice-objs := dice-transaction.o dice-stream.o dice-proc.o dice-midi.o \
2 dice-pcm.o dice-hwdep.o dice.o
3obj-m += snd-dice.o
diff --git a/sound/firewire/dice/dice-hwdep.c b/sound/firewire/dice/dice-hwdep.c
new file mode 100644
index 000000000000..a4dc02a86f12
--- /dev/null
+++ b/sound/firewire/dice/dice-hwdep.c
@@ -0,0 +1,190 @@
1/*
2 * dice_hwdep.c - a part of driver for DICE based devices
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Copyright (c) 2014 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 *
7 * Licensed under the terms of the GNU General Public License, version 2.
8 */
9
10#include "dice.h"
11
12static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf,
13 long count, loff_t *offset)
14{
15 struct snd_dice *dice = hwdep->private_data;
16 DEFINE_WAIT(wait);
17 union snd_firewire_event event;
18
19 spin_lock_irq(&dice->lock);
20
21 while (!dice->dev_lock_changed && dice->notification_bits == 0) {
22 prepare_to_wait(&dice->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
23 spin_unlock_irq(&dice->lock);
24 schedule();
25 finish_wait(&dice->hwdep_wait, &wait);
26 if (signal_pending(current))
27 return -ERESTARTSYS;
28 spin_lock_irq(&dice->lock);
29 }
30
31 memset(&event, 0, sizeof(event));
32 if (dice->dev_lock_changed) {
33 event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
34 event.lock_status.status = dice->dev_lock_count > 0;
35 dice->dev_lock_changed = false;
36
37 count = min_t(long, count, sizeof(event.lock_status));
38 } else {
39 event.dice_notification.type =
40 SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION;
41 event.dice_notification.notification = dice->notification_bits;
42 dice->notification_bits = 0;
43
44 count = min_t(long, count, sizeof(event.dice_notification));
45 }
46
47 spin_unlock_irq(&dice->lock);
48
49 if (copy_to_user(buf, &event, count))
50 return -EFAULT;
51
52 return count;
53}
54
55static unsigned int hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
56 poll_table *wait)
57{
58 struct snd_dice *dice = hwdep->private_data;
59 unsigned int events;
60
61 poll_wait(file, &dice->hwdep_wait, wait);
62
63 spin_lock_irq(&dice->lock);
64 if (dice->dev_lock_changed || dice->notification_bits != 0)
65 events = POLLIN | POLLRDNORM;
66 else
67 events = 0;
68 spin_unlock_irq(&dice->lock);
69
70 return events;
71}
72
73static int hwdep_get_info(struct snd_dice *dice, void __user *arg)
74{
75 struct fw_device *dev = fw_parent_device(dice->unit);
76 struct snd_firewire_get_info info;
77
78 memset(&info, 0, sizeof(info));
79 info.type = SNDRV_FIREWIRE_TYPE_DICE;
80 info.card = dev->card->index;
81 *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);
82 *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);
83 strlcpy(info.device_name, dev_name(&dev->device),
84 sizeof(info.device_name));
85
86 if (copy_to_user(arg, &info, sizeof(info)))
87 return -EFAULT;
88
89 return 0;
90}
91
92static int hwdep_lock(struct snd_dice *dice)
93{
94 int err;
95
96 spin_lock_irq(&dice->lock);
97
98 if (dice->dev_lock_count == 0) {
99 dice->dev_lock_count = -1;
100 err = 0;
101 } else {
102 err = -EBUSY;
103 }
104
105 spin_unlock_irq(&dice->lock);
106
107 return err;
108}
109
110static int hwdep_unlock(struct snd_dice *dice)
111{
112 int err;
113
114 spin_lock_irq(&dice->lock);
115
116 if (dice->dev_lock_count == -1) {
117 dice->dev_lock_count = 0;
118 err = 0;
119 } else {
120 err = -EBADFD;
121 }
122
123 spin_unlock_irq(&dice->lock);
124
125 return err;
126}
127
128static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
129{
130 struct snd_dice *dice = hwdep->private_data;
131
132 spin_lock_irq(&dice->lock);
133 if (dice->dev_lock_count == -1)
134 dice->dev_lock_count = 0;
135 spin_unlock_irq(&dice->lock);
136
137 return 0;
138}
139
140static int hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,
141 unsigned int cmd, unsigned long arg)
142{
143 struct snd_dice *dice = hwdep->private_data;
144
145 switch (cmd) {
146 case SNDRV_FIREWIRE_IOCTL_GET_INFO:
147 return hwdep_get_info(dice, (void __user *)arg);
148 case SNDRV_FIREWIRE_IOCTL_LOCK:
149 return hwdep_lock(dice);
150 case SNDRV_FIREWIRE_IOCTL_UNLOCK:
151 return hwdep_unlock(dice);
152 default:
153 return -ENOIOCTLCMD;
154 }
155}
156
157#ifdef CONFIG_COMPAT
158static int hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
159 unsigned int cmd, unsigned long arg)
160{
161 return hwdep_ioctl(hwdep, file, cmd,
162 (unsigned long)compat_ptr(arg));
163}
164#else
165#define hwdep_compat_ioctl NULL
166#endif
167
168int snd_dice_create_hwdep(struct snd_dice *dice)
169{
170 static const struct snd_hwdep_ops ops = {
171 .read = hwdep_read,
172 .release = hwdep_release,
173 .poll = hwdep_poll,
174 .ioctl = hwdep_ioctl,
175 .ioctl_compat = hwdep_compat_ioctl,
176 };
177 struct snd_hwdep *hwdep;
178 int err;
179
180 err = snd_hwdep_new(dice->card, "DICE", 0, &hwdep);
181 if (err < 0)
182 return err;
183 strcpy(hwdep->name, "DICE");
184 hwdep->iface = SNDRV_HWDEP_IFACE_FW_DICE;
185 hwdep->ops = ops;
186 hwdep->private_data = dice;
187 hwdep->exclusive = true;
188
189 return 0;
190}
diff --git a/sound/firewire/dice-interface.h b/sound/firewire/dice/dice-interface.h
index 27b044f84c81..27b044f84c81 100644
--- a/sound/firewire/dice-interface.h
+++ b/sound/firewire/dice/dice-interface.h
diff --git a/sound/firewire/dice/dice-midi.c b/sound/firewire/dice/dice-midi.c
new file mode 100644
index 000000000000..fe43ce791f84
--- /dev/null
+++ b/sound/firewire/dice/dice-midi.c
@@ -0,0 +1,157 @@
1/*
2 * dice_midi.c - a part of driver for Dice based devices
3 *
4 * Copyright (c) 2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8#include "dice.h"
9
10static int midi_open(struct snd_rawmidi_substream *substream)
11{
12 struct snd_dice *dice = substream->rmidi->private_data;
13 int err;
14
15 err = snd_dice_stream_lock_try(dice);
16 if (err < 0)
17 return err;
18
19 mutex_lock(&dice->mutex);
20
21 dice->substreams_counter++;
22 err = snd_dice_stream_start_duplex(dice, 0);
23
24 mutex_unlock(&dice->mutex);
25
26 if (err < 0)
27 snd_dice_stream_lock_release(dice);
28
29 return err;
30}
31
32static int midi_close(struct snd_rawmidi_substream *substream)
33{
34 struct snd_dice *dice = substream->rmidi->private_data;
35
36 mutex_lock(&dice->mutex);
37
38 dice->substreams_counter--;
39 snd_dice_stream_stop_duplex(dice);
40
41 mutex_unlock(&dice->mutex);
42
43 snd_dice_stream_lock_release(dice);
44 return 0;
45}
46
47static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
48{
49 struct snd_dice *dice = substrm->rmidi->private_data;
50 unsigned long flags;
51
52 spin_lock_irqsave(&dice->lock, flags);
53
54 if (up)
55 amdtp_stream_midi_trigger(&dice->tx_stream,
56 substrm->number, substrm);
57 else
58 amdtp_stream_midi_trigger(&dice->tx_stream,
59 substrm->number, NULL);
60
61 spin_unlock_irqrestore(&dice->lock, flags);
62}
63
64static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
65{
66 struct snd_dice *dice = substrm->rmidi->private_data;
67 unsigned long flags;
68
69 spin_lock_irqsave(&dice->lock, flags);
70
71 if (up)
72 amdtp_stream_midi_trigger(&dice->rx_stream,
73 substrm->number, substrm);
74 else
75 amdtp_stream_midi_trigger(&dice->rx_stream,
76 substrm->number, NULL);
77
78 spin_unlock_irqrestore(&dice->lock, flags);
79}
80
81static struct snd_rawmidi_ops capture_ops = {
82 .open = midi_open,
83 .close = midi_close,
84 .trigger = midi_capture_trigger,
85};
86
87static struct snd_rawmidi_ops playback_ops = {
88 .open = midi_open,
89 .close = midi_close,
90 .trigger = midi_playback_trigger,
91};
92
93static void set_midi_substream_names(struct snd_dice *dice,
94 struct snd_rawmidi_str *str)
95{
96 struct snd_rawmidi_substream *subs;
97
98 list_for_each_entry(subs, &str->substreams, list) {
99 snprintf(subs->name, sizeof(subs->name),
100 "%s MIDI %d", dice->card->shortname, subs->number + 1);
101 }
102}
103
104int snd_dice_create_midi(struct snd_dice *dice)
105{
106 struct snd_rawmidi *rmidi;
107 struct snd_rawmidi_str *str;
108 unsigned int i, midi_in_ports, midi_out_ports;
109 int err;
110
111 midi_in_ports = midi_out_ports = 0;
112 for (i = 0; i < 3; i++) {
113 midi_in_ports = max(dice->tx_midi_ports[i], midi_in_ports);
114 midi_out_ports = max(dice->rx_midi_ports[i], midi_out_ports);
115 }
116
117 if (midi_in_ports + midi_out_ports == 0)
118 return 0;
119
120 /* create midi ports */
121 err = snd_rawmidi_new(dice->card, dice->card->driver, 0,
122 midi_out_ports, midi_in_ports,
123 &rmidi);
124 if (err < 0)
125 return err;
126
127 snprintf(rmidi->name, sizeof(rmidi->name),
128 "%s MIDI", dice->card->shortname);
129 rmidi->private_data = dice;
130
131 if (midi_in_ports > 0) {
132 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
133
134 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
135 &capture_ops);
136
137 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT];
138
139 set_midi_substream_names(dice, str);
140 }
141
142 if (midi_out_ports > 0) {
143 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
144
145 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
146 &playback_ops);
147
148 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT];
149
150 set_midi_substream_names(dice, str);
151 }
152
153 if ((midi_out_ports > 0) && (midi_in_ports > 0))
154 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
155
156 return 0;
157}
diff --git a/sound/firewire/dice/dice-pcm.c b/sound/firewire/dice/dice-pcm.c
new file mode 100644
index 000000000000..f77714511f8b
--- /dev/null
+++ b/sound/firewire/dice/dice-pcm.c
@@ -0,0 +1,422 @@
1/*
2 * dice_pcm.c - a part of driver for DICE based devices
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Copyright (c) 2014 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 *
7 * Licensed under the terms of the GNU General Public License, version 2.
8 */
9
10#include "dice.h"
11
12static int dice_rate_constraint(struct snd_pcm_hw_params *params,
13 struct snd_pcm_hw_rule *rule)
14{
15 struct snd_pcm_substream *substream = rule->private;
16 struct snd_dice *dice = substream->private_data;
17
18 const struct snd_interval *c =
19 hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS);
20 struct snd_interval *r =
21 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
22 struct snd_interval rates = {
23 .min = UINT_MAX, .max = 0, .integer = 1
24 };
25 unsigned int i, rate, mode, *pcm_channels;
26
27 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
28 pcm_channels = dice->tx_channels;
29 else
30 pcm_channels = dice->rx_channels;
31
32 for (i = 0; i < ARRAY_SIZE(snd_dice_rates); ++i) {
33 rate = snd_dice_rates[i];
34 if (snd_dice_stream_get_rate_mode(dice, rate, &mode) < 0)
35 continue;
36
37 if (!snd_interval_test(c, pcm_channels[mode]))
38 continue;
39
40 rates.min = min(rates.min, rate);
41 rates.max = max(rates.max, rate);
42 }
43
44 return snd_interval_refine(r, &rates);
45}
46
47static int dice_channels_constraint(struct snd_pcm_hw_params *params,
48 struct snd_pcm_hw_rule *rule)
49{
50 struct snd_pcm_substream *substream = rule->private;
51 struct snd_dice *dice = substream->private_data;
52
53 const struct snd_interval *r =
54 hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE);
55 struct snd_interval *c =
56 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
57 struct snd_interval channels = {
58 .min = UINT_MAX, .max = 0, .integer = 1
59 };
60 unsigned int i, rate, mode, *pcm_channels;
61
62 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
63 pcm_channels = dice->tx_channels;
64 else
65 pcm_channels = dice->rx_channels;
66
67 for (i = 0; i < ARRAY_SIZE(snd_dice_rates); ++i) {
68 rate = snd_dice_rates[i];
69 if (snd_dice_stream_get_rate_mode(dice, rate, &mode) < 0)
70 continue;
71
72 if (!snd_interval_test(r, rate))
73 continue;
74
75 channels.min = min(channels.min, pcm_channels[mode]);
76 channels.max = max(channels.max, pcm_channels[mode]);
77 }
78
79 return snd_interval_refine(c, &channels);
80}
81
82static void limit_channels_and_rates(struct snd_dice *dice,
83 struct snd_pcm_runtime *runtime,
84 unsigned int *pcm_channels)
85{
86 struct snd_pcm_hardware *hw = &runtime->hw;
87 unsigned int i, rate, mode;
88
89 hw->channels_min = UINT_MAX;
90 hw->channels_max = 0;
91
92 for (i = 0; i < ARRAY_SIZE(snd_dice_rates); ++i) {
93 rate = snd_dice_rates[i];
94 if (snd_dice_stream_get_rate_mode(dice, rate, &mode) < 0)
95 continue;
96 hw->rates |= snd_pcm_rate_to_rate_bit(rate);
97
98 if (pcm_channels[mode] == 0)
99 continue;
100 hw->channels_min = min(hw->channels_min, pcm_channels[mode]);
101 hw->channels_max = max(hw->channels_max, pcm_channels[mode]);
102 }
103
104 snd_pcm_limit_hw_rates(runtime);
105}
106
107static void limit_period_and_buffer(struct snd_pcm_hardware *hw)
108{
109 hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */
110 hw->periods_max = UINT_MAX;
111
112 hw->period_bytes_min = 4 * hw->channels_max; /* byte for a frame */
113
114 /* Just to prevent from allocating much pages. */
115 hw->period_bytes_max = hw->period_bytes_min * 2048;
116 hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
117}
118
119static int init_hw_info(struct snd_dice *dice,
120 struct snd_pcm_substream *substream)
121{
122 struct snd_pcm_runtime *runtime = substream->runtime;
123 struct snd_pcm_hardware *hw = &runtime->hw;
124 struct amdtp_stream *stream;
125 unsigned int *pcm_channels;
126 int err;
127
128 hw->info = SNDRV_PCM_INFO_MMAP |
129 SNDRV_PCM_INFO_MMAP_VALID |
130 SNDRV_PCM_INFO_BATCH |
131 SNDRV_PCM_INFO_INTERLEAVED |
132 SNDRV_PCM_INFO_JOINT_DUPLEX |
133 SNDRV_PCM_INFO_BLOCK_TRANSFER;
134
135 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
136 hw->formats = AMDTP_IN_PCM_FORMAT_BITS;
137 stream = &dice->tx_stream;
138 pcm_channels = dice->tx_channels;
139 } else {
140 hw->formats = AMDTP_OUT_PCM_FORMAT_BITS;
141 stream = &dice->rx_stream;
142 pcm_channels = dice->rx_channels;
143 }
144
145 limit_channels_and_rates(dice, runtime, pcm_channels);
146 limit_period_and_buffer(hw);
147
148 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
149 dice_rate_constraint, substream,
150 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
151 if (err < 0)
152 goto end;
153 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
154 dice_channels_constraint, substream,
155 SNDRV_PCM_HW_PARAM_RATE, -1);
156 if (err < 0)
157 goto end;
158
159 err = amdtp_stream_add_pcm_hw_constraints(stream, runtime);
160end:
161 return err;
162}
163
164static int pcm_open(struct snd_pcm_substream *substream)
165{
166 struct snd_dice *dice = substream->private_data;
167 unsigned int source, rate;
168 bool internal;
169 int err;
170
171 err = snd_dice_stream_lock_try(dice);
172 if (err < 0)
173 goto end;
174
175 err = init_hw_info(dice, substream);
176 if (err < 0)
177 goto err_locked;
178
179 err = snd_dice_transaction_get_clock_source(dice, &source);
180 if (err < 0)
181 goto err_locked;
182 switch (source) {
183 case CLOCK_SOURCE_AES1:
184 case CLOCK_SOURCE_AES2:
185 case CLOCK_SOURCE_AES3:
186 case CLOCK_SOURCE_AES4:
187 case CLOCK_SOURCE_AES_ANY:
188 case CLOCK_SOURCE_ADAT:
189 case CLOCK_SOURCE_TDIF:
190 case CLOCK_SOURCE_WC:
191 internal = false;
192 break;
193 default:
194 internal = true;
195 break;
196 }
197
198 /*
199 * When source of clock is not internal or any PCM streams are running,
200 * available sampling rate is limited at current sampling rate.
201 */
202 if (!internal ||
203 amdtp_stream_pcm_running(&dice->tx_stream) ||
204 amdtp_stream_pcm_running(&dice->rx_stream)) {
205 err = snd_dice_transaction_get_rate(dice, &rate);
206 if (err < 0)
207 goto err_locked;
208 substream->runtime->hw.rate_min = rate;
209 substream->runtime->hw.rate_max = rate;
210 }
211
212 snd_pcm_set_sync(substream);
213end:
214 return err;
215err_locked:
216 snd_dice_stream_lock_release(dice);
217 return err;
218}
219
220static int pcm_close(struct snd_pcm_substream *substream)
221{
222 struct snd_dice *dice = substream->private_data;
223
224 snd_dice_stream_lock_release(dice);
225
226 return 0;
227}
228
229static int capture_hw_params(struct snd_pcm_substream *substream,
230 struct snd_pcm_hw_params *hw_params)
231{
232 struct snd_dice *dice = substream->private_data;
233
234 if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
235 mutex_lock(&dice->mutex);
236 dice->substreams_counter++;
237 mutex_unlock(&dice->mutex);
238 }
239
240 amdtp_stream_set_pcm_format(&dice->tx_stream,
241 params_format(hw_params));
242
243 return snd_pcm_lib_alloc_vmalloc_buffer(substream,
244 params_buffer_bytes(hw_params));
245}
246static int playback_hw_params(struct snd_pcm_substream *substream,
247 struct snd_pcm_hw_params *hw_params)
248{
249 struct snd_dice *dice = substream->private_data;
250
251 if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
252 mutex_lock(&dice->mutex);
253 dice->substreams_counter++;
254 mutex_unlock(&dice->mutex);
255 }
256
257 amdtp_stream_set_pcm_format(&dice->rx_stream,
258 params_format(hw_params));
259
260 return snd_pcm_lib_alloc_vmalloc_buffer(substream,
261 params_buffer_bytes(hw_params));
262}
263
264static int capture_hw_free(struct snd_pcm_substream *substream)
265{
266 struct snd_dice *dice = substream->private_data;
267
268 mutex_lock(&dice->mutex);
269
270 if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
271 dice->substreams_counter--;
272
273 snd_dice_stream_stop_duplex(dice);
274
275 mutex_unlock(&dice->mutex);
276
277 return snd_pcm_lib_free_vmalloc_buffer(substream);
278}
279
280static int playback_hw_free(struct snd_pcm_substream *substream)
281{
282 struct snd_dice *dice = substream->private_data;
283
284 mutex_lock(&dice->mutex);
285
286 if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
287 dice->substreams_counter--;
288
289 snd_dice_stream_stop_duplex(dice);
290
291 mutex_unlock(&dice->mutex);
292
293 return snd_pcm_lib_free_vmalloc_buffer(substream);
294}
295
296static int capture_prepare(struct snd_pcm_substream *substream)
297{
298 struct snd_dice *dice = substream->private_data;
299 int err;
300
301 mutex_lock(&dice->mutex);
302 err = snd_dice_stream_start_duplex(dice, substream->runtime->rate);
303 mutex_unlock(&dice->mutex);
304 if (err >= 0)
305 amdtp_stream_pcm_prepare(&dice->tx_stream);
306
307 return 0;
308}
309static int playback_prepare(struct snd_pcm_substream *substream)
310{
311 struct snd_dice *dice = substream->private_data;
312 int err;
313
314 mutex_lock(&dice->mutex);
315 err = snd_dice_stream_start_duplex(dice, substream->runtime->rate);
316 mutex_unlock(&dice->mutex);
317 if (err >= 0)
318 amdtp_stream_pcm_prepare(&dice->rx_stream);
319
320 return err;
321}
322
323static int capture_trigger(struct snd_pcm_substream *substream, int cmd)
324{
325 struct snd_dice *dice = substream->private_data;
326
327 switch (cmd) {
328 case SNDRV_PCM_TRIGGER_START:
329 amdtp_stream_pcm_trigger(&dice->tx_stream, substream);
330 break;
331 case SNDRV_PCM_TRIGGER_STOP:
332 amdtp_stream_pcm_trigger(&dice->tx_stream, NULL);
333 break;
334 default:
335 return -EINVAL;
336 }
337
338 return 0;
339}
340static int playback_trigger(struct snd_pcm_substream *substream, int cmd)
341{
342 struct snd_dice *dice = substream->private_data;
343
344 switch (cmd) {
345 case SNDRV_PCM_TRIGGER_START:
346 amdtp_stream_pcm_trigger(&dice->rx_stream, substream);
347 break;
348 case SNDRV_PCM_TRIGGER_STOP:
349 amdtp_stream_pcm_trigger(&dice->rx_stream, NULL);
350 break;
351 default:
352 return -EINVAL;
353 }
354
355 return 0;
356}
357
358static snd_pcm_uframes_t capture_pointer(struct snd_pcm_substream *substream)
359{
360 struct snd_dice *dice = substream->private_data;
361
362 return amdtp_stream_pcm_pointer(&dice->tx_stream);
363}
364static snd_pcm_uframes_t playback_pointer(struct snd_pcm_substream *substream)
365{
366 struct snd_dice *dice = substream->private_data;
367
368 return amdtp_stream_pcm_pointer(&dice->rx_stream);
369}
370
371int snd_dice_create_pcm(struct snd_dice *dice)
372{
373 static struct snd_pcm_ops capture_ops = {
374 .open = pcm_open,
375 .close = pcm_close,
376 .ioctl = snd_pcm_lib_ioctl,
377 .hw_params = capture_hw_params,
378 .hw_free = capture_hw_free,
379 .prepare = capture_prepare,
380 .trigger = capture_trigger,
381 .pointer = capture_pointer,
382 .page = snd_pcm_lib_get_vmalloc_page,
383 .mmap = snd_pcm_lib_mmap_vmalloc,
384 };
385 static struct snd_pcm_ops playback_ops = {
386 .open = pcm_open,
387 .close = pcm_close,
388 .ioctl = snd_pcm_lib_ioctl,
389 .hw_params = playback_hw_params,
390 .hw_free = playback_hw_free,
391 .prepare = playback_prepare,
392 .trigger = playback_trigger,
393 .pointer = playback_pointer,
394 .page = snd_pcm_lib_get_vmalloc_page,
395 .mmap = snd_pcm_lib_mmap_vmalloc,
396 };
397 struct snd_pcm *pcm;
398 unsigned int i, capture, playback;
399 int err;
400
401 capture = playback = 0;
402 for (i = 0; i < 3; i++) {
403 if (dice->tx_channels[i] > 0)
404 capture = 1;
405 if (dice->rx_channels[i] > 0)
406 playback = 1;
407 }
408
409 err = snd_pcm_new(dice->card, "DICE", 0, playback, capture, &pcm);
410 if (err < 0)
411 return err;
412 pcm->private_data = dice;
413 strcpy(pcm->name, dice->card->shortname);
414
415 if (capture > 0)
416 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops);
417
418 if (playback > 0)
419 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops);
420
421 return 0;
422}
diff --git a/sound/firewire/dice/dice-proc.c b/sound/firewire/dice/dice-proc.c
new file mode 100644
index 000000000000..f5c1d1bced59
--- /dev/null
+++ b/sound/firewire/dice/dice-proc.c
@@ -0,0 +1,252 @@
1/*
2 * dice_proc.c - a part of driver for Dice based devices
3 *
4 * Copyright (c) Clemens Ladisch
5 * Copyright (c) 2014 Takashi Sakamoto
6 *
7 * Licensed under the terms of the GNU General Public License, version 2.
8 */
9
10#include "dice.h"
11
12static int dice_proc_read_mem(struct snd_dice *dice, void *buffer,
13 unsigned int offset_q, unsigned int quadlets)
14{
15 unsigned int i;
16 int err;
17
18 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
19 DICE_PRIVATE_SPACE + 4 * offset_q,
20 buffer, 4 * quadlets, 0);
21 if (err < 0)
22 return err;
23
24 for (i = 0; i < quadlets; ++i)
25 be32_to_cpus(&((u32 *)buffer)[i]);
26
27 return 0;
28}
29
30static const char *str_from_array(const char *const strs[], unsigned int count,
31 unsigned int i)
32{
33 if (i < count)
34 return strs[i];
35
36 return "(unknown)";
37}
38
39static void dice_proc_fixup_string(char *s, unsigned int size)
40{
41 unsigned int i;
42
43 for (i = 0; i < size; i += 4)
44 cpu_to_le32s((u32 *)(s + i));
45
46 for (i = 0; i < size - 2; ++i) {
47 if (s[i] == '\0')
48 return;
49 if (s[i] == '\\' && s[i + 1] == '\\') {
50 s[i + 2] = '\0';
51 return;
52 }
53 }
54 s[size - 1] = '\0';
55}
56
57static void dice_proc_read(struct snd_info_entry *entry,
58 struct snd_info_buffer *buffer)
59{
60 static const char *const section_names[5] = {
61 "global", "tx", "rx", "ext_sync", "unused2"
62 };
63 static const char *const clock_sources[] = {
64 "aes1", "aes2", "aes3", "aes4", "aes", "adat", "tdif",
65 "wc", "arx1", "arx2", "arx3", "arx4", "internal"
66 };
67 static const char *const rates[] = {
68 "32000", "44100", "48000", "88200", "96000", "176400", "192000",
69 "any low", "any mid", "any high", "none"
70 };
71 struct snd_dice *dice = entry->private_data;
72 u32 sections[ARRAY_SIZE(section_names) * 2];
73 struct {
74 u32 number;
75 u32 size;
76 } tx_rx_header;
77 union {
78 struct {
79 u32 owner_hi, owner_lo;
80 u32 notification;
81 char nick_name[NICK_NAME_SIZE];
82 u32 clock_select;
83 u32 enable;
84 u32 status;
85 u32 extended_status;
86 u32 sample_rate;
87 u32 version;
88 u32 clock_caps;
89 char clock_source_names[CLOCK_SOURCE_NAMES_SIZE];
90 } global;
91 struct {
92 u32 iso;
93 u32 number_audio;
94 u32 number_midi;
95 u32 speed;
96 char names[TX_NAMES_SIZE];
97 u32 ac3_caps;
98 u32 ac3_enable;
99 } tx;
100 struct {
101 u32 iso;
102 u32 seq_start;
103 u32 number_audio;
104 u32 number_midi;
105 char names[RX_NAMES_SIZE];
106 u32 ac3_caps;
107 u32 ac3_enable;
108 } rx;
109 struct {
110 u32 clock_source;
111 u32 locked;
112 u32 rate;
113 u32 adat_user_data;
114 } ext_sync;
115 } buf;
116 unsigned int quadlets, stream, i;
117
118 if (dice_proc_read_mem(dice, sections, 0, ARRAY_SIZE(sections)) < 0)
119 return;
120 snd_iprintf(buffer, "sections:\n");
121 for (i = 0; i < ARRAY_SIZE(section_names); ++i)
122 snd_iprintf(buffer, " %s: offset %u, size %u\n",
123 section_names[i],
124 sections[i * 2], sections[i * 2 + 1]);
125
126 quadlets = min_t(u32, sections[1], sizeof(buf.global) / 4);
127 if (dice_proc_read_mem(dice, &buf.global, sections[0], quadlets) < 0)
128 return;
129 snd_iprintf(buffer, "global:\n");
130 snd_iprintf(buffer, " owner: %04x:%04x%08x\n",
131 buf.global.owner_hi >> 16,
132 buf.global.owner_hi & 0xffff, buf.global.owner_lo);
133 snd_iprintf(buffer, " notification: %08x\n", buf.global.notification);
134 dice_proc_fixup_string(buf.global.nick_name, NICK_NAME_SIZE);
135 snd_iprintf(buffer, " nick name: %s\n", buf.global.nick_name);
136 snd_iprintf(buffer, " clock select: %s %s\n",
137 str_from_array(clock_sources, ARRAY_SIZE(clock_sources),
138 buf.global.clock_select & CLOCK_SOURCE_MASK),
139 str_from_array(rates, ARRAY_SIZE(rates),
140 (buf.global.clock_select & CLOCK_RATE_MASK)
141 >> CLOCK_RATE_SHIFT));
142 snd_iprintf(buffer, " enable: %u\n", buf.global.enable);
143 snd_iprintf(buffer, " status: %slocked %s\n",
144 buf.global.status & STATUS_SOURCE_LOCKED ? "" : "un",
145 str_from_array(rates, ARRAY_SIZE(rates),
146 (buf.global.status &
147 STATUS_NOMINAL_RATE_MASK)
148 >> CLOCK_RATE_SHIFT));
149 snd_iprintf(buffer, " ext status: %08x\n", buf.global.extended_status);
150 snd_iprintf(buffer, " sample rate: %u\n", buf.global.sample_rate);
151 snd_iprintf(buffer, " version: %u.%u.%u.%u\n",
152 (buf.global.version >> 24) & 0xff,
153 (buf.global.version >> 16) & 0xff,
154 (buf.global.version >> 8) & 0xff,
155 (buf.global.version >> 0) & 0xff);
156 if (quadlets >= 90) {
157 snd_iprintf(buffer, " clock caps:");
158 for (i = 0; i <= 6; ++i)
159 if (buf.global.clock_caps & (1 << i))
160 snd_iprintf(buffer, " %s", rates[i]);
161 for (i = 0; i <= 12; ++i)
162 if (buf.global.clock_caps & (1 << (16 + i)))
163 snd_iprintf(buffer, " %s", clock_sources[i]);
164 snd_iprintf(buffer, "\n");
165 dice_proc_fixup_string(buf.global.clock_source_names,
166 CLOCK_SOURCE_NAMES_SIZE);
167 snd_iprintf(buffer, " clock source names: %s\n",
168 buf.global.clock_source_names);
169 }
170
171 if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
172 return;
173 quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);
174 for (stream = 0; stream < tx_rx_header.number; ++stream) {
175 if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
176 stream * tx_rx_header.size,
177 quadlets) < 0)
178 break;
179 snd_iprintf(buffer, "tx %u:\n", stream);
180 snd_iprintf(buffer, " iso channel: %d\n", (int)buf.tx.iso);
181 snd_iprintf(buffer, " audio channels: %u\n",
182 buf.tx.number_audio);
183 snd_iprintf(buffer, " midi ports: %u\n", buf.tx.number_midi);
184 snd_iprintf(buffer, " speed: S%u\n", 100u << buf.tx.speed);
185 if (quadlets >= 68) {
186 dice_proc_fixup_string(buf.tx.names, TX_NAMES_SIZE);
187 snd_iprintf(buffer, " names: %s\n", buf.tx.names);
188 }
189 if (quadlets >= 70) {
190 snd_iprintf(buffer, " ac3 caps: %08x\n",
191 buf.tx.ac3_caps);
192 snd_iprintf(buffer, " ac3 enable: %08x\n",
193 buf.tx.ac3_enable);
194 }
195 }
196
197 if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
198 return;
199 quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
200 for (stream = 0; stream < tx_rx_header.number; ++stream) {
201 if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
202 stream * tx_rx_header.size,
203 quadlets) < 0)
204 break;
205 snd_iprintf(buffer, "rx %u:\n", stream);
206 snd_iprintf(buffer, " iso channel: %d\n", (int)buf.rx.iso);
207 snd_iprintf(buffer, " sequence start: %u\n", buf.rx.seq_start);
208 snd_iprintf(buffer, " audio channels: %u\n",
209 buf.rx.number_audio);
210 snd_iprintf(buffer, " midi ports: %u\n", buf.rx.number_midi);
211 if (quadlets >= 68) {
212 dice_proc_fixup_string(buf.rx.names, RX_NAMES_SIZE);
213 snd_iprintf(buffer, " names: %s\n", buf.rx.names);
214 }
215 if (quadlets >= 70) {
216 snd_iprintf(buffer, " ac3 caps: %08x\n",
217 buf.rx.ac3_caps);
218 snd_iprintf(buffer, " ac3 enable: %08x\n",
219 buf.rx.ac3_enable);
220 }
221 }
222
223 quadlets = min_t(u32, sections[7], sizeof(buf.ext_sync) / 4);
224 if (quadlets >= 4) {
225 if (dice_proc_read_mem(dice, &buf.ext_sync,
226 sections[6], 4) < 0)
227 return;
228 snd_iprintf(buffer, "ext status:\n");
229 snd_iprintf(buffer, " clock source: %s\n",
230 str_from_array(clock_sources,
231 ARRAY_SIZE(clock_sources),
232 buf.ext_sync.clock_source));
233 snd_iprintf(buffer, " locked: %u\n", buf.ext_sync.locked);
234 snd_iprintf(buffer, " rate: %s\n",
235 str_from_array(rates, ARRAY_SIZE(rates),
236 buf.ext_sync.rate));
237 snd_iprintf(buffer, " adat user data: ");
238 if (buf.ext_sync.adat_user_data & ADAT_USER_DATA_NO_DATA)
239 snd_iprintf(buffer, "-\n");
240 else
241 snd_iprintf(buffer, "%x\n",
242 buf.ext_sync.adat_user_data);
243 }
244}
245
246void snd_dice_create_proc(struct snd_dice *dice)
247{
248 struct snd_info_entry *entry;
249
250 if (!snd_card_proc_new(dice->card, "dice", &entry))
251 snd_info_set_text_ops(entry, dice, dice_proc_read);
252}
diff --git a/sound/firewire/dice/dice-stream.c b/sound/firewire/dice/dice-stream.c
new file mode 100644
index 000000000000..fa9cf761b610
--- /dev/null
+++ b/sound/firewire/dice/dice-stream.c
@@ -0,0 +1,407 @@
1/*
2 * dice_stream.c - a part of driver for DICE based devices
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Copyright (c) 2014 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 *
7 * Licensed under the terms of the GNU General Public License, version 2.
8 */
9
10#include "dice.h"
11
12#define CALLBACK_TIMEOUT 200
13
14const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT] = {
15 /* mode 0 */
16 [0] = 32000,
17 [1] = 44100,
18 [2] = 48000,
19 /* mode 1 */
20 [3] = 88200,
21 [4] = 96000,
22 /* mode 2 */
23 [5] = 176400,
24 [6] = 192000,
25};
26
27int snd_dice_stream_get_rate_mode(struct snd_dice *dice, unsigned int rate,
28 unsigned int *mode)
29{
30 int i;
31
32 for (i = 0; i < ARRAY_SIZE(snd_dice_rates); i++) {
33 if (!(dice->clock_caps & BIT(i)))
34 continue;
35 if (snd_dice_rates[i] != rate)
36 continue;
37
38 *mode = (i - 1) / 2;
39 return 0;
40 }
41 return -EINVAL;
42}
43
44static void release_resources(struct snd_dice *dice,
45 struct fw_iso_resources *resources)
46{
47 unsigned int channel;
48
49 /* Reset channel number */
50 channel = cpu_to_be32((u32)-1);
51 if (resources == &dice->tx_resources)
52 snd_dice_transaction_write_tx(dice, TX_ISOCHRONOUS,
53 &channel, 4);
54 else
55 snd_dice_transaction_write_rx(dice, RX_ISOCHRONOUS,
56 &channel, 4);
57
58 fw_iso_resources_free(resources);
59}
60
61static int keep_resources(struct snd_dice *dice,
62 struct fw_iso_resources *resources,
63 unsigned int max_payload_bytes)
64{
65 unsigned int channel;
66 int err;
67
68 err = fw_iso_resources_allocate(resources, max_payload_bytes,
69 fw_parent_device(dice->unit)->max_speed);
70 if (err < 0)
71 goto end;
72
73 /* Set channel number */
74 channel = cpu_to_be32(resources->channel);
75 if (resources == &dice->tx_resources)
76 err = snd_dice_transaction_write_tx(dice, TX_ISOCHRONOUS,
77 &channel, 4);
78 else
79 err = snd_dice_transaction_write_rx(dice, RX_ISOCHRONOUS,
80 &channel, 4);
81 if (err < 0)
82 release_resources(dice, resources);
83end:
84 return err;
85}
86
87static void stop_stream(struct snd_dice *dice, struct amdtp_stream *stream)
88{
89 amdtp_stream_pcm_abort(stream);
90 amdtp_stream_stop(stream);
91
92 if (stream == &dice->tx_stream)
93 release_resources(dice, &dice->tx_resources);
94 else
95 release_resources(dice, &dice->rx_resources);
96}
97
98static int start_stream(struct snd_dice *dice, struct amdtp_stream *stream,
99 unsigned int rate)
100{
101 struct fw_iso_resources *resources;
102 unsigned int i, mode, pcm_chs, midi_ports;
103 int err;
104
105 err = snd_dice_stream_get_rate_mode(dice, rate, &mode);
106 if (err < 0)
107 goto end;
108 if (stream == &dice->tx_stream) {
109 resources = &dice->tx_resources;
110 pcm_chs = dice->tx_channels[mode];
111 midi_ports = dice->tx_midi_ports[mode];
112 } else {
113 resources = &dice->rx_resources;
114 pcm_chs = dice->rx_channels[mode];
115 midi_ports = dice->rx_midi_ports[mode];
116 }
117
118 /*
119 * At 176.4/192.0 kHz, Dice has a quirk to transfer two PCM frames in
120 * one data block of AMDTP packet. Thus sampling transfer frequency is
121 * a half of PCM sampling frequency, i.e. PCM frames at 192.0 kHz are
122 * transferred on AMDTP packets at 96 kHz. Two successive samples of a
123 * channel are stored consecutively in the packet. This quirk is called
124 * as 'Dual Wire'.
125 * For this quirk, blocking mode is required and PCM buffer size should
126 * be aligned to SYT_INTERVAL.
127 */
128 if (mode > 1) {
129 rate /= 2;
130 pcm_chs *= 2;
131 stream->double_pcm_frames = true;
132 } else {
133 stream->double_pcm_frames = false;
134 }
135
136 amdtp_stream_set_parameters(stream, rate, pcm_chs, midi_ports);
137 if (mode > 1) {
138 pcm_chs /= 2;
139
140 for (i = 0; i < pcm_chs; i++) {
141 stream->pcm_positions[i] = i * 2;
142 stream->pcm_positions[i + pcm_chs] = i * 2 + 1;
143 }
144 }
145
146 err = keep_resources(dice, resources,
147 amdtp_stream_get_max_payload(stream));
148 if (err < 0) {
149 dev_err(&dice->unit->device,
150 "fail to keep isochronous resources\n");
151 goto end;
152 }
153
154 err = amdtp_stream_start(stream, resources->channel,
155 fw_parent_device(dice->unit)->max_speed);
156 if (err < 0)
157 release_resources(dice, resources);
158end:
159 return err;
160}
161
162static int get_sync_mode(struct snd_dice *dice, enum cip_flags *sync_mode)
163{
164 u32 source;
165 int err;
166
167 err = snd_dice_transaction_get_clock_source(dice, &source);
168 if (err < 0)
169 goto end;
170
171 switch (source) {
172 /* So-called 'SYT Match' modes, sync_to_syt value of packets received */
173 case CLOCK_SOURCE_ARX4: /* in 4th stream */
174 case CLOCK_SOURCE_ARX3: /* in 3rd stream */
175 case CLOCK_SOURCE_ARX2: /* in 2nd stream */
176 err = -ENOSYS;
177 break;
178 case CLOCK_SOURCE_ARX1: /* in 1st stream, which this driver uses */
179 *sync_mode = 0;
180 break;
181 default:
182 *sync_mode = CIP_SYNC_TO_DEVICE;
183 break;
184 }
185end:
186 return err;
187}
188
189int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate)
190{
191 struct amdtp_stream *master, *slave;
192 unsigned int curr_rate;
193 enum cip_flags sync_mode;
194 int err = 0;
195
196 if (dice->substreams_counter == 0)
197 goto end;
198
199 err = get_sync_mode(dice, &sync_mode);
200 if (err < 0)
201 goto end;
202 if (sync_mode == CIP_SYNC_TO_DEVICE) {
203 master = &dice->tx_stream;
204 slave = &dice->rx_stream;
205 } else {
206 master = &dice->rx_stream;
207 slave = &dice->tx_stream;
208 }
209
210 /* Some packet queueing errors. */
211 if (amdtp_streaming_error(master) || amdtp_streaming_error(slave))
212 stop_stream(dice, master);
213
214 /* Stop stream if rate is different. */
215 err = snd_dice_transaction_get_rate(dice, &curr_rate);
216 if (err < 0) {
217 dev_err(&dice->unit->device,
218 "fail to get sampling rate\n");
219 goto end;
220 }
221 if (rate == 0)
222 rate = curr_rate;
223 if (rate != curr_rate)
224 stop_stream(dice, master);
225
226 if (!amdtp_stream_running(master)) {
227 stop_stream(dice, slave);
228 snd_dice_transaction_clear_enable(dice);
229
230 amdtp_stream_set_sync(sync_mode, master, slave);
231
232 err = snd_dice_transaction_set_rate(dice, rate);
233 if (err < 0) {
234 dev_err(&dice->unit->device,
235 "fail to set sampling rate\n");
236 goto end;
237 }
238
239 /* Start both streams. */
240 err = start_stream(dice, master, rate);
241 if (err < 0) {
242 dev_err(&dice->unit->device,
243 "fail to start AMDTP master stream\n");
244 goto end;
245 }
246 err = start_stream(dice, slave, rate);
247 if (err < 0) {
248 dev_err(&dice->unit->device,
249 "fail to start AMDTP slave stream\n");
250 stop_stream(dice, master);
251 goto end;
252 }
253 err = snd_dice_transaction_set_enable(dice);
254 if (err < 0) {
255 dev_err(&dice->unit->device,
256 "fail to enable interface\n");
257 stop_stream(dice, master);
258 stop_stream(dice, slave);
259 goto end;
260 }
261
262 /* Wait first callbacks */
263 if (!amdtp_stream_wait_callback(master, CALLBACK_TIMEOUT) ||
264 !amdtp_stream_wait_callback(slave, CALLBACK_TIMEOUT)) {
265 snd_dice_transaction_clear_enable(dice);
266 stop_stream(dice, master);
267 stop_stream(dice, slave);
268 err = -ETIMEDOUT;
269 }
270 }
271end:
272 return err;
273}
274
275void snd_dice_stream_stop_duplex(struct snd_dice *dice)
276{
277 if (dice->substreams_counter > 0)
278 return;
279
280 snd_dice_transaction_clear_enable(dice);
281
282 stop_stream(dice, &dice->tx_stream);
283 stop_stream(dice, &dice->rx_stream);
284}
285
286static int init_stream(struct snd_dice *dice, struct amdtp_stream *stream)
287{
288 int err;
289 struct fw_iso_resources *resources;
290 enum amdtp_stream_direction dir;
291
292 if (stream == &dice->tx_stream) {
293 resources = &dice->tx_resources;
294 dir = AMDTP_IN_STREAM;
295 } else {
296 resources = &dice->rx_resources;
297 dir = AMDTP_OUT_STREAM;
298 }
299
300 err = fw_iso_resources_init(resources, dice->unit);
301 if (err < 0)
302 goto end;
303 resources->channels_mask = 0x00000000ffffffffuLL;
304
305 err = amdtp_stream_init(stream, dice->unit, dir, CIP_BLOCKING);
306 if (err < 0) {
307 amdtp_stream_destroy(stream);
308 fw_iso_resources_destroy(resources);
309 }
310end:
311 return err;
312}
313
314static void destroy_stream(struct snd_dice *dice, struct amdtp_stream *stream)
315{
316 amdtp_stream_destroy(stream);
317
318 if (stream == &dice->tx_stream)
319 fw_iso_resources_destroy(&dice->tx_resources);
320 else
321 fw_iso_resources_destroy(&dice->rx_resources);
322}
323
324int snd_dice_stream_init_duplex(struct snd_dice *dice)
325{
326 int err;
327
328 dice->substreams_counter = 0;
329
330 err = init_stream(dice, &dice->tx_stream);
331 if (err < 0)
332 goto end;
333
334 err = init_stream(dice, &dice->rx_stream);
335end:
336 return err;
337}
338
339void snd_dice_stream_destroy_duplex(struct snd_dice *dice)
340{
341 snd_dice_transaction_clear_enable(dice);
342
343 stop_stream(dice, &dice->tx_stream);
344 destroy_stream(dice, &dice->tx_stream);
345
346 stop_stream(dice, &dice->rx_stream);
347 destroy_stream(dice, &dice->rx_stream);
348
349 dice->substreams_counter = 0;
350}
351
352void snd_dice_stream_update_duplex(struct snd_dice *dice)
353{
354 /*
355 * On a bus reset, the DICE firmware disables streaming and then goes
356 * off contemplating its own navel for hundreds of milliseconds before
357 * it can react to any of our attempts to reenable streaming. This
358 * means that we lose synchronization anyway, so we force our streams
359 * to stop so that the application can restart them in an orderly
360 * manner.
361 */
362 dice->global_enabled = false;
363
364 stop_stream(dice, &dice->rx_stream);
365 stop_stream(dice, &dice->tx_stream);
366
367 fw_iso_resources_update(&dice->rx_resources);
368 fw_iso_resources_update(&dice->tx_resources);
369}
370
371static void dice_lock_changed(struct snd_dice *dice)
372{
373 dice->dev_lock_changed = true;
374 wake_up(&dice->hwdep_wait);
375}
376
377int snd_dice_stream_lock_try(struct snd_dice *dice)
378{
379 int err;
380
381 spin_lock_irq(&dice->lock);
382
383 if (dice->dev_lock_count < 0) {
384 err = -EBUSY;
385 goto out;
386 }
387
388 if (dice->dev_lock_count++ == 0)
389 dice_lock_changed(dice);
390 err = 0;
391out:
392 spin_unlock_irq(&dice->lock);
393 return err;
394}
395
396void snd_dice_stream_lock_release(struct snd_dice *dice)
397{
398 spin_lock_irq(&dice->lock);
399
400 if (WARN_ON(dice->dev_lock_count <= 0))
401 goto out;
402
403 if (--dice->dev_lock_count == 0)
404 dice_lock_changed(dice);
405out:
406 spin_unlock_irq(&dice->lock);
407}
diff --git a/sound/firewire/dice/dice-transaction.c b/sound/firewire/dice/dice-transaction.c
new file mode 100644
index 000000000000..aee746187665
--- /dev/null
+++ b/sound/firewire/dice/dice-transaction.c
@@ -0,0 +1,382 @@
1/*
2 * dice_transaction.c - a part of driver for Dice based devices
3 *
4 * Copyright (c) Clemens Ladisch
5 * Copyright (c) 2014 Takashi Sakamoto
6 *
7 * Licensed under the terms of the GNU General Public License, version 2.
8 */
9
10#include "dice.h"
11
12#define NOTIFICATION_TIMEOUT_MS 100
13
14static u64 get_subaddr(struct snd_dice *dice, enum snd_dice_addr_type type,
15 u64 offset)
16{
17 switch (type) {
18 case SND_DICE_ADDR_TYPE_TX:
19 offset += dice->tx_offset;
20 break;
21 case SND_DICE_ADDR_TYPE_RX:
22 offset += dice->rx_offset;
23 break;
24 case SND_DICE_ADDR_TYPE_SYNC:
25 offset += dice->sync_offset;
26 break;
27 case SND_DICE_ADDR_TYPE_RSRV:
28 offset += dice->rsrv_offset;
29 break;
30 case SND_DICE_ADDR_TYPE_GLOBAL:
31 default:
32 offset += dice->global_offset;
33 break;
34 }
35 offset += DICE_PRIVATE_SPACE;
36 return offset;
37}
38
39int snd_dice_transaction_write(struct snd_dice *dice,
40 enum snd_dice_addr_type type,
41 unsigned int offset, void *buf, unsigned int len)
42{
43 return snd_fw_transaction(dice->unit,
44 (len == 4) ? TCODE_WRITE_QUADLET_REQUEST :
45 TCODE_WRITE_BLOCK_REQUEST,
46 get_subaddr(dice, type, offset), buf, len, 0);
47}
48
49int snd_dice_transaction_read(struct snd_dice *dice,
50 enum snd_dice_addr_type type, unsigned int offset,
51 void *buf, unsigned int len)
52{
53 return snd_fw_transaction(dice->unit,
54 (len == 4) ? TCODE_READ_QUADLET_REQUEST :
55 TCODE_READ_BLOCK_REQUEST,
56 get_subaddr(dice, type, offset), buf, len, 0);
57}
58
59static unsigned int get_clock_info(struct snd_dice *dice, __be32 *info)
60{
61 return snd_dice_transaction_read_global(dice, GLOBAL_CLOCK_SELECT,
62 info, 4);
63}
64
65static int set_clock_info(struct snd_dice *dice,
66 unsigned int rate, unsigned int source)
67{
68 unsigned int retries = 3;
69 unsigned int i;
70 __be32 info;
71 u32 mask;
72 u32 clock;
73 int err;
74retry:
75 err = get_clock_info(dice, &info);
76 if (err < 0)
77 goto end;
78
79 clock = be32_to_cpu(info);
80 if (source != UINT_MAX) {
81 mask = CLOCK_SOURCE_MASK;
82 clock &= ~mask;
83 clock |= source;
84 }
85 if (rate != UINT_MAX) {
86 for (i = 0; i < ARRAY_SIZE(snd_dice_rates); i++) {
87 if (snd_dice_rates[i] == rate)
88 break;
89 }
90 if (i == ARRAY_SIZE(snd_dice_rates)) {
91 err = -EINVAL;
92 goto end;
93 }
94
95 mask = CLOCK_RATE_MASK;
96 clock &= ~mask;
97 clock |= i << CLOCK_RATE_SHIFT;
98 }
99 info = cpu_to_be32(clock);
100
101 if (completion_done(&dice->clock_accepted))
102 reinit_completion(&dice->clock_accepted);
103
104 err = snd_dice_transaction_write_global(dice, GLOBAL_CLOCK_SELECT,
105 &info, 4);
106 if (err < 0)
107 goto end;
108
109 /* Timeout means it's invalid request, probably bus reset occurred. */
110 if (wait_for_completion_timeout(&dice->clock_accepted,
111 msecs_to_jiffies(NOTIFICATION_TIMEOUT_MS)) == 0) {
112 if (retries-- == 0) {
113 err = -ETIMEDOUT;
114 goto end;
115 }
116
117 err = snd_dice_transaction_reinit(dice);
118 if (err < 0)
119 goto end;
120
121 msleep(500); /* arbitrary */
122 goto retry;
123 }
124end:
125 return err;
126}
127
128int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
129 unsigned int *source)
130{
131 __be32 info;
132 int err;
133
134 err = get_clock_info(dice, &info);
135 if (err >= 0)
136 *source = be32_to_cpu(info) & CLOCK_SOURCE_MASK;
137
138 return err;
139}
140
141int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate)
142{
143 __be32 info;
144 unsigned int index;
145 int err;
146
147 err = get_clock_info(dice, &info);
148 if (err < 0)
149 goto end;
150
151 index = (be32_to_cpu(info) & CLOCK_RATE_MASK) >> CLOCK_RATE_SHIFT;
152 if (index >= SND_DICE_RATES_COUNT) {
153 err = -ENOSYS;
154 goto end;
155 }
156
157 *rate = snd_dice_rates[index];
158end:
159 return err;
160}
161int snd_dice_transaction_set_rate(struct snd_dice *dice, unsigned int rate)
162{
163 return set_clock_info(dice, rate, UINT_MAX);
164}
165
166int snd_dice_transaction_set_enable(struct snd_dice *dice)
167{
168 __be32 value;
169 int err = 0;
170
171 if (dice->global_enabled)
172 goto end;
173
174 value = cpu_to_be32(1);
175 err = snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
176 get_subaddr(dice, SND_DICE_ADDR_TYPE_GLOBAL,
177 GLOBAL_ENABLE),
178 &value, 4,
179 FW_FIXED_GENERATION | dice->owner_generation);
180 if (err < 0)
181 goto end;
182
183 dice->global_enabled = true;
184end:
185 return err;
186}
187
188void snd_dice_transaction_clear_enable(struct snd_dice *dice)
189{
190 __be32 value;
191
192 value = 0;
193 snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
194 get_subaddr(dice, SND_DICE_ADDR_TYPE_GLOBAL,
195 GLOBAL_ENABLE),
196 &value, 4, FW_QUIET |
197 FW_FIXED_GENERATION | dice->owner_generation);
198
199 dice->global_enabled = false;
200}
201
202static void dice_notification(struct fw_card *card, struct fw_request *request,
203 int tcode, int destination, int source,
204 int generation, unsigned long long offset,
205 void *data, size_t length, void *callback_data)
206{
207 struct snd_dice *dice = callback_data;
208 u32 bits;
209 unsigned long flags;
210
211 if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
212 fw_send_response(card, request, RCODE_TYPE_ERROR);
213 return;
214 }
215 if ((offset & 3) != 0) {
216 fw_send_response(card, request, RCODE_ADDRESS_ERROR);
217 return;
218 }
219
220 bits = be32_to_cpup(data);
221
222 spin_lock_irqsave(&dice->lock, flags);
223 dice->notification_bits |= bits;
224 spin_unlock_irqrestore(&dice->lock, flags);
225
226 fw_send_response(card, request, RCODE_COMPLETE);
227
228 if (bits & NOTIFY_CLOCK_ACCEPTED)
229 complete(&dice->clock_accepted);
230 wake_up(&dice->hwdep_wait);
231}
232
233static int register_notification_address(struct snd_dice *dice, bool retry)
234{
235 struct fw_device *device = fw_parent_device(dice->unit);
236 __be64 *buffer;
237 unsigned int retries;
238 int err;
239
240 retries = (retry) ? 3 : 0;
241
242 buffer = kmalloc(2 * 8, GFP_KERNEL);
243 if (!buffer)
244 return -ENOMEM;
245
246 for (;;) {
247 buffer[0] = cpu_to_be64(OWNER_NO_OWNER);
248 buffer[1] = cpu_to_be64(
249 ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
250 dice->notification_handler.offset);
251
252 dice->owner_generation = device->generation;
253 smp_rmb(); /* node_id vs. generation */
254 err = snd_fw_transaction(dice->unit, TCODE_LOCK_COMPARE_SWAP,
255 get_subaddr(dice,
256 SND_DICE_ADDR_TYPE_GLOBAL,
257 GLOBAL_OWNER),
258 buffer, 2 * 8,
259 FW_FIXED_GENERATION |
260 dice->owner_generation);
261 if (err == 0) {
262 /* success */
263 if (buffer[0] == cpu_to_be64(OWNER_NO_OWNER))
264 break;
265 /* The address seems to be already registered. */
266 if (buffer[0] == buffer[1])
267 break;
268
269 dev_err(&dice->unit->device,
270 "device is already in use\n");
271 err = -EBUSY;
272 }
273 if (err != -EAGAIN || retries-- > 0)
274 break;
275
276 msleep(20);
277 }
278
279 kfree(buffer);
280
281 if (err < 0)
282 dice->owner_generation = -1;
283
284 return err;
285}
286
287static void unregister_notification_address(struct snd_dice *dice)
288{
289 struct fw_device *device = fw_parent_device(dice->unit);
290 __be64 *buffer;
291
292 buffer = kmalloc(2 * 8, GFP_KERNEL);
293 if (buffer == NULL)
294 return;
295
296 buffer[0] = cpu_to_be64(
297 ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
298 dice->notification_handler.offset);
299 buffer[1] = cpu_to_be64(OWNER_NO_OWNER);
300 snd_fw_transaction(dice->unit, TCODE_LOCK_COMPARE_SWAP,
301 get_subaddr(dice, SND_DICE_ADDR_TYPE_GLOBAL,
302 GLOBAL_OWNER),
303 buffer, 2 * 8, FW_QUIET |
304 FW_FIXED_GENERATION | dice->owner_generation);
305
306 kfree(buffer);
307
308 dice->owner_generation = -1;
309}
310
311void snd_dice_transaction_destroy(struct snd_dice *dice)
312{
313 struct fw_address_handler *handler = &dice->notification_handler;
314
315 if (handler->callback_data == NULL)
316 return;
317
318 unregister_notification_address(dice);
319
320 fw_core_remove_address_handler(handler);
321 handler->callback_data = NULL;
322}
323
324int snd_dice_transaction_reinit(struct snd_dice *dice)
325{
326 struct fw_address_handler *handler = &dice->notification_handler;
327
328 if (handler->callback_data == NULL)
329 return -EINVAL;
330
331 return register_notification_address(dice, false);
332}
333
334int snd_dice_transaction_init(struct snd_dice *dice)
335{
336 struct fw_address_handler *handler = &dice->notification_handler;
337 __be32 *pointers;
338 int err;
339
340 /* Use the same way which dice_interface_check() does. */
341 pointers = kmalloc(sizeof(__be32) * 10, GFP_KERNEL);
342 if (pointers == NULL)
343 return -ENOMEM;
344
345 /* Get offsets for sub-addresses */
346 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
347 DICE_PRIVATE_SPACE,
348 pointers, sizeof(__be32) * 10, 0);
349 if (err < 0)
350 goto end;
351
352 /* Allocation callback in address space over host controller */
353 handler->length = 4;
354 handler->address_callback = dice_notification;
355 handler->callback_data = dice;
356 err = fw_core_add_address_handler(handler, &fw_high_memory_region);
357 if (err < 0) {
358 handler->callback_data = NULL;
359 goto end;
360 }
361
362 /* Register the address space */
363 err = register_notification_address(dice, true);
364 if (err < 0) {
365 fw_core_remove_address_handler(handler);
366 handler->callback_data = NULL;
367 goto end;
368 }
369
370 dice->global_offset = be32_to_cpu(pointers[0]) * 4;
371 dice->tx_offset = be32_to_cpu(pointers[2]) * 4;
372 dice->rx_offset = be32_to_cpu(pointers[4]) * 4;
373 dice->sync_offset = be32_to_cpu(pointers[6]) * 4;
374 dice->rsrv_offset = be32_to_cpu(pointers[8]) * 4;
375
376 /* Set up later. */
377 if (be32_to_cpu(pointers[1]) * 4 >= GLOBAL_CLOCK_CAPABILITIES + 4)
378 dice->clock_caps = 1;
379end:
380 kfree(pointers);
381 return err;
382}
diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c
new file mode 100644
index 000000000000..90d8f40ff727
--- /dev/null
+++ b/sound/firewire/dice/dice.c
@@ -0,0 +1,361 @@
1/*
2 * TC Applied Technologies Digital Interface Communications Engine driver
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include "dice.h"
9
10MODULE_DESCRIPTION("DICE driver");
11MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
12MODULE_LICENSE("GPL v2");
13
14#define OUI_WEISS 0x001c6a
15
16#define DICE_CATEGORY_ID 0x04
17#define WEISS_CATEGORY_ID 0x00
18
19static int dice_interface_check(struct fw_unit *unit)
20{
21 static const int min_values[10] = {
22 10, 0x64 / 4,
23 10, 0x18 / 4,
24 10, 0x18 / 4,
25 0, 0,
26 0, 0,
27 };
28 struct fw_device *device = fw_parent_device(unit);
29 struct fw_csr_iterator it;
30 int key, val, vendor = -1, model = -1, err;
31 unsigned int category, i;
32 __be32 *pointers, value;
33 __be32 version;
34
35 pointers = kmalloc_array(ARRAY_SIZE(min_values), sizeof(__be32),
36 GFP_KERNEL);
37 if (pointers == NULL)
38 return -ENOMEM;
39
40 /*
41 * Check that GUID and unit directory are constructed according to DICE
42 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
43 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
44 * ID, and a 22-bit serial number.
45 */
46 fw_csr_iterator_init(&it, unit->directory);
47 while (fw_csr_iterator_next(&it, &key, &val)) {
48 switch (key) {
49 case CSR_SPECIFIER_ID:
50 vendor = val;
51 break;
52 case CSR_MODEL:
53 model = val;
54 break;
55 }
56 }
57 if (vendor == OUI_WEISS)
58 category = WEISS_CATEGORY_ID;
59 else
60 category = DICE_CATEGORY_ID;
61 if (device->config_rom[3] != ((vendor << 8) | category) ||
62 device->config_rom[4] >> 22 != model) {
63 err = -ENODEV;
64 goto end;
65 }
66
67 /*
68 * Check that the sub address spaces exist and are located inside the
69 * private address space. The minimum values are chosen so that all
70 * minimally required registers are included.
71 */
72 err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
73 DICE_PRIVATE_SPACE, pointers,
74 sizeof(__be32) * ARRAY_SIZE(min_values), 0);
75 if (err < 0) {
76 err = -ENODEV;
77 goto end;
78 }
79 for (i = 0; i < ARRAY_SIZE(min_values); ++i) {
80 value = be32_to_cpu(pointers[i]);
81 if (value < min_values[i] || value >= 0x40000) {
82 err = -ENODEV;
83 goto end;
84 }
85 }
86
87 /*
88 * Check that the implemented DICE driver specification major version
89 * number matches.
90 */
91 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
92 DICE_PRIVATE_SPACE +
93 be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION,
94 &version, 4, 0);
95 if (err < 0) {
96 err = -ENODEV;
97 goto end;
98 }
99 if ((version & cpu_to_be32(0xff000000)) != cpu_to_be32(0x01000000)) {
100 dev_err(&unit->device,
101 "unknown DICE version: 0x%08x\n", be32_to_cpu(version));
102 err = -ENODEV;
103 goto end;
104 }
105end:
106 return err;
107}
108
109static int highest_supported_mode_rate(struct snd_dice *dice,
110 unsigned int mode, unsigned int *rate)
111{
112 unsigned int i, m;
113
114 for (i = ARRAY_SIZE(snd_dice_rates); i > 0; i--) {
115 *rate = snd_dice_rates[i - 1];
116 if (snd_dice_stream_get_rate_mode(dice, *rate, &m) < 0)
117 continue;
118 if (mode == m)
119 break;
120 }
121 if (i == 0)
122 return -EINVAL;
123
124 return 0;
125}
126
127static int dice_read_mode_params(struct snd_dice *dice, unsigned int mode)
128{
129 __be32 values[2];
130 unsigned int rate;
131 int err;
132
133 if (highest_supported_mode_rate(dice, mode, &rate) < 0) {
134 dice->tx_channels[mode] = 0;
135 dice->tx_midi_ports[mode] = 0;
136 dice->rx_channels[mode] = 0;
137 dice->rx_midi_ports[mode] = 0;
138 return 0;
139 }
140
141 err = snd_dice_transaction_set_rate(dice, rate);
142 if (err < 0)
143 return err;
144
145 err = snd_dice_transaction_read_tx(dice, TX_NUMBER_AUDIO,
146 values, sizeof(values));
147 if (err < 0)
148 return err;
149
150 dice->tx_channels[mode] = be32_to_cpu(values[0]);
151 dice->tx_midi_ports[mode] = be32_to_cpu(values[1]);
152
153 err = snd_dice_transaction_read_rx(dice, RX_NUMBER_AUDIO,
154 values, sizeof(values));
155 if (err < 0)
156 return err;
157
158 dice->rx_channels[mode] = be32_to_cpu(values[0]);
159 dice->rx_midi_ports[mode] = be32_to_cpu(values[1]);
160
161 return 0;
162}
163
164static int dice_read_params(struct snd_dice *dice)
165{
166 __be32 value;
167 int mode, err;
168
169 /* some very old firmwares don't tell about their clock support */
170 if (dice->clock_caps > 0) {
171 err = snd_dice_transaction_read_global(dice,
172 GLOBAL_CLOCK_CAPABILITIES,
173 &value, 4);
174 if (err < 0)
175 return err;
176 dice->clock_caps = be32_to_cpu(value);
177 } else {
178 /* this should be supported by any device */
179 dice->clock_caps = CLOCK_CAP_RATE_44100 |
180 CLOCK_CAP_RATE_48000 |
181 CLOCK_CAP_SOURCE_ARX1 |
182 CLOCK_CAP_SOURCE_INTERNAL;
183 }
184
185 for (mode = 2; mode >= 0; --mode) {
186 err = dice_read_mode_params(dice, mode);
187 if (err < 0)
188 return err;
189 }
190
191 return 0;
192}
193
194static void dice_card_strings(struct snd_dice *dice)
195{
196 struct snd_card *card = dice->card;
197 struct fw_device *dev = fw_parent_device(dice->unit);
198 char vendor[32], model[32];
199 unsigned int i;
200 int err;
201
202 strcpy(card->driver, "DICE");
203
204 strcpy(card->shortname, "DICE");
205 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
206 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
207 card->shortname,
208 sizeof(card->shortname));
209 if (err >= 0) {
210 /* DICE strings are returned in "always-wrong" endianness */
211 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
212 for (i = 0; i < sizeof(card->shortname); i += 4)
213 swab32s((u32 *)&card->shortname[i]);
214 card->shortname[sizeof(card->shortname) - 1] = '\0';
215 }
216
217 strcpy(vendor, "?");
218 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
219 strcpy(model, "?");
220 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
221 snprintf(card->longname, sizeof(card->longname),
222 "%s %s (serial %u) at %s, S%d",
223 vendor, model, dev->config_rom[4] & 0x3fffff,
224 dev_name(&dice->unit->device), 100 << dev->max_speed);
225
226 strcpy(card->mixername, "DICE");
227}
228
229static void dice_card_free(struct snd_card *card)
230{
231 struct snd_dice *dice = card->private_data;
232
233 snd_dice_transaction_destroy(dice);
234 mutex_destroy(&dice->mutex);
235}
236
237static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
238{
239 struct snd_card *card;
240 struct snd_dice *dice;
241 int err;
242
243 err = dice_interface_check(unit);
244 if (err < 0)
245 goto end;
246
247 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
248 sizeof(*dice), &card);
249 if (err < 0)
250 goto end;
251
252 dice = card->private_data;
253 dice->card = card;
254 dice->unit = unit;
255 card->private_free = dice_card_free;
256
257 spin_lock_init(&dice->lock);
258 mutex_init(&dice->mutex);
259 init_completion(&dice->clock_accepted);
260 init_waitqueue_head(&dice->hwdep_wait);
261
262 err = snd_dice_transaction_init(dice);
263 if (err < 0)
264 goto error;
265
266 err = dice_read_params(dice);
267 if (err < 0)
268 goto error;
269
270 dice_card_strings(dice);
271
272 err = snd_dice_create_pcm(dice);
273 if (err < 0)
274 goto error;
275
276 err = snd_dice_create_hwdep(dice);
277 if (err < 0)
278 goto error;
279
280 snd_dice_create_proc(dice);
281
282 err = snd_dice_create_midi(dice);
283 if (err < 0)
284 goto error;
285
286 err = snd_dice_stream_init_duplex(dice);
287 if (err < 0)
288 goto error;
289
290 err = snd_card_register(card);
291 if (err < 0) {
292 snd_dice_stream_destroy_duplex(dice);
293 goto error;
294 }
295
296 dev_set_drvdata(&unit->device, dice);
297end:
298 return err;
299error:
300 snd_card_free(card);
301 return err;
302}
303
304static void dice_remove(struct fw_unit *unit)
305{
306 struct snd_dice *dice = dev_get_drvdata(&unit->device);
307
308 snd_card_disconnect(dice->card);
309
310 snd_dice_stream_destroy_duplex(dice);
311
312 snd_card_free_when_closed(dice->card);
313}
314
315static void dice_bus_reset(struct fw_unit *unit)
316{
317 struct snd_dice *dice = dev_get_drvdata(&unit->device);
318
319 /* The handler address register becomes initialized. */
320 snd_dice_transaction_reinit(dice);
321
322 mutex_lock(&dice->mutex);
323 snd_dice_stream_update_duplex(dice);
324 mutex_unlock(&dice->mutex);
325}
326
327#define DICE_INTERFACE 0x000001
328
329static const struct ieee1394_device_id dice_id_table[] = {
330 {
331 .match_flags = IEEE1394_MATCH_VERSION,
332 .version = DICE_INTERFACE,
333 },
334 { }
335};
336MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
337
338static struct fw_driver dice_driver = {
339 .driver = {
340 .owner = THIS_MODULE,
341 .name = KBUILD_MODNAME,
342 .bus = &fw_bus_type,
343 },
344 .probe = dice_probe,
345 .update = dice_bus_reset,
346 .remove = dice_remove,
347 .id_table = dice_id_table,
348};
349
350static int __init alsa_dice_init(void)
351{
352 return driver_register(&dice_driver.driver);
353}
354
355static void __exit alsa_dice_exit(void)
356{
357 driver_unregister(&dice_driver.driver);
358}
359
360module_init(alsa_dice_init);
361module_exit(alsa_dice_exit);
diff --git a/sound/firewire/dice/dice.h b/sound/firewire/dice/dice.h
new file mode 100644
index 000000000000..ecf5dc862235
--- /dev/null
+++ b/sound/firewire/dice/dice.h
@@ -0,0 +1,189 @@
1/*
2 * dice.h - a part of driver for Dice based devices
3 *
4 * Copyright (c) Clemens Ladisch
5 * Copyright (c) 2014 Takashi Sakamoto
6 *
7 * Licensed under the terms of the GNU General Public License, version 2.
8 */
9
10#ifndef SOUND_DICE_H_INCLUDED
11#define SOUND_DICE_H_INCLUDED
12
13#include <linux/compat.h>
14#include <linux/completion.h>
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <linux/firewire.h>
18#include <linux/firewire-constants.h>
19#include <linux/jiffies.h>
20#include <linux/module.h>
21#include <linux/mod_devicetable.h>
22#include <linux/mutex.h>
23#include <linux/slab.h>
24#include <linux/spinlock.h>
25#include <linux/wait.h>
26
27#include <sound/control.h>
28#include <sound/core.h>
29#include <sound/firewire.h>
30#include <sound/hwdep.h>
31#include <sound/info.h>
32#include <sound/initval.h>
33#include <sound/pcm.h>
34#include <sound/pcm_params.h>
35#include <sound/rawmidi.h>
36
37#include "../amdtp.h"
38#include "../iso-resources.h"
39#include "../lib.h"
40#include "dice-interface.h"
41
42struct snd_dice {
43 struct snd_card *card;
44 struct fw_unit *unit;
45 spinlock_t lock;
46 struct mutex mutex;
47
48 /* Offsets for sub-addresses */
49 unsigned int global_offset;
50 unsigned int rx_offset;
51 unsigned int tx_offset;
52 unsigned int sync_offset;
53 unsigned int rsrv_offset;
54
55 unsigned int clock_caps;
56 unsigned int tx_channels[3];
57 unsigned int rx_channels[3];
58 unsigned int tx_midi_ports[3];
59 unsigned int rx_midi_ports[3];
60
61 struct fw_address_handler notification_handler;
62 int owner_generation;
63 u32 notification_bits;
64
65 /* For uapi */
66 int dev_lock_count; /* > 0 driver, < 0 userspace */
67 bool dev_lock_changed;
68 wait_queue_head_t hwdep_wait;
69
70 /* For streaming */
71 struct fw_iso_resources tx_resources;
72 struct fw_iso_resources rx_resources;
73 struct amdtp_stream tx_stream;
74 struct amdtp_stream rx_stream;
75 bool global_enabled;
76 struct completion clock_accepted;
77 unsigned int substreams_counter;
78};
79
80enum snd_dice_addr_type {
81 SND_DICE_ADDR_TYPE_PRIVATE,
82 SND_DICE_ADDR_TYPE_GLOBAL,
83 SND_DICE_ADDR_TYPE_TX,
84 SND_DICE_ADDR_TYPE_RX,
85 SND_DICE_ADDR_TYPE_SYNC,
86 SND_DICE_ADDR_TYPE_RSRV,
87};
88
89int snd_dice_transaction_write(struct snd_dice *dice,
90 enum snd_dice_addr_type type,
91 unsigned int offset,
92 void *buf, unsigned int len);
93int snd_dice_transaction_read(struct snd_dice *dice,
94 enum snd_dice_addr_type type, unsigned int offset,
95 void *buf, unsigned int len);
96
97static inline int snd_dice_transaction_write_global(struct snd_dice *dice,
98 unsigned int offset,
99 void *buf, unsigned int len)
100{
101 return snd_dice_transaction_write(dice,
102 SND_DICE_ADDR_TYPE_GLOBAL, offset,
103 buf, len);
104}
105static inline int snd_dice_transaction_read_global(struct snd_dice *dice,
106 unsigned int offset,
107 void *buf, unsigned int len)
108{
109 return snd_dice_transaction_read(dice,
110 SND_DICE_ADDR_TYPE_GLOBAL, offset,
111 buf, len);
112}
113static inline int snd_dice_transaction_write_tx(struct snd_dice *dice,
114 unsigned int offset,
115 void *buf, unsigned int len)
116{
117 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset,
118 buf, len);
119}
120static inline int snd_dice_transaction_read_tx(struct snd_dice *dice,
121 unsigned int offset,
122 void *buf, unsigned int len)
123{
124 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset,
125 buf, len);
126}
127static inline int snd_dice_transaction_write_rx(struct snd_dice *dice,
128 unsigned int offset,
129 void *buf, unsigned int len)
130{
131 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset,
132 buf, len);
133}
134static inline int snd_dice_transaction_read_rx(struct snd_dice *dice,
135 unsigned int offset,
136 void *buf, unsigned int len)
137{
138 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset,
139 buf, len);
140}
141static inline int snd_dice_transaction_write_sync(struct snd_dice *dice,
142 unsigned int offset,
143 void *buf, unsigned int len)
144{
145 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
146 buf, len);
147}
148static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
149 unsigned int offset,
150 void *buf, unsigned int len)
151{
152 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
153 buf, len);
154}
155
156int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
157 unsigned int *source);
158int snd_dice_transaction_set_rate(struct snd_dice *dice, unsigned int rate);
159int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate);
160int snd_dice_transaction_set_enable(struct snd_dice *dice);
161void snd_dice_transaction_clear_enable(struct snd_dice *dice);
162int snd_dice_transaction_init(struct snd_dice *dice);
163int snd_dice_transaction_reinit(struct snd_dice *dice);
164void snd_dice_transaction_destroy(struct snd_dice *dice);
165
166#define SND_DICE_RATES_COUNT 7
167extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT];
168
169int snd_dice_stream_get_rate_mode(struct snd_dice *dice,
170 unsigned int rate, unsigned int *mode);
171
172int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate);
173void snd_dice_stream_stop_duplex(struct snd_dice *dice);
174int snd_dice_stream_init_duplex(struct snd_dice *dice);
175void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
176void snd_dice_stream_update_duplex(struct snd_dice *dice);
177
178int snd_dice_stream_lock_try(struct snd_dice *dice);
179void snd_dice_stream_lock_release(struct snd_dice *dice);
180
181int snd_dice_create_pcm(struct snd_dice *dice);
182
183int snd_dice_create_hwdep(struct snd_dice *dice);
184
185void snd_dice_create_proc(struct snd_dice *dice);
186
187int snd_dice_create_midi(struct snd_dice *dice);
188
189#endif
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
index 7ac94439e758..48d6dca471c6 100644
--- a/sound/firewire/isight.c
+++ b/sound/firewire/isight.c
@@ -131,14 +131,8 @@ static void isight_samples(struct isight *isight,
131 131
132static void isight_pcm_abort(struct isight *isight) 132static void isight_pcm_abort(struct isight *isight)
133{ 133{
134 unsigned long flags; 134 if (ACCESS_ONCE(isight->pcm_active))
135 135 snd_pcm_stop_xrun(isight->pcm);
136 if (ACCESS_ONCE(isight->pcm_active)) {
137 snd_pcm_stream_lock_irqsave(isight->pcm, flags);
138 if (snd_pcm_running(isight->pcm))
139 snd_pcm_stop(isight->pcm, SNDRV_PCM_STATE_XRUN);
140 snd_pcm_stream_unlock_irqrestore(isight->pcm, flags);
141 }
142} 136}
143 137
144static void isight_dropped_samples(struct isight *isight, unsigned int total) 138static void isight_dropped_samples(struct isight *isight, unsigned int total)
diff --git a/sound/firewire/oxfw/Makefile b/sound/firewire/oxfw/Makefile
new file mode 100644
index 000000000000..a926850864f6
--- /dev/null
+++ b/sound/firewire/oxfw/Makefile
@@ -0,0 +1,3 @@
1snd-oxfw-objs := oxfw-command.o oxfw-stream.o oxfw-control.o oxfw-pcm.o \
2 oxfw-proc.o oxfw-midi.o oxfw-hwdep.o oxfw.o
3obj-m += snd-oxfw.o
diff --git a/sound/firewire/oxfw/oxfw-command.c b/sound/firewire/oxfw/oxfw-command.c
new file mode 100644
index 000000000000..12ef3253bc89
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw-command.c
@@ -0,0 +1,153 @@
1/*
2 * oxfw_command.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) 2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "oxfw.h"
10
11int avc_stream_set_format(struct fw_unit *unit, enum avc_general_plug_dir dir,
12 unsigned int pid, u8 *format, unsigned int len)
13{
14 u8 *buf;
15 int err;
16
17 buf = kmalloc(len + 10, GFP_KERNEL);
18 if (buf == NULL)
19 return -ENOMEM;
20
21 buf[0] = 0x00; /* CONTROL */
22 buf[1] = 0xff; /* UNIT */
23 buf[2] = 0xbf; /* EXTENDED STREAM FORMAT INFORMATION */
24 buf[3] = 0xc0; /* SINGLE subfunction */
25 buf[4] = dir; /* Plug Direction */
26 buf[5] = 0x00; /* UNIT */
27 buf[6] = 0x00; /* PCR (Isochronous Plug) */
28 buf[7] = 0xff & pid; /* Plug ID */
29 buf[8] = 0xff; /* Padding */
30 buf[9] = 0xff; /* Support status in response */
31 memcpy(buf + 10, format, len);
32
33 /* do transaction and check buf[1-8] are the same against command */
34 err = fcp_avc_transaction(unit, buf, len + 10, buf, len + 10,
35 BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
36 BIT(6) | BIT(7) | BIT(8));
37 if ((err > 0) && (err < len + 10))
38 err = -EIO;
39 else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
40 err = -ENOSYS;
41 else if (buf[0] == 0x0a) /* REJECTED */
42 err = -EINVAL;
43 else
44 err = 0;
45
46 kfree(buf);
47
48 return err;
49}
50
51int avc_stream_get_format(struct fw_unit *unit,
52 enum avc_general_plug_dir dir, unsigned int pid,
53 u8 *buf, unsigned int *len, unsigned int eid)
54{
55 unsigned int subfunc;
56 int err;
57
58 if (eid == 0xff)
59 subfunc = 0xc0; /* SINGLE */
60 else
61 subfunc = 0xc1; /* LIST */
62
63 buf[0] = 0x01; /* STATUS */
64 buf[1] = 0xff; /* UNIT */
65 buf[2] = 0xbf; /* EXTENDED STREAM FORMAT INFORMATION */
66 buf[3] = subfunc; /* SINGLE or LIST */
67 buf[4] = dir; /* Plug Direction */
68 buf[5] = 0x00; /* Unit */
69 buf[6] = 0x00; /* PCR (Isochronous Plug) */
70 buf[7] = 0xff & pid; /* Plug ID */
71 buf[8] = 0xff; /* Padding */
72 buf[9] = 0xff; /* support status in response */
73 buf[10] = 0xff & eid; /* entry ID for LIST subfunction */
74 buf[11] = 0xff; /* padding */
75
76 /* do transaction and check buf[1-7] are the same against command */
77 err = fcp_avc_transaction(unit, buf, 12, buf, *len,
78 BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
79 BIT(6) | BIT(7));
80 if ((err > 0) && (err < 10))
81 err = -EIO;
82 else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
83 err = -ENOSYS;
84 else if (buf[0] == 0x0a) /* REJECTED */
85 err = -EINVAL;
86 else if (buf[0] == 0x0b) /* IN TRANSITION */
87 err = -EAGAIN;
88 /* LIST subfunction has entry ID */
89 else if ((subfunc == 0xc1) && (buf[10] != eid))
90 err = -EIO;
91 if (err < 0)
92 goto end;
93
94 /* keep just stream format information */
95 if (subfunc == 0xc0) {
96 memmove(buf, buf + 10, err - 10);
97 *len = err - 10;
98 } else {
99 memmove(buf, buf + 11, err - 11);
100 *len = err - 11;
101 }
102
103 err = 0;
104end:
105 return err;
106}
107
108int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate,
109 enum avc_general_plug_dir dir,
110 unsigned short pid)
111{
112 unsigned int sfc;
113 u8 *buf;
114 int err;
115
116 for (sfc = 0; sfc < CIP_SFC_COUNT; sfc++) {
117 if (amdtp_rate_table[sfc] == rate)
118 break;
119 }
120 if (sfc == CIP_SFC_COUNT)
121 return -EINVAL;
122
123 buf = kzalloc(8, GFP_KERNEL);
124 if (buf == NULL)
125 return -ENOMEM;
126
127 buf[0] = 0x02; /* SPECIFIC INQUIRY */
128 buf[1] = 0xff; /* UNIT */
129 if (dir == AVC_GENERAL_PLUG_DIR_IN)
130 buf[2] = 0x19; /* INPUT PLUG SIGNAL FORMAT */
131 else
132 buf[2] = 0x18; /* OUTPUT PLUG SIGNAL FORMAT */
133 buf[3] = 0xff & pid; /* plug id */
134 buf[4] = 0x90; /* EOH_1, Form_1, FMT. AM824 */
135 buf[5] = 0x07 & sfc; /* FDF-hi. AM824, frequency */
136 buf[6] = 0xff; /* FDF-mid. AM824, SYT hi (not used) */
137 buf[7] = 0xff; /* FDF-low. AM824, SYT lo (not used) */
138
139 /* do transaction and check buf[1-5] are the same against command */
140 err = fcp_avc_transaction(unit, buf, 8, buf, 8,
141 BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5));
142 if ((err > 0) && (err < 8))
143 err = -EIO;
144 else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
145 err = -ENOSYS;
146 if (err < 0)
147 goto end;
148
149 err = 0;
150end:
151 kfree(buf);
152 return err;
153}
diff --git a/sound/firewire/oxfw/oxfw-control.c b/sound/firewire/oxfw/oxfw-control.c
new file mode 100644
index 000000000000..02a1cb90f20d
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw-control.c
@@ -0,0 +1,283 @@
1/*
2 * oxfw_stream.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include "oxfw.h"
9
10enum control_action { CTL_READ, CTL_WRITE };
11enum control_attribute {
12 CTL_MIN = 0x02,
13 CTL_MAX = 0x03,
14 CTL_CURRENT = 0x10,
15};
16
17static int oxfw_mute_command(struct snd_oxfw *oxfw, bool *value,
18 enum control_action action)
19{
20 u8 *buf;
21 u8 response_ok;
22 int err;
23
24 buf = kmalloc(11, GFP_KERNEL);
25 if (!buf)
26 return -ENOMEM;
27
28 if (action == CTL_READ) {
29 buf[0] = 0x01; /* AV/C, STATUS */
30 response_ok = 0x0c; /* STABLE */
31 } else {
32 buf[0] = 0x00; /* AV/C, CONTROL */
33 response_ok = 0x09; /* ACCEPTED */
34 }
35 buf[1] = 0x08; /* audio unit 0 */
36 buf[2] = 0xb8; /* FUNCTION BLOCK */
37 buf[3] = 0x81; /* function block type: feature */
38 buf[4] = oxfw->device_info->mute_fb_id; /* function block ID */
39 buf[5] = 0x10; /* control attribute: current */
40 buf[6] = 0x02; /* selector length */
41 buf[7] = 0x00; /* audio channel number */
42 buf[8] = 0x01; /* control selector: mute */
43 buf[9] = 0x01; /* control data length */
44 if (action == CTL_READ)
45 buf[10] = 0xff;
46 else
47 buf[10] = *value ? 0x70 : 0x60;
48
49 err = fcp_avc_transaction(oxfw->unit, buf, 11, buf, 11, 0x3fe);
50 if (err < 0)
51 goto error;
52 if (err < 11) {
53 dev_err(&oxfw->unit->device, "short FCP response\n");
54 err = -EIO;
55 goto error;
56 }
57 if (buf[0] != response_ok) {
58 dev_err(&oxfw->unit->device, "mute command failed\n");
59 err = -EIO;
60 goto error;
61 }
62 if (action == CTL_READ)
63 *value = buf[10] == 0x70;
64
65 err = 0;
66
67error:
68 kfree(buf);
69
70 return err;
71}
72
73static int oxfw_volume_command(struct snd_oxfw *oxfw, s16 *value,
74 unsigned int channel,
75 enum control_attribute attribute,
76 enum control_action action)
77{
78 u8 *buf;
79 u8 response_ok;
80 int err;
81
82 buf = kmalloc(12, GFP_KERNEL);
83 if (!buf)
84 return -ENOMEM;
85
86 if (action == CTL_READ) {
87 buf[0] = 0x01; /* AV/C, STATUS */
88 response_ok = 0x0c; /* STABLE */
89 } else {
90 buf[0] = 0x00; /* AV/C, CONTROL */
91 response_ok = 0x09; /* ACCEPTED */
92 }
93 buf[1] = 0x08; /* audio unit 0 */
94 buf[2] = 0xb8; /* FUNCTION BLOCK */
95 buf[3] = 0x81; /* function block type: feature */
96 buf[4] = oxfw->device_info->volume_fb_id; /* function block ID */
97 buf[5] = attribute; /* control attribute */
98 buf[6] = 0x02; /* selector length */
99 buf[7] = channel; /* audio channel number */
100 buf[8] = 0x02; /* control selector: volume */
101 buf[9] = 0x02; /* control data length */
102 if (action == CTL_READ) {
103 buf[10] = 0xff;
104 buf[11] = 0xff;
105 } else {
106 buf[10] = *value >> 8;
107 buf[11] = *value;
108 }
109
110 err = fcp_avc_transaction(oxfw->unit, buf, 12, buf, 12, 0x3fe);
111 if (err < 0)
112 goto error;
113 if (err < 12) {
114 dev_err(&oxfw->unit->device, "short FCP response\n");
115 err = -EIO;
116 goto error;
117 }
118 if (buf[0] != response_ok) {
119 dev_err(&oxfw->unit->device, "volume command failed\n");
120 err = -EIO;
121 goto error;
122 }
123 if (action == CTL_READ)
124 *value = (buf[10] << 8) | buf[11];
125
126 err = 0;
127
128error:
129 kfree(buf);
130
131 return err;
132}
133
134static int oxfw_mute_get(struct snd_kcontrol *control,
135 struct snd_ctl_elem_value *value)
136{
137 struct snd_oxfw *oxfw = control->private_data;
138
139 value->value.integer.value[0] = !oxfw->mute;
140
141 return 0;
142}
143
144static int oxfw_mute_put(struct snd_kcontrol *control,
145 struct snd_ctl_elem_value *value)
146{
147 struct snd_oxfw *oxfw = control->private_data;
148 bool mute;
149 int err;
150
151 mute = !value->value.integer.value[0];
152
153 if (mute == oxfw->mute)
154 return 0;
155
156 err = oxfw_mute_command(oxfw, &mute, CTL_WRITE);
157 if (err < 0)
158 return err;
159 oxfw->mute = mute;
160
161 return 1;
162}
163
164static int oxfw_volume_info(struct snd_kcontrol *control,
165 struct snd_ctl_elem_info *info)
166{
167 struct snd_oxfw *oxfw = control->private_data;
168
169 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
170 info->count = oxfw->device_info->mixer_channels;
171 info->value.integer.min = oxfw->volume_min;
172 info->value.integer.max = oxfw->volume_max;
173
174 return 0;
175}
176
177static const u8 channel_map[6] = { 0, 1, 4, 5, 2, 3 };
178
179static int oxfw_volume_get(struct snd_kcontrol *control,
180 struct snd_ctl_elem_value *value)
181{
182 struct snd_oxfw *oxfw = control->private_data;
183 unsigned int i;
184
185 for (i = 0; i < oxfw->device_info->mixer_channels; ++i)
186 value->value.integer.value[channel_map[i]] = oxfw->volume[i];
187
188 return 0;
189}
190
191static int oxfw_volume_put(struct snd_kcontrol *control,
192 struct snd_ctl_elem_value *value)
193{
194 struct snd_oxfw *oxfw = control->private_data;
195 unsigned int i, changed_channels;
196 bool equal_values = true;
197 s16 volume;
198 int err;
199
200 for (i = 0; i < oxfw->device_info->mixer_channels; ++i) {
201 if (value->value.integer.value[i] < oxfw->volume_min ||
202 value->value.integer.value[i] > oxfw->volume_max)
203 return -EINVAL;
204 if (value->value.integer.value[i] !=
205 value->value.integer.value[0])
206 equal_values = false;
207 }
208
209 changed_channels = 0;
210 for (i = 0; i < oxfw->device_info->mixer_channels; ++i)
211 if (value->value.integer.value[channel_map[i]] !=
212 oxfw->volume[i])
213 changed_channels |= 1 << (i + 1);
214
215 if (equal_values && changed_channels != 0)
216 changed_channels = 1 << 0;
217
218 for (i = 0; i <= oxfw->device_info->mixer_channels; ++i) {
219 volume = value->value.integer.value[channel_map[i ? i - 1 : 0]];
220 if (changed_channels & (1 << i)) {
221 err = oxfw_volume_command(oxfw, &volume, i,
222 CTL_CURRENT, CTL_WRITE);
223 if (err < 0)
224 return err;
225 }
226 if (i > 0)
227 oxfw->volume[i - 1] = volume;
228 }
229
230 return changed_channels != 0;
231}
232
233int snd_oxfw_create_mixer(struct snd_oxfw *oxfw)
234{
235 static const struct snd_kcontrol_new controls[] = {
236 {
237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
238 .name = "PCM Playback Switch",
239 .info = snd_ctl_boolean_mono_info,
240 .get = oxfw_mute_get,
241 .put = oxfw_mute_put,
242 },
243 {
244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
245 .name = "PCM Playback Volume",
246 .info = oxfw_volume_info,
247 .get = oxfw_volume_get,
248 .put = oxfw_volume_put,
249 },
250 };
251 unsigned int i, first_ch;
252 int err;
253
254 err = oxfw_volume_command(oxfw, &oxfw->volume_min,
255 0, CTL_MIN, CTL_READ);
256 if (err < 0)
257 return err;
258 err = oxfw_volume_command(oxfw, &oxfw->volume_max,
259 0, CTL_MAX, CTL_READ);
260 if (err < 0)
261 return err;
262
263 err = oxfw_mute_command(oxfw, &oxfw->mute, CTL_READ);
264 if (err < 0)
265 return err;
266
267 first_ch = oxfw->device_info->mixer_channels == 1 ? 0 : 1;
268 for (i = 0; i < oxfw->device_info->mixer_channels; ++i) {
269 err = oxfw_volume_command(oxfw, &oxfw->volume[i],
270 first_ch + i, CTL_CURRENT, CTL_READ);
271 if (err < 0)
272 return err;
273 }
274
275 for (i = 0; i < ARRAY_SIZE(controls); ++i) {
276 err = snd_ctl_add(oxfw->card,
277 snd_ctl_new1(&controls[i], oxfw));
278 if (err < 0)
279 return err;
280 }
281
282 return 0;
283}
diff --git a/sound/firewire/oxfw/oxfw-hwdep.c b/sound/firewire/oxfw/oxfw-hwdep.c
new file mode 100644
index 000000000000..ff2687ad0460
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw-hwdep.c
@@ -0,0 +1,190 @@
1/*
2 * oxfw_hwdep.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) 2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9/*
10 * This codes give three functionality.
11 *
12 * 1.get firewire node information
13 * 2.get notification about starting/stopping stream
14 * 3.lock/unlock stream
15 */
16
17#include "oxfw.h"
18
19static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
20 loff_t *offset)
21{
22 struct snd_oxfw *oxfw = hwdep->private_data;
23 DEFINE_WAIT(wait);
24 union snd_firewire_event event;
25
26 spin_lock_irq(&oxfw->lock);
27
28 while (!oxfw->dev_lock_changed) {
29 prepare_to_wait(&oxfw->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
30 spin_unlock_irq(&oxfw->lock);
31 schedule();
32 finish_wait(&oxfw->hwdep_wait, &wait);
33 if (signal_pending(current))
34 return -ERESTARTSYS;
35 spin_lock_irq(&oxfw->lock);
36 }
37
38 memset(&event, 0, sizeof(event));
39 if (oxfw->dev_lock_changed) {
40 event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
41 event.lock_status.status = (oxfw->dev_lock_count > 0);
42 oxfw->dev_lock_changed = false;
43
44 count = min_t(long, count, sizeof(event.lock_status));
45 }
46
47 spin_unlock_irq(&oxfw->lock);
48
49 if (copy_to_user(buf, &event, count))
50 return -EFAULT;
51
52 return count;
53}
54
55static unsigned int hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
56 poll_table *wait)
57{
58 struct snd_oxfw *oxfw = hwdep->private_data;
59 unsigned int events;
60
61 poll_wait(file, &oxfw->hwdep_wait, wait);
62
63 spin_lock_irq(&oxfw->lock);
64 if (oxfw->dev_lock_changed)
65 events = POLLIN | POLLRDNORM;
66 else
67 events = 0;
68 spin_unlock_irq(&oxfw->lock);
69
70 return events;
71}
72
73static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg)
74{
75 struct fw_device *dev = fw_parent_device(oxfw->unit);
76 struct snd_firewire_get_info info;
77
78 memset(&info, 0, sizeof(info));
79 info.type = SNDRV_FIREWIRE_TYPE_OXFW;
80 info.card = dev->card->index;
81 *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);
82 *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);
83 strlcpy(info.device_name, dev_name(&dev->device),
84 sizeof(info.device_name));
85
86 if (copy_to_user(arg, &info, sizeof(info)))
87 return -EFAULT;
88
89 return 0;
90}
91
92static int hwdep_lock(struct snd_oxfw *oxfw)
93{
94 int err;
95
96 spin_lock_irq(&oxfw->lock);
97
98 if (oxfw->dev_lock_count == 0) {
99 oxfw->dev_lock_count = -1;
100 err = 0;
101 } else {
102 err = -EBUSY;
103 }
104
105 spin_unlock_irq(&oxfw->lock);
106
107 return err;
108}
109
110static int hwdep_unlock(struct snd_oxfw *oxfw)
111{
112 int err;
113
114 spin_lock_irq(&oxfw->lock);
115
116 if (oxfw->dev_lock_count == -1) {
117 oxfw->dev_lock_count = 0;
118 err = 0;
119 } else {
120 err = -EBADFD;
121 }
122
123 spin_unlock_irq(&oxfw->lock);
124
125 return err;
126}
127
128static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
129{
130 struct snd_oxfw *oxfw = hwdep->private_data;
131
132 spin_lock_irq(&oxfw->lock);
133 if (oxfw->dev_lock_count == -1)
134 oxfw->dev_lock_count = 0;
135 spin_unlock_irq(&oxfw->lock);
136
137 return 0;
138}
139
140static int hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,
141 unsigned int cmd, unsigned long arg)
142{
143 struct snd_oxfw *oxfw = hwdep->private_data;
144
145 switch (cmd) {
146 case SNDRV_FIREWIRE_IOCTL_GET_INFO:
147 return hwdep_get_info(oxfw, (void __user *)arg);
148 case SNDRV_FIREWIRE_IOCTL_LOCK:
149 return hwdep_lock(oxfw);
150 case SNDRV_FIREWIRE_IOCTL_UNLOCK:
151 return hwdep_unlock(oxfw);
152 default:
153 return -ENOIOCTLCMD;
154 }
155}
156
157#ifdef CONFIG_COMPAT
158static int hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
159 unsigned int cmd, unsigned long arg)
160{
161 return hwdep_ioctl(hwdep, file, cmd,
162 (unsigned long)compat_ptr(arg));
163}
164#else
165#define hwdep_compat_ioctl NULL
166#endif
167
168int snd_oxfw_create_hwdep(struct snd_oxfw *oxfw)
169{
170 static const struct snd_hwdep_ops hwdep_ops = {
171 .read = hwdep_read,
172 .release = hwdep_release,
173 .poll = hwdep_poll,
174 .ioctl = hwdep_ioctl,
175 .ioctl_compat = hwdep_compat_ioctl,
176 };
177 struct snd_hwdep *hwdep;
178 int err;
179
180 err = snd_hwdep_new(oxfw->card, oxfw->card->driver, 0, &hwdep);
181 if (err < 0)
182 goto end;
183 strcpy(hwdep->name, oxfw->card->driver);
184 hwdep->iface = SNDRV_HWDEP_IFACE_FW_OXFW;
185 hwdep->ops = hwdep_ops;
186 hwdep->private_data = oxfw;
187 hwdep->exclusive = true;
188end:
189 return err;
190}
diff --git a/sound/firewire/oxfw/oxfw-midi.c b/sound/firewire/oxfw/oxfw-midi.c
new file mode 100644
index 000000000000..540a30338516
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw-midi.c
@@ -0,0 +1,207 @@
1/*
2 * oxfw_midi.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) 2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "oxfw.h"
10
11static int midi_capture_open(struct snd_rawmidi_substream *substream)
12{
13 struct snd_oxfw *oxfw = substream->rmidi->private_data;
14 int err;
15
16 err = snd_oxfw_stream_lock_try(oxfw);
17 if (err < 0)
18 return err;
19
20 mutex_lock(&oxfw->mutex);
21
22 oxfw->capture_substreams++;
23 err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->tx_stream, 0, 0);
24
25 mutex_unlock(&oxfw->mutex);
26
27 if (err < 0)
28 snd_oxfw_stream_lock_release(oxfw);
29
30 return err;
31}
32
33static int midi_playback_open(struct snd_rawmidi_substream *substream)
34{
35 struct snd_oxfw *oxfw = substream->rmidi->private_data;
36 int err;
37
38 err = snd_oxfw_stream_lock_try(oxfw);
39 if (err < 0)
40 return err;
41
42 mutex_lock(&oxfw->mutex);
43
44 oxfw->playback_substreams++;
45 err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->rx_stream, 0, 0);
46
47 mutex_unlock(&oxfw->mutex);
48
49 if (err < 0)
50 snd_oxfw_stream_lock_release(oxfw);
51
52 return err;
53}
54
55static int midi_capture_close(struct snd_rawmidi_substream *substream)
56{
57 struct snd_oxfw *oxfw = substream->rmidi->private_data;
58
59 mutex_lock(&oxfw->mutex);
60
61 oxfw->capture_substreams--;
62 snd_oxfw_stream_stop_simplex(oxfw, &oxfw->tx_stream);
63
64 mutex_unlock(&oxfw->mutex);
65
66 snd_oxfw_stream_lock_release(oxfw);
67 return 0;
68}
69
70static int midi_playback_close(struct snd_rawmidi_substream *substream)
71{
72 struct snd_oxfw *oxfw = substream->rmidi->private_data;
73
74 mutex_lock(&oxfw->mutex);
75
76 oxfw->playback_substreams--;
77 snd_oxfw_stream_stop_simplex(oxfw, &oxfw->rx_stream);
78
79 mutex_unlock(&oxfw->mutex);
80
81 snd_oxfw_stream_lock_release(oxfw);
82 return 0;
83}
84
85static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
86{
87 struct snd_oxfw *oxfw = substrm->rmidi->private_data;
88 unsigned long flags;
89
90 spin_lock_irqsave(&oxfw->lock, flags);
91
92 if (up)
93 amdtp_stream_midi_trigger(&oxfw->tx_stream,
94 substrm->number, substrm);
95 else
96 amdtp_stream_midi_trigger(&oxfw->tx_stream,
97 substrm->number, NULL);
98
99 spin_unlock_irqrestore(&oxfw->lock, flags);
100}
101
102static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
103{
104 struct snd_oxfw *oxfw = substrm->rmidi->private_data;
105 unsigned long flags;
106
107 spin_lock_irqsave(&oxfw->lock, flags);
108
109 if (up)
110 amdtp_stream_midi_trigger(&oxfw->rx_stream,
111 substrm->number, substrm);
112 else
113 amdtp_stream_midi_trigger(&oxfw->rx_stream,
114 substrm->number, NULL);
115
116 spin_unlock_irqrestore(&oxfw->lock, flags);
117}
118
119static struct snd_rawmidi_ops midi_capture_ops = {
120 .open = midi_capture_open,
121 .close = midi_capture_close,
122 .trigger = midi_capture_trigger,
123};
124
125static struct snd_rawmidi_ops midi_playback_ops = {
126 .open = midi_playback_open,
127 .close = midi_playback_close,
128 .trigger = midi_playback_trigger,
129};
130
131static void set_midi_substream_names(struct snd_oxfw *oxfw,
132 struct snd_rawmidi_str *str)
133{
134 struct snd_rawmidi_substream *subs;
135
136 list_for_each_entry(subs, &str->substreams, list) {
137 snprintf(subs->name, sizeof(subs->name),
138 "%s MIDI %d",
139 oxfw->card->shortname, subs->number + 1);
140 }
141}
142
143int snd_oxfw_create_midi(struct snd_oxfw *oxfw)
144{
145 struct snd_oxfw_stream_formation formation;
146 struct snd_rawmidi *rmidi;
147 struct snd_rawmidi_str *str;
148 u8 *format;
149 int i, err;
150
151 /* If its stream has MIDI conformant data channel, add one MIDI port */
152 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
153 format = oxfw->tx_stream_formats[i];
154 if (format != NULL) {
155 err = snd_oxfw_stream_parse_format(format, &formation);
156 if (err >= 0 && formation.midi > 0)
157 oxfw->midi_input_ports = 1;
158 }
159
160 format = oxfw->rx_stream_formats[i];
161 if (format != NULL) {
162 err = snd_oxfw_stream_parse_format(format, &formation);
163 if (err >= 0 && formation.midi > 0)
164 oxfw->midi_output_ports = 1;
165 }
166 }
167 if ((oxfw->midi_input_ports == 0) && (oxfw->midi_output_ports == 0))
168 return 0;
169
170 /* create midi ports */
171 err = snd_rawmidi_new(oxfw->card, oxfw->card->driver, 0,
172 oxfw->midi_output_ports, oxfw->midi_input_ports,
173 &rmidi);
174 if (err < 0)
175 return err;
176
177 snprintf(rmidi->name, sizeof(rmidi->name),
178 "%s MIDI", oxfw->card->shortname);
179 rmidi->private_data = oxfw;
180
181 if (oxfw->midi_input_ports > 0) {
182 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
183
184 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
185 &midi_capture_ops);
186
187 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT];
188
189 set_midi_substream_names(oxfw, str);
190 }
191
192 if (oxfw->midi_output_ports > 0) {
193 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
194
195 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
196 &midi_playback_ops);
197
198 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT];
199
200 set_midi_substream_names(oxfw, str);
201 }
202
203 if ((oxfw->midi_output_ports > 0) && (oxfw->midi_input_ports > 0))
204 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
205
206 return 0;
207}
diff --git a/sound/firewire/oxfw/oxfw-pcm.c b/sound/firewire/oxfw/oxfw-pcm.c
new file mode 100644
index 000000000000..9bc556b15a92
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw-pcm.c
@@ -0,0 +1,424 @@
1/*
2 * oxfw_pcm.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include "oxfw.h"
9
10static int hw_rule_rate(struct snd_pcm_hw_params *params,
11 struct snd_pcm_hw_rule *rule)
12{
13 u8 **formats = rule->private;
14 struct snd_interval *r =
15 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
16 const struct snd_interval *c =
17 hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS);
18 struct snd_interval t = {
19 .min = UINT_MAX, .max = 0, .integer = 1
20 };
21 struct snd_oxfw_stream_formation formation;
22 unsigned int i, err;
23
24 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
25 if (formats[i] == NULL)
26 continue;
27
28 err = snd_oxfw_stream_parse_format(formats[i], &formation);
29 if (err < 0)
30 continue;
31 if (!snd_interval_test(c, formation.pcm))
32 continue;
33
34 t.min = min(t.min, formation.rate);
35 t.max = max(t.max, formation.rate);
36
37 }
38 return snd_interval_refine(r, &t);
39}
40
41static int hw_rule_channels(struct snd_pcm_hw_params *params,
42 struct snd_pcm_hw_rule *rule)
43{
44 u8 **formats = rule->private;
45 struct snd_interval *c =
46 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
47 const struct snd_interval *r =
48 hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE);
49 struct snd_oxfw_stream_formation formation;
50 unsigned int i, j, err;
51 unsigned int count, list[SND_OXFW_STREAM_FORMAT_ENTRIES] = {0};
52
53 count = 0;
54 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
55 if (formats[i] == NULL)
56 break;
57
58 err = snd_oxfw_stream_parse_format(formats[i], &formation);
59 if (err < 0)
60 continue;
61 if (!snd_interval_test(r, formation.rate))
62 continue;
63 if (list[count] == formation.pcm)
64 continue;
65
66 for (j = 0; j < ARRAY_SIZE(list); j++) {
67 if (list[j] == formation.pcm)
68 break;
69 }
70 if (j == ARRAY_SIZE(list)) {
71 list[count] = formation.pcm;
72 if (++count == ARRAY_SIZE(list))
73 break;
74 }
75 }
76
77 return snd_interval_list(c, count, list, 0);
78}
79
80static void limit_channels_and_rates(struct snd_pcm_hardware *hw, u8 **formats)
81{
82 struct snd_oxfw_stream_formation formation;
83 unsigned int i, err;
84
85 hw->channels_min = UINT_MAX;
86 hw->channels_max = 0;
87
88 hw->rate_min = UINT_MAX;
89 hw->rate_max = 0;
90 hw->rates = 0;
91
92 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
93 if (formats[i] == NULL)
94 break;
95
96 err = snd_oxfw_stream_parse_format(formats[i], &formation);
97 if (err < 0)
98 continue;
99
100 hw->channels_min = min(hw->channels_min, formation.pcm);
101 hw->channels_max = max(hw->channels_max, formation.pcm);
102
103 hw->rate_min = min(hw->rate_min, formation.rate);
104 hw->rate_max = max(hw->rate_max, formation.rate);
105 hw->rates |= snd_pcm_rate_to_rate_bit(formation.rate);
106 }
107}
108
109static void limit_period_and_buffer(struct snd_pcm_hardware *hw)
110{
111 hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */
112 hw->periods_max = UINT_MAX;
113
114 hw->period_bytes_min = 4 * hw->channels_max; /* bytes for a frame */
115
116 /* Just to prevent from allocating much pages. */
117 hw->period_bytes_max = hw->period_bytes_min * 2048;
118 hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
119}
120
121static int init_hw_params(struct snd_oxfw *oxfw,
122 struct snd_pcm_substream *substream)
123{
124 struct snd_pcm_runtime *runtime = substream->runtime;
125 u8 **formats;
126 struct amdtp_stream *stream;
127 int err;
128
129 runtime->hw.info = SNDRV_PCM_INFO_BATCH |
130 SNDRV_PCM_INFO_BLOCK_TRANSFER |
131 SNDRV_PCM_INFO_INTERLEAVED |
132 SNDRV_PCM_INFO_JOINT_DUPLEX |
133 SNDRV_PCM_INFO_MMAP |
134 SNDRV_PCM_INFO_MMAP_VALID;
135
136 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
137 runtime->hw.formats = AMDTP_IN_PCM_FORMAT_BITS;
138 stream = &oxfw->tx_stream;
139 formats = oxfw->tx_stream_formats;
140 } else {
141 runtime->hw.formats = AMDTP_OUT_PCM_FORMAT_BITS;
142 stream = &oxfw->rx_stream;
143 formats = oxfw->rx_stream_formats;
144 }
145
146 limit_channels_and_rates(&runtime->hw, formats);
147 limit_period_and_buffer(&runtime->hw);
148
149 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
150 hw_rule_channels, formats,
151 SNDRV_PCM_HW_PARAM_RATE, -1);
152 if (err < 0)
153 goto end;
154
155 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
156 hw_rule_rate, formats,
157 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
158 if (err < 0)
159 goto end;
160
161 err = amdtp_stream_add_pcm_hw_constraints(stream, runtime);
162end:
163 return err;
164}
165
166static int limit_to_current_params(struct snd_pcm_substream *substream)
167{
168 struct snd_oxfw *oxfw = substream->private_data;
169 struct snd_oxfw_stream_formation formation;
170 enum avc_general_plug_dir dir;
171 int err;
172
173 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
174 dir = AVC_GENERAL_PLUG_DIR_OUT;
175 else
176 dir = AVC_GENERAL_PLUG_DIR_IN;
177
178 err = snd_oxfw_stream_get_current_formation(oxfw, dir, &formation);
179 if (err < 0)
180 goto end;
181
182 substream->runtime->hw.channels_min = formation.pcm;
183 substream->runtime->hw.channels_max = formation.pcm;
184 substream->runtime->hw.rate_min = formation.rate;
185 substream->runtime->hw.rate_max = formation.rate;
186end:
187 return err;
188}
189
190static int pcm_open(struct snd_pcm_substream *substream)
191{
192 struct snd_oxfw *oxfw = substream->private_data;
193 int err;
194
195 err = snd_oxfw_stream_lock_try(oxfw);
196 if (err < 0)
197 goto end;
198
199 err = init_hw_params(oxfw, substream);
200 if (err < 0)
201 goto err_locked;
202
203 /*
204 * When any PCM streams are already running, the available sampling
205 * rate is limited at current value.
206 */
207 if (amdtp_stream_pcm_running(&oxfw->tx_stream) ||
208 amdtp_stream_pcm_running(&oxfw->rx_stream)) {
209 err = limit_to_current_params(substream);
210 if (err < 0)
211 goto end;
212 }
213
214 snd_pcm_set_sync(substream);
215end:
216 return err;
217err_locked:
218 snd_oxfw_stream_lock_release(oxfw);
219 return err;
220}
221
222static int pcm_close(struct snd_pcm_substream *substream)
223{
224 struct snd_oxfw *oxfw = substream->private_data;
225
226 snd_oxfw_stream_lock_release(oxfw);
227 return 0;
228}
229
230static int pcm_capture_hw_params(struct snd_pcm_substream *substream,
231 struct snd_pcm_hw_params *hw_params)
232{
233 struct snd_oxfw *oxfw = substream->private_data;
234
235
236 if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
237 mutex_lock(&oxfw->mutex);
238 oxfw->capture_substreams++;
239 mutex_unlock(&oxfw->mutex);
240 }
241
242 amdtp_stream_set_pcm_format(&oxfw->tx_stream, params_format(hw_params));
243
244 return snd_pcm_lib_alloc_vmalloc_buffer(substream,
245 params_buffer_bytes(hw_params));
246}
247static int pcm_playback_hw_params(struct snd_pcm_substream *substream,
248 struct snd_pcm_hw_params *hw_params)
249{
250 struct snd_oxfw *oxfw = substream->private_data;
251
252 if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
253 mutex_lock(&oxfw->mutex);
254 oxfw->playback_substreams++;
255 mutex_unlock(&oxfw->mutex);
256 }
257
258 amdtp_stream_set_pcm_format(&oxfw->rx_stream, params_format(hw_params));
259
260 return snd_pcm_lib_alloc_vmalloc_buffer(substream,
261 params_buffer_bytes(hw_params));
262}
263
264static int pcm_capture_hw_free(struct snd_pcm_substream *substream)
265{
266 struct snd_oxfw *oxfw = substream->private_data;
267
268 mutex_lock(&oxfw->mutex);
269
270 if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
271 oxfw->capture_substreams--;
272
273 snd_oxfw_stream_stop_simplex(oxfw, &oxfw->tx_stream);
274
275 mutex_unlock(&oxfw->mutex);
276
277 return snd_pcm_lib_free_vmalloc_buffer(substream);
278}
279static int pcm_playback_hw_free(struct snd_pcm_substream *substream)
280{
281 struct snd_oxfw *oxfw = substream->private_data;
282
283 mutex_lock(&oxfw->mutex);
284
285 if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
286 oxfw->playback_substreams--;
287
288 snd_oxfw_stream_stop_simplex(oxfw, &oxfw->rx_stream);
289
290 mutex_unlock(&oxfw->mutex);
291
292 return snd_pcm_lib_free_vmalloc_buffer(substream);
293}
294
295static int pcm_capture_prepare(struct snd_pcm_substream *substream)
296{
297 struct snd_oxfw *oxfw = substream->private_data;
298 struct snd_pcm_runtime *runtime = substream->runtime;
299 int err;
300
301 mutex_lock(&oxfw->mutex);
302 err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->tx_stream,
303 runtime->rate, runtime->channels);
304 mutex_unlock(&oxfw->mutex);
305 if (err < 0)
306 goto end;
307
308 amdtp_stream_pcm_prepare(&oxfw->tx_stream);
309end:
310 return err;
311}
312static int pcm_playback_prepare(struct snd_pcm_substream *substream)
313{
314 struct snd_oxfw *oxfw = substream->private_data;
315 struct snd_pcm_runtime *runtime = substream->runtime;
316 int err;
317
318 mutex_lock(&oxfw->mutex);
319 err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->rx_stream,
320 runtime->rate, runtime->channels);
321 mutex_unlock(&oxfw->mutex);
322 if (err < 0)
323 goto end;
324
325 amdtp_stream_pcm_prepare(&oxfw->rx_stream);
326end:
327 return err;
328}
329
330static int pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd)
331{
332 struct snd_oxfw *oxfw = substream->private_data;
333 struct snd_pcm_substream *pcm;
334
335 switch (cmd) {
336 case SNDRV_PCM_TRIGGER_START:
337 pcm = substream;
338 break;
339 case SNDRV_PCM_TRIGGER_STOP:
340 pcm = NULL;
341 break;
342 default:
343 return -EINVAL;
344 }
345 amdtp_stream_pcm_trigger(&oxfw->tx_stream, pcm);
346 return 0;
347}
348static int pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd)
349{
350 struct snd_oxfw *oxfw = substream->private_data;
351 struct snd_pcm_substream *pcm;
352
353 switch (cmd) {
354 case SNDRV_PCM_TRIGGER_START:
355 pcm = substream;
356 break;
357 case SNDRV_PCM_TRIGGER_STOP:
358 pcm = NULL;
359 break;
360 default:
361 return -EINVAL;
362 }
363 amdtp_stream_pcm_trigger(&oxfw->rx_stream, pcm);
364 return 0;
365}
366
367static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstm)
368{
369 struct snd_oxfw *oxfw = sbstm->private_data;
370
371 return amdtp_stream_pcm_pointer(&oxfw->tx_stream);
372}
373static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstm)
374{
375 struct snd_oxfw *oxfw = sbstm->private_data;
376
377 return amdtp_stream_pcm_pointer(&oxfw->rx_stream);
378}
379
380int snd_oxfw_create_pcm(struct snd_oxfw *oxfw)
381{
382 static struct snd_pcm_ops capture_ops = {
383 .open = pcm_open,
384 .close = pcm_close,
385 .ioctl = snd_pcm_lib_ioctl,
386 .hw_params = pcm_capture_hw_params,
387 .hw_free = pcm_capture_hw_free,
388 .prepare = pcm_capture_prepare,
389 .trigger = pcm_capture_trigger,
390 .pointer = pcm_capture_pointer,
391 .page = snd_pcm_lib_get_vmalloc_page,
392 .mmap = snd_pcm_lib_mmap_vmalloc,
393 };
394 static struct snd_pcm_ops playback_ops = {
395 .open = pcm_open,
396 .close = pcm_close,
397 .ioctl = snd_pcm_lib_ioctl,
398 .hw_params = pcm_playback_hw_params,
399 .hw_free = pcm_playback_hw_free,
400 .prepare = pcm_playback_prepare,
401 .trigger = pcm_playback_trigger,
402 .pointer = pcm_playback_pointer,
403 .page = snd_pcm_lib_get_vmalloc_page,
404 .mmap = snd_pcm_lib_mmap_vmalloc,
405 };
406 struct snd_pcm *pcm;
407 unsigned int cap = 0;
408 int err;
409
410 if (oxfw->has_output)
411 cap = 1;
412
413 err = snd_pcm_new(oxfw->card, oxfw->card->driver, 0, 1, cap, &pcm);
414 if (err < 0)
415 return err;
416
417 pcm->private_data = oxfw;
418 strcpy(pcm->name, oxfw->card->shortname);
419 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops);
420 if (cap > 0)
421 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops);
422
423 return 0;
424}
diff --git a/sound/firewire/oxfw/oxfw-proc.c b/sound/firewire/oxfw/oxfw-proc.c
new file mode 100644
index 000000000000..604808e5526d
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw-proc.c
@@ -0,0 +1,113 @@
1/*
2 * oxfw_proc.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) 2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "./oxfw.h"
10
11static void proc_read_formation(struct snd_info_entry *entry,
12 struct snd_info_buffer *buffer)
13{
14 struct snd_oxfw *oxfw = entry->private_data;
15 struct snd_oxfw_stream_formation formation, curr;
16 u8 *format;
17 char flag;
18 unsigned int i, err;
19
20 /* Show input. */
21 err = snd_oxfw_stream_get_current_formation(oxfw,
22 AVC_GENERAL_PLUG_DIR_IN,
23 &curr);
24 if (err < 0)
25 return;
26
27 snd_iprintf(buffer, "Input Stream to device:\n");
28 snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
29 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
30 format = oxfw->rx_stream_formats[i];
31 if (format == NULL)
32 continue;
33
34 err = snd_oxfw_stream_parse_format(format, &formation);
35 if (err < 0)
36 continue;
37
38 if (memcmp(&formation, &curr, sizeof(curr)) == 0)
39 flag = '*';
40 else
41 flag = ' ';
42
43 snd_iprintf(buffer, "%c\t%d\t%d\t%d\n", flag,
44 formation.rate, formation.pcm, formation.midi);
45 }
46
47 if (!oxfw->has_output)
48 return;
49
50 /* Show output. */
51 err = snd_oxfw_stream_get_current_formation(oxfw,
52 AVC_GENERAL_PLUG_DIR_OUT,
53 &curr);
54 if (err < 0)
55 return;
56
57 snd_iprintf(buffer, "Output Stream from device:\n");
58 snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
59 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
60 format = oxfw->tx_stream_formats[i];
61 if (format == NULL)
62 continue;
63
64 err = snd_oxfw_stream_parse_format(format, &formation);
65 if (err < 0)
66 continue;
67
68 if (memcmp(&formation, &curr, sizeof(curr)) == 0)
69 flag = '*';
70 else
71 flag = ' ';
72
73 snd_iprintf(buffer, "%c\t%d\t%d\t%d\n", flag,
74 formation.rate, formation.pcm, formation.midi);
75 }
76}
77
78static void add_node(struct snd_oxfw *oxfw, struct snd_info_entry *root,
79 const char *name,
80 void (*op)(struct snd_info_entry *e,
81 struct snd_info_buffer *b))
82{
83 struct snd_info_entry *entry;
84
85 entry = snd_info_create_card_entry(oxfw->card, name, root);
86 if (entry == NULL)
87 return;
88
89 snd_info_set_text_ops(entry, oxfw, op);
90 if (snd_info_register(entry) < 0)
91 snd_info_free_entry(entry);
92}
93
94void snd_oxfw_proc_init(struct snd_oxfw *oxfw)
95{
96 struct snd_info_entry *root;
97
98 /*
99 * All nodes are automatically removed at snd_card_disconnect(),
100 * by following to link list.
101 */
102 root = snd_info_create_card_entry(oxfw->card, "firewire",
103 oxfw->card->proc_root);
104 if (root == NULL)
105 return;
106 root->mode = S_IFDIR | S_IRUGO | S_IXUGO;
107 if (snd_info_register(root) < 0) {
108 snd_info_free_entry(root);
109 return;
110 }
111
112 add_node(oxfw, root, "formation", proc_read_formation);
113}
diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
new file mode 100644
index 000000000000..b77cf80f1678
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw-stream.c
@@ -0,0 +1,685 @@
1/*
2 * oxfw_stream.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) 2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "oxfw.h"
10#include <linux/delay.h>
11
12#define AVC_GENERIC_FRAME_MAXIMUM_BYTES 512
13#define CALLBACK_TIMEOUT 200
14
15/*
16 * According to datasheet of Oxford Semiconductor:
17 * OXFW970: 32.0/44.1/48.0/96.0 Khz, 8 audio channels I/O
18 * OXFW971: 32.0/44.1/48.0/88.2/96.0/192.0 kHz, 16 audio channels I/O, MIDI I/O
19 */
20static const unsigned int oxfw_rate_table[] = {
21 [0] = 32000,
22 [1] = 44100,
23 [2] = 48000,
24 [3] = 88200,
25 [4] = 96000,
26 [5] = 192000,
27};
28
29/*
30 * See Table 5.7 – Sampling frequency for Multi-bit Audio
31 * in AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA)
32 */
33static const unsigned int avc_stream_rate_table[] = {
34 [0] = 0x02,
35 [1] = 0x03,
36 [2] = 0x04,
37 [3] = 0x0a,
38 [4] = 0x05,
39 [5] = 0x07,
40};
41
42static int set_rate(struct snd_oxfw *oxfw, unsigned int rate)
43{
44 int err;
45
46 err = avc_general_set_sig_fmt(oxfw->unit, rate,
47 AVC_GENERAL_PLUG_DIR_IN, 0);
48 if (err < 0)
49 goto end;
50
51 if (oxfw->has_output)
52 err = avc_general_set_sig_fmt(oxfw->unit, rate,
53 AVC_GENERAL_PLUG_DIR_OUT, 0);
54end:
55 return err;
56}
57
58static int set_stream_format(struct snd_oxfw *oxfw, struct amdtp_stream *s,
59 unsigned int rate, unsigned int pcm_channels)
60{
61 u8 **formats;
62 struct snd_oxfw_stream_formation formation;
63 enum avc_general_plug_dir dir;
64 unsigned int i, err, len;
65
66 if (s == &oxfw->tx_stream) {
67 formats = oxfw->tx_stream_formats;
68 dir = AVC_GENERAL_PLUG_DIR_OUT;
69 } else {
70 formats = oxfw->rx_stream_formats;
71 dir = AVC_GENERAL_PLUG_DIR_IN;
72 }
73
74 /* Seek stream format for requirements. */
75 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
76 err = snd_oxfw_stream_parse_format(formats[i], &formation);
77 if (err < 0)
78 return err;
79
80 if ((formation.rate == rate) && (formation.pcm == pcm_channels))
81 break;
82 }
83 if (i == SND_OXFW_STREAM_FORMAT_ENTRIES)
84 return -EINVAL;
85
86 /* If assumed, just change rate. */
87 if (oxfw->assumed)
88 return set_rate(oxfw, rate);
89
90 /* Calculate format length. */
91 len = 5 + formats[i][4] * 2;
92
93 err = avc_stream_set_format(oxfw->unit, dir, 0, formats[i], len);
94 if (err < 0)
95 return err;
96
97 /* Some requests just after changing format causes freezing. */
98 msleep(100);
99
100 return 0;
101}
102
103static void stop_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
104{
105 amdtp_stream_pcm_abort(stream);
106 amdtp_stream_stop(stream);
107
108 if (stream == &oxfw->tx_stream)
109 cmp_connection_break(&oxfw->out_conn);
110 else
111 cmp_connection_break(&oxfw->in_conn);
112}
113
114static int start_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream,
115 unsigned int rate, unsigned int pcm_channels)
116{
117 u8 **formats;
118 struct cmp_connection *conn;
119 struct snd_oxfw_stream_formation formation;
120 unsigned int i, midi_ports;
121 int err;
122
123 if (stream == &oxfw->rx_stream) {
124 formats = oxfw->rx_stream_formats;
125 conn = &oxfw->in_conn;
126 } else {
127 formats = oxfw->tx_stream_formats;
128 conn = &oxfw->out_conn;
129 }
130
131 /* Get stream format */
132 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
133 if (formats[i] == NULL)
134 break;
135
136 err = snd_oxfw_stream_parse_format(formats[i], &formation);
137 if (err < 0)
138 goto end;
139 if (rate != formation.rate)
140 continue;
141 if (pcm_channels == 0 || pcm_channels == formation.pcm)
142 break;
143 }
144 if (i == SND_OXFW_STREAM_FORMAT_ENTRIES) {
145 err = -EINVAL;
146 goto end;
147 }
148
149 pcm_channels = formation.pcm;
150 midi_ports = DIV_ROUND_UP(formation.midi, 8);
151
152 /* The stream should have one pcm channels at least */
153 if (pcm_channels == 0) {
154 err = -EINVAL;
155 goto end;
156 }
157 amdtp_stream_set_parameters(stream, rate, pcm_channels, midi_ports);
158
159 err = cmp_connection_establish(conn,
160 amdtp_stream_get_max_payload(stream));
161 if (err < 0)
162 goto end;
163
164 err = amdtp_stream_start(stream,
165 conn->resources.channel,
166 conn->speed);
167 if (err < 0) {
168 cmp_connection_break(conn);
169 goto end;
170 }
171
172 /* Wait first packet */
173 err = amdtp_stream_wait_callback(stream, CALLBACK_TIMEOUT);
174 if (err < 0)
175 stop_stream(oxfw, stream);
176end:
177 return err;
178}
179
180static int check_connection_used_by_others(struct snd_oxfw *oxfw,
181 struct amdtp_stream *stream)
182{
183 struct cmp_connection *conn;
184 bool used;
185 int err;
186
187 if (stream == &oxfw->tx_stream)
188 conn = &oxfw->out_conn;
189 else
190 conn = &oxfw->in_conn;
191
192 err = cmp_connection_check_used(conn, &used);
193 if ((err >= 0) && used && !amdtp_stream_running(stream)) {
194 dev_err(&oxfw->unit->device,
195 "Connection established by others: %cPCR[%d]\n",
196 (conn->direction == CMP_OUTPUT) ? 'o' : 'i',
197 conn->pcr_index);
198 err = -EBUSY;
199 }
200
201 return err;
202}
203
204int snd_oxfw_stream_init_simplex(struct snd_oxfw *oxfw,
205 struct amdtp_stream *stream)
206{
207 struct cmp_connection *conn;
208 enum cmp_direction c_dir;
209 enum amdtp_stream_direction s_dir;
210 int err;
211
212 if (stream == &oxfw->tx_stream) {
213 conn = &oxfw->out_conn;
214 c_dir = CMP_OUTPUT;
215 s_dir = AMDTP_IN_STREAM;
216 } else {
217 conn = &oxfw->in_conn;
218 c_dir = CMP_INPUT;
219 s_dir = AMDTP_OUT_STREAM;
220 }
221
222 err = cmp_connection_init(conn, oxfw->unit, c_dir, 0);
223 if (err < 0)
224 goto end;
225
226 err = amdtp_stream_init(stream, oxfw->unit, s_dir, CIP_NONBLOCKING);
227 if (err < 0) {
228 amdtp_stream_destroy(stream);
229 cmp_connection_destroy(conn);
230 goto end;
231 }
232
233 /* OXFW starts to transmit packets with non-zero dbc. */
234 if (stream == &oxfw->tx_stream)
235 oxfw->tx_stream.flags |= CIP_SKIP_INIT_DBC_CHECK;
236end:
237 return err;
238}
239
240int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw,
241 struct amdtp_stream *stream,
242 unsigned int rate, unsigned int pcm_channels)
243{
244 struct amdtp_stream *opposite;
245 struct snd_oxfw_stream_formation formation;
246 enum avc_general_plug_dir dir;
247 unsigned int substreams, opposite_substreams;
248 int err = 0;
249
250 if (stream == &oxfw->tx_stream) {
251 substreams = oxfw->capture_substreams;
252 opposite = &oxfw->rx_stream;
253 opposite_substreams = oxfw->playback_substreams;
254 dir = AVC_GENERAL_PLUG_DIR_OUT;
255 } else {
256 substreams = oxfw->playback_substreams;
257 opposite_substreams = oxfw->capture_substreams;
258
259 if (oxfw->has_output)
260 opposite = &oxfw->rx_stream;
261 else
262 opposite = NULL;
263
264 dir = AVC_GENERAL_PLUG_DIR_IN;
265 }
266
267 if (substreams == 0)
268 goto end;
269
270 /*
271 * Considering JACK/FFADO streaming:
272 * TODO: This can be removed hwdep functionality becomes popular.
273 */
274 err = check_connection_used_by_others(oxfw, stream);
275 if (err < 0)
276 goto end;
277
278 /* packet queueing error */
279 if (amdtp_streaming_error(stream))
280 stop_stream(oxfw, stream);
281
282 err = snd_oxfw_stream_get_current_formation(oxfw, dir, &formation);
283 if (err < 0)
284 goto end;
285 if (rate == 0)
286 rate = formation.rate;
287 if (pcm_channels == 0)
288 pcm_channels = formation.pcm;
289
290 if ((formation.rate != rate) || (formation.pcm != pcm_channels)) {
291 if (opposite != NULL) {
292 err = check_connection_used_by_others(oxfw, opposite);
293 if (err < 0)
294 goto end;
295 stop_stream(oxfw, opposite);
296 }
297 stop_stream(oxfw, stream);
298
299 err = set_stream_format(oxfw, stream, rate, pcm_channels);
300 if (err < 0) {
301 dev_err(&oxfw->unit->device,
302 "fail to set stream format: %d\n", err);
303 goto end;
304 }
305
306 /* Start opposite stream if needed. */
307 if (opposite && !amdtp_stream_running(opposite) &&
308 (opposite_substreams > 0)) {
309 err = start_stream(oxfw, opposite, rate, 0);
310 if (err < 0) {
311 dev_err(&oxfw->unit->device,
312 "fail to restart stream: %d\n", err);
313 goto end;
314 }
315 }
316 }
317
318 /* Start requested stream. */
319 if (!amdtp_stream_running(stream)) {
320 err = start_stream(oxfw, stream, rate, pcm_channels);
321 if (err < 0)
322 dev_err(&oxfw->unit->device,
323 "fail to start stream: %d\n", err);
324 }
325end:
326 return err;
327}
328
329void snd_oxfw_stream_stop_simplex(struct snd_oxfw *oxfw,
330 struct amdtp_stream *stream)
331{
332 if (((stream == &oxfw->tx_stream) && (oxfw->capture_substreams > 0)) ||
333 ((stream == &oxfw->rx_stream) && (oxfw->playback_substreams > 0)))
334 return;
335
336 stop_stream(oxfw, stream);
337}
338
339void snd_oxfw_stream_destroy_simplex(struct snd_oxfw *oxfw,
340 struct amdtp_stream *stream)
341{
342 struct cmp_connection *conn;
343
344 if (stream == &oxfw->tx_stream)
345 conn = &oxfw->out_conn;
346 else
347 conn = &oxfw->in_conn;
348
349 stop_stream(oxfw, stream);
350
351 amdtp_stream_destroy(stream);
352 cmp_connection_destroy(conn);
353}
354
355void snd_oxfw_stream_update_simplex(struct snd_oxfw *oxfw,
356 struct amdtp_stream *stream)
357{
358 struct cmp_connection *conn;
359
360 if (stream == &oxfw->tx_stream)
361 conn = &oxfw->out_conn;
362 else
363 conn = &oxfw->in_conn;
364
365 if (cmp_connection_update(conn) < 0)
366 stop_stream(oxfw, stream);
367 else
368 amdtp_stream_update(stream);
369}
370
371int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
372 enum avc_general_plug_dir dir,
373 struct snd_oxfw_stream_formation *formation)
374{
375 u8 *format;
376 unsigned int len;
377 int err;
378
379 len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
380 format = kmalloc(len, GFP_KERNEL);
381 if (format == NULL)
382 return -ENOMEM;
383
384 err = avc_stream_get_format_single(oxfw->unit, dir, 0, format, &len);
385 if (err < 0)
386 goto end;
387 if (len < 3) {
388 err = -EIO;
389 goto end;
390 }
391
392 err = snd_oxfw_stream_parse_format(format, formation);
393end:
394 kfree(format);
395 return err;
396}
397
398/*
399 * See Table 6.16 - AM824 Stream Format
400 * Figure 6.19 - format_information field for AM824 Compound
401 * in AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA)
402 * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005
403 */
404int snd_oxfw_stream_parse_format(u8 *format,
405 struct snd_oxfw_stream_formation *formation)
406{
407 unsigned int i, e, channels, type;
408
409 memset(formation, 0, sizeof(struct snd_oxfw_stream_formation));
410
411 /*
412 * this module can support a hierarchy combination that:
413 * Root: Audio and Music (0x90)
414 * Level 1: AM824 Compound (0x40)
415 */
416 if ((format[0] != 0x90) || (format[1] != 0x40))
417 return -ENOSYS;
418
419 /* check the sampling rate */
420 for (i = 0; i < ARRAY_SIZE(avc_stream_rate_table); i++) {
421 if (format[2] == avc_stream_rate_table[i])
422 break;
423 }
424 if (i == ARRAY_SIZE(avc_stream_rate_table))
425 return -ENOSYS;
426
427 formation->rate = oxfw_rate_table[i];
428
429 for (e = 0; e < format[4]; e++) {
430 channels = format[5 + e * 2];
431 type = format[6 + e * 2];
432
433 switch (type) {
434 /* IEC 60958 Conformant, currently handled as MBLA */
435 case 0x00:
436 /* Multi Bit Linear Audio (Raw) */
437 case 0x06:
438 formation->pcm += channels;
439 break;
440 /* MIDI Conformant */
441 case 0x0d:
442 formation->midi = channels;
443 break;
444 /* IEC 61937-3 to 7 */
445 case 0x01:
446 case 0x02:
447 case 0x03:
448 case 0x04:
449 case 0x05:
450 /* Multi Bit Linear Audio */
451 case 0x07: /* DVD-Audio */
452 case 0x0c: /* High Precision */
453 /* One Bit Audio */
454 case 0x08: /* (Plain) Raw */
455 case 0x09: /* (Plain) SACD */
456 case 0x0a: /* (Encoded) Raw */
457 case 0x0b: /* (Encoded) SACD */
458 /* SMPTE Time-Code conformant */
459 case 0x0e:
460 /* Sample Count */
461 case 0x0f:
462 /* Anciliary Data */
463 case 0x10:
464 /* Synchronization Stream (Stereo Raw audio) */
465 case 0x40:
466 /* Don't care */
467 case 0xff:
468 default:
469 return -ENOSYS; /* not supported */
470 }
471 }
472
473 if (formation->pcm > AMDTP_MAX_CHANNELS_FOR_PCM ||
474 formation->midi > AMDTP_MAX_CHANNELS_FOR_MIDI)
475 return -ENOSYS;
476
477 return 0;
478}
479
480static int
481assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
482 unsigned int pid, u8 *buf, unsigned int *len,
483 u8 **formats)
484{
485 struct snd_oxfw_stream_formation formation;
486 unsigned int i, eid;
487 int err;
488
489 /* get format at current sampling rate */
490 err = avc_stream_get_format_single(oxfw->unit, dir, pid, buf, len);
491 if (err < 0) {
492 dev_err(&oxfw->unit->device,
493 "fail to get current stream format for isoc %s plug %d:%d\n",
494 (dir == AVC_GENERAL_PLUG_DIR_IN) ? "in" : "out",
495 pid, err);
496 goto end;
497 }
498
499 /* parse and set stream format */
500 eid = 0;
501 err = snd_oxfw_stream_parse_format(buf, &formation);
502 if (err < 0)
503 goto end;
504
505 formats[eid] = kmalloc(*len, GFP_KERNEL);
506 if (formats[eid] == NULL) {
507 err = -ENOMEM;
508 goto end;
509 }
510 memcpy(formats[eid], buf, *len);
511
512 /* apply the format for each available sampling rate */
513 for (i = 0; i < ARRAY_SIZE(oxfw_rate_table); i++) {
514 if (formation.rate == oxfw_rate_table[i])
515 continue;
516
517 err = avc_general_inquiry_sig_fmt(oxfw->unit,
518 oxfw_rate_table[i],
519 dir, pid);
520 if (err < 0)
521 continue;
522
523 eid++;
524 formats[eid] = kmalloc(*len, GFP_KERNEL);
525 if (formats[eid] == NULL) {
526 err = -ENOMEM;
527 goto end;
528 }
529 memcpy(formats[eid], buf, *len);
530 formats[eid][2] = avc_stream_rate_table[i];
531 }
532
533 err = 0;
534 oxfw->assumed = true;
535end:
536 return err;
537}
538
539static int fill_stream_formats(struct snd_oxfw *oxfw,
540 enum avc_general_plug_dir dir,
541 unsigned short pid)
542{
543 u8 *buf, **formats;
544 unsigned int len, eid = 0;
545 struct snd_oxfw_stream_formation dummy;
546 int err;
547
548 buf = kmalloc(AVC_GENERIC_FRAME_MAXIMUM_BYTES, GFP_KERNEL);
549 if (buf == NULL)
550 return -ENOMEM;
551
552 if (dir == AVC_GENERAL_PLUG_DIR_OUT)
553 formats = oxfw->tx_stream_formats;
554 else
555 formats = oxfw->rx_stream_formats;
556
557 /* get first entry */
558 len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
559 err = avc_stream_get_format_list(oxfw->unit, dir, 0, buf, &len, 0);
560 if (err == -ENOSYS) {
561 /* LIST subfunction is not implemented */
562 len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
563 err = assume_stream_formats(oxfw, dir, pid, buf, &len,
564 formats);
565 goto end;
566 } else if (err < 0) {
567 dev_err(&oxfw->unit->device,
568 "fail to get stream format %d for isoc %s plug %d:%d\n",
569 eid, (dir == AVC_GENERAL_PLUG_DIR_IN) ? "in" : "out",
570 pid, err);
571 goto end;
572 }
573
574 /* LIST subfunction is implemented */
575 while (eid < SND_OXFW_STREAM_FORMAT_ENTRIES) {
576 /* The format is too short. */
577 if (len < 3) {
578 err = -EIO;
579 break;
580 }
581
582 /* parse and set stream format */
583 err = snd_oxfw_stream_parse_format(buf, &dummy);
584 if (err < 0)
585 break;
586
587 formats[eid] = kmalloc(len, GFP_KERNEL);
588 if (formats[eid] == NULL) {
589 err = -ENOMEM;
590 break;
591 }
592 memcpy(formats[eid], buf, len);
593
594 /* get next entry */
595 len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
596 err = avc_stream_get_format_list(oxfw->unit, dir, 0,
597 buf, &len, ++eid);
598 /* No entries remained. */
599 if (err == -EINVAL) {
600 err = 0;
601 break;
602 } else if (err < 0) {
603 dev_err(&oxfw->unit->device,
604 "fail to get stream format %d for isoc %s plug %d:%d\n",
605 eid, (dir == AVC_GENERAL_PLUG_DIR_IN) ? "in" :
606 "out",
607 pid, err);
608 break;
609 }
610 }
611end:
612 kfree(buf);
613 return err;
614}
615
616int snd_oxfw_stream_discover(struct snd_oxfw *oxfw)
617{
618 u8 plugs[AVC_PLUG_INFO_BUF_BYTES];
619 int err;
620
621 /* the number of plugs for isoc in/out, ext in/out */
622 err = avc_general_get_plug_info(oxfw->unit, 0x1f, 0x07, 0x00, plugs);
623 if (err < 0) {
624 dev_err(&oxfw->unit->device,
625 "fail to get info for isoc/external in/out plugs: %d\n",
626 err);
627 goto end;
628 } else if ((plugs[0] == 0) && (plugs[1] == 0)) {
629 err = -ENOSYS;
630 goto end;
631 }
632
633 /* use oPCR[0] if exists */
634 if (plugs[1] > 0) {
635 err = fill_stream_formats(oxfw, AVC_GENERAL_PLUG_DIR_OUT, 0);
636 if (err < 0)
637 goto end;
638 oxfw->has_output = true;
639 }
640
641 /* use iPCR[0] if exists */
642 if (plugs[0] > 0)
643 err = fill_stream_formats(oxfw, AVC_GENERAL_PLUG_DIR_IN, 0);
644end:
645 return err;
646}
647
648void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw)
649{
650 oxfw->dev_lock_changed = true;
651 wake_up(&oxfw->hwdep_wait);
652}
653
654int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw)
655{
656 int err;
657
658 spin_lock_irq(&oxfw->lock);
659
660 /* user land lock this */
661 if (oxfw->dev_lock_count < 0) {
662 err = -EBUSY;
663 goto end;
664 }
665
666 /* this is the first time */
667 if (oxfw->dev_lock_count++ == 0)
668 snd_oxfw_stream_lock_changed(oxfw);
669 err = 0;
670end:
671 spin_unlock_irq(&oxfw->lock);
672 return err;
673}
674
675void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw)
676{
677 spin_lock_irq(&oxfw->lock);
678
679 if (WARN_ON(oxfw->dev_lock_count <= 0))
680 goto end;
681 if (--oxfw->dev_lock_count == 0)
682 snd_oxfw_stream_lock_changed(oxfw);
683end:
684 spin_unlock_irq(&oxfw->lock);
685}
diff --git a/sound/firewire/oxfw/oxfw.c b/sound/firewire/oxfw/oxfw.c
new file mode 100644
index 000000000000..cf1d0b55e827
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw.c
@@ -0,0 +1,317 @@
1/*
2 * oxfw.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include "oxfw.h"
9
10#define OXFORD_FIRMWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x50000)
11/* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */
12
13#define OXFORD_HARDWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x90020)
14#define OXFORD_HARDWARE_ID_OXFW970 0x39443841
15#define OXFORD_HARDWARE_ID_OXFW971 0x39373100
16
17#define VENDOR_LOUD 0x000ff2
18#define VENDOR_GRIFFIN 0x001292
19#define VENDOR_BEHRINGER 0x001564
20#define VENDOR_LACIE 0x00d04b
21
22#define SPECIFIER_1394TA 0x00a02d
23#define VERSION_AVC 0x010001
24
25MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
26MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
27MODULE_LICENSE("GPL v2");
28MODULE_ALIAS("snd-firewire-speakers");
29
30static bool detect_loud_models(struct fw_unit *unit)
31{
32 const char *const models[] = {
33 "Onyxi",
34 "Onyx-i",
35 "d.Pro",
36 "Mackie Onyx Satellite",
37 "Tapco LINK.firewire 4x6",
38 "U.420"};
39 char model[32];
40 unsigned int i;
41 int err;
42
43 err = fw_csr_string(unit->directory, CSR_MODEL,
44 model, sizeof(model));
45 if (err < 0)
46 return err;
47
48 for (i = 0; i < ARRAY_SIZE(models); i++) {
49 if (strcmp(models[i], model) == 0)
50 break;
51 }
52
53 return (i < ARRAY_SIZE(models));
54}
55
56static int name_card(struct snd_oxfw *oxfw)
57{
58 struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
59 char vendor[24];
60 char model[32];
61 const char *d, *v, *m;
62 u32 firmware;
63 int err;
64
65 /* get vendor name from root directory */
66 err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR,
67 vendor, sizeof(vendor));
68 if (err < 0)
69 goto end;
70
71 /* get model name from unit directory */
72 err = fw_csr_string(oxfw->unit->directory, CSR_MODEL,
73 model, sizeof(model));
74 if (err < 0)
75 goto end;
76
77 err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST,
78 OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0);
79 if (err < 0)
80 goto end;
81 be32_to_cpus(&firmware);
82
83 /* to apply card definitions */
84 if (oxfw->device_info) {
85 d = oxfw->device_info->driver_name;
86 v = oxfw->device_info->vendor_name;
87 m = oxfw->device_info->model_name;
88 } else {
89 d = "OXFW";
90 v = vendor;
91 m = model;
92 }
93
94 strcpy(oxfw->card->driver, d);
95 strcpy(oxfw->card->mixername, m);
96 strcpy(oxfw->card->shortname, m);
97
98 snprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
99 "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
100 v, m, firmware >> 20, firmware & 0xffff,
101 fw_dev->config_rom[3], fw_dev->config_rom[4],
102 dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
103end:
104 return err;
105}
106
107static void oxfw_card_free(struct snd_card *card)
108{
109 struct snd_oxfw *oxfw = card->private_data;
110 unsigned int i;
111
112 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
113 kfree(oxfw->tx_stream_formats[i]);
114 kfree(oxfw->rx_stream_formats[i]);
115 }
116
117 mutex_destroy(&oxfw->mutex);
118}
119
120static int oxfw_probe(struct fw_unit *unit,
121 const struct ieee1394_device_id *id)
122{
123 struct snd_card *card;
124 struct snd_oxfw *oxfw;
125 int err;
126
127 if ((id->vendor_id == VENDOR_LOUD) && !detect_loud_models(unit))
128 return -ENODEV;
129
130 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
131 sizeof(*oxfw), &card);
132 if (err < 0)
133 return err;
134
135 card->private_free = oxfw_card_free;
136 oxfw = card->private_data;
137 oxfw->card = card;
138 mutex_init(&oxfw->mutex);
139 oxfw->unit = unit;
140 oxfw->device_info = (const struct device_info *)id->driver_data;
141 spin_lock_init(&oxfw->lock);
142 init_waitqueue_head(&oxfw->hwdep_wait);
143
144 err = snd_oxfw_stream_discover(oxfw);
145 if (err < 0)
146 goto error;
147
148 err = name_card(oxfw);
149 if (err < 0)
150 goto error;
151
152 err = snd_oxfw_create_pcm(oxfw);
153 if (err < 0)
154 goto error;
155
156 if (oxfw->device_info) {
157 err = snd_oxfw_create_mixer(oxfw);
158 if (err < 0)
159 goto error;
160 }
161
162 snd_oxfw_proc_init(oxfw);
163
164 err = snd_oxfw_create_midi(oxfw);
165 if (err < 0)
166 goto error;
167
168 err = snd_oxfw_create_hwdep(oxfw);
169 if (err < 0)
170 goto error;
171
172 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream);
173 if (err < 0)
174 goto error;
175 if (oxfw->has_output) {
176 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream);
177 if (err < 0)
178 goto error;
179 }
180
181 err = snd_card_register(card);
182 if (err < 0) {
183 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
184 if (oxfw->has_output)
185 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
186 goto error;
187 }
188 dev_set_drvdata(&unit->device, oxfw);
189
190 return 0;
191error:
192 snd_card_free(card);
193 return err;
194}
195
196static void oxfw_bus_reset(struct fw_unit *unit)
197{
198 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
199
200 fcp_bus_reset(oxfw->unit);
201
202 mutex_lock(&oxfw->mutex);
203
204 snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream);
205 if (oxfw->has_output)
206 snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream);
207
208 mutex_unlock(&oxfw->mutex);
209}
210
211static void oxfw_remove(struct fw_unit *unit)
212{
213 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
214
215 snd_card_disconnect(oxfw->card);
216
217 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
218 if (oxfw->has_output)
219 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
220
221 snd_card_free_when_closed(oxfw->card);
222}
223
224static const struct device_info griffin_firewave = {
225 .driver_name = "FireWave",
226 .vendor_name = "Griffin",
227 .model_name = "FireWave",
228 .mixer_channels = 6,
229 .mute_fb_id = 0x01,
230 .volume_fb_id = 0x02,
231};
232
233static const struct device_info lacie_speakers = {
234 .driver_name = "FWSpeakers",
235 .vendor_name = "LaCie",
236 .model_name = "FireWire Speakers",
237 .mixer_channels = 1,
238 .mute_fb_id = 0x01,
239 .volume_fb_id = 0x01,
240};
241
242static const struct ieee1394_device_id oxfw_id_table[] = {
243 {
244 .match_flags = IEEE1394_MATCH_VENDOR_ID |
245 IEEE1394_MATCH_MODEL_ID |
246 IEEE1394_MATCH_SPECIFIER_ID |
247 IEEE1394_MATCH_VERSION,
248 .vendor_id = VENDOR_GRIFFIN,
249 .model_id = 0x00f970,
250 .specifier_id = SPECIFIER_1394TA,
251 .version = VERSION_AVC,
252 .driver_data = (kernel_ulong_t)&griffin_firewave,
253 },
254 {
255 .match_flags = IEEE1394_MATCH_VENDOR_ID |
256 IEEE1394_MATCH_MODEL_ID |
257 IEEE1394_MATCH_SPECIFIER_ID |
258 IEEE1394_MATCH_VERSION,
259 .vendor_id = VENDOR_LACIE,
260 .model_id = 0x00f970,
261 .specifier_id = SPECIFIER_1394TA,
262 .version = VERSION_AVC,
263 .driver_data = (kernel_ulong_t)&lacie_speakers,
264 },
265 /* Behringer,F-Control Audio 202 */
266 {
267 .match_flags = IEEE1394_MATCH_VENDOR_ID |
268 IEEE1394_MATCH_MODEL_ID,
269 .vendor_id = VENDOR_BEHRINGER,
270 .model_id = 0x00fc22,
271 },
272 /*
273 * Any Mackie(Loud) models (name string/model id):
274 * Onyx-i series (former models): 0x081216
275 * Mackie Onyx Satellite: 0x00200f
276 * Tapco LINK.firewire 4x6: 0x000460
277 * d.2 pro: Unknown
278 * d.4 pro: Unknown
279 * U.420: Unknown
280 * U.420d: Unknown
281 */
282 {
283 .match_flags = IEEE1394_MATCH_VENDOR_ID |
284 IEEE1394_MATCH_SPECIFIER_ID |
285 IEEE1394_MATCH_VERSION,
286 .vendor_id = VENDOR_LOUD,
287 .specifier_id = SPECIFIER_1394TA,
288 .version = VERSION_AVC,
289 },
290 { }
291};
292MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
293
294static struct fw_driver oxfw_driver = {
295 .driver = {
296 .owner = THIS_MODULE,
297 .name = KBUILD_MODNAME,
298 .bus = &fw_bus_type,
299 },
300 .probe = oxfw_probe,
301 .update = oxfw_bus_reset,
302 .remove = oxfw_remove,
303 .id_table = oxfw_id_table,
304};
305
306static int __init snd_oxfw_init(void)
307{
308 return driver_register(&oxfw_driver.driver);
309}
310
311static void __exit snd_oxfw_exit(void)
312{
313 driver_unregister(&oxfw_driver.driver);
314}
315
316module_init(snd_oxfw_init);
317module_exit(snd_oxfw_exit);
diff --git a/sound/firewire/oxfw/oxfw.h b/sound/firewire/oxfw/oxfw.h
new file mode 100644
index 000000000000..cace5ad4fe76
--- /dev/null
+++ b/sound/firewire/oxfw/oxfw.h
@@ -0,0 +1,146 @@
1/*
2 * oxfw.h - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include <linux/device.h>
9#include <linux/firewire.h>
10#include <linux/firewire-constants.h>
11#include <linux/module.h>
12#include <linux/mod_devicetable.h>
13#include <linux/mutex.h>
14#include <linux/slab.h>
15#include <linux/compat.h>
16
17#include <sound/control.h>
18#include <sound/core.h>
19#include <sound/initval.h>
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22#include <sound/info.h>
23#include <sound/rawmidi.h>
24#include <sound/firewire.h>
25#include <sound/hwdep.h>
26
27#include "../lib.h"
28#include "../fcp.h"
29#include "../packets-buffer.h"
30#include "../iso-resources.h"
31#include "../amdtp.h"
32#include "../cmp.h"
33
34struct device_info {
35 const char *driver_name;
36 const char *vendor_name;
37 const char *model_name;
38 unsigned int mixer_channels;
39 u8 mute_fb_id;
40 u8 volume_fb_id;
41};
42
43/* This is an arbitrary number for convinience. */
44#define SND_OXFW_STREAM_FORMAT_ENTRIES 10
45struct snd_oxfw {
46 struct snd_card *card;
47 struct fw_unit *unit;
48 const struct device_info *device_info;
49 struct mutex mutex;
50 spinlock_t lock;
51
52 bool has_output;
53 u8 *tx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES];
54 u8 *rx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES];
55 bool assumed;
56 struct cmp_connection out_conn;
57 struct cmp_connection in_conn;
58 struct amdtp_stream tx_stream;
59 struct amdtp_stream rx_stream;
60 unsigned int capture_substreams;
61 unsigned int playback_substreams;
62
63 unsigned int midi_input_ports;
64 unsigned int midi_output_ports;
65
66 bool mute;
67 s16 volume[6];
68 s16 volume_min;
69 s16 volume_max;
70
71 int dev_lock_count;
72 bool dev_lock_changed;
73 wait_queue_head_t hwdep_wait;
74};
75
76/*
77 * AV/C Stream Format Information Specification 1.1 Working Draft
78 * (Apr 2005, 1394TA)
79 */
80int avc_stream_set_format(struct fw_unit *unit, enum avc_general_plug_dir dir,
81 unsigned int pid, u8 *format, unsigned int len);
82int avc_stream_get_format(struct fw_unit *unit,
83 enum avc_general_plug_dir dir, unsigned int pid,
84 u8 *buf, unsigned int *len, unsigned int eid);
85static inline int
86avc_stream_get_format_single(struct fw_unit *unit,
87 enum avc_general_plug_dir dir, unsigned int pid,
88 u8 *buf, unsigned int *len)
89{
90 return avc_stream_get_format(unit, dir, pid, buf, len, 0xff);
91}
92static inline int
93avc_stream_get_format_list(struct fw_unit *unit,
94 enum avc_general_plug_dir dir, unsigned int pid,
95 u8 *buf, unsigned int *len,
96 unsigned int eid)
97{
98 return avc_stream_get_format(unit, dir, pid, buf, len, eid);
99}
100
101/*
102 * AV/C Digital Interface Command Set General Specification 4.2
103 * (Sep 2004, 1394TA)
104 */
105int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate,
106 enum avc_general_plug_dir dir,
107 unsigned short pid);
108
109int snd_oxfw_stream_init_simplex(struct snd_oxfw *oxfw,
110 struct amdtp_stream *stream);
111int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw,
112 struct amdtp_stream *stream,
113 unsigned int rate, unsigned int pcm_channels);
114void snd_oxfw_stream_stop_simplex(struct snd_oxfw *oxfw,
115 struct amdtp_stream *stream);
116void snd_oxfw_stream_destroy_simplex(struct snd_oxfw *oxfw,
117 struct amdtp_stream *stream);
118void snd_oxfw_stream_update_simplex(struct snd_oxfw *oxfw,
119 struct amdtp_stream *stream);
120
121struct snd_oxfw_stream_formation {
122 unsigned int rate;
123 unsigned int pcm;
124 unsigned int midi;
125};
126int snd_oxfw_stream_parse_format(u8 *format,
127 struct snd_oxfw_stream_formation *formation);
128int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
129 enum avc_general_plug_dir dir,
130 struct snd_oxfw_stream_formation *formation);
131
132int snd_oxfw_stream_discover(struct snd_oxfw *oxfw);
133
134void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw);
135int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw);
136void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw);
137
138int snd_oxfw_create_pcm(struct snd_oxfw *oxfw);
139
140int snd_oxfw_create_mixer(struct snd_oxfw *oxfw);
141
142void snd_oxfw_proc_init(struct snd_oxfw *oxfw);
143
144int snd_oxfw_create_midi(struct snd_oxfw *oxfw);
145
146int snd_oxfw_create_hwdep(struct snd_oxfw *oxfw);
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c
deleted file mode 100644
index 768d40ddfebb..000000000000
--- a/sound/firewire/speakers.c
+++ /dev/null
@@ -1,792 +0,0 @@
1/*
2 * OXFW970-based speakers driver
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include <linux/device.h>
9#include <linux/firewire.h>
10#include <linux/firewire-constants.h>
11#include <linux/module.h>
12#include <linux/mod_devicetable.h>
13#include <linux/mutex.h>
14#include <linux/slab.h>
15#include <sound/control.h>
16#include <sound/core.h>
17#include <sound/initval.h>
18#include <sound/pcm.h>
19#include <sound/pcm_params.h>
20#include "cmp.h"
21#include "fcp.h"
22#include "amdtp.h"
23#include "lib.h"
24
25#define OXFORD_FIRMWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x50000)
26/* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */
27
28#define OXFORD_HARDWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x90020)
29#define OXFORD_HARDWARE_ID_OXFW970 0x39443841
30#define OXFORD_HARDWARE_ID_OXFW971 0x39373100
31
32#define VENDOR_GRIFFIN 0x001292
33#define VENDOR_LACIE 0x00d04b
34
35#define SPECIFIER_1394TA 0x00a02d
36#define VERSION_AVC 0x010001
37
38struct device_info {
39 const char *driver_name;
40 const char *short_name;
41 const char *long_name;
42 int (*pcm_constraints)(struct snd_pcm_runtime *runtime);
43 unsigned int mixer_channels;
44 u8 mute_fb_id;
45 u8 volume_fb_id;
46};
47
48struct fwspk {
49 struct snd_card *card;
50 struct fw_unit *unit;
51 const struct device_info *device_info;
52 struct mutex mutex;
53 struct cmp_connection connection;
54 struct amdtp_stream stream;
55 bool mute;
56 s16 volume[6];
57 s16 volume_min;
58 s16 volume_max;
59};
60
61MODULE_DESCRIPTION("FireWire speakers driver");
62MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
63MODULE_LICENSE("GPL v2");
64
65static int firewave_rate_constraint(struct snd_pcm_hw_params *params,
66 struct snd_pcm_hw_rule *rule)
67{
68 static unsigned int stereo_rates[] = { 48000, 96000 };
69 struct snd_interval *channels =
70 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
71 struct snd_interval *rate =
72 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
73
74 /* two channels work only at 48/96 kHz */
75 if (snd_interval_max(channels) < 6)
76 return snd_interval_list(rate, 2, stereo_rates, 0);
77 return 0;
78}
79
80static int firewave_channels_constraint(struct snd_pcm_hw_params *params,
81 struct snd_pcm_hw_rule *rule)
82{
83 static const struct snd_interval all_channels = { .min = 6, .max = 6 };
84 struct snd_interval *rate =
85 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
86 struct snd_interval *channels =
87 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
88
89 /* 32/44.1 kHz work only with all six channels */
90 if (snd_interval_max(rate) < 48000)
91 return snd_interval_refine(channels, &all_channels);
92 return 0;
93}
94
95static int firewave_constraints(struct snd_pcm_runtime *runtime)
96{
97 static unsigned int channels_list[] = { 2, 6 };
98 static struct snd_pcm_hw_constraint_list channels_list_constraint = {
99 .count = 2,
100 .list = channels_list,
101 };
102 int err;
103
104 runtime->hw.rates = SNDRV_PCM_RATE_32000 |
105 SNDRV_PCM_RATE_44100 |
106 SNDRV_PCM_RATE_48000 |
107 SNDRV_PCM_RATE_96000;
108 runtime->hw.channels_max = 6;
109
110 err = snd_pcm_hw_constraint_list(runtime, 0,
111 SNDRV_PCM_HW_PARAM_CHANNELS,
112 &channels_list_constraint);
113 if (err < 0)
114 return err;
115 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
116 firewave_rate_constraint, NULL,
117 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
118 if (err < 0)
119 return err;
120 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
121 firewave_channels_constraint, NULL,
122 SNDRV_PCM_HW_PARAM_RATE, -1);
123 if (err < 0)
124 return err;
125
126 return 0;
127}
128
129static int lacie_speakers_constraints(struct snd_pcm_runtime *runtime)
130{
131 runtime->hw.rates = SNDRV_PCM_RATE_32000 |
132 SNDRV_PCM_RATE_44100 |
133 SNDRV_PCM_RATE_48000 |
134 SNDRV_PCM_RATE_88200 |
135 SNDRV_PCM_RATE_96000;
136
137 return 0;
138}
139
140static int fwspk_open(struct snd_pcm_substream *substream)
141{
142 static const struct snd_pcm_hardware hardware = {
143 .info = SNDRV_PCM_INFO_MMAP |
144 SNDRV_PCM_INFO_MMAP_VALID |
145 SNDRV_PCM_INFO_BATCH |
146 SNDRV_PCM_INFO_INTERLEAVED |
147 SNDRV_PCM_INFO_BLOCK_TRANSFER,
148 .formats = AMDTP_OUT_PCM_FORMAT_BITS,
149 .channels_min = 2,
150 .channels_max = 2,
151 .buffer_bytes_max = 4 * 1024 * 1024,
152 .period_bytes_min = 1,
153 .period_bytes_max = UINT_MAX,
154 .periods_min = 1,
155 .periods_max = UINT_MAX,
156 };
157 struct fwspk *fwspk = substream->private_data;
158 struct snd_pcm_runtime *runtime = substream->runtime;
159 int err;
160
161 runtime->hw = hardware;
162
163 err = fwspk->device_info->pcm_constraints(runtime);
164 if (err < 0)
165 return err;
166 err = snd_pcm_limit_hw_rates(runtime);
167 if (err < 0)
168 return err;
169
170 err = amdtp_stream_add_pcm_hw_constraints(&fwspk->stream, runtime);
171 if (err < 0)
172 return err;
173
174 return 0;
175}
176
177static int fwspk_close(struct snd_pcm_substream *substream)
178{
179 return 0;
180}
181
182static void fwspk_stop_stream(struct fwspk *fwspk)
183{
184 if (amdtp_stream_running(&fwspk->stream)) {
185 amdtp_stream_stop(&fwspk->stream);
186 cmp_connection_break(&fwspk->connection);
187 }
188}
189
190static int fwspk_hw_params(struct snd_pcm_substream *substream,
191 struct snd_pcm_hw_params *hw_params)
192{
193 struct fwspk *fwspk = substream->private_data;
194 int err;
195
196 mutex_lock(&fwspk->mutex);
197 fwspk_stop_stream(fwspk);
198 mutex_unlock(&fwspk->mutex);
199
200 err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
201 params_buffer_bytes(hw_params));
202 if (err < 0)
203 goto error;
204
205 amdtp_stream_set_parameters(&fwspk->stream,
206 params_rate(hw_params),
207 params_channels(hw_params),
208 0);
209
210 amdtp_stream_set_pcm_format(&fwspk->stream,
211 params_format(hw_params));
212
213 err = avc_general_set_sig_fmt(fwspk->unit, params_rate(hw_params),
214 AVC_GENERAL_PLUG_DIR_IN, 0);
215 if (err < 0) {
216 dev_err(&fwspk->unit->device, "failed to set sample rate\n");
217 goto err_buffer;
218 }
219
220 return 0;
221
222err_buffer:
223 snd_pcm_lib_free_vmalloc_buffer(substream);
224error:
225 return err;
226}
227
228static int fwspk_hw_free(struct snd_pcm_substream *substream)
229{
230 struct fwspk *fwspk = substream->private_data;
231
232 mutex_lock(&fwspk->mutex);
233 fwspk_stop_stream(fwspk);
234 mutex_unlock(&fwspk->mutex);
235
236 return snd_pcm_lib_free_vmalloc_buffer(substream);
237}
238
239static int fwspk_prepare(struct snd_pcm_substream *substream)
240{
241 struct fwspk *fwspk = substream->private_data;
242 int err;
243
244 mutex_lock(&fwspk->mutex);
245
246 if (amdtp_streaming_error(&fwspk->stream))
247 fwspk_stop_stream(fwspk);
248
249 if (!amdtp_stream_running(&fwspk->stream)) {
250 err = cmp_connection_establish(&fwspk->connection,
251 amdtp_stream_get_max_payload(&fwspk->stream));
252 if (err < 0)
253 goto err_mutex;
254
255 err = amdtp_stream_start(&fwspk->stream,
256 fwspk->connection.resources.channel,
257 fwspk->connection.speed);
258 if (err < 0)
259 goto err_connection;
260 }
261
262 mutex_unlock(&fwspk->mutex);
263
264 amdtp_stream_pcm_prepare(&fwspk->stream);
265
266 return 0;
267
268err_connection:
269 cmp_connection_break(&fwspk->connection);
270err_mutex:
271 mutex_unlock(&fwspk->mutex);
272
273 return err;
274}
275
276static int fwspk_trigger(struct snd_pcm_substream *substream, int cmd)
277{
278 struct fwspk *fwspk = substream->private_data;
279 struct snd_pcm_substream *pcm;
280
281 switch (cmd) {
282 case SNDRV_PCM_TRIGGER_START:
283 pcm = substream;
284 break;
285 case SNDRV_PCM_TRIGGER_STOP:
286 pcm = NULL;
287 break;
288 default:
289 return -EINVAL;
290 }
291 amdtp_stream_pcm_trigger(&fwspk->stream, pcm);
292 return 0;
293}
294
295static snd_pcm_uframes_t fwspk_pointer(struct snd_pcm_substream *substream)
296{
297 struct fwspk *fwspk = substream->private_data;
298
299 return amdtp_stream_pcm_pointer(&fwspk->stream);
300}
301
302static int fwspk_create_pcm(struct fwspk *fwspk)
303{
304 static struct snd_pcm_ops ops = {
305 .open = fwspk_open,
306 .close = fwspk_close,
307 .ioctl = snd_pcm_lib_ioctl,
308 .hw_params = fwspk_hw_params,
309 .hw_free = fwspk_hw_free,
310 .prepare = fwspk_prepare,
311 .trigger = fwspk_trigger,
312 .pointer = fwspk_pointer,
313 .page = snd_pcm_lib_get_vmalloc_page,
314 .mmap = snd_pcm_lib_mmap_vmalloc,
315 };
316 struct snd_pcm *pcm;
317 int err;
318
319 err = snd_pcm_new(fwspk->card, "OXFW970", 0, 1, 0, &pcm);
320 if (err < 0)
321 return err;
322 pcm->private_data = fwspk;
323 strcpy(pcm->name, fwspk->device_info->short_name);
324 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &ops);
325 return 0;
326}
327
328enum control_action { CTL_READ, CTL_WRITE };
329enum control_attribute {
330 CTL_MIN = 0x02,
331 CTL_MAX = 0x03,
332 CTL_CURRENT = 0x10,
333};
334
335static int fwspk_mute_command(struct fwspk *fwspk, bool *value,
336 enum control_action action)
337{
338 u8 *buf;
339 u8 response_ok;
340 int err;
341
342 buf = kmalloc(11, GFP_KERNEL);
343 if (!buf)
344 return -ENOMEM;
345
346 if (action == CTL_READ) {
347 buf[0] = 0x01; /* AV/C, STATUS */
348 response_ok = 0x0c; /* STABLE */
349 } else {
350 buf[0] = 0x00; /* AV/C, CONTROL */
351 response_ok = 0x09; /* ACCEPTED */
352 }
353 buf[1] = 0x08; /* audio unit 0 */
354 buf[2] = 0xb8; /* FUNCTION BLOCK */
355 buf[3] = 0x81; /* function block type: feature */
356 buf[4] = fwspk->device_info->mute_fb_id; /* function block ID */
357 buf[5] = 0x10; /* control attribute: current */
358 buf[6] = 0x02; /* selector length */
359 buf[7] = 0x00; /* audio channel number */
360 buf[8] = 0x01; /* control selector: mute */
361 buf[9] = 0x01; /* control data length */
362 if (action == CTL_READ)
363 buf[10] = 0xff;
364 else
365 buf[10] = *value ? 0x70 : 0x60;
366
367 err = fcp_avc_transaction(fwspk->unit, buf, 11, buf, 11, 0x3fe);
368 if (err < 0)
369 goto error;
370 if (err < 11) {
371 dev_err(&fwspk->unit->device, "short FCP response\n");
372 err = -EIO;
373 goto error;
374 }
375 if (buf[0] != response_ok) {
376 dev_err(&fwspk->unit->device, "mute command failed\n");
377 err = -EIO;
378 goto error;
379 }
380 if (action == CTL_READ)
381 *value = buf[10] == 0x70;
382
383 err = 0;
384
385error:
386 kfree(buf);
387
388 return err;
389}
390
391static int fwspk_volume_command(struct fwspk *fwspk, s16 *value,
392 unsigned int channel,
393 enum control_attribute attribute,
394 enum control_action action)
395{
396 u8 *buf;
397 u8 response_ok;
398 int err;
399
400 buf = kmalloc(12, GFP_KERNEL);
401 if (!buf)
402 return -ENOMEM;
403
404 if (action == CTL_READ) {
405 buf[0] = 0x01; /* AV/C, STATUS */
406 response_ok = 0x0c; /* STABLE */
407 } else {
408 buf[0] = 0x00; /* AV/C, CONTROL */
409 response_ok = 0x09; /* ACCEPTED */
410 }
411 buf[1] = 0x08; /* audio unit 0 */
412 buf[2] = 0xb8; /* FUNCTION BLOCK */
413 buf[3] = 0x81; /* function block type: feature */
414 buf[4] = fwspk->device_info->volume_fb_id; /* function block ID */
415 buf[5] = attribute; /* control attribute */
416 buf[6] = 0x02; /* selector length */
417 buf[7] = channel; /* audio channel number */
418 buf[8] = 0x02; /* control selector: volume */
419 buf[9] = 0x02; /* control data length */
420 if (action == CTL_READ) {
421 buf[10] = 0xff;
422 buf[11] = 0xff;
423 } else {
424 buf[10] = *value >> 8;
425 buf[11] = *value;
426 }
427
428 err = fcp_avc_transaction(fwspk->unit, buf, 12, buf, 12, 0x3fe);
429 if (err < 0)
430 goto error;
431 if (err < 12) {
432 dev_err(&fwspk->unit->device, "short FCP response\n");
433 err = -EIO;
434 goto error;
435 }
436 if (buf[0] != response_ok) {
437 dev_err(&fwspk->unit->device, "volume command failed\n");
438 err = -EIO;
439 goto error;
440 }
441 if (action == CTL_READ)
442 *value = (buf[10] << 8) | buf[11];
443
444 err = 0;
445
446error:
447 kfree(buf);
448
449 return err;
450}
451
452static int fwspk_mute_get(struct snd_kcontrol *control,
453 struct snd_ctl_elem_value *value)
454{
455 struct fwspk *fwspk = control->private_data;
456
457 value->value.integer.value[0] = !fwspk->mute;
458
459 return 0;
460}
461
462static int fwspk_mute_put(struct snd_kcontrol *control,
463 struct snd_ctl_elem_value *value)
464{
465 struct fwspk *fwspk = control->private_data;
466 bool mute;
467 int err;
468
469 mute = !value->value.integer.value[0];
470
471 if (mute == fwspk->mute)
472 return 0;
473
474 err = fwspk_mute_command(fwspk, &mute, CTL_WRITE);
475 if (err < 0)
476 return err;
477 fwspk->mute = mute;
478
479 return 1;
480}
481
482static int fwspk_volume_info(struct snd_kcontrol *control,
483 struct snd_ctl_elem_info *info)
484{
485 struct fwspk *fwspk = control->private_data;
486
487 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
488 info->count = fwspk->device_info->mixer_channels;
489 info->value.integer.min = fwspk->volume_min;
490 info->value.integer.max = fwspk->volume_max;
491
492 return 0;
493}
494
495static const u8 channel_map[6] = { 0, 1, 4, 5, 2, 3 };
496
497static int fwspk_volume_get(struct snd_kcontrol *control,
498 struct snd_ctl_elem_value *value)
499{
500 struct fwspk *fwspk = control->private_data;
501 unsigned int i;
502
503 for (i = 0; i < fwspk->device_info->mixer_channels; ++i)
504 value->value.integer.value[channel_map[i]] = fwspk->volume[i];
505
506 return 0;
507}
508
509static int fwspk_volume_put(struct snd_kcontrol *control,
510 struct snd_ctl_elem_value *value)
511{
512 struct fwspk *fwspk = control->private_data;
513 unsigned int i, changed_channels;
514 bool equal_values = true;
515 s16 volume;
516 int err;
517
518 for (i = 0; i < fwspk->device_info->mixer_channels; ++i) {
519 if (value->value.integer.value[i] < fwspk->volume_min ||
520 value->value.integer.value[i] > fwspk->volume_max)
521 return -EINVAL;
522 if (value->value.integer.value[i] !=
523 value->value.integer.value[0])
524 equal_values = false;
525 }
526
527 changed_channels = 0;
528 for (i = 0; i < fwspk->device_info->mixer_channels; ++i)
529 if (value->value.integer.value[channel_map[i]] !=
530 fwspk->volume[i])
531 changed_channels |= 1 << (i + 1);
532
533 if (equal_values && changed_channels != 0)
534 changed_channels = 1 << 0;
535
536 for (i = 0; i <= fwspk->device_info->mixer_channels; ++i) {
537 volume = value->value.integer.value[channel_map[i ? i - 1 : 0]];
538 if (changed_channels & (1 << i)) {
539 err = fwspk_volume_command(fwspk, &volume, i,
540 CTL_CURRENT, CTL_WRITE);
541 if (err < 0)
542 return err;
543 }
544 if (i > 0)
545 fwspk->volume[i - 1] = volume;
546 }
547
548 return changed_channels != 0;
549}
550
551static int fwspk_create_mixer(struct fwspk *fwspk)
552{
553 static const struct snd_kcontrol_new controls[] = {
554 {
555 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
556 .name = "PCM Playback Switch",
557 .info = snd_ctl_boolean_mono_info,
558 .get = fwspk_mute_get,
559 .put = fwspk_mute_put,
560 },
561 {
562 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
563 .name = "PCM Playback Volume",
564 .info = fwspk_volume_info,
565 .get = fwspk_volume_get,
566 .put = fwspk_volume_put,
567 },
568 };
569 unsigned int i, first_ch;
570 int err;
571
572 err = fwspk_volume_command(fwspk, &fwspk->volume_min,
573 0, CTL_MIN, CTL_READ);
574 if (err < 0)
575 return err;
576 err = fwspk_volume_command(fwspk, &fwspk->volume_max,
577 0, CTL_MAX, CTL_READ);
578 if (err < 0)
579 return err;
580
581 err = fwspk_mute_command(fwspk, &fwspk->mute, CTL_READ);
582 if (err < 0)
583 return err;
584
585 first_ch = fwspk->device_info->mixer_channels == 1 ? 0 : 1;
586 for (i = 0; i < fwspk->device_info->mixer_channels; ++i) {
587 err = fwspk_volume_command(fwspk, &fwspk->volume[i],
588 first_ch + i, CTL_CURRENT, CTL_READ);
589 if (err < 0)
590 return err;
591 }
592
593 for (i = 0; i < ARRAY_SIZE(controls); ++i) {
594 err = snd_ctl_add(fwspk->card,
595 snd_ctl_new1(&controls[i], fwspk));
596 if (err < 0)
597 return err;
598 }
599
600 return 0;
601}
602
603static u32 fwspk_read_firmware_version(struct fw_unit *unit)
604{
605 __be32 data;
606 int err;
607
608 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
609 OXFORD_FIRMWARE_ID_ADDRESS, &data, 4, 0);
610 return err >= 0 ? be32_to_cpu(data) : 0;
611}
612
613static void fwspk_card_free(struct snd_card *card)
614{
615 struct fwspk *fwspk = card->private_data;
616
617 amdtp_stream_destroy(&fwspk->stream);
618 cmp_connection_destroy(&fwspk->connection);
619 fw_unit_put(fwspk->unit);
620 mutex_destroy(&fwspk->mutex);
621}
622
623static int fwspk_probe(struct fw_unit *unit,
624 const struct ieee1394_device_id *id)
625{
626 struct fw_device *fw_dev = fw_parent_device(unit);
627 struct snd_card *card;
628 struct fwspk *fwspk;
629 u32 firmware;
630 int err;
631
632 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
633 sizeof(*fwspk), &card);
634 if (err < 0)
635 return err;
636
637 fwspk = card->private_data;
638 fwspk->card = card;
639 mutex_init(&fwspk->mutex);
640 fwspk->unit = fw_unit_get(unit);
641 fwspk->device_info = (const struct device_info *)id->driver_data;
642
643 err = cmp_connection_init(&fwspk->connection, unit, CMP_INPUT, 0);
644 if (err < 0)
645 goto err_unit;
646
647 err = amdtp_stream_init(&fwspk->stream, unit, AMDTP_OUT_STREAM,
648 CIP_NONBLOCKING);
649 if (err < 0)
650 goto err_connection;
651
652 card->private_free = fwspk_card_free;
653
654 strcpy(card->driver, fwspk->device_info->driver_name);
655 strcpy(card->shortname, fwspk->device_info->short_name);
656 firmware = fwspk_read_firmware_version(unit);
657 snprintf(card->longname, sizeof(card->longname),
658 "%s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
659 fwspk->device_info->long_name,
660 firmware >> 20, firmware & 0xffff,
661 fw_dev->config_rom[3], fw_dev->config_rom[4],
662 dev_name(&unit->device), 100 << fw_dev->max_speed);
663 strcpy(card->mixername, "OXFW970");
664
665 err = fwspk_create_pcm(fwspk);
666 if (err < 0)
667 goto error;
668
669 err = fwspk_create_mixer(fwspk);
670 if (err < 0)
671 goto error;
672
673 err = snd_card_register(card);
674 if (err < 0)
675 goto error;
676
677 dev_set_drvdata(&unit->device, fwspk);
678
679 return 0;
680
681err_connection:
682 cmp_connection_destroy(&fwspk->connection);
683err_unit:
684 fw_unit_put(fwspk->unit);
685 mutex_destroy(&fwspk->mutex);
686error:
687 snd_card_free(card);
688 return err;
689}
690
691static void fwspk_bus_reset(struct fw_unit *unit)
692{
693 struct fwspk *fwspk = dev_get_drvdata(&unit->device);
694
695 fcp_bus_reset(fwspk->unit);
696
697 if (cmp_connection_update(&fwspk->connection) < 0) {
698 amdtp_stream_pcm_abort(&fwspk->stream);
699 mutex_lock(&fwspk->mutex);
700 fwspk_stop_stream(fwspk);
701 mutex_unlock(&fwspk->mutex);
702 return;
703 }
704
705 amdtp_stream_update(&fwspk->stream);
706}
707
708static void fwspk_remove(struct fw_unit *unit)
709{
710 struct fwspk *fwspk = dev_get_drvdata(&unit->device);
711
712 amdtp_stream_pcm_abort(&fwspk->stream);
713 snd_card_disconnect(fwspk->card);
714
715 mutex_lock(&fwspk->mutex);
716 fwspk_stop_stream(fwspk);
717 mutex_unlock(&fwspk->mutex);
718
719 snd_card_free_when_closed(fwspk->card);
720}
721
722static const struct device_info griffin_firewave = {
723 .driver_name = "FireWave",
724 .short_name = "FireWave",
725 .long_name = "Griffin FireWave Surround",
726 .pcm_constraints = firewave_constraints,
727 .mixer_channels = 6,
728 .mute_fb_id = 0x01,
729 .volume_fb_id = 0x02,
730};
731
732static const struct device_info lacie_speakers = {
733 .driver_name = "FWSpeakers",
734 .short_name = "FireWire Speakers",
735 .long_name = "LaCie FireWire Speakers",
736 .pcm_constraints = lacie_speakers_constraints,
737 .mixer_channels = 1,
738 .mute_fb_id = 0x01,
739 .volume_fb_id = 0x01,
740};
741
742static const struct ieee1394_device_id fwspk_id_table[] = {
743 {
744 .match_flags = IEEE1394_MATCH_VENDOR_ID |
745 IEEE1394_MATCH_MODEL_ID |
746 IEEE1394_MATCH_SPECIFIER_ID |
747 IEEE1394_MATCH_VERSION,
748 .vendor_id = VENDOR_GRIFFIN,
749 .model_id = 0x00f970,
750 .specifier_id = SPECIFIER_1394TA,
751 .version = VERSION_AVC,
752 .driver_data = (kernel_ulong_t)&griffin_firewave,
753 },
754 {
755 .match_flags = IEEE1394_MATCH_VENDOR_ID |
756 IEEE1394_MATCH_MODEL_ID |
757 IEEE1394_MATCH_SPECIFIER_ID |
758 IEEE1394_MATCH_VERSION,
759 .vendor_id = VENDOR_LACIE,
760 .model_id = 0x00f970,
761 .specifier_id = SPECIFIER_1394TA,
762 .version = VERSION_AVC,
763 .driver_data = (kernel_ulong_t)&lacie_speakers,
764 },
765 { }
766};
767MODULE_DEVICE_TABLE(ieee1394, fwspk_id_table);
768
769static struct fw_driver fwspk_driver = {
770 .driver = {
771 .owner = THIS_MODULE,
772 .name = KBUILD_MODNAME,
773 .bus = &fw_bus_type,
774 },
775 .probe = fwspk_probe,
776 .update = fwspk_bus_reset,
777 .remove = fwspk_remove,
778 .id_table = fwspk_id_table,
779};
780
781static int __init alsa_fwspk_init(void)
782{
783 return driver_register(&fwspk_driver.driver);
784}
785
786static void __exit alsa_fwspk_exit(void)
787{
788 driver_unregister(&fwspk_driver.driver);
789}
790
791module_init(alsa_fwspk_init);
792module_exit(alsa_fwspk_exit);
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c
index f3735e64791c..67dbfde837ab 100644
--- a/sound/i2c/other/ak4xxx-adda.c
+++ b/sound/i2c/other/ak4xxx-adda.c
@@ -465,17 +465,10 @@ static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol,
465static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol, 465static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol,
466 struct snd_ctl_elem_info *uinfo) 466 struct snd_ctl_elem_info *uinfo)
467{ 467{
468 static char *texts[4] = { 468 static const char * const texts[4] = {
469 "44.1kHz", "Off", "48kHz", "32kHz", 469 "44.1kHz", "Off", "48kHz", "32kHz",
470 }; 470 };
471 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 471 return snd_ctl_enum_info(uinfo, 1, 4, texts);
472 uinfo->count = 1;
473 uinfo->value.enumerated.items = 4;
474 if (uinfo->value.enumerated.item >= 4)
475 uinfo->value.enumerated.item = 3;
476 strcpy(uinfo->value.enumerated.name,
477 texts[uinfo->value.enumerated.item]);
478 return 0;
479} 472}
480 473
481static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol, 474static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol,
@@ -570,22 +563,13 @@ static int ak4xxx_capture_source_info(struct snd_kcontrol *kcontrol,
570{ 563{
571 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); 564 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
572 int mixer_ch = AK_GET_SHIFT(kcontrol->private_value); 565 int mixer_ch = AK_GET_SHIFT(kcontrol->private_value);
573 const char **input_names; 566 unsigned int num_names;
574 unsigned int num_names, idx;
575 567
576 num_names = ak4xxx_capture_num_inputs(ak, mixer_ch); 568 num_names = ak4xxx_capture_num_inputs(ak, mixer_ch);
577 if (!num_names) 569 if (!num_names)
578 return -EINVAL; 570 return -EINVAL;
579 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 571 return snd_ctl_enum_info(uinfo, 1, num_names,
580 uinfo->count = 1; 572 ak->adc_info[mixer_ch].input_names);
581 uinfo->value.enumerated.items = num_names;
582 idx = uinfo->value.enumerated.item;
583 if (idx >= num_names)
584 return -EINVAL;
585 input_names = ak->adc_info[mixer_ch].input_names;
586 strlcpy(uinfo->value.enumerated.name, input_names[idx],
587 sizeof(uinfo->value.enumerated.name));
588 return 0;
589} 573}
590 574
591static int ak4xxx_capture_source_get(struct snd_kcontrol *kcontrol, 575static int ak4xxx_capture_source_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/isa/ad1816a/ad1816a_lib.c b/sound/isa/ad1816a/ad1816a_lib.c
index f0fd98e695e3..01a07986f4a3 100644
--- a/sound/isa/ad1816a/ad1816a_lib.c
+++ b/sound/isa/ad1816a/ad1816a_lib.c
@@ -731,18 +731,12 @@ int snd_ad1816a_timer(struct snd_ad1816a *chip, int device,
731 731
732static int snd_ad1816a_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 732static int snd_ad1816a_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
733{ 733{
734 static char *texts[8] = { 734 static const char * const texts[8] = {
735 "Line", "Mix", "CD", "Synth", "Video", 735 "Line", "Mix", "CD", "Synth", "Video",
736 "Mic", "Phone", 736 "Mic", "Phone",
737 }; 737 };
738 738
739 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 739 return snd_ctl_enum_info(uinfo, 2, 7, texts);
740 uinfo->count = 2;
741 uinfo->value.enumerated.items = 7;
742 if (uinfo->value.enumerated.item > 6)
743 uinfo->value.enumerated.item = 6;
744 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
745 return 0;
746} 740}
747 741
748static int snd_ad1816a_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 742static int snd_ad1816a_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c
index b3b4f15e45ba..b5450143407b 100644
--- a/sound/isa/es1688/es1688_lib.c
+++ b/sound/isa/es1688/es1688_lib.c
@@ -614,8 +614,7 @@ static int snd_es1688_free(struct snd_es1688 *chip)
614{ 614{
615 if (chip->hardware != ES1688_HW_UNDEF) 615 if (chip->hardware != ES1688_HW_UNDEF)
616 snd_es1688_init(chip, 0); 616 snd_es1688_init(chip, 0);
617 if (chip->res_port) 617 release_and_free_resource(chip->res_port);
618 release_and_free_resource(chip->res_port);
619 if (chip->irq >= 0) 618 if (chip->irq >= 0)
620 free_irq(chip->irq, (void *) chip); 619 free_irq(chip->irq, (void *) chip);
621 if (chip->dma8 >= 0) { 620 if (chip->dma8 >= 0) {
@@ -762,18 +761,12 @@ int snd_es1688_pcm(struct snd_card *card, struct snd_es1688 *chip,
762 761
763static int snd_es1688_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 762static int snd_es1688_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
764{ 763{
765 static char *texts[9] = { 764 static const char * const texts[8] = {
766 "Mic", "Mic Master", "CD", "AOUT", 765 "Mic", "Mic Master", "CD", "AOUT",
767 "Mic1", "Mix", "Line", "Master" 766 "Mic1", "Mix", "Line", "Master"
768 }; 767 };
769 768
770 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 769 return snd_ctl_enum_info(uinfo, 1, 8, texts);
771 uinfo->count = 1;
772 uinfo->value.enumerated.items = 8;
773 if (uinfo->value.enumerated.item > 7)
774 uinfo->value.enumerated.item = 7;
775 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
776 return 0;
777} 770}
778 771
779static int snd_es1688_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 772static int snd_es1688_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index 6faaac60161a..b481bb8c31bc 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -156,6 +156,7 @@ struct snd_es18xx {
156#define ES18XX_I2S 0x0200 /* I2S mixer control */ 156#define ES18XX_I2S 0x0200 /* I2S mixer control */
157#define ES18XX_MUTEREC 0x0400 /* Record source can be muted */ 157#define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
158#define ES18XX_CONTROL 0x0800 /* Has control ports */ 158#define ES18XX_CONTROL 0x0800 /* Has control ports */
159#define ES18XX_GPO_2BIT 0x1000 /* GPO0,1 controlled by PM port */
159 160
160/* Power Management */ 161/* Power Management */
161#define ES18XX_PM 0x07 162#define ES18XX_PM 0x07
@@ -964,44 +965,28 @@ static int snd_es18xx_capture_close(struct snd_pcm_substream *substream)
964 965
965static 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)
966{ 967{
967 static char *texts5Source[5] = { 968 static const char * const texts5Source[5] = {
968 "Mic", "CD", "Line", "Master", "Mix" 969 "Mic", "CD", "Line", "Master", "Mix"
969 }; 970 };
970 static char *texts8Source[8] = { 971 static const char * const texts8Source[8] = {
971 "Mic", "Mic Master", "CD", "AOUT", 972 "Mic", "Mic Master", "CD", "AOUT",
972 "Mic1", "Mix", "Line", "Master" 973 "Mic1", "Mix", "Line", "Master"
973 }; 974 };
974 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); 975 struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
975 976
976 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
977 uinfo->count = 1;
978 switch (chip->version) { 977 switch (chip->version) {
979 case 0x1868: 978 case 0x1868:
980 case 0x1878: 979 case 0x1878:
981 uinfo->value.enumerated.items = 4; 980 return snd_ctl_enum_info(uinfo, 1, 4, texts5Source);
982 if (uinfo->value.enumerated.item > 3)
983 uinfo->value.enumerated.item = 3;
984 strcpy(uinfo->value.enumerated.name,
985 texts5Source[uinfo->value.enumerated.item]);
986 break;
987 case 0x1887: 981 case 0x1887:
988 case 0x1888: 982 case 0x1888:
989 uinfo->value.enumerated.items = 5; 983 return snd_ctl_enum_info(uinfo, 1, 5, texts5Source);
990 if (uinfo->value.enumerated.item > 4)
991 uinfo->value.enumerated.item = 4;
992 strcpy(uinfo->value.enumerated.name, texts5Source[uinfo->value.enumerated.item]);
993 break;
994 case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */ 984 case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */
995 case 0x1879: 985 case 0x1879:
996 uinfo->value.enumerated.items = 8; 986 return snd_ctl_enum_info(uinfo, 1, 8, texts8Source);
997 if (uinfo->value.enumerated.item > 7)
998 uinfo->value.enumerated.item = 7;
999 strcpy(uinfo->value.enumerated.name, texts8Source[uinfo->value.enumerated.item]);
1000 break;
1001 default: 987 default:
1002 return -EINVAL; 988 return -EINVAL;
1003 } 989 }
1004 return 0;
1005} 990}
1006 991
1007static int snd_es18xx_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 992static int snd_es18xx_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1136,11 +1121,14 @@ static int snd_es18xx_reg_read(struct snd_es18xx *chip, unsigned char reg)
1136 return snd_es18xx_read(chip, reg); 1121 return snd_es18xx_read(chip, reg);
1137} 1122}
1138 1123
1139#define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \ 1124#define ES18XX_SINGLE(xname, xindex, reg, shift, mask, flags) \
1140{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 1125{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1141 .info = snd_es18xx_info_single, \ 1126 .info = snd_es18xx_info_single, \
1142 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \ 1127 .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
1143 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } 1128 .private_value = reg | (shift << 8) | (mask << 16) | (flags << 24) }
1129
1130#define ES18XX_FL_INVERT (1 << 0)
1131#define ES18XX_FL_PMPORT (1 << 1)
1144 1132
1145static int snd_es18xx_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1133static int snd_es18xx_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1146{ 1134{
@@ -1159,10 +1147,14 @@ static int snd_es18xx_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_e
1159 int reg = kcontrol->private_value & 0xff; 1147 int reg = kcontrol->private_value & 0xff;
1160 int shift = (kcontrol->private_value >> 8) & 0xff; 1148 int shift = (kcontrol->private_value >> 8) & 0xff;
1161 int mask = (kcontrol->private_value >> 16) & 0xff; 1149 int mask = (kcontrol->private_value >> 16) & 0xff;
1162 int invert = (kcontrol->private_value >> 24) & 0xff; 1150 int invert = (kcontrol->private_value >> 24) & ES18XX_FL_INVERT;
1151 int pm_port = (kcontrol->private_value >> 24) & ES18XX_FL_PMPORT;
1163 int val; 1152 int val;
1164 1153
1165 val = snd_es18xx_reg_read(chip, reg); 1154 if (pm_port)
1155 val = inb(chip->port + ES18XX_PM);
1156 else
1157 val = snd_es18xx_reg_read(chip, reg);
1166 ucontrol->value.integer.value[0] = (val >> shift) & mask; 1158 ucontrol->value.integer.value[0] = (val >> shift) & mask;
1167 if (invert) 1159 if (invert)
1168 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; 1160 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
@@ -1175,7 +1167,8 @@ static int snd_es18xx_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_e
1175 int reg = kcontrol->private_value & 0xff; 1167 int reg = kcontrol->private_value & 0xff;
1176 int shift = (kcontrol->private_value >> 8) & 0xff; 1168 int shift = (kcontrol->private_value >> 8) & 0xff;
1177 int mask = (kcontrol->private_value >> 16) & 0xff; 1169 int mask = (kcontrol->private_value >> 16) & 0xff;
1178 int invert = (kcontrol->private_value >> 24) & 0xff; 1170 int invert = (kcontrol->private_value >> 24) & ES18XX_FL_INVERT;
1171 int pm_port = (kcontrol->private_value >> 24) & ES18XX_FL_PMPORT;
1179 unsigned char val; 1172 unsigned char val;
1180 1173
1181 val = (ucontrol->value.integer.value[0] & mask); 1174 val = (ucontrol->value.integer.value[0] & mask);
@@ -1183,6 +1176,15 @@ static int snd_es18xx_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_e
1183 val = mask - val; 1176 val = mask - val;
1184 mask <<= shift; 1177 mask <<= shift;
1185 val <<= shift; 1178 val <<= shift;
1179 if (pm_port) {
1180 unsigned char cur = inb(chip->port + ES18XX_PM);
1181
1182 if ((cur & mask) == val)
1183 return 0;
1184 outb((cur & ~mask) | val, chip->port + ES18XX_PM);
1185 return 1;
1186 }
1187
1186 return snd_es18xx_reg_bits(chip, reg, mask, val) != val; 1188 return snd_es18xx_reg_bits(chip, reg, mask, val) != val;
1187} 1189}
1188 1190
@@ -1304,7 +1306,7 @@ static struct snd_kcontrol_new snd_es18xx_opt_speaker =
1304 ES18XX_SINGLE("Beep Playback Volume", 0, 0x3c, 0, 7, 0); 1306 ES18XX_SINGLE("Beep Playback Volume", 0, 0x3c, 0, 7, 0);
1305 1307
1306static struct snd_kcontrol_new snd_es18xx_opt_1869[] = { 1308static struct snd_kcontrol_new snd_es18xx_opt_1869[] = {
1307ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), 1309ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, ES18XX_FL_INVERT),
1308ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0), 1310ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0),
1309ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), 1311ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1310ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0) 1312ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
@@ -1363,6 +1365,11 @@ static struct snd_kcontrol_new snd_es18xx_hw_volume_controls[] = {
1363ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0), 1365ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1364}; 1366};
1365 1367
1368static struct snd_kcontrol_new snd_es18xx_opt_gpo_2bit[] = {
1369ES18XX_SINGLE("GPO0 Switch", 0, ES18XX_PM, 0, 1, ES18XX_FL_PMPORT),
1370ES18XX_SINGLE("GPO1 Switch", 0, ES18XX_PM, 1, 1, ES18XX_FL_PMPORT),
1371};
1372
1366static int snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg) 1373static int snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg)
1367{ 1374{
1368 int data; 1375 int data;
@@ -1629,10 +1636,10 @@ static int snd_es18xx_probe(struct snd_es18xx *chip,
1629 1636
1630 switch (chip->version) { 1637 switch (chip->version) {
1631 case 0x1868: 1638 case 0x1868:
1632 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL; 1639 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL | ES18XX_GPO_2BIT;
1633 break; 1640 break;
1634 case 0x1869: 1641 case 0x1869:
1635 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV; 1642 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV | ES18XX_GPO_2BIT;
1636 break; 1643 break;
1637 case 0x1878: 1644 case 0x1878:
1638 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL; 1645 chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL;
@@ -1642,7 +1649,7 @@ static int snd_es18xx_probe(struct snd_es18xx *chip,
1642 break; 1649 break;
1643 case 0x1887: 1650 case 0x1887:
1644 case 0x1888: 1651 case 0x1888:
1645 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME; 1652 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_GPO_2BIT;
1646 break; 1653 break;
1647 default: 1654 default:
1648 snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n", 1655 snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n",
@@ -1944,6 +1951,15 @@ static int snd_es18xx_mixer(struct snd_card *card)
1944 return err; 1951 return err;
1945 } 1952 }
1946 } 1953 }
1954 if (chip->caps & ES18XX_GPO_2BIT) {
1955 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_gpo_2bit); idx++) {
1956 err = snd_ctl_add(card,
1957 snd_ctl_new1(&snd_es18xx_opt_gpo_2bit[idx],
1958 chip));
1959 if (err < 0)
1960 return err;
1961 }
1962 }
1947 return 0; 1963 return 0;
1948} 1964}
1949 1965
diff --git a/sound/isa/msnd/msnd_pinnacle_mixer.c b/sound/isa/msnd/msnd_pinnacle_mixer.c
index 031dc69b7470..17e49a071af4 100644
--- a/sound/isa/msnd/msnd_pinnacle_mixer.c
+++ b/sound/isa/msnd/msnd_pinnacle_mixer.c
@@ -55,20 +55,13 @@
55static int snd_msndmix_info_mux(struct snd_kcontrol *kcontrol, 55static int snd_msndmix_info_mux(struct snd_kcontrol *kcontrol,
56 struct snd_ctl_elem_info *uinfo) 56 struct snd_ctl_elem_info *uinfo)
57{ 57{
58 static char *texts[3] = { 58 static const char * const texts[3] = {
59 "Analog", "MASS", "SPDIF", 59 "Analog", "MASS", "SPDIF",
60 }; 60 };
61 struct snd_msnd *chip = snd_kcontrol_chip(kcontrol); 61 struct snd_msnd *chip = snd_kcontrol_chip(kcontrol);
62 unsigned items = test_bit(F_HAVEDIGITAL, &chip->flags) ? 3 : 2; 62 unsigned items = test_bit(F_HAVEDIGITAL, &chip->flags) ? 3 : 2;
63 63
64 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 64 return snd_ctl_enum_info(uinfo, 1, items, texts);
65 uinfo->count = 1;
66 uinfo->value.enumerated.items = items;
67 if (uinfo->value.enumerated.item >= items)
68 uinfo->value.enumerated.item = items - 1;
69 strcpy(uinfo->value.enumerated.name,
70 texts[uinfo->value.enumerated.item]);
71 return 0;
72} 65}
73 66
74static int snd_msndmix_get_mux(struct snd_kcontrol *kcontrol, 67static int snd_msndmix_get_mux(struct snd_kcontrol *kcontrol,
diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
index 4e3fcfb15ad4..95b39beb61c1 100644
--- a/sound/isa/sb/emu8000_synth.c
+++ b/sound/isa/sb/emu8000_synth.c
@@ -105,8 +105,7 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev)
105 snd_device_free(dev->card, hw->pcm); 105 snd_device_free(dev->card, hw->pcm);
106 if (hw->emu) 106 if (hw->emu)
107 snd_emux_free(hw->emu); 107 snd_emux_free(hw->emu);
108 if (hw->memhdr) 108 snd_util_memhdr_free(hw->memhdr);
109 snd_util_memhdr_free(hw->memhdr);
110 hw->emu = NULL; 109 hw->emu = NULL;
111 hw->memhdr = NULL; 110 hw->memhdr = NULL;
112 return 0; 111 return 0;
diff --git a/sound/isa/sb/sb16_main.c b/sound/isa/sb/sb16_main.c
index 0bbcd4714d28..72b10f4f3e70 100644
--- a/sound/isa/sb/sb16_main.c
+++ b/sound/isa/sb/sb16_main.c
@@ -702,17 +702,11 @@ static int snd_sb16_get_dma_mode(struct snd_sb *chip)
702 702
703static int snd_sb16_dma_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 703static int snd_sb16_dma_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
704{ 704{
705 static char *texts[3] = { 705 static const char * const texts[3] = {
706 "Auto", "Playback", "Capture" 706 "Auto", "Playback", "Capture"
707 }; 707 };
708 708
709 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 709 return snd_ctl_enum_info(uinfo, 1, 3, texts);
710 uinfo->count = 1;
711 uinfo->value.enumerated.items = 3;
712 if (uinfo->value.enumerated.item > 2)
713 uinfo->value.enumerated.item = 2;
714 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
715 return 0;
716} 710}
717 711
718static int snd_sb16_dma_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 712static int snd_sb16_dma_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c
index 3ef990602cdd..f22b4480828e 100644
--- a/sound/isa/sb/sb_common.c
+++ b/sound/isa/sb/sb_common.c
@@ -184,8 +184,7 @@ static int snd_sbdsp_probe(struct snd_sb * chip)
184 184
185static int snd_sbdsp_free(struct snd_sb *chip) 185static int snd_sbdsp_free(struct snd_sb *chip)
186{ 186{
187 if (chip->res_port) 187 release_and_free_resource(chip->res_port);
188 release_and_free_resource(chip->res_port);
189 if (chip->irq >= 0) 188 if (chip->irq >= 0)
190 free_irq(chip->irq, (void *) chip); 189 free_irq(chip->irq, (void *) chip);
191#ifdef CONFIG_ISA 190#ifdef CONFIG_ISA
diff --git a/sound/isa/sb/sb_mixer.c b/sound/isa/sb/sb_mixer.c
index 1ff78ec9f0ac..e403334a19ad 100644
--- a/sound/isa/sb/sb_mixer.c
+++ b/sound/isa/sb/sb_mixer.c
@@ -182,17 +182,11 @@ static int snd_sbmixer_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_
182 182
183static int snd_dt019x_input_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 183static int snd_dt019x_input_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
184{ 184{
185 static const char *texts[5] = { 185 static const char * const texts[5] = {
186 "CD", "Mic", "Line", "Synth", "Master" 186 "CD", "Mic", "Line", "Synth", "Master"
187 }; 187 };
188 188
189 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 189 return snd_ctl_enum_info(uinfo, 1, 5, texts);
190 uinfo->count = 1;
191 uinfo->value.enumerated.items = 5;
192 if (uinfo->value.enumerated.item > 4)
193 uinfo->value.enumerated.item = 4;
194 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
195 return 0;
196} 190}
197 191
198static int snd_dt019x_input_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 192static int snd_dt019x_input_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -275,18 +269,11 @@ static int snd_dt019x_input_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl
275static int snd_als4k_mono_capture_route_info(struct snd_kcontrol *kcontrol, 269static int snd_als4k_mono_capture_route_info(struct snd_kcontrol *kcontrol,
276 struct snd_ctl_elem_info *uinfo) 270 struct snd_ctl_elem_info *uinfo)
277{ 271{
278 static const char *texts[3] = { 272 static const char * const texts[3] = {
279 "L chan only", "R chan only", "L ch/2 + R ch/2" 273 "L chan only", "R chan only", "L ch/2 + R ch/2"
280 }; 274 };
281 275
282 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 276 return snd_ctl_enum_info(uinfo, 1, 3, texts);
283 uinfo->count = 1;
284 uinfo->value.enumerated.items = 3;
285 if (uinfo->value.enumerated.item > 2)
286 uinfo->value.enumerated.item = 2;
287 strcpy(uinfo->value.enumerated.name,
288 texts[uinfo->value.enumerated.item]);
289 return 0;
290} 277}
291 278
292static int snd_als4k_mono_capture_route_get(struct snd_kcontrol *kcontrol, 279static int snd_als4k_mono_capture_route_get(struct snd_kcontrol *kcontrol,
@@ -335,17 +322,11 @@ static int snd_als4k_mono_capture_route_put(struct snd_kcontrol *kcontrol,
335 322
336static int snd_sb8mixer_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 323static int snd_sb8mixer_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
337{ 324{
338 static const char *texts[3] = { 325 static const char * const texts[3] = {
339 "Mic", "CD", "Line" 326 "Mic", "CD", "Line"
340 }; 327 };
341 328
342 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 329 return snd_ctl_enum_info(uinfo, 1, 3, texts);
343 uinfo->count = 1;
344 uinfo->value.enumerated.items = 3;
345 if (uinfo->value.enumerated.item > 2)
346 uinfo->value.enumerated.item = 2;
347 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
348 return 0;
349} 330}
350 331
351 332
diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c
index 360b08b03e1d..347bb1bda110 100644
--- a/sound/isa/wss/wss_lib.c
+++ b/sound/isa/wss/wss_lib.c
@@ -1993,25 +1993,20 @@ EXPORT_SYMBOL(snd_wss_timer);
1993static int snd_wss_info_mux(struct snd_kcontrol *kcontrol, 1993static int snd_wss_info_mux(struct snd_kcontrol *kcontrol,
1994 struct snd_ctl_elem_info *uinfo) 1994 struct snd_ctl_elem_info *uinfo)
1995{ 1995{
1996 static char *texts[4] = { 1996 static const char * const texts[4] = {
1997 "Line", "Aux", "Mic", "Mix" 1997 "Line", "Aux", "Mic", "Mix"
1998 }; 1998 };
1999 static char *opl3sa_texts[4] = { 1999 static const char * const opl3sa_texts[4] = {
2000 "Line", "CD", "Mic", "Mix" 2000 "Line", "CD", "Mic", "Mix"
2001 }; 2001 };
2002 static char *gusmax_texts[4] = { 2002 static const char * const gusmax_texts[4] = {
2003 "Line", "Synth", "Mic", "Mix" 2003 "Line", "Synth", "Mic", "Mix"
2004 }; 2004 };
2005 char **ptexts = texts; 2005 const char * const *ptexts = texts;
2006 struct snd_wss *chip = snd_kcontrol_chip(kcontrol); 2006 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
2007 2007
2008 if (snd_BUG_ON(!chip->card)) 2008 if (snd_BUG_ON(!chip->card))
2009 return -EINVAL; 2009 return -EINVAL;
2010 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2011 uinfo->count = 2;
2012 uinfo->value.enumerated.items = 4;
2013 if (uinfo->value.enumerated.item > 3)
2014 uinfo->value.enumerated.item = 3;
2015 if (!strcmp(chip->card->driver, "GUS MAX")) 2010 if (!strcmp(chip->card->driver, "GUS MAX"))
2016 ptexts = gusmax_texts; 2011 ptexts = gusmax_texts;
2017 switch (chip->hardware) { 2012 switch (chip->hardware) {
@@ -2023,8 +2018,7 @@ static int snd_wss_info_mux(struct snd_kcontrol *kcontrol,
2023 ptexts = opl3sa_texts; 2018 ptexts = opl3sa_texts;
2024 break; 2019 break;
2025 } 2020 }
2026 strcpy(uinfo->value.enumerated.name, ptexts[uinfo->value.enumerated.item]); 2021 return snd_ctl_enum_info(uinfo, 2, 4, ptexts);
2027 return 0;
2028} 2022}
2029 2023
2030static int snd_wss_get_mux(struct snd_kcontrol *kcontrol, 2024static int snd_wss_get_mux(struct snd_kcontrol *kcontrol,
diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index 04bb06c03ec8..33b08fcc27a9 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -201,17 +201,10 @@ static int sgio2audio_gain_put(struct snd_kcontrol *kcontrol,
201static int sgio2audio_source_info(struct snd_kcontrol *kcontrol, 201static int sgio2audio_source_info(struct snd_kcontrol *kcontrol,
202 struct snd_ctl_elem_info *uinfo) 202 struct snd_ctl_elem_info *uinfo)
203{ 203{
204 static const char *texts[3] = { 204 static const char * const texts[3] = {
205 "Cam Mic", "Mic", "Line" 205 "Cam Mic", "Mic", "Line"
206 }; 206 };
207 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 207 return snd_ctl_enum_info(uinfo, 1, 3, texts);
208 uinfo->count = 1;
209 uinfo->value.enumerated.items = 3;
210 if (uinfo->value.enumerated.item >= 3)
211 uinfo->value.enumerated.item = 1;
212 strcpy(uinfo->value.enumerated.name,
213 texts[uinfo->value.enumerated.item]);
214 return 0;
215} 208}
216 209
217static int sgio2audio_source_get(struct snd_kcontrol *kcontrol, 210static int sgio2audio_source_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/oss/uart401.c b/sound/oss/uart401.c
index 279bc565ac7e..dae4d4344407 100644
--- a/sound/oss/uart401.c
+++ b/sound/oss/uart401.c
@@ -412,13 +412,10 @@ void unload_uart401(struct address_info *hw_config)
412 412
413 if (!devc->share_irq) 413 if (!devc->share_irq)
414 free_irq(devc->irq, devc); 414 free_irq(devc->irq, devc);
415 if (devc) 415 kfree(midi_devs[devc->my_dev]->converter);
416 { 416 kfree(midi_devs[devc->my_dev]);
417 kfree(midi_devs[devc->my_dev]->converter); 417 kfree(devc);
418 kfree(midi_devs[devc->my_dev]); 418
419 kfree(devc);
420 devc = NULL;
421 }
422 /* This kills midi_devs[x] */ 419 /* This kills midi_devs[x] */
423 sound_unload_mididev(hw_config->slots[4]); 420 sound_unload_mididev(hw_config->slots[4]);
424} 421}
diff --git a/sound/parisc/harmony.c b/sound/parisc/harmony.c
index 4b20be79c1dd..29604a239c44 100644
--- a/sound/parisc/harmony.c
+++ b/sound/parisc/harmony.c
@@ -776,15 +776,9 @@ static int
776snd_harmony_captureroute_info(struct snd_kcontrol *kc, 776snd_harmony_captureroute_info(struct snd_kcontrol *kc,
777 struct snd_ctl_elem_info *uinfo) 777 struct snd_ctl_elem_info *uinfo)
778{ 778{
779 static char *texts[2] = { "Line", "Mic" }; 779 static const char * const texts[2] = { "Line", "Mic" };
780 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 780
781 uinfo->count = 1; 781 return snd_ctl_enum_info(uinfo, 1, 2, texts);
782 uinfo->value.enumerated.items = 2;
783 if (uinfo->value.enumerated.item > 1)
784 uinfo->value.enumerated.item = 1;
785 strcpy(uinfo->value.enumerated.name,
786 texts[uinfo->value.enumerated.item]);
787 return 0;
788} 782}
789 783
790static int 784static int
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 14ad54b7928c..5ee2f17c287c 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -463,14 +463,8 @@ static int snd_ac97_info_enum_double(struct snd_kcontrol *kcontrol,
463{ 463{
464 struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value; 464 struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
465 465
466 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 466 return snd_ctl_enum_info(uinfo, e->shift_l == e->shift_r ? 1 : 2,
467 uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 467 e->mask, e->texts);
468 uinfo->value.enumerated.items = e->mask;
469
470 if (uinfo->value.enumerated.item > e->mask - 1)
471 uinfo->value.enumerated.item = e->mask - 1;
472 strcpy(uinfo->value.enumerated.name, e->texts[uinfo->value.enumerated.item]);
473 return 0;
474} 468}
475 469
476static int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol, 470static int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 991762215417..ceaac1c41906 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -33,7 +33,8 @@
33static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97, 33static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
34 const char *name); 34 const char *name);
35static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, 35static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
36 const unsigned int *tlv, const char **slaves); 36 const unsigned int *tlv,
37 const char * const *slaves);
37 38
38/* 39/*
39 * Chip specific initialization 40 * Chip specific initialization
@@ -81,22 +82,11 @@ static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsi
81/* 82/*
82 * shared line-in/mic controls 83 * shared line-in/mic controls
83 */ 84 */
84static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo,
85 const char **texts, unsigned int nums)
86{
87 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
88 uinfo->count = 1;
89 uinfo->value.enumerated.items = nums;
90 if (uinfo->value.enumerated.item > nums - 1)
91 uinfo->value.enumerated.item = nums - 1;
92 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
93 return 0;
94}
95
96static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 85static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
97{ 86{
98 static const char *texts[] = { "Shared", "Independent" }; 87 static const char * const texts[] = { "Shared", "Independent" };
99 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); 88
89 return snd_ctl_enum_info(uinfo, 1, 2, texts);
100} 90}
101 91
102static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 92static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -123,9 +113,9 @@ static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd
123 113
124static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 114static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
125{ 115{
126 static const char *texts[] = { "2ch", "4ch", "6ch", "8ch" }; 116 static const char * const texts[] = { "2ch", "4ch", "6ch", "8ch" };
127 return ac97_enum_text_info(kcontrol, uinfo, texts, 117
128 kcontrol->private_value); 118 return snd_ctl_enum_info(uinfo, 1, kcontrol->private_value, texts);
129} 119}
130 120
131static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 121static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -240,17 +230,11 @@ static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
240static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol, 230static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_info *uinfo) 231 struct snd_ctl_elem_info *uinfo)
242{ 232{
243 static char *texts[3] = { 233 static const char * const texts[3] = {
244 "Standard", "Small", "Smaller" 234 "Standard", "Small", "Smaller"
245 }; 235 };
246 236
247 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 237 return snd_ctl_enum_info(uinfo, 1, 3, texts);
248 uinfo->count = 1;
249 uinfo->value.enumerated.items = 3;
250 if (uinfo->value.enumerated.item > 2)
251 uinfo->value.enumerated.item = 2;
252 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
253 return 0;
254} 238}
255 239
256static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol, 240static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
@@ -293,15 +277,9 @@ static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
293static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol, 277static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
294 struct snd_ctl_elem_info *uinfo) 278 struct snd_ctl_elem_info *uinfo)
295{ 279{
296 static char *texts[2] = { "AC-Link", "A/D Converter" }; 280 static const char * const texts[2] = { "AC-Link", "A/D Converter" };
297 281
298 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 282 return snd_ctl_enum_info(uinfo, 1, 2, texts);
299 uinfo->count = 1;
300 uinfo->value.enumerated.items = 2;
301 if (uinfo->value.enumerated.item > 1)
302 uinfo->value.enumerated.item = 1;
303 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
304 return 0;
305} 283}
306 284
307static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol, 285static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
@@ -401,15 +379,9 @@ static int patch_yamaha_ymf743(struct snd_ac97 *ac97)
401 There is also a bit to mute S/PDIF output in a vendor-specific register. */ 379 There is also a bit to mute S/PDIF output in a vendor-specific register. */
402static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 380static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
403{ 381{
404 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" }; 382 static const char * const texts[3] = { "Disabled", "Pin 43", "Pin 48" };
405 383
406 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 384 return snd_ctl_enum_info(uinfo, 1, 3, texts);
407 uinfo->count = 1;
408 uinfo->value.enumerated.items = 3;
409 if (uinfo->value.enumerated.item > 2)
410 uinfo->value.enumerated.item = 2;
411 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
412 return 0;
413} 385}
414 386
415static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 387static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1103,16 +1075,11 @@ static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
1103 1075
1104static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1076static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1105{ 1077{
1106 static char *texts[5] = { "Input/Disabled", "Front Output", 1078 static const char * const texts[5] = {
1079 "Input/Disabled", "Front Output",
1107 "Rear Output", "Center/LFE Output", "Mixer Output" }; 1080 "Rear Output", "Center/LFE Output", "Mixer Output" };
1108 1081
1109 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1082 return snd_ctl_enum_info(uinfo, 1, 5, texts);
1110 uinfo->count = 1;
1111 uinfo->value.enumerated.items = 5;
1112 if (uinfo->value.enumerated.item > 4)
1113 uinfo->value.enumerated.item = 4;
1114 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1115 return 0;
1116} 1083}
1117 1084
1118static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1085static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1147,16 +1114,11 @@ static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, stru
1147 1114
1148static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1115static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1149{ 1116{
1150 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack", 1117 static const char * const texts[7] = {
1118 "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1151 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; 1119 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1152 1120
1153 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1121 return snd_ctl_enum_info(uinfo, 1, 7, texts);
1154 uinfo->count = 1;
1155 uinfo->value.enumerated.items = 7;
1156 if (uinfo->value.enumerated.item > 6)
1157 uinfo->value.enumerated.item = 6;
1158 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1159 return 0;
1160} 1122}
1161 1123
1162static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1124static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1181,15 +1143,11 @@ static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struc
1181 1143
1182static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1144static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1183{ 1145{
1184 static char *texts[3] = { "None", "Front Jack", "Rear Jack" }; 1146 static const char * const texts[3] = {
1147 "None", "Front Jack", "Rear Jack"
1148 };
1185 1149
1186 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1150 return snd_ctl_enum_info(uinfo, 1, 3, texts);
1187 uinfo->count = 1;
1188 uinfo->value.enumerated.items = 3;
1189 if (uinfo->value.enumerated.item > 2)
1190 uinfo->value.enumerated.item = 2;
1191 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1192 return 0;
1193} 1151}
1194 1152
1195static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1153static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1804,15 +1762,9 @@ static int patch_ad1886(struct snd_ac97 * ac97)
1804 1762
1805static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1763static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1806{ 1764{
1807 static char *texts[2] = { "AC-Link", "A/D Converter" }; 1765 static const char * const texts[2] = { "AC-Link", "A/D Converter" };
1808 1766
1809 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1767 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1810 uinfo->count = 1;
1811 uinfo->value.enumerated.items = 2;
1812 if (uinfo->value.enumerated.item > 1)
1813 uinfo->value.enumerated.item = 1;
1814 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1815 return 0;
1816} 1768}
1817 1769
1818static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1770static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1994,15 +1946,9 @@ static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd
1994 1946
1995static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1947static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1996{ 1948{
1997 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"}; 1949 static const char * const texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1998 1950
1999 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1951 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2000 uinfo->count = 1;
2001 uinfo->value.enumerated.items = 3;
2002 if (uinfo->value.enumerated.item > 2)
2003 uinfo->value.enumerated.item = 2;
2004 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2005 return 0;
2006} 1952}
2007 1953
2008static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1954static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2153,16 +2099,11 @@ static int patch_ad1980(struct snd_ac97 * ac97)
2153static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, 2099static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
2154 struct snd_ctl_elem_info *uinfo) 2100 struct snd_ctl_elem_info *uinfo)
2155{ 2101{
2156 static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"}; 2102 static const char * const texts[4] = {
2103 "High-Z", "3.7 V", "2.25 V", "0 V"
2104 };
2157 2105
2158 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2106 return snd_ctl_enum_info(uinfo, 1, 4, texts);
2159 uinfo->count = 1;
2160 uinfo->value.enumerated.items = 4;
2161 if (uinfo->value.enumerated.item > 3)
2162 uinfo->value.enumerated.item = 3;
2163 strcpy(uinfo->value.enumerated.name,
2164 texts[uinfo->value.enumerated.item]);
2165 return 0;
2166} 2107}
2167 2108
2168static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol, 2109static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
@@ -2756,20 +2697,18 @@ static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
2756 2697
2757static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2698static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2758{ 2699{
2759 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" }; 2700 static const char * const texts_655[3] = {
2760 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" }; 2701 "PCM", "Analog In", "IEC958 In"
2702 };
2703 static const char * const texts_658[4] = {
2704 "PCM", "Analog1 In", "Analog2 In", "IEC958 In"
2705 };
2761 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2706 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2762 2707
2763 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2708 if (ac97->spec.dev_flags)
2764 uinfo->count = 1; 2709 return snd_ctl_enum_info(uinfo, 1, 4, texts_658);
2765 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3; 2710 else
2766 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2711 return snd_ctl_enum_info(uinfo, 1, 3, texts_655);
2767 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2768 strcpy(uinfo->value.enumerated.name,
2769 ac97->spec.dev_flags ?
2770 texts_658[uinfo->value.enumerated.item] :
2771 texts_655[uinfo->value.enumerated.item]);
2772 return 0;
2773} 2712}
2774 2713
2775static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2714static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -3055,15 +2994,9 @@ static int patch_cm9738(struct snd_ac97 * ac97)
3055 2994
3056static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2995static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3057{ 2996{
3058 static char *texts[] = { "Analog", "Digital" }; 2997 static const char * const texts[] = { "Analog", "Digital" };
3059 2998
3060 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2999 return snd_ctl_enum_info(uinfo, 1, 2, texts);
3061 uinfo->count = 1;
3062 uinfo->value.enumerated.items = 2;
3063 if (uinfo->value.enumerated.item > 1)
3064 uinfo->value.enumerated.item = 1;
3065 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3066 return 0;
3067} 3000}
3068 3001
3069static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3002static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -3235,15 +3168,9 @@ static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
3235 3168
3236static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3169static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3237{ 3170{
3238 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" }; 3171 static const char * const texts[] = { "AC-Link", "ADC", "SPDIF-In" };
3239 3172
3240 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3173 return snd_ctl_enum_info(uinfo, 1, 3, texts);
3241 uinfo->count = 1;
3242 uinfo->value.enumerated.items = 3;
3243 if (uinfo->value.enumerated.item > 2)
3244 uinfo->value.enumerated.item = 2;
3245 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3246 return 0;
3247} 3174}
3248 3175
3249static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3176static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -3270,7 +3197,9 @@ static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd
3270 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); 3197 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
3271} 3198}
3272 3199
3273static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" }; 3200static const char * const cm9761_dac_clock[] = {
3201 "AC-Link", "SPDIF-In", "Both"
3202};
3274static const struct ac97_enum cm9761_dac_clock_enum = 3203static const struct ac97_enum cm9761_dac_clock_enum =
3275 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock); 3204 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
3276 3205
@@ -3384,7 +3313,9 @@ static int patch_cm9761(struct snd_ac97 *ac97)
3384#define AC97_CM9780_MULTI_CHAN 0x66 3313#define AC97_CM9780_MULTI_CHAN 0x66
3385#define AC97_CM9780_SPDIF 0x6c 3314#define AC97_CM9780_SPDIF 0x6c
3386 3315
3387static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" }; 3316static const char * const cm9780_ch_select[] = {
3317 "Front", "Side", "Center/LFE", "Rear"
3318};
3388static const struct ac97_enum cm9780_ch_select_enum = 3319static const struct ac97_enum cm9780_ch_select_enum =
3389 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select); 3320 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
3390static const struct snd_kcontrol_new cm9780_controls[] = { 3321static const struct snd_kcontrol_new cm9780_controls[] = {
@@ -3430,7 +3361,7 @@ AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
3430AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0), 3361AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
3431}; 3362};
3432 3363
3433static const char *slave_vols_vt1616[] = { 3364static const char * const slave_vols_vt1616[] = {
3434 "Front Playback Volume", 3365 "Front Playback Volume",
3435 "Surround Playback Volume", 3366 "Surround Playback Volume",
3436 "Center Playback Volume", 3367 "Center Playback Volume",
@@ -3438,7 +3369,7 @@ static const char *slave_vols_vt1616[] = {
3438 NULL 3369 NULL
3439}; 3370};
3440 3371
3441static const char *slave_sws_vt1616[] = { 3372static const char * const slave_sws_vt1616[] = {
3442 "Front Playback Switch", 3373 "Front Playback Switch",
3443 "Surround Playback Switch", 3374 "Surround Playback Switch",
3444 "Center Playback Switch", 3375 "Center Playback Switch",
@@ -3459,10 +3390,11 @@ static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
3459 3390
3460/* create a virtual master control and add slaves */ 3391/* create a virtual master control and add slaves */
3461static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, 3392static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
3462 const unsigned int *tlv, const char **slaves) 3393 const unsigned int *tlv,
3394 const char * const *slaves)
3463{ 3395{
3464 struct snd_kcontrol *kctl; 3396 struct snd_kcontrol *kctl;
3465 const char **s; 3397 const char * const *s;
3466 int err; 3398 int err;
3467 3399
3468 kctl = snd_ctl_make_virtual_master(name, tlv); 3400 kctl = snd_ctl_make_virtual_master(name, tlv);
@@ -3552,11 +3484,12 @@ static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
3552 * is SM51EN *AND* it's Bit14, not Bit15 so the table is very 3484 * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
3553 * counter-intuitive */ 3485 * counter-intuitive */
3554 3486
3555 static const char* texts[] = { "LineIn Mic1", "LineIn Mic1 Mic3", 3487 static const char * const texts[] = {"LineIn Mic1", "LineIn Mic1 Mic3",
3556 "Surr LFE/C Mic3", "LineIn LFE/C Mic3", 3488 "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
3557 "LineIn Mic2", "LineIn Mic2 Mic1", 3489 "LineIn Mic2", "LineIn Mic2 Mic1",
3558 "Surr LFE Mic1", "Surr LFE Mic1 Mic2"}; 3490 "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
3559 return ac97_enum_text_info(kcontrol, uinfo, texts, 8); 3491
3492 return snd_ctl_enum_info(uinfo, 1, 8, texts);
3560} 3493}
3561 3494
3562static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol, 3495static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
@@ -3685,7 +3618,7 @@ static int patch_vt1617a(struct snd_ac97 * ac97)
3685struct vt1618_uaj_item { 3618struct vt1618_uaj_item {
3686 unsigned short mask; 3619 unsigned short mask;
3687 unsigned short shift; 3620 unsigned short shift;
3688 const char *items[4]; 3621 const char * const items[4];
3689}; 3622};
3690 3623
3691/* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */ 3624/* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */
@@ -3720,9 +3653,8 @@ static struct vt1618_uaj_item vt1618_uaj[3] = {
3720static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol, 3653static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol,
3721 struct snd_ctl_elem_info *uinfo) 3654 struct snd_ctl_elem_info *uinfo)
3722{ 3655{
3723 return ac97_enum_text_info(kcontrol, uinfo, 3656 return snd_ctl_enum_info(uinfo, 1, 4,
3724 vt1618_uaj[kcontrol->private_value].items, 3657 vt1618_uaj[kcontrol->private_value].items);
3725 4);
3726} 3658}
3727 3659
3728/* All of the vt1618 Universal Audio Jack twiddlers are on 3660/* All of the vt1618 Universal Audio Jack twiddlers are on
@@ -3767,9 +3699,9 @@ static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol,
3767static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol, 3699static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol,
3768 struct snd_ctl_elem_info *uinfo) 3700 struct snd_ctl_elem_info *uinfo)
3769{ 3701{
3770 static const char *txt_aux[] = {"Aux In", "Back Surr Out"}; 3702 static const char * const txt_aux[] = {"Aux In", "Back Surr Out"};
3771 3703
3772 return ac97_enum_text_info(kcontrol, uinfo, txt_aux, 2); 3704 return snd_ctl_enum_info(uinfo, 1, 2, txt_aux);
3773} 3705}
3774 3706
3775static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol, 3707static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/ac97/ac97_patch.h b/sound/pci/ac97/ac97_patch.h
index 47bf8dfe8276..d1ce151fe722 100644
--- a/sound/pci/ac97/ac97_patch.h
+++ b/sound/pci/ac97/ac97_patch.h
@@ -49,7 +49,7 @@ struct ac97_enum {
49 unsigned char shift_l; 49 unsigned char shift_l;
50 unsigned char shift_r; 50 unsigned char shift_r;
51 unsigned short mask; 51 unsigned short mask;
52 const char **texts; 52 const char * const *texts;
53}; 53};
54 54
55#define AC97_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \ 55#define AC97_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
index 5017176bfaa1..e9273fb2a505 100644
--- a/sound/pci/asihpi/asihpi.c
+++ b/sound/pci/asihpi/asihpi.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Asihpi soundcard 2 * Asihpi soundcard
3 * Copyright (c) by AudioScience Inc <alsa@audioscience.com> 3 * Copyright (c) by AudioScience Inc <support@audioscience.com>
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as 6 * it under the terms of version 2 of the GNU General Public License as
@@ -28,7 +28,6 @@
28#include "hpioctl.h" 28#include "hpioctl.h"
29#include "hpicmn.h" 29#include "hpicmn.h"
30 30
31
32#include <linux/pci.h> 31#include <linux/pci.h>
33#include <linux/init.h> 32#include <linux/init.h>
34#include <linux/jiffies.h> 33#include <linux/jiffies.h>
@@ -47,7 +46,7 @@
47 46
48MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
49MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>"); 48MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
50MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx " 49MODULE_DESCRIPTION("AudioScience ALSA ASI5xxx ASI6xxx ASI87xx ASI89xx "
51 HPI_VER_STRING); 50 HPI_VER_STRING);
52 51
53#if defined CONFIG_SND_DEBUG_VERBOSE 52#if defined CONFIG_SND_DEBUG_VERBOSE
@@ -87,11 +86,11 @@ MODULE_PARM_DESC(enable_hpi_hwdep,
87#ifdef KERNEL_ALSA_BUILD 86#ifdef KERNEL_ALSA_BUILD
88static char *build_info = "Built using headers from kernel source"; 87static char *build_info = "Built using headers from kernel source";
89module_param(build_info, charp, S_IRUGO); 88module_param(build_info, charp, S_IRUGO);
90MODULE_PARM_DESC(build_info, "built using headers from kernel source"); 89MODULE_PARM_DESC(build_info, "Built using headers from kernel source");
91#else 90#else
92static char *build_info = "Built within ALSA source"; 91static char *build_info = "Built within ALSA source";
93module_param(build_info, charp, S_IRUGO); 92module_param(build_info, charp, S_IRUGO);
94MODULE_PARM_DESC(build_info, "built within ALSA source"); 93MODULE_PARM_DESC(build_info, "Built within ALSA source");
95#endif 94#endif
96 95
97/* set to 1 to dump every control from adapter to log */ 96/* set to 1 to dump every control from adapter to log */
@@ -110,7 +109,7 @@ static int adapter_fs = DEFAULT_SAMPLERATE;
110struct clk_source { 109struct clk_source {
111 int source; 110 int source;
112 int index; 111 int index;
113 char *name; 112 const char *name;
114}; 113};
115 114
116struct clk_cache { 115struct clk_cache {
@@ -125,6 +124,16 @@ struct snd_card_asihpi {
125 struct pci_dev *pci; 124 struct pci_dev *pci;
126 struct hpi_adapter *hpi; 125 struct hpi_adapter *hpi;
127 126
127 /* In low latency mode there is only one stream, a pointer to its
128 * private data is stored here on trigger and cleared on stop.
129 * The interrupt handler uses it as a parameter when calling
130 * snd_card_asihpi_timer_function().
131 */
132 struct snd_card_asihpi_pcm *llmode_streampriv;
133 struct tasklet_struct t;
134 void (*pcm_start)(struct snd_pcm_substream *substream);
135 void (*pcm_stop)(struct snd_pcm_substream *substream);
136
128 u32 h_mixer; 137 u32 h_mixer;
129 struct clk_cache cc; 138 struct clk_cache cc;
130 139
@@ -289,21 +298,17 @@ static void print_hwparams(struct snd_pcm_substream *substream,
289{ 298{
290 char name[16]; 299 char name[16];
291 snd_pcm_debug_name(substream, name, sizeof(name)); 300 snd_pcm_debug_name(substream, name, sizeof(name));
292 snd_printd("%s HWPARAMS\n", name); 301 snd_printdd("%s HWPARAMS\n", name);
293 snd_printd(" samplerate %d Hz\n", params_rate(p)); 302 snd_printdd(" samplerate=%dHz channels=%d format=%d subformat=%d\n",
294 snd_printd(" channels %d\n", params_channels(p)); 303 params_rate(p), params_channels(p),
295 snd_printd(" format %d\n", params_format(p)); 304 params_format(p), params_subformat(p));
296 snd_printd(" subformat %d\n", params_subformat(p)); 305 snd_printdd(" buffer=%dB period=%dB period_size=%dB periods=%d\n",
297 snd_printd(" buffer %d B\n", params_buffer_bytes(p)); 306 params_buffer_bytes(p), params_period_bytes(p),
298 snd_printd(" period %d B\n", params_period_bytes(p)); 307 params_period_size(p), params_periods(p));
299 snd_printd(" access %d\n", params_access(p)); 308 snd_printdd(" buffer_size=%d access=%d data_rate=%dB/s\n",
300 snd_printd(" period_size %d\n", params_period_size(p)); 309 params_buffer_size(p), params_access(p),
301 snd_printd(" periods %d\n", params_periods(p)); 310 params_rate(p) * params_channels(p) *
302 snd_printd(" buffer_size %d\n", params_buffer_size(p));
303 snd_printd(" %d B/s\n", params_rate(p) *
304 params_channels(p) *
305 snd_pcm_format_width(params_format(p)) / 8); 311 snd_pcm_format_width(params_format(p)) / 8);
306
307} 312}
308 313
309static snd_pcm_format_t hpi_to_alsa_formats[] = { 314static snd_pcm_format_t hpi_to_alsa_formats[] = {
@@ -375,7 +380,7 @@ static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,
375 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0, 380 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
376 HPI_CONTROL_SAMPLECLOCK, &h_control); 381 HPI_CONTROL_SAMPLECLOCK, &h_control);
377 if (err) { 382 if (err) {
378 snd_printk(KERN_ERR 383 dev_err(&asihpi->pci->dev,
379 "No local sampleclock, err %d\n", err); 384 "No local sampleclock, err %d\n", err);
380 } 385 }
381 386
@@ -481,7 +486,7 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
481 params_buffer_bytes(params), runtime->dma_addr); 486 params_buffer_bytes(params), runtime->dma_addr);
482 if (err == 0) { 487 if (err == 0) {
483 snd_printdd( 488 snd_printdd(
484 "stream_host_buffer_attach succeeded %u %lu\n", 489 "stream_host_buffer_attach success %u %lu\n",
485 params_buffer_bytes(params), 490 params_buffer_bytes(params),
486 (unsigned long)runtime->dma_addr); 491 (unsigned long)runtime->dma_addr);
487 } else { 492 } else {
@@ -491,12 +496,7 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
491 } 496 }
492 497
493 err = hpi_stream_get_info_ex(dpcm->h_stream, NULL, 498 err = hpi_stream_get_info_ex(dpcm->h_stream, NULL,
494 &dpcm->hpi_buffer_attached, 499 &dpcm->hpi_buffer_attached, NULL, NULL, NULL);
495 NULL, NULL, NULL);
496
497 snd_printdd("stream_host_buffer_attach status 0x%x\n",
498 dpcm->hpi_buffer_attached);
499
500 } 500 }
501 bytes_per_sec = params_rate(params) * params_channels(params); 501 bytes_per_sec = params_rate(params) * params_channels(params);
502 width = snd_pcm_format_width(params_format(params)); 502 width = snd_pcm_format_width(params_format(params));
@@ -538,7 +538,7 @@ static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
538 int expiry; 538 int expiry;
539 539
540 expiry = HZ / 200; 540 expiry = HZ / 200;
541 /*? (dpcm->period_bytes * HZ / dpcm->bytes_per_sec); */ 541
542 expiry = max(expiry, 1); /* don't let it be zero! */ 542 expiry = max(expiry, 1); /* don't let it be zero! */
543 dpcm->timer.expires = jiffies + expiry; 543 dpcm->timer.expires = jiffies + expiry;
544 dpcm->respawn_timer = 1; 544 dpcm->respawn_timer = 1;
@@ -554,6 +554,48 @@ static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
554 del_timer(&dpcm->timer); 554 del_timer(&dpcm->timer);
555} 555}
556 556
557static void snd_card_asihpi_pcm_int_start(struct snd_pcm_substream *substream)
558{
559 struct snd_card_asihpi_pcm *dpcm;
560 struct snd_card_asihpi *card;
561
562 BUG_ON(!substream);
563
564 dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data;
565 card = snd_pcm_substream_chip(substream);
566
567 BUG_ON(in_interrupt());
568 tasklet_disable(&card->t);
569 card->llmode_streampriv = dpcm;
570 tasklet_enable(&card->t);
571
572 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
573 HPI_ADAPTER_PROPERTY_IRQ_RATE,
574 card->update_interval_frames, 0));
575}
576
577static void snd_card_asihpi_pcm_int_stop(struct snd_pcm_substream *substream)
578{
579 struct snd_card_asihpi_pcm *dpcm;
580 struct snd_card_asihpi *card;
581
582 BUG_ON(!substream);
583
584 dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data;
585 card = snd_pcm_substream_chip(substream);
586
587 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
588 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
589
590 if (in_interrupt())
591 card->llmode_streampriv = NULL;
592 else {
593 tasklet_disable(&card->t);
594 card->llmode_streampriv = NULL;
595 tasklet_enable(&card->t);
596 }
597}
598
557static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream, 599static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
558 int cmd) 600 int cmd)
559{ 601{
@@ -564,10 +606,10 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
564 char name[16]; 606 char name[16];
565 607
566 snd_pcm_debug_name(substream, name, sizeof(name)); 608 snd_pcm_debug_name(substream, name, sizeof(name));
567 snd_printdd("%s trigger\n", name);
568 609
569 switch (cmd) { 610 switch (cmd) {
570 case SNDRV_PCM_TRIGGER_START: 611 case SNDRV_PCM_TRIGGER_START:
612 snd_printdd("%s trigger start\n", name);
571 snd_pcm_group_for_each_entry(s, substream) { 613 snd_pcm_group_for_each_entry(s, substream) {
572 struct snd_pcm_runtime *runtime = s->runtime; 614 struct snd_pcm_runtime *runtime = s->runtime;
573 struct snd_card_asihpi_pcm *ds = runtime->private_data; 615 struct snd_card_asihpi_pcm *ds = runtime->private_data;
@@ -588,7 +630,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
588 * data?? 630 * data??
589 */ 631 */
590 unsigned int preload = ds->period_bytes * 1; 632 unsigned int preload = ds->period_bytes * 1;
591 snd_printddd("%d preload x%x\n", s->number, preload); 633 snd_printddd("%d preload %d\n", s->number, preload);
592 hpi_handle_error(hpi_outstream_write_buf( 634 hpi_handle_error(hpi_outstream_write_buf(
593 ds->h_stream, 635 ds->h_stream,
594 &runtime->dma_area[0], 636 &runtime->dma_area[0],
@@ -611,16 +653,16 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
611 } else 653 } else
612 break; 654 break;
613 } 655 }
614 snd_printdd("start\n");
615 /* start the master stream */ 656 /* start the master stream */
616 snd_card_asihpi_pcm_timer_start(substream); 657 card->pcm_start(substream);
617 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) || 658 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ||
618 !card->can_dma) 659 !card->can_dma)
619 hpi_handle_error(hpi_stream_start(dpcm->h_stream)); 660 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
620 break; 661 break;
621 662
622 case SNDRV_PCM_TRIGGER_STOP: 663 case SNDRV_PCM_TRIGGER_STOP:
623 snd_card_asihpi_pcm_timer_stop(substream); 664 snd_printdd("%s trigger stop\n", name);
665 card->pcm_stop(substream);
624 snd_pcm_group_for_each_entry(s, substream) { 666 snd_pcm_group_for_each_entry(s, substream) {
625 if (snd_pcm_substream_chip(s) != card) 667 if (snd_pcm_substream_chip(s) != card)
626 continue; 668 continue;
@@ -638,7 +680,6 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
638 } else 680 } else
639 break; 681 break;
640 } 682 }
641 snd_printdd("stop\n");
642 683
643 /* _prepare and _hwparams reset the stream */ 684 /* _prepare and _hwparams reset the stream */
644 hpi_handle_error(hpi_stream_stop(dpcm->h_stream)); 685 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
@@ -651,13 +692,13 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
651 break; 692 break;
652 693
653 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 694 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
654 snd_printdd("pause release\n"); 695 snd_printdd("%s trigger pause release\n", name);
696 card->pcm_start(substream);
655 hpi_handle_error(hpi_stream_start(dpcm->h_stream)); 697 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
656 snd_card_asihpi_pcm_timer_start(substream);
657 break; 698 break;
658 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 699 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
659 snd_printdd("pause\n"); 700 snd_printdd("%s trigger pause push\n", name);
660 snd_card_asihpi_pcm_timer_stop(substream); 701 card->pcm_stop(substream);
661 hpi_handle_error(hpi_stream_stop(dpcm->h_stream)); 702 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
662 break; 703 break;
663 default: 704 default:
@@ -729,9 +770,8 @@ static void snd_card_asihpi_timer_function(unsigned long data)
729 u32 buffer_size, bytes_avail, samples_played, on_card_bytes; 770 u32 buffer_size, bytes_avail, samples_played, on_card_bytes;
730 char name[16]; 771 char name[16];
731 772
732 snd_pcm_debug_name(substream, name, sizeof(name));
733 773
734 snd_printdd("%s snd_card_asihpi_timer_function\n", name); 774 snd_pcm_debug_name(substream, name, sizeof(name));
735 775
736 /* find minimum newdata and buffer pos in group */ 776 /* find minimum newdata and buffer pos in group */
737 snd_pcm_group_for_each_entry(s, substream) { 777 snd_pcm_group_for_each_entry(s, substream) {
@@ -769,10 +809,7 @@ static void snd_card_asihpi_timer_function(unsigned long data)
769 s->number); 809 s->number);
770 ds->drained_count++; 810 ds->drained_count++;
771 if (ds->drained_count > 20) { 811 if (ds->drained_count > 20) {
772 unsigned long flags; 812 snd_pcm_stop_xrun(s);
773 snd_pcm_stream_lock_irqsave(s, flags);
774 snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN);
775 snd_pcm_stream_unlock_irqrestore(s, flags);
776 continue; 813 continue;
777 } 814 }
778 } else { 815 } else {
@@ -794,19 +831,21 @@ static void snd_card_asihpi_timer_function(unsigned long data)
794 newdata); 831 newdata);
795 } 832 }
796 833
797 snd_printdd("hw_ptr 0x%04lX, appl_ptr 0x%04lX\n", 834 snd_printddd(
835 "timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n",
836 name, s->number, state,
837 ds->pcm_buf_elapsed_dma_ofs,
838 ds->pcm_buf_host_rw_ofs,
839 pcm_buf_dma_ofs,
840 (int)bytes_avail,
841
842 (int)on_card_bytes,
843 buffer_size-bytes_avail,
798 (unsigned long)frames_to_bytes(runtime, 844 (unsigned long)frames_to_bytes(runtime,
799 runtime->status->hw_ptr), 845 runtime->status->hw_ptr),
800 (unsigned long)frames_to_bytes(runtime, 846 (unsigned long)frames_to_bytes(runtime,
801 runtime->control->appl_ptr)); 847 runtime->control->appl_ptr)
802 848 );
803 snd_printdd("%d S=%d, "
804 "rw=0x%04X, dma=0x%04X, left=0x%04X, "
805 "aux=0x%04X space=0x%04X\n",
806 s->number, state,
807 ds->pcm_buf_host_rw_ofs, pcm_buf_dma_ofs,
808 (int)bytes_avail,
809 (int)on_card_bytes, buffer_size-bytes_avail);
810 loops++; 849 loops++;
811 } 850 }
812 pcm_buf_dma_ofs = min_buf_pos; 851 pcm_buf_dma_ofs = min_buf_pos;
@@ -824,16 +863,18 @@ static void snd_card_asihpi_timer_function(unsigned long data)
824 863
825 next_jiffies = max(next_jiffies, 1U); 864 next_jiffies = max(next_jiffies, 1U);
826 dpcm->timer.expires = jiffies + next_jiffies; 865 dpcm->timer.expires = jiffies + next_jiffies;
827 snd_printdd("jif %d buf pos 0x%04X newdata 0x%04X xfer 0x%04X\n", 866 snd_printddd("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n",
828 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount); 867 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
829 868
830 snd_pcm_group_for_each_entry(s, substream) { 869 snd_pcm_group_for_each_entry(s, substream) {
831 struct snd_card_asihpi_pcm *ds = s->runtime->private_data; 870 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
871 runtime = s->runtime;
832 872
833 /* don't link Cap and Play */ 873 /* don't link Cap and Play */
834 if (substream->stream != s->stream) 874 if (substream->stream != s->stream)
835 continue; 875 continue;
836 876
877 /* Store dma offset for use by pointer callback */
837 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs; 878 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs;
838 879
839 if (xfercount && 880 if (xfercount &&
@@ -856,7 +897,7 @@ static void snd_card_asihpi_timer_function(unsigned long data)
856 } 897 }
857 898
858 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { 899 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
859 snd_printddd("P%d write1 0x%04X 0x%04X\n", 900 snd_printddd("write1, P=%d, xfer=%d, buf_ofs=%d\n",
860 s->number, xfer1, buf_ofs); 901 s->number, xfer1, buf_ofs);
861 hpi_handle_error( 902 hpi_handle_error(
862 hpi_outstream_write_buf( 903 hpi_outstream_write_buf(
@@ -866,7 +907,7 @@ static void snd_card_asihpi_timer_function(unsigned long data)
866 if (xfer2) { 907 if (xfer2) {
867 pd = s->runtime->dma_area; 908 pd = s->runtime->dma_area;
868 909
869 snd_printddd("P%d write2 0x%04X 0x%04X\n", 910 snd_printddd("write2, P=%d, xfer=%d, buf_ofs=%d\n",
870 s->number, 911 s->number,
871 xfercount - xfer1, buf_ofs); 912 xfercount - xfer1, buf_ofs);
872 hpi_handle_error( 913 hpi_handle_error(
@@ -876,7 +917,7 @@ static void snd_card_asihpi_timer_function(unsigned long data)
876 &ds->format)); 917 &ds->format));
877 } 918 }
878 } else { 919 } else {
879 snd_printddd("C%d read1 0x%04x\n", 920 snd_printddd("read1, C=%d, xfer=%d\n",
880 s->number, xfer1); 921 s->number, xfer1);
881 hpi_handle_error( 922 hpi_handle_error(
882 hpi_instream_read_buf( 923 hpi_instream_read_buf(
@@ -884,7 +925,7 @@ static void snd_card_asihpi_timer_function(unsigned long data)
884 pd, xfer1)); 925 pd, xfer1));
885 if (xfer2) { 926 if (xfer2) {
886 pd = s->runtime->dma_area; 927 pd = s->runtime->dma_area;
887 snd_printddd("C%d read2 0x%04x\n", 928 snd_printddd("read2, C=%d, xfer=%d\n",
888 s->number, xfer2); 929 s->number, xfer2);
889 hpi_handle_error( 930 hpi_handle_error(
890 hpi_instream_read_buf( 931 hpi_instream_read_buf(
@@ -892,16 +933,38 @@ static void snd_card_asihpi_timer_function(unsigned long data)
892 pd, xfer2)); 933 pd, xfer2));
893 } 934 }
894 } 935 }
936 /* ? host_rw_ofs always ahead of elapsed_dma_ofs by preload size? */
895 ds->pcm_buf_host_rw_ofs += xfercount; 937 ds->pcm_buf_host_rw_ofs += xfercount;
896 ds->pcm_buf_elapsed_dma_ofs += xfercount; 938 ds->pcm_buf_elapsed_dma_ofs += xfercount;
897 snd_pcm_period_elapsed(s); 939 snd_pcm_period_elapsed(s);
898 } 940 }
899 } 941 }
900 942
901 if (dpcm->respawn_timer) 943 if (!card->hpi->interrupt_mode && dpcm->respawn_timer)
902 add_timer(&dpcm->timer); 944 add_timer(&dpcm->timer);
903} 945}
904 946
947static void snd_card_asihpi_int_task(unsigned long data)
948{
949 struct hpi_adapter *a = (struct hpi_adapter *)data;
950 struct snd_card_asihpi *asihpi;
951
952 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
953 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
954 if (asihpi->llmode_streampriv)
955 snd_card_asihpi_timer_function(
956 (unsigned long)asihpi->llmode_streampriv);
957}
958
959static void snd_card_asihpi_isr(struct hpi_adapter *a)
960{
961 struct snd_card_asihpi *asihpi;
962
963 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
964 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
965 tasklet_schedule(&asihpi->t);
966}
967
905/***************************** PLAYBACK OPS ****************/ 968/***************************** PLAYBACK OPS ****************/
906static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream, 969static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream,
907 unsigned int cmd, void *arg) 970 unsigned int cmd, void *arg)
@@ -937,7 +1000,7 @@ snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
937 snd_pcm_debug_name(substream, name, sizeof(name)); 1000 snd_pcm_debug_name(substream, name, sizeof(name));
938 1001
939 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes); 1002 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
940 snd_printddd("%s pointer = 0x%04lx\n", name, (unsigned long)ptr); 1003 snd_printddd("%s, pointer=%ld\n", name, (unsigned long)ptr);
941 return ptr; 1004 return ptr;
942} 1005}
943 1006
@@ -1009,13 +1072,22 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
1009 runtime->private_free = snd_card_asihpi_runtime_free; 1072 runtime->private_free = snd_card_asihpi_runtime_free;
1010 1073
1011 memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback)); 1074 memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback));
1012 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX; 1075 if (!card->hpi->interrupt_mode) {
1013 snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN; 1076 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1014 /*?snd_card_asihpi_playback.period_bytes_min = 1077 snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN;
1015 card->out_max_chans * 4096; */ 1078 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1016 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN; 1079 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1017 snd_card_asihpi_playback.periods_min = PERIODS_MIN; 1080 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1018 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN; 1081 } else {
1082 size_t pbmin = card->update_interval_frames *
1083 card->out_max_chans;
1084 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1085 snd_card_asihpi_playback.period_bytes_min = pbmin;
1086 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1087 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1088 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / pbmin;
1089 }
1090
1019 /* snd_card_asihpi_playback.fifo_size = 0; */ 1091 /* snd_card_asihpi_playback.fifo_size = 0; */
1020 snd_card_asihpi_playback.channels_max = card->out_max_chans; 1092 snd_card_asihpi_playback.channels_max = card->out_max_chans;
1021 snd_card_asihpi_playback.channels_min = card->out_min_chans; 1093 snd_card_asihpi_playback.channels_min = card->out_min_chans;
@@ -1050,7 +1122,7 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
1050 card->update_interval_frames); 1122 card->update_interval_frames);
1051 1123
1052 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 1124 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1053 card->update_interval_frames * 2, UINT_MAX); 1125 card->update_interval_frames, UINT_MAX);
1054 1126
1055 snd_printdd("playback open\n"); 1127 snd_printdd("playback open\n");
1056 1128
@@ -1085,9 +1157,10 @@ snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
1085{ 1157{
1086 struct snd_pcm_runtime *runtime = substream->runtime; 1158 struct snd_pcm_runtime *runtime = substream->runtime;
1087 struct snd_card_asihpi_pcm *dpcm = runtime->private_data; 1159 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1160 char name[16];
1161 snd_pcm_debug_name(substream, name, sizeof(name));
1088 1162
1089 snd_printddd("capture pointer %d=%d\n", 1163 snd_printddd("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs);
1090 substream->number, dpcm->pcm_buf_dma_ofs);
1091 /* NOTE Unlike playback can't use actual samples_played 1164 /* NOTE Unlike playback can't use actual samples_played
1092 for the capture position, because those samples aren't yet in 1165 for the capture position, because those samples aren't yet in
1093 the local buffer available for reading. 1166 the local buffer available for reading.
@@ -1115,8 +1188,6 @@ static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
1115 return 0; 1188 return 0;
1116} 1189}
1117 1190
1118
1119
1120static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi, 1191static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi,
1121 u32 h_stream) 1192 u32 h_stream)
1122{ 1193{
@@ -1183,11 +1254,21 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1183 runtime->private_free = snd_card_asihpi_runtime_free; 1254 runtime->private_free = snd_card_asihpi_runtime_free;
1184 1255
1185 memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture)); 1256 memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture));
1186 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX; 1257 if (!card->hpi->interrupt_mode) {
1187 snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN; 1258 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1188 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN; 1259 snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN;
1189 snd_card_asihpi_capture.periods_min = PERIODS_MIN; 1260 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1190 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN; 1261 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1262 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1263 } else {
1264 size_t pbmin = card->update_interval_frames *
1265 card->out_max_chans;
1266 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1267 snd_card_asihpi_capture.period_bytes_min = pbmin;
1268 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1269 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1270 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / pbmin;
1271 }
1191 /* snd_card_asihpi_capture.fifo_size = 0; */ 1272 /* snd_card_asihpi_capture.fifo_size = 0; */
1192 snd_card_asihpi_capture.channels_max = card->in_max_chans; 1273 snd_card_asihpi_capture.channels_max = card->in_max_chans;
1193 snd_card_asihpi_capture.channels_min = card->in_min_chans; 1274 snd_card_asihpi_capture.channels_min = card->in_min_chans;
@@ -1212,7 +1293,7 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1212 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 1293 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1213 card->update_interval_frames); 1294 card->update_interval_frames);
1214 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 1295 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1215 card->update_interval_frames * 2, UINT_MAX); 1296 card->update_interval_frames, UINT_MAX);
1216 1297
1217 snd_pcm_set_sync(substream); 1298 snd_pcm_set_sync(substream);
1218 1299
@@ -1296,8 +1377,9 @@ static const char * const asihpi_tuner_band_names[] = {
1296 "TV PAL I", 1377 "TV PAL I",
1297 "TV PAL DK", 1378 "TV PAL DK",
1298 "TV SECAM", 1379 "TV SECAM",
1380 "TV DAB",
1299}; 1381};
1300 1382/* Number of strings must match the enumerations for HPI_TUNER_BAND in hpi.h */
1301compile_time_assert( 1383compile_time_assert(
1302 (ARRAY_SIZE(asihpi_tuner_band_names) == 1384 (ARRAY_SIZE(asihpi_tuner_band_names) ==
1303 (HPI_TUNER_BAND_LAST+1)), 1385 (HPI_TUNER_BAND_LAST+1)),
@@ -1317,9 +1399,11 @@ static const char * const asihpi_src_names[] = {
1317 "Analog", 1399 "Analog",
1318 "Adapter", 1400 "Adapter",
1319 "RTP", 1401 "RTP",
1320 "Internal" 1402 "Internal",
1403 "AVB",
1404 "BLU-Link"
1321}; 1405};
1322 1406/* Number of strings must match the enumerations for HPI_SOURCENODES in hpi.h */
1323compile_time_assert( 1407compile_time_assert(
1324 (ARRAY_SIZE(asihpi_src_names) == 1408 (ARRAY_SIZE(asihpi_src_names) ==
1325 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)), 1409 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),
@@ -1335,8 +1419,11 @@ static const char * const asihpi_dst_names[] = {
1335 "Net", 1419 "Net",
1336 "Analog", 1420 "Analog",
1337 "RTP", 1421 "RTP",
1422 "AVB",
1423 "Internal",
1424 "BLU-Link"
1338}; 1425};
1339 1426/* Number of strings must match the enumerations for HPI_DESTNODES in hpi.h */
1340compile_time_assert( 1427compile_time_assert(
1341 (ARRAY_SIZE(asihpi_dst_names) == 1428 (ARRAY_SIZE(asihpi_dst_names) ==
1342 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)), 1429 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)),
@@ -1351,7 +1438,7 @@ static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
1351 if (err < 0) 1438 if (err < 0)
1352 return err; 1439 return err;
1353 else if (mixer_dump) 1440 else if (mixer_dump)
1354 snd_printk(KERN_INFO "added %s(%d)\n", ctl->name, ctl->index); 1441 dev_info(&asihpi->pci->dev, "added %s(%d)\n", ctl->name, ctl->index);
1355 1442
1356 return 0; 1443 return 0;
1357} 1444}
@@ -1625,18 +1712,7 @@ static const char * const asihpi_aesebu_format_names[] = {
1625static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol, 1712static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
1626 struct snd_ctl_elem_info *uinfo) 1713 struct snd_ctl_elem_info *uinfo)
1627{ 1714{
1628 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1715 return snd_ctl_enum_info(uinfo, 1, 3, asihpi_aesebu_format_names);
1629 uinfo->count = 1;
1630 uinfo->value.enumerated.items = 3;
1631
1632 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1633 uinfo->value.enumerated.item =
1634 uinfo->value.enumerated.items - 1;
1635
1636 strcpy(uinfo->value.enumerated.name,
1637 asihpi_aesebu_format_names[uinfo->value.enumerated.item]);
1638
1639 return 0;
1640} 1716}
1641 1717
1642static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol, 1718static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,
@@ -1863,22 +1939,7 @@ static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol,
1863 if (num_bands < 0) 1939 if (num_bands < 0)
1864 return num_bands; 1940 return num_bands;
1865 1941
1866 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1942 return snd_ctl_enum_info(uinfo, 1, num_bands, asihpi_tuner_band_names);
1867 uinfo->count = 1;
1868 uinfo->value.enumerated.items = num_bands;
1869
1870 if (num_bands > 0) {
1871 if (uinfo->value.enumerated.item >=
1872 uinfo->value.enumerated.items)
1873 uinfo->value.enumerated.item =
1874 uinfo->value.enumerated.items - 1;
1875
1876 strcpy(uinfo->value.enumerated.name,
1877 asihpi_tuner_band_names[
1878 tuner_bands[uinfo->value.enumerated.item]]);
1879
1880 }
1881 return 0;
1882} 1943}
1883 1944
1884static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol, 1945static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
@@ -2253,7 +2314,7 @@ static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2253 u32 h_control = kcontrol->private_value; 2314 u32 h_control = kcontrol->private_value;
2254 u16 mode; 2315 u16 mode;
2255 int i; 2316 int i;
2256 u16 mode_map[6]; 2317 const char *mapped_names[6];
2257 int valid_modes = 0; 2318 int valid_modes = 0;
2258 2319
2259 /* HPI channel mode values can be from 1 to 6 2320 /* HPI channel mode values can be from 1 to 6
@@ -2262,24 +2323,14 @@ static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2262 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++) 2323 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
2263 if (!hpi_channel_mode_query_mode( 2324 if (!hpi_channel_mode_query_mode(
2264 h_control, i, &mode)) { 2325 h_control, i, &mode)) {
2265 mode_map[valid_modes] = mode; 2326 mapped_names[valid_modes] = mode_names[mode];
2266 valid_modes++; 2327 valid_modes++;
2267 } 2328 }
2268 2329
2269 if (!valid_modes) 2330 if (!valid_modes)
2270 return -EINVAL; 2331 return -EINVAL;
2271 2332
2272 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2333 return snd_ctl_enum_info(uinfo, 1, valid_modes, mapped_names);
2273 uinfo->count = 1;
2274 uinfo->value.enumerated.items = valid_modes;
2275
2276 if (uinfo->value.enumerated.item >= valid_modes)
2277 uinfo->value.enumerated.item = valid_modes - 1;
2278
2279 strcpy(uinfo->value.enumerated.name,
2280 mode_names[mode_map[uinfo->value.enumerated.item]]);
2281
2282 return 0;
2283} 2334}
2284 2335
2285static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol, 2336static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,
@@ -2328,13 +2379,18 @@ static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
2328/*------------------------------------------------------------ 2379/*------------------------------------------------------------
2329 Sampleclock source controls 2380 Sampleclock source controls
2330 ------------------------------------------------------------*/ 2381 ------------------------------------------------------------*/
2331static char *sampleclock_sources[MAX_CLOCKSOURCES] = { 2382static const char const *sampleclock_sources[] = {
2332 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header", 2383 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2333 "SMPTE", "Digital1", "Auto", "Network", "Invalid", 2384 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2334 "Prev Module", 2385 "Prev Module", "BLU-Link",
2335 "Digital2", "Digital3", "Digital4", "Digital5", 2386 "Digital2", "Digital3", "Digital4", "Digital5",
2336 "Digital6", "Digital7", "Digital8"}; 2387 "Digital6", "Digital7", "Digital8"};
2337 2388
2389 /* Number of strings must match expected enumerated values */
2390 compile_time_assert(
2391 (ARRAY_SIZE(sampleclock_sources) == MAX_CLOCKSOURCES),
2392 assert_sampleclock_sources_size);
2393
2338static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol, 2394static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,
2339 struct snd_ctl_elem_info *uinfo) 2395 struct snd_ctl_elem_info *uinfo)
2340{ 2396{
@@ -2482,15 +2538,19 @@ static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
2482static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi, 2538static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
2483 struct hpi_control *hpi_ctl) 2539 struct hpi_control *hpi_ctl)
2484{ 2540{
2485 struct snd_card *card = asihpi->card; 2541 struct snd_card *card;
2486 struct snd_kcontrol_new snd_control; 2542 struct snd_kcontrol_new snd_control;
2487 2543
2488 struct clk_cache *clkcache = &asihpi->cc; 2544 struct clk_cache *clkcache;
2489 u32 hSC = hpi_ctl->h_control; 2545 u32 hSC = hpi_ctl->h_control;
2490 int has_aes_in = 0; 2546 int has_aes_in = 0;
2491 int i, j; 2547 int i, j;
2492 u16 source; 2548 u16 source;
2493 2549
2550 if (snd_BUG_ON(!asihpi))
2551 return -EINVAL;
2552 card = asihpi->card;
2553 clkcache = &asihpi->cc;
2494 snd_control.private_value = hpi_ctl->h_control; 2554 snd_control.private_value = hpi_ctl->h_control;
2495 2555
2496 clkcache->has_local = 0; 2556 clkcache->has_local = 0;
@@ -2592,7 +2652,7 @@ static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2592 if (err) { 2652 if (err) {
2593 if (err == HPI_ERROR_CONTROL_DISABLED) { 2653 if (err == HPI_ERROR_CONTROL_DISABLED) {
2594 if (mixer_dump) 2654 if (mixer_dump)
2595 snd_printk(KERN_INFO 2655 dev_info(&asihpi->pci->dev,
2596 "Disabled HPI Control(%d)\n", 2656 "Disabled HPI Control(%d)\n",
2597 idx); 2657 idx);
2598 continue; 2658 continue;
@@ -2657,9 +2717,8 @@ static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2657 case HPI_CONTROL_COMPANDER: 2717 case HPI_CONTROL_COMPANDER:
2658 default: 2718 default:
2659 if (mixer_dump) 2719 if (mixer_dump)
2660 snd_printk(KERN_INFO 2720 dev_info(&asihpi->pci->dev,
2661 "Untranslated HPI Control" 2721 "Untranslated HPI Control (%d) %d %d %d %d %d\n",
2662 "(%d) %d %d %d %d %d\n",
2663 idx, 2722 idx,
2664 hpi_ctl.control_type, 2723 hpi_ctl.control_type,
2665 hpi_ctl.src_node_type, 2724 hpi_ctl.src_node_type,
@@ -2674,7 +2733,7 @@ static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2674 if (HPI_ERROR_INVALID_OBJ_INDEX != err) 2733 if (HPI_ERROR_INVALID_OBJ_INDEX != err)
2675 hpi_handle_error(err); 2734 hpi_handle_error(err);
2676 2735
2677 snd_printk(KERN_INFO "%d mixer controls found\n", idx); 2736 dev_info(&asihpi->pci->dev, "%d mixer controls found\n", idx);
2678 2737
2679 return 0; 2738 return 0;
2680} 2739}
@@ -2837,8 +2896,7 @@ static int snd_asihpi_probe(struct pci_dev *pci_dev,
2837 &card); 2896 &card);
2838 if (err < 0) 2897 if (err < 0)
2839 return err; 2898 return err;
2840 snd_printk(KERN_WARNING 2899 dev_warn(&pci_dev->dev, "Adapter index %d->ALSA index %d\n",
2841 "**** WARNING **** Adapter index %d->ALSA index %d\n",
2842 adapter_index, card->number); 2900 adapter_index, card->number);
2843 } 2901 }
2844 2902
@@ -2846,9 +2904,7 @@ static int snd_asihpi_probe(struct pci_dev *pci_dev,
2846 asihpi->card = card; 2904 asihpi->card = card;
2847 asihpi->pci = pci_dev; 2905 asihpi->pci = pci_dev;
2848 asihpi->hpi = hpi; 2906 asihpi->hpi = hpi;
2849 2907 hpi->snd_card = card;
2850 snd_printk(KERN_INFO "adapter ID=%4X index=%d\n",
2851 asihpi->hpi->adapter->type, adapter_index);
2852 2908
2853 err = hpi_adapter_get_property(adapter_index, 2909 err = hpi_adapter_get_property(adapter_index,
2854 HPI_ADAPTER_PROPERTY_CAPS1, 2910 HPI_ADAPTER_PROPERTY_CAPS1,
@@ -2868,8 +2924,16 @@ static int snd_asihpi_probe(struct pci_dev *pci_dev,
2868 if (err) 2924 if (err)
2869 asihpi->update_interval_frames = 512; 2925 asihpi->update_interval_frames = 512;
2870 2926
2871 if (!asihpi->can_dma) 2927 if (hpi->interrupt_mode) {
2872 asihpi->update_interval_frames *= 2; 2928 asihpi->pcm_start = snd_card_asihpi_pcm_int_start;
2929 asihpi->pcm_stop = snd_card_asihpi_pcm_int_stop;
2930 tasklet_init(&asihpi->t, snd_card_asihpi_int_task,
2931 (unsigned long)hpi);
2932 hpi->interrupt_callback = snd_card_asihpi_isr;
2933 } else {
2934 asihpi->pcm_start = snd_card_asihpi_pcm_timer_start;
2935 asihpi->pcm_stop = snd_card_asihpi_pcm_timer_stop;
2936 }
2873 2937
2874 hpi_handle_error(hpi_instream_open(adapter_index, 2938 hpi_handle_error(hpi_instream_open(adapter_index,
2875 0, &h_stream)); 2939 0, &h_stream));
@@ -2879,6 +2943,9 @@ static int snd_asihpi_probe(struct pci_dev *pci_dev,
2879 2943
2880 hpi_handle_error(hpi_instream_close(h_stream)); 2944 hpi_handle_error(hpi_instream_close(h_stream));
2881 2945
2946 if (!asihpi->can_dma)
2947 asihpi->update_interval_frames *= 2;
2948
2882 err = hpi_adapter_get_property(adapter_index, 2949 err = hpi_adapter_get_property(adapter_index,
2883 HPI_ADAPTER_PROPERTY_CURCHANNELS, 2950 HPI_ADAPTER_PROPERTY_CURCHANNELS,
2884 &asihpi->in_max_chans, &asihpi->out_max_chans); 2951 &asihpi->in_max_chans, &asihpi->out_max_chans);
@@ -2896,20 +2963,21 @@ static int snd_asihpi_probe(struct pci_dev *pci_dev,
2896 asihpi->in_min_chans = 1; 2963 asihpi->in_min_chans = 1;
2897 } 2964 }
2898 2965
2899 snd_printk(KERN_INFO "Has dma:%d, grouping:%d, mrx:%d\n", 2966 dev_info(&pci_dev->dev, "Has dma:%d, grouping:%d, mrx:%d, uif:%d\n",
2900 asihpi->can_dma, 2967 asihpi->can_dma,
2901 asihpi->support_grouping, 2968 asihpi->support_grouping,
2902 asihpi->support_mrx 2969 asihpi->support_mrx,
2970 asihpi->update_interval_frames
2903 ); 2971 );
2904 2972
2905 err = snd_card_asihpi_pcm_new(asihpi, 0); 2973 err = snd_card_asihpi_pcm_new(asihpi, 0);
2906 if (err < 0) { 2974 if (err < 0) {
2907 snd_printk(KERN_ERR "pcm_new failed\n"); 2975 dev_err(&pci_dev->dev, "pcm_new failed\n");
2908 goto __nodev; 2976 goto __nodev;
2909 } 2977 }
2910 err = snd_card_asihpi_mixer_new(asihpi); 2978 err = snd_card_asihpi_mixer_new(asihpi);
2911 if (err < 0) { 2979 if (err < 0) {
2912 snd_printk(KERN_ERR "mixer_new failed\n"); 2980 dev_err(&pci_dev->dev, "mixer_new failed\n");
2913 goto __nodev; 2981 goto __nodev;
2914 } 2982 }
2915 2983
@@ -2936,13 +3004,12 @@ static int snd_asihpi_probe(struct pci_dev *pci_dev,
2936 err = snd_card_register(card); 3004 err = snd_card_register(card);
2937 3005
2938 if (!err) { 3006 if (!err) {
2939 hpi->snd_card = card;
2940 dev++; 3007 dev++;
2941 return 0; 3008 return 0;
2942 } 3009 }
2943__nodev: 3010__nodev:
2944 snd_card_free(card); 3011 snd_card_free(card);
2945 snd_printk(KERN_ERR "snd_asihpi_probe error %d\n", err); 3012 dev_err(&pci_dev->dev, "snd_asihpi_probe error %d\n", err);
2946 return err; 3013 return err;
2947 3014
2948} 3015}
@@ -2950,6 +3017,16 @@ __nodev:
2950static void snd_asihpi_remove(struct pci_dev *pci_dev) 3017static void snd_asihpi_remove(struct pci_dev *pci_dev)
2951{ 3018{
2952 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev); 3019 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev);
3020 struct snd_card_asihpi *asihpi = hpi->snd_card->private_data;
3021
3022 /* Stop interrupts */
3023 if (hpi->interrupt_mode) {
3024 hpi->interrupt_callback = NULL;
3025 hpi_handle_error(hpi_adapter_set_property(hpi->adapter->index,
3026 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
3027 tasklet_kill(&asihpi->t);
3028 }
3029
2953 snd_card_free(hpi->snd_card); 3030 snd_card_free(hpi->snd_card);
2954 hpi->snd_card = NULL; 3031 hpi->snd_card = NULL;
2955 asihpi_adapter_remove(pci_dev); 3032 asihpi_adapter_remove(pci_dev);
@@ -2971,10 +3048,6 @@ static struct pci_driver driver = {
2971 .id_table = asihpi_pci_tbl, 3048 .id_table = asihpi_pci_tbl,
2972 .probe = snd_asihpi_probe, 3049 .probe = snd_asihpi_probe,
2973 .remove = snd_asihpi_remove, 3050 .remove = snd_asihpi_remove,
2974#ifdef CONFIG_PM_SLEEP
2975/* .suspend = snd_asihpi_suspend,
2976 .resume = snd_asihpi_resume, */
2977#endif
2978}; 3051};
2979 3052
2980static int __init snd_asihpi_init(void) 3053static int __init snd_asihpi_init(void)
diff --git a/sound/pci/asihpi/hpi.h b/sound/pci/asihpi/hpi.h
index 20887241a3ae..4466bd2c5272 100644
--- a/sound/pci/asihpi/hpi.h
+++ b/sound/pci/asihpi/hpi.h
@@ -196,8 +196,10 @@ enum HPI_SOURCENODES {
196 packets of RTP audio samples from other devices. */ 196 packets of RTP audio samples from other devices. */
197 HPI_SOURCENODE_RTP_DESTINATION = 112, 197 HPI_SOURCENODE_RTP_DESTINATION = 112,
198 HPI_SOURCENODE_INTERNAL = 113, /**< node internal to the device. */ 198 HPI_SOURCENODE_INTERNAL = 113, /**< node internal to the device. */
199 HPI_SOURCENODE_AVB = 114, /**< AVB input stream */
200 HPI_SOURCENODE_BLULINK = 115, /**< BLU-link input channel */
199 /* !!!Update this AND hpidebug.h if you add a new sourcenode type!!! */ 201 /* !!!Update this AND hpidebug.h if you add a new sourcenode type!!! */
200 HPI_SOURCENODE_LAST_INDEX = 113 /**< largest ID */ 202 HPI_SOURCENODE_LAST_INDEX = 115 /**< largest ID */
201 /* AX6 max sourcenode types = 15 */ 203 /* AX6 max sourcenode types = 15 */
202}; 204};
203 205
@@ -224,8 +226,11 @@ enum HPI_DESTNODES {
224 /** RTP stream output node - This node is a source for 226 /** RTP stream output node - This node is a source for
225 packets of RTP audio samples that are sent to other devices. */ 227 packets of RTP audio samples that are sent to other devices. */
226 HPI_DESTNODE_RTP_SOURCE = 208, 228 HPI_DESTNODE_RTP_SOURCE = 208,
229 HPI_DESTNODE_AVB = 209, /**< AVB output stream */
230 HPI_DESTNODE_INTERNAL = 210, /**< node internal to the device. */
231 HPI_DESTNODE_BLULINK = 211, /**< BLU-link output channel. */
227 /* !!!Update this AND hpidebug.h if you add a new destnode type!!! */ 232 /* !!!Update this AND hpidebug.h if you add a new destnode type!!! */
228 HPI_DESTNODE_LAST_INDEX = 208 /**< largest ID */ 233 HPI_DESTNODE_LAST_INDEX = 211 /**< largest ID */
229 /* AX6 max destnode types = 15 */ 234 /* AX6 max destnode types = 15 */
230}; 235};
231 236
@@ -752,7 +757,8 @@ enum HPI_TUNER_BAND {
752 HPI_TUNER_BAND_TV_PAL_I = 7, /**< PAL-I TV band*/ 757 HPI_TUNER_BAND_TV_PAL_I = 7, /**< PAL-I TV band*/
753 HPI_TUNER_BAND_TV_PAL_DK = 8, /**< PAL-D/K TV band*/ 758 HPI_TUNER_BAND_TV_PAL_DK = 8, /**< PAL-D/K TV band*/
754 HPI_TUNER_BAND_TV_SECAM_L = 9, /**< SECAM-L TV band*/ 759 HPI_TUNER_BAND_TV_SECAM_L = 9, /**< SECAM-L TV band*/
755 HPI_TUNER_BAND_LAST = 9 /**< the index of the last tuner band. */ 760 HPI_TUNER_BAND_DAB = 10,
761 HPI_TUNER_BAND_LAST = 10 /**< the index of the last tuner band. */
756}; 762};
757 763
758/** Tuner mode attributes 764/** Tuner mode attributes
@@ -842,8 +848,10 @@ enum HPI_SAMPLECLOCK_SOURCES {
842 HPI_SAMPLECLOCK_SOURCE_NETWORK = 8, 848 HPI_SAMPLECLOCK_SOURCE_NETWORK = 8,
843/** From previous adjacent module (ASI2416 only)*/ 849/** From previous adjacent module (ASI2416 only)*/
844 HPI_SAMPLECLOCK_SOURCE_PREV_MODULE = 10, 850 HPI_SAMPLECLOCK_SOURCE_PREV_MODULE = 10,
851/** Blu link sample clock*/
852 HPI_SAMPLECLOCK_SOURCE_BLULINK = 11,
845/*! Update this if you add a new clock source.*/ 853/*! Update this if you add a new clock source.*/
846 HPI_SAMPLECLOCK_SOURCE_LAST = 10 854 HPI_SAMPLECLOCK_SOURCE_LAST = 11
847}; 855};
848 856
849/** Equalizer filter types. Used by HPI_ParametricEq_SetBand() 857/** Equalizer filter types. Used by HPI_ParametricEq_SetBand()
diff --git a/sound/pci/asihpi/hpi6205.c b/sound/pci/asihpi/hpi6205.c
index 4f2873880b16..8d5abfa4e24b 100644
--- a/sound/pci/asihpi/hpi6205.c
+++ b/sound/pci/asihpi/hpi6205.c
@@ -1,7 +1,7 @@
1/****************************************************************************** 1/******************************************************************************
2 2
3 AudioScience HPI driver 3 AudioScience HPI driver
4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> 4 Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as 7 it under the terms of version 2 of the GNU General Public License as
@@ -163,6 +163,9 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
163 163
164static void delete_adapter_obj(struct hpi_adapter_obj *pao); 164static void delete_adapter_obj(struct hpi_adapter_obj *pao);
165 165
166static int adapter_irq_query_and_clear(struct hpi_adapter_obj *pao,
167 u32 message);
168
166static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao, 169static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
167 struct hpi_message *phm, struct hpi_response *phr); 170 struct hpi_message *phm, struct hpi_response *phr);
168 171
@@ -283,7 +286,6 @@ static void adapter_message(struct hpi_adapter_obj *pao,
283 case HPI_ADAPTER_DELETE: 286 case HPI_ADAPTER_DELETE:
284 adapter_delete(pao, phm, phr); 287 adapter_delete(pao, phm, phr);
285 break; 288 break;
286
287 default: 289 default:
288 hw_message(pao, phm, phr); 290 hw_message(pao, phm, phr);
289 break; 291 break;
@@ -673,6 +675,12 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
673 675
674 HPI_DEBUG_LOG(INFO, "bootload DSP OK\n"); 676 HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
675 677
678 pao->irq_query_and_clear = adapter_irq_query_and_clear;
679 pao->instream_host_buffer_status =
680 phw->p_interface_buffer->instream_host_buffer_status;
681 pao->outstream_host_buffer_status =
682 phw->p_interface_buffer->outstream_host_buffer_status;
683
676 return hpi_add_adapter(pao); 684 return hpi_add_adapter(pao);
677} 685}
678 686
@@ -713,6 +721,21 @@ static void delete_adapter_obj(struct hpi_adapter_obj *pao)
713 721
714/*****************************************************************************/ 722/*****************************************************************************/
715/* Adapter functions */ 723/* Adapter functions */
724static int adapter_irq_query_and_clear(struct hpi_adapter_obj *pao,
725 u32 message)
726{
727 struct hpi_hw_obj *phw = pao->priv;
728 u32 hsr = 0;
729
730 hsr = ioread32(phw->prHSR);
731 if (hsr & C6205_HSR_INTSRC) {
732 /* reset the interrupt from the DSP */
733 iowrite32(C6205_HSR_INTSRC, phw->prHSR);
734 return HPI_IRQ_MIXER;
735 }
736
737 return HPI_IRQ_NONE;
738}
716 739
717/*****************************************************************************/ 740/*****************************************************************************/
718/* OutStream Host buffer functions */ 741/* OutStream Host buffer functions */
@@ -1331,17 +1354,21 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
1331 if (boot_code_id[1] != 0) { 1354 if (boot_code_id[1] != 0) {
1332 /* DSP 1 is a C6713 */ 1355 /* DSP 1 is a C6713 */
1333 /* CLKX0 <- '1' release the C6205 bootmode pulldowns */ 1356 /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
1334 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202); 1357 boot_loader_write_mem32(pao, 0, 0x018C0024, 0x00002202);
1335 hpios_delay_micro_seconds(100); 1358 hpios_delay_micro_seconds(100);
1336 /* Reset the 6713 #1 - revB */ 1359 /* Reset the 6713 #1 - revB */
1337 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0); 1360 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
1338 1361 /* value of bit 3 is unknown after DSP reset, other bits shoudl be 0 */
1339 /* dummy read every 4 words for 6205 advisory 1.4.4 */ 1362 if (0 != (boot_loader_read_mem32(pao, 0,
1340 boot_loader_read_mem32(pao, 0, 0); 1363 (C6205_BAR0_TIMER1_CTL)) & ~8))
1341 1364 return HPI6205_ERROR_6205_REG;
1342 hpios_delay_micro_seconds(100); 1365 hpios_delay_micro_seconds(100);
1366
1343 /* Release C6713 from reset - revB */ 1367 /* Release C6713 from reset - revB */
1344 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4); 1368 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
1369 if (4 != (boot_loader_read_mem32(pao, 0,
1370 (C6205_BAR0_TIMER1_CTL)) & ~8))
1371 return HPI6205_ERROR_6205_REG;
1345 hpios_delay_micro_seconds(100); 1372 hpios_delay_micro_seconds(100);
1346 } 1373 }
1347 1374
@@ -2089,7 +2116,7 @@ static u16 message_response_sequence(struct hpi_adapter_obj *pao,
2089 return 0; 2116 return 0;
2090 } 2117 }
2091 2118
2092 /* Assume buffer of type struct bus_master_interface 2119 /* Assume buffer of type struct bus_master_interface_62
2093 is allocated "noncacheable" */ 2120 is allocated "noncacheable" */
2094 2121
2095 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) { 2122 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
diff --git a/sound/pci/asihpi/hpi_internal.h b/sound/pci/asihpi/hpi_internal.h
index bc86cb726d79..48380ce2c81b 100644
--- a/sound/pci/asihpi/hpi_internal.h
+++ b/sound/pci/asihpi/hpi_internal.h
@@ -554,17 +554,21 @@ struct hpi_pci {
554 struct pci_dev *pci_dev; 554 struct pci_dev *pci_dev;
555}; 555};
556 556
557/** Adapter specification resource */
558struct hpi_adapter_specification {
559 u32 type;
560 u8 modules[4];
561};
562
557struct hpi_resource { 563struct hpi_resource {
558 union { 564 union {
559 const struct hpi_pci *pci; 565 const struct hpi_pci *pci;
560 const char *net_if; 566 const char *net_if;
567 struct hpi_adapter_specification adapter_spec;
568 const void *sw_if;
561 } r; 569 } r;
562#ifndef HPI64BIT /* keep structure size constant */
563 u32 pad_to64;
564#endif
565 u16 bus_type; /* HPI_BUS_PNPISA, _PCI, _USB etc */ 570 u16 bus_type; /* HPI_BUS_PNPISA, _PCI, _USB etc */
566 u16 padding; 571 u16 padding;
567
568}; 572};
569 573
570/** Format info used inside struct hpi_message 574/** Format info used inside struct hpi_message
@@ -582,7 +586,7 @@ struct hpi_msg_format {
582struct hpi_msg_data { 586struct hpi_msg_data {
583 struct hpi_msg_format format; 587 struct hpi_msg_format format;
584 u8 *pb_data; 588 u8 *pb_data;
585#ifndef HPI64BIT 589#ifndef CONFIG_64BIT
586 u32 padding; 590 u32 padding;
587#endif 591#endif
588 u32 data_size; 592 u32 data_size;
@@ -595,7 +599,7 @@ struct hpi_data_legacy32 {
595 u32 data_size; 599 u32 data_size;
596}; 600};
597 601
598#ifdef HPI64BIT 602#ifdef CONFIG_64BIT
599/* Compatibility version of struct hpi_data*/ 603/* Compatibility version of struct hpi_data*/
600struct hpi_data_compat32 { 604struct hpi_data_compat32 {
601 struct hpi_msg_format format; 605 struct hpi_msg_format format;
@@ -682,8 +686,8 @@ union hpi_adapterx_msg {
682 u16 value; 686 u16 value;
683 } test_assert; 687 } test_assert;
684 struct { 688 struct {
685 u32 yes; 689 u32 message;
686 } irq_query; 690 } irq;
687 u32 pad[3]; 691 u32 pad[3];
688}; 692};
689 693
diff --git a/sound/pci/asihpi/hpicmn.c b/sound/pci/asihpi/hpicmn.c
index 7ed5c26c3737..c7751243dc42 100644
--- a/sound/pci/asihpi/hpicmn.c
+++ b/sound/pci/asihpi/hpicmn.c
@@ -1,7 +1,7 @@
1/****************************************************************************** 1/******************************************************************************
2 2
3 AudioScience HPI driver 3 AudioScience HPI driver
4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> 4 Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as 7 it under the terms of version 2 of the GNU General Public License as
@@ -206,6 +206,14 @@ static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)
206 struct hpi_control_cache_info *info = 206 struct hpi_control_cache_info *info =
207 (struct hpi_control_cache_info *) 207 (struct hpi_control_cache_info *)
208 &p_master_cache[byte_count]; 208 &p_master_cache[byte_count];
209 u16 control_index = info->control_index;
210
211 if (control_index >= pC->control_count) {
212 HPI_DEBUG_LOG(INFO,
213 "adap %d control index %d out of range, cache not ready?\n",
214 pC->adap_idx, control_index);
215 return 0;
216 }
209 217
210 if (!info->size_in32bit_words) { 218 if (!info->size_in32bit_words) {
211 if (!i) { 219 if (!i) {
@@ -225,10 +233,10 @@ static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)
225 } 233 }
226 234
227 if (info->control_type) { 235 if (info->control_type) {
228 pC->p_info[info->control_index] = info; 236 pC->p_info[control_index] = info;
229 cached++; 237 cached++;
230 } else { /* dummy cache entry */ 238 } else { /* dummy cache entry */
231 pC->p_info[info->control_index] = NULL; 239 pC->p_info[control_index] = NULL;
232 } 240 }
233 241
234 byte_count += info->size_in32bit_words * 4; 242 byte_count += info->size_in32bit_words * 4;
@@ -309,35 +317,18 @@ static const struct pad_ofs_size pad_desc[] = {
309/** CheckControlCache checks the cache and fills the struct hpi_response 317/** CheckControlCache checks the cache and fills the struct hpi_response
310 * accordingly. It returns one if a cache hit occurred, zero otherwise. 318 * accordingly. It returns one if a cache hit occurred, zero otherwise.
311 */ 319 */
312short hpi_check_control_cache(struct hpi_control_cache *p_cache, 320short hpi_check_control_cache_single(struct hpi_control_cache_single *pC,
313 struct hpi_message *phm, struct hpi_response *phr) 321 struct hpi_message *phm, struct hpi_response *phr)
314{ 322{
315 short found = 1;
316 struct hpi_control_cache_info *pI;
317 struct hpi_control_cache_single *pC;
318 size_t response_size; 323 size_t response_size;
319 if (!find_control(phm->obj_index, p_cache, &pI)) { 324 short found = 1;
320 HPI_DEBUG_LOG(VERBOSE,
321 "HPICMN find_control() failed for adap %d\n",
322 phm->adapter_index);
323 return 0;
324 }
325
326 phr->error = 0;
327 phr->specific_error = 0;
328 phr->version = 0;
329 325
330 /* set the default response size */ 326 /* set the default response size */
331 response_size = 327 response_size =
332 sizeof(struct hpi_response_header) + 328 sizeof(struct hpi_response_header) +
333 sizeof(struct hpi_control_res); 329 sizeof(struct hpi_control_res);
334 330
335 /* pC is the default cached control strucure. May be cast to 331 switch (pC->u.i.control_type) {
336 something else in the following switch statement.
337 */
338 pC = (struct hpi_control_cache_single *)pI;
339
340 switch (pI->control_type) {
341 332
342 case HPI_CONTROL_METER: 333 case HPI_CONTROL_METER:
343 if (phm->u.c.attribute == HPI_METER_PEAK) { 334 if (phm->u.c.attribute == HPI_METER_PEAK) {
@@ -467,7 +458,7 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
467 break; 458 break;
468 case HPI_CONTROL_PAD:{ 459 case HPI_CONTROL_PAD:{
469 struct hpi_control_cache_pad *p_pad; 460 struct hpi_control_cache_pad *p_pad;
470 p_pad = (struct hpi_control_cache_pad *)pI; 461 p_pad = (struct hpi_control_cache_pad *)pC;
471 462
472 if (!(p_pad->field_valid_flags & (1 << 463 if (!(p_pad->field_valid_flags & (1 <<
473 HPI_CTL_ATTR_INDEX(phm->u.c. 464 HPI_CTL_ATTR_INDEX(phm->u.c.
@@ -531,7 +522,8 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
531 522
532 HPI_DEBUG_LOG(VERBOSE, "%s Adap %d, Ctl %d, Type %d, Attr %d\n", 523 HPI_DEBUG_LOG(VERBOSE, "%s Adap %d, Ctl %d, Type %d, Attr %d\n",
533 found ? "Cached" : "Uncached", phm->adapter_index, 524 found ? "Cached" : "Uncached", phm->adapter_index,
534 pI->control_index, pI->control_type, phm->u.c.attribute); 525 pC->u.i.control_index, pC->u.i.control_type,
526 phm->u.c.attribute);
535 527
536 if (found) { 528 if (found) {
537 phr->size = (u16)response_size; 529 phr->size = (u16)response_size;
@@ -543,34 +535,36 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
543 return found; 535 return found;
544} 536}
545 537
546/** Updates the cache with Set values. 538short hpi_check_control_cache(struct hpi_control_cache *p_cache,
547
548Only update if no error.
549Volume and Level return the limited values in the response, so use these
550Multiplexer does so use sent values
551*/
552void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,
553 struct hpi_message *phm, struct hpi_response *phr) 539 struct hpi_message *phm, struct hpi_response *phr)
554{ 540{
555 struct hpi_control_cache_single *pC;
556 struct hpi_control_cache_info *pI; 541 struct hpi_control_cache_info *pI;
557 542
558 if (phr->error)
559 return;
560
561 if (!find_control(phm->obj_index, p_cache, &pI)) { 543 if (!find_control(phm->obj_index, p_cache, &pI)) {
562 HPI_DEBUG_LOG(VERBOSE, 544 HPI_DEBUG_LOG(VERBOSE,
563 "HPICMN find_control() failed for adap %d\n", 545 "HPICMN find_control() failed for adap %d\n",
564 phm->adapter_index); 546 phm->adapter_index);
565 return; 547 return 0;
566 } 548 }
567 549
568 /* pC is the default cached control strucure. 550 phr->error = 0;
569 May be cast to something else in the following switch statement. 551 phr->specific_error = 0;
570 */ 552 phr->version = 0;
571 pC = (struct hpi_control_cache_single *)pI; 553
554 return hpi_check_control_cache_single((struct hpi_control_cache_single
555 *)pI, phm, phr);
556}
557
558/** Updates the cache with Set values.
572 559
573 switch (pI->control_type) { 560Only update if no error.
561Volume and Level return the limited values in the response, so use these
562Multiplexer does so use sent values
563*/
564void hpi_cmn_control_cache_sync_to_msg_single(struct hpi_control_cache_single
565 *pC, struct hpi_message *phm, struct hpi_response *phr)
566{
567 switch (pC->u.i.control_type) {
574 case HPI_CONTROL_VOLUME: 568 case HPI_CONTROL_VOLUME:
575 if (phm->u.c.attribute == HPI_VOLUME_GAIN) { 569 if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
576 pC->u.vol.an_log[0] = phr->u.c.an_log_value[0]; 570 pC->u.vol.an_log[0] = phr->u.c.an_log_value[0];
@@ -625,6 +619,30 @@ void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,
625 } 619 }
626} 620}
627 621
622void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,
623 struct hpi_message *phm, struct hpi_response *phr)
624{
625 struct hpi_control_cache_single *pC;
626 struct hpi_control_cache_info *pI;
627
628 if (phr->error)
629 return;
630
631 if (!find_control(phm->obj_index, p_cache, &pI)) {
632 HPI_DEBUG_LOG(VERBOSE,
633 "HPICMN find_control() failed for adap %d\n",
634 phm->adapter_index);
635 return;
636 }
637
638 /* pC is the default cached control strucure.
639 May be cast to something else in the following switch statement.
640 */
641 pC = (struct hpi_control_cache_single *)pI;
642
643 hpi_cmn_control_cache_sync_to_msg_single(pC, phm, phr);
644}
645
628/** Allocate control cache. 646/** Allocate control cache.
629 647
630\return Cache pointer, or NULL if allocation fails. 648\return Cache pointer, or NULL if allocation fails.
@@ -637,12 +655,13 @@ struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count,
637 if (!p_cache) 655 if (!p_cache)
638 return NULL; 656 return NULL;
639 657
640 p_cache->p_info = kcalloc(control_count, sizeof(*p_cache->p_info), 658 p_cache->p_info =
641 GFP_KERNEL); 659 kcalloc(control_count, sizeof(*p_cache->p_info), GFP_KERNEL);
642 if (!p_cache->p_info) { 660 if (!p_cache->p_info) {
643 kfree(p_cache); 661 kfree(p_cache);
644 return NULL; 662 return NULL;
645 } 663 }
664
646 p_cache->cache_size_in_bytes = size_in_bytes; 665 p_cache->cache_size_in_bytes = size_in_bytes;
647 p_cache->control_count = control_count; 666 p_cache->control_count = control_count;
648 p_cache->p_cache = p_dsp_control_buffer; 667 p_cache->p_cache = p_dsp_control_buffer;
diff --git a/sound/pci/asihpi/hpicmn.h b/sound/pci/asihpi/hpicmn.h
index e44121283047..46629c2d101b 100644
--- a/sound/pci/asihpi/hpicmn.h
+++ b/sound/pci/asihpi/hpicmn.h
@@ -1,7 +1,7 @@
1/** 1/**
2 2
3 AudioScience HPI driver 3 AudioScience HPI driver
4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> 4 Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as 7 it under the terms of version 2 of the GNU General Public License as
@@ -21,7 +21,11 @@
21struct hpi_adapter_obj; 21struct hpi_adapter_obj;
22 22
23/* a function that takes an adapter obj and returns an int */ 23/* a function that takes an adapter obj and returns an int */
24typedef int adapter_int_func(struct hpi_adapter_obj *pao); 24typedef int adapter_int_func(struct hpi_adapter_obj *pao, u32 message);
25
26#define HPI_IRQ_NONE (0)
27#define HPI_IRQ_MESSAGE (1)
28#define HPI_IRQ_MIXER (2)
25 29
26struct hpi_adapter_obj { 30struct hpi_adapter_obj {
27 struct hpi_pci pci; /* PCI info - bus#,dev#,address etc */ 31 struct hpi_pci pci; /* PCI info - bus#,dev#,address etc */
@@ -33,6 +37,9 @@ struct hpi_adapter_obj {
33 u16 dsp_crashed; 37 u16 dsp_crashed;
34 u16 has_control_cache; 38 u16 has_control_cache;
35 void *priv; 39 void *priv;
40 adapter_int_func *irq_query_and_clear;
41 struct hpi_hostbuffer_status *instream_host_buffer_status;
42 struct hpi_hostbuffer_status *outstream_host_buffer_status;
36}; 43};
37 44
38struct hpi_control_cache { 45struct hpi_control_cache {
@@ -55,13 +62,21 @@ void hpi_delete_adapter(struct hpi_adapter_obj *pao);
55 62
56short hpi_check_control_cache(struct hpi_control_cache *pC, 63short hpi_check_control_cache(struct hpi_control_cache *pC,
57 struct hpi_message *phm, struct hpi_response *phr); 64 struct hpi_message *phm, struct hpi_response *phr);
65
66short hpi_check_control_cache_single(struct hpi_control_cache_single *pC,
67 struct hpi_message *phm, struct hpi_response *phr);
68
58struct hpi_control_cache *hpi_alloc_control_cache(const u32 69struct hpi_control_cache *hpi_alloc_control_cache(const u32
59 number_of_controls, const u32 size_in_bytes, u8 *pDSP_control_buffer); 70 number_of_controls, const u32 size_in_bytes, u8 *pDSP_control_buffer);
71
60void hpi_free_control_cache(struct hpi_control_cache *p_cache); 72void hpi_free_control_cache(struct hpi_control_cache *p_cache);
61 73
62void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *pC, 74void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *pC,
63 struct hpi_message *phm, struct hpi_response *phr); 75 struct hpi_message *phm, struct hpi_response *phr);
64 76
77void hpi_cmn_control_cache_sync_to_msg_single(struct hpi_control_cache_single
78 *pC, struct hpi_message *phm, struct hpi_response *phr);
79
65u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr); 80u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr);
66 81
67hpi_handler_func HPI_COMMON; 82hpi_handler_func HPI_COMMON;
diff --git a/sound/pci/asihpi/hpimsginit.c b/sound/pci/asihpi/hpimsginit.c
index 032d563e3708..7eb617175fde 100644
--- a/sound/pci/asihpi/hpimsginit.c
+++ b/sound/pci/asihpi/hpimsginit.c
@@ -1,7 +1,7 @@
1/****************************************************************************** 1/******************************************************************************
2 2
3 AudioScience HPI driver 3 AudioScience HPI driver
4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> 4 Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as 7 it under the terms of version 2 of the GNU General Public License as
@@ -37,11 +37,15 @@ static u16 gwSSX2_bypass;
37static void hpi_init_message(struct hpi_message *phm, u16 object, 37static void hpi_init_message(struct hpi_message *phm, u16 object,
38 u16 function) 38 u16 function)
39{ 39{
40 memset(phm, 0, sizeof(*phm)); 40 u16 size;
41
41 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) 42 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
42 phm->size = msg_size[object]; 43 size = msg_size[object];
43 else 44 else
44 phm->size = sizeof(*phm); 45 size = sizeof(*phm);
46
47 memset(phm, 0, size);
48 phm->size = size;
45 49
46 if (gwSSX2_bypass) 50 if (gwSSX2_bypass)
47 phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE; 51 phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
@@ -60,12 +64,16 @@ static void hpi_init_message(struct hpi_message *phm, u16 object,
60void hpi_init_response(struct hpi_response *phr, u16 object, u16 function, 64void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
61 u16 error) 65 u16 error)
62{ 66{
63 memset(phr, 0, sizeof(*phr)); 67 u16 size;
64 phr->type = HPI_TYPE_RESPONSE; 68
65 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) 69 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
66 phr->size = res_size[object]; 70 size = res_size[object];
67 else 71 else
68 phr->size = sizeof(*phr); 72 size = sizeof(*phr);
73
74 memset(phr, 0, sizeof(*phr));
75 phr->size = size;
76 phr->type = HPI_TYPE_RESPONSE;
69 phr->object = object; 77 phr->object = object;
70 phr->function = function; 78 phr->function = function;
71 phr->error = error; 79 phr->error = error;
@@ -86,7 +94,7 @@ void hpi_init_message_response(struct hpi_message *phm,
86static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size, 94static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
87 u16 object, u16 function) 95 u16 object, u16 function)
88{ 96{
89 memset(phm, 0, sizeof(*phm)); 97 memset(phm, 0, size);
90 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) { 98 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
91 phm->size = size; 99 phm->size = size;
92 phm->type = HPI_TYPE_REQUEST; 100 phm->type = HPI_TYPE_REQUEST;
@@ -100,7 +108,9 @@ static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
100void hpi_init_responseV1(struct hpi_response_header *phr, u16 size, 108void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
101 u16 object, u16 function) 109 u16 object, u16 function)
102{ 110{
103 memset(phr, 0, sizeof(*phr)); 111 (void)object;
112 (void)function;
113 memset(phr, 0, size);
104 phr->size = size; 114 phr->size = size;
105 phr->version = 1; 115 phr->version = 1;
106 phr->type = HPI_TYPE_RESPONSE; 116 phr->type = HPI_TYPE_RESPONSE;
diff --git a/sound/pci/asihpi/hpimsgx.c b/sound/pci/asihpi/hpimsgx.c
index d4790ddc225c..736f45337fc7 100644
--- a/sound/pci/asihpi/hpimsgx.c
+++ b/sound/pci/asihpi/hpimsgx.c
@@ -1,7 +1,7 @@
1/****************************************************************************** 1/******************************************************************************
2 2
3 AudioScience HPI driver 3 AudioScience HPI driver
4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> 4 Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as 7 it under the terms of version 2 of the GNU General Public License as
@@ -35,6 +35,7 @@ static struct pci_device_id asihpi_pci_tbl[] = {
35static struct hpios_spinlock msgx_lock; 35static struct hpios_spinlock msgx_lock;
36 36
37static hpi_handler_func *hpi_entry_points[HPI_MAX_ADAPTERS]; 37static hpi_handler_func *hpi_entry_points[HPI_MAX_ADAPTERS];
38static int logging_enabled = 1;
38 39
39static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci 40static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci
40 *pci_info) 41 *pci_info)
@@ -312,7 +313,9 @@ static void instream_message(struct hpi_message *phm,
312void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr, 313void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,
313 void *h_owner) 314 void *h_owner)
314{ 315{
315 HPI_DEBUG_MESSAGE(DEBUG, phm); 316
317 if (logging_enabled)
318 HPI_DEBUG_MESSAGE(DEBUG, phm);
316 319
317 if (phm->type != HPI_TYPE_REQUEST) { 320 if (phm->type != HPI_TYPE_REQUEST) {
318 hpi_init_response(phr, phm->object, phm->function, 321 hpi_init_response(phr, phm->object, phm->function,
@@ -352,8 +355,14 @@ void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,
352 hw_entry_point(phm, phr); 355 hw_entry_point(phm, phr);
353 break; 356 break;
354 } 357 }
355 HPI_DEBUG_RESPONSE(phr);
356 358
359 if (logging_enabled)
360 HPI_DEBUG_RESPONSE(phr);
361
362 if (phr->error >= HPI_ERROR_DSP_COMMUNICATION) {
363 hpi_debug_level_set(HPI_DEBUG_LEVEL_ERROR);
364 logging_enabled = 0;
365 }
357} 366}
358 367
359static void adapter_open(struct hpi_message *phm, struct hpi_response *phr) 368static void adapter_open(struct hpi_message *phm, struct hpi_response *phr)
diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
index 7f0272032fbb..6aa677e60555 100644
--- a/sound/pci/asihpi/hpioctl.c
+++ b/sound/pci/asihpi/hpioctl.c
@@ -1,7 +1,8 @@
1/******************************************************************************* 1/*******************************************************************************
2
3 AudioScience HPI driver 2 AudioScience HPI driver
4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> 3 Common Linux HPI ioctl and module probe/remove functions
4
5 Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
5 6
6 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
7 it under the terms of version 2 of the GNU General Public License as 8 it under the terms of version 2 of the GNU General Public License as
@@ -12,11 +13,6 @@
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 14 GNU General Public License for more details.
14 15
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19Common Linux HPI ioctl and module probe/remove functions
20*******************************************************************************/ 16*******************************************************************************/
21#define SOURCEFILE_NAME "hpioctl.c" 17#define SOURCEFILE_NAME "hpioctl.c"
22 18
@@ -29,6 +25,7 @@ Common Linux HPI ioctl and module probe/remove functions
29#include "hpicmn.h" 25#include "hpicmn.h"
30 26
31#include <linux/fs.h> 27#include <linux/fs.h>
28#include <linux/interrupt.h>
32#include <linux/slab.h> 29#include <linux/slab.h>
33#include <linux/moduleparam.h> 30#include <linux/moduleparam.h>
34#include <asm/uaccess.h> 31#include <asm/uaccess.h>
@@ -307,10 +304,38 @@ out:
307 return err; 304 return err;
308} 305}
309 306
307static int asihpi_irq_count;
308
309static irqreturn_t asihpi_isr(int irq, void *dev_id)
310{
311 struct hpi_adapter *a = dev_id;
312 int handled;
313
314 if (!a->adapter->irq_query_and_clear) {
315 pr_err("asihpi_isr ASI%04X:%d no handler\n", a->adapter->type,
316 a->adapter->index);
317 return IRQ_NONE;
318 }
319
320 handled = a->adapter->irq_query_and_clear(a->adapter, 0);
321
322 if (!handled)
323 return IRQ_NONE;
324
325 asihpi_irq_count++;
326 /* printk(KERN_INFO "asihpi_isr %d ASI%04X:%d irq handled\n",
327 asihpi_irq_count, a->adapter->type, a->adapter->index); */
328
329 if (a->interrupt_callback)
330 a->interrupt_callback(a);
331
332 return IRQ_HANDLED;
333}
334
310int asihpi_adapter_probe(struct pci_dev *pci_dev, 335int asihpi_adapter_probe(struct pci_dev *pci_dev,
311 const struct pci_device_id *pci_id) 336 const struct pci_device_id *pci_id)
312{ 337{
313 int idx, nm; 338 int idx, nm, low_latency_mode = 0, irq_supported = 0;
314 int adapter_index; 339 int adapter_index;
315 unsigned int memlen; 340 unsigned int memlen;
316 struct hpi_message hm; 341 struct hpi_message hm;
@@ -388,8 +413,38 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
388 hm.adapter_index = adapter.adapter->index; 413 hm.adapter_index = adapter.adapter->index;
389 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL); 414 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
390 415
391 if (hr.error) 416 if (hr.error) {
417 HPI_DEBUG_LOG(ERROR, "HPI_ADAPTER_OPEN failed, aborting\n");
392 goto err; 418 goto err;
419 }
420
421 /* Check if current mode == Low Latency mode */
422 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
423 HPI_ADAPTER_GET_MODE);
424 hm.adapter_index = adapter.adapter->index;
425 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
426
427 if (!hr.error
428 && hr.u.ax.mode.adapter_mode == HPI_ADAPTER_MODE_LOW_LATENCY)
429 low_latency_mode = 1;
430 else
431 dev_info(&pci_dev->dev,
432 "Adapter at index %d is not in low latency mode\n",
433 adapter.adapter->index);
434
435 /* Check if IRQs are supported */
436 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
437 HPI_ADAPTER_GET_PROPERTY);
438 hm.adapter_index = adapter.adapter->index;
439 hm.u.ax.property_set.property = HPI_ADAPTER_PROPERTY_SUPPORTS_IRQ;
440 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
441 if (hr.error || !hr.u.ax.property_get.parameter1) {
442 dev_info(&pci_dev->dev,
443 "IRQs not supported by adapter at index %d\n",
444 adapter.adapter->index);
445 } else {
446 irq_supported = 1;
447 }
393 448
394 /* WARNING can't init mutex in 'adapter' 449 /* WARNING can't init mutex in 'adapter'
395 * and then copy it to adapters[] ?!?! 450 * and then copy it to adapters[] ?!?!
@@ -398,6 +453,44 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
398 mutex_init(&adapters[adapter_index].mutex); 453 mutex_init(&adapters[adapter_index].mutex);
399 pci_set_drvdata(pci_dev, &adapters[adapter_index]); 454 pci_set_drvdata(pci_dev, &adapters[adapter_index]);
400 455
456 if (low_latency_mode && irq_supported) {
457 if (!adapter.adapter->irq_query_and_clear) {
458 dev_err(&pci_dev->dev,
459 "no IRQ handler for adapter %d, aborting\n",
460 adapter.adapter->index);
461 goto err;
462 }
463
464 /* Disable IRQ generation on DSP side by setting the rate to 0 */
465 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
466 HPI_ADAPTER_SET_PROPERTY);
467 hm.adapter_index = adapter.adapter->index;
468 hm.u.ax.property_set.property = HPI_ADAPTER_PROPERTY_IRQ_RATE;
469 hm.u.ax.property_set.parameter1 = 0;
470 hm.u.ax.property_set.parameter2 = 0;
471 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
472 if (hr.error) {
473 HPI_DEBUG_LOG(ERROR,
474 "HPI_ADAPTER_GET_MODE failed, aborting\n");
475 goto err;
476 }
477
478 /* Note: request_irq calls asihpi_isr here */
479 if (request_irq(pci_dev->irq, asihpi_isr, IRQF_SHARED,
480 "asihpi", &adapters[adapter_index])) {
481 dev_err(&pci_dev->dev, "request_irq(%d) failed\n",
482 pci_dev->irq);
483 goto err;
484 }
485
486 adapters[adapter_index].interrupt_mode = 1;
487
488 dev_info(&pci_dev->dev, "using irq %d\n", pci_dev->irq);
489 adapters[adapter_index].irq = pci_dev->irq;
490 } else {
491 dev_info(&pci_dev->dev, "using polled mode\n");
492 }
493
401 dev_info(&pci_dev->dev, "probe succeeded for ASI%04X HPI index %d\n", 494 dev_info(&pci_dev->dev, "probe succeeded for ASI%04X HPI index %d\n",
402 adapter.adapter->type, adapter_index); 495 adapter.adapter->type, adapter_index);
403 496
@@ -431,6 +524,15 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev)
431 pa = pci_get_drvdata(pci_dev); 524 pa = pci_get_drvdata(pci_dev);
432 pci = pa->adapter->pci; 525 pci = pa->adapter->pci;
433 526
527 /* Disable IRQ generation on DSP side */
528 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
529 HPI_ADAPTER_SET_PROPERTY);
530 hm.adapter_index = pa->adapter->index;
531 hm.u.ax.property_set.property = HPI_ADAPTER_PROPERTY_IRQ_RATE;
532 hm.u.ax.property_set.parameter1 = 0;
533 hm.u.ax.property_set.parameter2 = 0;
534 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
535
434 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, 536 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
435 HPI_ADAPTER_DELETE); 537 HPI_ADAPTER_DELETE);
436 hm.adapter_index = pa->adapter->index; 538 hm.adapter_index = pa->adapter->index;
@@ -442,8 +544,10 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev)
442 iounmap(pci.ap_mem_base[idx]); 544 iounmap(pci.ap_mem_base[idx]);
443 } 545 }
444 546
445 if (pa->p_buffer) 547 if (pa->irq)
446 vfree(pa->p_buffer); 548 free_irq(pa->irq, pa);
549
550 vfree(pa->p_buffer);
447 551
448 if (1) 552 if (1)
449 dev_info(&pci_dev->dev, 553 dev_info(&pci_dev->dev,
diff --git a/sound/pci/asihpi/hpios.h b/sound/pci/asihpi/hpios.h
index d3fbd0d76c37..4e383601b9cf 100644
--- a/sound/pci/asihpi/hpios.h
+++ b/sound/pci/asihpi/hpios.h
@@ -41,10 +41,6 @@ HPI Operating System Specific macros for Linux Kernel driver
41 41
42#define HPI_NO_OS_FILE_OPS 42#define HPI_NO_OS_FILE_OPS
43 43
44#ifdef CONFIG_64BIT
45#define HPI64BIT
46#endif
47
48/** Details of a memory area allocated with pci_alloc_consistent 44/** Details of a memory area allocated with pci_alloc_consistent
49Need all info for parameters to pci_free_consistent 45Need all info for parameters to pci_free_consistent
50*/ 46*/
@@ -155,6 +151,10 @@ struct hpi_adapter {
155 struct hpi_adapter_obj *adapter; 151 struct hpi_adapter_obj *adapter;
156 struct snd_card *snd_card; 152 struct snd_card *snd_card;
157 153
154 int irq;
155 int interrupt_mode;
156 void (*interrupt_callback) (struct hpi_adapter *);
157
158 /* mutex prevents contention for one card 158 /* mutex prevents contention for one card
159 between multiple user programs (via ioctl) */ 159 between multiple user programs (via ioctl) */
160 struct mutex mutex; 160 struct mutex mutex;
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 7895c5d300c7..9c1c4452a8ee 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -688,9 +688,7 @@ static void snd_atiixp_xrun_dma(struct atiixp *chip, struct atiixp_dma *dma)
688 if (! dma->substream || ! dma->running) 688 if (! dma->substream || ! dma->running)
689 return; 689 return;
690 dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type); 690 dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
691 snd_pcm_stream_lock(dma->substream); 691 snd_pcm_stop_xrun(dma->substream);
692 snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN);
693 snd_pcm_stream_unlock(dma->substream);
694} 692}
695 693
696/* 694/*
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index 3c3241309a30..b2f63e0727de 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -638,9 +638,7 @@ static void snd_atiixp_xrun_dma(struct atiixp_modem *chip,
638 if (! dma->substream || ! dma->running) 638 if (! dma->substream || ! dma->running)
639 return; 639 return;
640 dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type); 640 dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
641 snd_pcm_stream_lock(dma->substream); 641 snd_pcm_stop_xrun(dma->substream);
642 snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN);
643 snd_pcm_stream_unlock(dma->substream);
644} 642}
645 643
646/* 644/*
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index 21ce31f636bc..996369134ea8 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -48,11 +48,10 @@ static void vortex_fix_latency(struct pci_dev *vortex)
48{ 48{
49 int rc; 49 int rc;
50 if (!(rc = pci_write_config_byte(vortex, 0x40, 0xff))) { 50 if (!(rc = pci_write_config_byte(vortex, 0x40, 0xff))) {
51 pr_info( CARD_NAME 51 dev_info(&vortex->dev, "vortex latency is 0xff\n");
52 ": vortex latency is 0xff\n");
53 } else { 52 } else {
54 pr_warn( CARD_NAME 53 dev_warn(&vortex->dev,
55 ": could not set vortex latency: pci error 0x%x\n", rc); 54 "could not set vortex latency: pci error 0x%x\n", rc);
56 } 55 }
57} 56}
58 57
@@ -70,11 +69,10 @@ static void vortex_fix_agp_bridge(struct pci_dev *via)
70 if (!(rc = pci_read_config_byte(via, 0x42, &value)) 69 if (!(rc = pci_read_config_byte(via, 0x42, &value))
71 && ((value & 0x10) 70 && ((value & 0x10)
72 || !(rc = pci_write_config_byte(via, 0x42, value | 0x10)))) { 71 || !(rc = pci_write_config_byte(via, 0x42, value | 0x10)))) {
73 pr_info( CARD_NAME 72 dev_info(&via->dev, "bridge config is 0x%x\n", value | 0x10);
74 ": bridge config is 0x%x\n", value | 0x10);
75 } else { 73 } else {
76 pr_warn( CARD_NAME 74 dev_warn(&via->dev,
77 ": could not set vortex latency: pci error 0x%x\n", rc); 75 "could not set vortex latency: pci error 0x%x\n", rc);
78 } 76 }
79} 77}
80 78
@@ -97,7 +95,8 @@ static void snd_vortex_workaround(struct pci_dev *vortex, int fix)
97 PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL); 95 PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL);
98 } 96 }
99 if (via) { 97 if (via) {
100 pr_info( CARD_NAME ": Activating latency workaround...\n"); 98 dev_info(&vortex->dev,
99 "Activating latency workaround...\n");
101 vortex_fix_latency(vortex); 100 vortex_fix_latency(vortex);
102 vortex_fix_agp_bridge(via); 101 vortex_fix_agp_bridge(via);
103 } 102 }
@@ -153,7 +152,7 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
153 return err; 152 return err;
154 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || 153 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 ||
155 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { 154 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
156 pr_err( "error to set DMA mask\n"); 155 dev_err(card->dev, "error to set DMA mask\n");
157 pci_disable_device(pci); 156 pci_disable_device(pci);
158 return -ENXIO; 157 return -ENXIO;
159 } 158 }
@@ -182,7 +181,7 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
182 181
183 chip->mmio = pci_ioremap_bar(pci, 0); 182 chip->mmio = pci_ioremap_bar(pci, 0);
184 if (!chip->mmio) { 183 if (!chip->mmio) {
185 pr_err( "MMIO area remap failed.\n"); 184 dev_err(card->dev, "MMIO area remap failed.\n");
186 err = -ENOMEM; 185 err = -ENOMEM;
187 goto ioremap_out; 186 goto ioremap_out;
188 } 187 }
@@ -191,14 +190,14 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
191 * This must be done before we do request_irq otherwise we can get spurious 190 * This must be done before we do request_irq otherwise we can get spurious
192 * interrupts that we do not handle properly and make a mess of things */ 191 * interrupts that we do not handle properly and make a mess of things */
193 if ((err = vortex_core_init(chip)) != 0) { 192 if ((err = vortex_core_init(chip)) != 0) {
194 pr_err( "hw core init failed\n"); 193 dev_err(card->dev, "hw core init failed\n");
195 goto core_out; 194 goto core_out;
196 } 195 }
197 196
198 if ((err = request_irq(pci->irq, vortex_interrupt, 197 if ((err = request_irq(pci->irq, vortex_interrupt,
199 IRQF_SHARED, KBUILD_MODNAME, 198 IRQF_SHARED, KBUILD_MODNAME,
200 chip)) != 0) { 199 chip)) != 0) {
201 pr_err( "cannot grab irq\n"); 200 dev_err(card->dev, "cannot grab irq\n");
202 goto irq_out; 201 goto irq_out;
203 } 202 }
204 chip->irq = pci->irq; 203 chip->irq = pci->irq;
@@ -315,7 +314,7 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
315 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH, 314 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH,
316 sizeof(snd_vortex_synth_arg_t), &wave) < 0 315 sizeof(snd_vortex_synth_arg_t), &wave) < 0
317 || wave == NULL) { 316 || wave == NULL) {
318 snd_printk(KERN_ERR "Can't initialize Aureal wavetable synth\n"); 317 dev_err(card->dev, "Can't initialize Aureal wavetable synth\n");
319 } else { 318 } else {
320 snd_vortex_synth_arg_t *arg; 319 snd_vortex_synth_arg_t *arg;
321 320
@@ -342,11 +341,11 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
342 chip->rev = pci->revision; 341 chip->rev = pci->revision;
343#ifdef CHIP_AU8830 342#ifdef CHIP_AU8830
344 if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) { 343 if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) {
345 pr_alert( 344 dev_alert(card->dev,
346 "vortex: The revision (%x) of your card has not been seen before.\n", 345 "The revision (%x) of your card has not been seen before.\n",
347 chip->rev); 346 chip->rev);
348 pr_alert( 347 dev_alert(card->dev,
349 "vortex: Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n"); 348 "Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n");
350 snd_card_free(card); 349 snd_card_free(card);
351 err = -ENODEV; 350 err = -ENODEV;
352 return err; 351 return err;
diff --git a/sound/pci/au88x0/au88x0.h b/sound/pci/au88x0/au88x0.h
index 466a5c8e8354..3a8fefefea77 100644
--- a/sound/pci/au88x0/au88x0.h
+++ b/sound/pci/au88x0/au88x0.h
@@ -243,7 +243,7 @@ static int vortex_core_init(vortex_t * card);
243static int vortex_core_shutdown(vortex_t * card); 243static int vortex_core_shutdown(vortex_t * card);
244static void vortex_enable_int(vortex_t * card); 244static void vortex_enable_int(vortex_t * card);
245static irqreturn_t vortex_interrupt(int irq, void *dev_id); 245static irqreturn_t vortex_interrupt(int irq, void *dev_id);
246static int vortex_alsafmt_aspfmt(int alsafmt); 246static int vortex_alsafmt_aspfmt(int alsafmt, vortex_t *v);
247 247
248/* Connection stuff. */ 248/* Connection stuff. */
249static void vortex_connect_default(vortex_t * vortex, int en); 249static void vortex_connect_default(vortex_t * vortex, int en);
@@ -278,7 +278,7 @@ static void vortex_mix_setvolumebyte(vortex_t * vortex, unsigned char mix,
278static void vortex_Vort3D_enable(vortex_t * v); 278static void vortex_Vort3D_enable(vortex_t * v);
279static void vortex_Vort3D_disable(vortex_t * v); 279static void vortex_Vort3D_disable(vortex_t * v);
280static void vortex_Vort3D_connect(vortex_t * vortex, int en); 280static void vortex_Vort3D_connect(vortex_t * vortex, int en);
281static void vortex_Vort3D_InitializeSource(a3dsrc_t * a, int en); 281static void vortex_Vort3D_InitializeSource(a3dsrc_t *a, int en, vortex_t *v);
282#endif 282#endif
283 283
284/* Driver stuff. */ 284/* Driver stuff. */
diff --git a/sound/pci/au88x0/au88x0_a3d.c b/sound/pci/au88x0/au88x0_a3d.c
index 30f760e3d2c0..ab0f87312911 100644
--- a/sound/pci/au88x0/au88x0_a3d.c
+++ b/sound/pci/au88x0/au88x0_a3d.c
@@ -484,12 +484,13 @@ static void a3dsrc_ZeroState(a3dsrc_t * a)
484} 484}
485 485
486/* Reset entire A3D engine */ 486/* Reset entire A3D engine */
487static void a3dsrc_ZeroStateA3D(a3dsrc_t * a) 487static void a3dsrc_ZeroStateA3D(a3dsrc_t *a, vortex_t *v)
488{ 488{
489 int i, var, var2; 489 int i, var, var2;
490 490
491 if ((a->vortex) == NULL) { 491 if ((a->vortex) == NULL) {
492 pr_err( "vortex: ZeroStateA3D: ERROR: a->vortex is NULL\n"); 492 dev_err(v->card->dev,
493 "ZeroStateA3D: ERROR: a->vortex is NULL\n");
493 return; 494 return;
494 } 495 }
495 496
@@ -601,7 +602,7 @@ static void vortex_Vort3D_enable(vortex_t *v)
601 Vort3DRend_Initialize(v, XT_HEADPHONE); 602 Vort3DRend_Initialize(v, XT_HEADPHONE);
602 for (i = 0; i < NR_A3D; i++) { 603 for (i = 0; i < NR_A3D; i++) {
603 vortex_A3dSourceHw_Initialize(v, i % 4, i >> 2); 604 vortex_A3dSourceHw_Initialize(v, i % 4, i >> 2);
604 a3dsrc_ZeroStateA3D(&(v->a3d[0])); 605 a3dsrc_ZeroStateA3D(&v->a3d[0], v);
605 } 606 }
606 /* Register ALSA controls */ 607 /* Register ALSA controls */
607 vortex_a3d_register_controls(v); 608 vortex_a3d_register_controls(v);
@@ -628,15 +629,15 @@ static void vortex_Vort3D_connect(vortex_t * v, int en)
628 v->mixxtlk[0] = 629 v->mixxtlk[0] =
629 vortex_adb_checkinout(v, v->fixed_res, en, VORTEX_RESOURCE_MIXIN); 630 vortex_adb_checkinout(v, v->fixed_res, en, VORTEX_RESOURCE_MIXIN);
630 if (v->mixxtlk[0] < 0) { 631 if (v->mixxtlk[0] < 0) {
631 pr_warn 632 dev_warn(v->card->dev,
632 ("vortex: vortex_Vort3D: ERROR: not enough free mixer resources.\n"); 633 "vortex_Vort3D: ERROR: not enough free mixer resources.\n");
633 return; 634 return;
634 } 635 }
635 v->mixxtlk[1] = 636 v->mixxtlk[1] =
636 vortex_adb_checkinout(v, v->fixed_res, en, VORTEX_RESOURCE_MIXIN); 637 vortex_adb_checkinout(v, v->fixed_res, en, VORTEX_RESOURCE_MIXIN);
637 if (v->mixxtlk[1] < 0) { 638 if (v->mixxtlk[1] < 0) {
638 pr_warn 639 dev_warn(v->card->dev,
639 ("vortex: vortex_Vort3D: ERROR: not enough free mixer resources.\n"); 640 "vortex_Vort3D: ERROR: not enough free mixer resources.\n");
640 return; 641 return;
641 } 642 }
642#endif 643#endif
@@ -676,11 +677,11 @@ static void vortex_Vort3D_connect(vortex_t * v, int en)
676} 677}
677 678
678/* Initialize one single A3D source. */ 679/* Initialize one single A3D source. */
679static void vortex_Vort3D_InitializeSource(a3dsrc_t * a, int en) 680static void vortex_Vort3D_InitializeSource(a3dsrc_t *a, int en, vortex_t *v)
680{ 681{
681 if (a->vortex == NULL) { 682 if (a->vortex == NULL) {
682 pr_warn 683 dev_warn(v->card->dev,
683 ("vortex: Vort3D_InitializeSource: A3D source not initialized\n"); 684 "Vort3D_InitializeSource: A3D source not initialized\n");
684 return; 685 return;
685 } 686 }
686 if (en) { 687 if (en) {
diff --git a/sound/pci/au88x0/au88x0_core.c b/sound/pci/au88x0/au88x0_core.c
index 72e81286b70e..4667c3232b7f 100644
--- a/sound/pci/au88x0/au88x0_core.c
+++ b/sound/pci/au88x0/au88x0_core.c
@@ -285,8 +285,8 @@ vortex_mixer_addWTD(vortex_t * vortex, unsigned char mix, unsigned char ch)
285 temp = hwread(vortex->mmio, prev); 285 temp = hwread(vortex->mmio, prev);
286 //printk(KERN_INFO "vortex: mixAddWTD: while addr=%x, val=%x\n", prev, temp); 286 //printk(KERN_INFO "vortex: mixAddWTD: while addr=%x, val=%x\n", prev, temp);
287 if ((++lifeboat) > 0xf) { 287 if ((++lifeboat) > 0xf) {
288 pr_err( 288 dev_err(vortex->card->dev,
289 "vortex_mixer_addWTD: lifeboat overflow\n"); 289 "vortex_mixer_addWTD: lifeboat overflow\n");
290 return 0; 290 return 0;
291 } 291 }
292 } 292 }
@@ -303,7 +303,7 @@ vortex_mixer_delWTD(vortex_t * vortex, unsigned char mix, unsigned char ch)
303 303
304 eax = hwread(vortex->mmio, VORTEX_MIXER_SR); 304 eax = hwread(vortex->mmio, VORTEX_MIXER_SR);
305 if (((1 << ch) & eax) == 0) { 305 if (((1 << ch) & eax) == 0) {
306 pr_err( "mix ALARM %x\n", eax); 306 dev_err(vortex->card->dev, "mix ALARM %x\n", eax);
307 return 0; 307 return 0;
308 } 308 }
309 ebp = VORTEX_MIXER_CHNBASE + (ch << 2); 309 ebp = VORTEX_MIXER_CHNBASE + (ch << 2);
@@ -324,8 +324,8 @@ vortex_mixer_delWTD(vortex_t * vortex, unsigned char mix, unsigned char ch)
324 //printk(KERN_INFO "vortex: mixdelWTD: 1 addr=%x, val=%x, src=%x\n", ebx, edx, src); 324 //printk(KERN_INFO "vortex: mixdelWTD: 1 addr=%x, val=%x, src=%x\n", ebx, edx, src);
325 while ((edx & 0xf) != mix) { 325 while ((edx & 0xf) != mix) {
326 if ((esi) > 0xf) { 326 if ((esi) > 0xf) {
327 pr_err( 327 dev_err(vortex->card->dev,
328 "vortex: mixdelWTD: error lifeboat overflow\n"); 328 "mixdelWTD: error lifeboat overflow\n");
329 return 0; 329 return 0;
330 } 330 }
331 esp14 = ebx; 331 esp14 = ebx;
@@ -492,7 +492,7 @@ vortex_src_persist_convratio(vortex_t * vortex, unsigned char src, int ratio)
492 hwwrite(vortex->mmio, VORTEX_SRC_CONVRATIO + (src << 2), ratio); 492 hwwrite(vortex->mmio, VORTEX_SRC_CONVRATIO + (src << 2), ratio);
493 temp = hwread(vortex->mmio, VORTEX_SRC_CONVRATIO + (src << 2)); 493 temp = hwread(vortex->mmio, VORTEX_SRC_CONVRATIO + (src << 2));
494 if ((++lifeboat) > 0x9) { 494 if ((++lifeboat) > 0x9) {
495 pr_err( "Vortex: Src cvr fail\n"); 495 dev_err(vortex->card->dev, "Src cvr fail\n");
496 break; 496 break;
497 } 497 }
498 } 498 }
@@ -684,8 +684,8 @@ vortex_src_addWTD(vortex_t * vortex, unsigned char src, unsigned char ch)
684 temp = hwread(vortex->mmio, prev); 684 temp = hwread(vortex->mmio, prev);
685 //printk(KERN_INFO "vortex: srcAddWTD: while addr=%x, val=%x\n", prev, temp); 685 //printk(KERN_INFO "vortex: srcAddWTD: while addr=%x, val=%x\n", prev, temp);
686 if ((++lifeboat) > 0xf) { 686 if ((++lifeboat) > 0xf) {
687 pr_err( 687 dev_err(vortex->card->dev,
688 "vortex_src_addWTD: lifeboat overflow\n"); 688 "vortex_src_addWTD: lifeboat overflow\n");
689 return 0; 689 return 0;
690 } 690 }
691 } 691 }
@@ -703,7 +703,7 @@ vortex_src_delWTD(vortex_t * vortex, unsigned char src, unsigned char ch)
703 703
704 eax = hwread(vortex->mmio, VORTEX_SRCBLOCK_SR); 704 eax = hwread(vortex->mmio, VORTEX_SRCBLOCK_SR);
705 if (((1 << ch) & eax) == 0) { 705 if (((1 << ch) & eax) == 0) {
706 pr_err( "src alarm\n"); 706 dev_err(vortex->card->dev, "src alarm\n");
707 return 0; 707 return 0;
708 } 708 }
709 ebp = VORTEX_SRC_CHNBASE + (ch << 2); 709 ebp = VORTEX_SRC_CHNBASE + (ch << 2);
@@ -724,8 +724,8 @@ vortex_src_delWTD(vortex_t * vortex, unsigned char src, unsigned char ch)
724 //printk(KERN_INFO "vortex: srcdelWTD: 1 addr=%x, val=%x, src=%x\n", ebx, edx, src); 724 //printk(KERN_INFO "vortex: srcdelWTD: 1 addr=%x, val=%x, src=%x\n", ebx, edx, src);
725 while ((edx & 0xf) != src) { 725 while ((edx & 0xf) != src) {
726 if ((esi) > 0xf) { 726 if ((esi) > 0xf) {
727 pr_warn 727 dev_warn(vortex->card->dev,
728 ("vortex: srcdelWTD: error, lifeboat overflow\n"); 728 "srcdelWTD: error, lifeboat overflow\n");
729 return 0; 729 return 0;
730 } 730 }
731 esp14 = ebx; 731 esp14 = ebx;
@@ -819,8 +819,8 @@ vortex_fifo_setadbctrl(vortex_t * vortex, int fifo, int stereo, int priority,
819 do { 819 do {
820 temp = hwread(vortex->mmio, VORTEX_FIFO_ADBCTRL + (fifo << 2)); 820 temp = hwread(vortex->mmio, VORTEX_FIFO_ADBCTRL + (fifo << 2));
821 if (lifeboat++ > 0xbb8) { 821 if (lifeboat++ > 0xbb8) {
822 pr_err( 822 dev_err(vortex->card->dev,
823 "Vortex: vortex_fifo_setadbctrl fail\n"); 823 "vortex_fifo_setadbctrl fail\n");
824 break; 824 break;
825 } 825 }
826 } 826 }
@@ -915,7 +915,8 @@ vortex_fifo_setwtctrl(vortex_t * vortex, int fifo, int ctrl, int priority,
915 do { 915 do {
916 temp = hwread(vortex->mmio, VORTEX_FIFO_WTCTRL + (fifo << 2)); 916 temp = hwread(vortex->mmio, VORTEX_FIFO_WTCTRL + (fifo << 2));
917 if (lifeboat++ > 0xbb8) { 917 if (lifeboat++ > 0xbb8) {
918 pr_err( "Vortex: vortex_fifo_setwtctrl fail\n"); 918 dev_err(vortex->card->dev,
919 "vortex_fifo_setwtctrl fail\n");
919 break; 920 break;
920 } 921 }
921 } 922 }
@@ -1042,7 +1043,7 @@ static void vortex_fifo_init(vortex_t * vortex)
1042 for (x = NR_ADB - 1; x >= 0; x--) { 1043 for (x = NR_ADB - 1; x >= 0; x--) {
1043 hwwrite(vortex->mmio, addr, (FIFO_U0 | FIFO_U1)); 1044 hwwrite(vortex->mmio, addr, (FIFO_U0 | FIFO_U1));
1044 if (hwread(vortex->mmio, addr) != (FIFO_U0 | FIFO_U1)) 1045 if (hwread(vortex->mmio, addr) != (FIFO_U0 | FIFO_U1))
1045 pr_err( "bad adb fifo reset!"); 1046 dev_err(vortex->card->dev, "bad adb fifo reset!");
1046 vortex_fifo_clearadbdata(vortex, x, FIFO_SIZE); 1047 vortex_fifo_clearadbdata(vortex, x, FIFO_SIZE);
1047 addr -= 4; 1048 addr -= 4;
1048 } 1049 }
@@ -1053,9 +1054,9 @@ static void vortex_fifo_init(vortex_t * vortex)
1053 for (x = NR_WT - 1; x >= 0; x--) { 1054 for (x = NR_WT - 1; x >= 0; x--) {
1054 hwwrite(vortex->mmio, addr, FIFO_U0); 1055 hwwrite(vortex->mmio, addr, FIFO_U0);
1055 if (hwread(vortex->mmio, addr) != FIFO_U0) 1056 if (hwread(vortex->mmio, addr) != FIFO_U0)
1056 pr_err( 1057 dev_err(vortex->card->dev,
1057 "bad wt fifo reset (0x%08x, 0x%08x)!\n", 1058 "bad wt fifo reset (0x%08x, 0x%08x)!\n",
1058 addr, hwread(vortex->mmio, addr)); 1059 addr, hwread(vortex->mmio, addr));
1059 vortex_fifo_clearwtdata(vortex, x, FIFO_SIZE); 1060 vortex_fifo_clearwtdata(vortex, x, FIFO_SIZE);
1060 addr -= 4; 1061 addr -= 4;
1061 } 1062 }
@@ -1213,8 +1214,9 @@ static int vortex_adbdma_bufshift(vortex_t * vortex, int adbdma)
1213 if (dma->period_virt >= dma->nr_periods) 1214 if (dma->period_virt >= dma->nr_periods)
1214 dma->period_virt -= dma->nr_periods; 1215 dma->period_virt -= dma->nr_periods;
1215 if (delta != 1) 1216 if (delta != 1)
1216 pr_info( "vortex: %d virt=%d, real=%d, delta=%d\n", 1217 dev_info(vortex->card->dev,
1217 adbdma, dma->period_virt, dma->period_real, delta); 1218 "%d virt=%d, real=%d, delta=%d\n",
1219 adbdma, dma->period_virt, dma->period_real, delta);
1218 1220
1219 return delta; 1221 return delta;
1220} 1222}
@@ -1482,8 +1484,8 @@ static int vortex_wtdma_bufshift(vortex_t * vortex, int wtdma)
1482 dma->period_real = page; 1484 dma->period_real = page;
1483 1485
1484 if (delta != 1) 1486 if (delta != 1)
1485 pr_warn( "vortex: wt virt = %d, delta = %d\n", 1487 dev_warn(vortex->card->dev, "wt virt = %d, delta = %d\n",
1486 dma->period_virt, delta); 1488 dma->period_virt, delta);
1487 1489
1488 return delta; 1490 return delta;
1489} 1491}
@@ -1667,9 +1669,9 @@ vortex_adb_addroutes(vortex_t * vortex, unsigned char channel,
1667 hwread(vortex->mmio, 1669 hwread(vortex->mmio,
1668 VORTEX_ADB_RTBASE + (temp << 2)) & ADB_MASK; 1670 VORTEX_ADB_RTBASE + (temp << 2)) & ADB_MASK;
1669 if ((lifeboat++) > ADB_MASK) { 1671 if ((lifeboat++) > ADB_MASK) {
1670 pr_err( 1672 dev_err(vortex->card->dev,
1671 "vortex_adb_addroutes: unending route! 0x%x\n", 1673 "vortex_adb_addroutes: unending route! 0x%x\n",
1672 *route); 1674 *route);
1673 return; 1675 return;
1674 } 1676 }
1675 } 1677 }
@@ -1703,9 +1705,9 @@ vortex_adb_delroutes(vortex_t * vortex, unsigned char channel,
1703 hwread(vortex->mmio, 1705 hwread(vortex->mmio,
1704 VORTEX_ADB_RTBASE + (prev << 2)) & ADB_MASK; 1706 VORTEX_ADB_RTBASE + (prev << 2)) & ADB_MASK;
1705 if (((lifeboat++) > ADB_MASK) || (temp == ADB_MASK)) { 1707 if (((lifeboat++) > ADB_MASK) || (temp == ADB_MASK)) {
1706 pr_err( 1708 dev_err(vortex->card->dev,
1707 "vortex_adb_delroutes: route not found! 0x%x\n", 1709 "vortex_adb_delroutes: route not found! 0x%x\n",
1708 route0); 1710 route0);
1709 return; 1711 return;
1710 } 1712 }
1711 } 1713 }
@@ -2045,7 +2047,9 @@ vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out, int restype)
2045 } 2047 }
2046 } 2048 }
2047 } 2049 }
2048 pr_err( "vortex: FATAL: ResManager: resource type %d exhausted.\n", restype); 2050 dev_err(vortex->card->dev,
2051 "FATAL: ResManager: resource type %d exhausted.\n",
2052 restype);
2049 return -ENOMEM; 2053 return -ENOMEM;
2050} 2054}
2051 2055
@@ -2173,11 +2177,13 @@ vortex_adb_allocroute(vortex_t *vortex, int dma, int nr_ch, int dir,
2173 memset(stream->resources, 0, 2177 memset(stream->resources, 0,
2174 sizeof(unsigned char) * 2178 sizeof(unsigned char) *
2175 VORTEX_RESOURCE_LAST); 2179 VORTEX_RESOURCE_LAST);
2176 pr_err( "vortex: out of A3D sources. Sorry\n"); 2180 dev_err(vortex->card->dev,
2181 "out of A3D sources. Sorry\n");
2177 return -EBUSY; 2182 return -EBUSY;
2178 } 2183 }
2179 /* (De)Initialize A3D hardware source. */ 2184 /* (De)Initialize A3D hardware source. */
2180 vortex_Vort3D_InitializeSource(&(vortex->a3d[a3d]), en); 2185 vortex_Vort3D_InitializeSource(&vortex->a3d[a3d], en,
2186 vortex);
2181 } 2187 }
2182 /* Make SPDIF out exclusive to "spdif" device when in use. */ 2188 /* Make SPDIF out exclusive to "spdif" device when in use. */
2183 if ((stream->type == VORTEX_PCM_SPDIF) && (en)) { 2189 if ((stream->type == VORTEX_PCM_SPDIF) && (en)) {
@@ -2421,7 +2427,7 @@ static irqreturn_t vortex_interrupt(int irq, void *dev_id)
2421 hwread(vortex->mmio, VORTEX_IRQ_SOURCE); 2427 hwread(vortex->mmio, VORTEX_IRQ_SOURCE);
2422 // Is at least one IRQ flag set? 2428 // Is at least one IRQ flag set?
2423 if (source == 0) { 2429 if (source == 0) {
2424 pr_err( "vortex: missing irq source\n"); 2430 dev_err(vortex->card->dev, "missing irq source\n");
2425 return IRQ_NONE; 2431 return IRQ_NONE;
2426 } 2432 }
2427 2433
@@ -2429,19 +2435,19 @@ static irqreturn_t vortex_interrupt(int irq, void *dev_id)
2429 // Attend every interrupt source. 2435 // Attend every interrupt source.
2430 if (unlikely(source & IRQ_ERR_MASK)) { 2436 if (unlikely(source & IRQ_ERR_MASK)) {
2431 if (source & IRQ_FATAL) { 2437 if (source & IRQ_FATAL) {
2432 pr_err( "vortex: IRQ fatal error\n"); 2438 dev_err(vortex->card->dev, "IRQ fatal error\n");
2433 } 2439 }
2434 if (source & IRQ_PARITY) { 2440 if (source & IRQ_PARITY) {
2435 pr_err( "vortex: IRQ parity error\n"); 2441 dev_err(vortex->card->dev, "IRQ parity error\n");
2436 } 2442 }
2437 if (source & IRQ_REG) { 2443 if (source & IRQ_REG) {
2438 pr_err( "vortex: IRQ reg error\n"); 2444 dev_err(vortex->card->dev, "IRQ reg error\n");
2439 } 2445 }
2440 if (source & IRQ_FIFO) { 2446 if (source & IRQ_FIFO) {
2441 pr_err( "vortex: IRQ fifo error\n"); 2447 dev_err(vortex->card->dev, "IRQ fifo error\n");
2442 } 2448 }
2443 if (source & IRQ_DMA) { 2449 if (source & IRQ_DMA) {
2444 pr_err( "vortex: IRQ dma error\n"); 2450 dev_err(vortex->card->dev, "IRQ dma error\n");
2445 } 2451 }
2446 handled = 1; 2452 handled = 1;
2447 } 2453 }
@@ -2489,7 +2495,7 @@ static irqreturn_t vortex_interrupt(int irq, void *dev_id)
2489 } 2495 }
2490 2496
2491 if (!handled) { 2497 if (!handled) {
2492 pr_err( "vortex: unknown irq source %x\n", source); 2498 dev_err(vortex->card->dev, "unknown irq source %x\n", source);
2493 } 2499 }
2494 return IRQ_RETVAL(handled); 2500 return IRQ_RETVAL(handled);
2495} 2501}
@@ -2546,7 +2552,7 @@ vortex_codec_write(struct snd_ac97 * codec, unsigned short addr, unsigned short
2546 while (!(hwread(card->mmio, VORTEX_CODEC_CTRL) & 0x100)) { 2552 while (!(hwread(card->mmio, VORTEX_CODEC_CTRL) & 0x100)) {
2547 udelay(100); 2553 udelay(100);
2548 if (lifeboat++ > POLL_COUNT) { 2554 if (lifeboat++ > POLL_COUNT) {
2549 pr_err( "vortex: ac97 codec stuck busy\n"); 2555 dev_err(card->card->dev, "ac97 codec stuck busy\n");
2550 return; 2556 return;
2551 } 2557 }
2552 } 2558 }
@@ -2572,7 +2578,7 @@ static unsigned short vortex_codec_read(struct snd_ac97 * codec, unsigned short
2572 while (!(hwread(card->mmio, VORTEX_CODEC_CTRL) & 0x100)) { 2578 while (!(hwread(card->mmio, VORTEX_CODEC_CTRL) & 0x100)) {
2573 udelay(100); 2579 udelay(100);
2574 if (lifeboat++ > POLL_COUNT) { 2580 if (lifeboat++ > POLL_COUNT) {
2575 pr_err( "vortex: ac97 codec stuck busy\n"); 2581 dev_err(card->card->dev, "ac97 codec stuck busy\n");
2576 return 0xffff; 2582 return 0xffff;
2577 } 2583 }
2578 } 2584 }
@@ -2586,7 +2592,8 @@ static unsigned short vortex_codec_read(struct snd_ac97 * codec, unsigned short
2586 udelay(100); 2592 udelay(100);
2587 data = hwread(card->mmio, VORTEX_CODEC_IO); 2593 data = hwread(card->mmio, VORTEX_CODEC_IO);
2588 if (lifeboat++ > POLL_COUNT) { 2594 if (lifeboat++ > POLL_COUNT) {
2589 pr_err( "vortex: ac97 address never arrived\n"); 2595 dev_err(card->card->dev,
2596 "ac97 address never arrived\n");
2590 return 0xffff; 2597 return 0xffff;
2591 } 2598 }
2592 } while ((data & VORTEX_CODEC_ADDMASK) != 2599 } while ((data & VORTEX_CODEC_ADDMASK) !=
@@ -2683,7 +2690,7 @@ static void vortex_spdif_init(vortex_t * vortex, int spdif_sr, int spdif_mode)
2683static int vortex_core_init(vortex_t *vortex) 2690static int vortex_core_init(vortex_t *vortex)
2684{ 2691{
2685 2692
2686 pr_info( "Vortex: init.... "); 2693 dev_info(vortex->card->dev, "init started\n");
2687 /* Hardware Init. */ 2694 /* Hardware Init. */
2688 hwwrite(vortex->mmio, VORTEX_CTRL, 0xffffffff); 2695 hwwrite(vortex->mmio, VORTEX_CTRL, 0xffffffff);
2689 msleep(5); 2696 msleep(5);
@@ -2728,7 +2735,7 @@ static int vortex_core_init(vortex_t *vortex)
2728 //vortex_enable_timer_int(vortex); 2735 //vortex_enable_timer_int(vortex);
2729 //vortex_disable_timer_int(vortex); 2736 //vortex_disable_timer_int(vortex);
2730 2737
2731 pr_info( "done.\n"); 2738 dev_info(vortex->card->dev, "init.... done.\n");
2732 spin_lock_init(&vortex->lock); 2739 spin_lock_init(&vortex->lock);
2733 2740
2734 return 0; 2741 return 0;
@@ -2737,7 +2744,7 @@ static int vortex_core_init(vortex_t *vortex)
2737static int vortex_core_shutdown(vortex_t * vortex) 2744static int vortex_core_shutdown(vortex_t * vortex)
2738{ 2745{
2739 2746
2740 pr_info( "Vortex: shutdown..."); 2747 dev_info(vortex->card->dev, "shutdown started\n");
2741#ifndef CHIP_AU8820 2748#ifndef CHIP_AU8820
2742 vortex_eq_free(vortex); 2749 vortex_eq_free(vortex);
2743 vortex_Vort3D_disable(vortex); 2750 vortex_Vort3D_disable(vortex);
@@ -2759,13 +2766,13 @@ static int vortex_core_shutdown(vortex_t * vortex)
2759 msleep(5); 2766 msleep(5);
2760 hwwrite(vortex->mmio, VORTEX_IRQ_SOURCE, 0xffff); 2767 hwwrite(vortex->mmio, VORTEX_IRQ_SOURCE, 0xffff);
2761 2768
2762 pr_info( "done.\n"); 2769 dev_info(vortex->card->dev, "shutdown.... done.\n");
2763 return 0; 2770 return 0;
2764} 2771}
2765 2772
2766/* Alsa support. */ 2773/* Alsa support. */
2767 2774
2768static int vortex_alsafmt_aspfmt(int alsafmt) 2775static int vortex_alsafmt_aspfmt(int alsafmt, vortex_t *v)
2769{ 2776{
2770 int fmt; 2777 int fmt;
2771 2778
@@ -2793,7 +2800,8 @@ static int vortex_alsafmt_aspfmt(int alsafmt)
2793 break; 2800 break;
2794 default: 2801 default:
2795 fmt = 0x8; 2802 fmt = 0x8;
2796 pr_err( "vortex: format unsupported %d\n", alsafmt); 2803 dev_err(v->card->dev,
2804 "format unsupported %d\n", alsafmt);
2797 break; 2805 break;
2798 } 2806 }
2799 return fmt; 2807 return fmt;
diff --git a/sound/pci/au88x0/au88x0_eq.c b/sound/pci/au88x0/au88x0_eq.c
index 9404ba73eaf6..9585c5c63b96 100644
--- a/sound/pci/au88x0/au88x0_eq.c
+++ b/sound/pci/au88x0/au88x0_eq.c
@@ -845,7 +845,8 @@ snd_vortex_peaks_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u
845 845
846 vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count); 846 vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count);
847 if (count != 20) { 847 if (count != 20) {
848 pr_err( "vortex: peak count error 20 != %d \n", count); 848 dev_err(vortex->card->dev,
849 "peak count error 20 != %d\n", count);
849 return -1; 850 return -1;
850 } 851 }
851 for (i = 0; i < 20; i++) 852 for (i = 0; i < 20; i++)
diff --git a/sound/pci/au88x0/au88x0_game.c b/sound/pci/au88x0/au88x0_game.c
index 72daf6cf8169..151815b857a0 100644
--- a/sound/pci/au88x0/au88x0_game.c
+++ b/sound/pci/au88x0/au88x0_game.c
@@ -98,7 +98,8 @@ static int vortex_gameport_register(vortex_t *vortex)
98 98
99 vortex->gameport = gp = gameport_allocate_port(); 99 vortex->gameport = gp = gameport_allocate_port();
100 if (!gp) { 100 if (!gp) {
101 pr_err( "vortex: cannot allocate memory for gameport\n"); 101 dev_err(vortex->card->dev,
102 "cannot allocate memory for gameport\n");
102 return -ENOMEM; 103 return -ENOMEM;
103 } 104 }
104 105
diff --git a/sound/pci/au88x0/au88x0_mpu401.c b/sound/pci/au88x0/au88x0_mpu401.c
index 328c1943c0c3..1025e55ca854 100644
--- a/sound/pci/au88x0/au88x0_mpu401.c
+++ b/sound/pci/au88x0/au88x0_mpu401.c
@@ -73,7 +73,7 @@ static int snd_vortex_midi(vortex_t *vortex)
73 /* Check if anything is OK. */ 73 /* Check if anything is OK. */
74 temp = hwread(vortex->mmio, VORTEX_MIDI_DATA); 74 temp = hwread(vortex->mmio, VORTEX_MIDI_DATA);
75 if (temp != MPU401_ACK /*0xfe */ ) { 75 if (temp != MPU401_ACK /*0xfe */ ) {
76 pr_err( "midi port doesn't acknowledge!\n"); 76 dev_err(vortex->card->dev, "midi port doesn't acknowledge!\n");
77 return -ENODEV; 77 return -ENODEV;
78 } 78 }
79 /* Enable MPU401 interrupts. */ 79 /* Enable MPU401 interrupts. */
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index 5adc6b92ffab..a6d6d8d0867a 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -227,7 +227,7 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
227 err = 227 err =
228 snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 228 snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
229 if (err < 0) { 229 if (err < 0) {
230 pr_err( "Vortex: pcm page alloc failed!\n"); 230 dev_err(chip->card->dev, "Vortex: pcm page alloc failed!\n");
231 return err; 231 return err;
232 } 232 }
233 /* 233 /*
@@ -332,7 +332,7 @@ static int snd_vortex_pcm_prepare(struct snd_pcm_substream *substream)
332 dir = 1; 332 dir = 1;
333 else 333 else
334 dir = 0; 334 dir = 0;
335 fmt = vortex_alsafmt_aspfmt(runtime->format); 335 fmt = vortex_alsafmt_aspfmt(runtime->format, chip);
336 spin_lock_irq(&chip->lock); 336 spin_lock_irq(&chip->lock);
337 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) { 337 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
338 vortex_adbdma_setmode(chip, dma, 1, dir, fmt, 338 vortex_adbdma_setmode(chip, dma, 1, dir, fmt,
@@ -371,7 +371,7 @@ static int snd_vortex_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
371 } 371 }
372#ifndef CHIP_AU8810 372#ifndef CHIP_AU8810
373 else { 373 else {
374 pr_info( "vortex: wt start %d\n", dma); 374 dev_info(chip->card->dev, "wt start %d\n", dma);
375 vortex_wtdma_startfifo(chip, dma); 375 vortex_wtdma_startfifo(chip, dma);
376 } 376 }
377#endif 377#endif
@@ -384,7 +384,7 @@ static int snd_vortex_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
384 vortex_adbdma_stopfifo(chip, dma); 384 vortex_adbdma_stopfifo(chip, dma);
385#ifndef CHIP_AU8810 385#ifndef CHIP_AU8810
386 else { 386 else {
387 pr_info( "vortex: wt stop %d\n", dma); 387 dev_info(chip->card->dev, "wt stop %d\n", dma);
388 vortex_wtdma_stopfifo(chip, dma); 388 vortex_wtdma_stopfifo(chip, dma);
389 } 389 }
390#endif 390#endif
diff --git a/sound/pci/au88x0/au88x0_synth.c b/sound/pci/au88x0/au88x0_synth.c
index f094bac24291..78e12f4796f3 100644
--- a/sound/pci/au88x0/au88x0_synth.c
+++ b/sound/pci/au88x0/au88x0_synth.c
@@ -90,7 +90,7 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
90 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0); 90 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0);
91 91
92 temp = hwread(vortex->mmio, WT_PARM(wt, 3)); 92 temp = hwread(vortex->mmio, WT_PARM(wt, 3));
93 pr_debug( "vortex: WT PARM3: %x\n", temp); 93 dev_dbg(vortex->card->dev, "WT PARM3: %x\n", temp);
94 //hwwrite(vortex->mmio, WT_PARM(wt, 3), temp); 94 //hwwrite(vortex->mmio, WT_PARM(wt, 3), temp);
95 95
96 hwwrite(vortex->mmio, WT_DELAY(wt, 0), 0); 96 hwwrite(vortex->mmio, WT_DELAY(wt, 0), 0);
@@ -98,7 +98,8 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
98 hwwrite(vortex->mmio, WT_DELAY(wt, 2), 0); 98 hwwrite(vortex->mmio, WT_DELAY(wt, 2), 0);
99 hwwrite(vortex->mmio, WT_DELAY(wt, 3), 0); 99 hwwrite(vortex->mmio, WT_DELAY(wt, 3), 0);
100 100
101 pr_debug( "vortex: WT GMODE: %x\n", hwread(vortex->mmio, WT_GMODE(wt))); 101 dev_dbg(vortex->card->dev, "WT GMODE: %x\n",
102 hwread(vortex->mmio, WT_GMODE(wt)));
102 103
103 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff); 104 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff);
104 hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810); 105 hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810);
@@ -106,7 +107,8 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
106 voice->parm0 = voice->parm1 = 0xcfb23e2f; 107 voice->parm0 = voice->parm1 = 0xcfb23e2f;
107 hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0); 108 hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
108 hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1); 109 hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
109 pr_debug( "vortex: WT GMODE 2 : %x\n", hwread(vortex->mmio, WT_GMODE(wt))); 110 dev_dbg(vortex->card->dev, "WT GMODE 2 : %x\n",
111 hwread(vortex->mmio, WT_GMODE(wt)));
110 return 0; 112 return 0;
111} 113}
112 114
@@ -196,14 +198,15 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
196 198
197 if ((reg == 5) || ((reg >= 7) && (reg <= 10)) || (reg == 0xc)) { 199 if ((reg == 5) || ((reg >= 7) && (reg <= 10)) || (reg == 0xc)) {
198 if (wt >= (NR_WT / NR_WT_PB)) { 200 if (wt >= (NR_WT / NR_WT_PB)) {
199 pr_warn 201 dev_warn(vortex->card->dev,
200 ("vortex: WT SetReg: bank out of range. reg=0x%x, wt=%d\n", 202 "WT SetReg: bank out of range. reg=0x%x, wt=%d\n",
201 reg, wt); 203 reg, wt);
202 return 0; 204 return 0;
203 } 205 }
204 } else { 206 } else {
205 if (wt >= NR_WT) { 207 if (wt >= NR_WT) {
206 pr_err( "vortex: WT SetReg: voice out of range\n"); 208 dev_err(vortex->card->dev,
209 "WT SetReg: voice out of range\n");
207 return 0; 210 return 0;
208 } 211 }
209 } 212 }
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c
index 3878cf5de9a4..e1cf01949fda 100644
--- a/sound/pci/aw2/aw2-alsa.c
+++ b/sound/pci/aw2/aw2-alsa.c
@@ -725,19 +725,10 @@ static int snd_aw2_new_pcm(struct aw2 *chip)
725static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol, 725static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
726 struct snd_ctl_elem_info *uinfo) 726 struct snd_ctl_elem_info *uinfo)
727{ 727{
728 static char *texts[2] = { 728 static const char * const texts[2] = {
729 "Analog", "Digital" 729 "Analog", "Digital"
730 }; 730 };
731 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 731 return snd_ctl_enum_info(uinfo, 1, 2, texts);
732 uinfo->count = 1;
733 uinfo->value.enumerated.items = 2;
734 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) {
735 uinfo->value.enumerated.item =
736 uinfo->value.enumerated.items - 1;
737 }
738 strcpy(uinfo->value.enumerated.name,
739 texts[uinfo->value.enumerated.item]);
740 return 0;
741} 732}
742 733
743static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol, 734static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 5a69e26cb2fb..fdbb9c05c77b 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -1034,11 +1034,6 @@ snd_azf3328_info_mixer_enum(struct snd_kcontrol *kcontrol,
1034 const char * const *p = NULL; 1034 const char * const *p = NULL;
1035 1035
1036 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 1036 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
1037 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1038 uinfo->count = (reg.reg == IDX_MIXER_REC_SELECT) ? 2 : 1;
1039 uinfo->value.enumerated.items = reg.enum_c;
1040 if (uinfo->value.enumerated.item > reg.enum_c - 1U)
1041 uinfo->value.enumerated.item = reg.enum_c - 1U;
1042 if (reg.reg == IDX_MIXER_ADVCTL2) { 1037 if (reg.reg == IDX_MIXER_ADVCTL2) {
1043 switch(reg.lchan_shift) { 1038 switch(reg.lchan_shift) {
1044 case 8: /* modem out sel */ 1039 case 8: /* modem out sel */
@@ -1051,12 +1046,12 @@ snd_azf3328_info_mixer_enum(struct snd_kcontrol *kcontrol,
1051 p = texts4; 1046 p = texts4;
1052 break; 1047 break;
1053 } 1048 }
1054 } else 1049 } else if (reg.reg == IDX_MIXER_REC_SELECT)
1055 if (reg.reg == IDX_MIXER_REC_SELECT)
1056 p = texts3; 1050 p = texts3;
1057 1051
1058 strcpy(uinfo->value.enumerated.name, p[uinfo->value.enumerated.item]); 1052 return snd_ctl_enum_info(uinfo,
1059 return 0; 1053 (reg.reg == IDX_MIXER_REC_SELECT) ? 2 : 1,
1054 reg.enum_c, p);
1060} 1055}
1061 1056
1062static int 1057static int
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index 27de0de90018..68c0eb0a2807 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -185,17 +185,11 @@ static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol,
185static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol, 185static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol,
186 struct snd_ctl_elem_info *uinfo) 186 struct snd_ctl_elem_info *uinfo)
187{ 187{
188 static char *texts[6] = { 188 static const char * const texts[6] = {
189 "IEC958 out", "i2s mixer out", "IEC958 in", "i2s in", "AC97 in", "SRC out" 189 "IEC958 out", "i2s mixer out", "IEC958 in", "i2s in", "AC97 in", "SRC out"
190 }; 190 };
191 191
192 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 192 return snd_ctl_enum_info(uinfo, 1, 6, texts);
193 uinfo->count = 1;
194 uinfo->value.enumerated.items = 6;
195 if (uinfo->value.enumerated.item > 5)
196 uinfo->value.enumerated.item = 5;
197 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
198 return 0;
199} 193}
200 194
201static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol, 195static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol,
@@ -228,17 +222,11 @@ static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol,
228static int snd_ca0106_i2c_capture_source_info(struct snd_kcontrol *kcontrol, 222static int snd_ca0106_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
229 struct snd_ctl_elem_info *uinfo) 223 struct snd_ctl_elem_info *uinfo)
230{ 224{
231 static char *texts[6] = { 225 static const char * const texts[4] = {
232 "Phone", "Mic", "Line in", "Aux" 226 "Phone", "Mic", "Line in", "Aux"
233 }; 227 };
234 228
235 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 229 return snd_ctl_enum_info(uinfo, 1, 4, texts);
236 uinfo->count = 1;
237 uinfo->value.enumerated.items = 4;
238 if (uinfo->value.enumerated.item > 3)
239 uinfo->value.enumerated.item = 3;
240 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
241 return 0;
242} 230}
243 231
244static int snd_ca0106_i2c_capture_source_get(struct snd_kcontrol *kcontrol, 232static int snd_ca0106_i2c_capture_source_get(struct snd_kcontrol *kcontrol,
@@ -273,29 +261,17 @@ static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
273static int snd_ca0106_capture_line_in_side_out_info(struct snd_kcontrol *kcontrol, 261static int snd_ca0106_capture_line_in_side_out_info(struct snd_kcontrol *kcontrol,
274 struct snd_ctl_elem_info *uinfo) 262 struct snd_ctl_elem_info *uinfo)
275{ 263{
276 static char *texts[2] = { "Side out", "Line in" }; 264 static const char * const texts[2] = { "Side out", "Line in" };
277 265
278 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 266 return snd_ctl_enum_info(uinfo, 1, 2, texts);
279 uinfo->count = 1;
280 uinfo->value.enumerated.items = 2;
281 if (uinfo->value.enumerated.item > 1)
282 uinfo->value.enumerated.item = 1;
283 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
284 return 0;
285} 267}
286 268
287static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol, 269static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol,
288 struct snd_ctl_elem_info *uinfo) 270 struct snd_ctl_elem_info *uinfo)
289{ 271{
290 static char *texts[2] = { "Line in", "Mic in" }; 272 static const char * const texts[2] = { "Line in", "Mic in" };
291 273
292 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 274 return snd_ctl_enum_info(uinfo, 1, 2, texts);
293 uinfo->count = 1;
294 uinfo->value.enumerated.items = 2;
295 if (uinfo->value.enumerated.item > 1)
296 uinfo->value.enumerated.item = 1;
297 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
298 return 0;
299} 275}
300 276
301static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol, 277static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index 454659074390..977a59855fa6 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -438,7 +438,9 @@ atc_pcm_playback_position(struct ct_atc *atc, struct ct_atc_pcm *apcm)
438 position = src->ops->get_ca(src); 438 position = src->ops->get_ca(src);
439 439
440 if (position < apcm->vm_block->addr) { 440 if (position < apcm->vm_block->addr) {
441 snd_printdd("ctxfi: bad ca - ca=0x%08x, vba=0x%08x, vbs=0x%08x\n", position, apcm->vm_block->addr, apcm->vm_block->size); 441 dev_dbg(atc->card->dev,
442 "bad ca - ca=0x%08x, vba=0x%08x, vbs=0x%08x\n",
443 position, apcm->vm_block->addr, apcm->vm_block->size);
442 position = apcm->vm_block->addr; 444 position = apcm->vm_block->addr;
443 } 445 }
444 446
@@ -1145,7 +1147,6 @@ static int atc_release_resources(struct ct_atc *atc)
1145 int i; 1147 int i;
1146 struct daio_mgr *daio_mgr = NULL; 1148 struct daio_mgr *daio_mgr = NULL;
1147 struct dao *dao = NULL; 1149 struct dao *dao = NULL;
1148 struct dai *dai = NULL;
1149 struct daio *daio = NULL; 1150 struct daio *daio = NULL;
1150 struct sum_mgr *sum_mgr = NULL; 1151 struct sum_mgr *sum_mgr = NULL;
1151 struct src_mgr *src_mgr = NULL; 1152 struct src_mgr *src_mgr = NULL;
@@ -1172,9 +1173,6 @@ static int atc_release_resources(struct ct_atc *atc)
1172 dao = container_of(daio, struct dao, daio); 1173 dao = container_of(daio, struct dao, daio);
1173 dao->ops->clear_left_input(dao); 1174 dao->ops->clear_left_input(dao);
1174 dao->ops->clear_right_input(dao); 1175 dao->ops->clear_right_input(dao);
1175 } else {
1176 dai = container_of(daio, struct dai, daio);
1177 /* some thing to do for dai ... */
1178 } 1176 }
1179 daio_mgr->put_daio(daio_mgr, daio); 1177 daio_mgr->put_daio(daio_mgr, daio);
1180 } 1178 }
@@ -1299,7 +1297,7 @@ static int atc_identify_card(struct ct_atc *atc, unsigned int ssid)
1299 atc->model = CT20K2_UNKNOWN; 1297 atc->model = CT20K2_UNKNOWN;
1300 } 1298 }
1301 atc->model_name = ct_subsys_name[atc->model]; 1299 atc->model_name = ct_subsys_name[atc->model];
1302 snd_printd("ctxfi: chip %s model %s (%04x:%04x) is found\n", 1300 dev_info(atc->card->dev, "chip %s model %s (%04x:%04x) is found\n",
1303 atc->chip_name, atc->model_name, 1301 atc->chip_name, atc->model_name,
1304 vendor_id, device_id); 1302 vendor_id, device_id);
1305 return 0; 1303 return 0;
diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c
index c1c3f8816fff..9b87dd28de83 100644
--- a/sound/pci/ctxfi/ctdaio.c
+++ b/sound/pci/ctxfi/ctdaio.c
@@ -528,8 +528,6 @@ static int get_daio_rsc(struct daio_mgr *mgr,
528 struct daio **rdaio) 528 struct daio **rdaio)
529{ 529{
530 int err; 530 int err;
531 struct dai *dai = NULL;
532 struct dao *dao = NULL;
533 unsigned long flags; 531 unsigned long flags;
534 532
535 *rdaio = NULL; 533 *rdaio = NULL;
@@ -544,27 +542,30 @@ static int get_daio_rsc(struct daio_mgr *mgr,
544 return err; 542 return err;
545 } 543 }
546 544
545 err = -ENOMEM;
547 /* Allocate mem for daio resource */ 546 /* Allocate mem for daio resource */
548 if (desc->type <= DAIO_OUT_MAX) { 547 if (desc->type <= DAIO_OUT_MAX) {
549 dao = kzalloc(sizeof(*dao), GFP_KERNEL); 548 struct dao *dao = kzalloc(sizeof(*dao), GFP_KERNEL);
550 if (!dao) { 549 if (!dao)
551 err = -ENOMEM;
552 goto error; 550 goto error;
553 } 551
554 err = dao_rsc_init(dao, desc, mgr); 552 err = dao_rsc_init(dao, desc, mgr);
555 if (err) 553 if (err) {
554 kfree(dao);
556 goto error; 555 goto error;
556 }
557 557
558 *rdaio = &dao->daio; 558 *rdaio = &dao->daio;
559 } else { 559 } else {
560 dai = kzalloc(sizeof(*dai), GFP_KERNEL); 560 struct dai *dai = kzalloc(sizeof(*dai), GFP_KERNEL);
561 if (!dai) { 561 if (!dai)
562 err = -ENOMEM;
563 goto error; 562 goto error;
564 } 563
565 err = dai_rsc_init(dai, desc, mgr); 564 err = dai_rsc_init(dai, desc, mgr);
566 if (err) 565 if (err) {
566 kfree(dai);
567 goto error; 567 goto error;
568 }
568 569
569 *rdaio = &dai->daio; 570 *rdaio = &dai->daio;
570 } 571 }
@@ -575,11 +576,6 @@ static int get_daio_rsc(struct daio_mgr *mgr,
575 return 0; 576 return 0;
576 577
577error: 578error:
578 if (dao)
579 kfree(dao);
580 else if (dai)
581 kfree(dai);
582
583 spin_lock_irqsave(&mgr->mgr_lock, flags); 579 spin_lock_irqsave(&mgr->mgr_lock, flags);
584 daio_mgr_put_rsc(&mgr->mgr, desc->type); 580 daio_mgr_put_rsc(&mgr->mgr, desc->type);
585 spin_unlock_irqrestore(&mgr->mgr_lock, flags); 581 spin_unlock_irqrestore(&mgr->mgr_lock, flags);
diff --git a/sound/pci/ctxfi/cttimer.c b/sound/pci/ctxfi/cttimer.c
index 03fb909085af..a5d460453d7b 100644
--- a/sound/pci/ctxfi/cttimer.c
+++ b/sound/pci/ctxfi/cttimer.c
@@ -421,12 +421,12 @@ struct ct_timer *ct_timer_new(struct ct_atc *atc)
421 atimer->atc = atc; 421 atimer->atc = atc;
422 hw = atc->hw; 422 hw = atc->hw;
423 if (!use_system_timer && hw->set_timer_irq) { 423 if (!use_system_timer && hw->set_timer_irq) {
424 snd_printd(KERN_INFO "ctxfi: Use xfi-native timer\n"); 424 dev_info(atc->card->dev, "Use xfi-native timer\n");
425 atimer->ops = &ct_xfitimer_ops; 425 atimer->ops = &ct_xfitimer_ops;
426 hw->irq_callback_data = atimer; 426 hw->irq_callback_data = atimer;
427 hw->irq_callback = ct_timer_interrupt; 427 hw->irq_callback = ct_timer_interrupt;
428 } else { 428 } else {
429 snd_printd(KERN_INFO "ctxfi: Use system timer\n"); 429 dev_info(atc->card->dev, "Use system timer\n");
430 atimer->ops = &ct_systimer_ops; 430 atimer->ops = &ct_systimer_ops;
431 } 431 }
432 return atimer; 432 return atimer;
diff --git a/sound/pci/echoaudio/darla20_dsp.c b/sound/pci/echoaudio/darla20_dsp.c
index 20c7cbc89bb3..febee5bda877 100644
--- a/sound/pci/echoaudio/darla20_dsp.c
+++ b/sound/pci/echoaudio/darla20_dsp.c
@@ -33,12 +33,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
33{ 33{
34 int err; 34 int err;
35 35
36 DE_INIT(("init_hw() - Darla20\n"));
37 if (snd_BUG_ON((subdevice_id & 0xfff0) != DARLA20)) 36 if (snd_BUG_ON((subdevice_id & 0xfff0) != DARLA20))
38 return -ENODEV; 37 return -ENODEV;
39 38
40 if ((err = init_dsp_comm_page(chip))) { 39 if ((err = init_dsp_comm_page(chip))) {
41 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 40 dev_err(chip->card->dev,
41 "init_hw: could not initialize DSP comm page\n");
42 return err; 42 return err;
43 } 43 }
44 44
@@ -57,7 +57,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
57 return err; 57 return err;
58 chip->bad_board = FALSE; 58 chip->bad_board = FALSE;
59 59
60 DE_INIT(("init_hw done\n"));
61 return err; 60 return err;
62} 61}
63 62
diff --git a/sound/pci/echoaudio/darla24_dsp.c b/sound/pci/echoaudio/darla24_dsp.c
index 6da6663e9176..7b4f6fd51b09 100644
--- a/sound/pci/echoaudio/darla24_dsp.c
+++ b/sound/pci/echoaudio/darla24_dsp.c
@@ -33,12 +33,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
33{ 33{
34 int err; 34 int err;
35 35
36 DE_INIT(("init_hw() - Darla24\n"));
37 if (snd_BUG_ON((subdevice_id & 0xfff0) != DARLA24)) 36 if (snd_BUG_ON((subdevice_id & 0xfff0) != DARLA24))
38 return -ENODEV; 37 return -ENODEV;
39 38
40 if ((err = init_dsp_comm_page(chip))) { 39 if ((err = init_dsp_comm_page(chip))) {
41 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 40 dev_err(chip->card->dev,
41 "init_hw: could not initialize DSP comm page\n");
42 return err; 42 return err;
43 } 43 }
44 44
@@ -56,7 +56,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
56 return err; 56 return err;
57 chip->bad_board = FALSE; 57 chip->bad_board = FALSE;
58 58
59 DE_INIT(("init_hw done\n"));
60 return err; 59 return err;
61} 60}
62 61
@@ -128,15 +127,17 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
128 clock = GD24_8000; 127 clock = GD24_8000;
129 break; 128 break;
130 default: 129 default:
131 DE_ACT(("set_sample_rate: Error, invalid sample rate %d\n", 130 dev_err(chip->card->dev,
132 rate)); 131 "set_sample_rate: Error, invalid sample rate %d\n",
132 rate);
133 return -EINVAL; 133 return -EINVAL;
134 } 134 }
135 135
136 if (wait_handshake(chip)) 136 if (wait_handshake(chip))
137 return -EIO; 137 return -EIO;
138 138
139 DE_ACT(("set_sample_rate: %d clock %d\n", rate, clock)); 139 dev_dbg(chip->card->dev,
140 "set_sample_rate: %d clock %d\n", rate, clock);
140 chip->sample_rate = rate; 141 chip->sample_rate = rate;
141 142
142 /* Override the sample rate if this card is set to Echo sync. */ 143 /* Override the sample rate if this card is set to Echo sync. */
diff --git a/sound/pci/echoaudio/echo3g_dsp.c b/sound/pci/echoaudio/echo3g_dsp.c
index 3cdc2ee2d1dd..ae11ce11b1c2 100644
--- a/sound/pci/echoaudio/echo3g_dsp.c
+++ b/sound/pci/echoaudio/echo3g_dsp.c
@@ -46,12 +46,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
46 int err; 46 int err;
47 47
48 local_irq_enable(); 48 local_irq_enable();
49 DE_INIT(("init_hw() - Echo3G\n"));
50 if (snd_BUG_ON((subdevice_id & 0xfff0) != ECHO3G)) 49 if (snd_BUG_ON((subdevice_id & 0xfff0) != ECHO3G))
51 return -ENODEV; 50 return -ENODEV;
52 51
53 if ((err = init_dsp_comm_page(chip))) { 52 if ((err = init_dsp_comm_page(chip))) {
54 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 53 dev_err(chip->card->dev,
54 "init_hw - could not initialize DSP comm page\n");
55 return err; 55 return err;
56 } 56 }
57 57
@@ -98,7 +98,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
98 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL | 98 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
99 ECHOCAPS_HAS_DIGITAL_MODE_ADAT; 99 ECHOCAPS_HAS_DIGITAL_MODE_ADAT;
100 100
101 DE_INIT(("init_hw done\n"));
102 return err; 101 return err;
103} 102}
104 103
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 631aaa4046ad..21228adaa70c 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -48,13 +48,16 @@ static int get_firmware(const struct firmware **fw_entry,
48 48
49#ifdef CONFIG_PM_SLEEP 49#ifdef CONFIG_PM_SLEEP
50 if (chip->fw_cache[fw_index]) { 50 if (chip->fw_cache[fw_index]) {
51 DE_ACT(("firmware requested: %s is cached\n", card_fw[fw_index].data)); 51 dev_dbg(chip->card->dev,
52 "firmware requested: %s is cached\n",
53 card_fw[fw_index].data);
52 *fw_entry = chip->fw_cache[fw_index]; 54 *fw_entry = chip->fw_cache[fw_index];
53 return 0; 55 return 0;
54 } 56 }
55#endif 57#endif
56 58
57 DE_ACT(("firmware requested: %s\n", card_fw[fw_index].data)); 59 dev_dbg(chip->card->dev,
60 "firmware requested: %s\n", card_fw[fw_index].data);
58 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data); 61 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data);
59 err = request_firmware(fw_entry, name, pci_device(chip)); 62 err = request_firmware(fw_entry, name, pci_device(chip));
60 if (err < 0) 63 if (err < 0)
@@ -69,13 +72,13 @@ static int get_firmware(const struct firmware **fw_entry,
69 72
70 73
71 74
72static void free_firmware(const struct firmware *fw_entry) 75static void free_firmware(const struct firmware *fw_entry,
76 struct echoaudio *chip)
73{ 77{
74#ifdef CONFIG_PM_SLEEP 78#ifdef CONFIG_PM_SLEEP
75 DE_ACT(("firmware not released (kept in cache)\n")); 79 dev_dbg(chip->card->dev, "firmware not released (kept in cache)\n");
76#else 80#else
77 release_firmware(fw_entry); 81 release_firmware(fw_entry);
78 DE_ACT(("firmware released\n"));
79#endif 82#endif
80} 83}
81 84
@@ -89,10 +92,9 @@ static void free_firmware_cache(struct echoaudio *chip)
89 for (i = 0; i < 8 ; i++) 92 for (i = 0; i < 8 ; i++)
90 if (chip->fw_cache[i]) { 93 if (chip->fw_cache[i]) {
91 release_firmware(chip->fw_cache[i]); 94 release_firmware(chip->fw_cache[i]);
92 DE_ACT(("release_firmware(%d)\n", i)); 95 dev_dbg(chip->card->dev, "release_firmware(%d)\n", i);
93 } 96 }
94 97
95 DE_ACT(("firmware_cache released\n"));
96#endif 98#endif
97} 99}
98 100
@@ -286,7 +288,7 @@ static int pcm_open(struct snd_pcm_substream *substream,
286 288
287 /* Set up hw capabilities and contraints */ 289 /* Set up hw capabilities and contraints */
288 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware)); 290 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
289 DE_HWP(("max_channels=%d\n", max_channels)); 291 dev_dbg(chip->card->dev, "max_channels=%d\n", max_channels);
290 pipe->constr.list = channels_list; 292 pipe->constr.list = channels_list;
291 pipe->constr.mask = 0; 293 pipe->constr.mask = 0;
292 for (i = 0; channels_list[i] <= max_channels; i++); 294 for (i = 0; channels_list[i] <= max_channels; i++);
@@ -336,7 +338,7 @@ static int pcm_open(struct snd_pcm_substream *substream,
336 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 338 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
337 snd_dma_pci_data(chip->pci), 339 snd_dma_pci_data(chip->pci),
338 PAGE_SIZE, &pipe->sgpage)) < 0) { 340 PAGE_SIZE, &pipe->sgpage)) < 0) {
339 DE_HWP(("s-g list allocation failed\n")); 341 dev_err(chip->card->dev, "s-g list allocation failed\n");
340 return err; 342 return err;
341 } 343 }
342 344
@@ -350,7 +352,6 @@ static int pcm_analog_in_open(struct snd_pcm_substream *substream)
350 struct echoaudio *chip = snd_pcm_substream_chip(substream); 352 struct echoaudio *chip = snd_pcm_substream_chip(substream);
351 int err; 353 int err;
352 354
353 DE_ACT(("pcm_analog_in_open\n"));
354 if ((err = pcm_open(substream, num_analog_busses_in(chip) - 355 if ((err = pcm_open(substream, num_analog_busses_in(chip) -
355 substream->number)) < 0) 356 substream->number)) < 0)
356 return err; 357 return err;
@@ -367,9 +368,9 @@ static int pcm_analog_in_open(struct snd_pcm_substream *substream)
367 atomic_inc(&chip->opencount); 368 atomic_inc(&chip->opencount);
368 if (atomic_read(&chip->opencount) > 1 && chip->rate_set) 369 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
369 chip->can_set_rate=0; 370 chip->can_set_rate=0;
370 DE_HWP(("pcm_analog_in_open cs=%d oc=%d r=%d\n", 371 dev_dbg(chip->card->dev, "pcm_analog_in_open cs=%d oc=%d r=%d\n",
371 chip->can_set_rate, atomic_read(&chip->opencount), 372 chip->can_set_rate, atomic_read(&chip->opencount),
372 chip->sample_rate)); 373 chip->sample_rate);
373 return 0; 374 return 0;
374} 375}
375 376
@@ -385,7 +386,6 @@ static int pcm_analog_out_open(struct snd_pcm_substream *substream)
385#else 386#else
386 max_channels = num_analog_busses_out(chip); 387 max_channels = num_analog_busses_out(chip);
387#endif 388#endif
388 DE_ACT(("pcm_analog_out_open\n"));
389 if ((err = pcm_open(substream, max_channels - substream->number)) < 0) 389 if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
390 return err; 390 return err;
391 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, 391 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
@@ -403,9 +403,9 @@ static int pcm_analog_out_open(struct snd_pcm_substream *substream)
403 atomic_inc(&chip->opencount); 403 atomic_inc(&chip->opencount);
404 if (atomic_read(&chip->opencount) > 1 && chip->rate_set) 404 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
405 chip->can_set_rate=0; 405 chip->can_set_rate=0;
406 DE_HWP(("pcm_analog_out_open cs=%d oc=%d r=%d\n", 406 dev_dbg(chip->card->dev, "pcm_analog_out_open cs=%d oc=%d r=%d\n",
407 chip->can_set_rate, atomic_read(&chip->opencount), 407 chip->can_set_rate, atomic_read(&chip->opencount),
408 chip->sample_rate)); 408 chip->sample_rate);
409 return 0; 409 return 0;
410} 410}
411 411
@@ -418,7 +418,6 @@ static int pcm_digital_in_open(struct snd_pcm_substream *substream)
418 struct echoaudio *chip = snd_pcm_substream_chip(substream); 418 struct echoaudio *chip = snd_pcm_substream_chip(substream);
419 int err, max_channels; 419 int err, max_channels;
420 420
421 DE_ACT(("pcm_digital_in_open\n"));
422 max_channels = num_digital_busses_in(chip) - substream->number; 421 max_channels = num_digital_busses_in(chip) - substream->number;
423 mutex_lock(&chip->mode_mutex); 422 mutex_lock(&chip->mode_mutex);
424 if (chip->digital_mode == DIGITAL_MODE_ADAT) 423 if (chip->digital_mode == DIGITAL_MODE_ADAT)
@@ -460,7 +459,6 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream)
460 struct echoaudio *chip = snd_pcm_substream_chip(substream); 459 struct echoaudio *chip = snd_pcm_substream_chip(substream);
461 int err, max_channels; 460 int err, max_channels;
462 461
463 DE_ACT(("pcm_digital_out_open\n"));
464 max_channels = num_digital_busses_out(chip) - substream->number; 462 max_channels = num_digital_busses_out(chip) - substream->number;
465 mutex_lock(&chip->mode_mutex); 463 mutex_lock(&chip->mode_mutex);
466 if (chip->digital_mode == DIGITAL_MODE_ADAT) 464 if (chip->digital_mode == DIGITAL_MODE_ADAT)
@@ -507,18 +505,17 @@ static int pcm_close(struct snd_pcm_substream *substream)
507 /* Nothing to do here. Audio is already off and pipe will be 505 /* Nothing to do here. Audio is already off and pipe will be
508 * freed by its callback 506 * freed by its callback
509 */ 507 */
510 DE_ACT(("pcm_close\n"));
511 508
512 atomic_dec(&chip->opencount); 509 atomic_dec(&chip->opencount);
513 oc = atomic_read(&chip->opencount); 510 oc = atomic_read(&chip->opencount);
514 DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc, 511 dev_dbg(chip->card->dev, "pcm_close oc=%d cs=%d rs=%d\n", oc,
515 chip->can_set_rate, chip->rate_set)); 512 chip->can_set_rate, chip->rate_set);
516 if (oc < 2) 513 if (oc < 2)
517 chip->can_set_rate = 1; 514 chip->can_set_rate = 1;
518 if (oc == 0) 515 if (oc == 0)
519 chip->rate_set = 0; 516 chip->rate_set = 0;
520 DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc, 517 dev_dbg(chip->card->dev, "pcm_close2 oc=%d cs=%d rs=%d\n", oc,
521 chip->can_set_rate,chip->rate_set)); 518 chip->can_set_rate, chip->rate_set);
522 519
523 return 0; 520 return 0;
524} 521}
@@ -542,7 +539,7 @@ static int init_engine(struct snd_pcm_substream *substream,
542 */ 539 */
543 spin_lock_irq(&chip->lock); 540 spin_lock_irq(&chip->lock);
544 if (pipe->index >= 0) { 541 if (pipe->index >= 0) {
545 DE_HWP(("hwp_ie free(%d)\n", pipe->index)); 542 dev_dbg(chip->card->dev, "hwp_ie free(%d)\n", pipe->index);
546 err = free_pipes(chip, pipe); 543 err = free_pipes(chip, pipe);
547 snd_BUG_ON(err); 544 snd_BUG_ON(err);
548 chip->substream[pipe->index] = NULL; 545 chip->substream[pipe->index] = NULL;
@@ -551,16 +548,17 @@ static int init_engine(struct snd_pcm_substream *substream,
551 err = allocate_pipes(chip, pipe, pipe_index, interleave); 548 err = allocate_pipes(chip, pipe, pipe_index, interleave);
552 if (err < 0) { 549 if (err < 0) {
553 spin_unlock_irq(&chip->lock); 550 spin_unlock_irq(&chip->lock);
554 DE_ACT((KERN_NOTICE "allocate_pipes(%d) err=%d\n", 551 dev_err(chip->card->dev, "allocate_pipes(%d) err=%d\n",
555 pipe_index, err)); 552 pipe_index, err);
556 return err; 553 return err;
557 } 554 }
558 spin_unlock_irq(&chip->lock); 555 spin_unlock_irq(&chip->lock);
559 DE_ACT((KERN_NOTICE "allocate_pipes()=%d\n", pipe_index)); 556 dev_dbg(chip->card->dev, "allocate_pipes()=%d\n", pipe_index);
560 557
561 DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n", 558 dev_dbg(chip->card->dev,
559 "pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
562 params_buffer_bytes(hw_params), params_periods(hw_params), 560 params_buffer_bytes(hw_params), params_periods(hw_params),
563 params_period_bytes(hw_params))); 561 params_period_bytes(hw_params));
564 err = snd_pcm_lib_malloc_pages(substream, 562 err = snd_pcm_lib_malloc_pages(substream,
565 params_buffer_bytes(hw_params)); 563 params_buffer_bytes(hw_params));
566 if (err < 0) { 564 if (err < 0) {
@@ -615,7 +613,6 @@ static int init_engine(struct snd_pcm_substream *substream,
615 spin_lock_irq(&chip->lock); 613 spin_lock_irq(&chip->lock);
616 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den); 614 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
617 spin_unlock_irq(&chip->lock); 615 spin_unlock_irq(&chip->lock);
618 DE_HWP(("pcm_hw_params ok\n"));
619 return 0; 616 return 0;
620} 617}
621 618
@@ -679,14 +676,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
679 676
680 spin_lock_irq(&chip->lock); 677 spin_lock_irq(&chip->lock);
681 if (pipe->index >= 0) { 678 if (pipe->index >= 0) {
682 DE_HWP(("pcm_hw_free(%d)\n", pipe->index)); 679 dev_dbg(chip->card->dev, "pcm_hw_free(%d)\n", pipe->index);
683 free_pipes(chip, pipe); 680 free_pipes(chip, pipe);
684 chip->substream[pipe->index] = NULL; 681 chip->substream[pipe->index] = NULL;
685 pipe->index = -1; 682 pipe->index = -1;
686 } 683 }
687 spin_unlock_irq(&chip->lock); 684 spin_unlock_irq(&chip->lock);
688 685
689 DE_HWP(("pcm_hw_freed\n"));
690 snd_pcm_lib_free_pages(substream); 686 snd_pcm_lib_free_pages(substream);
691 return 0; 687 return 0;
692} 688}
@@ -700,8 +696,8 @@ static int pcm_prepare(struct snd_pcm_substream *substream)
700 struct audioformat format; 696 struct audioformat format;
701 int pipe_index = ((struct audiopipe *)runtime->private_data)->index; 697 int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
702 698
703 DE_HWP(("Prepare rate=%d format=%d channels=%d\n", 699 dev_dbg(chip->card->dev, "Prepare rate=%d format=%d channels=%d\n",
704 runtime->rate, runtime->format, runtime->channels)); 700 runtime->rate, runtime->format, runtime->channels);
705 format.interleave = runtime->channels; 701 format.interleave = runtime->channels;
706 format.data_are_bigendian = 0; 702 format.data_are_bigendian = 0;
707 format.mono_to_stereo = 0; 703 format.mono_to_stereo = 0;
@@ -721,8 +717,9 @@ static int pcm_prepare(struct snd_pcm_substream *substream)
721 format.bits_per_sample = 32; 717 format.bits_per_sample = 32;
722 break; 718 break;
723 default: 719 default:
724 DE_HWP(("Prepare error: unsupported format %d\n", 720 dev_err(chip->card->dev,
725 runtime->format)); 721 "Prepare error: unsupported format %d\n",
722 runtime->format);
726 return -EINVAL; 723 return -EINVAL;
727 } 724 }
728 725
@@ -757,10 +754,8 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
757 spin_lock(&chip->lock); 754 spin_lock(&chip->lock);
758 switch (cmd) { 755 switch (cmd) {
759 case SNDRV_PCM_TRIGGER_RESUME: 756 case SNDRV_PCM_TRIGGER_RESUME:
760 DE_ACT(("pcm_trigger resume\n"));
761 case SNDRV_PCM_TRIGGER_START: 757 case SNDRV_PCM_TRIGGER_START:
762 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 758 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
763 DE_ACT(("pcm_trigger start\n"));
764 for (i = 0; i < DSP_MAXPIPES; i++) { 759 for (i = 0; i < DSP_MAXPIPES; i++) {
765 if (channelmask & (1 << i)) { 760 if (channelmask & (1 << i)) {
766 pipe = chip->substream[i]->runtime->private_data; 761 pipe = chip->substream[i]->runtime->private_data;
@@ -782,9 +777,7 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
782 chip->pipe_cyclic_mask); 777 chip->pipe_cyclic_mask);
783 break; 778 break;
784 case SNDRV_PCM_TRIGGER_SUSPEND: 779 case SNDRV_PCM_TRIGGER_SUSPEND:
785 DE_ACT(("pcm_trigger suspend\n"));
786 case SNDRV_PCM_TRIGGER_STOP: 780 case SNDRV_PCM_TRIGGER_STOP:
787 DE_ACT(("pcm_trigger stop\n"));
788 for (i = 0; i < DSP_MAXPIPES; i++) { 781 for (i = 0; i < DSP_MAXPIPES; i++) {
789 if (channelmask & (1 << i)) { 782 if (channelmask & (1 << i)) {
790 pipe = chip->substream[i]->runtime->private_data; 783 pipe = chip->substream[i]->runtime->private_data;
@@ -794,7 +787,6 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
794 err = stop_transport(chip, channelmask); 787 err = stop_transport(chip, channelmask);
795 break; 788 break;
796 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 789 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
797 DE_ACT(("pcm_trigger pause\n"));
798 for (i = 0; i < DSP_MAXPIPES; i++) { 790 for (i = 0; i < DSP_MAXPIPES; i++) {
799 if (channelmask & (1 << i)) { 791 if (channelmask & (1 << i)) {
800 pipe = chip->substream[i]->runtime->private_data; 792 pipe = chip->substream[i]->runtime->private_data;
@@ -931,7 +923,6 @@ static int snd_echo_new_pcm(struct echoaudio *chip)
931 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops); 923 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
932 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0) 924 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
933 return err; 925 return err;
934 DE_INIT(("Analog PCM ok\n"));
935 926
936#ifdef ECHOCARD_HAS_DIGITAL_IO 927#ifdef ECHOCARD_HAS_DIGITAL_IO
937 /* PCM#1 Digital inputs, no outputs */ 928 /* PCM#1 Digital inputs, no outputs */
@@ -944,7 +935,6 @@ static int snd_echo_new_pcm(struct echoaudio *chip)
944 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops); 935 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
945 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0) 936 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
946 return err; 937 return err;
947 DE_INIT(("Digital PCM ok\n"));
948#endif /* ECHOCARD_HAS_DIGITAL_IO */ 938#endif /* ECHOCARD_HAS_DIGITAL_IO */
949 939
950#else /* ECHOCARD_HAS_VMIXER */ 940#else /* ECHOCARD_HAS_VMIXER */
@@ -966,7 +956,6 @@ static int snd_echo_new_pcm(struct echoaudio *chip)
966 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops); 956 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
967 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0) 957 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
968 return err; 958 return err;
969 DE_INIT(("Analog PCM ok\n"));
970 959
971#ifdef ECHOCARD_HAS_DIGITAL_IO 960#ifdef ECHOCARD_HAS_DIGITAL_IO
972 /* PCM#1 Digital i/o */ 961 /* PCM#1 Digital i/o */
@@ -981,7 +970,6 @@ static int snd_echo_new_pcm(struct echoaudio *chip)
981 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops); 970 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
982 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0) 971 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
983 return err; 972 return err;
984 DE_INIT(("Digital PCM ok\n"));
985#endif /* ECHOCARD_HAS_DIGITAL_IO */ 973#endif /* ECHOCARD_HAS_DIGITAL_IO */
986 974
987#endif /* ECHOCARD_HAS_VMIXER */ 975#endif /* ECHOCARD_HAS_VMIXER */
@@ -1416,21 +1404,14 @@ static struct snd_kcontrol_new snd_echo_vmixer = {
1416static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol, 1404static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1417 struct snd_ctl_elem_info *uinfo) 1405 struct snd_ctl_elem_info *uinfo)
1418{ 1406{
1419 static char *names[4] = { 1407 static const char * const names[4] = {
1420 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical", 1408 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1421 "S/PDIF Cdrom" 1409 "S/PDIF Cdrom"
1422 }; 1410 };
1423 struct echoaudio *chip; 1411 struct echoaudio *chip;
1424 1412
1425 chip = snd_kcontrol_chip(kcontrol); 1413 chip = snd_kcontrol_chip(kcontrol);
1426 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1414 return snd_ctl_enum_info(uinfo, 1, chip->num_digital_modes, names);
1427 uinfo->value.enumerated.items = chip->num_digital_modes;
1428 uinfo->count = 1;
1429 if (uinfo->value.enumerated.item >= chip->num_digital_modes)
1430 uinfo->value.enumerated.item = chip->num_digital_modes - 1;
1431 strcpy(uinfo->value.enumerated.name, names[
1432 chip->digital_mode_list[uinfo->value.enumerated.item]]);
1433 return 0;
1434} 1415}
1435 1416
1436static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol, 1417static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
@@ -1481,7 +1462,8 @@ static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1481 snd_ctl_notify(chip->card, 1462 snd_ctl_notify(chip->card,
1482 SNDRV_CTL_EVENT_MASK_VALUE, 1463 SNDRV_CTL_EVENT_MASK_VALUE,
1483 &chip->clock_src_ctl->id); 1464 &chip->clock_src_ctl->id);
1484 DE_ACT(("SDM() =%d\n", changed)); 1465 dev_dbg(chip->card->dev,
1466 "SDM() =%d\n", changed);
1485 } 1467 }
1486 if (changed >= 0) 1468 if (changed >= 0)
1487 changed = 1; /* No errors */ 1469 changed = 1; /* No errors */
@@ -1509,16 +1491,9 @@ static struct snd_kcontrol_new snd_echo_digital_mode_switch = {
1509static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol, 1491static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1510 struct snd_ctl_elem_info *uinfo) 1492 struct snd_ctl_elem_info *uinfo)
1511{ 1493{
1512 static char *names[2] = {"Consumer", "Professional"}; 1494 static const char * const names[2] = {"Consumer", "Professional"};
1513 1495
1514 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1496 return snd_ctl_enum_info(uinfo, 1, 2, names);
1515 uinfo->value.enumerated.items = 2;
1516 uinfo->count = 1;
1517 if (uinfo->value.enumerated.item)
1518 uinfo->value.enumerated.item = 1;
1519 strcpy(uinfo->value.enumerated.name,
1520 names[uinfo->value.enumerated.item]);
1521 return 0;
1522} 1497}
1523 1498
1524static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol, 1499static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
@@ -1566,21 +1541,14 @@ static struct snd_kcontrol_new snd_echo_spdif_mode_switch = {
1566static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol, 1541static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1567 struct snd_ctl_elem_info *uinfo) 1542 struct snd_ctl_elem_info *uinfo)
1568{ 1543{
1569 static char *names[8] = { 1544 static const char * const names[8] = {
1570 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync", 1545 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1571 "ESync96", "MTC" 1546 "ESync96", "MTC"
1572 }; 1547 };
1573 struct echoaudio *chip; 1548 struct echoaudio *chip;
1574 1549
1575 chip = snd_kcontrol_chip(kcontrol); 1550 chip = snd_kcontrol_chip(kcontrol);
1576 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1551 return snd_ctl_enum_info(uinfo, 1, chip->num_clock_sources, names);
1577 uinfo->value.enumerated.items = chip->num_clock_sources;
1578 uinfo->count = 1;
1579 if (uinfo->value.enumerated.item >= chip->num_clock_sources)
1580 uinfo->value.enumerated.item = chip->num_clock_sources - 1;
1581 strcpy(uinfo->value.enumerated.name, names[
1582 chip->clock_source_list[uinfo->value.enumerated.item]]);
1583 return 0;
1584} 1552}
1585 1553
1586static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol, 1554static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
@@ -1622,7 +1590,8 @@ static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1622 } 1590 }
1623 1591
1624 if (changed < 0) 1592 if (changed < 0)
1625 DE_ACT(("seticlk val%d err 0x%x\n", dclock, changed)); 1593 dev_dbg(chip->card->dev,
1594 "seticlk val%d err 0x%x\n", dclock, changed);
1626 1595
1627 return changed; 1596 return changed;
1628} 1597}
@@ -1879,7 +1848,7 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1879#ifdef ECHOCARD_HAS_MIDI 1848#ifdef ECHOCARD_HAS_MIDI
1880 if (st > 0 && chip->midi_in) { 1849 if (st > 0 && chip->midi_in) {
1881 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st); 1850 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1882 DE_MID(("rawmidi_iread=%d\n", st)); 1851 dev_dbg(chip->card->dev, "rawmidi_iread=%d\n", st);
1883 } 1852 }
1884#endif 1853#endif
1885 return IRQ_HANDLED; 1854 return IRQ_HANDLED;
@@ -1894,10 +1863,8 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1894 1863
1895static int snd_echo_free(struct echoaudio *chip) 1864static int snd_echo_free(struct echoaudio *chip)
1896{ 1865{
1897 DE_INIT(("Stop DSP...\n"));
1898 if (chip->comm_page) 1866 if (chip->comm_page)
1899 rest_in_peace(chip); 1867 rest_in_peace(chip);
1900 DE_INIT(("Stopped.\n"));
1901 1868
1902 if (chip->irq >= 0) 1869 if (chip->irq >= 0)
1903 free_irq(chip->irq, chip); 1870 free_irq(chip->irq, chip);
@@ -1908,17 +1875,14 @@ static int snd_echo_free(struct echoaudio *chip)
1908 if (chip->dsp_registers) 1875 if (chip->dsp_registers)
1909 iounmap(chip->dsp_registers); 1876 iounmap(chip->dsp_registers);
1910 1877
1911 if (chip->iores) 1878 release_and_free_resource(chip->iores);
1912 release_and_free_resource(chip->iores);
1913 1879
1914 DE_INIT(("MMIO freed.\n"));
1915 1880
1916 pci_disable_device(chip->pci); 1881 pci_disable_device(chip->pci);
1917 1882
1918 /* release chip data */ 1883 /* release chip data */
1919 free_firmware_cache(chip); 1884 free_firmware_cache(chip);
1920 kfree(chip); 1885 kfree(chip);
1921 DE_INIT(("Chip freed.\n"));
1922 return 0; 1886 return 0;
1923} 1887}
1924 1888
@@ -1928,7 +1892,6 @@ static int snd_echo_dev_free(struct snd_device *device)
1928{ 1892{
1929 struct echoaudio *chip = device->device_data; 1893 struct echoaudio *chip = device->device_data;
1930 1894
1931 DE_INIT(("snd_echo_dev_free()...\n"));
1932 return snd_echo_free(chip); 1895 return snd_echo_free(chip);
1933} 1896}
1934 1897
@@ -1961,7 +1924,7 @@ static int snd_echo_create(struct snd_card *card,
1961 pci_disable_device(pci); 1924 pci_disable_device(pci);
1962 return -ENOMEM; 1925 return -ENOMEM;
1963 } 1926 }
1964 DE_INIT(("chip=%p\n", chip)); 1927 dev_dbg(card->dev, "chip=%p\n", chip);
1965 spin_lock_init(&chip->lock); 1928 spin_lock_init(&chip->lock);
1966 chip->card = card; 1929 chip->card = card;
1967 chip->pci = pci; 1930 chip->pci = pci;
@@ -1998,8 +1961,8 @@ static int snd_echo_create(struct snd_card *card,
1998 return -EBUSY; 1961 return -EBUSY;
1999 } 1962 }
2000 chip->irq = pci->irq; 1963 chip->irq = pci->irq;
2001 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n", 1964 dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n",
2002 chip->pci, chip->irq, chip->pci->subsystem_device)); 1965 chip->pci, chip->irq, chip->pci->subsystem_device);
2003 1966
2004 /* Create the DSP comm page - this is the area of memory used for most 1967 /* Create the DSP comm page - this is the area of memory used for most
2005 of the communication with the DSP, which accesses it via bus mastering */ 1968 of the communication with the DSP, which accesses it via bus mastering */
@@ -2017,11 +1980,10 @@ static int snd_echo_create(struct snd_card *card,
2017 if (err >= 0) 1980 if (err >= 0)
2018 err = set_mixer_defaults(chip); 1981 err = set_mixer_defaults(chip);
2019 if (err < 0) { 1982 if (err < 0) {
2020 DE_INIT(("init_hw err=%d\n", err)); 1983 dev_err(card->dev, "init_hw err=%d\n", err);
2021 snd_echo_free(chip); 1984 snd_echo_free(chip);
2022 return err; 1985 return err;
2023 } 1986 }
2024 DE_INIT(("Card init OK\n"));
2025 1987
2026 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1988 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2027 snd_echo_free(chip); 1989 snd_echo_free(chip);
@@ -2051,7 +2013,6 @@ static int snd_echo_probe(struct pci_dev *pci,
2051 return -ENOENT; 2013 return -ENOENT;
2052 } 2014 }
2053 2015
2054 DE_INIT(("Echoaudio driver starting...\n"));
2055 i = 0; 2016 i = 0;
2056 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 2017 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2057 0, &card); 2018 0, &card);
@@ -2204,7 +2165,6 @@ static int snd_echo_suspend(struct device *dev)
2204 struct pci_dev *pci = to_pci_dev(dev); 2165 struct pci_dev *pci = to_pci_dev(dev);
2205 struct echoaudio *chip = dev_get_drvdata(dev); 2166 struct echoaudio *chip = dev_get_drvdata(dev);
2206 2167
2207 DE_INIT(("suspend start\n"));
2208 snd_pcm_suspend_all(chip->analog_pcm); 2168 snd_pcm_suspend_all(chip->analog_pcm);
2209 snd_pcm_suspend_all(chip->digital_pcm); 2169 snd_pcm_suspend_all(chip->digital_pcm);
2210 2170
@@ -2231,7 +2191,6 @@ static int snd_echo_suspend(struct device *dev)
2231 pci_save_state(pci); 2191 pci_save_state(pci);
2232 pci_disable_device(pci); 2192 pci_disable_device(pci);
2233 2193
2234 DE_INIT(("suspend done\n"));
2235 return 0; 2194 return 0;
2236} 2195}
2237 2196
@@ -2245,7 +2204,6 @@ static int snd_echo_resume(struct device *dev)
2245 u32 pipe_alloc_mask; 2204 u32 pipe_alloc_mask;
2246 int err; 2205 int err;
2247 2206
2248 DE_INIT(("resume start\n"));
2249 pci_restore_state(pci); 2207 pci_restore_state(pci);
2250 commpage_bak = kmalloc(sizeof(struct echoaudio), GFP_KERNEL); 2208 commpage_bak = kmalloc(sizeof(struct echoaudio), GFP_KERNEL);
2251 if (commpage_bak == NULL) 2209 if (commpage_bak == NULL)
@@ -2256,11 +2214,10 @@ static int snd_echo_resume(struct device *dev)
2256 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); 2214 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
2257 if (err < 0) { 2215 if (err < 0) {
2258 kfree(commpage_bak); 2216 kfree(commpage_bak);
2259 DE_INIT(("resume init_hw err=%d\n", err)); 2217 dev_err(dev, "resume init_hw err=%d\n", err);
2260 snd_echo_free(chip); 2218 snd_echo_free(chip);
2261 return err; 2219 return err;
2262 } 2220 }
2263 DE_INIT(("resume init OK\n"));
2264 2221
2265 /* Temporarily set chip->pipe_alloc_mask=0 otherwise 2222 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2266 * restore_dsp_settings() fails. 2223 * restore_dsp_settings() fails.
@@ -2273,7 +2230,6 @@ static int snd_echo_resume(struct device *dev)
2273 kfree(commpage_bak); 2230 kfree(commpage_bak);
2274 return err; 2231 return err;
2275 } 2232 }
2276 DE_INIT(("resume restore OK\n"));
2277 2233
2278 memcpy(&commpage->audio_format, &commpage_bak->audio_format, 2234 memcpy(&commpage->audio_format, &commpage_bak->audio_format,
2279 sizeof(commpage->audio_format)); 2235 sizeof(commpage->audio_format));
@@ -2290,7 +2246,7 @@ static int snd_echo_resume(struct device *dev)
2290 return -EBUSY; 2246 return -EBUSY;
2291 } 2247 }
2292 chip->irq = pci->irq; 2248 chip->irq = pci->irq;
2293 DE_INIT(("resume irq=%d\n", chip->irq)); 2249 dev_dbg(dev, "resume irq=%d\n", chip->irq);
2294 2250
2295#ifdef ECHOCARD_HAS_MIDI 2251#ifdef ECHOCARD_HAS_MIDI
2296 if (chip->midi_input_enabled) 2252 if (chip->midi_input_enabled)
@@ -2299,7 +2255,6 @@ static int snd_echo_resume(struct device *dev)
2299 snd_echo_midi_output_trigger(chip->midi_out, 1); 2255 snd_echo_midi_output_trigger(chip->midi_out, 1);
2300#endif 2256#endif
2301 2257
2302 DE_INIT(("resume done\n"));
2303 return 0; 2258 return 0;
2304} 2259}
2305 2260
diff --git a/sound/pci/echoaudio/echoaudio.h b/sound/pci/echoaudio/echoaudio.h
index b86b88da81cd..32515227a692 100644
--- a/sound/pci/echoaudio/echoaudio.h
+++ b/sound/pci/echoaudio/echoaudio.h
@@ -295,34 +295,6 @@
295#define PIPE_STATE_PENDING 3 /* Pipe has pending start */ 295#define PIPE_STATE_PENDING 3 /* Pipe has pending start */
296 296
297 297
298/* Debug initialization */
299#ifdef CONFIG_SND_DEBUG
300#define DE_INIT(x) snd_printk x
301#else
302#define DE_INIT(x)
303#endif
304
305/* Debug hw_params callbacks */
306#ifdef CONFIG_SND_DEBUG
307#define DE_HWP(x) snd_printk x
308#else
309#define DE_HWP(x)
310#endif
311
312/* Debug normal activity (open, start, stop...) */
313#ifdef CONFIG_SND_DEBUG
314#define DE_ACT(x) snd_printk x
315#else
316#define DE_ACT(x)
317#endif
318
319/* Debug midi activity */
320#ifdef CONFIG_SND_DEBUG
321#define DE_MID(x) snd_printk x
322#else
323#define DE_MID(x)
324#endif
325
326 298
327struct audiopipe { 299struct audiopipe {
328 volatile u32 *dma_counter; /* Commpage register that contains 300 volatile u32 *dma_counter; /* Commpage register that contains
@@ -468,7 +440,8 @@ static int wait_handshake(struct echoaudio *chip);
468static int send_vector(struct echoaudio *chip, u32 command); 440static int send_vector(struct echoaudio *chip, u32 command);
469static int get_firmware(const struct firmware **fw_entry, 441static int get_firmware(const struct firmware **fw_entry,
470 struct echoaudio *chip, const short fw_index); 442 struct echoaudio *chip, const short fw_index);
471static void free_firmware(const struct firmware *fw_entry); 443static void free_firmware(const struct firmware *fw_entry,
444 struct echoaudio *chip);
472 445
473#ifdef ECHOCARD_HAS_MIDI 446#ifdef ECHOCARD_HAS_MIDI
474static int enable_midi_input(struct echoaudio *chip, char enable); 447static int enable_midi_input(struct echoaudio *chip, char enable);
diff --git a/sound/pci/echoaudio/echoaudio_3g.c b/sound/pci/echoaudio/echoaudio_3g.c
index 658db44ef746..2fa66dc3e675 100644
--- a/sound/pci/echoaudio/echoaudio_3g.c
+++ b/sound/pci/echoaudio/echoaudio_3g.c
@@ -51,7 +51,7 @@ static int check_asic_status(struct echoaudio *chip)
51 } 51 }
52 52
53 box_status = le32_to_cpu(chip->comm_page->ext_box_status); 53 box_status = le32_to_cpu(chip->comm_page->ext_box_status);
54 DE_INIT(("box_status=%x\n", box_status)); 54 dev_dbg(chip->card->dev, "box_status=%x\n", box_status);
55 if (box_status == E3G_ASIC_NOT_LOADED) 55 if (box_status == E3G_ASIC_NOT_LOADED)
56 return -ENODEV; 56 return -ENODEV;
57 57
@@ -76,7 +76,8 @@ static int write_control_reg(struct echoaudio *chip, u32 ctl, u32 frq,
76 if (wait_handshake(chip)) 76 if (wait_handshake(chip))
77 return -EIO; 77 return -EIO;
78 78
79 DE_ACT(("WriteControlReg: Setting 0x%x, 0x%x\n", ctl, frq)); 79 dev_dbg(chip->card->dev,
80 "WriteControlReg: Setting 0x%x, 0x%x\n", ctl, frq);
80 81
81 ctl = cpu_to_le32(ctl); 82 ctl = cpu_to_le32(ctl);
82 frq = cpu_to_le32(frq); 83 frq = cpu_to_le32(frq);
@@ -89,7 +90,7 @@ static int write_control_reg(struct echoaudio *chip, u32 ctl, u32 frq,
89 return send_vector(chip, DSP_VC_WRITE_CONTROL_REG); 90 return send_vector(chip, DSP_VC_WRITE_CONTROL_REG);
90 } 91 }
91 92
92 DE_ACT(("WriteControlReg: not written, no change\n")); 93 dev_dbg(chip->card->dev, "WriteControlReg: not written, no change\n");
93 return 0; 94 return 0;
94} 95}
95 96
@@ -258,8 +259,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
258 259
259 /* Only set the clock for internal mode. */ 260 /* Only set the clock for internal mode. */
260 if (chip->input_clock != ECHO_CLOCK_INTERNAL) { 261 if (chip->input_clock != ECHO_CLOCK_INTERNAL) {
261 DE_ACT(("set_sample_rate: Cannot set sample rate - " 262 dev_warn(chip->card->dev,
262 "clock not set to CLK_CLOCKININTERNAL\n")); 263 "Cannot set sample rate - clock not set to CLK_CLOCKININTERNAL\n");
263 /* Save the rate anyhow */ 264 /* Save the rate anyhow */
264 chip->comm_page->sample_rate = cpu_to_le32(rate); 265 chip->comm_page->sample_rate = cpu_to_le32(rate);
265 chip->sample_rate = rate; 266 chip->sample_rate = rate;
@@ -313,7 +314,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
313 314
314 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */ 315 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */
315 chip->sample_rate = rate; 316 chip->sample_rate = rate;
316 DE_ACT(("SetSampleRate: %d clock %x\n", rate, control_reg)); 317 dev_dbg(chip->card->dev,
318 "SetSampleRate: %d clock %x\n", rate, control_reg);
317 319
318 /* Tell the DSP about it - DSP reads both control reg & freq reg */ 320 /* Tell the DSP about it - DSP reads both control reg & freq reg */
319 return write_control_reg(chip, control_reg, frq_reg, 0); 321 return write_control_reg(chip, control_reg, frq_reg, 0);
@@ -326,7 +328,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
326{ 328{
327 u32 control_reg, clocks_from_dsp; 329 u32 control_reg, clocks_from_dsp;
328 330
329 DE_ACT(("set_input_clock:\n"));
330 331
331 /* Mask off the clock select bits */ 332 /* Mask off the clock select bits */
332 control_reg = le32_to_cpu(chip->comm_page->control_register) & 333 control_reg = le32_to_cpu(chip->comm_page->control_register) &
@@ -335,13 +336,11 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
335 336
336 switch (clock) { 337 switch (clock) {
337 case ECHO_CLOCK_INTERNAL: 338 case ECHO_CLOCK_INTERNAL:
338 DE_ACT(("Set Echo3G clock to INTERNAL\n"));
339 chip->input_clock = ECHO_CLOCK_INTERNAL; 339 chip->input_clock = ECHO_CLOCK_INTERNAL;
340 return set_sample_rate(chip, chip->sample_rate); 340 return set_sample_rate(chip, chip->sample_rate);
341 case ECHO_CLOCK_SPDIF: 341 case ECHO_CLOCK_SPDIF:
342 if (chip->digital_mode == DIGITAL_MODE_ADAT) 342 if (chip->digital_mode == DIGITAL_MODE_ADAT)
343 return -EAGAIN; 343 return -EAGAIN;
344 DE_ACT(("Set Echo3G clock to SPDIF\n"));
345 control_reg |= E3G_SPDIF_CLOCK; 344 control_reg |= E3G_SPDIF_CLOCK;
346 if (clocks_from_dsp & E3G_CLOCK_DETECT_BIT_SPDIF96) 345 if (clocks_from_dsp & E3G_CLOCK_DETECT_BIT_SPDIF96)
347 control_reg |= E3G_DOUBLE_SPEED_MODE; 346 control_reg |= E3G_DOUBLE_SPEED_MODE;
@@ -351,12 +350,10 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
351 case ECHO_CLOCK_ADAT: 350 case ECHO_CLOCK_ADAT:
352 if (chip->digital_mode != DIGITAL_MODE_ADAT) 351 if (chip->digital_mode != DIGITAL_MODE_ADAT)
353 return -EAGAIN; 352 return -EAGAIN;
354 DE_ACT(("Set Echo3G clock to ADAT\n"));
355 control_reg |= E3G_ADAT_CLOCK; 353 control_reg |= E3G_ADAT_CLOCK;
356 control_reg &= ~E3G_DOUBLE_SPEED_MODE; 354 control_reg &= ~E3G_DOUBLE_SPEED_MODE;
357 break; 355 break;
358 case ECHO_CLOCK_WORD: 356 case ECHO_CLOCK_WORD:
359 DE_ACT(("Set Echo3G clock to WORD\n"));
360 control_reg |= E3G_WORD_CLOCK; 357 control_reg |= E3G_WORD_CLOCK;
361 if (clocks_from_dsp & E3G_CLOCK_DETECT_BIT_WORD96) 358 if (clocks_from_dsp & E3G_CLOCK_DETECT_BIT_WORD96)
362 control_reg |= E3G_DOUBLE_SPEED_MODE; 359 control_reg |= E3G_DOUBLE_SPEED_MODE;
@@ -364,7 +361,8 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
364 control_reg &= ~E3G_DOUBLE_SPEED_MODE; 361 control_reg &= ~E3G_DOUBLE_SPEED_MODE;
365 break; 362 break;
366 default: 363 default:
367 DE_ACT(("Input clock 0x%x not supported for Echo3G\n", clock)); 364 dev_err(chip->card->dev,
365 "Input clock 0x%x not supported for Echo3G\n", clock);
368 return -EINVAL; 366 return -EINVAL;
369 } 367 }
370 368
@@ -392,7 +390,8 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
392 incompatible_clock = TRUE; 390 incompatible_clock = TRUE;
393 break; 391 break;
394 default: 392 default:
395 DE_ACT(("Digital mode not supported: %d\n", mode)); 393 dev_err(chip->card->dev,
394 "Digital mode not supported: %d\n", mode);
396 return -EINVAL; 395 return -EINVAL;
397 } 396 }
398 397
@@ -427,6 +426,6 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
427 return err; 426 return err;
428 chip->digital_mode = mode; 427 chip->digital_mode = mode;
429 428
430 DE_ACT(("set_digital_mode(%d)\n", chip->digital_mode)); 429 dev_dbg(chip->card->dev, "set_digital_mode(%d)\n", chip->digital_mode);
431 return incompatible_clock; 430 return incompatible_clock;
432} 431}
diff --git a/sound/pci/echoaudio/echoaudio_dsp.c b/sound/pci/echoaudio/echoaudio_dsp.c
index 5a6a217b82e0..1a9427aabe1d 100644
--- a/sound/pci/echoaudio/echoaudio_dsp.c
+++ b/sound/pci/echoaudio/echoaudio_dsp.c
@@ -80,7 +80,7 @@ static int send_vector(struct echoaudio *chip, u32 command)
80 udelay(1); 80 udelay(1);
81 } 81 }
82 82
83 DE_ACT((KERN_ERR "timeout on send_vector\n")); 83 dev_err(chip->card->dev, "timeout on send_vector\n");
84 return -EBUSY; 84 return -EBUSY;
85} 85}
86 86
@@ -104,7 +104,7 @@ static int write_dsp(struct echoaudio *chip, u32 data)
104 } 104 }
105 105
106 chip->bad_board = TRUE; /* Set TRUE until DSP re-loaded */ 106 chip->bad_board = TRUE; /* Set TRUE until DSP re-loaded */
107 DE_ACT((KERN_ERR "write_dsp: Set bad_board to TRUE\n")); 107 dev_dbg(chip->card->dev, "write_dsp: Set bad_board to TRUE\n");
108 return -EIO; 108 return -EIO;
109} 109}
110 110
@@ -127,7 +127,7 @@ static int read_dsp(struct echoaudio *chip, u32 *data)
127 } 127 }
128 128
129 chip->bad_board = TRUE; /* Set TRUE until DSP re-loaded */ 129 chip->bad_board = TRUE; /* Set TRUE until DSP re-loaded */
130 DE_INIT((KERN_ERR "read_dsp: Set bad_board to TRUE\n")); 130 dev_err(chip->card->dev, "read_dsp: Set bad_board to TRUE\n");
131 return -EIO; 131 return -EIO;
132} 132}
133 133
@@ -154,8 +154,9 @@ static int read_sn(struct echoaudio *chip)
154 return -EIO; 154 return -EIO;
155 } 155 }
156 } 156 }
157 DE_INIT(("Read serial number %08x %08x %08x %08x %08x\n", 157 dev_dbg(chip->card->dev,
158 sn[0], sn[1], sn[2], sn[3], sn[4])); 158 "Read serial number %08x %08x %08x %08x %08x\n",
159 sn[0], sn[1], sn[2], sn[3], sn[4]);
159 return 0; 160 return 0;
160} 161}
161 162
@@ -205,13 +206,12 @@ static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic)
205 goto la_error; 206 goto la_error;
206 } 207 }
207 208
208 DE_INIT(("ASIC loaded\n")); 209 free_firmware(fw, chip);
209 free_firmware(fw);
210 return 0; 210 return 0;
211 211
212la_error: 212la_error:
213 DE_INIT(("failed on write_dsp\n")); 213 dev_err(chip->card->dev, "failed on write_dsp\n");
214 free_firmware(fw); 214 free_firmware(fw, chip);
215 return -EIO; 215 return -EIO;
216} 216}
217 217
@@ -241,8 +241,9 @@ static int install_resident_loader(struct echoaudio *chip)
241 loader is already installed, host flag 5 will be on. */ 241 loader is already installed, host flag 5 will be on. */
242 status = get_dsp_register(chip, CHI32_STATUS_REG); 242 status = get_dsp_register(chip, CHI32_STATUS_REG);
243 if (status & CHI32_STATUS_REG_HF5) { 243 if (status & CHI32_STATUS_REG_HF5) {
244 DE_INIT(("Resident loader already installed; status is 0x%x\n", 244 dev_dbg(chip->card->dev,
245 status)); 245 "Resident loader already installed; status is 0x%x\n",
246 status);
246 return 0; 247 return 0;
247 } 248 }
248 249
@@ -283,12 +284,14 @@ static int install_resident_loader(struct echoaudio *chip)
283 284
284 /* Write the count to the DSP */ 285 /* Write the count to the DSP */
285 if (write_dsp(chip, words)) { 286 if (write_dsp(chip, words)) {
286 DE_INIT(("install_resident_loader: Failed to write word count!\n")); 287 dev_err(chip->card->dev,
288 "install_resident_loader: Failed to write word count!\n");
287 goto irl_error; 289 goto irl_error;
288 } 290 }
289 /* Write the DSP address */ 291 /* Write the DSP address */
290 if (write_dsp(chip, address)) { 292 if (write_dsp(chip, address)) {
291 DE_INIT(("install_resident_loader: Failed to write DSP address!\n")); 293 dev_err(chip->card->dev,
294 "install_resident_loader: Failed to write DSP address!\n");
292 goto irl_error; 295 goto irl_error;
293 } 296 }
294 /* Write out this block of code to the DSP */ 297 /* Write out this block of code to the DSP */
@@ -297,7 +300,8 @@ static int install_resident_loader(struct echoaudio *chip)
297 300
298 data = ((u32)code[index] << 16) + code[index + 1]; 301 data = ((u32)code[index] << 16) + code[index + 1];
299 if (write_dsp(chip, data)) { 302 if (write_dsp(chip, data)) {
300 DE_INIT(("install_resident_loader: Failed to write DSP code\n")); 303 dev_err(chip->card->dev,
304 "install_resident_loader: Failed to write DSP code\n");
301 goto irl_error; 305 goto irl_error;
302 } 306 }
303 index += 2; 307 index += 2;
@@ -312,16 +316,16 @@ static int install_resident_loader(struct echoaudio *chip)
312 } 316 }
313 317
314 if (i == 200) { 318 if (i == 200) {
315 DE_INIT(("Resident loader failed to set HF5\n")); 319 dev_err(chip->card->dev, "Resident loader failed to set HF5\n");
316 goto irl_error; 320 goto irl_error;
317 } 321 }
318 322
319 DE_INIT(("Resident loader successfully installed\n")); 323 dev_dbg(chip->card->dev, "Resident loader successfully installed\n");
320 free_firmware(fw); 324 free_firmware(fw, chip);
321 return 0; 325 return 0;
322 326
323irl_error: 327irl_error:
324 free_firmware(fw); 328 free_firmware(fw, chip);
325 return -EIO; 329 return -EIO;
326} 330}
327 331
@@ -334,14 +338,14 @@ static int load_dsp(struct echoaudio *chip, u16 *code)
334 int index, words, i; 338 int index, words, i;
335 339
336 if (chip->dsp_code == code) { 340 if (chip->dsp_code == code) {
337 DE_INIT(("DSP is already loaded!\n")); 341 dev_warn(chip->card->dev, "DSP is already loaded!\n");
338 return 0; 342 return 0;
339 } 343 }
340 chip->bad_board = TRUE; /* Set TRUE until DSP loaded */ 344 chip->bad_board = TRUE; /* Set TRUE until DSP loaded */
341 chip->dsp_code = NULL; /* Current DSP code not loaded */ 345 chip->dsp_code = NULL; /* Current DSP code not loaded */
342 chip->asic_loaded = FALSE; /* Loading the DSP code will reset the ASIC */ 346 chip->asic_loaded = FALSE; /* Loading the DSP code will reset the ASIC */
343 347
344 DE_INIT(("load_dsp: Set bad_board to TRUE\n")); 348 dev_dbg(chip->card->dev, "load_dsp: Set bad_board to TRUE\n");
345 349
346 /* If this board requires a resident loader, install it. */ 350 /* If this board requires a resident loader, install it. */
347#ifdef DSP_56361 351#ifdef DSP_56361
@@ -351,7 +355,8 @@ static int load_dsp(struct echoaudio *chip, u16 *code)
351 355
352 /* Send software reset command */ 356 /* Send software reset command */
353 if (send_vector(chip, DSP_VC_RESET) < 0) { 357 if (send_vector(chip, DSP_VC_RESET) < 0) {
354 DE_INIT(("LoadDsp: send_vector DSP_VC_RESET failed, Critical Failure\n")); 358 dev_err(chip->card->dev,
359 "LoadDsp: send_vector DSP_VC_RESET failed, Critical Failure\n");
355 return -EIO; 360 return -EIO;
356 } 361 }
357 /* Delay 10us */ 362 /* Delay 10us */
@@ -366,7 +371,8 @@ static int load_dsp(struct echoaudio *chip, u16 *code)
366 } 371 }
367 372
368 if (i == 1000) { 373 if (i == 1000) {
369 DE_INIT(("load_dsp: Timeout waiting for CHI32_STATUS_REG_HF3\n")); 374 dev_err(chip->card->dev,
375 "load_dsp: Timeout waiting for CHI32_STATUS_REG_HF3\n");
370 return -EIO; 376 return -EIO;
371 } 377 }
372 378
@@ -403,29 +409,34 @@ static int load_dsp(struct echoaudio *chip, u16 *code)
403 index += 2; 409 index += 2;
404 410
405 if (write_dsp(chip, words) < 0) { 411 if (write_dsp(chip, words) < 0) {
406 DE_INIT(("load_dsp: failed to write number of DSP words\n")); 412 dev_err(chip->card->dev,
413 "load_dsp: failed to write number of DSP words\n");
407 return -EIO; 414 return -EIO;
408 } 415 }
409 if (write_dsp(chip, address) < 0) { 416 if (write_dsp(chip, address) < 0) {
410 DE_INIT(("load_dsp: failed to write DSP address\n")); 417 dev_err(chip->card->dev,
418 "load_dsp: failed to write DSP address\n");
411 return -EIO; 419 return -EIO;
412 } 420 }
413 if (write_dsp(chip, mem_type) < 0) { 421 if (write_dsp(chip, mem_type) < 0) {
414 DE_INIT(("load_dsp: failed to write DSP memory type\n")); 422 dev_err(chip->card->dev,
423 "load_dsp: failed to write DSP memory type\n");
415 return -EIO; 424 return -EIO;
416 } 425 }
417 /* Code */ 426 /* Code */
418 for (i = 0; i < words; i++, index+=2) { 427 for (i = 0; i < words; i++, index+=2) {
419 data = ((u32)code[index] << 16) + code[index + 1]; 428 data = ((u32)code[index] << 16) + code[index + 1];
420 if (write_dsp(chip, data) < 0) { 429 if (write_dsp(chip, data) < 0) {
421 DE_INIT(("load_dsp: failed to write DSP data\n")); 430 dev_err(chip->card->dev,
431 "load_dsp: failed to write DSP data\n");
422 return -EIO; 432 return -EIO;
423 } 433 }
424 } 434 }
425 } 435 }
426 436
427 if (write_dsp(chip, 0) < 0) { /* We're done!!! */ 437 if (write_dsp(chip, 0) < 0) { /* We're done!!! */
428 DE_INIT(("load_dsp: Failed to write final zero\n")); 438 dev_err(chip->card->dev,
439 "load_dsp: Failed to write final zero\n");
429 return -EIO; 440 return -EIO;
430 } 441 }
431 udelay(10); 442 udelay(10);
@@ -438,12 +449,14 @@ static int load_dsp(struct echoaudio *chip, u16 *code)
438 get_dsp_register(chip, CHI32_CONTROL_REG) & ~0x1b00); 449 get_dsp_register(chip, CHI32_CONTROL_REG) & ~0x1b00);
439 450
440 if (write_dsp(chip, DSP_FNC_SET_COMMPAGE_ADDR) < 0) { 451 if (write_dsp(chip, DSP_FNC_SET_COMMPAGE_ADDR) < 0) {
441 DE_INIT(("load_dsp: Failed to write DSP_FNC_SET_COMMPAGE_ADDR\n")); 452 dev_err(chip->card->dev,
453 "load_dsp: Failed to write DSP_FNC_SET_COMMPAGE_ADDR\n");
442 return -EIO; 454 return -EIO;
443 } 455 }
444 456
445 if (write_dsp(chip, chip->comm_page_phys) < 0) { 457 if (write_dsp(chip, chip->comm_page_phys) < 0) {
446 DE_INIT(("load_dsp: Failed to write comm page address\n")); 458 dev_err(chip->card->dev,
459 "load_dsp: Failed to write comm page address\n");
447 return -EIO; 460 return -EIO;
448 } 461 }
449 462
@@ -452,19 +465,20 @@ static int load_dsp(struct echoaudio *chip, u16 *code)
452 We don't actually use the serial number but we have to 465 We don't actually use the serial number but we have to
453 get it as part of the DSP init voodoo. */ 466 get it as part of the DSP init voodoo. */
454 if (read_sn(chip) < 0) { 467 if (read_sn(chip) < 0) {
455 DE_INIT(("load_dsp: Failed to read serial number\n")); 468 dev_err(chip->card->dev,
469 "load_dsp: Failed to read serial number\n");
456 return -EIO; 470 return -EIO;
457 } 471 }
458 472
459 chip->dsp_code = code; /* Show which DSP code loaded */ 473 chip->dsp_code = code; /* Show which DSP code loaded */
460 chip->bad_board = FALSE; /* DSP OK */ 474 chip->bad_board = FALSE; /* DSP OK */
461 DE_INIT(("load_dsp: OK!\n"));
462 return 0; 475 return 0;
463 } 476 }
464 udelay(100); 477 udelay(100);
465 } 478 }
466 479
467 DE_INIT(("load_dsp: DSP load timed out waiting for HF4\n")); 480 dev_err(chip->card->dev,
481 "load_dsp: DSP load timed out waiting for HF4\n");
468 return -EIO; 482 return -EIO;
469} 483}
470 484
@@ -491,7 +505,7 @@ static int load_firmware(struct echoaudio *chip)
491 if (err < 0) 505 if (err < 0)
492 return err; 506 return err;
493 err = load_dsp(chip, (u16 *)fw->data); 507 err = load_dsp(chip, (u16 *)fw->data);
494 free_firmware(fw); 508 free_firmware(fw, chip);
495 if (err < 0) 509 if (err < 0)
496 return err; 510 return err;
497 511
@@ -658,7 +672,6 @@ static void get_audio_meters(struct echoaudio *chip, long *meters)
658static int restore_dsp_rettings(struct echoaudio *chip) 672static int restore_dsp_rettings(struct echoaudio *chip)
659{ 673{
660 int i, o, err; 674 int i, o, err;
661 DE_INIT(("restore_dsp_settings\n"));
662 675
663 if ((err = check_asic_status(chip)) < 0) 676 if ((err = check_asic_status(chip)) < 0)
664 return err; 677 return err;
@@ -755,7 +768,6 @@ static int restore_dsp_rettings(struct echoaudio *chip)
755 if (send_vector(chip, DSP_VC_UPDATE_FLAGS) < 0) 768 if (send_vector(chip, DSP_VC_UPDATE_FLAGS) < 0)
756 return -EIO; 769 return -EIO;
757 770
758 DE_INIT(("restore_dsp_rettings done\n"));
759 return 0; 771 return 0;
760} 772}
761 773
@@ -835,7 +847,8 @@ static void set_audio_format(struct echoaudio *chip, u16 pipe_index,
835 break; 847 break;
836 } 848 }
837 } 849 }
838 DE_ACT(("set_audio_format[%d] = %x\n", pipe_index, dsp_format)); 850 dev_dbg(chip->card->dev,
851 "set_audio_format[%d] = %x\n", pipe_index, dsp_format);
839 chip->comm_page->audio_format[pipe_index] = cpu_to_le16(dsp_format); 852 chip->comm_page->audio_format[pipe_index] = cpu_to_le16(dsp_format);
840} 853}
841 854
@@ -848,7 +861,6 @@ Same thing for pause_ and stop_ -trasport below. */
848static int start_transport(struct echoaudio *chip, u32 channel_mask, 861static int start_transport(struct echoaudio *chip, u32 channel_mask,
849 u32 cyclic_mask) 862 u32 cyclic_mask)
850{ 863{
851 DE_ACT(("start_transport %x\n", channel_mask));
852 864
853 if (wait_handshake(chip)) 865 if (wait_handshake(chip))
854 return -EIO; 866 return -EIO;
@@ -866,7 +878,7 @@ static int start_transport(struct echoaudio *chip, u32 channel_mask,
866 return 0; 878 return 0;
867 } 879 }
868 880
869 DE_ACT(("start_transport: No pipes to start!\n")); 881 dev_err(chip->card->dev, "start_transport: No pipes to start!\n");
870 return -EINVAL; 882 return -EINVAL;
871} 883}
872 884
@@ -874,7 +886,6 @@ static int start_transport(struct echoaudio *chip, u32 channel_mask,
874 886
875static int pause_transport(struct echoaudio *chip, u32 channel_mask) 887static int pause_transport(struct echoaudio *chip, u32 channel_mask)
876{ 888{
877 DE_ACT(("pause_transport %x\n", channel_mask));
878 889
879 if (wait_handshake(chip)) 890 if (wait_handshake(chip))
880 return -EIO; 891 return -EIO;
@@ -893,7 +904,7 @@ static int pause_transport(struct echoaudio *chip, u32 channel_mask)
893 return 0; 904 return 0;
894 } 905 }
895 906
896 DE_ACT(("pause_transport: No pipes to stop!\n")); 907 dev_warn(chip->card->dev, "pause_transport: No pipes to stop!\n");
897 return 0; 908 return 0;
898} 909}
899 910
@@ -901,7 +912,6 @@ static int pause_transport(struct echoaudio *chip, u32 channel_mask)
901 912
902static int stop_transport(struct echoaudio *chip, u32 channel_mask) 913static int stop_transport(struct echoaudio *chip, u32 channel_mask)
903{ 914{
904 DE_ACT(("stop_transport %x\n", channel_mask));
905 915
906 if (wait_handshake(chip)) 916 if (wait_handshake(chip))
907 return -EIO; 917 return -EIO;
@@ -920,7 +930,7 @@ static int stop_transport(struct echoaudio *chip, u32 channel_mask)
920 return 0; 930 return 0;
921 } 931 }
922 932
923 DE_ACT(("stop_transport: No pipes to stop!\n")); 933 dev_warn(chip->card->dev, "stop_transport: No pipes to stop!\n");
924 return 0; 934 return 0;
925} 935}
926 936
@@ -937,7 +947,6 @@ static inline int is_pipe_allocated(struct echoaudio *chip, u16 pipe_index)
937stopped and unallocated. */ 947stopped and unallocated. */
938static int rest_in_peace(struct echoaudio *chip) 948static int rest_in_peace(struct echoaudio *chip)
939{ 949{
940 DE_ACT(("rest_in_peace() open=%x\n", chip->pipe_alloc_mask));
941 950
942 /* Stops all active pipes (just to be sure) */ 951 /* Stops all active pipes (just to be sure) */
943 stop_transport(chip, chip->active_mask); 952 stop_transport(chip, chip->active_mask);
@@ -965,7 +974,8 @@ static int init_dsp_comm_page(struct echoaudio *chip)
965{ 974{
966 /* Check if the compiler added extra padding inside the structure */ 975 /* Check if the compiler added extra padding inside the structure */
967 if (offsetof(struct comm_page, midi_output) != 0xbe0) { 976 if (offsetof(struct comm_page, midi_output) != 0xbe0) {
968 DE_INIT(("init_dsp_comm_page() - Invalid struct comm_page structure\n")); 977 dev_err(chip->card->dev,
978 "init_dsp_comm_page() - Invalid struct comm_page structure\n");
969 return -EPERM; 979 return -EPERM;
970 } 980 }
971 981
@@ -999,7 +1009,6 @@ static int init_dsp_comm_page(struct echoaudio *chip)
999 */ 1009 */
1000static int init_line_levels(struct echoaudio *chip) 1010static int init_line_levels(struct echoaudio *chip)
1001{ 1011{
1002 DE_INIT(("init_line_levels\n"));
1003 memset(chip->output_gain, ECHOGAIN_MUTED, sizeof(chip->output_gain)); 1012 memset(chip->output_gain, ECHOGAIN_MUTED, sizeof(chip->output_gain));
1004 memset(chip->input_gain, ECHOGAIN_MUTED, sizeof(chip->input_gain)); 1013 memset(chip->input_gain, ECHOGAIN_MUTED, sizeof(chip->input_gain));
1005 memset(chip->monitor_gain, ECHOGAIN_MUTED, sizeof(chip->monitor_gain)); 1014 memset(chip->monitor_gain, ECHOGAIN_MUTED, sizeof(chip->monitor_gain));
@@ -1051,7 +1060,8 @@ static int allocate_pipes(struct echoaudio *chip, struct audiopipe *pipe,
1051 u32 channel_mask; 1060 u32 channel_mask;
1052 char is_cyclic; 1061 char is_cyclic;
1053 1062
1054 DE_ACT(("allocate_pipes: ch=%d int=%d\n", pipe_index, interleave)); 1063 dev_dbg(chip->card->dev,
1064 "allocate_pipes: ch=%d int=%d\n", pipe_index, interleave);
1055 1065
1056 if (chip->bad_board) 1066 if (chip->bad_board)
1057 return -EIO; 1067 return -EIO;
@@ -1061,7 +1071,8 @@ static int allocate_pipes(struct echoaudio *chip, struct audiopipe *pipe,
1061 for (channel_mask = i = 0; i < interleave; i++) 1071 for (channel_mask = i = 0; i < interleave; i++)
1062 channel_mask |= 1 << (pipe_index + i); 1072 channel_mask |= 1 << (pipe_index + i);
1063 if (chip->pipe_alloc_mask & channel_mask) { 1073 if (chip->pipe_alloc_mask & channel_mask) {
1064 DE_ACT(("allocate_pipes: channel already open\n")); 1074 dev_err(chip->card->dev,
1075 "allocate_pipes: channel already open\n");
1065 return -EAGAIN; 1076 return -EAGAIN;
1066 } 1077 }
1067 1078
@@ -1078,7 +1089,6 @@ static int allocate_pipes(struct echoaudio *chip, struct audiopipe *pipe,
1078 it moves data. The DMA counter is in units of bytes, not samples. */ 1089 it moves data. The DMA counter is in units of bytes, not samples. */
1079 pipe->dma_counter = &chip->comm_page->position[pipe_index]; 1090 pipe->dma_counter = &chip->comm_page->position[pipe_index];
1080 *pipe->dma_counter = 0; 1091 *pipe->dma_counter = 0;
1081 DE_ACT(("allocate_pipes: ok\n"));
1082 return pipe_index; 1092 return pipe_index;
1083} 1093}
1084 1094
@@ -1089,7 +1099,6 @@ static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe)
1089 u32 channel_mask; 1099 u32 channel_mask;
1090 int i; 1100 int i;
1091 1101
1092 DE_ACT(("free_pipes: Pipe %d\n", pipe->index));
1093 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe->index))) 1102 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe->index)))
1094 return -EINVAL; 1103 return -EINVAL;
1095 if (snd_BUG_ON(pipe->state != PIPE_STATE_STOPPED)) 1104 if (snd_BUG_ON(pipe->state != PIPE_STATE_STOPPED))
@@ -1131,7 +1140,7 @@ static int sglist_add_mapping(struct echoaudio *chip, struct audiopipe *pipe,
1131 list[head].size = cpu_to_le32(length); 1140 list[head].size = cpu_to_le32(length);
1132 pipe->sglist_head++; 1141 pipe->sglist_head++;
1133 } else { 1142 } else {
1134 DE_ACT(("SGlist: too many fragments\n")); 1143 dev_err(chip->card->dev, "SGlist: too many fragments\n");
1135 return -ENOMEM; 1144 return -ENOMEM;
1136 } 1145 }
1137 return 0; 1146 return 0;
diff --git a/sound/pci/echoaudio/echoaudio_gml.c b/sound/pci/echoaudio/echoaudio_gml.c
index afa273330e8a..23a099425834 100644
--- a/sound/pci/echoaudio/echoaudio_gml.c
+++ b/sound/pci/echoaudio/echoaudio_gml.c
@@ -46,7 +46,8 @@ static int check_asic_status(struct echoaudio *chip)
46 /* The DSP will return a value to indicate whether or not the 46 /* The DSP will return a value to indicate whether or not the
47 ASIC is currently loaded */ 47 ASIC is currently loaded */
48 if (read_dsp(chip, &asic_status) < 0) { 48 if (read_dsp(chip, &asic_status) < 0) {
49 DE_INIT(("check_asic_status: failed on read_dsp\n")); 49 dev_err(chip->card->dev,
50 "check_asic_status: failed on read_dsp\n");
50 chip->asic_loaded = FALSE; 51 chip->asic_loaded = FALSE;
51 return -EIO; 52 return -EIO;
52 } 53 }
@@ -68,7 +69,7 @@ static int write_control_reg(struct echoaudio *chip, u32 value, char force)
68 else 69 else
69 value &= ~GML_DIGITAL_IN_AUTO_MUTE; 70 value &= ~GML_DIGITAL_IN_AUTO_MUTE;
70 71
71 DE_ACT(("write_control_reg: 0x%x\n", value)); 72 dev_dbg(chip->card->dev, "write_control_reg: 0x%x\n", value);
72 73
73 /* Write the control register */ 74 /* Write the control register */
74 value = cpu_to_le32(value); 75 value = cpu_to_le32(value);
@@ -91,7 +92,7 @@ If the auto-mute is disabled, the digital inputs are enabled regardless of
91what the input clock is set or what is connected. */ 92what the input clock is set or what is connected. */
92static int set_input_auto_mute(struct echoaudio *chip, int automute) 93static int set_input_auto_mute(struct echoaudio *chip, int automute)
93{ 94{
94 DE_ACT(("set_input_auto_mute %d\n", automute)); 95 dev_dbg(chip->card->dev, "set_input_auto_mute %d\n", automute);
95 96
96 chip->digital_in_automute = automute; 97 chip->digital_in_automute = automute;
97 98
@@ -194,7 +195,7 @@ static int set_professional_spdif(struct echoaudio *chip, char prof)
194 if ((err = write_control_reg(chip, control_reg, FALSE))) 195 if ((err = write_control_reg(chip, control_reg, FALSE)))
195 return err; 196 return err;
196 chip->professional_spdif = prof; 197 chip->professional_spdif = prof;
197 DE_ACT(("set_professional_spdif to %s\n", 198 dev_dbg(chip->card->dev, "set_professional_spdif to %s\n",
198 prof ? "Professional" : "Consumer")); 199 prof ? "Professional" : "Consumer");
199 return 0; 200 return 0;
200} 201}
diff --git a/sound/pci/echoaudio/gina20_dsp.c b/sound/pci/echoaudio/gina20_dsp.c
index d1615a0579d1..5dafe9260cb4 100644
--- a/sound/pci/echoaudio/gina20_dsp.c
+++ b/sound/pci/echoaudio/gina20_dsp.c
@@ -37,12 +37,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
37{ 37{
38 int err; 38 int err;
39 39
40 DE_INIT(("init_hw() - Gina20\n"));
41 if (snd_BUG_ON((subdevice_id & 0xfff0) != GINA20)) 40 if (snd_BUG_ON((subdevice_id & 0xfff0) != GINA20))
42 return -ENODEV; 41 return -ENODEV;
43 42
44 if ((err = init_dsp_comm_page(chip))) { 43 if ((err = init_dsp_comm_page(chip))) {
45 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 44 dev_err(chip->card->dev,
45 "init_hw - could not initialize DSP comm page\n");
46 return err; 46 return err;
47 } 47 }
48 48
@@ -62,7 +62,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
62 return err; 62 return err;
63 chip->bad_board = FALSE; 63 chip->bad_board = FALSE;
64 64
65 DE_INIT(("init_hw done\n"));
66 return err; 65 return err;
67} 66}
68 67
@@ -149,7 +148,6 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
149 148
150static int set_input_clock(struct echoaudio *chip, u16 clock) 149static int set_input_clock(struct echoaudio *chip, u16 clock)
151{ 150{
152 DE_ACT(("set_input_clock:\n"));
153 151
154 switch (clock) { 152 switch (clock) {
155 case ECHO_CLOCK_INTERNAL: 153 case ECHO_CLOCK_INTERNAL:
@@ -158,7 +156,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
158 chip->spdif_status = GD_SPDIF_STATUS_UNDEF; 156 chip->spdif_status = GD_SPDIF_STATUS_UNDEF;
159 set_sample_rate(chip, chip->sample_rate); 157 set_sample_rate(chip, chip->sample_rate);
160 chip->input_clock = clock; 158 chip->input_clock = clock;
161 DE_ACT(("Set Gina clock to INTERNAL\n"));
162 break; 159 break;
163 case ECHO_CLOCK_SPDIF: 160 case ECHO_CLOCK_SPDIF:
164 chip->comm_page->gd_clock_state = GD_CLOCK_SPDIFIN; 161 chip->comm_page->gd_clock_state = GD_CLOCK_SPDIFIN;
@@ -166,7 +163,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
166 clear_handshake(chip); 163 clear_handshake(chip);
167 send_vector(chip, DSP_VC_SET_GD_AUDIO_STATE); 164 send_vector(chip, DSP_VC_SET_GD_AUDIO_STATE);
168 chip->clock_state = GD_CLOCK_SPDIFIN; 165 chip->clock_state = GD_CLOCK_SPDIFIN;
169 DE_ACT(("Set Gina20 clock to SPDIF\n"));
170 chip->input_clock = clock; 166 chip->input_clock = clock;
171 break; 167 break;
172 default: 168 default:
@@ -208,7 +204,6 @@ static int update_flags(struct echoaudio *chip)
208 204
209static int set_professional_spdif(struct echoaudio *chip, char prof) 205static int set_professional_spdif(struct echoaudio *chip, char prof)
210{ 206{
211 DE_ACT(("set_professional_spdif %d\n", prof));
212 if (prof) 207 if (prof)
213 chip->comm_page->flags |= 208 chip->comm_page->flags |=
214 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 209 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
diff --git a/sound/pci/echoaudio/gina24_dsp.c b/sound/pci/echoaudio/gina24_dsp.c
index 98f7cfa81b5f..6971766938bf 100644
--- a/sound/pci/echoaudio/gina24_dsp.c
+++ b/sound/pci/echoaudio/gina24_dsp.c
@@ -41,12 +41,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
41{ 41{
42 int err; 42 int err;
43 43
44 DE_INIT(("init_hw() - Gina24\n"));
45 if (snd_BUG_ON((subdevice_id & 0xfff0) != GINA24)) 44 if (snd_BUG_ON((subdevice_id & 0xfff0) != GINA24))
46 return -ENODEV; 45 return -ENODEV;
47 46
48 if ((err = init_dsp_comm_page(chip))) { 47 if ((err = init_dsp_comm_page(chip))) {
49 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 48 dev_err(chip->card->dev,
49 "init_hw - could not initialize DSP comm page\n");
50 return err; 50 return err;
51 } 51 }
52 52
@@ -78,7 +78,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
78 return err; 78 return err;
79 chip->bad_board = FALSE; 79 chip->bad_board = FALSE;
80 80
81 DE_INIT(("init_hw done\n"));
82 return err; 81 return err;
83} 82}
84 83
@@ -155,7 +154,6 @@ static int load_asic(struct echoaudio *chip)
155 control_reg = GML_CONVERTER_ENABLE | GML_48KHZ; 154 control_reg = GML_CONVERTER_ENABLE | GML_48KHZ;
156 err = write_control_reg(chip, control_reg, TRUE); 155 err = write_control_reg(chip, control_reg, TRUE);
157 } 156 }
158 DE_INIT(("load_asic() done\n"));
159 return err; 157 return err;
160} 158}
161 159
@@ -171,8 +169,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
171 169
172 /* Only set the clock for internal mode. */ 170 /* Only set the clock for internal mode. */
173 if (chip->input_clock != ECHO_CLOCK_INTERNAL) { 171 if (chip->input_clock != ECHO_CLOCK_INTERNAL) {
174 DE_ACT(("set_sample_rate: Cannot set sample rate - " 172 dev_warn(chip->card->dev,
175 "clock not set to CLK_CLOCKININTERNAL\n")); 173 "Cannot set sample rate - clock not set to CLK_CLOCKININTERNAL\n");
176 /* Save the rate anyhow */ 174 /* Save the rate anyhow */
177 chip->comm_page->sample_rate = cpu_to_le32(rate); 175 chip->comm_page->sample_rate = cpu_to_le32(rate);
178 chip->sample_rate = rate; 176 chip->sample_rate = rate;
@@ -217,7 +215,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
217 clock = GML_8KHZ; 215 clock = GML_8KHZ;
218 break; 216 break;
219 default: 217 default:
220 DE_ACT(("set_sample_rate: %d invalid!\n", rate)); 218 dev_err(chip->card->dev,
219 "set_sample_rate: %d invalid!\n", rate);
221 return -EINVAL; 220 return -EINVAL;
222 } 221 }
223 222
@@ -225,7 +224,7 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
225 224
226 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */ 225 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */
227 chip->sample_rate = rate; 226 chip->sample_rate = rate;
228 DE_ACT(("set_sample_rate: %d clock %d\n", rate, clock)); 227 dev_dbg(chip->card->dev, "set_sample_rate: %d clock %d\n", rate, clock);
229 228
230 return write_control_reg(chip, control_reg, FALSE); 229 return write_control_reg(chip, control_reg, FALSE);
231} 230}
@@ -236,7 +235,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
236{ 235{
237 u32 control_reg, clocks_from_dsp; 236 u32 control_reg, clocks_from_dsp;
238 237
239 DE_ACT(("set_input_clock:\n"));
240 238
241 /* Mask off the clock select bits */ 239 /* Mask off the clock select bits */
242 control_reg = le32_to_cpu(chip->comm_page->control_register) & 240 control_reg = le32_to_cpu(chip->comm_page->control_register) &
@@ -245,13 +243,11 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
245 243
246 switch (clock) { 244 switch (clock) {
247 case ECHO_CLOCK_INTERNAL: 245 case ECHO_CLOCK_INTERNAL:
248 DE_ACT(("Set Gina24 clock to INTERNAL\n"));
249 chip->input_clock = ECHO_CLOCK_INTERNAL; 246 chip->input_clock = ECHO_CLOCK_INTERNAL;
250 return set_sample_rate(chip, chip->sample_rate); 247 return set_sample_rate(chip, chip->sample_rate);
251 case ECHO_CLOCK_SPDIF: 248 case ECHO_CLOCK_SPDIF:
252 if (chip->digital_mode == DIGITAL_MODE_ADAT) 249 if (chip->digital_mode == DIGITAL_MODE_ADAT)
253 return -EAGAIN; 250 return -EAGAIN;
254 DE_ACT(("Set Gina24 clock to SPDIF\n"));
255 control_reg |= GML_SPDIF_CLOCK; 251 control_reg |= GML_SPDIF_CLOCK;
256 if (clocks_from_dsp & GML_CLOCK_DETECT_BIT_SPDIF96) 252 if (clocks_from_dsp & GML_CLOCK_DETECT_BIT_SPDIF96)
257 control_reg |= GML_DOUBLE_SPEED_MODE; 253 control_reg |= GML_DOUBLE_SPEED_MODE;
@@ -261,21 +257,19 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
261 case ECHO_CLOCK_ADAT: 257 case ECHO_CLOCK_ADAT:
262 if (chip->digital_mode != DIGITAL_MODE_ADAT) 258 if (chip->digital_mode != DIGITAL_MODE_ADAT)
263 return -EAGAIN; 259 return -EAGAIN;
264 DE_ACT(("Set Gina24 clock to ADAT\n"));
265 control_reg |= GML_ADAT_CLOCK; 260 control_reg |= GML_ADAT_CLOCK;
266 control_reg &= ~GML_DOUBLE_SPEED_MODE; 261 control_reg &= ~GML_DOUBLE_SPEED_MODE;
267 break; 262 break;
268 case ECHO_CLOCK_ESYNC: 263 case ECHO_CLOCK_ESYNC:
269 DE_ACT(("Set Gina24 clock to ESYNC\n"));
270 control_reg |= GML_ESYNC_CLOCK; 264 control_reg |= GML_ESYNC_CLOCK;
271 control_reg &= ~GML_DOUBLE_SPEED_MODE; 265 control_reg &= ~GML_DOUBLE_SPEED_MODE;
272 break; 266 break;
273 case ECHO_CLOCK_ESYNC96: 267 case ECHO_CLOCK_ESYNC96:
274 DE_ACT(("Set Gina24 clock to ESYNC96\n"));
275 control_reg |= GML_ESYNC_CLOCK | GML_DOUBLE_SPEED_MODE; 268 control_reg |= GML_ESYNC_CLOCK | GML_DOUBLE_SPEED_MODE;
276 break; 269 break;
277 default: 270 default:
278 DE_ACT(("Input clock 0x%x not supported for Gina24\n", clock)); 271 dev_err(chip->card->dev,
272 "Input clock 0x%x not supported for Gina24\n", clock);
279 return -EINVAL; 273 return -EINVAL;
280 } 274 }
281 275
@@ -304,7 +298,8 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
304 incompatible_clock = TRUE; 298 incompatible_clock = TRUE;
305 break; 299 break;
306 default: 300 default:
307 DE_ACT(("Digital mode not supported: %d\n", mode)); 301 dev_err(chip->card->dev,
302 "Digital mode not supported: %d\n", mode);
308 return -EINVAL; 303 return -EINVAL;
309 } 304 }
310 305
@@ -344,6 +339,7 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
344 return err; 339 return err;
345 chip->digital_mode = mode; 340 chip->digital_mode = mode;
346 341
347 DE_ACT(("set_digital_mode to %d\n", chip->digital_mode)); 342 dev_dbg(chip->card->dev,
343 "set_digital_mode to %d\n", chip->digital_mode);
348 return incompatible_clock; 344 return incompatible_clock;
349} 345}
diff --git a/sound/pci/echoaudio/indigo_dsp.c b/sound/pci/echoaudio/indigo_dsp.c
index 5e85f14fe5a8..54edd67edff7 100644
--- a/sound/pci/echoaudio/indigo_dsp.c
+++ b/sound/pci/echoaudio/indigo_dsp.c
@@ -38,12 +38,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
38{ 38{
39 int err; 39 int err;
40 40
41 DE_INIT(("init_hw() - Indigo\n"));
42 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO)) 41 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO))
43 return -ENODEV; 42 return -ENODEV;
44 43
45 if ((err = init_dsp_comm_page(chip))) { 44 if ((err = init_dsp_comm_page(chip))) {
46 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 45 dev_err(chip->card->dev,
46 "init_hw - could not initialize DSP comm page\n");
47 return err; 47 return err;
48 } 48 }
49 49
@@ -60,7 +60,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
60 return err; 60 return err;
61 chip->bad_board = FALSE; 61 chip->bad_board = FALSE;
62 62
63 DE_INIT(("init_hw done\n"));
64 return err; 63 return err;
65} 64}
66 65
@@ -109,7 +108,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
109 control_reg = MIA_32000; 108 control_reg = MIA_32000;
110 break; 109 break;
111 default: 110 default:
112 DE_ACT(("set_sample_rate: %d invalid!\n", rate)); 111 dev_err(chip->card->dev,
112 "set_sample_rate: %d invalid!\n", rate);
113 return -EINVAL; 113 return -EINVAL;
114 } 114 }
115 115
@@ -147,7 +147,8 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
147 index = output * num_pipes_out(chip) + pipe; 147 index = output * num_pipes_out(chip) + pipe;
148 chip->comm_page->vmixer[index] = gain; 148 chip->comm_page->vmixer[index] = gain;
149 149
150 DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain)); 150 dev_dbg(chip->card->dev,
151 "set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
151 return 0; 152 return 0;
152} 153}
153 154
diff --git a/sound/pci/echoaudio/indigo_express_dsp.c b/sound/pci/echoaudio/indigo_express_dsp.c
index 2e4ab3e34a74..ceda2d7046ac 100644
--- a/sound/pci/echoaudio/indigo_express_dsp.c
+++ b/sound/pci/echoaudio/indigo_express_dsp.c
@@ -61,7 +61,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
61 61
62 control_reg |= clock; 62 control_reg |= clock;
63 if (control_reg != old_control_reg) { 63 if (control_reg != old_control_reg) {
64 DE_ACT(("set_sample_rate: %d clock %d\n", rate, clock)); 64 dev_dbg(chip->card->dev,
65 "set_sample_rate: %d clock %d\n", rate, clock);
65 chip->comm_page->control_register = cpu_to_le32(control_reg); 66 chip->comm_page->control_register = cpu_to_le32(control_reg);
66 chip->sample_rate = rate; 67 chip->sample_rate = rate;
67 clear_handshake(chip); 68 clear_handshake(chip);
@@ -89,7 +90,8 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
89 index = output * num_pipes_out(chip) + pipe; 90 index = output * num_pipes_out(chip) + pipe;
90 chip->comm_page->vmixer[index] = gain; 91 chip->comm_page->vmixer[index] = gain;
91 92
92 DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain)); 93 dev_dbg(chip->card->dev,
94 "set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
93 return 0; 95 return 0;
94} 96}
95 97
diff --git a/sound/pci/echoaudio/indigodj_dsp.c b/sound/pci/echoaudio/indigodj_dsp.c
index 68f3c8ccc1bf..2cf5cc092d7a 100644
--- a/sound/pci/echoaudio/indigodj_dsp.c
+++ b/sound/pci/echoaudio/indigodj_dsp.c
@@ -38,12 +38,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
38{ 38{
39 int err; 39 int err;
40 40
41 DE_INIT(("init_hw() - Indigo DJ\n"));
42 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_DJ)) 41 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_DJ))
43 return -ENODEV; 42 return -ENODEV;
44 43
45 if ((err = init_dsp_comm_page(chip))) { 44 if ((err = init_dsp_comm_page(chip))) {
46 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 45 dev_err(chip->card->dev,
46 "init_hw - could not initialize DSP comm page\n");
47 return err; 47 return err;
48 } 48 }
49 49
@@ -60,7 +60,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
60 return err; 60 return err;
61 chip->bad_board = FALSE; 61 chip->bad_board = FALSE;
62 62
63 DE_INIT(("init_hw done\n"));
64 return err; 63 return err;
65} 64}
66 65
@@ -109,7 +108,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
109 control_reg = MIA_32000; 108 control_reg = MIA_32000;
110 break; 109 break;
111 default: 110 default:
112 DE_ACT(("set_sample_rate: %d invalid!\n", rate)); 111 dev_err(chip->card->dev,
112 "set_sample_rate: %d invalid!\n", rate);
113 return -EINVAL; 113 return -EINVAL;
114 } 114 }
115 115
@@ -147,7 +147,8 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
147 index = output * num_pipes_out(chip) + pipe; 147 index = output * num_pipes_out(chip) + pipe;
148 chip->comm_page->vmixer[index] = gain; 148 chip->comm_page->vmixer[index] = gain;
149 149
150 DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain)); 150 dev_dbg(chip->card->dev,
151 "set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
151 return 0; 152 return 0;
152} 153}
153 154
diff --git a/sound/pci/echoaudio/indigodjx_dsp.c b/sound/pci/echoaudio/indigodjx_dsp.c
index bb9632c752a9..5252863f1681 100644
--- a/sound/pci/echoaudio/indigodjx_dsp.c
+++ b/sound/pci/echoaudio/indigodjx_dsp.c
@@ -35,13 +35,13 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
35{ 35{
36 int err; 36 int err;
37 37
38 DE_INIT(("init_hw() - Indigo DJx\n"));
39 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_DJX)) 38 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_DJX))
40 return -ENODEV; 39 return -ENODEV;
41 40
42 err = init_dsp_comm_page(chip); 41 err = init_dsp_comm_page(chip);
43 if (err < 0) { 42 if (err < 0) {
44 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 43 dev_err(chip->card->dev,
44 "init_hw - could not initialize DSP comm page\n");
45 return err; 45 return err;
46 } 46 }
47 47
@@ -59,7 +59,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
59 return err; 59 return err;
60 chip->bad_board = FALSE; 60 chip->bad_board = FALSE;
61 61
62 DE_INIT(("init_hw done\n"));
63 return err; 62 return err;
64} 63}
65 64
diff --git a/sound/pci/echoaudio/indigoio_dsp.c b/sound/pci/echoaudio/indigoio_dsp.c
index beb9a5b69892..4e81787627e0 100644
--- a/sound/pci/echoaudio/indigoio_dsp.c
+++ b/sound/pci/echoaudio/indigoio_dsp.c
@@ -38,12 +38,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
38{ 38{
39 int err; 39 int err;
40 40
41 DE_INIT(("init_hw() - Indigo IO\n"));
42 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_IO)) 41 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_IO))
43 return -ENODEV; 42 return -ENODEV;
44 43
45 if ((err = init_dsp_comm_page(chip))) { 44 if ((err = init_dsp_comm_page(chip))) {
46 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 45 dev_err(chip->card->dev,
46 "init_hw - could not initialize DSP comm page\n");
47 return err; 47 return err;
48 } 48 }
49 49
@@ -60,7 +60,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
60 return err; 60 return err;
61 chip->bad_board = FALSE; 61 chip->bad_board = FALSE;
62 62
63 DE_INIT(("init_hw done\n"));
64 return err; 63 return err;
65} 64}
66 65
@@ -118,7 +117,8 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
118 index = output * num_pipes_out(chip) + pipe; 117 index = output * num_pipes_out(chip) + pipe;
119 chip->comm_page->vmixer[index] = gain; 118 chip->comm_page->vmixer[index] = gain;
120 119
121 DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain)); 120 dev_dbg(chip->card->dev,
121 "set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
122 return 0; 122 return 0;
123} 123}
124 124
diff --git a/sound/pci/echoaudio/indigoiox_dsp.c b/sound/pci/echoaudio/indigoiox_dsp.c
index 394c6e76bcbc..6de3f9bc6d26 100644
--- a/sound/pci/echoaudio/indigoiox_dsp.c
+++ b/sound/pci/echoaudio/indigoiox_dsp.c
@@ -35,13 +35,13 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
35{ 35{
36 int err; 36 int err;
37 37
38 DE_INIT(("init_hw() - Indigo IOx\n"));
39 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_IOX)) 38 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_IOX))
40 return -ENODEV; 39 return -ENODEV;
41 40
42 err = init_dsp_comm_page(chip); 41 err = init_dsp_comm_page(chip);
43 if (err < 0) { 42 if (err < 0) {
44 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 43 dev_err(chip->card->dev,
44 "init_hw - could not initialize DSP comm page\n");
45 return err; 45 return err;
46 } 46 }
47 47
@@ -59,7 +59,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
59 return err; 59 return err;
60 chip->bad_board = FALSE; 60 chip->bad_board = FALSE;
61 61
62 DE_INIT(("init_hw done\n"));
63 return err; 62 return err;
64} 63}
65 64
diff --git a/sound/pci/echoaudio/layla20_dsp.c b/sound/pci/echoaudio/layla20_dsp.c
index 53ce94605044..f2024a3565af 100644
--- a/sound/pci/echoaudio/layla20_dsp.c
+++ b/sound/pci/echoaudio/layla20_dsp.c
@@ -40,12 +40,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
40{ 40{
41 int err; 41 int err;
42 42
43 DE_INIT(("init_hw() - Layla20\n"));
44 if (snd_BUG_ON((subdevice_id & 0xfff0) != LAYLA20)) 43 if (snd_BUG_ON((subdevice_id & 0xfff0) != LAYLA20))
45 return -ENODEV; 44 return -ENODEV;
46 45
47 if ((err = init_dsp_comm_page(chip))) { 46 if ((err = init_dsp_comm_page(chip))) {
48 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 47 dev_err(chip->card->dev,
48 "init_hw - could not initialize DSP comm page\n");
49 return err; 49 return err;
50 } 50 }
51 51
@@ -64,7 +64,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
64 return err; 64 return err;
65 chip->bad_board = FALSE; 65 chip->bad_board = FALSE;
66 66
67 DE_INIT(("init_hw done\n"));
68 return err; 67 return err;
69} 68}
70 69
@@ -121,7 +120,8 @@ static int check_asic_status(struct echoaudio *chip)
121 /* The DSP will return a value to indicate whether or not 120 /* The DSP will return a value to indicate whether or not
122 the ASIC is currently loaded */ 121 the ASIC is currently loaded */
123 if (read_dsp(chip, &asic_status) < 0) { 122 if (read_dsp(chip, &asic_status) < 0) {
124 DE_ACT(("check_asic_status: failed on read_dsp\n")); 123 dev_err(chip->card->dev,
124 "check_asic_status: failed on read_dsp\n");
125 return -EIO; 125 return -EIO;
126 } 126 }
127 127
@@ -164,8 +164,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
164 /* Only set the clock for internal mode. Do not return failure, 164 /* Only set the clock for internal mode. Do not return failure,
165 simply treat it as a non-event. */ 165 simply treat it as a non-event. */
166 if (chip->input_clock != ECHO_CLOCK_INTERNAL) { 166 if (chip->input_clock != ECHO_CLOCK_INTERNAL) {
167 DE_ACT(("set_sample_rate: Cannot set sample rate - " 167 dev_warn(chip->card->dev,
168 "clock not set to CLK_CLOCKININTERNAL\n")); 168 "Cannot set sample rate - clock not set to CLK_CLOCKININTERNAL\n");
169 chip->comm_page->sample_rate = cpu_to_le32(rate); 169 chip->comm_page->sample_rate = cpu_to_le32(rate);
170 chip->sample_rate = rate; 170 chip->sample_rate = rate;
171 return 0; 171 return 0;
@@ -174,7 +174,7 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
174 if (wait_handshake(chip)) 174 if (wait_handshake(chip))
175 return -EIO; 175 return -EIO;
176 176
177 DE_ACT(("set_sample_rate(%d)\n", rate)); 177 dev_dbg(chip->card->dev, "set_sample_rate(%d)\n", rate);
178 chip->sample_rate = rate; 178 chip->sample_rate = rate;
179 chip->comm_page->sample_rate = cpu_to_le32(rate); 179 chip->comm_page->sample_rate = cpu_to_le32(rate);
180 clear_handshake(chip); 180 clear_handshake(chip);
@@ -188,29 +188,25 @@ static int set_input_clock(struct echoaudio *chip, u16 clock_source)
188 u16 clock; 188 u16 clock;
189 u32 rate; 189 u32 rate;
190 190
191 DE_ACT(("set_input_clock:\n"));
192 rate = 0; 191 rate = 0;
193 switch (clock_source) { 192 switch (clock_source) {
194 case ECHO_CLOCK_INTERNAL: 193 case ECHO_CLOCK_INTERNAL:
195 DE_ACT(("Set Layla20 clock to INTERNAL\n"));
196 rate = chip->sample_rate; 194 rate = chip->sample_rate;
197 clock = LAYLA20_CLOCK_INTERNAL; 195 clock = LAYLA20_CLOCK_INTERNAL;
198 break; 196 break;
199 case ECHO_CLOCK_SPDIF: 197 case ECHO_CLOCK_SPDIF:
200 DE_ACT(("Set Layla20 clock to SPDIF\n"));
201 clock = LAYLA20_CLOCK_SPDIF; 198 clock = LAYLA20_CLOCK_SPDIF;
202 break; 199 break;
203 case ECHO_CLOCK_WORD: 200 case ECHO_CLOCK_WORD:
204 DE_ACT(("Set Layla20 clock to WORD\n"));
205 clock = LAYLA20_CLOCK_WORD; 201 clock = LAYLA20_CLOCK_WORD;
206 break; 202 break;
207 case ECHO_CLOCK_SUPER: 203 case ECHO_CLOCK_SUPER:
208 DE_ACT(("Set Layla20 clock to SUPER\n"));
209 clock = LAYLA20_CLOCK_SUPER; 204 clock = LAYLA20_CLOCK_SUPER;
210 break; 205 break;
211 default: 206 default:
212 DE_ACT(("Input clock 0x%x not supported for Layla24\n", 207 dev_err(chip->card->dev,
213 clock_source)); 208 "Input clock 0x%x not supported for Layla24\n",
209 clock_source);
214 return -EINVAL; 210 return -EINVAL;
215 } 211 }
216 chip->input_clock = clock_source; 212 chip->input_clock = clock_source;
@@ -229,7 +225,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock_source)
229 225
230static int set_output_clock(struct echoaudio *chip, u16 clock) 226static int set_output_clock(struct echoaudio *chip, u16 clock)
231{ 227{
232 DE_ACT(("set_output_clock: %d\n", clock));
233 switch (clock) { 228 switch (clock) {
234 case ECHO_CLOCK_SUPER: 229 case ECHO_CLOCK_SUPER:
235 clock = LAYLA20_OUTPUT_CLOCK_SUPER; 230 clock = LAYLA20_OUTPUT_CLOCK_SUPER;
@@ -238,7 +233,7 @@ static int set_output_clock(struct echoaudio *chip, u16 clock)
238 clock = LAYLA20_OUTPUT_CLOCK_WORD; 233 clock = LAYLA20_OUTPUT_CLOCK_WORD;
239 break; 234 break;
240 default: 235 default:
241 DE_ACT(("set_output_clock wrong clock\n")); 236 dev_err(chip->card->dev, "set_output_clock wrong clock\n");
242 return -EINVAL; 237 return -EINVAL;
243 } 238 }
244 239
@@ -283,7 +278,6 @@ static int update_flags(struct echoaudio *chip)
283 278
284static int set_professional_spdif(struct echoaudio *chip, char prof) 279static int set_professional_spdif(struct echoaudio *chip, char prof)
285{ 280{
286 DE_ACT(("set_professional_spdif %d\n", prof));
287 if (prof) 281 if (prof)
288 chip->comm_page->flags |= 282 chip->comm_page->flags |=
289 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 283 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
diff --git a/sound/pci/echoaudio/layla24_dsp.c b/sound/pci/echoaudio/layla24_dsp.c
index 8c041647f285..4f11e81f6c0e 100644
--- a/sound/pci/echoaudio/layla24_dsp.c
+++ b/sound/pci/echoaudio/layla24_dsp.c
@@ -40,12 +40,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
40{ 40{
41 int err; 41 int err;
42 42
43 DE_INIT(("init_hw() - Layla24\n"));
44 if (snd_BUG_ON((subdevice_id & 0xfff0) != LAYLA24)) 43 if (snd_BUG_ON((subdevice_id & 0xfff0) != LAYLA24))
45 return -ENODEV; 44 return -ENODEV;
46 45
47 if ((err = init_dsp_comm_page(chip))) { 46 if ((err = init_dsp_comm_page(chip))) {
48 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 47 dev_err(chip->card->dev,
48 "init_hw - could not initialize DSP comm page\n");
49 return err; 49 return err;
50 } 50 }
51 51
@@ -69,7 +69,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
69 if ((err = init_line_levels(chip)) < 0) 69 if ((err = init_line_levels(chip)) < 0)
70 return err; 70 return err;
71 71
72 DE_INIT(("init_hw done\n"));
73 return err; 72 return err;
74} 73}
75 74
@@ -117,7 +116,6 @@ static int load_asic(struct echoaudio *chip)
117 if (chip->asic_loaded) 116 if (chip->asic_loaded)
118 return 1; 117 return 1;
119 118
120 DE_INIT(("load_asic\n"));
121 119
122 /* Give the DSP a few milliseconds to settle down */ 120 /* Give the DSP a few milliseconds to settle down */
123 mdelay(10); 121 mdelay(10);
@@ -151,7 +149,6 @@ static int load_asic(struct echoaudio *chip)
151 err = write_control_reg(chip, GML_CONVERTER_ENABLE | GML_48KHZ, 149 err = write_control_reg(chip, GML_CONVERTER_ENABLE | GML_48KHZ,
152 TRUE); 150 TRUE);
153 151
154 DE_INIT(("load_asic() done\n"));
155 return err; 152 return err;
156} 153}
157 154
@@ -167,8 +164,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
167 164
168 /* Only set the clock for internal mode. */ 165 /* Only set the clock for internal mode. */
169 if (chip->input_clock != ECHO_CLOCK_INTERNAL) { 166 if (chip->input_clock != ECHO_CLOCK_INTERNAL) {
170 DE_ACT(("set_sample_rate: Cannot set sample rate - " 167 dev_warn(chip->card->dev,
171 "clock not set to CLK_CLOCKININTERNAL\n")); 168 "Cannot set sample rate - clock not set to CLK_CLOCKININTERNAL\n");
172 /* Save the rate anyhow */ 169 /* Save the rate anyhow */
173 chip->comm_page->sample_rate = cpu_to_le32(rate); 170 chip->comm_page->sample_rate = cpu_to_le32(rate);
174 chip->sample_rate = rate; 171 chip->sample_rate = rate;
@@ -241,7 +238,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
241 238
242 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP ? */ 239 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP ? */
243 chip->sample_rate = rate; 240 chip->sample_rate = rate;
244 DE_ACT(("set_sample_rate: %d clock %d\n", rate, control_reg)); 241 dev_dbg(chip->card->dev,
242 "set_sample_rate: %d clock %d\n", rate, control_reg);
245 243
246 return write_control_reg(chip, control_reg, FALSE); 244 return write_control_reg(chip, control_reg, FALSE);
247} 245}
@@ -260,7 +258,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
260 /* Pick the new clock */ 258 /* Pick the new clock */
261 switch (clock) { 259 switch (clock) {
262 case ECHO_CLOCK_INTERNAL: 260 case ECHO_CLOCK_INTERNAL:
263 DE_ACT(("Set Layla24 clock to INTERNAL\n"));
264 chip->input_clock = ECHO_CLOCK_INTERNAL; 261 chip->input_clock = ECHO_CLOCK_INTERNAL;
265 return set_sample_rate(chip, chip->sample_rate); 262 return set_sample_rate(chip, chip->sample_rate);
266 case ECHO_CLOCK_SPDIF: 263 case ECHO_CLOCK_SPDIF:
@@ -269,7 +266,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
269 control_reg |= GML_SPDIF_CLOCK; 266 control_reg |= GML_SPDIF_CLOCK;
270 /* Layla24 doesn't support 96KHz S/PDIF */ 267 /* Layla24 doesn't support 96KHz S/PDIF */
271 control_reg &= ~GML_DOUBLE_SPEED_MODE; 268 control_reg &= ~GML_DOUBLE_SPEED_MODE;
272 DE_ACT(("Set Layla24 clock to SPDIF\n"));
273 break; 269 break;
274 case ECHO_CLOCK_WORD: 270 case ECHO_CLOCK_WORD:
275 control_reg |= GML_WORD_CLOCK; 271 control_reg |= GML_WORD_CLOCK;
@@ -277,17 +273,16 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
277 control_reg |= GML_DOUBLE_SPEED_MODE; 273 control_reg |= GML_DOUBLE_SPEED_MODE;
278 else 274 else
279 control_reg &= ~GML_DOUBLE_SPEED_MODE; 275 control_reg &= ~GML_DOUBLE_SPEED_MODE;
280 DE_ACT(("Set Layla24 clock to WORD\n"));
281 break; 276 break;
282 case ECHO_CLOCK_ADAT: 277 case ECHO_CLOCK_ADAT:
283 if (chip->digital_mode != DIGITAL_MODE_ADAT) 278 if (chip->digital_mode != DIGITAL_MODE_ADAT)
284 return -EAGAIN; 279 return -EAGAIN;
285 control_reg |= GML_ADAT_CLOCK; 280 control_reg |= GML_ADAT_CLOCK;
286 control_reg &= ~GML_DOUBLE_SPEED_MODE; 281 control_reg &= ~GML_DOUBLE_SPEED_MODE;
287 DE_ACT(("Set Layla24 clock to ADAT\n"));
288 break; 282 break;
289 default: 283 default:
290 DE_ACT(("Input clock 0x%x not supported for Layla24\n", clock)); 284 dev_err(chip->card->dev,
285 "Input clock 0x%x not supported for Layla24\n", clock);
291 return -EINVAL; 286 return -EINVAL;
292 } 287 }
293 288
@@ -353,7 +348,8 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
353 asic = FW_LAYLA24_2A_ASIC; 348 asic = FW_LAYLA24_2A_ASIC;
354 break; 349 break;
355 default: 350 default:
356 DE_ACT(("Digital mode not supported: %d\n", mode)); 351 dev_err(chip->card->dev,
352 "Digital mode not supported: %d\n", mode);
357 return -EINVAL; 353 return -EINVAL;
358 } 354 }
359 355
@@ -393,6 +389,6 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
393 return err; 389 return err;
394 chip->digital_mode = mode; 390 chip->digital_mode = mode;
395 391
396 DE_ACT(("set_digital_mode to %d\n", mode)); 392 dev_dbg(chip->card->dev, "set_digital_mode to %d\n", mode);
397 return incompatible_clock; 393 return incompatible_clock;
398} 394}
diff --git a/sound/pci/echoaudio/mia_dsp.c b/sound/pci/echoaudio/mia_dsp.c
index 6ebfa6e7ab9e..fdad079ad9a1 100644
--- a/sound/pci/echoaudio/mia_dsp.c
+++ b/sound/pci/echoaudio/mia_dsp.c
@@ -41,12 +41,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
41{ 41{
42 int err; 42 int err;
43 43
44 DE_INIT(("init_hw() - Mia\n"));
45 if (snd_BUG_ON((subdevice_id & 0xfff0) != MIA)) 44 if (snd_BUG_ON((subdevice_id & 0xfff0) != MIA))
46 return -ENODEV; 45 return -ENODEV;
47 46
48 if ((err = init_dsp_comm_page(chip))) { 47 if ((err = init_dsp_comm_page(chip))) {
49 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 48 dev_err(chip->card->dev,
49 "init_hw - could not initialize DSP comm page\n");
50 return err; 50 return err;
51 } 51 }
52 52
@@ -66,7 +66,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
66 return err; 66 return err;
67 chip->bad_board = FALSE; 67 chip->bad_board = FALSE;
68 68
69 DE_INIT(("init_hw done\n"));
70 return err; 69 return err;
71} 70}
72 71
@@ -126,7 +125,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
126 control_reg = MIA_32000; 125 control_reg = MIA_32000;
127 break; 126 break;
128 default: 127 default:
129 DE_ACT(("set_sample_rate: %d invalid!\n", rate)); 128 dev_err(chip->card->dev,
129 "set_sample_rate: %d invalid!\n", rate);
130 return -EINVAL; 130 return -EINVAL;
131 } 131 }
132 132
@@ -153,7 +153,7 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
153 153
154static int set_input_clock(struct echoaudio *chip, u16 clock) 154static int set_input_clock(struct echoaudio *chip, u16 clock)
155{ 155{
156 DE_ACT(("set_input_clock(%d)\n", clock)); 156 dev_dbg(chip->card->dev, "set_input_clock(%d)\n", clock);
157 if (snd_BUG_ON(clock != ECHO_CLOCK_INTERNAL && 157 if (snd_BUG_ON(clock != ECHO_CLOCK_INTERNAL &&
158 clock != ECHO_CLOCK_SPDIF)) 158 clock != ECHO_CLOCK_SPDIF))
159 return -EINVAL; 159 return -EINVAL;
@@ -181,7 +181,8 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
181 index = output * num_pipes_out(chip) + pipe; 181 index = output * num_pipes_out(chip) + pipe;
182 chip->comm_page->vmixer[index] = gain; 182 chip->comm_page->vmixer[index] = gain;
183 183
184 DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain)); 184 dev_dbg(chip->card->dev,
185 "set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
185 return 0; 186 return 0;
186} 187}
187 188
@@ -211,7 +212,7 @@ static int update_flags(struct echoaudio *chip)
211 212
212static int set_professional_spdif(struct echoaudio *chip, char prof) 213static int set_professional_spdif(struct echoaudio *chip, char prof)
213{ 214{
214 DE_ACT(("set_professional_spdif %d\n", prof)); 215 dev_dbg(chip->card->dev, "set_professional_spdif %d\n", prof);
215 if (prof) 216 if (prof)
216 chip->comm_page->flags |= 217 chip->comm_page->flags |=
217 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 218 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
diff --git a/sound/pci/echoaudio/midi.c b/sound/pci/echoaudio/midi.c
index 7f4dfae0323a..d913749d154a 100644
--- a/sound/pci/echoaudio/midi.c
+++ b/sound/pci/echoaudio/midi.c
@@ -36,7 +36,7 @@
36/* Start and stop Midi input */ 36/* Start and stop Midi input */
37static int enable_midi_input(struct echoaudio *chip, char enable) 37static int enable_midi_input(struct echoaudio *chip, char enable)
38{ 38{
39 DE_MID(("enable_midi_input(%d)\n", enable)); 39 dev_dbg(chip->card->dev, "enable_midi_input(%d)\n", enable);
40 40
41 if (wait_handshake(chip)) 41 if (wait_handshake(chip))
42 return -EIO; 42 return -EIO;
@@ -74,7 +74,7 @@ static int write_midi(struct echoaudio *chip, u8 *data, int bytes)
74 chip->comm_page->midi_out_free_count = 0; 74 chip->comm_page->midi_out_free_count = 0;
75 clear_handshake(chip); 75 clear_handshake(chip);
76 send_vector(chip, DSP_VC_MIDI_WRITE); 76 send_vector(chip, DSP_VC_MIDI_WRITE);
77 DE_MID(("write_midi: %d\n", bytes)); 77 dev_dbg(chip->card->dev, "write_midi: %d\n", bytes);
78 return bytes; 78 return bytes;
79} 79}
80 80
@@ -157,7 +157,6 @@ static int snd_echo_midi_input_open(struct snd_rawmidi_substream *substream)
157 struct echoaudio *chip = substream->rmidi->private_data; 157 struct echoaudio *chip = substream->rmidi->private_data;
158 158
159 chip->midi_in = substream; 159 chip->midi_in = substream;
160 DE_MID(("rawmidi_iopen\n"));
161 return 0; 160 return 0;
162} 161}
163 162
@@ -183,7 +182,6 @@ static int snd_echo_midi_input_close(struct snd_rawmidi_substream *substream)
183 struct echoaudio *chip = substream->rmidi->private_data; 182 struct echoaudio *chip = substream->rmidi->private_data;
184 183
185 chip->midi_in = NULL; 184 chip->midi_in = NULL;
186 DE_MID(("rawmidi_iclose\n"));
187 return 0; 185 return 0;
188} 186}
189 187
@@ -196,7 +194,6 @@ static int snd_echo_midi_output_open(struct snd_rawmidi_substream *substream)
196 chip->tinuse = 0; 194 chip->tinuse = 0;
197 chip->midi_full = 0; 195 chip->midi_full = 0;
198 chip->midi_out = substream; 196 chip->midi_out = substream;
199 DE_MID(("rawmidi_oopen\n"));
200 return 0; 197 return 0;
201} 198}
202 199
@@ -209,7 +206,6 @@ static void snd_echo_midi_output_write(unsigned long data)
209 int bytes, sent, time; 206 int bytes, sent, time;
210 unsigned char buf[MIDI_OUT_BUFFER_SIZE - 1]; 207 unsigned char buf[MIDI_OUT_BUFFER_SIZE - 1];
211 208
212 DE_MID(("snd_echo_midi_output_write\n"));
213 /* No interrupts are involved: we have to check at regular intervals 209 /* No interrupts are involved: we have to check at regular intervals
214 if the card's output buffer has room for new data. */ 210 if the card's output buffer has room for new data. */
215 sent = bytes = 0; 211 sent = bytes = 0;
@@ -218,7 +214,7 @@ static void snd_echo_midi_output_write(unsigned long data)
218 if (!snd_rawmidi_transmit_empty(chip->midi_out)) { 214 if (!snd_rawmidi_transmit_empty(chip->midi_out)) {
219 bytes = snd_rawmidi_transmit_peek(chip->midi_out, buf, 215 bytes = snd_rawmidi_transmit_peek(chip->midi_out, buf,
220 MIDI_OUT_BUFFER_SIZE - 1); 216 MIDI_OUT_BUFFER_SIZE - 1);
221 DE_MID(("Try to send %d bytes...\n", bytes)); 217 dev_dbg(chip->card->dev, "Try to send %d bytes...\n", bytes);
222 sent = write_midi(chip, buf, bytes); 218 sent = write_midi(chip, buf, bytes);
223 if (sent < 0) { 219 if (sent < 0) {
224 dev_err(chip->card->dev, 220 dev_err(chip->card->dev,
@@ -227,12 +223,12 @@ static void snd_echo_midi_output_write(unsigned long data)
227 sent = 9000; 223 sent = 9000;
228 chip->midi_full = 1; 224 chip->midi_full = 1;
229 } else if (sent > 0) { 225 } else if (sent > 0) {
230 DE_MID(("%d bytes sent\n", sent)); 226 dev_dbg(chip->card->dev, "%d bytes sent\n", sent);
231 snd_rawmidi_transmit_ack(chip->midi_out, sent); 227 snd_rawmidi_transmit_ack(chip->midi_out, sent);
232 } else { 228 } else {
233 /* Buffer is full. DSP's internal buffer is 64 (128 ?) 229 /* Buffer is full. DSP's internal buffer is 64 (128 ?)
234 bytes long. Let's wait until half of them are sent */ 230 bytes long. Let's wait until half of them are sent */
235 DE_MID(("Full\n")); 231 dev_dbg(chip->card->dev, "Full\n");
236 sent = 32; 232 sent = 32;
237 chip->midi_full = 1; 233 chip->midi_full = 1;
238 } 234 }
@@ -244,7 +240,8 @@ static void snd_echo_midi_output_write(unsigned long data)
244 sent */ 240 sent */
245 time = (sent << 3) / 25 + 1; /* 8/25=0.32ms to send a byte */ 241 time = (sent << 3) / 25 + 1; /* 8/25=0.32ms to send a byte */
246 mod_timer(&chip->timer, jiffies + (time * HZ + 999) / 1000); 242 mod_timer(&chip->timer, jiffies + (time * HZ + 999) / 1000);
247 DE_MID(("Timer armed(%d)\n", ((time * HZ + 999) / 1000))); 243 dev_dbg(chip->card->dev,
244 "Timer armed(%d)\n", ((time * HZ + 999) / 1000));
248 } 245 }
249 spin_unlock_irqrestore(&chip->lock, flags); 246 spin_unlock_irqrestore(&chip->lock, flags);
250} 247}
@@ -256,7 +253,7 @@ static void snd_echo_midi_output_trigger(struct snd_rawmidi_substream *substream
256{ 253{
257 struct echoaudio *chip = substream->rmidi->private_data; 254 struct echoaudio *chip = substream->rmidi->private_data;
258 255
259 DE_MID(("snd_echo_midi_output_trigger(%d)\n", up)); 256 dev_dbg(chip->card->dev, "snd_echo_midi_output_trigger(%d)\n", up);
260 spin_lock_irq(&chip->lock); 257 spin_lock_irq(&chip->lock);
261 if (up) { 258 if (up) {
262 if (!chip->tinuse) { 259 if (!chip->tinuse) {
@@ -270,7 +267,7 @@ static void snd_echo_midi_output_trigger(struct snd_rawmidi_substream *substream
270 chip->tinuse = 0; 267 chip->tinuse = 0;
271 spin_unlock_irq(&chip->lock); 268 spin_unlock_irq(&chip->lock);
272 del_timer_sync(&chip->timer); 269 del_timer_sync(&chip->timer);
273 DE_MID(("Timer removed\n")); 270 dev_dbg(chip->card->dev, "Timer removed\n");
274 return; 271 return;
275 } 272 }
276 } 273 }
@@ -287,7 +284,6 @@ static int snd_echo_midi_output_close(struct snd_rawmidi_substream *substream)
287 struct echoaudio *chip = substream->rmidi->private_data; 284 struct echoaudio *chip = substream->rmidi->private_data;
288 285
289 chip->midi_out = NULL; 286 chip->midi_out = NULL;
290 DE_MID(("rawmidi_oclose\n"));
291 return 0; 287 return 0;
292} 288}
293 289
@@ -327,6 +323,5 @@ static int snd_echo_midi_create(struct snd_card *card,
327 323
328 chip->rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | 324 chip->rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
329 SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; 325 SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX;
330 DE_INIT(("MIDI ok\n"));
331 return 0; 326 return 0;
332} 327}
diff --git a/sound/pci/echoaudio/mona_dsp.c b/sound/pci/echoaudio/mona_dsp.c
index 6e6a7eb555b8..843c7a5e5105 100644
--- a/sound/pci/echoaudio/mona_dsp.c
+++ b/sound/pci/echoaudio/mona_dsp.c
@@ -41,12 +41,12 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
41{ 41{
42 int err; 42 int err;
43 43
44 DE_INIT(("init_hw() - Mona\n"));
45 if (snd_BUG_ON((subdevice_id & 0xfff0) != MONA)) 44 if (snd_BUG_ON((subdevice_id & 0xfff0) != MONA))
46 return -ENODEV; 45 return -ENODEV;
47 46
48 if ((err = init_dsp_comm_page(chip))) { 47 if ((err = init_dsp_comm_page(chip))) {
49 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 48 dev_err(chip->card->dev,
49 "init_hw - could not initialize DSP comm page\n");
50 return err; 50 return err;
51 } 51 }
52 52
@@ -71,7 +71,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
71 return err; 71 return err;
72 chip->bad_board = FALSE; 72 chip->bad_board = FALSE;
73 73
74 DE_INIT(("init_hw done\n"));
75 return err; 74 return err;
76} 75}
77 76
@@ -202,8 +201,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
202 201
203 /* Only set the clock for internal mode. */ 202 /* Only set the clock for internal mode. */
204 if (chip->input_clock != ECHO_CLOCK_INTERNAL) { 203 if (chip->input_clock != ECHO_CLOCK_INTERNAL) {
205 DE_ACT(("set_sample_rate: Cannot set sample rate - " 204 dev_dbg(chip->card->dev,
206 "clock not set to CLK_CLOCKININTERNAL\n")); 205 "Cannot set sample rate - clock not set to CLK_CLOCKININTERNAL\n");
207 /* Save the rate anyhow */ 206 /* Save the rate anyhow */
208 chip->comm_page->sample_rate = cpu_to_le32(rate); 207 chip->comm_page->sample_rate = cpu_to_le32(rate);
209 chip->sample_rate = rate; 208 chip->sample_rate = rate;
@@ -279,7 +278,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
279 clock = GML_8KHZ; 278 clock = GML_8KHZ;
280 break; 279 break;
281 default: 280 default:
282 DE_ACT(("set_sample_rate: %d invalid!\n", rate)); 281 dev_err(chip->card->dev,
282 "set_sample_rate: %d invalid!\n", rate);
283 return -EINVAL; 283 return -EINVAL;
284 } 284 }
285 285
@@ -287,7 +287,8 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
287 287
288 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */ 288 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */
289 chip->sample_rate = rate; 289 chip->sample_rate = rate;
290 DE_ACT(("set_sample_rate: %d clock %d\n", rate, clock)); 290 dev_dbg(chip->card->dev,
291 "set_sample_rate: %d clock %d\n", rate, clock);
291 292
292 return write_control_reg(chip, control_reg, force_write); 293 return write_control_reg(chip, control_reg, force_write);
293} 294}
@@ -299,7 +300,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
299 u32 control_reg, clocks_from_dsp; 300 u32 control_reg, clocks_from_dsp;
300 int err; 301 int err;
301 302
302 DE_ACT(("set_input_clock:\n"));
303 303
304 /* Prevent two simultaneous calls to switch_asic() */ 304 /* Prevent two simultaneous calls to switch_asic() */
305 if (atomic_read(&chip->opencount)) 305 if (atomic_read(&chip->opencount))
@@ -312,7 +312,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
312 312
313 switch (clock) { 313 switch (clock) {
314 case ECHO_CLOCK_INTERNAL: 314 case ECHO_CLOCK_INTERNAL:
315 DE_ACT(("Set Mona clock to INTERNAL\n"));
316 chip->input_clock = ECHO_CLOCK_INTERNAL; 315 chip->input_clock = ECHO_CLOCK_INTERNAL;
317 return set_sample_rate(chip, chip->sample_rate); 316 return set_sample_rate(chip, chip->sample_rate);
318 case ECHO_CLOCK_SPDIF: 317 case ECHO_CLOCK_SPDIF:
@@ -324,7 +323,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
324 spin_lock_irq(&chip->lock); 323 spin_lock_irq(&chip->lock);
325 if (err < 0) 324 if (err < 0)
326 return err; 325 return err;
327 DE_ACT(("Set Mona clock to SPDIF\n"));
328 control_reg |= GML_SPDIF_CLOCK; 326 control_reg |= GML_SPDIF_CLOCK;
329 if (clocks_from_dsp & GML_CLOCK_DETECT_BIT_SPDIF96) 327 if (clocks_from_dsp & GML_CLOCK_DETECT_BIT_SPDIF96)
330 control_reg |= GML_DOUBLE_SPEED_MODE; 328 control_reg |= GML_DOUBLE_SPEED_MODE;
@@ -332,7 +330,6 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
332 control_reg &= ~GML_DOUBLE_SPEED_MODE; 330 control_reg &= ~GML_DOUBLE_SPEED_MODE;
333 break; 331 break;
334 case ECHO_CLOCK_WORD: 332 case ECHO_CLOCK_WORD:
335 DE_ACT(("Set Mona clock to WORD\n"));
336 spin_unlock_irq(&chip->lock); 333 spin_unlock_irq(&chip->lock);
337 err = switch_asic(chip, clocks_from_dsp & 334 err = switch_asic(chip, clocks_from_dsp &
338 GML_CLOCK_DETECT_BIT_WORD96); 335 GML_CLOCK_DETECT_BIT_WORD96);
@@ -346,14 +343,15 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
346 control_reg &= ~GML_DOUBLE_SPEED_MODE; 343 control_reg &= ~GML_DOUBLE_SPEED_MODE;
347 break; 344 break;
348 case ECHO_CLOCK_ADAT: 345 case ECHO_CLOCK_ADAT:
349 DE_ACT(("Set Mona clock to ADAT\n")); 346 dev_dbg(chip->card->dev, "Set Mona clock to ADAT\n");
350 if (chip->digital_mode != DIGITAL_MODE_ADAT) 347 if (chip->digital_mode != DIGITAL_MODE_ADAT)
351 return -EAGAIN; 348 return -EAGAIN;
352 control_reg |= GML_ADAT_CLOCK; 349 control_reg |= GML_ADAT_CLOCK;
353 control_reg &= ~GML_DOUBLE_SPEED_MODE; 350 control_reg &= ~GML_DOUBLE_SPEED_MODE;
354 break; 351 break;
355 default: 352 default:
356 DE_ACT(("Input clock 0x%x not supported for Mona\n", clock)); 353 dev_err(chip->card->dev,
354 "Input clock 0x%x not supported for Mona\n", clock);
357 return -EINVAL; 355 return -EINVAL;
358 } 356 }
359 357
@@ -381,7 +379,8 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
381 incompatible_clock = TRUE; 379 incompatible_clock = TRUE;
382 break; 380 break;
383 default: 381 default:
384 DE_ACT(("Digital mode not supported: %d\n", mode)); 382 dev_err(chip->card->dev,
383 "Digital mode not supported: %d\n", mode);
385 return -EINVAL; 384 return -EINVAL;
386 } 385 }
387 386
@@ -422,6 +421,6 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
422 return err; 421 return err;
423 chip->digital_mode = mode; 422 chip->digital_mode = mode;
424 423
425 DE_ACT(("set_digital_mode to %d\n", mode)); 424 dev_dbg(chip->card->dev, "set_digital_mode to %d\n", mode);
426 return incompatible_clock; 425 return incompatible_clock;
427} 426}
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 229269788023..b4458a630a7c 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -1289,10 +1289,8 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1289 } 1289 }
1290 if (emu->emu1010.firmware_thread) 1290 if (emu->emu1010.firmware_thread)
1291 kthread_stop(emu->emu1010.firmware_thread); 1291 kthread_stop(emu->emu1010.firmware_thread);
1292 if (emu->firmware) 1292 release_firmware(emu->firmware);
1293 release_firmware(emu->firmware); 1293 release_firmware(emu->dock_fw);
1294 if (emu->dock_fw)
1295 release_firmware(emu->dock_fw);
1296 if (emu->irq >= 0) 1294 if (emu->irq >= 0)
1297 free_irq(emu->irq, emu); 1295 free_irq(emu->irq, emu);
1298 /* remove reserved page */ 1296 /* remove reserved page */
@@ -1301,8 +1299,7 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1301 (struct snd_util_memblk *)emu->reserved_page); 1299 (struct snd_util_memblk *)emu->reserved_page);
1302 emu->reserved_page = NULL; 1300 emu->reserved_page = NULL;
1303 } 1301 }
1304 if (emu->memhdr) 1302 snd_util_memhdr_free(emu->memhdr);
1305 snd_util_memhdr_free(emu->memhdr);
1306 if (emu->silent_page.area) 1303 if (emu->silent_page.area)
1307 snd_dma_free_pages(&emu->silent_page); 1304 snd_dma_free_pages(&emu->silent_page);
1308 if (emu->ptb_pages.area) 1305 if (emu->ptb_pages.area)
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index e223de1408c0..15933f92f63a 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -180,7 +180,7 @@ MODULE_PARM_DESC(enable, "Enable the EMU10K1X soundcard.");
180 180
181/* From 0x50 - 0x5f, last samples captured */ 181/* From 0x50 - 0x5f, last samples captured */
182 182
183/** 183/*
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
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 745f0627c634..eb5c0aba41c1 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -777,8 +777,7 @@ static void snd_emu10k1_ctl_private_free(struct snd_kcontrol *kctl)
777 kctl->private_value = 0; 777 kctl->private_value = 0;
778 list_del(&ctl->list); 778 list_del(&ctl->list);
779 kfree(ctl); 779 kfree(ctl);
780 if (kctl->tlv.p) 780 kfree(kctl->tlv.p);
781 kfree(kctl->tlv.p);
782} 781}
783 782
784static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu, 783static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu,
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index c5ae2a24d8a5..1de33025669a 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -83,7 +83,7 @@ static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
83 * Items labels in enum mixer controls assigning source data to 83 * Items labels in enum mixer controls assigning source data to
84 * each destination 84 * each destination
85 */ 85 */
86static char *emu1010_src_texts[] = { 86static const char * const emu1010_src_texts[] = {
87 "Silence", 87 "Silence",
88 "Dock Mic A", 88 "Dock Mic A",
89 "Dock Mic B", 89 "Dock Mic B",
@@ -141,7 +141,7 @@ static char *emu1010_src_texts[] = {
141 141
142/* 1616(m) cardbus */ 142/* 1616(m) cardbus */
143 143
144static char *emu1616_src_texts[] = { 144static const char * const emu1616_src_texts[] = {
145 "Silence", 145 "Silence",
146 "Dock Mic A", 146 "Dock Mic A",
147 "Dock Mic B", 147 "Dock Mic B",
@@ -393,23 +393,11 @@ static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol,
393 struct snd_ctl_elem_info *uinfo) 393 struct snd_ctl_elem_info *uinfo)
394{ 394{
395 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 395 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
396 char **items;
397 396
398 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 397 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616)
399 uinfo->count = 1; 398 return snd_ctl_enum_info(uinfo, 1, 49, emu1616_src_texts);
400 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) { 399 else
401 uinfo->value.enumerated.items = 49; 400 return snd_ctl_enum_info(uinfo, 1, 53, emu1010_src_texts);
402 items = emu1616_src_texts;
403 } else {
404 uinfo->value.enumerated.items = 53;
405 items = emu1010_src_texts;
406 }
407 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
408 uinfo->value.enumerated.item =
409 uinfo->value.enumerated.items - 1;
410 strcpy(uinfo->value.enumerated.name,
411 items[uinfo->value.enumerated.item]);
412 return 0;
413} 401}
414 402
415static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol, 403static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol,
@@ -699,19 +687,11 @@ static struct snd_kcontrol_new snd_emu1010_dac_pads[] = {
699static int snd_emu1010_internal_clock_info(struct snd_kcontrol *kcontrol, 687static int snd_emu1010_internal_clock_info(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_info *uinfo) 688 struct snd_ctl_elem_info *uinfo)
701{ 689{
702 static char *texts[4] = { 690 static const char * const texts[4] = {
703 "44100", "48000", "SPDIF", "ADAT" 691 "44100", "48000", "SPDIF", "ADAT"
704 }; 692 };
705 693
706 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 694 return snd_ctl_enum_info(uinfo, 1, 4, texts);
707 uinfo->count = 1;
708 uinfo->value.enumerated.items = 4;
709 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
710 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
711 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
712 return 0;
713
714
715} 695}
716 696
717static int snd_emu1010_internal_clock_get(struct snd_kcontrol *kcontrol, 697static int snd_emu1010_internal_clock_get(struct snd_kcontrol *kcontrol,
@@ -830,21 +810,15 @@ static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
830 struct snd_ctl_elem_info *uinfo) 810 struct snd_ctl_elem_info *uinfo)
831{ 811{
832#if 0 812#if 0
833 static char *texts[4] = { 813 static const char * const texts[4] = {
834 "Unknown1", "Unknown2", "Mic", "Line" 814 "Unknown1", "Unknown2", "Mic", "Line"
835 }; 815 };
836#endif 816#endif
837 static char *texts[2] = { 817 static const char * const texts[2] = {
838 "Mic", "Line" 818 "Mic", "Line"
839 }; 819 };
840 820
841 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 821 return snd_ctl_enum_info(uinfo, 1, 2, texts);
842 uinfo->count = 1;
843 uinfo->value.enumerated.items = 2;
844 if (uinfo->value.enumerated.item > 1)
845 uinfo->value.enumerated.item = 1;
846 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
847 return 0;
848} 822}
849 823
850static int snd_audigy_i2c_capture_source_get(struct snd_kcontrol *kcontrol, 824static int snd_audigy_i2c_capture_source_get(struct snd_kcontrol *kcontrol,
@@ -997,15 +971,9 @@ static struct snd_kcontrol_new snd_audigy_i2c_volume_ctls[] = {
997#if 0 971#if 0
998static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 972static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
999{ 973{
1000 static char *texts[] = {"44100", "48000", "96000"}; 974 static const char * const texts[] = {"44100", "48000", "96000"};
1001 975
1002 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 976 return snd_ctl_enum_info(uinfo, 1, 3, texts);
1003 uinfo->count = 1;
1004 uinfo->value.enumerated.items = 3;
1005 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1006 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1007 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1008 return 0;
1009} 977}
1010 978
1011static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol, 979static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
index a4fe7f0c9458..7ef3898a7806 100644
--- a/sound/pci/emu10k1/p16v.c
+++ b/sound/pci/emu10k1/p16v.c
@@ -757,18 +757,12 @@ static int snd_p16v_volume_put(struct snd_kcontrol *kcontrol,
757static int snd_p16v_capture_source_info(struct snd_kcontrol *kcontrol, 757static int snd_p16v_capture_source_info(struct snd_kcontrol *kcontrol,
758 struct snd_ctl_elem_info *uinfo) 758 struct snd_ctl_elem_info *uinfo)
759{ 759{
760 static char *texts[8] = { 760 static const char * const texts[8] = {
761 "SPDIF", "I2S", "SRC48", "SRCMulti_SPDIF", "SRCMulti_I2S", 761 "SPDIF", "I2S", "SRC48", "SRCMulti_SPDIF", "SRCMulti_I2S",
762 "CDIF", "FX", "AC97" 762 "CDIF", "FX", "AC97"
763 }; 763 };
764 764
765 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 765 return snd_ctl_enum_info(uinfo, 1, 8, texts);
766 uinfo->count = 1;
767 uinfo->value.enumerated.items = 8;
768 if (uinfo->value.enumerated.item > 7)
769 uinfo->value.enumerated.item = 7;
770 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
771 return 0;
772} 766}
773 767
774static int snd_p16v_capture_source_get(struct snd_kcontrol *kcontrol, 768static int snd_p16v_capture_source_get(struct snd_kcontrol *kcontrol,
@@ -805,15 +799,9 @@ static int snd_p16v_capture_source_put(struct snd_kcontrol *kcontrol,
805static int snd_p16v_capture_channel_info(struct snd_kcontrol *kcontrol, 799static int snd_p16v_capture_channel_info(struct snd_kcontrol *kcontrol,
806 struct snd_ctl_elem_info *uinfo) 800 struct snd_ctl_elem_info *uinfo)
807{ 801{
808 static char *texts[4] = { "0", "1", "2", "3", }; 802 static const char * const texts[4] = { "0", "1", "2", "3", };
809 803
810 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 804 return snd_ctl_enum_info(uinfo, 1, 4, texts);
811 uinfo->count = 1;
812 uinfo->value.enumerated.items = 4;
813 if (uinfo->value.enumerated.item > 3)
814 uinfo->value.enumerated.item = 3;
815 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
816 return 0;
817} 805}
818 806
819static int snd_p16v_capture_channel_get(struct snd_kcontrol *kcontrol, 807static int snd_p16v_capture_channel_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 639962443ccc..0fc46eb4e251 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1045,18 +1045,12 @@ static int snd_es1938_new_pcm(struct es1938 *chip, int device)
1045static int snd_es1938_info_mux(struct snd_kcontrol *kcontrol, 1045static int snd_es1938_info_mux(struct snd_kcontrol *kcontrol,
1046 struct snd_ctl_elem_info *uinfo) 1046 struct snd_ctl_elem_info *uinfo)
1047{ 1047{
1048 static char *texts[8] = { 1048 static const char * const texts[8] = {
1049 "Mic", "Mic Master", "CD", "AOUT", 1049 "Mic", "Mic Master", "CD", "AOUT",
1050 "Mic1", "Mix", "Line", "Master" 1050 "Mic1", "Mix", "Line", "Master"
1051 }; 1051 };
1052 1052
1053 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1053 return snd_ctl_enum_info(uinfo, 1, 8, texts);
1054 uinfo->count = 1;
1055 uinfo->value.enumerated.items = 8;
1056 if (uinfo->value.enumerated.item > 7)
1057 uinfo->value.enumerated.item = 7;
1058 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1059 return 0;
1060} 1054}
1061 1055
1062static int snd_es1938_get_mux(struct snd_kcontrol *kcontrol, 1056static int snd_es1938_get_mux(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index a9956a7c5677..6039700f8579 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -1710,7 +1710,8 @@ static void es1968_measure_clock(struct es1968 *chip)
1710 int i, apu; 1710 int i, apu;
1711 unsigned int pa, offset, t; 1711 unsigned int pa, offset, t;
1712 struct esm_memory *memory; 1712 struct esm_memory *memory;
1713 struct timeval start_time, stop_time; 1713 ktime_t start_time, stop_time;
1714 ktime_t diff;
1714 1715
1715 if (chip->clock == 0) 1716 if (chip->clock == 0)
1716 chip->clock = 48000; /* default clock value */ 1717 chip->clock = 48000; /* default clock value */
@@ -1761,12 +1762,12 @@ static void es1968_measure_clock(struct es1968 *chip)
1761 snd_es1968_bob_inc(chip, ESM_BOB_FREQ); 1762 snd_es1968_bob_inc(chip, ESM_BOB_FREQ);
1762 __apu_set_register(chip, apu, 5, pa & 0xffff); 1763 __apu_set_register(chip, apu, 5, pa & 0xffff);
1763 snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR); 1764 snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR);
1764 do_gettimeofday(&start_time); 1765 start_time = ktime_get();
1765 spin_unlock_irq(&chip->reg_lock); 1766 spin_unlock_irq(&chip->reg_lock);
1766 msleep(50); 1767 msleep(50);
1767 spin_lock_irq(&chip->reg_lock); 1768 spin_lock_irq(&chip->reg_lock);
1768 offset = __apu_get_register(chip, apu, 5); 1769 offset = __apu_get_register(chip, apu, 5);
1769 do_gettimeofday(&stop_time); 1770 stop_time = ktime_get();
1770 snd_es1968_trigger_apu(chip, apu, 0); /* stop */ 1771 snd_es1968_trigger_apu(chip, apu, 0); /* stop */
1771 snd_es1968_bob_dec(chip); 1772 snd_es1968_bob_dec(chip);
1772 chip->in_measurement = 0; 1773 chip->in_measurement = 0;
@@ -1777,12 +1778,8 @@ static void es1968_measure_clock(struct es1968 *chip)
1777 offset &= 0xfffe; 1778 offset &= 0xfffe;
1778 offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2); 1779 offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2);
1779 1780
1780 t = stop_time.tv_sec - start_time.tv_sec; 1781 diff = ktime_sub(stop_time, start_time);
1781 t *= 1000000; 1782 t = ktime_to_us(diff);
1782 if (stop_time.tv_usec < start_time.tv_usec)
1783 t -= start_time.tv_usec - stop_time.tv_usec;
1784 else
1785 t += stop_time.tv_usec - start_time.tv_usec;
1786 if (t == 0) { 1783 if (t == 0) {
1787 dev_err(chip->card->dev, "?? calculation error..\n"); 1784 dev_err(chip->card->dev, "?? calculation error..\n");
1788 } else { 1785 } else {
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index c5038303a126..d167afffce5f 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -958,17 +958,11 @@ static int snd_fm801_put_double(struct snd_kcontrol *kcontrol,
958static int snd_fm801_info_mux(struct snd_kcontrol *kcontrol, 958static int snd_fm801_info_mux(struct snd_kcontrol *kcontrol,
959 struct snd_ctl_elem_info *uinfo) 959 struct snd_ctl_elem_info *uinfo)
960{ 960{
961 static char *texts[5] = { 961 static const char * const texts[5] = {
962 "AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary" 962 "AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary"
963 }; 963 };
964 964
965 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 965 return snd_ctl_enum_info(uinfo, 1, 5, texts);
966 uinfo->count = 1;
967 uinfo->value.enumerated.items = 5;
968 if (uinfo->value.enumerated.item > 4)
969 uinfo->value.enumerated.item = 4;
970 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
971 return 0;
972} 966}
973 967
974static int snd_fm801_get_mux(struct snd_kcontrol *kcontrol, 968static int snd_fm801_get_mux(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c
index fcc5e478c9a1..1ede82200ee5 100644
--- a/sound/pci/hda/hda_auto_parser.c
+++ b/sound/pci/hda/hda_auto_parser.c
@@ -441,6 +441,13 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
441} 441}
442EXPORT_SYMBOL_GPL(snd_hda_parse_pin_defcfg); 442EXPORT_SYMBOL_GPL(snd_hda_parse_pin_defcfg);
443 443
444/**
445 * snd_hda_get_input_pin_attr - Get the input pin attribute from pin config
446 * @def_conf: pin configuration value
447 *
448 * Guess the input pin attribute (INPUT_PIN_ATTR_XXX) from the given
449 * default pin configuration value.
450 */
444int snd_hda_get_input_pin_attr(unsigned int def_conf) 451int snd_hda_get_input_pin_attr(unsigned int def_conf)
445{ 452{
446 unsigned int loc = get_defcfg_location(def_conf); 453 unsigned int loc = get_defcfg_location(def_conf);
@@ -464,12 +471,15 @@ EXPORT_SYMBOL_GPL(snd_hda_get_input_pin_attr);
464 471
465/** 472/**
466 * hda_get_input_pin_label - Give a label for the given input pin 473 * hda_get_input_pin_label - Give a label for the given input pin
474 * @codec: the HDA codec
475 * @item: ping config item to refer
476 * @pin: the pin NID
477 * @check_location: flag to add the jack location prefix
467 * 478 *
468 * When check_location is true, the function checks the pin location 479 * When @check_location is true, the function checks the pin location
469 * for mic and line-in pins, and set an appropriate prefix like "Front", 480 * for mic and line-in pins, and set an appropriate prefix like "Front",
470 * "Rear", "Internal". 481 * "Rear", "Internal".
471 */ 482 */
472
473static const char *hda_get_input_pin_label(struct hda_codec *codec, 483static const char *hda_get_input_pin_label(struct hda_codec *codec,
474 const struct auto_pin_cfg_item *item, 484 const struct auto_pin_cfg_item *item,
475 hda_nid_t pin, bool check_location) 485 hda_nid_t pin, bool check_location)
@@ -550,6 +560,9 @@ static int check_mic_location_need(struct hda_codec *codec,
550 560
551/** 561/**
552 * hda_get_autocfg_input_label - Get a label for the given input 562 * hda_get_autocfg_input_label - Get a label for the given input
563 * @codec: the HDA codec
564 * @cfg: the parsed pin configuration
565 * @input: the input index number
553 * 566 *
554 * Get a label for the given input pin defined by the autocfg item. 567 * Get a label for the given input pin defined by the autocfg item.
555 * Unlike hda_get_input_pin_label(), this function checks all inputs 568 * Unlike hda_get_input_pin_label(), this function checks all inputs
@@ -677,6 +690,12 @@ static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
677 690
678/** 691/**
679 * snd_hda_get_pin_label - Get a label for the given I/O pin 692 * snd_hda_get_pin_label - Get a label for the given I/O pin
693 * @codec: the HDA codec
694 * @nid: pin NID
695 * @cfg: the parsed pin configuration
696 * @label: the string buffer to store
697 * @maxlen: the max length of string buffer (including termination)
698 * @indexp: the pointer to return the index number (for multiple ctls)
680 * 699 *
681 * Get a label for the given pin. This function works for both input and 700 * Get a label for the given pin. This function works for both input and
682 * output pins. When @cfg is given as non-NULL, the function tries to get 701 * output pins. When @cfg is given as non-NULL, the function tries to get
@@ -748,6 +767,14 @@ int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
748} 767}
749EXPORT_SYMBOL_GPL(snd_hda_get_pin_label); 768EXPORT_SYMBOL_GPL(snd_hda_get_pin_label);
750 769
770/**
771 * snd_hda_add_verbs - Add verbs to the init list
772 * @codec: the HDA codec
773 * @list: zero-terminated verb list to add
774 *
775 * Append the given verb list to the execution list. The verbs will be
776 * performed at init and resume time via snd_hda_apply_verbs().
777 */
751int snd_hda_add_verbs(struct hda_codec *codec, 778int snd_hda_add_verbs(struct hda_codec *codec,
752 const struct hda_verb *list) 779 const struct hda_verb *list)
753{ 780{
@@ -760,6 +787,10 @@ int snd_hda_add_verbs(struct hda_codec *codec,
760} 787}
761EXPORT_SYMBOL_GPL(snd_hda_add_verbs); 788EXPORT_SYMBOL_GPL(snd_hda_add_verbs);
762 789
790/**
791 * snd_hda_apply_verbs - Execute the init verb lists
792 * @codec: the HDA codec
793 */
763void snd_hda_apply_verbs(struct hda_codec *codec) 794void snd_hda_apply_verbs(struct hda_codec *codec)
764{ 795{
765 int i; 796 int i;
@@ -770,6 +801,11 @@ void snd_hda_apply_verbs(struct hda_codec *codec)
770} 801}
771EXPORT_SYMBOL_GPL(snd_hda_apply_verbs); 802EXPORT_SYMBOL_GPL(snd_hda_apply_verbs);
772 803
804/**
805 * snd_hda_apply_pincfgs - Set each pin config in the given list
806 * @codec: the HDA codec
807 * @cfg: NULL-terminated pin config table
808 */
773void snd_hda_apply_pincfgs(struct hda_codec *codec, 809void snd_hda_apply_pincfgs(struct hda_codec *codec,
774 const struct hda_pintbl *cfg) 810 const struct hda_pintbl *cfg)
775{ 811{
@@ -837,6 +873,11 @@ static void apply_fixup(struct hda_codec *codec, int id, int action, int depth)
837 } 873 }
838} 874}
839 875
876/**
877 * snd_hda_apply_fixup - Apply the fixup chain with the given action
878 * @codec: the HDA codec
879 * @action: fixup action (HDA_FIXUP_ACT_XXX)
880 */
840void snd_hda_apply_fixup(struct hda_codec *codec, int action) 881void snd_hda_apply_fixup(struct hda_codec *codec, int action)
841{ 882{
842 if (codec->fixup_list) 883 if (codec->fixup_list)
@@ -855,6 +896,12 @@ static bool pin_config_match(struct hda_codec *codec,
855 return true; 896 return true;
856} 897}
857 898
899/**
900 * snd_hda_pick_pin_fixup - Pick up a fixup matching with the pin quirk list
901 * @codec: the HDA codec
902 * @pin_quirk: zero-terminated pin quirk list
903 * @fixlist: the fixup list
904 */
858void snd_hda_pick_pin_fixup(struct hda_codec *codec, 905void snd_hda_pick_pin_fixup(struct hda_codec *codec,
859 const struct snd_hda_pin_quirk *pin_quirk, 906 const struct snd_hda_pin_quirk *pin_quirk,
860 const struct hda_fixup *fixlist) 907 const struct hda_fixup *fixlist)
@@ -881,6 +928,21 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec,
881} 928}
882EXPORT_SYMBOL_GPL(snd_hda_pick_pin_fixup); 929EXPORT_SYMBOL_GPL(snd_hda_pick_pin_fixup);
883 930
931/**
932 * snd_hda_pick_fixup - Pick up a fixup matching with PCI/codec SSID or model string
933 * @codec: the HDA codec
934 * @models: NULL-terminated model string list
935 * @quirk: zero-terminated PCI/codec SSID quirk list
936 * @fixlist: the fixup list
937 *
938 * Pick up a fixup entry matching with the given model string or SSID.
939 * If a fixup was already set beforehand, the function doesn't do anything.
940 * When a special model string "nofixup" is given, also no fixup is applied.
941 *
942 * The function tries to find the matching model name at first, if given.
943 * If nothing matched, try to look up the PCI SSID.
944 * If still nothing matched, try to look up the codec SSID.
945 */
884void snd_hda_pick_fixup(struct hda_codec *codec, 946void snd_hda_pick_fixup(struct hda_codec *codec,
885 const struct hda_model_fixup *models, 947 const struct hda_model_fixup *models,
886 const struct snd_pci_quirk *quirk, 948 const struct snd_pci_quirk *quirk,
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 8c6c50afc0b7..1e7de08e77cb 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -175,6 +175,11 @@ static int snd_hda_do_attach(struct hda_beep *beep)
175 return 0; 175 return 0;
176} 176}
177 177
178/**
179 * snd_hda_enable_beep_device - Turn on/off beep sound
180 * @codec: the HDA codec
181 * @enable: flag to turn on/off
182 */
178int snd_hda_enable_beep_device(struct hda_codec *codec, int enable) 183int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
179{ 184{
180 struct hda_beep *beep = codec->beep; 185 struct hda_beep *beep = codec->beep;
@@ -191,6 +196,20 @@ int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
191} 196}
192EXPORT_SYMBOL_GPL(snd_hda_enable_beep_device); 197EXPORT_SYMBOL_GPL(snd_hda_enable_beep_device);
193 198
199/**
200 * snd_hda_attach_beep_device - Attach a beep input device
201 * @codec: the HDA codec
202 * @nid: beep NID
203 *
204 * Attach a beep object to the given widget. If beep hint is turned off
205 * explicitly or beep_mode of the codec is turned off, this doesn't nothing.
206 *
207 * The attached beep device has to be registered via
208 * snd_hda_register_beep_device() and released via snd_hda_detach_beep_device()
209 * appropriately.
210 *
211 * Currently, only one beep device is allowed to each codec.
212 */
194int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) 213int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
195{ 214{
196 struct hda_beep *beep; 215 struct hda_beep *beep;
@@ -228,6 +247,10 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
228} 247}
229EXPORT_SYMBOL_GPL(snd_hda_attach_beep_device); 248EXPORT_SYMBOL_GPL(snd_hda_attach_beep_device);
230 249
250/**
251 * snd_hda_detach_beep_device - Detach the beep device
252 * @codec: the HDA codec
253 */
231void snd_hda_detach_beep_device(struct hda_codec *codec) 254void snd_hda_detach_beep_device(struct hda_codec *codec)
232{ 255{
233 struct hda_beep *beep = codec->beep; 256 struct hda_beep *beep = codec->beep;
@@ -240,6 +263,10 @@ void snd_hda_detach_beep_device(struct hda_codec *codec)
240} 263}
241EXPORT_SYMBOL_GPL(snd_hda_detach_beep_device); 264EXPORT_SYMBOL_GPL(snd_hda_detach_beep_device);
242 265
266/**
267 * snd_hda_register_beep_device - Register the beep device
268 * @codec: the HDA codec
269 */
243int snd_hda_register_beep_device(struct hda_codec *codec) 270int snd_hda_register_beep_device(struct hda_codec *codec)
244{ 271{
245 struct hda_beep *beep = codec->beep; 272 struct hda_beep *beep = codec->beep;
@@ -269,6 +296,12 @@ static bool ctl_has_mute(struct snd_kcontrol *kcontrol)
269} 296}
270 297
271/* get/put callbacks for beep mute mixer switches */ 298/* get/put callbacks for beep mute mixer switches */
299
300/**
301 * snd_hda_mixer_amp_switch_get_beep - Get callback for beep controls
302 * @kcontrol: ctl element
303 * @ucontrol: pointer to get/store the data
304 */
272int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol, 305int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol,
273 struct snd_ctl_elem_value *ucontrol) 306 struct snd_ctl_elem_value *ucontrol)
274{ 307{
@@ -283,6 +316,11 @@ int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol,
283} 316}
284EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_get_beep); 317EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_get_beep);
285 318
319/**
320 * snd_hda_mixer_amp_switch_put_beep - Put callback for beep controls
321 * @kcontrol: ctl element
322 * @ucontrol: pointer to get/store the data
323 */
286int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol, 324int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
287 struct snd_ctl_elem_value *ucontrol) 325 struct snd_ctl_elem_value *ucontrol)
288{ 326{
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 15e0089492f7..2fe86d2e1b09 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -77,6 +77,10 @@ static struct hda_vendor_id hda_vendor_ids[] = {
77static DEFINE_MUTEX(preset_mutex); 77static DEFINE_MUTEX(preset_mutex);
78static LIST_HEAD(hda_preset_tables); 78static LIST_HEAD(hda_preset_tables);
79 79
80/**
81 * snd_hda_add_codec_preset - Add a codec preset to the chain
82 * @preset: codec preset table to add
83 */
80int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset) 84int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset)
81{ 85{
82 mutex_lock(&preset_mutex); 86 mutex_lock(&preset_mutex);
@@ -86,6 +90,10 @@ int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset)
86} 90}
87EXPORT_SYMBOL_GPL(snd_hda_add_codec_preset); 91EXPORT_SYMBOL_GPL(snd_hda_add_codec_preset);
88 92
93/**
94 * snd_hda_delete_codec_preset - Delete a codec preset from the chain
95 * @preset: codec preset table to delete
96 */
89int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset) 97int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset)
90{ 98{
91 mutex_lock(&preset_mutex); 99 mutex_lock(&preset_mutex);
@@ -338,8 +346,10 @@ int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
338 unsigned int parm; 346 unsigned int parm;
339 347
340 parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT); 348 parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT);
341 if (parm == -1) 349 if (parm == -1) {
350 *start_id = 0;
342 return 0; 351 return 0;
352 }
343 *start_id = (parm >> 16) & 0x7fff; 353 *start_id = (parm >> 16) & 0x7fff;
344 return (int)(parm & 0x7fff); 354 return (int)(parm & 0x7fff);
345} 355}
@@ -416,7 +426,6 @@ static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
416 * snd_hda_get_conn_list - get connection list 426 * snd_hda_get_conn_list - get connection list
417 * @codec: the HDA codec 427 * @codec: the HDA codec
418 * @nid: NID to parse 428 * @nid: NID to parse
419 * @len: number of connection list entries
420 * @listp: the pointer to store NID list 429 * @listp: the pointer to store NID list
421 * 430 *
422 * Parses the connection list of the given widget and stores the pointer 431 * Parses the connection list of the given widget and stores the pointer
@@ -827,8 +836,7 @@ static void snd_hda_bus_free(struct hda_bus *bus)
827 WARN_ON(!list_empty(&bus->codec_list)); 836 WARN_ON(!list_empty(&bus->codec_list));
828 if (bus->workq) 837 if (bus->workq)
829 flush_workqueue(bus->workq); 838 flush_workqueue(bus->workq);
830 if (bus->unsol) 839 kfree(bus->unsol);
831 kfree(bus->unsol);
832 if (bus->ops.private_free) 840 if (bus->ops.private_free)
833 bus->ops.private_free(bus); 841 bus->ops.private_free(bus);
834 if (bus->workq) 842 if (bus->workq)
@@ -966,14 +974,12 @@ find_codec_preset(struct hda_codec *codec)
966 mutex_unlock(&preset_mutex); 974 mutex_unlock(&preset_mutex);
967 975
968 if (mod_requested < HDA_MODREQ_MAX_COUNT) { 976 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
969 char name[32];
970 if (!mod_requested) 977 if (!mod_requested)
971 snprintf(name, sizeof(name), "snd-hda-codec-id:%08x", 978 request_module("snd-hda-codec-id:%08x",
972 codec->vendor_id); 979 codec->vendor_id);
973 else 980 else
974 snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*", 981 request_module("snd-hda-codec-id:%04x*",
975 (codec->vendor_id >> 16) & 0xffff); 982 (codec->vendor_id >> 16) & 0xffff);
976 request_module(name);
977 mod_requested++; 983 mod_requested++;
978 goto again; 984 goto again;
979 } 985 }
@@ -1190,7 +1196,16 @@ unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
1190} 1196}
1191EXPORT_SYMBOL_GPL(snd_hda_codec_get_pincfg); 1197EXPORT_SYMBOL_GPL(snd_hda_codec_get_pincfg);
1192 1198
1193/* remember the current pinctl target value */ 1199/**
1200 * snd_hda_codec_set_pin_target - remember the current pinctl target value
1201 * @codec: the HDA codec
1202 * @nid: pin NID
1203 * @val: assigned pinctl value
1204 *
1205 * This function stores the given value to a pinctl target value in the
1206 * pincfg table. This isn't always as same as the actually written value
1207 * but can be referred at any time via snd_hda_codec_get_pin_target().
1208 */
1194int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, 1209int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
1195 unsigned int val) 1210 unsigned int val)
1196{ 1211{
@@ -1204,7 +1219,11 @@ int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
1204} 1219}
1205EXPORT_SYMBOL_GPL(snd_hda_codec_set_pin_target); 1220EXPORT_SYMBOL_GPL(snd_hda_codec_set_pin_target);
1206 1221
1207/* return the current pinctl target value */ 1222/**
1223 * snd_hda_codec_get_pin_target - return the current pinctl target value
1224 * @codec: the HDA codec
1225 * @nid: pin NID
1226 */
1208int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid) 1227int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid)
1209{ 1228{
1210 struct hda_pincfg *pin; 1229 struct hda_pincfg *pin;
@@ -1576,6 +1595,13 @@ int snd_hda_codec_new(struct hda_bus *bus,
1576} 1595}
1577EXPORT_SYMBOL_GPL(snd_hda_codec_new); 1596EXPORT_SYMBOL_GPL(snd_hda_codec_new);
1578 1597
1598/**
1599 * snd_hda_codec_update_widgets - Refresh widget caps and pin defaults
1600 * @codec: the HDA codec
1601 *
1602 * Forcibly refresh the all widget caps and the init pin configurations of
1603 * the given codec.
1604 */
1579int snd_hda_codec_update_widgets(struct hda_codec *codec) 1605int snd_hda_codec_update_widgets(struct hda_codec *codec)
1580{ 1606{
1581 hda_nid_t fg; 1607 hda_nid_t fg;
@@ -2006,6 +2032,7 @@ EXPORT_SYMBOL_GPL(query_amp_caps);
2006 * @codec: the HD-audio codec 2032 * @codec: the HD-audio codec
2007 * @nid: the NID to query 2033 * @nid: the NID to query
2008 * @dir: either #HDA_INPUT or #HDA_OUTPUT 2034 * @dir: either #HDA_INPUT or #HDA_OUTPUT
2035 * @bits: bit mask to check the result
2009 * 2036 *
2010 * Check whether the widget has the given amp capability for the direction. 2037 * Check whether the widget has the given amp capability for the direction.
2011 */ 2038 */
@@ -2025,7 +2052,7 @@ EXPORT_SYMBOL_GPL(snd_hda_check_amp_caps);
2025 * snd_hda_override_amp_caps - Override the AMP capabilities 2052 * snd_hda_override_amp_caps - Override the AMP capabilities
2026 * @codec: the CODEC to clean up 2053 * @codec: the CODEC to clean up
2027 * @nid: the NID to clean up 2054 * @nid: the NID to clean up
2028 * @direction: either #HDA_INPUT or #HDA_OUTPUT 2055 * @dir: either #HDA_INPUT or #HDA_OUTPUT
2029 * @caps: the capability bits to set 2056 * @caps: the capability bits to set
2030 * 2057 *
2031 * Override the cached AMP caps bits value by the given one. 2058 * Override the cached AMP caps bits value by the given one.
@@ -2241,7 +2268,17 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
2241} 2268}
2242EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo); 2269EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo);
2243 2270
2244/* Works like snd_hda_codec_amp_update() but it writes the value only at 2271/**
2272 * snd_hda_codec_amp_init - initialize the AMP value
2273 * @codec: the HDA codec
2274 * @nid: NID to read the AMP value
2275 * @ch: channel (left=0 or right=1)
2276 * @dir: #HDA_INPUT or #HDA_OUTPUT
2277 * @idx: the index value (only for input direction)
2278 * @mask: bit mask to set
2279 * @val: the bits value to set
2280 *
2281 * Works like snd_hda_codec_amp_update() but it writes the value only at
2245 * the first access. If the amp was already initialized / updated beforehand, 2282 * the first access. If the amp was already initialized / updated beforehand,
2246 * this does nothing. 2283 * this does nothing.
2247 */ 2284 */
@@ -2252,6 +2289,17 @@ int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
2252} 2289}
2253EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); 2290EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
2254 2291
2292/**
2293 * snd_hda_codec_amp_init_stereo - initialize the stereo AMP value
2294 * @codec: the HDA codec
2295 * @nid: NID to read the AMP value
2296 * @dir: #HDA_INPUT or #HDA_OUTPUT
2297 * @idx: the index value (only for input direction)
2298 * @mask: bit mask to set
2299 * @val: the bits value to set
2300 *
2301 * Call snd_hda_codec_amp_init() for both stereo channels.
2302 */
2255int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, 2303int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
2256 int dir, int idx, int mask, int val) 2304 int dir, int idx, int mask, int val)
2257{ 2305{
@@ -2322,6 +2370,8 @@ static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir,
2322 2370
2323/** 2371/**
2324 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer 2372 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
2373 * @kcontrol: referred ctl element
2374 * @uinfo: pointer to get/store the data
2325 * 2375 *
2326 * The control element is supposed to have the private_value field 2376 * The control element is supposed to have the private_value field
2327 * set up via HDA_COMPOSE_AMP_VAL*() or related macros. 2377 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
@@ -2383,6 +2433,8 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
2383 2433
2384/** 2434/**
2385 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume 2435 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
2436 * @kcontrol: ctl element
2437 * @ucontrol: pointer to get/store the data
2386 * 2438 *
2387 * The control element is supposed to have the private_value field 2439 * The control element is supposed to have the private_value field
2388 * set up via HDA_COMPOSE_AMP_VAL*() or related macros. 2440 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
@@ -2408,6 +2460,8 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_get);
2408 2460
2409/** 2461/**
2410 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume 2462 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
2463 * @kcontrol: ctl element
2464 * @ucontrol: pointer to get/store the data
2411 * 2465 *
2412 * The control element is supposed to have the private_value field 2466 * The control element is supposed to have the private_value field
2413 * set up via HDA_COMPOSE_AMP_VAL*() or related macros. 2467 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
@@ -2438,6 +2492,10 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put);
2438 2492
2439/** 2493/**
2440 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume 2494 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume
2495 * @kcontrol: ctl element
2496 * @op_flag: operation flag
2497 * @size: byte size of input TLV
2498 * @_tlv: TLV data
2441 * 2499 *
2442 * The control element is supposed to have the private_value field 2500 * The control element is supposed to have the private_value field
2443 * set up via HDA_COMPOSE_AMP_VAL*() or related macros. 2501 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
@@ -2636,7 +2694,10 @@ void snd_hda_ctls_clear(struct hda_codec *codec)
2636 snd_array_free(&codec->nids); 2694 snd_array_free(&codec->nids);
2637} 2695}
2638 2696
2639/* pseudo device locking 2697/**
2698 * snd_hda_lock_devices - pseudo device locking
2699 * @bus: the BUS
2700 *
2640 * toggle card->shutdown to allow/disallow the device access (as a hack) 2701 * toggle card->shutdown to allow/disallow the device access (as a hack)
2641 */ 2702 */
2642int snd_hda_lock_devices(struct hda_bus *bus) 2703int snd_hda_lock_devices(struct hda_bus *bus)
@@ -2673,6 +2734,10 @@ int snd_hda_lock_devices(struct hda_bus *bus)
2673} 2734}
2674EXPORT_SYMBOL_GPL(snd_hda_lock_devices); 2735EXPORT_SYMBOL_GPL(snd_hda_lock_devices);
2675 2736
2737/**
2738 * snd_hda_unlock_devices - pseudo device unlocking
2739 * @bus: the BUS
2740 */
2676void snd_hda_unlock_devices(struct hda_bus *bus) 2741void snd_hda_unlock_devices(struct hda_bus *bus)
2677{ 2742{
2678 struct snd_card *card = bus->card; 2743 struct snd_card *card = bus->card;
@@ -2859,7 +2924,7 @@ static int add_slave(struct hda_codec *codec,
2859} 2924}
2860 2925
2861/** 2926/**
2862 * snd_hda_add_vmaster - create a virtual master control and add slaves 2927 * __snd_hda_add_vmaster - create a virtual master control and add slaves
2863 * @codec: HD-audio codec 2928 * @codec: HD-audio codec
2864 * @name: vmaster control name 2929 * @name: vmaster control name
2865 * @tlv: TLV data (optional) 2930 * @tlv: TLV data (optional)
@@ -2927,16 +2992,8 @@ static int vmaster_mute_mode_info(struct snd_kcontrol *kcontrol,
2927 static const char * const texts[] = { 2992 static const char * const texts[] = {
2928 "On", "Off", "Follow Master" 2993 "On", "Off", "Follow Master"
2929 }; 2994 };
2930 unsigned int index;
2931 2995
2932 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2996 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2933 uinfo->count = 1;
2934 uinfo->value.enumerated.items = 3;
2935 index = uinfo->value.enumerated.item;
2936 if (index >= 3)
2937 index = 2;
2938 strcpy(uinfo->value.enumerated.name, texts[index]);
2939 return 0;
2940} 2997}
2941 2998
2942static int vmaster_mute_mode_get(struct snd_kcontrol *kcontrol, 2999static int vmaster_mute_mode_get(struct snd_kcontrol *kcontrol,
@@ -2970,10 +3027,15 @@ static struct snd_kcontrol_new vmaster_mute_mode = {
2970 .put = vmaster_mute_mode_put, 3027 .put = vmaster_mute_mode_put,
2971}; 3028};
2972 3029
2973/* 3030/**
2974 * Add a mute-LED hook with the given vmaster switch kctl 3031 * snd_hda_add_vmaster_hook - Add a vmaster hook for mute-LED
2975 * "Mute-LED Mode" control is automatically created and associated with 3032 * @codec: the HDA codec
2976 * the given hook. 3033 * @hook: the vmaster hook object
3034 * @expose_enum_ctl: flag to create an enum ctl
3035 *
3036 * Add a mute-LED hook with the given vmaster switch kctl.
3037 * When @expose_enum_ctl is set, "Mute-LED Mode" control is automatically
3038 * created and associated with the given hook.
2977 */ 3039 */
2978int snd_hda_add_vmaster_hook(struct hda_codec *codec, 3040int snd_hda_add_vmaster_hook(struct hda_codec *codec,
2979 struct hda_vmaster_mute_hook *hook, 3041 struct hda_vmaster_mute_hook *hook,
@@ -2995,9 +3057,12 @@ int snd_hda_add_vmaster_hook(struct hda_codec *codec,
2995} 3057}
2996EXPORT_SYMBOL_GPL(snd_hda_add_vmaster_hook); 3058EXPORT_SYMBOL_GPL(snd_hda_add_vmaster_hook);
2997 3059
2998/* 3060/**
2999 * Call the hook with the current value for synchronization 3061 * snd_hda_sync_vmaster_hook - Sync vmaster hook
3000 * Should be called in init callback 3062 * @hook: the vmaster hook
3063 *
3064 * Call the hook with the current value for synchronization.
3065 * Should be called in init callback.
3001 */ 3066 */
3002void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook) 3067void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook)
3003{ 3068{
@@ -3022,6 +3087,8 @@ EXPORT_SYMBOL_GPL(snd_hda_sync_vmaster_hook);
3022 3087
3023/** 3088/**
3024 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch 3089 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
3090 * @kcontrol: referred ctl element
3091 * @uinfo: pointer to get/store the data
3025 * 3092 *
3026 * The control element is supposed to have the private_value field 3093 * The control element is supposed to have the private_value field
3027 * set up via HDA_COMPOSE_AMP_VAL*() or related macros. 3094 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
@@ -3041,6 +3108,8 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_info);
3041 3108
3042/** 3109/**
3043 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch 3110 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
3111 * @kcontrol: ctl element
3112 * @ucontrol: pointer to get/store the data
3044 * 3113 *
3045 * The control element is supposed to have the private_value field 3114 * The control element is supposed to have the private_value field
3046 * set up via HDA_COMPOSE_AMP_VAL*() or related macros. 3115 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
@@ -3067,6 +3136,8 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_get);
3067 3136
3068/** 3137/**
3069 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch 3138 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
3139 * @kcontrol: ctl element
3140 * @ucontrol: pointer to get/store the data
3070 * 3141 *
3071 * The control element is supposed to have the private_value field 3142 * The control element is supposed to have the private_value field
3072 * set up via HDA_COMPOSE_AMP_VAL*() or related macros. 3143 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
@@ -3110,6 +3181,8 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put);
3110 3181
3111/** 3182/**
3112 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control 3183 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control
3184 * @kcontrol: ctl element
3185 * @ucontrol: pointer to get/store the data
3113 * 3186 *
3114 * The control element is supposed to have the private_value field 3187 * The control element is supposed to have the private_value field
3115 * set up via HDA_BIND_MUTE*() macros. 3188 * set up via HDA_BIND_MUTE*() macros.
@@ -3133,6 +3206,8 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_switch_get);
3133 3206
3134/** 3207/**
3135 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control 3208 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control
3209 * @kcontrol: ctl element
3210 * @ucontrol: pointer to get/store the data
3136 * 3211 *
3137 * The control element is supposed to have the private_value field 3212 * The control element is supposed to have the private_value field
3138 * set up via HDA_BIND_MUTE*() macros. 3213 * set up via HDA_BIND_MUTE*() macros.
@@ -3163,6 +3238,8 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_switch_put);
3163 3238
3164/** 3239/**
3165 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control 3240 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control
3241 * @kcontrol: referred ctl element
3242 * @uinfo: pointer to get/store the data
3166 * 3243 *
3167 * The control element is supposed to have the private_value field 3244 * The control element is supposed to have the private_value field
3168 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. 3245 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
@@ -3186,6 +3263,8 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_ctls_info);
3186 3263
3187/** 3264/**
3188 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control 3265 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control
3266 * @kcontrol: ctl element
3267 * @ucontrol: pointer to get/store the data
3189 * 3268 *
3190 * The control element is supposed to have the private_value field 3269 * The control element is supposed to have the private_value field
3191 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. 3270 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
@@ -3209,6 +3288,8 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_ctls_get);
3209 3288
3210/** 3289/**
3211 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control 3290 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control
3291 * @kcontrol: ctl element
3292 * @ucontrol: pointer to get/store the data
3212 * 3293 *
3213 * The control element is supposed to have the private_value field 3294 * The control element is supposed to have the private_value field
3214 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. 3295 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
@@ -3238,6 +3319,10 @@ EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_ctls_put);
3238 3319
3239/** 3320/**
3240 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control 3321 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control
3322 * @kcontrol: ctl element
3323 * @op_flag: operation flag
3324 * @size: byte size of input TLV
3325 * @tlv: TLV data
3241 * 3326 *
3242 * The control element is supposed to have the private_value field 3327 * The control element is supposed to have the private_value field
3243 * set up via HDA_BIND_VOL() macro. 3328 * set up via HDA_BIND_VOL() macro.
@@ -3579,7 +3664,11 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
3579} 3664}
3580EXPORT_SYMBOL_GPL(snd_hda_create_dig_out_ctls); 3665EXPORT_SYMBOL_GPL(snd_hda_create_dig_out_ctls);
3581 3666
3582/* get the hda_spdif_out entry from the given NID 3667/**
3668 * snd_hda_spdif_out_of_nid - get the hda_spdif_out entry from the given NID
3669 * @codec: the HDA codec
3670 * @nid: widget NID
3671 *
3583 * call within spdif_mutex lock 3672 * call within spdif_mutex lock
3584 */ 3673 */
3585struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, 3674struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
@@ -3596,6 +3685,13 @@ struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
3596} 3685}
3597EXPORT_SYMBOL_GPL(snd_hda_spdif_out_of_nid); 3686EXPORT_SYMBOL_GPL(snd_hda_spdif_out_of_nid);
3598 3687
3688/**
3689 * snd_hda_spdif_ctls_unassign - Unassign the given SPDIF ctl
3690 * @codec: the HDA codec
3691 * @idx: the SPDIF ctl index
3692 *
3693 * Unassign the widget from the given SPDIF control.
3694 */
3599void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) 3695void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)
3600{ 3696{
3601 struct hda_spdif_out *spdif; 3697 struct hda_spdif_out *spdif;
@@ -3607,6 +3703,14 @@ void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)
3607} 3703}
3608EXPORT_SYMBOL_GPL(snd_hda_spdif_ctls_unassign); 3704EXPORT_SYMBOL_GPL(snd_hda_spdif_ctls_unassign);
3609 3705
3706/**
3707 * snd_hda_spdif_ctls_assign - Assign the SPDIF controls to the given NID
3708 * @codec: the HDA codec
3709 * @idx: the SPDIF ctl idx
3710 * @nid: widget NID
3711 *
3712 * Assign the widget to the SPDIF control with the given index.
3713 */
3610void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) 3714void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid)
3611{ 3715{
3612 struct hda_spdif_out *spdif; 3716 struct hda_spdif_out *spdif;
@@ -3926,6 +4030,16 @@ void snd_hda_codec_flush_cache(struct hda_codec *codec)
3926} 4030}
3927EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache); 4031EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache);
3928 4032
4033/**
4034 * snd_hda_codec_set_power_to_all - Set the power state to all widgets
4035 * @codec: the HDA codec
4036 * @fg: function group (not used now)
4037 * @power_state: the power state to set (AC_PWRST_*)
4038 *
4039 * Set the given power state to all widgets that have the power control.
4040 * If the codec has power_filter set, it evaluates the power state and
4041 * filter out if it's unchanged as D3.
4042 */
3929void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, 4043void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
3930 unsigned int power_state) 4044 unsigned int power_state)
3931{ 4045{
@@ -3990,7 +4104,15 @@ static unsigned int hda_sync_power_state(struct hda_codec *codec,
3990 return state; 4104 return state;
3991} 4105}
3992 4106
3993/* don't power down the widget if it controls eapd and EAPD_BTLENABLE is set */ 4107/**
4108 * snd_hda_codec_eapd_power_filter - A power filter callback for EAPD
4109 * @codec: the HDA codec
4110 * @nid: widget NID
4111 * @power_state: power state to evalue
4112 *
4113 * Don't power down the widget if it controls eapd and EAPD_BTLENABLE is set.
4114 * This can be used a codec power_filter callback.
4115 */
3994unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, 4116unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
3995 hda_nid_t nid, 4117 hda_nid_t nid,
3996 unsigned int power_state) 4118 unsigned int power_state)
@@ -4315,6 +4437,7 @@ static struct hda_rate_tbl rate_bits[] = {
4315 * @channels: the number of channels 4437 * @channels: the number of channels
4316 * @format: the PCM format (SNDRV_PCM_FORMAT_XXX) 4438 * @format: the PCM format (SNDRV_PCM_FORMAT_XXX)
4317 * @maxbps: the max. bps 4439 * @maxbps: the max. bps
4440 * @spdif_ctls: HD-audio SPDIF status bits (0 if irrelevant)
4318 * 4441 *
4319 * Calculate the format bitset from the given rate, channels and th PCM format. 4442 * Calculate the format bitset from the given rate, channels and th PCM format.
4320 * 4443 *
@@ -4650,6 +4773,17 @@ static int set_pcm_default_values(struct hda_codec *codec,
4650/* 4773/*
4651 * codec prepare/cleanup entries 4774 * codec prepare/cleanup entries
4652 */ 4775 */
4776/**
4777 * snd_hda_codec_prepare - Prepare a stream
4778 * @codec: the HDA codec
4779 * @hinfo: PCM information
4780 * @stream: stream tag to assign
4781 * @format: format id to assign
4782 * @substream: PCM substream to assign
4783 *
4784 * Calls the prepare callback set by the codec with the given arguments.
4785 * Clean up the inactive streams when successful.
4786 */
4653int snd_hda_codec_prepare(struct hda_codec *codec, 4787int snd_hda_codec_prepare(struct hda_codec *codec,
4654 struct hda_pcm_stream *hinfo, 4788 struct hda_pcm_stream *hinfo,
4655 unsigned int stream, 4789 unsigned int stream,
@@ -4666,6 +4800,14 @@ int snd_hda_codec_prepare(struct hda_codec *codec,
4666} 4800}
4667EXPORT_SYMBOL_GPL(snd_hda_codec_prepare); 4801EXPORT_SYMBOL_GPL(snd_hda_codec_prepare);
4668 4802
4803/**
4804 * snd_hda_codec_cleanup - Prepare a stream
4805 * @codec: the HDA codec
4806 * @hinfo: PCM information
4807 * @substream: PCM substream
4808 *
4809 * Calls the cleanup callback set by the codec with the given arguments.
4810 */
4669void snd_hda_codec_cleanup(struct hda_codec *codec, 4811void snd_hda_codec_cleanup(struct hda_codec *codec,
4670 struct hda_pcm_stream *hinfo, 4812 struct hda_pcm_stream *hinfo,
4671 struct snd_pcm_substream *substream) 4813 struct snd_pcm_substream *substream)
@@ -4990,6 +5132,7 @@ static void __snd_hda_power_down(struct hda_codec *codec)
4990 * snd_hda_power_save - Power-up/down/sync the codec 5132 * snd_hda_power_save - Power-up/down/sync the codec
4991 * @codec: HD-audio codec 5133 * @codec: HD-audio codec
4992 * @delta: the counter delta to change 5134 * @delta: the counter delta to change
5135 * @d3wait: sync for D3 transition complete
4993 * 5136 *
4994 * Change the power-up counter via @delta, and power up or down the hardware 5137 * Change the power-up counter via @delta, and power up or down the hardware
4995 * appropriately. For the power-down, queue to the delayed action. 5138 * appropriately. For the power-down, queue to the delayed action.
@@ -5065,6 +5208,10 @@ EXPORT_SYMBOL_GPL(snd_hda_check_amp_list_power);
5065 5208
5066/** 5209/**
5067 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum 5210 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
5211 * @codec: the HDA codec
5212 * @uinfo: pointer to get/store the data
5213 * @chmode: channel mode array
5214 * @num_chmodes: channel mode array size
5068 */ 5215 */
5069int snd_hda_ch_mode_info(struct hda_codec *codec, 5216int snd_hda_ch_mode_info(struct hda_codec *codec,
5070 struct snd_ctl_elem_info *uinfo, 5217 struct snd_ctl_elem_info *uinfo,
@@ -5084,6 +5231,11 @@ EXPORT_SYMBOL_GPL(snd_hda_ch_mode_info);
5084 5231
5085/** 5232/**
5086 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum 5233 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
5234 * @codec: the HDA codec
5235 * @ucontrol: pointer to get/store the data
5236 * @chmode: channel mode array
5237 * @num_chmodes: channel mode array size
5238 * @max_channels: max number of channels
5087 */ 5239 */
5088int snd_hda_ch_mode_get(struct hda_codec *codec, 5240int snd_hda_ch_mode_get(struct hda_codec *codec,
5089 struct snd_ctl_elem_value *ucontrol, 5241 struct snd_ctl_elem_value *ucontrol,
@@ -5105,6 +5257,11 @@ EXPORT_SYMBOL_GPL(snd_hda_ch_mode_get);
5105 5257
5106/** 5258/**
5107 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum 5259 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
5260 * @codec: the HDA codec
5261 * @ucontrol: pointer to get/store the data
5262 * @chmode: channel mode array
5263 * @num_chmodes: channel mode array size
5264 * @max_channelsp: pointer to store the max channels
5108 */ 5265 */
5109int snd_hda_ch_mode_put(struct hda_codec *codec, 5266int snd_hda_ch_mode_put(struct hda_codec *codec,
5110 struct snd_ctl_elem_value *ucontrol, 5267 struct snd_ctl_elem_value *ucontrol,
@@ -5133,6 +5290,8 @@ EXPORT_SYMBOL_GPL(snd_hda_ch_mode_put);
5133 5290
5134/** 5291/**
5135 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum 5292 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
5293 * @imux: imux helper object
5294 * @uinfo: pointer to get/store the data
5136 */ 5295 */
5137int snd_hda_input_mux_info(const struct hda_input_mux *imux, 5296int snd_hda_input_mux_info(const struct hda_input_mux *imux,
5138 struct snd_ctl_elem_info *uinfo) 5297 struct snd_ctl_elem_info *uinfo)
@@ -5154,6 +5313,11 @@ EXPORT_SYMBOL_GPL(snd_hda_input_mux_info);
5154 5313
5155/** 5314/**
5156 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum 5315 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
5316 * @codec: the HDA codec
5317 * @imux: imux helper object
5318 * @ucontrol: pointer to get/store the data
5319 * @nid: input mux NID
5320 * @cur_val: pointer to get/store the current imux value
5157 */ 5321 */
5158int snd_hda_input_mux_put(struct hda_codec *codec, 5322int snd_hda_input_mux_put(struct hda_codec *codec,
5159 const struct hda_input_mux *imux, 5323 const struct hda_input_mux *imux,
@@ -5178,7 +5342,13 @@ int snd_hda_input_mux_put(struct hda_codec *codec,
5178EXPORT_SYMBOL_GPL(snd_hda_input_mux_put); 5342EXPORT_SYMBOL_GPL(snd_hda_input_mux_put);
5179 5343
5180 5344
5181/* 5345/**
5346 * snd_hda_enum_helper_info - Helper for simple enum ctls
5347 * @kcontrol: ctl element
5348 * @uinfo: pointer to get/store the data
5349 * @num_items: number of enum items
5350 * @texts: enum item string array
5351 *
5182 * process kcontrol info callback of a simple string enum array 5352 * process kcontrol info callback of a simple string enum array
5183 * when @num_items is 0 or @texts is NULL, assume a boolean enum array 5353 * when @num_items is 0 or @texts is NULL, assume a boolean enum array
5184 */ 5354 */
@@ -5195,14 +5365,7 @@ int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
5195 texts = texts_default; 5365 texts = texts_default;
5196 } 5366 }
5197 5367
5198 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 5368 return snd_ctl_enum_info(uinfo, 1, num_items, texts);
5199 uinfo->count = 1;
5200 uinfo->value.enumerated.items = num_items;
5201 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
5202 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
5203 strcpy(uinfo->value.enumerated.name,
5204 texts[uinfo->value.enumerated.item]);
5205 return 0;
5206} 5369}
5207EXPORT_SYMBOL_GPL(snd_hda_enum_helper_info); 5370EXPORT_SYMBOL_GPL(snd_hda_enum_helper_info);
5208 5371
@@ -5274,6 +5437,8 @@ EXPORT_SYMBOL_GPL(snd_hda_bus_reboot_notify);
5274 5437
5275/** 5438/**
5276 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode 5439 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
5440 * @codec: the HDA codec
5441 * @mout: hda_multi_out object
5277 */ 5442 */
5278int snd_hda_multi_out_dig_open(struct hda_codec *codec, 5443int snd_hda_multi_out_dig_open(struct hda_codec *codec,
5279 struct hda_multi_out *mout) 5444 struct hda_multi_out *mout)
@@ -5290,6 +5455,11 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_open);
5290 5455
5291/** 5456/**
5292 * snd_hda_multi_out_dig_prepare - prepare the digital out stream 5457 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
5458 * @codec: the HDA codec
5459 * @mout: hda_multi_out object
5460 * @stream_tag: stream tag to assign
5461 * @format: format id to assign
5462 * @substream: PCM substream to assign
5293 */ 5463 */
5294int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, 5464int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
5295 struct hda_multi_out *mout, 5465 struct hda_multi_out *mout,
@@ -5306,6 +5476,8 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_prepare);
5306 5476
5307/** 5477/**
5308 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream 5478 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
5479 * @codec: the HDA codec
5480 * @mout: hda_multi_out object
5309 */ 5481 */
5310int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, 5482int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
5311 struct hda_multi_out *mout) 5483 struct hda_multi_out *mout)
@@ -5319,6 +5491,8 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_cleanup);
5319 5491
5320/** 5492/**
5321 * snd_hda_multi_out_dig_close - release the digital out stream 5493 * snd_hda_multi_out_dig_close - release the digital out stream
5494 * @codec: the HDA codec
5495 * @mout: hda_multi_out object
5322 */ 5496 */
5323int snd_hda_multi_out_dig_close(struct hda_codec *codec, 5497int snd_hda_multi_out_dig_close(struct hda_codec *codec,
5324 struct hda_multi_out *mout) 5498 struct hda_multi_out *mout)
@@ -5332,6 +5506,10 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_close);
5332 5506
5333/** 5507/**
5334 * snd_hda_multi_out_analog_open - open analog outputs 5508 * snd_hda_multi_out_analog_open - open analog outputs
5509 * @codec: the HDA codec
5510 * @mout: hda_multi_out object
5511 * @substream: PCM substream to assign
5512 * @hinfo: PCM information to assign
5335 * 5513 *
5336 * Open analog outputs and set up the hw-constraints. 5514 * Open analog outputs and set up the hw-constraints.
5337 * If the digital outputs can be opened as slave, open the digital 5515 * If the digital outputs can be opened as slave, open the digital
@@ -5382,6 +5560,11 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_open);
5382 5560
5383/** 5561/**
5384 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs. 5562 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs.
5563 * @codec: the HDA codec
5564 * @mout: hda_multi_out object
5565 * @stream_tag: stream tag to assign
5566 * @format: format id to assign
5567 * @substream: PCM substream to assign
5385 * 5568 *
5386 * Set up the i/o for analog out. 5569 * Set up the i/o for analog out.
5387 * When the digital out is available, copy the front out to digital out, too. 5570 * When the digital out is available, copy the front out to digital out, too.
@@ -5459,6 +5642,8 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_prepare);
5459 5642
5460/** 5643/**
5461 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out 5644 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
5645 * @codec: the HDA codec
5646 * @mout: hda_multi_out object
5462 */ 5647 */
5463int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, 5648int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
5464 struct hda_multi_out *mout) 5649 struct hda_multi_out *mout)
@@ -5490,6 +5675,8 @@ EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_cleanup);
5490 5675
5491/** 5676/**
5492 * snd_hda_get_default_vref - Get the default (mic) VREF pin bits 5677 * snd_hda_get_default_vref - Get the default (mic) VREF pin bits
5678 * @codec: the HDA codec
5679 * @pin: referred pin NID
5493 * 5680 *
5494 * Guess the suitable VREF pin bits to be set as the pin-control value. 5681 * Guess the suitable VREF pin bits to be set as the pin-control value.
5495 * Note: the function doesn't set the AC_PINCTL_IN_EN bit. 5682 * Note: the function doesn't set the AC_PINCTL_IN_EN bit.
@@ -5515,7 +5702,12 @@ unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin)
5515} 5702}
5516EXPORT_SYMBOL_GPL(snd_hda_get_default_vref); 5703EXPORT_SYMBOL_GPL(snd_hda_get_default_vref);
5517 5704
5518/* correct the pin ctl value for matching with the pin cap */ 5705/**
5706 * snd_hda_correct_pin_ctl - correct the pin ctl value for matching with the pin cap
5707 * @codec: the HDA codec
5708 * @pin: referred pin NID
5709 * @val: pin ctl value to audit
5710 */
5519unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, 5711unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
5520 hda_nid_t pin, unsigned int val) 5712 hda_nid_t pin, unsigned int val)
5521{ 5713{
@@ -5566,6 +5758,19 @@ unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
5566} 5758}
5567EXPORT_SYMBOL_GPL(snd_hda_correct_pin_ctl); 5759EXPORT_SYMBOL_GPL(snd_hda_correct_pin_ctl);
5568 5760
5761/**
5762 * _snd_hda_pin_ctl - Helper to set pin ctl value
5763 * @codec: the HDA codec
5764 * @pin: referred pin NID
5765 * @val: pin control value to set
5766 * @cached: access over codec pinctl cache or direct write
5767 *
5768 * This function is a helper to set a pin ctl value more safely.
5769 * It corrects the pin ctl value via snd_hda_correct_pin_ctl(), stores the
5770 * value in pin target array via snd_hda_codec_set_pin_target(), then
5771 * actually writes the value via either snd_hda_codec_update_cache() or
5772 * snd_hda_codec_write() depending on @cached flag.
5773 */
5569int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, 5774int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
5570 unsigned int val, bool cached) 5775 unsigned int val, bool cached)
5571{ 5776{
@@ -5582,6 +5787,11 @@ EXPORT_SYMBOL_GPL(_snd_hda_set_pin_ctl);
5582 5787
5583/** 5788/**
5584 * snd_hda_add_imux_item - Add an item to input_mux 5789 * snd_hda_add_imux_item - Add an item to input_mux
5790 * @codec: the HDA codec
5791 * @imux: imux helper object
5792 * @label: the name of imux item to assign
5793 * @index: index number of imux item to assign
5794 * @type_idx: pointer to store the resultant label index
5585 * 5795 *
5586 * When the same label is used already in the existing items, the number 5796 * When the same label is used already in the existing items, the number
5587 * suffix is appended to the label. This label index number is stored 5797 * suffix is appended to the label. This label index number is stored
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index e1cd34d9011d..0e6d7534f491 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -371,7 +371,7 @@ error:
371 return ret; 371 return ret;
372} 372}
373 373
374/** 374/*
375 * SNDRV_PCM_RATE_* and AC_PAR_PCM values don't match, print correct rates with 375 * SNDRV_PCM_RATE_* and AC_PAR_PCM values don't match, print correct rates with
376 * hdmi-specific routine. 376 * hdmi-specific routine.
377 */ 377 */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 64220c08bd98..63b69f750d8e 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -40,7 +40,12 @@
40#include "hda_generic.h" 40#include "hda_generic.h"
41 41
42 42
43/* initialize hda_gen_spec struct */ 43/**
44 * snd_hda_gen_spec_init - initialize hda_gen_spec struct
45 * @spec: hda_gen_spec object to initialize
46 *
47 * Initialize the given hda_gen_spec object.
48 */
44int snd_hda_gen_spec_init(struct hda_gen_spec *spec) 49int snd_hda_gen_spec_init(struct hda_gen_spec *spec)
45{ 50{
46 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); 51 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
@@ -51,6 +56,17 @@ int snd_hda_gen_spec_init(struct hda_gen_spec *spec)
51} 56}
52EXPORT_SYMBOL_GPL(snd_hda_gen_spec_init); 57EXPORT_SYMBOL_GPL(snd_hda_gen_spec_init);
53 58
59/**
60 * snd_hda_gen_add_kctl - Add a new kctl_new struct from the template
61 * @spec: hda_gen_spec object
62 * @name: name string to override the template, NULL if unchanged
63 * @temp: template for the new kctl
64 *
65 * Add a new kctl (actually snd_kcontrol_new to be instantiated later)
66 * element based on the given snd_kcontrol_new template @temp and the
67 * name string @name to the list in @spec.
68 * Returns the newly created object or NULL as error.
69 */
54struct snd_kcontrol_new * 70struct snd_kcontrol_new *
55snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name, 71snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name,
56 const struct snd_kcontrol_new *temp) 72 const struct snd_kcontrol_new *temp)
@@ -259,8 +275,14 @@ static struct nid_path *get_nid_path(struct hda_codec *codec,
259 return NULL; 275 return NULL;
260} 276}
261 277
262/* get the path between the given NIDs; 278/**
263 * passing 0 to either @pin or @dac behaves as a wildcard 279 * snd_hda_get_nid_path - get the path between the given NIDs
280 * @codec: the HDA codec
281 * @from_nid: the NID where the path start from
282 * @to_nid: the NID where the path ends at
283 *
284 * Return the found nid_path object or NULL for error.
285 * Passing 0 to either @from_nid or @to_nid behaves as a wildcard.
264 */ 286 */
265struct nid_path *snd_hda_get_nid_path(struct hda_codec *codec, 287struct nid_path *snd_hda_get_nid_path(struct hda_codec *codec,
266 hda_nid_t from_nid, hda_nid_t to_nid) 288 hda_nid_t from_nid, hda_nid_t to_nid)
@@ -269,8 +291,14 @@ struct nid_path *snd_hda_get_nid_path(struct hda_codec *codec,
269} 291}
270EXPORT_SYMBOL_GPL(snd_hda_get_nid_path); 292EXPORT_SYMBOL_GPL(snd_hda_get_nid_path);
271 293
272/* get the index number corresponding to the path instance; 294/**
273 * the index starts from 1, for easier checking the invalid value 295 * snd_hda_get_path_idx - get the index number corresponding to the path
296 * instance
297 * @codec: the HDA codec
298 * @path: nid_path object
299 *
300 * The returned index starts from 1, i.e. the actual array index with offset 1,
301 * and zero is handled as an invalid path
274 */ 302 */
275int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path) 303int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
276{ 304{
@@ -287,7 +315,12 @@ int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
287} 315}
288EXPORT_SYMBOL_GPL(snd_hda_get_path_idx); 316EXPORT_SYMBOL_GPL(snd_hda_get_path_idx);
289 317
290/* get the path instance corresponding to the given index number */ 318/**
319 * snd_hda_get_path_from_idx - get the path instance corresponding to the
320 * given index number
321 * @codec: the HDA codec
322 * @idx: the path index
323 */
291struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx) 324struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx)
292{ 325{
293 struct hda_gen_spec *spec = codec->spec; 326 struct hda_gen_spec *spec = codec->spec;
@@ -415,7 +448,18 @@ static bool __parse_nid_path(struct hda_codec *codec,
415 return true; 448 return true;
416} 449}
417 450
418/* parse the widget path from the given nid to the target nid; 451/**
452 * snd_hda_parse_nid_path - parse the widget path from the given nid to
453 * the target nid
454 * @codec: the HDA codec
455 * @from_nid: the NID where the path start from
456 * @to_nid: the NID where the path ends at
457 * @anchor_nid: the anchor indication
458 * @path: the path object to store the result
459 *
460 * Returns true if a matching path is found.
461 *
462 * The parsing behavior depends on parameters:
419 * when @from_nid is 0, try to find an empty DAC; 463 * when @from_nid is 0, try to find an empty DAC;
420 * when @anchor_nid is set to a positive value, only paths through the widget 464 * when @anchor_nid is set to a positive value, only paths through the widget
421 * with the given value are evaluated. 465 * with the given value are evaluated.
@@ -436,9 +480,15 @@ bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
436} 480}
437EXPORT_SYMBOL_GPL(snd_hda_parse_nid_path); 481EXPORT_SYMBOL_GPL(snd_hda_parse_nid_path);
438 482
439/* 483/**
440 * parse the path between the given NIDs and add to the path list. 484 * snd_hda_add_new_path - parse the path between the given NIDs and
441 * if no valid path is found, return NULL 485 * add to the path list
486 * @codec: the HDA codec
487 * @from_nid: the NID where the path start from
488 * @to_nid: the NID where the path ends at
489 * @anchor_nid: the anchor indication, see snd_hda_parse_nid_path()
490 *
491 * If no valid path is found, returns NULL.
442 */ 492 */
443struct nid_path * 493struct nid_path *
444snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid, 494snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
@@ -724,8 +774,14 @@ static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
724 } 774 }
725} 775}
726 776
727/* activate or deactivate the given path 777/**
728 * if @add_aamix is set, enable the input from aa-mix NID as well (if any) 778 * snd_hda_activate_path - activate or deactivate the given path
779 * @codec: the HDA codec
780 * @path: the path to activate/deactivate
781 * @enable: flag to activate or not
782 * @add_aamix: enable the input from aamix NID
783 *
784 * If @add_aamix is set, enable the input from aa-mix NID as well (if any).
729 */ 785 */
730void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path, 786void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
731 bool enable, bool add_aamix) 787 bool enable, bool add_aamix)
@@ -1038,11 +1094,24 @@ static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
1038 break; 1094 break;
1039 *index = ch; 1095 *index = ch;
1040 return "Headphone"; 1096 return "Headphone";
1097 case AUTO_PIN_LINE_OUT:
1098 /* This deals with the case where we have two DACs and
1099 * one LO, one HP and one Speaker */
1100 if (!ch && cfg->speaker_outs && cfg->hp_outs) {
1101 bool hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
1102 bool spk_lo_shared = !path_has_mixer(codec, spec->speaker_paths[0], ctl_type);
1103 if (hp_lo_shared && spk_lo_shared)
1104 return spec->vmaster_mute.hook ? "PCM" : "Master";
1105 if (hp_lo_shared)
1106 return "Headphone+LO";
1107 if (spk_lo_shared)
1108 return "Speaker+LO";
1109 }
1041 } 1110 }
1042 1111
1043 /* for a single channel output, we don't have to name the channel */ 1112 /* for a single channel output, we don't have to name the channel */
1044 if (cfg->line_outs == 1 && !spec->multi_ios) 1113 if (cfg->line_outs == 1 && !spec->multi_ios)
1045 return "PCM"; 1114 return "Line Out";
1046 1115
1047 if (ch >= ARRAY_SIZE(channel_name)) { 1116 if (ch >= ARRAY_SIZE(channel_name)) {
1048 snd_BUG(); 1117 snd_BUG();
@@ -3870,7 +3939,12 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3870 } 3939 }
3871} 3940}
3872 3941
3873/* Toggle outputs muting */ 3942/**
3943 * snd_hda_gen_update_outputs - Toggle outputs muting
3944 * @codec: the HDA codec
3945 *
3946 * Update the mute status of all outputs based on the current jack states.
3947 */
3874void snd_hda_gen_update_outputs(struct hda_codec *codec) 3948void snd_hda_gen_update_outputs(struct hda_codec *codec)
3875{ 3949{
3876 struct hda_gen_spec *spec = codec->spec; 3950 struct hda_gen_spec *spec = codec->spec;
@@ -3931,7 +4005,11 @@ static void call_update_outputs(struct hda_codec *codec)
3931 snd_ctl_sync_vmaster(spec->vmaster_mute.sw_kctl, false); 4005 snd_ctl_sync_vmaster(spec->vmaster_mute.sw_kctl, false);
3932} 4006}
3933 4007
3934/* standard HP-automute helper */ 4008/**
4009 * snd_hda_gen_hp_automute - standard HP-automute helper
4010 * @codec: the HDA codec
4011 * @jack: jack object, NULL for the whole
4012 */
3935void snd_hda_gen_hp_automute(struct hda_codec *codec, 4013void snd_hda_gen_hp_automute(struct hda_codec *codec,
3936 struct hda_jack_callback *jack) 4014 struct hda_jack_callback *jack)
3937{ 4015{
@@ -3952,7 +4030,11 @@ void snd_hda_gen_hp_automute(struct hda_codec *codec,
3952} 4030}
3953EXPORT_SYMBOL_GPL(snd_hda_gen_hp_automute); 4031EXPORT_SYMBOL_GPL(snd_hda_gen_hp_automute);
3954 4032
3955/* standard line-out-automute helper */ 4033/**
4034 * snd_hda_gen_line_automute - standard line-out-automute helper
4035 * @codec: the HDA codec
4036 * @jack: jack object, NULL for the whole
4037 */
3956void snd_hda_gen_line_automute(struct hda_codec *codec, 4038void snd_hda_gen_line_automute(struct hda_codec *codec,
3957 struct hda_jack_callback *jack) 4039 struct hda_jack_callback *jack)
3958{ 4040{
@@ -3973,7 +4055,11 @@ void snd_hda_gen_line_automute(struct hda_codec *codec,
3973} 4055}
3974EXPORT_SYMBOL_GPL(snd_hda_gen_line_automute); 4056EXPORT_SYMBOL_GPL(snd_hda_gen_line_automute);
3975 4057
3976/* standard mic auto-switch helper */ 4058/**
4059 * snd_hda_gen_mic_autoswitch - standard mic auto-switch helper
4060 * @codec: the HDA codec
4061 * @jack: jack object, NULL for the whole
4062 */
3977void snd_hda_gen_mic_autoswitch(struct hda_codec *codec, 4063void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
3978 struct hda_jack_callback *jack) 4064 struct hda_jack_callback *jack)
3979{ 4065{
@@ -4305,7 +4391,13 @@ static int check_auto_mic_availability(struct hda_codec *codec)
4305 return 0; 4391 return 0;
4306} 4392}
4307 4393
4308/* power_filter hook; make inactive widgets into power down */ 4394/**
4395 * snd_hda_gen_path_power_filter - power_filter hook to make inactive widgets
4396 * into power down
4397 * @codec: the HDA codec
4398 * @nid: NID to evalute
4399 * @power_state: target power state
4400 */
4309unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, 4401unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
4310 hda_nid_t nid, 4402 hda_nid_t nid,
4311 unsigned int power_state) 4403 unsigned int power_state)
@@ -4341,8 +4433,11 @@ static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4341 } 4433 }
4342} 4434}
4343 4435
4344/* 4436/**
4345 * Parse the given BIOS configuration and set up the hda_gen_spec 4437 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
4438 * set up the hda_gen_spec
4439 * @codec: the HDA codec
4440 * @cfg: Parsed pin configuration
4346 * 4441 *
4347 * return 1 if successful, 0 if the proper config is not found, 4442 * return 1 if successful, 0 if the proper config is not found,
4348 * or a negative error code 4443 * or a negative error code
@@ -4524,10 +4619,16 @@ static const char * const slave_pfxs[] = {
4524 "CLFE", "Bass Speaker", "PCM", 4619 "CLFE", "Bass Speaker", "PCM",
4525 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side", 4620 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
4526 "Headphone Front", "Headphone Surround", "Headphone CLFE", 4621 "Headphone Front", "Headphone Surround", "Headphone CLFE",
4527 "Headphone Side", 4622 "Headphone Side", "Headphone+LO", "Speaker+LO",
4528 NULL, 4623 NULL,
4529}; 4624};
4530 4625
4626/**
4627 * snd_hda_gen_build_controls - Build controls from the parsed results
4628 * @codec: the HDA codec
4629 *
4630 * Pass this to build_controls patch_ops.
4631 */
4531int snd_hda_gen_build_controls(struct hda_codec *codec) 4632int snd_hda_gen_build_controls(struct hda_codec *codec)
4532{ 4633{
4533 struct hda_gen_spec *spec = codec->spec; 4634 struct hda_gen_spec *spec = codec->spec;
@@ -5005,7 +5106,12 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5005 strlcat(str, sfx, len); 5106 strlcat(str, sfx, len);
5006} 5107}
5007 5108
5008/* build PCM streams based on the parsed results */ 5109/**
5110 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
5111 * @codec: the HDA codec
5112 *
5113 * Pass this to build_pcms patch_ops.
5114 */
5009int snd_hda_gen_build_pcms(struct hda_codec *codec) 5115int snd_hda_gen_build_pcms(struct hda_codec *codec)
5010{ 5116{
5011 struct hda_gen_spec *spec = codec->spec; 5117 struct hda_gen_spec *spec = codec->spec;
@@ -5300,9 +5406,11 @@ static void clear_unsol_on_unused_pins(struct hda_codec *codec)
5300 } 5406 }
5301} 5407}
5302 5408
5303/* 5409/**
5304 * initialize the generic spec; 5410 * snd_hda_gen_init - initialize the generic spec
5305 * this can be put as patch_ops.init function 5411 * @codec: the HDA codec
5412 *
5413 * This can be put as patch_ops init function.
5306 */ 5414 */
5307int snd_hda_gen_init(struct hda_codec *codec) 5415int snd_hda_gen_init(struct hda_codec *codec)
5308{ 5416{
@@ -5338,9 +5446,11 @@ int snd_hda_gen_init(struct hda_codec *codec)
5338} 5446}
5339EXPORT_SYMBOL_GPL(snd_hda_gen_init); 5447EXPORT_SYMBOL_GPL(snd_hda_gen_init);
5340 5448
5341/* 5449/**
5342 * free the generic spec; 5450 * snd_hda_gen_free - free the generic spec
5343 * this can be put as patch_ops.free function 5451 * @codec: the HDA codec
5452 *
5453 * This can be put as patch_ops free function.
5344 */ 5454 */
5345void snd_hda_gen_free(struct hda_codec *codec) 5455void snd_hda_gen_free(struct hda_codec *codec)
5346{ 5456{
@@ -5352,9 +5462,12 @@ void snd_hda_gen_free(struct hda_codec *codec)
5352EXPORT_SYMBOL_GPL(snd_hda_gen_free); 5462EXPORT_SYMBOL_GPL(snd_hda_gen_free);
5353 5463
5354#ifdef CONFIG_PM 5464#ifdef CONFIG_PM
5355/* 5465/**
5356 * check the loopback power save state; 5466 * snd_hda_gen_check_power_status - check the loopback power save state
5357 * this can be put as patch_ops.check_power_status function 5467 * @codec: the HDA codec
5468 * @nid: NID to inspect
5469 *
5470 * This can be put as patch_ops check_power_status function.
5358 */ 5471 */
5359int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid) 5472int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
5360{ 5473{
@@ -5380,6 +5493,12 @@ static const struct hda_codec_ops generic_patch_ops = {
5380#endif 5493#endif
5381}; 5494};
5382 5495
5496/**
5497 * snd_hda_parse_generic_codec - Generic codec parser
5498 * @codec: the HDA codec
5499 *
5500 * This should be called from the HDA codec core.
5501 */
5383int snd_hda_parse_generic_codec(struct hda_codec *codec) 5502int snd_hda_parse_generic_codec(struct hda_codec *codec)
5384{ 5503{
5385 struct hda_gen_spec *spec; 5504 struct hda_gen_spec *spec;
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 48b6c5a3884f..5ac0d39d59bc 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -196,8 +196,8 @@ MODULE_PARM_DESC(align_buffer_size,
196 "Force buffer and period sizes to be multiple of 128 bytes."); 196 "Force buffer and period sizes to be multiple of 128 bytes.");
197 197
198#ifdef CONFIG_X86 198#ifdef CONFIG_X86
199static bool hda_snoop = true; 199static int hda_snoop = -1;
200module_param_named(snoop, hda_snoop, bool, 0444); 200module_param_named(snoop, hda_snoop, bint, 0444);
201MODULE_PARM_DESC(snoop, "Enable/disable snooping"); 201MODULE_PARM_DESC(snoop, "Enable/disable snooping");
202#else 202#else
203#define hda_snoop true 203#define hda_snoop true
@@ -272,43 +272,56 @@ enum {
272 AZX_NUM_DRIVERS, /* keep this as last entry */ 272 AZX_NUM_DRIVERS, /* keep this as last entry */
273}; 273};
274 274
275#define azx_get_snoop_type(chip) \
276 (((chip)->driver_caps & AZX_DCAPS_SNOOP_MASK) >> 10)
277#define AZX_DCAPS_SNOOP_TYPE(type) ((AZX_SNOOP_TYPE_ ## type) << 10)
278
279/* quirks for old Intel chipsets */
280#define AZX_DCAPS_INTEL_ICH \
281 (AZX_DCAPS_OLD_SSYNC | AZX_DCAPS_NO_ALIGN_BUFSIZE)
282
275/* quirks for Intel PCH */ 283/* quirks for Intel PCH */
276#define AZX_DCAPS_INTEL_PCH_NOPM \ 284#define AZX_DCAPS_INTEL_PCH_NOPM \
277 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_BUFSIZE | \ 285 (AZX_DCAPS_NO_ALIGN_BUFSIZE | AZX_DCAPS_COUNT_LPIB_DELAY |\
278 AZX_DCAPS_COUNT_LPIB_DELAY | AZX_DCAPS_REVERSE_ASSIGN) 286 AZX_DCAPS_REVERSE_ASSIGN | AZX_DCAPS_SNOOP_TYPE(SCH))
279 287
280#define AZX_DCAPS_INTEL_PCH \ 288#define AZX_DCAPS_INTEL_PCH \
281 (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_PM_RUNTIME) 289 (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_PM_RUNTIME)
282 290
283#define AZX_DCAPS_INTEL_HASWELL \ 291#define AZX_DCAPS_INTEL_HASWELL \
284 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_ALIGN_BUFSIZE | \ 292 (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_COUNT_LPIB_DELAY |\
285 AZX_DCAPS_COUNT_LPIB_DELAY | AZX_DCAPS_PM_RUNTIME | \ 293 AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\
286 AZX_DCAPS_I915_POWERWELL) 294 AZX_DCAPS_SNOOP_TYPE(SCH))
287 295
288/* Broadwell HDMI can't use position buffer reliably, force to use LPIB */ 296/* Broadwell HDMI can't use position buffer reliably, force to use LPIB */
289#define AZX_DCAPS_INTEL_BROADWELL \ 297#define AZX_DCAPS_INTEL_BROADWELL \
290 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_ALIGN_BUFSIZE | \ 298 (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_POSFIX_LPIB |\
291 AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_PM_RUNTIME | \ 299 AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\
292 AZX_DCAPS_I915_POWERWELL) 300 AZX_DCAPS_SNOOP_TYPE(SCH))
293 301
294/* quirks for ATI SB / AMD Hudson */ 302/* quirks for ATI SB / AMD Hudson */
295#define AZX_DCAPS_PRESET_ATI_SB \ 303#define AZX_DCAPS_PRESET_ATI_SB \
296 (AZX_DCAPS_ATI_SNOOP | AZX_DCAPS_NO_TCSEL | \ 304 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB |\
297 AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB) 305 AZX_DCAPS_SNOOP_TYPE(ATI))
298 306
299/* quirks for ATI/AMD HDMI */ 307/* quirks for ATI/AMD HDMI */
300#define AZX_DCAPS_PRESET_ATI_HDMI \ 308#define AZX_DCAPS_PRESET_ATI_HDMI \
301 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB|\ 309 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB|\
302 AZX_DCAPS_NO_MSI64) 310 AZX_DCAPS_NO_MSI64)
303 311
312/* quirks for ATI HDMI with snoop off */
313#define AZX_DCAPS_PRESET_ATI_HDMI_NS \
314 (AZX_DCAPS_PRESET_ATI_HDMI | AZX_DCAPS_SNOOP_OFF)
315
304/* quirks for Nvidia */ 316/* quirks for Nvidia */
305#define AZX_DCAPS_PRESET_NVIDIA \ 317#define AZX_DCAPS_PRESET_NVIDIA \
306 (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\ 318 (AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI | /*AZX_DCAPS_ALIGN_BUFSIZE |*/ \
307 AZX_DCAPS_ALIGN_BUFSIZE | AZX_DCAPS_NO_64BIT |\ 319 AZX_DCAPS_NO_64BIT | AZX_DCAPS_CORBRP_SELF_CLEAR |\
308 AZX_DCAPS_CORBRP_SELF_CLEAR) 320 AZX_DCAPS_SNOOP_TYPE(NVIDIA))
309 321
310#define AZX_DCAPS_PRESET_CTHDA \ 322#define AZX_DCAPS_PRESET_CTHDA \
311 (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY) 323 (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB |\
324 AZX_DCAPS_4K_BDLE_BOUNDARY | AZX_DCAPS_SNOOP_OFF)
312 325
313/* 326/*
314 * VGA-switcher support 327 * VGA-switcher support
@@ -437,6 +450,8 @@ static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
437 450
438static void azx_init_pci(struct azx *chip) 451static void azx_init_pci(struct azx *chip)
439{ 452{
453 int snoop_type = azx_get_snoop_type(chip);
454
440 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44) 455 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
441 * TCSEL == Traffic Class Select Register, which sets PCI express QOS 456 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
442 * Ensuring these bits are 0 clears playback static on some HD Audio 457 * Ensuring these bits are 0 clears playback static on some HD Audio
@@ -451,7 +466,7 @@ static void azx_init_pci(struct azx *chip)
451 /* For ATI SB450/600/700/800/900 and AMD Hudson azalia HD audio, 466 /* For ATI SB450/600/700/800/900 and AMD Hudson azalia HD audio,
452 * we need to enable snoop. 467 * we need to enable snoop.
453 */ 468 */
454 if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) { 469 if (snoop_type == AZX_SNOOP_TYPE_ATI) {
455 dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n", 470 dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n",
456 azx_snoop(chip)); 471 azx_snoop(chip));
457 update_pci_byte(chip->pci, 472 update_pci_byte(chip->pci,
@@ -460,7 +475,7 @@ static void azx_init_pci(struct azx *chip)
460 } 475 }
461 476
462 /* For NVIDIA HDA, enable snoop */ 477 /* For NVIDIA HDA, enable snoop */
463 if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) { 478 if (snoop_type == AZX_SNOOP_TYPE_NVIDIA) {
464 dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n", 479 dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n",
465 azx_snoop(chip)); 480 azx_snoop(chip));
466 update_pci_byte(chip->pci, 481 update_pci_byte(chip->pci,
@@ -475,7 +490,7 @@ static void azx_init_pci(struct azx *chip)
475 } 490 }
476 491
477 /* Enable SCH/PCH snoop if needed */ 492 /* Enable SCH/PCH snoop if needed */
478 if (chip->driver_caps & AZX_DCAPS_SCH_SNOOP) { 493 if (snoop_type == AZX_SNOOP_TYPE_SCH) {
479 unsigned short snoop; 494 unsigned short snoop;
480 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop); 495 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
481 if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) || 496 if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) ||
@@ -1132,8 +1147,7 @@ static int azx_free(struct azx *chip)
1132 pci_disable_device(chip->pci); 1147 pci_disable_device(chip->pci);
1133 kfree(chip->azx_dev); 1148 kfree(chip->azx_dev);
1134#ifdef CONFIG_SND_HDA_PATCH_LOADER 1149#ifdef CONFIG_SND_HDA_PATCH_LOADER
1135 if (chip->fw) 1150 release_firmware(chip->fw);
1136 release_firmware(chip->fw);
1137#endif 1151#endif
1138 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 1152 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1139 hda_display_power(false); 1153 hda_display_power(false);
@@ -1361,35 +1375,33 @@ static void check_msi(struct azx *chip)
1361/* check the snoop mode availability */ 1375/* check the snoop mode availability */
1362static void azx_check_snoop_available(struct azx *chip) 1376static void azx_check_snoop_available(struct azx *chip)
1363{ 1377{
1364 bool snoop = chip->snoop; 1378 int snoop = hda_snoop;
1365 1379
1366 switch (chip->driver_type) { 1380 if (snoop >= 0) {
1367 case AZX_DRIVER_VIA: 1381 dev_info(chip->card->dev, "Force to %s mode by module option\n",
1382 snoop ? "snoop" : "non-snoop");
1383 chip->snoop = snoop;
1384 return;
1385 }
1386
1387 snoop = true;
1388 if (azx_get_snoop_type(chip) == AZX_SNOOP_TYPE_NONE &&
1389 chip->driver_type == AZX_DRIVER_VIA) {
1368 /* force to non-snoop mode for a new VIA controller 1390 /* force to non-snoop mode for a new VIA controller
1369 * when BIOS is set 1391 * when BIOS is set
1370 */ 1392 */
1371 if (snoop) { 1393 u8 val;
1372 u8 val; 1394 pci_read_config_byte(chip->pci, 0x42, &val);
1373 pci_read_config_byte(chip->pci, 0x42, &val); 1395 if (!(val & 0x80) && chip->pci->revision == 0x30)
1374 if (!(val & 0x80) && chip->pci->revision == 0x30) 1396 snoop = false;
1375 snoop = false;
1376 }
1377 break;
1378 case AZX_DRIVER_ATIHDMI_NS:
1379 /* new ATI HDMI requires non-snoop */
1380 snoop = false;
1381 break;
1382 case AZX_DRIVER_CTHDA:
1383 case AZX_DRIVER_CMEDIA:
1384 snoop = false;
1385 break;
1386 } 1397 }
1387 1398
1388 if (snoop != chip->snoop) { 1399 if (chip->driver_caps & AZX_DCAPS_SNOOP_OFF)
1389 dev_info(chip->card->dev, "Force to %s mode\n", 1400 snoop = false;
1390 snoop ? "snoop" : "non-snoop"); 1401
1391 chip->snoop = snoop; 1402 chip->snoop = snoop;
1392 } 1403 if (!snoop)
1404 dev_info(chip->card->dev, "Force to non-snoop mode\n");
1393} 1405}
1394 1406
1395static void azx_probe_work(struct work_struct *work) 1407static void azx_probe_work(struct work_struct *work)
@@ -1449,7 +1461,6 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
1449 check_probe_mask(chip, dev); 1461 check_probe_mask(chip, dev);
1450 1462
1451 chip->single_cmd = single_cmd; 1463 chip->single_cmd = single_cmd;
1452 chip->snoop = hda_snoop;
1453 azx_check_snoop_available(chip); 1464 azx_check_snoop_available(chip);
1454 1465
1455 if (bdl_pos_adj[dev] < 0) { 1466 if (bdl_pos_adj[dev] < 0) {
@@ -1557,10 +1568,8 @@ static int azx_first_init(struct azx *chip)
1557 if (align_buffer_size >= 0) 1568 if (align_buffer_size >= 0)
1558 chip->align_buffer_size = !!align_buffer_size; 1569 chip->align_buffer_size = !!align_buffer_size;
1559 else { 1570 else {
1560 if (chip->driver_caps & AZX_DCAPS_BUFSIZE) 1571 if (chip->driver_caps & AZX_DCAPS_NO_ALIGN_BUFSIZE)
1561 chip->align_buffer_size = 0; 1572 chip->align_buffer_size = 0;
1562 else if (chip->driver_caps & AZX_DCAPS_ALIGN_BUFSIZE)
1563 chip->align_buffer_size = 1;
1564 else 1573 else
1565 chip->align_buffer_size = 1; 1574 chip->align_buffer_size = 1;
1566 } 1575 }
@@ -2047,36 +2056,35 @@ static const struct pci_device_id azx_ids[] = {
2047 /* Braswell */ 2056 /* Braswell */
2048 { PCI_DEVICE(0x8086, 0x2284), 2057 { PCI_DEVICE(0x8086, 0x2284),
2049 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, 2058 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2050 /* ICH */ 2059 /* ICH6 */
2051 { PCI_DEVICE(0x8086, 0x2668), 2060 { PCI_DEVICE(0x8086, 0x2668),
2052 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | 2061 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2053 AZX_DCAPS_BUFSIZE }, /* ICH6 */ 2062 /* ICH7 */
2054 { PCI_DEVICE(0x8086, 0x27d8), 2063 { PCI_DEVICE(0x8086, 0x27d8),
2055 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | 2064 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2056 AZX_DCAPS_BUFSIZE }, /* ICH7 */ 2065 /* ESB2 */
2057 { PCI_DEVICE(0x8086, 0x269a), 2066 { PCI_DEVICE(0x8086, 0x269a),
2058 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | 2067 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2059 AZX_DCAPS_BUFSIZE }, /* ESB2 */ 2068 /* ICH8 */
2060 { PCI_DEVICE(0x8086, 0x284b), 2069 { PCI_DEVICE(0x8086, 0x284b),
2061 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | 2070 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2062 AZX_DCAPS_BUFSIZE }, /* ICH8 */ 2071 /* ICH9 */
2063 { PCI_DEVICE(0x8086, 0x293e), 2072 { PCI_DEVICE(0x8086, 0x293e),
2064 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | 2073 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2065 AZX_DCAPS_BUFSIZE }, /* ICH9 */ 2074 /* ICH9 */
2066 { PCI_DEVICE(0x8086, 0x293f), 2075 { PCI_DEVICE(0x8086, 0x293f),
2067 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | 2076 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2068 AZX_DCAPS_BUFSIZE }, /* ICH9 */ 2077 /* ICH10 */
2069 { PCI_DEVICE(0x8086, 0x3a3e), 2078 { PCI_DEVICE(0x8086, 0x3a3e),
2070 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | 2079 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2071 AZX_DCAPS_BUFSIZE }, /* ICH10 */ 2080 /* ICH10 */
2072 { PCI_DEVICE(0x8086, 0x3a6e), 2081 { PCI_DEVICE(0x8086, 0x3a6e),
2073 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | 2082 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2074 AZX_DCAPS_BUFSIZE }, /* ICH10 */
2075 /* Generic Intel */ 2083 /* Generic Intel */
2076 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID), 2084 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
2077 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2085 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2078 .class_mask = 0xffffff, 2086 .class_mask = 0xffffff,
2079 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_BUFSIZE }, 2087 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_NO_ALIGN_BUFSIZE },
2080 /* ATI SB 450/600/700/800/900 */ 2088 /* ATI SB 450/600/700/800/900 */
2081 { PCI_DEVICE(0x1002, 0x437b), 2089 { PCI_DEVICE(0x1002, 0x437b),
2082 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB }, 2090 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
@@ -2131,13 +2139,13 @@ static const struct pci_device_id azx_ids[] = {
2131 { PCI_DEVICE(0x1002, 0xaa98), 2139 { PCI_DEVICE(0x1002, 0xaa98),
2132 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, 2140 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2133 { PCI_DEVICE(0x1002, 0x9902), 2141 { PCI_DEVICE(0x1002, 0x9902),
2134 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, 2142 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2135 { PCI_DEVICE(0x1002, 0xaaa0), 2143 { PCI_DEVICE(0x1002, 0xaaa0),
2136 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, 2144 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2137 { PCI_DEVICE(0x1002, 0xaaa8), 2145 { PCI_DEVICE(0x1002, 0xaaa8),
2138 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, 2146 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2139 { PCI_DEVICE(0x1002, 0xaab0), 2147 { PCI_DEVICE(0x1002, 0xaab0),
2140 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, 2148 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2141 /* VIA VT8251/VT8237A */ 2149 /* VIA VT8251/VT8237A */
2142 { PCI_DEVICE(0x1106, 0x3288), 2150 { PCI_DEVICE(0x1106, 0x3288),
2143 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA }, 2151 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA },
@@ -2184,7 +2192,7 @@ static const struct pci_device_id azx_ids[] = {
2184 /* CM8888 */ 2192 /* CM8888 */
2185 { PCI_DEVICE(0x13f6, 0x5011), 2193 { PCI_DEVICE(0x13f6, 0x5011),
2186 .driver_data = AZX_DRIVER_CMEDIA | 2194 .driver_data = AZX_DRIVER_CMEDIA |
2187 AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB }, 2195 AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_SNOOP_OFF },
2188 /* Vortex86MX */ 2196 /* Vortex86MX */
2189 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC }, 2197 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
2190 /* VMware HDAudio */ 2198 /* VMware HDAudio */
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index f56765ae73a7..e664307617bd 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -20,6 +20,16 @@
20#include "hda_auto_parser.h" 20#include "hda_auto_parser.h"
21#include "hda_jack.h" 21#include "hda_jack.h"
22 22
23/**
24 * is_jack_detectable - Check whether the given pin is jack-detectable
25 * @codec: the HDA codec
26 * @nid: pin NID
27 *
28 * Check whether the given pin is capable to report the jack detection.
29 * The jack detection might not work by various reasons, e.g. the jack
30 * detection is prohibited in the codec level, the pin config has
31 * AC_DEFCFG_MISC_NO_PRESENCE bit, no unsol support, etc.
32 */
23bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid) 33bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
24{ 34{
25 if (codec->no_jack_detect) 35 if (codec->no_jack_detect)
@@ -57,6 +67,8 @@ static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid)
57 67
58/** 68/**
59 * snd_hda_jack_tbl_get - query the jack-table entry for the given NID 69 * snd_hda_jack_tbl_get - query the jack-table entry for the given NID
70 * @codec: the HDA codec
71 * @nid: pin NID to refer to
60 */ 72 */
61struct hda_jack_tbl * 73struct hda_jack_tbl *
62snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid) 74snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid)
@@ -75,6 +87,8 @@ EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get);
75 87
76/** 88/**
77 * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag 89 * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag
90 * @codec: the HDA codec
91 * @tag: tag value to refer to
78 */ 92 */
79struct hda_jack_tbl * 93struct hda_jack_tbl *
80snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag) 94snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag)
@@ -93,6 +107,8 @@ EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get_from_tag);
93 107
94/** 108/**
95 * snd_hda_jack_tbl_new - create a jack-table entry for the given NID 109 * snd_hda_jack_tbl_new - create a jack-table entry for the given NID
110 * @codec: the HDA codec
111 * @nid: pin NID to assign
96 */ 112 */
97static struct hda_jack_tbl * 113static struct hda_jack_tbl *
98snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) 114snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)
@@ -162,6 +178,7 @@ static void jack_detect_update(struct hda_codec *codec,
162 178
163/** 179/**
164 * snd_hda_set_dirty_all - Mark all the cached as dirty 180 * snd_hda_set_dirty_all - Mark all the cached as dirty
181 * @codec: the HDA codec
165 * 182 *
166 * This function sets the dirty flag to all entries of jack table. 183 * This function sets the dirty flag to all entries of jack table.
167 * It's called from the resume path in hda_codec.c. 184 * It's called from the resume path in hda_codec.c.
@@ -218,6 +235,9 @@ EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state);
218 235
219/** 236/**
220 * snd_hda_jack_detect_enable - enable the jack-detection 237 * snd_hda_jack_detect_enable - enable the jack-detection
238 * @codec: the HDA codec
239 * @nid: pin NID to enable
240 * @func: callback function to register
221 * 241 *
222 * In the case of error, the return value will be a pointer embedded with 242 * In the case of error, the return value will be a pointer embedded with
223 * errno. Check and handle the return value appropriately with standard 243 * errno. Check and handle the return value appropriately with standard
@@ -258,6 +278,14 @@ snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
258} 278}
259EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback); 279EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback);
260 280
281/**
282 * snd_hda_jack_detect_enable - Enable the jack detection on the given pin
283 * @codec: the HDA codec
284 * @nid: pin NID to enable jack detection
285 *
286 * Enable the jack detection with the default callback. Returns zero if
287 * successful or a negative error code.
288 */
261int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid) 289int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid)
262{ 290{
263 return PTR_ERR_OR_ZERO(snd_hda_jack_detect_enable_callback(codec, nid, NULL)); 291 return PTR_ERR_OR_ZERO(snd_hda_jack_detect_enable_callback(codec, nid, NULL));
@@ -266,6 +294,9 @@ EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable);
266 294
267/** 295/**
268 * snd_hda_jack_set_gating_jack - Set gating jack. 296 * snd_hda_jack_set_gating_jack - Set gating jack.
297 * @codec: the HDA codec
298 * @gated_nid: gated pin NID
299 * @gating_nid: gating pin NID
269 * 300 *
270 * Indicates the gated jack is only valid when the gating jack is plugged. 301 * Indicates the gated jack is only valid when the gating jack is plugged.
271 */ 302 */
@@ -287,6 +318,7 @@ EXPORT_SYMBOL_GPL(snd_hda_jack_set_gating_jack);
287 318
288/** 319/**
289 * snd_hda_jack_report_sync - sync the states of all jacks and report if changed 320 * snd_hda_jack_report_sync - sync the states of all jacks and report if changed
321 * @codec: the HDA codec
290 */ 322 */
291void snd_hda_jack_report_sync(struct hda_codec *codec) 323void snd_hda_jack_report_sync(struct hda_codec *codec)
292{ 324{
@@ -349,6 +381,11 @@ static void hda_free_jack_priv(struct snd_jack *jack)
349 381
350/** 382/**
351 * snd_hda_jack_add_kctl - Add a kctl for the given pin 383 * snd_hda_jack_add_kctl - Add a kctl for the given pin
384 * @codec: the HDA codec
385 * @nid: pin NID to assign
386 * @name: string name for the jack
387 * @idx: index number for the jack
388 * @phantom_jack: flag to deal as a phantom jack
352 * 389 *
353 * This assigns a jack-detection kctl to the given pin. The kcontrol 390 * This assigns a jack-detection kctl to the given pin. The kcontrol
354 * will have the given name and index. 391 * will have the given name and index.
@@ -391,6 +428,15 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
391 return 0; 428 return 0;
392} 429}
393 430
431/**
432 * snd_hda_jack_add_kctl - Add a jack kctl for the given pin
433 * @codec: the HDA codec
434 * @nid: pin NID
435 * @name: the name string for the jack ctl
436 * @idx: the ctl index for the jack ctl
437 *
438 * This is a simple helper calling __snd_hda_jack_add_kctl().
439 */
394int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, 440int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
395 const char *name, int idx) 441 const char *name, int idx)
396{ 442{
@@ -456,6 +502,8 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
456 502
457/** 503/**
458 * snd_hda_jack_add_kctls - Add kctls for all pins included in the given pincfg 504 * snd_hda_jack_add_kctls - Add kctls for all pins included in the given pincfg
505 * @codec: the HDA codec
506 * @cfg: pin config table to parse
459 */ 507 */
460int snd_hda_jack_add_kctls(struct hda_codec *codec, 508int snd_hda_jack_add_kctls(struct hda_codec *codec,
461 const struct auto_pin_cfg *cfg) 509 const struct auto_pin_cfg *cfg)
@@ -531,6 +579,11 @@ static void call_jack_callback(struct hda_codec *codec,
531 } 579 }
532} 580}
533 581
582/**
583 * snd_hda_jack_unsol_event - Handle an unsolicited event
584 * @codec: the HDA codec
585 * @res: the unsolicited event data
586 */
534void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res) 587void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res)
535{ 588{
536 struct hda_jack_tbl *event; 589 struct hda_jack_tbl *event;
@@ -546,6 +599,13 @@ void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res)
546} 599}
547EXPORT_SYMBOL_GPL(snd_hda_jack_unsol_event); 600EXPORT_SYMBOL_GPL(snd_hda_jack_unsol_event);
548 601
602/**
603 * snd_hda_jack_poll_all - Poll all jacks
604 * @codec: the HDA codec
605 *
606 * Poll all detectable jacks with dirty flag, update the status, call
607 * callbacks and call snd_hda_jack_report_sync() if any changes are found.
608 */
549void snd_hda_jack_poll_all(struct hda_codec *codec) 609void snd_hda_jack_poll_all(struct hda_codec *codec)
550{ 610{
551 struct hda_jack_tbl *jack = codec->jacktbl.list; 611 struct hda_jack_tbl *jack = codec->jacktbl.list;
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
index 13cb375454f6..b279e327a23b 100644
--- a/sound/pci/hda/hda_jack.h
+++ b/sound/pci/hda/hda_jack.h
@@ -72,6 +72,11 @@ enum {
72 72
73int snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid); 73int snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid);
74 74
75/**
76 * snd_hda_jack_detect - Detect the jack
77 * @codec: the HDA codec
78 * @nid: pin NID to check jack detection
79 */
75static inline bool snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid) 80static inline bool snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
76{ 81{
77 return snd_hda_jack_detect_state(codec, nid) != HDA_JACK_NOT_PRESENT; 82 return snd_hda_jack_detect_state(codec, nid) != HDA_JACK_NOT_PRESENT;
diff --git a/sound/pci/hda/hda_priv.h b/sound/pci/hda/hda_priv.h
index 5016014e57f2..aa484fdf4338 100644
--- a/sound/pci/hda/hda_priv.h
+++ b/sound/pci/hda/hda_priv.h
@@ -152,9 +152,8 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
152/* bits 0-7 are used for indicating driver type */ 152/* bits 0-7 are used for indicating driver type */
153#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */ 153#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
154#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */ 154#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
155#define AZX_DCAPS_ATI_SNOOP (1 << 10) /* ATI snoop enable */ 155#define AZX_DCAPS_SNOOP_MASK (3 << 10) /* snoop type mask */
156#define AZX_DCAPS_NVIDIA_SNOOP (1 << 11) /* Nvidia snoop enable */ 156#define AZX_DCAPS_SNOOP_OFF (1 << 12) /* snoop default off */
157#define AZX_DCAPS_SCH_SNOOP (1 << 12) /* SCH/PCH snoop enable */
158#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */ 157#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
159#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */ 158#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
160#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */ 159#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
@@ -163,8 +162,8 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
163#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */ 162#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
164#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */ 163#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
165#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */ 164#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
166#define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */ 165#define AZX_DCAPS_NO_ALIGN_BUFSIZE (1 << 21) /* no buffer size alignment */
167#define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */ 166/* 22 unused */
168#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */ 167#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
169#define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */ 168#define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */
170#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */ 169#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
@@ -173,6 +172,13 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
173#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */ 172#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */
174#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */ 173#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */
175 174
175enum {
176 AZX_SNOOP_TYPE_NONE ,
177 AZX_SNOOP_TYPE_SCH,
178 AZX_SNOOP_TYPE_ATI,
179 AZX_SNOOP_TYPE_NVIDIA,
180};
181
176/* HD Audio class code */ 182/* HD Audio class code */
177#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 183#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
178 184
diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c
index 9b49f156a12e..bef721592c3a 100644
--- a/sound/pci/hda/hda_sysfs.c
+++ b/sound/pci/hda/hda_sysfs.c
@@ -417,8 +417,13 @@ static DEVICE_ATTR_RW(user_pin_configs);
417static DEVICE_ATTR_WO(reconfig); 417static DEVICE_ATTR_WO(reconfig);
418static DEVICE_ATTR_WO(clear); 418static DEVICE_ATTR_WO(clear);
419 419
420/* 420/**
421 * Look for hint string 421 * snd_hda_get_hint - Look for hint string
422 * @codec: the HDA codec
423 * @key: the hint key string
424 *
425 * Look for a hint key/value pair matching with the given key string
426 * and returns the value string. If nothing found, returns NULL.
422 */ 427 */
423const char *snd_hda_get_hint(struct hda_codec *codec, const char *key) 428const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
424{ 429{
@@ -427,6 +432,15 @@ const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
427} 432}
428EXPORT_SYMBOL_GPL(snd_hda_get_hint); 433EXPORT_SYMBOL_GPL(snd_hda_get_hint);
429 434
435/**
436 * snd_hda_get_bool_hint - Get a boolean hint value
437 * @codec: the HDA codec
438 * @key: the hint key string
439 *
440 * Look for a hint key/value pair matching with the given key string
441 * and returns a boolean value parsed from the value. If no matching
442 * key is found, return a negative value.
443 */
430int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key) 444int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
431{ 445{
432 const char *p; 446 const char *p;
@@ -453,6 +467,16 @@ int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
453} 467}
454EXPORT_SYMBOL_GPL(snd_hda_get_bool_hint); 468EXPORT_SYMBOL_GPL(snd_hda_get_bool_hint);
455 469
470/**
471 * snd_hda_get_bool_hint - Get a boolean hint value
472 * @codec: the HDA codec
473 * @key: the hint key string
474 * @valp: pointer to store a value
475 *
476 * Look for a hint key/value pair matching with the given key string
477 * and stores the integer value to @valp. If no matching key is found,
478 * return a negative error code. Otherwise it returns zero.
479 */
456int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp) 480int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
457{ 481{
458 const char *p; 482 const char *p;
@@ -690,8 +714,11 @@ static int get_line_from_fw(char *buf, int size, size_t *fw_size_p,
690 return 1; 714 return 1;
691} 715}
692 716
693/* 717/**
694 * load a "patch" firmware file and parse it 718 * snd_hda_load_patch - load a "patch" firmware file and parse it
719 * @bus: HD-audio bus
720 * @fw_size: the firmware byte size
721 * @fw_buf: the firmware data
695 */ 722 */
696int snd_hda_load_patch(struct hda_bus *bus, size_t fw_size, const void *fw_buf) 723int snd_hda_load_patch(struct hda_bus *bus, size_t fw_size, const void *fw_buf)
697{ 724{
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 06275f8807a8..c81b715d6c98 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -332,6 +332,7 @@ static const struct hda_fixup ad1986a_fixups[] = {
332 332
333static const struct snd_pci_quirk ad1986a_fixup_tbl[] = { 333static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
334 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC), 334 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
335 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD),
335 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD), 336 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD),
336 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK), 337 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
337 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK), 338 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
@@ -351,6 +352,7 @@ static const struct hda_model_fixup ad1986a_fixup_models[] = {
351 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" }, 352 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
352 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" }, 353 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
353 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */ 354 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
355 { .id = AD1986A_FIXUP_EAPD, .name = "eapd" },
354 {} 356 {}
355}; 357};
356 358
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 4f7ffa8c4a0d..e0383eea9880 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -2417,7 +2417,7 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2417 * @reloc: Relocation address for loading single-segment overlays, or 0 for 2417 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2418 * no relocation 2418 * no relocation
2419 * @sample_rate: sampling rate of the stream used for DSP download 2419 * @sample_rate: sampling rate of the stream used for DSP download
2420 * @number_channels: channels of the stream used for DSP download 2420 * @channels: channels of the stream used for DSP download
2421 * @ovly: TRUE if overlay format is required 2421 * @ovly: TRUE if overlay format is required
2422 * 2422 *
2423 * Returns zero or a negative error code. 2423 * Returns zero or a negative error code.
@@ -2556,10 +2556,7 @@ static void dspload_post_setup(struct hda_codec *codec)
2556} 2556}
2557 2557
2558/** 2558/**
2559 * Download DSP from a DSP Image Fast Load structure. This structure is a 2559 * dspload_image - Download DSP from a DSP Image Fast Load structure.
2560 * linear, non-constant sized element array of structures, each of which
2561 * contain the count of the data to be loaded, the data itself, and the
2562 * corresponding starting chip address of the starting data location.
2563 * 2560 *
2564 * @codec: the HDA codec 2561 * @codec: the HDA codec
2565 * @fls: pointer to a fast load image 2562 * @fls: pointer to a fast load image
@@ -2570,6 +2567,10 @@ static void dspload_post_setup(struct hda_codec *codec)
2570 * @router_chans: number of audio router channels to be allocated (0 means use 2567 * @router_chans: number of audio router channels to be allocated (0 means use
2571 * internal defaults; max is 32) 2568 * internal defaults; max is 32)
2572 * 2569 *
2570 * Download DSP from a DSP Image Fast Load structure. This structure is a
2571 * linear, non-constant sized element array of structures, each of which
2572 * contain the count of the data to be loaded, the data itself, and the
2573 * corresponding starting chip address of the starting data location.
2573 * Returns zero or a negative error code. 2574 * Returns zero or a negative error code.
2574 */ 2575 */
2575static int dspload_image(struct hda_codec *codec, 2576static int dspload_image(struct hda_codec *codec,
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index b118a5be18df..a722067c491c 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -96,6 +96,8 @@ struct alc_spec {
96 hda_nid_t cap_mute_led_nid; 96 hda_nid_t cap_mute_led_nid;
97 97
98 unsigned int gpio_led; /* used for alc269_fixup_hp_gpio_led() */ 98 unsigned int gpio_led; /* used for alc269_fixup_hp_gpio_led() */
99 unsigned int gpio_mute_led_mask;
100 unsigned int gpio_mic_led_mask;
99 101
100 hda_nid_t headset_mic_pin; 102 hda_nid_t headset_mic_pin;
101 hda_nid_t headphone_mic_pin; 103 hda_nid_t headphone_mic_pin;
@@ -3310,41 +3312,45 @@ static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
3310 } 3312 }
3311} 3313}
3312 3314
3313/* turn on/off mute LED per vmaster hook */ 3315/* update LED status via GPIO */
3314static void alc269_fixup_hp_gpio_mute_hook(void *private_data, int enabled) 3316static void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask,
3317 bool enabled)
3315{ 3318{
3316 struct hda_codec *codec = private_data;
3317 struct alc_spec *spec = codec->spec; 3319 struct alc_spec *spec = codec->spec;
3318 unsigned int oldval = spec->gpio_led; 3320 unsigned int oldval = spec->gpio_led;
3319 3321
3322 if (spec->mute_led_polarity)
3323 enabled = !enabled;
3324
3320 if (enabled) 3325 if (enabled)
3321 spec->gpio_led &= ~0x08; 3326 spec->gpio_led &= ~mask;
3322 else 3327 else
3323 spec->gpio_led |= 0x08; 3328 spec->gpio_led |= mask;
3324 if (spec->gpio_led != oldval) 3329 if (spec->gpio_led != oldval)
3325 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 3330 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3326 spec->gpio_led); 3331 spec->gpio_led);
3327} 3332}
3328 3333
3329/* turn on/off mic-mute LED per capture hook */ 3334/* turn on/off mute LED via GPIO per vmaster hook */
3330static void alc269_fixup_hp_gpio_mic_mute_hook(struct hda_codec *codec, 3335static void alc_fixup_gpio_mute_hook(void *private_data, int enabled)
3331 struct snd_kcontrol *kcontrol,
3332 struct snd_ctl_elem_value *ucontrol)
3333{ 3336{
3337 struct hda_codec *codec = private_data;
3334 struct alc_spec *spec = codec->spec; 3338 struct alc_spec *spec = codec->spec;
3335 unsigned int oldval = spec->gpio_led;
3336 3339
3337 if (!ucontrol) 3340 alc_update_gpio_led(codec, spec->gpio_mute_led_mask, enabled);
3338 return; 3341}
3339 3342
3340 if (ucontrol->value.integer.value[0] || 3343/* turn on/off mic-mute LED via GPIO per capture hook */
3341 ucontrol->value.integer.value[1]) 3344static void alc_fixup_gpio_mic_mute_hook(struct hda_codec *codec,
3342 spec->gpio_led &= ~0x10; 3345 struct snd_kcontrol *kcontrol,
3343 else 3346 struct snd_ctl_elem_value *ucontrol)
3344 spec->gpio_led |= 0x10; 3347{
3345 if (spec->gpio_led != oldval) 3348 struct alc_spec *spec = codec->spec;
3346 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 3349
3347 spec->gpio_led); 3350 if (ucontrol)
3351 alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
3352 ucontrol->value.integer.value[0] ||
3353 ucontrol->value.integer.value[1]);
3348} 3354}
3349 3355
3350static void alc269_fixup_hp_gpio_led(struct hda_codec *codec, 3356static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
@@ -3358,9 +3364,33 @@ static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
3358 }; 3364 };
3359 3365
3360 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 3366 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3361 spec->gen.vmaster_mute.hook = alc269_fixup_hp_gpio_mute_hook; 3367 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3362 spec->gen.cap_sync_hook = alc269_fixup_hp_gpio_mic_mute_hook; 3368 spec->gen.cap_sync_hook = alc_fixup_gpio_mic_mute_hook;
3369 spec->gpio_led = 0;
3370 spec->mute_led_polarity = 0;
3371 spec->gpio_mute_led_mask = 0x08;
3372 spec->gpio_mic_led_mask = 0x10;
3373 snd_hda_add_verbs(codec, gpio_init);
3374 }
3375}
3376
3377static void alc286_fixup_hp_gpio_led(struct hda_codec *codec,
3378 const struct hda_fixup *fix, int action)
3379{
3380 struct alc_spec *spec = codec->spec;
3381 static const struct hda_verb gpio_init[] = {
3382 { 0x01, AC_VERB_SET_GPIO_MASK, 0x22 },
3383 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x22 },
3384 {}
3385 };
3386
3387 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3388 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3389 spec->gen.cap_sync_hook = alc_fixup_gpio_mic_mute_hook;
3363 spec->gpio_led = 0; 3390 spec->gpio_led = 0;
3391 spec->mute_led_polarity = 0;
3392 spec->gpio_mute_led_mask = 0x02;
3393 spec->gpio_mic_led_mask = 0x20;
3364 snd_hda_add_verbs(codec, gpio_init); 3394 snd_hda_add_verbs(codec, gpio_init);
3365 } 3395 }
3366} 3396}
@@ -3402,9 +3432,11 @@ static void alc269_fixup_hp_gpio_mic1_led(struct hda_codec *codec,
3402 }; 3432 };
3403 3433
3404 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 3434 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3405 spec->gen.vmaster_mute.hook = alc269_fixup_hp_gpio_mute_hook; 3435 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3406 spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook; 3436 spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3407 spec->gpio_led = 0; 3437 spec->gpio_led = 0;
3438 spec->mute_led_polarity = 0;
3439 spec->gpio_mute_led_mask = 0x08;
3408 spec->cap_mute_led_nid = 0x18; 3440 spec->cap_mute_led_nid = 0x18;
3409 snd_hda_add_verbs(codec, gpio_init); 3441 snd_hda_add_verbs(codec, gpio_init);
3410 codec->power_filter = led_power_filter; 3442 codec->power_filter = led_power_filter;
@@ -3423,9 +3455,11 @@ static void alc280_fixup_hp_gpio4(struct hda_codec *codec,
3423 }; 3455 };
3424 3456
3425 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 3457 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3426 spec->gen.vmaster_mute.hook = alc269_fixup_hp_gpio_mute_hook; 3458 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3427 spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook; 3459 spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3428 spec->gpio_led = 0; 3460 spec->gpio_led = 0;
3461 spec->mute_led_polarity = 0;
3462 spec->gpio_mute_led_mask = 0x08;
3429 spec->cap_mute_led_nid = 0x18; 3463 spec->cap_mute_led_nid = 0x18;
3430 snd_hda_add_verbs(codec, gpio_init); 3464 snd_hda_add_verbs(codec, gpio_init);
3431 codec->power_filter = led_power_filter; 3465 codec->power_filter = led_power_filter;
@@ -4300,6 +4334,7 @@ enum {
4300 ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED, 4334 ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED,
4301 ALC282_FIXUP_ASPIRE_V5_PINS, 4335 ALC282_FIXUP_ASPIRE_V5_PINS,
4302 ALC280_FIXUP_HP_GPIO4, 4336 ALC280_FIXUP_HP_GPIO4,
4337 ALC286_FIXUP_HP_GPIO_LED,
4303}; 4338};
4304 4339
4305static const struct hda_fixup alc269_fixups[] = { 4340static const struct hda_fixup alc269_fixups[] = {
@@ -4769,6 +4804,10 @@ static const struct hda_fixup alc269_fixups[] = {
4769 .type = HDA_FIXUP_FUNC, 4804 .type = HDA_FIXUP_FUNC,
4770 .v.func = alc280_fixup_hp_gpio4, 4805 .v.func = alc280_fixup_hp_gpio4,
4771 }, 4806 },
4807 [ALC286_FIXUP_HP_GPIO_LED] = {
4808 .type = HDA_FIXUP_FUNC,
4809 .v.func = alc286_fixup_hp_gpio_led,
4810 },
4772}; 4811};
4773 4812
4774static const struct snd_pci_quirk alc269_fixup_tbl[] = { 4813static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -4809,6 +4848,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4809 SND_PCI_QUIRK(0x103c, 0x226a, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4848 SND_PCI_QUIRK(0x103c, 0x226a, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4810 SND_PCI_QUIRK(0x103c, 0x226b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4849 SND_PCI_QUIRK(0x103c, 0x226b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4811 SND_PCI_QUIRK(0x103c, 0x226e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4850 SND_PCI_QUIRK(0x103c, 0x226e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4851 SND_PCI_QUIRK(0x103c, 0x2271, "HP", ALC286_FIXUP_HP_GPIO_LED),
4812 SND_PCI_QUIRK(0x103c, 0x229e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4852 SND_PCI_QUIRK(0x103c, 0x229e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4813 SND_PCI_QUIRK(0x103c, 0x22b2, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4853 SND_PCI_QUIRK(0x103c, 0x22b2, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4814 SND_PCI_QUIRK(0x103c, 0x22b7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4854 SND_PCI_QUIRK(0x103c, 0x22b7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
@@ -4887,6 +4927,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4887 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK), 4927 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK),
4888 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK), 4928 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK),
4889 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4929 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4930 SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC),
4890 SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP), 4931 SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP),
4891 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4932 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4892 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC), 4933 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC),
@@ -5697,22 +5738,6 @@ static void alc_fixup_bass_chmap(struct hda_codec *codec,
5697 } 5738 }
5698} 5739}
5699 5740
5700/* turn on/off mute LED per vmaster hook */
5701static void alc662_led_gpio1_mute_hook(void *private_data, int enabled)
5702{
5703 struct hda_codec *codec = private_data;
5704 struct alc_spec *spec = codec->spec;
5705 unsigned int oldval = spec->gpio_led;
5706
5707 if (enabled)
5708 spec->gpio_led |= 0x01;
5709 else
5710 spec->gpio_led &= ~0x01;
5711 if (spec->gpio_led != oldval)
5712 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5713 spec->gpio_led);
5714}
5715
5716/* avoid D3 for keeping GPIO up */ 5741/* avoid D3 for keeping GPIO up */
5717static unsigned int gpio_led_power_filter(struct hda_codec *codec, 5742static unsigned int gpio_led_power_filter(struct hda_codec *codec,
5718 hda_nid_t nid, 5743 hda_nid_t nid,
@@ -5735,8 +5760,10 @@ static void alc662_fixup_led_gpio1(struct hda_codec *codec,
5735 }; 5760 };
5736 5761
5737 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 5762 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5738 spec->gen.vmaster_mute.hook = alc662_led_gpio1_mute_hook; 5763 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
5739 spec->gpio_led = 0; 5764 spec->gpio_led = 0;
5765 spec->mute_led_polarity = 1;
5766 spec->gpio_mute_led_mask = 0x01;
5740 snd_hda_add_verbs(codec, gpio_init); 5767 snd_hda_add_verbs(codec, gpio_init);
5741 codec->power_filter = gpio_led_power_filter; 5768 codec->power_filter = gpio_led_power_filter;
5742 } 5769 }
diff --git a/sound/pci/ice1712/aureon.c b/sound/pci/ice1712/aureon.c
index 3b3cf4ac9060..c9411dfff5a4 100644
--- a/sound/pci/ice1712/aureon.c
+++ b/sound/pci/ice1712/aureon.c
@@ -205,13 +205,7 @@ static int aureon_universe_inmux_info(struct snd_kcontrol *kcontrol,
205 static const char * const texts[3] = 205 static const char * const texts[3] =
206 {"Internal Aux", "Wavetable", "Rear Line-In"}; 206 {"Internal Aux", "Wavetable", "Rear Line-In"};
207 207
208 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 208 return snd_ctl_enum_info(uinfo, 1, 3, texts);
209 uinfo->count = 1;
210 uinfo->value.enumerated.items = 3;
211 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
212 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
213 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
214 return 0;
215} 209}
216 210
217static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol, 211static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol,
@@ -1106,20 +1100,10 @@ static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_in
1106 }; 1100 };
1107 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1101 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1108 1102
1109 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1103 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE)
1110 uinfo->count = 2; 1104 return snd_ctl_enum_info(uinfo, 2, 8, universe_texts);
1111 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE) { 1105 else
1112 uinfo->value.enumerated.items = 8; 1106 return snd_ctl_enum_info(uinfo, 2, 5, texts);
1113 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1114 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1115 strcpy(uinfo->value.enumerated.name, universe_texts[uinfo->value.enumerated.item]);
1116 } else {
1117 uinfo->value.enumerated.items = 5;
1118 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1119 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1120 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1121 }
1122 return 0;
1123} 1107}
1124 1108
1125static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1109static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1167,16 +1151,10 @@ static int aureon_cs8415_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
1167 "CD", 1151 "CD",
1168 "Coax" 1152 "Coax"
1169 }; 1153 };
1170 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1171 uinfo->count = 1;
1172 uinfo->value.enumerated.items = 2;
1173 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1174 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1175 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71) 1154 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71)
1176 strcpy(uinfo->value.enumerated.name, prodigy_texts[uinfo->value.enumerated.item]); 1155 return snd_ctl_enum_info(uinfo, 1, 2, prodigy_texts);
1177 else 1156 else
1178 strcpy(uinfo->value.enumerated.name, aureon_texts[uinfo->value.enumerated.item]); 1157 return snd_ctl_enum_info(uinfo, 1, 2, aureon_texts);
1179 return 0;
1180} 1158}
1181 1159
1182static int aureon_cs8415_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1160static int aureon_cs8415_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1392,15 +1370,7 @@ static int aureon_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_
1392{ 1370{
1393 static const char * const texts[2] = { "128x", "64x" }; 1371 static const char * const texts[2] = { "128x", "64x" };
1394 1372
1395 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1373 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1396 uinfo->count = 1;
1397 uinfo->value.enumerated.items = 2;
1398
1399 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1400 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1401 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1402
1403 return 0;
1404} 1374}
1405 1375
1406static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1376static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
index 817a1bc50a60..5cb587cf360e 100644
--- a/sound/pci/ice1712/ews.c
+++ b/sound/pci/ice1712/ews.c
@@ -580,13 +580,7 @@ static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct s
580 static const char * const texts[2] = { 580 static const char * const texts[2] = {
581 "+4dBu", "-10dBV", 581 "+4dBu", "-10dBV",
582 }; 582 };
583 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 583 return snd_ctl_enum_info(uinfo, 1, 2, texts);
584 uinfo->count = 1;
585 uinfo->value.enumerated.items = 2;
586 if (uinfo->value.enumerated.item >= 2)
587 uinfo->value.enumerated.item = 1;
588 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
589 return 0;
590} 584}
591 585
592static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 586static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -903,13 +897,7 @@ static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, st
903 static const char * const texts[4] = { 897 static const char * const texts[4] = {
904 "Internal", "Front Input", "Rear Input", "Wave Table" 898 "Internal", "Front Input", "Rear Input", "Wave Table"
905 }; 899 };
906 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 900 return snd_ctl_enum_info(uinfo, 1, 4, texts);
907 uinfo->count = 1;
908 uinfo->value.enumerated.items = 4;
909 if (uinfo->value.enumerated.item >= 4)
910 uinfo->value.enumerated.item = 1;
911 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
912 return 0;
913} 901}
914 902
915static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 903static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/pci/ice1712/hoontech.c b/sound/pci/ice1712/hoontech.c
index 59e37c581691..a40001c1d9e8 100644
--- a/sound/pci/ice1712/hoontech.c
+++ b/sound/pci/ice1712/hoontech.c
@@ -309,11 +309,7 @@ static int snd_ice1712_value_init(struct snd_ice1712 *ice)
309 return err; 309 return err;
310 310
311 /* ak4524 controls */ 311 /* ak4524 controls */
312 err = snd_ice1712_akm4xxx_build_controls(ice); 312 return snd_ice1712_akm4xxx_build_controls(ice);
313 if (err < 0)
314 return err;
315
316 return 0;
317} 313}
318 314
319static int snd_ice1712_ez8_init(struct snd_ice1712 *ice) 315static int snd_ice1712_ez8_init(struct snd_ice1712 *ice)
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 206ed2cbcef9..b039b46152c6 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -620,10 +620,9 @@ static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
620{ 620{
621 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 621 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
622 struct snd_pcm_runtime *runtime = substream->runtime; 622 struct snd_pcm_runtime *runtime = substream->runtime;
623 u32 period_size, buf_size, rate, tmp, chn; 623 u32 period_size, rate, tmp, chn;
624 624
625 period_size = snd_pcm_lib_period_bytes(substream) - 1; 625 period_size = snd_pcm_lib_period_bytes(substream) - 1;
626 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
627 tmp = 0x0064; 626 tmp = 0x0064;
628 if (snd_pcm_format_width(runtime->format) == 16) 627 if (snd_pcm_format_width(runtime->format) == 16)
629 tmp &= ~0x04; 628 tmp &= ~0x04;
@@ -1295,10 +1294,7 @@ static int snd_ice1712_pcm_profi(struct snd_ice1712 *ice, int device, struct snd
1295 return err; 1294 return err;
1296 } 1295 }
1297 1296
1298 err = snd_ice1712_build_pro_mixer(ice); 1297 return snd_ice1712_build_pro_mixer(ice);
1299 if (err < 0)
1300 return err;
1301 return 0;
1302} 1298}
1303 1299
1304/* 1300/*
@@ -1545,10 +1541,9 @@ static int snd_ice1712_ac97_mixer(struct snd_ice1712 *ice)
1545 dev_warn(ice->card->dev, 1541 dev_warn(ice->card->dev,
1546 "cannot initialize ac97 for consumer, skipped\n"); 1542 "cannot initialize ac97 for consumer, skipped\n");
1547 else { 1543 else {
1548 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice)); 1544 return snd_ctl_add(ice->card,
1549 if (err < 0) 1545 snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97,
1550 return err; 1546 ice));
1551 return 0;
1552 } 1547 }
1553 } 1548 }
1554 1549
@@ -1839,13 +1834,7 @@ static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1839 "96000", /* 12: 7 */ 1834 "96000", /* 12: 7 */
1840 "IEC958 Input", /* 13: -- */ 1835 "IEC958 Input", /* 13: -- */
1841 }; 1836 };
1842 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1837 return snd_ctl_enum_info(uinfo, 1, 14, texts);
1843 uinfo->count = 1;
1844 uinfo->value.enumerated.items = 14;
1845 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1846 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1847 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1848 return 0;
1849} 1838}
1850 1839
1851static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol, 1840static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
@@ -1930,13 +1919,7 @@ static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcon
1930 "96000", /* 12: 7 */ 1919 "96000", /* 12: 7 */
1931 /* "IEC958 Input", 13: -- */ 1920 /* "IEC958 Input", 13: -- */
1932 }; 1921 };
1933 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1922 return snd_ctl_enum_info(uinfo, 1, 13, texts);
1934 uinfo->count = 1;
1935 uinfo->value.enumerated.items = 13;
1936 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1937 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1938 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1939 return 0;
1940} 1923}
1941 1924
1942static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol, 1925static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
@@ -2057,15 +2040,8 @@ static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2057 "IEC958 In L", "IEC958 In R", /* 9-10 */ 2040 "IEC958 In L", "IEC958 In R", /* 9-10 */
2058 "Digital Mixer", /* 11 - optional */ 2041 "Digital Mixer", /* 11 - optional */
2059 }; 2042 };
2060 2043 int num_items = snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2061 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2044 return snd_ctl_enum_info(uinfo, 1, num_items, texts);
2062 uinfo->count = 1;
2063 uinfo->value.enumerated.items =
2064 snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2065 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2066 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2067 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2068 return 0;
2069} 2045}
2070 2046
2071static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol, 2047static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
@@ -2516,11 +2492,8 @@ static int snd_ice1712_build_controls(struct snd_ice1712 *ice)
2516 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice)); 2492 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2517 if (err < 0) 2493 if (err < 0)
2518 return err; 2494 return err;
2519 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice)); 2495 return snd_ctl_add(ice->card,
2520 if (err < 0) 2496 snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2521 return err;
2522
2523 return 0;
2524} 2497}
2525 2498
2526static int snd_ice1712_free(struct snd_ice1712 *ice) 2499static int snd_ice1712_free(struct snd_ice1712 *ice)
@@ -2905,8 +2878,7 @@ static int snd_ice1712_resume(struct device *dev)
2905 outw(ice->pm_saved_spdif_ctrl, ICEMT(ice, ROUTE_SPDOUT)); 2878 outw(ice->pm_saved_spdif_ctrl, ICEMT(ice, ROUTE_SPDOUT));
2906 outw(ice->pm_saved_route, ICEMT(ice, ROUTE_PSDOUT03)); 2879 outw(ice->pm_saved_route, ICEMT(ice, ROUTE_PSDOUT03));
2907 2880
2908 if (ice->ac97) 2881 snd_ac97_resume(ice->ac97);
2909 snd_ac97_resume(ice->ac97);
2910 2882
2911 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 2883 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2912 return 0; 2884 return 0;
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 08cb08ac85e6..d73da157ea14 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -2049,13 +2049,7 @@ static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
2049 "IEC958 In L", "IEC958 In R", /* 3-4 */ 2049 "IEC958 In L", "IEC958 In R", /* 3-4 */
2050 }; 2050 };
2051 2051
2052 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2052 return snd_ctl_enum_info(uinfo, 1, 5, texts);
2053 uinfo->count = 1;
2054 uinfo->value.enumerated.items = 5;
2055 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2056 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2057 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2058 return 0;
2059} 2053}
2060 2054
2061static inline int analog_route_shift(int idx) 2055static inline int analog_route_shift(int idx)
@@ -2503,11 +2497,8 @@ static int snd_vt1724_build_controls(struct snd_ice1712 *ice)
2503 return err; 2497 return err;
2504 } 2498 }
2505 2499
2506 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice)); 2500 return snd_ctl_add(ice->card,
2507 if (err < 0) 2501 snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2508 return err;
2509
2510 return 0;
2511} 2502}
2512 2503
2513static int snd_vt1724_free(struct snd_ice1712 *ice) 2504static int snd_vt1724_free(struct snd_ice1712 *ice)
@@ -2884,8 +2875,7 @@ static int snd_vt1724_resume(struct device *dev)
2884 outb(ice->pm_saved_spdif_cfg, ICEREG1724(ice, SPDIF_CFG)); 2875 outb(ice->pm_saved_spdif_cfg, ICEREG1724(ice, SPDIF_CFG));
2885 outl(ice->pm_saved_route, ICEMT1724(ice, ROUTE_PLAYBACK)); 2876 outl(ice->pm_saved_route, ICEMT1724(ice, ROUTE_PLAYBACK));
2886 2877
2887 if (ice->ac97) 2878 snd_ac97_resume(ice->ac97);
2888 snd_ac97_resume(ice->ac97);
2889 2879
2890 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 2880 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2891 return 0; 2881 return 0;
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index 7a6c0786c55c..a1536c1a7ed4 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -475,11 +475,8 @@ static int juli_add_controls(struct snd_ice1712 *ice)
475 return err; 475 return err;
476 476
477 /* only capture SPDIF over AK4114 */ 477 /* only capture SPDIF over AK4114 */
478 err = snd_ak4114_build(spec->ak4114, NULL, 478 return snd_ak4114_build(spec->ak4114, NULL,
479 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 479 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
480 if (err < 0)
481 return err;
482 return 0;
483} 480}
484 481
485/* 482/*
diff --git a/sound/pci/ice1712/maya44.c b/sound/pci/ice1712/maya44.c
index 63aa39f06f02..7de25c4807fd 100644
--- a/sound/pci/ice1712/maya44.c
+++ b/sound/pci/ice1712/maya44.c
@@ -359,15 +359,7 @@ static int maya_rec_src_info(struct snd_kcontrol *kcontrol,
359{ 359{
360 static const char * const texts[] = { "Line", "Mic" }; 360 static const char * const texts[] = { "Line", "Mic" };
361 361
362 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 362 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
363 uinfo->count = 1;
364 uinfo->value.enumerated.items = ARRAY_SIZE(texts);
365 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
366 uinfo->value.enumerated.item =
367 uinfo->value.enumerated.items - 1;
368 strcpy(uinfo->value.enumerated.name,
369 texts[uinfo->value.enumerated.item]);
370 return 0;
371} 363}
372 364
373static int maya_rec_src_get(struct snd_kcontrol *kcontrol, 365static int maya_rec_src_get(struct snd_kcontrol *kcontrol,
@@ -411,15 +403,7 @@ static int maya_pb_route_info(struct snd_kcontrol *kcontrol,
411 "Input 1", "Input 2", "Input 3", "Input 4" 403 "Input 1", "Input 2", "Input 3", "Input 4"
412 }; 404 };
413 405
414 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 406 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
415 uinfo->count = 1;
416 uinfo->value.enumerated.items = ARRAY_SIZE(texts);
417 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
418 uinfo->value.enumerated.item =
419 uinfo->value.enumerated.items - 1;
420 strcpy(uinfo->value.enumerated.name,
421 texts[uinfo->value.enumerated.item]);
422 return 0;
423} 407}
424 408
425static int maya_pb_route_shift(int idx) 409static int maya_pb_route_shift(int idx)
diff --git a/sound/pci/ice1712/phase.c b/sound/pci/ice1712/phase.c
index 0011e04f36a2..e9ca89c9174b 100644
--- a/sound/pci/ice1712/phase.c
+++ b/sound/pci/ice1712/phase.c
@@ -723,17 +723,7 @@ static int phase28_oversampling_info(struct snd_kcontrol *k,
723{ 723{
724 static const char * const texts[2] = { "128x", "64x" }; 724 static const char * const texts[2] = { "128x", "64x" };
725 725
726 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 726 return snd_ctl_enum_info(uinfo, 1, 2, texts);
727 uinfo->count = 1;
728 uinfo->value.enumerated.items = 2;
729
730 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
731 uinfo->value.enumerated.item = uinfo->value.enumerated.items -
732 1;
733 strcpy(uinfo->value.enumerated.name,
734 texts[uinfo->value.enumerated.item]);
735
736 return 0;
737} 727}
738 728
739static int phase28_oversampling_get(struct snd_kcontrol *kcontrol, 729static int phase28_oversampling_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/ice1712/pontis.c b/sound/pci/ice1712/pontis.c
index 5555eb4b2400..5101f40f6fbd 100644
--- a/sound/pci/ice1712/pontis.c
+++ b/sound/pci/ice1712/pontis.c
@@ -417,13 +417,7 @@ static int cs_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_inf
417 "Optical", /* RXP1 */ 417 "Optical", /* RXP1 */
418 "CD", /* RXP2 */ 418 "CD", /* RXP2 */
419 }; 419 };
420 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 420 return snd_ctl_enum_info(uinfo, 1, 3, texts);
421 uinfo->count = 1;
422 uinfo->value.enumerated.items = 3;
423 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
424 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
425 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
426 return 0;
427} 421}
428 422
429static int cs_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 423static int cs_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/pci/ice1712/prodigy192.c b/sound/pci/ice1712/prodigy192.c
index f3b491aa3e22..3919aed39ca0 100644
--- a/sound/pci/ice1712/prodigy192.c
+++ b/sound/pci/ice1712/prodigy192.c
@@ -284,15 +284,7 @@ static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
284{ 284{
285 static const char * const texts[2] = { "Line In", "Mic" }; 285 static const char * const texts[2] = { "Line In", "Mic" };
286 286
287 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 287 return snd_ctl_enum_info(uinfo, 1, 2, texts);
288 uinfo->count = 1;
289 uinfo->value.enumerated.items = 2;
290
291 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
292 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
293 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
294
295 return 0;
296} 288}
297 289
298 290
@@ -563,13 +555,7 @@ static int ak4114_input_sw_info(struct snd_kcontrol *kcontrol,
563{ 555{
564 static const char * const texts[2] = { "Toslink", "Coax" }; 556 static const char * const texts[2] = { "Toslink", "Coax" };
565 557
566 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 558 return snd_ctl_enum_info(uinfo, 1, 2, texts);
567 uinfo->count = 1;
568 uinfo->value.enumerated.items = 2;
569 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
570 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
571 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
572 return 0;
573} 559}
574 560
575 561
@@ -772,10 +758,8 @@ static int prodigy192_init(struct snd_ice1712 *ice)
772 "AK4114 initialized with status %d\n", err); 758 "AK4114 initialized with status %d\n", err);
773 } else 759 } else
774 dev_dbg(ice->card->dev, "AK4114 not found\n"); 760 dev_dbg(ice->card->dev, "AK4114 not found\n");
775 if (err < 0)
776 return err;
777 761
778 return 0; 762 return err;
779} 763}
780 764
781 765
diff --git a/sound/pci/ice1712/prodigy_hifi.c b/sound/pci/ice1712/prodigy_hifi.c
index 2261d1e49150..2697402b5195 100644
--- a/sound/pci/ice1712/prodigy_hifi.c
+++ b/sound/pci/ice1712/prodigy_hifi.c
@@ -537,7 +537,7 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol,
537static int wm_adc_mux_enum_info(struct snd_kcontrol *kcontrol, 537static int wm_adc_mux_enum_info(struct snd_kcontrol *kcontrol,
538 struct snd_ctl_elem_info *uinfo) 538 struct snd_ctl_elem_info *uinfo)
539{ 539{
540 static char* texts[32] = { 540 static const char * const texts[32] = {
541 "NULL", WM_AIN1, WM_AIN2, WM_AIN1 "+" WM_AIN2, 541 "NULL", WM_AIN1, WM_AIN2, WM_AIN1 "+" WM_AIN2,
542 WM_AIN3, WM_AIN1 "+" WM_AIN3, WM_AIN2 "+" WM_AIN3, 542 WM_AIN3, WM_AIN1 "+" WM_AIN3, WM_AIN2 "+" WM_AIN3,
543 WM_AIN1 "+" WM_AIN2 "+" WM_AIN3, 543 WM_AIN1 "+" WM_AIN2 "+" WM_AIN3,
@@ -560,14 +560,7 @@ static int wm_adc_mux_enum_info(struct snd_kcontrol *kcontrol,
560 WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5 560 WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5
561 }; 561 };
562 562
563 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 563 return snd_ctl_enum_info(uinfo, 1, 32, texts);
564 uinfo->count = 1;
565 uinfo->value.enumerated.items = 32;
566 if (uinfo->value.enumerated.item > 31)
567 uinfo->value.enumerated.item = 31;
568 strcpy(uinfo->value.enumerated.name,
569 texts[uinfo->value.enumerated.item]);
570 return 0;
571} 564}
572 565
573static int wm_adc_mux_enum_get(struct snd_kcontrol *kcontrol, 566static int wm_adc_mux_enum_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/ice1712/quartet.c b/sound/pci/ice1712/quartet.c
index 2c2df4b74e01..6f55e02e5c84 100644
--- a/sound/pci/ice1712/quartet.c
+++ b/sound/pci/ice1712/quartet.c
@@ -46,7 +46,7 @@ struct qtet_kcontrol_private {
46 unsigned int bit; 46 unsigned int bit;
47 void (*set_register)(struct snd_ice1712 *ice, unsigned int val); 47 void (*set_register)(struct snd_ice1712 *ice, unsigned int val);
48 unsigned int (*get_register)(struct snd_ice1712 *ice); 48 unsigned int (*get_register)(struct snd_ice1712 *ice);
49 unsigned char * const texts[2]; 49 const char * const texts[2];
50}; 50};
51 51
52enum { 52enum {
@@ -554,17 +554,7 @@ static int qtet_ain12_enum_info(struct snd_kcontrol *kcontrol,
554{ 554{
555 static const char * const texts[3] = 555 static const char * const texts[3] =
556 {"Line In 1/2", "Mic", "Mic + Low-cut"}; 556 {"Line In 1/2", "Mic", "Mic + Low-cut"};
557 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 557 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
558 uinfo->count = 1;
559 uinfo->value.enumerated.items = ARRAY_SIZE(texts);
560
561 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
562 uinfo->value.enumerated.item =
563 uinfo->value.enumerated.items - 1;
564 strcpy(uinfo->value.enumerated.name,
565 texts[uinfo->value.enumerated.item]);
566
567 return 0;
568} 558}
569 559
570static int qtet_ain12_sw_get(struct snd_kcontrol *kcontrol, 560static int qtet_ain12_sw_get(struct snd_kcontrol *kcontrol,
@@ -706,17 +696,8 @@ static int qtet_enum_info(struct snd_kcontrol *kcontrol,
706{ 696{
707 struct qtet_kcontrol_private private = 697 struct qtet_kcontrol_private private =
708 qtet_privates[kcontrol->private_value]; 698 qtet_privates[kcontrol->private_value];
709 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 699 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(private.texts),
710 uinfo->count = 1; 700 private.texts);
711 uinfo->value.enumerated.items = ARRAY_SIZE(private.texts);
712
713 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
714 uinfo->value.enumerated.item =
715 uinfo->value.enumerated.items - 1;
716 strcpy(uinfo->value.enumerated.name,
717 private.texts[uinfo->value.enumerated.item]);
718
719 return 0;
720} 701}
721 702
722static int qtet_sw_get(struct snd_kcontrol *kcontrol, 703static int qtet_sw_get(struct snd_kcontrol *kcontrol,
@@ -852,11 +833,8 @@ static int qtet_add_controls(struct snd_ice1712 *ice)
852 if (err < 0) 833 if (err < 0)
853 return err; 834 return err;
854 /* only capture SPDIF over AK4113 */ 835 /* only capture SPDIF over AK4113 */
855 err = snd_ak4113_build(spec->ak4113, 836 return snd_ak4113_build(spec->ak4113,
856 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 837 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
857 if (err < 0)
858 return err;
859 return 0;
860} 838}
861 839
862static inline int qtet_is_spdif_master(struct snd_ice1712 *ice) 840static inline int qtet_is_spdif_master(struct snd_ice1712 *ice)
diff --git a/sound/pci/ice1712/revo.c b/sound/pci/ice1712/revo.c
index 1112ec1953be..1d81ae677573 100644
--- a/sound/pci/ice1712/revo.c
+++ b/sound/pci/ice1712/revo.c
@@ -494,11 +494,13 @@ static int ap192_ak4114_init(struct snd_ice1712 *ice)
494 ap192_ak4114_write, 494 ap192_ak4114_write,
495 ak4114_init_vals, ak4114_init_txcsb, 495 ak4114_init_vals, ak4114_init_txcsb,
496 ice, &spec->ak4114); 496 ice, &spec->ak4114);
497 if (err < 0)
498 return err;
497 /* AK4114 in Revo cannot detect external rate correctly. 499 /* AK4114 in Revo cannot detect external rate correctly.
498 * No reason to stop capture stream due to incorrect checks */ 500 * No reason to stop capture stream due to incorrect checks */
499 spec->ak4114->check_flags = AK4114_CHECK_NO_RATE; 501 spec->ak4114->check_flags = AK4114_CHECK_NO_RATE;
500 502
501 return 0; /* error ignored; it's no fatal error */ 503 return 0;
502} 504}
503 505
504static int revo_init(struct snd_ice1712 *ice) 506static int revo_init(struct snd_ice1712 *ice)
diff --git a/sound/pci/ice1712/se.c b/sound/pci/ice1712/se.c
index ffd894bb4507..1c5d5b22c7a0 100644
--- a/sound/pci/ice1712/se.c
+++ b/sound/pci/ice1712/se.c
@@ -452,14 +452,7 @@ static int se200pci_cont_enum_info(struct snd_kcontrol *kc,
452 c = se200pci_get_enum_count(n); 452 c = se200pci_get_enum_count(n);
453 if (!c) 453 if (!c)
454 return -EINVAL; 454 return -EINVAL;
455 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 455 return snd_ctl_enum_info(uinfo, 1, c, se200pci_cont[n].member);
456 uinfo->count = 1;
457 uinfo->value.enumerated.items = c;
458 if (uinfo->value.enumerated.item >= c)
459 uinfo->value.enumerated.item = c - 1;
460 strcpy(uinfo->value.enumerated.name,
461 se200pci_cont[n].member[uinfo->value.enumerated.item]);
462 return 0;
463} 456}
464 457
465static int se200pci_cont_volume_get(struct snd_kcontrol *kc, 458static int se200pci_cont_volume_get(struct snd_kcontrol *kc,
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 9fe549b2efdf..59d21c9401d2 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -444,9 +444,9 @@ static char *stateName[] = {
444 "Invalid" 444 "Invalid"
445}; 445};
446 446
447static char *clockSourceTypeName[] = { "ADAT", "S/PDIF", "local" }; 447static const char * const clockSourceTypeName[] = { "ADAT", "S/PDIF", "local" };
448 448
449static char *clockSourceName[] = { 449static const char * const clockSourceName[] = {
450 "ADAT at 44.1 kHz", 450 "ADAT at 44.1 kHz",
451 "ADAT at 48 kHz", 451 "ADAT at 48 kHz",
452 "S/PDIF at 44.1 kHz", 452 "S/PDIF at 44.1 kHz",
@@ -455,7 +455,7 @@ static char *clockSourceName[] = {
455 "local clock at 48 kHz" 455 "local clock at 48 kHz"
456}; 456};
457 457
458static char *channelName[] = { 458static const char * const channelName[] = {
459 "ADAT-1", 459 "ADAT-1",
460 "ADAT-2", 460 "ADAT-2",
461 "ADAT-3", 461 "ADAT-3",
@@ -1844,14 +1844,9 @@ static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol,
1844static int snd_korg1212_control_route_info(struct snd_kcontrol *kcontrol, 1844static int snd_korg1212_control_route_info(struct snd_kcontrol *kcontrol,
1845 struct snd_ctl_elem_info *uinfo) 1845 struct snd_ctl_elem_info *uinfo)
1846{ 1846{
1847 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1847 return snd_ctl_enum_info(uinfo,
1848 uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; 1848 (kcontrol->private_value >= 8) ? 2 : 1,
1849 uinfo->value.enumerated.items = kAudioChannels; 1849 kAudioChannels, channelName);
1850 if (uinfo->value.enumerated.item > kAudioChannels-1) {
1851 uinfo->value.enumerated.item = kAudioChannels-1;
1852 }
1853 strcpy(uinfo->value.enumerated.name, channelName[uinfo->value.enumerated.item]);
1854 return 0;
1855} 1850}
1856 1851
1857static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol, 1852static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol,
@@ -1961,14 +1956,7 @@ static int snd_korg1212_control_put(struct snd_kcontrol *kcontrol,
1961static int snd_korg1212_control_sync_info(struct snd_kcontrol *kcontrol, 1956static int snd_korg1212_control_sync_info(struct snd_kcontrol *kcontrol,
1962 struct snd_ctl_elem_info *uinfo) 1957 struct snd_ctl_elem_info *uinfo)
1963{ 1958{
1964 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1959 return snd_ctl_enum_info(uinfo, 1, 3, clockSourceTypeName);
1965 uinfo->count = 1;
1966 uinfo->value.enumerated.items = 3;
1967 if (uinfo->value.enumerated.item > 2) {
1968 uinfo->value.enumerated.item = 2;
1969 }
1970 strcpy(uinfo->value.enumerated.name, clockSourceTypeName[uinfo->value.enumerated.item]);
1971 return 0;
1972} 1960}
1973 1961
1974static int snd_korg1212_control_sync_get(struct snd_kcontrol *kcontrol, 1962static int snd_korg1212_control_sync_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/lola/lola.c b/sound/pci/lola/lola.c
index a75c8dc66dec..4cf4be5ef82a 100644
--- a/sound/pci/lola/lola.c
+++ b/sound/pci/lola/lola.c
@@ -719,7 +719,7 @@ static int lola_probe(struct pci_dev *pci,
719 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 719 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
720 0, &card); 720 0, &card);
721 if (err < 0) { 721 if (err < 0) {
722 dev_err(card->dev, "Error creating card!\n"); 722 dev_err(&pci->dev, "Error creating card!\n");
723 return err; 723 return err;
724 } 724 }
725 725
diff --git a/sound/pci/lola/lola_mixer.c b/sound/pci/lola/lola_mixer.c
index 782f4d8299ae..e7fe15dd5a90 100644
--- a/sound/pci/lola/lola_mixer.c
+++ b/sound/pci/lola/lola_mixer.c
@@ -108,8 +108,7 @@ int lola_init_pins(struct lola *chip, int dir, int *nidp)
108 108
109void lola_free_mixer(struct lola *chip) 109void lola_free_mixer(struct lola *chip)
110{ 110{
111 if (chip->mixer.array_saved) 111 vfree(chip->mixer.array_saved);
112 vfree(chip->mixer.array_saved);
113} 112}
114 113
115int lola_init_mixer_widget(struct lola *chip, int nid) 114int lola_init_mixer_widget(struct lola *chip, int nid)
diff --git a/sound/pci/lx6464es/lx_defs.h b/sound/pci/lx6464es/lx_defs.h
index 49d36bdd512c..469bcc685edf 100644
--- a/sound/pci/lx6464es/lx_defs.h
+++ b/sound/pci/lx6464es/lx_defs.h
@@ -175,7 +175,7 @@ enum buffer_flags {
175 BF_ZERO = 0x00, /* no flags (init).*/ 175 BF_ZERO = 0x00, /* no flags (init).*/
176}; 176};
177 177
178/** 178/*
179* Stream Flags definitions 179* Stream Flags definitions
180*/ 180*/
181enum stream_flags { 181enum stream_flags {
diff --git a/sound/pci/mixart/mixart_hwdep.c b/sound/pci/mixart/mixart_hwdep.c
index 581e1e74863c..9996a4dead0f 100644
--- a/sound/pci/mixart/mixart_hwdep.c
+++ b/sound/pci/mixart/mixart_hwdep.c
@@ -37,10 +37,11 @@
37/** 37/**
38 * wait for a value on a peudo register, exit with a timeout 38 * wait for a value on a peudo register, exit with a timeout
39 * 39 *
40 * @param mgr pointer to miXart manager structure 40 * @mgr: pointer to miXart manager structure
41 * @param offset unsigned pseudo_register base + offset of value 41 * @offset: unsigned pseudo_register base + offset of value
42 * @param value value 42 * @is_egal: wait for the equal value
43 * @param timeout timeout in centisenconds 43 * @value: value
44 * @timeout: timeout in centisenconds
44 */ 45 */
45static int mixart_wait_nice_for_register_value(struct mixart_mgr *mgr, 46static int mixart_wait_nice_for_register_value(struct mixart_mgr *mgr,
46 u32 offset, int is_egal, 47 u32 offset, int is_egal,
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index b854fc5e01f5..c6092e48ceb6 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -501,10 +501,10 @@ int pcxhr_get_external_clock(struct pcxhr_mgr *mgr,
501/* 501/*
502 * start or stop playback/capture substream 502 * start or stop playback/capture substream
503 */ 503 */
504static int pcxhr_set_stream_state(struct pcxhr_stream *stream) 504static int pcxhr_set_stream_state(struct snd_pcxhr *chip,
505 struct pcxhr_stream *stream)
505{ 506{
506 int err; 507 int err;
507 struct snd_pcxhr *chip;
508 struct pcxhr_rmh rmh; 508 struct pcxhr_rmh rmh;
509 int stream_mask, start; 509 int stream_mask, start;
510 510
@@ -512,8 +512,8 @@ static int pcxhr_set_stream_state(struct pcxhr_stream *stream)
512 start = 1; 512 start = 1;
513 else { 513 else {
514 if (stream->status != PCXHR_STREAM_STATUS_SCHEDULE_STOP) { 514 if (stream->status != PCXHR_STREAM_STATUS_SCHEDULE_STOP) {
515 snd_printk(KERN_ERR "ERROR pcxhr_set_stream_state " 515 dev_err(chip->card->dev,
516 "CANNOT be stopped\n"); 516 "pcxhr_set_stream_state CANNOT be stopped\n");
517 return -EINVAL; 517 return -EINVAL;
518 } 518 }
519 start = 0; 519 start = 0;
@@ -560,6 +560,7 @@ static int pcxhr_set_format(struct pcxhr_stream *stream)
560 struct pcxhr_rmh rmh; 560 struct pcxhr_rmh rmh;
561 unsigned int header; 561 unsigned int header;
562 562
563 chip = snd_pcm_substream_chip(stream->substream);
563 switch (stream->format) { 564 switch (stream->format) {
564 case SNDRV_PCM_FORMAT_U8: 565 case SNDRV_PCM_FORMAT_U8:
565 header = HEADER_FMT_BASE_LIN; 566 header = HEADER_FMT_BASE_LIN;
@@ -582,11 +583,10 @@ static int pcxhr_set_format(struct pcxhr_stream *stream)
582 header = HEADER_FMT_BASE_FLOAT | HEADER_FMT_INTEL; 583 header = HEADER_FMT_BASE_FLOAT | HEADER_FMT_INTEL;
583 break; 584 break;
584 default: 585 default:
585 snd_printk(KERN_ERR 586 dev_err(chip->card->dev,
586 "error pcxhr_set_format() : unknown format\n"); 587 "error pcxhr_set_format() : unknown format\n");
587 return -EINVAL; 588 return -EINVAL;
588 } 589 }
589 chip = snd_pcm_substream_chip(stream->substream);
590 590
591 sample_rate = chip->mgr->sample_rate; 591 sample_rate = chip->mgr->sample_rate;
592 if (sample_rate <= 32000 && sample_rate !=0) { 592 if (sample_rate <= 32000 && sample_rate !=0) {
@@ -643,11 +643,11 @@ static int pcxhr_update_r_buffer(struct pcxhr_stream *stream)
643 is_capture = (subs->stream == SNDRV_PCM_STREAM_CAPTURE); 643 is_capture = (subs->stream == SNDRV_PCM_STREAM_CAPTURE);
644 stream_num = is_capture ? 0 : subs->number; 644 stream_num = is_capture ? 0 : subs->number;
645 645
646 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : " 646 dev_dbg(chip->card->dev,
647 "addr(%p) bytes(%zx) subs(%d)\n", 647 "pcxhr_update_r_buffer(pcm%c%d) : addr(%p) bytes(%zx) subs(%d)\n",
648 is_capture ? 'c' : 'p', 648 is_capture ? 'c' : 'p',
649 chip->chip_idx, (void *)(long)subs->runtime->dma_addr, 649 chip->chip_idx, (void *)(long)subs->runtime->dma_addr,
650 subs->runtime->dma_bytes, subs->number); 650 subs->runtime->dma_bytes, subs->number);
651 651
652 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS); 652 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS);
653 pcxhr_set_pipe_cmd_params(&rmh, is_capture, stream->pipe->first_audio, 653 pcxhr_set_pipe_cmd_params(&rmh, is_capture, stream->pipe->first_audio,
@@ -687,7 +687,7 @@ static int pcxhr_pipe_sample_count(struct pcxhr_stream *stream,
687 *sample_count = ((snd_pcm_uframes_t)rmh.stat[0]) << 24; 687 *sample_count = ((snd_pcm_uframes_t)rmh.stat[0]) << 24;
688 *sample_count += (snd_pcm_uframes_t)rmh.stat[1]; 688 *sample_count += (snd_pcm_uframes_t)rmh.stat[1];
689 } 689 }
690 snd_printdd("PIPE_SAMPLE_COUNT = %lx\n", *sample_count); 690 dev_dbg(chip->card->dev, "PIPE_SAMPLE_COUNT = %lx\n", *sample_count);
691 return err; 691 return err;
692} 692}
693#endif 693#endif
@@ -711,8 +711,9 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr)
711 int playback_mask = 0; 711 int playback_mask = 0;
712 712
713#ifdef CONFIG_SND_DEBUG_VERBOSE 713#ifdef CONFIG_SND_DEBUG_VERBOSE
714 struct timeval my_tv1, my_tv2; 714 ktime_t start_time, stop_time, diff_time;
715 do_gettimeofday(&my_tv1); 715
716 start_time = ktime_get();
716#endif 717#endif
717 mutex_lock(&mgr->setup_mutex); 718 mutex_lock(&mgr->setup_mutex);
718 719
@@ -778,12 +779,12 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr)
778 for (j = 0; j < chip->nb_streams_capt; j++) { 779 for (j = 0; j < chip->nb_streams_capt; j++) {
779 stream = &chip->capture_stream[j]; 780 stream = &chip->capture_stream[j];
780 if (pcxhr_stream_scheduled_get_pipe(stream, &pipe)) 781 if (pcxhr_stream_scheduled_get_pipe(stream, &pipe))
781 err = pcxhr_set_stream_state(stream); 782 err = pcxhr_set_stream_state(chip, stream);
782 } 783 }
783 for (j = 0; j < chip->nb_streams_play; j++) { 784 for (j = 0; j < chip->nb_streams_play; j++) {
784 stream = &chip->playback_stream[j]; 785 stream = &chip->playback_stream[j];
785 if (pcxhr_stream_scheduled_get_pipe(stream, &pipe)) 786 if (pcxhr_stream_scheduled_get_pipe(stream, &pipe))
786 err = pcxhr_set_stream_state(stream); 787 err = pcxhr_set_stream_state(chip, stream);
787 } 788 }
788 } 789 }
789 790
@@ -823,9 +824,10 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr)
823 mutex_unlock(&mgr->setup_mutex); 824 mutex_unlock(&mgr->setup_mutex);
824 825
825#ifdef CONFIG_SND_DEBUG_VERBOSE 826#ifdef CONFIG_SND_DEBUG_VERBOSE
826 do_gettimeofday(&my_tv2); 827 stop_time = ktime_get();
828 diff_time = ktime_sub(stop_time, start_time);
827 dev_dbg(&mgr->pci->dev, "***TRIGGER START*** TIME = %ld (err = %x)\n", 829 dev_dbg(&mgr->pci->dev, "***TRIGGER START*** TIME = %ld (err = %x)\n",
828 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err); 830 (long)(ktime_to_ns(diff_time)), err);
829#endif 831#endif
830} 832}
831 833
@@ -837,12 +839,12 @@ static int pcxhr_trigger(struct snd_pcm_substream *subs, int cmd)
837{ 839{
838 struct pcxhr_stream *stream; 840 struct pcxhr_stream *stream;
839 struct snd_pcm_substream *s; 841 struct snd_pcm_substream *s;
842 struct snd_pcxhr *chip = snd_pcm_substream_chip(subs);
840 843
841 switch (cmd) { 844 switch (cmd) {
842 case SNDRV_PCM_TRIGGER_START: 845 case SNDRV_PCM_TRIGGER_START:
843 snd_printdd("SNDRV_PCM_TRIGGER_START\n"); 846 dev_dbg(chip->card->dev, "SNDRV_PCM_TRIGGER_START\n");
844 if (snd_pcm_stream_linked(subs)) { 847 if (snd_pcm_stream_linked(subs)) {
845 struct snd_pcxhr *chip = snd_pcm_substream_chip(subs);
846 snd_pcm_group_for_each_entry(s, subs) { 848 snd_pcm_group_for_each_entry(s, subs) {
847 if (snd_pcm_substream_chip(s) != chip) 849 if (snd_pcm_substream_chip(s) != chip)
848 continue; 850 continue;
@@ -854,7 +856,7 @@ static int pcxhr_trigger(struct snd_pcm_substream *subs, int cmd)
854 pcxhr_start_linked_stream(chip->mgr); 856 pcxhr_start_linked_stream(chip->mgr);
855 } else { 857 } else {
856 stream = subs->runtime->private_data; 858 stream = subs->runtime->private_data;
857 snd_printdd("Only one Substream %c %d\n", 859 dev_dbg(chip->card->dev, "Only one Substream %c %d\n",
858 stream->pipe->is_capture ? 'C' : 'P', 860 stream->pipe->is_capture ? 'C' : 'P',
859 stream->pipe->first_audio); 861 stream->pipe->first_audio);
860 if (pcxhr_set_format(stream)) 862 if (pcxhr_set_format(stream))
@@ -863,17 +865,17 @@ static int pcxhr_trigger(struct snd_pcm_substream *subs, int cmd)
863 return -EINVAL; 865 return -EINVAL;
864 866
865 stream->status = PCXHR_STREAM_STATUS_SCHEDULE_RUN; 867 stream->status = PCXHR_STREAM_STATUS_SCHEDULE_RUN;
866 if (pcxhr_set_stream_state(stream)) 868 if (pcxhr_set_stream_state(chip, stream))
867 return -EINVAL; 869 return -EINVAL;
868 stream->status = PCXHR_STREAM_STATUS_RUNNING; 870 stream->status = PCXHR_STREAM_STATUS_RUNNING;
869 } 871 }
870 break; 872 break;
871 case SNDRV_PCM_TRIGGER_STOP: 873 case SNDRV_PCM_TRIGGER_STOP:
872 snd_printdd("SNDRV_PCM_TRIGGER_STOP\n"); 874 dev_dbg(chip->card->dev, "SNDRV_PCM_TRIGGER_STOP\n");
873 snd_pcm_group_for_each_entry(s, subs) { 875 snd_pcm_group_for_each_entry(s, subs) {
874 stream = s->runtime->private_data; 876 stream = s->runtime->private_data;
875 stream->status = PCXHR_STREAM_STATUS_SCHEDULE_STOP; 877 stream->status = PCXHR_STREAM_STATUS_SCHEDULE_STOP;
876 if (pcxhr_set_stream_state(stream)) 878 if (pcxhr_set_stream_state(chip, stream))
877 return -EINVAL; 879 return -EINVAL;
878 snd_pcm_trigger_done(s, subs); 880 snd_pcm_trigger_done(s, subs);
879 } 881 }
@@ -1636,7 +1638,7 @@ static int pcxhr_probe(struct pci_dev *pci,
1636 0, &card); 1638 0, &card);
1637 1639
1638 if (err < 0) { 1640 if (err < 0) {
1639 dev_err(card->dev, "cannot allocate the card %d\n", i); 1641 dev_err(&pci->dev, "cannot allocate the card %d\n", i);
1640 pcxhr_free(mgr); 1642 pcxhr_free(mgr);
1641 return err; 1643 return err;
1642 } 1644 }
diff --git a/sound/pci/pcxhr/pcxhr_core.c b/sound/pci/pcxhr/pcxhr_core.c
index a584acb61c00..181f7729d409 100644
--- a/sound/pci/pcxhr/pcxhr_core.c
+++ b/sound/pci/pcxhr/pcxhr_core.c
@@ -910,8 +910,9 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask,
910 int audio_mask; 910 int audio_mask;
911 911
912#ifdef CONFIG_SND_DEBUG_VERBOSE 912#ifdef CONFIG_SND_DEBUG_VERBOSE
913 struct timeval my_tv1, my_tv2; 913 ktime_t start_time, stop_time, diff_time;
914 do_gettimeofday(&my_tv1); 914
915 start_time = ktime_get();
915#endif 916#endif
916 audio_mask = (playback_mask | 917 audio_mask = (playback_mask |
917 (capture_mask << PCXHR_PIPE_STATE_CAPTURE_OFFSET)); 918 (capture_mask << PCXHR_PIPE_STATE_CAPTURE_OFFSET));
@@ -960,9 +961,10 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask,
960 return err; 961 return err;
961 } 962 }
962#ifdef CONFIG_SND_DEBUG_VERBOSE 963#ifdef CONFIG_SND_DEBUG_VERBOSE
963 do_gettimeofday(&my_tv2); 964 stop_time = ktime_get();
965 diff_time = ktime_sub(stop_time, start_time);
964 dev_dbg(&mgr->pci->dev, "***SET PIPE STATE*** TIME = %ld (err = %x)\n", 966 dev_dbg(&mgr->pci->dev, "***SET PIPE STATE*** TIME = %ld (err = %x)\n",
965 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err); 967 (long)(ktime_to_ns(diff_time)), err);
966#endif 968#endif
967 return 0; 969 return 0;
968} 970}
diff --git a/sound/pci/pcxhr/pcxhr_mixer.c b/sound/pci/pcxhr/pcxhr_mixer.c
index 95c9571780d8..63136c4f3f3d 100644
--- a/sound/pci/pcxhr/pcxhr_mixer.c
+++ b/sound/pci/pcxhr/pcxhr_mixer.c
@@ -660,14 +660,7 @@ static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol,
660 if (chip->mgr->board_has_mic) 660 if (chip->mgr->board_has_mic)
661 i = 5; /* Mic and MicroMix available */ 661 i = 5; /* Mic and MicroMix available */
662 } 662 }
663 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 663 return snd_ctl_enum_info(uinfo, 1, i, texts);
664 uinfo->count = 1;
665 uinfo->value.enumerated.items = i;
666 if (uinfo->value.enumerated.item > (i-1))
667 uinfo->value.enumerated.item = i-1;
668 strcpy(uinfo->value.enumerated.name,
669 texts[uinfo->value.enumerated.item]);
670 return 0;
671} 664}
672 665
673static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol, 666static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol,
@@ -756,14 +749,7 @@ static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol,
756 texts = textsPCXHR; 749 texts = textsPCXHR;
757 snd_BUG_ON(clock_items > (PCXHR_CLOCK_TYPE_MAX+1)); 750 snd_BUG_ON(clock_items > (PCXHR_CLOCK_TYPE_MAX+1));
758 } 751 }
759 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 752 return snd_ctl_enum_info(uinfo, 1, clock_items, texts);
760 uinfo->count = 1;
761 uinfo->value.enumerated.items = clock_items;
762 if (uinfo->value.enumerated.item >= clock_items)
763 uinfo->value.enumerated.item = clock_items-1;
764 strcpy(uinfo->value.enumerated.name,
765 texts[uinfo->value.enumerated.item]);
766 return 0;
767} 753}
768 754
769static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol, 755static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index 4afd3cab775b..6c60dcd2e5a1 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1608,30 +1608,24 @@ snd_rme32_info_inputtype_control(struct snd_kcontrol *kcontrol,
1608 struct snd_ctl_elem_info *uinfo) 1608 struct snd_ctl_elem_info *uinfo)
1609{ 1609{
1610 struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); 1610 struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1611 static char *texts[4] = { "Optical", "Coaxial", "Internal", "XLR" }; 1611 static const char * const texts[4] = {
1612 "Optical", "Coaxial", "Internal", "XLR"
1613 };
1614 int num_items;
1612 1615
1613 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1614 uinfo->count = 1;
1615 switch (rme32->pci->device) { 1616 switch (rme32->pci->device) {
1616 case PCI_DEVICE_ID_RME_DIGI32: 1617 case PCI_DEVICE_ID_RME_DIGI32:
1617 case PCI_DEVICE_ID_RME_DIGI32_8: 1618 case PCI_DEVICE_ID_RME_DIGI32_8:
1618 uinfo->value.enumerated.items = 3; 1619 num_items = 3;
1619 break; 1620 break;
1620 case PCI_DEVICE_ID_RME_DIGI32_PRO: 1621 case PCI_DEVICE_ID_RME_DIGI32_PRO:
1621 uinfo->value.enumerated.items = 4; 1622 num_items = 4;
1622 break; 1623 break;
1623 default: 1624 default:
1624 snd_BUG(); 1625 snd_BUG();
1625 break; 1626 return -EINVAL;
1626 }
1627 if (uinfo->value.enumerated.item >
1628 uinfo->value.enumerated.items - 1) {
1629 uinfo->value.enumerated.item =
1630 uinfo->value.enumerated.items - 1;
1631 } 1627 }
1632 strcpy(uinfo->value.enumerated.name, 1628 return snd_ctl_enum_info(uinfo, 1, num_items, texts);
1633 texts[uinfo->value.enumerated.item]);
1634 return 0;
1635} 1629}
1636static int 1630static int
1637snd_rme32_get_inputtype_control(struct snd_kcontrol *kcontrol, 1631snd_rme32_get_inputtype_control(struct snd_kcontrol *kcontrol,
@@ -1695,20 +1689,12 @@ static int
1695snd_rme32_info_clockmode_control(struct snd_kcontrol *kcontrol, 1689snd_rme32_info_clockmode_control(struct snd_kcontrol *kcontrol,
1696 struct snd_ctl_elem_info *uinfo) 1690 struct snd_ctl_elem_info *uinfo)
1697{ 1691{
1698 static char *texts[4] = { "AutoSync", 1692 static const char * const texts[4] = { "AutoSync",
1699 "Internal 32.0kHz", 1693 "Internal 32.0kHz",
1700 "Internal 44.1kHz", 1694 "Internal 44.1kHz",
1701 "Internal 48.0kHz" }; 1695 "Internal 48.0kHz" };
1702 1696
1703 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1697 return snd_ctl_enum_info(uinfo, 1, 4, texts);
1704 uinfo->count = 1;
1705 uinfo->value.enumerated.items = 4;
1706 if (uinfo->value.enumerated.item > 3) {
1707 uinfo->value.enumerated.item = 3;
1708 }
1709 strcpy(uinfo->value.enumerated.name,
1710 texts[uinfo->value.enumerated.item]);
1711 return 0;
1712} 1698}
1713static int 1699static int
1714snd_rme32_get_clockmode_control(struct snd_kcontrol *kcontrol, 1700snd_rme32_get_clockmode_control(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index 5a395c87c6fc..2f1a85185a16 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -1884,39 +1884,38 @@ snd_rme96_put_loopback_control(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
1884static int 1884static int
1885snd_rme96_info_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1885snd_rme96_info_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1886{ 1886{
1887 static char *_texts[5] = { "Optical", "Coaxial", "Internal", "XLR", "Analog" }; 1887 static const char * const _texts[5] = {
1888 "Optical", "Coaxial", "Internal", "XLR", "Analog"
1889 };
1888 struct rme96 *rme96 = snd_kcontrol_chip(kcontrol); 1890 struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
1889 char *texts[5] = { _texts[0], _texts[1], _texts[2], _texts[3], _texts[4] }; 1891 const char *texts[5] = {
1892 _texts[0], _texts[1], _texts[2], _texts[3], _texts[4]
1893 };
1894 int num_items;
1890 1895
1891 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1892 uinfo->count = 1;
1893 switch (rme96->pci->device) { 1896 switch (rme96->pci->device) {
1894 case PCI_DEVICE_ID_RME_DIGI96: 1897 case PCI_DEVICE_ID_RME_DIGI96:
1895 case PCI_DEVICE_ID_RME_DIGI96_8: 1898 case PCI_DEVICE_ID_RME_DIGI96_8:
1896 uinfo->value.enumerated.items = 3; 1899 num_items = 3;
1897 break; 1900 break;
1898 case PCI_DEVICE_ID_RME_DIGI96_8_PRO: 1901 case PCI_DEVICE_ID_RME_DIGI96_8_PRO:
1899 uinfo->value.enumerated.items = 4; 1902 num_items = 4;
1900 break; 1903 break;
1901 case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST: 1904 case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST:
1902 if (rme96->rev > 4) { 1905 if (rme96->rev > 4) {
1903 /* PST */ 1906 /* PST */
1904 uinfo->value.enumerated.items = 4; 1907 num_items = 4;
1905 texts[3] = _texts[4]; /* Analog instead of XLR */ 1908 texts[3] = _texts[4]; /* Analog instead of XLR */
1906 } else { 1909 } else {
1907 /* PAD */ 1910 /* PAD */
1908 uinfo->value.enumerated.items = 5; 1911 num_items = 5;
1909 } 1912 }
1910 break; 1913 break;
1911 default: 1914 default:
1912 snd_BUG(); 1915 snd_BUG();
1913 break; 1916 return -EINVAL;
1914 }
1915 if (uinfo->value.enumerated.item > uinfo->value.enumerated.items - 1) {
1916 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1917 } 1917 }
1918 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1918 return snd_ctl_enum_info(uinfo, 1, num_items, texts);
1919 return 0;
1920} 1919}
1921static int 1920static int
1922snd_rme96_get_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1921snd_rme96_get_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2002,16 +2001,9 @@ snd_rme96_put_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_el
2002static int 2001static int
2003snd_rme96_info_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2002snd_rme96_info_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2004{ 2003{
2005 static char *texts[3] = { "AutoSync", "Internal", "Word" }; 2004 static const char * const texts[3] = { "AutoSync", "Internal", "Word" };
2006 2005
2007 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2006 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2008 uinfo->count = 1;
2009 uinfo->value.enumerated.items = 3;
2010 if (uinfo->value.enumerated.item > 2) {
2011 uinfo->value.enumerated.item = 2;
2012 }
2013 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2014 return 0;
2015} 2007}
2016static int 2008static int
2017snd_rme96_get_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2009snd_rme96_get_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2041,16 +2033,11 @@ snd_rme96_put_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_el
2041static int 2033static int
2042snd_rme96_info_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2034snd_rme96_info_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2043{ 2035{
2044 static char *texts[4] = { "0 dB", "-6 dB", "-12 dB", "-18 dB" }; 2036 static const char * const texts[4] = {
2037 "0 dB", "-6 dB", "-12 dB", "-18 dB"
2038 };
2045 2039
2046 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2040 return snd_ctl_enum_info(uinfo, 1, 4, texts);
2047 uinfo->count = 1;
2048 uinfo->value.enumerated.items = 4;
2049 if (uinfo->value.enumerated.item > 3) {
2050 uinfo->value.enumerated.item = 3;
2051 }
2052 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2053 return 0;
2054} 2041}
2055static int 2042static int
2056snd_rme96_get_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2043snd_rme96_get_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2081,16 +2068,9 @@ snd_rme96_put_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_
2081static int 2068static int
2082snd_rme96_info_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2069snd_rme96_info_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2083{ 2070{
2084 static char *texts[4] = { "1+2", "3+4", "5+6", "7+8" }; 2071 static const char * const texts[4] = { "1+2", "3+4", "5+6", "7+8" };
2085 2072
2086 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2073 return snd_ctl_enum_info(uinfo, 1, 4, texts);
2087 uinfo->count = 1;
2088 uinfo->value.enumerated.items = 4;
2089 if (uinfo->value.enumerated.item > 3) {
2090 uinfo->value.enumerated.item = 3;
2091 }
2092 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2093 return 0;
2094} 2074}
2095static int 2075static int
2096snd_rme96_get_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2076snd_rme96_get_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 7646ba1664eb..cf5a6c8b9a63 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -1680,16 +1680,13 @@ static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1680 1680
1681static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1681static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1682{ 1682{
1683 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"}; 1683 static const char * const texts[4] = {
1684 "Optical", "Coaxial", "Internal", "AES"
1685 };
1684 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1686 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1685 1687
1686 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1688 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 4 : 3,
1687 uinfo->count = 1; 1689 texts);
1688 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1689 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1690 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1691 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1692 return 0;
1693} 1690}
1694 1691
1695static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1692static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1786,16 +1783,14 @@ static int snd_hdsp_put_toggle_setting(struct snd_kcontrol *kcontrol,
1786 1783
1787static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1784static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1788{ 1785{
1789 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"}; 1786 static const char * const texts[] = {
1787 "32000", "44100", "48000", "64000", "88200", "96000",
1788 "None", "128000", "176400", "192000"
1789 };
1790 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1790 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1791 1791
1792 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1792 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1793 uinfo->count = 1; 1793 texts);
1794 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1795 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1796 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1797 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1798 return 0;
1799} 1794}
1800 1795
1801static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1796static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1872,14 +1867,13 @@ static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct
1872static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1867static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1873{ 1868{
1874 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1869 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1875 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"}; 1870 static const char * const texts[] = {
1876 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1871 "32000", "44100", "48000", "64000", "88200", "96000",
1877 uinfo->count = 1; 1872 "None", "128000", "176400", "192000"
1878 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ; 1873 };
1879 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1874
1880 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1875 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1881 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1876 texts);
1882 return 0;
1883} 1877}
1884 1878
1885static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1879static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1940,15 +1934,9 @@ static int hdsp_system_clock_mode(struct hdsp *hdsp)
1940 1934
1941static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1935static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1942{ 1936{
1943 static char *texts[] = {"Master", "Slave" }; 1937 static const char * const texts[] = {"Master", "Slave" };
1944 1938
1945 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1939 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1946 uinfo->count = 1;
1947 uinfo->value.enumerated.items = 2;
1948 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1949 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1950 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1951 return 0;
1952} 1940}
1953 1941
1954static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1942static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2049,19 +2037,16 @@ static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
2049 2037
2050static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2038static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2051{ 2039{
2052 static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" }; 2040 static const char * const texts[] = {
2041 "AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz",
2042 "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz",
2043 "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz",
2044 "Internal 192.0 KHz"
2045 };
2053 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2046 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2054 2047
2055 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2048 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
2056 uinfo->count = 1; 2049 texts);
2057 if (hdsp->io_type == H9632)
2058 uinfo->value.enumerated.items = 10;
2059 else
2060 uinfo->value.enumerated.items = 7;
2061 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2062 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2063 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2064 return 0;
2065} 2050}
2066 2051
2067static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2052static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2165,15 +2150,9 @@ static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2165 2150
2166static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2151static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2167{ 2152{
2168 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"}; 2153 static const char * const texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2169 2154
2170 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2155 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2171 uinfo->count = 1;
2172 uinfo->value.enumerated.items = 3;
2173 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2174 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2175 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2176 return 0;
2177} 2156}
2178 2157
2179static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2158static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2250,15 +2229,9 @@ static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2250 2229
2251static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2230static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2252{ 2231{
2253 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"}; 2232 static const char * const texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2254 2233
2255 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2234 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2256 uinfo->count = 1;
2257 uinfo->value.enumerated.items = 3;
2258 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2259 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2260 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2261 return 0;
2262} 2235}
2263 2236
2264static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2237static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2335,15 +2308,9 @@ static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2335 2308
2336static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2309static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2337{ 2310{
2338 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"}; 2311 static const char * const texts[] = {"0 dB", "-6 dB", "-12 dB"};
2339 2312
2340 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2313 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2341 uinfo->count = 1;
2342 uinfo->value.enumerated.items = 3;
2343 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2344 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2345 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2346 return 0;
2347} 2314}
2348 2315
2349static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2316static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2439,31 +2406,28 @@ static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2439 2406
2440static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2407static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2441{ 2408{
2442 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" }; 2409 static const char * const texts[] = {
2410 "Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3"
2411 };
2443 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2412 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2444 2413 int num_items;
2445 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2446 uinfo->count = 1;
2447 2414
2448 switch (hdsp->io_type) { 2415 switch (hdsp->io_type) {
2449 case Digiface: 2416 case Digiface:
2450 case H9652: 2417 case H9652:
2451 uinfo->value.enumerated.items = 6; 2418 num_items = 6;
2452 break; 2419 break;
2453 case Multiface: 2420 case Multiface:
2454 uinfo->value.enumerated.items = 4; 2421 num_items = 4;
2455 break; 2422 break;
2456 case H9632: 2423 case H9632:
2457 uinfo->value.enumerated.items = 3; 2424 num_items = 3;
2458 break; 2425 break;
2459 default: 2426 default:
2460 return -EINVAL; 2427 return -EINVAL;
2461 } 2428 }
2462 2429
2463 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2430 return snd_ctl_enum_info(uinfo, 1, num_items, texts);
2464 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2465 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2466 return 0;
2467} 2431}
2468 2432
2469static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2433static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2543,15 +2507,11 @@ static int hdsp_autosync_ref(struct hdsp *hdsp)
2543 2507
2544static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2508static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2545{ 2509{
2546 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" }; 2510 static const char * const texts[] = {
2511 "Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3"
2512 };
2547 2513
2548 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2514 return snd_ctl_enum_info(uinfo, 1, 7, texts);
2549 uinfo->count = 1;
2550 uinfo->value.enumerated.items = 7;
2551 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2552 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2553 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2554 return 0;
2555} 2515}
2556 2516
2557static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2517static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -2738,14 +2698,9 @@ static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
2738 2698
2739static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2699static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2740{ 2700{
2741 static char *texts[] = {"No Lock", "Lock", "Sync" }; 2701 static const char * const texts[] = {"No Lock", "Lock", "Sync" };
2742 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2702
2743 uinfo->count = 1; 2703 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2744 uinfo->value.enumerated.items = 3;
2745 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2746 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2747 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2748 return 0;
2749} 2704}
2750 2705
2751static int hdsp_wc_sync_check(struct hdsp *hdsp) 2706static int hdsp_wc_sync_check(struct hdsp *hdsp)
@@ -3101,15 +3056,11 @@ static int snd_hdsp_put_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ct
3101 3056
3102static int snd_hdsp_info_rpm_input(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3057static int snd_hdsp_info_rpm_input(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3103{ 3058{
3104 static char *texts[] = {"Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"}; 3059 static const char * const texts[] = {
3060 "Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"
3061 };
3105 3062
3106 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3063 return snd_ctl_enum_info(uinfo, 1, 5, texts);
3107 uinfo->count = 1;
3108 uinfo->value.enumerated.items = 5;
3109 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3110 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3111 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3112 return 0;
3113} 3064}
3114 3065
3115 3066
@@ -3234,15 +3185,9 @@ static int snd_hdsp_put_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl
3234 3185
3235static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3186static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3236{ 3187{
3237 static char *texts[] = {"On", "Off"}; 3188 static const char * const texts[] = {"On", "Off"};
3238 3189
3239 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3190 return snd_ctl_enum_info(uinfo, 1, 2, texts);
3240 uinfo->count = 1;
3241 uinfo->value.enumerated.items = 2;
3242 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3243 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3244 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3245 return 0;
3246} 3191}
3247 3192
3248 3193
@@ -3291,15 +3236,9 @@ static int snd_hdsp_put_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd
3291 3236
3292static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3237static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3293{ 3238{
3294 static char *texts[] = {"On", "Off"}; 3239 static const char * const texts[] = {"On", "Off"};
3295 3240
3296 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3241 return snd_ctl_enum_info(uinfo, 1, 2, texts);
3297 uinfo->count = 1;
3298 uinfo->value.enumerated.items = 2;
3299 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3300 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3301 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3302 return 0;
3303} 3242}
3304 3243
3305static struct snd_kcontrol_new snd_hdsp_rpm_controls[] = { 3244static struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
@@ -5368,8 +5307,7 @@ static int snd_hdsp_free(struct hdsp *hdsp)
5368 5307
5369 snd_hdsp_free_buffers(hdsp); 5308 snd_hdsp_free_buffers(hdsp);
5370 5309
5371 if (hdsp->firmware) 5310 release_firmware(hdsp->firmware);
5372 release_firmware(hdsp->firmware);
5373 vfree(hdsp->fw_uploaded); 5311 vfree(hdsp->fw_uploaded);
5374 5312
5375 if (hdsp->iobase) 5313 if (hdsp->iobase)
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 52d86af3ef2d..3342705a5715 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -1257,14 +1257,13 @@ static int hdspm_rate_multiplier(struct hdspm *hdspm, int rate)
1257/* check for external sample rate, returns the sample rate in Hz*/ 1257/* check for external sample rate, returns the sample rate in Hz*/
1258static int hdspm_external_sample_rate(struct hdspm *hdspm) 1258static int hdspm_external_sample_rate(struct hdspm *hdspm)
1259{ 1259{
1260 unsigned int status, status2, timecode; 1260 unsigned int status, status2;
1261 int syncref, rate = 0, rate_bits; 1261 int syncref, rate = 0, rate_bits;
1262 1262
1263 switch (hdspm->io_type) { 1263 switch (hdspm->io_type) {
1264 case AES32: 1264 case AES32:
1265 status2 = hdspm_read(hdspm, HDSPM_statusRegister2); 1265 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1266 status = hdspm_read(hdspm, HDSPM_statusRegister); 1266 status = hdspm_read(hdspm, HDSPM_statusRegister);
1267 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
1268 1267
1269 syncref = hdspm_autosync_ref(hdspm); 1268 syncref = hdspm_autosync_ref(hdspm);
1270 switch (syncref) { 1269 switch (syncref) {
@@ -2202,10 +2201,10 @@ static inline int hdspm_get_pll_freq(struct hdspm *hdspm)
2202 return rate; 2201 return rate;
2203} 2202}
2204 2203
2205/** 2204/*
2206 * Calculate the real sample rate from the 2205 * Calculate the real sample rate from the
2207 * current DDS value. 2206 * current DDS value.
2208 **/ 2207 */
2209static int hdspm_get_system_sample_rate(struct hdspm *hdspm) 2208static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
2210{ 2209{
2211 unsigned int rate; 2210 unsigned int rate;
@@ -2271,9 +2270,9 @@ static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol,
2271} 2270}
2272 2271
2273 2272
2274/** 2273/*
2275 * Returns the WordClock sample rate class for the given card. 2274 * Returns the WordClock sample rate class for the given card.
2276 **/ 2275 */
2277static int hdspm_get_wc_sample_rate(struct hdspm *hdspm) 2276static int hdspm_get_wc_sample_rate(struct hdspm *hdspm)
2278{ 2277{
2279 int status; 2278 int status;
@@ -2296,9 +2295,9 @@ static int hdspm_get_wc_sample_rate(struct hdspm *hdspm)
2296} 2295}
2297 2296
2298 2297
2299/** 2298/*
2300 * Returns the TCO sample rate class for the given card. 2299 * Returns the TCO sample rate class for the given card.
2301 **/ 2300 */
2302static int hdspm_get_tco_sample_rate(struct hdspm *hdspm) 2301static int hdspm_get_tco_sample_rate(struct hdspm *hdspm)
2303{ 2302{
2304 int status; 2303 int status;
@@ -2322,9 +2321,9 @@ static int hdspm_get_tco_sample_rate(struct hdspm *hdspm)
2322} 2321}
2323 2322
2324 2323
2325/** 2324/*
2326 * Returns the SYNC_IN sample rate class for the given card. 2325 * Returns the SYNC_IN sample rate class for the given card.
2327 **/ 2326 */
2328static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm) 2327static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm)
2329{ 2328{
2330 int status; 2329 int status;
@@ -2344,9 +2343,9 @@ static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm)
2344 return 0; 2343 return 0;
2345} 2344}
2346 2345
2347/** 2346/*
2348 * Returns the AES sample rate class for the given card. 2347 * Returns the AES sample rate class for the given card.
2349 **/ 2348 */
2350static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index) 2349static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index)
2351{ 2350{
2352 int timecode; 2351 int timecode;
@@ -2362,10 +2361,10 @@ static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index)
2362 return 0; 2361 return 0;
2363} 2362}
2364 2363
2365/** 2364/*
2366 * Returns the sample rate class for input source <idx> for 2365 * Returns the sample rate class for input source <idx> for
2367 * 'new style' cards like the AIO and RayDAT. 2366 * 'new style' cards like the AIO and RayDAT.
2368 **/ 2367 */
2369static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx) 2368static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
2370{ 2369{
2371 int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); 2370 int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
@@ -2513,10 +2512,10 @@ static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2513} 2512}
2514 2513
2515 2514
2516/** 2515/*
2517 * Returns the system clock mode for the given card. 2516 * Returns the system clock mode for the given card.
2518 * @returns 0 - master, 1 - slave 2517 * @returns 0 - master, 1 - slave
2519 **/ 2518 */
2520static int hdspm_system_clock_mode(struct hdspm *hdspm) 2519static int hdspm_system_clock_mode(struct hdspm *hdspm)
2521{ 2520{
2522 switch (hdspm->io_type) { 2521 switch (hdspm->io_type) {
@@ -2535,10 +2534,10 @@ static int hdspm_system_clock_mode(struct hdspm *hdspm)
2535} 2534}
2536 2535
2537 2536
2538/** 2537/*
2539 * Sets the system clock mode. 2538 * Sets the system clock mode.
2540 * @param mode 0 - master, 1 - slave 2539 * @param mode 0 - master, 1 - slave
2541 **/ 2540 */
2542static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode) 2541static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode)
2543{ 2542{
2544 hdspm_set_toggle_setting(hdspm, 2543 hdspm_set_toggle_setting(hdspm,
@@ -2645,18 +2644,7 @@ static int hdspm_set_clock_source(struct hdspm * hdspm, int mode)
2645static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol, 2644static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol,
2646 struct snd_ctl_elem_info *uinfo) 2645 struct snd_ctl_elem_info *uinfo)
2647{ 2646{
2648 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2647 return snd_ctl_enum_info(uinfo, 1, 9, texts_freq + 1);
2649 uinfo->count = 1;
2650 uinfo->value.enumerated.items = 9;
2651
2652 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2653 uinfo->value.enumerated.item =
2654 uinfo->value.enumerated.items - 1;
2655
2656 strcpy(uinfo->value.enumerated.name,
2657 texts_freq[uinfo->value.enumerated.item+1]);
2658
2659 return 0;
2660} 2648}
2661 2649
2662static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol, 2650static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol,
@@ -2704,11 +2692,11 @@ static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol,
2704} 2692}
2705 2693
2706 2694
2707/** 2695/*
2708 * Returns the current preferred sync reference setting. 2696 * Returns the current preferred sync reference setting.
2709 * The semantics of the return value are depending on the 2697 * The semantics of the return value are depending on the
2710 * card, please see the comments for clarification. 2698 * card, please see the comments for clarification.
2711 **/ 2699 */
2712static int hdspm_pref_sync_ref(struct hdspm * hdspm) 2700static int hdspm_pref_sync_ref(struct hdspm * hdspm)
2713{ 2701{
2714 switch (hdspm->io_type) { 2702 switch (hdspm->io_type) {
@@ -2807,11 +2795,11 @@ static int hdspm_pref_sync_ref(struct hdspm * hdspm)
2807} 2795}
2808 2796
2809 2797
2810/** 2798/*
2811 * Set the preferred sync reference to <pref>. The semantics 2799 * Set the preferred sync reference to <pref>. The semantics
2812 * of <pref> are depending on the card type, see the comments 2800 * of <pref> are depending on the card type, see the comments
2813 * for clarification. 2801 * for clarification.
2814 **/ 2802 */
2815static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref) 2803static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref)
2816{ 2804{
2817 int p = 0; 2805 int p = 0;
@@ -4113,9 +4101,9 @@ static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol,
4113 4101
4114 4102
4115 4103
4116/** 4104/*
4117 * TCO controls 4105 * TCO controls
4118 **/ 4106 */
4119static void hdspm_tco_write(struct hdspm *hdspm) 4107static void hdspm_tco_write(struct hdspm *hdspm)
4120{ 4108{
4121 unsigned int tc[4] = { 0, 0, 0, 0}; 4109 unsigned int tc[4] = { 0, 0, 0, 0};
@@ -4873,18 +4861,15 @@ snd_hdspm_proc_read_madi(struct snd_info_entry *entry,
4873 struct snd_info_buffer *buffer) 4861 struct snd_info_buffer *buffer)
4874{ 4862{
4875 struct hdspm *hdspm = entry->private_data; 4863 struct hdspm *hdspm = entry->private_data;
4876 unsigned int status, status2, control, freq; 4864 unsigned int status, status2;
4877 4865
4878 char *pref_sync_ref; 4866 char *pref_sync_ref;
4879 char *autosync_ref; 4867 char *autosync_ref;
4880 char *system_clock_mode; 4868 char *system_clock_mode;
4881 char *insel;
4882 int x, x2; 4869 int x, x2;
4883 4870
4884 status = hdspm_read(hdspm, HDSPM_statusRegister); 4871 status = hdspm_read(hdspm, HDSPM_statusRegister);
4885 status2 = hdspm_read(hdspm, HDSPM_statusRegister2); 4872 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
4886 control = hdspm->control_register;
4887 freq = hdspm_read(hdspm, HDSPM_timecodeRegister);
4888 4873
4889 snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n", 4874 snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n",
4890 hdspm->card_name, hdspm->card->number + 1, 4875 hdspm->card_name, hdspm->card->number + 1,
@@ -4947,17 +4932,6 @@ snd_hdspm_proc_read_madi(struct snd_info_entry *entry,
4947 snd_iprintf(buffer, "Line out: %s\n", 4932 snd_iprintf(buffer, "Line out: %s\n",
4948 (hdspm->control_register & HDSPM_LineOut) ? "on " : "off"); 4933 (hdspm->control_register & HDSPM_LineOut) ? "on " : "off");
4949 4934
4950 switch (hdspm->control_register & HDSPM_InputMask) {
4951 case HDSPM_InputOptical:
4952 insel = "Optical";
4953 break;
4954 case HDSPM_InputCoaxial:
4955 insel = "Coaxial";
4956 break;
4957 default:
4958 insel = "Unknown";
4959 }
4960
4961 snd_iprintf(buffer, 4935 snd_iprintf(buffer,
4962 "ClearTrackMarker = %s, Transmit in %s Channel Mode, " 4936 "ClearTrackMarker = %s, Transmit in %s Channel Mode, "
4963 "Auto Input %s\n", 4937 "Auto Input %s\n",
@@ -5202,15 +5176,13 @@ snd_hdspm_proc_read_raydat(struct snd_info_entry *entry,
5202 struct snd_info_buffer *buffer) 5176 struct snd_info_buffer *buffer)
5203{ 5177{
5204 struct hdspm *hdspm = entry->private_data; 5178 struct hdspm *hdspm = entry->private_data;
5205 unsigned int status1, status2, status3, control, i; 5179 unsigned int status1, status2, status3, i;
5206 unsigned int lock, sync; 5180 unsigned int lock, sync;
5207 5181
5208 status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */ 5182 status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */
5209 status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */ 5183 status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */
5210 status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */ 5184 status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */
5211 5185
5212 control = hdspm->control_register;
5213
5214 snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1); 5186 snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1);
5215 snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2); 5187 snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2);
5216 snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3); 5188 snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3);
@@ -5431,7 +5403,7 @@ static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
5431 HDSPM_midi2IRQPending | HDSPM_midi3IRQPending); 5403 HDSPM_midi2IRQPending | HDSPM_midi3IRQPending);
5432 5404
5433 /* now = get_cycles(); */ 5405 /* now = get_cycles(); */
5434 /** 5406 /*
5435 * LAT_2..LAT_0 period counter (win) counter (mac) 5407 * LAT_2..LAT_0 period counter (win) counter (mac)
5436 * 6 4096 ~256053425 ~514672358 5408 * 6 4096 ~256053425 ~514672358
5437 * 5 2048 ~128024983 ~257373821 5409 * 5 2048 ~128024983 ~257373821
@@ -5440,7 +5412,7 @@ static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
5440 * 2 256 ~16003039 ~32260176 5412 * 2 256 ~16003039 ~32260176
5441 * 1 128 ~7998738 ~16194507 5413 * 1 128 ~7998738 ~16194507
5442 * 0 64 ~3998231 ~8191558 5414 * 0 64 ~3998231 ~8191558
5443 **/ 5415 */
5444 /* 5416 /*
5445 dev_info(hdspm->card->dev, "snd_hdspm_interrupt %llu @ %llx\n", 5417 dev_info(hdspm->card->dev, "snd_hdspm_interrupt %llu @ %llx\n",
5446 now-hdspm->last_interrupt, status & 0xFFC0); 5418 now-hdspm->last_interrupt, status & 0xFFC0);
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index fa9a2a8dce5a..6521521853b8 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -920,15 +920,9 @@ static int rme9652_set_adat1_input(struct snd_rme9652 *rme9652, int internal)
920 920
921static int snd_rme9652_info_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 921static int snd_rme9652_info_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
922{ 922{
923 static char *texts[2] = {"ADAT1", "Internal"}; 923 static const char * const texts[2] = {"ADAT1", "Internal"};
924 924
925 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 925 return snd_ctl_enum_info(uinfo, 1, 2, texts);
926 uinfo->count = 1;
927 uinfo->value.enumerated.items = 2;
928 if (uinfo->value.enumerated.item > 1)
929 uinfo->value.enumerated.item = 1;
930 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
931 return 0;
932} 926}
933 927
934static int snd_rme9652_get_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 928static int snd_rme9652_get_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -991,15 +985,9 @@ static int rme9652_set_spdif_input(struct snd_rme9652 *rme9652, int in)
991 985
992static int snd_rme9652_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 986static int snd_rme9652_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
993{ 987{
994 static char *texts[3] = {"ADAT1", "Coaxial", "Internal"}; 988 static const char * const texts[3] = {"ADAT1", "Coaxial", "Internal"};
995 989
996 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 990 return snd_ctl_enum_info(uinfo, 1, 3, texts);
997 uinfo->count = 1;
998 uinfo->value.enumerated.items = 3;
999 if (uinfo->value.enumerated.item > 2)
1000 uinfo->value.enumerated.item = 2;
1001 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1002 return 0;
1003} 991}
1004 992
1005static int snd_rme9652_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 993static int snd_rme9652_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1140,15 +1128,11 @@ static int rme9652_set_sync_mode(struct snd_rme9652 *rme9652, int mode)
1140 1128
1141static int snd_rme9652_info_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1129static int snd_rme9652_info_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1142{ 1130{
1143 static char *texts[3] = {"AutoSync", "Master", "Word Clock"}; 1131 static const char * const texts[3] = {
1132 "AutoSync", "Master", "Word Clock"
1133 };
1144 1134
1145 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1135 return snd_ctl_enum_info(uinfo, 1, 3, texts);
1146 uinfo->count = 1;
1147 uinfo->value.enumerated.items = 3;
1148 if (uinfo->value.enumerated.item > 2)
1149 uinfo->value.enumerated.item = 2;
1150 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1151 return 0;
1152} 1136}
1153 1137
1154static int snd_rme9652_get_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1138static int snd_rme9652_get_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1231,16 +1215,14 @@ static int rme9652_set_sync_pref(struct snd_rme9652 *rme9652, int pref)
1231 1215
1232static int snd_rme9652_info_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1216static int snd_rme9652_info_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1233{ 1217{
1234 static char *texts[4] = {"IEC958 In", "ADAT1 In", "ADAT2 In", "ADAT3 In"}; 1218 static const char * const texts[4] = {
1219 "IEC958 In", "ADAT1 In", "ADAT2 In", "ADAT3 In"
1220 };
1235 struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); 1221 struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol);
1236 1222
1237 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1223 return snd_ctl_enum_info(uinfo, 1,
1238 uinfo->count = 1; 1224 rme9652->ss_channels == RME9652_NCHANNELS ? 4 : 3,
1239 uinfo->value.enumerated.items = rme9652->ss_channels == RME9652_NCHANNELS ? 4 : 3; 1225 texts);
1240 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1241 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1242 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1243 return 0;
1244} 1226}
1245 1227
1246static int snd_rme9652_get_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1228static int snd_rme9652_get_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1392,15 +1374,11 @@ static int snd_rme9652_get_spdif_rate(struct snd_kcontrol *kcontrol, struct snd_
1392 1374
1393static int snd_rme9652_info_adat_sync(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1375static int snd_rme9652_info_adat_sync(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1394{ 1376{
1395 static char *texts[4] = {"No Lock", "Lock", "No Lock Sync", "Lock Sync"}; 1377 static const char * const texts[4] = {
1378 "No Lock", "Lock", "No Lock Sync", "Lock Sync"
1379 };
1396 1380
1397 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1381 return snd_ctl_enum_info(uinfo, 1, 4, texts);
1398 uinfo->count = 1;
1399 uinfo->value.enumerated.items = 4;
1400 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1401 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1402 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1403 return 0;
1404} 1382}
1405 1383
1406static int snd_rme9652_get_adat_sync(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1384static int snd_rme9652_get_adat_sync(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 5b0d317cc9a6..313a7328bf9c 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -918,17 +918,11 @@ static int snd_sonicvibes_pcm(struct sonicvibes *sonic, int device,
918 918
919static int snd_sonicvibes_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 919static int snd_sonicvibes_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
920{ 920{
921 static char *texts[7] = { 921 static const char * const texts[7] = {
922 "CD", "PCM", "Aux1", "Line", "Aux0", "Mic", "Mix" 922 "CD", "PCM", "Aux1", "Line", "Aux0", "Mic", "Mix"
923 }; 923 };
924 924
925 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 925 return snd_ctl_enum_info(uinfo, 2, 7, texts);
926 uinfo->count = 2;
927 uinfo->value.enumerated.items = 7;
928 if (uinfo->value.enumerated.item >= 7)
929 uinfo->value.enumerated.item = 6;
930 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
931 return 0;
932} 926}
933 927
934static int snd_sonicvibes_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 928static int snd_sonicvibes_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index da875dced2ef..57cd757acfe7 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -3702,8 +3702,7 @@ static int snd_trident_free(struct snd_trident *trident)
3702 free_irq(trident->irq, trident); 3702 free_irq(trident->irq, trident);
3703 if (trident->tlb.buffer.area) { 3703 if (trident->tlb.buffer.area) {
3704 outl(0, TRID_REG(trident, NX_TLBC)); 3704 outl(0, TRID_REG(trident, NX_TLBC));
3705 if (trident->tlb.memhdr) 3705 snd_util_memhdr_free(trident->tlb.memhdr);
3706 snd_util_memhdr_free(trident->tlb.memhdr);
3707 if (trident->tlb.silent_page.area) 3706 if (trident->tlb.silent_page.area)
3708 snd_dma_free_pages(&trident->tlb.silent_page); 3707 snd_dma_free_pages(&trident->tlb.silent_page);
3709 vfree(trident->tlb.shadow_entries); 3708 vfree(trident->tlb.shadow_entries);
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index ecedf4dbfa2a..e088467fb736 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -1610,16 +1610,10 @@ static int snd_via8233_capture_source_info(struct snd_kcontrol *kcontrol,
1610 /* formerly they were "Line" and "Mic", but it looks like that they 1610 /* formerly they were "Line" and "Mic", but it looks like that they
1611 * have nothing to do with the actual physical connections... 1611 * have nothing to do with the actual physical connections...
1612 */ 1612 */
1613 static char *texts[2] = { 1613 static const char * const texts[2] = {
1614 "Input1", "Input2" 1614 "Input1", "Input2"
1615 }; 1615 };
1616 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1616 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1617 uinfo->count = 1;
1618 uinfo->value.enumerated.items = 2;
1619 if (uinfo->value.enumerated.item >= 2)
1620 uinfo->value.enumerated.item = 1;
1621 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1622 return 0;
1623} 1617}
1624 1618
1625static int snd_via8233_capture_source_get(struct snd_kcontrol *kcontrol, 1619static int snd_via8233_capture_source_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c
index 2d1570273e99..52c1a8d5b88a 100644
--- a/sound/pci/vx222/vx222_ops.c
+++ b/sound/pci/vx222/vx222_ops.c
@@ -92,6 +92,7 @@ static inline unsigned long vx2_reg_addr(struct vx_core *_chip, int reg)
92 92
93/** 93/**
94 * snd_vx_inb - read a byte from the register 94 * snd_vx_inb - read a byte from the register
95 * @chip: VX core instance
95 * @offset: register enum 96 * @offset: register enum
96 */ 97 */
97static unsigned char vx2_inb(struct vx_core *chip, int offset) 98static unsigned char vx2_inb(struct vx_core *chip, int offset)
@@ -101,6 +102,7 @@ static unsigned char vx2_inb(struct vx_core *chip, int offset)
101 102
102/** 103/**
103 * snd_vx_outb - write a byte on the register 104 * snd_vx_outb - write a byte on the register
105 * @chip: VX core instance
104 * @offset: the register offset 106 * @offset: the register offset
105 * @val: the value to write 107 * @val: the value to write
106 */ 108 */
@@ -114,6 +116,7 @@ static void vx2_outb(struct vx_core *chip, int offset, unsigned char val)
114 116
115/** 117/**
116 * snd_vx_inl - read a 32bit word from the register 118 * snd_vx_inl - read a 32bit word from the register
119 * @chip: VX core instance
117 * @offset: register enum 120 * @offset: register enum
118 */ 121 */
119static unsigned int vx2_inl(struct vx_core *chip, int offset) 122static unsigned int vx2_inl(struct vx_core *chip, int offset)
@@ -123,6 +126,7 @@ static unsigned int vx2_inl(struct vx_core *chip, int offset)
123 126
124/** 127/**
125 * snd_vx_outl - write a 32bit word on the register 128 * snd_vx_outl - write a 32bit word on the register
129 * @chip: VX core instance
126 * @offset: the register enum 130 * @offset: the register enum
127 * @val: the value to write 131 * @val: the value to write
128 */ 132 */
@@ -223,6 +227,7 @@ static int vx2_test_xilinx(struct vx_core *_chip)
223 227
224/** 228/**
225 * vx_setup_pseudo_dma - set up the pseudo dma read/write mode. 229 * vx_setup_pseudo_dma - set up the pseudo dma read/write mode.
230 * @chip: VX core instance
226 * @do_write: 0 = read, 1 = set up for DMA write 231 * @do_write: 0 = read, 1 = set up for DMA write
227 */ 232 */
228static void vx2_setup_pseudo_dma(struct vx_core *chip, int do_write) 233static void vx2_setup_pseudo_dma(struct vx_core *chip, int do_write)
diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c
index 92ec11456e3a..b16f42deed67 100644
--- a/sound/pcmcia/vx/vxpocket.c
+++ b/sound/pcmcia/vx/vxpocket.c
@@ -174,6 +174,7 @@ static int snd_vxpocket_new(struct snd_card *card, int ibl,
174 174
175/** 175/**
176 * snd_vxpocket_assign_resources - initialize the hardware and card instance. 176 * snd_vxpocket_assign_resources - initialize the hardware and card instance.
177 * @chip: VX core instance
177 * @port: i/o port for the card 178 * @port: i/o port for the card
178 * @irq: irq number for the card 179 * @irq: irq number for the card
179 * 180 *
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 8a431bcb056c..5a13b22748b2 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -887,8 +887,7 @@ static int snd_pmac_free(struct snd_pmac *chip)
887 } 887 }
888 } 888 }
889 889
890 if (chip->pdev) 890 pci_dev_put(chip->pdev);
891 pci_dev_put(chip->pdev);
892 of_node_put(chip->node); 891 of_node_put(chip->node);
893 kfree(chip); 892 kfree(chip);
894 return 0; 893 return 0;
diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c
index b9ffc17a4799..24c8766a925d 100644
--- a/sound/ppc/tumbler.c
+++ b/sound/ppc/tumbler.c
@@ -795,16 +795,11 @@ static int snapper_set_capture_source(struct pmac_tumbler *mix)
795static int snapper_info_capture_source(struct snd_kcontrol *kcontrol, 795static int snapper_info_capture_source(struct snd_kcontrol *kcontrol,
796 struct snd_ctl_elem_info *uinfo) 796 struct snd_ctl_elem_info *uinfo)
797{ 797{
798 static char *texts[2] = { 798 static const char * const texts[2] = {
799 "Line", "Mic" 799 "Line", "Mic"
800 }; 800 };
801 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 801
802 uinfo->count = 1; 802 return snd_ctl_enum_info(uinfo, 1, 2, texts);
803 uinfo->value.enumerated.items = 2;
804 if (uinfo->value.enumerated.item > 1)
805 uinfo->value.enumerated.item = 1;
806 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
807 return 0;
808} 803}
809 804
810static int snapper_get_capture_source(struct snd_kcontrol *kcontrol, 805static int snapper_get_capture_source(struct snd_kcontrol *kcontrol,
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index d88edfced8c4..865e090c8061 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,10 +1,14 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o 1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o
2snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o 2snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o soc-ops.o
3 3
4ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),) 4ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),)
5snd-soc-core-objs += soc-generic-dmaengine-pcm.o 5snd-soc-core-objs += soc-generic-dmaengine-pcm.o
6endif 6endif
7 7
8ifneq ($(CONFIG_SND_SOC_AC97_BUS),)
9snd-soc-core-objs += soc-ac97.o
10endif
11
8obj-$(CONFIG_SND_SOC) += snd-soc-core.o 12obj-$(CONFIG_SND_SOC) += snd-soc-core.o
9obj-$(CONFIG_SND_SOC) += codecs/ 13obj-$(CONFIG_SND_SOC) += codecs/
10obj-$(CONFIG_SND_SOC) += generic/ 14obj-$(CONFIG_SND_SOC) += generic/
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index 27e3fc4a536b..fb3878312bf8 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -52,12 +52,3 @@ config SND_AT91_SOC_SAM9X5_WM8731
52 help 52 help
53 Say Y if you want to add support for audio SoC on an 53 Say Y if you want to add support for audio SoC on an
54 at91sam9x5 based board that is using WM8731 codec. 54 at91sam9x5 based board that is using WM8731 codec.
55
56config SND_AT91_SOC_AFEB9260
57 tristate "SoC Audio support for AFEB9260 board"
58 depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC
59 select SND_ATMEL_SOC_PDC
60 select SND_ATMEL_SOC_SSC
61 select SND_SOC_TLV320AIC23_I2C
62 help
63 Say Y here to support sound on AFEB9260 board.
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
index 5baabc8bde3a..466a821da98c 100644
--- a/sound/soc/atmel/Makefile
+++ b/sound/soc/atmel/Makefile
@@ -17,4 +17,3 @@ snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o
17obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o 17obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o
18obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o 18obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o
19obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o 19obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o
20obj-$(CONFIG_SND_AT91_SOC_AFEB9260) += snd-soc-afeb9260.o
diff --git a/sound/soc/atmel/atmel-pcm-dma.c b/sound/soc/atmel/atmel-pcm-dma.c
index b79a2a864513..33fb3bb133df 100644
--- a/sound/soc/atmel/atmel-pcm-dma.c
+++ b/sound/soc/atmel/atmel-pcm-dma.c
@@ -80,9 +80,7 @@ static void atmel_pcm_dma_irq(u32 ssc_sr,
80 80
81 /* stop RX and capture: will be enabled again at restart */ 81 /* stop RX and capture: will be enabled again at restart */
82 ssc_writex(prtd->ssc->regs, SSC_CR, prtd->mask->ssc_disable); 82 ssc_writex(prtd->ssc->regs, SSC_CR, prtd->mask->ssc_disable);
83 snd_pcm_stream_lock(substream); 83 snd_pcm_stop_xrun(substream);
84 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
85 snd_pcm_stream_unlock(substream);
86 84
87 /* now drain RHR and read status to remove xrun condition */ 85 /* now drain RHR and read status to remove xrun condition */
88 ssc_readx(prtd->ssc->regs, SSC_RHR); 86 ssc_readx(prtd->ssc->regs, SSC_RHR);
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index f403f399808a..b1cc2a4a7fc0 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -310,7 +310,10 @@ static int atmel_ssc_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
310 * transmit and receive, so if a value has already 310 * transmit and receive, so if a value has already
311 * been set, it must match this value. 311 * been set, it must match this value.
312 */ 312 */
313 if (ssc_p->cmr_div == 0) 313 if (ssc_p->dir_mask !=
314 (SSC_DIR_MASK_PLAYBACK | SSC_DIR_MASK_CAPTURE))
315 ssc_p->cmr_div = div;
316 else if (ssc_p->cmr_div == 0)
314 ssc_p->cmr_div = div; 317 ssc_p->cmr_div = div;
315 else 318 else
316 if (div != ssc_p->cmr_div) 319 if (div != ssc_p->cmr_div)
diff --git a/sound/soc/atmel/snd-soc-afeb9260.c b/sound/soc/atmel/snd-soc-afeb9260.c
deleted file mode 100644
index 9579799ace54..000000000000
--- a/sound/soc/atmel/snd-soc-afeb9260.c
+++ /dev/null
@@ -1,151 +0,0 @@
1/*
2 * afeb9260.c -- SoC audio for AFEB9260
3 *
4 * Copyright (C) 2009 Sergey Lapin <slapin@ossfans.org>
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/module.h>
23#include <linux/moduleparam.h>
24#include <linux/kernel.h>
25#include <linux/clk.h>
26#include <linux/platform_device.h>
27
28#include <linux/atmel-ssc.h>
29#include <sound/core.h>
30#include <sound/pcm.h>
31#include <sound/pcm_params.h>
32#include <sound/soc.h>
33
34#include <asm/mach-types.h>
35#include <mach/hardware.h>
36#include <linux/gpio.h>
37
38#include "../codecs/tlv320aic23.h"
39#include "atmel-pcm.h"
40#include "atmel_ssc_dai.h"
41
42#define CODEC_CLOCK 12000000
43
44static int afeb9260_hw_params(struct snd_pcm_substream *substream,
45 struct snd_pcm_hw_params *params)
46{
47 struct snd_soc_pcm_runtime *rtd = substream->private_data;
48 struct snd_soc_dai *codec_dai = rtd->codec_dai;
49 int err;
50
51 /* Set the codec system clock for DAC and ADC */
52 err =
53 snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
54
55 if (err < 0) {
56 printk(KERN_ERR "can't set codec system clock\n");
57 return err;
58 }
59
60 return err;
61}
62
63static struct snd_soc_ops afeb9260_ops = {
64 .hw_params = afeb9260_hw_params,
65};
66
67static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
68 SND_SOC_DAPM_HP("Headphone Jack", NULL),
69 SND_SOC_DAPM_LINE("Line In", NULL),
70 SND_SOC_DAPM_MIC("Mic Jack", NULL),
71};
72
73static const struct snd_soc_dapm_route afeb9260_audio_map[] = {
74 {"Headphone Jack", NULL, "LHPOUT"},
75 {"Headphone Jack", NULL, "RHPOUT"},
76
77 {"LLINEIN", NULL, "Line In"},
78 {"RLINEIN", NULL, "Line In"},
79
80 {"MICIN", NULL, "Mic Jack"},
81};
82
83
84/* Digital audio interface glue - connects codec <--> CPU */
85static struct snd_soc_dai_link afeb9260_dai = {
86 .name = "TLV320AIC23",
87 .stream_name = "AIC23",
88 .cpu_dai_name = "atmel-ssc-dai.0",
89 .codec_dai_name = "tlv320aic23-hifi",
90 .platform_name = "atmel_pcm-audio",
91 .codec_name = "tlv320aic23-codec.0-001a",
92 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
93 SND_SOC_DAIFMT_CBM_CFM,
94 .ops = &afeb9260_ops,
95};
96
97/* Audio machine driver */
98static struct snd_soc_card snd_soc_machine_afeb9260 = {
99 .name = "AFEB9260",
100 .owner = THIS_MODULE,
101 .dai_link = &afeb9260_dai,
102 .num_links = 1,
103
104 .dapm_widgets = tlv320aic23_dapm_widgets,
105 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
106 .dapm_routes = afeb9260_audio_map,
107 .num_dapm_routes = ARRAY_SIZE(afeb9260_audio_map),
108};
109
110static struct platform_device *afeb9260_snd_device;
111
112static int __init afeb9260_soc_init(void)
113{
114 int err;
115 struct device *dev;
116
117 if (!(machine_is_afeb9260()))
118 return -ENODEV;
119
120
121 afeb9260_snd_device = platform_device_alloc("soc-audio", -1);
122 if (!afeb9260_snd_device) {
123 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
124 return -ENOMEM;
125 }
126
127 platform_set_drvdata(afeb9260_snd_device, &snd_soc_machine_afeb9260);
128 err = platform_device_add(afeb9260_snd_device);
129 if (err)
130 goto err1;
131
132 dev = &afeb9260_snd_device->dev;
133
134 return 0;
135err1:
136 platform_device_put(afeb9260_snd_device);
137 return err;
138}
139
140static void __exit afeb9260_soc_exit(void)
141{
142 platform_device_unregister(afeb9260_snd_device);
143}
144
145module_init(afeb9260_soc_init);
146module_exit(afeb9260_soc_exit);
147
148MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>");
149MODULE_DESCRIPTION("ALSA SoC for AFEB9260");
150MODULE_LICENSE("GPL");
151
diff --git a/sound/soc/au1x/ac97c.c b/sound/soc/au1x/ac97c.c
index c8a2de103c5f..5159a50a45a6 100644
--- a/sound/soc/au1x/ac97c.c
+++ b/sound/soc/au1x/ac97c.c
@@ -205,7 +205,7 @@ static int au1xac97c_dai_probe(struct snd_soc_dai *dai)
205 205
206static struct snd_soc_dai_driver au1xac97c_dai_driver = { 206static struct snd_soc_dai_driver au1xac97c_dai_driver = {
207 .name = "alchemy-ac97c", 207 .name = "alchemy-ac97c",
208 .ac97_control = 1, 208 .bus_control = true,
209 .probe = au1xac97c_dai_probe, 209 .probe = au1xac97c_dai_probe,
210 .playback = { 210 .playback = {
211 .rates = AC97_RATES, 211 .rates = AC97_RATES,
diff --git a/sound/soc/au1x/psc-ac97.c b/sound/soc/au1x/psc-ac97.c
index 84f31e1f9d24..c6daec98ff89 100644
--- a/sound/soc/au1x/psc-ac97.c
+++ b/sound/soc/au1x/psc-ac97.c
@@ -343,7 +343,7 @@ static const struct snd_soc_dai_ops au1xpsc_ac97_dai_ops = {
343}; 343};
344 344
345static const struct snd_soc_dai_driver au1xpsc_ac97_dai_template = { 345static const struct snd_soc_dai_driver au1xpsc_ac97_dai_template = {
346 .ac97_control = 1, 346 .bus_control = true,
347 .probe = au1xpsc_ac97_probe, 347 .probe = au1xpsc_ac97_probe,
348 .playback = { 348 .playback = {
349 .rates = AC97_RATES, 349 .rates = AC97_RATES,
diff --git a/sound/soc/blackfin/bf5xx-ac97.c b/sound/soc/blackfin/bf5xx-ac97.c
index e82eb373a731..6bf21a6c02e4 100644
--- a/sound/soc/blackfin/bf5xx-ac97.c
+++ b/sound/soc/blackfin/bf5xx-ac97.c
@@ -260,7 +260,7 @@ static int bf5xx_ac97_resume(struct snd_soc_dai *dai)
260#endif 260#endif
261 261
262static struct snd_soc_dai_driver bfin_ac97_dai = { 262static struct snd_soc_dai_driver bfin_ac97_dai = {
263 .ac97_control = 1, 263 .bus_control = true,
264 .suspend = bf5xx_ac97_suspend, 264 .suspend = bf5xx_ac97_suspend,
265 .resume = bf5xx_ac97_resume, 265 .resume = bf5xx_ac97_resume,
266 .playback = { 266 .playback = {
diff --git a/sound/soc/blackfin/bf5xx-ad1980.c b/sound/soc/blackfin/bf5xx-ad1980.c
index 3450e8f9080d..0fa81a523b8a 100644
--- a/sound/soc/blackfin/bf5xx-ad1980.c
+++ b/sound/soc/blackfin/bf5xx-ad1980.c
@@ -46,8 +46,6 @@
46#include <linux/gpio.h> 46#include <linux/gpio.h>
47#include <asm/portmux.h> 47#include <asm/portmux.h>
48 48
49#include "../codecs/ad1980.h"
50
51#include "bf5xx-ac97.h" 49#include "bf5xx-ac97.h"
52 50
53static struct snd_soc_card bf5xx_board; 51static struct snd_soc_card bf5xx_board;
diff --git a/sound/soc/cirrus/Kconfig b/sound/soc/cirrus/Kconfig
index 5477c5475923..7b7fbcd49e5e 100644
--- a/sound/soc/cirrus/Kconfig
+++ b/sound/soc/cirrus/Kconfig
@@ -36,7 +36,8 @@ config SND_EP93XX_SOC_EDB93XX
36 tristate "SoC Audio support for Cirrus Logic EDB93xx boards" 36 tristate "SoC Audio support for Cirrus Logic EDB93xx boards"
37 depends on SND_EP93XX_SOC && (MACH_EDB9301 || MACH_EDB9302 || MACH_EDB9302A || MACH_EDB9307A || MACH_EDB9315A) 37 depends on SND_EP93XX_SOC && (MACH_EDB9301 || MACH_EDB9302 || MACH_EDB9302A || MACH_EDB9307A || MACH_EDB9315A)
38 select SND_EP93XX_SOC_I2S 38 select SND_EP93XX_SOC_I2S
39 select SND_SOC_CS4271 39 select SND_SOC_CS4271_I2C if I2C
40 select SND_SOC_CS4271_SPI if SPI_MASTER
40 help 41 help
41 Say Y or M here if you want to add support for I2S audio on the 42 Say Y or M here if you want to add support for I2S audio on the
42 Cirrus Logic EDB93xx boards. 43 Cirrus Logic EDB93xx boards.
diff --git a/sound/soc/cirrus/ep93xx-ac97.c b/sound/soc/cirrus/ep93xx-ac97.c
index f30dadf85b99..6b8a366b0211 100644
--- a/sound/soc/cirrus/ep93xx-ac97.c
+++ b/sound/soc/cirrus/ep93xx-ac97.c
@@ -338,7 +338,7 @@ static const struct snd_soc_dai_ops ep93xx_ac97_dai_ops = {
338static struct snd_soc_dai_driver ep93xx_ac97_dai = { 338static struct snd_soc_dai_driver ep93xx_ac97_dai = {
339 .name = "ep93xx-ac97", 339 .name = "ep93xx-ac97",
340 .id = 0, 340 .id = 0,
341 .ac97_control = 1, 341 .bus_control = true,
342 .probe = ep93xx_ac97_dai_probe, 342 .probe = ep93xx_ac97_dai_probe,
343 .playback = { 343 .playback = {
344 .stream_name = "AC97 Playback", 344 .stream_name = "AC97 Playback",
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index a68d1731a8fd..883c5778b309 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -50,7 +50,8 @@ config SND_SOC_ALL_CODECS
50 select SND_SOC_CS42L73 if I2C 50 select SND_SOC_CS42L73 if I2C
51 select SND_SOC_CS4265 if I2C 51 select SND_SOC_CS4265 if I2C
52 select SND_SOC_CS4270 if I2C 52 select SND_SOC_CS4270 if I2C
53 select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI 53 select SND_SOC_CS4271_I2C if I2C
54 select SND_SOC_CS4271_SPI if SPI_MASTER
54 select SND_SOC_CS42XX8_I2C if I2C 55 select SND_SOC_CS42XX8_I2C if I2C
55 select SND_SOC_CX20442 if TTY 56 select SND_SOC_CX20442 if TTY
56 select SND_SOC_DA7210 if I2C 57 select SND_SOC_DA7210 if I2C
@@ -85,7 +86,7 @@ config SND_SOC_ALL_CODECS
85 select SND_SOC_RT5645 if I2C 86 select SND_SOC_RT5645 if I2C
86 select SND_SOC_RT5651 if I2C 87 select SND_SOC_RT5651 if I2C
87 select SND_SOC_RT5670 if I2C 88 select SND_SOC_RT5670 if I2C
88 select SND_SOC_RT5677 if I2C 89 select SND_SOC_RT5677 if I2C && SPI_MASTER
89 select SND_SOC_SGTL5000 if I2C 90 select SND_SOC_SGTL5000 if I2C
90 select SND_SOC_SI476X if MFD_SI476X_CORE 91 select SND_SOC_SI476X if MFD_SI476X_CORE
91 select SND_SOC_SIRF_AUDIO_CODEC 92 select SND_SOC_SIRF_AUDIO_CODEC
@@ -101,6 +102,7 @@ config SND_SOC_ALL_CODECS
101 select SND_SOC_STAC9766 if SND_SOC_AC97_BUS 102 select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
102 select SND_SOC_TAS2552 if I2C 103 select SND_SOC_TAS2552 if I2C
103 select SND_SOC_TAS5086 if I2C 104 select SND_SOC_TAS5086 if I2C
105 select SND_SOC_TFA9879 if I2C
104 select SND_SOC_TLV320AIC23_I2C if I2C 106 select SND_SOC_TLV320AIC23_I2C if I2C
105 select SND_SOC_TLV320AIC23_SPI if SPI_MASTER 107 select SND_SOC_TLV320AIC23_SPI if SPI_MASTER
106 select SND_SOC_TLV320AIC26 if SPI_MASTER 108 select SND_SOC_TLV320AIC26 if SPI_MASTER
@@ -109,6 +111,7 @@ config SND_SOC_ALL_CODECS
109 select SND_SOC_TLV320AIC3X if I2C 111 select SND_SOC_TLV320AIC3X if I2C
110 select SND_SOC_TPA6130A2 if I2C 112 select SND_SOC_TPA6130A2 if I2C
111 select SND_SOC_TLV320DAC33 if I2C 113 select SND_SOC_TLV320DAC33 if I2C
114 select SND_SOC_TS3A227E if I2C
112 select SND_SOC_TWL4030 if TWL4030_CORE 115 select SND_SOC_TWL4030 if TWL4030_CORE
113 select SND_SOC_TWL6040 if TWL6040_CORE 116 select SND_SOC_TWL6040 if TWL6040_CORE
114 select SND_SOC_UDA134X 117 select SND_SOC_UDA134X
@@ -223,6 +226,7 @@ config SND_SOC_AD193X_I2C
223 select SND_SOC_AD193X 226 select SND_SOC_AD193X
224 227
225config SND_SOC_AD1980 228config SND_SOC_AD1980
229 select REGMAP_AC97
226 tristate 230 tristate
227 231
228config SND_SOC_AD73311 232config SND_SOC_AD73311
@@ -336,7 +340,8 @@ config SND_SOC_CS42L51
336 tristate 340 tristate
337 341
338config SND_SOC_CS42L51_I2C 342config SND_SOC_CS42L51_I2C
339 tristate 343 tristate "Cirrus Logic CS42L51 CODEC (I2C)"
344 depends on I2C
340 select SND_SOC_CS42L51 345 select SND_SOC_CS42L51
341 346
342config SND_SOC_CS42L52 347config SND_SOC_CS42L52
@@ -370,8 +375,19 @@ config SND_SOC_CS4270_VD33_ERRATA
370 depends on SND_SOC_CS4270 375 depends on SND_SOC_CS4270
371 376
372config SND_SOC_CS4271 377config SND_SOC_CS4271
373 tristate "Cirrus Logic CS4271 CODEC" 378 tristate
374 depends on SND_SOC_I2C_AND_SPI 379
380config SND_SOC_CS4271_I2C
381 tristate "Cirrus Logic CS4271 CODEC (I2C)"
382 depends on I2C
383 select SND_SOC_CS4271
384 select REGMAP_I2C
385
386config SND_SOC_CS4271_SPI
387 tristate "Cirrus Logic CS4271 CODEC (SPI)"
388 depends on SPI_MASTER
389 select SND_SOC_CS4271
390 select REGMAP_SPI
375 391
376config SND_SOC_CS42XX8 392config SND_SOC_CS42XX8
377 tristate 393 tristate
@@ -487,7 +503,8 @@ config SND_SOC_RT286
487 depends on I2C 503 depends on I2C
488 504
489config SND_SOC_RT5631 505config SND_SOC_RT5631
490 tristate 506 tristate "Realtek ALC5631/RT5631 CODEC"
507 depends on I2C
491 508
492config SND_SOC_RT5640 509config SND_SOC_RT5640
493 tristate 510 tristate
@@ -504,6 +521,10 @@ config SND_SOC_RT5670
504config SND_SOC_RT5677 521config SND_SOC_RT5677
505 tristate 522 tristate
506 523
524config SND_SOC_RT5677_SPI
525 tristate
526 default SND_SOC_RT5677
527
507#Freescale sgtl5000 codec 528#Freescale sgtl5000 codec
508config SND_SOC_SGTL5000 529config SND_SOC_SGTL5000
509 tristate "Freescale SGTL5000 CODEC" 530 tristate "Freescale SGTL5000 CODEC"
@@ -577,15 +598,21 @@ config SND_SOC_TAS5086
577 tristate "Texas Instruments TAS5086 speaker amplifier" 598 tristate "Texas Instruments TAS5086 speaker amplifier"
578 depends on I2C 599 depends on I2C
579 600
601config SND_SOC_TFA9879
602 tristate "NXP Semiconductors TFA9879 amplifier"
603 depends on I2C
604
580config SND_SOC_TLV320AIC23 605config SND_SOC_TLV320AIC23
581 tristate 606 tristate
582 607
583config SND_SOC_TLV320AIC23_I2C 608config SND_SOC_TLV320AIC23_I2C
584 tristate 609 tristate "Texas Instruments TLV320AIC23 audio CODEC - I2C"
610 depends on I2C
585 select SND_SOC_TLV320AIC23 611 select SND_SOC_TLV320AIC23
586 612
587config SND_SOC_TLV320AIC23_SPI 613config SND_SOC_TLV320AIC23_SPI
588 tristate 614 tristate "Texas Instruments TLV320AIC23 audio CODEC - SPI"
615 depends on SPI_MASTER
589 select SND_SOC_TLV320AIC23 616 select SND_SOC_TLV320AIC23
590 617
591config SND_SOC_TLV320AIC26 618config SND_SOC_TLV320AIC26
@@ -607,6 +634,10 @@ config SND_SOC_TLV320AIC3X
607config SND_SOC_TLV320DAC33 634config SND_SOC_TLV320DAC33
608 tristate 635 tristate
609 636
637config SND_SOC_TS3A227E
638 tristate "TI Headset/Mic detect and keypress chip"
639 depends on I2C
640
610config SND_SOC_TWL4030 641config SND_SOC_TWL4030
611 select MFD_TWL4030_AUDIO 642 select MFD_TWL4030_AUDIO
612 tristate 643 tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 5dce451661e4..bbdfd1e1c182 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -41,6 +41,8 @@ snd-soc-cs42l73-objs := cs42l73.o
41snd-soc-cs4265-objs := cs4265.o 41snd-soc-cs4265-objs := cs4265.o
42snd-soc-cs4270-objs := cs4270.o 42snd-soc-cs4270-objs := cs4270.o
43snd-soc-cs4271-objs := cs4271.o 43snd-soc-cs4271-objs := cs4271.o
44snd-soc-cs4271-i2c-objs := cs4271-i2c.o
45snd-soc-cs4271-spi-objs := cs4271-spi.o
44snd-soc-cs42xx8-objs := cs42xx8.o 46snd-soc-cs42xx8-objs := cs42xx8.o
45snd-soc-cs42xx8-i2c-objs := cs42xx8-i2c.o 47snd-soc-cs42xx8-i2c-objs := cs42xx8-i2c.o
46snd-soc-cx20442-objs := cx20442.o 48snd-soc-cx20442-objs := cx20442.o
@@ -80,6 +82,7 @@ snd-soc-rt5645-objs := rt5645.o
80snd-soc-rt5651-objs := rt5651.o 82snd-soc-rt5651-objs := rt5651.o
81snd-soc-rt5670-objs := rt5670.o 83snd-soc-rt5670-objs := rt5670.o
82snd-soc-rt5677-objs := rt5677.o 84snd-soc-rt5677-objs := rt5677.o
85snd-soc-rt5677-spi-objs := rt5677-spi.o
83snd-soc-sgtl5000-objs := sgtl5000.o 86snd-soc-sgtl5000-objs := sgtl5000.o
84snd-soc-alc5623-objs := alc5623.o 87snd-soc-alc5623-objs := alc5623.o
85snd-soc-alc5632-objs := alc5632.o 88snd-soc-alc5632-objs := alc5632.o
@@ -101,6 +104,7 @@ snd-soc-sta350-objs := sta350.o
101snd-soc-sta529-objs := sta529.o 104snd-soc-sta529-objs := sta529.o
102snd-soc-stac9766-objs := stac9766.o 105snd-soc-stac9766-objs := stac9766.o
103snd-soc-tas5086-objs := tas5086.o 106snd-soc-tas5086-objs := tas5086.o
107snd-soc-tfa9879-objs := tfa9879.o
104snd-soc-tlv320aic23-objs := tlv320aic23.o 108snd-soc-tlv320aic23-objs := tlv320aic23.o
105snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o 109snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o
106snd-soc-tlv320aic23-spi-objs := tlv320aic23-spi.o 110snd-soc-tlv320aic23-spi-objs := tlv320aic23-spi.o
@@ -109,6 +113,7 @@ snd-soc-tlv320aic31xx-objs := tlv320aic31xx.o
109snd-soc-tlv320aic32x4-objs := tlv320aic32x4.o 113snd-soc-tlv320aic32x4-objs := tlv320aic32x4.o
110snd-soc-tlv320aic3x-objs := tlv320aic3x.o 114snd-soc-tlv320aic3x-objs := tlv320aic3x.o
111snd-soc-tlv320dac33-objs := tlv320dac33.o 115snd-soc-tlv320dac33-objs := tlv320dac33.o
116snd-soc-ts3a227e-objs := ts3a227e.o
112snd-soc-twl4030-objs := twl4030.o 117snd-soc-twl4030-objs := twl4030.o
113snd-soc-twl6040-objs := twl6040.o 118snd-soc-twl6040-objs := twl6040.o
114snd-soc-uda134x-objs := uda134x.o 119snd-soc-uda134x-objs := uda134x.o
@@ -217,6 +222,8 @@ obj-$(CONFIG_SND_SOC_CS42L73) += snd-soc-cs42l73.o
217obj-$(CONFIG_SND_SOC_CS4265) += snd-soc-cs4265.o 222obj-$(CONFIG_SND_SOC_CS4265) += snd-soc-cs4265.o
218obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 223obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
219obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o 224obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o
225obj-$(CONFIG_SND_SOC_CS4271_I2C) += snd-soc-cs4271-i2c.o
226obj-$(CONFIG_SND_SOC_CS4271_SPI) += snd-soc-cs4271-spi.o
220obj-$(CONFIG_SND_SOC_CS42XX8) += snd-soc-cs42xx8.o 227obj-$(CONFIG_SND_SOC_CS42XX8) += snd-soc-cs42xx8.o
221obj-$(CONFIG_SND_SOC_CS42XX8_I2C) += snd-soc-cs42xx8-i2c.o 228obj-$(CONFIG_SND_SOC_CS42XX8_I2C) += snd-soc-cs42xx8-i2c.o
222obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o 229obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o
@@ -256,6 +263,7 @@ obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o
256obj-$(CONFIG_SND_SOC_RT5651) += snd-soc-rt5651.o 263obj-$(CONFIG_SND_SOC_RT5651) += snd-soc-rt5651.o
257obj-$(CONFIG_SND_SOC_RT5670) += snd-soc-rt5670.o 264obj-$(CONFIG_SND_SOC_RT5670) += snd-soc-rt5670.o
258obj-$(CONFIG_SND_SOC_RT5677) += snd-soc-rt5677.o 265obj-$(CONFIG_SND_SOC_RT5677) += snd-soc-rt5677.o
266obj-$(CONFIG_SND_SOC_RT5677_SPI) += snd-soc-rt5677-spi.o
259obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o 267obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
260obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o 268obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o
261obj-$(CONFIG_SND_SOC_SIGMADSP_I2C) += snd-soc-sigmadsp-i2c.o 269obj-$(CONFIG_SND_SOC_SIGMADSP_I2C) += snd-soc-sigmadsp-i2c.o
@@ -274,6 +282,7 @@ obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o
274obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o 282obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
275obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o 283obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o
276obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o 284obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o
285obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o
277obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o 286obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
278obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o 287obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o
279obj-$(CONFIG_SND_SOC_TLV320AIC23_SPI) += snd-soc-tlv320aic23-spi.o 288obj-$(CONFIG_SND_SOC_TLV320AIC23_SPI) += snd-soc-tlv320aic23-spi.o
@@ -282,6 +291,7 @@ obj-$(CONFIG_SND_SOC_TLV320AIC31XX) += snd-soc-tlv320aic31xx.o
282obj-$(CONFIG_SND_SOC_TLV320AIC32X4) += snd-soc-tlv320aic32x4.o 291obj-$(CONFIG_SND_SOC_TLV320AIC32X4) += snd-soc-tlv320aic32x4.o
283obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o 292obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
284obj-$(CONFIG_SND_SOC_TLV320DAC33) += snd-soc-tlv320dac33.o 293obj-$(CONFIG_SND_SOC_TLV320DAC33) += snd-soc-tlv320dac33.o
294obj-$(CONFIG_SND_SOC_TS3A227E) += snd-soc-ts3a227e.o
285obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o 295obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o
286obj-$(CONFIG_SND_SOC_TWL6040) += snd-soc-twl6040.o 296obj-$(CONFIG_SND_SOC_TWL6040) += snd-soc-twl6040.o
287obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o 297obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o
diff --git a/sound/soc/codecs/ab8500-codec.c b/sound/soc/codecs/ab8500-codec.c
index fd43827bb856..7dfbc9921e91 100644
--- a/sound/soc/codecs/ab8500-codec.c
+++ b/sound/soc/codecs/ab8500-codec.c
@@ -126,13 +126,13 @@ struct ab8500_codec_drvdata_dbg {
126/* Private data for AB8500 device-driver */ 126/* Private data for AB8500 device-driver */
127struct ab8500_codec_drvdata { 127struct ab8500_codec_drvdata {
128 struct regmap *regmap; 128 struct regmap *regmap;
129 struct mutex ctrl_lock;
129 130
130 /* Sidetone */ 131 /* Sidetone */
131 long *sid_fir_values; 132 long *sid_fir_values;
132 enum sid_state sid_status; 133 enum sid_state sid_status;
133 134
134 /* ANC */ 135 /* ANC */
135 struct mutex anc_lock;
136 long *anc_fir_values; 136 long *anc_fir_values;
137 long *anc_iir_values; 137 long *anc_iir_values;
138 enum anc_state anc_status; 138 enum anc_state anc_status;
@@ -1129,9 +1129,9 @@ static int sid_status_control_get(struct snd_kcontrol *kcontrol,
1129 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 1129 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1130 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev); 1130 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
1131 1131
1132 mutex_lock(&codec->mutex); 1132 mutex_lock(&drvdata->ctrl_lock);
1133 ucontrol->value.integer.value[0] = drvdata->sid_status; 1133 ucontrol->value.integer.value[0] = drvdata->sid_status;
1134 mutex_unlock(&codec->mutex); 1134 mutex_unlock(&drvdata->ctrl_lock);
1135 1135
1136 return 0; 1136 return 0;
1137} 1137}
@@ -1154,7 +1154,7 @@ static int sid_status_control_put(struct snd_kcontrol *kcontrol,
1154 return -EIO; 1154 return -EIO;
1155 } 1155 }
1156 1156
1157 mutex_lock(&codec->mutex); 1157 mutex_lock(&drvdata->ctrl_lock);
1158 1158
1159 sidconf = snd_soc_read(codec, AB8500_SIDFIRCONF); 1159 sidconf = snd_soc_read(codec, AB8500_SIDFIRCONF);
1160 if (((sidconf & BIT(AB8500_SIDFIRCONF_FIRSIDBUSY)) != 0)) { 1160 if (((sidconf & BIT(AB8500_SIDFIRCONF_FIRSIDBUSY)) != 0)) {
@@ -1185,7 +1185,7 @@ static int sid_status_control_put(struct snd_kcontrol *kcontrol,
1185 drvdata->sid_status = SID_FIR_CONFIGURED; 1185 drvdata->sid_status = SID_FIR_CONFIGURED;
1186 1186
1187out: 1187out:
1188 mutex_unlock(&codec->mutex); 1188 mutex_unlock(&drvdata->ctrl_lock);
1189 1189
1190 dev_dbg(codec->dev, "%s: Exit\n", __func__); 1190 dev_dbg(codec->dev, "%s: Exit\n", __func__);
1191 1191
@@ -1198,9 +1198,9 @@ static int anc_status_control_get(struct snd_kcontrol *kcontrol,
1198 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 1198 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1199 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev); 1199 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
1200 1200
1201 mutex_lock(&codec->mutex); 1201 mutex_lock(&drvdata->ctrl_lock);
1202 ucontrol->value.integer.value[0] = drvdata->anc_status; 1202 ucontrol->value.integer.value[0] = drvdata->anc_status;
1203 mutex_unlock(&codec->mutex); 1203 mutex_unlock(&drvdata->ctrl_lock);
1204 1204
1205 return 0; 1205 return 0;
1206} 1206}
@@ -1217,7 +1217,7 @@ static int anc_status_control_put(struct snd_kcontrol *kcontrol,
1217 1217
1218 dev_dbg(dev, "%s: Enter.\n", __func__); 1218 dev_dbg(dev, "%s: Enter.\n", __func__);
1219 1219
1220 mutex_lock(&drvdata->anc_lock); 1220 mutex_lock(&drvdata->ctrl_lock);
1221 1221
1222 req = ucontrol->value.integer.value[0]; 1222 req = ucontrol->value.integer.value[0];
1223 if (req >= ARRAY_SIZE(enum_anc_state)) { 1223 if (req >= ARRAY_SIZE(enum_anc_state)) {
@@ -1244,9 +1244,7 @@ static int anc_status_control_put(struct snd_kcontrol *kcontrol,
1244 } 1244 }
1245 snd_soc_dapm_sync(&codec->dapm); 1245 snd_soc_dapm_sync(&codec->dapm);
1246 1246
1247 mutex_lock(&codec->mutex);
1248 anc_configure(codec, apply_fir, apply_iir); 1247 anc_configure(codec, apply_fir, apply_iir);
1249 mutex_unlock(&codec->mutex);
1250 1248
1251 if (apply_fir) { 1249 if (apply_fir) {
1252 if (drvdata->anc_status == ANC_IIR_CONFIGURED) 1250 if (drvdata->anc_status == ANC_IIR_CONFIGURED)
@@ -1265,7 +1263,7 @@ static int anc_status_control_put(struct snd_kcontrol *kcontrol,
1265 snd_soc_dapm_sync(&codec->dapm); 1263 snd_soc_dapm_sync(&codec->dapm);
1266 1264
1267cleanup: 1265cleanup:
1268 mutex_unlock(&drvdata->anc_lock); 1266 mutex_unlock(&drvdata->ctrl_lock);
1269 1267
1270 if (status < 0) 1268 if (status < 0)
1271 dev_err(dev, "%s: Unable to configure ANC! (status = %d)\n", 1269 dev_err(dev, "%s: Unable to configure ANC! (status = %d)\n",
@@ -1294,14 +1292,15 @@ static int filter_control_get(struct snd_kcontrol *kcontrol,
1294 struct snd_ctl_elem_value *ucontrol) 1292 struct snd_ctl_elem_value *ucontrol)
1295{ 1293{
1296 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 1294 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1295 struct ab8500_codec_drvdata *drvdata = snd_soc_codec_get_drvdata(codec);
1297 struct filter_control *fc = 1296 struct filter_control *fc =
1298 (struct filter_control *)kcontrol->private_value; 1297 (struct filter_control *)kcontrol->private_value;
1299 unsigned int i; 1298 unsigned int i;
1300 1299
1301 mutex_lock(&codec->mutex); 1300 mutex_lock(&drvdata->ctrl_lock);
1302 for (i = 0; i < fc->count; i++) 1301 for (i = 0; i < fc->count; i++)
1303 ucontrol->value.integer.value[i] = fc->value[i]; 1302 ucontrol->value.integer.value[i] = fc->value[i];
1304 mutex_unlock(&codec->mutex); 1303 mutex_unlock(&drvdata->ctrl_lock);
1305 1304
1306 return 0; 1305 return 0;
1307} 1306}
@@ -1310,14 +1309,15 @@ static int filter_control_put(struct snd_kcontrol *kcontrol,
1310 struct snd_ctl_elem_value *ucontrol) 1309 struct snd_ctl_elem_value *ucontrol)
1311{ 1310{
1312 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 1311 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1312 struct ab8500_codec_drvdata *drvdata = snd_soc_codec_get_drvdata(codec);
1313 struct filter_control *fc = 1313 struct filter_control *fc =
1314 (struct filter_control *)kcontrol->private_value; 1314 (struct filter_control *)kcontrol->private_value;
1315 unsigned int i; 1315 unsigned int i;
1316 1316
1317 mutex_lock(&codec->mutex); 1317 mutex_lock(&drvdata->ctrl_lock);
1318 for (i = 0; i < fc->count; i++) 1318 for (i = 0; i < fc->count; i++)
1319 fc->value[i] = ucontrol->value.integer.value[i]; 1319 fc->value[i] = ucontrol->value.integer.value[i];
1320 mutex_unlock(&codec->mutex); 1320 mutex_unlock(&drvdata->ctrl_lock);
1321 1321
1322 return 0; 1322 return 0;
1323} 1323}
@@ -2545,7 +2545,7 @@ static int ab8500_codec_probe(struct snd_soc_codec *codec)
2545 2545
2546 (void)snd_soc_dapm_disable_pin(&codec->dapm, "ANC Configure Input"); 2546 (void)snd_soc_dapm_disable_pin(&codec->dapm, "ANC Configure Input");
2547 2547
2548 mutex_init(&drvdata->anc_lock); 2548 mutex_init(&drvdata->ctrl_lock);
2549 2549
2550 return status; 2550 return status;
2551} 2551}
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index bd9b1839c8b0..c6e5a313ebf4 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -37,10 +37,11 @@ static int ac97_prepare(struct snd_pcm_substream *substream,
37 struct snd_soc_dai *dai) 37 struct snd_soc_dai *dai)
38{ 38{
39 struct snd_soc_codec *codec = dai->codec; 39 struct snd_soc_codec *codec = dai->codec;
40 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
40 41
41 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 42 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
42 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; 43 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
43 return snd_ac97_set_rate(codec->ac97, reg, substream->runtime->rate); 44 return snd_ac97_set_rate(ac97, reg, substream->runtime->rate);
44} 45}
45 46
46#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 47#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
@@ -53,7 +54,6 @@ static const struct snd_soc_dai_ops ac97_dai_ops = {
53 54
54static struct snd_soc_dai_driver ac97_dai = { 55static struct snd_soc_dai_driver ac97_dai = {
55 .name = "ac97-hifi", 56 .name = "ac97-hifi",
56 .ac97_control = 1,
57 .playback = { 57 .playback = {
58 .stream_name = "AC97 Playback", 58 .stream_name = "AC97 Playback",
59 .channels_min = 1, 59 .channels_min = 1,
@@ -71,6 +71,7 @@ static struct snd_soc_dai_driver ac97_dai = {
71 71
72static int ac97_soc_probe(struct snd_soc_codec *codec) 72static int ac97_soc_probe(struct snd_soc_codec *codec)
73{ 73{
74 struct snd_ac97 *ac97;
74 struct snd_ac97_bus *ac97_bus; 75 struct snd_ac97_bus *ac97_bus;
75 struct snd_ac97_template ac97_template; 76 struct snd_ac97_template ac97_template;
76 int ret; 77 int ret;
@@ -82,24 +83,31 @@ static int ac97_soc_probe(struct snd_soc_codec *codec)
82 return ret; 83 return ret;
83 84
84 memset(&ac97_template, 0, sizeof(struct snd_ac97_template)); 85 memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
85 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97); 86 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &ac97);
86 if (ret < 0) 87 if (ret < 0)
87 return ret; 88 return ret;
88 89
90 snd_soc_codec_set_drvdata(codec, ac97);
91
89 return 0; 92 return 0;
90} 93}
91 94
92#ifdef CONFIG_PM 95#ifdef CONFIG_PM
93static int ac97_soc_suspend(struct snd_soc_codec *codec) 96static int ac97_soc_suspend(struct snd_soc_codec *codec)
94{ 97{
95 snd_ac97_suspend(codec->ac97); 98 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
99
100 snd_ac97_suspend(ac97);
96 101
97 return 0; 102 return 0;
98} 103}
99 104
100static int ac97_soc_resume(struct snd_soc_codec *codec) 105static int ac97_soc_resume(struct snd_soc_codec *codec)
101{ 106{
102 snd_ac97_resume(codec->ac97); 107
108 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
109
110 snd_ac97_resume(ac97);
103 111
104 return 0; 112 return 0;
105} 113}
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c
index 6844d0b2af68..387530b0b0fd 100644
--- a/sound/soc/codecs/ad193x.c
+++ b/sound/soc/codecs/ad193x.c
@@ -72,11 +72,13 @@ static const struct snd_kcontrol_new ad193x_snd_controls[] = {
72}; 72};
73 73
74static const struct snd_soc_dapm_widget ad193x_dapm_widgets[] = { 74static const struct snd_soc_dapm_widget ad193x_dapm_widgets[] = {
75 SND_SOC_DAPM_DAC("DAC", "Playback", AD193X_DAC_CTRL0, 0, 1), 75 SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
76 SND_SOC_DAPM_PGA("DAC Output", AD193X_DAC_CTRL0, 0, 1, NULL, 0),
76 SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0), 77 SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0),
77 SND_SOC_DAPM_SUPPLY("PLL_PWR", AD193X_PLL_CLK_CTRL0, 0, 1, NULL, 0), 78 SND_SOC_DAPM_SUPPLY("PLL_PWR", AD193X_PLL_CLK_CTRL0, 0, 1, NULL, 0),
78 SND_SOC_DAPM_SUPPLY("ADC_PWR", AD193X_ADC_CTRL0, 0, 1, NULL, 0), 79 SND_SOC_DAPM_SUPPLY("ADC_PWR", AD193X_ADC_CTRL0, 0, 1, NULL, 0),
79 SND_SOC_DAPM_SUPPLY("SYSCLK", AD193X_PLL_CLK_CTRL0, 7, 0, NULL, 0), 80 SND_SOC_DAPM_SUPPLY("SYSCLK", AD193X_PLL_CLK_CTRL0, 7, 0, NULL, 0),
81 SND_SOC_DAPM_VMID("VMID"),
80 SND_SOC_DAPM_OUTPUT("DAC1OUT"), 82 SND_SOC_DAPM_OUTPUT("DAC1OUT"),
81 SND_SOC_DAPM_OUTPUT("DAC2OUT"), 83 SND_SOC_DAPM_OUTPUT("DAC2OUT"),
82 SND_SOC_DAPM_OUTPUT("DAC3OUT"), 84 SND_SOC_DAPM_OUTPUT("DAC3OUT"),
@@ -87,13 +89,15 @@ static const struct snd_soc_dapm_widget ad193x_dapm_widgets[] = {
87 89
88static const struct snd_soc_dapm_route audio_paths[] = { 90static const struct snd_soc_dapm_route audio_paths[] = {
89 { "DAC", NULL, "SYSCLK" }, 91 { "DAC", NULL, "SYSCLK" },
92 { "DAC Output", NULL, "DAC" },
93 { "DAC Output", NULL, "VMID" },
90 { "ADC", NULL, "SYSCLK" }, 94 { "ADC", NULL, "SYSCLK" },
91 { "DAC", NULL, "ADC_PWR" }, 95 { "DAC", NULL, "ADC_PWR" },
92 { "ADC", NULL, "ADC_PWR" }, 96 { "ADC", NULL, "ADC_PWR" },
93 { "DAC1OUT", NULL, "DAC" }, 97 { "DAC1OUT", NULL, "DAC Output" },
94 { "DAC2OUT", NULL, "DAC" }, 98 { "DAC2OUT", NULL, "DAC Output" },
95 { "DAC3OUT", NULL, "DAC" }, 99 { "DAC3OUT", NULL, "DAC Output" },
96 { "DAC4OUT", NULL, "DAC" }, 100 { "DAC4OUT", NULL, "DAC Output" },
97 { "ADC", NULL, "ADC1IN" }, 101 { "ADC", NULL, "ADC1IN" },
98 { "ADC", NULL, "ADC2IN" }, 102 { "ADC", NULL, "ADC2IN" },
99 { "SYSCLK", NULL, "PLL_PWR" }, 103 { "SYSCLK", NULL, "PLL_PWR" },
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index 304d3003339a..2860eef8610c 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -24,34 +24,86 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/regmap.h>
27#include <sound/core.h> 28#include <sound/core.h>
28#include <sound/pcm.h> 29#include <sound/pcm.h>
29#include <sound/ac97_codec.h> 30#include <sound/ac97_codec.h>
30#include <sound/initval.h> 31#include <sound/initval.h>
31#include <sound/soc.h> 32#include <sound/soc.h>
32 33
33#include "ad1980.h" 34static const struct reg_default ad1980_reg_defaults[] = {
35 { 0x02, 0x8000 },
36 { 0x04, 0x8000 },
37 { 0x06, 0x8000 },
38 { 0x0c, 0x8008 },
39 { 0x0e, 0x8008 },
40 { 0x10, 0x8808 },
41 { 0x12, 0x8808 },
42 { 0x16, 0x8808 },
43 { 0x18, 0x8808 },
44 { 0x1a, 0x0000 },
45 { 0x1c, 0x8000 },
46 { 0x20, 0x0000 },
47 { 0x28, 0x03c7 },
48 { 0x2c, 0xbb80 },
49 { 0x2e, 0xbb80 },
50 { 0x30, 0xbb80 },
51 { 0x32, 0xbb80 },
52 { 0x36, 0x8080 },
53 { 0x38, 0x8080 },
54 { 0x3a, 0x2000 },
55 { 0x60, 0x0000 },
56 { 0x62, 0x0000 },
57 { 0x72, 0x0000 },
58 { 0x74, 0x1001 },
59 { 0x76, 0x0000 },
60};
34 61
35/* 62static bool ad1980_readable_reg(struct device *dev, unsigned int reg)
36 * AD1980 register cache 63{
37 */ 64 switch (reg) {
38static const u16 ad1980_reg[] = { 65 case AC97_RESET ... AC97_MASTER_MONO:
39 0x0090, 0x8000, 0x8000, 0x8000, /* 0 - 6 */ 66 case AC97_PHONE ... AC97_CD:
40 0x0000, 0x0000, 0x8008, 0x8008, /* 8 - e */ 67 case AC97_AUX ... AC97_GENERAL_PURPOSE:
41 0x8808, 0x8808, 0x0000, 0x8808, /* 10 - 16 */ 68 case AC97_POWERDOWN ... AC97_PCM_LR_ADC_RATE:
42 0x8808, 0x0000, 0x8000, 0x0000, /* 18 - 1e */ 69 case AC97_SPDIF:
43 0x0000, 0x0000, 0x0000, 0x0000, /* 20 - 26 */ 70 case AC97_CODEC_CLASS_REV:
44 0x03c7, 0x0000, 0xbb80, 0xbb80, /* 28 - 2e */ 71 case AC97_PCI_SVID:
45 0xbb80, 0xbb80, 0x0000, 0x8080, /* 30 - 36 */ 72 case AC97_AD_CODEC_CFG:
46 0x8080, 0x2000, 0x0000, 0x0000, /* 38 - 3e */ 73 case AC97_AD_JACK_SPDIF:
47 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */ 74 case AC97_AD_SERIAL_CFG:
48 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */ 75 case AC97_VENDOR_ID1:
49 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */ 76 case AC97_VENDOR_ID2:
50 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */ 77 return true;
51 0x8080, 0x0000, 0x0000, 0x0000, /* 60 - 66 */ 78 default:
52 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */ 79 return false;
53 0x0000, 0x0000, 0x1001, 0x0000, /* 70 - 76 */ 80 }
54 0x0000, 0x0000, 0x4144, 0x5370 /* 78 - 7e */ 81}
82
83static bool ad1980_writeable_reg(struct device *dev, unsigned int reg)
84{
85 switch (reg) {
86 case AC97_VENDOR_ID1:
87 case AC97_VENDOR_ID2:
88 return false;
89 default:
90 return ad1980_readable_reg(dev, reg);
91 }
92}
93
94static const struct regmap_config ad1980_regmap_config = {
95 .reg_bits = 16,
96 .reg_stride = 2,
97 .val_bits = 16,
98 .max_register = 0x7e,
99 .cache_type = REGCACHE_RBTREE,
100
101 .volatile_reg = regmap_ac97_default_volatile,
102 .readable_reg = ad1980_readable_reg,
103 .writeable_reg = ad1980_writeable_reg,
104
105 .reg_defaults = ad1980_reg_defaults,
106 .num_reg_defaults = ARRAY_SIZE(ad1980_reg_defaults),
55}; 107};
56 108
57static const char *ad1980_rec_sel[] = {"Mic", "CD", "NC", "AUX", "Line", 109static const char *ad1980_rec_sel[] = {"Mic", "CD", "NC", "AUX", "Line",
@@ -134,45 +186,8 @@ static const struct snd_soc_dapm_route ad1980_dapm_routes[] = {
134 { "HP_OUT_R", NULL, "Playback" }, 186 { "HP_OUT_R", NULL, "Playback" },
135}; 187};
136 188
137static unsigned int ac97_read(struct snd_soc_codec *codec,
138 unsigned int reg)
139{
140 u16 *cache = codec->reg_cache;
141
142 switch (reg) {
143 case AC97_RESET:
144 case AC97_INT_PAGING:
145 case AC97_POWERDOWN:
146 case AC97_EXTENDED_STATUS:
147 case AC97_VENDOR_ID1:
148 case AC97_VENDOR_ID2:
149 return soc_ac97_ops->read(codec->ac97, reg);
150 default:
151 reg = reg >> 1;
152
153 if (reg >= ARRAY_SIZE(ad1980_reg))
154 return -EINVAL;
155
156 return cache[reg];
157 }
158}
159
160static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
161 unsigned int val)
162{
163 u16 *cache = codec->reg_cache;
164
165 soc_ac97_ops->write(codec->ac97, reg, val);
166 reg = reg >> 1;
167 if (reg < ARRAY_SIZE(ad1980_reg))
168 cache[reg] = val;
169
170 return 0;
171}
172
173static struct snd_soc_dai_driver ad1980_dai = { 189static struct snd_soc_dai_driver ad1980_dai = {
174 .name = "ad1980-hifi", 190 .name = "ad1980-hifi",
175 .ac97_control = 1,
176 .playback = { 191 .playback = {
177 .stream_name = "Playback", 192 .stream_name = "Playback",
178 .channels_min = 2, 193 .channels_min = 2,
@@ -189,108 +204,115 @@ static struct snd_soc_dai_driver ad1980_dai = {
189 204
190static int ad1980_reset(struct snd_soc_codec *codec, int try_warm) 205static int ad1980_reset(struct snd_soc_codec *codec, int try_warm)
191{ 206{
207 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
192 unsigned int retry_cnt = 0; 208 unsigned int retry_cnt = 0;
193 209
194 do { 210 do {
195 if (try_warm && soc_ac97_ops->warm_reset) { 211 if (try_warm && soc_ac97_ops->warm_reset) {
196 soc_ac97_ops->warm_reset(codec->ac97); 212 soc_ac97_ops->warm_reset(ac97);
197 if (ac97_read(codec, AC97_RESET) == 0x0090) 213 if (snd_soc_read(codec, AC97_RESET) == 0x0090)
198 return 1; 214 return 1;
199 } 215 }
200 216
201 soc_ac97_ops->reset(codec->ac97); 217 soc_ac97_ops->reset(ac97);
202 /* 218 /*
203 * Set bit 16slot in register 74h, then every slot will has only 219 * Set bit 16slot in register 74h, then every slot will has only
204 * 16 bits. This command is sent out in 20bit mode, in which 220 * 16 bits. This command is sent out in 20bit mode, in which
205 * case the first nibble of data is eaten by the addr. (Tag is 221 * case the first nibble of data is eaten by the addr. (Tag is
206 * always 16 bit) 222 * always 16 bit)
207 */ 223 */
208 ac97_write(codec, AC97_AD_SERIAL_CFG, 0x9900); 224 snd_soc_write(codec, AC97_AD_SERIAL_CFG, 0x9900);
209 225
210 if (ac97_read(codec, AC97_RESET) == 0x0090) 226 if (snd_soc_read(codec, AC97_RESET) == 0x0090)
211 return 0; 227 return 0;
212 } while (retry_cnt++ < 10); 228 } while (retry_cnt++ < 10);
213 229
214 printk(KERN_ERR "AD1980 AC97 reset failed\n"); 230 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
231
215 return -EIO; 232 return -EIO;
216} 233}
217 234
218static int ad1980_soc_probe(struct snd_soc_codec *codec) 235static int ad1980_soc_probe(struct snd_soc_codec *codec)
219{ 236{
237 struct snd_ac97 *ac97;
238 struct regmap *regmap;
220 int ret; 239 int ret;
221 u16 vendor_id2; 240 u16 vendor_id2;
222 u16 ext_status; 241 u16 ext_status;
223 242
224 printk(KERN_INFO "AD1980 SoC Audio Codec\n"); 243 ac97 = snd_soc_new_ac97_codec(codec);
225 244 if (IS_ERR(ac97)) {
226 ret = snd_soc_new_ac97_codec(codec, soc_ac97_ops, 0); 245 ret = PTR_ERR(ac97);
227 if (ret < 0) { 246 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret);
228 printk(KERN_ERR "ad1980: failed to register AC97 codec\n");
229 return ret; 247 return ret;
230 } 248 }
231 249
250 regmap = regmap_init_ac97(ac97, &ad1980_regmap_config);
251 if (IS_ERR(regmap)) {
252 ret = PTR_ERR(regmap);
253 goto err_free_ac97;
254 }
255
256 snd_soc_codec_init_regmap(codec, regmap);
257 snd_soc_codec_set_drvdata(codec, ac97);
258
232 ret = ad1980_reset(codec, 0); 259 ret = ad1980_reset(codec, 0);
233 if (ret < 0) { 260 if (ret < 0)
234 printk(KERN_ERR "Failed to reset AD1980: AC97 link error\n");
235 goto reset_err; 261 goto reset_err;
236 }
237 262
238 /* Read out vendor ID to make sure it is ad1980 */ 263 /* Read out vendor ID to make sure it is ad1980 */
239 if (ac97_read(codec, AC97_VENDOR_ID1) != 0x4144) { 264 if (snd_soc_read(codec, AC97_VENDOR_ID1) != 0x4144) {
240 ret = -ENODEV; 265 ret = -ENODEV;
241 goto reset_err; 266 goto reset_err;
242 } 267 }
243 268
244 vendor_id2 = ac97_read(codec, AC97_VENDOR_ID2); 269 vendor_id2 = snd_soc_read(codec, AC97_VENDOR_ID2);
245 270
246 if (vendor_id2 != 0x5370) { 271 if (vendor_id2 != 0x5370) {
247 if (vendor_id2 != 0x5374) { 272 if (vendor_id2 != 0x5374) {
248 ret = -ENODEV; 273 ret = -ENODEV;
249 goto reset_err; 274 goto reset_err;
250 } else { 275 } else {
251 printk(KERN_WARNING "ad1980: " 276 dev_warn(codec->dev,
252 "Found AD1981 - only 2/2 IN/OUT Channels " 277 "Found AD1981 - only 2/2 IN/OUT Channels supported\n");
253 "supported\n");
254 } 278 }
255 } 279 }
256 280
257 /* unmute captures and playbacks volume */ 281 /* unmute captures and playbacks volume */
258 ac97_write(codec, AC97_MASTER, 0x0000); 282 snd_soc_write(codec, AC97_MASTER, 0x0000);
259 ac97_write(codec, AC97_PCM, 0x0000); 283 snd_soc_write(codec, AC97_PCM, 0x0000);
260 ac97_write(codec, AC97_REC_GAIN, 0x0000); 284 snd_soc_write(codec, AC97_REC_GAIN, 0x0000);
261 ac97_write(codec, AC97_CENTER_LFE_MASTER, 0x0000); 285 snd_soc_write(codec, AC97_CENTER_LFE_MASTER, 0x0000);
262 ac97_write(codec, AC97_SURROUND_MASTER, 0x0000); 286 snd_soc_write(codec, AC97_SURROUND_MASTER, 0x0000);
263 287
264 /*power on LFE/CENTER/Surround DACs*/ 288 /*power on LFE/CENTER/Surround DACs*/
265 ext_status = ac97_read(codec, AC97_EXTENDED_STATUS); 289 ext_status = snd_soc_read(codec, AC97_EXTENDED_STATUS);
266 ac97_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800); 290 snd_soc_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800);
267
268 snd_soc_add_codec_controls(codec, ad1980_snd_ac97_controls,
269 ARRAY_SIZE(ad1980_snd_ac97_controls));
270 291
271 return 0; 292 return 0;
272 293
273reset_err: 294reset_err:
274 snd_soc_free_ac97_codec(codec); 295 snd_soc_codec_exit_regmap(codec);
296err_free_ac97:
297 snd_soc_free_ac97_codec(ac97);
275 return ret; 298 return ret;
276} 299}
277 300
278static int ad1980_soc_remove(struct snd_soc_codec *codec) 301static int ad1980_soc_remove(struct snd_soc_codec *codec)
279{ 302{
280 snd_soc_free_ac97_codec(codec); 303 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
304
305 snd_soc_codec_exit_regmap(codec);
306 snd_soc_free_ac97_codec(ac97);
281 return 0; 307 return 0;
282} 308}
283 309
284static struct snd_soc_codec_driver soc_codec_dev_ad1980 = { 310static struct snd_soc_codec_driver soc_codec_dev_ad1980 = {
285 .probe = ad1980_soc_probe, 311 .probe = ad1980_soc_probe,
286 .remove = ad1980_soc_remove, 312 .remove = ad1980_soc_remove,
287 .reg_cache_size = ARRAY_SIZE(ad1980_reg),
288 .reg_word_size = sizeof(u16),
289 .reg_cache_default = ad1980_reg,
290 .reg_cache_step = 2,
291 .write = ac97_write,
292 .read = ac97_read,
293 313
314 .controls = ad1980_snd_ac97_controls,
315 .num_controls = ARRAY_SIZE(ad1980_snd_ac97_controls),
294 .dapm_widgets = ad1980_dapm_widgets, 316 .dapm_widgets = ad1980_dapm_widgets,
295 .num_dapm_widgets = ARRAY_SIZE(ad1980_dapm_widgets), 317 .num_dapm_widgets = ARRAY_SIZE(ad1980_dapm_widgets),
296 .dapm_routes = ad1980_dapm_routes, 318 .dapm_routes = ad1980_dapm_routes,
diff --git a/sound/soc/codecs/ad1980.h b/sound/soc/codecs/ad1980.h
deleted file mode 100644
index eb0af44ad3df..000000000000
--- a/sound/soc/codecs/ad1980.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 * ad1980.h -- ad1980 Soc Audio driver
3 *
4 * WARNING:
5 *
6 * Because Analog Devices Inc. discontinued the ad1980 sound chip since
7 * Sep. 2009, this ad1980 driver is not maintained, tested and supported
8 * by ADI now.
9 */
10
11#ifndef _AD1980_H
12#define _AD1980_H
13/* Bit definition of Power-Down Control/Status Register */
14#define ADC 0x0001
15#define DAC 0x0002
16#define ANL 0x0004
17#define REF 0x0008
18#define PR0 0x0100
19#define PR1 0x0200
20#define PR2 0x0400
21#define PR3 0x0800
22#define PR4 0x1000
23#define PR5 0x2000
24#define PR6 0x4000
25
26#endif
diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
index 7c784ad3e8b2..783dcb57043a 100644
--- a/sound/soc/codecs/adau1373.c
+++ b/sound/soc/codecs/adau1373.c
@@ -551,7 +551,7 @@ static const struct snd_kcontrol_new adau1373_drc_controls[] = {
551static int adau1373_pll_event(struct snd_soc_dapm_widget *w, 551static int adau1373_pll_event(struct snd_soc_dapm_widget *w,
552 struct snd_kcontrol *kcontrol, int event) 552 struct snd_kcontrol *kcontrol, int event)
553{ 553{
554 struct snd_soc_codec *codec = w->codec; 554 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
555 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec); 555 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
556 unsigned int pll_id = w->name[3] - '1'; 556 unsigned int pll_id = w->name[3] - '1';
557 unsigned int val; 557 unsigned int val;
@@ -823,7 +823,7 @@ static const struct snd_soc_dapm_widget adau1373_dapm_widgets[] = {
823static int adau1373_check_aif_clk(struct snd_soc_dapm_widget *source, 823static int adau1373_check_aif_clk(struct snd_soc_dapm_widget *source,
824 struct snd_soc_dapm_widget *sink) 824 struct snd_soc_dapm_widget *sink)
825{ 825{
826 struct snd_soc_codec *codec = source->codec; 826 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
827 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec); 827 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
828 unsigned int dai; 828 unsigned int dai;
829 const char *clk; 829 const char *clk;
@@ -844,7 +844,7 @@ static int adau1373_check_aif_clk(struct snd_soc_dapm_widget *source,
844static int adau1373_check_src(struct snd_soc_dapm_widget *source, 844static int adau1373_check_src(struct snd_soc_dapm_widget *source,
845 struct snd_soc_dapm_widget *sink) 845 struct snd_soc_dapm_widget *sink)
846{ 846{
847 struct snd_soc_codec *codec = source->codec; 847 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
848 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec); 848 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
849 unsigned int dai; 849 unsigned int dai;
850 850
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c
index 370b742117ef..d4e219b6b98f 100644
--- a/sound/soc/codecs/adau1701.c
+++ b/sound/soc/codecs/adau1701.c
@@ -22,9 +22,14 @@
22#include <sound/pcm_params.h> 22#include <sound/pcm_params.h>
23#include <sound/soc.h> 23#include <sound/soc.h>
24 24
25#include <asm/unaligned.h>
26
25#include "sigmadsp.h" 27#include "sigmadsp.h"
26#include "adau1701.h" 28#include "adau1701.h"
27 29
30#define ADAU1701_SAFELOAD_DATA(i) (0x0810 + (i))
31#define ADAU1701_SAFELOAD_ADDR(i) (0x0815 + (i))
32
28#define ADAU1701_DSPCTRL 0x081c 33#define ADAU1701_DSPCTRL 0x081c
29#define ADAU1701_SEROCTL 0x081e 34#define ADAU1701_SEROCTL 0x081e
30#define ADAU1701_SERICTL 0x081f 35#define ADAU1701_SERICTL 0x081f
@@ -42,6 +47,7 @@
42#define ADAU1701_DSPCTRL_CR (1 << 2) 47#define ADAU1701_DSPCTRL_CR (1 << 2)
43#define ADAU1701_DSPCTRL_DAM (1 << 3) 48#define ADAU1701_DSPCTRL_DAM (1 << 3)
44#define ADAU1701_DSPCTRL_ADM (1 << 4) 49#define ADAU1701_DSPCTRL_ADM (1 << 4)
50#define ADAU1701_DSPCTRL_IST (1 << 5)
45#define ADAU1701_DSPCTRL_SR_48 0x00 51#define ADAU1701_DSPCTRL_SR_48 0x00
46#define ADAU1701_DSPCTRL_SR_96 0x01 52#define ADAU1701_DSPCTRL_SR_96 0x01
47#define ADAU1701_DSPCTRL_SR_192 0x02 53#define ADAU1701_DSPCTRL_SR_192 0x02
@@ -102,7 +108,10 @@ struct adau1701 {
102 unsigned int pll_clkdiv; 108 unsigned int pll_clkdiv;
103 unsigned int sysclk; 109 unsigned int sysclk;
104 struct regmap *regmap; 110 struct regmap *regmap;
111 struct i2c_client *client;
105 u8 pin_config[12]; 112 u8 pin_config[12];
113
114 struct sigmadsp *sigmadsp;
106}; 115};
107 116
108static const struct snd_kcontrol_new adau1701_controls[] = { 117static const struct snd_kcontrol_new adau1701_controls[] = {
@@ -159,6 +168,7 @@ static bool adau1701_volatile_reg(struct device *dev, unsigned int reg)
159{ 168{
160 switch (reg) { 169 switch (reg) {
161 case ADAU1701_DACSET: 170 case ADAU1701_DACSET:
171 case ADAU1701_DSPCTRL:
162 return true; 172 return true;
163 default: 173 default:
164 return false; 174 return false;
@@ -238,12 +248,58 @@ static int adau1701_reg_read(void *context, unsigned int reg,
238 return 0; 248 return 0;
239} 249}
240 250
241static int adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv) 251static int adau1701_safeload(struct sigmadsp *sigmadsp, unsigned int addr,
252 const uint8_t bytes[], size_t len)
253{
254 struct i2c_client *client = to_i2c_client(sigmadsp->dev);
255 struct adau1701 *adau1701 = i2c_get_clientdata(client);
256 unsigned int val;
257 unsigned int i;
258 uint8_t buf[10];
259 int ret;
260
261 ret = regmap_read(adau1701->regmap, ADAU1701_DSPCTRL, &val);
262 if (ret)
263 return ret;
264
265 if (val & ADAU1701_DSPCTRL_IST)
266 msleep(50);
267
268 for (i = 0; i < len / 4; i++) {
269 put_unaligned_le16(ADAU1701_SAFELOAD_DATA(i), buf);
270 buf[2] = 0x00;
271 memcpy(buf + 3, bytes + i * 4, 4);
272 ret = i2c_master_send(client, buf, 7);
273 if (ret < 0)
274 return ret;
275 else if (ret != 7)
276 return -EIO;
277
278 put_unaligned_le16(ADAU1701_SAFELOAD_ADDR(i), buf);
279 put_unaligned_le16(addr + i, buf + 2);
280 ret = i2c_master_send(client, buf, 4);
281 if (ret < 0)
282 return ret;
283 else if (ret != 4)
284 return -EIO;
285 }
286
287 return regmap_update_bits(adau1701->regmap, ADAU1701_DSPCTRL,
288 ADAU1701_DSPCTRL_IST, ADAU1701_DSPCTRL_IST);
289}
290
291static const struct sigmadsp_ops adau1701_sigmadsp_ops = {
292 .safeload = adau1701_safeload,
293};
294
295static int adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv,
296 unsigned int rate)
242{ 297{
243 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec); 298 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
244 struct i2c_client *client = to_i2c_client(codec->dev);
245 int ret; 299 int ret;
246 300
301 sigmadsp_reset(adau1701->sigmadsp);
302
247 if (clkdiv != ADAU1707_CLKDIV_UNSET && 303 if (clkdiv != ADAU1707_CLKDIV_UNSET &&
248 gpio_is_valid(adau1701->gpio_pll_mode[0]) && 304 gpio_is_valid(adau1701->gpio_pll_mode[0]) &&
249 gpio_is_valid(adau1701->gpio_pll_mode[1])) { 305 gpio_is_valid(adau1701->gpio_pll_mode[1])) {
@@ -284,7 +340,7 @@ static int adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv)
284 * know the correct PLL setup 340 * know the correct PLL setup
285 */ 341 */
286 if (clkdiv != ADAU1707_CLKDIV_UNSET) { 342 if (clkdiv != ADAU1707_CLKDIV_UNSET) {
287 ret = process_sigma_firmware(client, ADAU1701_FIRMWARE); 343 ret = sigmadsp_setup(adau1701->sigmadsp, rate);
288 if (ret) { 344 if (ret) {
289 dev_warn(codec->dev, "Failed to load firmware\n"); 345 dev_warn(codec->dev, "Failed to load firmware\n");
290 return ret; 346 return ret;
@@ -385,7 +441,7 @@ static int adau1701_hw_params(struct snd_pcm_substream *substream,
385 * firmware upload. 441 * firmware upload.
386 */ 442 */
387 if (clkdiv != adau1701->pll_clkdiv) { 443 if (clkdiv != adau1701->pll_clkdiv) {
388 ret = adau1701_reset(codec, clkdiv); 444 ret = adau1701_reset(codec, clkdiv, params_rate(params));
389 if (ret < 0) 445 if (ret < 0)
390 return ret; 446 return ret;
391 } 447 }
@@ -554,6 +610,14 @@ static int adau1701_set_sysclk(struct snd_soc_codec *codec, int clk_id,
554 return 0; 610 return 0;
555} 611}
556 612
613static int adau1701_startup(struct snd_pcm_substream *substream,
614 struct snd_soc_dai *dai)
615{
616 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(dai->codec);
617
618 return sigmadsp_restrict_params(adau1701->sigmadsp, substream);
619}
620
557#define ADAU1701_RATES (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | \ 621#define ADAU1701_RATES (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | \
558 SNDRV_PCM_RATE_192000) 622 SNDRV_PCM_RATE_192000)
559 623
@@ -564,6 +628,7 @@ static const struct snd_soc_dai_ops adau1701_dai_ops = {
564 .set_fmt = adau1701_set_dai_fmt, 628 .set_fmt = adau1701_set_dai_fmt,
565 .hw_params = adau1701_hw_params, 629 .hw_params = adau1701_hw_params,
566 .digital_mute = adau1701_digital_mute, 630 .digital_mute = adau1701_digital_mute,
631 .startup = adau1701_startup,
567}; 632};
568 633
569static struct snd_soc_dai_driver adau1701_dai = { 634static struct snd_soc_dai_driver adau1701_dai = {
@@ -600,6 +665,10 @@ static int adau1701_probe(struct snd_soc_codec *codec)
600 unsigned int val; 665 unsigned int val;
601 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec); 666 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
602 667
668 ret = sigmadsp_attach(adau1701->sigmadsp, &codec->component);
669 if (ret)
670 return ret;
671
603 /* 672 /*
604 * Let the pll_clkdiv variable default to something that won't happen 673 * Let the pll_clkdiv variable default to something that won't happen
605 * at runtime. That way, we can postpone the firmware download from 674 * at runtime. That way, we can postpone the firmware download from
@@ -609,7 +678,7 @@ static int adau1701_probe(struct snd_soc_codec *codec)
609 adau1701->pll_clkdiv = ADAU1707_CLKDIV_UNSET; 678 adau1701->pll_clkdiv = ADAU1707_CLKDIV_UNSET;
610 679
611 /* initalize with pre-configured pll mode settings */ 680 /* initalize with pre-configured pll mode settings */
612 ret = adau1701_reset(codec, adau1701->pll_clkdiv); 681 ret = adau1701_reset(codec, adau1701->pll_clkdiv, 0);
613 if (ret < 0) 682 if (ret < 0)
614 return ret; 683 return ret;
615 684
@@ -667,6 +736,7 @@ static int adau1701_i2c_probe(struct i2c_client *client,
667 if (!adau1701) 736 if (!adau1701)
668 return -ENOMEM; 737 return -ENOMEM;
669 738
739 adau1701->client = client;
670 adau1701->regmap = devm_regmap_init(dev, NULL, client, 740 adau1701->regmap = devm_regmap_init(dev, NULL, client,
671 &adau1701_regmap); 741 &adau1701_regmap);
672 if (IS_ERR(adau1701->regmap)) 742 if (IS_ERR(adau1701->regmap))
@@ -722,6 +792,12 @@ static int adau1701_i2c_probe(struct i2c_client *client,
722 adau1701->gpio_pll_mode[1] = gpio_pll_mode[1]; 792 adau1701->gpio_pll_mode[1] = gpio_pll_mode[1];
723 793
724 i2c_set_clientdata(client, adau1701); 794 i2c_set_clientdata(client, adau1701);
795
796 adau1701->sigmadsp = devm_sigmadsp_init_i2c(client,
797 &adau1701_sigmadsp_ops, ADAU1701_FIRMWARE);
798 if (IS_ERR(adau1701->sigmadsp))
799 return PTR_ERR(adau1701->sigmadsp);
800
725 ret = snd_soc_register_codec(&client->dev, &adau1701_codec_drv, 801 ret = snd_soc_register_codec(&client->dev, &adau1701_codec_drv,
726 &adau1701_dai, 1); 802 &adau1701_dai, 1);
727 return ret; 803 return ret;
diff --git a/sound/soc/codecs/adau1761.c b/sound/soc/codecs/adau1761.c
index 91f60282fd2f..a1baeee160f4 100644
--- a/sound/soc/codecs/adau1761.c
+++ b/sound/soc/codecs/adau1761.c
@@ -255,7 +255,8 @@ static const struct snd_kcontrol_new adau1761_input_mux_control =
255static int adau1761_dejitter_fixup(struct snd_soc_dapm_widget *w, 255static int adau1761_dejitter_fixup(struct snd_soc_dapm_widget *w,
256 struct snd_kcontrol *kcontrol, int event) 256 struct snd_kcontrol *kcontrol, int event)
257{ 257{
258 struct adau *adau = snd_soc_codec_get_drvdata(w->codec); 258 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
259 struct adau *adau = snd_soc_codec_get_drvdata(codec);
259 260
260 /* After any power changes have been made the dejitter circuit 261 /* After any power changes have been made the dejitter circuit
261 * has to be reinitialized. */ 262 * has to be reinitialized. */
@@ -702,11 +703,6 @@ static int adau1761_codec_probe(struct snd_soc_codec *codec)
702 ARRAY_SIZE(adau1761_dapm_routes)); 703 ARRAY_SIZE(adau1761_dapm_routes));
703 if (ret) 704 if (ret)
704 return ret; 705 return ret;
705
706 ret = adau17x1_load_firmware(adau, codec->dev,
707 ADAU1761_FIRMWARE);
708 if (ret)
709 dev_warn(codec->dev, "Failed to firmware\n");
710 } 706 }
711 707
712 ret = adau17x1_add_routes(codec); 708 ret = adau17x1_add_routes(codec);
@@ -775,16 +771,20 @@ int adau1761_probe(struct device *dev, struct regmap *regmap,
775 enum adau17x1_type type, void (*switch_mode)(struct device *dev)) 771 enum adau17x1_type type, void (*switch_mode)(struct device *dev))
776{ 772{
777 struct snd_soc_dai_driver *dai_drv; 773 struct snd_soc_dai_driver *dai_drv;
774 const char *firmware_name;
778 int ret; 775 int ret;
779 776
780 ret = adau17x1_probe(dev, regmap, type, switch_mode); 777 if (type == ADAU1361) {
781 if (ret)
782 return ret;
783
784 if (type == ADAU1361)
785 dai_drv = &adau1361_dai_driver; 778 dai_drv = &adau1361_dai_driver;
786 else 779 firmware_name = NULL;
780 } else {
787 dai_drv = &adau1761_dai_driver; 781 dai_drv = &adau1761_dai_driver;
782 firmware_name = ADAU1761_FIRMWARE;
783 }
784
785 ret = adau17x1_probe(dev, regmap, type, switch_mode, firmware_name);
786 if (ret)
787 return ret;
788 788
789 return snd_soc_register_codec(dev, &adau1761_codec_driver, dai_drv, 1); 789 return snd_soc_register_codec(dev, &adau1761_codec_driver, dai_drv, 1);
790} 790}
@@ -798,6 +798,7 @@ const struct regmap_config adau1761_regmap_config = {
798 .num_reg_defaults = ARRAY_SIZE(adau1761_reg_defaults), 798 .num_reg_defaults = ARRAY_SIZE(adau1761_reg_defaults),
799 .readable_reg = adau1761_readable_register, 799 .readable_reg = adau1761_readable_register,
800 .volatile_reg = adau17x1_volatile_register, 800 .volatile_reg = adau17x1_volatile_register,
801 .precious_reg = adau17x1_precious_register,
801 .cache_type = REGCACHE_RBTREE, 802 .cache_type = REGCACHE_RBTREE,
802}; 803};
803EXPORT_SYMBOL_GPL(adau1761_regmap_config); 804EXPORT_SYMBOL_GPL(adau1761_regmap_config);
diff --git a/sound/soc/codecs/adau1781.c b/sound/soc/codecs/adau1781.c
index e9fc00fb13dd..35581f43fa6d 100644
--- a/sound/soc/codecs/adau1781.c
+++ b/sound/soc/codecs/adau1781.c
@@ -174,7 +174,7 @@ static const struct snd_kcontrol_new adau1781_mono_mixer_controls[] = {
174static int adau1781_dejitter_fixup(struct snd_soc_dapm_widget *w, 174static int adau1781_dejitter_fixup(struct snd_soc_dapm_widget *w,
175 struct snd_kcontrol *kcontrol, int event) 175 struct snd_kcontrol *kcontrol, int event)
176{ 176{
177 struct snd_soc_codec *codec = w->codec; 177 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
178 struct adau *adau = snd_soc_codec_get_drvdata(codec); 178 struct adau *adau = snd_soc_codec_get_drvdata(codec);
179 179
180 /* After any power changes have been made the dejitter circuit 180 /* After any power changes have been made the dejitter circuit
@@ -385,7 +385,6 @@ static int adau1781_codec_probe(struct snd_soc_codec *codec)
385{ 385{
386 struct adau1781_platform_data *pdata = dev_get_platdata(codec->dev); 386 struct adau1781_platform_data *pdata = dev_get_platdata(codec->dev);
387 struct adau *adau = snd_soc_codec_get_drvdata(codec); 387 struct adau *adau = snd_soc_codec_get_drvdata(codec);
388 const char *firmware;
389 int ret; 388 int ret;
390 389
391 ret = adau17x1_add_widgets(codec); 390 ret = adau17x1_add_widgets(codec);
@@ -422,25 +421,10 @@ static int adau1781_codec_probe(struct snd_soc_codec *codec)
422 return ret; 421 return ret;
423 } 422 }
424 423
425 switch (adau->type) {
426 case ADAU1381:
427 firmware = ADAU1381_FIRMWARE;
428 break;
429 case ADAU1781:
430 firmware = ADAU1781_FIRMWARE;
431 break;
432 default:
433 return -EINVAL;
434 }
435
436 ret = adau17x1_add_routes(codec); 424 ret = adau17x1_add_routes(codec);
437 if (ret < 0) 425 if (ret < 0)
438 return ret; 426 return ret;
439 427
440 ret = adau17x1_load_firmware(adau, codec->dev, firmware);
441 if (ret)
442 dev_warn(codec->dev, "Failed to load firmware\n");
443
444 return 0; 428 return 0;
445} 429}
446 430
@@ -488,6 +472,7 @@ const struct regmap_config adau1781_regmap_config = {
488 .num_reg_defaults = ARRAY_SIZE(adau1781_reg_defaults), 472 .num_reg_defaults = ARRAY_SIZE(adau1781_reg_defaults),
489 .readable_reg = adau1781_readable_register, 473 .readable_reg = adau1781_readable_register,
490 .volatile_reg = adau17x1_volatile_register, 474 .volatile_reg = adau17x1_volatile_register,
475 .precious_reg = adau17x1_precious_register,
491 .cache_type = REGCACHE_RBTREE, 476 .cache_type = REGCACHE_RBTREE,
492}; 477};
493EXPORT_SYMBOL_GPL(adau1781_regmap_config); 478EXPORT_SYMBOL_GPL(adau1781_regmap_config);
@@ -495,9 +480,21 @@ EXPORT_SYMBOL_GPL(adau1781_regmap_config);
495int adau1781_probe(struct device *dev, struct regmap *regmap, 480int adau1781_probe(struct device *dev, struct regmap *regmap,
496 enum adau17x1_type type, void (*switch_mode)(struct device *dev)) 481 enum adau17x1_type type, void (*switch_mode)(struct device *dev))
497{ 482{
483 const char *firmware_name;
498 int ret; 484 int ret;
499 485
500 ret = adau17x1_probe(dev, regmap, type, switch_mode); 486 switch (type) {
487 case ADAU1381:
488 firmware_name = ADAU1381_FIRMWARE;
489 break;
490 case ADAU1781:
491 firmware_name = ADAU1781_FIRMWARE;
492 break;
493 default:
494 return -EINVAL;
495 }
496
497 ret = adau17x1_probe(dev, regmap, type, switch_mode, firmware_name);
501 if (ret) 498 if (ret)
502 return ret; 499 return ret;
503 500
diff --git a/sound/soc/codecs/adau17x1.c b/sound/soc/codecs/adau17x1.c
index 3e16c1c64115..fa2e690e51c8 100644
--- a/sound/soc/codecs/adau17x1.c
+++ b/sound/soc/codecs/adau17x1.c
@@ -61,7 +61,8 @@ static const struct snd_kcontrol_new adau17x1_controls[] = {
61static int adau17x1_pll_event(struct snd_soc_dapm_widget *w, 61static int adau17x1_pll_event(struct snd_soc_dapm_widget *w,
62 struct snd_kcontrol *kcontrol, int event) 62 struct snd_kcontrol *kcontrol, int event)
63{ 63{
64 struct adau *adau = snd_soc_codec_get_drvdata(w->codec); 64 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
65 struct adau *adau = snd_soc_codec_get_drvdata(codec);
65 int ret; 66 int ret;
66 67
67 if (SND_SOC_DAPM_EVENT_ON(event)) { 68 if (SND_SOC_DAPM_EVENT_ON(event)) {
@@ -307,6 +308,7 @@ static int adau17x1_hw_params(struct snd_pcm_substream *substream,
307 struct adau *adau = snd_soc_codec_get_drvdata(codec); 308 struct adau *adau = snd_soc_codec_get_drvdata(codec);
308 unsigned int val, div, dsp_div; 309 unsigned int val, div, dsp_div;
309 unsigned int freq; 310 unsigned int freq;
311 int ret;
310 312
311 if (adau->clk_src == ADAU17X1_CLK_SRC_PLL) 313 if (adau->clk_src == ADAU17X1_CLK_SRC_PLL)
312 freq = adau->pll_freq; 314 freq = adau->pll_freq;
@@ -356,6 +358,12 @@ static int adau17x1_hw_params(struct snd_pcm_substream *substream,
356 regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, dsp_div); 358 regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, dsp_div);
357 } 359 }
358 360
361 if (adau->sigmadsp) {
362 ret = adau17x1_setup_firmware(adau, params_rate(params));
363 if (ret < 0)
364 return ret;
365 }
366
359 if (adau->dai_fmt != SND_SOC_DAIFMT_RIGHT_J) 367 if (adau->dai_fmt != SND_SOC_DAIFMT_RIGHT_J)
360 return 0; 368 return 0;
361 369
@@ -661,12 +669,24 @@ static int adau17x1_set_dai_tdm_slot(struct snd_soc_dai *dai,
661 return 0; 669 return 0;
662} 670}
663 671
672static int adau17x1_startup(struct snd_pcm_substream *substream,
673 struct snd_soc_dai *dai)
674{
675 struct adau *adau = snd_soc_codec_get_drvdata(dai->codec);
676
677 if (adau->sigmadsp)
678 return sigmadsp_restrict_params(adau->sigmadsp, substream);
679
680 return 0;
681}
682
664const struct snd_soc_dai_ops adau17x1_dai_ops = { 683const struct snd_soc_dai_ops adau17x1_dai_ops = {
665 .hw_params = adau17x1_hw_params, 684 .hw_params = adau17x1_hw_params,
666 .set_sysclk = adau17x1_set_dai_sysclk, 685 .set_sysclk = adau17x1_set_dai_sysclk,
667 .set_fmt = adau17x1_set_dai_fmt, 686 .set_fmt = adau17x1_set_dai_fmt,
668 .set_pll = adau17x1_set_dai_pll, 687 .set_pll = adau17x1_set_dai_pll,
669 .set_tdm_slot = adau17x1_set_dai_tdm_slot, 688 .set_tdm_slot = adau17x1_set_dai_tdm_slot,
689 .startup = adau17x1_startup,
670}; 690};
671EXPORT_SYMBOL_GPL(adau17x1_dai_ops); 691EXPORT_SYMBOL_GPL(adau17x1_dai_ops);
672 692
@@ -687,8 +707,22 @@ int adau17x1_set_micbias_voltage(struct snd_soc_codec *codec,
687} 707}
688EXPORT_SYMBOL_GPL(adau17x1_set_micbias_voltage); 708EXPORT_SYMBOL_GPL(adau17x1_set_micbias_voltage);
689 709
710bool adau17x1_precious_register(struct device *dev, unsigned int reg)
711{
712 /* SigmaDSP parameter memory */
713 if (reg < 0x400)
714 return true;
715
716 return false;
717}
718EXPORT_SYMBOL_GPL(adau17x1_precious_register);
719
690bool adau17x1_readable_register(struct device *dev, unsigned int reg) 720bool adau17x1_readable_register(struct device *dev, unsigned int reg)
691{ 721{
722 /* SigmaDSP parameter memory */
723 if (reg < 0x400)
724 return true;
725
692 switch (reg) { 726 switch (reg) {
693 case ADAU17X1_CLOCK_CONTROL: 727 case ADAU17X1_CLOCK_CONTROL:
694 case ADAU17X1_PLL_CONTROL: 728 case ADAU17X1_PLL_CONTROL:
@@ -745,8 +779,7 @@ bool adau17x1_volatile_register(struct device *dev, unsigned int reg)
745} 779}
746EXPORT_SYMBOL_GPL(adau17x1_volatile_register); 780EXPORT_SYMBOL_GPL(adau17x1_volatile_register);
747 781
748int adau17x1_load_firmware(struct adau *adau, struct device *dev, 782int adau17x1_setup_firmware(struct adau *adau, unsigned int rate)
749 const char *firmware)
750{ 783{
751 int ret; 784 int ret;
752 int dspsr; 785 int dspsr;
@@ -758,7 +791,7 @@ int adau17x1_load_firmware(struct adau *adau, struct device *dev,
758 regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 1); 791 regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 1);
759 regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, 0xf); 792 regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, 0xf);
760 793
761 ret = process_sigma_firmware_regmap(dev, adau->regmap, firmware); 794 ret = sigmadsp_setup(adau->sigmadsp, rate);
762 if (ret) { 795 if (ret) {
763 regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 0); 796 regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 0);
764 return ret; 797 return ret;
@@ -767,7 +800,7 @@ int adau17x1_load_firmware(struct adau *adau, struct device *dev,
767 800
768 return 0; 801 return 0;
769} 802}
770EXPORT_SYMBOL_GPL(adau17x1_load_firmware); 803EXPORT_SYMBOL_GPL(adau17x1_setup_firmware);
771 804
772int adau17x1_add_widgets(struct snd_soc_codec *codec) 805int adau17x1_add_widgets(struct snd_soc_codec *codec)
773{ 806{
@@ -787,8 +820,21 @@ int adau17x1_add_widgets(struct snd_soc_codec *codec)
787 ret = snd_soc_dapm_new_controls(&codec->dapm, 820 ret = snd_soc_dapm_new_controls(&codec->dapm,
788 adau17x1_dsp_dapm_widgets, 821 adau17x1_dsp_dapm_widgets,
789 ARRAY_SIZE(adau17x1_dsp_dapm_widgets)); 822 ARRAY_SIZE(adau17x1_dsp_dapm_widgets));
823 if (ret)
824 return ret;
825
826 if (!adau->sigmadsp)
827 return 0;
828
829 ret = sigmadsp_attach(adau->sigmadsp, &codec->component);
830 if (ret) {
831 dev_err(codec->dev, "Failed to attach firmware: %d\n",
832 ret);
833 return ret;
834 }
790 } 835 }
791 return ret; 836
837 return 0;
792} 838}
793EXPORT_SYMBOL_GPL(adau17x1_add_widgets); 839EXPORT_SYMBOL_GPL(adau17x1_add_widgets);
794 840
@@ -829,7 +875,8 @@ int adau17x1_resume(struct snd_soc_codec *codec)
829EXPORT_SYMBOL_GPL(adau17x1_resume); 875EXPORT_SYMBOL_GPL(adau17x1_resume);
830 876
831int adau17x1_probe(struct device *dev, struct regmap *regmap, 877int adau17x1_probe(struct device *dev, struct regmap *regmap,
832 enum adau17x1_type type, void (*switch_mode)(struct device *dev)) 878 enum adau17x1_type type, void (*switch_mode)(struct device *dev),
879 const char *firmware_name)
833{ 880{
834 struct adau *adau; 881 struct adau *adau;
835 882
@@ -846,6 +893,16 @@ int adau17x1_probe(struct device *dev, struct regmap *regmap,
846 893
847 dev_set_drvdata(dev, adau); 894 dev_set_drvdata(dev, adau);
848 895
896 if (firmware_name) {
897 adau->sigmadsp = devm_sigmadsp_init_regmap(dev, regmap, NULL,
898 firmware_name);
899 if (IS_ERR(adau->sigmadsp)) {
900 dev_warn(dev, "Could not find firmware file: %ld\n",
901 PTR_ERR(adau->sigmadsp));
902 adau->sigmadsp = NULL;
903 }
904 }
905
849 if (switch_mode) 906 if (switch_mode)
850 switch_mode(dev); 907 switch_mode(dev);
851 908
diff --git a/sound/soc/codecs/adau17x1.h b/sound/soc/codecs/adau17x1.h
index e4a557fd7155..e13583e6ff56 100644
--- a/sound/soc/codecs/adau17x1.h
+++ b/sound/soc/codecs/adau17x1.h
@@ -4,6 +4,8 @@
4#include <linux/regmap.h> 4#include <linux/regmap.h>
5#include <linux/platform_data/adau17x1.h> 5#include <linux/platform_data/adau17x1.h>
6 6
7#include "sigmadsp.h"
8
7enum adau17x1_type { 9enum adau17x1_type {
8 ADAU1361, 10 ADAU1361,
9 ADAU1761, 11 ADAU1761,
@@ -42,22 +44,24 @@ struct adau {
42 bool dsp_bypass[2]; 44 bool dsp_bypass[2];
43 45
44 struct regmap *regmap; 46 struct regmap *regmap;
47 struct sigmadsp *sigmadsp;
45}; 48};
46 49
47int adau17x1_add_widgets(struct snd_soc_codec *codec); 50int adau17x1_add_widgets(struct snd_soc_codec *codec);
48int adau17x1_add_routes(struct snd_soc_codec *codec); 51int adau17x1_add_routes(struct snd_soc_codec *codec);
49int adau17x1_probe(struct device *dev, struct regmap *regmap, 52int adau17x1_probe(struct device *dev, struct regmap *regmap,
50 enum adau17x1_type type, void (*switch_mode)(struct device *dev)); 53 enum adau17x1_type type, void (*switch_mode)(struct device *dev),
54 const char *firmware_name);
51int adau17x1_set_micbias_voltage(struct snd_soc_codec *codec, 55int adau17x1_set_micbias_voltage(struct snd_soc_codec *codec,
52 enum adau17x1_micbias_voltage micbias); 56 enum adau17x1_micbias_voltage micbias);
53bool adau17x1_readable_register(struct device *dev, unsigned int reg); 57bool adau17x1_readable_register(struct device *dev, unsigned int reg);
54bool adau17x1_volatile_register(struct device *dev, unsigned int reg); 58bool adau17x1_volatile_register(struct device *dev, unsigned int reg);
59bool adau17x1_precious_register(struct device *dev, unsigned int reg);
55int adau17x1_resume(struct snd_soc_codec *codec); 60int adau17x1_resume(struct snd_soc_codec *codec);
56 61
57extern const struct snd_soc_dai_ops adau17x1_dai_ops; 62extern const struct snd_soc_dai_ops adau17x1_dai_ops;
58 63
59int adau17x1_load_firmware(struct adau *adau, struct device *dev, 64int adau17x1_setup_firmware(struct adau *adau, unsigned int rate);
60 const char *firmware);
61bool adau17x1_has_dsp(struct adau *adau); 65bool adau17x1_has_dsp(struct adau *adau);
62 66
63#define ADAU17X1_CLOCK_CONTROL 0x4000 67#define ADAU17X1_CLOCK_CONTROL 0x4000
diff --git a/sound/soc/codecs/adav80x.c b/sound/soc/codecs/adav80x.c
index ce3cdca9fc62..b67480f1b1aa 100644
--- a/sound/soc/codecs/adav80x.c
+++ b/sound/soc/codecs/adav80x.c
@@ -212,7 +212,7 @@ static const struct snd_soc_dapm_widget adav80x_dapm_widgets[] = {
212static int adav80x_dapm_sysclk_check(struct snd_soc_dapm_widget *source, 212static int adav80x_dapm_sysclk_check(struct snd_soc_dapm_widget *source,
213 struct snd_soc_dapm_widget *sink) 213 struct snd_soc_dapm_widget *sink)
214{ 214{
215 struct snd_soc_codec *codec = source->codec; 215 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
216 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 216 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
217 const char *clk; 217 const char *clk;
218 218
@@ -236,7 +236,7 @@ static int adav80x_dapm_sysclk_check(struct snd_soc_dapm_widget *source,
236static int adav80x_dapm_pll_check(struct snd_soc_dapm_widget *source, 236static int adav80x_dapm_pll_check(struct snd_soc_dapm_widget *source,
237 struct snd_soc_dapm_widget *sink) 237 struct snd_soc_dapm_widget *sink)
238{ 238{
239 struct snd_soc_codec *codec = source->codec; 239 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
240 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 240 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
241 241
242 return adav80x->pll_src == ADAV80X_PLL_SRC_XTAL; 242 return adav80x->pll_src == ADAV80X_PLL_SRC_XTAL;
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
index 30e297890fec..9130d916f2f4 100644
--- a/sound/soc/codecs/ak4535.c
+++ b/sound/soc/codecs/ak4535.c
@@ -373,33 +373,9 @@ static struct snd_soc_dai_driver ak4535_dai = {
373 .ops = &ak4535_dai_ops, 373 .ops = &ak4535_dai_ops,
374}; 374};
375 375
376static int ak4535_suspend(struct snd_soc_codec *codec)
377{
378 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
379 return 0;
380}
381
382static int ak4535_resume(struct snd_soc_codec *codec) 376static int ak4535_resume(struct snd_soc_codec *codec)
383{ 377{
384 snd_soc_cache_sync(codec); 378 snd_soc_cache_sync(codec);
385 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
386 return 0;
387}
388
389static int ak4535_probe(struct snd_soc_codec *codec)
390{
391 /* power on device */
392 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
393
394 snd_soc_add_codec_controls(codec, ak4535_snd_controls,
395 ARRAY_SIZE(ak4535_snd_controls));
396 return 0;
397}
398
399/* power down chip */
400static int ak4535_remove(struct snd_soc_codec *codec)
401{
402 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
403 return 0; 379 return 0;
404} 380}
405 381
@@ -416,11 +392,12 @@ static const struct regmap_config ak4535_regmap = {
416}; 392};
417 393
418static struct snd_soc_codec_driver soc_codec_dev_ak4535 = { 394static struct snd_soc_codec_driver soc_codec_dev_ak4535 = {
419 .probe = ak4535_probe,
420 .remove = ak4535_remove,
421 .suspend = ak4535_suspend,
422 .resume = ak4535_resume, 395 .resume = ak4535_resume,
423 .set_bias_level = ak4535_set_bias_level, 396 .set_bias_level = ak4535_set_bias_level,
397 .suspend_bias_off = true,
398
399 .controls = ak4535_snd_controls,
400 .num_controls = ARRAY_SIZE(ak4535_snd_controls),
424 .dapm_widgets = ak4535_dapm_widgets, 401 .dapm_widgets = ak4535_dapm_widgets,
425 .num_dapm_widgets = ARRAY_SIZE(ak4535_dapm_widgets), 402 .num_dapm_widgets = ARRAY_SIZE(ak4535_dapm_widgets),
426 .dapm_routes = ak4535_audio_map, 403 .dapm_routes = ak4535_audio_map,
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c
index 7afe8f482088..70861c7b1631 100644
--- a/sound/soc/codecs/ak4641.c
+++ b/sound/soc/codecs/ak4641.c
@@ -505,39 +505,7 @@ static struct snd_soc_dai_driver ak4641_dai[] = {
505}, 505},
506}; 506};
507 507
508static int ak4641_suspend(struct snd_soc_codec *codec)
509{
510 ak4641_set_bias_level(codec, SND_SOC_BIAS_OFF);
511 return 0;
512}
513
514static int ak4641_resume(struct snd_soc_codec *codec)
515{
516 ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
517 return 0;
518}
519
520static int ak4641_probe(struct snd_soc_codec *codec)
521{
522 /* power on device */
523 ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
524
525 return 0;
526}
527
528static int ak4641_remove(struct snd_soc_codec *codec)
529{
530 ak4641_set_bias_level(codec, SND_SOC_BIAS_OFF);
531
532 return 0;
533}
534
535
536static struct snd_soc_codec_driver soc_codec_dev_ak4641 = { 508static struct snd_soc_codec_driver soc_codec_dev_ak4641 = {
537 .probe = ak4641_probe,
538 .remove = ak4641_remove,
539 .suspend = ak4641_suspend,
540 .resume = ak4641_resume,
541 .controls = ak4641_snd_controls, 509 .controls = ak4641_snd_controls,
542 .num_controls = ARRAY_SIZE(ak4641_snd_controls), 510 .num_controls = ARRAY_SIZE(ak4641_snd_controls),
543 .dapm_widgets = ak4641_dapm_widgets, 511 .dapm_widgets = ak4641_dapm_widgets,
@@ -545,6 +513,7 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4641 = {
545 .dapm_routes = ak4641_audio_map, 513 .dapm_routes = ak4641_audio_map,
546 .num_dapm_routes = ARRAY_SIZE(ak4641_audio_map), 514 .num_dapm_routes = ARRAY_SIZE(ak4641_audio_map),
547 .set_bias_level = ak4641_set_bias_level, 515 .set_bias_level = ak4641_set_bias_level,
516 .suspend_bias_off = true,
548}; 517};
549 518
550static const struct regmap_config ak4641_regmap = { 519static const struct regmap_config ak4641_regmap = {
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 041712592e29..dde8b49c19ad 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -491,23 +491,7 @@ static int ak4642_resume(struct snd_soc_codec *codec)
491 return 0; 491 return 0;
492} 492}
493 493
494
495static int ak4642_probe(struct snd_soc_codec *codec)
496{
497 ak4642_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
498
499 return 0;
500}
501
502static int ak4642_remove(struct snd_soc_codec *codec)
503{
504 ak4642_set_bias_level(codec, SND_SOC_BIAS_OFF);
505 return 0;
506}
507
508static struct snd_soc_codec_driver soc_codec_dev_ak4642 = { 494static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
509 .probe = ak4642_probe,
510 .remove = ak4642_remove,
511 .resume = ak4642_resume, 495 .resume = ak4642_resume,
512 .set_bias_level = ak4642_set_bias_level, 496 .set_bias_level = ak4642_set_bias_level,
513 .controls = ak4642_snd_controls, 497 .controls = ak4642_snd_controls,
diff --git a/sound/soc/codecs/ak4671.c b/sound/soc/codecs/ak4671.c
index 998fa0c5a0b9..686cacb0e835 100644
--- a/sound/soc/codecs/ak4671.c
+++ b/sound/soc/codecs/ak4671.c
@@ -611,20 +611,7 @@ static struct snd_soc_dai_driver ak4671_dai = {
611 .ops = &ak4671_dai_ops, 611 .ops = &ak4671_dai_ops,
612}; 612};
613 613
614static int ak4671_probe(struct snd_soc_codec *codec)
615{
616 return ak4671_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
617}
618
619static int ak4671_remove(struct snd_soc_codec *codec)
620{
621 ak4671_set_bias_level(codec, SND_SOC_BIAS_OFF);
622 return 0;
623}
624
625static struct snd_soc_codec_driver soc_codec_dev_ak4671 = { 614static struct snd_soc_codec_driver soc_codec_dev_ak4671 = {
626 .probe = ak4671_probe,
627 .remove = ak4671_remove,
628 .set_bias_level = ak4671_set_bias_level, 615 .set_bias_level = ak4671_set_bias_level,
629 .controls = ak4671_snd_controls, 616 .controls = ak4671_snd_controls,
630 .num_controls = ARRAY_SIZE(ak4671_snd_controls), 617 .num_controls = ARRAY_SIZE(ak4671_snd_controls),
diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c
index 9d0755aa1d16..bdf8c5ac8ca4 100644
--- a/sound/soc/codecs/alc5623.c
+++ b/sound/soc/codecs/alc5623.c
@@ -866,7 +866,6 @@ static int alc5623_suspend(struct snd_soc_codec *codec)
866{ 866{
867 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec); 867 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
868 868
869 alc5623_set_bias_level(codec, SND_SOC_BIAS_OFF);
870 regcache_cache_only(alc5623->regmap, true); 869 regcache_cache_only(alc5623->regmap, true);
871 870
872 return 0; 871 return 0;
@@ -887,15 +886,6 @@ static int alc5623_resume(struct snd_soc_codec *codec)
887 return ret; 886 return ret;
888 } 887 }
889 888
890 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
891
892 /* charge alc5623 caps */
893 if (codec->dapm.suspend_bias_level == SND_SOC_BIAS_ON) {
894 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
895 codec->dapm.bias_level = SND_SOC_BIAS_ON;
896 alc5623_set_bias_level(codec, codec->dapm.bias_level);
897 }
898
899 return 0; 889 return 0;
900} 890}
901 891
@@ -906,9 +896,6 @@ static int alc5623_probe(struct snd_soc_codec *codec)
906 896
907 alc5623_reset(codec); 897 alc5623_reset(codec);
908 898
909 /* power on device */
910 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
911
912 if (alc5623->add_ctrl) { 899 if (alc5623->add_ctrl) {
913 snd_soc_write(codec, ALC5623_ADD_CTRL_REG, 900 snd_soc_write(codec, ALC5623_ADD_CTRL_REG,
914 alc5623->add_ctrl); 901 alc5623->add_ctrl);
@@ -964,19 +951,12 @@ static int alc5623_probe(struct snd_soc_codec *codec)
964 return 0; 951 return 0;
965} 952}
966 953
967/* power down chip */
968static int alc5623_remove(struct snd_soc_codec *codec)
969{
970 alc5623_set_bias_level(codec, SND_SOC_BIAS_OFF);
971 return 0;
972}
973
974static struct snd_soc_codec_driver soc_codec_device_alc5623 = { 954static struct snd_soc_codec_driver soc_codec_device_alc5623 = {
975 .probe = alc5623_probe, 955 .probe = alc5623_probe,
976 .remove = alc5623_remove,
977 .suspend = alc5623_suspend, 956 .suspend = alc5623_suspend,
978 .resume = alc5623_resume, 957 .resume = alc5623_resume,
979 .set_bias_level = alc5623_set_bias_level, 958 .set_bias_level = alc5623_set_bias_level,
959 .suspend_bias_off = true,
980}; 960};
981 961
982static const struct regmap_config alc5623_regmap = { 962static const struct regmap_config alc5623_regmap = {
diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c
index 85942ca36cbf..d1fdbc266631 100644
--- a/sound/soc/codecs/alc5632.c
+++ b/sound/soc/codecs/alc5632.c
@@ -1038,23 +1038,15 @@ static struct snd_soc_dai_driver alc5632_dai = {
1038}; 1038};
1039 1039
1040#ifdef CONFIG_PM 1040#ifdef CONFIG_PM
1041static int alc5632_suspend(struct snd_soc_codec *codec)
1042{
1043 alc5632_set_bias_level(codec, SND_SOC_BIAS_OFF);
1044 return 0;
1045}
1046
1047static int alc5632_resume(struct snd_soc_codec *codec) 1041static int alc5632_resume(struct snd_soc_codec *codec)
1048{ 1042{
1049 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec); 1043 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec);
1050 1044
1051 regcache_sync(alc5632->regmap); 1045 regcache_sync(alc5632->regmap);
1052 1046
1053 alc5632_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1054 return 0; 1047 return 0;
1055} 1048}
1056#else 1049#else
1057#define alc5632_suspend NULL
1058#define alc5632_resume NULL 1050#define alc5632_resume NULL
1059#endif 1051#endif
1060 1052
@@ -1062,9 +1054,6 @@ static int alc5632_probe(struct snd_soc_codec *codec)
1062{ 1054{
1063 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec); 1055 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec);
1064 1056
1065 /* power on device */
1066 alc5632_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1067
1068 switch (alc5632->id) { 1057 switch (alc5632->id) {
1069 case 0x5c: 1058 case 0x5c:
1070 snd_soc_add_codec_controls(codec, alc5632_vol_snd_controls, 1059 snd_soc_add_codec_controls(codec, alc5632_vol_snd_controls,
@@ -1077,19 +1066,12 @@ static int alc5632_probe(struct snd_soc_codec *codec)
1077 return 0; 1066 return 0;
1078} 1067}
1079 1068
1080/* power down chip */
1081static int alc5632_remove(struct snd_soc_codec *codec)
1082{
1083 alc5632_set_bias_level(codec, SND_SOC_BIAS_OFF);
1084 return 0;
1085}
1086
1087static struct snd_soc_codec_driver soc_codec_device_alc5632 = { 1069static struct snd_soc_codec_driver soc_codec_device_alc5632 = {
1088 .probe = alc5632_probe, 1070 .probe = alc5632_probe,
1089 .remove = alc5632_remove,
1090 .suspend = alc5632_suspend,
1091 .resume = alc5632_resume, 1071 .resume = alc5632_resume,
1092 .set_bias_level = alc5632_set_bias_level, 1072 .set_bias_level = alc5632_set_bias_level,
1073 .suspend_bias_off = true,
1074
1093 .controls = alc5632_snd_controls, 1075 .controls = alc5632_snd_controls,
1094 .num_controls = ARRAY_SIZE(alc5632_snd_controls), 1076 .num_controls = ARRAY_SIZE(alc5632_snd_controls),
1095 .dapm_widgets = alc5632_dapm_widgets, 1077 .dapm_widgets = alc5632_dapm_widgets,
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index 0c05e7a7945f..9550d7433ad0 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -61,6 +61,11 @@
61#define ARIZONA_FLL_MIN_OUTDIV 2 61#define ARIZONA_FLL_MIN_OUTDIV 2
62#define ARIZONA_FLL_MAX_OUTDIV 7 62#define ARIZONA_FLL_MAX_OUTDIV 7
63 63
64#define ARIZONA_FMT_DSP_MODE_A 0
65#define ARIZONA_FMT_DSP_MODE_B 1
66#define ARIZONA_FMT_I2S_MODE 2
67#define ARIZONA_FMT_LEFT_JUSTIFIED_MODE 3
68
64#define arizona_fll_err(_fll, fmt, ...) \ 69#define arizona_fll_err(_fll, fmt, ...) \
65 dev_err(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__) 70 dev_err(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
66#define arizona_fll_warn(_fll, fmt, ...) \ 71#define arizona_fll_warn(_fll, fmt, ...) \
@@ -648,7 +653,7 @@ SOC_ENUM_SINGLE_DECL(arizona_in_hpf_cut_enum,
648EXPORT_SYMBOL_GPL(arizona_in_hpf_cut_enum); 653EXPORT_SYMBOL_GPL(arizona_in_hpf_cut_enum);
649 654
650static const char * const arizona_in_dmic_osr_text[] = { 655static const char * const arizona_in_dmic_osr_text[] = {
651 "1.536MHz", "3.072MHz", "6.144MHz", 656 "1.536MHz", "3.072MHz", "6.144MHz", "768kHz",
652}; 657};
653 658
654const struct soc_enum arizona_in_dmic_osr[] = { 659const struct soc_enum arizona_in_dmic_osr[] = {
@@ -946,10 +951,26 @@ static int arizona_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
946 951
947 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 952 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
948 case SND_SOC_DAIFMT_DSP_A: 953 case SND_SOC_DAIFMT_DSP_A:
949 mode = 0; 954 mode = ARIZONA_FMT_DSP_MODE_A;
955 break;
956 case SND_SOC_DAIFMT_DSP_B:
957 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK)
958 != SND_SOC_DAIFMT_CBM_CFM) {
959 arizona_aif_err(dai, "DSP_B not valid in slave mode\n");
960 return -EINVAL;
961 }
962 mode = ARIZONA_FMT_DSP_MODE_B;
950 break; 963 break;
951 case SND_SOC_DAIFMT_I2S: 964 case SND_SOC_DAIFMT_I2S:
952 mode = 2; 965 mode = ARIZONA_FMT_I2S_MODE;
966 break;
967 case SND_SOC_DAIFMT_LEFT_J:
968 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK)
969 != SND_SOC_DAIFMT_CBM_CFM) {
970 arizona_aif_err(dai, "LEFT_J not valid in slave mode\n");
971 return -EINVAL;
972 }
973 mode = ARIZONA_FMT_LEFT_JUSTIFIED_MODE;
953 break; 974 break;
954 default: 975 default:
955 arizona_aif_err(dai, "Unsupported DAI format %d\n", 976 arizona_aif_err(dai, "Unsupported DAI format %d\n",
@@ -1164,13 +1185,13 @@ static void arizona_wm5102_set_dac_comp(struct snd_soc_codec *codec,
1164 { 0x80, 0x0 }, 1185 { 0x80, 0x0 },
1165 }; 1186 };
1166 1187
1167 mutex_lock(&codec->mutex); 1188 mutex_lock(&arizona->dac_comp_lock);
1168 1189
1169 dac_comp[1].def = arizona->dac_comp_coeff; 1190 dac_comp[1].def = arizona->dac_comp_coeff;
1170 if (rate >= 176400) 1191 if (rate >= 176400)
1171 dac_comp[2].def = arizona->dac_comp_enabled; 1192 dac_comp[2].def = arizona->dac_comp_enabled;
1172 1193
1173 mutex_unlock(&codec->mutex); 1194 mutex_unlock(&arizona->dac_comp_lock);
1174 1195
1175 regmap_multi_reg_write(arizona->regmap, 1196 regmap_multi_reg_write(arizona->regmap,
1176 dac_comp, 1197 dac_comp,
@@ -1298,7 +1319,8 @@ static int arizona_hw_params(struct snd_pcm_substream *substream,
1298 1319
1299 /* Force multiple of 2 channels for I2S mode */ 1320 /* Force multiple of 2 channels for I2S mode */
1300 val = snd_soc_read(codec, base + ARIZONA_AIF_FORMAT); 1321 val = snd_soc_read(codec, base + ARIZONA_AIF_FORMAT);
1301 if ((channels & 1) && (val & ARIZONA_AIF1_FMT_MASK)) { 1322 val &= ARIZONA_AIF1_FMT_MASK;
1323 if ((channels & 1) && (val == ARIZONA_FMT_I2S_MODE)) {
1302 arizona_aif_dbg(dai, "Forcing stereo mode\n"); 1324 arizona_aif_dbg(dai, "Forcing stereo mode\n");
1303 bclk_target /= channels; 1325 bclk_target /= channels;
1304 bclk_target *= channels + 1; 1326 bclk_target *= channels + 1;
diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c
index 537327c7f7f1..8d638e8aa8eb 100644
--- a/sound/soc/codecs/cq93vc.c
+++ b/sound/soc/codecs/cq93vc.c
@@ -62,14 +62,10 @@ static int cq93vc_mute(struct snd_soc_dai *dai, int mute)
62static int cq93vc_set_dai_sysclk(struct snd_soc_dai *codec_dai, 62static int cq93vc_set_dai_sysclk(struct snd_soc_dai *codec_dai,
63 int clk_id, unsigned int freq, int dir) 63 int clk_id, unsigned int freq, int dir)
64{ 64{
65 struct snd_soc_codec *codec = codec_dai->codec;
66 struct davinci_vc *davinci_vc = codec->dev->platform_data;
67
68 switch (freq) { 65 switch (freq) {
69 case 22579200: 66 case 22579200:
70 case 27000000: 67 case 27000000:
71 case 33868800: 68 case 33868800:
72 davinci_vc->cq93vc.sysclk = freq;
73 return 0; 69 return 0;
74 } 70 }
75 71
@@ -126,32 +122,6 @@ static struct snd_soc_dai_driver cq93vc_dai = {
126 .ops = &cq93vc_dai_ops, 122 .ops = &cq93vc_dai_ops,
127}; 123};
128 124
129static int cq93vc_resume(struct snd_soc_codec *codec)
130{
131 cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
132
133 return 0;
134}
135
136static int cq93vc_probe(struct snd_soc_codec *codec)
137{
138 struct davinci_vc *davinci_vc = codec->dev->platform_data;
139
140 davinci_vc->cq93vc.codec = codec;
141
142 /* Off, with power on */
143 cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
144
145 return 0;
146}
147
148static int cq93vc_remove(struct snd_soc_codec *codec)
149{
150 cq93vc_set_bias_level(codec, SND_SOC_BIAS_OFF);
151
152 return 0;
153}
154
155static struct regmap *cq93vc_get_regmap(struct device *dev) 125static struct regmap *cq93vc_get_regmap(struct device *dev)
156{ 126{
157 struct davinci_vc *davinci_vc = dev->platform_data; 127 struct davinci_vc *davinci_vc = dev->platform_data;
@@ -161,9 +131,6 @@ static struct regmap *cq93vc_get_regmap(struct device *dev)
161 131
162static struct snd_soc_codec_driver soc_codec_dev_cq93vc = { 132static struct snd_soc_codec_driver soc_codec_dev_cq93vc = {
163 .set_bias_level = cq93vc_set_bias_level, 133 .set_bias_level = cq93vc_set_bias_level,
164 .probe = cq93vc_probe,
165 .remove = cq93vc_remove,
166 .resume = cq93vc_resume,
167 .get_regmap = cq93vc_get_regmap, 134 .get_regmap = cq93vc_get_regmap,
168 .controls = cq93vc_snd_controls, 135 .controls = cq93vc_snd_controls,
169 .num_controls = ARRAY_SIZE(cq93vc_snd_controls), 136 .num_controls = ARRAY_SIZE(cq93vc_snd_controls),
diff --git a/sound/soc/codecs/cs4265.c b/sound/soc/codecs/cs4265.c
index 4fdd47d700e3..ce6086835ebd 100644
--- a/sound/soc/codecs/cs4265.c
+++ b/sound/soc/codecs/cs4265.c
@@ -32,7 +32,6 @@
32#include "cs4265.h" 32#include "cs4265.h"
33 33
34struct cs4265_private { 34struct cs4265_private {
35 struct device *dev;
36 struct regmap *regmap; 35 struct regmap *regmap;
37 struct gpio_desc *reset_gpio; 36 struct gpio_desc *reset_gpio;
38 u8 format; 37 u8 format;
@@ -598,7 +597,6 @@ static int cs4265_i2c_probe(struct i2c_client *i2c_client,
598 GFP_KERNEL); 597 GFP_KERNEL);
599 if (cs4265 == NULL) 598 if (cs4265 == NULL)
600 return -ENOMEM; 599 return -ENOMEM;
601 cs4265->dev = &i2c_client->dev;
602 600
603 cs4265->regmap = devm_regmap_init_i2c(i2c_client, &cs4265_regmap); 601 cs4265->regmap = devm_regmap_init_i2c(i2c_client, &cs4265_regmap);
604 if (IS_ERR(cs4265->regmap)) { 602 if (IS_ERR(cs4265->regmap)) {
diff --git a/sound/soc/codecs/cs4271-i2c.c b/sound/soc/codecs/cs4271-i2c.c
new file mode 100644
index 000000000000..b264da030340
--- /dev/null
+++ b/sound/soc/codecs/cs4271-i2c.c
@@ -0,0 +1,62 @@
1/*
2 * CS4271 I2C audio driver
3 *
4 * Copyright (c) 2010 Alexander Sverdlin <subaparts@yandex.ru>
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 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/module.h>
18#include <linux/i2c.h>
19#include <linux/regmap.h>
20#include <sound/soc.h>
21#include "cs4271.h"
22
23static int cs4271_i2c_probe(struct i2c_client *client,
24 const struct i2c_device_id *id)
25{
26 struct regmap_config config;
27
28 config = cs4271_regmap_config;
29 config.reg_bits = 8;
30 config.val_bits = 8;
31
32 return cs4271_probe(&client->dev,
33 devm_regmap_init_i2c(client, &config));
34}
35
36static int cs4271_i2c_remove(struct i2c_client *client)
37{
38 snd_soc_unregister_codec(&client->dev);
39 return 0;
40}
41
42static const struct i2c_device_id cs4271_i2c_id[] = {
43 { "cs4271", 0 },
44 { }
45};
46MODULE_DEVICE_TABLE(i2c, cs4271_i2c_id);
47
48static struct i2c_driver cs4271_i2c_driver = {
49 .driver = {
50 .name = "cs4271",
51 .owner = THIS_MODULE,
52 .of_match_table = of_match_ptr(cs4271_dt_ids),
53 },
54 .probe = cs4271_i2c_probe,
55 .remove = cs4271_i2c_remove,
56 .id_table = cs4271_i2c_id,
57};
58module_i2c_driver(cs4271_i2c_driver);
59
60MODULE_DESCRIPTION("ASoC CS4271 I2C Driver");
61MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
62MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs4271-spi.c b/sound/soc/codecs/cs4271-spi.c
new file mode 100644
index 000000000000..acd49d86e706
--- /dev/null
+++ b/sound/soc/codecs/cs4271-spi.c
@@ -0,0 +1,55 @@
1/*
2 * CS4271 SPI audio driver
3 *
4 * Copyright (c) 2010 Alexander Sverdlin <subaparts@yandex.ru>
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 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/module.h>
18#include <linux/spi/spi.h>
19#include <linux/regmap.h>
20#include <sound/soc.h>
21#include "cs4271.h"
22
23static int cs4271_spi_probe(struct spi_device *spi)
24{
25 struct regmap_config config;
26
27 config = cs4271_regmap_config;
28 config.reg_bits = 16;
29 config.val_bits = 8;
30 config.read_flag_mask = 0x21;
31 config.write_flag_mask = 0x20;
32
33 return cs4271_probe(&spi->dev, devm_regmap_init_spi(spi, &config));
34}
35
36static int cs4271_spi_remove(struct spi_device *spi)
37{
38 snd_soc_unregister_codec(&spi->dev);
39 return 0;
40}
41
42static struct spi_driver cs4271_spi_driver = {
43 .driver = {
44 .name = "cs4271",
45 .owner = THIS_MODULE,
46 .of_match_table = of_match_ptr(cs4271_dt_ids),
47 },
48 .probe = cs4271_spi_probe,
49 .remove = cs4271_spi_remove,
50};
51module_spi_driver(cs4271_spi_driver);
52
53MODULE_DESCRIPTION("ASoC CS4271 SPI Driver");
54MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
55MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
index 93cec52f4733..79a4efcb894c 100644
--- a/sound/soc/codecs/cs4271.c
+++ b/sound/soc/codecs/cs4271.c
@@ -23,8 +23,6 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/i2c.h>
27#include <linux/spi/spi.h>
28#include <linux/of.h> 26#include <linux/of.h>
29#include <linux/of_device.h> 27#include <linux/of_device.h>
30#include <linux/of_gpio.h> 28#include <linux/of_gpio.h>
@@ -32,6 +30,7 @@
32#include <sound/soc.h> 30#include <sound/soc.h>
33#include <sound/tlv.h> 31#include <sound/tlv.h>
34#include <sound/cs4271.h> 32#include <sound/cs4271.h>
33#include "cs4271.h"
35 34
36#define CS4271_PCM_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \ 35#define CS4271_PCM_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
37 SNDRV_PCM_FMTBIT_S24_LE | \ 36 SNDRV_PCM_FMTBIT_S24_LE | \
@@ -527,14 +526,15 @@ static int cs4271_soc_resume(struct snd_soc_codec *codec)
527#endif /* CONFIG_PM */ 526#endif /* CONFIG_PM */
528 527
529#ifdef CONFIG_OF 528#ifdef CONFIG_OF
530static const struct of_device_id cs4271_dt_ids[] = { 529const struct of_device_id cs4271_dt_ids[] = {
531 { .compatible = "cirrus,cs4271", }, 530 { .compatible = "cirrus,cs4271", },
532 { } 531 { }
533}; 532};
534MODULE_DEVICE_TABLE(of, cs4271_dt_ids); 533MODULE_DEVICE_TABLE(of, cs4271_dt_ids);
534EXPORT_SYMBOL_GPL(cs4271_dt_ids);
535#endif 535#endif
536 536
537static int cs4271_probe(struct snd_soc_codec *codec) 537static int cs4271_codec_probe(struct snd_soc_codec *codec)
538{ 538{
539 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); 539 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec);
540 struct cs4271_platform_data *cs4271plat = codec->dev->platform_data; 540 struct cs4271_platform_data *cs4271plat = codec->dev->platform_data;
@@ -587,7 +587,7 @@ static int cs4271_probe(struct snd_soc_codec *codec)
587 return 0; 587 return 0;
588} 588}
589 589
590static int cs4271_remove(struct snd_soc_codec *codec) 590static int cs4271_codec_remove(struct snd_soc_codec *codec)
591{ 591{
592 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); 592 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec);
593 593
@@ -599,8 +599,8 @@ static int cs4271_remove(struct snd_soc_codec *codec)
599}; 599};
600 600
601static struct snd_soc_codec_driver soc_codec_dev_cs4271 = { 601static struct snd_soc_codec_driver soc_codec_dev_cs4271 = {
602 .probe = cs4271_probe, 602 .probe = cs4271_codec_probe,
603 .remove = cs4271_remove, 603 .remove = cs4271_codec_remove,
604 .suspend = cs4271_soc_suspend, 604 .suspend = cs4271_soc_suspend,
605 .resume = cs4271_soc_resume, 605 .resume = cs4271_soc_resume,
606 606
@@ -642,14 +642,8 @@ static int cs4271_common_probe(struct device *dev,
642 return 0; 642 return 0;
643} 643}
644 644
645#if defined(CONFIG_SPI_MASTER) 645const struct regmap_config cs4271_regmap_config = {
646
647static const struct regmap_config cs4271_spi_regmap = {
648 .reg_bits = 16,
649 .val_bits = 8,
650 .max_register = CS4271_LASTREG, 646 .max_register = CS4271_LASTREG,
651 .read_flag_mask = 0x21,
652 .write_flag_mask = 0x20,
653 647
654 .reg_defaults = cs4271_reg_defaults, 648 .reg_defaults = cs4271_reg_defaults,
655 .num_reg_defaults = ARRAY_SIZE(cs4271_reg_defaults), 649 .num_reg_defaults = ARRAY_SIZE(cs4271_reg_defaults),
@@ -657,140 +651,27 @@ static const struct regmap_config cs4271_spi_regmap = {
657 651
658 .volatile_reg = cs4271_volatile_reg, 652 .volatile_reg = cs4271_volatile_reg,
659}; 653};
654EXPORT_SYMBOL_GPL(cs4271_regmap_config);
660 655
661static int cs4271_spi_probe(struct spi_device *spi) 656int cs4271_probe(struct device *dev, struct regmap *regmap)
662{ 657{
663 struct cs4271_private *cs4271; 658 struct cs4271_private *cs4271;
664 int ret; 659 int ret;
665 660
666 ret = cs4271_common_probe(&spi->dev, &cs4271); 661 if (IS_ERR(regmap))
667 if (ret < 0) 662 return PTR_ERR(regmap);
668 return ret;
669
670 spi_set_drvdata(spi, cs4271);
671 cs4271->regmap = devm_regmap_init_spi(spi, &cs4271_spi_regmap);
672 if (IS_ERR(cs4271->regmap))
673 return PTR_ERR(cs4271->regmap);
674
675 return snd_soc_register_codec(&spi->dev, &soc_codec_dev_cs4271,
676 &cs4271_dai, 1);
677}
678
679static int cs4271_spi_remove(struct spi_device *spi)
680{
681 snd_soc_unregister_codec(&spi->dev);
682 return 0;
683}
684
685static struct spi_driver cs4271_spi_driver = {
686 .driver = {
687 .name = "cs4271",
688 .owner = THIS_MODULE,
689 .of_match_table = of_match_ptr(cs4271_dt_ids),
690 },
691 .probe = cs4271_spi_probe,
692 .remove = cs4271_spi_remove,
693};
694#endif /* defined(CONFIG_SPI_MASTER) */
695
696#if IS_ENABLED(CONFIG_I2C)
697static const struct i2c_device_id cs4271_i2c_id[] = {
698 {"cs4271", 0},
699 {}
700};
701MODULE_DEVICE_TABLE(i2c, cs4271_i2c_id);
702 663
703static const struct regmap_config cs4271_i2c_regmap = { 664 ret = cs4271_common_probe(dev, &cs4271);
704 .reg_bits = 8,
705 .val_bits = 8,
706 .max_register = CS4271_LASTREG,
707
708 .reg_defaults = cs4271_reg_defaults,
709 .num_reg_defaults = ARRAY_SIZE(cs4271_reg_defaults),
710 .cache_type = REGCACHE_RBTREE,
711
712 .volatile_reg = cs4271_volatile_reg,
713};
714
715static int cs4271_i2c_probe(struct i2c_client *client,
716 const struct i2c_device_id *id)
717{
718 struct cs4271_private *cs4271;
719 int ret;
720
721 ret = cs4271_common_probe(&client->dev, &cs4271);
722 if (ret < 0) 665 if (ret < 0)
723 return ret; 666 return ret;
724 667
725 i2c_set_clientdata(client, cs4271); 668 dev_set_drvdata(dev, cs4271);
726 cs4271->regmap = devm_regmap_init_i2c(client, &cs4271_i2c_regmap); 669 cs4271->regmap = regmap;
727 if (IS_ERR(cs4271->regmap))
728 return PTR_ERR(cs4271->regmap);
729 670
730 return snd_soc_register_codec(&client->dev, &soc_codec_dev_cs4271, 671 return snd_soc_register_codec(dev, &soc_codec_dev_cs4271, &cs4271_dai,
731 &cs4271_dai, 1); 672 1);
732}
733
734static int cs4271_i2c_remove(struct i2c_client *client)
735{
736 snd_soc_unregister_codec(&client->dev);
737 return 0;
738}
739
740static struct i2c_driver cs4271_i2c_driver = {
741 .driver = {
742 .name = "cs4271",
743 .owner = THIS_MODULE,
744 .of_match_table = of_match_ptr(cs4271_dt_ids),
745 },
746 .id_table = cs4271_i2c_id,
747 .probe = cs4271_i2c_probe,
748 .remove = cs4271_i2c_remove,
749};
750#endif /* IS_ENABLED(CONFIG_I2C) */
751
752/*
753 * We only register our serial bus driver here without
754 * assignment to particular chip. So if any of the below
755 * fails, there is some problem with I2C or SPI subsystem.
756 * In most cases this module will be compiled with support
757 * of only one serial bus.
758 */
759static int __init cs4271_modinit(void)
760{
761 int ret;
762
763#if IS_ENABLED(CONFIG_I2C)
764 ret = i2c_add_driver(&cs4271_i2c_driver);
765 if (ret) {
766 pr_err("Failed to register CS4271 I2C driver: %d\n", ret);
767 return ret;
768 }
769#endif
770
771#if defined(CONFIG_SPI_MASTER)
772 ret = spi_register_driver(&cs4271_spi_driver);
773 if (ret) {
774 pr_err("Failed to register CS4271 SPI driver: %d\n", ret);
775 return ret;
776 }
777#endif
778
779 return 0;
780}
781module_init(cs4271_modinit);
782
783static void __exit cs4271_modexit(void)
784{
785#if defined(CONFIG_SPI_MASTER)
786 spi_unregister_driver(&cs4271_spi_driver);
787#endif
788
789#if IS_ENABLED(CONFIG_I2C)
790 i2c_del_driver(&cs4271_i2c_driver);
791#endif
792} 673}
793module_exit(cs4271_modexit); 674EXPORT_SYMBOL_GPL(cs4271_probe);
794 675
795MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>"); 676MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
796MODULE_DESCRIPTION("Cirrus Logic CS4271 ALSA SoC Codec Driver"); 677MODULE_DESCRIPTION("Cirrus Logic CS4271 ALSA SoC Codec Driver");
diff --git a/sound/soc/codecs/cs4271.h b/sound/soc/codecs/cs4271.h
new file mode 100644
index 000000000000..9adad8eefdc9
--- /dev/null
+++ b/sound/soc/codecs/cs4271.h
@@ -0,0 +1,11 @@
1#ifndef _CS4271_PRIV_H
2#define _CS4271_PRIV_H
3
4#include <linux/regmap.h>
5
6extern const struct of_device_id cs4271_dt_ids[];
7extern const struct regmap_config cs4271_regmap_config;
8
9int cs4271_probe(struct device *dev, struct regmap *regmap);
10
11#endif
diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c
index 669c38fc3034..b3951524339f 100644
--- a/sound/soc/codecs/cs42l51.c
+++ b/sound/soc/codecs/cs42l51.c
@@ -153,15 +153,17 @@ static const struct snd_kcontrol_new cs42l51_snd_controls[] = {
153static int cs42l51_pdn_event(struct snd_soc_dapm_widget *w, 153static int cs42l51_pdn_event(struct snd_soc_dapm_widget *w,
154 struct snd_kcontrol *kcontrol, int event) 154 struct snd_kcontrol *kcontrol, int event)
155{ 155{
156 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
157
156 switch (event) { 158 switch (event) {
157 case SND_SOC_DAPM_PRE_PMD: 159 case SND_SOC_DAPM_PRE_PMD:
158 snd_soc_update_bits(w->codec, CS42L51_POWER_CTL1, 160 snd_soc_update_bits(codec, CS42L51_POWER_CTL1,
159 CS42L51_POWER_CTL1_PDN, 161 CS42L51_POWER_CTL1_PDN,
160 CS42L51_POWER_CTL1_PDN); 162 CS42L51_POWER_CTL1_PDN);
161 break; 163 break;
162 default: 164 default:
163 case SND_SOC_DAPM_POST_PMD: 165 case SND_SOC_DAPM_POST_PMD:
164 snd_soc_update_bits(w->codec, CS42L51_POWER_CTL1, 166 snd_soc_update_bits(codec, CS42L51_POWER_CTL1,
165 CS42L51_POWER_CTL1_PDN, 0); 167 CS42L51_POWER_CTL1_PDN, 0);
166 break; 168 break;
167 } 169 }
diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index 2f8b94683e83..7c55537c69cf 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -584,7 +584,7 @@ static const struct snd_kcontrol_new cs42l73_snd_controls[] = {
584static int cs42l73_spklo_spk_amp_event(struct snd_soc_dapm_widget *w, 584static int cs42l73_spklo_spk_amp_event(struct snd_soc_dapm_widget *w,
585 struct snd_kcontrol *kcontrol, int event) 585 struct snd_kcontrol *kcontrol, int event)
586{ 586{
587 struct snd_soc_codec *codec = w->codec; 587 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
588 struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec); 588 struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec);
589 switch (event) { 589 switch (event) {
590 case SND_SOC_DAPM_POST_PMD: 590 case SND_SOC_DAPM_POST_PMD:
@@ -600,7 +600,7 @@ static int cs42l73_spklo_spk_amp_event(struct snd_soc_dapm_widget *w,
600static int cs42l73_ear_amp_event(struct snd_soc_dapm_widget *w, 600static int cs42l73_ear_amp_event(struct snd_soc_dapm_widget *w,
601 struct snd_kcontrol *kcontrol, int event) 601 struct snd_kcontrol *kcontrol, int event)
602{ 602{
603 struct snd_soc_codec *codec = w->codec; 603 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
604 struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec); 604 struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec);
605 switch (event) { 605 switch (event) {
606 case SND_SOC_DAPM_POST_PMD: 606 case SND_SOC_DAPM_POST_PMD:
@@ -618,7 +618,7 @@ static int cs42l73_ear_amp_event(struct snd_soc_dapm_widget *w,
618static int cs42l73_hp_amp_event(struct snd_soc_dapm_widget *w, 618static int cs42l73_hp_amp_event(struct snd_soc_dapm_widget *w,
619 struct snd_kcontrol *kcontrol, int event) 619 struct snd_kcontrol *kcontrol, int event)
620{ 620{
621 struct snd_soc_codec *codec = w->codec; 621 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
622 struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec); 622 struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec);
623 switch (event) { 623 switch (event) {
624 case SND_SOC_DAPM_POST_PMD: 624 case SND_SOC_DAPM_POST_PMD:
diff --git a/sound/soc/codecs/hdmi.c b/sound/soc/codecs/hdmi.c
index 1087fd5f9917..1391ad50f95d 100644
--- a/sound/soc/codecs/hdmi.c
+++ b/sound/soc/codecs/hdmi.c
@@ -47,6 +47,7 @@ static struct snd_soc_dai_driver hdmi_codec_dai = {
47 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, 47 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000,
48 .formats = SNDRV_PCM_FMTBIT_S16_LE | 48 .formats = SNDRV_PCM_FMTBIT_S16_LE |
49 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, 49 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE,
50 .sig_bits = 24,
50 }, 51 },
51 .capture = { 52 .capture = {
52 .stream_name = "Capture", 53 .stream_name = "Capture",
@@ -75,6 +76,7 @@ static struct snd_soc_codec_driver hdmi_codec = {
75 .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), 76 .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets),
76 .dapm_routes = hdmi_routes, 77 .dapm_routes = hdmi_routes,
77 .num_dapm_routes = ARRAY_SIZE(hdmi_routes), 78 .num_dapm_routes = ARRAY_SIZE(hdmi_routes),
79 .ignore_pmdown_time = true,
78}; 80};
79 81
80static int hdmi_codec_probe(struct platform_device *pdev) 82static int hdmi_codec_probe(struct platform_device *pdev)
diff --git a/sound/soc/codecs/lm49453.c b/sound/soc/codecs/lm49453.c
index c1ae5764983f..c4dfde9bdf1c 100644
--- a/sound/soc/codecs/lm49453.c
+++ b/sound/soc/codecs/lm49453.c
@@ -1395,15 +1395,7 @@ static struct snd_soc_dai_driver lm49453_dai[] = {
1395 }, 1395 },
1396}; 1396};
1397 1397
1398/* power down chip */
1399static int lm49453_remove(struct snd_soc_codec *codec)
1400{
1401 lm49453_set_bias_level(codec, SND_SOC_BIAS_OFF);
1402 return 0;
1403}
1404
1405static struct snd_soc_codec_driver soc_codec_dev_lm49453 = { 1398static struct snd_soc_codec_driver soc_codec_dev_lm49453 = {
1406 .remove = lm49453_remove,
1407 .set_bias_level = lm49453_set_bias_level, 1399 .set_bias_level = lm49453_set_bias_level,
1408 .controls = lm49453_snd_controls, 1400 .controls = lm49453_snd_controls,
1409 .num_controls = ARRAY_SIZE(lm49453_snd_controls), 1401 .num_controls = ARRAY_SIZE(lm49453_snd_controls),
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 2cd3e5427441..805b3f8cd39d 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -875,7 +875,7 @@ static const struct snd_kcontrol_new max98088_right_ADC_mixer_controls[] = {
875static int max98088_mic_event(struct snd_soc_dapm_widget *w, 875static int max98088_mic_event(struct snd_soc_dapm_widget *w,
876 struct snd_kcontrol *kcontrol, int event) 876 struct snd_kcontrol *kcontrol, int event)
877{ 877{
878 struct snd_soc_codec *codec = w->codec; 878 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
879 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec); 879 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
880 880
881 switch (event) { 881 switch (event) {
@@ -905,7 +905,7 @@ static int max98088_mic_event(struct snd_soc_dapm_widget *w,
905static int max98088_line_pga(struct snd_soc_dapm_widget *w, 905static int max98088_line_pga(struct snd_soc_dapm_widget *w,
906 int event, int line, u8 channel) 906 int event, int line, u8 channel)
907{ 907{
908 struct snd_soc_codec *codec = w->codec; 908 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
909 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec); 909 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
910 u8 *state; 910 u8 *state;
911 911
@@ -1887,25 +1887,6 @@ static void max98088_handle_pdata(struct snd_soc_codec *codec)
1887 max98088_handle_eq_pdata(codec); 1887 max98088_handle_eq_pdata(codec);
1888} 1888}
1889 1889
1890#ifdef CONFIG_PM
1891static int max98088_suspend(struct snd_soc_codec *codec)
1892{
1893 max98088_set_bias_level(codec, SND_SOC_BIAS_OFF);
1894
1895 return 0;
1896}
1897
1898static int max98088_resume(struct snd_soc_codec *codec)
1899{
1900 max98088_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1901
1902 return 0;
1903}
1904#else
1905#define max98088_suspend NULL
1906#define max98088_resume NULL
1907#endif
1908
1909static int max98088_probe(struct snd_soc_codec *codec) 1890static int max98088_probe(struct snd_soc_codec *codec)
1910{ 1891{
1911 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec); 1892 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
@@ -1946,9 +1927,6 @@ static int max98088_probe(struct snd_soc_codec *codec)
1946 1927
1947 snd_soc_write(codec, M98088_REG_51_PWR_SYS, M98088_PWRSV); 1928 snd_soc_write(codec, M98088_REG_51_PWR_SYS, M98088_PWRSV);
1948 1929
1949 /* initialize registers cache to hardware default */
1950 max98088_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1951
1952 snd_soc_write(codec, M98088_REG_0F_IRQ_ENABLE, 0x00); 1930 snd_soc_write(codec, M98088_REG_0F_IRQ_ENABLE, 0x00);
1953 1931
1954 snd_soc_write(codec, M98088_REG_22_MIX_DAC, 1932 snd_soc_write(codec, M98088_REG_22_MIX_DAC,
@@ -1974,7 +1952,6 @@ static int max98088_remove(struct snd_soc_codec *codec)
1974{ 1952{
1975 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec); 1953 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1976 1954
1977 max98088_set_bias_level(codec, SND_SOC_BIAS_OFF);
1978 kfree(max98088->eq_texts); 1955 kfree(max98088->eq_texts);
1979 1956
1980 return 0; 1957 return 0;
@@ -1983,9 +1960,9 @@ static int max98088_remove(struct snd_soc_codec *codec)
1983static struct snd_soc_codec_driver soc_codec_dev_max98088 = { 1960static struct snd_soc_codec_driver soc_codec_dev_max98088 = {
1984 .probe = max98088_probe, 1961 .probe = max98088_probe,
1985 .remove = max98088_remove, 1962 .remove = max98088_remove,
1986 .suspend = max98088_suspend,
1987 .resume = max98088_resume,
1988 .set_bias_level = max98088_set_bias_level, 1963 .set_bias_level = max98088_set_bias_level,
1964 .suspend_bias_off = true,
1965
1989 .controls = max98088_snd_controls, 1966 .controls = max98088_snd_controls,
1990 .num_controls = ARRAY_SIZE(max98088_snd_controls), 1967 .num_controls = ARRAY_SIZE(max98088_snd_controls),
1991 .dapm_widgets = max98088_dapm_widgets, 1968 .dapm_widgets = max98088_dapm_widgets,
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index 1229554f1464..151f718241ea 100644
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -806,7 +806,7 @@ static const struct snd_kcontrol_new max98091_snd_controls[] = {
806static int max98090_micinput_event(struct snd_soc_dapm_widget *w, 806static int max98090_micinput_event(struct snd_soc_dapm_widget *w,
807 struct snd_kcontrol *kcontrol, int event) 807 struct snd_kcontrol *kcontrol, int event)
808{ 808{
809 struct snd_soc_codec *codec = w->codec; 809 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
810 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec); 810 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
811 811
812 unsigned int val = snd_soc_read(codec, w->reg); 812 unsigned int val = snd_soc_read(codec, w->reg);
@@ -1311,6 +1311,10 @@ static const struct snd_soc_dapm_route max98090_dapm_routes[] = {
1311 {"MIC1 Input", NULL, "MIC1"}, 1311 {"MIC1 Input", NULL, "MIC1"},
1312 {"MIC2 Input", NULL, "MIC2"}, 1312 {"MIC2 Input", NULL, "MIC2"},
1313 1313
1314 {"DMICL", NULL, "DMICL_ENA"},
1315 {"DMICL", NULL, "DMICR_ENA"},
1316 {"DMICR", NULL, "DMICL_ENA"},
1317 {"DMICR", NULL, "DMICR_ENA"},
1314 {"DMICL", NULL, "AHPF"}, 1318 {"DMICL", NULL, "AHPF"},
1315 {"DMICR", NULL, "AHPF"}, 1319 {"DMICR", NULL, "AHPF"},
1316 1320
@@ -1368,8 +1372,6 @@ static const struct snd_soc_dapm_route max98090_dapm_routes[] = {
1368 {"DMIC Mux", "ADC", "ADCR"}, 1372 {"DMIC Mux", "ADC", "ADCR"},
1369 {"DMIC Mux", "DMIC", "DMICL"}, 1373 {"DMIC Mux", "DMIC", "DMICL"},
1370 {"DMIC Mux", "DMIC", "DMICR"}, 1374 {"DMIC Mux", "DMIC", "DMICR"},
1371 {"DMIC Mux", "DMIC", "DMICL_ENA"},
1372 {"DMIC Mux", "DMIC", "DMICR_ENA"},
1373 1375
1374 {"LBENL Mux", "Normal", "DMIC Mux"}, 1376 {"LBENL Mux", "Normal", "DMIC Mux"},
1375 {"LBENL Mux", "Loopback", "LTENL Mux"}, 1377 {"LBENL Mux", "Loopback", "LTENL Mux"},
@@ -1395,8 +1397,8 @@ static const struct snd_soc_dapm_route max98090_dapm_routes[] = {
1395 {"STENL Mux", "Sidetone Left", "DMICL"}, 1397 {"STENL Mux", "Sidetone Left", "DMICL"},
1396 {"STENR Mux", "Sidetone Right", "ADCR"}, 1398 {"STENR Mux", "Sidetone Right", "ADCR"},
1397 {"STENR Mux", "Sidetone Right", "DMICR"}, 1399 {"STENR Mux", "Sidetone Right", "DMICR"},
1398 {"DACL", "NULL", "STENL Mux"}, 1400 {"DACL", NULL, "STENL Mux"},
1399 {"DACR", "NULL", "STENL Mux"}, 1401 {"DACR", NULL, "STENR Mux"},
1400 1402
1401 {"AIFINL", NULL, "SHDN"}, 1403 {"AIFINL", NULL, "SHDN"},
1402 {"AIFINR", NULL, "SHDN"}, 1404 {"AIFINR", NULL, "SHDN"},
@@ -1826,27 +1828,155 @@ static int max98090_set_bias_level(struct snd_soc_codec *codec,
1826 return 0; 1828 return 0;
1827} 1829}
1828 1830
1829static const int comp_pclk_rates[] = { 1831static const int dmic_divisors[] = { 2, 3, 4, 5, 6, 8 };
1830 11289600, 12288000, 12000000, 13000000, 19200000
1831};
1832
1833static const int dmic_micclk[] = {
1834 2, 2, 2, 2, 4, 2
1835};
1836 1832
1837static const int comp_lrclk_rates[] = { 1833static const int comp_lrclk_rates[] = {
1838 8000, 16000, 32000, 44100, 48000, 96000 1834 8000, 16000, 32000, 44100, 48000, 96000
1839}; 1835};
1840 1836
1841static const int dmic_comp[6][6] = { 1837struct dmic_table {
1842 {7, 8, 3, 3, 3, 3}, 1838 int pclk;
1843 {7, 8, 3, 3, 3, 3}, 1839 struct {
1844 {7, 8, 3, 3, 3, 3}, 1840 int freq;
1845 {7, 8, 3, 1, 1, 1}, 1841 int comp[6]; /* One each for 8, 16, 32, 44.1, 48, and 96 kHz */
1846 {7, 8, 3, 1, 2, 2}, 1842 } settings[6]; /* One for each dmic divisor. */
1847 {7, 8, 3, 3, 3, 3}
1848}; 1843};
1849 1844
1845static const struct dmic_table dmic_table[] = { /* One for each pclk freq. */
1846 {
1847 .pclk = 11289600,
1848 .settings = {
1849 { .freq = 2, .comp = { 7, 8, 3, 3, 3, 3 } },
1850 { .freq = 1, .comp = { 7, 8, 2, 2, 2, 2 } },
1851 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1852 { .freq = 0, .comp = { 7, 8, 6, 6, 6, 6 } },
1853 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1854 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1855 },
1856 },
1857 {
1858 .pclk = 12000000,
1859 .settings = {
1860 { .freq = 2, .comp = { 7, 8, 3, 3, 3, 3 } },
1861 { .freq = 1, .comp = { 7, 8, 2, 2, 2, 2 } },
1862 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1863 { .freq = 0, .comp = { 7, 8, 5, 5, 6, 6 } },
1864 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1865 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1866 }
1867 },
1868 {
1869 .pclk = 12288000,
1870 .settings = {
1871 { .freq = 2, .comp = { 7, 8, 3, 3, 3, 3 } },
1872 { .freq = 1, .comp = { 7, 8, 2, 2, 2, 2 } },
1873 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1874 { .freq = 0, .comp = { 7, 8, 6, 6, 6, 6 } },
1875 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1876 { .freq = 0, .comp = { 7, 8, 3, 3, 3, 3 } },
1877 }
1878 },
1879 {
1880 .pclk = 13000000,
1881 .settings = {
1882 { .freq = 2, .comp = { 7, 8, 1, 1, 1, 1 } },
1883 { .freq = 1, .comp = { 7, 8, 0, 0, 0, 0 } },
1884 { .freq = 0, .comp = { 7, 8, 1, 1, 1, 1 } },
1885 { .freq = 0, .comp = { 7, 8, 4, 4, 5, 5 } },
1886 { .freq = 0, .comp = { 7, 8, 1, 1, 1, 1 } },
1887 { .freq = 0, .comp = { 7, 8, 1, 1, 1, 1 } },
1888 }
1889 },
1890 {
1891 .pclk = 19200000,
1892 .settings = {
1893 { .freq = 2, .comp = { 0, 0, 0, 0, 0, 0 } },
1894 { .freq = 1, .comp = { 7, 8, 1, 1, 1, 1 } },
1895 { .freq = 0, .comp = { 7, 8, 5, 5, 6, 6 } },
1896 { .freq = 0, .comp = { 7, 8, 2, 2, 3, 3 } },
1897 { .freq = 0, .comp = { 7, 8, 1, 1, 2, 2 } },
1898 { .freq = 0, .comp = { 7, 8, 5, 5, 6, 6 } },
1899 }
1900 },
1901};
1902
1903static int max98090_find_divisor(int target_freq, int pclk)
1904{
1905 int current_diff = INT_MAX;
1906 int test_diff = INT_MAX;
1907 int divisor_index = 0;
1908 int i;
1909
1910 for (i = 0; i < ARRAY_SIZE(dmic_divisors); i++) {
1911 test_diff = abs(target_freq - (pclk / dmic_divisors[i]));
1912 if (test_diff < current_diff) {
1913 current_diff = test_diff;
1914 divisor_index = i;
1915 }
1916 }
1917
1918 return divisor_index;
1919}
1920
1921static int max98090_find_closest_pclk(int pclk)
1922{
1923 int m1;
1924 int m2;
1925 int i;
1926
1927 for (i = 0; i < ARRAY_SIZE(dmic_table); i++) {
1928 if (pclk == dmic_table[i].pclk)
1929 return i;
1930 if (pclk < dmic_table[i].pclk) {
1931 if (i == 0)
1932 return i;
1933 m1 = pclk - dmic_table[i-1].pclk;
1934 m2 = dmic_table[i].pclk - pclk;
1935 if (m1 < m2)
1936 return i - 1;
1937 else
1938 return i;
1939 }
1940 }
1941
1942 return -EINVAL;
1943}
1944
1945static int max98090_configure_dmic(struct max98090_priv *max98090,
1946 int target_dmic_clk, int pclk, int fs)
1947{
1948 int micclk_index;
1949 int pclk_index;
1950 int dmic_freq;
1951 int dmic_comp;
1952 int i;
1953
1954 pclk_index = max98090_find_closest_pclk(pclk);
1955 if (pclk_index < 0)
1956 return pclk_index;
1957
1958 micclk_index = max98090_find_divisor(target_dmic_clk, pclk);
1959
1960 for (i = 0; i < ARRAY_SIZE(comp_lrclk_rates) - 1; i++) {
1961 if (fs <= (comp_lrclk_rates[i] + comp_lrclk_rates[i+1]) / 2)
1962 break;
1963 }
1964
1965 dmic_freq = dmic_table[pclk_index].settings[micclk_index].freq;
1966 dmic_comp = dmic_table[pclk_index].settings[micclk_index].comp[i];
1967
1968 regmap_update_bits(max98090->regmap, M98090_REG_DIGITAL_MIC_ENABLE,
1969 M98090_MICCLK_MASK,
1970 micclk_index << M98090_MICCLK_SHIFT);
1971
1972 regmap_update_bits(max98090->regmap, M98090_REG_DIGITAL_MIC_CONFIG,
1973 M98090_DMIC_COMP_MASK | M98090_DMIC_FREQ_MASK,
1974 dmic_comp << M98090_DMIC_COMP_SHIFT |
1975 dmic_freq << M98090_DMIC_FREQ_SHIFT);
1976
1977 return 0;
1978}
1979
1850static int max98090_dai_hw_params(struct snd_pcm_substream *substream, 1980static int max98090_dai_hw_params(struct snd_pcm_substream *substream,
1851 struct snd_pcm_hw_params *params, 1981 struct snd_pcm_hw_params *params,
1852 struct snd_soc_dai *dai) 1982 struct snd_soc_dai *dai)
@@ -1854,7 +1984,6 @@ static int max98090_dai_hw_params(struct snd_pcm_substream *substream,
1854 struct snd_soc_codec *codec = dai->codec; 1984 struct snd_soc_codec *codec = dai->codec;
1855 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec); 1985 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
1856 struct max98090_cdata *cdata; 1986 struct max98090_cdata *cdata;
1857 int i, j;
1858 1987
1859 cdata = &max98090->dai[0]; 1988 cdata = &max98090->dai[0];
1860 max98090->bclk = snd_soc_params_to_bclk(params); 1989 max98090->bclk = snd_soc_params_to_bclk(params);
@@ -1893,27 +2022,8 @@ static int max98090_dai_hw_params(struct snd_pcm_substream *substream,
1893 snd_soc_update_bits(codec, M98090_REG_FILTER_CONFIG, 2022 snd_soc_update_bits(codec, M98090_REG_FILTER_CONFIG,
1894 M98090_DHF_MASK, M98090_DHF_MASK); 2023 M98090_DHF_MASK, M98090_DHF_MASK);
1895 2024
1896 /* Check for supported PCLK to LRCLK ratios */ 2025 max98090_configure_dmic(max98090, max98090->dmic_freq, max98090->pclk,
1897 for (j = 0; j < ARRAY_SIZE(comp_pclk_rates); j++) { 2026 max98090->lrclk);
1898 if (comp_pclk_rates[j] == max98090->sysclk) {
1899 break;
1900 }
1901 }
1902
1903 for (i = 0; i < ARRAY_SIZE(comp_lrclk_rates) - 1; i++) {
1904 if (max98090->lrclk <= (comp_lrclk_rates[i] +
1905 comp_lrclk_rates[i + 1]) / 2) {
1906 break;
1907 }
1908 }
1909
1910 snd_soc_update_bits(codec, M98090_REG_DIGITAL_MIC_ENABLE,
1911 M98090_MICCLK_MASK,
1912 dmic_micclk[j] << M98090_MICCLK_SHIFT);
1913
1914 snd_soc_update_bits(codec, M98090_REG_DIGITAL_MIC_CONFIG,
1915 M98090_DMIC_COMP_MASK,
1916 dmic_comp[j][i] << M98090_DMIC_COMP_SHIFT);
1917 2027
1918 return 0; 2028 return 0;
1919} 2029}
@@ -1944,12 +2054,15 @@ static int max98090_dai_set_sysclk(struct snd_soc_dai *dai,
1944 if ((freq >= 10000000) && (freq <= 20000000)) { 2054 if ((freq >= 10000000) && (freq <= 20000000)) {
1945 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK, 2055 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
1946 M98090_PSCLK_DIV1); 2056 M98090_PSCLK_DIV1);
2057 max98090->pclk = freq;
1947 } else if ((freq > 20000000) && (freq <= 40000000)) { 2058 } else if ((freq > 20000000) && (freq <= 40000000)) {
1948 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK, 2059 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
1949 M98090_PSCLK_DIV2); 2060 M98090_PSCLK_DIV2);
2061 max98090->pclk = freq >> 1;
1950 } else if ((freq > 40000000) && (freq <= 60000000)) { 2062 } else if ((freq > 40000000) && (freq <= 60000000)) {
1951 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK, 2063 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
1952 M98090_PSCLK_DIV4); 2064 M98090_PSCLK_DIV4);
2065 max98090->pclk = freq >> 2;
1953 } else { 2066 } else {
1954 dev_err(codec->dev, "Invalid master clock frequency\n"); 2067 dev_err(codec->dev, "Invalid master clock frequency\n");
1955 return -EINVAL; 2068 return -EINVAL;
@@ -2324,6 +2437,7 @@ static int max98090_probe(struct snd_soc_codec *codec)
2324 /* Initialize private data */ 2437 /* Initialize private data */
2325 2438
2326 max98090->sysclk = (unsigned)-1; 2439 max98090->sysclk = (unsigned)-1;
2440 max98090->pclk = (unsigned)-1;
2327 max98090->master = false; 2441 max98090->master = false;
2328 2442
2329 cdata = &max98090->dai[0]; 2443 cdata = &max98090->dai[0];
@@ -2463,6 +2577,11 @@ static int max98090_i2c_probe(struct i2c_client *i2c,
2463 i2c_set_clientdata(i2c, max98090); 2577 i2c_set_clientdata(i2c, max98090);
2464 max98090->pdata = i2c->dev.platform_data; 2578 max98090->pdata = i2c->dev.platform_data;
2465 2579
2580 ret = of_property_read_u32(i2c->dev.of_node, "maxim,dmic-freq",
2581 &max98090->dmic_freq);
2582 if (ret < 0)
2583 max98090->dmic_freq = MAX98090_DEFAULT_DMIC_FREQ;
2584
2466 max98090->regmap = devm_regmap_init_i2c(i2c, &max98090_regmap); 2585 max98090->regmap = devm_regmap_init_i2c(i2c, &max98090_regmap);
2467 if (IS_ERR(max98090->regmap)) { 2586 if (IS_ERR(max98090->regmap)) {
2468 ret = PTR_ERR(max98090->regmap); 2587 ret = PTR_ERR(max98090->regmap);
diff --git a/sound/soc/codecs/max98090.h b/sound/soc/codecs/max98090.h
index a5f6bada06da..21ff743f5af2 100644
--- a/sound/soc/codecs/max98090.h
+++ b/sound/soc/codecs/max98090.h
@@ -12,6 +12,12 @@
12#define _MAX98090_H 12#define _MAX98090_H
13 13
14/* 14/*
15 * The default operating frequency for a DMIC attached to the codec.
16 * This can be overridden by a device tree property.
17 */
18#define MAX98090_DEFAULT_DMIC_FREQ 2500000
19
20/*
15 * MAX98090 Register Definitions 21 * MAX98090 Register Definitions
16 */ 22 */
17 23
@@ -1518,8 +1524,10 @@ struct max98090_priv {
1518 struct max98090_pdata *pdata; 1524 struct max98090_pdata *pdata;
1519 struct clk *mclk; 1525 struct clk *mclk;
1520 unsigned int sysclk; 1526 unsigned int sysclk;
1527 unsigned int pclk;
1521 unsigned int bclk; 1528 unsigned int bclk;
1522 unsigned int lrclk; 1529 unsigned int lrclk;
1530 u32 dmic_freq;
1523 struct max98090_cdata dai[1]; 1531 struct max98090_cdata dai[1];
1524 int jack_state; 1532 int jack_state;
1525 struct delayed_work jack_work; 1533 struct delayed_work jack_work;
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 0ee6797d5083..8fba0c3db798 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -16,6 +16,7 @@
16#include <linux/pm.h> 16#include <linux/pm.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/clk.h> 18#include <linux/clk.h>
19#include <linux/mutex.h>
19#include <sound/core.h> 20#include <sound/core.h>
20#include <sound/pcm.h> 21#include <sound/pcm.h>
21#include <sound/pcm_params.h> 22#include <sound/pcm_params.h>
@@ -57,6 +58,7 @@ struct max98095_priv {
57 unsigned int mic2pre; 58 unsigned int mic2pre;
58 struct snd_soc_jack *headphone_jack; 59 struct snd_soc_jack *headphone_jack;
59 struct snd_soc_jack *mic_jack; 60 struct snd_soc_jack *mic_jack;
61 struct mutex lock;
60}; 62};
61 63
62static const struct reg_default max98095_reg_def[] = { 64static const struct reg_default max98095_reg_def[] = {
@@ -864,7 +866,7 @@ static const struct snd_kcontrol_new max98095_right_ADC_mixer_controls[] = {
864static int max98095_mic_event(struct snd_soc_dapm_widget *w, 866static int max98095_mic_event(struct snd_soc_dapm_widget *w,
865 struct snd_kcontrol *kcontrol, int event) 867 struct snd_kcontrol *kcontrol, int event)
866{ 868{
867 struct snd_soc_codec *codec = w->codec; 869 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
868 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 870 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
869 871
870 switch (event) { 872 switch (event) {
@@ -894,7 +896,7 @@ static int max98095_mic_event(struct snd_soc_dapm_widget *w,
894static int max98095_line_pga(struct snd_soc_dapm_widget *w, 896static int max98095_line_pga(struct snd_soc_dapm_widget *w,
895 int event, u8 channel) 897 int event, u8 channel)
896{ 898{
897 struct snd_soc_codec *codec = w->codec; 899 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
898 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 900 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
899 u8 *state; 901 u8 *state;
900 902
@@ -942,7 +944,7 @@ static int max98095_pga_in2_event(struct snd_soc_dapm_widget *w,
942static int max98095_lineout_event(struct snd_soc_dapm_widget *w, 944static int max98095_lineout_event(struct snd_soc_dapm_widget *w,
943 struct snd_kcontrol *kcontrol, int event) 945 struct snd_kcontrol *kcontrol, int event)
944{ 946{
945 struct snd_soc_codec *codec = w->codec; 947 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
946 948
947 switch (event) { 949 switch (event) {
948 case SND_SOC_DAPM_POST_PMU: 950 case SND_SOC_DAPM_POST_PMU:
@@ -1803,7 +1805,7 @@ static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol,
1803 regsave = snd_soc_read(codec, M98095_088_CFG_LEVEL); 1805 regsave = snd_soc_read(codec, M98095_088_CFG_LEVEL);
1804 snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, 0); 1806 snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, 0);
1805 1807
1806 mutex_lock(&codec->mutex); 1808 mutex_lock(&max98095->lock);
1807 snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, M98095_SEG); 1809 snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, M98095_SEG);
1808 m98095_eq_band(codec, channel, 0, coef_set->band1); 1810 m98095_eq_band(codec, channel, 0, coef_set->band1);
1809 m98095_eq_band(codec, channel, 1, coef_set->band2); 1811 m98095_eq_band(codec, channel, 1, coef_set->band2);
@@ -1811,7 +1813,7 @@ static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol,
1811 m98095_eq_band(codec, channel, 3, coef_set->band4); 1813 m98095_eq_band(codec, channel, 3, coef_set->band4);
1812 m98095_eq_band(codec, channel, 4, coef_set->band5); 1814 m98095_eq_band(codec, channel, 4, coef_set->band5);
1813 snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, 0); 1815 snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, 0);
1814 mutex_unlock(&codec->mutex); 1816 mutex_unlock(&max98095->lock);
1815 1817
1816 /* Restore the original on/off state */ 1818 /* Restore the original on/off state */
1817 snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, regsave); 1819 snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, regsave);
@@ -1957,12 +1959,12 @@ static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
1957 regsave = snd_soc_read(codec, M98095_088_CFG_LEVEL); 1959 regsave = snd_soc_read(codec, M98095_088_CFG_LEVEL);
1958 snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, 0); 1960 snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, 0);
1959 1961
1960 mutex_lock(&codec->mutex); 1962 mutex_lock(&max98095->lock);
1961 snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, M98095_SEG); 1963 snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, M98095_SEG);
1962 m98095_biquad_band(codec, channel, 0, coef_set->band1); 1964 m98095_biquad_band(codec, channel, 0, coef_set->band1);
1963 m98095_biquad_band(codec, channel, 1, coef_set->band2); 1965 m98095_biquad_band(codec, channel, 1, coef_set->band2);
1964 snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, 0); 1966 snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, 0);
1965 mutex_unlock(&codec->mutex); 1967 mutex_unlock(&max98095->lock);
1966 1968
1967 /* Restore the original on/off state */ 1969 /* Restore the original on/off state */
1968 snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, regsave); 1970 snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, regsave);
@@ -2317,9 +2319,6 @@ static int max98095_probe(struct snd_soc_codec *codec)
2317 2319
2318 snd_soc_write(codec, M98095_097_PWR_SYS, M98095_PWRSV); 2320 snd_soc_write(codec, M98095_097_PWR_SYS, M98095_PWRSV);
2319 2321
2320 /* initialize registers cache to hardware default */
2321 max98095_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2322
2323 snd_soc_write(codec, M98095_048_MIX_DAC_LR, 2322 snd_soc_write(codec, M98095_048_MIX_DAC_LR,
2324 M98095_DAI1L_TO_DACL|M98095_DAI1R_TO_DACR); 2323 M98095_DAI1L_TO_DACL|M98095_DAI1R_TO_DACR);
2325 2324
@@ -2359,8 +2358,6 @@ static int max98095_remove(struct snd_soc_codec *codec)
2359 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 2358 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2360 struct i2c_client *client = to_i2c_client(codec->dev); 2359 struct i2c_client *client = to_i2c_client(codec->dev);
2361 2360
2362 max98095_set_bias_level(codec, SND_SOC_BIAS_OFF);
2363
2364 if (max98095->headphone_jack || max98095->mic_jack) 2361 if (max98095->headphone_jack || max98095->mic_jack)
2365 max98095_jack_detect_disable(codec); 2362 max98095_jack_detect_disable(codec);
2366 2363
@@ -2395,6 +2392,8 @@ static int max98095_i2c_probe(struct i2c_client *i2c,
2395 if (max98095 == NULL) 2392 if (max98095 == NULL)
2396 return -ENOMEM; 2393 return -ENOMEM;
2397 2394
2395 mutex_init(&max98095->lock);
2396
2398 max98095->regmap = devm_regmap_init_i2c(i2c, &max98095_regmap); 2397 max98095->regmap = devm_regmap_init_i2c(i2c, &max98095_regmap);
2399 if (IS_ERR(max98095->regmap)) { 2398 if (IS_ERR(max98095->regmap)) {
2400 ret = PTR_ERR(max98095->regmap); 2399 ret = PTR_ERR(max98095->regmap);
diff --git a/sound/soc/codecs/max9850.c b/sound/soc/codecs/max9850.c
index 4fdf5aaa236f..10f8e47ce2c2 100644
--- a/sound/soc/codecs/max9850.c
+++ b/sound/soc/codecs/max9850.c
@@ -291,25 +291,6 @@ static struct snd_soc_dai_driver max9850_dai = {
291 .ops = &max9850_dai_ops, 291 .ops = &max9850_dai_ops,
292}; 292};
293 293
294#ifdef CONFIG_PM
295static int max9850_suspend(struct snd_soc_codec *codec)
296{
297 max9850_set_bias_level(codec, SND_SOC_BIAS_OFF);
298
299 return 0;
300}
301
302static int max9850_resume(struct snd_soc_codec *codec)
303{
304 max9850_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
305
306 return 0;
307}
308#else
309#define max9850_suspend NULL
310#define max9850_resume NULL
311#endif
312
313static int max9850_probe(struct snd_soc_codec *codec) 294static int max9850_probe(struct snd_soc_codec *codec)
314{ 295{
315 /* enable zero-detect */ 296 /* enable zero-detect */
@@ -324,9 +305,8 @@ static int max9850_probe(struct snd_soc_codec *codec)
324 305
325static struct snd_soc_codec_driver soc_codec_dev_max9850 = { 306static struct snd_soc_codec_driver soc_codec_dev_max9850 = {
326 .probe = max9850_probe, 307 .probe = max9850_probe,
327 .suspend = max9850_suspend,
328 .resume = max9850_resume,
329 .set_bias_level = max9850_set_bias_level, 308 .set_bias_level = max9850_set_bias_level,
309 .suspend_bias_off = true,
330 310
331 .controls = max9850_controls, 311 .controls = max9850_controls,
332 .num_controls = ARRAY_SIZE(max9850_controls), 312 .num_controls = ARRAY_SIZE(max9850_controls),
diff --git a/sound/soc/codecs/rt286.c b/sound/soc/codecs/rt286.c
index 4aa555cbcca8..2cd4fe463102 100644
--- a/sound/soc/codecs/rt286.c
+++ b/sound/soc/codecs/rt286.c
@@ -17,6 +17,7 @@
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/spi/spi.h> 19#include <linux/spi/spi.h>
20#include <linux/dmi.h>
20#include <linux/acpi.h> 21#include <linux/acpi.h>
21#include <sound/core.h> 22#include <sound/core.h>
22#include <sound/pcm.h> 23#include <sound/pcm.h>
@@ -36,11 +37,13 @@
36 37
37struct rt286_priv { 38struct rt286_priv {
38 struct regmap *regmap; 39 struct regmap *regmap;
40 struct snd_soc_codec *codec;
39 struct rt286_platform_data pdata; 41 struct rt286_platform_data pdata;
40 struct i2c_client *i2c; 42 struct i2c_client *i2c;
41 struct snd_soc_jack *jack; 43 struct snd_soc_jack *jack;
42 struct delayed_work jack_detect_work; 44 struct delayed_work jack_detect_work;
43 int sys_clk; 45 int sys_clk;
46 int clk_id;
44 struct reg_default *index_cache; 47 struct reg_default *index_cache;
45}; 48};
46 49
@@ -188,7 +191,7 @@ static int rt286_hw_write(void *context, unsigned int reg, unsigned int value)
188 u8 data[4]; 191 u8 data[4];
189 int ret, i; 192 int ret, i;
190 193
191 /*handle index registers*/ 194 /* handle index registers */
192 if (reg <= 0xff) { 195 if (reg <= 0xff) {
193 rt286_hw_write(client, RT286_COEF_INDEX, reg); 196 rt286_hw_write(client, RT286_COEF_INDEX, reg);
194 for (i = 0; i < INDEX_CACHE_SIZE; i++) { 197 for (i = 0; i < INDEX_CACHE_SIZE; i++) {
@@ -231,7 +234,7 @@ static int rt286_hw_read(void *context, unsigned int reg, unsigned int *value)
231 __be32 be_reg; 234 __be32 be_reg;
232 unsigned int index, vid, buf = 0x0; 235 unsigned int index, vid, buf = 0x0;
233 236
234 /*handle index registers*/ 237 /* handle index registers */
235 if (reg <= 0xff) { 238 if (reg <= 0xff) {
236 rt286_hw_write(client, RT286_COEF_INDEX, reg); 239 rt286_hw_write(client, RT286_COEF_INDEX, reg);
237 reg = RT286_PROC_COEF; 240 reg = RT286_PROC_COEF;
@@ -298,7 +301,6 @@ static int rt286_support_power_controls[] = {
298static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic) 301static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic)
299{ 302{
300 unsigned int val, buf; 303 unsigned int val, buf;
301 int i;
302 304
303 *hp = false; 305 *hp = false;
304 *mic = false; 306 *mic = false;
@@ -309,67 +311,44 @@ static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic)
309 if (*hp) { 311 if (*hp) {
310 /* power on HV,VERF */ 312 /* power on HV,VERF */
311 regmap_update_bits(rt286->regmap, 313 regmap_update_bits(rt286->regmap,
312 RT286_POWER_CTRL1, 0x1001, 0x0); 314 RT286_DC_GAIN, 0x200, 0x200);
315
316 snd_soc_dapm_force_enable_pin(&rt286->codec->dapm,
317 "HV");
318 snd_soc_dapm_force_enable_pin(&rt286->codec->dapm,
319 "VREF");
313 /* power LDO1 */ 320 /* power LDO1 */
314 regmap_update_bits(rt286->regmap, 321 snd_soc_dapm_force_enable_pin(&rt286->codec->dapm,
315 RT286_POWER_CTRL2, 0x4, 0x4); 322 "LDO1");
316 regmap_write(rt286->regmap, RT286_SET_MIC1, 0x24); 323 snd_soc_dapm_sync(&rt286->codec->dapm);
317 regmap_read(rt286->regmap, RT286_CBJ_CTRL2, &val);
318 324
319 msleep(200); 325 regmap_write(rt286->regmap, RT286_SET_MIC1, 0x24);
320 i = 40; 326 msleep(50);
321 while (((val & 0x0800) == 0) && (i > 0)) {
322 regmap_read(rt286->regmap,
323 RT286_CBJ_CTRL2, &val);
324 i--;
325 msleep(20);
326 }
327 327
328 if (0x0400 == (val & 0x0700)) { 328 regmap_update_bits(rt286->regmap,
329 *mic = false; 329 RT286_CBJ_CTRL1, 0xfcc0, 0xd400);
330 msleep(300);
331 regmap_read(rt286->regmap, RT286_CBJ_CTRL2, &val);
330 332
331 regmap_write(rt286->regmap, 333 if (0x0070 == (val & 0x0070)) {
332 RT286_SET_MIC1, 0x20);
333 /* power off HV,VERF */
334 regmap_update_bits(rt286->regmap,
335 RT286_POWER_CTRL1, 0x1001, 0x1001);
336 regmap_update_bits(rt286->regmap,
337 RT286_A_BIAS_CTRL3, 0xc000, 0x0000);
338 regmap_update_bits(rt286->regmap,
339 RT286_CBJ_CTRL1, 0x0030, 0x0000);
340 regmap_update_bits(rt286->regmap,
341 RT286_A_BIAS_CTRL2, 0xc000, 0x0000);
342 } else if ((0x0200 == (val & 0x0700)) ||
343 (0x0100 == (val & 0x0700))) {
344 *mic = true; 334 *mic = true;
345 regmap_update_bits(rt286->regmap,
346 RT286_A_BIAS_CTRL3, 0xc000, 0x8000);
347 regmap_update_bits(rt286->regmap,
348 RT286_CBJ_CTRL1, 0x0030, 0x0020);
349 regmap_update_bits(rt286->regmap,
350 RT286_A_BIAS_CTRL2, 0xc000, 0x8000);
351 } else { 335 } else {
352 *mic = false; 336 regmap_update_bits(rt286->regmap,
337 RT286_CBJ_CTRL1, 0xfcc0, 0xe400);
338 msleep(300);
339 regmap_read(rt286->regmap,
340 RT286_CBJ_CTRL2, &val);
341 if (0x0070 == (val & 0x0070))
342 *mic = true;
343 else
344 *mic = false;
353 } 345 }
354
355 regmap_update_bits(rt286->regmap,
356 RT286_MISC_CTRL1,
357 0x0060, 0x0000);
358 } else {
359 regmap_update_bits(rt286->regmap,
360 RT286_MISC_CTRL1,
361 0x0060, 0x0020);
362 regmap_update_bits(rt286->regmap, 346 regmap_update_bits(rt286->regmap,
363 RT286_A_BIAS_CTRL3, 347 RT286_DC_GAIN, 0x200, 0x0);
364 0xc000, 0x8000);
365 regmap_update_bits(rt286->regmap,
366 RT286_CBJ_CTRL1,
367 0x0030, 0x0020);
368 regmap_update_bits(rt286->regmap,
369 RT286_A_BIAS_CTRL2,
370 0xc000, 0x8000);
371 348
349 } else {
372 *mic = false; 350 *mic = false;
351 regmap_write(rt286->regmap, RT286_SET_MIC1, 0x20);
373 } 352 }
374 } else { 353 } else {
375 regmap_read(rt286->regmap, RT286_GET_HP_SENSE, &buf); 354 regmap_read(rt286->regmap, RT286_GET_HP_SENSE, &buf);
@@ -378,6 +357,12 @@ static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic)
378 *mic = buf & 0x80000000; 357 *mic = buf & 0x80000000;
379 } 358 }
380 359
360 snd_soc_dapm_disable_pin(&rt286->codec->dapm, "HV");
361 snd_soc_dapm_disable_pin(&rt286->codec->dapm, "VREF");
362 if (!*hp)
363 snd_soc_dapm_disable_pin(&rt286->codec->dapm, "LDO1");
364 snd_soc_dapm_sync(&rt286->codec->dapm);
365
381 return 0; 366 return 0;
382} 367}
383 368
@@ -415,6 +400,17 @@ int rt286_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
415} 400}
416EXPORT_SYMBOL_GPL(rt286_mic_detect); 401EXPORT_SYMBOL_GPL(rt286_mic_detect);
417 402
403static int is_mclk_mode(struct snd_soc_dapm_widget *source,
404 struct snd_soc_dapm_widget *sink)
405{
406 struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(source->codec);
407
408 if (rt286->clk_id == RT286_SCLK_S_MCLK)
409 return 1;
410 else
411 return 0;
412}
413
418static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6350, 50, 0); 414static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6350, 50, 0);
419static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, 0, 1000, 0); 415static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, 0, 1000, 0);
420 416
@@ -568,7 +564,84 @@ static int rt286_adc_event(struct snd_soc_dapm_widget *w,
568 return 0; 564 return 0;
569} 565}
570 566
567static int rt286_vref_event(struct snd_soc_dapm_widget *w,
568 struct snd_kcontrol *kcontrol, int event)
569{
570 struct snd_soc_codec *codec = w->codec;
571
572 switch (event) {
573 case SND_SOC_DAPM_PRE_PMU:
574 snd_soc_update_bits(codec,
575 RT286_CBJ_CTRL1, 0x0400, 0x0000);
576 mdelay(50);
577 break;
578 default:
579 return 0;
580 }
581
582 return 0;
583}
584
585static int rt286_ldo2_event(struct snd_soc_dapm_widget *w,
586 struct snd_kcontrol *kcontrol, int event)
587{
588 struct snd_soc_codec *codec = w->codec;
589
590 switch (event) {
591 case SND_SOC_DAPM_POST_PMU:
592 snd_soc_update_bits(codec, RT286_POWER_CTRL2, 0x38, 0x08);
593 break;
594 case SND_SOC_DAPM_PRE_PMD:
595 snd_soc_update_bits(codec, RT286_POWER_CTRL2, 0x38, 0x30);
596 break;
597 default:
598 return 0;
599 }
600
601 return 0;
602}
603
604static int rt286_mic1_event(struct snd_soc_dapm_widget *w,
605 struct snd_kcontrol *kcontrol, int event)
606{
607 struct snd_soc_codec *codec = w->codec;
608
609 switch (event) {
610 case SND_SOC_DAPM_PRE_PMU:
611 snd_soc_update_bits(codec,
612 RT286_A_BIAS_CTRL3, 0xc000, 0x8000);
613 snd_soc_update_bits(codec,
614 RT286_A_BIAS_CTRL2, 0xc000, 0x8000);
615 break;
616 case SND_SOC_DAPM_POST_PMD:
617 snd_soc_update_bits(codec,
618 RT286_A_BIAS_CTRL3, 0xc000, 0x0000);
619 snd_soc_update_bits(codec,
620 RT286_A_BIAS_CTRL2, 0xc000, 0x0000);
621 break;
622 default:
623 return 0;
624 }
625
626 return 0;
627}
628
571static const struct snd_soc_dapm_widget rt286_dapm_widgets[] = { 629static const struct snd_soc_dapm_widget rt286_dapm_widgets[] = {
630 SND_SOC_DAPM_SUPPLY_S("HV", 1, RT286_POWER_CTRL1,
631 12, 1, NULL, 0),
632 SND_SOC_DAPM_SUPPLY("VREF", RT286_POWER_CTRL1,
633 0, 1, rt286_vref_event, SND_SOC_DAPM_PRE_PMU),
634 SND_SOC_DAPM_SUPPLY_S("LDO1", 1, RT286_POWER_CTRL2,
635 2, 0, NULL, 0),
636 SND_SOC_DAPM_SUPPLY_S("LDO2", 2, RT286_POWER_CTRL1,
637 13, 1, rt286_ldo2_event, SND_SOC_DAPM_PRE_PMD |
638 SND_SOC_DAPM_POST_PMU),
639 SND_SOC_DAPM_SUPPLY("MCLK MODE", RT286_PLL_CTRL1,
640 5, 0, NULL, 0),
641 SND_SOC_DAPM_SUPPLY("MIC1 Input Buffer", SND_SOC_NOPM,
642 0, 0, rt286_mic1_event, SND_SOC_DAPM_PRE_PMU |
643 SND_SOC_DAPM_POST_PMD),
644
572 /* Input Lines */ 645 /* Input Lines */
573 SND_SOC_DAPM_INPUT("DMIC1 Pin"), 646 SND_SOC_DAPM_INPUT("DMIC1 Pin"),
574 SND_SOC_DAPM_INPUT("DMIC2 Pin"), 647 SND_SOC_DAPM_INPUT("DMIC2 Pin"),
@@ -642,6 +715,25 @@ static const struct snd_soc_dapm_widget rt286_dapm_widgets[] = {
642}; 715};
643 716
644static const struct snd_soc_dapm_route rt286_dapm_routes[] = { 717static const struct snd_soc_dapm_route rt286_dapm_routes[] = {
718 {"ADC 0", NULL, "MCLK MODE", is_mclk_mode},
719 {"ADC 1", NULL, "MCLK MODE", is_mclk_mode},
720 {"Front", NULL, "MCLK MODE", is_mclk_mode},
721 {"Surround", NULL, "MCLK MODE", is_mclk_mode},
722
723 {"HP Power", NULL, "LDO1"},
724 {"HP Power", NULL, "LDO2"},
725
726 {"MIC1", NULL, "LDO1"},
727 {"MIC1", NULL, "LDO2"},
728 {"MIC1", NULL, "HV"},
729 {"MIC1", NULL, "VREF"},
730 {"MIC1", NULL, "MIC1 Input Buffer"},
731
732 {"SPO", NULL, "LDO1"},
733 {"SPO", NULL, "LDO2"},
734 {"SPO", NULL, "HV"},
735 {"SPO", NULL, "VREF"},
736
645 {"DMIC1", NULL, "DMIC1 Pin"}, 737 {"DMIC1", NULL, "DMIC1 Pin"},
646 {"DMIC2", NULL, "DMIC2 Pin"}, 738 {"DMIC2", NULL, "DMIC2 Pin"},
647 {"DMIC1", NULL, "DMIC Receiver"}, 739 {"DMIC1", NULL, "DMIC Receiver"},
@@ -880,6 +972,7 @@ static int rt286_set_dai_sysclk(struct snd_soc_dai *dai,
880 } 972 }
881 973
882 rt286->sys_clk = freq; 974 rt286->sys_clk = freq;
975 rt286->clk_id = clk_id;
883 976
884 return 0; 977 return 0;
885} 978}
@@ -915,13 +1008,18 @@ static int rt286_set_bias_level(struct snd_soc_codec *codec,
915 1008
916 case SND_SOC_BIAS_ON: 1009 case SND_SOC_BIAS_ON:
917 mdelay(10); 1010 mdelay(10);
1011 snd_soc_update_bits(codec,
1012 RT286_CBJ_CTRL1, 0x0400, 0x0400);
1013 snd_soc_update_bits(codec,
1014 RT286_DC_GAIN, 0x200, 0x0);
1015
918 break; 1016 break;
919 1017
920 case SND_SOC_BIAS_STANDBY: 1018 case SND_SOC_BIAS_STANDBY:
921 snd_soc_write(codec, 1019 snd_soc_write(codec,
922 RT286_SET_AUDIO_POWER, AC_PWRST_D3); 1020 RT286_SET_AUDIO_POWER, AC_PWRST_D3);
923 snd_soc_update_bits(codec, 1021 snd_soc_update_bits(codec,
924 RT286_DC_GAIN, 0x200, 0x0); 1022 RT286_CBJ_CTRL1, 0x0400, 0x0000);
925 break; 1023 break;
926 1024
927 default: 1025 default:
@@ -962,6 +1060,7 @@ static int rt286_probe(struct snd_soc_codec *codec)
962{ 1060{
963 struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); 1061 struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec);
964 1062
1063 rt286->codec = codec;
965 codec->dapm.bias_level = SND_SOC_BIAS_OFF; 1064 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
966 1065
967 if (rt286->i2c->irq) { 1066 if (rt286->i2c->irq) {
@@ -1107,6 +1206,16 @@ static const struct acpi_device_id rt286_acpi_match[] = {
1107}; 1206};
1108MODULE_DEVICE_TABLE(acpi, rt286_acpi_match); 1207MODULE_DEVICE_TABLE(acpi, rt286_acpi_match);
1109 1208
1209static struct dmi_system_id force_combo_jack_table[] = {
1210 {
1211 .ident = "Intel Wilson Beach",
1212 .matches = {
1213 DMI_MATCH(DMI_BOARD_NAME, "Wilson Beach SDS")
1214 }
1215 },
1216 { }
1217};
1218
1110static int rt286_i2c_probe(struct i2c_client *i2c, 1219static int rt286_i2c_probe(struct i2c_client *i2c,
1111 const struct i2c_device_id *id) 1220 const struct i2c_device_id *id)
1112{ 1221{
@@ -1142,6 +1251,9 @@ static int rt286_i2c_probe(struct i2c_client *i2c,
1142 if (pdata) 1251 if (pdata)
1143 rt286->pdata = *pdata; 1252 rt286->pdata = *pdata;
1144 1253
1254 if (dmi_check_system(force_combo_jack_table))
1255 rt286->pdata.cbj_en = true;
1256
1145 regmap_write(rt286->regmap, RT286_SET_AUDIO_POWER, AC_PWRST_D3); 1257 regmap_write(rt286->regmap, RT286_SET_AUDIO_POWER, AC_PWRST_D3);
1146 1258
1147 for (i = 0; i < RT286_POWER_REG_LEN; i++) 1259 for (i = 0; i < RT286_POWER_REG_LEN; i++)
@@ -1152,7 +1264,6 @@ static int rt286_i2c_probe(struct i2c_client *i2c,
1152 if (!rt286->pdata.cbj_en) { 1264 if (!rt286->pdata.cbj_en) {
1153 regmap_write(rt286->regmap, RT286_CBJ_CTRL2, 0x0000); 1265 regmap_write(rt286->regmap, RT286_CBJ_CTRL2, 0x0000);
1154 regmap_write(rt286->regmap, RT286_MIC1_DET_CTRL, 0x0816); 1266 regmap_write(rt286->regmap, RT286_MIC1_DET_CTRL, 0x0816);
1155 regmap_write(rt286->regmap, RT286_MISC_CTRL1, 0x0000);
1156 regmap_update_bits(rt286->regmap, 1267 regmap_update_bits(rt286->regmap,
1157 RT286_CBJ_CTRL1, 0xf000, 0xb000); 1268 RT286_CBJ_CTRL1, 0xf000, 0xb000);
1158 } else { 1269 } else {
@@ -1169,10 +1280,12 @@ static int rt286_i2c_probe(struct i2c_client *i2c,
1169 1280
1170 mdelay(10); 1281 mdelay(10);
1171 1282
1172 /*Power down LDO2*/ 1283 regmap_write(rt286->regmap, RT286_MISC_CTRL1, 0x0000);
1173 regmap_update_bits(rt286->regmap, RT286_POWER_CTRL2, 0x8, 0x0); 1284 /* Power down LDO, VREF */
1285 regmap_update_bits(rt286->regmap, RT286_POWER_CTRL2, 0xc, 0x0);
1286 regmap_update_bits(rt286->regmap, RT286_POWER_CTRL1, 0x1001, 0x1001);
1174 1287
1175 /*Set depop parameter*/ 1288 /* Set depop parameter */
1176 regmap_update_bits(rt286->regmap, RT286_DEPOP_CTRL2, 0x403a, 0x401a); 1289 regmap_update_bits(rt286->regmap, RT286_DEPOP_CTRL2, 0x403a, 0x401a);
1177 regmap_update_bits(rt286->regmap, RT286_DEPOP_CTRL3, 0xf777, 0x4737); 1290 regmap_update_bits(rt286->regmap, RT286_DEPOP_CTRL3, 0xf777, 0x4737);
1178 regmap_update_bits(rt286->regmap, RT286_DEPOP_CTRL4, 0x00ff, 0x003f); 1291 regmap_update_bits(rt286->regmap, RT286_DEPOP_CTRL4, 0x00ff, 0x003f);
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c
index 1ba27db660a6..6d7b7ca7d530 100644
--- a/sound/soc/codecs/rt5631.c
+++ b/sound/soc/codecs/rt5631.c
@@ -1612,29 +1612,6 @@ static int rt5631_probe(struct snd_soc_codec *codec)
1612 return 0; 1612 return 0;
1613} 1613}
1614 1614
1615static int rt5631_remove(struct snd_soc_codec *codec)
1616{
1617 rt5631_set_bias_level(codec, SND_SOC_BIAS_OFF);
1618 return 0;
1619}
1620
1621#ifdef CONFIG_PM
1622static int rt5631_suspend(struct snd_soc_codec *codec)
1623{
1624 rt5631_set_bias_level(codec, SND_SOC_BIAS_OFF);
1625 return 0;
1626}
1627
1628static int rt5631_resume(struct snd_soc_codec *codec)
1629{
1630 rt5631_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1631 return 0;
1632}
1633#else
1634#define rt5631_suspend NULL
1635#define rt5631_resume NULL
1636#endif
1637
1638#define RT5631_STEREO_RATES SNDRV_PCM_RATE_8000_96000 1615#define RT5631_STEREO_RATES SNDRV_PCM_RATE_8000_96000
1639#define RT5631_FORMAT (SNDRV_PCM_FMTBIT_S16_LE | \ 1616#define RT5631_FORMAT (SNDRV_PCM_FMTBIT_S16_LE | \
1640 SNDRV_PCM_FMTBIT_S20_3LE | \ 1617 SNDRV_PCM_FMTBIT_S20_3LE | \
@@ -1672,10 +1649,8 @@ static struct snd_soc_dai_driver rt5631_dai[] = {
1672 1649
1673static struct snd_soc_codec_driver soc_codec_dev_rt5631 = { 1650static struct snd_soc_codec_driver soc_codec_dev_rt5631 = {
1674 .probe = rt5631_probe, 1651 .probe = rt5631_probe,
1675 .remove = rt5631_remove,
1676 .suspend = rt5631_suspend,
1677 .resume = rt5631_resume,
1678 .set_bias_level = rt5631_set_bias_level, 1652 .set_bias_level = rt5631_set_bias_level,
1653 .suspend_bias_off = true,
1679 .controls = rt5631_snd_controls, 1654 .controls = rt5631_snd_controls,
1680 .num_controls = ARRAY_SIZE(rt5631_snd_controls), 1655 .num_controls = ARRAY_SIZE(rt5631_snd_controls),
1681 .dapm_widgets = rt5631_dapm_widgets, 1656 .dapm_widgets = rt5631_dapm_widgets,
@@ -1686,10 +1661,20 @@ static struct snd_soc_codec_driver soc_codec_dev_rt5631 = {
1686 1661
1687static const struct i2c_device_id rt5631_i2c_id[] = { 1662static const struct i2c_device_id rt5631_i2c_id[] = {
1688 { "rt5631", 0 }, 1663 { "rt5631", 0 },
1664 { "alc5631", 0 },
1689 { } 1665 { }
1690}; 1666};
1691MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id); 1667MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id);
1692 1668
1669#ifdef CONFIG_OF
1670static struct of_device_id rt5631_i2c_dt_ids[] = {
1671 { .compatible = "realtek,rt5631"},
1672 { .compatible = "realtek,alc5631"},
1673 { }
1674};
1675MODULE_DEVICE_TABLE(of, rt5631_i2c_dt_ids);
1676#endif
1677
1693static const struct regmap_config rt5631_regmap_config = { 1678static const struct regmap_config rt5631_regmap_config = {
1694 .reg_bits = 8, 1679 .reg_bits = 8,
1695 .val_bits = 16, 1680 .val_bits = 16,
@@ -1734,6 +1719,7 @@ static struct i2c_driver rt5631_i2c_driver = {
1734 .driver = { 1719 .driver = {
1735 .name = "rt5631", 1720 .name = "rt5631",
1736 .owner = THIS_MODULE, 1721 .owner = THIS_MODULE,
1722 .of_match_table = of_match_ptr(rt5631_i2c_dt_ids),
1737 }, 1723 },
1738 .probe = rt5631_i2c_probe, 1724 .probe = rt5631_i2c_probe,
1739 .remove = rt5631_i2c_remove, 1725 .remove = rt5631_i2c_remove,
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index d16331e0b64d..a7789a8726e3 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -554,6 +554,53 @@ static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
554 return 0; 554 return 0;
555} 555}
556 556
557static int is_using_asrc(struct snd_soc_dapm_widget *source,
558 struct snd_soc_dapm_widget *sink)
559{
560 unsigned int reg, shift, val;
561
562 switch (source->shift) {
563 case 0:
564 reg = RT5645_ASRC_3;
565 shift = 0;
566 break;
567 case 1:
568 reg = RT5645_ASRC_3;
569 shift = 4;
570 break;
571 case 3:
572 reg = RT5645_ASRC_2;
573 shift = 0;
574 break;
575 case 8:
576 reg = RT5645_ASRC_2;
577 shift = 4;
578 break;
579 case 9:
580 reg = RT5645_ASRC_2;
581 shift = 8;
582 break;
583 case 10:
584 reg = RT5645_ASRC_2;
585 shift = 12;
586 break;
587 default:
588 return 0;
589 }
590
591 val = (snd_soc_read(source->codec, reg) >> shift) & 0xf;
592 switch (val) {
593 case 1:
594 case 2:
595 case 3:
596 case 4:
597 return 1;
598 default:
599 return 0;
600 }
601
602}
603
557/* Digital Mixer */ 604/* Digital Mixer */
558static const struct snd_kcontrol_new rt5645_sto1_adc_l_mix[] = { 605static const struct snd_kcontrol_new rt5645_sto1_adc_l_mix[] = {
559 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_STO1_ADC_MIXER, 606 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_STO1_ADC_MIXER,
@@ -1246,6 +1293,30 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = {
1246 SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5645_PWR_VOL, 1293 SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5645_PWR_VOL,
1247 RT5645_PWR_MIC_DET_BIT, 0, NULL, 0), 1294 RT5645_PWR_MIC_DET_BIT, 0, NULL, 0),
1248 1295
1296 /* ASRC */
1297 SND_SOC_DAPM_SUPPLY_S("I2S1 ASRC", 1, RT5645_ASRC_1,
1298 11, 0, NULL, 0),
1299 SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5645_ASRC_1,
1300 12, 0, NULL, 0),
1301 SND_SOC_DAPM_SUPPLY_S("DAC STO ASRC", 1, RT5645_ASRC_1,
1302 10, 0, NULL, 0),
1303 SND_SOC_DAPM_SUPPLY_S("DAC MONO L ASRC", 1, RT5645_ASRC_1,
1304 9, 0, NULL, 0),
1305 SND_SOC_DAPM_SUPPLY_S("DAC MONO R ASRC", 1, RT5645_ASRC_1,
1306 8, 0, NULL, 0),
1307 SND_SOC_DAPM_SUPPLY_S("DMIC STO1 ASRC", 1, RT5645_ASRC_1,
1308 7, 0, NULL, 0),
1309 SND_SOC_DAPM_SUPPLY_S("DMIC MONO L ASRC", 1, RT5645_ASRC_1,
1310 5, 0, NULL, 0),
1311 SND_SOC_DAPM_SUPPLY_S("DMIC MONO R ASRC", 1, RT5645_ASRC_1,
1312 4, 0, NULL, 0),
1313 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5645_ASRC_1,
1314 3, 0, NULL, 0),
1315 SND_SOC_DAPM_SUPPLY_S("ADC MONO L ASRC", 1, RT5645_ASRC_1,
1316 1, 0, NULL, 0),
1317 SND_SOC_DAPM_SUPPLY_S("ADC MONO R ASRC", 1, RT5645_ASRC_1,
1318 0, 0, NULL, 0),
1319
1249 /* Input Side */ 1320 /* Input Side */
1250 /* micbias */ 1321 /* micbias */
1251 SND_SOC_DAPM_MICBIAS("micbias1", RT5645_PWR_ANLG2, 1322 SND_SOC_DAPM_MICBIAS("micbias1", RT5645_PWR_ANLG2,
@@ -1504,6 +1575,17 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = {
1504}; 1575};
1505 1576
1506static const struct snd_soc_dapm_route rt5645_dapm_routes[] = { 1577static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {
1578 { "adc stereo1 filter", NULL, "ADC STO1 ASRC", is_using_asrc },
1579 { "adc stereo2 filter", NULL, "ADC STO2 ASRC", is_using_asrc },
1580 { "adc mono left filter", NULL, "ADC MONO L ASRC", is_using_asrc },
1581 { "adc mono right filter", NULL, "ADC MONO R ASRC", is_using_asrc },
1582 { "dac mono left filter", NULL, "DAC MONO L ASRC", is_using_asrc },
1583 { "dac mono right filter", NULL, "DAC MONO R ASRC", is_using_asrc },
1584 { "dac stereo1 filter", NULL, "DAC STO ASRC", is_using_asrc },
1585
1586 { "I2S1", NULL, "I2S1 ASRC" },
1587 { "I2S2", NULL, "I2S2 ASRC" },
1588
1507 { "IN1P", NULL, "LDO2" }, 1589 { "IN1P", NULL, "LDO2" },
1508 { "IN2P", NULL, "LDO2" }, 1590 { "IN2P", NULL, "LDO2" },
1509 1591
@@ -1550,12 +1632,15 @@ static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {
1550 1632
1551 { "Stereo1 DMIC Mux", "DMIC1", "DMIC1" }, 1633 { "Stereo1 DMIC Mux", "DMIC1", "DMIC1" },
1552 { "Stereo1 DMIC Mux", "DMIC2", "DMIC2" }, 1634 { "Stereo1 DMIC Mux", "DMIC2", "DMIC2" },
1635 { "Stereo1 DMIC Mux", NULL, "DMIC STO1 ASRC" },
1553 1636
1554 { "Mono DMIC L Mux", "DMIC1", "DMIC L1" }, 1637 { "Mono DMIC L Mux", "DMIC1", "DMIC L1" },
1555 { "Mono DMIC L Mux", "DMIC2", "DMIC L2" }, 1638 { "Mono DMIC L Mux", "DMIC2", "DMIC L2" },
1639 { "Mono DMIC L Mux", NULL, "DMIC MONO L ASRC" },
1556 1640
1557 { "Mono DMIC R Mux", "DMIC1", "DMIC R1" }, 1641 { "Mono DMIC R Mux", "DMIC1", "DMIC R1" },
1558 { "Mono DMIC R Mux", "DMIC2", "DMIC R2" }, 1642 { "Mono DMIC R Mux", "DMIC2", "DMIC R2" },
1643 { "Mono DMIC R Mux", NULL, "DMIC MONO R ASRC" },
1559 1644
1560 { "Stereo1 ADC L2 Mux", "DMIC", "Stereo1 DMIC Mux" }, 1645 { "Stereo1 ADC L2 Mux", "DMIC", "Stereo1 DMIC Mux" },
1561 { "Stereo1 ADC L2 Mux", "DAC MIX", "DAC MIXL" }, 1646 { "Stereo1 ADC L2 Mux", "DAC MIX", "DAC MIXL" },
@@ -2029,8 +2114,11 @@ static int rt5645_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
2029 struct snd_soc_codec *codec = dai->codec; 2114 struct snd_soc_codec *codec = dai->codec;
2030 unsigned int val = 0; 2115 unsigned int val = 0;
2031 2116
2032 if (rx_mask || tx_mask) 2117 if (rx_mask || tx_mask) {
2033 val |= (1 << 14); 2118 val |= (1 << 14);
2119 snd_soc_update_bits(codec, RT5645_BASS_BACK,
2120 RT5645_G_BB_BST_MASK, RT5645_G_BB_BST_25DB);
2121 }
2034 2122
2035 switch (slots) { 2123 switch (slots) {
2036 case 4: 2124 case 4:
@@ -2071,8 +2159,8 @@ static int rt5645_set_bias_level(struct snd_soc_codec *codec,
2071 enum snd_soc_bias_level level) 2159 enum snd_soc_bias_level level)
2072{ 2160{
2073 switch (level) { 2161 switch (level) {
2074 case SND_SOC_BIAS_STANDBY: 2162 case SND_SOC_BIAS_PREPARE:
2075 if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) { 2163 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) {
2076 snd_soc_update_bits(codec, RT5645_PWR_ANLG1, 2164 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
2077 RT5645_PWR_VREF1 | RT5645_PWR_MB | 2165 RT5645_PWR_VREF1 | RT5645_PWR_MB |
2078 RT5645_PWR_BG | RT5645_PWR_VREF2, 2166 RT5645_PWR_BG | RT5645_PWR_VREF2,
@@ -2087,15 +2175,24 @@ static int rt5645_set_bias_level(struct snd_soc_codec *codec,
2087 } 2175 }
2088 break; 2176 break;
2089 2177
2178 case SND_SOC_BIAS_STANDBY:
2179 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
2180 RT5645_PWR_VREF1 | RT5645_PWR_MB |
2181 RT5645_PWR_BG | RT5645_PWR_VREF2,
2182 RT5645_PWR_VREF1 | RT5645_PWR_MB |
2183 RT5645_PWR_BG | RT5645_PWR_VREF2);
2184 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
2185 RT5645_PWR_FV1 | RT5645_PWR_FV2,
2186 RT5645_PWR_FV1 | RT5645_PWR_FV2);
2187 break;
2188
2090 case SND_SOC_BIAS_OFF: 2189 case SND_SOC_BIAS_OFF:
2091 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1100); 2190 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1100);
2092 snd_soc_write(codec, RT5645_GEN_CTRL1, 0x0128); 2191 snd_soc_write(codec, RT5645_GEN_CTRL1, 0x0128);
2093 snd_soc_write(codec, RT5645_PWR_DIG1, 0x0000); 2192 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
2094 snd_soc_write(codec, RT5645_PWR_DIG2, 0x0000); 2193 RT5645_PWR_VREF1 | RT5645_PWR_MB |
2095 snd_soc_write(codec, RT5645_PWR_VOL, 0x0000); 2194 RT5645_PWR_BG | RT5645_PWR_VREF2 |
2096 snd_soc_write(codec, RT5645_PWR_MIXER, 0x0000); 2195 RT5645_PWR_FV1 | RT5645_PWR_FV2, 0x0);
2097 snd_soc_write(codec, RT5645_PWR_ANLG1, 0x0000);
2098 snd_soc_write(codec, RT5645_PWR_ANLG2, 0x0000);
2099 break; 2196 break;
2100 2197
2101 default: 2198 default:
@@ -2106,8 +2203,7 @@ static int rt5645_set_bias_level(struct snd_soc_codec *codec,
2106 return 0; 2203 return 0;
2107} 2204}
2108 2205
2109static int rt5645_jack_detect(struct snd_soc_codec *codec, 2206static int rt5645_jack_detect(struct snd_soc_codec *codec)
2110 struct snd_soc_jack *jack)
2111{ 2207{
2112 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 2208 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
2113 int gpio_state, jack_type = 0; 2209 int gpio_state, jack_type = 0;
@@ -2145,34 +2241,44 @@ static int rt5645_jack_detect(struct snd_soc_codec *codec,
2145 2241
2146 snd_soc_dapm_disable_pin(&codec->dapm, "micbias1"); 2242 snd_soc_dapm_disable_pin(&codec->dapm, "micbias1");
2147 snd_soc_dapm_disable_pin(&codec->dapm, "micbias2"); 2243 snd_soc_dapm_disable_pin(&codec->dapm, "micbias2");
2148 snd_soc_dapm_disable_pin(&codec->dapm, "LDO2"); 2244 if (rt5645->pdata.jd_mode == 0)
2245 snd_soc_dapm_disable_pin(&codec->dapm, "LDO2");
2149 snd_soc_dapm_disable_pin(&codec->dapm, "Mic Det Power"); 2246 snd_soc_dapm_disable_pin(&codec->dapm, "Mic Det Power");
2150 snd_soc_dapm_sync(&codec->dapm); 2247 snd_soc_dapm_sync(&codec->dapm);
2151 } 2248 }
2152 2249
2153 snd_soc_jack_report(rt5645->jack, jack_type, SND_JACK_HEADSET); 2250 snd_soc_jack_report(rt5645->hp_jack, jack_type, SND_JACK_HEADPHONE);
2154 2251 snd_soc_jack_report(rt5645->mic_jack, jack_type, SND_JACK_MICROPHONE);
2155 return 0; 2252 return 0;
2156} 2253}
2157 2254
2158int rt5645_set_jack_detect(struct snd_soc_codec *codec, 2255int rt5645_set_jack_detect(struct snd_soc_codec *codec,
2159 struct snd_soc_jack *jack) 2256 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack)
2160{ 2257{
2161 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 2258 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
2162 2259
2163 rt5645->jack = jack; 2260 rt5645->hp_jack = hp_jack;
2164 2261 rt5645->mic_jack = mic_jack;
2165 rt5645_jack_detect(codec, rt5645->jack); 2262 rt5645_jack_detect(codec);
2166 2263
2167 return 0; 2264 return 0;
2168} 2265}
2169EXPORT_SYMBOL_GPL(rt5645_set_jack_detect); 2266EXPORT_SYMBOL_GPL(rt5645_set_jack_detect);
2170 2267
2268static void rt5645_jack_detect_work(struct work_struct *work)
2269{
2270 struct rt5645_priv *rt5645 =
2271 container_of(work, struct rt5645_priv, jack_detect_work.work);
2272
2273 rt5645_jack_detect(rt5645->codec);
2274}
2275
2171static irqreturn_t rt5645_irq(int irq, void *data) 2276static irqreturn_t rt5645_irq(int irq, void *data)
2172{ 2277{
2173 struct rt5645_priv *rt5645 = data; 2278 struct rt5645_priv *rt5645 = data;
2174 2279
2175 rt5645_jack_detect(rt5645->codec, rt5645->jack); 2280 queue_delayed_work(system_power_efficient_wq,
2281 &rt5645->jack_detect_work, msecs_to_jiffies(250));
2176 2282
2177 return IRQ_HANDLED; 2283 return IRQ_HANDLED;
2178} 2284}
@@ -2187,6 +2293,13 @@ static int rt5645_probe(struct snd_soc_codec *codec)
2187 2293
2188 snd_soc_update_bits(codec, RT5645_CHARGE_PUMP, 0x0300, 0x0200); 2294 snd_soc_update_bits(codec, RT5645_CHARGE_PUMP, 0x0300, 0x0200);
2189 2295
2296 /* for JD function */
2297 if (rt5645->pdata.en_jd_func) {
2298 snd_soc_dapm_force_enable_pin(&codec->dapm, "JD Power");
2299 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2");
2300 snd_soc_dapm_sync(&codec->dapm);
2301 }
2302
2190 return 0; 2303 return 0;
2191} 2304}
2192 2305
@@ -2420,6 +2533,51 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2420 2533
2421 } 2534 }
2422 2535
2536 if (rt5645->pdata.en_jd_func) {
2537 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3,
2538 RT5645_IRQ_CLK_GATE_CTRL | RT5645_MICINDET_MANU,
2539 RT5645_IRQ_CLK_GATE_CTRL | RT5645_MICINDET_MANU);
2540 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1,
2541 RT5645_CBJ_BST1_EN, RT5645_CBJ_BST1_EN);
2542 regmap_update_bits(rt5645->regmap, RT5645_JD_CTRL3,
2543 RT5645_JD_CBJ_EN | RT5645_JD_CBJ_POL,
2544 RT5645_JD_CBJ_EN | RT5645_JD_CBJ_POL);
2545 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS,
2546 RT5645_IRQ_CLK_INT, RT5645_IRQ_CLK_INT);
2547 }
2548
2549 if (rt5645->pdata.jd_mode) {
2550 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2,
2551 RT5645_IRQ_JD_1_1_EN, RT5645_IRQ_JD_1_1_EN);
2552 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3,
2553 RT5645_JD_PSV_MODE, RT5645_JD_PSV_MODE);
2554 regmap_update_bits(rt5645->regmap, RT5645_HPO_MIXER,
2555 RT5645_IRQ_PSV_MODE, RT5645_IRQ_PSV_MODE);
2556 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS,
2557 RT5645_MIC2_OVCD_EN, RT5645_MIC2_OVCD_EN);
2558 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2559 RT5645_GP1_PIN_IRQ, RT5645_GP1_PIN_IRQ);
2560 switch (rt5645->pdata.jd_mode) {
2561 case 1:
2562 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1,
2563 RT5645_JD1_MODE_MASK,
2564 RT5645_JD1_MODE_0);
2565 break;
2566 case 2:
2567 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1,
2568 RT5645_JD1_MODE_MASK,
2569 RT5645_JD1_MODE_1);
2570 break;
2571 case 3:
2572 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1,
2573 RT5645_JD1_MODE_MASK,
2574 RT5645_JD1_MODE_2);
2575 break;
2576 default:
2577 break;
2578 }
2579 }
2580
2423 if (rt5645->i2c->irq) { 2581 if (rt5645->i2c->irq) {
2424 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq, 2582 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq,
2425 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING 2583 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
@@ -2438,6 +2596,8 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2438 dev_err(&i2c->dev, "Fail gpio_direction hp_det_gpio\n"); 2596 dev_err(&i2c->dev, "Fail gpio_direction hp_det_gpio\n");
2439 } 2597 }
2440 2598
2599 INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work);
2600
2441 return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5645, 2601 return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5645,
2442 rt5645_dai, ARRAY_SIZE(rt5645_dai)); 2602 rt5645_dai, ARRAY_SIZE(rt5645_dai));
2443} 2603}
@@ -2449,6 +2609,8 @@ static int rt5645_i2c_remove(struct i2c_client *i2c)
2449 if (i2c->irq) 2609 if (i2c->irq)
2450 free_irq(i2c->irq, rt5645); 2610 free_irq(i2c->irq, rt5645);
2451 2611
2612 cancel_delayed_work_sync(&rt5645->jack_detect_work);
2613
2452 if (gpio_is_valid(rt5645->pdata.hp_det_gpio)) 2614 if (gpio_is_valid(rt5645->pdata.hp_det_gpio))
2453 gpio_free(rt5645->pdata.hp_det_gpio); 2615 gpio_free(rt5645->pdata.hp_det_gpio);
2454 2616
diff --git a/sound/soc/codecs/rt5645.h b/sound/soc/codecs/rt5645.h
index 50c62c5668ea..a815e36a2bdb 100644
--- a/sound/soc/codecs/rt5645.h
+++ b/sound/soc/codecs/rt5645.h
@@ -594,6 +594,7 @@
594#define RT5645_M_DAC1_HM_SFT 14 594#define RT5645_M_DAC1_HM_SFT 14
595#define RT5645_M_HPVOL_HM (0x1 << 13) 595#define RT5645_M_HPVOL_HM (0x1 << 13)
596#define RT5645_M_HPVOL_HM_SFT 13 596#define RT5645_M_HPVOL_HM_SFT 13
597#define RT5645_IRQ_PSV_MODE (0x1 << 12)
597 598
598/* SPK Left Mixer Control (0x46) */ 599/* SPK Left Mixer Control (0x46) */
599#define RT5645_G_RM_L_SM_L_MASK (0x3 << 14) 600#define RT5645_G_RM_L_SM_L_MASK (0x3 << 14)
@@ -1348,6 +1349,12 @@
1348#define RT5645_PWR_CLK25M_SFT 4 1349#define RT5645_PWR_CLK25M_SFT 4
1349#define RT5645_PWR_CLK25M_PD (0x0 << 4) 1350#define RT5645_PWR_CLK25M_PD (0x0 << 4)
1350#define RT5645_PWR_CLK25M_PU (0x1 << 4) 1351#define RT5645_PWR_CLK25M_PU (0x1 << 4)
1352#define RT5645_IRQ_CLK_MCLK (0x0 << 3)
1353#define RT5645_IRQ_CLK_INT (0x1 << 3)
1354#define RT5645_JD1_MODE_MASK (0x3 << 0)
1355#define RT5645_JD1_MODE_0 (0x0 << 0)
1356#define RT5645_JD1_MODE_1 (0x1 << 0)
1357#define RT5645_JD1_MODE_2 (0x2 << 0)
1351 1358
1352/* VAD Control 4 (0x9d) */ 1359/* VAD Control 4 (0x9d) */
1353#define RT5645_VAD_SEL_MASK (0x3 << 8) 1360#define RT5645_VAD_SEL_MASK (0x3 << 8)
@@ -1636,6 +1643,7 @@
1636#define RT5645_OT_P_SFT 10 1643#define RT5645_OT_P_SFT 10
1637#define RT5645_OT_P_NOR (0x0 << 10) 1644#define RT5645_OT_P_NOR (0x0 << 10)
1638#define RT5645_OT_P_INV (0x1 << 10) 1645#define RT5645_OT_P_INV (0x1 << 10)
1646#define RT5645_IRQ_JD_1_1_EN (0x1 << 9)
1639 1647
1640/* IRQ Control 2 (0xbe) */ 1648/* IRQ Control 2 (0xbe) */
1641#define RT5645_IRQ_MB1_OC_MASK (0x1 << 15) 1649#define RT5645_IRQ_MB1_OC_MASK (0x1 << 15)
@@ -1853,6 +1861,7 @@
1853#define RT5645_M_BB_HPF_R_SFT 6 1861#define RT5645_M_BB_HPF_R_SFT 6
1854#define RT5645_G_BB_BST_MASK (0x3f) 1862#define RT5645_G_BB_BST_MASK (0x3f)
1855#define RT5645_G_BB_BST_SFT 0 1863#define RT5645_G_BB_BST_SFT 0
1864#define RT5645_G_BB_BST_25DB 0x14
1856 1865
1857/* MP3 Plus Control 1 (0xd0) */ 1866/* MP3 Plus Control 1 (0xd0) */
1858#define RT5645_M_MP3_L_MASK (0x1 << 15) 1867#define RT5645_M_MP3_L_MASK (0x1 << 15)
@@ -2116,6 +2125,10 @@ enum {
2116#define RT5645_RXDP2_SEL_ADC (0x1 << 3) 2125#define RT5645_RXDP2_SEL_ADC (0x1 << 3)
2117#define RT5645_RXDP2_SEL_SFT (3) 2126#define RT5645_RXDP2_SEL_SFT (3)
2118 2127
2128/* General Control3 (0xfc) */
2129#define RT5645_JD_PSV_MODE (0x1 << 12)
2130#define RT5645_IRQ_CLK_GATE_CTRL (0x1 << 11)
2131#define RT5645_MICINDET_MANU (0x1 << 7)
2119 2132
2120/* Vendor ID (0xfd) */ 2133/* Vendor ID (0xfd) */
2121#define RT5645_VER_C 0x2 2134#define RT5645_VER_C 0x2
@@ -2167,7 +2180,9 @@ struct rt5645_priv {
2167 struct rt5645_platform_data pdata; 2180 struct rt5645_platform_data pdata;
2168 struct regmap *regmap; 2181 struct regmap *regmap;
2169 struct i2c_client *i2c; 2182 struct i2c_client *i2c;
2170 struct snd_soc_jack *jack; 2183 struct snd_soc_jack *hp_jack;
2184 struct snd_soc_jack *mic_jack;
2185 struct delayed_work jack_detect_work;
2171 2186
2172 int sysclk; 2187 int sysclk;
2173 int sysclk_src; 2188 int sysclk_src;
@@ -2181,6 +2196,6 @@ struct rt5645_priv {
2181}; 2196};
2182 2197
2183int rt5645_set_jack_detect(struct snd_soc_codec *codec, 2198int rt5645_set_jack_detect(struct snd_soc_codec *codec,
2184 struct snd_soc_jack *jack); 2199 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack);
2185 2200
2186#endif /* __RT5645_H__ */ 2201#endif /* __RT5645_H__ */
diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c
index 9bd8b4f63303..8a0833de1665 100644
--- a/sound/soc/codecs/rt5670.c
+++ b/sound/soc/codecs/rt5670.c
@@ -16,6 +16,7 @@
16#include <linux/pm.h> 16#include <linux/pm.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/acpi.h>
19#include <linux/spi/spi.h> 20#include <linux/spi/spi.h>
20#include <sound/core.h> 21#include <sound/core.h>
21#include <sound/pcm.h> 22#include <sound/pcm.h>
@@ -575,6 +576,18 @@ static int is_using_asrc(struct snd_soc_dapm_widget *source,
575 576
576} 577}
577 578
579static int can_use_asrc(struct snd_soc_dapm_widget *source,
580 struct snd_soc_dapm_widget *sink)
581{
582 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
583 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
584
585 if (rt5670->sysclk > rt5670->lrck[RT5670_AIF1] * 384)
586 return 1;
587
588 return 0;
589}
590
578/* Digital Mixer */ 591/* Digital Mixer */
579static const struct snd_kcontrol_new rt5670_sto1_adc_l_mix[] = { 592static const struct snd_kcontrol_new rt5670_sto1_adc_l_mix[] = {
580 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_STO1_ADC_MIXER, 593 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_STO1_ADC_MIXER,
@@ -1281,6 +1294,14 @@ static const struct snd_soc_dapm_widget rt5670_dapm_widgets[] = {
1281 9, 0, NULL, 0), 1294 9, 0, NULL, 0),
1282 SND_SOC_DAPM_SUPPLY_S("DAC MONO R ASRC", 1, RT5670_ASRC_1, 1295 SND_SOC_DAPM_SUPPLY_S("DAC MONO R ASRC", 1, RT5670_ASRC_1,
1283 8, 0, NULL, 0), 1296 8, 0, NULL, 0),
1297 SND_SOC_DAPM_SUPPLY_S("DMIC STO1 ASRC", 1, RT5670_ASRC_1,
1298 7, 0, NULL, 0),
1299 SND_SOC_DAPM_SUPPLY_S("DMIC STO2 ASRC", 1, RT5670_ASRC_1,
1300 6, 0, NULL, 0),
1301 SND_SOC_DAPM_SUPPLY_S("DMIC MONO L ASRC", 1, RT5670_ASRC_1,
1302 5, 0, NULL, 0),
1303 SND_SOC_DAPM_SUPPLY_S("DMIC MONO R ASRC", 1, RT5670_ASRC_1,
1304 4, 0, NULL, 0),
1284 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5670_ASRC_1, 1305 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5670_ASRC_1,
1285 3, 0, NULL, 0), 1306 3, 0, NULL, 0),
1286 SND_SOC_DAPM_SUPPLY_S("ADC STO2 ASRC", 1, RT5670_ASRC_1, 1307 SND_SOC_DAPM_SUPPLY_S("ADC STO2 ASRC", 1, RT5670_ASRC_1,
@@ -1595,29 +1616,40 @@ static const struct snd_soc_dapm_widget rt5670_dapm_widgets[] = {
1595 /* PDM */ 1616 /* PDM */
1596 SND_SOC_DAPM_SUPPLY("PDM1 Power", RT5670_PWR_DIG2, 1617 SND_SOC_DAPM_SUPPLY("PDM1 Power", RT5670_PWR_DIG2,
1597 RT5670_PWR_PDM1_BIT, 0, NULL, 0), 1618 RT5670_PWR_PDM1_BIT, 0, NULL, 0),
1598 SND_SOC_DAPM_SUPPLY("PDM2 Power", RT5670_PWR_DIG2,
1599 RT5670_PWR_PDM2_BIT, 0, NULL, 0),
1600 1619
1601 SND_SOC_DAPM_MUX("PDM1 L Mux", RT5670_PDM_OUT_CTRL, 1620 SND_SOC_DAPM_MUX("PDM1 L Mux", RT5670_PDM_OUT_CTRL,
1602 RT5670_M_PDM1_L_SFT, 1, &rt5670_pdm1_l_mux), 1621 RT5670_M_PDM1_L_SFT, 1, &rt5670_pdm1_l_mux),
1603 SND_SOC_DAPM_MUX("PDM1 R Mux", RT5670_PDM_OUT_CTRL, 1622 SND_SOC_DAPM_MUX("PDM1 R Mux", RT5670_PDM_OUT_CTRL,
1604 RT5670_M_PDM1_R_SFT, 1, &rt5670_pdm1_r_mux), 1623 RT5670_M_PDM1_R_SFT, 1, &rt5670_pdm1_r_mux),
1605 SND_SOC_DAPM_MUX("PDM2 L Mux", RT5670_PDM_OUT_CTRL,
1606 RT5670_M_PDM2_L_SFT, 1, &rt5670_pdm2_l_mux),
1607 SND_SOC_DAPM_MUX("PDM2 R Mux", RT5670_PDM_OUT_CTRL,
1608 RT5670_M_PDM2_R_SFT, 1, &rt5670_pdm2_r_mux),
1609 1624
1610 /* Output Lines */ 1625 /* Output Lines */
1611 SND_SOC_DAPM_OUTPUT("HPOL"), 1626 SND_SOC_DAPM_OUTPUT("HPOL"),
1612 SND_SOC_DAPM_OUTPUT("HPOR"), 1627 SND_SOC_DAPM_OUTPUT("HPOR"),
1613 SND_SOC_DAPM_OUTPUT("LOUTL"), 1628 SND_SOC_DAPM_OUTPUT("LOUTL"),
1614 SND_SOC_DAPM_OUTPUT("LOUTR"), 1629 SND_SOC_DAPM_OUTPUT("LOUTR"),
1630};
1631
1632static const struct snd_soc_dapm_widget rt5670_specific_dapm_widgets[] = {
1633 SND_SOC_DAPM_SUPPLY("PDM2 Power", RT5670_PWR_DIG2,
1634 RT5670_PWR_PDM2_BIT, 0, NULL, 0),
1635 SND_SOC_DAPM_MUX("PDM2 L Mux", RT5670_PDM_OUT_CTRL,
1636 RT5670_M_PDM2_L_SFT, 1, &rt5670_pdm2_l_mux),
1637 SND_SOC_DAPM_MUX("PDM2 R Mux", RT5670_PDM_OUT_CTRL,
1638 RT5670_M_PDM2_R_SFT, 1, &rt5670_pdm2_r_mux),
1615 SND_SOC_DAPM_OUTPUT("PDM1L"), 1639 SND_SOC_DAPM_OUTPUT("PDM1L"),
1616 SND_SOC_DAPM_OUTPUT("PDM1R"), 1640 SND_SOC_DAPM_OUTPUT("PDM1R"),
1617 SND_SOC_DAPM_OUTPUT("PDM2L"), 1641 SND_SOC_DAPM_OUTPUT("PDM2L"),
1618 SND_SOC_DAPM_OUTPUT("PDM2R"), 1642 SND_SOC_DAPM_OUTPUT("PDM2R"),
1619}; 1643};
1620 1644
1645static const struct snd_soc_dapm_widget rt5672_specific_dapm_widgets[] = {
1646 SND_SOC_DAPM_PGA("SPO Amp", SND_SOC_NOPM, 0, 0, NULL, 0),
1647 SND_SOC_DAPM_OUTPUT("SPOLP"),
1648 SND_SOC_DAPM_OUTPUT("SPOLN"),
1649 SND_SOC_DAPM_OUTPUT("SPORP"),
1650 SND_SOC_DAPM_OUTPUT("SPORN"),
1651};
1652
1621static const struct snd_soc_dapm_route rt5670_dapm_routes[] = { 1653static const struct snd_soc_dapm_route rt5670_dapm_routes[] = {
1622 { "ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc }, 1654 { "ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc },
1623 { "ADC Stereo2 Filter", NULL, "ADC STO2 ASRC", is_using_asrc }, 1655 { "ADC Stereo2 Filter", NULL, "ADC STO2 ASRC", is_using_asrc },
@@ -1626,9 +1658,13 @@ static const struct snd_soc_dapm_route rt5670_dapm_routes[] = {
1626 { "DAC Mono Left Filter", NULL, "DAC MONO L ASRC", is_using_asrc }, 1658 { "DAC Mono Left Filter", NULL, "DAC MONO L ASRC", is_using_asrc },
1627 { "DAC Mono Right Filter", NULL, "DAC MONO R ASRC", is_using_asrc }, 1659 { "DAC Mono Right Filter", NULL, "DAC MONO R ASRC", is_using_asrc },
1628 { "DAC Stereo1 Filter", NULL, "DAC STO ASRC", is_using_asrc }, 1660 { "DAC Stereo1 Filter", NULL, "DAC STO ASRC", is_using_asrc },
1661 { "Stereo1 DMIC Mux", NULL, "DMIC STO1 ASRC", can_use_asrc },
1662 { "Stereo2 DMIC Mux", NULL, "DMIC STO2 ASRC", can_use_asrc },
1663 { "Mono DMIC L Mux", NULL, "DMIC MONO L ASRC", can_use_asrc },
1664 { "Mono DMIC R Mux", NULL, "DMIC MONO R ASRC", can_use_asrc },
1629 1665
1630 { "I2S1", NULL, "I2S1 ASRC" }, 1666 { "I2S1", NULL, "I2S1 ASRC", can_use_asrc},
1631 { "I2S2", NULL, "I2S2 ASRC" }, 1667 { "I2S2", NULL, "I2S2 ASRC", can_use_asrc},
1632 1668
1633 { "DMIC1", NULL, "DMIC L1" }, 1669 { "DMIC1", NULL, "DMIC L1" },
1634 { "DMIC1", NULL, "DMIC R1" }, 1670 { "DMIC1", NULL, "DMIC R1" },
@@ -1970,12 +2006,6 @@ static const struct snd_soc_dapm_route rt5670_dapm_routes[] = {
1970 { "PDM1 R Mux", "Stereo DAC", "Stereo DAC MIXR" }, 2006 { "PDM1 R Mux", "Stereo DAC", "Stereo DAC MIXR" },
1971 { "PDM1 R Mux", "Mono DAC", "Mono DAC MIXR" }, 2007 { "PDM1 R Mux", "Mono DAC", "Mono DAC MIXR" },
1972 { "PDM1 R Mux", NULL, "PDM1 Power" }, 2008 { "PDM1 R Mux", NULL, "PDM1 Power" },
1973 { "PDM2 L Mux", "Stereo DAC", "Stereo DAC MIXL" },
1974 { "PDM2 L Mux", "Mono DAC", "Mono DAC MIXL" },
1975 { "PDM2 L Mux", NULL, "PDM2 Power" },
1976 { "PDM2 R Mux", "Stereo DAC", "Stereo DAC MIXR" },
1977 { "PDM2 R Mux", "Mono DAC", "Mono DAC MIXR" },
1978 { "PDM2 R Mux", NULL, "PDM2 Power" },
1979 2009
1980 { "HP Amp", NULL, "HPO MIX" }, 2010 { "HP Amp", NULL, "HPO MIX" },
1981 { "HP Amp", NULL, "Mic Det Power" }, 2011 { "HP Amp", NULL, "Mic Det Power" },
@@ -1993,13 +2023,30 @@ static const struct snd_soc_dapm_route rt5670_dapm_routes[] = {
1993 { "LOUTR", NULL, "LOUT R Playback" }, 2023 { "LOUTR", NULL, "LOUT R Playback" },
1994 { "LOUTL", NULL, "Improve HP Amp Drv" }, 2024 { "LOUTL", NULL, "Improve HP Amp Drv" },
1995 { "LOUTR", NULL, "Improve HP Amp Drv" }, 2025 { "LOUTR", NULL, "Improve HP Amp Drv" },
2026};
1996 2027
2028static const struct snd_soc_dapm_route rt5670_specific_dapm_routes[] = {
2029 { "PDM2 L Mux", "Stereo DAC", "Stereo DAC MIXL" },
2030 { "PDM2 L Mux", "Mono DAC", "Mono DAC MIXL" },
2031 { "PDM2 L Mux", NULL, "PDM2 Power" },
2032 { "PDM2 R Mux", "Stereo DAC", "Stereo DAC MIXR" },
2033 { "PDM2 R Mux", "Mono DAC", "Mono DAC MIXR" },
2034 { "PDM2 R Mux", NULL, "PDM2 Power" },
1997 { "PDM1L", NULL, "PDM1 L Mux" }, 2035 { "PDM1L", NULL, "PDM1 L Mux" },
1998 { "PDM1R", NULL, "PDM1 R Mux" }, 2036 { "PDM1R", NULL, "PDM1 R Mux" },
1999 { "PDM2L", NULL, "PDM2 L Mux" }, 2037 { "PDM2L", NULL, "PDM2 L Mux" },
2000 { "PDM2R", NULL, "PDM2 R Mux" }, 2038 { "PDM2R", NULL, "PDM2 R Mux" },
2001}; 2039};
2002 2040
2041static const struct snd_soc_dapm_route rt5672_specific_dapm_routes[] = {
2042 { "SPO Amp", NULL, "PDM1 L Mux" },
2043 { "SPO Amp", NULL, "PDM1 R Mux" },
2044 { "SPOLP", NULL, "SPO Amp" },
2045 { "SPOLN", NULL, "SPO Amp" },
2046 { "SPORP", NULL, "SPO Amp" },
2047 { "SPORN", NULL, "SPO Amp" },
2048};
2049
2003static int rt5670_hw_params(struct snd_pcm_substream *substream, 2050static int rt5670_hw_params(struct snd_pcm_substream *substream,
2004 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 2051 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
2005{ 2052{
@@ -2287,6 +2334,8 @@ static int rt5670_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
2287static int rt5670_set_bias_level(struct snd_soc_codec *codec, 2334static int rt5670_set_bias_level(struct snd_soc_codec *codec,
2288 enum snd_soc_bias_level level) 2335 enum snd_soc_bias_level level)
2289{ 2336{
2337 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
2338
2290 switch (level) { 2339 switch (level) {
2291 case SND_SOC_BIAS_PREPARE: 2340 case SND_SOC_BIAS_PREPARE:
2292 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) { 2341 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) {
@@ -2308,16 +2357,27 @@ static int rt5670_set_bias_level(struct snd_soc_codec *codec,
2308 } 2357 }
2309 break; 2358 break;
2310 case SND_SOC_BIAS_STANDBY: 2359 case SND_SOC_BIAS_STANDBY:
2311 snd_soc_write(codec, RT5670_PWR_DIG1, 0x0000); 2360 snd_soc_update_bits(codec, RT5670_PWR_ANLG1,
2312 snd_soc_write(codec, RT5670_PWR_DIG2, 0x0001); 2361 RT5670_PWR_VREF1 | RT5670_PWR_VREF2 |
2313 snd_soc_write(codec, RT5670_PWR_VOL, 0x0000); 2362 RT5670_PWR_FV1 | RT5670_PWR_FV2, 0);
2314 snd_soc_write(codec, RT5670_PWR_MIXER, 0x0001);
2315 snd_soc_write(codec, RT5670_PWR_ANLG1, 0x2800);
2316 snd_soc_write(codec, RT5670_PWR_ANLG2, 0x0004);
2317 snd_soc_update_bits(codec, RT5670_DIG_MISC, 0x1, 0x0);
2318 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2363 snd_soc_update_bits(codec, RT5670_PWR_ANLG1,
2319 RT5670_LDO_SEL_MASK, 0x1); 2364 RT5670_LDO_SEL_MASK, 0x1);
2320 break; 2365 break;
2366 case SND_SOC_BIAS_OFF:
2367 if (rt5670->pdata.jd_mode)
2368 snd_soc_update_bits(codec, RT5670_PWR_ANLG1,
2369 RT5670_PWR_VREF1 | RT5670_PWR_MB |
2370 RT5670_PWR_BG | RT5670_PWR_VREF2 |
2371 RT5670_PWR_FV1 | RT5670_PWR_FV2,
2372 RT5670_PWR_MB | RT5670_PWR_BG);
2373 else
2374 snd_soc_update_bits(codec, RT5670_PWR_ANLG1,
2375 RT5670_PWR_VREF1 | RT5670_PWR_MB |
2376 RT5670_PWR_BG | RT5670_PWR_VREF2 |
2377 RT5670_PWR_FV1 | RT5670_PWR_FV2, 0);
2378
2379 snd_soc_update_bits(codec, RT5670_DIG_MISC, 0x1, 0x0);
2380 break;
2321 2381
2322 default: 2382 default:
2323 break; 2383 break;
@@ -2331,6 +2391,29 @@ static int rt5670_probe(struct snd_soc_codec *codec)
2331{ 2391{
2332 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2392 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
2333 2393
2394 switch (snd_soc_read(codec, RT5670_RESET) & RT5670_ID_MASK) {
2395 case RT5670_ID_5670:
2396 case RT5670_ID_5671:
2397 snd_soc_dapm_new_controls(&codec->dapm,
2398 rt5670_specific_dapm_widgets,
2399 ARRAY_SIZE(rt5670_specific_dapm_widgets));
2400 snd_soc_dapm_add_routes(&codec->dapm,
2401 rt5670_specific_dapm_routes,
2402 ARRAY_SIZE(rt5670_specific_dapm_routes));
2403 break;
2404 case RT5670_ID_5672:
2405 snd_soc_dapm_new_controls(&codec->dapm,
2406 rt5672_specific_dapm_widgets,
2407 ARRAY_SIZE(rt5672_specific_dapm_widgets));
2408 snd_soc_dapm_add_routes(&codec->dapm,
2409 rt5672_specific_dapm_routes,
2410 ARRAY_SIZE(rt5672_specific_dapm_routes));
2411 break;
2412 default:
2413 dev_err(codec->dev,
2414 "The driver is for RT5670 RT5671 or RT5672 only\n");
2415 return -ENODEV;
2416 }
2334 rt5670->codec = codec; 2417 rt5670->codec = codec;
2335 2418
2336 return 0; 2419 return 0;
@@ -2452,10 +2535,20 @@ static const struct regmap_config rt5670_regmap = {
2452 2535
2453static const struct i2c_device_id rt5670_i2c_id[] = { 2536static const struct i2c_device_id rt5670_i2c_id[] = {
2454 { "rt5670", 0 }, 2537 { "rt5670", 0 },
2538 { "rt5671", 0 },
2539 { "rt5672", 0 },
2455 { } 2540 { }
2456}; 2541};
2457MODULE_DEVICE_TABLE(i2c, rt5670_i2c_id); 2542MODULE_DEVICE_TABLE(i2c, rt5670_i2c_id);
2458 2543
2544#ifdef CONFIG_ACPI
2545static struct acpi_device_id rt5670_acpi_match[] = {
2546 { "10EC5670", 0},
2547 { },
2548};
2549MODULE_DEVICE_TABLE(acpi, rt5670_acpi_match);
2550#endif
2551
2459static int rt5670_i2c_probe(struct i2c_client *i2c, 2552static int rt5670_i2c_probe(struct i2c_client *i2c,
2460 const struct i2c_device_id *id) 2553 const struct i2c_device_id *id)
2461{ 2554{
@@ -2644,6 +2737,7 @@ static struct i2c_driver rt5670_i2c_driver = {
2644 .driver = { 2737 .driver = {
2645 .name = "rt5670", 2738 .name = "rt5670",
2646 .owner = THIS_MODULE, 2739 .owner = THIS_MODULE,
2740 .acpi_match_table = ACPI_PTR(rt5670_acpi_match),
2647 }, 2741 },
2648 .probe = rt5670_i2c_probe, 2742 .probe = rt5670_i2c_probe,
2649 .remove = rt5670_i2c_remove, 2743 .remove = rt5670_i2c_remove,
diff --git a/sound/soc/codecs/rt5670.h b/sound/soc/codecs/rt5670.h
index a0b5c855b492..d11b9c207e26 100644
--- a/sound/soc/codecs/rt5670.h
+++ b/sound/soc/codecs/rt5670.h
@@ -228,6 +228,12 @@
228#define RT5670_R_VOL_MASK (0x3f) 228#define RT5670_R_VOL_MASK (0x3f)
229#define RT5670_R_VOL_SFT 0 229#define RT5670_R_VOL_SFT 0
230 230
231/* SW Reset & Device ID (0x00) */
232#define RT5670_ID_MASK (0x3 << 1)
233#define RT5670_ID_5670 (0x0 << 1)
234#define RT5670_ID_5672 (0x1 << 1)
235#define RT5670_ID_5671 (0x2 << 1)
236
231/* Combo Jack Control 1 (0x0a) */ 237/* Combo Jack Control 1 (0x0a) */
232#define RT5670_CBJ_BST1_MASK (0xf << 12) 238#define RT5670_CBJ_BST1_MASK (0xf << 12)
233#define RT5670_CBJ_BST1_SFT (12) 239#define RT5670_CBJ_BST1_SFT (12)
diff --git a/sound/soc/codecs/rt5677-spi.c b/sound/soc/codecs/rt5677-spi.c
new file mode 100644
index 000000000000..ef6348cb9157
--- /dev/null
+++ b/sound/soc/codecs/rt5677-spi.c
@@ -0,0 +1,130 @@
1/*
2 * rt5677-spi.c -- RT5677 ALSA SoC audio codec driver
3 *
4 * Copyright 2013 Realtek Semiconductor Corp.
5 * Author: Oder Chiou <oder_chiou@realtek.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/input.h>
14#include <linux/spi/spi.h>
15#include <linux/device.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/interrupt.h>
19#include <linux/irq.h>
20#include <linux/slab.h>
21#include <linux/gpio.h>
22#include <linux/sched.h>
23#include <linux/kthread.h>
24#include <linux/uaccess.h>
25#include <linux/miscdevice.h>
26#include <linux/regulator/consumer.h>
27#include <linux/pm_qos.h>
28#include <linux/sysfs.h>
29#include <linux/clk.h>
30#include <linux/firmware.h>
31
32#include "rt5677-spi.h"
33
34static struct spi_device *g_spi;
35
36/**
37 * rt5677_spi_write - Write data to SPI.
38 * @txbuf: Data Buffer for writing.
39 * @len: Data length.
40 *
41 *
42 * Returns true for success.
43 */
44int rt5677_spi_write(u8 *txbuf, size_t len)
45{
46 int status;
47
48 status = spi_write(g_spi, txbuf, len);
49
50 if (status)
51 dev_err(&g_spi->dev, "rt5677_spi_write error %d\n", status);
52
53 return status;
54}
55EXPORT_SYMBOL_GPL(rt5677_spi_write);
56
57/**
58 * rt5677_spi_burst_write - Write data to SPI by rt5677 dsp memory address.
59 * @addr: Start address.
60 * @txbuf: Data Buffer for writng.
61 * @len: Data length, it must be a multiple of 8.
62 *
63 *
64 * Returns true for success.
65 */
66int rt5677_spi_burst_write(u32 addr, const struct firmware *fw)
67{
68 u8 spi_cmd = RT5677_SPI_CMD_BURST_WRITE;
69 u8 *write_buf;
70 unsigned int i, end, offset = 0;
71
72 write_buf = kmalloc(RT5677_SPI_BUF_LEN + 6, GFP_KERNEL);
73
74 if (write_buf == NULL)
75 return -ENOMEM;
76
77 while (offset < fw->size) {
78 if (offset + RT5677_SPI_BUF_LEN <= fw->size)
79 end = RT5677_SPI_BUF_LEN;
80 else
81 end = fw->size % RT5677_SPI_BUF_LEN;
82
83 write_buf[0] = spi_cmd;
84 write_buf[1] = ((addr + offset) & 0xff000000) >> 24;
85 write_buf[2] = ((addr + offset) & 0x00ff0000) >> 16;
86 write_buf[3] = ((addr + offset) & 0x0000ff00) >> 8;
87 write_buf[4] = ((addr + offset) & 0x000000ff) >> 0;
88
89 for (i = 0; i < end; i += 8) {
90 write_buf[i + 12] = fw->data[offset + i + 0];
91 write_buf[i + 11] = fw->data[offset + i + 1];
92 write_buf[i + 10] = fw->data[offset + i + 2];
93 write_buf[i + 9] = fw->data[offset + i + 3];
94 write_buf[i + 8] = fw->data[offset + i + 4];
95 write_buf[i + 7] = fw->data[offset + i + 5];
96 write_buf[i + 6] = fw->data[offset + i + 6];
97 write_buf[i + 5] = fw->data[offset + i + 7];
98 }
99
100 write_buf[end + 5] = spi_cmd;
101
102 rt5677_spi_write(write_buf, end + 6);
103
104 offset += RT5677_SPI_BUF_LEN;
105 }
106
107 kfree(write_buf);
108
109 return 0;
110}
111EXPORT_SYMBOL_GPL(rt5677_spi_burst_write);
112
113static int rt5677_spi_probe(struct spi_device *spi)
114{
115 g_spi = spi;
116 return 0;
117}
118
119static struct spi_driver rt5677_spi_driver = {
120 .driver = {
121 .name = "rt5677",
122 .owner = THIS_MODULE,
123 },
124 .probe = rt5677_spi_probe,
125};
126module_spi_driver(rt5677_spi_driver);
127
128MODULE_DESCRIPTION("ASoC RT5677 SPI driver");
129MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>");
130MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/rt5677-spi.h b/sound/soc/codecs/rt5677-spi.h
new file mode 100644
index 000000000000..ec41b2b3b2ca
--- /dev/null
+++ b/sound/soc/codecs/rt5677-spi.h
@@ -0,0 +1,21 @@
1/*
2 * rt5677-spi.h -- RT5677 ALSA SoC audio codec driver
3 *
4 * Copyright 2013 Realtek Semiconductor Corp.
5 * Author: Oder Chiou <oder_chiou@realtek.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef __RT5677_SPI_H__
13#define __RT5677_SPI_H__
14
15#define RT5677_SPI_BUF_LEN 240
16#define RT5677_SPI_CMD_BURST_WRITE 0x05
17
18int rt5677_spi_write(u8 *txbuf, size_t len);
19int rt5677_spi_burst_write(u32 addr, const struct firmware *fw);
20
21#endif /* __RT5677_SPI_H__ */
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index 16aa4d99a713..81fe1464d268 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -20,6 +20,7 @@
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/spi/spi.h> 22#include <linux/spi/spi.h>
23#include <linux/firmware.h>
23#include <linux/gpio.h> 24#include <linux/gpio.h>
24#include <sound/core.h> 25#include <sound/core.h>
25#include <sound/pcm.h> 26#include <sound/pcm.h>
@@ -31,6 +32,7 @@
31 32
32#include "rl6231.h" 33#include "rl6231.h"
33#include "rt5677.h" 34#include "rt5677.h"
35#include "rt5677-spi.h"
34 36
35#define RT5677_DEVICE_ID 0x6327 37#define RT5677_DEVICE_ID 0x6327
36 38
@@ -53,12 +55,13 @@ static const struct regmap_range_cfg rt5677_ranges[] = {
53}; 55};
54 56
55static const struct reg_default init_list[] = { 57static const struct reg_default init_list[] = {
58 {RT5677_ASRC_12, 0x0018},
56 {RT5677_PR_BASE + 0x3d, 0x364d}, 59 {RT5677_PR_BASE + 0x3d, 0x364d},
57 {RT5677_PR_BASE + 0x17, 0x4fc0}, 60 {RT5677_PR_BASE + 0x17, 0x4fc0},
58 {RT5677_PR_BASE + 0x13, 0x0312}, 61 {RT5677_PR_BASE + 0x13, 0x0312},
59 {RT5677_PR_BASE + 0x1e, 0x0000}, 62 {RT5677_PR_BASE + 0x1e, 0x0000},
60 {RT5677_PR_BASE + 0x12, 0x0eaa}, 63 {RT5677_PR_BASE + 0x12, 0x0eaa},
61 {RT5677_PR_BASE + 0x14, 0x018a}, 64 {RT5677_PR_BASE + 0x14, 0x018a},
62}; 65};
63#define RT5677_INIT_REG_LEN ARRAY_SIZE(init_list) 66#define RT5677_INIT_REG_LEN ARRAY_SIZE(init_list)
64 67
@@ -171,7 +174,7 @@ static const struct reg_default rt5677_reg[] = {
171 {RT5677_ASRC_9 , 0x0000}, 174 {RT5677_ASRC_9 , 0x0000},
172 {RT5677_ASRC_10 , 0x0000}, 175 {RT5677_ASRC_10 , 0x0000},
173 {RT5677_ASRC_11 , 0x0000}, 176 {RT5677_ASRC_11 , 0x0000},
174 {RT5677_ASRC_12 , 0x0008}, 177 {RT5677_ASRC_12 , 0x0018},
175 {RT5677_ASRC_13 , 0x0000}, 178 {RT5677_ASRC_13 , 0x0000},
176 {RT5677_ASRC_14 , 0x0000}, 179 {RT5677_ASRC_14 , 0x0000},
177 {RT5677_ASRC_15 , 0x0000}, 180 {RT5677_ASRC_15 , 0x0000},
@@ -537,10 +540,232 @@ static bool rt5677_readable_register(struct device *dev, unsigned int reg)
537 } 540 }
538} 541}
539 542
543/**
544 * rt5677_dsp_mode_i2c_write_addr - Write value to address on DSP mode.
545 * @rt5677: Private Data.
546 * @addr: Address index.
547 * @value: Address data.
548 *
549 *
550 * Returns 0 for success or negative error code.
551 */
552static int rt5677_dsp_mode_i2c_write_addr(struct rt5677_priv *rt5677,
553 unsigned int addr, unsigned int value, unsigned int opcode)
554{
555 struct snd_soc_codec *codec = rt5677->codec;
556 int ret;
557
558 mutex_lock(&rt5677->dsp_cmd_lock);
559
560 ret = regmap_write(rt5677->regmap_physical, RT5677_DSP_I2C_ADDR_MSB,
561 addr >> 16);
562 if (ret < 0) {
563 dev_err(codec->dev, "Failed to set addr msb value: %d\n", ret);
564 goto err;
565 }
566
567 ret = regmap_write(rt5677->regmap_physical, RT5677_DSP_I2C_ADDR_LSB,
568 addr & 0xffff);
569 if (ret < 0) {
570 dev_err(codec->dev, "Failed to set addr lsb value: %d\n", ret);
571 goto err;
572 }
573
574 ret = regmap_write(rt5677->regmap_physical, RT5677_DSP_I2C_DATA_MSB,
575 value >> 16);
576 if (ret < 0) {
577 dev_err(codec->dev, "Failed to set data msb value: %d\n", ret);
578 goto err;
579 }
580
581 ret = regmap_write(rt5677->regmap_physical, RT5677_DSP_I2C_DATA_LSB,
582 value & 0xffff);
583 if (ret < 0) {
584 dev_err(codec->dev, "Failed to set data lsb value: %d\n", ret);
585 goto err;
586 }
587
588 ret = regmap_write(rt5677->regmap_physical, RT5677_DSP_I2C_OP_CODE,
589 opcode);
590 if (ret < 0) {
591 dev_err(codec->dev, "Failed to set op code value: %d\n", ret);
592 goto err;
593 }
594
595err:
596 mutex_unlock(&rt5677->dsp_cmd_lock);
597
598 return ret;
599}
600
601/**
602 * rt5677_dsp_mode_i2c_read_addr - Read value from address on DSP mode.
603 * rt5677: Private Data.
604 * @addr: Address index.
605 * @value: Address data.
606 *
607 *
608 * Returns 0 for success or negative error code.
609 */
610static int rt5677_dsp_mode_i2c_read_addr(
611 struct rt5677_priv *rt5677, unsigned int addr, unsigned int *value)
612{
613 struct snd_soc_codec *codec = rt5677->codec;
614 int ret;
615 unsigned int msb, lsb;
616
617 mutex_lock(&rt5677->dsp_cmd_lock);
618
619 ret = regmap_write(rt5677->regmap_physical, RT5677_DSP_I2C_ADDR_MSB,
620 addr >> 16);
621 if (ret < 0) {
622 dev_err(codec->dev, "Failed to set addr msb value: %d\n", ret);
623 goto err;
624 }
625
626 ret = regmap_write(rt5677->regmap_physical, RT5677_DSP_I2C_ADDR_LSB,
627 addr & 0xffff);
628 if (ret < 0) {
629 dev_err(codec->dev, "Failed to set addr lsb value: %d\n", ret);
630 goto err;
631 }
632
633 ret = regmap_write(rt5677->regmap_physical, RT5677_DSP_I2C_OP_CODE,
634 0x0002);
635 if (ret < 0) {
636 dev_err(codec->dev, "Failed to set op code value: %d\n", ret);
637 goto err;
638 }
639
640 regmap_read(rt5677->regmap_physical, RT5677_DSP_I2C_DATA_MSB, &msb);
641 regmap_read(rt5677->regmap_physical, RT5677_DSP_I2C_DATA_LSB, &lsb);
642 *value = (msb << 16) | lsb;
643
644err:
645 mutex_unlock(&rt5677->dsp_cmd_lock);
646
647 return ret;
648}
649
650/**
651 * rt5677_dsp_mode_i2c_write - Write register on DSP mode.
652 * rt5677: Private Data.
653 * @reg: Register index.
654 * @value: Register data.
655 *
656 *
657 * Returns 0 for success or negative error code.
658 */
659static int rt5677_dsp_mode_i2c_write(struct rt5677_priv *rt5677,
660 unsigned int reg, unsigned int value)
661{
662 return rt5677_dsp_mode_i2c_write_addr(rt5677, 0x18020000 + reg * 2,
663 value, 0x0001);
664}
665
666/**
667 * rt5677_dsp_mode_i2c_read - Read register on DSP mode.
668 * @codec: SoC audio codec device.
669 * @reg: Register index.
670 * @value: Register data.
671 *
672 *
673 * Returns 0 for success or negative error code.
674 */
675static int rt5677_dsp_mode_i2c_read(
676 struct rt5677_priv *rt5677, unsigned int reg, unsigned int *value)
677{
678 int ret = rt5677_dsp_mode_i2c_read_addr(rt5677, 0x18020000 + reg * 2,
679 value);
680
681 *value &= 0xffff;
682
683 return ret;
684}
685
686static void rt5677_set_dsp_mode(struct snd_soc_codec *codec, bool on)
687{
688 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
689
690 if (on) {
691 regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x2, 0x2);
692 rt5677->is_dsp_mode = true;
693 } else {
694 regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x2, 0x0);
695 rt5677->is_dsp_mode = false;
696 }
697}
698
699static int rt5677_set_dsp_vad(struct snd_soc_codec *codec, bool on)
700{
701 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
702 static bool activity;
703 int ret;
704
705 if (on && !activity) {
706 activity = true;
707
708 regcache_cache_only(rt5677->regmap, false);
709 regcache_cache_bypass(rt5677->regmap, true);
710
711 regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x1);
712 regmap_update_bits(rt5677->regmap,
713 RT5677_PR_BASE + RT5677_BIAS_CUR4, 0x0f00, 0x0f00);
714 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
715 RT5677_LDO1_SEL_MASK, 0x0);
716 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2,
717 RT5677_PWR_LDO1, RT5677_PWR_LDO1);
718 regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK1,
719 RT5677_MCLK_SRC_MASK, RT5677_MCLK2_SRC);
720 regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK2,
721 RT5677_PLL2_PR_SRC_MASK | RT5677_DSP_CLK_SRC_MASK,
722 RT5677_PLL2_PR_SRC_MCLK2 | RT5677_DSP_CLK_SRC_BYPASS);
723 regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x07ff);
724 regmap_write(rt5677->regmap, RT5677_PWR_DSP1, 0x07fd);
725 rt5677_set_dsp_mode(codec, true);
726
727 ret = request_firmware(&rt5677->fw1, RT5677_FIRMWARE1,
728 codec->dev);
729 if (ret == 0) {
730 rt5677_spi_burst_write(0x50000000, rt5677->fw1);
731 release_firmware(rt5677->fw1);
732 }
733
734 ret = request_firmware(&rt5677->fw2, RT5677_FIRMWARE2,
735 codec->dev);
736 if (ret == 0) {
737 rt5677_spi_burst_write(0x60000000, rt5677->fw2);
738 release_firmware(rt5677->fw2);
739 }
740
741 regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x1, 0x0);
742
743 regcache_cache_bypass(rt5677->regmap, false);
744 regcache_cache_only(rt5677->regmap, true);
745 } else if (!on && activity) {
746 activity = false;
747
748 regcache_cache_only(rt5677->regmap, false);
749 regcache_cache_bypass(rt5677->regmap, true);
750
751 regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x1, 0x1);
752 rt5677_set_dsp_mode(codec, false);
753 regmap_write(rt5677->regmap, RT5677_PWR_DSP1, 0x0001);
754
755 regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec);
756
757 regcache_cache_bypass(rt5677->regmap, false);
758 regcache_mark_dirty(rt5677->regmap);
759 regcache_sync(rt5677->regmap);
760 }
761
762 return 0;
763}
764
540static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0); 765static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
541static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0); 766static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
542static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0); 767static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
543static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -17625, 375, 0); 768static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
544static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0); 769static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0);
545static const DECLARE_TLV_DB_SCALE(st_vol_tlv, -4650, 150, 0); 770static const DECLARE_TLV_DB_SCALE(st_vol_tlv, -4650, 150, 0);
546 771
@@ -556,6 +781,31 @@ static unsigned int bst_tlv[] = {
556 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0), 781 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0),
557}; 782};
558 783
784static int rt5677_dsp_vad_get(struct snd_kcontrol *kcontrol,
785 struct snd_ctl_elem_value *ucontrol)
786{
787 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
788 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
789
790 ucontrol->value.integer.value[0] = rt5677->dsp_vad_en;
791
792 return 0;
793}
794
795static int rt5677_dsp_vad_put(struct snd_kcontrol *kcontrol,
796 struct snd_ctl_elem_value *ucontrol)
797{
798 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
799 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
800
801 rt5677->dsp_vad_en = !!ucontrol->value.integer.value[0];
802
803 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
804 rt5677_set_dsp_vad(codec, rt5677->dsp_vad_en);
805
806 return 0;
807}
808
559static const struct snd_kcontrol_new rt5677_snd_controls[] = { 809static const struct snd_kcontrol_new rt5677_snd_controls[] = {
560 /* OUTPUT Control */ 810 /* OUTPUT Control */
561 SOC_SINGLE("OUT1 Playback Switch", RT5677_LOUT1, 811 SOC_SINGLE("OUT1 Playback Switch", RT5677_LOUT1,
@@ -567,13 +817,13 @@ static const struct snd_kcontrol_new rt5677_snd_controls[] = {
567 817
568 /* DAC Digital Volume */ 818 /* DAC Digital Volume */
569 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5677_DAC1_DIG_VOL, 819 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5677_DAC1_DIG_VOL,
570 RT5677_L_VOL_SFT, RT5677_R_VOL_SFT, 175, 0, dac_vol_tlv), 820 RT5677_L_VOL_SFT, RT5677_R_VOL_SFT, 87, 0, dac_vol_tlv),
571 SOC_DOUBLE_TLV("DAC2 Playback Volume", RT5677_DAC2_DIG_VOL, 821 SOC_DOUBLE_TLV("DAC2 Playback Volume", RT5677_DAC2_DIG_VOL,
572 RT5677_L_VOL_SFT, RT5677_R_VOL_SFT, 175, 0, dac_vol_tlv), 822 RT5677_L_VOL_SFT, RT5677_R_VOL_SFT, 87, 0, dac_vol_tlv),
573 SOC_DOUBLE_TLV("DAC3 Playback Volume", RT5677_DAC3_DIG_VOL, 823 SOC_DOUBLE_TLV("DAC3 Playback Volume", RT5677_DAC3_DIG_VOL,
574 RT5677_L_VOL_SFT, RT5677_R_VOL_SFT, 175, 0, dac_vol_tlv), 824 RT5677_L_VOL_SFT, RT5677_R_VOL_SFT, 87, 0, dac_vol_tlv),
575 SOC_DOUBLE_TLV("DAC4 Playback Volume", RT5677_DAC4_DIG_VOL, 825 SOC_DOUBLE_TLV("DAC4 Playback Volume", RT5677_DAC4_DIG_VOL,
576 RT5677_L_VOL_SFT, RT5677_R_VOL_SFT, 175, 0, dac_vol_tlv), 826 RT5677_L_VOL_SFT, RT5677_R_VOL_SFT, 87, 0, dac_vol_tlv),
577 827
578 /* IN1/IN2 Control */ 828 /* IN1/IN2 Control */
579 SOC_SINGLE_TLV("IN1 Boost", RT5677_IN1, RT5677_BST_SFT1, 8, 0, bst_tlv), 829 SOC_SINGLE_TLV("IN1 Boost", RT5677_IN1, RT5677_BST_SFT1, 8, 0, bst_tlv),
@@ -592,19 +842,19 @@ static const struct snd_kcontrol_new rt5677_snd_controls[] = {
592 RT5677_L_MUTE_SFT, RT5677_R_MUTE_SFT, 1, 1), 842 RT5677_L_MUTE_SFT, RT5677_R_MUTE_SFT, 1, 1),
593 843
594 SOC_DOUBLE_TLV("ADC1 Capture Volume", RT5677_STO1_ADC_DIG_VOL, 844 SOC_DOUBLE_TLV("ADC1 Capture Volume", RT5677_STO1_ADC_DIG_VOL,
595 RT5677_STO1_ADC_L_VOL_SFT, RT5677_STO1_ADC_R_VOL_SFT, 127, 0, 845 RT5677_STO1_ADC_L_VOL_SFT, RT5677_STO1_ADC_R_VOL_SFT, 63, 0,
596 adc_vol_tlv), 846 adc_vol_tlv),
597 SOC_DOUBLE_TLV("ADC2 Capture Volume", RT5677_STO2_ADC_DIG_VOL, 847 SOC_DOUBLE_TLV("ADC2 Capture Volume", RT5677_STO2_ADC_DIG_VOL,
598 RT5677_STO1_ADC_L_VOL_SFT, RT5677_STO1_ADC_R_VOL_SFT, 127, 0, 848 RT5677_STO1_ADC_L_VOL_SFT, RT5677_STO1_ADC_R_VOL_SFT, 63, 0,
599 adc_vol_tlv), 849 adc_vol_tlv),
600 SOC_DOUBLE_TLV("ADC3 Capture Volume", RT5677_STO3_ADC_DIG_VOL, 850 SOC_DOUBLE_TLV("ADC3 Capture Volume", RT5677_STO3_ADC_DIG_VOL,
601 RT5677_STO1_ADC_L_VOL_SFT, RT5677_STO1_ADC_R_VOL_SFT, 127, 0, 851 RT5677_STO1_ADC_L_VOL_SFT, RT5677_STO1_ADC_R_VOL_SFT, 63, 0,
602 adc_vol_tlv), 852 adc_vol_tlv),
603 SOC_DOUBLE_TLV("ADC4 Capture Volume", RT5677_STO4_ADC_DIG_VOL, 853 SOC_DOUBLE_TLV("ADC4 Capture Volume", RT5677_STO4_ADC_DIG_VOL,
604 RT5677_STO1_ADC_L_VOL_SFT, RT5677_STO1_ADC_R_VOL_SFT, 127, 0, 854 RT5677_STO1_ADC_L_VOL_SFT, RT5677_STO1_ADC_R_VOL_SFT, 63, 0,
605 adc_vol_tlv), 855 adc_vol_tlv),
606 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5677_MONO_ADC_DIG_VOL, 856 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5677_MONO_ADC_DIG_VOL,
607 RT5677_MONO_ADC_L_VOL_SFT, RT5677_MONO_ADC_R_VOL_SFT, 127, 0, 857 RT5677_MONO_ADC_L_VOL_SFT, RT5677_MONO_ADC_R_VOL_SFT, 63, 0,
608 adc_vol_tlv), 858 adc_vol_tlv),
609 859
610 /* Sidetone Control */ 860 /* Sidetone Control */
@@ -627,6 +877,9 @@ static const struct snd_kcontrol_new rt5677_snd_controls[] = {
627 SOC_DOUBLE_TLV("Mono ADC Boost Volume", RT5677_ADC_BST_CTRL2, 877 SOC_DOUBLE_TLV("Mono ADC Boost Volume", RT5677_ADC_BST_CTRL2,
628 RT5677_MONO_ADC_L_BST_SFT, RT5677_MONO_ADC_R_BST_SFT, 3, 0, 878 RT5677_MONO_ADC_L_BST_SFT, RT5677_MONO_ADC_R_BST_SFT, 3, 0,
629 adc_bst_tlv), 879 adc_bst_tlv),
880
881 SOC_SINGLE_EXT("DSP VAD Switch", SND_SOC_NOPM, 0, 1, 0,
882 rt5677_dsp_vad_get, rt5677_dsp_vad_put),
630}; 883};
631 884
632/** 885/**
@@ -1086,7 +1339,7 @@ static SOC_ENUM_SINGLE_DECL(
1086static const struct snd_kcontrol_new rt5677_ib45_bypass_src_mux = 1339static const struct snd_kcontrol_new rt5677_ib45_bypass_src_mux =
1087 SOC_DAPM_ENUM("IB45 Bypass Source", rt5677_ib45_bypass_src_enum); 1340 SOC_DAPM_ENUM("IB45 Bypass Source", rt5677_ib45_bypass_src_enum);
1088 1341
1089/* Stereo ADC Source 2 */ /* MX-27 MX26 MX25 [11:10] */ 1342/* Stereo ADC Source 2 */ /* MX-27 MX26 MX25 [11:10] */
1090static const char * const rt5677_stereo_adc2_src[] = { 1343static const char * const rt5677_stereo_adc2_src[] = {
1091 "DD MIX1", "DMIC", "Stereo DAC MIX" 1344 "DD MIX1", "DMIC", "Stereo DAC MIX"
1092}; 1345};
@@ -1171,7 +1424,7 @@ static SOC_ENUM_SINGLE_DECL(
1171static const struct snd_kcontrol_new rt5677_sto2_adc_lr_mux = 1424static const struct snd_kcontrol_new rt5677_sto2_adc_lr_mux =
1172 SOC_DAPM_ENUM("Stereo2 ADC LR Source", rt5677_stereo2_adc_lr_enum); 1425 SOC_DAPM_ENUM("Stereo2 ADC LR Source", rt5677_stereo2_adc_lr_enum);
1173 1426
1174/* Stereo1 ADC Source 1 */ /* MX-27 MX26 MX25 [13:12] */ 1427/* Stereo1 ADC Source 1 */ /* MX-27 MX26 MX25 [13:12] */
1175static const char * const rt5677_stereo_adc1_src[] = { 1428static const char * const rt5677_stereo_adc1_src[] = {
1176 "DD MIX1", "ADC1/2", "Stereo DAC MIX" 1429 "DD MIX1", "ADC1/2", "Stereo DAC MIX"
1177}; 1430};
@@ -1443,7 +1696,7 @@ static SOC_ENUM_SINGLE_DECL(
1443static const struct snd_kcontrol_new rt5677_pdm2_r_mux = 1696static const struct snd_kcontrol_new rt5677_pdm2_r_mux =
1444 SOC_DAPM_ENUM("PDM2 Source", rt5677_pdm2_r_enum); 1697 SOC_DAPM_ENUM("PDM2 Source", rt5677_pdm2_r_enum);
1445 1698
1446/* TDM IF1/2 SLB ADC1 Data Selection */ /* MX-3C MX-41 [5:4] MX-08 [1:0]*/ 1699/* TDM IF1/2 SLB ADC1 Data Selection */ /* MX-3C MX-41 [5:4] MX-08 [1:0] */
1447static const char * const rt5677_if12_adc1_src[] = { 1700static const char * const rt5677_if12_adc1_src[] = {
1448 "STO1 ADC MIX", "OB01", "VAD ADC" 1701 "STO1 ADC MIX", "OB01", "VAD ADC"
1449}; 1702};
@@ -1521,7 +1774,7 @@ static SOC_ENUM_SINGLE_DECL(
1521static const struct snd_kcontrol_new rt5677_slb_adc3_mux = 1774static const struct snd_kcontrol_new rt5677_slb_adc3_mux =
1522 SOC_DAPM_ENUM("SLB ADC3 Source", rt5677_slb_adc3_enum); 1775 SOC_DAPM_ENUM("SLB ADC3 Source", rt5677_slb_adc3_enum);
1523 1776
1524/* TDM IF1/2 SLB ADC4 Data Selection */ /* MX-3C MX-41 [11:10] MX-08 [7:6] */ 1777/* TDM IF1/2 SLB ADC4 Data Selection */ /* MX-3C MX-41 [11:10] MX-08 [7:6] */
1525static const char * const rt5677_if12_adc4_src[] = { 1778static const char * const rt5677_if12_adc4_src[] = {
1526 "STO4 ADC MIX", "OB67", "OB01" 1779 "STO4 ADC MIX", "OB67", "OB01"
1527}; 1780};
@@ -1547,7 +1800,7 @@ static SOC_ENUM_SINGLE_DECL(
1547static const struct snd_kcontrol_new rt5677_slb_adc4_mux = 1800static const struct snd_kcontrol_new rt5677_slb_adc4_mux =
1548 SOC_DAPM_ENUM("SLB ADC4 Source", rt5677_slb_adc4_enum); 1801 SOC_DAPM_ENUM("SLB ADC4 Source", rt5677_slb_adc4_enum);
1549 1802
1550/* Interface3/4 ADC Data Input */ /* MX-2F [3:0] MX-30 [7:4]*/ 1803/* Interface3/4 ADC Data Input */ /* MX-2F [3:0] MX-30 [7:4] */
1551static const char * const rt5677_if34_adc_src[] = { 1804static const char * const rt5677_if34_adc_src[] = {
1552 "STO1 ADC MIX", "STO2 ADC MIX", "STO3 ADC MIX", "STO4 ADC MIX", 1805 "STO1 ADC MIX", "STO2 ADC MIX", "STO3 ADC MIX", "STO4 ADC MIX",
1553 "MONO ADC MIX", "OB01", "OB23", "VAD ADC" 1806 "MONO ADC MIX", "OB01", "OB23", "VAD ADC"
@@ -1567,6 +1820,213 @@ static SOC_ENUM_SINGLE_DECL(
1567static const struct snd_kcontrol_new rt5677_if4_adc_mux = 1820static const struct snd_kcontrol_new rt5677_if4_adc_mux =
1568 SOC_DAPM_ENUM("IF4 ADC Source", rt5677_if4_adc_enum); 1821 SOC_DAPM_ENUM("IF4 ADC Source", rt5677_if4_adc_enum);
1569 1822
1823/* TDM IF1/2 ADC Data Selection */ /* MX-3B MX-40 [7:6][5:4][3:2][1:0] */
1824static const char * const rt5677_if12_adc_swap_src[] = {
1825 "L/R", "R/L", "L/L", "R/R"
1826};
1827
1828static SOC_ENUM_SINGLE_DECL(
1829 rt5677_if1_adc1_swap_enum, RT5677_TDM1_CTRL1,
1830 RT5677_IF1_ADC1_SWAP_SFT, rt5677_if12_adc_swap_src);
1831
1832static const struct snd_kcontrol_new rt5677_if1_adc1_swap_mux =
1833 SOC_DAPM_ENUM("IF1 ADC1 Swap Source", rt5677_if1_adc1_swap_enum);
1834
1835static SOC_ENUM_SINGLE_DECL(
1836 rt5677_if1_adc2_swap_enum, RT5677_TDM1_CTRL1,
1837 RT5677_IF1_ADC2_SWAP_SFT, rt5677_if12_adc_swap_src);
1838
1839static const struct snd_kcontrol_new rt5677_if1_adc2_swap_mux =
1840 SOC_DAPM_ENUM("IF1 ADC2 Swap Source", rt5677_if1_adc2_swap_enum);
1841
1842static SOC_ENUM_SINGLE_DECL(
1843 rt5677_if1_adc3_swap_enum, RT5677_TDM1_CTRL1,
1844 RT5677_IF1_ADC3_SWAP_SFT, rt5677_if12_adc_swap_src);
1845
1846static const struct snd_kcontrol_new rt5677_if1_adc3_swap_mux =
1847 SOC_DAPM_ENUM("IF1 ADC3 Swap Source", rt5677_if1_adc3_swap_enum);
1848
1849static SOC_ENUM_SINGLE_DECL(
1850 rt5677_if1_adc4_swap_enum, RT5677_TDM1_CTRL1,
1851 RT5677_IF1_ADC4_SWAP_SFT, rt5677_if12_adc_swap_src);
1852
1853static const struct snd_kcontrol_new rt5677_if1_adc4_swap_mux =
1854 SOC_DAPM_ENUM("IF1 ADC4 Swap Source", rt5677_if1_adc4_swap_enum);
1855
1856static SOC_ENUM_SINGLE_DECL(
1857 rt5677_if2_adc1_swap_enum, RT5677_TDM2_CTRL1,
1858 RT5677_IF1_ADC2_SWAP_SFT, rt5677_if12_adc_swap_src);
1859
1860static const struct snd_kcontrol_new rt5677_if2_adc1_swap_mux =
1861 SOC_DAPM_ENUM("IF1 ADC2 Swap Source", rt5677_if2_adc1_swap_enum);
1862
1863static SOC_ENUM_SINGLE_DECL(
1864 rt5677_if2_adc2_swap_enum, RT5677_TDM2_CTRL1,
1865 RT5677_IF2_ADC2_SWAP_SFT, rt5677_if12_adc_swap_src);
1866
1867static const struct snd_kcontrol_new rt5677_if2_adc2_swap_mux =
1868 SOC_DAPM_ENUM("IF2 ADC2 Swap Source", rt5677_if2_adc2_swap_enum);
1869
1870static SOC_ENUM_SINGLE_DECL(
1871 rt5677_if2_adc3_swap_enum, RT5677_TDM2_CTRL1,
1872 RT5677_IF2_ADC3_SWAP_SFT, rt5677_if12_adc_swap_src);
1873
1874static const struct snd_kcontrol_new rt5677_if2_adc3_swap_mux =
1875 SOC_DAPM_ENUM("IF2 ADC3 Swap Source", rt5677_if2_adc3_swap_enum);
1876
1877static SOC_ENUM_SINGLE_DECL(
1878 rt5677_if2_adc4_swap_enum, RT5677_TDM2_CTRL1,
1879 RT5677_IF2_ADC4_SWAP_SFT, rt5677_if12_adc_swap_src);
1880
1881static const struct snd_kcontrol_new rt5677_if2_adc4_swap_mux =
1882 SOC_DAPM_ENUM("IF2 ADC4 Swap Source", rt5677_if2_adc4_swap_enum);
1883
1884/* TDM IF1 ADC Data Selection */ /* MX-3C [2:0] */
1885static const char * const rt5677_if1_adc_tdm_swap_src[] = {
1886 "1/2/3/4", "2/1/3/4", "2/3/1/4", "4/1/2/3", "1/3/2/4", "1/4/2/3",
1887 "3/1/2/4", "3/4/1/2"
1888};
1889
1890static SOC_ENUM_SINGLE_DECL(
1891 rt5677_if1_adc_tdm_swap_enum, RT5677_TDM1_CTRL2,
1892 RT5677_IF1_ADC_CTRL_SFT, rt5677_if1_adc_tdm_swap_src);
1893
1894static const struct snd_kcontrol_new rt5677_if1_adc_tdm_swap_mux =
1895 SOC_DAPM_ENUM("IF1 ADC TDM Swap Source", rt5677_if1_adc_tdm_swap_enum);
1896
1897/* TDM IF2 ADC Data Selection */ /* MX-41[2:0] */
1898static const char * const rt5677_if2_adc_tdm_swap_src[] = {
1899 "1/2/3/4", "2/1/3/4", "3/1/2/4", "4/1/2/3", "1/3/2/4", "1/4/2/3",
1900 "2/3/1/4", "3/4/1/2"
1901};
1902
1903static SOC_ENUM_SINGLE_DECL(
1904 rt5677_if2_adc_tdm_swap_enum, RT5677_TDM2_CTRL2,
1905 RT5677_IF2_ADC_CTRL_SFT, rt5677_if2_adc_tdm_swap_src);
1906
1907static const struct snd_kcontrol_new rt5677_if2_adc_tdm_swap_mux =
1908 SOC_DAPM_ENUM("IF2 ADC TDM Swap Source", rt5677_if2_adc_tdm_swap_enum);
1909
1910/* TDM IF1/2 DAC Data Selection */ /* MX-3E[14:12][10:8][6:4][2:0]
1911 MX-3F[14:12][10:8][6:4][2:0]
1912 MX-43[14:12][10:8][6:4][2:0]
1913 MX-44[14:12][10:8][6:4][2:0] */
1914static const char * const rt5677_if12_dac_tdm_sel_src[] = {
1915 "Slot0", "Slot1", "Slot2", "Slot3", "Slot4", "Slot5", "Slot6", "Slot7"
1916};
1917
1918static SOC_ENUM_SINGLE_DECL(
1919 rt5677_if1_dac0_tdm_sel_enum, RT5677_TDM1_CTRL4,
1920 RT5677_IF1_DAC0_SFT, rt5677_if12_dac_tdm_sel_src);
1921
1922static const struct snd_kcontrol_new rt5677_if1_dac0_tdm_sel_mux =
1923 SOC_DAPM_ENUM("IF1 DAC0 TDM Source", rt5677_if1_dac0_tdm_sel_enum);
1924
1925static SOC_ENUM_SINGLE_DECL(
1926 rt5677_if1_dac1_tdm_sel_enum, RT5677_TDM1_CTRL4,
1927 RT5677_IF1_DAC1_SFT, rt5677_if12_dac_tdm_sel_src);
1928
1929static const struct snd_kcontrol_new rt5677_if1_dac1_tdm_sel_mux =
1930 SOC_DAPM_ENUM("IF1 DAC1 TDM Source", rt5677_if1_dac1_tdm_sel_enum);
1931
1932static SOC_ENUM_SINGLE_DECL(
1933 rt5677_if1_dac2_tdm_sel_enum, RT5677_TDM1_CTRL4,
1934 RT5677_IF1_DAC2_SFT, rt5677_if12_dac_tdm_sel_src);
1935
1936static const struct snd_kcontrol_new rt5677_if1_dac2_tdm_sel_mux =
1937 SOC_DAPM_ENUM("IF1 DAC2 TDM Source", rt5677_if1_dac2_tdm_sel_enum);
1938
1939static SOC_ENUM_SINGLE_DECL(
1940 rt5677_if1_dac3_tdm_sel_enum, RT5677_TDM1_CTRL4,
1941 RT5677_IF1_DAC3_SFT, rt5677_if12_dac_tdm_sel_src);
1942
1943static const struct snd_kcontrol_new rt5677_if1_dac3_tdm_sel_mux =
1944 SOC_DAPM_ENUM("IF1 DAC3 TDM Source", rt5677_if1_dac3_tdm_sel_enum);
1945
1946static SOC_ENUM_SINGLE_DECL(
1947 rt5677_if1_dac4_tdm_sel_enum, RT5677_TDM1_CTRL5,
1948 RT5677_IF1_DAC4_SFT, rt5677_if12_dac_tdm_sel_src);
1949
1950static const struct snd_kcontrol_new rt5677_if1_dac4_tdm_sel_mux =
1951 SOC_DAPM_ENUM("IF1 DAC4 TDM Source", rt5677_if1_dac4_tdm_sel_enum);
1952
1953static SOC_ENUM_SINGLE_DECL(
1954 rt5677_if1_dac5_tdm_sel_enum, RT5677_TDM1_CTRL5,
1955 RT5677_IF1_DAC5_SFT, rt5677_if12_dac_tdm_sel_src);
1956
1957static const struct snd_kcontrol_new rt5677_if1_dac5_tdm_sel_mux =
1958 SOC_DAPM_ENUM("IF1 DAC5 TDM Source", rt5677_if1_dac5_tdm_sel_enum);
1959
1960static SOC_ENUM_SINGLE_DECL(
1961 rt5677_if1_dac6_tdm_sel_enum, RT5677_TDM1_CTRL5,
1962 RT5677_IF1_DAC6_SFT, rt5677_if12_dac_tdm_sel_src);
1963
1964static const struct snd_kcontrol_new rt5677_if1_dac6_tdm_sel_mux =
1965 SOC_DAPM_ENUM("IF1 DAC6 TDM Source", rt5677_if1_dac6_tdm_sel_enum);
1966
1967static SOC_ENUM_SINGLE_DECL(
1968 rt5677_if1_dac7_tdm_sel_enum, RT5677_TDM1_CTRL5,
1969 RT5677_IF1_DAC7_SFT, rt5677_if12_dac_tdm_sel_src);
1970
1971static const struct snd_kcontrol_new rt5677_if1_dac7_tdm_sel_mux =
1972 SOC_DAPM_ENUM("IF1 DAC7 TDM Source", rt5677_if1_dac7_tdm_sel_enum);
1973
1974static SOC_ENUM_SINGLE_DECL(
1975 rt5677_if2_dac0_tdm_sel_enum, RT5677_TDM2_CTRL4,
1976 RT5677_IF2_DAC0_SFT, rt5677_if12_dac_tdm_sel_src);
1977
1978static const struct snd_kcontrol_new rt5677_if2_dac0_tdm_sel_mux =
1979 SOC_DAPM_ENUM("IF2 DAC0 TDM Source", rt5677_if2_dac0_tdm_sel_enum);
1980
1981static SOC_ENUM_SINGLE_DECL(
1982 rt5677_if2_dac1_tdm_sel_enum, RT5677_TDM2_CTRL4,
1983 RT5677_IF2_DAC1_SFT, rt5677_if12_dac_tdm_sel_src);
1984
1985static const struct snd_kcontrol_new rt5677_if2_dac1_tdm_sel_mux =
1986 SOC_DAPM_ENUM("IF2 DAC1 TDM Source", rt5677_if2_dac1_tdm_sel_enum);
1987
1988static SOC_ENUM_SINGLE_DECL(
1989 rt5677_if2_dac2_tdm_sel_enum, RT5677_TDM2_CTRL4,
1990 RT5677_IF2_DAC2_SFT, rt5677_if12_dac_tdm_sel_src);
1991
1992static const struct snd_kcontrol_new rt5677_if2_dac2_tdm_sel_mux =
1993 SOC_DAPM_ENUM("IF2 DAC2 TDM Source", rt5677_if2_dac2_tdm_sel_enum);
1994
1995static SOC_ENUM_SINGLE_DECL(
1996 rt5677_if2_dac3_tdm_sel_enum, RT5677_TDM2_CTRL4,
1997 RT5677_IF2_DAC3_SFT, rt5677_if12_dac_tdm_sel_src);
1998
1999static const struct snd_kcontrol_new rt5677_if2_dac3_tdm_sel_mux =
2000 SOC_DAPM_ENUM("IF2 DAC3 TDM Source", rt5677_if2_dac3_tdm_sel_enum);
2001
2002static SOC_ENUM_SINGLE_DECL(
2003 rt5677_if2_dac4_tdm_sel_enum, RT5677_TDM2_CTRL5,
2004 RT5677_IF2_DAC4_SFT, rt5677_if12_dac_tdm_sel_src);
2005
2006static const struct snd_kcontrol_new rt5677_if2_dac4_tdm_sel_mux =
2007 SOC_DAPM_ENUM("IF2 DAC4 TDM Source", rt5677_if2_dac4_tdm_sel_enum);
2008
2009static SOC_ENUM_SINGLE_DECL(
2010 rt5677_if2_dac5_tdm_sel_enum, RT5677_TDM2_CTRL5,
2011 RT5677_IF2_DAC5_SFT, rt5677_if12_dac_tdm_sel_src);
2012
2013static const struct snd_kcontrol_new rt5677_if2_dac5_tdm_sel_mux =
2014 SOC_DAPM_ENUM("IF2 DAC5 TDM Source", rt5677_if2_dac5_tdm_sel_enum);
2015
2016static SOC_ENUM_SINGLE_DECL(
2017 rt5677_if2_dac6_tdm_sel_enum, RT5677_TDM2_CTRL5,
2018 RT5677_IF2_DAC6_SFT, rt5677_if12_dac_tdm_sel_src);
2019
2020static const struct snd_kcontrol_new rt5677_if2_dac6_tdm_sel_mux =
2021 SOC_DAPM_ENUM("IF2 DAC6 TDM Source", rt5677_if2_dac6_tdm_sel_enum);
2022
2023static SOC_ENUM_SINGLE_DECL(
2024 rt5677_if2_dac7_tdm_sel_enum, RT5677_TDM2_CTRL5,
2025 RT5677_IF2_DAC7_SFT, rt5677_if12_dac_tdm_sel_src);
2026
2027static const struct snd_kcontrol_new rt5677_if2_dac7_tdm_sel_mux =
2028 SOC_DAPM_ENUM("IF2 DAC7 TDM Source", rt5677_if2_dac7_tdm_sel_enum);
2029
1570static int rt5677_bst1_event(struct snd_soc_dapm_widget *w, 2030static int rt5677_bst1_event(struct snd_soc_dapm_widget *w,
1571 struct snd_kcontrol *kcontrol, int event) 2031 struct snd_kcontrol *kcontrol, int event)
1572{ 2032{
@@ -1678,6 +2138,77 @@ static int rt5677_set_micbias1_event(struct snd_soc_dapm_widget *w,
1678 return 0; 2138 return 0;
1679} 2139}
1680 2140
2141static int rt5677_if1_adc_tdm_event(struct snd_soc_dapm_widget *w,
2142 struct snd_kcontrol *kcontrol, int event)
2143{
2144 struct snd_soc_codec *codec = w->codec;
2145 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2146 unsigned int value;
2147
2148 switch (event) {
2149 case SND_SOC_DAPM_PRE_PMU:
2150 regmap_read(rt5677->regmap, RT5677_TDM1_CTRL2, &value);
2151 if (value & RT5677_IF1_ADC_CTRL_MASK)
2152 regmap_update_bits(rt5677->regmap, RT5677_TDM1_CTRL1,
2153 RT5677_IF1_ADC_MODE_MASK,
2154 RT5677_IF1_ADC_MODE_TDM);
2155 break;
2156
2157 default:
2158 return 0;
2159 }
2160
2161 return 0;
2162}
2163
2164static int rt5677_if2_adc_tdm_event(struct snd_soc_dapm_widget *w,
2165 struct snd_kcontrol *kcontrol, int event)
2166{
2167 struct snd_soc_codec *codec = w->codec;
2168 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2169 unsigned int value;
2170
2171 switch (event) {
2172 case SND_SOC_DAPM_PRE_PMU:
2173 regmap_read(rt5677->regmap, RT5677_TDM2_CTRL2, &value);
2174 if (value & RT5677_IF2_ADC_CTRL_MASK)
2175 regmap_update_bits(rt5677->regmap, RT5677_TDM2_CTRL1,
2176 RT5677_IF2_ADC_MODE_MASK,
2177 RT5677_IF2_ADC_MODE_TDM);
2178 break;
2179
2180 default:
2181 return 0;
2182 }
2183
2184 return 0;
2185}
2186
2187static int rt5677_vref_event(struct snd_soc_dapm_widget *w,
2188 struct snd_kcontrol *kcontrol, int event)
2189{
2190 struct snd_soc_codec *codec = w->codec;
2191 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2192
2193 switch (event) {
2194 case SND_SOC_DAPM_POST_PMU:
2195 if (codec->dapm.bias_level != SND_SOC_BIAS_ON &&
2196 !rt5677->is_vref_slow) {
2197 mdelay(20);
2198 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
2199 RT5677_PWR_FV1 | RT5677_PWR_FV2,
2200 RT5677_PWR_FV1 | RT5677_PWR_FV2);
2201 rt5677->is_vref_slow = true;
2202 }
2203 break;
2204
2205 default:
2206 return 0;
2207 }
2208
2209 return 0;
2210}
2211
1681static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = { 2212static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = {
1682 SND_SOC_DAPM_SUPPLY("PLL1", RT5677_PWR_ANLG2, RT5677_PWR_PLL1_BIT, 2213 SND_SOC_DAPM_SUPPLY("PLL1", RT5677_PWR_ANLG2, RT5677_PWR_PLL1_BIT,
1683 0, rt5677_set_pll1_event, SND_SOC_DAPM_POST_PMU), 2214 0, rt5677_set_pll1_event, SND_SOC_DAPM_POST_PMU),
@@ -1837,10 +2368,8 @@ static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = {
1837 SND_SOC_DAPM_PGA("Stereo4 ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 2368 SND_SOC_DAPM_PGA("Stereo4 ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
1838 SND_SOC_DAPM_PGA("Sto2 ADC LR MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 2369 SND_SOC_DAPM_PGA("Sto2 ADC LR MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
1839 SND_SOC_DAPM_PGA("Mono ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 2370 SND_SOC_DAPM_PGA("Mono ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
1840 SND_SOC_DAPM_PGA("IF1_ADC1", SND_SOC_NOPM, 0, 0, NULL, 0), 2371 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
1841 SND_SOC_DAPM_PGA("IF1_ADC2", SND_SOC_NOPM, 0, 0, NULL, 0), 2372 SND_SOC_DAPM_PGA("IF2 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
1842 SND_SOC_DAPM_PGA("IF1_ADC3", SND_SOC_NOPM, 0, 0, NULL, 0),
1843 SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM, 0, 0, NULL, 0),
1844 2373
1845 /* DSP */ 2374 /* DSP */
1846 SND_SOC_DAPM_MUX("IB9 Mux", SND_SOC_NOPM, 0, 0, 2375 SND_SOC_DAPM_MUX("IB9 Mux", SND_SOC_NOPM, 0, 0,
@@ -1963,6 +2492,17 @@ static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = {
1963 &rt5677_if1_adc3_mux), 2492 &rt5677_if1_adc3_mux),
1964 SND_SOC_DAPM_MUX("IF1 ADC4 Mux", SND_SOC_NOPM, 0, 0, 2493 SND_SOC_DAPM_MUX("IF1 ADC4 Mux", SND_SOC_NOPM, 0, 0,
1965 &rt5677_if1_adc4_mux), 2494 &rt5677_if1_adc4_mux),
2495 SND_SOC_DAPM_MUX("IF1 ADC1 Swap Mux", SND_SOC_NOPM, 0, 0,
2496 &rt5677_if1_adc1_swap_mux),
2497 SND_SOC_DAPM_MUX("IF1 ADC2 Swap Mux", SND_SOC_NOPM, 0, 0,
2498 &rt5677_if1_adc2_swap_mux),
2499 SND_SOC_DAPM_MUX("IF1 ADC3 Swap Mux", SND_SOC_NOPM, 0, 0,
2500 &rt5677_if1_adc3_swap_mux),
2501 SND_SOC_DAPM_MUX("IF1 ADC4 Swap Mux", SND_SOC_NOPM, 0, 0,
2502 &rt5677_if1_adc4_swap_mux),
2503 SND_SOC_DAPM_MUX_E("IF1 ADC TDM Swap Mux", SND_SOC_NOPM, 0, 0,
2504 &rt5677_if1_adc_tdm_swap_mux, rt5677_if1_adc_tdm_event,
2505 SND_SOC_DAPM_PRE_PMU),
1966 SND_SOC_DAPM_MUX("IF2 ADC1 Mux", SND_SOC_NOPM, 0, 0, 2506 SND_SOC_DAPM_MUX("IF2 ADC1 Mux", SND_SOC_NOPM, 0, 0,
1967 &rt5677_if2_adc1_mux), 2507 &rt5677_if2_adc1_mux),
1968 SND_SOC_DAPM_MUX("IF2 ADC2 Mux", SND_SOC_NOPM, 0, 0, 2508 SND_SOC_DAPM_MUX("IF2 ADC2 Mux", SND_SOC_NOPM, 0, 0,
@@ -1971,6 +2511,17 @@ static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = {
1971 &rt5677_if2_adc3_mux), 2511 &rt5677_if2_adc3_mux),
1972 SND_SOC_DAPM_MUX("IF2 ADC4 Mux", SND_SOC_NOPM, 0, 0, 2512 SND_SOC_DAPM_MUX("IF2 ADC4 Mux", SND_SOC_NOPM, 0, 0,
1973 &rt5677_if2_adc4_mux), 2513 &rt5677_if2_adc4_mux),
2514 SND_SOC_DAPM_MUX("IF2 ADC1 Swap Mux", SND_SOC_NOPM, 0, 0,
2515 &rt5677_if2_adc1_swap_mux),
2516 SND_SOC_DAPM_MUX("IF2 ADC2 Swap Mux", SND_SOC_NOPM, 0, 0,
2517 &rt5677_if2_adc2_swap_mux),
2518 SND_SOC_DAPM_MUX("IF2 ADC3 Swap Mux", SND_SOC_NOPM, 0, 0,
2519 &rt5677_if2_adc3_swap_mux),
2520 SND_SOC_DAPM_MUX("IF2 ADC4 Swap Mux", SND_SOC_NOPM, 0, 0,
2521 &rt5677_if2_adc4_swap_mux),
2522 SND_SOC_DAPM_MUX_E("IF2 ADC TDM Swap Mux", SND_SOC_NOPM, 0, 0,
2523 &rt5677_if2_adc_tdm_swap_mux, rt5677_if2_adc_tdm_event,
2524 SND_SOC_DAPM_PRE_PMU),
1974 SND_SOC_DAPM_MUX("IF3 ADC Mux", SND_SOC_NOPM, 0, 0, 2525 SND_SOC_DAPM_MUX("IF3 ADC Mux", SND_SOC_NOPM, 0, 0,
1975 &rt5677_if3_adc_mux), 2526 &rt5677_if3_adc_mux),
1976 SND_SOC_DAPM_MUX("IF4 ADC Mux", SND_SOC_NOPM, 0, 0, 2527 SND_SOC_DAPM_MUX("IF4 ADC Mux", SND_SOC_NOPM, 0, 0,
@@ -1984,6 +2535,40 @@ static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = {
1984 SND_SOC_DAPM_MUX("SLB ADC4 Mux", SND_SOC_NOPM, 0, 0, 2535 SND_SOC_DAPM_MUX("SLB ADC4 Mux", SND_SOC_NOPM, 0, 0,
1985 &rt5677_slb_adc4_mux), 2536 &rt5677_slb_adc4_mux),
1986 2537
2538 SND_SOC_DAPM_MUX("IF1 DAC0 Mux", SND_SOC_NOPM, 0, 0,
2539 &rt5677_if1_dac0_tdm_sel_mux),
2540 SND_SOC_DAPM_MUX("IF1 DAC1 Mux", SND_SOC_NOPM, 0, 0,
2541 &rt5677_if1_dac1_tdm_sel_mux),
2542 SND_SOC_DAPM_MUX("IF1 DAC2 Mux", SND_SOC_NOPM, 0, 0,
2543 &rt5677_if1_dac2_tdm_sel_mux),
2544 SND_SOC_DAPM_MUX("IF1 DAC3 Mux", SND_SOC_NOPM, 0, 0,
2545 &rt5677_if1_dac3_tdm_sel_mux),
2546 SND_SOC_DAPM_MUX("IF1 DAC4 Mux", SND_SOC_NOPM, 0, 0,
2547 &rt5677_if1_dac4_tdm_sel_mux),
2548 SND_SOC_DAPM_MUX("IF1 DAC5 Mux", SND_SOC_NOPM, 0, 0,
2549 &rt5677_if1_dac5_tdm_sel_mux),
2550 SND_SOC_DAPM_MUX("IF1 DAC6 Mux", SND_SOC_NOPM, 0, 0,
2551 &rt5677_if1_dac6_tdm_sel_mux),
2552 SND_SOC_DAPM_MUX("IF1 DAC7 Mux", SND_SOC_NOPM, 0, 0,
2553 &rt5677_if1_dac7_tdm_sel_mux),
2554
2555 SND_SOC_DAPM_MUX("IF2 DAC0 Mux", SND_SOC_NOPM, 0, 0,
2556 &rt5677_if2_dac0_tdm_sel_mux),
2557 SND_SOC_DAPM_MUX("IF2 DAC1 Mux", SND_SOC_NOPM, 0, 0,
2558 &rt5677_if2_dac1_tdm_sel_mux),
2559 SND_SOC_DAPM_MUX("IF2 DAC2 Mux", SND_SOC_NOPM, 0, 0,
2560 &rt5677_if2_dac2_tdm_sel_mux),
2561 SND_SOC_DAPM_MUX("IF2 DAC3 Mux", SND_SOC_NOPM, 0, 0,
2562 &rt5677_if2_dac3_tdm_sel_mux),
2563 SND_SOC_DAPM_MUX("IF2 DAC4 Mux", SND_SOC_NOPM, 0, 0,
2564 &rt5677_if2_dac4_tdm_sel_mux),
2565 SND_SOC_DAPM_MUX("IF2 DAC5 Mux", SND_SOC_NOPM, 0, 0,
2566 &rt5677_if2_dac5_tdm_sel_mux),
2567 SND_SOC_DAPM_MUX("IF2 DAC6 Mux", SND_SOC_NOPM, 0, 0,
2568 &rt5677_if2_dac6_tdm_sel_mux),
2569 SND_SOC_DAPM_MUX("IF2 DAC7 Mux", SND_SOC_NOPM, 0, 0,
2570 &rt5677_if2_dac7_tdm_sel_mux),
2571
1987 /* Audio Interface */ 2572 /* Audio Interface */
1988 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 2573 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1989 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0), 2574 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
@@ -2022,7 +2607,7 @@ static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = {
2022 rt5677_ob_7_mix, ARRAY_SIZE(rt5677_ob_7_mix)), 2607 rt5677_ob_7_mix, ARRAY_SIZE(rt5677_ob_7_mix)),
2023 2608
2024 /* Output Side */ 2609 /* Output Side */
2025 /* DAC mixer before sound effect */ 2610 /* DAC mixer before sound effect */
2026 SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM, 0, 0, 2611 SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM, 0, 0,
2027 rt5677_dac_l_mix, ARRAY_SIZE(rt5677_dac_l_mix)), 2612 rt5677_dac_l_mix, ARRAY_SIZE(rt5677_dac_l_mix)),
2028 SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM, 0, 0, 2613 SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM, 0, 0,
@@ -2109,13 +2694,20 @@ static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = {
2109 SND_SOC_DAPM_MUX("PDM2 R Mux", RT5677_PDM_OUT_CTRL, RT5677_M_PDM2_R_SFT, 2694 SND_SOC_DAPM_MUX("PDM2 R Mux", RT5677_PDM_OUT_CTRL, RT5677_M_PDM2_R_SFT,
2110 1, &rt5677_pdm2_r_mux), 2695 1, &rt5677_pdm2_r_mux),
2111 2696
2112 SND_SOC_DAPM_PGA_S("LOUT1 amp", 1, RT5677_PWR_ANLG1, RT5677_PWR_LO1_BIT, 2697 SND_SOC_DAPM_PGA_S("LOUT1 amp", 0, RT5677_PWR_ANLG1, RT5677_PWR_LO1_BIT,
2113 0, NULL, 0), 2698 0, NULL, 0),
2114 SND_SOC_DAPM_PGA_S("LOUT2 amp", 1, RT5677_PWR_ANLG1, RT5677_PWR_LO2_BIT, 2699 SND_SOC_DAPM_PGA_S("LOUT2 amp", 0, RT5677_PWR_ANLG1, RT5677_PWR_LO2_BIT,
2115 0, NULL, 0), 2700 0, NULL, 0),
2116 SND_SOC_DAPM_PGA_S("LOUT3 amp", 1, RT5677_PWR_ANLG1, RT5677_PWR_LO3_BIT, 2701 SND_SOC_DAPM_PGA_S("LOUT3 amp", 0, RT5677_PWR_ANLG1, RT5677_PWR_LO3_BIT,
2117 0, NULL, 0), 2702 0, NULL, 0),
2118 2703
2704 SND_SOC_DAPM_PGA_S("LOUT1 vref", 1, SND_SOC_NOPM, 0, 0,
2705 rt5677_vref_event, SND_SOC_DAPM_POST_PMU),
2706 SND_SOC_DAPM_PGA_S("LOUT2 vref", 1, SND_SOC_NOPM, 0, 0,
2707 rt5677_vref_event, SND_SOC_DAPM_POST_PMU),
2708 SND_SOC_DAPM_PGA_S("LOUT3 vref", 1, SND_SOC_NOPM, 0, 0,
2709 rt5677_vref_event, SND_SOC_DAPM_POST_PMU),
2710
2119 /* Output Lines */ 2711 /* Output Lines */
2120 SND_SOC_DAPM_OUTPUT("LOUT1"), 2712 SND_SOC_DAPM_OUTPUT("LOUT1"),
2121 SND_SOC_DAPM_OUTPUT("LOUT2"), 2713 SND_SOC_DAPM_OUTPUT("LOUT2"),
@@ -2124,6 +2716,8 @@ static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = {
2124 SND_SOC_DAPM_OUTPUT("PDM1R"), 2716 SND_SOC_DAPM_OUTPUT("PDM1R"),
2125 SND_SOC_DAPM_OUTPUT("PDM2L"), 2717 SND_SOC_DAPM_OUTPUT("PDM2L"),
2126 SND_SOC_DAPM_OUTPUT("PDM2R"), 2718 SND_SOC_DAPM_OUTPUT("PDM2R"),
2719
2720 SND_SOC_DAPM_POST("vref", rt5677_vref_event),
2127}; 2721};
2128 2722
2129static const struct snd_soc_dapm_route rt5677_dapm_routes[] = { 2723static const struct snd_soc_dapm_route rt5677_dapm_routes[] = {
@@ -2354,11 +2948,42 @@ static const struct snd_soc_dapm_route rt5677_dapm_routes[] = {
2354 { "IF1 ADC4 Mux", "OB67", "OB67" }, 2948 { "IF1 ADC4 Mux", "OB67", "OB67" },
2355 { "IF1 ADC4 Mux", "OB01", "OB01 Bypass Mux" }, 2949 { "IF1 ADC4 Mux", "OB01", "OB01 Bypass Mux" },
2356 2950
2951 { "IF1 ADC1 Swap Mux", "L/R", "IF1 ADC1 Mux" },
2952 { "IF1 ADC1 Swap Mux", "R/L", "IF1 ADC1 Mux" },
2953 { "IF1 ADC1 Swap Mux", "L/L", "IF1 ADC1 Mux" },
2954 { "IF1 ADC1 Swap Mux", "R/R", "IF1 ADC1 Mux" },
2955
2956 { "IF1 ADC2 Swap Mux", "L/R", "IF1 ADC2 Mux" },
2957 { "IF1 ADC2 Swap Mux", "R/L", "IF1 ADC2 Mux" },
2958 { "IF1 ADC2 Swap Mux", "L/L", "IF1 ADC2 Mux" },
2959 { "IF1 ADC2 Swap Mux", "R/R", "IF1 ADC2 Mux" },
2960
2961 { "IF1 ADC3 Swap Mux", "L/R", "IF1 ADC3 Mux" },
2962 { "IF1 ADC3 Swap Mux", "R/L", "IF1 ADC3 Mux" },
2963 { "IF1 ADC3 Swap Mux", "L/L", "IF1 ADC3 Mux" },
2964 { "IF1 ADC3 Swap Mux", "R/R", "IF1 ADC3 Mux" },
2965
2966 { "IF1 ADC4 Swap Mux", "L/R", "IF1 ADC4 Mux" },
2967 { "IF1 ADC4 Swap Mux", "R/L", "IF1 ADC4 Mux" },
2968 { "IF1 ADC4 Swap Mux", "L/L", "IF1 ADC4 Mux" },
2969 { "IF1 ADC4 Swap Mux", "R/R", "IF1 ADC4 Mux" },
2970
2971 { "IF1 ADC", NULL, "IF1 ADC1 Swap Mux" },
2972 { "IF1 ADC", NULL, "IF1 ADC2 Swap Mux" },
2973 { "IF1 ADC", NULL, "IF1 ADC3 Swap Mux" },
2974 { "IF1 ADC", NULL, "IF1 ADC4 Swap Mux" },
2975
2976 { "IF1 ADC TDM Swap Mux", "1/2/3/4", "IF1 ADC" },
2977 { "IF1 ADC TDM Swap Mux", "2/1/3/4", "IF1 ADC" },
2978 { "IF1 ADC TDM Swap Mux", "2/3/1/4", "IF1 ADC" },
2979 { "IF1 ADC TDM Swap Mux", "4/1/2/3", "IF1 ADC" },
2980 { "IF1 ADC TDM Swap Mux", "1/3/2/4", "IF1 ADC" },
2981 { "IF1 ADC TDM Swap Mux", "1/4/2/3", "IF1 ADC" },
2982 { "IF1 ADC TDM Swap Mux", "3/1/2/4", "IF1 ADC" },
2983 { "IF1 ADC TDM Swap Mux", "3/4/1/2", "IF1 ADC" },
2984
2357 { "AIF1TX", NULL, "I2S1" }, 2985 { "AIF1TX", NULL, "I2S1" },
2358 { "AIF1TX", NULL, "IF1 ADC1 Mux" }, 2986 { "AIF1TX", NULL, "IF1 ADC TDM Swap Mux" },
2359 { "AIF1TX", NULL, "IF1 ADC2 Mux" },
2360 { "AIF1TX", NULL, "IF1 ADC3 Mux" },
2361 { "AIF1TX", NULL, "IF1 ADC4 Mux" },
2362 2987
2363 { "IF2 ADC1 Mux", "STO1 ADC MIX", "Stereo1 ADC MIX" }, 2988 { "IF2 ADC1 Mux", "STO1 ADC MIX", "Stereo1 ADC MIX" },
2364 { "IF2 ADC1 Mux", "OB01", "OB01 Bypass Mux" }, 2989 { "IF2 ADC1 Mux", "OB01", "OB01 Bypass Mux" },
@@ -2375,11 +3000,42 @@ static const struct snd_soc_dapm_route rt5677_dapm_routes[] = {
2375 { "IF2 ADC4 Mux", "OB67", "OB67" }, 3000 { "IF2 ADC4 Mux", "OB67", "OB67" },
2376 { "IF2 ADC4 Mux", "OB01", "OB01 Bypass Mux" }, 3001 { "IF2 ADC4 Mux", "OB01", "OB01 Bypass Mux" },
2377 3002
3003 { "IF2 ADC1 Swap Mux", "L/R", "IF2 ADC1 Mux" },
3004 { "IF2 ADC1 Swap Mux", "R/L", "IF2 ADC1 Mux" },
3005 { "IF2 ADC1 Swap Mux", "L/L", "IF2 ADC1 Mux" },
3006 { "IF2 ADC1 Swap Mux", "R/R", "IF2 ADC1 Mux" },
3007
3008 { "IF2 ADC2 Swap Mux", "L/R", "IF2 ADC2 Mux" },
3009 { "IF2 ADC2 Swap Mux", "R/L", "IF2 ADC2 Mux" },
3010 { "IF2 ADC2 Swap Mux", "L/L", "IF2 ADC2 Mux" },
3011 { "IF2 ADC2 Swap Mux", "R/R", "IF2 ADC2 Mux" },
3012
3013 { "IF2 ADC3 Swap Mux", "L/R", "IF2 ADC3 Mux" },
3014 { "IF2 ADC3 Swap Mux", "R/L", "IF2 ADC3 Mux" },
3015 { "IF2 ADC3 Swap Mux", "L/L", "IF2 ADC3 Mux" },
3016 { "IF2 ADC3 Swap Mux", "R/R", "IF2 ADC3 Mux" },
3017
3018 { "IF2 ADC4 Swap Mux", "L/R", "IF2 ADC4 Mux" },
3019 { "IF2 ADC4 Swap Mux", "R/L", "IF2 ADC4 Mux" },
3020 { "IF2 ADC4 Swap Mux", "L/L", "IF2 ADC4 Mux" },
3021 { "IF2 ADC4 Swap Mux", "R/R", "IF2 ADC4 Mux" },
3022
3023 { "IF2 ADC", NULL, "IF2 ADC1 Swap Mux" },
3024 { "IF2 ADC", NULL, "IF2 ADC2 Swap Mux" },
3025 { "IF2 ADC", NULL, "IF2 ADC3 Swap Mux" },
3026 { "IF2 ADC", NULL, "IF2 ADC4 Swap Mux" },
3027
3028 { "IF2 ADC TDM Swap Mux", "1/2/3/4", "IF2 ADC" },
3029 { "IF2 ADC TDM Swap Mux", "2/1/3/4", "IF2 ADC" },
3030 { "IF2 ADC TDM Swap Mux", "3/1/2/4", "IF2 ADC" },
3031 { "IF2 ADC TDM Swap Mux", "4/1/2/3", "IF2 ADC" },
3032 { "IF2 ADC TDM Swap Mux", "1/3/2/4", "IF2 ADC" },
3033 { "IF2 ADC TDM Swap Mux", "1/4/2/3", "IF2 ADC" },
3034 { "IF2 ADC TDM Swap Mux", "2/3/1/4", "IF2 ADC" },
3035 { "IF2 ADC TDM Swap Mux", "3/4/1/2", "IF2 ADC" },
3036
2378 { "AIF2TX", NULL, "I2S2" }, 3037 { "AIF2TX", NULL, "I2S2" },
2379 { "AIF2TX", NULL, "IF2 ADC1 Mux" }, 3038 { "AIF2TX", NULL, "IF2 ADC TDM Swap Mux" },
2380 { "AIF2TX", NULL, "IF2 ADC2 Mux" },
2381 { "AIF2TX", NULL, "IF2 ADC3 Mux" },
2382 { "AIF2TX", NULL, "IF2 ADC4 Mux" },
2383 3039
2384 { "IF3 ADC Mux", "STO1 ADC MIX", "Stereo1 ADC MIX" }, 3040 { "IF3 ADC Mux", "STO1 ADC MIX", "Stereo1 ADC MIX" },
2385 { "IF3 ADC Mux", "STO2 ADC MIX", "Stereo2 ADC MIX" }, 3041 { "IF3 ADC Mux", "STO2 ADC MIX", "Stereo2 ADC MIX" },
@@ -2569,14 +3225,86 @@ static const struct snd_soc_dapm_route rt5677_dapm_routes[] = {
2569 { "IF1 DAC6", NULL, "I2S1" }, 3225 { "IF1 DAC6", NULL, "I2S1" },
2570 { "IF1 DAC7", NULL, "I2S1" }, 3226 { "IF1 DAC7", NULL, "I2S1" },
2571 3227
2572 { "IF1 DAC01", NULL, "IF1 DAC0" }, 3228 { "IF1 DAC0 Mux", "Slot0", "IF1 DAC0" },
2573 { "IF1 DAC01", NULL, "IF1 DAC1" }, 3229 { "IF1 DAC0 Mux", "Slot1", "IF1 DAC1" },
2574 { "IF1 DAC23", NULL, "IF1 DAC2" }, 3230 { "IF1 DAC0 Mux", "Slot2", "IF1 DAC2" },
2575 { "IF1 DAC23", NULL, "IF1 DAC3" }, 3231 { "IF1 DAC0 Mux", "Slot3", "IF1 DAC3" },
2576 { "IF1 DAC45", NULL, "IF1 DAC4" }, 3232 { "IF1 DAC0 Mux", "Slot4", "IF1 DAC4" },
2577 { "IF1 DAC45", NULL, "IF1 DAC5" }, 3233 { "IF1 DAC0 Mux", "Slot5", "IF1 DAC5" },
2578 { "IF1 DAC67", NULL, "IF1 DAC6" }, 3234 { "IF1 DAC0 Mux", "Slot6", "IF1 DAC6" },
2579 { "IF1 DAC67", NULL, "IF1 DAC7" }, 3235 { "IF1 DAC0 Mux", "Slot7", "IF1 DAC7" },
3236
3237 { "IF1 DAC1 Mux", "Slot0", "IF1 DAC0" },
3238 { "IF1 DAC1 Mux", "Slot1", "IF1 DAC1" },
3239 { "IF1 DAC1 Mux", "Slot2", "IF1 DAC2" },
3240 { "IF1 DAC1 Mux", "Slot3", "IF1 DAC3" },
3241 { "IF1 DAC1 Mux", "Slot4", "IF1 DAC4" },
3242 { "IF1 DAC1 Mux", "Slot5", "IF1 DAC5" },
3243 { "IF1 DAC1 Mux", "Slot6", "IF1 DAC6" },
3244 { "IF1 DAC1 Mux", "Slot7", "IF1 DAC7" },
3245
3246 { "IF1 DAC2 Mux", "Slot0", "IF1 DAC0" },
3247 { "IF1 DAC2 Mux", "Slot1", "IF1 DAC1" },
3248 { "IF1 DAC2 Mux", "Slot2", "IF1 DAC2" },
3249 { "IF1 DAC2 Mux", "Slot3", "IF1 DAC3" },
3250 { "IF1 DAC2 Mux", "Slot4", "IF1 DAC4" },
3251 { "IF1 DAC2 Mux", "Slot5", "IF1 DAC5" },
3252 { "IF1 DAC2 Mux", "Slot6", "IF1 DAC6" },
3253 { "IF1 DAC2 Mux", "Slot7", "IF1 DAC7" },
3254
3255 { "IF1 DAC3 Mux", "Slot0", "IF1 DAC0" },
3256 { "IF1 DAC3 Mux", "Slot1", "IF1 DAC1" },
3257 { "IF1 DAC3 Mux", "Slot2", "IF1 DAC2" },
3258 { "IF1 DAC3 Mux", "Slot3", "IF1 DAC3" },
3259 { "IF1 DAC3 Mux", "Slot4", "IF1 DAC4" },
3260 { "IF1 DAC3 Mux", "Slot5", "IF1 DAC5" },
3261 { "IF1 DAC3 Mux", "Slot6", "IF1 DAC6" },
3262 { "IF1 DAC3 Mux", "Slot7", "IF1 DAC7" },
3263
3264 { "IF1 DAC4 Mux", "Slot0", "IF1 DAC0" },
3265 { "IF1 DAC4 Mux", "Slot1", "IF1 DAC1" },
3266 { "IF1 DAC4 Mux", "Slot2", "IF1 DAC2" },
3267 { "IF1 DAC4 Mux", "Slot3", "IF1 DAC3" },
3268 { "IF1 DAC4 Mux", "Slot4", "IF1 DAC4" },
3269 { "IF1 DAC4 Mux", "Slot5", "IF1 DAC5" },
3270 { "IF1 DAC4 Mux", "Slot6", "IF1 DAC6" },
3271 { "IF1 DAC4 Mux", "Slot7", "IF1 DAC7" },
3272
3273 { "IF1 DAC5 Mux", "Slot0", "IF1 DAC0" },
3274 { "IF1 DAC5 Mux", "Slot1", "IF1 DAC1" },
3275 { "IF1 DAC5 Mux", "Slot2", "IF1 DAC2" },
3276 { "IF1 DAC5 Mux", "Slot3", "IF1 DAC3" },
3277 { "IF1 DAC5 Mux", "Slot4", "IF1 DAC4" },
3278 { "IF1 DAC5 Mux", "Slot5", "IF1 DAC5" },
3279 { "IF1 DAC5 Mux", "Slot6", "IF1 DAC6" },
3280 { "IF1 DAC5 Mux", "Slot7", "IF1 DAC7" },
3281
3282 { "IF1 DAC6 Mux", "Slot0", "IF1 DAC0" },
3283 { "IF1 DAC6 Mux", "Slot1", "IF1 DAC1" },
3284 { "IF1 DAC6 Mux", "Slot2", "IF1 DAC2" },
3285 { "IF1 DAC6 Mux", "Slot3", "IF1 DAC3" },
3286 { "IF1 DAC6 Mux", "Slot4", "IF1 DAC4" },
3287 { "IF1 DAC6 Mux", "Slot5", "IF1 DAC5" },
3288 { "IF1 DAC6 Mux", "Slot6", "IF1 DAC6" },
3289 { "IF1 DAC6 Mux", "Slot7", "IF1 DAC7" },
3290
3291 { "IF1 DAC7 Mux", "Slot0", "IF1 DAC0" },
3292 { "IF1 DAC7 Mux", "Slot1", "IF1 DAC1" },
3293 { "IF1 DAC7 Mux", "Slot2", "IF1 DAC2" },
3294 { "IF1 DAC7 Mux", "Slot3", "IF1 DAC3" },
3295 { "IF1 DAC7 Mux", "Slot4", "IF1 DAC4" },
3296 { "IF1 DAC7 Mux", "Slot5", "IF1 DAC5" },
3297 { "IF1 DAC7 Mux", "Slot6", "IF1 DAC6" },
3298 { "IF1 DAC7 Mux", "Slot7", "IF1 DAC7" },
3299
3300 { "IF1 DAC01", NULL, "IF1 DAC0 Mux" },
3301 { "IF1 DAC01", NULL, "IF1 DAC1 Mux" },
3302 { "IF1 DAC23", NULL, "IF1 DAC2 Mux" },
3303 { "IF1 DAC23", NULL, "IF1 DAC3 Mux" },
3304 { "IF1 DAC45", NULL, "IF1 DAC4 Mux" },
3305 { "IF1 DAC45", NULL, "IF1 DAC5 Mux" },
3306 { "IF1 DAC67", NULL, "IF1 DAC6 Mux" },
3307 { "IF1 DAC67", NULL, "IF1 DAC7 Mux" },
2580 3308
2581 { "IF2 DAC0", NULL, "AIF2RX" }, 3309 { "IF2 DAC0", NULL, "AIF2RX" },
2582 { "IF2 DAC1", NULL, "AIF2RX" }, 3310 { "IF2 DAC1", NULL, "AIF2RX" },
@@ -2595,14 +3323,86 @@ static const struct snd_soc_dapm_route rt5677_dapm_routes[] = {
2595 { "IF2 DAC6", NULL, "I2S2" }, 3323 { "IF2 DAC6", NULL, "I2S2" },
2596 { "IF2 DAC7", NULL, "I2S2" }, 3324 { "IF2 DAC7", NULL, "I2S2" },
2597 3325
2598 { "IF2 DAC01", NULL, "IF2 DAC0" }, 3326 { "IF2 DAC0 Mux", "Slot0", "IF2 DAC0" },
2599 { "IF2 DAC01", NULL, "IF2 DAC1" }, 3327 { "IF2 DAC0 Mux", "Slot1", "IF2 DAC1" },
2600 { "IF2 DAC23", NULL, "IF2 DAC2" }, 3328 { "IF2 DAC0 Mux", "Slot2", "IF2 DAC2" },
2601 { "IF2 DAC23", NULL, "IF2 DAC3" }, 3329 { "IF2 DAC0 Mux", "Slot3", "IF2 DAC3" },
2602 { "IF2 DAC45", NULL, "IF2 DAC4" }, 3330 { "IF2 DAC0 Mux", "Slot4", "IF2 DAC4" },
2603 { "IF2 DAC45", NULL, "IF2 DAC5" }, 3331 { "IF2 DAC0 Mux", "Slot5", "IF2 DAC5" },
2604 { "IF2 DAC67", NULL, "IF2 DAC6" }, 3332 { "IF2 DAC0 Mux", "Slot6", "IF2 DAC6" },
2605 { "IF2 DAC67", NULL, "IF2 DAC7" }, 3333 { "IF2 DAC0 Mux", "Slot7", "IF2 DAC7" },
3334
3335 { "IF2 DAC1 Mux", "Slot0", "IF2 DAC0" },
3336 { "IF2 DAC1 Mux", "Slot1", "IF2 DAC1" },
3337 { "IF2 DAC1 Mux", "Slot2", "IF2 DAC2" },
3338 { "IF2 DAC1 Mux", "Slot3", "IF2 DAC3" },
3339 { "IF2 DAC1 Mux", "Slot4", "IF2 DAC4" },
3340 { "IF2 DAC1 Mux", "Slot5", "IF2 DAC5" },
3341 { "IF2 DAC1 Mux", "Slot6", "IF2 DAC6" },
3342 { "IF2 DAC1 Mux", "Slot7", "IF2 DAC7" },
3343
3344 { "IF2 DAC2 Mux", "Slot0", "IF2 DAC0" },
3345 { "IF2 DAC2 Mux", "Slot1", "IF2 DAC1" },
3346 { "IF2 DAC2 Mux", "Slot2", "IF2 DAC2" },
3347 { "IF2 DAC2 Mux", "Slot3", "IF2 DAC3" },
3348 { "IF2 DAC2 Mux", "Slot4", "IF2 DAC4" },
3349 { "IF2 DAC2 Mux", "Slot5", "IF2 DAC5" },
3350 { "IF2 DAC2 Mux", "Slot6", "IF2 DAC6" },
3351 { "IF2 DAC2 Mux", "Slot7", "IF2 DAC7" },
3352
3353 { "IF2 DAC3 Mux", "Slot0", "IF2 DAC0" },
3354 { "IF2 DAC3 Mux", "Slot1", "IF2 DAC1" },
3355 { "IF2 DAC3 Mux", "Slot2", "IF2 DAC2" },
3356 { "IF2 DAC3 Mux", "Slot3", "IF2 DAC3" },
3357 { "IF2 DAC3 Mux", "Slot4", "IF2 DAC4" },
3358 { "IF2 DAC3 Mux", "Slot5", "IF2 DAC5" },
3359 { "IF2 DAC3 Mux", "Slot6", "IF2 DAC6" },
3360 { "IF2 DAC3 Mux", "Slot7", "IF2 DAC7" },
3361
3362 { "IF2 DAC4 Mux", "Slot0", "IF2 DAC0" },
3363 { "IF2 DAC4 Mux", "Slot1", "IF2 DAC1" },
3364 { "IF2 DAC4 Mux", "Slot2", "IF2 DAC2" },
3365 { "IF2 DAC4 Mux", "Slot3", "IF2 DAC3" },
3366 { "IF2 DAC4 Mux", "Slot4", "IF2 DAC4" },
3367 { "IF2 DAC4 Mux", "Slot5", "IF2 DAC5" },
3368 { "IF2 DAC4 Mux", "Slot6", "IF2 DAC6" },
3369 { "IF2 DAC4 Mux", "Slot7", "IF2 DAC7" },
3370
3371 { "IF2 DAC5 Mux", "Slot0", "IF2 DAC0" },
3372 { "IF2 DAC5 Mux", "Slot1", "IF2 DAC1" },
3373 { "IF2 DAC5 Mux", "Slot2", "IF2 DAC2" },
3374 { "IF2 DAC5 Mux", "Slot3", "IF2 DAC3" },
3375 { "IF2 DAC5 Mux", "Slot4", "IF2 DAC4" },
3376 { "IF2 DAC5 Mux", "Slot5", "IF2 DAC5" },
3377 { "IF2 DAC5 Mux", "Slot6", "IF2 DAC6" },
3378 { "IF2 DAC5 Mux", "Slot7", "IF2 DAC7" },
3379
3380 { "IF2 DAC6 Mux", "Slot0", "IF2 DAC0" },
3381 { "IF2 DAC6 Mux", "Slot1", "IF2 DAC1" },
3382 { "IF2 DAC6 Mux", "Slot2", "IF2 DAC2" },
3383 { "IF2 DAC6 Mux", "Slot3", "IF2 DAC3" },
3384 { "IF2 DAC6 Mux", "Slot4", "IF2 DAC4" },
3385 { "IF2 DAC6 Mux", "Slot5", "IF2 DAC5" },
3386 { "IF2 DAC6 Mux", "Slot6", "IF2 DAC6" },
3387 { "IF2 DAC6 Mux", "Slot7", "IF2 DAC7" },
3388
3389 { "IF2 DAC7 Mux", "Slot0", "IF2 DAC0" },
3390 { "IF2 DAC7 Mux", "Slot1", "IF2 DAC1" },
3391 { "IF2 DAC7 Mux", "Slot2", "IF2 DAC2" },
3392 { "IF2 DAC7 Mux", "Slot3", "IF2 DAC3" },
3393 { "IF2 DAC7 Mux", "Slot4", "IF2 DAC4" },
3394 { "IF2 DAC7 Mux", "Slot5", "IF2 DAC5" },
3395 { "IF2 DAC7 Mux", "Slot6", "IF2 DAC6" },
3396 { "IF2 DAC7 Mux", "Slot7", "IF2 DAC7" },
3397
3398 { "IF2 DAC01", NULL, "IF2 DAC0 Mux" },
3399 { "IF2 DAC01", NULL, "IF2 DAC1 Mux" },
3400 { "IF2 DAC23", NULL, "IF2 DAC2 Mux" },
3401 { "IF2 DAC23", NULL, "IF2 DAC3 Mux" },
3402 { "IF2 DAC45", NULL, "IF2 DAC4 Mux" },
3403 { "IF2 DAC45", NULL, "IF2 DAC5 Mux" },
3404 { "IF2 DAC67", NULL, "IF2 DAC6 Mux" },
3405 { "IF2 DAC67", NULL, "IF2 DAC7 Mux" },
2606 3406
2607 { "IF3 DAC", NULL, "AIF3RX" }, 3407 { "IF3 DAC", NULL, "AIF3RX" },
2608 { "IF3 DAC", NULL, "I2S3" }, 3408 { "IF3 DAC", NULL, "I2S3" },
@@ -2806,9 +3606,13 @@ static const struct snd_soc_dapm_route rt5677_dapm_routes[] = {
2806 { "LOUT2 amp", NULL, "DAC 2" }, 3606 { "LOUT2 amp", NULL, "DAC 2" },
2807 { "LOUT3 amp", NULL, "DAC 3" }, 3607 { "LOUT3 amp", NULL, "DAC 3" },
2808 3608
2809 { "LOUT1", NULL, "LOUT1 amp" }, 3609 { "LOUT1 vref", NULL, "LOUT1 amp" },
2810 { "LOUT2", NULL, "LOUT2 amp" }, 3610 { "LOUT2 vref", NULL, "LOUT2 amp" },
2811 { "LOUT3", NULL, "LOUT3 amp" }, 3611 { "LOUT3 vref", NULL, "LOUT3 amp" },
3612
3613 { "LOUT1", NULL, "LOUT1 vref" },
3614 { "LOUT2", NULL, "LOUT2 vref" },
3615 { "LOUT3", NULL, "LOUT3 vref" },
2812 3616
2813 { "PDM1L", NULL, "PDM1 L Mux" }, 3617 { "PDM1L", NULL, "PDM1 L Mux" },
2814 { "PDM1R", NULL, "PDM1 R Mux" }, 3618 { "PDM1R", NULL, "PDM1 R Mux" },
@@ -2837,7 +3641,8 @@ static int rt5677_hw_params(struct snd_pcm_substream *substream,
2837 rt5677->lrck[dai->id] = params_rate(params); 3641 rt5677->lrck[dai->id] = params_rate(params);
2838 pre_div = rl6231_get_clk_info(rt5677->sysclk, rt5677->lrck[dai->id]); 3642 pre_div = rl6231_get_clk_info(rt5677->sysclk, rt5677->lrck[dai->id]);
2839 if (pre_div < 0) { 3643 if (pre_div < 0) {
2840 dev_err(codec->dev, "Unsupported clock setting\n"); 3644 dev_err(codec->dev, "Unsupported clock setting: sysclk=%dHz lrck=%dHz\n",
3645 rt5677->sysclk, rt5677->lrck[dai->id]);
2841 return -EINVAL; 3646 return -EINVAL;
2842 } 3647 }
2843 frame_size = snd_soc_params_to_frame_size(params); 3648 frame_size = snd_soc_params_to_frame_size(params);
@@ -3181,6 +3986,8 @@ static int rt5677_set_bias_level(struct snd_soc_codec *codec,
3181 3986
3182 case SND_SOC_BIAS_PREPARE: 3987 case SND_SOC_BIAS_PREPARE:
3183 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) { 3988 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
3989 rt5677_set_dsp_vad(codec, false);
3990
3184 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1, 3991 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
3185 RT5677_LDO1_SEL_MASK | RT5677_LDO2_SEL_MASK, 3992 RT5677_LDO1_SEL_MASK | RT5677_LDO2_SEL_MASK,
3186 0x0055); 3993 0x0055);
@@ -3188,14 +3995,12 @@ static int rt5677_set_bias_level(struct snd_soc_codec *codec,
3188 RT5677_PR_BASE + RT5677_BIAS_CUR4, 3995 RT5677_PR_BASE + RT5677_BIAS_CUR4,
3189 0x0f00, 0x0f00); 3996 0x0f00, 0x0f00);
3190 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1, 3997 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
3998 RT5677_PWR_FV1 | RT5677_PWR_FV2 |
3191 RT5677_PWR_VREF1 | RT5677_PWR_MB | 3999 RT5677_PWR_VREF1 | RT5677_PWR_MB |
3192 RT5677_PWR_BG | RT5677_PWR_VREF2, 4000 RT5677_PWR_BG | RT5677_PWR_VREF2,
3193 RT5677_PWR_VREF1 | RT5677_PWR_MB | 4001 RT5677_PWR_VREF1 | RT5677_PWR_MB |
3194 RT5677_PWR_BG | RT5677_PWR_VREF2); 4002 RT5677_PWR_BG | RT5677_PWR_VREF2);
3195 mdelay(20); 4003 rt5677->is_vref_slow = false;
3196 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
3197 RT5677_PWR_FV1 | RT5677_PWR_FV2,
3198 RT5677_PWR_FV1 | RT5677_PWR_FV2);
3199 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2, 4004 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2,
3200 RT5677_PWR_CORE, RT5677_PWR_CORE); 4005 RT5677_PWR_CORE, RT5677_PWR_CORE);
3201 regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 4006 regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC,
@@ -3214,6 +4019,9 @@ static int rt5677_set_bias_level(struct snd_soc_codec *codec,
3214 regmap_write(rt5677->regmap, RT5677_PWR_ANLG2, 0x0000); 4019 regmap_write(rt5677->regmap, RT5677_PWR_ANLG2, 0x0000);
3215 regmap_update_bits(rt5677->regmap, 4020 regmap_update_bits(rt5677->regmap,
3216 RT5677_PR_BASE + RT5677_BIAS_CUR4, 0x0f00, 0x0000); 4021 RT5677_PR_BASE + RT5677_BIAS_CUR4, 0x0f00, 0x0000);
4022
4023 if (rt5677->dsp_vad_en)
4024 rt5677_set_dsp_vad(codec, true);
3217 break; 4025 break;
3218 4026
3219 default: 4027 default:
@@ -3309,6 +4117,78 @@ static int rt5677_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
3309 return 0; 4117 return 0;
3310} 4118}
3311 4119
4120/** Configures the gpio as
4121 * 0 - floating
4122 * 1 - pull down
4123 * 2 - pull up
4124 */
4125static void rt5677_gpio_config(struct rt5677_priv *rt5677, unsigned offset,
4126 int value)
4127{
4128 int shift;
4129
4130 switch (offset) {
4131 case RT5677_GPIO1 ... RT5677_GPIO2:
4132 shift = 2 * (1 - offset);
4133 regmap_update_bits(rt5677->regmap,
4134 RT5677_PR_BASE + RT5677_DIG_IN_PIN_ST_CTRL2,
4135 0x3 << shift,
4136 (value & 0x3) << shift);
4137 break;
4138
4139 case RT5677_GPIO3 ... RT5677_GPIO6:
4140 shift = 2 * (9 - offset);
4141 regmap_update_bits(rt5677->regmap,
4142 RT5677_PR_BASE + RT5677_DIG_IN_PIN_ST_CTRL3,
4143 0x3 << shift,
4144 (value & 0x3) << shift);
4145 break;
4146
4147 default:
4148 break;
4149 }
4150}
4151
4152static int rt5677_to_irq(struct gpio_chip *chip, unsigned offset)
4153{
4154 struct rt5677_priv *rt5677 = gpio_to_rt5677(chip);
4155 struct regmap_irq_chip_data *data = rt5677->irq_data;
4156 int irq;
4157
4158 if (offset >= RT5677_GPIO1 && offset <= RT5677_GPIO3) {
4159 if ((rt5677->pdata.jd1_gpio == 1 && offset == RT5677_GPIO1) ||
4160 (rt5677->pdata.jd1_gpio == 2 &&
4161 offset == RT5677_GPIO2) ||
4162 (rt5677->pdata.jd1_gpio == 3 &&
4163 offset == RT5677_GPIO3)) {
4164 irq = RT5677_IRQ_JD1;
4165 } else {
4166 return -ENXIO;
4167 }
4168 }
4169
4170 if (offset >= RT5677_GPIO4 && offset <= RT5677_GPIO6) {
4171 if ((rt5677->pdata.jd2_gpio == 1 && offset == RT5677_GPIO4) ||
4172 (rt5677->pdata.jd2_gpio == 2 &&
4173 offset == RT5677_GPIO5) ||
4174 (rt5677->pdata.jd2_gpio == 3 &&
4175 offset == RT5677_GPIO6)) {
4176 irq = RT5677_IRQ_JD2;
4177 } else if ((rt5677->pdata.jd3_gpio == 1 &&
4178 offset == RT5677_GPIO4) ||
4179 (rt5677->pdata.jd3_gpio == 2 &&
4180 offset == RT5677_GPIO5) ||
4181 (rt5677->pdata.jd3_gpio == 3 &&
4182 offset == RT5677_GPIO6)) {
4183 irq = RT5677_IRQ_JD3;
4184 } else {
4185 return -ENXIO;
4186 }
4187 }
4188
4189 return regmap_irq_get_virq(data, irq);
4190}
4191
3312static struct gpio_chip rt5677_template_chip = { 4192static struct gpio_chip rt5677_template_chip = {
3313 .label = "rt5677", 4193 .label = "rt5677",
3314 .owner = THIS_MODULE, 4194 .owner = THIS_MODULE,
@@ -3316,6 +4196,7 @@ static struct gpio_chip rt5677_template_chip = {
3316 .set = rt5677_gpio_set, 4196 .set = rt5677_gpio_set,
3317 .direction_input = rt5677_gpio_direction_in, 4197 .direction_input = rt5677_gpio_direction_in,
3318 .get = rt5677_gpio_get, 4198 .get = rt5677_gpio_get,
4199 .to_irq = rt5677_to_irq,
3319 .can_sleep = 1, 4200 .can_sleep = 1,
3320}; 4201};
3321 4202
@@ -3341,6 +4222,11 @@ static void rt5677_free_gpio(struct i2c_client *i2c)
3341 gpiochip_remove(&rt5677->gpio_chip); 4222 gpiochip_remove(&rt5677->gpio_chip);
3342} 4223}
3343#else 4224#else
4225static void rt5677_gpio_config(struct rt5677_priv *rt5677, unsigned offset,
4226 int value)
4227{
4228}
4229
3344static void rt5677_init_gpio(struct i2c_client *i2c) 4230static void rt5677_init_gpio(struct i2c_client *i2c)
3345{ 4231{
3346} 4232}
@@ -3353,6 +4239,7 @@ static void rt5677_free_gpio(struct i2c_client *i2c)
3353static int rt5677_probe(struct snd_soc_codec *codec) 4239static int rt5677_probe(struct snd_soc_codec *codec)
3354{ 4240{
3355 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 4241 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
4242 int i;
3356 4243
3357 rt5677->codec = codec; 4244 rt5677->codec = codec;
3358 4245
@@ -3371,6 +4258,37 @@ static int rt5677_probe(struct snd_soc_codec *codec)
3371 regmap_write(rt5677->regmap, RT5677_DIG_MISC, 0x0020); 4258 regmap_write(rt5677->regmap, RT5677_DIG_MISC, 0x0020);
3372 regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x0c00); 4259 regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x0c00);
3373 4260
4261 for (i = 0; i < RT5677_GPIO_NUM; i++)
4262 rt5677_gpio_config(rt5677, i, rt5677->pdata.gpio_config[i]);
4263
4264 if (rt5677->irq_data) {
4265 regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1, 0x8000,
4266 0x8000);
4267 regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x0018,
4268 0x0008);
4269
4270 if (rt5677->pdata.jd1_gpio)
4271 regmap_update_bits(rt5677->regmap, RT5677_JD_CTRL1,
4272 RT5677_SEL_GPIO_JD1_MASK,
4273 rt5677->pdata.jd1_gpio <<
4274 RT5677_SEL_GPIO_JD1_SFT);
4275
4276 if (rt5677->pdata.jd2_gpio)
4277 regmap_update_bits(rt5677->regmap, RT5677_JD_CTRL1,
4278 RT5677_SEL_GPIO_JD2_MASK,
4279 rt5677->pdata.jd2_gpio <<
4280 RT5677_SEL_GPIO_JD2_SFT);
4281
4282 if (rt5677->pdata.jd3_gpio)
4283 regmap_update_bits(rt5677->regmap, RT5677_JD_CTRL1,
4284 RT5677_SEL_GPIO_JD3_MASK,
4285 rt5677->pdata.jd3_gpio <<
4286 RT5677_SEL_GPIO_JD3_SFT);
4287 }
4288
4289 mutex_init(&rt5677->dsp_cmd_lock);
4290 mutex_init(&rt5677->dsp_pri_lock);
4291
3374 return 0; 4292 return 0;
3375} 4293}
3376 4294
@@ -3390,8 +4308,11 @@ static int rt5677_suspend(struct snd_soc_codec *codec)
3390{ 4308{
3391 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 4309 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
3392 4310
3393 regcache_cache_only(rt5677->regmap, true); 4311 if (!rt5677->dsp_vad_en) {
3394 regcache_mark_dirty(rt5677->regmap); 4312 regcache_cache_only(rt5677->regmap, true);
4313 regcache_mark_dirty(rt5677->regmap);
4314 }
4315
3395 if (gpio_is_valid(rt5677->pow_ldo2)) 4316 if (gpio_is_valid(rt5677->pow_ldo2))
3396 gpio_set_value_cansleep(rt5677->pow_ldo2, 0); 4317 gpio_set_value_cansleep(rt5677->pow_ldo2, 0);
3397 4318
@@ -3406,8 +4327,11 @@ static int rt5677_resume(struct snd_soc_codec *codec)
3406 gpio_set_value_cansleep(rt5677->pow_ldo2, 1); 4327 gpio_set_value_cansleep(rt5677->pow_ldo2, 1);
3407 msleep(10); 4328 msleep(10);
3408 } 4329 }
3409 regcache_cache_only(rt5677->regmap, false); 4330
3410 regcache_sync(rt5677->regmap); 4331 if (!rt5677->dsp_vad_en) {
4332 regcache_cache_only(rt5677->regmap, false);
4333 regcache_sync(rt5677->regmap);
4334 }
3411 4335
3412 return 0; 4336 return 0;
3413} 4337}
@@ -3416,6 +4340,51 @@ static int rt5677_resume(struct snd_soc_codec *codec)
3416#define rt5677_resume NULL 4340#define rt5677_resume NULL
3417#endif 4341#endif
3418 4342
4343static int rt5677_read(void *context, unsigned int reg, unsigned int *val)
4344{
4345 struct i2c_client *client = context;
4346 struct rt5677_priv *rt5677 = i2c_get_clientdata(client);
4347
4348 if (rt5677->is_dsp_mode) {
4349 if (reg > 0xff) {
4350 mutex_lock(&rt5677->dsp_pri_lock);
4351 rt5677_dsp_mode_i2c_write(rt5677, RT5677_PRIV_INDEX,
4352 reg & 0xff);
4353 rt5677_dsp_mode_i2c_read(rt5677, RT5677_PRIV_DATA, val);
4354 mutex_unlock(&rt5677->dsp_pri_lock);
4355 } else {
4356 rt5677_dsp_mode_i2c_read(rt5677, reg, val);
4357 }
4358 } else {
4359 regmap_read(rt5677->regmap_physical, reg, val);
4360 }
4361
4362 return 0;
4363}
4364
4365static int rt5677_write(void *context, unsigned int reg, unsigned int val)
4366{
4367 struct i2c_client *client = context;
4368 struct rt5677_priv *rt5677 = i2c_get_clientdata(client);
4369
4370 if (rt5677->is_dsp_mode) {
4371 if (reg > 0xff) {
4372 mutex_lock(&rt5677->dsp_pri_lock);
4373 rt5677_dsp_mode_i2c_write(rt5677, RT5677_PRIV_INDEX,
4374 reg & 0xff);
4375 rt5677_dsp_mode_i2c_write(rt5677, RT5677_PRIV_DATA,
4376 val);
4377 mutex_unlock(&rt5677->dsp_pri_lock);
4378 } else {
4379 rt5677_dsp_mode_i2c_write(rt5677, reg, val);
4380 }
4381 } else {
4382 regmap_write(rt5677->regmap_physical, reg, val);
4383 }
4384
4385 return 0;
4386}
4387
3419#define RT5677_STEREO_RATES SNDRV_PCM_RATE_8000_96000 4388#define RT5677_STEREO_RATES SNDRV_PCM_RATE_8000_96000
3420#define RT5677_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 4389#define RT5677_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
3421 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 4390 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
@@ -3541,6 +4510,20 @@ static struct snd_soc_codec_driver soc_codec_dev_rt5677 = {
3541 .num_dapm_routes = ARRAY_SIZE(rt5677_dapm_routes), 4510 .num_dapm_routes = ARRAY_SIZE(rt5677_dapm_routes),
3542}; 4511};
3543 4512
4513static const struct regmap_config rt5677_regmap_physical = {
4514 .name = "physical",
4515 .reg_bits = 8,
4516 .val_bits = 16,
4517
4518 .max_register = RT5677_VENDOR_ID2 + 1 + (ARRAY_SIZE(rt5677_ranges) *
4519 RT5677_PR_SPACING),
4520 .readable_reg = rt5677_readable_register,
4521
4522 .cache_type = REGCACHE_NONE,
4523 .ranges = rt5677_ranges,
4524 .num_ranges = ARRAY_SIZE(rt5677_ranges),
4525};
4526
3544static const struct regmap_config rt5677_regmap = { 4527static const struct regmap_config rt5677_regmap = {
3545 .reg_bits = 8, 4528 .reg_bits = 8,
3546 .val_bits = 16, 4529 .val_bits = 16,
@@ -3550,6 +4533,8 @@ static const struct regmap_config rt5677_regmap = {
3550 4533
3551 .volatile_reg = rt5677_volatile_register, 4534 .volatile_reg = rt5677_volatile_register,
3552 .readable_reg = rt5677_readable_register, 4535 .readable_reg = rt5677_readable_register,
4536 .reg_read = rt5677_read,
4537 .reg_write = rt5677_write,
3553 4538
3554 .cache_type = REGCACHE_RBTREE, 4539 .cache_type = REGCACHE_RBTREE,
3555 .reg_defaults = rt5677_reg, 4540 .reg_defaults = rt5677_reg,
@@ -3590,9 +4575,77 @@ static int rt5677_parse_dt(struct rt5677_priv *rt5677, struct device_node *np)
3590 (rt5677->pow_ldo2 != -ENOENT)) 4575 (rt5677->pow_ldo2 != -ENOENT))
3591 return rt5677->pow_ldo2; 4576 return rt5677->pow_ldo2;
3592 4577
4578 of_property_read_u8_array(np, "realtek,gpio-config",
4579 rt5677->pdata.gpio_config, RT5677_GPIO_NUM);
4580
4581 of_property_read_u32(np, "realtek,jd1-gpio", &rt5677->pdata.jd1_gpio);
4582 of_property_read_u32(np, "realtek,jd2-gpio", &rt5677->pdata.jd2_gpio);
4583 of_property_read_u32(np, "realtek,jd3-gpio", &rt5677->pdata.jd3_gpio);
4584
4585 return 0;
4586}
4587
4588static struct regmap_irq rt5677_irqs[] = {
4589 [RT5677_IRQ_JD1] = {
4590 .reg_offset = 0,
4591 .mask = RT5677_EN_IRQ_GPIO_JD1,
4592 },
4593 [RT5677_IRQ_JD2] = {
4594 .reg_offset = 0,
4595 .mask = RT5677_EN_IRQ_GPIO_JD2,
4596 },
4597 [RT5677_IRQ_JD3] = {
4598 .reg_offset = 0,
4599 .mask = RT5677_EN_IRQ_GPIO_JD3,
4600 },
4601};
4602
4603static struct regmap_irq_chip rt5677_irq_chip = {
4604 .name = "rt5677",
4605 .irqs = rt5677_irqs,
4606 .num_irqs = ARRAY_SIZE(rt5677_irqs),
4607
4608 .num_regs = 1,
4609 .status_base = RT5677_IRQ_CTRL1,
4610 .mask_base = RT5677_IRQ_CTRL1,
4611 .mask_invert = 1,
4612};
4613
4614static int rt5677_init_irq(struct i2c_client *i2c)
4615{
4616 int ret;
4617 struct rt5677_priv *rt5677 = i2c_get_clientdata(i2c);
4618
4619 if (!rt5677->pdata.jd1_gpio &&
4620 !rt5677->pdata.jd2_gpio &&
4621 !rt5677->pdata.jd3_gpio)
4622 return 0;
4623
4624 if (!i2c->irq) {
4625 dev_err(&i2c->dev, "No interrupt specified\n");
4626 return -EINVAL;
4627 }
4628
4629 ret = regmap_add_irq_chip(rt5677->regmap, i2c->irq,
4630 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0,
4631 &rt5677_irq_chip, &rt5677->irq_data);
4632
4633 if (ret != 0) {
4634 dev_err(&i2c->dev, "Failed to register IRQ chip: %d\n", ret);
4635 return ret;
4636 }
4637
3593 return 0; 4638 return 0;
3594} 4639}
3595 4640
4641static void rt5677_free_irq(struct i2c_client *i2c)
4642{
4643 struct rt5677_priv *rt5677 = i2c_get_clientdata(i2c);
4644
4645 if (rt5677->irq_data)
4646 regmap_del_irq_chip(i2c->irq, rt5677->irq_data);
4647}
4648
3596static int rt5677_i2c_probe(struct i2c_client *i2c, 4649static int rt5677_i2c_probe(struct i2c_client *i2c,
3597 const struct i2c_device_id *id) 4650 const struct i2c_device_id *id)
3598{ 4651{
@@ -3638,7 +4691,16 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
3638 msleep(10); 4691 msleep(10);
3639 } 4692 }
3640 4693
3641 rt5677->regmap = devm_regmap_init_i2c(i2c, &rt5677_regmap); 4694 rt5677->regmap_physical = devm_regmap_init_i2c(i2c,
4695 &rt5677_regmap_physical);
4696 if (IS_ERR(rt5677->regmap_physical)) {
4697 ret = PTR_ERR(rt5677->regmap_physical);
4698 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
4699 ret);
4700 return ret;
4701 }
4702
4703 rt5677->regmap = devm_regmap_init(&i2c->dev, NULL, i2c, &rt5677_regmap);
3642 if (IS_ERR(rt5677->regmap)) { 4704 if (IS_ERR(rt5677->regmap)) {
3643 ret = PTR_ERR(rt5677->regmap); 4705 ret = PTR_ERR(rt5677->regmap);
3644 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 4706 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
@@ -3690,6 +4752,7 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
3690 } 4752 }
3691 4753
3692 rt5677_init_gpio(i2c); 4754 rt5677_init_gpio(i2c);
4755 rt5677_init_irq(i2c);
3693 4756
3694 return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5677, 4757 return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5677,
3695 rt5677_dai, ARRAY_SIZE(rt5677_dai)); 4758 rt5677_dai, ARRAY_SIZE(rt5677_dai));
@@ -3698,6 +4761,7 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
3698static int rt5677_i2c_remove(struct i2c_client *i2c) 4761static int rt5677_i2c_remove(struct i2c_client *i2c)
3699{ 4762{
3700 snd_soc_unregister_codec(&i2c->dev); 4763 snd_soc_unregister_codec(&i2c->dev);
4764 rt5677_free_irq(i2c);
3701 rt5677_free_gpio(i2c); 4765 rt5677_free_gpio(i2c);
3702 4766
3703 return 0; 4767 return 0;
diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h
index d4eb6d5e6746..c0a625f290cc 100644
--- a/sound/soc/codecs/rt5677.h
+++ b/sound/soc/codecs/rt5677.h
@@ -13,6 +13,7 @@
13#define __RT5677_H__ 13#define __RT5677_H__
14 14
15#include <sound/rt5677.h> 15#include <sound/rt5677.h>
16#include <linux/gpio/driver.h>
16 17
17/* Info */ 18/* Info */
18#define RT5677_RESET 0x00 19#define RT5677_RESET 0x00
@@ -305,10 +306,10 @@
305#define RT5677_R_MUTE_SFT 7 306#define RT5677_R_MUTE_SFT 7
306#define RT5677_VOL_R_MUTE (0x1 << 6) 307#define RT5677_VOL_R_MUTE (0x1 << 6)
307#define RT5677_VOL_R_SFT 6 308#define RT5677_VOL_R_SFT 6
308#define RT5677_L_VOL_MASK (0x3f << 8) 309#define RT5677_L_VOL_MASK (0x7f << 9)
309#define RT5677_L_VOL_SFT 8 310#define RT5677_L_VOL_SFT 9
310#define RT5677_R_VOL_MASK (0x3f) 311#define RT5677_R_VOL_MASK (0x7f << 1)
311#define RT5677_R_VOL_SFT 0 312#define RT5677_R_VOL_SFT 1
312 313
313/* LOUT1 Control (0x01) */ 314/* LOUT1 Control (0x01) */
314#define RT5677_LOUT1_L_MUTE (0x1 << 15) 315#define RT5677_LOUT1_L_MUTE (0x1 << 15)
@@ -446,16 +447,16 @@
446#define RT5677_SEL_DAC2_R_SRC_SFT 0 447#define RT5677_SEL_DAC2_R_SRC_SFT 0
447 448
448/* Stereo1 ADC Digital Volume Control (0x1c) */ 449/* Stereo1 ADC Digital Volume Control (0x1c) */
449#define RT5677_STO1_ADC_L_VOL_MASK (0x7f << 8) 450#define RT5677_STO1_ADC_L_VOL_MASK (0x3f << 9)
450#define RT5677_STO1_ADC_L_VOL_SFT 8 451#define RT5677_STO1_ADC_L_VOL_SFT 9
451#define RT5677_STO1_ADC_R_VOL_MASK (0x7f) 452#define RT5677_STO1_ADC_R_VOL_MASK (0x3f << 1)
452#define RT5677_STO1_ADC_R_VOL_SFT 0 453#define RT5677_STO1_ADC_R_VOL_SFT 1
453 454
454/* Mono ADC Digital Volume Control (0x1d) */ 455/* Mono ADC Digital Volume Control (0x1d) */
455#define RT5677_MONO_ADC_L_VOL_MASK (0x7f << 8) 456#define RT5677_MONO_ADC_L_VOL_MASK (0x3f << 9)
456#define RT5677_MONO_ADC_L_VOL_SFT 8 457#define RT5677_MONO_ADC_L_VOL_SFT 9
457#define RT5677_MONO_ADC_R_VOL_MASK (0x7f) 458#define RT5677_MONO_ADC_R_VOL_MASK (0x3f << 1)
458#define RT5677_MONO_ADC_R_VOL_SFT 0 459#define RT5677_MONO_ADC_R_VOL_SFT 1
459 460
460/* Stereo 1/2 ADC Boost Gain Control (0x1e) */ 461/* Stereo 1/2 ADC Boost Gain Control (0x1e) */
461#define RT5677_STO1_ADC_L_BST_MASK (0x3 << 14) 462#define RT5677_STO1_ADC_L_BST_MASK (0x3 << 14)
@@ -798,7 +799,21 @@
798#define RT5677_PDM2_I2C_EXE (0x1 << 1) 799#define RT5677_PDM2_I2C_EXE (0x1 << 1)
799#define RT5677_PDM2_I2C_BUSY (0x1 << 0) 800#define RT5677_PDM2_I2C_BUSY (0x1 << 0)
800 801
801/* MX3C TDM1 control 1 (0x3c) */ 802/* TDM1 control 1 (0x3b) */
803#define RT5677_IF1_ADC_MODE_MASK (0x1 << 12)
804#define RT5677_IF1_ADC_MODE_SFT 12
805#define RT5677_IF1_ADC_MODE_I2S (0x0 << 12)
806#define RT5677_IF1_ADC_MODE_TDM (0x1 << 12)
807#define RT5677_IF1_ADC1_SWAP_MASK (0x3 << 6)
808#define RT5677_IF1_ADC1_SWAP_SFT 6
809#define RT5677_IF1_ADC2_SWAP_MASK (0x3 << 4)
810#define RT5677_IF1_ADC2_SWAP_SFT 4
811#define RT5677_IF1_ADC3_SWAP_MASK (0x3 << 2)
812#define RT5677_IF1_ADC3_SWAP_SFT 2
813#define RT5677_IF1_ADC4_SWAP_MASK (0x3 << 0)
814#define RT5677_IF1_ADC4_SWAP_SFT 0
815
816/* TDM1 control 2 (0x3c) */
802#define RT5677_IF1_ADC4_MASK (0x3 << 10) 817#define RT5677_IF1_ADC4_MASK (0x3 << 10)
803#define RT5677_IF1_ADC4_SFT 10 818#define RT5677_IF1_ADC4_SFT 10
804#define RT5677_IF1_ADC3_MASK (0x3 << 8) 819#define RT5677_IF1_ADC3_MASK (0x3 << 8)
@@ -807,8 +822,44 @@
807#define RT5677_IF1_ADC2_SFT 6 822#define RT5677_IF1_ADC2_SFT 6
808#define RT5677_IF1_ADC1_MASK (0x3 << 4) 823#define RT5677_IF1_ADC1_MASK (0x3 << 4)
809#define RT5677_IF1_ADC1_SFT 4 824#define RT5677_IF1_ADC1_SFT 4
810 825#define RT5677_IF1_ADC_CTRL_MASK (0x7 << 0)
811/* MX41 TDM2 control 1 (0x41) */ 826#define RT5677_IF1_ADC_CTRL_SFT 0
827
828/* TDM1 control 4 (0x3e) */
829#define RT5677_IF1_DAC0_MASK (0x7 << 12)
830#define RT5677_IF1_DAC0_SFT 12
831#define RT5677_IF1_DAC1_MASK (0x7 << 8)
832#define RT5677_IF1_DAC1_SFT 8
833#define RT5677_IF1_DAC2_MASK (0x7 << 4)
834#define RT5677_IF1_DAC2_SFT 4
835#define RT5677_IF1_DAC3_MASK (0x7 << 0)
836#define RT5677_IF1_DAC3_SFT 0
837
838/* TDM1 control 5 (0x3f) */
839#define RT5677_IF1_DAC4_MASK (0x7 << 12)
840#define RT5677_IF1_DAC4_SFT 12
841#define RT5677_IF1_DAC5_MASK (0x7 << 8)
842#define RT5677_IF1_DAC5_SFT 8
843#define RT5677_IF1_DAC6_MASK (0x7 << 4)
844#define RT5677_IF1_DAC6_SFT 4
845#define RT5677_IF1_DAC7_MASK (0x7 << 0)
846#define RT5677_IF1_DAC7_SFT 0
847
848/* TDM2 control 1 (0x40) */
849#define RT5677_IF2_ADC_MODE_MASK (0x1 << 12)
850#define RT5677_IF2_ADC_MODE_SFT 12
851#define RT5677_IF2_ADC_MODE_I2S (0x0 << 12)
852#define RT5677_IF2_ADC_MODE_TDM (0x1 << 12)
853#define RT5677_IF2_ADC1_SWAP_MASK (0x3 << 6)
854#define RT5677_IF2_ADC1_SWAP_SFT 6
855#define RT5677_IF2_ADC2_SWAP_MASK (0x3 << 4)
856#define RT5677_IF2_ADC2_SWAP_SFT 4
857#define RT5677_IF2_ADC3_SWAP_MASK (0x3 << 2)
858#define RT5677_IF2_ADC3_SWAP_SFT 2
859#define RT5677_IF2_ADC4_SWAP_MASK (0x3 << 0)
860#define RT5677_IF2_ADC4_SWAP_SFT 0
861
862/* TDM2 control 2 (0x41) */
812#define RT5677_IF2_ADC4_MASK (0x3 << 10) 863#define RT5677_IF2_ADC4_MASK (0x3 << 10)
813#define RT5677_IF2_ADC4_SFT 10 864#define RT5677_IF2_ADC4_SFT 10
814#define RT5677_IF2_ADC3_MASK (0x3 << 8) 865#define RT5677_IF2_ADC3_MASK (0x3 << 8)
@@ -817,6 +868,28 @@
817#define RT5677_IF2_ADC2_SFT 6 868#define RT5677_IF2_ADC2_SFT 6
818#define RT5677_IF2_ADC1_MASK (0x3 << 4) 869#define RT5677_IF2_ADC1_MASK (0x3 << 4)
819#define RT5677_IF2_ADC1_SFT 4 870#define RT5677_IF2_ADC1_SFT 4
871#define RT5677_IF2_ADC_CTRL_MASK (0x7 << 0)
872#define RT5677_IF2_ADC_CTRL_SFT 0
873
874/* TDM2 control 4 (0x43) */
875#define RT5677_IF2_DAC0_MASK (0x7 << 12)
876#define RT5677_IF2_DAC0_SFT 12
877#define RT5677_IF2_DAC1_MASK (0x7 << 8)
878#define RT5677_IF2_DAC1_SFT 8
879#define RT5677_IF2_DAC2_MASK (0x7 << 4)
880#define RT5677_IF2_DAC2_SFT 4
881#define RT5677_IF2_DAC3_MASK (0x7 << 0)
882#define RT5677_IF2_DAC3_SFT 0
883
884/* TDM2 control 5 (0x44) */
885#define RT5677_IF2_DAC4_MASK (0x7 << 12)
886#define RT5677_IF2_DAC4_SFT 12
887#define RT5677_IF2_DAC5_MASK (0x7 << 8)
888#define RT5677_IF2_DAC5_SFT 8
889#define RT5677_IF2_DAC6_MASK (0x7 << 4)
890#define RT5677_IF2_DAC6_SFT 4
891#define RT5677_IF2_DAC7_MASK (0x7 << 0)
892#define RT5677_IF2_DAC7_SFT 0
820 893
821/* Digital Microphone Control 1 (0x50) */ 894/* Digital Microphone Control 1 (0x50) */
822#define RT5677_DMIC_1_EN_MASK (0x1 << 15) 895#define RT5677_DMIC_1_EN_MASK (0x1 << 15)
@@ -1367,6 +1440,48 @@
1367#define RT5677_SEL_SRC_IB01 (0x1 << 0) 1440#define RT5677_SEL_SRC_IB01 (0x1 << 0)
1368#define RT5677_SEL_SRC_IB01_SFT 0 1441#define RT5677_SEL_SRC_IB01_SFT 0
1369 1442
1443/* Jack Detect Control 1 (0xb5) */
1444#define RT5677_SEL_GPIO_JD1_MASK (0x3 << 14)
1445#define RT5677_SEL_GPIO_JD1_SFT 14
1446#define RT5677_SEL_GPIO_JD2_MASK (0x3 << 12)
1447#define RT5677_SEL_GPIO_JD2_SFT 12
1448#define RT5677_SEL_GPIO_JD3_MASK (0x3 << 10)
1449#define RT5677_SEL_GPIO_JD3_SFT 10
1450
1451/* IRQ Control 1 (0xbd) */
1452#define RT5677_STA_GPIO_JD1 (0x1 << 15)
1453#define RT5677_STA_GPIO_JD1_SFT 15
1454#define RT5677_EN_IRQ_GPIO_JD1 (0x1 << 14)
1455#define RT5677_EN_IRQ_GPIO_JD1_SFT 14
1456#define RT5677_EN_GPIO_JD1_STICKY (0x1 << 13)
1457#define RT5677_EN_GPIO_JD1_STICKY_SFT 13
1458#define RT5677_INV_GPIO_JD1 (0x1 << 12)
1459#define RT5677_INV_GPIO_JD1_SFT 12
1460#define RT5677_STA_GPIO_JD2 (0x1 << 11)
1461#define RT5677_STA_GPIO_JD2_SFT 11
1462#define RT5677_EN_IRQ_GPIO_JD2 (0x1 << 10)
1463#define RT5677_EN_IRQ_GPIO_JD2_SFT 10
1464#define RT5677_EN_GPIO_JD2_STICKY (0x1 << 9)
1465#define RT5677_EN_GPIO_JD2_STICKY_SFT 9
1466#define RT5677_INV_GPIO_JD2 (0x1 << 8)
1467#define RT5677_INV_GPIO_JD2_SFT 8
1468#define RT5677_STA_MICBIAS1_OVCD (0x1 << 7)
1469#define RT5677_STA_MICBIAS1_OVCD_SFT 7
1470#define RT5677_EN_IRQ_MICBIAS1_OVCD (0x1 << 6)
1471#define RT5677_EN_IRQ_MICBIAS1_OVCD_SFT 6
1472#define RT5677_EN_MICBIAS1_OVCD_STICKY (0x1 << 5)
1473#define RT5677_EN_MICBIAS1_OVCD_STICKY_SFT 5
1474#define RT5677_INV_MICBIAS1_OVCD (0x1 << 4)
1475#define RT5677_INV_MICBIAS1_OVCD_SFT 4
1476#define RT5677_STA_GPIO_JD3 (0x1 << 3)
1477#define RT5677_STA_GPIO_JD3_SFT 3
1478#define RT5677_EN_IRQ_GPIO_JD3 (0x1 << 2)
1479#define RT5677_EN_IRQ_GPIO_JD3_SFT 2
1480#define RT5677_EN_GPIO_JD3_STICKY (0x1 << 1)
1481#define RT5677_EN_GPIO_JD3_STICKY_SFT 1
1482#define RT5677_INV_GPIO_JD3 (0x1 << 0)
1483#define RT5677_INV_GPIO_JD3_SFT 0
1484
1370/* GPIO status (0xbf) */ 1485/* GPIO status (0xbf) */
1371#define RT5677_GPIO6_STATUS_MASK (0x1 << 5) 1486#define RT5677_GPIO6_STATUS_MASK (0x1 << 5)
1372#define RT5677_GPIO6_STATUS_SFT 5 1487#define RT5677_GPIO6_STATUS_SFT 5
@@ -1506,6 +1621,9 @@
1506#define RT5677_GPIO5_FUNC_GPIO (0x0 << 9) 1621#define RT5677_GPIO5_FUNC_GPIO (0x0 << 9)
1507#define RT5677_GPIO5_FUNC_DMIC (0x1 << 9) 1622#define RT5677_GPIO5_FUNC_DMIC (0x1 << 9)
1508 1623
1624#define RT5677_FIRMWARE1 "rt5677_dsp_fw1.bin"
1625#define RT5677_FIRMWARE2 "rt5677_dsp_fw2.bin"
1626
1509/* System Clock Source */ 1627/* System Clock Source */
1510enum { 1628enum {
1511 RT5677_SCLK_S_MCLK, 1629 RT5677_SCLK_S_MCLK,
@@ -1541,10 +1659,18 @@ enum {
1541 RT5677_GPIO_NUM, 1659 RT5677_GPIO_NUM,
1542}; 1660};
1543 1661
1662enum {
1663 RT5677_IRQ_JD1,
1664 RT5677_IRQ_JD2,
1665 RT5677_IRQ_JD3,
1666};
1667
1544struct rt5677_priv { 1668struct rt5677_priv {
1545 struct snd_soc_codec *codec; 1669 struct snd_soc_codec *codec;
1546 struct rt5677_platform_data pdata; 1670 struct rt5677_platform_data pdata;
1547 struct regmap *regmap; 1671 struct regmap *regmap, *regmap_physical;
1672 const struct firmware *fw1, *fw2;
1673 struct mutex dsp_cmd_lock, dsp_pri_lock;
1548 1674
1549 int sysclk; 1675 int sysclk;
1550 int sysclk_src; 1676 int sysclk_src;
@@ -1558,6 +1684,10 @@ struct rt5677_priv {
1558#ifdef CONFIG_GPIOLIB 1684#ifdef CONFIG_GPIOLIB
1559 struct gpio_chip gpio_chip; 1685 struct gpio_chip gpio_chip;
1560#endif 1686#endif
1687 bool dsp_vad_en;
1688 struct regmap_irq_chip_data *irq_data;
1689 bool is_dsp_mode;
1690 bool is_vref_slow;
1561}; 1691};
1562 1692
1563#endif /* __RT5677_H__ */ 1693#endif /* __RT5677_H__ */
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index dab9b15304af..29cf7ce610f4 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -16,6 +16,7 @@
16#include <linux/pm.h> 16#include <linux/pm.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/clk.h> 18#include <linux/clk.h>
19#include <linux/log2.h>
19#include <linux/regmap.h> 20#include <linux/regmap.h>
20#include <linux/regulator/driver.h> 21#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h> 22#include <linux/regulator/machine.h>
@@ -121,6 +122,13 @@ struct ldo_regulator {
121 bool enabled; 122 bool enabled;
122}; 123};
123 124
125enum sgtl5000_micbias_resistor {
126 SGTL5000_MICBIAS_OFF = 0,
127 SGTL5000_MICBIAS_2K = 2,
128 SGTL5000_MICBIAS_4K = 4,
129 SGTL5000_MICBIAS_8K = 8,
130};
131
124/* sgtl5000 private structure in codec */ 132/* sgtl5000 private structure in codec */
125struct sgtl5000_priv { 133struct sgtl5000_priv {
126 int sysclk; /* sysclk rate */ 134 int sysclk; /* sysclk rate */
@@ -131,6 +139,8 @@ struct sgtl5000_priv {
131 struct regmap *regmap; 139 struct regmap *regmap;
132 struct clk *mclk; 140 struct clk *mclk;
133 int revision; 141 int revision;
142 u8 micbias_resistor;
143 u8 micbias_voltage;
134}; 144};
135 145
136/* 146/*
@@ -145,12 +155,14 @@ struct sgtl5000_priv {
145static int mic_bias_event(struct snd_soc_dapm_widget *w, 155static int mic_bias_event(struct snd_soc_dapm_widget *w,
146 struct snd_kcontrol *kcontrol, int event) 156 struct snd_kcontrol *kcontrol, int event)
147{ 157{
158 struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(w->codec);
159
148 switch (event) { 160 switch (event) {
149 case SND_SOC_DAPM_POST_PMU: 161 case SND_SOC_DAPM_POST_PMU:
150 /* change mic bias resistor to 4Kohm */ 162 /* change mic bias resistor */
151 snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL, 163 snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL,
152 SGTL5000_BIAS_R_MASK, 164 SGTL5000_BIAS_R_MASK,
153 SGTL5000_BIAS_R_4k << SGTL5000_BIAS_R_SHIFT); 165 sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
154 break; 166 break;
155 167
156 case SND_SOC_DAPM_PRE_PMD: 168 case SND_SOC_DAPM_PRE_PMD:
@@ -530,16 +542,16 @@ static int sgtl5000_set_dai_sysclk(struct snd_soc_dai *codec_dai,
530 542
531/* 543/*
532 * set clock according to i2s frame clock, 544 * set clock according to i2s frame clock,
533 * sgtl5000 provide 2 clock sources. 545 * sgtl5000 provides 2 clock sources:
534 * 1. sys_mclk. sample freq can only configure to 546 * 1. sys_mclk: sample freq can only be configured to
535 * 1/256, 1/384, 1/512 of sys_mclk. 547 * 1/256, 1/384, 1/512 of sys_mclk.
536 * 2. pll. can derive any audio clocks. 548 * 2. pll: can derive any audio clocks.
537 * 549 *
538 * clock setting rules: 550 * clock setting rules:
539 * 1. in slave mode, only sys_mclk can use. 551 * 1. in slave mode, only sys_mclk can be used
540 * 2. as constraint by sys_mclk, sample freq should 552 * 2. as constraint by sys_mclk, sample freq should be set to 32 kHz, 44.1 kHz
541 * set to 32k, 44.1k and above. 553 * and above.
542 * 3. using sys_mclk prefer to pll to save power. 554 * 3. usage of sys_mclk is preferred over pll to save power.
543 */ 555 */
544static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate) 556static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate)
545{ 557{
@@ -549,8 +561,8 @@ static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate)
549 561
550 /* 562 /*
551 * sample freq should be divided by frame clock, 563 * sample freq should be divided by frame clock,
552 * if frame clock lower than 44.1khz, sample feq should set to 564 * if frame clock is lower than 44.1 kHz, sample freq should be set to
553 * 32khz or 44.1khz. 565 * 32 kHz or 44.1 kHz.
554 */ 566 */
555 switch (frame_rate) { 567 switch (frame_rate) {
556 case 8000: 568 case 8000:
@@ -603,9 +615,10 @@ static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate)
603 615
604 /* 616 /*
605 * calculate the divider of mclk/sample_freq, 617 * calculate the divider of mclk/sample_freq,
606 * factor of freq =96k can only be 256, since mclk in range (12m,27m) 618 * factor of freq = 96 kHz can only be 256, since mclk is in the range
619 * of 8 MHz - 27 MHz
607 */ 620 */
608 switch (sgtl5000->sysclk / sys_fs) { 621 switch (sgtl5000->sysclk / frame_rate) {
609 case 256: 622 case 256:
610 clk_ctl |= SGTL5000_MCLK_FREQ_256FS << 623 clk_ctl |= SGTL5000_MCLK_FREQ_256FS <<
611 SGTL5000_MCLK_FREQ_SHIFT; 624 SGTL5000_MCLK_FREQ_SHIFT;
@@ -619,7 +632,7 @@ static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate)
619 SGTL5000_MCLK_FREQ_SHIFT; 632 SGTL5000_MCLK_FREQ_SHIFT;
620 break; 633 break;
621 default: 634 default:
622 /* if mclk not satisify the divider, use pll */ 635 /* if mclk does not satisfy the divider, use pll */
623 if (sgtl5000->master) { 636 if (sgtl5000->master) {
624 clk_ctl |= SGTL5000_MCLK_FREQ_PLL << 637 clk_ctl |= SGTL5000_MCLK_FREQ_PLL <<
625 SGTL5000_MCLK_FREQ_SHIFT; 638 SGTL5000_MCLK_FREQ_SHIFT;
@@ -628,7 +641,7 @@ static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate)
628 "PLL not supported in slave mode\n"); 641 "PLL not supported in slave mode\n");
629 dev_err(codec->dev, "%d ratio is not supported. " 642 dev_err(codec->dev, "%d ratio is not supported. "
630 "SYS_MCLK needs to be 256, 384 or 512 * fs\n", 643 "SYS_MCLK needs to be 256, 384 or 512 * fs\n",
631 sgtl5000->sysclk / sys_fs); 644 sgtl5000->sysclk / frame_rate);
632 return -EINVAL; 645 return -EINVAL;
633 } 646 }
634 } 647 }
@@ -795,7 +808,7 @@ static int ldo_regulator_enable(struct regulator_dev *dev)
795 SGTL5000_LINEREG_D_POWERUP, 808 SGTL5000_LINEREG_D_POWERUP,
796 SGTL5000_LINEREG_D_POWERUP); 809 SGTL5000_LINEREG_D_POWERUP);
797 810
798 /* when internal ldo enabled, simple digital power can be disabled */ 811 /* when internal ldo is enabled, simple digital power can be disabled */
799 snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER, 812 snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
800 SGTL5000_LINREG_SIMPLE_POWERUP, 813 SGTL5000_LINREG_SIMPLE_POWERUP,
801 0); 814 0);
@@ -1079,7 +1092,7 @@ static bool sgtl5000_readable(struct device *dev, unsigned int reg)
1079/* 1092/*
1080 * sgtl5000 has 3 internal power supplies: 1093 * sgtl5000 has 3 internal power supplies:
1081 * 1. VAG, normally set to vdda/2 1094 * 1. VAG, normally set to vdda/2
1082 * 2. chargepump, set to different value 1095 * 2. charge pump, set to different value
1083 * according to voltage of vdda and vddio 1096 * according to voltage of vdda and vddio
1084 * 3. line out VAG, normally set to vddio/2 1097 * 3. line out VAG, normally set to vddio/2
1085 * 1098 *
@@ -1325,8 +1338,13 @@ static int sgtl5000_probe(struct snd_soc_codec *codec)
1325 SGTL5000_HP_ZCD_EN | 1338 SGTL5000_HP_ZCD_EN |
1326 SGTL5000_ADC_ZCD_EN); 1339 SGTL5000_ADC_ZCD_EN);
1327 1340
1328 snd_soc_write(codec, SGTL5000_CHIP_MIC_CTRL, 2); 1341 snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL,
1342 SGTL5000_BIAS_R_MASK,
1343 sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
1329 1344
1345 snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL,
1346 SGTL5000_BIAS_R_MASK,
1347 sgtl5000->micbias_voltage << SGTL5000_BIAS_R_SHIFT);
1330 /* 1348 /*
1331 * disable DAP 1349 * disable DAP
1332 * TODO: 1350 * TODO:
@@ -1416,10 +1434,10 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
1416{ 1434{
1417 struct sgtl5000_priv *sgtl5000; 1435 struct sgtl5000_priv *sgtl5000;
1418 int ret, reg, rev; 1436 int ret, reg, rev;
1419 unsigned int mclk; 1437 struct device_node *np = client->dev.of_node;
1438 u32 value;
1420 1439
1421 sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv), 1440 sgtl5000 = devm_kzalloc(&client->dev, sizeof(*sgtl5000), GFP_KERNEL);
1422 GFP_KERNEL);
1423 if (!sgtl5000) 1441 if (!sgtl5000)
1424 return -ENOMEM; 1442 return -ENOMEM;
1425 1443
@@ -1440,14 +1458,6 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
1440 return ret; 1458 return ret;
1441 } 1459 }
1442 1460
1443 /* SGTL5000 SYS_MCLK should be between 8 and 27 MHz */
1444 mclk = clk_get_rate(sgtl5000->mclk);
1445 if (mclk < 8000000 || mclk > 27000000) {
1446 dev_err(&client->dev, "Invalid SYS_CLK frequency: %u.%03uMHz\n",
1447 mclk / 1000000, mclk / 1000 % 1000);
1448 return -EINVAL;
1449 }
1450
1451 ret = clk_prepare_enable(sgtl5000->mclk); 1461 ret = clk_prepare_enable(sgtl5000->mclk);
1452 if (ret) 1462 if (ret)
1453 return ret; 1463 return ret;
@@ -1469,6 +1479,47 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
1469 dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev); 1479 dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev);
1470 sgtl5000->revision = rev; 1480 sgtl5000->revision = rev;
1471 1481
1482 if (np) {
1483 if (!of_property_read_u32(np,
1484 "micbias-resistor-k-ohms", &value)) {
1485 switch (value) {
1486 case SGTL5000_MICBIAS_OFF:
1487 sgtl5000->micbias_resistor = 0;
1488 break;
1489 case SGTL5000_MICBIAS_2K:
1490 sgtl5000->micbias_resistor = 1;
1491 break;
1492 case SGTL5000_MICBIAS_4K:
1493 sgtl5000->micbias_resistor = 2;
1494 break;
1495 case SGTL5000_MICBIAS_8K:
1496 sgtl5000->micbias_resistor = 3;
1497 break;
1498 default:
1499 sgtl5000->micbias_resistor = 2;
1500 dev_err(&client->dev,
1501 "Unsuitable MicBias resistor\n");
1502 }
1503 } else {
1504 /* default is 4Kohms */
1505 sgtl5000->micbias_resistor = 2;
1506 }
1507 if (!of_property_read_u32(np,
1508 "micbias-voltage-m-volts", &value)) {
1509 /* 1250mV => 0 */
1510 /* steps of 250mV */
1511 if ((value >= 1250) && (value <= 3000))
1512 sgtl5000->micbias_voltage = (value / 250) - 5;
1513 else {
1514 sgtl5000->micbias_voltage = 0;
1515 dev_err(&client->dev,
1516 "Unsuitable MicBias resistor\n");
1517 }
1518 } else {
1519 sgtl5000->micbias_voltage = 0;
1520 }
1521 }
1522
1472 i2c_set_clientdata(client, sgtl5000); 1523 i2c_set_clientdata(client, sgtl5000);
1473 1524
1474 /* Ensure sgtl5000 will start with sane register values */ 1525 /* Ensure sgtl5000 will start with sane register values */
diff --git a/sound/soc/codecs/sigmadsp-i2c.c b/sound/soc/codecs/sigmadsp-i2c.c
index 246081aae8ca..21ca3a5e9f66 100644
--- a/sound/soc/codecs/sigmadsp-i2c.c
+++ b/sound/soc/codecs/sigmadsp-i2c.c
@@ -6,29 +6,88 @@
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
8 8
9#include <linux/i2c.h>
10#include <linux/export.h> 9#include <linux/export.h>
10#include <linux/i2c.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/slab.h>
13#include <asm/unaligned.h>
12 14
13#include "sigmadsp.h" 15#include "sigmadsp.h"
14 16
15static int sigma_action_write_i2c(void *control_data, 17static int sigmadsp_write_i2c(void *control_data,
16 const struct sigma_action *sa, size_t len) 18 unsigned int addr, const uint8_t data[], size_t len)
19{
20 uint8_t *buf;
21 int ret;
22
23 buf = kzalloc(2 + len, GFP_KERNEL | GFP_DMA);
24 if (!buf)
25 return -ENOMEM;
26
27 put_unaligned_be16(addr, buf);
28 memcpy(buf + 2, data, len);
29
30 ret = i2c_master_send(control_data, buf, len + 2);
31
32 kfree(buf);
33
34 return ret;
35}
36
37static int sigmadsp_read_i2c(void *control_data,
38 unsigned int addr, uint8_t data[], size_t len)
17{ 39{
18 return i2c_master_send(control_data, (const unsigned char *)&sa->addr, 40 struct i2c_client *client = control_data;
19 len); 41 struct i2c_msg msgs[2];
42 uint8_t buf[2];
43 int ret;
44
45 put_unaligned_be16(addr, buf);
46
47 msgs[0].addr = client->addr;
48 msgs[0].len = sizeof(buf);
49 msgs[0].buf = buf;
50 msgs[0].flags = 0;
51
52 msgs[1].addr = client->addr;
53 msgs[1].len = len;
54 msgs[1].buf = data;
55 msgs[1].flags = I2C_M_RD;
56
57 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
58 if (ret < 0)
59 return ret;
60 else if (ret != ARRAY_SIZE(msgs))
61 return -EIO;
62 return 0;
20} 63}
21 64
22int process_sigma_firmware(struct i2c_client *client, const char *name) 65/**
66 * devm_sigmadsp_init_i2c() - Initialize SigmaDSP instance
67 * @client: The parent I2C device
68 * @ops: The sigmadsp_ops to use for this instance
69 * @firmware_name: Name of the firmware file to load
70 *
71 * Allocates a SigmaDSP instance and loads the specified firmware file.
72 *
73 * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
74 */
75struct sigmadsp *devm_sigmadsp_init_i2c(struct i2c_client *client,
76 const struct sigmadsp_ops *ops, const char *firmware_name)
23{ 77{
24 struct sigma_firmware ssfw; 78 struct sigmadsp *sigmadsp;
79
80 sigmadsp = devm_sigmadsp_init(&client->dev, ops, firmware_name);
81 if (IS_ERR(sigmadsp))
82 return sigmadsp;
25 83
26 ssfw.control_data = client; 84 sigmadsp->control_data = client;
27 ssfw.write = sigma_action_write_i2c; 85 sigmadsp->write = sigmadsp_write_i2c;
86 sigmadsp->read = sigmadsp_read_i2c;
28 87
29 return _process_sigma_firmware(&client->dev, &ssfw, name); 88 return sigmadsp;
30} 89}
31EXPORT_SYMBOL(process_sigma_firmware); 90EXPORT_SYMBOL_GPL(devm_sigmadsp_init_i2c);
32 91
33MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 92MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
34MODULE_DESCRIPTION("SigmaDSP I2C firmware loader"); 93MODULE_DESCRIPTION("SigmaDSP I2C firmware loader");
diff --git a/sound/soc/codecs/sigmadsp-regmap.c b/sound/soc/codecs/sigmadsp-regmap.c
index f78ed8d2cfb2..912861be5b87 100644
--- a/sound/soc/codecs/sigmadsp-regmap.c
+++ b/sound/soc/codecs/sigmadsp-regmap.c
@@ -12,24 +12,48 @@
12 12
13#include "sigmadsp.h" 13#include "sigmadsp.h"
14 14
15static int sigma_action_write_regmap(void *control_data, 15static int sigmadsp_write_regmap(void *control_data,
16 const struct sigma_action *sa, size_t len) 16 unsigned int addr, const uint8_t data[], size_t len)
17{ 17{
18 return regmap_raw_write(control_data, be16_to_cpu(sa->addr), 18 return regmap_raw_write(control_data, addr,
19 sa->payload, len - 2); 19 data, len);
20} 20}
21 21
22int process_sigma_firmware_regmap(struct device *dev, struct regmap *regmap, 22static int sigmadsp_read_regmap(void *control_data,
23 const char *name) 23 unsigned int addr, uint8_t data[], size_t len)
24{ 24{
25 struct sigma_firmware ssfw; 25 return regmap_raw_read(control_data, addr,
26 data, len);
27}
28
29/**
30 * devm_sigmadsp_init_i2c() - Initialize SigmaDSP instance
31 * @dev: The parent device
32 * @regmap: Regmap instance to use
33 * @ops: The sigmadsp_ops to use for this instance
34 * @firmware_name: Name of the firmware file to load
35 *
36 * Allocates a SigmaDSP instance and loads the specified firmware file.
37 *
38 * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
39 */
40struct sigmadsp *devm_sigmadsp_init_regmap(struct device *dev,
41 struct regmap *regmap, const struct sigmadsp_ops *ops,
42 const char *firmware_name)
43{
44 struct sigmadsp *sigmadsp;
45
46 sigmadsp = devm_sigmadsp_init(dev, ops, firmware_name);
47 if (IS_ERR(sigmadsp))
48 return sigmadsp;
26 49
27 ssfw.control_data = regmap; 50 sigmadsp->control_data = regmap;
28 ssfw.write = sigma_action_write_regmap; 51 sigmadsp->write = sigmadsp_write_regmap;
52 sigmadsp->read = sigmadsp_read_regmap;
29 53
30 return _process_sigma_firmware(dev, &ssfw, name); 54 return sigmadsp;
31} 55}
32EXPORT_SYMBOL(process_sigma_firmware_regmap); 56EXPORT_SYMBOL_GPL(devm_sigmadsp_init_regmap);
33 57
34MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 58MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
35MODULE_DESCRIPTION("SigmaDSP regmap firmware loader"); 59MODULE_DESCRIPTION("SigmaDSP regmap firmware loader");
diff --git a/sound/soc/codecs/sigmadsp.c b/sound/soc/codecs/sigmadsp.c
index f2de7e049bc6..d53680ac78e4 100644
--- a/sound/soc/codecs/sigmadsp.c
+++ b/sound/soc/codecs/sigmadsp.c
@@ -1,23 +1,74 @@
1/* 1/*
2 * Load Analog Devices SigmaStudio firmware files 2 * Load Analog Devices SigmaStudio firmware files
3 * 3 *
4 * Copyright 2009-2011 Analog Devices Inc. 4 * Copyright 2009-2014 Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
8 8
9#include <linux/crc32.h> 9#include <linux/crc32.h>
10#include <linux/delay.h>
11#include <linux/firmware.h> 10#include <linux/firmware.h>
12#include <linux/kernel.h> 11#include <linux/kernel.h>
13#include <linux/i2c.h> 12#include <linux/i2c.h>
14#include <linux/regmap.h> 13#include <linux/regmap.h>
15#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h>
16
17#include <sound/control.h>
18#include <sound/soc.h>
16 19
17#include "sigmadsp.h" 20#include "sigmadsp.h"
18 21
19#define SIGMA_MAGIC "ADISIGM" 22#define SIGMA_MAGIC "ADISIGM"
20 23
24#define SIGMA_FW_CHUNK_TYPE_DATA 0
25#define SIGMA_FW_CHUNK_TYPE_CONTROL 1
26#define SIGMA_FW_CHUNK_TYPE_SAMPLERATES 2
27
28struct sigmadsp_control {
29 struct list_head head;
30 uint32_t samplerates;
31 unsigned int addr;
32 unsigned int num_bytes;
33 const char *name;
34 struct snd_kcontrol *kcontrol;
35 bool cached;
36 uint8_t cache[];
37};
38
39struct sigmadsp_data {
40 struct list_head head;
41 uint32_t samplerates;
42 unsigned int addr;
43 unsigned int length;
44 uint8_t data[];
45};
46
47struct sigma_fw_chunk {
48 __le32 length;
49 __le32 tag;
50 __le32 samplerates;
51} __packed;
52
53struct sigma_fw_chunk_data {
54 struct sigma_fw_chunk chunk;
55 __le16 addr;
56 uint8_t data[];
57} __packed;
58
59struct sigma_fw_chunk_control {
60 struct sigma_fw_chunk chunk;
61 __le16 type;
62 __le16 addr;
63 __le16 num_bytes;
64 const char name[];
65} __packed;
66
67struct sigma_fw_chunk_samplerate {
68 struct sigma_fw_chunk chunk;
69 __le32 samplerates[];
70} __packed;
71
21struct sigma_firmware_header { 72struct sigma_firmware_header {
22 unsigned char magic[7]; 73 unsigned char magic[7];
23 u8 version; 74 u8 version;
@@ -28,12 +79,286 @@ enum {
28 SIGMA_ACTION_WRITEXBYTES = 0, 79 SIGMA_ACTION_WRITEXBYTES = 0,
29 SIGMA_ACTION_WRITESINGLE, 80 SIGMA_ACTION_WRITESINGLE,
30 SIGMA_ACTION_WRITESAFELOAD, 81 SIGMA_ACTION_WRITESAFELOAD,
31 SIGMA_ACTION_DELAY,
32 SIGMA_ACTION_PLLWAIT,
33 SIGMA_ACTION_NOOP,
34 SIGMA_ACTION_END, 82 SIGMA_ACTION_END,
35}; 83};
36 84
85struct sigma_action {
86 u8 instr;
87 u8 len_hi;
88 __le16 len;
89 __be16 addr;
90 unsigned char payload[];
91} __packed;
92
93static int sigmadsp_write(struct sigmadsp *sigmadsp, unsigned int addr,
94 const uint8_t data[], size_t len)
95{
96 return sigmadsp->write(sigmadsp->control_data, addr, data, len);
97}
98
99static int sigmadsp_read(struct sigmadsp *sigmadsp, unsigned int addr,
100 uint8_t data[], size_t len)
101{
102 return sigmadsp->read(sigmadsp->control_data, addr, data, len);
103}
104
105static int sigmadsp_ctrl_info(struct snd_kcontrol *kcontrol,
106 struct snd_ctl_elem_info *info)
107{
108 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
109
110 info->type = SNDRV_CTL_ELEM_TYPE_BYTES;
111 info->count = ctrl->num_bytes;
112
113 return 0;
114}
115
116static int sigmadsp_ctrl_write(struct sigmadsp *sigmadsp,
117 struct sigmadsp_control *ctrl, void *data)
118{
119 /* safeload loads up to 20 bytes in a atomic operation */
120 if (ctrl->num_bytes > 4 && ctrl->num_bytes <= 20 && sigmadsp->ops &&
121 sigmadsp->ops->safeload)
122 return sigmadsp->ops->safeload(sigmadsp, ctrl->addr, data,
123 ctrl->num_bytes);
124 else
125 return sigmadsp_write(sigmadsp, ctrl->addr, data,
126 ctrl->num_bytes);
127}
128
129static int sigmadsp_ctrl_put(struct snd_kcontrol *kcontrol,
130 struct snd_ctl_elem_value *ucontrol)
131{
132 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
133 struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
134 uint8_t *data;
135 int ret = 0;
136
137 mutex_lock(&sigmadsp->lock);
138
139 data = ucontrol->value.bytes.data;
140
141 if (!(kcontrol->vd[0].access & SNDRV_CTL_ELEM_ACCESS_INACTIVE))
142 ret = sigmadsp_ctrl_write(sigmadsp, ctrl, data);
143
144 if (ret == 0) {
145 memcpy(ctrl->cache, data, ctrl->num_bytes);
146 ctrl->cached = true;
147 }
148
149 mutex_unlock(&sigmadsp->lock);
150
151 return ret;
152}
153
154static int sigmadsp_ctrl_get(struct snd_kcontrol *kcontrol,
155 struct snd_ctl_elem_value *ucontrol)
156{
157 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
158 struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
159 int ret = 0;
160
161 mutex_lock(&sigmadsp->lock);
162
163 if (!ctrl->cached) {
164 ret = sigmadsp_read(sigmadsp, ctrl->addr, ctrl->cache,
165 ctrl->num_bytes);
166 }
167
168 if (ret == 0) {
169 ctrl->cached = true;
170 memcpy(ucontrol->value.bytes.data, ctrl->cache,
171 ctrl->num_bytes);
172 }
173
174 mutex_unlock(&sigmadsp->lock);
175
176 return ret;
177}
178
179static void sigmadsp_control_free(struct snd_kcontrol *kcontrol)
180{
181 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
182
183 ctrl->kcontrol = NULL;
184}
185
186static bool sigma_fw_validate_control_name(const char *name, unsigned int len)
187{
188 unsigned int i;
189
190 for (i = 0; i < len; i++) {
191 /* Normal ASCII characters are valid */
192 if (name[i] < ' ' || name[i] > '~')
193 return false;
194 }
195
196 return true;
197}
198
199static int sigma_fw_load_control(struct sigmadsp *sigmadsp,
200 const struct sigma_fw_chunk *chunk, unsigned int length)
201{
202 const struct sigma_fw_chunk_control *ctrl_chunk;
203 struct sigmadsp_control *ctrl;
204 unsigned int num_bytes;
205 size_t name_len;
206 char *name;
207 int ret;
208
209 if (length <= sizeof(*ctrl_chunk))
210 return -EINVAL;
211
212 ctrl_chunk = (const struct sigma_fw_chunk_control *)chunk;
213
214 name_len = length - sizeof(*ctrl_chunk);
215 if (name_len >= SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
216 name_len = SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1;
217
218 /* Make sure there are no non-displayable characaters in the string */
219 if (!sigma_fw_validate_control_name(ctrl_chunk->name, name_len))
220 return -EINVAL;
221
222 num_bytes = le16_to_cpu(ctrl_chunk->num_bytes);
223 ctrl = kzalloc(sizeof(*ctrl) + num_bytes, GFP_KERNEL);
224 if (!ctrl)
225 return -ENOMEM;
226
227 name = kzalloc(name_len + 1, GFP_KERNEL);
228 if (!name) {
229 ret = -ENOMEM;
230 goto err_free_ctrl;
231 }
232 memcpy(name, ctrl_chunk->name, name_len);
233 name[name_len] = '\0';
234 ctrl->name = name;
235
236 ctrl->addr = le16_to_cpu(ctrl_chunk->addr);
237 ctrl->num_bytes = num_bytes;
238 ctrl->samplerates = le32_to_cpu(chunk->samplerates);
239
240 list_add_tail(&ctrl->head, &sigmadsp->ctrl_list);
241
242 return 0;
243
244err_free_ctrl:
245 kfree(ctrl);
246
247 return ret;
248}
249
250static int sigma_fw_load_data(struct sigmadsp *sigmadsp,
251 const struct sigma_fw_chunk *chunk, unsigned int length)
252{
253 const struct sigma_fw_chunk_data *data_chunk;
254 struct sigmadsp_data *data;
255
256 if (length <= sizeof(*data_chunk))
257 return -EINVAL;
258
259 data_chunk = (struct sigma_fw_chunk_data *)chunk;
260
261 length -= sizeof(*data_chunk);
262
263 data = kzalloc(sizeof(*data) + length, GFP_KERNEL);
264 if (!data)
265 return -ENOMEM;
266
267 data->addr = le16_to_cpu(data_chunk->addr);
268 data->length = length;
269 data->samplerates = le32_to_cpu(chunk->samplerates);
270 memcpy(data->data, data_chunk->data, length);
271 list_add_tail(&data->head, &sigmadsp->data_list);
272
273 return 0;
274}
275
276static int sigma_fw_load_samplerates(struct sigmadsp *sigmadsp,
277 const struct sigma_fw_chunk *chunk, unsigned int length)
278{
279 const struct sigma_fw_chunk_samplerate *rate_chunk;
280 unsigned int num_rates;
281 unsigned int *rates;
282 unsigned int i;
283
284 rate_chunk = (const struct sigma_fw_chunk_samplerate *)chunk;
285
286 num_rates = (length - sizeof(*rate_chunk)) / sizeof(__le32);
287
288 if (num_rates > 32 || num_rates == 0)
289 return -EINVAL;
290
291 /* We only allow one samplerates block per file */
292 if (sigmadsp->rate_constraints.count)
293 return -EINVAL;
294
295 rates = kcalloc(num_rates, sizeof(*rates), GFP_KERNEL);
296 if (!rates)
297 return -ENOMEM;
298
299 for (i = 0; i < num_rates; i++)
300 rates[i] = le32_to_cpu(rate_chunk->samplerates[i]);
301
302 sigmadsp->rate_constraints.count = num_rates;
303 sigmadsp->rate_constraints.list = rates;
304
305 return 0;
306}
307
308static int sigmadsp_fw_load_v2(struct sigmadsp *sigmadsp,
309 const struct firmware *fw)
310{
311 struct sigma_fw_chunk *chunk;
312 unsigned int length, pos;
313 int ret;
314
315 /*
316 * Make sure that there is at least one chunk to avoid integer
317 * underflows later on. Empty firmware is still valid though.
318 */
319 if (fw->size < sizeof(*chunk) + sizeof(struct sigma_firmware_header))
320 return 0;
321
322 pos = sizeof(struct sigma_firmware_header);
323
324 while (pos < fw->size - sizeof(*chunk)) {
325 chunk = (struct sigma_fw_chunk *)(fw->data + pos);
326
327 length = le32_to_cpu(chunk->length);
328
329 if (length > fw->size - pos || length < sizeof(*chunk))
330 return -EINVAL;
331
332 switch (le32_to_cpu(chunk->tag)) {
333 case SIGMA_FW_CHUNK_TYPE_DATA:
334 ret = sigma_fw_load_data(sigmadsp, chunk, length);
335 break;
336 case SIGMA_FW_CHUNK_TYPE_CONTROL:
337 ret = sigma_fw_load_control(sigmadsp, chunk, length);
338 break;
339 case SIGMA_FW_CHUNK_TYPE_SAMPLERATES:
340 ret = sigma_fw_load_samplerates(sigmadsp, chunk, length);
341 break;
342 default:
343 dev_warn(sigmadsp->dev, "Unknown chunk type: %d\n",
344 chunk->tag);
345 ret = 0;
346 break;
347 }
348
349 if (ret)
350 return ret;
351
352 /*
353 * This can not overflow since if length is larger than the
354 * maximum firmware size (0x4000000) we'll error out earilier.
355 */
356 pos += ALIGN(length, sizeof(__le32));
357 }
358
359 return 0;
360}
361
37static inline u32 sigma_action_len(struct sigma_action *sa) 362static inline u32 sigma_action_len(struct sigma_action *sa)
38{ 363{
39 return (sa->len_hi << 16) | le16_to_cpu(sa->len); 364 return (sa->len_hi << 16) | le16_to_cpu(sa->len);
@@ -62,11 +387,11 @@ static size_t sigma_action_size(struct sigma_action *sa)
62 * Returns a negative error value in case of an error, 0 if processing of 387 * Returns a negative error value in case of an error, 0 if processing of
63 * the firmware should be stopped after this action, 1 otherwise. 388 * the firmware should be stopped after this action, 1 otherwise.
64 */ 389 */
65static int 390static int process_sigma_action(struct sigmadsp *sigmadsp,
66process_sigma_action(struct sigma_firmware *ssfw, struct sigma_action *sa) 391 struct sigma_action *sa)
67{ 392{
68 size_t len = sigma_action_len(sa); 393 size_t len = sigma_action_len(sa);
69 int ret; 394 struct sigmadsp_data *data;
70 395
71 pr_debug("%s: instr:%i addr:%#x len:%zu\n", __func__, 396 pr_debug("%s: instr:%i addr:%#x len:%zu\n", __func__,
72 sa->instr, sa->addr, len); 397 sa->instr, sa->addr, len);
@@ -75,13 +400,17 @@ process_sigma_action(struct sigma_firmware *ssfw, struct sigma_action *sa)
75 case SIGMA_ACTION_WRITEXBYTES: 400 case SIGMA_ACTION_WRITEXBYTES:
76 case SIGMA_ACTION_WRITESINGLE: 401 case SIGMA_ACTION_WRITESINGLE:
77 case SIGMA_ACTION_WRITESAFELOAD: 402 case SIGMA_ACTION_WRITESAFELOAD:
78 ret = ssfw->write(ssfw->control_data, sa, len); 403 if (len < 3)
79 if (ret < 0)
80 return -EINVAL; 404 return -EINVAL;
81 break; 405
82 case SIGMA_ACTION_DELAY: 406 data = kzalloc(sizeof(*data) + len - 2, GFP_KERNEL);
83 udelay(len); 407 if (!data)
84 len = 0; 408 return -ENOMEM;
409
410 data->addr = be16_to_cpu(sa->addr);
411 data->length = len - 2;
412 memcpy(data->data, sa->payload, data->length);
413 list_add_tail(&data->head, &sigmadsp->data_list);
85 break; 414 break;
86 case SIGMA_ACTION_END: 415 case SIGMA_ACTION_END:
87 return 0; 416 return 0;
@@ -92,22 +421,24 @@ process_sigma_action(struct sigma_firmware *ssfw, struct sigma_action *sa)
92 return 1; 421 return 1;
93} 422}
94 423
95static int 424static int sigmadsp_fw_load_v1(struct sigmadsp *sigmadsp,
96process_sigma_actions(struct sigma_firmware *ssfw) 425 const struct firmware *fw)
97{ 426{
98 struct sigma_action *sa; 427 struct sigma_action *sa;
99 size_t size; 428 size_t size, pos;
100 int ret; 429 int ret;
101 430
102 while (ssfw->pos + sizeof(*sa) <= ssfw->fw->size) { 431 pos = sizeof(struct sigma_firmware_header);
103 sa = (struct sigma_action *)(ssfw->fw->data + ssfw->pos); 432
433 while (pos + sizeof(*sa) <= fw->size) {
434 sa = (struct sigma_action *)(fw->data + pos);
104 435
105 size = sigma_action_size(sa); 436 size = sigma_action_size(sa);
106 ssfw->pos += size; 437 pos += size;
107 if (ssfw->pos > ssfw->fw->size || size == 0) 438 if (pos > fw->size || size == 0)
108 break; 439 break;
109 440
110 ret = process_sigma_action(ssfw, sa); 441 ret = process_sigma_action(sigmadsp, sa);
111 442
112 pr_debug("%s: action returned %i\n", __func__, ret); 443 pr_debug("%s: action returned %i\n", __func__, ret);
113 444
@@ -115,29 +446,47 @@ process_sigma_actions(struct sigma_firmware *ssfw)
115 return ret; 446 return ret;
116 } 447 }
117 448
118 if (ssfw->pos != ssfw->fw->size) 449 if (pos != fw->size)
119 return -EINVAL; 450 return -EINVAL;
120 451
121 return 0; 452 return 0;
122} 453}
123 454
124int _process_sigma_firmware(struct device *dev, 455static void sigmadsp_firmware_release(struct sigmadsp *sigmadsp)
125 struct sigma_firmware *ssfw, const char *name)
126{ 456{
127 int ret; 457 struct sigmadsp_control *ctrl, *_ctrl;
128 struct sigma_firmware_header *ssfw_head; 458 struct sigmadsp_data *data, *_data;
459
460 list_for_each_entry_safe(ctrl, _ctrl, &sigmadsp->ctrl_list, head) {
461 kfree(ctrl->name);
462 kfree(ctrl);
463 }
464
465 list_for_each_entry_safe(data, _data, &sigmadsp->data_list, head)
466 kfree(data);
467
468 INIT_LIST_HEAD(&sigmadsp->ctrl_list);
469 INIT_LIST_HEAD(&sigmadsp->data_list);
470}
471
472static void devm_sigmadsp_release(struct device *dev, void *res)
473{
474 sigmadsp_firmware_release((struct sigmadsp *)res);
475}
476
477static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
478{
479 const struct sigma_firmware_header *ssfw_head;
129 const struct firmware *fw; 480 const struct firmware *fw;
481 int ret;
130 u32 crc; 482 u32 crc;
131 483
132 pr_debug("%s: loading firmware %s\n", __func__, name);
133
134 /* first load the blob */ 484 /* first load the blob */
135 ret = request_firmware(&fw, name, dev); 485 ret = request_firmware(&fw, name, sigmadsp->dev);
136 if (ret) { 486 if (ret) {
137 pr_debug("%s: request_firmware() failed with %i\n", __func__, ret); 487 pr_debug("%s: request_firmware() failed with %i\n", __func__, ret);
138 return ret; 488 goto done;
139 } 489 }
140 ssfw->fw = fw;
141 490
142 /* then verify the header */ 491 /* then verify the header */
143 ret = -EINVAL; 492 ret = -EINVAL;
@@ -149,13 +498,13 @@ int _process_sigma_firmware(struct device *dev,
149 * overflows later in the loading process. 498 * overflows later in the loading process.
150 */ 499 */
151 if (fw->size < sizeof(*ssfw_head) || fw->size >= 0x4000000) { 500 if (fw->size < sizeof(*ssfw_head) || fw->size >= 0x4000000) {
152 dev_err(dev, "Failed to load firmware: Invalid size\n"); 501 dev_err(sigmadsp->dev, "Failed to load firmware: Invalid size\n");
153 goto done; 502 goto done;
154 } 503 }
155 504
156 ssfw_head = (void *)fw->data; 505 ssfw_head = (void *)fw->data;
157 if (memcmp(ssfw_head->magic, SIGMA_MAGIC, ARRAY_SIZE(ssfw_head->magic))) { 506 if (memcmp(ssfw_head->magic, SIGMA_MAGIC, ARRAY_SIZE(ssfw_head->magic))) {
158 dev_err(dev, "Failed to load firmware: Invalid magic\n"); 507 dev_err(sigmadsp->dev, "Failed to load firmware: Invalid magic\n");
159 goto done; 508 goto done;
160 } 509 }
161 510
@@ -163,23 +512,303 @@ int _process_sigma_firmware(struct device *dev,
163 fw->size - sizeof(*ssfw_head)); 512 fw->size - sizeof(*ssfw_head));
164 pr_debug("%s: crc=%x\n", __func__, crc); 513 pr_debug("%s: crc=%x\n", __func__, crc);
165 if (crc != le32_to_cpu(ssfw_head->crc)) { 514 if (crc != le32_to_cpu(ssfw_head->crc)) {
166 dev_err(dev, "Failed to load firmware: Wrong crc checksum: expected %x got %x\n", 515 dev_err(sigmadsp->dev, "Failed to load firmware: Wrong crc checksum: expected %x got %x\n",
167 le32_to_cpu(ssfw_head->crc), crc); 516 le32_to_cpu(ssfw_head->crc), crc);
168 goto done; 517 goto done;
169 } 518 }
170 519
171 ssfw->pos = sizeof(*ssfw_head); 520 switch (ssfw_head->version) {
521 case 1:
522 ret = sigmadsp_fw_load_v1(sigmadsp, fw);
523 break;
524 case 2:
525 ret = sigmadsp_fw_load_v2(sigmadsp, fw);
526 break;
527 default:
528 dev_err(sigmadsp->dev,
529 "Failed to load firmware: Invalid version %d. Supported firmware versions: 1, 2\n",
530 ssfw_head->version);
531 ret = -EINVAL;
532 break;
533 }
172 534
173 /* finally process all of the actions */ 535 if (ret)
174 ret = process_sigma_actions(ssfw); 536 sigmadsp_firmware_release(sigmadsp);
175 537
176 done: 538done:
177 release_firmware(fw); 539 release_firmware(fw);
178 540
179 pr_debug("%s: loaded %s\n", __func__, name); 541 return ret;
542}
543
544static int sigmadsp_init(struct sigmadsp *sigmadsp, struct device *dev,
545 const struct sigmadsp_ops *ops, const char *firmware_name)
546{
547 sigmadsp->ops = ops;
548 sigmadsp->dev = dev;
549
550 INIT_LIST_HEAD(&sigmadsp->ctrl_list);
551 INIT_LIST_HEAD(&sigmadsp->data_list);
552 mutex_init(&sigmadsp->lock);
553
554 return sigmadsp_firmware_load(sigmadsp, firmware_name);
555}
556
557/**
558 * devm_sigmadsp_init() - Initialize SigmaDSP instance
559 * @dev: The parent device
560 * @ops: The sigmadsp_ops to use for this instance
561 * @firmware_name: Name of the firmware file to load
562 *
563 * Allocates a SigmaDSP instance and loads the specified firmware file.
564 *
565 * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
566 */
567struct sigmadsp *devm_sigmadsp_init(struct device *dev,
568 const struct sigmadsp_ops *ops, const char *firmware_name)
569{
570 struct sigmadsp *sigmadsp;
571 int ret;
572
573 sigmadsp = devres_alloc(devm_sigmadsp_release, sizeof(*sigmadsp),
574 GFP_KERNEL);
575 if (!sigmadsp)
576 return ERR_PTR(-ENOMEM);
577
578 ret = sigmadsp_init(sigmadsp, dev, ops, firmware_name);
579 if (ret) {
580 devres_free(sigmadsp);
581 return ERR_PTR(ret);
582 }
583
584 devres_add(dev, sigmadsp);
585
586 return sigmadsp;
587}
588EXPORT_SYMBOL_GPL(devm_sigmadsp_init);
589
590static int sigmadsp_rate_to_index(struct sigmadsp *sigmadsp, unsigned int rate)
591{
592 unsigned int i;
593
594 for (i = 0; i < sigmadsp->rate_constraints.count; i++) {
595 if (sigmadsp->rate_constraints.list[i] == rate)
596 return i;
597 }
598
599 return -EINVAL;
600}
601
602static unsigned int sigmadsp_get_samplerate_mask(struct sigmadsp *sigmadsp,
603 unsigned int samplerate)
604{
605 int samplerate_index;
606
607 if (samplerate == 0)
608 return 0;
609
610 if (sigmadsp->rate_constraints.count) {
611 samplerate_index = sigmadsp_rate_to_index(sigmadsp, samplerate);
612 if (samplerate_index < 0)
613 return 0;
614
615 return BIT(samplerate_index);
616 } else {
617 return ~0;
618 }
619}
620
621static bool sigmadsp_samplerate_valid(unsigned int supported,
622 unsigned int requested)
623{
624 /* All samplerates are supported */
625 if (!supported)
626 return true;
627
628 return supported & requested;
629}
630
631static int sigmadsp_alloc_control(struct sigmadsp *sigmadsp,
632 struct sigmadsp_control *ctrl, unsigned int samplerate_mask)
633{
634 struct snd_kcontrol_new template;
635 struct snd_kcontrol *kcontrol;
636
637 memset(&template, 0, sizeof(template));
638 template.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
639 template.name = ctrl->name;
640 template.info = sigmadsp_ctrl_info;
641 template.get = sigmadsp_ctrl_get;
642 template.put = sigmadsp_ctrl_put;
643 template.private_value = (unsigned long)ctrl;
644 template.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
645 if (!sigmadsp_samplerate_valid(ctrl->samplerates, samplerate_mask))
646 template.access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
647
648 kcontrol = snd_ctl_new1(&template, sigmadsp);
649 if (!kcontrol)
650 return -ENOMEM;
651
652 kcontrol->private_free = sigmadsp_control_free;
653 ctrl->kcontrol = kcontrol;
654
655 return snd_ctl_add(sigmadsp->component->card->snd_card, kcontrol);
656}
657
658static void sigmadsp_activate_ctrl(struct sigmadsp *sigmadsp,
659 struct sigmadsp_control *ctrl, unsigned int samplerate_mask)
660{
661 struct snd_card *card = sigmadsp->component->card->snd_card;
662 struct snd_kcontrol_volatile *vd;
663 struct snd_ctl_elem_id id;
664 bool active;
665 bool changed = false;
666
667 active = sigmadsp_samplerate_valid(ctrl->samplerates, samplerate_mask);
668
669 down_write(&card->controls_rwsem);
670 if (!ctrl->kcontrol) {
671 up_write(&card->controls_rwsem);
672 return;
673 }
674
675 id = ctrl->kcontrol->id;
676 vd = &ctrl->kcontrol->vd[0];
677 if (active == (bool)(vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE)) {
678 vd->access ^= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
679 changed = true;
680 }
681 up_write(&card->controls_rwsem);
682
683 if (active && changed) {
684 mutex_lock(&sigmadsp->lock);
685 if (ctrl->cached)
686 sigmadsp_ctrl_write(sigmadsp, ctrl, ctrl->cache);
687 mutex_unlock(&sigmadsp->lock);
688 }
689
690 if (changed)
691 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, &id);
692}
693
694/**
695 * sigmadsp_attach() - Attach a sigmadsp instance to a ASoC component
696 * @sigmadsp: The sigmadsp instance to attach
697 * @component: The component to attach to
698 *
699 * Typically called in the components probe callback.
700 *
701 * Note, once this function has been called the firmware must not be released
702 * until after the ALSA snd_card that the component belongs to has been
703 * disconnected, even if sigmadsp_attach() returns an error.
704 */
705int sigmadsp_attach(struct sigmadsp *sigmadsp,
706 struct snd_soc_component *component)
707{
708 struct sigmadsp_control *ctrl;
709 unsigned int samplerate_mask;
710 int ret;
711
712 sigmadsp->component = component;
713
714 samplerate_mask = sigmadsp_get_samplerate_mask(sigmadsp,
715 sigmadsp->current_samplerate);
716
717 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head) {
718 ret = sigmadsp_alloc_control(sigmadsp, ctrl, samplerate_mask);
719 if (ret)
720 return ret;
721 }
722
723 return 0;
724}
725EXPORT_SYMBOL_GPL(sigmadsp_attach);
726
727/**
728 * sigmadsp_setup() - Setup the DSP for the specified samplerate
729 * @sigmadsp: The sigmadsp instance to configure
730 * @samplerate: The samplerate the DSP should be configured for
731 *
732 * Loads the appropriate firmware program and parameter memory (if not already
733 * loaded) and enables the controls for the specified samplerate. Any control
734 * parameter changes that have been made previously will be restored.
735 *
736 * Returns 0 on success, a negative error code otherwise.
737 */
738int sigmadsp_setup(struct sigmadsp *sigmadsp, unsigned int samplerate)
739{
740 struct sigmadsp_control *ctrl;
741 unsigned int samplerate_mask;
742 struct sigmadsp_data *data;
743 int ret;
744
745 if (sigmadsp->current_samplerate == samplerate)
746 return 0;
747
748 samplerate_mask = sigmadsp_get_samplerate_mask(sigmadsp, samplerate);
749 if (samplerate_mask == 0)
750 return -EINVAL;
751
752 list_for_each_entry(data, &sigmadsp->data_list, head) {
753 if (!sigmadsp_samplerate_valid(data->samplerates,
754 samplerate_mask))
755 continue;
756 ret = sigmadsp_write(sigmadsp, data->addr, data->data,
757 data->length);
758 if (ret)
759 goto err;
760 }
761
762 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head)
763 sigmadsp_activate_ctrl(sigmadsp, ctrl, samplerate_mask);
764
765 sigmadsp->current_samplerate = samplerate;
766
767 return 0;
768err:
769 sigmadsp_reset(sigmadsp);
180 770
181 return ret; 771 return ret;
182} 772}
183EXPORT_SYMBOL_GPL(_process_sigma_firmware); 773EXPORT_SYMBOL_GPL(sigmadsp_setup);
774
775/**
776 * sigmadsp_reset() - Notify the sigmadsp instance that the DSP has been reset
777 * @sigmadsp: The sigmadsp instance to reset
778 *
779 * Should be called whenever the DSP has been reset and parameter and program
780 * memory need to be re-loaded.
781 */
782void sigmadsp_reset(struct sigmadsp *sigmadsp)
783{
784 struct sigmadsp_control *ctrl;
785
786 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head)
787 sigmadsp_activate_ctrl(sigmadsp, ctrl, false);
788
789 sigmadsp->current_samplerate = 0;
790}
791EXPORT_SYMBOL_GPL(sigmadsp_reset);
792
793/**
794 * sigmadsp_restrict_params() - Applies DSP firmware specific constraints
795 * @sigmadsp: The sigmadsp instance
796 * @substream: The substream to restrict
797 *
798 * Applies samplerate constraints that may be required by the firmware Should
799 * typically be called from the CODEC/component drivers startup callback.
800 *
801 * Returns 0 on success, a negative error code otherwise.
802 */
803int sigmadsp_restrict_params(struct sigmadsp *sigmadsp,
804 struct snd_pcm_substream *substream)
805{
806 if (sigmadsp->rate_constraints.count == 0)
807 return 0;
808
809 return snd_pcm_hw_constraint_list(substream->runtime, 0,
810 SNDRV_PCM_HW_PARAM_RATE, &sigmadsp->rate_constraints);
811}
812EXPORT_SYMBOL_GPL(sigmadsp_restrict_params);
184 813
185MODULE_LICENSE("GPL"); 814MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/sigmadsp.h b/sound/soc/codecs/sigmadsp.h
index c47cd23e9827..614475cbb823 100644
--- a/sound/soc/codecs/sigmadsp.h
+++ b/sound/soc/codecs/sigmadsp.h
@@ -11,31 +11,56 @@
11 11
12#include <linux/device.h> 12#include <linux/device.h>
13#include <linux/regmap.h> 13#include <linux/regmap.h>
14#include <linux/list.h>
14 15
15struct sigma_action { 16#include <sound/pcm.h>
16 u8 instr;
17 u8 len_hi;
18 __le16 len;
19 __be16 addr;
20 unsigned char payload[];
21} __packed;
22 17
23struct sigma_firmware { 18struct sigmadsp;
24 const struct firmware *fw; 19struct snd_soc_component;
25 size_t pos; 20struct snd_pcm_substream;
21
22struct sigmadsp_ops {
23 int (*safeload)(struct sigmadsp *sigmadsp, unsigned int addr,
24 const uint8_t *data, size_t len);
25};
26
27struct sigmadsp {
28 const struct sigmadsp_ops *ops;
29
30 struct list_head ctrl_list;
31 struct list_head data_list;
32
33 struct snd_pcm_hw_constraint_list rate_constraints;
34
35 unsigned int current_samplerate;
36 struct snd_soc_component *component;
37 struct device *dev;
38
39 struct mutex lock;
26 40
27 void *control_data; 41 void *control_data;
28 int (*write)(void *control_data, const struct sigma_action *sa, 42 int (*write)(void *, unsigned int, const uint8_t *, size_t);
29 size_t len); 43 int (*read)(void *, unsigned int, uint8_t *, size_t);
30}; 44};
31 45
32int _process_sigma_firmware(struct device *dev, 46struct sigmadsp *devm_sigmadsp_init(struct device *dev,
33 struct sigma_firmware *ssfw, const char *name); 47 const struct sigmadsp_ops *ops, const char *firmware_name);
48void sigmadsp_reset(struct sigmadsp *sigmadsp);
49
50int sigmadsp_restrict_params(struct sigmadsp *sigmadsp,
51 struct snd_pcm_substream *substream);
34 52
35struct i2c_client; 53struct i2c_client;
36 54
37extern int process_sigma_firmware(struct i2c_client *client, const char *name); 55struct sigmadsp *devm_sigmadsp_init_regmap(struct device *dev,
38extern int process_sigma_firmware_regmap(struct device *dev, 56 struct regmap *regmap, const struct sigmadsp_ops *ops,
39 struct regmap *regmap, const char *name); 57 const char *firmware_name);
58struct sigmadsp *devm_sigmadsp_init_i2c(struct i2c_client *client,
59 const struct sigmadsp_ops *ops, const char *firmware_name);
60
61int sigmadsp_attach(struct sigmadsp *sigmadsp,
62 struct snd_soc_component *component);
63int sigmadsp_setup(struct sigmadsp *sigmadsp, unsigned int rate);
64void sigmadsp_reset(struct sigmadsp *sigmadsp);
40 65
41#endif 66#endif
diff --git a/sound/soc/codecs/sirf-audio-codec.c b/sound/soc/codecs/sirf-audio-codec.c
index 06ba4923fd5a..07eea20e6645 100644
--- a/sound/soc/codecs/sirf-audio-codec.c
+++ b/sound/soc/codecs/sirf-audio-codec.c
@@ -120,7 +120,8 @@ static int atlas6_codec_enable_and_reset_event(struct snd_soc_dapm_widget *w,
120{ 120{
121#define ATLAS6_CODEC_ENABLE_BITS (1 << 29) 121#define ATLAS6_CODEC_ENABLE_BITS (1 << 29)
122#define ATLAS6_CODEC_RESET_BITS (1 << 28) 122#define ATLAS6_CODEC_RESET_BITS (1 << 28)
123 struct sirf_audio_codec *sirf_audio_codec = dev_get_drvdata(w->codec->dev); 123 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
124 struct sirf_audio_codec *sirf_audio_codec = snd_soc_codec_get_drvdata(codec);
124 switch (event) { 125 switch (event) {
125 case SND_SOC_DAPM_PRE_PMU: 126 case SND_SOC_DAPM_PRE_PMU:
126 enable_and_reset_codec(sirf_audio_codec->regmap, 127 enable_and_reset_codec(sirf_audio_codec->regmap,
@@ -142,7 +143,8 @@ static int prima2_codec_enable_and_reset_event(struct snd_soc_dapm_widget *w,
142{ 143{
143#define PRIMA2_CODEC_ENABLE_BITS (1 << 27) 144#define PRIMA2_CODEC_ENABLE_BITS (1 << 27)
144#define PRIMA2_CODEC_RESET_BITS (1 << 26) 145#define PRIMA2_CODEC_RESET_BITS (1 << 26)
145 struct sirf_audio_codec *sirf_audio_codec = dev_get_drvdata(w->codec->dev); 146 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
147 struct sirf_audio_codec *sirf_audio_codec = snd_soc_codec_get_drvdata(codec);
146 switch (event) { 148 switch (event) {
147 case SND_SOC_DAPM_POST_PMU: 149 case SND_SOC_DAPM_POST_PMU:
148 enable_and_reset_codec(sirf_audio_codec->regmap, 150 enable_and_reset_codec(sirf_audio_codec->regmap,
diff --git a/sound/soc/codecs/sn95031.c b/sound/soc/codecs/sn95031.c
index cf8fa40662f0..31d97cd5e59b 100644
--- a/sound/soc/codecs/sn95031.c
+++ b/sound/soc/codecs/sn95031.c
@@ -867,25 +867,16 @@ static int sn95031_codec_probe(struct snd_soc_codec *codec)
867 snd_soc_write(codec, SN95031_SSR2, 0x10); 867 snd_soc_write(codec, SN95031_SSR2, 0x10);
868 snd_soc_write(codec, SN95031_SSR3, 0x40); 868 snd_soc_write(codec, SN95031_SSR3, 0x40);
869 869
870 snd_soc_add_codec_controls(codec, sn95031_snd_controls,
871 ARRAY_SIZE(sn95031_snd_controls));
872
873 return 0;
874}
875
876static int sn95031_codec_remove(struct snd_soc_codec *codec)
877{
878 pr_debug("codec_remove called\n");
879 sn95031_set_vaud_bias(codec, SND_SOC_BIAS_OFF);
880
881 return 0; 870 return 0;
882} 871}
883 872
884static struct snd_soc_codec_driver sn95031_codec = { 873static struct snd_soc_codec_driver sn95031_codec = {
885 .probe = sn95031_codec_probe, 874 .probe = sn95031_codec_probe,
886 .remove = sn95031_codec_remove,
887 .set_bias_level = sn95031_set_vaud_bias, 875 .set_bias_level = sn95031_set_vaud_bias,
888 .idle_bias_off = true, 876 .idle_bias_off = true,
877
878 .controls = sn95031_snd_controls,
879 .num_controls = ARRAY_SIZE(sn95031_snd_controls),
889 .dapm_widgets = sn95031_dapm_widgets, 880 .dapm_widgets = sn95031_dapm_widgets,
890 .num_dapm_widgets = ARRAY_SIZE(sn95031_dapm_widgets), 881 .num_dapm_widgets = ARRAY_SIZE(sn95031_dapm_widgets),
891 .dapm_routes = sn95031_audio_map, 882 .dapm_routes = sn95031_audio_map,
diff --git a/sound/soc/codecs/ssm4567.c b/sound/soc/codecs/ssm4567.c
index 4b5c17f8507e..a984485108cd 100644
--- a/sound/soc/codecs/ssm4567.c
+++ b/sound/soc/codecs/ssm4567.c
@@ -69,6 +69,22 @@
69#define SSM4567_DAC_FS_64000_96000 0x3 69#define SSM4567_DAC_FS_64000_96000 0x3
70#define SSM4567_DAC_FS_128000_192000 0x4 70#define SSM4567_DAC_FS_128000_192000 0x4
71 71
72/* SAI_CTRL_1 */
73#define SSM4567_SAI_CTRL_1_BCLK BIT(6)
74#define SSM4567_SAI_CTRL_1_TDM_BLCKS_MASK (0x3 << 4)
75#define SSM4567_SAI_CTRL_1_TDM_BLCKS_32 (0x0 << 4)
76#define SSM4567_SAI_CTRL_1_TDM_BLCKS_48 (0x1 << 4)
77#define SSM4567_SAI_CTRL_1_TDM_BLCKS_64 (0x2 << 4)
78#define SSM4567_SAI_CTRL_1_FSYNC BIT(3)
79#define SSM4567_SAI_CTRL_1_LJ BIT(2)
80#define SSM4567_SAI_CTRL_1_TDM BIT(1)
81#define SSM4567_SAI_CTRL_1_PDM BIT(0)
82
83/* SAI_CTRL_2 */
84#define SSM4567_SAI_CTRL_2_AUTO_SLOT BIT(3)
85#define SSM4567_SAI_CTRL_2_TDM_SLOT_MASK 0x7
86#define SSM4567_SAI_CTRL_2_TDM_SLOT(x) (x)
87
72struct ssm4567 { 88struct ssm4567 {
73 struct regmap *regmap; 89 struct regmap *regmap;
74}; 90};
@@ -145,15 +161,24 @@ static const struct snd_kcontrol_new ssm4567_snd_controls[] = {
145 SOC_SINGLE_TLV("Master Playback Volume", SSM4567_REG_DAC_VOLUME, 0, 161 SOC_SINGLE_TLV("Master Playback Volume", SSM4567_REG_DAC_VOLUME, 0,
146 0xff, 1, ssm4567_vol_tlv), 162 0xff, 1, ssm4567_vol_tlv),
147 SOC_SINGLE("DAC Low Power Mode Switch", SSM4567_REG_DAC_CTRL, 4, 1, 0), 163 SOC_SINGLE("DAC Low Power Mode Switch", SSM4567_REG_DAC_CTRL, 4, 1, 0),
164 SOC_SINGLE("DAC High Pass Filter Switch", SSM4567_REG_DAC_CTRL,
165 5, 1, 0),
148}; 166};
149 167
168static const struct snd_kcontrol_new ssm4567_amplifier_boost_control =
169 SOC_DAPM_SINGLE("Switch", SSM4567_REG_POWER_CTRL, 1, 1, 1);
170
150static const struct snd_soc_dapm_widget ssm4567_dapm_widgets[] = { 171static const struct snd_soc_dapm_widget ssm4567_dapm_widgets[] = {
151 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM4567_REG_POWER_CTRL, 2, 1), 172 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM4567_REG_POWER_CTRL, 2, 1),
173 SND_SOC_DAPM_SWITCH("Amplifier Boost", SSM4567_REG_POWER_CTRL, 3, 1,
174 &ssm4567_amplifier_boost_control),
152 175
153 SND_SOC_DAPM_OUTPUT("OUT"), 176 SND_SOC_DAPM_OUTPUT("OUT"),
154}; 177};
155 178
156static const struct snd_soc_dapm_route ssm4567_routes[] = { 179static const struct snd_soc_dapm_route ssm4567_routes[] = {
180 { "OUT", NULL, "Amplifier Boost" },
181 { "Amplifier Boost", "Switch", "DAC" },
157 { "OUT", NULL, "DAC" }, 182 { "OUT", NULL, "DAC" },
158}; 183};
159 184
@@ -192,6 +217,107 @@ static int ssm4567_mute(struct snd_soc_dai *dai, int mute)
192 SSM4567_DAC_MUTE, val); 217 SSM4567_DAC_MUTE, val);
193} 218}
194 219
220static int ssm4567_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
221 unsigned int rx_mask, int slots, int width)
222{
223 struct ssm4567 *ssm4567 = snd_soc_dai_get_drvdata(dai);
224 unsigned int blcks;
225 int slot;
226 int ret;
227
228 if (tx_mask == 0)
229 return -EINVAL;
230
231 if (rx_mask && rx_mask != tx_mask)
232 return -EINVAL;
233
234 slot = __ffs(tx_mask);
235 if (tx_mask != BIT(slot))
236 return -EINVAL;
237
238 switch (width) {
239 case 32:
240 blcks = SSM4567_SAI_CTRL_1_TDM_BLCKS_32;
241 break;
242 case 48:
243 blcks = SSM4567_SAI_CTRL_1_TDM_BLCKS_48;
244 break;
245 case 64:
246 blcks = SSM4567_SAI_CTRL_1_TDM_BLCKS_64;
247 break;
248 default:
249 return -EINVAL;
250 }
251
252 ret = regmap_update_bits(ssm4567->regmap, SSM4567_REG_SAI_CTRL_2,
253 SSM4567_SAI_CTRL_2_AUTO_SLOT | SSM4567_SAI_CTRL_2_TDM_SLOT_MASK,
254 SSM4567_SAI_CTRL_2_TDM_SLOT(slot));
255 if (ret)
256 return ret;
257
258 return regmap_update_bits(ssm4567->regmap, SSM4567_REG_SAI_CTRL_1,
259 SSM4567_SAI_CTRL_1_TDM_BLCKS_MASK, blcks);
260}
261
262static int ssm4567_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
263{
264 struct ssm4567 *ssm4567 = snd_soc_dai_get_drvdata(dai);
265 unsigned int ctrl1 = 0;
266 bool invert_fclk;
267
268 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
269 case SND_SOC_DAIFMT_CBS_CFS:
270 break;
271 default:
272 return -EINVAL;
273 }
274
275 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
276 case SND_SOC_DAIFMT_NB_NF:
277 invert_fclk = false;
278 break;
279 case SND_SOC_DAIFMT_IB_NF:
280 ctrl1 |= SSM4567_SAI_CTRL_1_BCLK;
281 invert_fclk = false;
282 break;
283 case SND_SOC_DAIFMT_NB_IF:
284 ctrl1 |= SSM4567_SAI_CTRL_1_FSYNC;
285 invert_fclk = true;
286 break;
287 case SND_SOC_DAIFMT_IB_IF:
288 ctrl1 |= SSM4567_SAI_CTRL_1_BCLK;
289 invert_fclk = true;
290 break;
291 default:
292 return -EINVAL;
293 }
294
295 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
296 case SND_SOC_DAIFMT_I2S:
297 break;
298 case SND_SOC_DAIFMT_LEFT_J:
299 ctrl1 |= SSM4567_SAI_CTRL_1_LJ;
300 invert_fclk = !invert_fclk;
301 break;
302 case SND_SOC_DAIFMT_DSP_A:
303 ctrl1 |= SSM4567_SAI_CTRL_1_TDM;
304 break;
305 case SND_SOC_DAIFMT_DSP_B:
306 ctrl1 |= SSM4567_SAI_CTRL_1_TDM | SSM4567_SAI_CTRL_1_LJ;
307 break;
308 case SND_SOC_DAIFMT_PDM:
309 ctrl1 |= SSM4567_SAI_CTRL_1_PDM;
310 break;
311 default:
312 return -EINVAL;
313 }
314
315 if (invert_fclk)
316 ctrl1 |= SSM4567_SAI_CTRL_1_FSYNC;
317
318 return regmap_write(ssm4567->regmap, SSM4567_REG_SAI_CTRL_1, ctrl1);
319}
320
195static int ssm4567_set_power(struct ssm4567 *ssm4567, bool enable) 321static int ssm4567_set_power(struct ssm4567 *ssm4567, bool enable)
196{ 322{
197 int ret = 0; 323 int ret = 0;
@@ -246,6 +372,8 @@ static int ssm4567_set_bias_level(struct snd_soc_codec *codec,
246static const struct snd_soc_dai_ops ssm4567_dai_ops = { 372static const struct snd_soc_dai_ops ssm4567_dai_ops = {
247 .hw_params = ssm4567_hw_params, 373 .hw_params = ssm4567_hw_params,
248 .digital_mute = ssm4567_mute, 374 .digital_mute = ssm4567_mute,
375 .set_fmt = ssm4567_set_dai_fmt,
376 .set_tdm_slot = ssm4567_set_tdm_slot,
249}; 377};
250 378
251static struct snd_soc_dai_driver ssm4567_dai = { 379static struct snd_soc_dai_driver ssm4567_dai = {
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 48740855566d..7e18200dd6a9 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -833,23 +833,6 @@ static struct snd_soc_dai_driver sta32x_dai = {
833 .ops = &sta32x_dai_ops, 833 .ops = &sta32x_dai_ops,
834}; 834};
835 835
836#ifdef CONFIG_PM
837static int sta32x_suspend(struct snd_soc_codec *codec)
838{
839 sta32x_set_bias_level(codec, SND_SOC_BIAS_OFF);
840 return 0;
841}
842
843static int sta32x_resume(struct snd_soc_codec *codec)
844{
845 sta32x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
846 return 0;
847}
848#else
849#define sta32x_suspend NULL
850#define sta32x_resume NULL
851#endif
852
853static int sta32x_probe(struct snd_soc_codec *codec) 836static int sta32x_probe(struct snd_soc_codec *codec)
854{ 837{
855 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 838 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
@@ -936,7 +919,6 @@ static int sta32x_remove(struct snd_soc_codec *codec)
936 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 919 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
937 920
938 sta32x_watchdog_stop(sta32x); 921 sta32x_watchdog_stop(sta32x);
939 sta32x_set_bias_level(codec, SND_SOC_BIAS_OFF);
940 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); 922 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
941 923
942 return 0; 924 return 0;
@@ -955,9 +937,8 @@ static bool sta32x_reg_is_volatile(struct device *dev, unsigned int reg)
955static const struct snd_soc_codec_driver sta32x_codec = { 937static const struct snd_soc_codec_driver sta32x_codec = {
956 .probe = sta32x_probe, 938 .probe = sta32x_probe,
957 .remove = sta32x_remove, 939 .remove = sta32x_remove,
958 .suspend = sta32x_suspend,
959 .resume = sta32x_resume,
960 .set_bias_level = sta32x_set_bias_level, 940 .set_bias_level = sta32x_set_bias_level,
941 .suspend_bias_off = true,
961 .controls = sta32x_snd_controls, 942 .controls = sta32x_snd_controls,
962 .num_controls = ARRAY_SIZE(sta32x_snd_controls), 943 .num_controls = ARRAY_SIZE(sta32x_snd_controls),
963 .dapm_widgets = sta32x_dapm_widgets, 944 .dapm_widgets = sta32x_dapm_widgets,
diff --git a/sound/soc/codecs/sta350.c b/sound/soc/codecs/sta350.c
index cc97dd52aa9c..bda2ee18769e 100644
--- a/sound/soc/codecs/sta350.c
+++ b/sound/soc/codecs/sta350.c
@@ -912,23 +912,6 @@ static struct snd_soc_dai_driver sta350_dai = {
912 .ops = &sta350_dai_ops, 912 .ops = &sta350_dai_ops,
913}; 913};
914 914
915#ifdef CONFIG_PM
916static int sta350_suspend(struct snd_soc_codec *codec)
917{
918 sta350_set_bias_level(codec, SND_SOC_BIAS_OFF);
919 return 0;
920}
921
922static int sta350_resume(struct snd_soc_codec *codec)
923{
924 sta350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
925 return 0;
926}
927#else
928#define sta350_suspend NULL
929#define sta350_resume NULL
930#endif
931
932static int sta350_probe(struct snd_soc_codec *codec) 915static int sta350_probe(struct snd_soc_codec *codec)
933{ 916{
934 struct sta350_priv *sta350 = snd_soc_codec_get_drvdata(codec); 917 struct sta350_priv *sta350 = snd_soc_codec_get_drvdata(codec);
@@ -1065,7 +1048,6 @@ static int sta350_remove(struct snd_soc_codec *codec)
1065{ 1048{
1066 struct sta350_priv *sta350 = snd_soc_codec_get_drvdata(codec); 1049 struct sta350_priv *sta350 = snd_soc_codec_get_drvdata(codec);
1067 1050
1068 sta350_set_bias_level(codec, SND_SOC_BIAS_OFF);
1069 regulator_bulk_disable(ARRAY_SIZE(sta350->supplies), sta350->supplies); 1051 regulator_bulk_disable(ARRAY_SIZE(sta350->supplies), sta350->supplies);
1070 1052
1071 return 0; 1053 return 0;
@@ -1074,9 +1056,8 @@ static int sta350_remove(struct snd_soc_codec *codec)
1074static const struct snd_soc_codec_driver sta350_codec = { 1056static const struct snd_soc_codec_driver sta350_codec = {
1075 .probe = sta350_probe, 1057 .probe = sta350_probe,
1076 .remove = sta350_remove, 1058 .remove = sta350_remove,
1077 .suspend = sta350_suspend,
1078 .resume = sta350_resume,
1079 .set_bias_level = sta350_set_bias_level, 1059 .set_bias_level = sta350_set_bias_level,
1060 .suspend_bias_off = true,
1080 .controls = sta350_snd_controls, 1061 .controls = sta350_snd_controls,
1081 .num_controls = ARRAY_SIZE(sta350_snd_controls), 1062 .num_controls = ARRAY_SIZE(sta350_snd_controls),
1082 .dapm_widgets = sta350_dapm_widgets, 1063 .dapm_widgets = sta350_dapm_widgets,
diff --git a/sound/soc/codecs/sta529.c b/sound/soc/codecs/sta529.c
index 89c748dd3d6e..b0f436d10125 100644
--- a/sound/soc/codecs/sta529.c
+++ b/sound/soc/codecs/sta529.c
@@ -319,41 +319,10 @@ static struct snd_soc_dai_driver sta529_dai = {
319 .ops = &sta529_dai_ops, 319 .ops = &sta529_dai_ops,
320}; 320};
321 321
322static int sta529_probe(struct snd_soc_codec *codec)
323{
324 sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
325
326 return 0;
327}
328
329/* power down chip */
330static int sta529_remove(struct snd_soc_codec *codec)
331{
332 sta529_set_bias_level(codec, SND_SOC_BIAS_OFF);
333
334 return 0;
335}
336
337static int sta529_suspend(struct snd_soc_codec *codec)
338{
339 sta529_set_bias_level(codec, SND_SOC_BIAS_OFF);
340
341 return 0;
342}
343
344static int sta529_resume(struct snd_soc_codec *codec)
345{
346 sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
347
348 return 0;
349}
350
351static const struct snd_soc_codec_driver sta529_codec_driver = { 322static const struct snd_soc_codec_driver sta529_codec_driver = {
352 .probe = sta529_probe,
353 .remove = sta529_remove,
354 .set_bias_level = sta529_set_bias_level, 323 .set_bias_level = sta529_set_bias_level,
355 .suspend = sta529_suspend, 324 .suspend_bias_off = true,
356 .resume = sta529_resume, 325
357 .controls = sta529_snd_controls, 326 .controls = sta529_snd_controls,
358 .num_controls = ARRAY_SIZE(sta529_snd_controls), 327 .num_controls = ARRAY_SIZE(sta529_snd_controls),
359}; 328};
diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c
index 53b810d23fea..dbff0c89be48 100644
--- a/sound/soc/codecs/stac9766.c
+++ b/sound/soc/codecs/stac9766.c
@@ -139,18 +139,19 @@ static const struct snd_kcontrol_new stac9766_snd_ac97_controls[] = {
139static int stac9766_ac97_write(struct snd_soc_codec *codec, unsigned int reg, 139static int stac9766_ac97_write(struct snd_soc_codec *codec, unsigned int reg,
140 unsigned int val) 140 unsigned int val)
141{ 141{
142 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
142 u16 *cache = codec->reg_cache; 143 u16 *cache = codec->reg_cache;
143 144
144 if (reg > AC97_STAC_PAGE0) { 145 if (reg > AC97_STAC_PAGE0) {
145 stac9766_ac97_write(codec, AC97_INT_PAGING, 0); 146 stac9766_ac97_write(codec, AC97_INT_PAGING, 0);
146 soc_ac97_ops->write(codec->ac97, reg, val); 147 soc_ac97_ops->write(ac97, reg, val);
147 stac9766_ac97_write(codec, AC97_INT_PAGING, 1); 148 stac9766_ac97_write(codec, AC97_INT_PAGING, 1);
148 return 0; 149 return 0;
149 } 150 }
150 if (reg / 2 >= ARRAY_SIZE(stac9766_reg)) 151 if (reg / 2 >= ARRAY_SIZE(stac9766_reg))
151 return -EIO; 152 return -EIO;
152 153
153 soc_ac97_ops->write(codec->ac97, reg, val); 154 soc_ac97_ops->write(ac97, reg, val);
154 cache[reg / 2] = val; 155 cache[reg / 2] = val;
155 return 0; 156 return 0;
156} 157}
@@ -158,11 +159,12 @@ static int stac9766_ac97_write(struct snd_soc_codec *codec, unsigned int reg,
158static unsigned int stac9766_ac97_read(struct snd_soc_codec *codec, 159static unsigned int stac9766_ac97_read(struct snd_soc_codec *codec,
159 unsigned int reg) 160 unsigned int reg)
160{ 161{
162 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
161 u16 val = 0, *cache = codec->reg_cache; 163 u16 val = 0, *cache = codec->reg_cache;
162 164
163 if (reg > AC97_STAC_PAGE0) { 165 if (reg > AC97_STAC_PAGE0) {
164 stac9766_ac97_write(codec, AC97_INT_PAGING, 0); 166 stac9766_ac97_write(codec, AC97_INT_PAGING, 0);
165 val = soc_ac97_ops->read(codec->ac97, reg - AC97_STAC_PAGE0); 167 val = soc_ac97_ops->read(ac97, reg - AC97_STAC_PAGE0);
166 stac9766_ac97_write(codec, AC97_INT_PAGING, 1); 168 stac9766_ac97_write(codec, AC97_INT_PAGING, 1);
167 return val; 169 return val;
168 } 170 }
@@ -173,7 +175,7 @@ static unsigned int stac9766_ac97_read(struct snd_soc_codec *codec,
173 reg == AC97_INT_PAGING || reg == AC97_VENDOR_ID1 || 175 reg == AC97_INT_PAGING || reg == AC97_VENDOR_ID1 ||
174 reg == AC97_VENDOR_ID2) { 176 reg == AC97_VENDOR_ID2) {
175 177
176 val = soc_ac97_ops->read(codec->ac97, reg); 178 val = soc_ac97_ops->read(ac97, reg);
177 return val; 179 return val;
178 } 180 }
179 return cache[reg / 2]; 181 return cache[reg / 2];
@@ -240,45 +242,41 @@ static int stac9766_set_bias_level(struct snd_soc_codec *codec,
240 242
241static int stac9766_reset(struct snd_soc_codec *codec, int try_warm) 243static int stac9766_reset(struct snd_soc_codec *codec, int try_warm)
242{ 244{
245 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
246
243 if (try_warm && soc_ac97_ops->warm_reset) { 247 if (try_warm && soc_ac97_ops->warm_reset) {
244 soc_ac97_ops->warm_reset(codec->ac97); 248 soc_ac97_ops->warm_reset(ac97);
245 if (stac9766_ac97_read(codec, 0) == stac9766_reg[0]) 249 if (stac9766_ac97_read(codec, 0) == stac9766_reg[0])
246 return 1; 250 return 1;
247 } 251 }
248 252
249 soc_ac97_ops->reset(codec->ac97); 253 soc_ac97_ops->reset(ac97);
250 if (soc_ac97_ops->warm_reset) 254 if (soc_ac97_ops->warm_reset)
251 soc_ac97_ops->warm_reset(codec->ac97); 255 soc_ac97_ops->warm_reset(ac97);
252 if (stac9766_ac97_read(codec, 0) != stac9766_reg[0]) 256 if (stac9766_ac97_read(codec, 0) != stac9766_reg[0])
253 return -EIO; 257 return -EIO;
254 return 0; 258 return 0;
255} 259}
256 260
257static int stac9766_codec_suspend(struct snd_soc_codec *codec)
258{
259 stac9766_set_bias_level(codec, SND_SOC_BIAS_OFF);
260 return 0;
261}
262
263static int stac9766_codec_resume(struct snd_soc_codec *codec) 261static int stac9766_codec_resume(struct snd_soc_codec *codec)
264{ 262{
263 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
265 u16 id, reset; 264 u16 id, reset;
266 265
267 reset = 0; 266 reset = 0;
268 /* give the codec an AC97 warm reset to start the link */ 267 /* give the codec an AC97 warm reset to start the link */
269reset: 268reset:
270 if (reset > 5) { 269 if (reset > 5) {
271 printk(KERN_ERR "stac9766 failed to resume"); 270 dev_err(codec->dev, "Failed to resume\n");
272 return -EIO; 271 return -EIO;
273 } 272 }
274 codec->ac97->bus->ops->warm_reset(codec->ac97); 273 ac97->bus->ops->warm_reset(ac97);
275 id = soc_ac97_ops->read(codec->ac97, AC97_VENDOR_ID2); 274 id = soc_ac97_ops->read(ac97, AC97_VENDOR_ID2);
276 if (id != 0x4c13) { 275 if (id != 0x4c13) {
277 stac9766_reset(codec, 0); 276 stac9766_reset(codec, 0);
278 reset++; 277 reset++;
279 goto reset; 278 goto reset;
280 } 279 }
281 stac9766_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
282 280
283 return 0; 281 return 0;
284} 282}
@@ -294,7 +292,6 @@ static const struct snd_soc_dai_ops stac9766_dai_ops_digital = {
294static struct snd_soc_dai_driver stac9766_dai[] = { 292static struct snd_soc_dai_driver stac9766_dai[] = {
295{ 293{
296 .name = "stac9766-hifi-analog", 294 .name = "stac9766-hifi-analog",
297 .ac97_control = 1,
298 295
299 /* stream cababilities */ 296 /* stream cababilities */
300 .playback = { 297 .playback = {
@@ -316,7 +313,6 @@ static struct snd_soc_dai_driver stac9766_dai[] = {
316}, 313},
317{ 314{
318 .name = "stac9766-hifi-IEC958", 315 .name = "stac9766-hifi-IEC958",
319 .ac97_control = 1,
320 316
321 /* stream cababilities */ 317 /* stream cababilities */
322 .playback = { 318 .playback = {
@@ -334,46 +330,48 @@ static struct snd_soc_dai_driver stac9766_dai[] = {
334 330
335static int stac9766_codec_probe(struct snd_soc_codec *codec) 331static int stac9766_codec_probe(struct snd_soc_codec *codec)
336{ 332{
333 struct snd_ac97 *ac97;
337 int ret = 0; 334 int ret = 0;
338 335
339 ret = snd_soc_new_ac97_codec(codec, soc_ac97_ops, 0); 336 ac97 = snd_soc_new_ac97_codec(codec);
340 if (ret < 0) 337 if (IS_ERR(ac97))
341 goto codec_err; 338 return PTR_ERR(ac97);
339
340 snd_soc_codec_set_drvdata(codec, ac97);
342 341
343 /* do a cold reset for the controller and then try 342 /* do a cold reset for the controller and then try
344 * a warm reset followed by an optional cold reset for codec */ 343 * a warm reset followed by an optional cold reset for codec */
345 stac9766_reset(codec, 0); 344 stac9766_reset(codec, 0);
346 ret = stac9766_reset(codec, 1); 345 ret = stac9766_reset(codec, 1);
347 if (ret < 0) { 346 if (ret < 0) {
348 printk(KERN_ERR "Failed to reset STAC9766: AC97 link error\n"); 347 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
349 goto codec_err; 348 goto codec_err;
350 } 349 }
351 350
352 stac9766_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
353
354 snd_soc_add_codec_controls(codec, stac9766_snd_ac97_controls,
355 ARRAY_SIZE(stac9766_snd_ac97_controls));
356
357 return 0; 351 return 0;
358 352
359codec_err: 353codec_err:
360 snd_soc_free_ac97_codec(codec); 354 snd_soc_free_ac97_codec(ac97);
361 return ret; 355 return ret;
362} 356}
363 357
364static int stac9766_codec_remove(struct snd_soc_codec *codec) 358static int stac9766_codec_remove(struct snd_soc_codec *codec)
365{ 359{
366 snd_soc_free_ac97_codec(codec); 360 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
361
362 snd_soc_free_ac97_codec(ac97);
367 return 0; 363 return 0;
368} 364}
369 365
370static struct snd_soc_codec_driver soc_codec_dev_stac9766 = { 366static struct snd_soc_codec_driver soc_codec_dev_stac9766 = {
367 .controls = stac9766_snd_ac97_controls,
368 .num_controls = ARRAY_SIZE(stac9766_snd_ac97_controls),
371 .write = stac9766_ac97_write, 369 .write = stac9766_ac97_write,
372 .read = stac9766_ac97_read, 370 .read = stac9766_ac97_read,
373 .set_bias_level = stac9766_set_bias_level, 371 .set_bias_level = stac9766_set_bias_level,
372 .suspend_bias_off = true,
374 .probe = stac9766_codec_probe, 373 .probe = stac9766_codec_probe,
375 .remove = stac9766_codec_remove, 374 .remove = stac9766_codec_remove,
376 .suspend = stac9766_codec_suspend,
377 .resume = stac9766_codec_resume, 375 .resume = stac9766_codec_resume,
378 .reg_cache_size = ARRAY_SIZE(stac9766_reg), 376 .reg_cache_size = ARRAY_SIZE(stac9766_reg),
379 .reg_word_size = sizeof(u16), 377 .reg_word_size = sizeof(u16),
diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index f039dc825971..b505212019e2 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -345,7 +345,6 @@ static const struct reg_default tas2552_init_regs[] = {
345static int tas2552_codec_probe(struct snd_soc_codec *codec) 345static int tas2552_codec_probe(struct snd_soc_codec *codec)
346{ 346{
347 struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec); 347 struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
348 struct snd_soc_dapm_context *dapm = &codec->dapm;
349 int ret; 348 int ret;
350 349
351 tas2552->codec = codec; 350 tas2552->codec = codec;
@@ -390,11 +389,6 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
390 snd_soc_write(codec, TAS2552_CFG_2, TAS2552_BOOST_EN | 389 snd_soc_write(codec, TAS2552_CFG_2, TAS2552_BOOST_EN |
391 TAS2552_APT_EN | TAS2552_LIM_EN); 390 TAS2552_APT_EN | TAS2552_LIM_EN);
392 391
393 snd_soc_dapm_new_controls(dapm, tas2552_dapm_widgets,
394 ARRAY_SIZE(tas2552_dapm_widgets));
395 snd_soc_dapm_add_routes(dapm, tas2552_audio_map,
396 ARRAY_SIZE(tas2552_audio_map));
397
398 return 0; 392 return 0;
399 393
400patch_fail: 394patch_fail:
@@ -462,6 +456,10 @@ static struct snd_soc_codec_driver soc_codec_dev_tas2552 = {
462 .resume = tas2552_resume, 456 .resume = tas2552_resume,
463 .controls = tas2552_snd_controls, 457 .controls = tas2552_snd_controls,
464 .num_controls = ARRAY_SIZE(tas2552_snd_controls), 458 .num_controls = ARRAY_SIZE(tas2552_snd_controls),
459 .dapm_widgets = tas2552_dapm_widgets,
460 .num_dapm_widgets = ARRAY_SIZE(tas2552_dapm_widgets),
461 .dapm_routes = tas2552_audio_map,
462 .num_dapm_routes = ARRAY_SIZE(tas2552_audio_map),
465}; 463};
466 464
467static const struct regmap_config tas2552_regmap_config = { 465static const struct regmap_config tas2552_regmap_config = {
diff --git a/sound/soc/codecs/tfa9879.c b/sound/soc/codecs/tfa9879.c
new file mode 100644
index 000000000000..16f1b71edb55
--- /dev/null
+++ b/sound/soc/codecs/tfa9879.c
@@ -0,0 +1,328 @@
1/*
2 * tfa9879.c -- driver for NXP Semiconductors TFA9879
3 *
4 * Copyright (C) 2014 Axentia Technologies AB
5 * Author: Peter Rosin <peda@axentia.se>
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/regmap.h>
18#include <sound/soc.h>
19#include <sound/tlv.h>
20#include <sound/pcm_params.h>
21
22#include "tfa9879.h"
23
24struct tfa9879_priv {
25 struct regmap *regmap;
26 int lsb_justified;
27};
28
29static int tfa9879_hw_params(struct snd_pcm_substream *substream,
30 struct snd_pcm_hw_params *params,
31 struct snd_soc_dai *dai)
32{
33 struct snd_soc_codec *codec = dai->codec;
34 struct tfa9879_priv *tfa9879 = snd_soc_codec_get_drvdata(codec);
35 int fs;
36 int i2s_set = 0;
37
38 switch (params_rate(params)) {
39 case 8000:
40 fs = TFA9879_I2S_FS_8000;
41 break;
42 case 11025:
43 fs = TFA9879_I2S_FS_11025;
44 break;
45 case 12000:
46 fs = TFA9879_I2S_FS_12000;
47 break;
48 case 16000:
49 fs = TFA9879_I2S_FS_16000;
50 break;
51 case 22050:
52 fs = TFA9879_I2S_FS_22050;
53 break;
54 case 24000:
55 fs = TFA9879_I2S_FS_24000;
56 break;
57 case 32000:
58 fs = TFA9879_I2S_FS_32000;
59 break;
60 case 44100:
61 fs = TFA9879_I2S_FS_44100;
62 break;
63 case 48000:
64 fs = TFA9879_I2S_FS_48000;
65 break;
66 case 64000:
67 fs = TFA9879_I2S_FS_64000;
68 break;
69 case 88200:
70 fs = TFA9879_I2S_FS_88200;
71 break;
72 case 96000:
73 fs = TFA9879_I2S_FS_96000;
74 break;
75 default:
76 return -EINVAL;
77 }
78
79 switch (params_width(params)) {
80 case 16:
81 i2s_set = TFA9879_I2S_SET_LSB_J_16;
82 break;
83 case 24:
84 i2s_set = TFA9879_I2S_SET_LSB_J_24;
85 break;
86 default:
87 return -EINVAL;
88 }
89
90 if (tfa9879->lsb_justified)
91 snd_soc_update_bits(codec, TFA9879_SERIAL_INTERFACE_1,
92 TFA9879_I2S_SET_MASK,
93 i2s_set << TFA9879_I2S_SET_SHIFT);
94
95 snd_soc_update_bits(codec, TFA9879_SERIAL_INTERFACE_1,
96 TFA9879_I2S_FS_MASK,
97 fs << TFA9879_I2S_FS_SHIFT);
98 return 0;
99}
100
101static int tfa9879_digital_mute(struct snd_soc_dai *dai, int mute)
102{
103 struct snd_soc_codec *codec = dai->codec;
104
105 snd_soc_update_bits(codec, TFA9879_MISC_CONTROL,
106 TFA9879_S_MUTE_MASK,
107 !!mute << TFA9879_S_MUTE_SHIFT);
108
109 return 0;
110}
111
112static int tfa9879_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
113{
114 struct snd_soc_codec *codec = dai->codec;
115 struct tfa9879_priv *tfa9879 = snd_soc_codec_get_drvdata(codec);
116 int i2s_set;
117 int sck_pol;
118
119 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
120 case SND_SOC_DAIFMT_CBS_CFS:
121 break;
122 default:
123 return -EINVAL;
124 }
125
126 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
127 case SND_SOC_DAIFMT_NB_NF:
128 sck_pol = TFA9879_SCK_POL_NORMAL;
129 break;
130 case SND_SOC_DAIFMT_IB_NF:
131 sck_pol = TFA9879_SCK_POL_INVERSE;
132 break;
133 default:
134 return -EINVAL;
135 }
136
137 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
138 case SND_SOC_DAIFMT_I2S:
139 tfa9879->lsb_justified = 0;
140 i2s_set = TFA9879_I2S_SET_I2S_24;
141 break;
142 case SND_SOC_DAIFMT_LEFT_J:
143 tfa9879->lsb_justified = 0;
144 i2s_set = TFA9879_I2S_SET_MSB_J_24;
145 break;
146 case SND_SOC_DAIFMT_RIGHT_J:
147 tfa9879->lsb_justified = 1;
148 i2s_set = TFA9879_I2S_SET_LSB_J_24;
149 break;
150 default:
151 return -EINVAL;
152 }
153
154 snd_soc_update_bits(codec, TFA9879_SERIAL_INTERFACE_1,
155 TFA9879_SCK_POL_MASK,
156 sck_pol << TFA9879_SCK_POL_SHIFT);
157 snd_soc_update_bits(codec, TFA9879_SERIAL_INTERFACE_1,
158 TFA9879_I2S_SET_MASK,
159 i2s_set << TFA9879_I2S_SET_SHIFT);
160 return 0;
161}
162
163static struct reg_default tfa9879_regs[] = {
164 { TFA9879_DEVICE_CONTROL, 0x0000 }, /* 0x00 */
165 { TFA9879_SERIAL_INTERFACE_1, 0x0a18 }, /* 0x01 */
166 { TFA9879_PCM_IOM2_FORMAT_1, 0x0007 }, /* 0x02 */
167 { TFA9879_SERIAL_INTERFACE_2, 0x0a18 }, /* 0x03 */
168 { TFA9879_PCM_IOM2_FORMAT_2, 0x0007 }, /* 0x04 */
169 { TFA9879_EQUALIZER_A1, 0x59dd }, /* 0x05 */
170 { TFA9879_EQUALIZER_A2, 0xc63e }, /* 0x06 */
171 { TFA9879_EQUALIZER_B1, 0x651a }, /* 0x07 */
172 { TFA9879_EQUALIZER_B2, 0xe53e }, /* 0x08 */
173 { TFA9879_EQUALIZER_C1, 0x4616 }, /* 0x09 */
174 { TFA9879_EQUALIZER_C2, 0xd33e }, /* 0x0a */
175 { TFA9879_EQUALIZER_D1, 0x4df3 }, /* 0x0b */
176 { TFA9879_EQUALIZER_D2, 0xea3e }, /* 0x0c */
177 { TFA9879_EQUALIZER_E1, 0x5ee0 }, /* 0x0d */
178 { TFA9879_EQUALIZER_E2, 0xf93e }, /* 0x0e */
179 { TFA9879_BYPASS_CONTROL, 0x0093 }, /* 0x0f */
180 { TFA9879_DYNAMIC_RANGE_COMPR, 0x92ba }, /* 0x10 */
181 { TFA9879_BASS_TREBLE, 0x12a5 }, /* 0x11 */
182 { TFA9879_HIGH_PASS_FILTER, 0x0004 }, /* 0x12 */
183 { TFA9879_VOLUME_CONTROL, 0x10bd }, /* 0x13 */
184 { TFA9879_MISC_CONTROL, 0x0000 }, /* 0x14 */
185};
186
187static bool tfa9879_volatile_reg(struct device *dev, unsigned int reg)
188{
189 return reg == TFA9879_MISC_STATUS;
190}
191
192static const DECLARE_TLV_DB_SCALE(volume_tlv, -7050, 50, 1);
193static const DECLARE_TLV_DB_SCALE(tb_gain_tlv, -1800, 200, 0);
194static const char * const tb_freq_text[] = {
195 "Low", "Mid", "High"
196};
197static const struct soc_enum treble_freq_enum =
198 SOC_ENUM_SINGLE(TFA9879_BASS_TREBLE, TFA9879_F_TRBLE_SHIFT,
199 ARRAY_SIZE(tb_freq_text), tb_freq_text);
200static const struct soc_enum bass_freq_enum =
201 SOC_ENUM_SINGLE(TFA9879_BASS_TREBLE, TFA9879_F_BASS_SHIFT,
202 ARRAY_SIZE(tb_freq_text), tb_freq_text);
203
204static const struct snd_kcontrol_new tfa9879_controls[] = {
205 SOC_SINGLE_TLV("PCM Playback Volume", TFA9879_VOLUME_CONTROL,
206 TFA9879_VOL_SHIFT, 0xbd, 1, volume_tlv),
207 SOC_SINGLE_TLV("Treble Volume", TFA9879_BASS_TREBLE,
208 TFA9879_G_TRBLE_SHIFT, 18, 0, tb_gain_tlv),
209 SOC_SINGLE_TLV("Bass Volume", TFA9879_BASS_TREBLE,
210 TFA9879_G_BASS_SHIFT, 18, 0, tb_gain_tlv),
211 SOC_ENUM("Treble Corner Freq", treble_freq_enum),
212 SOC_ENUM("Bass Corner Freq", bass_freq_enum),
213};
214
215static const struct snd_soc_dapm_widget tfa9879_dapm_widgets[] = {
216SND_SOC_DAPM_AIF_IN("AIFINL", "Playback", 0, SND_SOC_NOPM, 0, 0),
217SND_SOC_DAPM_AIF_IN("AIFINR", "Playback", 1, SND_SOC_NOPM, 0, 0),
218SND_SOC_DAPM_DAC("DAC", NULL, TFA9879_DEVICE_CONTROL, TFA9879_OPMODE_SHIFT, 0),
219SND_SOC_DAPM_OUTPUT("LINEOUT"),
220SND_SOC_DAPM_SUPPLY("POWER", TFA9879_DEVICE_CONTROL, TFA9879_POWERUP_SHIFT, 0,
221 NULL, 0),
222};
223
224static const struct snd_soc_dapm_route tfa9879_dapm_routes[] = {
225 { "DAC", NULL, "AIFINL" },
226 { "DAC", NULL, "AIFINR" },
227
228 { "LINEOUT", NULL, "DAC" },
229
230 { "DAC", NULL, "POWER" },
231};
232
233static const struct snd_soc_codec_driver tfa9879_codec = {
234 .controls = tfa9879_controls,
235 .num_controls = ARRAY_SIZE(tfa9879_controls),
236
237 .dapm_widgets = tfa9879_dapm_widgets,
238 .num_dapm_widgets = ARRAY_SIZE(tfa9879_dapm_widgets),
239 .dapm_routes = tfa9879_dapm_routes,
240 .num_dapm_routes = ARRAY_SIZE(tfa9879_dapm_routes),
241};
242
243static const struct regmap_config tfa9879_regmap = {
244 .reg_bits = 8,
245 .val_bits = 16,
246
247 .volatile_reg = tfa9879_volatile_reg,
248 .max_register = TFA9879_MISC_STATUS,
249 .reg_defaults = tfa9879_regs,
250 .num_reg_defaults = ARRAY_SIZE(tfa9879_regs),
251 .cache_type = REGCACHE_RBTREE,
252};
253
254static const struct snd_soc_dai_ops tfa9879_dai_ops = {
255 .hw_params = tfa9879_hw_params,
256 .digital_mute = tfa9879_digital_mute,
257 .set_fmt = tfa9879_set_fmt,
258};
259
260#define TFA9879_RATES SNDRV_PCM_RATE_8000_96000
261
262#define TFA9879_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
263 SNDRV_PCM_FMTBIT_S24_LE)
264
265static struct snd_soc_dai_driver tfa9879_dai = {
266 .name = "tfa9879-hifi",
267 .playback = {
268 .stream_name = "Playback",
269 .channels_min = 2,
270 .channels_max = 2,
271 .rates = TFA9879_RATES,
272 .formats = TFA9879_FORMATS, },
273 .ops = &tfa9879_dai_ops,
274};
275
276static int tfa9879_i2c_probe(struct i2c_client *i2c,
277 const struct i2c_device_id *id)
278{
279 struct tfa9879_priv *tfa9879;
280 int i;
281
282 tfa9879 = devm_kzalloc(&i2c->dev, sizeof(*tfa9879), GFP_KERNEL);
283 if (IS_ERR(tfa9879))
284 return PTR_ERR(tfa9879);
285
286 i2c_set_clientdata(i2c, tfa9879);
287
288 tfa9879->regmap = devm_regmap_init_i2c(i2c, &tfa9879_regmap);
289 if (IS_ERR(tfa9879->regmap))
290 return PTR_ERR(tfa9879->regmap);
291
292 /* Ensure the device is in reset state */
293 for (i = 0; i < ARRAY_SIZE(tfa9879_regs); i++)
294 regmap_write(tfa9879->regmap,
295 tfa9879_regs[i].reg, tfa9879_regs[i].def);
296
297 return snd_soc_register_codec(&i2c->dev, &tfa9879_codec,
298 &tfa9879_dai, 1);
299}
300
301static int tfa9879_i2c_remove(struct i2c_client *client)
302{
303 snd_soc_unregister_codec(&client->dev);
304
305 return 0;
306}
307
308static const struct i2c_device_id tfa9879_i2c_id[] = {
309 { "tfa9879", 0 },
310 { }
311};
312MODULE_DEVICE_TABLE(i2c, tfa9879_i2c_id);
313
314static struct i2c_driver tfa9879_i2c_driver = {
315 .driver = {
316 .name = "tfa9879",
317 .owner = THIS_MODULE,
318 },
319 .probe = tfa9879_i2c_probe,
320 .remove = tfa9879_i2c_remove,
321 .id_table = tfa9879_i2c_id,
322};
323
324module_i2c_driver(tfa9879_i2c_driver);
325
326MODULE_DESCRIPTION("ASoC NXP Semiconductors TFA9879 driver");
327MODULE_AUTHOR("Peter Rosin <peda@axentia.se>");
328MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/tfa9879.h b/sound/soc/codecs/tfa9879.h
new file mode 100644
index 000000000000..3408c90c4628
--- /dev/null
+++ b/sound/soc/codecs/tfa9879.h
@@ -0,0 +1,202 @@
1/*
2 * tfa9879.h -- driver for NXP Semiconductors TFA9879
3 *
4 * Copyright (C) 2014 Axentia Technologies AB
5 * Author: Peter Rosin <peda@axentia.se>
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 _TFA9879_H
15#define _TFA9879_H
16
17#define TFA9879_DEVICE_CONTROL 0x00
18#define TFA9879_SERIAL_INTERFACE_1 0x01
19#define TFA9879_PCM_IOM2_FORMAT_1 0x02
20#define TFA9879_SERIAL_INTERFACE_2 0x03
21#define TFA9879_PCM_IOM2_FORMAT_2 0x04
22#define TFA9879_EQUALIZER_A1 0x05
23#define TFA9879_EQUALIZER_A2 0x06
24#define TFA9879_EQUALIZER_B1 0x07
25#define TFA9879_EQUALIZER_B2 0x08
26#define TFA9879_EQUALIZER_C1 0x09
27#define TFA9879_EQUALIZER_C2 0x0a
28#define TFA9879_EQUALIZER_D1 0x0b
29#define TFA9879_EQUALIZER_D2 0x0c
30#define TFA9879_EQUALIZER_E1 0x0d
31#define TFA9879_EQUALIZER_E2 0x0e
32#define TFA9879_BYPASS_CONTROL 0x0f
33#define TFA9879_DYNAMIC_RANGE_COMPR 0x10
34#define TFA9879_BASS_TREBLE 0x11
35#define TFA9879_HIGH_PASS_FILTER 0x12
36#define TFA9879_VOLUME_CONTROL 0x13
37#define TFA9879_MISC_CONTROL 0x14
38#define TFA9879_MISC_STATUS 0x15
39
40/* TFA9879_DEVICE_CONTROL */
41#define TFA9879_INPUT_SEL_MASK 0x0010
42#define TFA9879_INPUT_SEL_SHIFT 4
43#define TFA9879_OPMODE_MASK 0x0008
44#define TFA9879_OPMODE_SHIFT 3
45#define TFA9879_RESET_MASK 0x0002
46#define TFA9879_RESET_SHIFT 1
47#define TFA9879_POWERUP_MASK 0x0001
48#define TFA9879_POWERUP_SHIFT 0
49
50/* TFA9879_SERIAL_INTERFACE */
51#define TFA9879_MONO_SEL_MASK 0x0c00
52#define TFA9879_MONO_SEL_SHIFT 10
53#define TFA9879_MONO_SEL_LEFT 0
54#define TFA9879_MONO_SEL_RIGHT 1
55#define TFA9879_MONO_SEL_BOTH 2
56#define TFA9879_I2S_FS_MASK 0x03c0
57#define TFA9879_I2S_FS_SHIFT 6
58#define TFA9879_I2S_FS_8000 0
59#define TFA9879_I2S_FS_11025 1
60#define TFA9879_I2S_FS_12000 2
61#define TFA9879_I2S_FS_16000 3
62#define TFA9879_I2S_FS_22050 4
63#define TFA9879_I2S_FS_24000 5
64#define TFA9879_I2S_FS_32000 6
65#define TFA9879_I2S_FS_44100 7
66#define TFA9879_I2S_FS_48000 8
67#define TFA9879_I2S_FS_64000 9
68#define TFA9879_I2S_FS_88200 10
69#define TFA9879_I2S_FS_96000 11
70#define TFA9879_I2S_SET_MASK 0x0038
71#define TFA9879_I2S_SET_SHIFT 3
72#define TFA9879_I2S_SET_MSB_J_24 2
73#define TFA9879_I2S_SET_I2S_24 3
74#define TFA9879_I2S_SET_LSB_J_16 4
75#define TFA9879_I2S_SET_LSB_J_18 5
76#define TFA9879_I2S_SET_LSB_J_20 6
77#define TFA9879_I2S_SET_LSB_J_24 7
78#define TFA9879_SCK_POL_MASK 0x0004
79#define TFA9879_SCK_POL_SHIFT 2
80#define TFA9879_SCK_POL_NORMAL 0
81#define TFA9879_SCK_POL_INVERSE 1
82#define TFA9879_I_MODE_MASK 0x0003
83#define TFA9879_I_MODE_SHIFT 0
84#define TFA9879_I_MODE_I2S 0
85#define TFA9879_I_MODE_PCM_IOM2_SHORT 1
86#define TFA9879_I_MODE_PCM_IOM2_LONG 2
87
88/* TFA9879_PCM_IOM2_FORMAT */
89#define TFA9879_PCM_FS_MASK 0x0800
90#define TFA9879_PCM_FS_SHIFT 11
91#define TFA9879_A_LAW_MASK 0x0400
92#define TFA9879_A_LAW_SHIFT 10
93#define TFA9879_PCM_COMP_MASK 0x0200
94#define TFA9879_PCM_COMP_SHIFT 9
95#define TFA9879_PCM_DL_MASK 0x0100
96#define TFA9879_PCM_DL_SHIFT 8
97#define TFA9879_D1_SLOT_MASK 0x00f0
98#define TFA9879_D1_SLOT_SHIFT 4
99#define TFA9879_D2_SLOT_MASK 0x000f
100#define TFA9879_D2_SLOT_SHIFT 0
101
102/* TFA9879_EQUALIZER_X1 */
103#define TFA9879_T1_MASK 0x8000
104#define TFA9879_T1_SHIFT 15
105#define TFA9879_K1M_MASK 0x7ff0
106#define TFA9879_K1M_SHIFT 4
107#define TFA9879_K1E_MASK 0x000f
108#define TFA9879_K1E_SHIFT 0
109
110/* TFA9879_EQUALIZER_X2 */
111#define TFA9879_T2_MASK 0x8000
112#define TFA9879_T2_SHIFT 15
113#define TFA9879_K2M_MASK 0x7800
114#define TFA9879_K2M_SHIFT 11
115#define TFA9879_K2E_MASK 0x0700
116#define TFA9879_K2E_SHIFT 8
117#define TFA9879_K0_MASK 0x00fe
118#define TFA9879_K0_SHIFT 1
119#define TFA9879_S_MASK 0x0001
120#define TFA9879_S_SHIFT 0
121
122/* TFA9879_BYPASS_CONTROL */
123#define TFA9879_L_OCP_MASK 0x00c0
124#define TFA9879_L_OCP_SHIFT 6
125#define TFA9879_L_OTP_MASK 0x0030
126#define TFA9879_L_OTP_SHIFT 4
127#define TFA9879_CLIPCTRL_MASK 0x0008
128#define TFA9879_CLIPCTRL_SHIFT 3
129#define TFA9879_HPF_BP_MASK 0x0004
130#define TFA9879_HPF_BP_SHIFT 2
131#define TFA9879_DRC_BP_MASK 0x0002
132#define TFA9879_DRC_BP_SHIFT 1
133#define TFA9879_EQ_BP_MASK 0x0001
134#define TFA9879_EQ_BP_SHIFT 0
135
136/* TFA9879_DYNAMIC_RANGE_COMPR */
137#define TFA9879_AT_LVL_MASK 0xf000
138#define TFA9879_AT_LVL_SHIFT 12
139#define TFA9879_AT_RATE_MASK 0x0f00
140#define TFA9879_AT_RATE_SHIFT 8
141#define TFA9879_RL_LVL_MASK 0x00f0
142#define TFA9879_RL_LVL_SHIFT 4
143#define TFA9879_RL_RATE_MASK 0x000f
144#define TFA9879_RL_RATE_SHIFT 0
145
146/* TFA9879_BASS_TREBLE */
147#define TFA9879_G_TRBLE_MASK 0x3e00
148#define TFA9879_G_TRBLE_SHIFT 9
149#define TFA9879_F_TRBLE_MASK 0x0180
150#define TFA9879_F_TRBLE_SHIFT 7
151#define TFA9879_G_BASS_MASK 0x007c
152#define TFA9879_G_BASS_SHIFT 2
153#define TFA9879_F_BASS_MASK 0x0003
154#define TFA9879_F_BASS_SHIFT 0
155
156/* TFA9879_HIGH_PASS_FILTER */
157#define TFA9879_HP_CTRL_MASK 0x00ff
158#define TFA9879_HP_CTRL_SHIFT 0
159
160/* TFA9879_VOLUME_CONTROL */
161#define TFA9879_ZR_CRSS_MASK 0x1000
162#define TFA9879_ZR_CRSS_SHIFT 12
163#define TFA9879_VOL_MASK 0x00ff
164#define TFA9879_VOL_SHIFT 0
165
166/* TFA9879_MISC_CONTROL */
167#define TFA9879_DE_PHAS_MASK 0x0c00
168#define TFA9879_DE_PHAS_SHIFT 10
169#define TFA9879_H_MUTE_MASK 0x0200
170#define TFA9879_H_MUTE_SHIFT 9
171#define TFA9879_S_MUTE_MASK 0x0100
172#define TFA9879_S_MUTE_SHIFT 8
173#define TFA9879_P_LIM_MASK 0x00ff
174#define TFA9879_P_LIM_SHIFT 0
175
176/* TFA9879_MISC_STATUS */
177#define TFA9879_PS_MASK 0x4000
178#define TFA9879_PS_SHIFT 14
179#define TFA9879_PORA_MASK 0x2000
180#define TFA9879_PORA_SHIFT 13
181#define TFA9879_AMP_MASK 0x0600
182#define TFA9879_AMP_SHIFT 9
183#define TFA9879_IBP_2_MASK 0x0100
184#define TFA9879_IBP_2_SHIFT 8
185#define TFA9879_OFP_2_MASK 0x0080
186#define TFA9879_OFP_2_SHIFT 7
187#define TFA9879_UFP_2_MASK 0x0040
188#define TFA9879_UFP_2_SHIFT 6
189#define TFA9879_IBP_1_MASK 0x0020
190#define TFA9879_IBP_1_SHIFT 5
191#define TFA9879_OFP_1_MASK 0x0010
192#define TFA9879_OFP_1_SHIFT 4
193#define TFA9879_UFP_1_MASK 0x0008
194#define TFA9879_UFP_1_SHIFT 3
195#define TFA9879_OCPOKA_MASK 0x0004
196#define TFA9879_OCPOKA_SHIFT 2
197#define TFA9879_OCPOKB_MASK 0x0002
198#define TFA9879_OCPOKB_SHIFT 1
199#define TFA9879_OTPOK_MASK 0x0001
200#define TFA9879_OTPOK_SHIFT 0
201
202#endif
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index d67167920c2f..cc17e7e5126e 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -540,19 +540,11 @@ static struct snd_soc_dai_driver tlv320aic23_dai = {
540 .ops = &tlv320aic23_dai_ops, 540 .ops = &tlv320aic23_dai_ops,
541}; 541};
542 542
543static int tlv320aic23_suspend(struct snd_soc_codec *codec)
544{
545 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF);
546
547 return 0;
548}
549
550static int tlv320aic23_resume(struct snd_soc_codec *codec) 543static int tlv320aic23_resume(struct snd_soc_codec *codec)
551{ 544{
552 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); 545 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
553 regcache_mark_dirty(aic23->regmap); 546 regcache_mark_dirty(aic23->regmap);
554 regcache_sync(aic23->regmap); 547 regcache_sync(aic23->regmap);
555 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
556 548
557 return 0; 549 return 0;
558} 550}
@@ -562,9 +554,6 @@ static int tlv320aic23_codec_probe(struct snd_soc_codec *codec)
562 /* Reset codec */ 554 /* Reset codec */
563 snd_soc_write(codec, TLV320AIC23_RESET, 0); 555 snd_soc_write(codec, TLV320AIC23_RESET, 0);
564 556
565 /* power on device */
566 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
567
568 snd_soc_write(codec, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K); 557 snd_soc_write(codec, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K);
569 558
570 /* Unmute input */ 559 /* Unmute input */
@@ -589,18 +578,12 @@ static int tlv320aic23_codec_probe(struct snd_soc_codec *codec)
589 return 0; 578 return 0;
590} 579}
591 580
592static int tlv320aic23_remove(struct snd_soc_codec *codec)
593{
594 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF);
595 return 0;
596}
597
598static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = { 581static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = {
599 .probe = tlv320aic23_codec_probe, 582 .probe = tlv320aic23_codec_probe,
600 .remove = tlv320aic23_remove,
601 .suspend = tlv320aic23_suspend,
602 .resume = tlv320aic23_resume, 583 .resume = tlv320aic23_resume,
603 .set_bias_level = tlv320aic23_set_bias_level, 584 .set_bias_level = tlv320aic23_set_bias_level,
585 .suspend_bias_off = true,
586
604 .controls = tlv320aic23_snd_controls, 587 .controls = tlv320aic23_snd_controls,
605 .num_controls = ARRAY_SIZE(tlv320aic23_snd_controls), 588 .num_controls = ARRAY_SIZE(tlv320aic23_snd_controls),
606 .dapm_widgets = tlv320aic23_dapm_widgets, 589 .dapm_widgets = tlv320aic23_dapm_widgets,
diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c
index 145fe5b253d4..dc3223d6eca1 100644
--- a/sound/soc/codecs/tlv320aic31xx.c
+++ b/sound/soc/codecs/tlv320aic31xx.c
@@ -911,12 +911,13 @@ static int aic31xx_set_dai_sysclk(struct snd_soc_dai *codec_dai,
911 } 911 }
912 aic31xx->p_div = i; 912 aic31xx->p_div = i;
913 913
914 for (i = 0; aic31xx_divs[i].mclk_p != freq/aic31xx->p_div; i++) { 914 for (i = 0; i < ARRAY_SIZE(aic31xx_divs) &&
915 if (i == ARRAY_SIZE(aic31xx_divs)) { 915 aic31xx_divs[i].mclk_p != freq/aic31xx->p_div; i++)
916 dev_err(aic31xx->dev, "%s: Unsupported frequency %d\n", 916 ;
917 __func__, freq); 917 if (i == ARRAY_SIZE(aic31xx_divs)) {
918 return -EINVAL; 918 dev_err(aic31xx->dev, "%s: Unsupported frequency %d\n",
919 } 919 __func__, freq);
920 return -EINVAL;
920 } 921 }
921 922
922 /* set clock on MCLK, BCLK, or GPIO1 as PLL input */ 923 /* set clock on MCLK, BCLK, or GPIO1 as PLL input */
@@ -1056,18 +1057,6 @@ static int aic31xx_set_bias_level(struct snd_soc_codec *codec,
1056 return 0; 1057 return 0;
1057} 1058}
1058 1059
1059static int aic31xx_suspend(struct snd_soc_codec *codec)
1060{
1061 aic31xx_set_bias_level(codec, SND_SOC_BIAS_OFF);
1062 return 0;
1063}
1064
1065static int aic31xx_resume(struct snd_soc_codec *codec)
1066{
1067 aic31xx_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1068 return 0;
1069}
1070
1071static int aic31xx_codec_probe(struct snd_soc_codec *codec) 1060static int aic31xx_codec_probe(struct snd_soc_codec *codec)
1072{ 1061{
1073 int ret = 0; 1062 int ret = 0;
@@ -1110,8 +1099,6 @@ static int aic31xx_codec_remove(struct snd_soc_codec *codec)
1110{ 1099{
1111 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); 1100 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
1112 int i; 1101 int i;
1113 /* power down chip */
1114 aic31xx_set_bias_level(codec, SND_SOC_BIAS_OFF);
1115 1102
1116 for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++) 1103 for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++)
1117 regulator_unregister_notifier(aic31xx->supplies[i].consumer, 1104 regulator_unregister_notifier(aic31xx->supplies[i].consumer,
@@ -1123,9 +1110,9 @@ static int aic31xx_codec_remove(struct snd_soc_codec *codec)
1123static struct snd_soc_codec_driver soc_codec_driver_aic31xx = { 1110static struct snd_soc_codec_driver soc_codec_driver_aic31xx = {
1124 .probe = aic31xx_codec_probe, 1111 .probe = aic31xx_codec_probe,
1125 .remove = aic31xx_codec_remove, 1112 .remove = aic31xx_codec_remove,
1126 .suspend = aic31xx_suspend,
1127 .resume = aic31xx_resume,
1128 .set_bias_level = aic31xx_set_bias_level, 1113 .set_bias_level = aic31xx_set_bias_level,
1114 .suspend_bias_off = true,
1115
1129 .controls = aic31xx_snd_controls, 1116 .controls = aic31xx_snd_controls,
1130 .num_controls = ARRAY_SIZE(aic31xx_snd_controls), 1117 .num_controls = ARRAY_SIZE(aic31xx_snd_controls),
1131 .dapm_widgets = aic31xx_dapm_widgets, 1118 .dapm_widgets = aic31xx_dapm_widgets,
diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c
index 6ea662db2410..015467ed606b 100644
--- a/sound/soc/codecs/tlv320aic32x4.c
+++ b/sound/soc/codecs/tlv320aic32x4.c
@@ -597,18 +597,6 @@ static struct snd_soc_dai_driver aic32x4_dai = {
597 .symmetric_rates = 1, 597 .symmetric_rates = 1,
598}; 598};
599 599
600static int aic32x4_suspend(struct snd_soc_codec *codec)
601{
602 aic32x4_set_bias_level(codec, SND_SOC_BIAS_OFF);
603 return 0;
604}
605
606static int aic32x4_resume(struct snd_soc_codec *codec)
607{
608 aic32x4_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
609 return 0;
610}
611
612static int aic32x4_probe(struct snd_soc_codec *codec) 600static int aic32x4_probe(struct snd_soc_codec *codec)
613{ 601{
614 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); 602 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
@@ -654,8 +642,6 @@ static int aic32x4_probe(struct snd_soc_codec *codec)
654 snd_soc_write(codec, AIC32X4_RMICPGANIN, 642 snd_soc_write(codec, AIC32X4_RMICPGANIN,
655 AIC32X4_RMICPGANIN_CM1R_10K); 643 AIC32X4_RMICPGANIN_CM1R_10K);
656 644
657 aic32x4_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
658
659 /* 645 /*
660 * Workaround: for an unknown reason, the ADC needs to be powered up 646 * Workaround: for an unknown reason, the ADC needs to be powered up
661 * and down for the first capture to work properly. It seems related to 647 * and down for the first capture to work properly. It seems related to
@@ -669,18 +655,10 @@ static int aic32x4_probe(struct snd_soc_codec *codec)
669 return 0; 655 return 0;
670} 656}
671 657
672static int aic32x4_remove(struct snd_soc_codec *codec)
673{
674 aic32x4_set_bias_level(codec, SND_SOC_BIAS_OFF);
675 return 0;
676}
677
678static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = { 658static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = {
679 .probe = aic32x4_probe, 659 .probe = aic32x4_probe,
680 .remove = aic32x4_remove,
681 .suspend = aic32x4_suspend,
682 .resume = aic32x4_resume,
683 .set_bias_level = aic32x4_set_bias_level, 660 .set_bias_level = aic32x4_set_bias_level,
661 .suspend_bias_off = true,
684 662
685 .controls = aic32x4_snd_controls, 663 .controls = aic32x4_snd_controls,
686 .num_controls = ARRAY_SIZE(aic32x4_snd_controls), 664 .num_controls = ARRAY_SIZE(aic32x4_snd_controls),
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index f7c2a575a892..b7ebce054b4e 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -78,6 +78,8 @@ struct aic3x_priv {
78 struct aic3x_disable_nb disable_nb[AIC3X_NUM_SUPPLIES]; 78 struct aic3x_disable_nb disable_nb[AIC3X_NUM_SUPPLIES];
79 struct aic3x_setup_data *setup; 79 struct aic3x_setup_data *setup;
80 unsigned int sysclk; 80 unsigned int sysclk;
81 unsigned int dai_fmt;
82 unsigned int tdm_delay;
81 struct list_head list; 83 struct list_head list;
82 int master; 84 int master;
83 int gpio_reset; 85 int gpio_reset;
@@ -214,61 +216,78 @@ static int mic_bias_event(struct snd_soc_dapm_widget *w,
214 return 0; 216 return 0;
215} 217}
216 218
217static const char *aic3x_left_dac_mux[] = { "DAC_L1", "DAC_L3", "DAC_L2" }; 219static const char * const aic3x_left_dac_mux[] = {
218static const char *aic3x_right_dac_mux[] = { "DAC_R1", "DAC_R3", "DAC_R2" }; 220 "DAC_L1", "DAC_L3", "DAC_L2" };
219static const char *aic3x_left_hpcom_mux[] = 221static SOC_ENUM_SINGLE_DECL(aic3x_left_dac_enum, DAC_LINE_MUX, 6,
220 { "differential of HPLOUT", "constant VCM", "single-ended" }; 222 aic3x_left_dac_mux);
221static const char *aic3x_right_hpcom_mux[] = 223
222 { "differential of HPROUT", "constant VCM", "single-ended", 224static const char * const aic3x_right_dac_mux[] = {
223 "differential of HPLCOM", "external feedback" }; 225 "DAC_R1", "DAC_R3", "DAC_R2" };
224static const char *aic3x_linein_mode_mux[] = { "single-ended", "differential" }; 226static SOC_ENUM_SINGLE_DECL(aic3x_right_dac_enum, DAC_LINE_MUX, 4,
225static const char *aic3x_adc_hpf[] = 227 aic3x_right_dac_mux);
226 { "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" }; 228
227 229static const char * const aic3x_left_hpcom_mux[] = {
228#define LDAC_ENUM 0 230 "differential of HPLOUT", "constant VCM", "single-ended" };
229#define RDAC_ENUM 1 231static SOC_ENUM_SINGLE_DECL(aic3x_left_hpcom_enum, HPLCOM_CFG, 4,
230#define LHPCOM_ENUM 2 232 aic3x_left_hpcom_mux);
231#define RHPCOM_ENUM 3 233
232#define LINE1L_2_L_ENUM 4 234static const char * const aic3x_right_hpcom_mux[] = {
233#define LINE1L_2_R_ENUM 5 235 "differential of HPROUT", "constant VCM", "single-ended",
234#define LINE1R_2_L_ENUM 6 236 "differential of HPLCOM", "external feedback" };
235#define LINE1R_2_R_ENUM 7 237static SOC_ENUM_SINGLE_DECL(aic3x_right_hpcom_enum, HPRCOM_CFG, 3,
236#define LINE2L_ENUM 8 238 aic3x_right_hpcom_mux);
237#define LINE2R_ENUM 9 239
238#define ADC_HPF_ENUM 10 240static const char * const aic3x_linein_mode_mux[] = {
239 241 "single-ended", "differential" };
240static const struct soc_enum aic3x_enum[] = { 242static SOC_ENUM_SINGLE_DECL(aic3x_line1l_2_l_enum, LINE1L_2_LADC_CTRL, 7,
241 SOC_ENUM_SINGLE(DAC_LINE_MUX, 6, 3, aic3x_left_dac_mux), 243 aic3x_linein_mode_mux);
242 SOC_ENUM_SINGLE(DAC_LINE_MUX, 4, 3, aic3x_right_dac_mux), 244static SOC_ENUM_SINGLE_DECL(aic3x_line1l_2_r_enum, LINE1L_2_RADC_CTRL, 7,
243 SOC_ENUM_SINGLE(HPLCOM_CFG, 4, 3, aic3x_left_hpcom_mux), 245 aic3x_linein_mode_mux);
244 SOC_ENUM_SINGLE(HPRCOM_CFG, 3, 5, aic3x_right_hpcom_mux), 246static SOC_ENUM_SINGLE_DECL(aic3x_line1r_2_l_enum, LINE1R_2_LADC_CTRL, 7,
245 SOC_ENUM_SINGLE(LINE1L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux), 247 aic3x_linein_mode_mux);
246 SOC_ENUM_SINGLE(LINE1L_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux), 248static SOC_ENUM_SINGLE_DECL(aic3x_line1r_2_r_enum, LINE1R_2_RADC_CTRL, 7,
247 SOC_ENUM_SINGLE(LINE1R_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux), 249 aic3x_linein_mode_mux);
248 SOC_ENUM_SINGLE(LINE1R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux), 250static SOC_ENUM_SINGLE_DECL(aic3x_line2l_2_ldac_enum, LINE2L_2_LADC_CTRL, 7,
249 SOC_ENUM_SINGLE(LINE2L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux), 251 aic3x_linein_mode_mux);
250 SOC_ENUM_SINGLE(LINE2R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux), 252static SOC_ENUM_SINGLE_DECL(aic3x_line2r_2_rdac_enum, LINE2R_2_RADC_CTRL, 7,
251 SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf), 253 aic3x_linein_mode_mux);
252}; 254
253 255static const char * const aic3x_adc_hpf[] = {
254static const char *aic3x_agc_level[] = 256 "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" };
255 { "-5.5dB", "-8dB", "-10dB", "-12dB", "-14dB", "-17dB", "-20dB", "-24dB" }; 257static SOC_ENUM_DOUBLE_DECL(aic3x_adc_hpf_enum, AIC3X_CODEC_DFILT_CTRL, 6, 4,
256static const struct soc_enum aic3x_agc_level_enum[] = { 258 aic3x_adc_hpf);
257 SOC_ENUM_SINGLE(LAGC_CTRL_A, 4, 8, aic3x_agc_level), 259
258 SOC_ENUM_SINGLE(RAGC_CTRL_A, 4, 8, aic3x_agc_level), 260static const char * const aic3x_agc_level[] = {
259}; 261 "-5.5dB", "-8dB", "-10dB", "-12dB",
260 262 "-14dB", "-17dB", "-20dB", "-24dB" };
261static const char *aic3x_agc_attack[] = { "8ms", "11ms", "16ms", "20ms" }; 263static SOC_ENUM_SINGLE_DECL(aic3x_lagc_level_enum, LAGC_CTRL_A, 4,
262static const struct soc_enum aic3x_agc_attack_enum[] = { 264 aic3x_agc_level);
263 SOC_ENUM_SINGLE(LAGC_CTRL_A, 2, 4, aic3x_agc_attack), 265static SOC_ENUM_SINGLE_DECL(aic3x_ragc_level_enum, RAGC_CTRL_A, 4,
264 SOC_ENUM_SINGLE(RAGC_CTRL_A, 2, 4, aic3x_agc_attack), 266 aic3x_agc_level);
265}; 267
266 268static const char * const aic3x_agc_attack[] = {
267static const char *aic3x_agc_decay[] = { "100ms", "200ms", "400ms", "500ms" }; 269 "8ms", "11ms", "16ms", "20ms" };
268static const struct soc_enum aic3x_agc_decay_enum[] = { 270static SOC_ENUM_SINGLE_DECL(aic3x_lagc_attack_enum, LAGC_CTRL_A, 2,
269 SOC_ENUM_SINGLE(LAGC_CTRL_A, 0, 4, aic3x_agc_decay), 271 aic3x_agc_attack);
270 SOC_ENUM_SINGLE(RAGC_CTRL_A, 0, 4, aic3x_agc_decay), 272static SOC_ENUM_SINGLE_DECL(aic3x_ragc_attack_enum, RAGC_CTRL_A, 2,
271}; 273 aic3x_agc_attack);
274
275static const char * const aic3x_agc_decay[] = {
276 "100ms", "200ms", "400ms", "500ms" };
277static SOC_ENUM_SINGLE_DECL(aic3x_lagc_decay_enum, LAGC_CTRL_A, 0,
278 aic3x_agc_decay);
279static SOC_ENUM_SINGLE_DECL(aic3x_ragc_decay_enum, RAGC_CTRL_A, 0,
280 aic3x_agc_decay);
281
282static const char * const aic3x_poweron_time[] = {
283 "0us", "10us", "100us", "1ms", "10ms", "50ms",
284 "100ms", "200ms", "400ms", "800ms", "2s", "4s" };
285static SOC_ENUM_SINGLE_DECL(aic3x_poweron_time_enum, HPOUT_POP_REDUCTION, 4,
286 aic3x_poweron_time);
287
288static const char * const aic3x_rampup_step[] = { "0ms", "1ms", "2ms", "4ms" };
289static SOC_ENUM_SINGLE_DECL(aic3x_rampup_step_enum, HPOUT_POP_REDUCTION, 2,
290 aic3x_rampup_step);
272 291
273/* 292/*
274 * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps 293 * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps
@@ -383,12 +402,12 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = {
383 * adjust PGA to max value when ADC is on and will never go back. 402 * adjust PGA to max value when ADC is on and will never go back.
384 */ 403 */
385 SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0), 404 SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
386 SOC_ENUM("Left AGC Target level", aic3x_agc_level_enum[0]), 405 SOC_ENUM("Left AGC Target level", aic3x_lagc_level_enum),
387 SOC_ENUM("Right AGC Target level", aic3x_agc_level_enum[1]), 406 SOC_ENUM("Right AGC Target level", aic3x_ragc_level_enum),
388 SOC_ENUM("Left AGC Attack time", aic3x_agc_attack_enum[0]), 407 SOC_ENUM("Left AGC Attack time", aic3x_lagc_attack_enum),
389 SOC_ENUM("Right AGC Attack time", aic3x_agc_attack_enum[1]), 408 SOC_ENUM("Right AGC Attack time", aic3x_ragc_attack_enum),
390 SOC_ENUM("Left AGC Decay time", aic3x_agc_decay_enum[0]), 409 SOC_ENUM("Left AGC Decay time", aic3x_lagc_decay_enum),
391 SOC_ENUM("Right AGC Decay time", aic3x_agc_decay_enum[1]), 410 SOC_ENUM("Right AGC Decay time", aic3x_ragc_decay_enum),
392 411
393 /* De-emphasis */ 412 /* De-emphasis */
394 SOC_DOUBLE("De-emphasis Switch", AIC3X_CODEC_DFILT_CTRL, 2, 0, 0x01, 0), 413 SOC_DOUBLE("De-emphasis Switch", AIC3X_CODEC_DFILT_CTRL, 2, 0, 0x01, 0),
@@ -398,7 +417,11 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = {
398 0, 119, 0, adc_tlv), 417 0, 119, 0, adc_tlv),
399 SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1), 418 SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1),
400 419
401 SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]), 420 SOC_ENUM("ADC HPF Cut-off", aic3x_adc_hpf_enum),
421
422 /* Pop reduction */
423 SOC_ENUM("Output Driver Power-On time", aic3x_poweron_time_enum),
424 SOC_ENUM("Output Driver Ramp-up step", aic3x_rampup_step_enum),
402}; 425};
403 426
404static const struct snd_kcontrol_new aic3x_mono_controls[] = { 427static const struct snd_kcontrol_new aic3x_mono_controls[] = {
@@ -425,19 +448,19 @@ static const struct snd_kcontrol_new aic3x_classd_amp_gain_ctrl =
425 448
426/* Left DAC Mux */ 449/* Left DAC Mux */
427static const struct snd_kcontrol_new aic3x_left_dac_mux_controls = 450static const struct snd_kcontrol_new aic3x_left_dac_mux_controls =
428SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]); 451SOC_DAPM_ENUM("Route", aic3x_left_dac_enum);
429 452
430/* Right DAC Mux */ 453/* Right DAC Mux */
431static const struct snd_kcontrol_new aic3x_right_dac_mux_controls = 454static const struct snd_kcontrol_new aic3x_right_dac_mux_controls =
432SOC_DAPM_ENUM("Route", aic3x_enum[RDAC_ENUM]); 455SOC_DAPM_ENUM("Route", aic3x_right_dac_enum);
433 456
434/* Left HPCOM Mux */ 457/* Left HPCOM Mux */
435static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls = 458static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls =
436SOC_DAPM_ENUM("Route", aic3x_enum[LHPCOM_ENUM]); 459SOC_DAPM_ENUM("Route", aic3x_left_hpcom_enum);
437 460
438/* Right HPCOM Mux */ 461/* Right HPCOM Mux */
439static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls = 462static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls =
440SOC_DAPM_ENUM("Route", aic3x_enum[RHPCOM_ENUM]); 463SOC_DAPM_ENUM("Route", aic3x_right_hpcom_enum);
441 464
442/* Left Line Mixer */ 465/* Left Line Mixer */
443static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = { 466static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = {
@@ -529,23 +552,23 @@ static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = {
529 552
530/* Left Line1 Mux */ 553/* Left Line1 Mux */
531static const struct snd_kcontrol_new aic3x_left_line1l_mux_controls = 554static const struct snd_kcontrol_new aic3x_left_line1l_mux_controls =
532SOC_DAPM_ENUM("Route", aic3x_enum[LINE1L_2_L_ENUM]); 555SOC_DAPM_ENUM("Route", aic3x_line1l_2_l_enum);
533static const struct snd_kcontrol_new aic3x_right_line1l_mux_controls = 556static const struct snd_kcontrol_new aic3x_right_line1l_mux_controls =
534SOC_DAPM_ENUM("Route", aic3x_enum[LINE1L_2_R_ENUM]); 557SOC_DAPM_ENUM("Route", aic3x_line1l_2_r_enum);
535 558
536/* Right Line1 Mux */ 559/* Right Line1 Mux */
537static const struct snd_kcontrol_new aic3x_right_line1r_mux_controls = 560static const struct snd_kcontrol_new aic3x_right_line1r_mux_controls =
538SOC_DAPM_ENUM("Route", aic3x_enum[LINE1R_2_R_ENUM]); 561SOC_DAPM_ENUM("Route", aic3x_line1r_2_r_enum);
539static const struct snd_kcontrol_new aic3x_left_line1r_mux_controls = 562static const struct snd_kcontrol_new aic3x_left_line1r_mux_controls =
540SOC_DAPM_ENUM("Route", aic3x_enum[LINE1R_2_L_ENUM]); 563SOC_DAPM_ENUM("Route", aic3x_line1r_2_l_enum);
541 564
542/* Left Line2 Mux */ 565/* Left Line2 Mux */
543static const struct snd_kcontrol_new aic3x_left_line2_mux_controls = 566static const struct snd_kcontrol_new aic3x_left_line2_mux_controls =
544SOC_DAPM_ENUM("Route", aic3x_enum[LINE2L_ENUM]); 567SOC_DAPM_ENUM("Route", aic3x_line2l_2_ldac_enum);
545 568
546/* Right Line2 Mux */ 569/* Right Line2 Mux */
547static const struct snd_kcontrol_new aic3x_right_line2_mux_controls = 570static const struct snd_kcontrol_new aic3x_right_line2_mux_controls =
548SOC_DAPM_ENUM("Route", aic3x_enum[LINE2R_ENUM]); 571SOC_DAPM_ENUM("Route", aic3x_line2r_2_rdac_enum);
549 572
550static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { 573static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
551 /* Left DAC to Left Outputs */ 574 /* Left DAC to Left Outputs */
@@ -1009,6 +1032,25 @@ found:
1009 return 0; 1032 return 0;
1010} 1033}
1011 1034
1035static int aic3x_prepare(struct snd_pcm_substream *substream,
1036 struct snd_soc_dai *dai)
1037{
1038 struct snd_soc_codec *codec = dai->codec;
1039 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
1040 int delay = 0;
1041
1042 /* TDM slot selection only valid in DSP_A/_B mode */
1043 if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_A)
1044 delay += (aic3x->tdm_delay + 1);
1045 else if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_B)
1046 delay += aic3x->tdm_delay;
1047
1048 /* Configure data delay */
1049 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, aic3x->tdm_delay);
1050
1051 return 0;
1052}
1053
1012static int aic3x_mute(struct snd_soc_dai *dai, int mute) 1054static int aic3x_mute(struct snd_soc_dai *dai, int mute)
1013{ 1055{
1014 struct snd_soc_codec *codec = dai->codec; 1056 struct snd_soc_codec *codec = dai->codec;
@@ -1048,7 +1090,6 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
1048 struct snd_soc_codec *codec = codec_dai->codec; 1090 struct snd_soc_codec *codec = codec_dai->codec;
1049 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 1091 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
1050 u8 iface_areg, iface_breg; 1092 u8 iface_areg, iface_breg;
1051 int delay = 0;
1052 1093
1053 iface_areg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f; 1094 iface_areg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f;
1054 iface_breg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f; 1095 iface_breg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f;
@@ -1076,7 +1117,6 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
1076 case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF): 1117 case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
1077 break; 1118 break;
1078 case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF): 1119 case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
1079 delay = 1;
1080 case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF): 1120 case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
1081 iface_breg |= (0x01 << 6); 1121 iface_breg |= (0x01 << 6);
1082 break; 1122 break;
@@ -1090,10 +1130,45 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
1090 return -EINVAL; 1130 return -EINVAL;
1091 } 1131 }
1092 1132
1133 aic3x->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
1134
1093 /* set iface */ 1135 /* set iface */
1094 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg); 1136 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg);
1095 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg); 1137 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg);
1096 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, delay); 1138
1139 return 0;
1140}
1141
1142static int aic3x_set_dai_tdm_slot(struct snd_soc_dai *codec_dai,
1143 unsigned int tx_mask, unsigned int rx_mask,
1144 int slots, int slot_width)
1145{
1146 struct snd_soc_codec *codec = codec_dai->codec;
1147 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
1148 unsigned int lsb;
1149
1150 if (tx_mask != rx_mask) {
1151 dev_err(codec->dev, "tx and rx masks must be symmetric\n");
1152 return -EINVAL;
1153 }
1154
1155 if (unlikely(!tx_mask)) {
1156 dev_err(codec->dev, "tx and rx masks need to be non 0\n");
1157 return -EINVAL;
1158 }
1159
1160 /* TDM based on DSP mode requires slots to be adjacent */
1161 lsb = __ffs(tx_mask);
1162 if ((lsb + 1) != __fls(tx_mask)) {
1163 dev_err(codec->dev, "Invalid mask, slots must be adjacent\n");
1164 return -EINVAL;
1165 }
1166
1167 aic3x->tdm_delay = lsb * slot_width;
1168
1169 /* DOUT in high-impedance on inactive bit clocks */
1170 snd_soc_update_bits(codec, AIC3X_ASD_INTF_CTRLA,
1171 DOUT_TRISTATE, DOUT_TRISTATE);
1097 1172
1098 return 0; 1173 return 0;
1099} 1174}
@@ -1212,9 +1287,11 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1212 1287
1213static const struct snd_soc_dai_ops aic3x_dai_ops = { 1288static const struct snd_soc_dai_ops aic3x_dai_ops = {
1214 .hw_params = aic3x_hw_params, 1289 .hw_params = aic3x_hw_params,
1290 .prepare = aic3x_prepare,
1215 .digital_mute = aic3x_mute, 1291 .digital_mute = aic3x_mute,
1216 .set_sysclk = aic3x_set_dai_sysclk, 1292 .set_sysclk = aic3x_set_dai_sysclk,
1217 .set_fmt = aic3x_set_dai_fmt, 1293 .set_fmt = aic3x_set_dai_fmt,
1294 .set_tdm_slot = aic3x_set_dai_tdm_slot,
1218}; 1295};
1219 1296
1220static struct snd_soc_dai_driver aic3x_dai = { 1297static struct snd_soc_dai_driver aic3x_dai = {
@@ -1414,7 +1491,6 @@ static int aic3x_remove(struct snd_soc_codec *codec)
1414 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 1491 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
1415 int i; 1492 int i;
1416 1493
1417 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
1418 list_del(&aic3x->list); 1494 list_del(&aic3x->list);
1419 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) 1495 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
1420 regulator_unregister_notifier(aic3x->supplies[i].consumer, 1496 regulator_unregister_notifier(aic3x->supplies[i].consumer,
diff --git a/sound/soc/codecs/tlv320aic3x.h b/sound/soc/codecs/tlv320aic3x.h
index e521ac3ddde8..89fa692df206 100644
--- a/sound/soc/codecs/tlv320aic3x.h
+++ b/sound/soc/codecs/tlv320aic3x.h
@@ -169,6 +169,7 @@
169/* Audio serial data interface control register A bits */ 169/* Audio serial data interface control register A bits */
170#define BIT_CLK_MASTER 0x80 170#define BIT_CLK_MASTER 0x80
171#define WORD_CLK_MASTER 0x40 171#define WORD_CLK_MASTER 0x40
172#define DOUT_TRISTATE 0x20
172 173
173/* Codec Datapath setup register 7 */ 174/* Codec Datapath setup register 7 */
174#define FSREF_44100 (1 << 7) 175#define FSREF_44100 (1 << 7)
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index e21ed934bdbf..0fe2ced5b09f 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -1436,8 +1436,6 @@ static int dac33_soc_remove(struct snd_soc_codec *codec)
1436{ 1436{
1437 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 1437 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1438 1438
1439 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
1440
1441 if (dac33->irq >= 0) { 1439 if (dac33->irq >= 0) {
1442 free_irq(dac33->irq, dac33->codec); 1440 free_irq(dac33->irq, dac33->codec);
1443 destroy_workqueue(dac33->dac33_wq); 1441 destroy_workqueue(dac33->dac33_wq);
diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c
new file mode 100644
index 000000000000..1d1205702d23
--- /dev/null
+++ b/sound/soc/codecs/ts3a227e.c
@@ -0,0 +1,314 @@
1/*
2 * TS3A227E Autonomous Audio Accessory Detection and Configuration Switch
3 *
4 * Copyright (C) 2014 Google, Inc.
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
11#include <linux/gpio.h>
12#include <linux/i2c.h>
13#include <linux/init.h>
14#include <linux/input.h>
15#include <linux/module.h>
16#include <linux/of_gpio.h>
17#include <linux/regmap.h>
18
19#include <sound/core.h>
20#include <sound/jack.h>
21#include <sound/soc.h>
22
23struct ts3a227e {
24 struct regmap *regmap;
25 struct snd_soc_jack *jack;
26 bool plugged;
27 bool mic_present;
28 unsigned int buttons_held;
29};
30
31/* Button values to be reported on the jack */
32static const int ts3a227e_buttons[] = {
33 SND_JACK_BTN_0,
34 SND_JACK_BTN_1,
35 SND_JACK_BTN_2,
36 SND_JACK_BTN_3,
37};
38
39#define TS3A227E_NUM_BUTTONS 4
40#define TS3A227E_JACK_MASK (SND_JACK_HEADPHONE | \
41 SND_JACK_MICROPHONE | \
42 SND_JACK_BTN_0 | \
43 SND_JACK_BTN_1 | \
44 SND_JACK_BTN_2 | \
45 SND_JACK_BTN_3)
46
47/* TS3A227E registers */
48#define TS3A227E_REG_DEVICE_ID 0x00
49#define TS3A227E_REG_INTERRUPT 0x01
50#define TS3A227E_REG_KP_INTERRUPT 0x02
51#define TS3A227E_REG_INTERRUPT_DISABLE 0x03
52#define TS3A227E_REG_SETTING_1 0x04
53#define TS3A227E_REG_SETTING_2 0x05
54#define TS3A227E_REG_SETTING_3 0x06
55#define TS3A227E_REG_SWITCH_CONTROL_1 0x07
56#define TS3A227E_REG_SWITCH_CONTROL_2 0x08
57#define TS3A227E_REG_SWITCH_STATUS_1 0x09
58#define TS3A227E_REG_SWITCH_STATUS_2 0x0a
59#define TS3A227E_REG_ACCESSORY_STATUS 0x0b
60#define TS3A227E_REG_ADC_OUTPUT 0x0c
61#define TS3A227E_REG_KP_THRESHOLD_1 0x0d
62#define TS3A227E_REG_KP_THRESHOLD_2 0x0e
63#define TS3A227E_REG_KP_THRESHOLD_3 0x0f
64
65/* TS3A227E_REG_INTERRUPT 0x01 */
66#define INS_REM_EVENT 0x01
67#define DETECTION_COMPLETE_EVENT 0x02
68
69/* TS3A227E_REG_KP_INTERRUPT 0x02 */
70#define PRESS_MASK(idx) (0x01 << (2 * (idx)))
71#define RELEASE_MASK(idx) (0x02 << (2 * (idx)))
72
73/* TS3A227E_REG_INTERRUPT_DISABLE 0x03 */
74#define INS_REM_INT_DISABLE 0x01
75#define DETECTION_COMPLETE_INT_DISABLE 0x02
76#define ADC_COMPLETE_INT_DISABLE 0x04
77#define INTB_DISABLE 0x08
78
79/* TS3A227E_REG_SETTING_2 0x05 */
80#define KP_ENABLE 0x04
81
82/* TS3A227E_REG_ACCESSORY_STATUS 0x0b */
83#define TYPE_3_POLE 0x01
84#define TYPE_4_POLE_OMTP 0x02
85#define TYPE_4_POLE_STANDARD 0x04
86#define JACK_INSERTED 0x08
87#define EITHER_MIC_MASK (TYPE_4_POLE_OMTP | TYPE_4_POLE_STANDARD)
88
89static const struct reg_default ts3a227e_reg_defaults[] = {
90 { TS3A227E_REG_DEVICE_ID, 0x10 },
91 { TS3A227E_REG_INTERRUPT, 0x00 },
92 { TS3A227E_REG_KP_INTERRUPT, 0x00 },
93 { TS3A227E_REG_INTERRUPT_DISABLE, 0x08 },
94 { TS3A227E_REG_SETTING_1, 0x23 },
95 { TS3A227E_REG_SETTING_2, 0x00 },
96 { TS3A227E_REG_SETTING_3, 0x0e },
97 { TS3A227E_REG_SWITCH_CONTROL_1, 0x00 },
98 { TS3A227E_REG_SWITCH_CONTROL_2, 0x00 },
99 { TS3A227E_REG_SWITCH_STATUS_1, 0x0c },
100 { TS3A227E_REG_SWITCH_STATUS_2, 0x00 },
101 { TS3A227E_REG_ACCESSORY_STATUS, 0x00 },
102 { TS3A227E_REG_ADC_OUTPUT, 0x00 },
103 { TS3A227E_REG_KP_THRESHOLD_1, 0x20 },
104 { TS3A227E_REG_KP_THRESHOLD_2, 0x40 },
105 { TS3A227E_REG_KP_THRESHOLD_3, 0x68 },
106};
107
108static bool ts3a227e_readable_reg(struct device *dev, unsigned int reg)
109{
110 switch (reg) {
111 case TS3A227E_REG_DEVICE_ID ... TS3A227E_REG_KP_THRESHOLD_3:
112 return true;
113 default:
114 return false;
115 }
116}
117
118static bool ts3a227e_writeable_reg(struct device *dev, unsigned int reg)
119{
120 switch (reg) {
121 case TS3A227E_REG_INTERRUPT_DISABLE ... TS3A227E_REG_SWITCH_CONTROL_2:
122 case TS3A227E_REG_KP_THRESHOLD_1 ... TS3A227E_REG_KP_THRESHOLD_3:
123 return true;
124 default:
125 return false;
126 }
127}
128
129static bool ts3a227e_volatile_reg(struct device *dev, unsigned int reg)
130{
131 switch (reg) {
132 case TS3A227E_REG_INTERRUPT ... TS3A227E_REG_INTERRUPT_DISABLE:
133 case TS3A227E_REG_SETTING_2:
134 case TS3A227E_REG_SWITCH_STATUS_1 ... TS3A227E_REG_ADC_OUTPUT:
135 return true;
136 default:
137 return false;
138 }
139}
140
141static void ts3a227e_jack_report(struct ts3a227e *ts3a227e)
142{
143 unsigned int i;
144 int report = 0;
145
146 if (!ts3a227e->jack)
147 return;
148
149 if (ts3a227e->plugged)
150 report = SND_JACK_HEADPHONE;
151 if (ts3a227e->mic_present)
152 report |= SND_JACK_MICROPHONE;
153 for (i = 0; i < TS3A227E_NUM_BUTTONS; i++) {
154 if (ts3a227e->buttons_held & (1 << i))
155 report |= ts3a227e_buttons[i];
156 }
157 snd_soc_jack_report(ts3a227e->jack, report, TS3A227E_JACK_MASK);
158}
159
160static void ts3a227e_new_jack_state(struct ts3a227e *ts3a227e, unsigned acc_reg)
161{
162 bool plugged, mic_present;
163
164 plugged = !!(acc_reg & JACK_INSERTED);
165 mic_present = plugged && !!(acc_reg & EITHER_MIC_MASK);
166
167 ts3a227e->plugged = plugged;
168
169 if (mic_present != ts3a227e->mic_present) {
170 ts3a227e->mic_present = mic_present;
171 ts3a227e->buttons_held = 0;
172 if (mic_present) {
173 /* Enable key press detection. */
174 regmap_update_bits(ts3a227e->regmap,
175 TS3A227E_REG_SETTING_2,
176 KP_ENABLE, KP_ENABLE);
177 }
178 }
179}
180
181static irqreturn_t ts3a227e_interrupt(int irq, void *data)
182{
183 struct ts3a227e *ts3a227e = (struct ts3a227e *)data;
184 struct regmap *regmap = ts3a227e->regmap;
185 unsigned int int_reg, kp_int_reg, acc_reg, i;
186
187 /* Check for plug/unplug. */
188 regmap_read(regmap, TS3A227E_REG_INTERRUPT, &int_reg);
189 if (int_reg & (DETECTION_COMPLETE_EVENT | INS_REM_EVENT)) {
190 regmap_read(regmap, TS3A227E_REG_ACCESSORY_STATUS, &acc_reg);
191 ts3a227e_new_jack_state(ts3a227e, acc_reg);
192 }
193
194 /* Report any key events. */
195 regmap_read(regmap, TS3A227E_REG_KP_INTERRUPT, &kp_int_reg);
196 for (i = 0; i < TS3A227E_NUM_BUTTONS; i++) {
197 if (kp_int_reg & PRESS_MASK(i))
198 ts3a227e->buttons_held |= (1 << i);
199 if (kp_int_reg & RELEASE_MASK(i))
200 ts3a227e->buttons_held &= ~(1 << i);
201 }
202
203 ts3a227e_jack_report(ts3a227e);
204
205 return IRQ_HANDLED;
206}
207
208/**
209 * ts3a227e_enable_jack_detect - Specify a jack for event reporting
210 *
211 * @component: component to register the jack with
212 * @jack: jack to use to report headset and button events on
213 *
214 * After this function has been called the headset insert/remove and button
215 * events 0-3 will be routed to the given jack. Jack can be null to stop
216 * reporting.
217 */
218int ts3a227e_enable_jack_detect(struct snd_soc_component *component,
219 struct snd_soc_jack *jack)
220{
221 struct ts3a227e *ts3a227e = snd_soc_component_get_drvdata(component);
222
223 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA);
224 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
225 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
226 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
227
228 ts3a227e->jack = jack;
229 ts3a227e_jack_report(ts3a227e);
230
231 return 0;
232}
233EXPORT_SYMBOL_GPL(ts3a227e_enable_jack_detect);
234
235static struct snd_soc_component_driver ts3a227e_soc_driver;
236
237static const struct regmap_config ts3a227e_regmap_config = {
238 .val_bits = 8,
239 .reg_bits = 8,
240
241 .max_register = TS3A227E_REG_KP_THRESHOLD_3,
242 .readable_reg = ts3a227e_readable_reg,
243 .writeable_reg = ts3a227e_writeable_reg,
244 .volatile_reg = ts3a227e_volatile_reg,
245
246 .cache_type = REGCACHE_RBTREE,
247 .reg_defaults = ts3a227e_reg_defaults,
248 .num_reg_defaults = ARRAY_SIZE(ts3a227e_reg_defaults),
249};
250
251static int ts3a227e_i2c_probe(struct i2c_client *i2c,
252 const struct i2c_device_id *id)
253{
254 struct ts3a227e *ts3a227e;
255 struct device *dev = &i2c->dev;
256 int ret;
257
258 ts3a227e = devm_kzalloc(&i2c->dev, sizeof(*ts3a227e), GFP_KERNEL);
259 if (ts3a227e == NULL)
260 return -ENOMEM;
261
262 i2c_set_clientdata(i2c, ts3a227e);
263
264 ts3a227e->regmap = devm_regmap_init_i2c(i2c, &ts3a227e_regmap_config);
265 if (IS_ERR(ts3a227e->regmap))
266 return PTR_ERR(ts3a227e->regmap);
267
268 ret = devm_request_threaded_irq(dev, i2c->irq, NULL, ts3a227e_interrupt,
269 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
270 "TS3A227E", ts3a227e);
271 if (ret) {
272 dev_err(dev, "Cannot request irq %d (%d)\n", i2c->irq, ret);
273 return ret;
274 }
275
276 ret = devm_snd_soc_register_component(&i2c->dev, &ts3a227e_soc_driver,
277 NULL, 0);
278 if (ret)
279 return ret;
280
281 /* Enable interrupts except for ADC complete. */
282 regmap_update_bits(ts3a227e->regmap, TS3A227E_REG_INTERRUPT_DISABLE,
283 INTB_DISABLE | ADC_COMPLETE_INT_DISABLE,
284 ADC_COMPLETE_INT_DISABLE);
285
286 return 0;
287}
288
289static const struct i2c_device_id ts3a227e_i2c_ids[] = {
290 { "ts3a227e", 0 },
291 { }
292};
293MODULE_DEVICE_TABLE(i2c, ts3a227e_i2c_ids);
294
295static const struct of_device_id ts3a227e_of_match[] = {
296 { .compatible = "ti,ts3a227e", },
297 { }
298};
299MODULE_DEVICE_TABLE(of, ts3a227e_of_match);
300
301static struct i2c_driver ts3a227e_driver = {
302 .driver = {
303 .name = "ts3a227e",
304 .owner = THIS_MODULE,
305 .of_match_table = of_match_ptr(ts3a227e_of_match),
306 },
307 .probe = ts3a227e_i2c_probe,
308 .id_table = ts3a227e_i2c_ids,
309};
310module_i2c_driver(ts3a227e_driver);
311
312MODULE_DESCRIPTION("ASoC ts3a227e driver");
313MODULE_AUTHOR("Dylan Reid <dgreid@chromium.org>");
314MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/ts3a227e.h b/sound/soc/codecs/ts3a227e.h
new file mode 100644
index 000000000000..e2acf9c5bebe
--- /dev/null
+++ b/sound/soc/codecs/ts3a227e.h
@@ -0,0 +1,17 @@
1/*
2 * TS3A227E Autonous Audio Accessory Detection and Configureation Switch
3 *
4 * Copyright (C) 2014 Google, Inc.
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
11#ifndef _TS3A227E_H
12#define _TS3A227E_H
13
14int ts3a227e_enable_jack_detect(struct snd_soc_component *component,
15 struct snd_soc_jack *jack);
16
17#endif
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index b6b0cb399599..27f3b21effb2 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -2177,8 +2177,6 @@ static int twl4030_soc_remove(struct snd_soc_codec *codec)
2177 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 2177 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
2178 struct twl4030_codec_data *pdata = twl4030->pdata; 2178 struct twl4030_codec_data *pdata = twl4030->pdata;
2179 2179
2180 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
2181
2182 if (pdata && pdata->hs_extmute && gpio_is_valid(pdata->hs_extmute_gpio)) 2180 if (pdata && pdata->hs_extmute && gpio_is_valid(pdata->hs_extmute_gpio))
2183 gpio_free(pdata->hs_extmute_gpio); 2181 gpio_free(pdata->hs_extmute_gpio);
2184 2182
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index 0f6067f04e29..5ff2b1e4638e 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -1095,25 +1095,6 @@ static struct snd_soc_dai_driver twl6040_dai[] = {
1095}, 1095},
1096}; 1096};
1097 1097
1098#ifdef CONFIG_PM
1099static int twl6040_suspend(struct snd_soc_codec *codec)
1100{
1101 twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
1102
1103 return 0;
1104}
1105
1106static int twl6040_resume(struct snd_soc_codec *codec)
1107{
1108 twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1109
1110 return 0;
1111}
1112#else
1113#define twl6040_suspend NULL
1114#define twl6040_resume NULL
1115#endif
1116
1117static int twl6040_probe(struct snd_soc_codec *codec) 1098static int twl6040_probe(struct snd_soc_codec *codec)
1118{ 1099{
1119 struct twl6040_data *priv; 1100 struct twl6040_data *priv;
@@ -1160,7 +1141,6 @@ static int twl6040_remove(struct snd_soc_codec *codec)
1160 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 1141 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1161 1142
1162 free_irq(priv->plug_irq, codec); 1143 free_irq(priv->plug_irq, codec);
1163 twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
1164 1144
1165 return 0; 1145 return 0;
1166} 1146}
@@ -1168,11 +1148,10 @@ static int twl6040_remove(struct snd_soc_codec *codec)
1168static struct snd_soc_codec_driver soc_codec_dev_twl6040 = { 1148static struct snd_soc_codec_driver soc_codec_dev_twl6040 = {
1169 .probe = twl6040_probe, 1149 .probe = twl6040_probe,
1170 .remove = twl6040_remove, 1150 .remove = twl6040_remove,
1171 .suspend = twl6040_suspend,
1172 .resume = twl6040_resume,
1173 .read = twl6040_read, 1151 .read = twl6040_read,
1174 .write = twl6040_write, 1152 .write = twl6040_write,
1175 .set_bias_level = twl6040_set_bias_level, 1153 .set_bias_level = twl6040_set_bias_level,
1154 .suspend_bias_off = true,
1176 .ignore_pmdown_time = true, 1155 .ignore_pmdown_time = true,
1177 1156
1178 .controls = twl6040_snd_controls, 1157 .controls = twl6040_snd_controls,
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index 32b2f78aa62c..4056260a502e 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -518,11 +518,6 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec)
518 518
519 uda134x_reset(codec); 519 uda134x_reset(codec);
520 520
521 if (pd->is_powered_on_standby)
522 uda134x_set_bias_level(codec, SND_SOC_BIAS_ON);
523 else
524 uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
525
526 if (pd->model == UDA134X_UDA1341) { 521 if (pd->model == UDA134X_UDA1341) {
527 widgets = uda1341_dapm_widgets; 522 widgets = uda1341_dapm_widgets;
528 num_widgets = ARRAY_SIZE(uda1341_dapm_widgets); 523 num_widgets = ARRAY_SIZE(uda1341_dapm_widgets);
@@ -574,44 +569,21 @@ static int uda134x_soc_remove(struct snd_soc_codec *codec)
574{ 569{
575 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); 570 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
576 571
577 uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
578 uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
579
580 kfree(uda134x); 572 kfree(uda134x);
581 return 0; 573 return 0;
582} 574}
583 575
584#if defined(CONFIG_PM)
585static int uda134x_soc_suspend(struct snd_soc_codec *codec)
586{
587 uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
588 uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
589 return 0;
590}
591
592static int uda134x_soc_resume(struct snd_soc_codec *codec)
593{
594 uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
595 uda134x_set_bias_level(codec, SND_SOC_BIAS_ON);
596 return 0;
597}
598#else
599#define uda134x_soc_suspend NULL
600#define uda134x_soc_resume NULL
601#endif /* CONFIG_PM */
602
603static struct snd_soc_codec_driver soc_codec_dev_uda134x = { 576static struct snd_soc_codec_driver soc_codec_dev_uda134x = {
604 .probe = uda134x_soc_probe, 577 .probe = uda134x_soc_probe,
605 .remove = uda134x_soc_remove, 578 .remove = uda134x_soc_remove,
606 .suspend = uda134x_soc_suspend,
607 .resume = uda134x_soc_resume,
608 .reg_cache_size = sizeof(uda134x_reg), 579 .reg_cache_size = sizeof(uda134x_reg),
609 .reg_word_size = sizeof(u8), 580 .reg_word_size = sizeof(u8),
610 .reg_cache_default = uda134x_reg, 581 .reg_cache_default = uda134x_reg,
611 .reg_cache_step = 1, 582 .reg_cache_step = 1,
612 .read = uda134x_read_reg_cache, 583 .read = uda134x_read_reg_cache,
613 .write = uda134x_write,
614 .set_bias_level = uda134x_set_bias_level, 584 .set_bias_level = uda134x_set_bias_level,
585 .suspend_bias_off = true,
586
615 .dapm_widgets = uda134x_dapm_widgets, 587 .dapm_widgets = uda134x_dapm_widgets,
616 .num_dapm_widgets = ARRAY_SIZE(uda134x_dapm_widgets), 588 .num_dapm_widgets = ARRAY_SIZE(uda134x_dapm_widgets),
617 .dapm_routes = uda134x_dapm_routes, 589 .dapm_routes = uda134x_dapm_routes,
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index e62e70781ec2..dc7778b6dd7f 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -693,18 +693,6 @@ static struct snd_soc_dai_driver uda1380_dai[] = {
693}, 693},
694}; 694};
695 695
696static int uda1380_suspend(struct snd_soc_codec *codec)
697{
698 uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF);
699 return 0;
700}
701
702static int uda1380_resume(struct snd_soc_codec *codec)
703{
704 uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
705 return 0;
706}
707
708static int uda1380_probe(struct snd_soc_codec *codec) 696static int uda1380_probe(struct snd_soc_codec *codec)
709{ 697{
710 struct uda1380_platform_data *pdata =codec->dev->platform_data; 698 struct uda1380_platform_data *pdata =codec->dev->platform_data;
@@ -739,8 +727,6 @@ static int uda1380_probe(struct snd_soc_codec *codec)
739 727
740 INIT_WORK(&uda1380->work, uda1380_flush_work); 728 INIT_WORK(&uda1380->work, uda1380_flush_work);
741 729
742 /* power on device */
743 uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
744 /* set clock input */ 730 /* set clock input */
745 switch (pdata->dac_clk) { 731 switch (pdata->dac_clk) {
746 case UDA1380_DAC_CLK_SYSCLK: 732 case UDA1380_DAC_CLK_SYSCLK:
@@ -766,8 +752,6 @@ static int uda1380_remove(struct snd_soc_codec *codec)
766{ 752{
767 struct uda1380_platform_data *pdata =codec->dev->platform_data; 753 struct uda1380_platform_data *pdata =codec->dev->platform_data;
768 754
769 uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF);
770
771 gpio_free(pdata->gpio_reset); 755 gpio_free(pdata->gpio_reset);
772 gpio_free(pdata->gpio_power); 756 gpio_free(pdata->gpio_power);
773 757
@@ -777,11 +761,11 @@ static int uda1380_remove(struct snd_soc_codec *codec)
777static struct snd_soc_codec_driver soc_codec_dev_uda1380 = { 761static struct snd_soc_codec_driver soc_codec_dev_uda1380 = {
778 .probe = uda1380_probe, 762 .probe = uda1380_probe,
779 .remove = uda1380_remove, 763 .remove = uda1380_remove,
780 .suspend = uda1380_suspend,
781 .resume = uda1380_resume,
782 .read = uda1380_read_reg_cache, 764 .read = uda1380_read_reg_cache,
783 .write = uda1380_write, 765 .write = uda1380_write,
784 .set_bias_level = uda1380_set_bias_level, 766 .set_bias_level = uda1380_set_bias_level,
767 .suspend_bias_off = true,
768
785 .reg_cache_size = ARRAY_SIZE(uda1380_reg), 769 .reg_cache_size = ARRAY_SIZE(uda1380_reg),
786 .reg_word_size = sizeof(u16), 770 .reg_word_size = sizeof(u16),
787 .reg_cache_default = uda1380_reg, 771 .reg_cache_default = uda1380_reg,
diff --git a/sound/soc/codecs/wl1273.c b/sound/soc/codecs/wl1273.c
index f3d4e88d0b7b..00aea4100bb3 100644
--- a/sound/soc/codecs/wl1273.c
+++ b/sound/soc/codecs/wl1273.c
@@ -452,7 +452,6 @@ static int wl1273_probe(struct snd_soc_codec *codec)
452{ 452{
453 struct wl1273_core **core = codec->dev->platform_data; 453 struct wl1273_core **core = codec->dev->platform_data;
454 struct wl1273_priv *wl1273; 454 struct wl1273_priv *wl1273;
455 int r;
456 455
457 dev_dbg(codec->dev, "%s.\n", __func__); 456 dev_dbg(codec->dev, "%s.\n", __func__);
458 457
@@ -470,12 +469,7 @@ static int wl1273_probe(struct snd_soc_codec *codec)
470 469
471 snd_soc_codec_set_drvdata(codec, wl1273); 470 snd_soc_codec_set_drvdata(codec, wl1273);
472 471
473 r = snd_soc_add_codec_controls(codec, wl1273_controls, 472 return 0;
474 ARRAY_SIZE(wl1273_controls));
475 if (r)
476 kfree(wl1273);
477
478 return r;
479} 473}
480 474
481static int wl1273_remove(struct snd_soc_codec *codec) 475static int wl1273_remove(struct snd_soc_codec *codec)
@@ -492,6 +486,8 @@ static struct snd_soc_codec_driver soc_codec_dev_wl1273 = {
492 .probe = wl1273_probe, 486 .probe = wl1273_probe,
493 .remove = wl1273_remove, 487 .remove = wl1273_remove,
494 488
489 .controls = wl1273_controls,
490 .num_controls = ARRAY_SIZE(wl1273_controls),
495 .dapm_widgets = wl1273_dapm_widgets, 491 .dapm_widgets = wl1273_dapm_widgets,
496 .num_dapm_widgets = ARRAY_SIZE(wl1273_dapm_widgets), 492 .num_dapm_widgets = ARRAY_SIZE(wl1273_dapm_widgets),
497 .dapm_routes = wl1273_dapm_routes, 493 .dapm_routes = wl1273_dapm_routes,
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index f60234962527..d78fb8dffc8c 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -619,10 +619,10 @@ static int wm5102_out_comp_coeff_get(struct snd_kcontrol *kcontrol,
619 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 619 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
620 uint16_t data; 620 uint16_t data;
621 621
622 mutex_lock(&codec->mutex); 622 mutex_lock(&arizona->dac_comp_lock);
623 data = cpu_to_be16(arizona->dac_comp_coeff); 623 data = cpu_to_be16(arizona->dac_comp_coeff);
624 memcpy(ucontrol->value.bytes.data, &data, sizeof(data)); 624 memcpy(ucontrol->value.bytes.data, &data, sizeof(data));
625 mutex_unlock(&codec->mutex); 625 mutex_unlock(&arizona->dac_comp_lock);
626 626
627 return 0; 627 return 0;
628} 628}
@@ -633,11 +633,11 @@ static int wm5102_out_comp_coeff_put(struct snd_kcontrol *kcontrol,
633 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 633 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
634 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 634 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
635 635
636 mutex_lock(&codec->mutex); 636 mutex_lock(&arizona->dac_comp_lock);
637 memcpy(&arizona->dac_comp_coeff, ucontrol->value.bytes.data, 637 memcpy(&arizona->dac_comp_coeff, ucontrol->value.bytes.data,
638 sizeof(arizona->dac_comp_coeff)); 638 sizeof(arizona->dac_comp_coeff));
639 arizona->dac_comp_coeff = be16_to_cpu(arizona->dac_comp_coeff); 639 arizona->dac_comp_coeff = be16_to_cpu(arizona->dac_comp_coeff);
640 mutex_unlock(&codec->mutex); 640 mutex_unlock(&arizona->dac_comp_lock);
641 641
642 return 0; 642 return 0;
643} 643}
@@ -648,9 +648,9 @@ static int wm5102_out_comp_switch_get(struct snd_kcontrol *kcontrol,
648 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 648 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
649 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 649 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
650 650
651 mutex_lock(&codec->mutex); 651 mutex_lock(&arizona->dac_comp_lock);
652 ucontrol->value.integer.value[0] = arizona->dac_comp_enabled; 652 ucontrol->value.integer.value[0] = arizona->dac_comp_enabled;
653 mutex_unlock(&codec->mutex); 653 mutex_unlock(&arizona->dac_comp_lock);
654 654
655 return 0; 655 return 0;
656} 656}
@@ -661,9 +661,9 @@ static int wm5102_out_comp_switch_put(struct snd_kcontrol *kcontrol,
661 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 661 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
662 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 662 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
663 663
664 mutex_lock(&codec->mutex); 664 mutex_lock(&arizona->dac_comp_lock);
665 arizona->dac_comp_enabled = ucontrol->value.integer.value[0]; 665 arizona->dac_comp_enabled = ucontrol->value.integer.value[0];
666 mutex_unlock(&codec->mutex); 666 mutex_unlock(&arizona->dac_comp_lock);
667 667
668 return 0; 668 return 0;
669} 669}
@@ -1900,6 +1900,8 @@ static int wm5102_probe(struct platform_device *pdev)
1900 return -ENOMEM; 1900 return -ENOMEM;
1901 platform_set_drvdata(pdev, wm5102); 1901 platform_set_drvdata(pdev, wm5102);
1902 1902
1903 mutex_init(&arizona->dac_comp_lock);
1904
1903 wm5102->core.arizona = arizona; 1905 wm5102->core.arizona = arizona;
1904 wm5102->core.num_inputs = 6; 1906 wm5102->core.num_inputs = 6;
1905 1907
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index 628ec774cf22..87f664b9cc7d 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -1242,19 +1242,6 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
1242 return 0; 1242 return 0;
1243} 1243}
1244 1244
1245static int wm8350_suspend(struct snd_soc_codec *codec)
1246{
1247 wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF);
1248 return 0;
1249}
1250
1251static int wm8350_resume(struct snd_soc_codec *codec)
1252{
1253 wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1254
1255 return 0;
1256}
1257
1258static void wm8350_hp_work(struct wm8350_data *priv, 1245static void wm8350_hp_work(struct wm8350_data *priv,
1259 struct wm8350_jack_data *jack, 1246 struct wm8350_jack_data *jack,
1260 u16 mask) 1247 u16 mask)
@@ -1565,9 +1552,6 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec)
1565 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICD, 1552 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICD,
1566 wm8350_mic_handler, 0, "Microphone detect", priv); 1553 wm8350_mic_handler, 0, "Microphone detect", priv);
1567 1554
1568
1569 wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1570
1571 return 0; 1555 return 0;
1572} 1556}
1573 1557
@@ -1596,8 +1580,6 @@ static int wm8350_codec_remove(struct snd_soc_codec *codec)
1596 * wait for its completion */ 1580 * wait for its completion */
1597 flush_delayed_work(&codec->dapm.delayed_work); 1581 flush_delayed_work(&codec->dapm.delayed_work);
1598 1582
1599 wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF);
1600
1601 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); 1583 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
1602 1584
1603 return 0; 1585 return 0;
@@ -1613,10 +1595,9 @@ static struct regmap *wm8350_get_regmap(struct device *dev)
1613static struct snd_soc_codec_driver soc_codec_dev_wm8350 = { 1595static struct snd_soc_codec_driver soc_codec_dev_wm8350 = {
1614 .probe = wm8350_codec_probe, 1596 .probe = wm8350_codec_probe,
1615 .remove = wm8350_codec_remove, 1597 .remove = wm8350_codec_remove,
1616 .suspend = wm8350_suspend,
1617 .resume = wm8350_resume,
1618 .get_regmap = wm8350_get_regmap, 1598 .get_regmap = wm8350_get_regmap,
1619 .set_bias_level = wm8350_set_bias_level, 1599 .set_bias_level = wm8350_set_bias_level,
1600 .suspend_bias_off = true,
1620 1601
1621 .controls = wm8350_snd_controls, 1602 .controls = wm8350_snd_controls,
1622 .num_controls = ARRAY_SIZE(wm8350_snd_controls), 1603 .num_controls = ARRAY_SIZE(wm8350_snd_controls),
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index 72471bef2e9a..385894f6e264 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -58,12 +58,10 @@ static struct regulator_bulk_data power[] = {
58 58
59/* codec private data */ 59/* codec private data */
60struct wm8400_priv { 60struct wm8400_priv {
61 struct snd_soc_codec *codec;
62 struct wm8400 *wm8400; 61 struct wm8400 *wm8400;
63 u16 fake_register; 62 u16 fake_register;
64 unsigned int sysclk; 63 unsigned int sysclk;
65 unsigned int pcmclk; 64 unsigned int pcmclk;
66 struct work_struct work;
67 int fll_in, fll_out; 65 int fll_in, fll_out;
68}; 66};
69 67
@@ -1278,30 +1276,6 @@ static struct snd_soc_dai_driver wm8400_dai = {
1278 .ops = &wm8400_dai_ops, 1276 .ops = &wm8400_dai_ops,
1279}; 1277};
1280 1278
1281static int wm8400_suspend(struct snd_soc_codec *codec)
1282{
1283 wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF);
1284
1285 return 0;
1286}
1287
1288static int wm8400_resume(struct snd_soc_codec *codec)
1289{
1290 wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1291
1292 return 0;
1293}
1294
1295static void wm8400_probe_deferred(struct work_struct *work)
1296{
1297 struct wm8400_priv *priv = container_of(work, struct wm8400_priv,
1298 work);
1299 struct snd_soc_codec *codec = priv->codec;
1300
1301 /* charge output caps */
1302 wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1303}
1304
1305static int wm8400_codec_probe(struct snd_soc_codec *codec) 1279static int wm8400_codec_probe(struct snd_soc_codec *codec)
1306{ 1280{
1307 struct wm8400 *wm8400 = dev_get_platdata(codec->dev); 1281 struct wm8400 *wm8400 = dev_get_platdata(codec->dev);
@@ -1316,7 +1290,6 @@ static int wm8400_codec_probe(struct snd_soc_codec *codec)
1316 1290
1317 snd_soc_codec_set_drvdata(codec, priv); 1291 snd_soc_codec_set_drvdata(codec, priv);
1318 priv->wm8400 = wm8400; 1292 priv->wm8400 = wm8400;
1319 priv->codec = codec;
1320 1293
1321 ret = devm_regulator_bulk_get(wm8400->dev, 1294 ret = devm_regulator_bulk_get(wm8400->dev,
1322 ARRAY_SIZE(power), &power[0]); 1295 ARRAY_SIZE(power), &power[0]);
@@ -1325,8 +1298,6 @@ static int wm8400_codec_probe(struct snd_soc_codec *codec)
1325 return ret; 1298 return ret;
1326 } 1299 }
1327 1300
1328 INIT_WORK(&priv->work, wm8400_probe_deferred);
1329
1330 wm8400_codec_reset(codec); 1301 wm8400_codec_reset(codec);
1331 1302
1332 reg = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1); 1303 reg = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1);
@@ -1343,8 +1314,6 @@ static int wm8400_codec_probe(struct snd_soc_codec *codec)
1343 snd_soc_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); 1314 snd_soc_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
1344 snd_soc_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); 1315 snd_soc_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
1345 1316
1346 if (!schedule_work(&priv->work))
1347 return -EINVAL;
1348 return 0; 1317 return 0;
1349} 1318}
1350 1319
@@ -1369,10 +1338,9 @@ static struct regmap *wm8400_get_regmap(struct device *dev)
1369static struct snd_soc_codec_driver soc_codec_dev_wm8400 = { 1338static struct snd_soc_codec_driver soc_codec_dev_wm8400 = {
1370 .probe = wm8400_codec_probe, 1339 .probe = wm8400_codec_probe,
1371 .remove = wm8400_codec_remove, 1340 .remove = wm8400_codec_remove,
1372 .suspend = wm8400_suspend,
1373 .resume = wm8400_resume,
1374 .get_regmap = wm8400_get_regmap, 1341 .get_regmap = wm8400_get_regmap,
1375 .set_bias_level = wm8400_set_bias_level, 1342 .set_bias_level = wm8400_set_bias_level,
1343 .suspend_bias_off = true,
1376 1344
1377 .controls = wm8400_snd_controls, 1345 .controls = wm8400_snd_controls,
1378 .num_controls = ARRAY_SIZE(wm8400_snd_controls), 1346 .num_controls = ARRAY_SIZE(wm8400_snd_controls),
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index e11127f9069e..8736ad094b24 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -575,41 +575,17 @@ static struct snd_soc_dai_driver wm8510_dai = {
575 .symmetric_rates = 1, 575 .symmetric_rates = 1,
576}; 576};
577 577
578static int wm8510_suspend(struct snd_soc_codec *codec)
579{
580 wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF);
581 return 0;
582}
583
584static int wm8510_resume(struct snd_soc_codec *codec)
585{
586 wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
587 return 0;
588}
589
590static int wm8510_probe(struct snd_soc_codec *codec) 578static int wm8510_probe(struct snd_soc_codec *codec)
591{ 579{
592 wm8510_reset(codec); 580 wm8510_reset(codec);
593 581
594 /* power on device */
595 wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
596
597 return 0;
598}
599
600/* power down chip */
601static int wm8510_remove(struct snd_soc_codec *codec)
602{
603 wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF);
604 return 0; 582 return 0;
605} 583}
606 584
607static struct snd_soc_codec_driver soc_codec_dev_wm8510 = { 585static struct snd_soc_codec_driver soc_codec_dev_wm8510 = {
608 .probe = wm8510_probe, 586 .probe = wm8510_probe,
609 .remove = wm8510_remove,
610 .suspend = wm8510_suspend,
611 .resume = wm8510_resume,
612 .set_bias_level = wm8510_set_bias_level, 587 .set_bias_level = wm8510_set_bias_level,
588 .suspend_bias_off = true,
613 589
614 .controls = wm8510_snd_controls, 590 .controls = wm8510_snd_controls,
615 .num_controls = ARRAY_SIZE(wm8510_snd_controls), 591 .num_controls = ARRAY_SIZE(wm8510_snd_controls),
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c
index ec1f5740dbd0..b1cc94f5fc4b 100644
--- a/sound/soc/codecs/wm8523.c
+++ b/sound/soc/codecs/wm8523.c
@@ -372,23 +372,6 @@ static struct snd_soc_dai_driver wm8523_dai = {
372 .ops = &wm8523_dai_ops, 372 .ops = &wm8523_dai_ops,
373}; 373};
374 374
375#ifdef CONFIG_PM
376static int wm8523_suspend(struct snd_soc_codec *codec)
377{
378 wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
379 return 0;
380}
381
382static int wm8523_resume(struct snd_soc_codec *codec)
383{
384 wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
385 return 0;
386}
387#else
388#define wm8523_suspend NULL
389#define wm8523_resume NULL
390#endif
391
392static int wm8523_probe(struct snd_soc_codec *codec) 375static int wm8523_probe(struct snd_soc_codec *codec)
393{ 376{
394 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec); 377 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
@@ -402,23 +385,13 @@ static int wm8523_probe(struct snd_soc_codec *codec)
402 WM8523_DACR_VU, WM8523_DACR_VU); 385 WM8523_DACR_VU, WM8523_DACR_VU);
403 snd_soc_update_bits(codec, WM8523_DAC_CTRL3, WM8523_ZC, WM8523_ZC); 386 snd_soc_update_bits(codec, WM8523_DAC_CTRL3, WM8523_ZC, WM8523_ZC);
404 387
405 wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
406
407 return 0;
408}
409
410static int wm8523_remove(struct snd_soc_codec *codec)
411{
412 wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
413 return 0; 388 return 0;
414} 389}
415 390
416static struct snd_soc_codec_driver soc_codec_dev_wm8523 = { 391static struct snd_soc_codec_driver soc_codec_dev_wm8523 = {
417 .probe = wm8523_probe, 392 .probe = wm8523_probe,
418 .remove = wm8523_remove,
419 .suspend = wm8523_suspend,
420 .resume = wm8523_resume,
421 .set_bias_level = wm8523_set_bias_level, 393 .set_bias_level = wm8523_set_bias_level,
394 .suspend_bias_off = true,
422 395
423 .controls = wm8523_controls, 396 .controls = wm8523_controls,
424 .num_controls = ARRAY_SIZE(wm8523_controls), 397 .num_controls = ARRAY_SIZE(wm8523_controls),
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 911605ee25b0..0a887c5ec83a 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -882,8 +882,6 @@ static int wm8580_probe(struct snd_soc_codec *codec)
882 goto err_regulator_enable; 882 goto err_regulator_enable;
883 } 883 }
884 884
885 wm8580_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
886
887 return 0; 885 return 0;
888 886
889err_regulator_enable: 887err_regulator_enable:
@@ -897,8 +895,6 @@ static int wm8580_remove(struct snd_soc_codec *codec)
897{ 895{
898 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec); 896 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
899 897
900 wm8580_set_bias_level(codec, SND_SOC_BIAS_OFF);
901
902 regulator_bulk_disable(ARRAY_SIZE(wm8580->supplies), wm8580->supplies); 898 regulator_bulk_disable(ARRAY_SIZE(wm8580->supplies), wm8580->supplies);
903 899
904 return 0; 900 return 0;
diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c
index 32187e739b4f..121e46d53779 100644
--- a/sound/soc/codecs/wm8711.c
+++ b/sound/soc/codecs/wm8711.c
@@ -350,19 +350,6 @@ static struct snd_soc_dai_driver wm8711_dai = {
350 .ops = &wm8711_ops, 350 .ops = &wm8711_ops,
351}; 351};
352 352
353static int wm8711_suspend(struct snd_soc_codec *codec)
354{
355 snd_soc_write(codec, WM8711_ACTIVE, 0x0);
356 wm8711_set_bias_level(codec, SND_SOC_BIAS_OFF);
357 return 0;
358}
359
360static int wm8711_resume(struct snd_soc_codec *codec)
361{
362 wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
363 return 0;
364}
365
366static int wm8711_probe(struct snd_soc_codec *codec) 353static int wm8711_probe(struct snd_soc_codec *codec)
367{ 354{
368 int ret; 355 int ret;
@@ -373,8 +360,6 @@ static int wm8711_probe(struct snd_soc_codec *codec)
373 return ret; 360 return ret;
374 } 361 }
375 362
376 wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
377
378 /* Latch the update bits */ 363 /* Latch the update bits */
379 snd_soc_update_bits(codec, WM8711_LOUT1V, 0x0100, 0x0100); 364 snd_soc_update_bits(codec, WM8711_LOUT1V, 0x0100, 0x0100);
380 snd_soc_update_bits(codec, WM8711_ROUT1V, 0x0100, 0x0100); 365 snd_soc_update_bits(codec, WM8711_ROUT1V, 0x0100, 0x0100);
@@ -383,19 +368,11 @@ static int wm8711_probe(struct snd_soc_codec *codec)
383 368
384} 369}
385 370
386/* power down chip */
387static int wm8711_remove(struct snd_soc_codec *codec)
388{
389 wm8711_set_bias_level(codec, SND_SOC_BIAS_OFF);
390 return 0;
391}
392
393static struct snd_soc_codec_driver soc_codec_dev_wm8711 = { 371static struct snd_soc_codec_driver soc_codec_dev_wm8711 = {
394 .probe = wm8711_probe, 372 .probe = wm8711_probe,
395 .remove = wm8711_remove,
396 .suspend = wm8711_suspend,
397 .resume = wm8711_resume,
398 .set_bias_level = wm8711_set_bias_level, 373 .set_bias_level = wm8711_set_bias_level,
374 .suspend_bias_off = true,
375
399 .controls = wm8711_snd_controls, 376 .controls = wm8711_snd_controls,
400 .num_controls = ARRAY_SIZE(wm8711_snd_controls), 377 .num_controls = ARRAY_SIZE(wm8711_snd_controls),
401 .dapm_widgets = wm8711_dapm_widgets, 378 .dapm_widgets = wm8711_dapm_widgets,
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index 38ff826f589a..55c7fb4fc786 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -212,40 +212,10 @@ static struct snd_soc_dai_driver wm8728_dai = {
212 .ops = &wm8728_dai_ops, 212 .ops = &wm8728_dai_ops,
213}; 213};
214 214
215static int wm8728_suspend(struct snd_soc_codec *codec)
216{
217 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF);
218
219 return 0;
220}
221
222static int wm8728_resume(struct snd_soc_codec *codec)
223{
224 wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
225
226 return 0;
227}
228
229static int wm8728_probe(struct snd_soc_codec *codec)
230{
231 /* power on device */
232 wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
233
234 return 0;
235}
236
237static int wm8728_remove(struct snd_soc_codec *codec)
238{
239 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF);
240 return 0;
241}
242
243static struct snd_soc_codec_driver soc_codec_dev_wm8728 = { 215static struct snd_soc_codec_driver soc_codec_dev_wm8728 = {
244 .probe = wm8728_probe,
245 .remove = wm8728_remove,
246 .suspend = wm8728_suspend,
247 .resume = wm8728_resume,
248 .set_bias_level = wm8728_set_bias_level, 216 .set_bias_level = wm8728_set_bias_level,
217 .suspend_bias_off = true,
218
249 .controls = wm8728_snd_controls, 219 .controls = wm8728_snd_controls,
250 .num_controls = ARRAY_SIZE(wm8728_snd_controls), 220 .num_controls = ARRAY_SIZE(wm8728_snd_controls),
251 .dapm_widgets = wm8728_dapm_widgets, 221 .dapm_widgets = wm8728_dapm_widgets,
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index eebb3280bfad..b9211b42f6e9 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -24,6 +24,7 @@
24#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/of_device.h> 26#include <linux/of_device.h>
27#include <linux/mutex.h>
27#include <sound/core.h> 28#include <sound/core.h>
28#include <sound/pcm.h> 29#include <sound/pcm.h>
29#include <sound/pcm_params.h> 30#include <sound/pcm_params.h>
@@ -50,6 +51,8 @@ struct wm8731_priv {
50 int sysclk_type; 51 int sysclk_type;
51 int playback_fs; 52 int playback_fs;
52 bool deemph; 53 bool deemph;
54
55 struct mutex lock;
53}; 56};
54 57
55 58
@@ -138,7 +141,7 @@ static int wm8731_put_deemph(struct snd_kcontrol *kcontrol,
138 if (deemph > 1) 141 if (deemph > 1)
139 return -EINVAL; 142 return -EINVAL;
140 143
141 mutex_lock(&codec->mutex); 144 mutex_lock(&wm8731->lock);
142 if (wm8731->deemph != deemph) { 145 if (wm8731->deemph != deemph) {
143 wm8731->deemph = deemph; 146 wm8731->deemph = deemph;
144 147
@@ -146,7 +149,7 @@ static int wm8731_put_deemph(struct snd_kcontrol *kcontrol,
146 149
147 ret = 1; 150 ret = 1;
148 } 151 }
149 mutex_unlock(&codec->mutex); 152 mutex_unlock(&wm8731->lock);
150 153
151 return ret; 154 return ret;
152} 155}
@@ -559,25 +562,6 @@ static struct snd_soc_dai_driver wm8731_dai = {
559 .symmetric_rates = 1, 562 .symmetric_rates = 1,
560}; 563};
561 564
562#ifdef CONFIG_PM
563static int wm8731_suspend(struct snd_soc_codec *codec)
564{
565 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
566
567 return 0;
568}
569
570static int wm8731_resume(struct snd_soc_codec *codec)
571{
572 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
573
574 return 0;
575}
576#else
577#define wm8731_suspend NULL
578#define wm8731_resume NULL
579#endif
580
581static int wm8731_probe(struct snd_soc_codec *codec) 565static int wm8731_probe(struct snd_soc_codec *codec)
582{ 566{
583 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 567 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
@@ -633,8 +617,6 @@ static int wm8731_remove(struct snd_soc_codec *codec)
633{ 617{
634 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 618 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
635 619
636 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
637
638 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 620 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
639 621
640 return 0; 622 return 0;
@@ -643,9 +625,9 @@ static int wm8731_remove(struct snd_soc_codec *codec)
643static struct snd_soc_codec_driver soc_codec_dev_wm8731 = { 625static struct snd_soc_codec_driver soc_codec_dev_wm8731 = {
644 .probe = wm8731_probe, 626 .probe = wm8731_probe,
645 .remove = wm8731_remove, 627 .remove = wm8731_remove,
646 .suspend = wm8731_suspend,
647 .resume = wm8731_resume,
648 .set_bias_level = wm8731_set_bias_level, 628 .set_bias_level = wm8731_set_bias_level,
629 .suspend_bias_off = true,
630
649 .dapm_widgets = wm8731_dapm_widgets, 631 .dapm_widgets = wm8731_dapm_widgets,
650 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), 632 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
651 .dapm_routes = wm8731_intercon, 633 .dapm_routes = wm8731_intercon,
@@ -680,11 +662,12 @@ static int wm8731_spi_probe(struct spi_device *spi)
680 struct wm8731_priv *wm8731; 662 struct wm8731_priv *wm8731;
681 int ret; 663 int ret;
682 664
683 wm8731 = devm_kzalloc(&spi->dev, sizeof(struct wm8731_priv), 665 wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL);
684 GFP_KERNEL);
685 if (wm8731 == NULL) 666 if (wm8731 == NULL)
686 return -ENOMEM; 667 return -ENOMEM;
687 668
669 mutex_init(&wm8731->lock);
670
688 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); 671 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
689 if (IS_ERR(wm8731->regmap)) { 672 if (IS_ERR(wm8731->regmap)) {
690 ret = PTR_ERR(wm8731->regmap); 673 ret = PTR_ERR(wm8731->regmap);
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c
index 744a422ecb05..ada9ac1ba2c6 100644
--- a/sound/soc/codecs/wm8737.c
+++ b/sound/soc/codecs/wm8737.c
@@ -277,17 +277,6 @@ static const struct snd_soc_dapm_route intercon[] = {
277 { "AIF", NULL, "ADCR" }, 277 { "AIF", NULL, "ADCR" },
278}; 278};
279 279
280static int wm8737_add_widgets(struct snd_soc_codec *codec)
281{
282 struct snd_soc_dapm_context *dapm = &codec->dapm;
283
284 snd_soc_dapm_new_controls(dapm, wm8737_dapm_widgets,
285 ARRAY_SIZE(wm8737_dapm_widgets));
286 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
287
288 return 0;
289}
290
291/* codec mclk clock divider coefficients */ 280/* codec mclk clock divider coefficients */
292static const struct { 281static const struct {
293 u32 mclk; 282 u32 mclk;
@@ -548,23 +537,6 @@ static struct snd_soc_dai_driver wm8737_dai = {
548 .ops = &wm8737_dai_ops, 537 .ops = &wm8737_dai_ops,
549}; 538};
550 539
551#ifdef CONFIG_PM
552static int wm8737_suspend(struct snd_soc_codec *codec)
553{
554 wm8737_set_bias_level(codec, SND_SOC_BIAS_OFF);
555 return 0;
556}
557
558static int wm8737_resume(struct snd_soc_codec *codec)
559{
560 wm8737_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
561 return 0;
562}
563#else
564#define wm8737_suspend NULL
565#define wm8737_resume NULL
566#endif
567
568static int wm8737_probe(struct snd_soc_codec *codec) 540static int wm8737_probe(struct snd_soc_codec *codec)
569{ 541{
570 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 542 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
@@ -593,10 +565,6 @@ static int wm8737_probe(struct snd_soc_codec *codec)
593 /* Bias level configuration will have done an extra enable */ 565 /* Bias level configuration will have done an extra enable */
594 regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 566 regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies);
595 567
596 snd_soc_add_codec_controls(codec, wm8737_snd_controls,
597 ARRAY_SIZE(wm8737_snd_controls));
598 wm8737_add_widgets(codec);
599
600 return 0; 568 return 0;
601 569
602err_enable: 570err_enable:
@@ -605,18 +573,17 @@ err_get:
605 return ret; 573 return ret;
606} 574}
607 575
608static int wm8737_remove(struct snd_soc_codec *codec)
609{
610 wm8737_set_bias_level(codec, SND_SOC_BIAS_OFF);
611 return 0;
612}
613
614static struct snd_soc_codec_driver soc_codec_dev_wm8737 = { 576static struct snd_soc_codec_driver soc_codec_dev_wm8737 = {
615 .probe = wm8737_probe, 577 .probe = wm8737_probe,
616 .remove = wm8737_remove,
617 .suspend = wm8737_suspend,
618 .resume = wm8737_resume,
619 .set_bias_level = wm8737_set_bias_level, 578 .set_bias_level = wm8737_set_bias_level,
579 .suspend_bias_off = true,
580
581 .controls = wm8737_snd_controls,
582 .num_controls = ARRAY_SIZE(wm8737_snd_controls),
583 .dapm_widgets = wm8737_dapm_widgets,
584 .num_dapm_widgets = ARRAY_SIZE(wm8737_dapm_widgets),
585 .dapm_routes = intercon,
586 .num_dapm_routes = ARRAY_SIZE(intercon),
620}; 587};
621 588
622static const struct of_device_id wm8737_of_match[] = { 589static const struct of_device_id wm8737_of_match[] = {
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 67653a2db223..f6847fdd6ddd 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -686,18 +686,6 @@ static struct snd_soc_dai_driver wm8750_dai = {
686 .ops = &wm8750_dai_ops, 686 .ops = &wm8750_dai_ops,
687}; 687};
688 688
689static int wm8750_suspend(struct snd_soc_codec *codec)
690{
691 wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
692 return 0;
693}
694
695static int wm8750_resume(struct snd_soc_codec *codec)
696{
697 wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
698 return 0;
699}
700
701static int wm8750_probe(struct snd_soc_codec *codec) 689static int wm8750_probe(struct snd_soc_codec *codec)
702{ 690{
703 int ret; 691 int ret;
@@ -708,9 +696,6 @@ static int wm8750_probe(struct snd_soc_codec *codec)
708 return ret; 696 return ret;
709 } 697 }
710 698
711 /* charge output caps */
712 wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
713
714 /* set the update bits */ 699 /* set the update bits */
715 snd_soc_update_bits(codec, WM8750_LDAC, 0x0100, 0x0100); 700 snd_soc_update_bits(codec, WM8750_LDAC, 0x0100, 0x0100);
716 snd_soc_update_bits(codec, WM8750_RDAC, 0x0100, 0x0100); 701 snd_soc_update_bits(codec, WM8750_RDAC, 0x0100, 0x0100);
@@ -724,18 +709,10 @@ static int wm8750_probe(struct snd_soc_codec *codec)
724 return ret; 709 return ret;
725} 710}
726 711
727static int wm8750_remove(struct snd_soc_codec *codec)
728{
729 wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
730 return 0;
731}
732
733static struct snd_soc_codec_driver soc_codec_dev_wm8750 = { 712static struct snd_soc_codec_driver soc_codec_dev_wm8750 = {
734 .probe = wm8750_probe, 713 .probe = wm8750_probe,
735 .remove = wm8750_remove,
736 .suspend = wm8750_suspend,
737 .resume = wm8750_resume,
738 .set_bias_level = wm8750_set_bias_level, 714 .set_bias_level = wm8750_set_bias_level,
715 .suspend_bias_off = true,
739 716
740 .controls = wm8750_snd_controls, 717 .controls = wm8750_snd_controls,
741 .num_controls = ARRAY_SIZE(wm8750_snd_controls), 718 .num_controls = ARRAY_SIZE(wm8750_snd_controls),
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index 70952ceb278b..c13050b77931 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -408,24 +408,6 @@ static struct snd_soc_dai_driver wm8776_dai[] = {
408 }, 408 },
409}; 409};
410 410
411#ifdef CONFIG_PM
412static int wm8776_suspend(struct snd_soc_codec *codec)
413{
414 wm8776_set_bias_level(codec, SND_SOC_BIAS_OFF);
415
416 return 0;
417}
418
419static int wm8776_resume(struct snd_soc_codec *codec)
420{
421 wm8776_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
422 return 0;
423}
424#else
425#define wm8776_suspend NULL
426#define wm8776_resume NULL
427#endif
428
429static int wm8776_probe(struct snd_soc_codec *codec) 411static int wm8776_probe(struct snd_soc_codec *codec)
430{ 412{
431 int ret = 0; 413 int ret = 0;
@@ -436,8 +418,6 @@ static int wm8776_probe(struct snd_soc_codec *codec)
436 return ret; 418 return ret;
437 } 419 }
438 420
439 wm8776_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
440
441 /* Latch the update bits; right channel only since we always 421 /* Latch the update bits; right channel only since we always
442 * update both. */ 422 * update both. */
443 snd_soc_update_bits(codec, WM8776_HPRVOL, 0x100, 0x100); 423 snd_soc_update_bits(codec, WM8776_HPRVOL, 0x100, 0x100);
@@ -446,19 +426,10 @@ static int wm8776_probe(struct snd_soc_codec *codec)
446 return ret; 426 return ret;
447} 427}
448 428
449/* power down chip */
450static int wm8776_remove(struct snd_soc_codec *codec)
451{
452 wm8776_set_bias_level(codec, SND_SOC_BIAS_OFF);
453 return 0;
454}
455
456static struct snd_soc_codec_driver soc_codec_dev_wm8776 = { 429static struct snd_soc_codec_driver soc_codec_dev_wm8776 = {
457 .probe = wm8776_probe, 430 .probe = wm8776_probe,
458 .remove = wm8776_remove,
459 .suspend = wm8776_suspend,
460 .resume = wm8776_resume,
461 .set_bias_level = wm8776_set_bias_level, 431 .set_bias_level = wm8776_set_bias_level,
432 .suspend_bias_off = true,
462 433
463 .controls = wm8776_snd_controls, 434 .controls = wm8776_snd_controls,
464 .num_controls = ARRAY_SIZE(wm8776_snd_controls), 435 .num_controls = ARRAY_SIZE(wm8776_snd_controls),
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
index 3addc5fe5cb2..1315f7642503 100644
--- a/sound/soc/codecs/wm8804.c
+++ b/sound/soc/codecs/wm8804.c
@@ -524,7 +524,6 @@ static int wm8804_remove(struct snd_soc_codec *codec)
524 int i; 524 int i;
525 525
526 wm8804 = snd_soc_codec_get_drvdata(codec); 526 wm8804 = snd_soc_codec_get_drvdata(codec);
527 wm8804_set_bias_level(codec, SND_SOC_BIAS_OFF);
528 527
529 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); ++i) 528 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); ++i)
530 regulator_unregister_notifier(wm8804->supplies[i].consumer, 529 regulator_unregister_notifier(wm8804->supplies[i].consumer,
@@ -606,8 +605,6 @@ static int wm8804_probe(struct snd_soc_codec *codec)
606 goto err_reg_enable; 605 goto err_reg_enable;
607 } 606 }
608 607
609 wm8804_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
610
611 return 0; 608 return 0;
612 609
613err_reg_enable: 610err_reg_enable:
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index 44a5f1511f0f..3a0d4b7d692f 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -1209,16 +1209,8 @@ static int wm8900_probe(struct snd_soc_codec *codec)
1209 return 0; 1209 return 0;
1210} 1210}
1211 1211
1212/* power down chip */
1213static int wm8900_remove(struct snd_soc_codec *codec)
1214{
1215 wm8900_set_bias_level(codec, SND_SOC_BIAS_OFF);
1216 return 0;
1217}
1218
1219static struct snd_soc_codec_driver soc_codec_dev_wm8900 = { 1212static struct snd_soc_codec_driver soc_codec_dev_wm8900 = {
1220 .probe = wm8900_probe, 1213 .probe = wm8900_probe,
1221 .remove = wm8900_remove,
1222 .suspend = wm8900_suspend, 1214 .suspend = wm8900_suspend,
1223 .resume = wm8900_resume, 1215 .resume = wm8900_resume,
1224 .set_bias_level = wm8900_set_bias_level, 1216 .set_bias_level = wm8900_set_bias_level,
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index c038b3e04398..cc6b0ef98a34 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -26,6 +26,7 @@
26#include <linux/regmap.h> 26#include <linux/regmap.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/irq.h> 28#include <linux/irq.h>
29#include <linux/mutex.h>
29#include <sound/core.h> 30#include <sound/core.h>
30#include <sound/jack.h> 31#include <sound/jack.h>
31#include <sound/pcm.h> 32#include <sound/pcm.h>
@@ -117,12 +118,12 @@ static const struct reg_default wm8903_reg_defaults[] = {
117struct wm8903_priv { 118struct wm8903_priv {
118 struct wm8903_platform_data *pdata; 119 struct wm8903_platform_data *pdata;
119 struct device *dev; 120 struct device *dev;
120 struct snd_soc_codec *codec;
121 struct regmap *regmap; 121 struct regmap *regmap;
122 122
123 int sysclk; 123 int sysclk;
124 int irq; 124 int irq;
125 125
126 struct mutex lock;
126 int fs; 127 int fs;
127 int deemph; 128 int deemph;
128 129
@@ -457,7 +458,7 @@ static int wm8903_put_deemph(struct snd_kcontrol *kcontrol,
457 if (deemph > 1) 458 if (deemph > 1)
458 return -EINVAL; 459 return -EINVAL;
459 460
460 mutex_lock(&codec->mutex); 461 mutex_lock(&wm8903->lock);
461 if (wm8903->deemph != deemph) { 462 if (wm8903->deemph != deemph) {
462 wm8903->deemph = deemph; 463 wm8903->deemph = deemph;
463 464
@@ -465,7 +466,7 @@ static int wm8903_put_deemph(struct snd_kcontrol *kcontrol,
465 466
466 ret = 1; 467 ret = 1;
467 } 468 }
468 mutex_unlock(&codec->mutex); 469 mutex_unlock(&wm8903->lock);
469 470
470 return ret; 471 return ret;
471} 472}
@@ -1757,21 +1758,12 @@ static struct snd_soc_dai_driver wm8903_dai = {
1757 .symmetric_rates = 1, 1758 .symmetric_rates = 1,
1758}; 1759};
1759 1760
1760static int wm8903_suspend(struct snd_soc_codec *codec)
1761{
1762 wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
1763
1764 return 0;
1765}
1766
1767static int wm8903_resume(struct snd_soc_codec *codec) 1761static int wm8903_resume(struct snd_soc_codec *codec)
1768{ 1762{
1769 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); 1763 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1770 1764
1771 regcache_sync(wm8903->regmap); 1765 regcache_sync(wm8903->regmap);
1772 1766
1773 wm8903_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1774
1775 return 0; 1767 return 0;
1776} 1768}
1777 1769
@@ -1889,33 +1881,12 @@ static void wm8903_free_gpio(struct wm8903_priv *wm8903)
1889} 1881}
1890#endif 1882#endif
1891 1883
1892static int wm8903_probe(struct snd_soc_codec *codec)
1893{
1894 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1895
1896 wm8903->codec = codec;
1897
1898 /* power on device */
1899 wm8903_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1900
1901 return 0;
1902}
1903
1904/* power down chip */
1905static int wm8903_remove(struct snd_soc_codec *codec)
1906{
1907 wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
1908
1909 return 0;
1910}
1911
1912static struct snd_soc_codec_driver soc_codec_dev_wm8903 = { 1884static struct snd_soc_codec_driver soc_codec_dev_wm8903 = {
1913 .probe = wm8903_probe,
1914 .remove = wm8903_remove,
1915 .suspend = wm8903_suspend,
1916 .resume = wm8903_resume, 1885 .resume = wm8903_resume,
1917 .set_bias_level = wm8903_set_bias_level, 1886 .set_bias_level = wm8903_set_bias_level,
1918 .seq_notifier = wm8903_seq_notifier, 1887 .seq_notifier = wm8903_seq_notifier,
1888 .suspend_bias_off = true,
1889
1919 .controls = wm8903_snd_controls, 1890 .controls = wm8903_snd_controls,
1920 .num_controls = ARRAY_SIZE(wm8903_snd_controls), 1891 .num_controls = ARRAY_SIZE(wm8903_snd_controls),
1921 .dapm_widgets = wm8903_dapm_widgets, 1892 .dapm_widgets = wm8903_dapm_widgets,
@@ -2023,6 +1994,8 @@ static int wm8903_i2c_probe(struct i2c_client *i2c,
2023 GFP_KERNEL); 1994 GFP_KERNEL);
2024 if (wm8903 == NULL) 1995 if (wm8903 == NULL)
2025 return -ENOMEM; 1996 return -ENOMEM;
1997
1998 mutex_init(&wm8903->lock);
2026 wm8903->dev = &i2c->dev; 1999 wm8903->dev = &i2c->dev;
2027 2000
2028 wm8903->regmap = devm_regmap_init_i2c(i2c, &wm8903_regmap); 2001 wm8903->regmap = devm_regmap_init_i2c(i2c, &wm8903_regmap);
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index 52011043e54c..e4142b4309eb 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -695,17 +695,6 @@ static struct snd_soc_dai_driver wm8940_dai = {
695 .symmetric_rates = 1, 695 .symmetric_rates = 1,
696}; 696};
697 697
698static int wm8940_suspend(struct snd_soc_codec *codec)
699{
700 return wm8940_set_bias_level(codec, SND_SOC_BIAS_OFF);
701}
702
703static int wm8940_resume(struct snd_soc_codec *codec)
704{
705 wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
706 return 0;
707}
708
709static int wm8940_probe(struct snd_soc_codec *codec) 698static int wm8940_probe(struct snd_soc_codec *codec)
710{ 699{
711 struct wm8940_setup_data *pdata = codec->dev->platform_data; 700 struct wm8940_setup_data *pdata = codec->dev->platform_data;
@@ -736,18 +725,11 @@ static int wm8940_probe(struct snd_soc_codec *codec)
736 return ret; 725 return ret;
737} 726}
738 727
739static int wm8940_remove(struct snd_soc_codec *codec)
740{
741 wm8940_set_bias_level(codec, SND_SOC_BIAS_OFF);
742 return 0;
743}
744
745static struct snd_soc_codec_driver soc_codec_dev_wm8940 = { 728static struct snd_soc_codec_driver soc_codec_dev_wm8940 = {
746 .probe = wm8940_probe, 729 .probe = wm8940_probe,
747 .remove = wm8940_remove,
748 .suspend = wm8940_suspend,
749 .resume = wm8940_resume,
750 .set_bias_level = wm8940_set_bias_level, 730 .set_bias_level = wm8940_set_bias_level,
731 .suspend_bias_off = true,
732
751 .controls = wm8940_snd_controls, 733 .controls = wm8940_snd_controls,
752 .num_controls = ARRAY_SIZE(wm8940_snd_controls), 734 .num_controls = ARRAY_SIZE(wm8940_snd_controls),
753 .dapm_widgets = wm8940_dapm_widgets, 735 .dapm_widgets = wm8940_dapm_widgets,
diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c
index 09d91d9dc4ee..1173f7fef5a7 100644
--- a/sound/soc/codecs/wm8955.c
+++ b/sound/soc/codecs/wm8955.c
@@ -866,29 +866,6 @@ static struct snd_soc_dai_driver wm8955_dai = {
866 .ops = &wm8955_dai_ops, 866 .ops = &wm8955_dai_ops,
867}; 867};
868 868
869#ifdef CONFIG_PM
870static int wm8955_suspend(struct snd_soc_codec *codec)
871{
872 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
873
874 wm8955_set_bias_level(codec, SND_SOC_BIAS_OFF);
875
876 regcache_mark_dirty(wm8955->regmap);
877
878 return 0;
879}
880
881static int wm8955_resume(struct snd_soc_codec *codec)
882{
883 wm8955_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
884
885 return 0;
886}
887#else
888#define wm8955_suspend NULL
889#define wm8955_resume NULL
890#endif
891
892static int wm8955_probe(struct snd_soc_codec *codec) 869static int wm8955_probe(struct snd_soc_codec *codec)
893{ 870{
894 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec); 871 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
@@ -964,18 +941,10 @@ err_enable:
964 return ret; 941 return ret;
965} 942}
966 943
967static int wm8955_remove(struct snd_soc_codec *codec)
968{
969 wm8955_set_bias_level(codec, SND_SOC_BIAS_OFF);
970 return 0;
971}
972
973static struct snd_soc_codec_driver soc_codec_dev_wm8955 = { 944static struct snd_soc_codec_driver soc_codec_dev_wm8955 = {
974 .probe = wm8955_probe, 945 .probe = wm8955_probe,
975 .remove = wm8955_remove,
976 .suspend = wm8955_suspend,
977 .resume = wm8955_resume,
978 .set_bias_level = wm8955_set_bias_level, 946 .set_bias_level = wm8955_set_bias_level,
947 .suspend_bias_off = true,
979 948
980 .controls = wm8955_snd_controls, 949 .controls = wm8955_snd_controls,
981 .num_controls = ARRAY_SIZE(wm8955_snd_controls), 950 .num_controls = ARRAY_SIZE(wm8955_snd_controls),
diff --git a/sound/soc/codecs/wm8958-dsp2.c b/sound/soc/codecs/wm8958-dsp2.c
index 0dada7f0105e..3cbc82b33292 100644
--- a/sound/soc/codecs/wm8958-dsp2.c
+++ b/sound/soc/codecs/wm8958-dsp2.c
@@ -867,9 +867,9 @@ static void wm8958_enh_eq_loaded(const struct firmware *fw, void *context)
867 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 867 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
868 868
869 if (fw && (wm8958_dsp2_fw(codec, "ENH_EQ", fw, true) == 0)) { 869 if (fw && (wm8958_dsp2_fw(codec, "ENH_EQ", fw, true) == 0)) {
870 mutex_lock(&codec->mutex); 870 mutex_lock(&wm8994->fw_lock);
871 wm8994->enh_eq = fw; 871 wm8994->enh_eq = fw;
872 mutex_unlock(&codec->mutex); 872 mutex_unlock(&wm8994->fw_lock);
873 } 873 }
874} 874}
875 875
@@ -879,9 +879,9 @@ static void wm8958_mbc_vss_loaded(const struct firmware *fw, void *context)
879 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 879 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
880 880
881 if (fw && (wm8958_dsp2_fw(codec, "MBC+VSS", fw, true) == 0)) { 881 if (fw && (wm8958_dsp2_fw(codec, "MBC+VSS", fw, true) == 0)) {
882 mutex_lock(&codec->mutex); 882 mutex_lock(&wm8994->fw_lock);
883 wm8994->mbc_vss = fw; 883 wm8994->mbc_vss = fw;
884 mutex_unlock(&codec->mutex); 884 mutex_unlock(&wm8994->fw_lock);
885 } 885 }
886} 886}
887 887
@@ -891,9 +891,9 @@ static void wm8958_mbc_loaded(const struct firmware *fw, void *context)
891 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 891 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
892 892
893 if (fw && (wm8958_dsp2_fw(codec, "MBC", fw, true) == 0)) { 893 if (fw && (wm8958_dsp2_fw(codec, "MBC", fw, true) == 0)) {
894 mutex_lock(&codec->mutex); 894 mutex_lock(&wm8994->fw_lock);
895 wm8994->mbc = fw; 895 wm8994->mbc = fw;
896 mutex_unlock(&codec->mutex); 896 mutex_unlock(&wm8994->fw_lock);
897 } 897 }
898} 898}
899 899
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index 4dc4e85116cd..031a1ae71d94 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -125,9 +125,10 @@ struct wm8960_priv {
125 struct snd_soc_dapm_widget *out3; 125 struct snd_soc_dapm_widget *out3;
126 bool deemph; 126 bool deemph;
127 int playback_fs; 127 int playback_fs;
128 struct wm8960_data pdata;
128}; 129};
129 130
130#define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0) 131#define wm8960_reset(c) regmap_write(c, WM8960_RESET, 0)
131 132
132/* enumerated controls */ 133/* enumerated controls */
133static const char *wm8960_polarity[] = {"No Inversion", "Left Inverted", 134static const char *wm8960_polarity[] = {"No Inversion", "Left Inverted",
@@ -440,8 +441,8 @@ static const struct snd_soc_dapm_route audio_paths_capless[] = {
440 441
441static int wm8960_add_widgets(struct snd_soc_codec *codec) 442static int wm8960_add_widgets(struct snd_soc_codec *codec)
442{ 443{
443 struct wm8960_data *pdata = codec->dev->platform_data;
444 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 444 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
445 struct wm8960_data *pdata = &wm8960->pdata;
445 struct snd_soc_dapm_context *dapm = &codec->dapm; 446 struct snd_soc_dapm_context *dapm = &codec->dapm;
446 struct snd_soc_dapm_widget *w; 447 struct snd_soc_dapm_widget *w;
447 448
@@ -942,56 +943,15 @@ static struct snd_soc_dai_driver wm8960_dai = {
942 .symmetric_rates = 1, 943 .symmetric_rates = 1,
943}; 944};
944 945
945static int wm8960_suspend(struct snd_soc_codec *codec)
946{
947 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
948
949 wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF);
950 return 0;
951}
952
953static int wm8960_resume(struct snd_soc_codec *codec)
954{
955 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
956
957 wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
958 return 0;
959}
960
961static int wm8960_probe(struct snd_soc_codec *codec) 946static int wm8960_probe(struct snd_soc_codec *codec)
962{ 947{
963 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 948 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
964 struct wm8960_data *pdata = dev_get_platdata(codec->dev); 949 struct wm8960_data *pdata = &wm8960->pdata;
965 int ret;
966
967 wm8960->set_bias_level = wm8960_set_bias_level_out3;
968
969 if (!pdata) {
970 dev_warn(codec->dev, "No platform data supplied\n");
971 } else {
972 if (pdata->capless)
973 wm8960->set_bias_level = wm8960_set_bias_level_capless;
974 }
975
976 ret = wm8960_reset(codec);
977 if (ret < 0) {
978 dev_err(codec->dev, "Failed to issue reset\n");
979 return ret;
980 }
981
982 wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
983 950
984 /* Latch the update bits */ 951 if (pdata->capless)
985 snd_soc_update_bits(codec, WM8960_LINVOL, 0x100, 0x100); 952 wm8960->set_bias_level = wm8960_set_bias_level_capless;
986 snd_soc_update_bits(codec, WM8960_RINVOL, 0x100, 0x100); 953 else
987 snd_soc_update_bits(codec, WM8960_LADC, 0x100, 0x100); 954 wm8960->set_bias_level = wm8960_set_bias_level_out3;
988 snd_soc_update_bits(codec, WM8960_RADC, 0x100, 0x100);
989 snd_soc_update_bits(codec, WM8960_LDAC, 0x100, 0x100);
990 snd_soc_update_bits(codec, WM8960_RDAC, 0x100, 0x100);
991 snd_soc_update_bits(codec, WM8960_LOUT1, 0x100, 0x100);
992 snd_soc_update_bits(codec, WM8960_ROUT1, 0x100, 0x100);
993 snd_soc_update_bits(codec, WM8960_LOUT2, 0x100, 0x100);
994 snd_soc_update_bits(codec, WM8960_ROUT2, 0x100, 0x100);
995 955
996 snd_soc_add_codec_controls(codec, wm8960_snd_controls, 956 snd_soc_add_codec_controls(codec, wm8960_snd_controls,
997 ARRAY_SIZE(wm8960_snd_controls)); 957 ARRAY_SIZE(wm8960_snd_controls));
@@ -1000,21 +960,10 @@ static int wm8960_probe(struct snd_soc_codec *codec)
1000 return 0; 960 return 0;
1001} 961}
1002 962
1003/* power down chip */
1004static int wm8960_remove(struct snd_soc_codec *codec)
1005{
1006 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
1007
1008 wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF);
1009 return 0;
1010}
1011
1012static struct snd_soc_codec_driver soc_codec_dev_wm8960 = { 963static struct snd_soc_codec_driver soc_codec_dev_wm8960 = {
1013 .probe = wm8960_probe, 964 .probe = wm8960_probe,
1014 .remove = wm8960_remove,
1015 .suspend = wm8960_suspend,
1016 .resume = wm8960_resume,
1017 .set_bias_level = wm8960_set_bias_level, 965 .set_bias_level = wm8960_set_bias_level,
966 .suspend_bias_off = true,
1018}; 967};
1019 968
1020static const struct regmap_config wm8960_regmap = { 969static const struct regmap_config wm8960_regmap = {
@@ -1029,6 +978,18 @@ static const struct regmap_config wm8960_regmap = {
1029 .volatile_reg = wm8960_volatile, 978 .volatile_reg = wm8960_volatile,
1030}; 979};
1031 980
981static void wm8960_set_pdata_from_of(struct i2c_client *i2c,
982 struct wm8960_data *pdata)
983{
984 const struct device_node *np = i2c->dev.of_node;
985
986 if (of_property_read_bool(np, "wlf,capless"))
987 pdata->capless = true;
988
989 if (of_property_read_bool(np, "wlf,shared-lrclk"))
990 pdata->shared_lrclk = true;
991}
992
1032static int wm8960_i2c_probe(struct i2c_client *i2c, 993static int wm8960_i2c_probe(struct i2c_client *i2c,
1033 const struct i2c_device_id *id) 994 const struct i2c_device_id *id)
1034{ 995{
@@ -1045,7 +1006,18 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
1045 if (IS_ERR(wm8960->regmap)) 1006 if (IS_ERR(wm8960->regmap))
1046 return PTR_ERR(wm8960->regmap); 1007 return PTR_ERR(wm8960->regmap);
1047 1008
1048 if (pdata && pdata->shared_lrclk) { 1009 if (pdata)
1010 memcpy(&wm8960->pdata, pdata, sizeof(struct wm8960_data));
1011 else if (i2c->dev.of_node)
1012 wm8960_set_pdata_from_of(i2c, &wm8960->pdata);
1013
1014 ret = wm8960_reset(wm8960->regmap);
1015 if (ret != 0) {
1016 dev_err(&i2c->dev, "Failed to issue reset\n");
1017 return ret;
1018 }
1019
1020 if (wm8960->pdata.shared_lrclk) {
1049 ret = regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2, 1021 ret = regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2,
1050 0x4, 0x4); 1022 0x4, 0x4);
1051 if (ret != 0) { 1023 if (ret != 0) {
@@ -1055,6 +1027,18 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
1055 } 1027 }
1056 } 1028 }
1057 1029
1030 /* Latch the update bits */
1031 regmap_update_bits(wm8960->regmap, WM8960_LINVOL, 0x100, 0x100);
1032 regmap_update_bits(wm8960->regmap, WM8960_RINVOL, 0x100, 0x100);
1033 regmap_update_bits(wm8960->regmap, WM8960_LADC, 0x100, 0x100);
1034 regmap_update_bits(wm8960->regmap, WM8960_RADC, 0x100, 0x100);
1035 regmap_update_bits(wm8960->regmap, WM8960_LDAC, 0x100, 0x100);
1036 regmap_update_bits(wm8960->regmap, WM8960_RDAC, 0x100, 0x100);
1037 regmap_update_bits(wm8960->regmap, WM8960_LOUT1, 0x100, 0x100);
1038 regmap_update_bits(wm8960->regmap, WM8960_ROUT1, 0x100, 0x100);
1039 regmap_update_bits(wm8960->regmap, WM8960_LOUT2, 0x100, 0x100);
1040 regmap_update_bits(wm8960->regmap, WM8960_ROUT2, 0x100, 0x100);
1041
1058 i2c_set_clientdata(i2c, wm8960); 1042 i2c_set_clientdata(i2c, wm8960);
1059 1043
1060 ret = snd_soc_register_codec(&i2c->dev, 1044 ret = snd_soc_register_codec(&i2c->dev,
@@ -1075,10 +1059,17 @@ static const struct i2c_device_id wm8960_i2c_id[] = {
1075}; 1059};
1076MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id); 1060MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id);
1077 1061
1062static const struct of_device_id wm8960_of_match[] = {
1063 { .compatible = "wlf,wm8960", },
1064 { }
1065};
1066MODULE_DEVICE_TABLE(of, wm8960_of_match);
1067
1078static struct i2c_driver wm8960_i2c_driver = { 1068static struct i2c_driver wm8960_i2c_driver = {
1079 .driver = { 1069 .driver = {
1080 .name = "wm8960", 1070 .name = "wm8960",
1081 .owner = THIS_MODULE, 1071 .owner = THIS_MODULE,
1072 .of_match_table = wm8960_of_match,
1082 }, 1073 },
1083 .probe = wm8960_i2c_probe, 1074 .probe = wm8960_i2c_probe,
1084 .remove = wm8960_i2c_remove, 1075 .remove = wm8960_i2c_remove,
diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c
index 41d23e920ad5..eeffd05384b4 100644
--- a/sound/soc/codecs/wm8961.c
+++ b/sound/soc/codecs/wm8961.c
@@ -835,7 +835,6 @@ static struct snd_soc_dai_driver wm8961_dai = {
835 835
836static int wm8961_probe(struct snd_soc_codec *codec) 836static int wm8961_probe(struct snd_soc_codec *codec)
837{ 837{
838 struct snd_soc_dapm_context *dapm = &codec->dapm;
839 u16 reg; 838 u16 reg;
840 839
841 /* Enable class W */ 840 /* Enable class W */
@@ -871,50 +870,33 @@ static int wm8961_probe(struct snd_soc_codec *codec)
871 reg &= ~WM8961_MANUAL_MODE; 870 reg &= ~WM8961_MANUAL_MODE;
872 snd_soc_write(codec, WM8961_CLOCKING_3, reg); 871 snd_soc_write(codec, WM8961_CLOCKING_3, reg);
873 872
874 wm8961_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
875
876 snd_soc_add_codec_controls(codec, wm8961_snd_controls,
877 ARRAY_SIZE(wm8961_snd_controls));
878 snd_soc_dapm_new_controls(dapm, wm8961_dapm_widgets,
879 ARRAY_SIZE(wm8961_dapm_widgets));
880 snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));
881
882 return 0;
883}
884
885static int wm8961_remove(struct snd_soc_codec *codec)
886{
887 wm8961_set_bias_level(codec, SND_SOC_BIAS_OFF);
888 return 0; 873 return 0;
889} 874}
890 875
891#ifdef CONFIG_PM 876#ifdef CONFIG_PM
892static int wm8961_suspend(struct snd_soc_codec *codec)
893{
894 wm8961_set_bias_level(codec, SND_SOC_BIAS_OFF);
895
896 return 0;
897}
898 877
899static int wm8961_resume(struct snd_soc_codec *codec) 878static int wm8961_resume(struct snd_soc_codec *codec)
900{ 879{
901 snd_soc_cache_sync(codec); 880 snd_soc_cache_sync(codec);
902 881
903 wm8961_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
904
905 return 0; 882 return 0;
906} 883}
907#else 884#else
908#define wm8961_suspend NULL
909#define wm8961_resume NULL 885#define wm8961_resume NULL
910#endif 886#endif
911 887
912static struct snd_soc_codec_driver soc_codec_dev_wm8961 = { 888static struct snd_soc_codec_driver soc_codec_dev_wm8961 = {
913 .probe = wm8961_probe, 889 .probe = wm8961_probe,
914 .remove = wm8961_remove,
915 .suspend = wm8961_suspend,
916 .resume = wm8961_resume, 890 .resume = wm8961_resume,
917 .set_bias_level = wm8961_set_bias_level, 891 .set_bias_level = wm8961_set_bias_level,
892 .suspend_bias_off = true,
893
894 .controls = wm8961_snd_controls,
895 .num_controls = ARRAY_SIZE(wm8961_snd_controls),
896 .dapm_widgets = wm8961_dapm_widgets,
897 .num_dapm_widgets = ARRAY_SIZE(wm8961_dapm_widgets),
898 .dapm_routes = audio_paths,
899 .num_dapm_routes = ARRAY_SIZE(audio_paths),
918}; 900};
919 901
920static const struct regmap_config wm8961_regmap = { 902static const struct regmap_config wm8961_regmap = {
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 9077411e62ce..1534d88a66e9 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -26,6 +26,7 @@
26#include <linux/regulator/consumer.h> 26#include <linux/regulator/consumer.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/workqueue.h> 28#include <linux/workqueue.h>
29#include <linux/mutex.h>
29#include <sound/core.h> 30#include <sound/core.h>
30#include <sound/jack.h> 31#include <sound/jack.h>
31#include <sound/pcm.h> 32#include <sound/pcm.h>
@@ -67,6 +68,7 @@ struct wm8962_priv {
67 int fll_fref; 68 int fll_fref;
68 int fll_fout; 69 int fll_fout;
69 70
71 struct mutex dsp2_ena_lock;
70 u16 dsp2_ena; 72 u16 dsp2_ena;
71 73
72 struct delayed_work mic_work; 74 struct delayed_work mic_work;
@@ -1570,7 +1572,7 @@ static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
1570 int dsp2_running = snd_soc_read(codec, WM8962_DSP2_POWER_MANAGEMENT) & 1572 int dsp2_running = snd_soc_read(codec, WM8962_DSP2_POWER_MANAGEMENT) &
1571 WM8962_DSP2_ENA; 1573 WM8962_DSP2_ENA;
1572 1574
1573 mutex_lock(&codec->mutex); 1575 mutex_lock(&wm8962->dsp2_ena_lock);
1574 1576
1575 if (ucontrol->value.integer.value[0]) 1577 if (ucontrol->value.integer.value[0])
1576 wm8962->dsp2_ena |= 1 << shift; 1578 wm8962->dsp2_ena |= 1 << shift;
@@ -1590,7 +1592,7 @@ static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
1590 } 1592 }
1591 1593
1592out: 1594out:
1593 mutex_unlock(&codec->mutex); 1595 mutex_unlock(&wm8962->dsp2_ena_lock);
1594 1596
1595 return ret; 1597 return ret;
1596} 1598}
@@ -3552,11 +3554,12 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
3552 unsigned int reg; 3554 unsigned int reg;
3553 int ret, i, irq_pol, trigger; 3555 int ret, i, irq_pol, trigger;
3554 3556
3555 wm8962 = devm_kzalloc(&i2c->dev, sizeof(struct wm8962_priv), 3557 wm8962 = devm_kzalloc(&i2c->dev, sizeof(*wm8962), GFP_KERNEL);
3556 GFP_KERNEL);
3557 if (wm8962 == NULL) 3558 if (wm8962 == NULL)
3558 return -ENOMEM; 3559 return -ENOMEM;
3559 3560
3561 mutex_init(&wm8962->dsp2_ena_lock);
3562
3560 i2c_set_clientdata(i2c, wm8962); 3563 i2c_set_clientdata(i2c, wm8962);
3561 3564
3562 INIT_DELAYED_WORK(&wm8962->mic_work, wm8962_mic_work); 3565 INIT_DELAYED_WORK(&wm8962->mic_work, wm8962_mic_work);
diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c
index 682e9eda1019..ff0e4646b934 100644
--- a/sound/soc/codecs/wm8974.c
+++ b/sound/soc/codecs/wm8974.c
@@ -568,18 +568,6 @@ static struct snd_soc_dai_driver wm8974_dai = {
568 .symmetric_rates = 1, 568 .symmetric_rates = 1,
569}; 569};
570 570
571static int wm8974_suspend(struct snd_soc_codec *codec)
572{
573 wm8974_set_bias_level(codec, SND_SOC_BIAS_OFF);
574 return 0;
575}
576
577static int wm8974_resume(struct snd_soc_codec *codec)
578{
579 wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
580 return 0;
581}
582
583static const struct regmap_config wm8974_regmap = { 571static const struct regmap_config wm8974_regmap = {
584 .reg_bits = 7, 572 .reg_bits = 7,
585 .val_bits = 9, 573 .val_bits = 9,
@@ -599,24 +587,13 @@ static int wm8974_probe(struct snd_soc_codec *codec)
599 return ret; 587 return ret;
600 } 588 }
601 589
602 wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
603
604 return ret;
605}
606
607/* power down chip */
608static int wm8974_remove(struct snd_soc_codec *codec)
609{
610 wm8974_set_bias_level(codec, SND_SOC_BIAS_OFF);
611 return 0; 590 return 0;
612} 591}
613 592
614static struct snd_soc_codec_driver soc_codec_dev_wm8974 = { 593static struct snd_soc_codec_driver soc_codec_dev_wm8974 = {
615 .probe = wm8974_probe, 594 .probe = wm8974_probe,
616 .remove = wm8974_remove,
617 .suspend = wm8974_suspend,
618 .resume = wm8974_resume,
619 .set_bias_level = wm8974_set_bias_level, 595 .set_bias_level = wm8974_set_bias_level,
596 .suspend_bias_off = true,
620 597
621 .controls = wm8974_snd_controls, 598 .controls = wm8974_snd_controls,
622 .num_controls = ARRAY_SIZE(wm8974_snd_controls), 599 .num_controls = ARRAY_SIZE(wm8974_snd_controls),
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c
index ee2ba574952b..cf7032911721 100644
--- a/sound/soc/codecs/wm8978.c
+++ b/sound/soc/codecs/wm8978.c
@@ -991,21 +991,11 @@ static int wm8978_probe(struct snd_soc_codec *codec)
991 for (i = 0; i < ARRAY_SIZE(update_reg); i++) 991 for (i = 0; i < ARRAY_SIZE(update_reg); i++)
992 snd_soc_update_bits(codec, update_reg[i], 0x100, 0x100); 992 snd_soc_update_bits(codec, update_reg[i], 0x100, 0x100);
993 993
994 wm8978_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
995
996 return 0;
997}
998
999/* power down chip */
1000static int wm8978_remove(struct snd_soc_codec *codec)
1001{
1002 wm8978_set_bias_level(codec, SND_SOC_BIAS_OFF);
1003 return 0; 994 return 0;
1004} 995}
1005 996
1006static struct snd_soc_codec_driver soc_codec_dev_wm8978 = { 997static struct snd_soc_codec_driver soc_codec_dev_wm8978 = {
1007 .probe = wm8978_probe, 998 .probe = wm8978_probe,
1008 .remove = wm8978_remove,
1009 .suspend = wm8978_suspend, 999 .suspend = wm8978_suspend,
1010 .resume = wm8978_resume, 1000 .resume = wm8978_resume,
1011 .set_bias_level = wm8978_set_bias_level, 1001 .set_bias_level = wm8978_set_bias_level,
diff --git a/sound/soc/codecs/wm8983.c b/sound/soc/codecs/wm8983.c
index ac5defda8824..5d1cf08a72b8 100644
--- a/sound/soc/codecs/wm8983.c
+++ b/sound/soc/codecs/wm8983.c
@@ -967,29 +967,6 @@ static int wm8983_set_bias_level(struct snd_soc_codec *codec,
967 return 0; 967 return 0;
968} 968}
969 969
970#ifdef CONFIG_PM
971static int wm8983_suspend(struct snd_soc_codec *codec)
972{
973 wm8983_set_bias_level(codec, SND_SOC_BIAS_OFF);
974 return 0;
975}
976
977static int wm8983_resume(struct snd_soc_codec *codec)
978{
979 wm8983_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
980 return 0;
981}
982#else
983#define wm8983_suspend NULL
984#define wm8983_resume NULL
985#endif
986
987static int wm8983_remove(struct snd_soc_codec *codec)
988{
989 wm8983_set_bias_level(codec, SND_SOC_BIAS_OFF);
990 return 0;
991}
992
993static int wm8983_probe(struct snd_soc_codec *codec) 970static int wm8983_probe(struct snd_soc_codec *codec)
994{ 971{
995 int ret; 972 int ret;
@@ -1055,10 +1032,8 @@ static struct snd_soc_dai_driver wm8983_dai = {
1055 1032
1056static struct snd_soc_codec_driver soc_codec_dev_wm8983 = { 1033static struct snd_soc_codec_driver soc_codec_dev_wm8983 = {
1057 .probe = wm8983_probe, 1034 .probe = wm8983_probe,
1058 .remove = wm8983_remove,
1059 .suspend = wm8983_suspend,
1060 .resume = wm8983_resume,
1061 .set_bias_level = wm8983_set_bias_level, 1035 .set_bias_level = wm8983_set_bias_level,
1036 .suspend_bias_off = true,
1062 .controls = wm8983_snd_controls, 1037 .controls = wm8983_snd_controls,
1063 .num_controls = ARRAY_SIZE(wm8983_snd_controls), 1038 .num_controls = ARRAY_SIZE(wm8983_snd_controls),
1064 .dapm_widgets = wm8983_dapm_widgets, 1039 .dapm_widgets = wm8983_dapm_widgets,
diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c
index ee380190399f..0b3b54c9971d 100644
--- a/sound/soc/codecs/wm8985.c
+++ b/sound/soc/codecs/wm8985.c
@@ -961,29 +961,6 @@ static int wm8985_set_bias_level(struct snd_soc_codec *codec,
961 return 0; 961 return 0;
962} 962}
963 963
964#ifdef CONFIG_PM
965static int wm8985_suspend(struct snd_soc_codec *codec)
966{
967 wm8985_set_bias_level(codec, SND_SOC_BIAS_OFF);
968 return 0;
969}
970
971static int wm8985_resume(struct snd_soc_codec *codec)
972{
973 wm8985_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
974 return 0;
975}
976#else
977#define wm8985_suspend NULL
978#define wm8985_resume NULL
979#endif
980
981static int wm8985_remove(struct snd_soc_codec *codec)
982{
983 wm8985_set_bias_level(codec, SND_SOC_BIAS_OFF);
984 return 0;
985}
986
987static int wm8985_probe(struct snd_soc_codec *codec) 964static int wm8985_probe(struct snd_soc_codec *codec)
988{ 965{
989 size_t i; 966 size_t i;
@@ -1023,7 +1000,6 @@ static int wm8985_probe(struct snd_soc_codec *codec)
1023 snd_soc_update_bits(codec, WM8985_BIAS_CTRL, WM8985_BIASCUT, 1000 snd_soc_update_bits(codec, WM8985_BIAS_CTRL, WM8985_BIASCUT,
1024 WM8985_BIASCUT); 1001 WM8985_BIASCUT);
1025 1002
1026 wm8985_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1027 return 0; 1003 return 0;
1028 1004
1029err_reg_enable: 1005err_reg_enable:
@@ -1064,10 +1040,8 @@ static struct snd_soc_dai_driver wm8985_dai = {
1064 1040
1065static struct snd_soc_codec_driver soc_codec_dev_wm8985 = { 1041static struct snd_soc_codec_driver soc_codec_dev_wm8985 = {
1066 .probe = wm8985_probe, 1042 .probe = wm8985_probe,
1067 .remove = wm8985_remove,
1068 .suspend = wm8985_suspend,
1069 .resume = wm8985_resume,
1070 .set_bias_level = wm8985_set_bias_level, 1043 .set_bias_level = wm8985_set_bias_level,
1044 .suspend_bias_off = true,
1071 1045
1072 .controls = wm8985_snd_controls, 1046 .controls = wm8985_snd_controls,
1073 .num_controls = ARRAY_SIZE(wm8985_snd_controls), 1047 .num_controls = ARRAY_SIZE(wm8985_snd_controls),
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index a5130d965146..e418199155a8 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -793,21 +793,6 @@ static struct snd_soc_dai_driver wm8988_dai = {
793 .symmetric_rates = 1, 793 .symmetric_rates = 1,
794}; 794};
795 795
796static int wm8988_suspend(struct snd_soc_codec *codec)
797{
798 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
799
800 wm8988_set_bias_level(codec, SND_SOC_BIAS_OFF);
801 regcache_mark_dirty(wm8988->regmap);
802 return 0;
803}
804
805static int wm8988_resume(struct snd_soc_codec *codec)
806{
807 wm8988_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
808 return 0;
809}
810
811static int wm8988_probe(struct snd_soc_codec *codec) 796static int wm8988_probe(struct snd_soc_codec *codec)
812{ 797{
813 int ret = 0; 798 int ret = 0;
@@ -825,23 +810,13 @@ static int wm8988_probe(struct snd_soc_codec *codec)
825 snd_soc_update_bits(codec, WM8988_ROUT2V, 0x0100, 0x0100); 810 snd_soc_update_bits(codec, WM8988_ROUT2V, 0x0100, 0x0100);
826 snd_soc_update_bits(codec, WM8988_RINVOL, 0x0100, 0x0100); 811 snd_soc_update_bits(codec, WM8988_RINVOL, 0x0100, 0x0100);
827 812
828 wm8988_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
829
830 return 0;
831}
832
833static int wm8988_remove(struct snd_soc_codec *codec)
834{
835 wm8988_set_bias_level(codec, SND_SOC_BIAS_OFF);
836 return 0; 813 return 0;
837} 814}
838 815
839static struct snd_soc_codec_driver soc_codec_dev_wm8988 = { 816static struct snd_soc_codec_driver soc_codec_dev_wm8988 = {
840 .probe = wm8988_probe, 817 .probe = wm8988_probe,
841 .remove = wm8988_remove,
842 .suspend = wm8988_suspend,
843 .resume = wm8988_resume,
844 .set_bias_level = wm8988_set_bias_level, 818 .set_bias_level = wm8988_set_bias_level,
819 .suspend_bias_off = true,
845 820
846 .controls = wm8988_snd_controls, 821 .controls = wm8988_snd_controls,
847 .num_controls = ARRAY_SIZE(wm8988_snd_controls), 822 .num_controls = ARRAY_SIZE(wm8988_snd_controls),
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index 03e43e3f395e..8a584229310a 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -1271,18 +1271,6 @@ static struct snd_soc_dai_driver wm8990_dai = {
1271 .ops = &wm8990_dai_ops, 1271 .ops = &wm8990_dai_ops,
1272}; 1272};
1273 1273
1274static int wm8990_suspend(struct snd_soc_codec *codec)
1275{
1276 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1277 return 0;
1278}
1279
1280static int wm8990_resume(struct snd_soc_codec *codec)
1281{
1282 wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1283 return 0;
1284}
1285
1286/* 1274/*
1287 * initialise the WM8990 driver 1275 * initialise the WM8990 driver
1288 * register the mixer and dsp interfaces with the kernel 1276 * register the mixer and dsp interfaces with the kernel
@@ -1309,19 +1297,11 @@ static int wm8990_probe(struct snd_soc_codec *codec)
1309 return 0; 1297 return 0;
1310} 1298}
1311 1299
1312/* power down chip */
1313static int wm8990_remove(struct snd_soc_codec *codec)
1314{
1315 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1316 return 0;
1317}
1318
1319static struct snd_soc_codec_driver soc_codec_dev_wm8990 = { 1300static struct snd_soc_codec_driver soc_codec_dev_wm8990 = {
1320 .probe = wm8990_probe, 1301 .probe = wm8990_probe,
1321 .remove = wm8990_remove,
1322 .suspend = wm8990_suspend,
1323 .resume = wm8990_resume,
1324 .set_bias_level = wm8990_set_bias_level, 1302 .set_bias_level = wm8990_set_bias_level,
1303 .suspend_bias_off = true,
1304
1325 .controls = wm8990_snd_controls, 1305 .controls = wm8990_snd_controls,
1326 .num_controls = ARRAY_SIZE(wm8990_snd_controls), 1306 .num_controls = ARRAY_SIZE(wm8990_snd_controls),
1327 .dapm_widgets = wm8990_dapm_widgets, 1307 .dapm_widgets = wm8990_dapm_widgets,
diff --git a/sound/soc/codecs/wm8991.c b/sound/soc/codecs/wm8991.c
index d0be89731cdb..b0ac2c3e31b9 100644
--- a/sound/soc/codecs/wm8991.c
+++ b/sound/soc/codecs/wm8991.c
@@ -1227,32 +1227,6 @@ static int wm8991_set_bias_level(struct snd_soc_codec *codec,
1227 return 0; 1227 return 0;
1228} 1228}
1229 1229
1230static int wm8991_suspend(struct snd_soc_codec *codec)
1231{
1232 wm8991_set_bias_level(codec, SND_SOC_BIAS_OFF);
1233 return 0;
1234}
1235
1236static int wm8991_resume(struct snd_soc_codec *codec)
1237{
1238 wm8991_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1239 return 0;
1240}
1241
1242/* power down chip */
1243static int wm8991_remove(struct snd_soc_codec *codec)
1244{
1245 wm8991_set_bias_level(codec, SND_SOC_BIAS_OFF);
1246 return 0;
1247}
1248
1249static int wm8991_probe(struct snd_soc_codec *codec)
1250{
1251 wm8991_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1252
1253 return 0;
1254}
1255
1256#define WM8991_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 1230#define WM8991_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1257 SNDRV_PCM_FMTBIT_S24_LE) 1231 SNDRV_PCM_FMTBIT_S24_LE)
1258 1232
@@ -1293,11 +1267,9 @@ static struct snd_soc_dai_driver wm8991_dai = {
1293}; 1267};
1294 1268
1295static struct snd_soc_codec_driver soc_codec_dev_wm8991 = { 1269static struct snd_soc_codec_driver soc_codec_dev_wm8991 = {
1296 .probe = wm8991_probe,
1297 .remove = wm8991_remove,
1298 .suspend = wm8991_suspend,
1299 .resume = wm8991_resume,
1300 .set_bias_level = wm8991_set_bias_level, 1270 .set_bias_level = wm8991_set_bias_level,
1271 .suspend_bias_off = true,
1272
1301 .controls = wm8991_snd_controls, 1273 .controls = wm8991_snd_controls,
1302 .num_controls = ARRAY_SIZE(wm8991_snd_controls), 1274 .num_controls = ARRAY_SIZE(wm8991_snd_controls),
1303 .dapm_widgets = wm8991_dapm_widgets, 1275 .dapm_widgets = wm8991_dapm_widgets,
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index 93b14eda355a..53c6fe359496 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -1486,7 +1486,6 @@ static int wm8993_probe(struct snd_soc_codec *codec)
1486{ 1486{
1487 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 1487 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1488 struct snd_soc_dapm_context *dapm = &codec->dapm; 1488 struct snd_soc_dapm_context *dapm = &codec->dapm;
1489 int ret;
1490 1489
1491 wm8993->hubs_data.hp_startup_mode = 1; 1490 wm8993->hubs_data.hp_startup_mode = 1;
1492 wm8993->hubs_data.dcs_codes_l = -2; 1491 wm8993->hubs_data.dcs_codes_l = -2;
@@ -1518,10 +1517,6 @@ static int wm8993_probe(struct snd_soc_codec *codec)
1518 wm8993->pdata.micbias1_lvl, 1517 wm8993->pdata.micbias1_lvl,
1519 wm8993->pdata.micbias2_lvl); 1518 wm8993->pdata.micbias2_lvl);
1520 1519
1521 ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1522 if (ret != 0)
1523 return ret;
1524
1525 snd_soc_add_codec_controls(codec, wm8993_snd_controls, 1520 snd_soc_add_codec_controls(codec, wm8993_snd_controls,
1526 ARRAY_SIZE(wm8993_snd_controls)); 1521 ARRAY_SIZE(wm8993_snd_controls));
1527 if (wm8993->pdata.num_retune_configs != 0) { 1522 if (wm8993->pdata.num_retune_configs != 0) {
@@ -1550,12 +1545,6 @@ static int wm8993_probe(struct snd_soc_codec *codec)
1550 1545
1551} 1546}
1552 1547
1553static int wm8993_remove(struct snd_soc_codec *codec)
1554{
1555 wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF);
1556 return 0;
1557}
1558
1559#ifdef CONFIG_PM 1548#ifdef CONFIG_PM
1560static int wm8993_suspend(struct snd_soc_codec *codec) 1549static int wm8993_suspend(struct snd_soc_codec *codec)
1561{ 1550{
@@ -1629,7 +1618,6 @@ static const struct regmap_config wm8993_regmap = {
1629 1618
1630static struct snd_soc_codec_driver soc_codec_dev_wm8993 = { 1619static struct snd_soc_codec_driver soc_codec_dev_wm8993 = {
1631 .probe = wm8993_probe, 1620 .probe = wm8993_probe,
1632 .remove = wm8993_remove,
1633 .suspend = wm8993_suspend, 1621 .suspend = wm8993_suspend,
1634 .resume = wm8993_resume, 1622 .resume = wm8993_resume,
1635 .set_bias_level = wm8993_set_bias_level, 1623 .set_bias_level = wm8993_set_bias_level,
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 1fcb9f3f3097..36b767fa37a6 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -4391,8 +4391,6 @@ static int wm8994_codec_remove(struct snd_soc_codec *codec)
4391 struct wm8994 *control = wm8994->wm8994; 4391 struct wm8994 *control = wm8994->wm8994;
4392 int i; 4392 int i;
4393 4393
4394 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
4395
4396 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) 4394 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
4397 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i, 4395 wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
4398 &wm8994->fll_locked[i]); 4396 &wm8994->fll_locked[i]);
@@ -4457,6 +4455,8 @@ static int wm8994_probe(struct platform_device *pdev)
4457 return -ENOMEM; 4455 return -ENOMEM;
4458 platform_set_drvdata(pdev, wm8994); 4456 platform_set_drvdata(pdev, wm8994);
4459 4457
4458 mutex_init(&wm8994->fw_lock);
4459
4460 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent); 4460 wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
4461 4461
4462 pm_runtime_enable(&pdev->dev); 4462 pm_runtime_enable(&pdev->dev);
diff --git a/sound/soc/codecs/wm8994.h b/sound/soc/codecs/wm8994.h
index 6536f8d45ac6..dd73387b1cc4 100644
--- a/sound/soc/codecs/wm8994.h
+++ b/sound/soc/codecs/wm8994.h
@@ -13,6 +13,7 @@
13#include <linux/firmware.h> 13#include <linux/firmware.h>
14#include <linux/completion.h> 14#include <linux/completion.h>
15#include <linux/workqueue.h> 15#include <linux/workqueue.h>
16#include <linux/mutex.h>
16 17
17#include "wm_hubs.h" 18#include "wm_hubs.h"
18 19
@@ -156,6 +157,7 @@ struct wm8994_priv {
156 unsigned int aif1clk_disable:1; 157 unsigned int aif1clk_disable:1;
157 unsigned int aif2clk_disable:1; 158 unsigned int aif2clk_disable:1;
158 159
160 struct mutex fw_lock;
159 int dsp_active; 161 int dsp_active;
160 const struct firmware *cur_fw; 162 const struct firmware *cur_fw;
161 const struct firmware *mbc; 163 const struct firmware *mbc;
diff --git a/sound/soc/codecs/wm8995.c b/sound/soc/codecs/wm8995.c
index 1288edeb8c7d..c280f0a3a424 100644
--- a/sound/soc/codecs/wm8995.c
+++ b/sound/soc/codecs/wm8995.c
@@ -2004,7 +2004,6 @@ static int wm8995_remove(struct snd_soc_codec *codec)
2004 int i; 2004 int i;
2005 2005
2006 wm8995 = snd_soc_codec_get_drvdata(codec); 2006 wm8995 = snd_soc_codec_get_drvdata(codec);
2007 wm8995_set_bias_level(codec, SND_SOC_BIAS_OFF);
2008 2007
2009 for (i = 0; i < ARRAY_SIZE(wm8995->supplies); ++i) 2008 for (i = 0; i < ARRAY_SIZE(wm8995->supplies); ++i)
2010 regulator_unregister_notifier(wm8995->supplies[i].consumer, 2009 regulator_unregister_notifier(wm8995->supplies[i].consumer,
@@ -2078,8 +2077,6 @@ static int wm8995_probe(struct snd_soc_codec *codec)
2078 goto err_reg_enable; 2077 goto err_reg_enable;
2079 } 2078 }
2080 2079
2081 wm8995_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2082
2083 /* Latch volume updates (right only; we always do left then right). */ 2080 /* Latch volume updates (right only; we always do left then right). */
2084 snd_soc_update_bits(codec, WM8995_AIF1_DAC1_RIGHT_VOLUME, 2081 snd_soc_update_bits(codec, WM8995_AIF1_DAC1_RIGHT_VOLUME,
2085 WM8995_AIF1DAC1_VU_MASK, WM8995_AIF1DAC1_VU); 2082 WM8995_AIF1DAC1_VU_MASK, WM8995_AIF1DAC1_VU);
@@ -2102,13 +2099,6 @@ static int wm8995_probe(struct snd_soc_codec *codec)
2102 2099
2103 wm8995_update_class_w(codec); 2100 wm8995_update_class_w(codec);
2104 2101
2105 snd_soc_add_codec_controls(codec, wm8995_snd_controls,
2106 ARRAY_SIZE(wm8995_snd_controls));
2107 snd_soc_dapm_new_controls(&codec->dapm, wm8995_dapm_widgets,
2108 ARRAY_SIZE(wm8995_dapm_widgets));
2109 snd_soc_dapm_add_routes(&codec->dapm, wm8995_intercon,
2110 ARRAY_SIZE(wm8995_intercon));
2111
2112 return 0; 2102 return 0;
2113 2103
2114err_reg_enable: 2104err_reg_enable:
@@ -2205,6 +2195,13 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8995 = {
2205 .remove = wm8995_remove, 2195 .remove = wm8995_remove,
2206 .set_bias_level = wm8995_set_bias_level, 2196 .set_bias_level = wm8995_set_bias_level,
2207 .idle_bias_off = true, 2197 .idle_bias_off = true,
2198
2199 .controls = wm8995_snd_controls,
2200 .num_controls = ARRAY_SIZE(wm8995_snd_controls),
2201 .dapm_widgets = wm8995_dapm_widgets,
2202 .num_dapm_widgets = ARRAY_SIZE(wm8995_dapm_widgets),
2203 .dapm_routes = wm8995_intercon,
2204 .num_dapm_routes = ARRAY_SIZE(wm8995_intercon),
2208}; 2205};
2209 2206
2210static struct regmap_config wm8995_regmap = { 2207static struct regmap_config wm8995_regmap = {
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index 0cdc9e2184ab..b1d946facd57 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -1277,15 +1277,8 @@ static int wm9081_probe(struct snd_soc_codec *codec)
1277 return 0; 1277 return 0;
1278} 1278}
1279 1279
1280static int wm9081_remove(struct snd_soc_codec *codec)
1281{
1282 wm9081_set_bias_level(codec, SND_SOC_BIAS_OFF);
1283 return 0;
1284}
1285
1286static struct snd_soc_codec_driver soc_codec_dev_wm9081 = { 1280static struct snd_soc_codec_driver soc_codec_dev_wm9081 = {
1287 .probe = wm9081_probe, 1281 .probe = wm9081_probe,
1288 .remove = wm9081_remove,
1289 1282
1290 .set_sysclk = wm9081_set_sysclk, 1283 .set_sysclk = wm9081_set_sysclk,
1291 .set_bias_level = wm9081_set_bias_level, 1284 .set_bias_level = wm9081_set_bias_level,
diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c
index a13f0725611a..6ffe8dc4f3fa 100644
--- a/sound/soc/codecs/wm9090.c
+++ b/sound/soc/codecs/wm9090.c
@@ -550,45 +550,15 @@ static int wm9090_probe(struct snd_soc_codec *codec)
550 snd_soc_update_bits(codec, WM9090_CLOCKING_1, 550 snd_soc_update_bits(codec, WM9090_CLOCKING_1,
551 WM9090_TOCLK_ENA, WM9090_TOCLK_ENA); 551 WM9090_TOCLK_ENA, WM9090_TOCLK_ENA);
552 552
553 wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
554
555 wm9090_add_controls(codec); 553 wm9090_add_controls(codec);
556 554
557 return 0; 555 return 0;
558} 556}
559 557
560#ifdef CONFIG_PM
561static int wm9090_suspend(struct snd_soc_codec *codec)
562{
563 wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
564
565 return 0;
566}
567
568static int wm9090_resume(struct snd_soc_codec *codec)
569{
570 wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
571
572 return 0;
573}
574#else
575#define wm9090_suspend NULL
576#define wm9090_resume NULL
577#endif
578
579static int wm9090_remove(struct snd_soc_codec *codec)
580{
581 wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
582
583 return 0;
584}
585
586static struct snd_soc_codec_driver soc_codec_dev_wm9090 = { 558static struct snd_soc_codec_driver soc_codec_dev_wm9090 = {
587 .probe = wm9090_probe, 559 .probe = wm9090_probe,
588 .remove = wm9090_remove,
589 .suspend = wm9090_suspend,
590 .resume = wm9090_resume,
591 .set_bias_level = wm9090_set_bias_level, 560 .set_bias_level = wm9090_set_bias_level,
561 .suspend_bias_off = true,
592}; 562};
593 563
594static const struct regmap_config wm9090_regmap = { 564static const struct regmap_config wm9090_regmap = {
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index c0b7f45dfa37..d3a800fa6f06 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -203,13 +203,14 @@ static const struct snd_soc_dapm_route wm9705_audio_map[] = {
203/* We use a register cache to enhance read performance. */ 203/* We use a register cache to enhance read performance. */
204static unsigned int ac97_read(struct snd_soc_codec *codec, unsigned int reg) 204static unsigned int ac97_read(struct snd_soc_codec *codec, unsigned int reg)
205{ 205{
206 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
206 u16 *cache = codec->reg_cache; 207 u16 *cache = codec->reg_cache;
207 208
208 switch (reg) { 209 switch (reg) {
209 case AC97_RESET: 210 case AC97_RESET:
210 case AC97_VENDOR_ID1: 211 case AC97_VENDOR_ID1:
211 case AC97_VENDOR_ID2: 212 case AC97_VENDOR_ID2:
212 return soc_ac97_ops->read(codec->ac97, reg); 213 return soc_ac97_ops->read(ac97, reg);
213 default: 214 default:
214 reg = reg >> 1; 215 reg = reg >> 1;
215 216
@@ -223,9 +224,10 @@ static unsigned int ac97_read(struct snd_soc_codec *codec, unsigned int reg)
223static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, 224static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
224 unsigned int val) 225 unsigned int val)
225{ 226{
227 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
226 u16 *cache = codec->reg_cache; 228 u16 *cache = codec->reg_cache;
227 229
228 soc_ac97_ops->write(codec->ac97, reg, val); 230 soc_ac97_ops->write(ac97, reg, val);
229 reg = reg >> 1; 231 reg = reg >> 1;
230 if (reg < (ARRAY_SIZE(wm9705_reg))) 232 if (reg < (ARRAY_SIZE(wm9705_reg)))
231 cache[reg] = val; 233 cache[reg] = val;
@@ -263,7 +265,6 @@ static const struct snd_soc_dai_ops wm9705_dai_ops = {
263static struct snd_soc_dai_driver wm9705_dai[] = { 265static struct snd_soc_dai_driver wm9705_dai[] = {
264 { 266 {
265 .name = "wm9705-hifi", 267 .name = "wm9705-hifi",
266 .ac97_control = 1,
267 .playback = { 268 .playback = {
268 .stream_name = "HiFi Playback", 269 .stream_name = "HiFi Playback",
269 .channels_min = 1, 270 .channels_min = 1,
@@ -294,36 +295,41 @@ static struct snd_soc_dai_driver wm9705_dai[] = {
294 295
295static int wm9705_reset(struct snd_soc_codec *codec) 296static int wm9705_reset(struct snd_soc_codec *codec)
296{ 297{
298 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
299
297 if (soc_ac97_ops->reset) { 300 if (soc_ac97_ops->reset) {
298 soc_ac97_ops->reset(codec->ac97); 301 soc_ac97_ops->reset(ac97);
299 if (ac97_read(codec, 0) == wm9705_reg[0]) 302 if (ac97_read(codec, 0) == wm9705_reg[0])
300 return 0; /* Success */ 303 return 0; /* Success */
301 } 304 }
302 305
306 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
307
303 return -EIO; 308 return -EIO;
304} 309}
305 310
306#ifdef CONFIG_PM 311#ifdef CONFIG_PM
307static int wm9705_soc_suspend(struct snd_soc_codec *codec) 312static int wm9705_soc_suspend(struct snd_soc_codec *codec)
308{ 313{
309 soc_ac97_ops->write(codec->ac97, AC97_POWERDOWN, 0xffff); 314 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
315
316 soc_ac97_ops->write(ac97, AC97_POWERDOWN, 0xffff);
310 317
311 return 0; 318 return 0;
312} 319}
313 320
314static int wm9705_soc_resume(struct snd_soc_codec *codec) 321static int wm9705_soc_resume(struct snd_soc_codec *codec)
315{ 322{
323 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
316 int i, ret; 324 int i, ret;
317 u16 *cache = codec->reg_cache; 325 u16 *cache = codec->reg_cache;
318 326
319 ret = wm9705_reset(codec); 327 ret = wm9705_reset(codec);
320 if (ret < 0) { 328 if (ret < 0)
321 printk(KERN_ERR "could not reset AC97 codec\n");
322 return ret; 329 return ret;
323 }
324 330
325 for (i = 2; i < ARRAY_SIZE(wm9705_reg) << 1; i += 2) { 331 for (i = 2; i < ARRAY_SIZE(wm9705_reg) << 1; i += 2) {
326 soc_ac97_ops->write(codec->ac97, i, cache[i>>1]); 332 soc_ac97_ops->write(ac97, i, cache[i>>1]);
327 } 333 }
328 334
329 return 0; 335 return 0;
@@ -335,31 +341,34 @@ static int wm9705_soc_resume(struct snd_soc_codec *codec)
335 341
336static int wm9705_soc_probe(struct snd_soc_codec *codec) 342static int wm9705_soc_probe(struct snd_soc_codec *codec)
337{ 343{
344 struct snd_ac97 *ac97;
338 int ret = 0; 345 int ret = 0;
339 346
340 ret = snd_soc_new_ac97_codec(codec, soc_ac97_ops, 0); 347 ac97 = snd_soc_new_ac97_codec(codec);
341 if (ret < 0) { 348 if (IS_ERR(ac97)) {
342 printk(KERN_ERR "wm9705: failed to register AC97 codec\n"); 349 ret = PTR_ERR(ac97);
350 dev_err(codec->dev, "Failed to register AC97 codec\n");
343 return ret; 351 return ret;
344 } 352 }
345 353
354 snd_soc_codec_set_drvdata(codec, ac97);
355
346 ret = wm9705_reset(codec); 356 ret = wm9705_reset(codec);
347 if (ret) 357 if (ret)
348 goto reset_err; 358 goto reset_err;
349 359
350 snd_soc_add_codec_controls(codec, wm9705_snd_ac97_controls,
351 ARRAY_SIZE(wm9705_snd_ac97_controls));
352
353 return 0; 360 return 0;
354 361
355reset_err: 362reset_err:
356 snd_soc_free_ac97_codec(codec); 363 snd_soc_free_ac97_codec(ac97);
357 return ret; 364 return ret;
358} 365}
359 366
360static int wm9705_soc_remove(struct snd_soc_codec *codec) 367static int wm9705_soc_remove(struct snd_soc_codec *codec)
361{ 368{
362 snd_soc_free_ac97_codec(codec); 369 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
370
371 snd_soc_free_ac97_codec(ac97);
363 return 0; 372 return 0;
364} 373}
365 374
@@ -374,6 +383,9 @@ static struct snd_soc_codec_driver soc_codec_dev_wm9705 = {
374 .reg_word_size = sizeof(u16), 383 .reg_word_size = sizeof(u16),
375 .reg_cache_step = 2, 384 .reg_cache_step = 2,
376 .reg_cache_default = wm9705_reg, 385 .reg_cache_default = wm9705_reg,
386
387 .controls = wm9705_snd_ac97_controls,
388 .num_controls = ARRAY_SIZE(wm9705_snd_ac97_controls),
377 .dapm_widgets = wm9705_dapm_widgets, 389 .dapm_widgets = wm9705_dapm_widgets,
378 .num_dapm_widgets = ARRAY_SIZE(wm9705_dapm_widgets), 390 .num_dapm_widgets = ARRAY_SIZE(wm9705_dapm_widgets),
379 .dapm_routes = wm9705_audio_map, 391 .dapm_routes = wm9705_audio_map,
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index c5eb746087b4..7c45971bb4ec 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -23,6 +23,12 @@
23#include <sound/tlv.h> 23#include <sound/tlv.h>
24#include "wm9712.h" 24#include "wm9712.h"
25 25
26struct wm9712_priv {
27 struct snd_ac97 *ac97;
28 unsigned int hp_mixer[2];
29 struct mutex lock;
30};
31
26static unsigned int ac97_read(struct snd_soc_codec *codec, 32static unsigned int ac97_read(struct snd_soc_codec *codec,
27 unsigned int reg); 33 unsigned int reg);
28static int ac97_write(struct snd_soc_codec *codec, 34static int ac97_write(struct snd_soc_codec *codec,
@@ -48,12 +54,10 @@ static const u16 wm9712_reg[] = {
48 0x0000, 0x0000, 0x0000, 0x0000, /* 6e */ 54 0x0000, 0x0000, 0x0000, 0x0000, /* 6e */
49 0x0000, 0x0000, 0x0000, 0x0006, /* 76 */ 55 0x0000, 0x0000, 0x0000, 0x0006, /* 76 */
50 0x0001, 0x0000, 0x574d, 0x4c12, /* 7e */ 56 0x0001, 0x0000, 0x574d, 0x4c12, /* 7e */
51 0x0000, 0x0000 /* virtual hp mixers */
52}; 57};
53 58
54/* virtual HP mixers regs */ 59#define HPL_MIXER 0x0
55#define HPL_MIXER 0x80 60#define HPR_MIXER 0x1
56#define HPR_MIXER 0x82
57 61
58static const char *wm9712_alc_select[] = {"None", "Left", "Right", "Stereo"}; 62static const char *wm9712_alc_select[] = {"None", "Left", "Right", "Stereo"};
59static const char *wm9712_alc_mux[] = {"Stereo", "Left", "Right", "None"}; 63static const char *wm9712_alc_mux[] = {"Stereo", "Left", "Right", "None"};
@@ -157,75 +161,108 @@ SOC_SINGLE_TLV("Mic 2 Volume", AC97_MIC, 0, 31, 1, main_tlv),
157SOC_SINGLE_TLV("Mic Boost Volume", AC97_MIC, 7, 1, 0, boost_tlv), 161SOC_SINGLE_TLV("Mic Boost Volume", AC97_MIC, 7, 1, 0, boost_tlv),
158}; 162};
159 163
164static const unsigned int wm9712_mixer_mute_regs[] = {
165 AC97_VIDEO,
166 AC97_PCM,
167 AC97_LINE,
168 AC97_PHONE,
169 AC97_CD,
170 AC97_PC_BEEP,
171};
172
160/* We have to create a fake left and right HP mixers because 173/* We have to create a fake left and right HP mixers because
161 * the codec only has a single control that is shared by both channels. 174 * the codec only has a single control that is shared by both channels.
162 * This makes it impossible to determine the audio path. 175 * This makes it impossible to determine the audio path.
163 */ 176 */
164static int mixer_event(struct snd_soc_dapm_widget *w, 177static int wm9712_hp_mixer_put(struct snd_kcontrol *kcontrol,
165 struct snd_kcontrol *k, int event) 178 struct snd_ctl_elem_value *ucontrol)
166{ 179{
167 u16 l, r, beep, line, phone, mic, pcm, aux; 180 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
168 181 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
169 l = ac97_read(w->codec, HPL_MIXER); 182 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
170 r = ac97_read(w->codec, HPR_MIXER); 183 unsigned int val = ucontrol->value.enumerated.item[0];
171 beep = ac97_read(w->codec, AC97_PC_BEEP); 184 struct soc_mixer_control *mc =
172 mic = ac97_read(w->codec, AC97_VIDEO); 185 (struct soc_mixer_control *)kcontrol->private_value;
173 phone = ac97_read(w->codec, AC97_PHONE); 186 unsigned int mixer, mask, shift, old;
174 line = ac97_read(w->codec, AC97_LINE); 187 struct snd_soc_dapm_update update;
175 pcm = ac97_read(w->codec, AC97_PCM); 188 bool change;
176 aux = ac97_read(w->codec, AC97_CD); 189
177 190 mixer = mc->shift >> 8;
178 if (l & 0x1 || r & 0x1) 191 shift = mc->shift & 0xff;
179 ac97_write(w->codec, AC97_VIDEO, mic & 0x7fff); 192 mask = 1 << shift;
193
194 mutex_lock(&wm9712->lock);
195 old = wm9712->hp_mixer[mixer];
196 if (ucontrol->value.enumerated.item[0])
197 wm9712->hp_mixer[mixer] |= mask;
180 else 198 else
181 ac97_write(w->codec, AC97_VIDEO, mic | 0x8000); 199 wm9712->hp_mixer[mixer] &= ~mask;
200
201 change = old != wm9712->hp_mixer[mixer];
202 if (change) {
203 update.kcontrol = kcontrol;
204 update.reg = wm9712_mixer_mute_regs[shift];
205 update.mask = 0x8000;
206 if ((wm9712->hp_mixer[0] & mask) ||
207 (wm9712->hp_mixer[1] & mask))
208 update.val = 0x0;
209 else
210 update.val = 0x8000;
211
212 snd_soc_dapm_mixer_update_power(dapm, kcontrol, val,
213 &update);
214 }
182 215
183 if (l & 0x2 || r & 0x2) 216 mutex_unlock(&wm9712->lock);
184 ac97_write(w->codec, AC97_PCM, pcm & 0x7fff);
185 else
186 ac97_write(w->codec, AC97_PCM, pcm | 0x8000);
187 217
188 if (l & 0x4 || r & 0x4) 218 return change;
189 ac97_write(w->codec, AC97_LINE, line & 0x7fff); 219}
190 else
191 ac97_write(w->codec, AC97_LINE, line | 0x8000);
192 220
193 if (l & 0x8 || r & 0x8) 221static int wm9712_hp_mixer_get(struct snd_kcontrol *kcontrol,
194 ac97_write(w->codec, AC97_PHONE, phone & 0x7fff); 222 struct snd_ctl_elem_value *ucontrol)
195 else 223{
196 ac97_write(w->codec, AC97_PHONE, phone | 0x8000); 224 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
225 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
226 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
227 struct soc_mixer_control *mc =
228 (struct soc_mixer_control *)kcontrol->private_value;
229 unsigned int shift, mixer;
197 230
198 if (l & 0x10 || r & 0x10) 231 mixer = mc->shift >> 8;
199 ac97_write(w->codec, AC97_CD, aux & 0x7fff); 232 shift = mc->shift & 0xff;
200 else
201 ac97_write(w->codec, AC97_CD, aux | 0x8000);
202 233
203 if (l & 0x20 || r & 0x20) 234 ucontrol->value.enumerated.item[0] =
204 ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff); 235 (wm9712->hp_mixer[mixer] >> shift) & 1;
205 else
206 ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000);
207 236
208 return 0; 237 return 0;
209} 238}
210 239
240#define WM9712_HP_MIXER_CTRL(xname, xmixer, xshift) { \
241 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
242 .info = snd_soc_info_volsw, \
243 .get = wm9712_hp_mixer_get, .put = wm9712_hp_mixer_put, \
244 .private_value = SOC_SINGLE_VALUE(SND_SOC_NOPM, \
245 (xmixer << 8) | xshift, 1, 0, 0) \
246}
247
211/* Left Headphone Mixers */ 248/* Left Headphone Mixers */
212static const struct snd_kcontrol_new wm9712_hpl_mixer_controls[] = { 249static const struct snd_kcontrol_new wm9712_hpl_mixer_controls[] = {
213 SOC_DAPM_SINGLE("PCBeep Bypass Switch", HPL_MIXER, 5, 1, 0), 250 WM9712_HP_MIXER_CTRL("PCBeep Bypass Switch", HPL_MIXER, 5),
214 SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 4, 1, 0), 251 WM9712_HP_MIXER_CTRL("Aux Playback Switch", HPL_MIXER, 4),
215 SOC_DAPM_SINGLE("Phone Bypass Switch", HPL_MIXER, 3, 1, 0), 252 WM9712_HP_MIXER_CTRL("Phone Bypass Switch", HPL_MIXER, 3),
216 SOC_DAPM_SINGLE("Line Bypass Switch", HPL_MIXER, 2, 1, 0), 253 WM9712_HP_MIXER_CTRL("Line Bypass Switch", HPL_MIXER, 2),
217 SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 1, 1, 0), 254 WM9712_HP_MIXER_CTRL("PCM Playback Switch", HPL_MIXER, 1),
218 SOC_DAPM_SINGLE("Mic Sidetone Switch", HPL_MIXER, 0, 1, 0), 255 WM9712_HP_MIXER_CTRL("Mic Sidetone Switch", HPL_MIXER, 0),
219}; 256};
220 257
221/* Right Headphone Mixers */ 258/* Right Headphone Mixers */
222static const struct snd_kcontrol_new wm9712_hpr_mixer_controls[] = { 259static const struct snd_kcontrol_new wm9712_hpr_mixer_controls[] = {
223 SOC_DAPM_SINGLE("PCBeep Bypass Switch", HPR_MIXER, 5, 1, 0), 260 WM9712_HP_MIXER_CTRL("PCBeep Bypass Switch", HPR_MIXER, 5),
224 SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 4, 1, 0), 261 WM9712_HP_MIXER_CTRL("Aux Playback Switch", HPR_MIXER, 4),
225 SOC_DAPM_SINGLE("Phone Bypass Switch", HPR_MIXER, 3, 1, 0), 262 WM9712_HP_MIXER_CTRL("Phone Bypass Switch", HPR_MIXER, 3),
226 SOC_DAPM_SINGLE("Line Bypass Switch", HPR_MIXER, 2, 1, 0), 263 WM9712_HP_MIXER_CTRL("Line Bypass Switch", HPR_MIXER, 2),
227 SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 1, 1, 0), 264 WM9712_HP_MIXER_CTRL("PCM Playback Switch", HPR_MIXER, 1),
228 SOC_DAPM_SINGLE("Mic Sidetone Switch", HPR_MIXER, 0, 1, 0), 265 WM9712_HP_MIXER_CTRL("Mic Sidetone Switch", HPR_MIXER, 0),
229}; 266};
230 267
231/* Speaker Mixer */ 268/* Speaker Mixer */
@@ -299,12 +336,10 @@ SND_SOC_DAPM_MUX("Right Mic Select Source", SND_SOC_NOPM, 0, 0,
299SND_SOC_DAPM_MUX("Differential Source", SND_SOC_NOPM, 0, 0, 336SND_SOC_DAPM_MUX("Differential Source", SND_SOC_NOPM, 0, 0,
300 &wm9712_diff_sel_controls), 337 &wm9712_diff_sel_controls),
301SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 338SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
302SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_INT_PAGING, 9, 1, 339SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_INT_PAGING, 9, 1,
303 &wm9712_hpl_mixer_controls[0], ARRAY_SIZE(wm9712_hpl_mixer_controls), 340 &wm9712_hpl_mixer_controls[0], ARRAY_SIZE(wm9712_hpl_mixer_controls)),
304 mixer_event, SND_SOC_DAPM_POST_REG), 341SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_INT_PAGING, 8, 1,
305SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_INT_PAGING, 8, 1, 342 &wm9712_hpr_mixer_controls[0], ARRAY_SIZE(wm9712_hpr_mixer_controls)),
306 &wm9712_hpr_mixer_controls[0], ARRAY_SIZE(wm9712_hpr_mixer_controls),
307 mixer_event, SND_SOC_DAPM_POST_REG),
308SND_SOC_DAPM_MIXER("Phone Mixer", AC97_INT_PAGING, 6, 1, 343SND_SOC_DAPM_MIXER("Phone Mixer", AC97_INT_PAGING, 6, 1,
309 &wm9712_phone_mixer_controls[0], ARRAY_SIZE(wm9712_phone_mixer_controls)), 344 &wm9712_phone_mixer_controls[0], ARRAY_SIZE(wm9712_phone_mixer_controls)),
310SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_INT_PAGING, 7, 1, 345SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_INT_PAGING, 7, 1,
@@ -450,12 +485,13 @@ static const struct snd_soc_dapm_route wm9712_audio_map[] = {
450static unsigned int ac97_read(struct snd_soc_codec *codec, 485static unsigned int ac97_read(struct snd_soc_codec *codec,
451 unsigned int reg) 486 unsigned int reg)
452{ 487{
488 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
453 u16 *cache = codec->reg_cache; 489 u16 *cache = codec->reg_cache;
454 490
455 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS || 491 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS ||
456 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 || 492 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
457 reg == AC97_REC_GAIN) 493 reg == AC97_REC_GAIN)
458 return soc_ac97_ops->read(codec->ac97, reg); 494 return soc_ac97_ops->read(wm9712->ac97, reg);
459 else { 495 else {
460 reg = reg >> 1; 496 reg = reg >> 1;
461 497
@@ -469,10 +505,10 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
469static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, 505static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
470 unsigned int val) 506 unsigned int val)
471{ 507{
508 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
472 u16 *cache = codec->reg_cache; 509 u16 *cache = codec->reg_cache;
473 510
474 if (reg < 0x7c) 511 soc_ac97_ops->write(wm9712->ac97, reg, val);
475 soc_ac97_ops->write(codec->ac97, reg, val);
476 reg = reg >> 1; 512 reg = reg >> 1;
477 if (reg < (ARRAY_SIZE(wm9712_reg))) 513 if (reg < (ARRAY_SIZE(wm9712_reg)))
478 cache[reg] = val; 514 cache[reg] = val;
@@ -532,7 +568,6 @@ static const struct snd_soc_dai_ops wm9712_dai_ops_aux = {
532static struct snd_soc_dai_driver wm9712_dai[] = { 568static struct snd_soc_dai_driver wm9712_dai[] = {
533{ 569{
534 .name = "wm9712-hifi", 570 .name = "wm9712-hifi",
535 .ac97_control = 1,
536 .playback = { 571 .playback = {
537 .stream_name = "HiFi Playback", 572 .stream_name = "HiFi Playback",
538 .channels_min = 1, 573 .channels_min = 1,
@@ -581,40 +616,35 @@ static int wm9712_set_bias_level(struct snd_soc_codec *codec,
581 616
582static int wm9712_reset(struct snd_soc_codec *codec, int try_warm) 617static int wm9712_reset(struct snd_soc_codec *codec, int try_warm)
583{ 618{
619 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
620
584 if (try_warm && soc_ac97_ops->warm_reset) { 621 if (try_warm && soc_ac97_ops->warm_reset) {
585 soc_ac97_ops->warm_reset(codec->ac97); 622 soc_ac97_ops->warm_reset(wm9712->ac97);
586 if (ac97_read(codec, 0) == wm9712_reg[0]) 623 if (ac97_read(codec, 0) == wm9712_reg[0])
587 return 1; 624 return 1;
588 } 625 }
589 626
590 soc_ac97_ops->reset(codec->ac97); 627 soc_ac97_ops->reset(wm9712->ac97);
591 if (soc_ac97_ops->warm_reset) 628 if (soc_ac97_ops->warm_reset)
592 soc_ac97_ops->warm_reset(codec->ac97); 629 soc_ac97_ops->warm_reset(wm9712->ac97);
593 if (ac97_read(codec, 0) != wm9712_reg[0]) 630 if (ac97_read(codec, 0) != wm9712_reg[0])
594 goto err; 631 goto err;
595 return 0; 632 return 0;
596 633
597err: 634err:
598 printk(KERN_ERR "WM9712 AC97 reset failed\n"); 635 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
599 return -EIO; 636 return -EIO;
600} 637}
601 638
602static int wm9712_soc_suspend(struct snd_soc_codec *codec)
603{
604 wm9712_set_bias_level(codec, SND_SOC_BIAS_OFF);
605 return 0;
606}
607
608static int wm9712_soc_resume(struct snd_soc_codec *codec) 639static int wm9712_soc_resume(struct snd_soc_codec *codec)
609{ 640{
641 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
610 int i, ret; 642 int i, ret;
611 u16 *cache = codec->reg_cache; 643 u16 *cache = codec->reg_cache;
612 644
613 ret = wm9712_reset(codec, 1); 645 ret = wm9712_reset(codec, 1);
614 if (ret < 0) { 646 if (ret < 0)
615 printk(KERN_ERR "could not reset AC97 codec\n");
616 return ret; 647 return ret;
617 }
618 648
619 wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 649 wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
620 650
@@ -624,7 +654,7 @@ static int wm9712_soc_resume(struct snd_soc_codec *codec)
624 if (i == AC97_INT_PAGING || i == AC97_POWERDOWN || 654 if (i == AC97_INT_PAGING || i == AC97_POWERDOWN ||
625 (i > 0x58 && i != 0x5c)) 655 (i > 0x58 && i != 0x5c))
626 continue; 656 continue;
627 soc_ac97_ops->write(codec->ac97, i, cache[i>>1]); 657 soc_ac97_ops->write(wm9712->ac97, i, cache[i>>1]);
628 } 658 }
629 } 659 }
630 660
@@ -633,52 +663,53 @@ static int wm9712_soc_resume(struct snd_soc_codec *codec)
633 663
634static int wm9712_soc_probe(struct snd_soc_codec *codec) 664static int wm9712_soc_probe(struct snd_soc_codec *codec)
635{ 665{
666 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
636 int ret = 0; 667 int ret = 0;
637 668
638 ret = snd_soc_new_ac97_codec(codec, soc_ac97_ops, 0); 669 wm9712->ac97 = snd_soc_new_ac97_codec(codec);
639 if (ret < 0) { 670 if (IS_ERR(wm9712->ac97)) {
640 printk(KERN_ERR "wm9712: failed to register AC97 codec\n"); 671 ret = PTR_ERR(wm9712->ac97);
672 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret);
641 return ret; 673 return ret;
642 } 674 }
643 675
644 ret = wm9712_reset(codec, 0); 676 ret = wm9712_reset(codec, 0);
645 if (ret < 0) { 677 if (ret < 0)
646 printk(KERN_ERR "Failed to reset WM9712: AC97 link error\n");
647 goto reset_err; 678 goto reset_err;
648 }
649 679
650 /* set alc mux to none */ 680 /* set alc mux to none */
651 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000); 681 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000);
652 682
653 wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
654 snd_soc_add_codec_controls(codec, wm9712_snd_ac97_controls,
655 ARRAY_SIZE(wm9712_snd_ac97_controls));
656
657 return 0; 683 return 0;
658 684
659reset_err: 685reset_err:
660 snd_soc_free_ac97_codec(codec); 686 snd_soc_free_ac97_codec(wm9712->ac97);
661 return ret; 687 return ret;
662} 688}
663 689
664static int wm9712_soc_remove(struct snd_soc_codec *codec) 690static int wm9712_soc_remove(struct snd_soc_codec *codec)
665{ 691{
666 snd_soc_free_ac97_codec(codec); 692 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
693
694 snd_soc_free_ac97_codec(wm9712->ac97);
667 return 0; 695 return 0;
668} 696}
669 697
670static struct snd_soc_codec_driver soc_codec_dev_wm9712 = { 698static struct snd_soc_codec_driver soc_codec_dev_wm9712 = {
671 .probe = wm9712_soc_probe, 699 .probe = wm9712_soc_probe,
672 .remove = wm9712_soc_remove, 700 .remove = wm9712_soc_remove,
673 .suspend = wm9712_soc_suspend,
674 .resume = wm9712_soc_resume, 701 .resume = wm9712_soc_resume,
675 .read = ac97_read, 702 .read = ac97_read,
676 .write = ac97_write, 703 .write = ac97_write,
677 .set_bias_level = wm9712_set_bias_level, 704 .set_bias_level = wm9712_set_bias_level,
705 .suspend_bias_off = true,
678 .reg_cache_size = ARRAY_SIZE(wm9712_reg), 706 .reg_cache_size = ARRAY_SIZE(wm9712_reg),
679 .reg_word_size = sizeof(u16), 707 .reg_word_size = sizeof(u16),
680 .reg_cache_step = 2, 708 .reg_cache_step = 2,
681 .reg_cache_default = wm9712_reg, 709 .reg_cache_default = wm9712_reg,
710
711 .controls = wm9712_snd_ac97_controls,
712 .num_controls = ARRAY_SIZE(wm9712_snd_ac97_controls),
682 .dapm_widgets = wm9712_dapm_widgets, 713 .dapm_widgets = wm9712_dapm_widgets,
683 .num_dapm_widgets = ARRAY_SIZE(wm9712_dapm_widgets), 714 .num_dapm_widgets = ARRAY_SIZE(wm9712_dapm_widgets),
684 .dapm_routes = wm9712_audio_map, 715 .dapm_routes = wm9712_audio_map,
@@ -687,6 +718,16 @@ static struct snd_soc_codec_driver soc_codec_dev_wm9712 = {
687 718
688static int wm9712_probe(struct platform_device *pdev) 719static int wm9712_probe(struct platform_device *pdev)
689{ 720{
721 struct wm9712_priv *wm9712;
722
723 wm9712 = devm_kzalloc(&pdev->dev, sizeof(*wm9712), GFP_KERNEL);
724 if (wm9712 == NULL)
725 return -ENOMEM;
726
727 mutex_init(&wm9712->lock);
728
729 platform_set_drvdata(pdev, wm9712);
730
690 return snd_soc_register_codec(&pdev->dev, 731 return snd_soc_register_codec(&pdev->dev,
691 &soc_codec_dev_wm9712, wm9712_dai, ARRAY_SIZE(wm9712_dai)); 732 &soc_codec_dev_wm9712, wm9712_dai, ARRAY_SIZE(wm9712_dai));
692} 733}
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index bddee30a4bc7..5df7f6d12bef 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -30,7 +30,10 @@
30#include "wm9713.h" 30#include "wm9713.h"
31 31
32struct wm9713_priv { 32struct wm9713_priv {
33 struct snd_ac97 *ac97;
33 u32 pll_in; /* PLL input frequency */ 34 u32 pll_in; /* PLL input frequency */
35 unsigned int hp_mixer[2];
36 struct mutex lock;
34}; 37};
35 38
36static unsigned int ac97_read(struct snd_soc_codec *codec, 39static unsigned int ac97_read(struct snd_soc_codec *codec,
@@ -59,13 +62,10 @@ static const u16 wm9713_reg[] = {
59 0x0000, 0x0000, 0x0000, 0x0000, 62 0x0000, 0x0000, 0x0000, 0x0000,
60 0x0000, 0x0000, 0x0000, 0x0006, 63 0x0000, 0x0000, 0x0000, 0x0006,
61 0x0001, 0x0000, 0x574d, 0x4c13, 64 0x0001, 0x0000, 0x574d, 0x4c13,
62 0x0000, 0x0000, 0x0000
63}; 65};
64 66
65/* virtual HP mixers regs */ 67#define HPL_MIXER 0
66#define HPL_MIXER 0x80 68#define HPR_MIXER 1
67#define HPR_MIXER 0x82
68#define MICB_MUX 0x82
69 69
70static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; 70static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
71static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; 71static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
@@ -110,7 +110,7 @@ SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */
110SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */ 110SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */
111SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */ 111SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */
112SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */ 112SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */
113SOC_ENUM_SINGLE(MICB_MUX, 0, 2, wm9713_micb_select), /* mic selection 19 */ 113SOC_ENUM_SINGLE_VIRT(2, wm9713_micb_select), /* mic selection 19 */
114}; 114};
115 115
116static const DECLARE_TLV_DB_SCALE(out_tlv, -4650, 150, 0); 116static const DECLARE_TLV_DB_SCALE(out_tlv, -4650, 150, 0);
@@ -234,6 +234,14 @@ static int wm9713_voice_shutdown(struct snd_soc_dapm_widget *w,
234 return 0; 234 return 0;
235} 235}
236 236
237static const unsigned int wm9713_mixer_mute_regs[] = {
238 AC97_PC_BEEP,
239 AC97_MASTER_TONE,
240 AC97_PHONE,
241 AC97_REC_SEL,
242 AC97_PCM,
243 AC97_AUX,
244};
237 245
238/* We have to create a fake left and right HP mixers because 246/* We have to create a fake left and right HP mixers because
239 * the codec only has a single control that is shared by both channels. 247 * the codec only has a single control that is shared by both channels.
@@ -241,73 +249,95 @@ static int wm9713_voice_shutdown(struct snd_soc_dapm_widget *w,
241 * register map, thus we add a new (virtual) register to help determine the 249 * register map, thus we add a new (virtual) register to help determine the
242 * audio route within the device. 250 * audio route within the device.
243 */ 251 */
244static int mixer_event(struct snd_soc_dapm_widget *w, 252static int wm9713_hp_mixer_put(struct snd_kcontrol *kcontrol,
245 struct snd_kcontrol *kcontrol, int event) 253 struct snd_ctl_elem_value *ucontrol)
246{ 254{
247 u16 l, r, beep, tone, phone, rec, pcm, aux; 255 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
248 256 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
249 l = ac97_read(w->codec, HPL_MIXER); 257 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
250 r = ac97_read(w->codec, HPR_MIXER); 258 unsigned int val = ucontrol->value.enumerated.item[0];
251 beep = ac97_read(w->codec, AC97_PC_BEEP); 259 struct soc_mixer_control *mc =
252 tone = ac97_read(w->codec, AC97_MASTER_TONE); 260 (struct soc_mixer_control *)kcontrol->private_value;
253 phone = ac97_read(w->codec, AC97_PHONE); 261 unsigned int mixer, mask, shift, old;
254 rec = ac97_read(w->codec, AC97_REC_SEL); 262 struct snd_soc_dapm_update update;
255 pcm = ac97_read(w->codec, AC97_PCM); 263 bool change;
256 aux = ac97_read(w->codec, AC97_AUX); 264
257 265 mixer = mc->shift >> 8;
258 if (event & SND_SOC_DAPM_PRE_REG) 266 shift = mc->shift & 0xff;
259 return 0; 267 mask = (1 << shift);
260 if ((l & 0x1) || (r & 0x1)) 268
261 ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff); 269 mutex_lock(&wm9713->lock);
270 old = wm9713->hp_mixer[mixer];
271 if (ucontrol->value.enumerated.item[0])
272 wm9713->hp_mixer[mixer] |= mask;
262 else 273 else
263 ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000); 274 wm9713->hp_mixer[mixer] &= ~mask;
275
276 change = old != wm9713->hp_mixer[mixer];
277 if (change) {
278 update.kcontrol = kcontrol;
279 update.reg = wm9713_mixer_mute_regs[shift];
280 update.mask = 0x8000;
281 if ((wm9713->hp_mixer[0] & mask) ||
282 (wm9713->hp_mixer[1] & mask))
283 update.val = 0x0;
284 else
285 update.val = 0x8000;
286
287 snd_soc_dapm_mixer_update_power(dapm, kcontrol, val,
288 &update);
289 }
264 290
265 if ((l & 0x2) || (r & 0x2)) 291 mutex_unlock(&wm9713->lock);
266 ac97_write(w->codec, AC97_MASTER_TONE, tone & 0x7fff);
267 else
268 ac97_write(w->codec, AC97_MASTER_TONE, tone | 0x8000);
269 292
270 if ((l & 0x4) || (r & 0x4)) 293 return change;
271 ac97_write(w->codec, AC97_PHONE, phone & 0x7fff); 294}
272 else
273 ac97_write(w->codec, AC97_PHONE, phone | 0x8000);
274 295
275 if ((l & 0x8) || (r & 0x8)) 296static int wm9713_hp_mixer_get(struct snd_kcontrol *kcontrol,
276 ac97_write(w->codec, AC97_REC_SEL, rec & 0x7fff); 297 struct snd_ctl_elem_value *ucontrol)
277 else 298{
278 ac97_write(w->codec, AC97_REC_SEL, rec | 0x8000); 299 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
300 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
301 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
302 struct soc_mixer_control *mc =
303 (struct soc_mixer_control *)kcontrol->private_value;
304 unsigned int mixer, shift;
279 305
280 if ((l & 0x10) || (r & 0x10)) 306 mixer = mc->shift >> 8;
281 ac97_write(w->codec, AC97_PCM, pcm & 0x7fff); 307 shift = mc->shift & 0xff;
282 else
283 ac97_write(w->codec, AC97_PCM, pcm | 0x8000);
284 308
285 if ((l & 0x20) || (r & 0x20)) 309 ucontrol->value.enumerated.item[0] =
286 ac97_write(w->codec, AC97_AUX, aux & 0x7fff); 310 (wm9713->hp_mixer[mixer] >> shift) & 1;
287 else
288 ac97_write(w->codec, AC97_AUX, aux | 0x8000);
289 311
290 return 0; 312 return 0;
291} 313}
292 314
315#define WM9713_HP_MIXER_CTRL(xname, xmixer, xshift) { \
316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
317 .info = snd_soc_info_volsw, \
318 .get = wm9713_hp_mixer_get, .put = wm9713_hp_mixer_put, \
319 .private_value = SOC_DOUBLE_VALUE(SND_SOC_NOPM, \
320 xshift, xmixer, 1, 0, 0) \
321}
322
293/* Left Headphone Mixers */ 323/* Left Headphone Mixers */
294static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = { 324static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = {
295SOC_DAPM_SINGLE("Beep Playback Switch", HPL_MIXER, 5, 1, 0), 325WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPL_MIXER, 5),
296SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0), 326WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPL_MIXER, 4),
297SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0), 327WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPL_MIXER, 3),
298SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0), 328WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPL_MIXER, 2),
299SOC_DAPM_SINGLE("MonoIn Playback Switch", HPL_MIXER, 1, 1, 0), 329WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPL_MIXER, 1),
300SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER, 0, 1, 0), 330WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPL_MIXER, 0),
301}; 331};
302 332
303/* Right Headphone Mixers */ 333/* Right Headphone Mixers */
304static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = { 334static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = {
305SOC_DAPM_SINGLE("Beep Playback Switch", HPR_MIXER, 5, 1, 0), 335WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPR_MIXER, 5),
306SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0), 336WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPR_MIXER, 4),
307SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0), 337WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPR_MIXER, 3),
308SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0), 338WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPR_MIXER, 2),
309SOC_DAPM_SINGLE("MonoIn Playback Switch", HPR_MIXER, 1, 1, 0), 339WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPR_MIXER, 1),
310SOC_DAPM_SINGLE("Bypass Playback Switch", HPR_MIXER, 0, 1, 0), 340WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPR_MIXER, 0),
311}; 341};
312 342
313/* headphone capture mux */ 343/* headphone capture mux */
@@ -429,12 +459,10 @@ SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0,
429 &wm9713_mic_sel_mux_controls), 459 &wm9713_mic_sel_mux_controls),
430SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0, 460SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0,
431 &wm9713_micb_sel_mux_controls), 461 &wm9713_micb_sel_mux_controls),
432SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_EXTENDED_MID, 3, 1, 462SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_EXTENDED_MID, 3, 1,
433 &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls), 463 &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls)),
434 mixer_event, SND_SOC_DAPM_POST_REG), 464SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_EXTENDED_MID, 2, 1,
435SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_EXTENDED_MID, 2, 1, 465 &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls)),
436 &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls),
437 mixer_event, SND_SOC_DAPM_POST_REG),
438SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1, 466SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1,
439 &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)), 467 &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)),
440SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1, 468SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1,
@@ -647,12 +675,13 @@ static const struct snd_soc_dapm_route wm9713_audio_map[] = {
647static unsigned int ac97_read(struct snd_soc_codec *codec, 675static unsigned int ac97_read(struct snd_soc_codec *codec,
648 unsigned int reg) 676 unsigned int reg)
649{ 677{
678 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
650 u16 *cache = codec->reg_cache; 679 u16 *cache = codec->reg_cache;
651 680
652 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS || 681 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS ||
653 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 || 682 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
654 reg == AC97_CD) 683 reg == AC97_CD)
655 return soc_ac97_ops->read(codec->ac97, reg); 684 return soc_ac97_ops->read(wm9713->ac97, reg);
656 else { 685 else {
657 reg = reg >> 1; 686 reg = reg >> 1;
658 687
@@ -666,9 +695,10 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
666static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, 695static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
667 unsigned int val) 696 unsigned int val)
668{ 697{
698 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
699
669 u16 *cache = codec->reg_cache; 700 u16 *cache = codec->reg_cache;
670 if (reg < 0x7c) 701 soc_ac97_ops->write(wm9713->ac97, reg, val);
671 soc_ac97_ops->write(codec->ac97, reg, val);
672 reg = reg >> 1; 702 reg = reg >> 1;
673 if (reg < (ARRAY_SIZE(wm9713_reg))) 703 if (reg < (ARRAY_SIZE(wm9713_reg)))
674 cache[reg] = val; 704 cache[reg] = val;
@@ -689,7 +719,8 @@ struct _pll_div {
689 * to allow rounding later */ 719 * to allow rounding later */
690#define FIXED_PLL_SIZE ((1 << 22) * 10) 720#define FIXED_PLL_SIZE ((1 << 22) * 10)
691 721
692static void pll_factors(struct _pll_div *pll_div, unsigned int source) 722static void pll_factors(struct snd_soc_codec *codec,
723 struct _pll_div *pll_div, unsigned int source)
693{ 724{
694 u64 Kpart; 725 u64 Kpart;
695 unsigned int K, Ndiv, Nmod, target; 726 unsigned int K, Ndiv, Nmod, target;
@@ -724,7 +755,7 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int source)
724 755
725 Ndiv = target / source; 756 Ndiv = target / source;
726 if ((Ndiv < 5) || (Ndiv > 12)) 757 if ((Ndiv < 5) || (Ndiv > 12))
727 printk(KERN_WARNING 758 dev_warn(codec->dev,
728 "WM9713 PLL N value %u out of recommended range!\n", 759 "WM9713 PLL N value %u out of recommended range!\n",
729 Ndiv); 760 Ndiv);
730 761
@@ -768,7 +799,7 @@ static int wm9713_set_pll(struct snd_soc_codec *codec,
768 return 0; 799 return 0;
769 } 800 }
770 801
771 pll_factors(&pll_div, freq_in); 802 pll_factors(codec, &pll_div, freq_in);
772 803
773 if (pll_div.k == 0) { 804 if (pll_div.k == 0) {
774 reg = (pll_div.n << 12) | (pll_div.lf << 11) | 805 reg = (pll_div.n << 12) | (pll_div.lf << 11) |
@@ -1049,7 +1080,6 @@ static const struct snd_soc_dai_ops wm9713_dai_ops_voice = {
1049static struct snd_soc_dai_driver wm9713_dai[] = { 1080static struct snd_soc_dai_driver wm9713_dai[] = {
1050{ 1081{
1051 .name = "wm9713-hifi", 1082 .name = "wm9713-hifi",
1052 .ac97_control = 1,
1053 .playback = { 1083 .playback = {
1054 .stream_name = "HiFi Playback", 1084 .stream_name = "HiFi Playback",
1055 .channels_min = 1, 1085 .channels_min = 1,
@@ -1095,17 +1125,22 @@ static struct snd_soc_dai_driver wm9713_dai[] = {
1095 1125
1096int wm9713_reset(struct snd_soc_codec *codec, int try_warm) 1126int wm9713_reset(struct snd_soc_codec *codec, int try_warm)
1097{ 1127{
1128 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1129
1098 if (try_warm && soc_ac97_ops->warm_reset) { 1130 if (try_warm && soc_ac97_ops->warm_reset) {
1099 soc_ac97_ops->warm_reset(codec->ac97); 1131 soc_ac97_ops->warm_reset(wm9713->ac97);
1100 if (ac97_read(codec, 0) == wm9713_reg[0]) 1132 if (ac97_read(codec, 0) == wm9713_reg[0])
1101 return 1; 1133 return 1;
1102 } 1134 }
1103 1135
1104 soc_ac97_ops->reset(codec->ac97); 1136 soc_ac97_ops->reset(wm9713->ac97);
1105 if (soc_ac97_ops->warm_reset) 1137 if (soc_ac97_ops->warm_reset)
1106 soc_ac97_ops->warm_reset(codec->ac97); 1138 soc_ac97_ops->warm_reset(wm9713->ac97);
1107 if (ac97_read(codec, 0) != wm9713_reg[0]) 1139 if (ac97_read(codec, 0) != wm9713_reg[0]) {
1140 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
1108 return -EIO; 1141 return -EIO;
1142 }
1143
1109 return 0; 1144 return 0;
1110} 1145}
1111EXPORT_SYMBOL_GPL(wm9713_reset); 1146EXPORT_SYMBOL_GPL(wm9713_reset);
@@ -1163,10 +1198,8 @@ static int wm9713_soc_resume(struct snd_soc_codec *codec)
1163 u16 *cache = codec->reg_cache; 1198 u16 *cache = codec->reg_cache;
1164 1199
1165 ret = wm9713_reset(codec, 1); 1200 ret = wm9713_reset(codec, 1);
1166 if (ret < 0) { 1201 if (ret < 0)
1167 printk(KERN_ERR "could not reset AC97 codec\n");
1168 return ret; 1202 return ret;
1169 }
1170 1203
1171 wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1204 wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1172 1205
@@ -1180,7 +1213,7 @@ static int wm9713_soc_resume(struct snd_soc_codec *codec)
1180 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID || 1213 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID ||
1181 i == AC97_EXTENDED_MSTATUS || i > 0x66) 1214 i == AC97_EXTENDED_MSTATUS || i > 0x66)
1182 continue; 1215 continue;
1183 soc_ac97_ops->write(codec->ac97, i, cache[i>>1]); 1216 soc_ac97_ops->write(wm9713->ac97, i, cache[i>>1]);
1184 } 1217 }
1185 } 1218 }
1186 1219
@@ -1189,50 +1222,36 @@ static int wm9713_soc_resume(struct snd_soc_codec *codec)
1189 1222
1190static int wm9713_soc_probe(struct snd_soc_codec *codec) 1223static int wm9713_soc_probe(struct snd_soc_codec *codec)
1191{ 1224{
1192 struct wm9713_priv *wm9713; 1225 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1193 int ret = 0, reg; 1226 int ret = 0, reg;
1194 1227
1195 wm9713 = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL); 1228 wm9713->ac97 = snd_soc_new_ac97_codec(codec);
1196 if (wm9713 == NULL) 1229 if (IS_ERR(wm9713->ac97))
1197 return -ENOMEM; 1230 return PTR_ERR(wm9713->ac97);
1198 snd_soc_codec_set_drvdata(codec, wm9713);
1199
1200 ret = snd_soc_new_ac97_codec(codec, soc_ac97_ops, 0);
1201 if (ret < 0)
1202 goto codec_err;
1203 1231
1204 /* do a cold reset for the controller and then try 1232 /* do a cold reset for the controller and then try
1205 * a warm reset followed by an optional cold reset for codec */ 1233 * a warm reset followed by an optional cold reset for codec */
1206 wm9713_reset(codec, 0); 1234 wm9713_reset(codec, 0);
1207 ret = wm9713_reset(codec, 1); 1235 ret = wm9713_reset(codec, 1);
1208 if (ret < 0) { 1236 if (ret < 0)
1209 printk(KERN_ERR "Failed to reset WM9713: AC97 link error\n");
1210 goto reset_err; 1237 goto reset_err;
1211 }
1212
1213 wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1214 1238
1215 /* unmute the adc - move to kcontrol */ 1239 /* unmute the adc - move to kcontrol */
1216 reg = ac97_read(codec, AC97_CD) & 0x7fff; 1240 reg = ac97_read(codec, AC97_CD) & 0x7fff;
1217 ac97_write(codec, AC97_CD, reg); 1241 ac97_write(codec, AC97_CD, reg);
1218 1242
1219 snd_soc_add_codec_controls(codec, wm9713_snd_ac97_controls,
1220 ARRAY_SIZE(wm9713_snd_ac97_controls));
1221
1222 return 0; 1243 return 0;
1223 1244
1224reset_err: 1245reset_err:
1225 snd_soc_free_ac97_codec(codec); 1246 snd_soc_free_ac97_codec(wm9713->ac97);
1226codec_err:
1227 kfree(wm9713);
1228 return ret; 1247 return ret;
1229} 1248}
1230 1249
1231static int wm9713_soc_remove(struct snd_soc_codec *codec) 1250static int wm9713_soc_remove(struct snd_soc_codec *codec)
1232{ 1251{
1233 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); 1252 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1234 snd_soc_free_ac97_codec(codec); 1253
1235 kfree(wm9713); 1254 snd_soc_free_ac97_codec(wm9713->ac97);
1236 return 0; 1255 return 0;
1237} 1256}
1238 1257
@@ -1248,6 +1267,9 @@ static struct snd_soc_codec_driver soc_codec_dev_wm9713 = {
1248 .reg_word_size = sizeof(u16), 1267 .reg_word_size = sizeof(u16),
1249 .reg_cache_step = 2, 1268 .reg_cache_step = 2,
1250 .reg_cache_default = wm9713_reg, 1269 .reg_cache_default = wm9713_reg,
1270
1271 .controls = wm9713_snd_ac97_controls,
1272 .num_controls = ARRAY_SIZE(wm9713_snd_ac97_controls),
1251 .dapm_widgets = wm9713_dapm_widgets, 1273 .dapm_widgets = wm9713_dapm_widgets,
1252 .num_dapm_widgets = ARRAY_SIZE(wm9713_dapm_widgets), 1274 .num_dapm_widgets = ARRAY_SIZE(wm9713_dapm_widgets),
1253 .dapm_routes = wm9713_audio_map, 1275 .dapm_routes = wm9713_audio_map,
@@ -1256,6 +1278,16 @@ static struct snd_soc_codec_driver soc_codec_dev_wm9713 = {
1256 1278
1257static int wm9713_probe(struct platform_device *pdev) 1279static int wm9713_probe(struct platform_device *pdev)
1258{ 1280{
1281 struct wm9713_priv *wm9713;
1282
1283 wm9713 = devm_kzalloc(&pdev->dev, sizeof(*wm9713), GFP_KERNEL);
1284 if (wm9713 == NULL)
1285 return -ENOMEM;
1286
1287 mutex_init(&wm9713->lock);
1288
1289 platform_set_drvdata(pdev, wm9713);
1290
1259 return snd_soc_register_codec(&pdev->dev, 1291 return snd_soc_register_codec(&pdev->dev,
1260 &soc_codec_dev_wm9713, wm9713_dai, ARRAY_SIZE(wm9713_dai)); 1292 &soc_codec_dev_wm9713, wm9713_dai, ARRAY_SIZE(wm9713_dai));
1261} 1293}
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index 67124783558a..720d6e852986 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -21,6 +21,7 @@
21#include <linux/regmap.h> 21#include <linux/regmap.h>
22#include <linux/regulator/consumer.h> 22#include <linux/regulator/consumer.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/vmalloc.h>
24#include <linux/workqueue.h> 25#include <linux/workqueue.h>
25#include <sound/core.h> 26#include <sound/core.h>
26#include <sound/pcm.h> 27#include <sound/pcm.h>
@@ -169,11 +170,12 @@ static struct wm_adsp_buf *wm_adsp_buf_alloc(const void *src, size_t len,
169 if (buf == NULL) 170 if (buf == NULL)
170 return NULL; 171 return NULL;
171 172
172 buf->buf = kmemdup(src, len, GFP_KERNEL | GFP_DMA); 173 buf->buf = vmalloc(len);
173 if (!buf->buf) { 174 if (!buf->buf) {
174 kfree(buf); 175 vfree(buf);
175 return NULL; 176 return NULL;
176 } 177 }
178 memcpy(buf->buf, src, len);
177 179
178 if (list) 180 if (list)
179 list_add_tail(&buf->list, list); 181 list_add_tail(&buf->list, list);
@@ -188,7 +190,7 @@ static void wm_adsp_buf_free(struct list_head *list)
188 struct wm_adsp_buf, 190 struct wm_adsp_buf,
189 list); 191 list);
190 list_del(&buf->list); 192 list_del(&buf->list);
191 kfree(buf->buf); 193 vfree(buf->buf);
192 kfree(buf); 194 kfree(buf);
193 } 195 }
194} 196}
@@ -684,38 +686,24 @@ static int wm_adsp_load(struct wm_adsp *dsp)
684 } 686 }
685 687
686 if (reg) { 688 if (reg) {
687 size_t to_write = PAGE_SIZE; 689 buf = wm_adsp_buf_alloc(region->data,
688 size_t remain = le32_to_cpu(region->len); 690 le32_to_cpu(region->len),
689 const u8 *data = region->data; 691 &buf_list);
690 692 if (!buf) {
691 while (remain > 0) { 693 adsp_err(dsp, "Out of memory\n");
692 if (remain < PAGE_SIZE) 694 ret = -ENOMEM;
693 to_write = remain; 695 goto out_fw;
694 696 }
695 buf = wm_adsp_buf_alloc(data,
696 to_write,
697 &buf_list);
698 if (!buf) {
699 adsp_err(dsp, "Out of memory\n");
700 ret = -ENOMEM;
701 goto out_fw;
702 }
703
704 ret = regmap_raw_write_async(regmap, reg,
705 buf->buf,
706 to_write);
707 if (ret != 0) {
708 adsp_err(dsp,
709 "%s.%d: Failed to write %zd bytes at %d in %s: %d\n",
710 file, regions,
711 to_write, offset,
712 region_name, ret);
713 goto out_fw;
714 }
715 697
716 data += to_write; 698 ret = regmap_raw_write_async(regmap, reg, buf->buf,
717 reg += to_write / 2; 699 le32_to_cpu(region->len));
718 remain -= to_write; 700 if (ret != 0) {
701 adsp_err(dsp,
702 "%s.%d: Failed to write %d bytes at %d in %s: %d\n",
703 file, regions,
704 le32_to_cpu(region->len), offset,
705 region_name, ret);
706 goto out_fw;
719 } 707 }
720 } 708 }
721 709
@@ -1065,8 +1053,10 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1065 be32_to_cpu(adsp1_alg[i].zm)); 1053 be32_to_cpu(adsp1_alg[i].zm));
1066 1054
1067 region = kzalloc(sizeof(*region), GFP_KERNEL); 1055 region = kzalloc(sizeof(*region), GFP_KERNEL);
1068 if (!region) 1056 if (!region) {
1069 return -ENOMEM; 1057 ret = -ENOMEM;
1058 goto out;
1059 }
1070 region->type = WMFW_ADSP1_DM; 1060 region->type = WMFW_ADSP1_DM;
1071 region->alg = be32_to_cpu(adsp1_alg[i].alg.id); 1061 region->alg = be32_to_cpu(adsp1_alg[i].alg.id);
1072 region->base = be32_to_cpu(adsp1_alg[i].dm); 1062 region->base = be32_to_cpu(adsp1_alg[i].dm);
@@ -1083,8 +1073,10 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1083 } 1073 }
1084 1074
1085 region = kzalloc(sizeof(*region), GFP_KERNEL); 1075 region = kzalloc(sizeof(*region), GFP_KERNEL);
1086 if (!region) 1076 if (!region) {
1087 return -ENOMEM; 1077 ret = -ENOMEM;
1078 goto out;
1079 }
1088 region->type = WMFW_ADSP1_ZM; 1080 region->type = WMFW_ADSP1_ZM;
1089 region->alg = be32_to_cpu(adsp1_alg[i].alg.id); 1081 region->alg = be32_to_cpu(adsp1_alg[i].alg.id);
1090 region->base = be32_to_cpu(adsp1_alg[i].zm); 1082 region->base = be32_to_cpu(adsp1_alg[i].zm);
@@ -1113,8 +1105,10 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1113 be32_to_cpu(adsp2_alg[i].zm)); 1105 be32_to_cpu(adsp2_alg[i].zm));
1114 1106
1115 region = kzalloc(sizeof(*region), GFP_KERNEL); 1107 region = kzalloc(sizeof(*region), GFP_KERNEL);
1116 if (!region) 1108 if (!region) {
1117 return -ENOMEM; 1109 ret = -ENOMEM;
1110 goto out;
1111 }
1118 region->type = WMFW_ADSP2_XM; 1112 region->type = WMFW_ADSP2_XM;
1119 region->alg = be32_to_cpu(adsp2_alg[i].alg.id); 1113 region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
1120 region->base = be32_to_cpu(adsp2_alg[i].xm); 1114 region->base = be32_to_cpu(adsp2_alg[i].xm);
@@ -1131,8 +1125,10 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1131 } 1125 }
1132 1126
1133 region = kzalloc(sizeof(*region), GFP_KERNEL); 1127 region = kzalloc(sizeof(*region), GFP_KERNEL);
1134 if (!region) 1128 if (!region) {
1135 return -ENOMEM; 1129 ret = -ENOMEM;
1130 goto out;
1131 }
1136 region->type = WMFW_ADSP2_YM; 1132 region->type = WMFW_ADSP2_YM;
1137 region->alg = be32_to_cpu(adsp2_alg[i].alg.id); 1133 region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
1138 region->base = be32_to_cpu(adsp2_alg[i].ym); 1134 region->base = be32_to_cpu(adsp2_alg[i].ym);
@@ -1149,8 +1145,10 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1149 } 1145 }
1150 1146
1151 region = kzalloc(sizeof(*region), GFP_KERNEL); 1147 region = kzalloc(sizeof(*region), GFP_KERNEL);
1152 if (!region) 1148 if (!region) {
1153 return -ENOMEM; 1149 ret = -ENOMEM;
1150 goto out;
1151 }
1154 region->type = WMFW_ADSP2_ZM; 1152 region->type = WMFW_ADSP2_ZM;
1155 region->alg = be32_to_cpu(adsp2_alg[i].alg.id); 1153 region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
1156 region->base = be32_to_cpu(adsp2_alg[i].zm); 1154 region->base = be32_to_cpu(adsp2_alg[i].zm);
@@ -1595,13 +1593,6 @@ static void wm_adsp2_boot_work(struct work_struct *work)
1595 if (ret != 0) 1593 if (ret != 0)
1596 goto err; 1594 goto err;
1597 1595
1598 ret = regmap_update_bits_async(dsp->regmap,
1599 dsp->base + ADSP2_CONTROL,
1600 ADSP2_CORE_ENA,
1601 ADSP2_CORE_ENA);
1602 if (ret != 0)
1603 goto err;
1604
1605 dsp->running = true; 1596 dsp->running = true;
1606 1597
1607 return; 1598 return;
@@ -1651,8 +1642,8 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
1651 1642
1652 ret = regmap_update_bits(dsp->regmap, 1643 ret = regmap_update_bits(dsp->regmap,
1653 dsp->base + ADSP2_CONTROL, 1644 dsp->base + ADSP2_CONTROL,
1654 ADSP2_START, 1645 ADSP2_CORE_ENA | ADSP2_START,
1655 ADSP2_START); 1646 ADSP2_CORE_ENA | ADSP2_START);
1656 if (ret != 0) 1647 if (ret != 0)
1657 goto err; 1648 goto err;
1658 break; 1649 break;
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 0eed9b1b24e1..0dab382ba147 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -70,6 +70,7 @@ struct davinci_mcasp {
70 void __iomem *base; 70 void __iomem *base;
71 u32 fifo_base; 71 u32 fifo_base;
72 struct device *dev; 72 struct device *dev;
73 struct snd_pcm_substream *substreams[2];
73 74
74 /* McASP specific data */ 75 /* McASP specific data */
75 int tdm_slots; 76 int tdm_slots;
@@ -80,6 +81,7 @@ struct davinci_mcasp {
80 u8 bclk_div; 81 u8 bclk_div;
81 u16 bclk_lrclk_ratio; 82 u16 bclk_lrclk_ratio;
82 int streams; 83 int streams;
84 u32 irq_request[2];
83 85
84 int sysclk_freq; 86 int sysclk_freq;
85 bool bclk_master; 87 bool bclk_master;
@@ -90,6 +92,9 @@ struct davinci_mcasp {
90 92
91 bool dat_port; 93 bool dat_port;
92 94
95 /* Used for comstraint setting on the second stream */
96 u32 channels;
97
93#ifdef CONFIG_PM_SLEEP 98#ifdef CONFIG_PM_SLEEP
94 struct davinci_mcasp_context context; 99 struct davinci_mcasp_context context;
95#endif 100#endif
@@ -154,9 +159,16 @@ static bool mcasp_is_synchronous(struct davinci_mcasp *mcasp)
154 159
155static void mcasp_start_rx(struct davinci_mcasp *mcasp) 160static void mcasp_start_rx(struct davinci_mcasp *mcasp)
156{ 161{
162 if (mcasp->rxnumevt) { /* enable FIFO */
163 u32 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
164
165 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
166 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
167 }
168
169 /* Start clocks */
157 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST); 170 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST);
158 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST); 171 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST);
159
160 /* 172 /*
161 * When ASYNC == 0 the transmit and receive sections operate 173 * When ASYNC == 0 the transmit and receive sections operate
162 * synchronously from the transmit clock and frame sync. We need to make 174 * synchronously from the transmit clock and frame sync. We need to make
@@ -167,74 +179,69 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp)
167 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); 179 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
168 } 180 }
169 181
182 /* Activate serializer(s) */
170 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR); 183 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR);
171 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXBUF_REG, 0); 184 /* Release RX state machine */
172
173 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
174 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
175 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXBUF_REG, 0);
176
177 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); 185 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
186 /* Release Frame Sync generator */
178 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); 187 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
179
180 if (mcasp_is_synchronous(mcasp)) 188 if (mcasp_is_synchronous(mcasp))
181 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST); 189 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
190
191 /* enable receive IRQs */
192 mcasp_set_bits(mcasp, DAVINCI_MCASP_EVTCTLR_REG,
193 mcasp->irq_request[SNDRV_PCM_STREAM_CAPTURE]);
182} 194}
183 195
184static void mcasp_start_tx(struct davinci_mcasp *mcasp) 196static void mcasp_start_tx(struct davinci_mcasp *mcasp)
185{ 197{
186 u8 offset = 0, i;
187 u32 cnt; 198 u32 cnt;
188 199
200 if (mcasp->txnumevt) { /* enable FIFO */
201 u32 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
202
203 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
204 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
205 }
206
207 /* Start clocks */
189 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST); 208 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
190 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); 209 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
210 /* Activate serializer(s) */
191 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR); 211 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR);
192 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
193 212
194 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSMRST); 213 /* wait for XDATA to be cleared */
195 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
196 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
197 for (i = 0; i < mcasp->num_serializer; i++) {
198 if (mcasp->serial_dir[i] == TX_MODE) {
199 offset = i;
200 break;
201 }
202 }
203
204 /* wait for TX ready */
205 cnt = 0; 214 cnt = 0;
206 while (!(mcasp_get_reg(mcasp, DAVINCI_MCASP_XRSRCTL_REG(offset)) & 215 while (!(mcasp_get_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG) &
207 TXSTATE) && (cnt < 100000)) 216 ~XRDATA) && (cnt < 100000))
208 cnt++; 217 cnt++;
209 218
210 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0); 219 /* Release TX state machine */
220 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSMRST);
221 /* Release Frame Sync generator */
222 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
223
224 /* enable transmit IRQs */
225 mcasp_set_bits(mcasp, DAVINCI_MCASP_EVTCTLX_REG,
226 mcasp->irq_request[SNDRV_PCM_STREAM_PLAYBACK]);
211} 227}
212 228
213static void davinci_mcasp_start(struct davinci_mcasp *mcasp, int stream) 229static void davinci_mcasp_start(struct davinci_mcasp *mcasp, int stream)
214{ 230{
215 u32 reg;
216
217 mcasp->streams++; 231 mcasp->streams++;
218 232
219 if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 233 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
220 if (mcasp->txnumevt) { /* enable FIFO */
221 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
222 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
223 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
224 }
225 mcasp_start_tx(mcasp); 234 mcasp_start_tx(mcasp);
226 } else { 235 else
227 if (mcasp->rxnumevt) { /* enable FIFO */
228 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
229 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
230 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
231 }
232 mcasp_start_rx(mcasp); 236 mcasp_start_rx(mcasp);
233 }
234} 237}
235 238
236static void mcasp_stop_rx(struct davinci_mcasp *mcasp) 239static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
237{ 240{
241 /* disable IRQ sources */
242 mcasp_clr_bits(mcasp, DAVINCI_MCASP_EVTCTLR_REG,
243 mcasp->irq_request[SNDRV_PCM_STREAM_CAPTURE]);
244
238 /* 245 /*
239 * In synchronous mode stop the TX clocks if no other stream is 246 * In synchronous mode stop the TX clocks if no other stream is
240 * running 247 * running
@@ -244,12 +251,22 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
244 251
245 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0); 252 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0);
246 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); 253 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
254
255 if (mcasp->rxnumevt) { /* disable FIFO */
256 u32 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
257
258 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
259 }
247} 260}
248 261
249static void mcasp_stop_tx(struct davinci_mcasp *mcasp) 262static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
250{ 263{
251 u32 val = 0; 264 u32 val = 0;
252 265
266 /* disable IRQ sources */
267 mcasp_clr_bits(mcasp, DAVINCI_MCASP_EVTCTLX_REG,
268 mcasp->irq_request[SNDRV_PCM_STREAM_PLAYBACK]);
269
253 /* 270 /*
254 * In synchronous mode keep TX clocks running if the capture stream is 271 * In synchronous mode keep TX clocks running if the capture stream is
255 * still running. 272 * still running.
@@ -259,27 +276,92 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
259 276
260 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, val); 277 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, val);
261 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); 278 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
279
280 if (mcasp->txnumevt) { /* disable FIFO */
281 u32 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
282
283 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
284 }
262} 285}
263 286
264static void davinci_mcasp_stop(struct davinci_mcasp *mcasp, int stream) 287static void davinci_mcasp_stop(struct davinci_mcasp *mcasp, int stream)
265{ 288{
266 u32 reg;
267
268 mcasp->streams--; 289 mcasp->streams--;
269 290
270 if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 291 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
271 if (mcasp->txnumevt) { /* disable FIFO */
272 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
273 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
274 }
275 mcasp_stop_tx(mcasp); 292 mcasp_stop_tx(mcasp);
276 } else { 293 else
277 if (mcasp->rxnumevt) { /* disable FIFO */
278 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
279 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
280 }
281 mcasp_stop_rx(mcasp); 294 mcasp_stop_rx(mcasp);
295}
296
297static irqreturn_t davinci_mcasp_tx_irq_handler(int irq, void *data)
298{
299 struct davinci_mcasp *mcasp = (struct davinci_mcasp *)data;
300 struct snd_pcm_substream *substream;
301 u32 irq_mask = mcasp->irq_request[SNDRV_PCM_STREAM_PLAYBACK];
302 u32 handled_mask = 0;
303 u32 stat;
304
305 stat = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG);
306 if (stat & XUNDRN & irq_mask) {
307 dev_warn(mcasp->dev, "Transmit buffer underflow\n");
308 handled_mask |= XUNDRN;
309
310 substream = mcasp->substreams[SNDRV_PCM_STREAM_PLAYBACK];
311 if (substream) {
312 snd_pcm_stream_lock_irq(substream);
313 if (snd_pcm_running(substream))
314 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
315 snd_pcm_stream_unlock_irq(substream);
316 }
282 } 317 }
318
319 if (!handled_mask)
320 dev_warn(mcasp->dev, "unhandled tx event. txstat: 0x%08x\n",
321 stat);
322
323 if (stat & XRERR)
324 handled_mask |= XRERR;
325
326 /* Ack the handled event only */
327 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, handled_mask);
328
329 return IRQ_RETVAL(handled_mask);
330}
331
332static irqreturn_t davinci_mcasp_rx_irq_handler(int irq, void *data)
333{
334 struct davinci_mcasp *mcasp = (struct davinci_mcasp *)data;
335 struct snd_pcm_substream *substream;
336 u32 irq_mask = mcasp->irq_request[SNDRV_PCM_STREAM_CAPTURE];
337 u32 handled_mask = 0;
338 u32 stat;
339
340 stat = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG);
341 if (stat & ROVRN & irq_mask) {
342 dev_warn(mcasp->dev, "Receive buffer overflow\n");
343 handled_mask |= ROVRN;
344
345 substream = mcasp->substreams[SNDRV_PCM_STREAM_CAPTURE];
346 if (substream) {
347 snd_pcm_stream_lock_irq(substream);
348 if (snd_pcm_running(substream))
349 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
350 snd_pcm_stream_unlock_irq(substream);
351 }
352 }
353
354 if (!handled_mask)
355 dev_warn(mcasp->dev, "unhandled rx event. rxstat: 0x%08x\n",
356 stat);
357
358 if (stat & XRERR)
359 handled_mask |= XRERR;
360
361 /* Ack the handled event only */
362 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, handled_mask);
363
364 return IRQ_RETVAL(handled_mask);
283} 365}
284 366
285static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai, 367static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
@@ -500,8 +582,17 @@ static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
500 * both left and right channels), so it has to be divided by number of 582 * both left and right channels), so it has to be divided by number of
501 * tdm-slots (for I2S - divided by 2). 583 * tdm-slots (for I2S - divided by 2).
502 */ 584 */
503 if (mcasp->bclk_lrclk_ratio) 585 if (mcasp->bclk_lrclk_ratio) {
504 word_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots; 586 u32 slot_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots;
587
588 /*
589 * When we have more bclk then it is needed for the data, we
590 * need to use the rotation to move the received samples to have
591 * correct alignment.
592 */
593 rx_rotate = (slot_length - word_length) / 4;
594 word_length = slot_length;
595 }
505 596
506 /* mapping of the XSSZ bit-field as described in the datasheet */ 597 /* mapping of the XSSZ bit-field as described in the datasheet */
507 fmt = (word_length >> 1) - 1; 598 fmt = (word_length >> 1) - 1;
@@ -635,19 +726,29 @@ static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
635 return 0; 726 return 0;
636} 727}
637 728
638static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream) 729static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream,
730 int channels)
639{ 731{
640 int i, active_slots; 732 int i, active_slots;
733 int total_slots;
734 int active_serializers;
641 u32 mask = 0; 735 u32 mask = 0;
642 u32 busel = 0; 736 u32 busel = 0;
643 737
644 if ((mcasp->tdm_slots < 2) || (mcasp->tdm_slots > 32)) { 738 total_slots = mcasp->tdm_slots;
645 dev_err(mcasp->dev, "tdm slot %d not supported\n", 739
646 mcasp->tdm_slots); 740 /*
647 return -EINVAL; 741 * If more than one serializer is needed, then use them with
648 } 742 * their specified tdm_slots count. Otherwise, one serializer
743 * can cope with the transaction using as many slots as channels
744 * in the stream, requires channels symmetry
745 */
746 active_serializers = (channels + total_slots - 1) / total_slots;
747 if (active_serializers == 1)
748 active_slots = channels;
749 else
750 active_slots = total_slots;
649 751
650 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots;
651 for (i = 0; i < active_slots; i++) 752 for (i = 0; i < active_slots; i++)
652 mask |= (1 << i); 753 mask |= (1 << i);
653 754
@@ -659,12 +760,12 @@ static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream)
659 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask); 760 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask);
660 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD); 761 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD);
661 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, 762 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG,
662 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF)); 763 FSXMOD(total_slots), FSXMOD(0x1FF));
663 764
664 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask); 765 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask);
665 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD); 766 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD);
666 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, 767 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG,
667 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF)); 768 FSRMOD(total_slots), FSRMOD(0x1FF));
668 769
669 return 0; 770 return 0;
670} 771}
@@ -778,7 +879,8 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
778 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE) 879 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
779 ret = mcasp_dit_hw_param(mcasp, params_rate(params)); 880 ret = mcasp_dit_hw_param(mcasp, params_rate(params));
780 else 881 else
781 ret = mcasp_i2s_hw_param(mcasp, substream->stream); 882 ret = mcasp_i2s_hw_param(mcasp, substream->stream,
883 channels);
782 884
783 if (ret) 885 if (ret)
784 return ret; 886 return ret;
@@ -826,6 +928,9 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
826 928
827 davinci_config_channel_size(mcasp, word_length); 929 davinci_config_channel_size(mcasp, word_length);
828 930
931 if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE)
932 mcasp->channels = channels;
933
829 return 0; 934 return 0;
830} 935}
831 936
@@ -854,7 +959,65 @@ static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
854 return ret; 959 return ret;
855} 960}
856 961
962static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
963 struct snd_soc_dai *cpu_dai)
964{
965 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
966 u32 max_channels = 0;
967 int i, dir;
968
969 mcasp->substreams[substream->stream] = substream;
970
971 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
972 return 0;
973
974 /*
975 * Limit the maximum allowed channels for the first stream:
976 * number of serializers for the direction * tdm slots per serializer
977 */
978 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
979 dir = TX_MODE;
980 else
981 dir = RX_MODE;
982
983 for (i = 0; i < mcasp->num_serializer; i++) {
984 if (mcasp->serial_dir[i] == dir)
985 max_channels++;
986 }
987 max_channels *= mcasp->tdm_slots;
988 /*
989 * If the already active stream has less channels than the calculated
990 * limnit based on the seirializers * tdm_slots, we need to use that as
991 * a constraint for the second stream.
992 * Otherwise (first stream or less allowed channels) we use the
993 * calculated constraint.
994 */
995 if (mcasp->channels && mcasp->channels < max_channels)
996 max_channels = mcasp->channels;
997
998 snd_pcm_hw_constraint_minmax(substream->runtime,
999 SNDRV_PCM_HW_PARAM_CHANNELS,
1000 2, max_channels);
1001 return 0;
1002}
1003
1004static void davinci_mcasp_shutdown(struct snd_pcm_substream *substream,
1005 struct snd_soc_dai *cpu_dai)
1006{
1007 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
1008
1009 mcasp->substreams[substream->stream] = NULL;
1010
1011 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
1012 return;
1013
1014 if (!cpu_dai->active)
1015 mcasp->channels = 0;
1016}
1017
857static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = { 1018static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
1019 .startup = davinci_mcasp_startup,
1020 .shutdown = davinci_mcasp_shutdown,
858 .trigger = davinci_mcasp_trigger, 1021 .trigger = davinci_mcasp_trigger,
859 .hw_params = davinci_mcasp_hw_params, 1022 .hw_params = davinci_mcasp_hw_params,
860 .set_fmt = davinci_mcasp_set_dai_fmt, 1023 .set_fmt = davinci_mcasp_set_dai_fmt,
@@ -971,6 +1134,7 @@ static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
971 }, 1134 },
972 .ops = &davinci_mcasp_dai_ops, 1135 .ops = &davinci_mcasp_dai_ops,
973 1136
1137 .symmetric_samplebits = 1,
974 }, 1138 },
975 { 1139 {
976 .name = "davinci-mcasp.1", 1140 .name = "davinci-mcasp.1",
@@ -1194,6 +1358,8 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1194 struct resource *mem, *ioarea, *res, *dat; 1358 struct resource *mem, *ioarea, *res, *dat;
1195 struct davinci_mcasp_pdata *pdata; 1359 struct davinci_mcasp_pdata *pdata;
1196 struct davinci_mcasp *mcasp; 1360 struct davinci_mcasp *mcasp;
1361 char *irq_name;
1362 int irq;
1197 int ret; 1363 int ret;
1198 1364
1199 if (!pdev->dev.platform_data && !pdev->dev.of_node) { 1365 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
@@ -1235,6 +1401,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1235 ret = pm_runtime_get_sync(&pdev->dev); 1401 ret = pm_runtime_get_sync(&pdev->dev);
1236 if (IS_ERR_VALUE(ret)) { 1402 if (IS_ERR_VALUE(ret)) {
1237 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n"); 1403 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
1404 pm_runtime_disable(&pdev->dev);
1238 return ret; 1405 return ret;
1239 } 1406 }
1240 1407
@@ -1246,7 +1413,21 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1246 } 1413 }
1247 1414
1248 mcasp->op_mode = pdata->op_mode; 1415 mcasp->op_mode = pdata->op_mode;
1249 mcasp->tdm_slots = pdata->tdm_slots; 1416 /* sanity check for tdm slots parameter */
1417 if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) {
1418 if (pdata->tdm_slots < 2) {
1419 dev_err(&pdev->dev, "invalid tdm slots: %d\n",
1420 pdata->tdm_slots);
1421 mcasp->tdm_slots = 2;
1422 } else if (pdata->tdm_slots > 32) {
1423 dev_err(&pdev->dev, "invalid tdm slots: %d\n",
1424 pdata->tdm_slots);
1425 mcasp->tdm_slots = 32;
1426 } else {
1427 mcasp->tdm_slots = pdata->tdm_slots;
1428 }
1429 }
1430
1250 mcasp->num_serializer = pdata->num_serializer; 1431 mcasp->num_serializer = pdata->num_serializer;
1251#ifdef CONFIG_PM_SLEEP 1432#ifdef CONFIG_PM_SLEEP
1252 mcasp->context.xrsr_regs = devm_kzalloc(&pdev->dev, 1433 mcasp->context.xrsr_regs = devm_kzalloc(&pdev->dev,
@@ -1260,6 +1441,36 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1260 1441
1261 mcasp->dev = &pdev->dev; 1442 mcasp->dev = &pdev->dev;
1262 1443
1444 irq = platform_get_irq_byname(pdev, "rx");
1445 if (irq >= 0) {
1446 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_rx\n",
1447 dev_name(&pdev->dev));
1448 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1449 davinci_mcasp_rx_irq_handler,
1450 IRQF_ONESHOT, irq_name, mcasp);
1451 if (ret) {
1452 dev_err(&pdev->dev, "RX IRQ request failed\n");
1453 goto err;
1454 }
1455
1456 mcasp->irq_request[SNDRV_PCM_STREAM_CAPTURE] = ROVRN;
1457 }
1458
1459 irq = platform_get_irq_byname(pdev, "tx");
1460 if (irq >= 0) {
1461 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_tx\n",
1462 dev_name(&pdev->dev));
1463 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1464 davinci_mcasp_tx_irq_handler,
1465 IRQF_ONESHOT, irq_name, mcasp);
1466 if (ret) {
1467 dev_err(&pdev->dev, "TX IRQ request failed\n");
1468 goto err;
1469 }
1470
1471 mcasp->irq_request[SNDRV_PCM_STREAM_PLAYBACK] = XUNDRN;
1472 }
1473
1263 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); 1474 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
1264 if (dat) 1475 if (dat)
1265 mcasp->dat_port = true; 1476 mcasp->dat_port = true;
diff --git a/sound/soc/davinci/davinci-mcasp.h b/sound/soc/davinci/davinci-mcasp.h
index 98fbc451892a..79dc511180bf 100644
--- a/sound/soc/davinci/davinci-mcasp.h
+++ b/sound/soc/davinci/davinci-mcasp.h
@@ -253,6 +253,13 @@
253#define TXFSRST BIT(12) /* Frame Sync Generator Reset */ 253#define TXFSRST BIT(12) /* Frame Sync Generator Reset */
254 254
255/* 255/*
256 * DAVINCI_MCASP_TXSTAT_REG - Transmitter Status Register Bits
257 * DAVINCI_MCASP_RXSTAT_REG - Receiver Status Register Bits
258 */
259#define XRERR BIT(8) /* Transmit/Receive error */
260#define XRDATA BIT(5) /* Transmit/Receive data ready */
261
262/*
256 * DAVINCI_MCASP_AMUTE_REG - Mute Control Register Bits 263 * DAVINCI_MCASP_AMUTE_REG - Mute Control Register Bits
257 */ 264 */
258#define MUTENA(val) (val) 265#define MUTENA(val) (val)
@@ -279,6 +286,16 @@
279#define TXDATADMADIS BIT(0) 286#define TXDATADMADIS BIT(0)
280 287
281/* 288/*
289 * DAVINCI_MCASP_EVTCTLR_REG - Receiver Interrupt Control Register Bits
290 */
291#define ROVRN BIT(0)
292
293/*
294 * DAVINCI_MCASP_EVTCTLX_REG - Transmitter Interrupt Control Register Bits
295 */
296#define XUNDRN BIT(0)
297
298/*
282 * DAVINCI_MCASP_W[R]FIFOCTL - Write/Read FIFO Control Register bits 299 * DAVINCI_MCASP_W[R]FIFOCTL - Write/Read FIFO Control Register bits
283 */ 300 */
284#define FIFO_ENABLE BIT(16) 301#define FIFO_ENABLE BIT(16)
diff --git a/sound/soc/dwc/designware_i2s.c b/sound/soc/dwc/designware_i2s.c
index e961388e6e9c..08f0229f8d68 100644
--- a/sound/soc/dwc/designware_i2s.c
+++ b/sound/soc/dwc/designware_i2s.c
@@ -338,31 +338,34 @@ static int dw_i2s_probe(struct platform_device *pdev)
338 return -EINVAL; 338 return -EINVAL;
339 } 339 }
340 340
341 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
342 if (!res) {
343 dev_err(&pdev->dev, "no i2s resource defined\n");
344 return -ENODEV;
345 }
346
347 if (!devm_request_mem_region(&pdev->dev, res->start,
348 resource_size(res), pdev->name)) {
349 dev_err(&pdev->dev, "i2s region already claimed\n");
350 return -EBUSY;
351 }
352
353 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 341 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
354 if (!dev) { 342 if (!dev) {
355 dev_warn(&pdev->dev, "kzalloc fail\n"); 343 dev_warn(&pdev->dev, "kzalloc fail\n");
356 return -ENOMEM; 344 return -ENOMEM;
357 } 345 }
358 346
359 dev->i2s_base = devm_ioremap(&pdev->dev, res->start, 347 dw_i2s_dai = devm_kzalloc(&pdev->dev, sizeof(*dw_i2s_dai), GFP_KERNEL);
360 resource_size(res)); 348 if (!dw_i2s_dai) {
361 if (!dev->i2s_base) { 349 dev_err(&pdev->dev, "mem allocation failed for dai driver\n");
362 dev_err(&pdev->dev, "ioremap fail for i2s_region\n");
363 return -ENOMEM; 350 return -ENOMEM;
364 } 351 }
365 352
353 dw_i2s_dai->ops = &dw_i2s_dai_ops;
354 dw_i2s_dai->suspend = dw_i2s_suspend;
355 dw_i2s_dai->resume = dw_i2s_resume;
356
357 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
358 if (!res) {
359 dev_err(&pdev->dev, "no i2s resource defined\n");
360 return -ENODEV;
361 }
362
363 dev->i2s_base = devm_ioremap_resource(&pdev->dev, res);
364 if (IS_ERR(dev->i2s_base)) {
365 dev_err(&pdev->dev, "ioremap fail for i2s_region\n");
366 return PTR_ERR(dev->i2s_base);
367 }
368
366 cap = pdata->cap; 369 cap = pdata->cap;
367 dev->capability = cap; 370 dev->capability = cap;
368 dev->i2s_clk_cfg = pdata->i2s_clk_cfg; 371 dev->i2s_clk_cfg = pdata->i2s_clk_cfg;
@@ -388,13 +391,6 @@ static int dw_i2s_probe(struct platform_device *pdev)
388 if (ret < 0) 391 if (ret < 0)
389 goto err_clk_put; 392 goto err_clk_put;
390 393
391 dw_i2s_dai = devm_kzalloc(&pdev->dev, sizeof(*dw_i2s_dai), GFP_KERNEL);
392 if (!dw_i2s_dai) {
393 dev_err(&pdev->dev, "mem allocation failed for dai driver\n");
394 ret = -ENOMEM;
395 goto err_clk_disable;
396 }
397
398 if (cap & DWC_I2S_PLAY) { 394 if (cap & DWC_I2S_PLAY) {
399 dev_dbg(&pdev->dev, " designware: play supported\n"); 395 dev_dbg(&pdev->dev, " designware: play supported\n");
400 dw_i2s_dai->playback.channels_min = MIN_CHANNEL_NUM; 396 dw_i2s_dai->playback.channels_min = MIN_CHANNEL_NUM;
@@ -411,10 +407,6 @@ static int dw_i2s_probe(struct platform_device *pdev)
411 dw_i2s_dai->capture.rates = pdata->snd_rates; 407 dw_i2s_dai->capture.rates = pdata->snd_rates;
412 } 408 }
413 409
414 dw_i2s_dai->ops = &dw_i2s_dai_ops;
415 dw_i2s_dai->suspend = dw_i2s_suspend;
416 dw_i2s_dai->resume = dw_i2s_resume;
417
418 dev->dev = &pdev->dev; 410 dev->dev = &pdev->dev;
419 dev_set_drvdata(&pdev->dev, dev); 411 dev_set_drvdata(&pdev->dev, dev);
420 ret = snd_soc_register_component(&pdev->dev, &dw_i2s_component, 412 ret = snd_soc_register_component(&pdev->dev, &dw_i2s_component,
diff --git a/sound/soc/fsl/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
index eb093d5b85c4..b175b0145a42 100644
--- a/sound/soc/fsl/eukrea-tlv320.c
+++ b/sound/soc/fsl/eukrea-tlv320.c
@@ -105,7 +105,7 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
105 int ret; 105 int ret;
106 int int_port = 0, ext_port; 106 int int_port = 0, ext_port;
107 struct device_node *np = pdev->dev.of_node; 107 struct device_node *np = pdev->dev.of_node;
108 struct device_node *ssi_np, *codec_np; 108 struct device_node *ssi_np = NULL, *codec_np = NULL;
109 109
110 eukrea_tlv320.dev = &pdev->dev; 110 eukrea_tlv320.dev = &pdev->dev;
111 if (np) { 111 if (np) {
@@ -217,8 +217,7 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
217err: 217err:
218 if (ret) 218 if (ret)
219 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); 219 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
220 if (np) 220 of_node_put(ssi_np);
221 of_node_put(ssi_np);
222 221
223 return ret; 222 return ret;
224} 223}
diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
index 007c772f3cef..3f6959c8e2f7 100644
--- a/sound/soc/fsl/fsl-asoc-card.c
+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -51,6 +51,7 @@ struct codec_priv {
51 * @sysclk_freq[2]: SYSCLK rates for set_sysclk() 51 * @sysclk_freq[2]: SYSCLK rates for set_sysclk()
52 * @sysclk_dir[2]: SYSCLK directions for set_sysclk() 52 * @sysclk_dir[2]: SYSCLK directions for set_sysclk()
53 * @sysclk_id[2]: SYSCLK ids for set_sysclk() 53 * @sysclk_id[2]: SYSCLK ids for set_sysclk()
54 * @slot_width: Slot width of each frame
54 * 55 *
55 * Note: [1] for tx and [0] for rx 56 * Note: [1] for tx and [0] for rx
56 */ 57 */
@@ -58,6 +59,7 @@ struct cpu_priv {
58 unsigned long sysclk_freq[2]; 59 unsigned long sysclk_freq[2];
59 u32 sysclk_dir[2]; 60 u32 sysclk_dir[2];
60 u32 sysclk_id[2]; 61 u32 sysclk_id[2];
62 u32 slot_width;
61}; 63};
62 64
63/** 65/**
@@ -125,7 +127,12 @@ static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
125 priv->sample_rate = params_rate(params); 127 priv->sample_rate = params_rate(params);
126 priv->sample_format = params_format(params); 128 priv->sample_format = params_format(params);
127 129
128 if (priv->card.set_bias_level) 130 /*
131 * If codec-dai is DAI Master and all configurations are already in the
132 * set_bias_level(), bypass the remaining settings in hw_params().
133 * Note: (dai_fmt & CBM_CFM) includes CBM_CFM and CBM_CFS.
134 */
135 if (priv->card.set_bias_level && priv->dai_fmt & SND_SOC_DAIFMT_CBM_CFM)
129 return 0; 136 return 0;
130 137
131 /* Specific configurations of DAIs starts from here */ 138 /* Specific configurations of DAIs starts from here */
@@ -137,6 +144,15 @@ static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
137 return ret; 144 return ret;
138 } 145 }
139 146
147 if (cpu_priv->slot_width) {
148 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2,
149 cpu_priv->slot_width);
150 if (ret) {
151 dev_err(dev, "failed to set TDM slot for cpu dai\n");
152 return ret;
153 }
154 }
155
140 return 0; 156 return 0;
141} 157}
142 158
@@ -448,6 +464,7 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
448 priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq; 464 priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq;
449 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT; 465 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
450 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT; 466 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
467 priv->cpu_priv.slot_width = 32;
451 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; 468 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
452 } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) { 469 } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
453 priv->codec_priv.mclk_id = SGTL5000_SYSCLK; 470 priv->codec_priv.mclk_id = SGTL5000_SYSCLK;
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index a609aafc994d..b2b108805b24 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -151,14 +151,7 @@ static const struct snd_pcm_hardware fsl_dma_hardware = {
151 */ 151 */
152static void fsl_dma_abort_stream(struct snd_pcm_substream *substream) 152static void fsl_dma_abort_stream(struct snd_pcm_substream *substream)
153{ 153{
154 unsigned long flags; 154 snd_pcm_stop_xrun(substream);
155
156 snd_pcm_stream_lock_irqsave(substream, flags);
157
158 if (snd_pcm_running(substream))
159 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
160
161 snd_pcm_stream_unlock_irqrestore(substream, flags);
162} 155}
163 156
164/** 157/**
diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
index a645e296199e..ca319d59f843 100644
--- a/sound/soc/fsl/fsl_esai.c
+++ b/sound/soc/fsl/fsl_esai.c
@@ -513,10 +513,15 @@ static int fsl_esai_hw_params(struct snd_pcm_substream *substream,
513 u32 width = snd_pcm_format_width(params_format(params)); 513 u32 width = snd_pcm_format_width(params_format(params));
514 u32 channels = params_channels(params); 514 u32 channels = params_channels(params);
515 u32 pins = DIV_ROUND_UP(channels, esai_priv->slots); 515 u32 pins = DIV_ROUND_UP(channels, esai_priv->slots);
516 u32 slot_width = width;
516 u32 bclk, mask, val; 517 u32 bclk, mask, val;
517 int ret; 518 int ret;
518 519
519 bclk = params_rate(params) * esai_priv->slot_width * esai_priv->slots; 520 /* Override slot_width if being specifially set */
521 if (esai_priv->slot_width)
522 slot_width = esai_priv->slot_width;
523
524 bclk = params_rate(params) * slot_width * esai_priv->slots;
520 525
521 ret = fsl_esai_set_bclk(dai, tx, bclk); 526 ret = fsl_esai_set_bclk(dai, tx, bclk);
522 if (ret) 527 if (ret)
@@ -538,7 +543,7 @@ static int fsl_esai_hw_params(struct snd_pcm_substream *substream,
538 regmap_update_bits(esai_priv->regmap, REG_ESAI_xFCR(tx), mask, val); 543 regmap_update_bits(esai_priv->regmap, REG_ESAI_xFCR(tx), mask, val);
539 544
540 mask = ESAI_xCR_xSWS_MASK | (tx ? ESAI_xCR_PADC : 0); 545 mask = ESAI_xCR_xSWS_MASK | (tx ? ESAI_xCR_PADC : 0);
541 val = ESAI_xCR_xSWS(esai_priv->slot_width, width) | (tx ? ESAI_xCR_PADC : 0); 546 val = ESAI_xCR_xSWS(slot_width, width) | (tx ? ESAI_xCR_PADC : 0);
542 547
543 regmap_update_bits(esai_priv->regmap, REG_ESAI_xCR(tx), mask, val); 548 regmap_update_bits(esai_priv->regmap, REG_ESAI_xCR(tx), mask, val);
544 549
@@ -780,9 +785,6 @@ static int fsl_esai_probe(struct platform_device *pdev)
780 return ret; 785 return ret;
781 } 786 }
782 787
783 /* Set a default slot size */
784 esai_priv->slot_width = 32;
785
786 /* Set a default slot number */ 788 /* Set a default slot number */
787 esai_priv->slots = 2; 789 esai_priv->slots = 2;
788 790
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index e6955170dc42..b6b0d25f6ace 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -67,8 +67,6 @@
67/** 67/**
68 * FSLSSI_I2S_FORMATS: audio formats supported by the SSI 68 * FSLSSI_I2S_FORMATS: audio formats supported by the SSI
69 * 69 *
70 * This driver currently only supports the SSI running in I2S slave mode.
71 *
72 * The SSI has a limitation in that the samples must be in the same byte 70 * The SSI has a limitation in that the samples must be in the same byte
73 * order as the host CPU. This is because when multiple bytes are written 71 * order as the host CPU. This is because when multiple bytes are written
74 * to the STX register, the bytes and bits must be written in the same 72 * to the STX register, the bytes and bits must be written in the same
@@ -1099,7 +1097,7 @@ static const struct snd_soc_component_driver fsl_ssi_component = {
1099}; 1097};
1100 1098
1101static struct snd_soc_dai_driver fsl_ssi_ac97_dai = { 1099static struct snd_soc_dai_driver fsl_ssi_ac97_dai = {
1102 .ac97_control = 1, 1100 .bus_control = true,
1103 .playback = { 1101 .playback = {
1104 .stream_name = "AC97 Playback", 1102 .stream_name = "AC97 Playback",
1105 .channels_min = 2, 1103 .channels_min = 2,
@@ -1363,7 +1361,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1363 return PTR_ERR(ssi_private->regs); 1361 return PTR_ERR(ssi_private->regs);
1364 } 1362 }
1365 1363
1366 ssi_private->irq = irq_of_parse_and_map(np, 0); 1364 ssi_private->irq = platform_get_irq(pdev, 0);
1367 if (!ssi_private->irq) { 1365 if (!ssi_private->irq) {
1368 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); 1366 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name);
1369 return -ENXIO; 1367 return -ENXIO;
@@ -1389,7 +1387,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1389 if (ssi_private->soc->imx) { 1387 if (ssi_private->soc->imx) {
1390 ret = fsl_ssi_imx_probe(pdev, ssi_private, iomem); 1388 ret = fsl_ssi_imx_probe(pdev, ssi_private, iomem);
1391 if (ret) 1389 if (ret)
1392 goto error_irqmap; 1390 return ret;
1393 } 1391 }
1394 1392
1395 ret = snd_soc_register_component(&pdev->dev, &fsl_ssi_component, 1393 ret = snd_soc_register_component(&pdev->dev, &fsl_ssi_component,
@@ -1412,7 +1410,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1412 1410
1413 ret = fsl_ssi_debugfs_create(&ssi_private->dbg_stats, &pdev->dev); 1411 ret = fsl_ssi_debugfs_create(&ssi_private->dbg_stats, &pdev->dev);
1414 if (ret) 1412 if (ret)
1415 goto error_asoc_register; 1413 goto error_irq;
1416 1414
1417 /* 1415 /*
1418 * If codec-handle property is missing from SSI node, we assume 1416 * If codec-handle property is missing from SSI node, we assume
@@ -1460,10 +1458,6 @@ error_asoc_register:
1460 if (ssi_private->soc->imx) 1458 if (ssi_private->soc->imx)
1461 fsl_ssi_imx_clean(pdev, ssi_private); 1459 fsl_ssi_imx_clean(pdev, ssi_private);
1462 1460
1463error_irqmap:
1464 if (ssi_private->use_dma)
1465 irq_dispose_mapping(ssi_private->irq);
1466
1467 return ret; 1461 return ret;
1468} 1462}
1469 1463
@@ -1480,9 +1474,6 @@ static int fsl_ssi_remove(struct platform_device *pdev)
1480 if (ssi_private->soc->imx) 1474 if (ssi_private->soc->imx)
1481 fsl_ssi_imx_clean(pdev, ssi_private); 1475 fsl_ssi_imx_clean(pdev, ssi_private);
1482 1476
1483 if (ssi_private->use_dma)
1484 irq_dispose_mapping(ssi_private->irq);
1485
1486 return 0; 1477 return 0;
1487} 1478}
1488 1479
diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c
index 1cb22dd034eb..1dab963a59f7 100644
--- a/sound/soc/fsl/imx-sgtl5000.c
+++ b/sound/soc/fsl/imx-sgtl5000.c
@@ -175,10 +175,8 @@ static int imx_sgtl5000_probe(struct platform_device *pdev)
175fail: 175fail:
176 if (data && !IS_ERR(data->codec_clk)) 176 if (data && !IS_ERR(data->codec_clk))
177 clk_put(data->codec_clk); 177 clk_put(data->codec_clk);
178 if (ssi_np) 178 of_node_put(ssi_np);
179 of_node_put(ssi_np); 179 of_node_put(codec_np);
180 if (codec_np)
181 of_node_put(codec_np);
182 180
183 return ret; 181 return ret;
184} 182}
diff --git a/sound/soc/fsl/imx-spdif.c b/sound/soc/fsl/imx-spdif.c
index e1dc40143600..0c9068ebe1e7 100644
--- a/sound/soc/fsl/imx-spdif.c
+++ b/sound/soc/fsl/imx-spdif.c
@@ -74,8 +74,7 @@ static int imx_spdif_audio_probe(struct platform_device *pdev)
74 platform_set_drvdata(pdev, data); 74 platform_set_drvdata(pdev, data);
75 75
76end: 76end:
77 if (spdif_np) 77 of_node_put(spdif_np);
78 of_node_put(spdif_np);
79 78
80 return ret; 79 return ret;
81} 80}
diff --git a/sound/soc/fsl/imx-ssi.c b/sound/soc/fsl/imx-ssi.c
index ab2fdd76b693..60b0a5b1f1f1 100644
--- a/sound/soc/fsl/imx-ssi.c
+++ b/sound/soc/fsl/imx-ssi.c
@@ -382,7 +382,7 @@ static struct snd_soc_dai_driver imx_ssi_dai = {
382 382
383static struct snd_soc_dai_driver imx_ac97_dai = { 383static struct snd_soc_dai_driver imx_ac97_dai = {
384 .probe = imx_ssi_dai_probe, 384 .probe = imx_ssi_dai_probe,
385 .ac97_control = 1, 385 .bus_control = true,
386 .playback = { 386 .playback = {
387 .stream_name = "AC97 Playback", 387 .stream_name = "AC97 Playback",
388 .channels_min = 2, 388 .channels_min = 2,
diff --git a/sound/soc/fsl/imx-wm8962.c b/sound/soc/fsl/imx-wm8962.c
index 3a3d17ce6ba4..48179ffe1543 100644
--- a/sound/soc/fsl/imx-wm8962.c
+++ b/sound/soc/fsl/imx-wm8962.c
@@ -281,10 +281,8 @@ static int imx_wm8962_probe(struct platform_device *pdev)
281clk_fail: 281clk_fail:
282 clk_disable_unprepare(data->codec_clk); 282 clk_disable_unprepare(data->codec_clk);
283fail: 283fail:
284 if (ssi_np) 284 of_node_put(ssi_np);
285 of_node_put(ssi_np); 285 of_node_put(codec_np);
286 if (codec_np)
287 of_node_put(codec_np);
288 286
289 return ret; 287 return ret;
290} 288}
diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
index f2b5d756b1f3..0b82e209b6e3 100644
--- a/sound/soc/fsl/mpc5200_dma.c
+++ b/sound/soc/fsl/mpc5200_dma.c
@@ -327,9 +327,6 @@ static int psc_dma_new(struct snd_soc_pcm_runtime *rtd)
327 goto capture_alloc_err; 327 goto capture_alloc_err;
328 } 328 }
329 329
330 if (rtd->codec->ac97)
331 rtd->codec->ac97->private_data = psc_dma;
332
333 return 0; 330 return 0;
334 331
335 capture_alloc_err: 332 capture_alloc_err:
diff --git a/sound/soc/fsl/mpc5200_psc_ac97.c b/sound/soc/fsl/mpc5200_psc_ac97.c
index 24eafa2cfbf4..c6ed6ba965a9 100644
--- a/sound/soc/fsl/mpc5200_psc_ac97.c
+++ b/sound/soc/fsl/mpc5200_psc_ac97.c
@@ -237,7 +237,7 @@ static const struct snd_soc_dai_ops psc_ac97_digital_ops = {
237static struct snd_soc_dai_driver psc_ac97_dai[] = { 237static struct snd_soc_dai_driver psc_ac97_dai[] = {
238{ 238{
239 .name = "mpc5200-psc-ac97.0", 239 .name = "mpc5200-psc-ac97.0",
240 .ac97_control = 1, 240 .bus_control = true,
241 .probe = psc_ac97_probe, 241 .probe = psc_ac97_probe,
242 .playback = { 242 .playback = {
243 .stream_name = "AC97 Playback", 243 .stream_name = "AC97 Playback",
@@ -257,7 +257,7 @@ static struct snd_soc_dai_driver psc_ac97_dai[] = {
257}, 257},
258{ 258{
259 .name = "mpc5200-psc-ac97.1", 259 .name = "mpc5200-psc-ac97.1",
260 .ac97_control = 1, 260 .bus_control = true,
261 .playback = { 261 .playback = {
262 .stream_name = "AC97 SPDIF", 262 .stream_name = "AC97 SPDIF",
263 .channels_min = 1, 263 .channels_min = 1,
@@ -282,7 +282,6 @@ static const struct snd_soc_component_driver psc_ac97_component = {
282static int psc_ac97_of_probe(struct platform_device *op) 282static int psc_ac97_of_probe(struct platform_device *op)
283{ 283{
284 int rc; 284 int rc;
285 struct snd_ac97 ac97;
286 struct mpc52xx_psc __iomem *regs; 285 struct mpc52xx_psc __iomem *regs;
287 286
288 rc = mpc5200_audio_dma_create(op); 287 rc = mpc5200_audio_dma_create(op);
@@ -304,7 +303,6 @@ static int psc_ac97_of_probe(struct platform_device *op)
304 303
305 psc_dma = dev_get_drvdata(&op->dev); 304 psc_dma = dev_get_drvdata(&op->dev);
306 regs = psc_dma->psc_regs; 305 regs = psc_dma->psc_regs;
307 ac97.private_data = psc_dma;
308 306
309 psc_dma->imr = 0; 307 psc_dma->imr = 0;
310 out_be16(&psc_dma->psc_regs->isr_imr.imr, psc_dma->imr); 308 out_be16(&psc_dma->psc_regs->isr_imr.imr, psc_dma->imr);
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index d1b7293c133e..ece22d55ba82 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -29,7 +29,9 @@ struct simple_card_data {
29 } *dai_props; 29 } *dai_props;
30 unsigned int mclk_fs; 30 unsigned int mclk_fs;
31 int gpio_hp_det; 31 int gpio_hp_det;
32 int gpio_hp_det_invert;
32 int gpio_mic_det; 33 int gpio_mic_det;
34 int gpio_mic_det_invert;
33 struct snd_soc_dai_link dai_link[]; /* dynamically allocated */ 35 struct snd_soc_dai_link dai_link[]; /* dynamically allocated */
34}; 36};
35 37
@@ -148,6 +150,7 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
148 simple_card_hp_jack_pins); 150 simple_card_hp_jack_pins);
149 151
150 simple_card_hp_jack_gpio.gpio = priv->gpio_hp_det; 152 simple_card_hp_jack_gpio.gpio = priv->gpio_hp_det;
153 simple_card_hp_jack_gpio.invert = priv->gpio_hp_det_invert;
151 snd_soc_jack_add_gpios(&simple_card_hp_jack, 1, 154 snd_soc_jack_add_gpios(&simple_card_hp_jack, 1,
152 &simple_card_hp_jack_gpio); 155 &simple_card_hp_jack_gpio);
153 } 156 }
@@ -159,6 +162,7 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
159 ARRAY_SIZE(simple_card_mic_jack_pins), 162 ARRAY_SIZE(simple_card_mic_jack_pins),
160 simple_card_mic_jack_pins); 163 simple_card_mic_jack_pins);
161 simple_card_mic_jack_gpio.gpio = priv->gpio_mic_det; 164 simple_card_mic_jack_gpio.gpio = priv->gpio_mic_det;
165 simple_card_mic_jack_gpio.invert = priv->gpio_mic_det_invert;
162 snd_soc_jack_add_gpios(&simple_card_mic_jack, 1, 166 snd_soc_jack_add_gpios(&simple_card_mic_jack, 1,
163 &simple_card_mic_jack_gpio); 167 &simple_card_mic_jack_gpio);
164 } 168 }
@@ -226,6 +230,52 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
226 return 0; 230 return 0;
227} 231}
228 232
233static int asoc_simple_card_parse_daifmt(struct device_node *node,
234 struct simple_card_data *priv,
235 struct device_node *codec,
236 char *prefix, int idx)
237{
238 struct device *dev = simple_priv_to_dev(priv);
239 struct device_node *bitclkmaster = NULL;
240 struct device_node *framemaster = NULL;
241 struct simple_dai_props *dai_props = simple_priv_to_props(priv, idx);
242 struct asoc_simple_dai *cpu_dai = &dai_props->cpu_dai;
243 struct asoc_simple_dai *codec_dai = &dai_props->codec_dai;
244 unsigned int daifmt;
245
246 daifmt = snd_soc_of_parse_daifmt(node, prefix,
247 &bitclkmaster, &framemaster);
248 daifmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
249
250 if (strlen(prefix) && !bitclkmaster && !framemaster) {
251 /*
252 * No dai-link level and master setting was not found from
253 * sound node level, revert back to legacy DT parsing and
254 * take the settings from codec node.
255 */
256 dev_dbg(dev, "Revert to legacy daifmt parsing\n");
257
258 cpu_dai->fmt = codec_dai->fmt =
259 snd_soc_of_parse_daifmt(codec, NULL, NULL, NULL) |
260 (daifmt & ~SND_SOC_DAIFMT_CLOCK_MASK);
261 } else {
262 if (codec == bitclkmaster)
263 daifmt |= (codec == framemaster) ?
264 SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBM_CFS;
265 else
266 daifmt |= (codec == framemaster) ?
267 SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS;
268
269 cpu_dai->fmt = daifmt;
270 codec_dai->fmt = daifmt;
271 }
272
273 of_node_put(bitclkmaster);
274 of_node_put(framemaster);
275
276 return 0;
277}
278
229static int asoc_simple_card_dai_link_of(struct device_node *node, 279static int asoc_simple_card_dai_link_of(struct device_node *node,
230 struct simple_card_data *priv, 280 struct simple_card_data *priv,
231 int idx, 281 int idx,
@@ -234,10 +284,8 @@ static int asoc_simple_card_dai_link_of(struct device_node *node,
234 struct device *dev = simple_priv_to_dev(priv); 284 struct device *dev = simple_priv_to_dev(priv);
235 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, idx); 285 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, idx);
236 struct simple_dai_props *dai_props = simple_priv_to_props(priv, idx); 286 struct simple_dai_props *dai_props = simple_priv_to_props(priv, idx);
237 struct device_node *np = NULL; 287 struct device_node *cpu = NULL;
238 struct device_node *bitclkmaster = NULL; 288 struct device_node *codec = NULL;
239 struct device_node *framemaster = NULL;
240 unsigned int daifmt;
241 char *name; 289 char *name;
242 char prop[128]; 290 char prop[128];
243 char *prefix = ""; 291 char *prefix = "";
@@ -247,85 +295,36 @@ static int asoc_simple_card_dai_link_of(struct device_node *node,
247 if (is_top_level_node) 295 if (is_top_level_node)
248 prefix = "simple-audio-card,"; 296 prefix = "simple-audio-card,";
249 297
250 daifmt = snd_soc_of_parse_daifmt(node, prefix,
251 &bitclkmaster, &framemaster);
252 daifmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
253
254 snprintf(prop, sizeof(prop), "%scpu", prefix); 298 snprintf(prop, sizeof(prop), "%scpu", prefix);
255 np = of_get_child_by_name(node, prop); 299 cpu = of_get_child_by_name(node, prop);
256 if (!np) { 300
301 snprintf(prop, sizeof(prop), "%scodec", prefix);
302 codec = of_get_child_by_name(node, prop);
303
304 if (!cpu || !codec) {
257 ret = -EINVAL; 305 ret = -EINVAL;
258 dev_err(dev, "%s: Can't find %s DT node\n", __func__, prop); 306 dev_err(dev, "%s: Can't find %s DT node\n", __func__, prop);
259 goto dai_link_of_err; 307 goto dai_link_of_err;
260 } 308 }
261 309
262 ret = asoc_simple_card_sub_parse_of(np, &dai_props->cpu_dai, 310 ret = asoc_simple_card_parse_daifmt(node, priv,
311 codec, prefix, idx);
312 if (ret < 0)
313 goto dai_link_of_err;
314
315 ret = asoc_simple_card_sub_parse_of(cpu, &dai_props->cpu_dai,
263 &dai_link->cpu_of_node, 316 &dai_link->cpu_of_node,
264 &dai_link->cpu_dai_name, 317 &dai_link->cpu_dai_name,
265 &cpu_args); 318 &cpu_args);
266 if (ret < 0) 319 if (ret < 0)
267 goto dai_link_of_err; 320 goto dai_link_of_err;
268 321
269 dai_props->cpu_dai.fmt = daifmt; 322 ret = asoc_simple_card_sub_parse_of(codec, &dai_props->codec_dai,
270 switch (((np == bitclkmaster) << 4) | (np == framemaster)) {
271 case 0x11:
272 dai_props->cpu_dai.fmt |= SND_SOC_DAIFMT_CBS_CFS;
273 break;
274 case 0x10:
275 dai_props->cpu_dai.fmt |= SND_SOC_DAIFMT_CBS_CFM;
276 break;
277 case 0x01:
278 dai_props->cpu_dai.fmt |= SND_SOC_DAIFMT_CBM_CFS;
279 break;
280 default:
281 dai_props->cpu_dai.fmt |= SND_SOC_DAIFMT_CBM_CFM;
282 break;
283 }
284
285 of_node_put(np);
286 snprintf(prop, sizeof(prop), "%scodec", prefix);
287 np = of_get_child_by_name(node, prop);
288 if (!np) {
289 ret = -EINVAL;
290 dev_err(dev, "%s: Can't find %s DT node\n", __func__, prop);
291 goto dai_link_of_err;
292 }
293
294 ret = asoc_simple_card_sub_parse_of(np, &dai_props->codec_dai,
295 &dai_link->codec_of_node, 323 &dai_link->codec_of_node,
296 &dai_link->codec_dai_name, NULL); 324 &dai_link->codec_dai_name, NULL);
297 if (ret < 0) 325 if (ret < 0)
298 goto dai_link_of_err; 326 goto dai_link_of_err;
299 327
300 if (strlen(prefix) && !bitclkmaster && !framemaster) {
301 /*
302 * No DAI link level and master setting was found
303 * from sound node level, revert back to legacy DT
304 * parsing and take the settings from codec node.
305 */
306 dev_dbg(dev, "%s: Revert to legacy daifmt parsing\n",
307 __func__);
308 dai_props->cpu_dai.fmt = dai_props->codec_dai.fmt =
309 snd_soc_of_parse_daifmt(np, NULL, NULL, NULL) |
310 (daifmt & ~SND_SOC_DAIFMT_CLOCK_MASK);
311 } else {
312 dai_props->codec_dai.fmt = daifmt;
313 switch (((np == bitclkmaster) << 4) | (np == framemaster)) {
314 case 0x11:
315 dai_props->codec_dai.fmt |= SND_SOC_DAIFMT_CBM_CFM;
316 break;
317 case 0x10:
318 dai_props->codec_dai.fmt |= SND_SOC_DAIFMT_CBM_CFS;
319 break;
320 case 0x01:
321 dai_props->codec_dai.fmt |= SND_SOC_DAIFMT_CBS_CFM;
322 break;
323 default:
324 dai_props->codec_dai.fmt |= SND_SOC_DAIFMT_CBS_CFS;
325 break;
326 }
327 }
328
329 if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) { 328 if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) {
330 ret = -EINVAL; 329 ret = -EINVAL;
331 goto dai_link_of_err; 330 goto dai_link_of_err;
@@ -368,12 +367,9 @@ static int asoc_simple_card_dai_link_of(struct device_node *node,
368 dai_link->cpu_dai_name = NULL; 367 dai_link->cpu_dai_name = NULL;
369 368
370dai_link_of_err: 369dai_link_of_err:
371 if (np) 370 of_node_put(cpu);
372 of_node_put(np); 371 of_node_put(codec);
373 if (bitclkmaster) 372
374 of_node_put(bitclkmaster);
375 if (framemaster)
376 of_node_put(framemaster);
377 return ret; 373 return ret;
378} 374}
379 375
@@ -381,6 +377,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
381 struct simple_card_data *priv) 377 struct simple_card_data *priv)
382{ 378{
383 struct device *dev = simple_priv_to_dev(priv); 379 struct device *dev = simple_priv_to_dev(priv);
380 enum of_gpio_flags flags;
384 u32 val; 381 u32 val;
385 int ret; 382 int ret;
386 383
@@ -436,13 +433,15 @@ static int asoc_simple_card_parse_of(struct device_node *node,
436 return ret; 433 return ret;
437 } 434 }
438 435
439 priv->gpio_hp_det = of_get_named_gpio(node, 436 priv->gpio_hp_det = of_get_named_gpio_flags(node,
440 "simple-audio-card,hp-det-gpio", 0); 437 "simple-audio-card,hp-det-gpio", 0, &flags);
438 priv->gpio_hp_det_invert = !!(flags & OF_GPIO_ACTIVE_LOW);
441 if (priv->gpio_hp_det == -EPROBE_DEFER) 439 if (priv->gpio_hp_det == -EPROBE_DEFER)
442 return -EPROBE_DEFER; 440 return -EPROBE_DEFER;
443 441
444 priv->gpio_mic_det = of_get_named_gpio(node, 442 priv->gpio_mic_det = of_get_named_gpio_flags(node,
445 "simple-audio-card,mic-det-gpio", 0); 443 "simple-audio-card,mic-det-gpio", 0, &flags);
444 priv->gpio_mic_det_invert = !!(flags & OF_GPIO_ACTIVE_LOW);
446 if (priv->gpio_mic_det == -EPROBE_DEFER) 445 if (priv->gpio_mic_det == -EPROBE_DEFER)
447 return -EPROBE_DEFER; 446 return -EPROBE_DEFER;
448 447
@@ -457,18 +456,13 @@ static int asoc_simple_card_unref(struct platform_device *pdev)
457{ 456{
458 struct snd_soc_card *card = platform_get_drvdata(pdev); 457 struct snd_soc_card *card = platform_get_drvdata(pdev);
459 struct snd_soc_dai_link *dai_link; 458 struct snd_soc_dai_link *dai_link;
460 struct device_node *np;
461 int num_links; 459 int num_links;
462 460
463 for (num_links = 0, dai_link = card->dai_link; 461 for (num_links = 0, dai_link = card->dai_link;
464 num_links < card->num_links; 462 num_links < card->num_links;
465 num_links++, dai_link++) { 463 num_links++, dai_link++) {
466 np = (struct device_node *) dai_link->cpu_of_node; 464 of_node_put(dai_link->cpu_of_node);
467 if (np) 465 of_node_put(dai_link->codec_of_node);
468 of_node_put(np);
469 np = (struct device_node *) dai_link->codec_of_node;
470 if (np)
471 of_node_put(np);
472 } 466 }
473 return 0; 467 return 0;
474} 468}
diff --git a/sound/soc/intel/Kconfig b/sound/soc/intel/Kconfig
index f5b4a9c79cdf..e989ecf046c9 100644
--- a/sound/soc/intel/Kconfig
+++ b/sound/soc/intel/Kconfig
@@ -3,6 +3,7 @@ config SND_MFLD_MACHINE
3 depends on INTEL_SCU_IPC 3 depends on INTEL_SCU_IPC
4 select SND_SOC_SN95031 4 select SND_SOC_SN95031
5 select SND_SST_MFLD_PLATFORM 5 select SND_SST_MFLD_PLATFORM
6 select SND_SST_IPC_PCI
6 help 7 help
7 This adds support for ASoC machine driver for Intel(R) MID Medfield platform 8 This adds support for ASoC machine driver for Intel(R) MID Medfield platform
8 used as alsa device in audio substem in Intel(R) MID devices 9 used as alsa device in audio substem in Intel(R) MID devices
@@ -12,10 +13,23 @@ config SND_MFLD_MACHINE
12config SND_SST_MFLD_PLATFORM 13config SND_SST_MFLD_PLATFORM
13 tristate 14 tristate
14 15
16config SND_SST_IPC
17 tristate
18
19config SND_SST_IPC_PCI
20 tristate
21 select SND_SST_IPC
22
23config SND_SST_IPC_ACPI
24 tristate
25 select SND_SST_IPC
26 depends on ACPI
27
15config SND_SOC_INTEL_SST 28config SND_SOC_INTEL_SST
16 tristate "ASoC support for Intel(R) Smart Sound Technology" 29 tristate "ASoC support for Intel(R) Smart Sound Technology"
17 select SND_SOC_INTEL_SST_ACPI if ACPI 30 select SND_SOC_INTEL_SST_ACPI if ACPI
18 depends on (X86 || COMPILE_TEST) 31 depends on (X86 || COMPILE_TEST)
32 depends on DW_DMAC_CORE
19 help 33 help
20 This adds support for Intel(R) Smart Sound Technology (SST). 34 This adds support for Intel(R) Smart Sound Technology (SST).
21 Say Y if you have such a device 35 Say Y if you have such a device
@@ -32,7 +46,8 @@ config SND_SOC_INTEL_BAYTRAIL
32 46
33config SND_SOC_INTEL_HASWELL_MACH 47config SND_SOC_INTEL_HASWELL_MACH
34 tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint" 48 tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint"
35 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && I2C 49 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && I2C && \\
50 I2C_DESIGNWARE_PLATFORM
36 select SND_SOC_INTEL_HASWELL 51 select SND_SOC_INTEL_HASWELL
37 select SND_SOC_RT5640 52 select SND_SOC_RT5640
38 help 53 help
@@ -61,7 +76,8 @@ config SND_SOC_INTEL_BYT_MAX98090_MACH
61 76
62config SND_SOC_INTEL_BROADWELL_MACH 77config SND_SOC_INTEL_BROADWELL_MACH
63 tristate "ASoC Audio DSP support for Intel Broadwell Wildcatpoint" 78 tristate "ASoC Audio DSP support for Intel Broadwell Wildcatpoint"
64 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && DW_DMAC 79 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && DW_DMAC && \\
80 I2C_DESIGNWARE_PLATFORM
65 select SND_SOC_INTEL_HASWELL 81 select SND_SOC_INTEL_HASWELL
66 select SND_COMPRESS_OFFLOAD 82 select SND_COMPRESS_OFFLOAD
67 select SND_SOC_RT286 83 select SND_SOC_RT286
@@ -70,3 +86,27 @@ config SND_SOC_INTEL_BROADWELL_MACH
70 Ultrabook platforms. 86 Ultrabook platforms.
71 Say Y if you have such a device 87 Say Y if you have such a device
72 If unsure select "N". 88 If unsure select "N".
89
90config SND_SOC_INTEL_BYTCR_RT5640_MACH
91 tristate "ASoC Audio DSP Support for MID BYT Platform"
92 depends on X86
93 select SND_SOC_RT5640
94 select SND_SST_MFLD_PLATFORM
95 select SND_SST_IPC_ACPI
96 help
97 This adds support for ASoC machine driver for Intel(R) MID Baytrail platform
98 used as alsa device in audio substem in Intel(R) MID devices
99 Say Y if you have such a device
100 If unsure select "N".
101
102config SND_SOC_INTEL_CHT_BSW_RT5672_MACH
103 tristate "ASoC Audio driver for Intel Cherrytrail & Braswell with RT5672 codec"
104 depends on X86_INTEL_LPSS
105 select SND_SOC_RT5670
106 select SND_SST_MFLD_PLATFORM
107 select SND_SST_IPC_ACPI
108 help
109 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell
110 platforms with RT5672 audio codec.
111 Say Y if you have such a device
112 If unsure select "N".
diff --git a/sound/soc/intel/Makefile b/sound/soc/intel/Makefile
index f841786dad15..e928ec385300 100644
--- a/sound/soc/intel/Makefile
+++ b/sound/soc/intel/Makefile
@@ -26,8 +26,15 @@ snd-soc-sst-haswell-objs := haswell.o
26snd-soc-sst-byt-rt5640-mach-objs := byt-rt5640.o 26snd-soc-sst-byt-rt5640-mach-objs := byt-rt5640.o
27snd-soc-sst-byt-max98090-mach-objs := byt-max98090.o 27snd-soc-sst-byt-max98090-mach-objs := byt-max98090.o
28snd-soc-sst-broadwell-objs := broadwell.o 28snd-soc-sst-broadwell-objs := broadwell.o
29snd-soc-sst-bytcr-dpcm-rt5640-objs := bytcr_dpcm_rt5640.o
30snd-soc-sst-cht-bsw-rt5672-objs := cht_bsw_rt5672.o
29 31
30obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-sst-haswell.o 32obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-sst-haswell.o
31obj-$(CONFIG_SND_SOC_INTEL_BYT_RT5640_MACH) += snd-soc-sst-byt-rt5640-mach.o 33obj-$(CONFIG_SND_SOC_INTEL_BYT_RT5640_MACH) += snd-soc-sst-byt-rt5640-mach.o
32obj-$(CONFIG_SND_SOC_INTEL_BYT_MAX98090_MACH) += snd-soc-sst-byt-max98090-mach.o 34obj-$(CONFIG_SND_SOC_INTEL_BYT_MAX98090_MACH) += snd-soc-sst-byt-max98090-mach.o
33obj-$(CONFIG_SND_SOC_INTEL_BROADWELL_MACH) += snd-soc-sst-broadwell.o 35obj-$(CONFIG_SND_SOC_INTEL_BROADWELL_MACH) += snd-soc-sst-broadwell.o
36obj-$(CONFIG_SND_SOC_INTEL_BYTCR_RT5640_MACH) += snd-soc-sst-bytcr-dpcm-rt5640.o
37obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5672_MACH) += snd-soc-sst-cht-bsw-rt5672.o
38
39# DSP driver
40obj-$(CONFIG_SND_SST_IPC) += sst/
diff --git a/sound/soc/intel/broadwell.c b/sound/soc/intel/broadwell.c
index 0e550f14028f..c256764e3c4b 100644
--- a/sound/soc/intel/broadwell.c
+++ b/sound/soc/intel/broadwell.c
@@ -19,6 +19,7 @@
19#include <sound/core.h> 19#include <sound/core.h>
20#include <sound/pcm.h> 20#include <sound/pcm.h>
21#include <sound/soc.h> 21#include <sound/soc.h>
22#include <sound/jack.h>
22#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
23 24
24#include "sst-dsp.h" 25#include "sst-dsp.h"
@@ -26,8 +27,26 @@
26 27
27#include "../codecs/rt286.h" 28#include "../codecs/rt286.h"
28 29
30static struct snd_soc_jack broadwell_headset;
31/* Headset jack detection DAPM pins */
32static struct snd_soc_jack_pin broadwell_headset_pins[] = {
33 {
34 .pin = "Mic Jack",
35 .mask = SND_JACK_MICROPHONE,
36 },
37 {
38 .pin = "Headphone Jack",
39 .mask = SND_JACK_HEADPHONE,
40 },
41};
42
43static const struct snd_kcontrol_new broadwell_controls[] = {
44 SOC_DAPM_PIN_SWITCH("Speaker"),
45 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
46};
47
29static const struct snd_soc_dapm_widget broadwell_widgets[] = { 48static const struct snd_soc_dapm_widget broadwell_widgets[] = {
30 SND_SOC_DAPM_HP("Headphones", NULL), 49 SND_SOC_DAPM_HP("Headphone Jack", NULL),
31 SND_SOC_DAPM_SPK("Speaker", NULL), 50 SND_SOC_DAPM_SPK("Speaker", NULL),
32 SND_SOC_DAPM_MIC("Mic Jack", NULL), 51 SND_SOC_DAPM_MIC("Mic Jack", NULL),
33 SND_SOC_DAPM_MIC("DMIC1", NULL), 52 SND_SOC_DAPM_MIC("DMIC1", NULL),
@@ -42,7 +61,7 @@ static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
42 {"Speaker", NULL, "SPOL"}, 61 {"Speaker", NULL, "SPOL"},
43 62
44 /* HP jack connectors - unknown if we have jack deteck */ 63 /* HP jack connectors - unknown if we have jack deteck */
45 {"Headphones", NULL, "HPO Pin"}, 64 {"Headphone Jack", NULL, "HPO Pin"},
46 65
47 /* other jacks */ 66 /* other jacks */
48 {"MIC1", NULL, "Mic Jack"}, 67 {"MIC1", NULL, "Mic Jack"},
@@ -57,6 +76,27 @@ static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
57 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"}, 76 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
58}; 77};
59 78
79static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
80{
81 struct snd_soc_codec *codec = rtd->codec;
82 int ret = 0;
83 ret = snd_soc_jack_new(codec, "Headset",
84 SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset);
85
86 if (ret)
87 return ret;
88
89 ret = snd_soc_jack_add_pins(&broadwell_headset,
90 ARRAY_SIZE(broadwell_headset_pins),
91 broadwell_headset_pins);
92 if (ret)
93 return ret;
94
95 rt286_mic_detect(codec, &broadwell_headset);
96 return 0;
97}
98
99
60static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd, 100static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
61 struct snd_pcm_hw_params *params) 101 struct snd_pcm_hw_params *params)
62{ 102{
@@ -116,7 +156,7 @@ static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
116 } 156 }
117 157
118 /* always connected - check HP for jack detect */ 158 /* always connected - check HP for jack detect */
119 snd_soc_dapm_enable_pin(dapm, "Headphones"); 159 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
120 snd_soc_dapm_enable_pin(dapm, "Speaker"); 160 snd_soc_dapm_enable_pin(dapm, "Speaker");
121 snd_soc_dapm_enable_pin(dapm, "Mic Jack"); 161 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
122 snd_soc_dapm_enable_pin(dapm, "Line Jack"); 162 snd_soc_dapm_enable_pin(dapm, "Line Jack");
@@ -131,7 +171,7 @@ static struct snd_soc_dai_link broadwell_rt286_dais[] = {
131 /* Front End DAI links */ 171 /* Front End DAI links */
132 { 172 {
133 .name = "System PCM", 173 .name = "System PCM",
134 .stream_name = "System Playback", 174 .stream_name = "System Playback/Capture",
135 .cpu_dai_name = "System Pin", 175 .cpu_dai_name = "System Pin",
136 .platform_name = "haswell-pcm-audio", 176 .platform_name = "haswell-pcm-audio",
137 .dynamic = 1, 177 .dynamic = 1,
@@ -140,6 +180,7 @@ static struct snd_soc_dai_link broadwell_rt286_dais[] = {
140 .init = broadwell_rtd_init, 180 .init = broadwell_rtd_init,
141 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 181 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
142 .dpcm_playback = 1, 182 .dpcm_playback = 1,
183 .dpcm_capture = 1,
143 }, 184 },
144 { 185 {
145 .name = "Offload0", 186 .name = "Offload0",
@@ -174,18 +215,6 @@ static struct snd_soc_dai_link broadwell_rt286_dais[] = {
174 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 215 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
175 .dpcm_capture = 1, 216 .dpcm_capture = 1,
176 }, 217 },
177 {
178 .name = "Capture PCM",
179 .stream_name = "Capture",
180 .cpu_dai_name = "Capture Pin",
181 .platform_name = "haswell-pcm-audio",
182 .dynamic = 1,
183 .codec_name = "snd-soc-dummy",
184 .codec_dai_name = "snd-soc-dummy-dai",
185 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
186 .dpcm_capture = 1,
187 },
188
189 /* Back End DAI links */ 218 /* Back End DAI links */
190 { 219 {
191 /* SSP0 - Codec */ 220 /* SSP0 - Codec */
@@ -196,6 +225,7 @@ static struct snd_soc_dai_link broadwell_rt286_dais[] = {
196 .no_pcm = 1, 225 .no_pcm = 1,
197 .codec_name = "i2c-INT343A:00", 226 .codec_name = "i2c-INT343A:00",
198 .codec_dai_name = "rt286-aif1", 227 .codec_dai_name = "rt286-aif1",
228 .init = broadwell_rt286_codec_init,
199 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 229 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
200 SND_SOC_DAIFMT_CBS_CFS, 230 SND_SOC_DAIFMT_CBS_CFS,
201 .ignore_suspend = 1, 231 .ignore_suspend = 1,
@@ -213,6 +243,8 @@ static struct snd_soc_card broadwell_rt286 = {
213 .owner = THIS_MODULE, 243 .owner = THIS_MODULE,
214 .dai_link = broadwell_rt286_dais, 244 .dai_link = broadwell_rt286_dais,
215 .num_links = ARRAY_SIZE(broadwell_rt286_dais), 245 .num_links = ARRAY_SIZE(broadwell_rt286_dais),
246 .controls = broadwell_controls,
247 .num_controls = ARRAY_SIZE(broadwell_controls),
216 .dapm_widgets = broadwell_widgets, 248 .dapm_widgets = broadwell_widgets,
217 .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets), 249 .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
218 .dapm_routes = broadwell_rt286_map, 250 .dapm_routes = broadwell_rt286_map,
diff --git a/sound/soc/intel/bytcr_dpcm_rt5640.c b/sound/soc/intel/bytcr_dpcm_rt5640.c
new file mode 100644
index 000000000000..f5d0fc1ab10c
--- /dev/null
+++ b/sound/soc/intel/bytcr_dpcm_rt5640.c
@@ -0,0 +1,230 @@
1/*
2 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
3 *
4 * Copyright (C) 2014 Intel Corp
5 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.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; version 2 of the License.
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 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 */
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/device.h>
24#include <linux/slab.h>
25#include <linux/input.h>
26#include <sound/pcm.h>
27#include <sound/pcm_params.h>
28#include <sound/soc.h>
29#include "../codecs/rt5640.h"
30#include "sst-atom-controls.h"
31
32static const struct snd_soc_dapm_widget byt_dapm_widgets[] = {
33 SND_SOC_DAPM_HP("Headphone", NULL),
34 SND_SOC_DAPM_MIC("Headset Mic", NULL),
35 SND_SOC_DAPM_MIC("Int Mic", NULL),
36 SND_SOC_DAPM_SPK("Ext Spk", NULL),
37};
38
39static const struct snd_soc_dapm_route byt_audio_map[] = {
40 {"IN2P", NULL, "Headset Mic"},
41 {"IN2N", NULL, "Headset Mic"},
42 {"Headset Mic", NULL, "MICBIAS1"},
43 {"IN1P", NULL, "MICBIAS1"},
44 {"LDO2", NULL, "Int Mic"},
45 {"Headphone", NULL, "HPOL"},
46 {"Headphone", NULL, "HPOR"},
47 {"Ext Spk", NULL, "SPOLP"},
48 {"Ext Spk", NULL, "SPOLN"},
49 {"Ext Spk", NULL, "SPORP"},
50 {"Ext Spk", NULL, "SPORN"},
51
52 {"AIF1 Playback", NULL, "ssp2 Tx"},
53 {"ssp2 Tx", NULL, "codec_out0"},
54 {"ssp2 Tx", NULL, "codec_out1"},
55 {"codec_in0", NULL, "ssp2 Rx"},
56 {"codec_in1", NULL, "ssp2 Rx"},
57 {"ssp2 Rx", NULL, "AIF1 Capture"},
58};
59
60static const struct snd_kcontrol_new byt_mc_controls[] = {
61 SOC_DAPM_PIN_SWITCH("Headphone"),
62 SOC_DAPM_PIN_SWITCH("Headset Mic"),
63 SOC_DAPM_PIN_SWITCH("Int Mic"),
64 SOC_DAPM_PIN_SWITCH("Ext Spk"),
65};
66
67static int byt_aif1_hw_params(struct snd_pcm_substream *substream,
68 struct snd_pcm_hw_params *params)
69{
70 struct snd_soc_pcm_runtime *rtd = substream->private_data;
71 struct snd_soc_dai *codec_dai = rtd->codec_dai;
72 int ret;
73
74 snd_soc_dai_set_bclk_ratio(codec_dai, 50);
75
76 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
77 params_rate(params) * 512,
78 SND_SOC_CLOCK_IN);
79 if (ret < 0) {
80 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
81 return ret;
82 }
83
84 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
85 params_rate(params) * 50,
86 params_rate(params) * 512);
87 if (ret < 0) {
88 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
89 return ret;
90 }
91
92 return 0;
93}
94
95static const struct snd_soc_pcm_stream byt_dai_params = {
96 .formats = SNDRV_PCM_FMTBIT_S24_LE,
97 .rate_min = 48000,
98 .rate_max = 48000,
99 .channels_min = 2,
100 .channels_max = 2,
101};
102
103static int byt_codec_fixup(struct snd_soc_pcm_runtime *rtd,
104 struct snd_pcm_hw_params *params)
105{
106 struct snd_interval *rate = hw_param_interval(params,
107 SNDRV_PCM_HW_PARAM_RATE);
108 struct snd_interval *channels = hw_param_interval(params,
109 SNDRV_PCM_HW_PARAM_CHANNELS);
110
111 /* The DSP will covert the FE rate to 48k, stereo, 24bits */
112 rate->min = rate->max = 48000;
113 channels->min = channels->max = 2;
114
115 /* set SSP2 to 24-bit */
116 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
117 SNDRV_PCM_HW_PARAM_FIRST_MASK],
118 SNDRV_PCM_FORMAT_S24_LE);
119 return 0;
120}
121
122static unsigned int rates_48000[] = {
123 48000,
124};
125
126static struct snd_pcm_hw_constraint_list constraints_48000 = {
127 .count = ARRAY_SIZE(rates_48000),
128 .list = rates_48000,
129};
130
131static int byt_aif1_startup(struct snd_pcm_substream *substream)
132{
133 return snd_pcm_hw_constraint_list(substream->runtime, 0,
134 SNDRV_PCM_HW_PARAM_RATE,
135 &constraints_48000);
136}
137
138static struct snd_soc_ops byt_aif1_ops = {
139 .startup = byt_aif1_startup,
140};
141
142static struct snd_soc_ops byt_be_ssp2_ops = {
143 .hw_params = byt_aif1_hw_params,
144};
145
146static struct snd_soc_dai_link byt_dailink[] = {
147 [MERR_DPCM_AUDIO] = {
148 .name = "Baytrail Audio Port",
149 .stream_name = "Baytrail Audio",
150 .cpu_dai_name = "media-cpu-dai",
151 .codec_dai_name = "snd-soc-dummy-dai",
152 .codec_name = "snd-soc-dummy",
153 .platform_name = "sst-mfld-platform",
154 .ignore_suspend = 1,
155 .dynamic = 1,
156 .dpcm_playback = 1,
157 .dpcm_capture = 1,
158 .ops = &byt_aif1_ops,
159 },
160 [MERR_DPCM_COMPR] = {
161 .name = "Baytrail Compressed Port",
162 .stream_name = "Baytrail Compress",
163 .cpu_dai_name = "compress-cpu-dai",
164 .codec_dai_name = "snd-soc-dummy-dai",
165 .codec_name = "snd-soc-dummy",
166 .platform_name = "sst-mfld-platform",
167 },
168 /* back ends */
169 {
170 .name = "SSP2-Codec",
171 .be_id = 1,
172 .cpu_dai_name = "ssp2-port",
173 .platform_name = "sst-mfld-platform",
174 .no_pcm = 1,
175 .codec_dai_name = "rt5640-aif1",
176 .codec_name = "i2c-10EC5640:00",
177 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
178 | SND_SOC_DAIFMT_CBS_CFS,
179 .be_hw_params_fixup = byt_codec_fixup,
180 .ignore_suspend = 1,
181 .dpcm_playback = 1,
182 .dpcm_capture = 1,
183 .ops = &byt_be_ssp2_ops,
184 },
185};
186
187/* SoC card */
188static struct snd_soc_card snd_soc_card_byt = {
189 .name = "baytrailcraudio",
190 .dai_link = byt_dailink,
191 .num_links = ARRAY_SIZE(byt_dailink),
192 .dapm_widgets = byt_dapm_widgets,
193 .num_dapm_widgets = ARRAY_SIZE(byt_dapm_widgets),
194 .dapm_routes = byt_audio_map,
195 .num_dapm_routes = ARRAY_SIZE(byt_audio_map),
196 .controls = byt_mc_controls,
197 .num_controls = ARRAY_SIZE(byt_mc_controls),
198};
199
200static int snd_byt_mc_probe(struct platform_device *pdev)
201{
202 int ret_val = 0;
203
204 /* register the soc card */
205 snd_soc_card_byt.dev = &pdev->dev;
206
207 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_byt);
208 if (ret_val) {
209 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", ret_val);
210 return ret_val;
211 }
212 platform_set_drvdata(pdev, &snd_soc_card_byt);
213 return ret_val;
214}
215
216static struct platform_driver snd_byt_mc_driver = {
217 .driver = {
218 .owner = THIS_MODULE,
219 .name = "bytt100_rt5640",
220 .pm = &snd_soc_pm_ops,
221 },
222 .probe = snd_byt_mc_probe,
223};
224
225module_platform_driver(snd_byt_mc_driver);
226
227MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
228MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
229MODULE_LICENSE("GPL v2");
230MODULE_ALIAS("platform:bytrt5640-audio");
diff --git a/sound/soc/intel/cht_bsw_rt5672.c b/sound/soc/intel/cht_bsw_rt5672.c
new file mode 100644
index 000000000000..9b8b561171b7
--- /dev/null
+++ b/sound/soc/intel/cht_bsw_rt5672.c
@@ -0,0 +1,285 @@
1/*
2 * cht_bsw_rt5672.c - ASoc Machine driver for Intel Cherryview-based platforms
3 * Cherrytrail and Braswell, with RT5672 codec.
4 *
5 * Copyright (C) 2014 Intel Corp
6 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
7 * Mengdong Lin <mengdong.lin@intel.com>
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; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/slab.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include <sound/soc.h>
25#include "../codecs/rt5670.h"
26#include "sst-atom-controls.h"
27
28/* The platform clock #3 outputs 19.2Mhz clock to codec as I2S MCLK */
29#define CHT_PLAT_CLK_3_HZ 19200000
30#define CHT_CODEC_DAI "rt5670-aif1"
31
32static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card)
33{
34 int i;
35
36 for (i = 0; i < card->num_rtd; i++) {
37 struct snd_soc_pcm_runtime *rtd;
38
39 rtd = card->rtd + i;
40 if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI,
41 strlen(CHT_CODEC_DAI)))
42 return rtd->codec_dai;
43 }
44 return NULL;
45}
46
47static int platform_clock_control(struct snd_soc_dapm_widget *w,
48 struct snd_kcontrol *k, int event)
49{
50 struct snd_soc_dapm_context *dapm = w->dapm;
51 struct snd_soc_card *card = dapm->card;
52 struct snd_soc_dai *codec_dai;
53
54 codec_dai = cht_get_codec_dai(card);
55 if (!codec_dai) {
56 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n");
57 return -EIO;
58 }
59
60 if (!SND_SOC_DAPM_EVENT_OFF(event))
61 return 0;
62
63 /* Set codec sysclk source to its internal clock because codec PLL will
64 * be off when idle and MCLK will also be off by ACPI when codec is
65 * runtime suspended. Codec needs clock for jack detection and button
66 * press.
67 */
68 snd_soc_dai_set_sysclk(codec_dai, RT5670_SCLK_S_RCCLK,
69 0, SND_SOC_CLOCK_IN);
70
71 return 0;
72}
73
74static const struct snd_soc_dapm_widget cht_dapm_widgets[] = {
75 SND_SOC_DAPM_HP("Headphone", NULL),
76 SND_SOC_DAPM_MIC("Headset Mic", NULL),
77 SND_SOC_DAPM_MIC("Int Mic", NULL),
78 SND_SOC_DAPM_SPK("Ext Spk", NULL),
79 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
80 platform_clock_control, SND_SOC_DAPM_POST_PMD),
81};
82
83static const struct snd_soc_dapm_route cht_audio_map[] = {
84 {"IN1P", NULL, "Headset Mic"},
85 {"IN1N", NULL, "Headset Mic"},
86 {"DMIC L1", NULL, "Int Mic"},
87 {"DMIC R1", NULL, "Int Mic"},
88 {"Headphone", NULL, "HPOL"},
89 {"Headphone", NULL, "HPOR"},
90 {"Ext Spk", NULL, "SPOLP"},
91 {"Ext Spk", NULL, "SPOLN"},
92 {"Ext Spk", NULL, "SPORP"},
93 {"Ext Spk", NULL, "SPORN"},
94 {"AIF1 Playback", NULL, "ssp2 Tx"},
95 {"ssp2 Tx", NULL, "codec_out0"},
96 {"ssp2 Tx", NULL, "codec_out1"},
97 {"codec_in0", NULL, "ssp2 Rx"},
98 {"codec_in1", NULL, "ssp2 Rx"},
99 {"ssp2 Rx", NULL, "AIF1 Capture"},
100 {"Headphone", NULL, "Platform Clock"},
101 {"Headset Mic", NULL, "Platform Clock"},
102 {"Int Mic", NULL, "Platform Clock"},
103 {"Ext Spk", NULL, "Platform Clock"},
104};
105
106static const struct snd_kcontrol_new cht_mc_controls[] = {
107 SOC_DAPM_PIN_SWITCH("Headphone"),
108 SOC_DAPM_PIN_SWITCH("Headset Mic"),
109 SOC_DAPM_PIN_SWITCH("Int Mic"),
110 SOC_DAPM_PIN_SWITCH("Ext Spk"),
111};
112
113static int cht_aif1_hw_params(struct snd_pcm_substream *substream,
114 struct snd_pcm_hw_params *params)
115{
116 struct snd_soc_pcm_runtime *rtd = substream->private_data;
117 struct snd_soc_dai *codec_dai = rtd->codec_dai;
118 int ret;
119
120 /* set codec PLL source to the 19.2MHz platform clock (MCLK) */
121 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5670_PLL1_S_MCLK,
122 CHT_PLAT_CLK_3_HZ, params_rate(params) * 512);
123 if (ret < 0) {
124 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
125 return ret;
126 }
127
128 /* set codec sysclk source to PLL */
129 ret = snd_soc_dai_set_sysclk(codec_dai, RT5670_SCLK_S_PLL1,
130 params_rate(params) * 512,
131 SND_SOC_CLOCK_IN);
132 if (ret < 0) {
133 dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret);
134 return ret;
135 }
136 return 0;
137}
138
139static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
140{
141 int ret;
142 struct snd_soc_dai *codec_dai = runtime->codec_dai;
143
144 /* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */
145 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0xF, 4, 24);
146 if (ret < 0) {
147 dev_err(runtime->dev, "can't set codec TDM slot %d\n", ret);
148 return ret;
149 }
150
151 return 0;
152}
153
154static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd,
155 struct snd_pcm_hw_params *params)
156{
157 struct snd_interval *rate = hw_param_interval(params,
158 SNDRV_PCM_HW_PARAM_RATE);
159 struct snd_interval *channels = hw_param_interval(params,
160 SNDRV_PCM_HW_PARAM_CHANNELS);
161
162 /* The DSP will covert the FE rate to 48k, stereo, 24bits */
163 rate->min = rate->max = 48000;
164 channels->min = channels->max = 2;
165
166 /* set SSP2 to 24-bit */
167 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
168 SNDRV_PCM_HW_PARAM_FIRST_MASK],
169 SNDRV_PCM_FORMAT_S24_LE);
170 return 0;
171}
172
173static unsigned int rates_48000[] = {
174 48000,
175};
176
177static struct snd_pcm_hw_constraint_list constraints_48000 = {
178 .count = ARRAY_SIZE(rates_48000),
179 .list = rates_48000,
180};
181
182static int cht_aif1_startup(struct snd_pcm_substream *substream)
183{
184 return snd_pcm_hw_constraint_list(substream->runtime, 0,
185 SNDRV_PCM_HW_PARAM_RATE,
186 &constraints_48000);
187}
188
189static struct snd_soc_ops cht_aif1_ops = {
190 .startup = cht_aif1_startup,
191};
192
193static struct snd_soc_ops cht_be_ssp2_ops = {
194 .hw_params = cht_aif1_hw_params,
195};
196
197static struct snd_soc_dai_link cht_dailink[] = {
198 /* Front End DAI links */
199 [MERR_DPCM_AUDIO] = {
200 .name = "Audio Port",
201 .stream_name = "Audio",
202 .cpu_dai_name = "media-cpu-dai",
203 .codec_dai_name = "snd-soc-dummy-dai",
204 .codec_name = "snd-soc-dummy",
205 .platform_name = "sst-mfld-platform",
206 .ignore_suspend = 1,
207 .dynamic = 1,
208 .dpcm_playback = 1,
209 .dpcm_capture = 1,
210 .ops = &cht_aif1_ops,
211 },
212 [MERR_DPCM_COMPR] = {
213 .name = "Compressed Port",
214 .stream_name = "Compress",
215 .cpu_dai_name = "compress-cpu-dai",
216 .codec_dai_name = "snd-soc-dummy-dai",
217 .codec_name = "snd-soc-dummy",
218 .platform_name = "sst-mfld-platform",
219 },
220
221 /* Back End DAI links */
222 {
223 /* SSP2 - Codec */
224 .name = "SSP2-Codec",
225 .be_id = 1,
226 .cpu_dai_name = "ssp2-port",
227 .platform_name = "sst-mfld-platform",
228 .no_pcm = 1,
229 .codec_dai_name = "rt5670-aif1",
230 .codec_name = "i2c-10EC5670:00",
231 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF
232 | SND_SOC_DAIFMT_CBS_CFS,
233 .init = cht_codec_init,
234 .be_hw_params_fixup = cht_codec_fixup,
235 .ignore_suspend = 1,
236 .dpcm_playback = 1,
237 .dpcm_capture = 1,
238 .ops = &cht_be_ssp2_ops,
239 },
240};
241
242/* SoC card */
243static struct snd_soc_card snd_soc_card_cht = {
244 .name = "cherrytrailcraudio",
245 .dai_link = cht_dailink,
246 .num_links = ARRAY_SIZE(cht_dailink),
247 .dapm_widgets = cht_dapm_widgets,
248 .num_dapm_widgets = ARRAY_SIZE(cht_dapm_widgets),
249 .dapm_routes = cht_audio_map,
250 .num_dapm_routes = ARRAY_SIZE(cht_audio_map),
251 .controls = cht_mc_controls,
252 .num_controls = ARRAY_SIZE(cht_mc_controls),
253};
254
255static int snd_cht_mc_probe(struct platform_device *pdev)
256{
257 int ret_val = 0;
258
259 /* register the soc card */
260 snd_soc_card_cht.dev = &pdev->dev;
261 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cht);
262 if (ret_val) {
263 dev_err(&pdev->dev,
264 "snd_soc_register_card failed %d\n", ret_val);
265 return ret_val;
266 }
267 platform_set_drvdata(pdev, &snd_soc_card_cht);
268 return ret_val;
269}
270
271static struct platform_driver snd_cht_mc_driver = {
272 .driver = {
273 .owner = THIS_MODULE,
274 .name = "cht-bsw-rt5672",
275 .pm = &snd_soc_pm_ops,
276 },
277 .probe = snd_cht_mc_probe,
278};
279
280module_platform_driver(snd_cht_mc_driver);
281
282MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
283MODULE_AUTHOR("Subhransu S. Prusty, Mengdong Lin");
284MODULE_LICENSE("GPL v2");
285MODULE_ALIAS("platform:cht-bsw-rt5672");
diff --git a/sound/soc/intel/haswell.c b/sound/soc/intel/haswell.c
index 3981982674ac..cb8a482b5f30 100644
--- a/sound/soc/intel/haswell.c
+++ b/sound/soc/intel/haswell.c
@@ -109,7 +109,7 @@ static struct snd_soc_dai_link haswell_rt5640_dais[] = {
109 /* Front End DAI links */ 109 /* Front End DAI links */
110 { 110 {
111 .name = "System", 111 .name = "System",
112 .stream_name = "System Playback", 112 .stream_name = "System Playback/Capture",
113 .cpu_dai_name = "System Pin", 113 .cpu_dai_name = "System Pin",
114 .platform_name = "haswell-pcm-audio", 114 .platform_name = "haswell-pcm-audio",
115 .dynamic = 1, 115 .dynamic = 1,
@@ -118,6 +118,7 @@ static struct snd_soc_dai_link haswell_rt5640_dais[] = {
118 .init = haswell_rtd_init, 118 .init = haswell_rtd_init,
119 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 119 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
120 .dpcm_playback = 1, 120 .dpcm_playback = 1,
121 .dpcm_capture = 1,
121 }, 122 },
122 { 123 {
123 .name = "Offload0", 124 .name = "Offload0",
@@ -152,17 +153,6 @@ static struct snd_soc_dai_link haswell_rt5640_dais[] = {
152 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 153 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
153 .dpcm_capture = 1, 154 .dpcm_capture = 1,
154 }, 155 },
155 {
156 .name = "Capture",
157 .stream_name = "Capture",
158 .cpu_dai_name = "Capture Pin",
159 .platform_name = "haswell-pcm-audio",
160 .dynamic = 1,
161 .codec_name = "snd-soc-dummy",
162 .codec_dai_name = "snd-soc-dummy-dai",
163 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
164 .dpcm_capture = 1,
165 },
166 156
167 /* Back End DAI links */ 157 /* Back End DAI links */
168 { 158 {
diff --git a/sound/soc/intel/sst-atom-controls.c b/sound/soc/intel/sst-atom-controls.c
index 7104a34181a9..90aa5c0476f3 100644
--- a/sound/soc/intel/sst-atom-controls.c
+++ b/sound/soc/intel/sst-atom-controls.c
@@ -15,6 +15,9 @@
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 * 17 *
18 * In the dpcm driver modelling when a particular FE/BE/Mixer/Pipe is active
19 * we forward the settings and parameters, rest we keep the values in
20 * driver and forward when DAPM enables them
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */ 22 */
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -81,6 +84,183 @@ static int sst_fill_and_send_cmd(struct sst_data *drv,
81 return ret; 84 return ret;
82} 85}
83 86
87/**
88 * tx map value is a bitfield where each bit represents a FW channel
89 *
90 * 3 2 1 0 # 0 = codec0, 1 = codec1
91 * RLRLRLRL # 3, 4 = reserved
92 *
93 * e.g. slot 0 rx map = 00001100b -> data from slot 0 goes into codec_in1 L,R
94 */
95static u8 sst_ssp_tx_map[SST_MAX_TDM_SLOTS] = {
96 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, /* default rx map */
97};
98
99/**
100 * rx map value is a bitfield where each bit represents a slot
101 *
102 * 76543210 # 0 = slot 0, 1 = slot 1
103 *
104 * e.g. codec1_0 tx map = 00000101b -> data from codec_out1_0 goes into slot 0, 2
105 */
106static u8 sst_ssp_rx_map[SST_MAX_TDM_SLOTS] = {
107 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, /* default tx map */
108};
109
110/**
111 * NOTE: this is invoked with lock held
112 */
113static int sst_send_slot_map(struct sst_data *drv)
114{
115 struct sst_param_sba_ssp_slot_map cmd;
116
117 SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
118 cmd.header.command_id = SBA_SET_SSP_SLOT_MAP;
119 cmd.header.length = sizeof(struct sst_param_sba_ssp_slot_map)
120 - sizeof(struct sst_dsp_header);
121
122 cmd.param_id = SBA_SET_SSP_SLOT_MAP;
123 cmd.param_len = sizeof(cmd.rx_slot_map) + sizeof(cmd.tx_slot_map)
124 + sizeof(cmd.ssp_index);
125 cmd.ssp_index = SSP_CODEC;
126
127 memcpy(cmd.rx_slot_map, &sst_ssp_tx_map[0], sizeof(cmd.rx_slot_map));
128 memcpy(cmd.tx_slot_map, &sst_ssp_rx_map[0], sizeof(cmd.tx_slot_map));
129
130 return sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
131 SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
132 sizeof(cmd.header) + cmd.header.length);
133}
134
135int sst_slot_enum_info(struct snd_kcontrol *kcontrol,
136 struct snd_ctl_elem_info *uinfo)
137{
138 struct sst_enum *e = (struct sst_enum *)kcontrol->private_value;
139
140 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
141 uinfo->count = 1;
142 uinfo->value.enumerated.items = e->max;
143
144 if (uinfo->value.enumerated.item > e->max - 1)
145 uinfo->value.enumerated.item = e->max - 1;
146 strcpy(uinfo->value.enumerated.name,
147 e->texts[uinfo->value.enumerated.item]);
148
149 return 0;
150}
151
152/**
153 * sst_slot_get - get the status of the interleaver/deinterleaver control
154 *
155 * Searches the map where the control status is stored, and gets the
156 * channel/slot which is currently set for this enumerated control. Since it is
157 * an enumerated control, there is only one possible value.
158 */
159static int sst_slot_get(struct snd_kcontrol *kcontrol,
160 struct snd_ctl_elem_value *ucontrol)
161{
162 struct sst_enum *e = (void *)kcontrol->private_value;
163 struct snd_soc_component *c = snd_kcontrol_chip(kcontrol);
164 struct sst_data *drv = snd_soc_component_get_drvdata(c);
165 unsigned int ctl_no = e->reg;
166 unsigned int is_tx = e->tx;
167 unsigned int val, mux;
168 u8 *map = is_tx ? sst_ssp_rx_map : sst_ssp_tx_map;
169
170 mutex_lock(&drv->lock);
171 val = 1 << ctl_no;
172 /* search which slot/channel has this bit set - there should be only one */
173 for (mux = e->max; mux > 0; mux--)
174 if (map[mux - 1] & val)
175 break;
176
177 ucontrol->value.enumerated.item[0] = mux;
178 mutex_unlock(&drv->lock);
179
180 dev_dbg(c->dev, "%s - %s map = %#x\n",
181 is_tx ? "tx channel" : "rx slot",
182 e->texts[mux], mux ? map[mux - 1] : -1);
183 return 0;
184}
185
186/* sst_check_and_send_slot_map - helper for checking power state and sending
187 * slot map cmd
188 *
189 * called with lock held
190 */
191static int sst_check_and_send_slot_map(struct sst_data *drv, struct snd_kcontrol *kcontrol)
192{
193 struct sst_enum *e = (void *)kcontrol->private_value;
194 int ret = 0;
195
196 if (e->w && e->w->power)
197 ret = sst_send_slot_map(drv);
198 else
199 dev_err(&drv->pdev->dev, "Slot control: %s doesn't have DAPM widget!!!\n",
200 kcontrol->id.name);
201 return ret;
202}
203
204/**
205 * sst_slot_put - set the status of interleaver/deinterleaver control
206 *
207 * (de)interleaver controls are defined in opposite sense to be user-friendly
208 *
209 * Instead of the enum value being the value written to the register, it is the
210 * register address; and the kcontrol number (register num) is the value written
211 * to the register. This is so that there can be only one value for each
212 * slot/channel since there is only one control for each slot/channel.
213 *
214 * This means that whenever an enum is set, we need to clear the bit
215 * for that kcontrol_no for all the interleaver OR deinterleaver registers
216 */
217static int sst_slot_put(struct snd_kcontrol *kcontrol,
218 struct snd_ctl_elem_value *ucontrol)
219{
220 struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
221 struct sst_data *drv = snd_soc_component_get_drvdata(c);
222 struct sst_enum *e = (void *)kcontrol->private_value;
223 int i, ret = 0;
224 unsigned int ctl_no = e->reg;
225 unsigned int is_tx = e->tx;
226 unsigned int slot_channel_no;
227 unsigned int val, mux;
228 u8 *map;
229
230 map = is_tx ? sst_ssp_rx_map : sst_ssp_tx_map;
231
232 val = 1 << ctl_no;
233 mux = ucontrol->value.enumerated.item[0];
234 if (mux > e->max - 1)
235 return -EINVAL;
236
237 mutex_lock(&drv->lock);
238 /* first clear all registers of this bit */
239 for (i = 0; i < e->max; i++)
240 map[i] &= ~val;
241
242 if (mux == 0) {
243 /* kctl set to 'none' and we reset the bits so send IPC */
244 ret = sst_check_and_send_slot_map(drv, kcontrol);
245
246 mutex_unlock(&drv->lock);
247 return ret;
248 }
249
250 /* offset by one to take "None" into account */
251 slot_channel_no = mux - 1;
252 map[slot_channel_no] |= val;
253
254 dev_dbg(c->dev, "%s %s map = %#x\n",
255 is_tx ? "tx channel" : "rx slot",
256 e->texts[mux], map[slot_channel_no]);
257
258 ret = sst_check_and_send_slot_map(drv, kcontrol);
259
260 mutex_unlock(&drv->lock);
261 return ret;
262}
263
84static int sst_send_algo_cmd(struct sst_data *drv, 264static int sst_send_algo_cmd(struct sst_data *drv,
85 struct sst_algo_control *bc) 265 struct sst_algo_control *bc)
86{ 266{
@@ -104,6 +284,34 @@ static int sst_send_algo_cmd(struct sst_data *drv,
104 return ret; 284 return ret;
105} 285}
106 286
287/**
288 * sst_find_and_send_pipe_algo - send all the algo parameters for a pipe
289 *
290 * The algos which are in each pipeline are sent to the firmware one by one
291 *
292 * Called with lock held
293 */
294static int sst_find_and_send_pipe_algo(struct sst_data *drv,
295 const char *pipe, struct sst_ids *ids)
296{
297 int ret = 0;
298 struct sst_algo_control *bc;
299 struct sst_module *algo = NULL;
300
301 dev_dbg(&drv->pdev->dev, "Enter: widget=%s\n", pipe);
302
303 list_for_each_entry(algo, &ids->algo_list, node) {
304 bc = (void *)algo->kctl->private_value;
305
306 dev_dbg(&drv->pdev->dev, "Found algo control name=%s pipe=%s\n",
307 algo->kctl->id.name, pipe);
308 ret = sst_send_algo_cmd(drv, bc);
309 if (ret)
310 return ret;
311 }
312 return ret;
313}
314
107static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol, 315static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
108 struct snd_ctl_elem_info *uinfo) 316 struct snd_ctl_elem_info *uinfo)
109{ 317{
@@ -162,6 +370,743 @@ static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
162 return ret; 370 return ret;
163} 371}
164 372
373static int sst_gain_ctl_info(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_info *uinfo)
375{
376 struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
377
378 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
379 uinfo->count = mc->stereo ? 2 : 1;
380 uinfo->value.integer.min = mc->min;
381 uinfo->value.integer.max = mc->max;
382
383 return 0;
384}
385
386/**
387 * sst_send_gain_cmd - send the gain algorithm IPC to the FW
388 * @gv: the stored value of gain (also contains rampduration)
389 * @mute: flag that indicates whether this was called from the
390 * digital_mute callback or directly. If called from the
391 * digital_mute callback, module will be muted/unmuted based on this
392 * flag. The flag is always 0 if called directly.
393 *
394 * Called with sst_data.lock held
395 *
396 * The user-set gain value is sent only if the user-controllable 'mute' control
397 * is OFF (indicated by gv->mute). Otherwise, the mute value (MIN value) is
398 * sent.
399 */
400static int sst_send_gain_cmd(struct sst_data *drv, struct sst_gain_value *gv,
401 u16 task_id, u16 loc_id, u16 module_id, int mute)
402{
403 struct sst_cmd_set_gain_dual cmd;
404
405 dev_dbg(&drv->pdev->dev, "Enter\n");
406
407 cmd.header.command_id = MMX_SET_GAIN;
408 SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
409 cmd.gain_cell_num = 1;
410
411 if (mute || gv->mute) {
412 cmd.cell_gains[0].cell_gain_left = SST_GAIN_MIN_VALUE;
413 cmd.cell_gains[0].cell_gain_right = SST_GAIN_MIN_VALUE;
414 } else {
415 cmd.cell_gains[0].cell_gain_left = gv->l_gain;
416 cmd.cell_gains[0].cell_gain_right = gv->r_gain;
417 }
418
419 SST_FILL_DESTINATION(2, cmd.cell_gains[0].dest,
420 loc_id, module_id);
421 cmd.cell_gains[0].gain_time_constant = gv->ramp_duration;
422
423 cmd.header.length = sizeof(struct sst_cmd_set_gain_dual)
424 - sizeof(struct sst_dsp_header);
425
426 /* we are with lock held, so call the unlocked api to send */
427 return sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
428 SST_FLAG_BLOCKED, task_id, 0, &cmd,
429 sizeof(cmd.header) + cmd.header.length);
430}
431
432static int sst_gain_get(struct snd_kcontrol *kcontrol,
433 struct snd_ctl_elem_value *ucontrol)
434{
435 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
436 struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
437 struct sst_gain_value *gv = mc->gain_val;
438
439 switch (mc->type) {
440 case SST_GAIN_TLV:
441 ucontrol->value.integer.value[0] = gv->l_gain;
442 ucontrol->value.integer.value[1] = gv->r_gain;
443 break;
444
445 case SST_GAIN_MUTE:
446 ucontrol->value.integer.value[0] = gv->mute ? 1 : 0;
447 break;
448
449 case SST_GAIN_RAMP_DURATION:
450 ucontrol->value.integer.value[0] = gv->ramp_duration;
451 break;
452
453 default:
454 dev_err(component->dev, "Invalid Input- gain type:%d\n",
455 mc->type);
456 return -EINVAL;
457 }
458
459 return 0;
460}
461
462static int sst_gain_put(struct snd_kcontrol *kcontrol,
463 struct snd_ctl_elem_value *ucontrol)
464{
465 int ret = 0;
466 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
467 struct sst_data *drv = snd_soc_component_get_drvdata(cmpnt);
468 struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
469 struct sst_gain_value *gv = mc->gain_val;
470
471 mutex_lock(&drv->lock);
472
473 switch (mc->type) {
474 case SST_GAIN_TLV:
475 gv->l_gain = ucontrol->value.integer.value[0];
476 gv->r_gain = ucontrol->value.integer.value[1];
477 dev_dbg(cmpnt->dev, "%s: Volume %d, %d\n",
478 mc->pname, gv->l_gain, gv->r_gain);
479 break;
480
481 case SST_GAIN_MUTE:
482 gv->mute = !!ucontrol->value.integer.value[0];
483 dev_dbg(cmpnt->dev, "%s: Mute %d\n", mc->pname, gv->mute);
484 break;
485
486 case SST_GAIN_RAMP_DURATION:
487 gv->ramp_duration = ucontrol->value.integer.value[0];
488 dev_dbg(cmpnt->dev, "%s: Ramp Delay%d\n",
489 mc->pname, gv->ramp_duration);
490 break;
491
492 default:
493 mutex_unlock(&drv->lock);
494 dev_err(cmpnt->dev, "Invalid Input- gain type:%d\n",
495 mc->type);
496 return -EINVAL;
497 }
498
499 if (mc->w && mc->w->power)
500 ret = sst_send_gain_cmd(drv, gv, mc->task_id,
501 mc->pipe_id | mc->instance_id, mc->module_id, 0);
502 mutex_unlock(&drv->lock);
503
504 return ret;
505}
506
507static int sst_set_pipe_gain(struct sst_ids *ids,
508 struct sst_data *drv, int mute);
509
510static int sst_send_pipe_module_params(struct snd_soc_dapm_widget *w,
511 struct snd_kcontrol *kcontrol)
512{
513 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
514 struct sst_data *drv = snd_soc_component_get_drvdata(c);
515 struct sst_ids *ids = w->priv;
516
517 mutex_lock(&drv->lock);
518 sst_find_and_send_pipe_algo(drv, w->name, ids);
519 sst_set_pipe_gain(ids, drv, 0);
520 mutex_unlock(&drv->lock);
521
522 return 0;
523}
524
525static int sst_generic_modules_event(struct snd_soc_dapm_widget *w,
526 struct snd_kcontrol *k, int event)
527{
528 if (SND_SOC_DAPM_EVENT_ON(event))
529 return sst_send_pipe_module_params(w, k);
530 return 0;
531}
532
533static const DECLARE_TLV_DB_SCALE(sst_gain_tlv_common, SST_GAIN_MIN_VALUE * 10, 10, 0);
534
535/* Look up table to convert MIXER SW bit regs to SWM inputs */
536static const uint swm_mixer_input_ids[SST_SWM_INPUT_COUNT] = {
537 [SST_IP_CODEC0] = SST_SWM_IN_CODEC0,
538 [SST_IP_CODEC1] = SST_SWM_IN_CODEC1,
539 [SST_IP_LOOP0] = SST_SWM_IN_SPROT_LOOP,
540 [SST_IP_LOOP1] = SST_SWM_IN_MEDIA_LOOP1,
541 [SST_IP_LOOP2] = SST_SWM_IN_MEDIA_LOOP2,
542 [SST_IP_PCM0] = SST_SWM_IN_PCM0,
543 [SST_IP_PCM1] = SST_SWM_IN_PCM1,
544 [SST_IP_MEDIA0] = SST_SWM_IN_MEDIA0,
545 [SST_IP_MEDIA1] = SST_SWM_IN_MEDIA1,
546 [SST_IP_MEDIA2] = SST_SWM_IN_MEDIA2,
547 [SST_IP_MEDIA3] = SST_SWM_IN_MEDIA3,
548};
549
550/**
551 * fill_swm_input - fill in the SWM input ids given the register
552 *
553 * The register value is a bit-field inicated which mixer inputs are ON. Use the
554 * lookup table to get the input-id and fill it in the structure.
555 */
556static int fill_swm_input(struct snd_soc_component *cmpnt,
557 struct swm_input_ids *swm_input, unsigned int reg)
558{
559 uint i, is_set, nb_inputs = 0;
560 u16 input_loc_id;
561
562 dev_dbg(cmpnt->dev, "reg: %#x\n", reg);
563 for (i = 0; i < SST_SWM_INPUT_COUNT; i++) {
564 is_set = reg & BIT(i);
565 if (!is_set)
566 continue;
567
568 input_loc_id = swm_mixer_input_ids[i];
569 SST_FILL_DESTINATION(2, swm_input->input_id,
570 input_loc_id, SST_DEFAULT_MODULE_ID);
571 nb_inputs++;
572 swm_input++;
573 dev_dbg(cmpnt->dev, "input id: %#x, nb_inputs: %d\n",
574 input_loc_id, nb_inputs);
575
576 if (nb_inputs == SST_CMD_SWM_MAX_INPUTS) {
577 dev_warn(cmpnt->dev, "SET_SWM cmd max inputs reached");
578 break;
579 }
580 }
581 return nb_inputs;
582}
583
584
585/**
586 * called with lock held
587 */
588static int sst_set_pipe_gain(struct sst_ids *ids,
589 struct sst_data *drv, int mute)
590{
591 int ret = 0;
592 struct sst_gain_mixer_control *mc;
593 struct sst_gain_value *gv;
594 struct sst_module *gain = NULL;
595
596 list_for_each_entry(gain, &ids->gain_list, node) {
597 struct snd_kcontrol *kctl = gain->kctl;
598
599 dev_dbg(&drv->pdev->dev, "control name=%s\n", kctl->id.name);
600 mc = (void *)kctl->private_value;
601 gv = mc->gain_val;
602
603 ret = sst_send_gain_cmd(drv, gv, mc->task_id,
604 mc->pipe_id | mc->instance_id, mc->module_id, mute);
605 if (ret)
606 return ret;
607 }
608 return ret;
609}
610
611static int sst_swm_mixer_event(struct snd_soc_dapm_widget *w,
612 struct snd_kcontrol *k, int event)
613{
614 struct sst_cmd_set_swm cmd;
615 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
616 struct sst_data *drv = snd_soc_component_get_drvdata(cmpnt);
617 struct sst_ids *ids = w->priv;
618 bool set_mixer = false;
619 struct soc_mixer_control *mc;
620 int val = 0;
621 int i = 0;
622
623 dev_dbg(cmpnt->dev, "widget = %s\n", w->name);
624 /*
625 * Identify which mixer input is on and send the bitmap of the
626 * inputs as an IPC to the DSP.
627 */
628 for (i = 0; i < w->num_kcontrols; i++) {
629 if (dapm_kcontrol_get_value(w->kcontrols[i])) {
630 mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
631 val |= 1 << mc->shift;
632 }
633 }
634 dev_dbg(cmpnt->dev, "val = %#x\n", val);
635
636 switch (event) {
637 case SND_SOC_DAPM_PRE_PMU:
638 case SND_SOC_DAPM_POST_PMD:
639 set_mixer = true;
640 break;
641 case SND_SOC_DAPM_POST_REG:
642 if (w->power)
643 set_mixer = true;
644 break;
645 default:
646 set_mixer = false;
647 }
648
649 if (set_mixer == false)
650 return 0;
651
652 if (SND_SOC_DAPM_EVENT_ON(event) ||
653 event == SND_SOC_DAPM_POST_REG)
654 cmd.switch_state = SST_SWM_ON;
655 else
656 cmd.switch_state = SST_SWM_OFF;
657
658 SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
659 /* MMX_SET_SWM == SBA_SET_SWM */
660 cmd.header.command_id = SBA_SET_SWM;
661
662 SST_FILL_DESTINATION(2, cmd.output_id,
663 ids->location_id, SST_DEFAULT_MODULE_ID);
664 cmd.nb_inputs = fill_swm_input(cmpnt, &cmd.input[0], val);
665 cmd.header.length = offsetof(struct sst_cmd_set_swm, input)
666 - sizeof(struct sst_dsp_header)
667 + (cmd.nb_inputs * sizeof(cmd.input[0]));
668
669 return sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
670 ids->task_id, 0, &cmd,
671 sizeof(cmd.header) + cmd.header.length);
672}
673
674/* SBA mixers - 16 inputs */
675#define SST_SBA_DECLARE_MIX_CONTROLS(kctl_name) \
676 static const struct snd_kcontrol_new kctl_name[] = { \
677 SOC_DAPM_SINGLE("codec_in0 Switch", SND_SOC_NOPM, SST_IP_CODEC0, 1, 0), \
678 SOC_DAPM_SINGLE("codec_in1 Switch", SND_SOC_NOPM, SST_IP_CODEC1, 1, 0), \
679 SOC_DAPM_SINGLE("sprot_loop_in Switch", SND_SOC_NOPM, SST_IP_LOOP0, 1, 0), \
680 SOC_DAPM_SINGLE("media_loop1_in Switch", SND_SOC_NOPM, SST_IP_LOOP1, 1, 0), \
681 SOC_DAPM_SINGLE("media_loop2_in Switch", SND_SOC_NOPM, SST_IP_LOOP2, 1, 0), \
682 SOC_DAPM_SINGLE("pcm0_in Switch", SND_SOC_NOPM, SST_IP_PCM0, 1, 0), \
683 SOC_DAPM_SINGLE("pcm1_in Switch", SND_SOC_NOPM, SST_IP_PCM1, 1, 0), \
684 }
685
686#define SST_SBA_MIXER_GRAPH_MAP(mix_name) \
687 { mix_name, "codec_in0 Switch", "codec_in0" }, \
688 { mix_name, "codec_in1 Switch", "codec_in1" }, \
689 { mix_name, "sprot_loop_in Switch", "sprot_loop_in" }, \
690 { mix_name, "media_loop1_in Switch", "media_loop1_in" }, \
691 { mix_name, "media_loop2_in Switch", "media_loop2_in" }, \
692 { mix_name, "pcm0_in Switch", "pcm0_in" }, \
693 { mix_name, "pcm1_in Switch", "pcm1_in" }
694
695#define SST_MMX_DECLARE_MIX_CONTROLS(kctl_name) \
696 static const struct snd_kcontrol_new kctl_name[] = { \
697 SOC_DAPM_SINGLE("media0_in Switch", SND_SOC_NOPM, SST_IP_MEDIA0, 1, 0), \
698 SOC_DAPM_SINGLE("media1_in Switch", SND_SOC_NOPM, SST_IP_MEDIA1, 1, 0), \
699 SOC_DAPM_SINGLE("media2_in Switch", SND_SOC_NOPM, SST_IP_MEDIA2, 1, 0), \
700 SOC_DAPM_SINGLE("media3_in Switch", SND_SOC_NOPM, SST_IP_MEDIA3, 1, 0), \
701 }
702
703SST_MMX_DECLARE_MIX_CONTROLS(sst_mix_media0_controls);
704SST_MMX_DECLARE_MIX_CONTROLS(sst_mix_media1_controls);
705
706/* 18 SBA mixers */
707SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm0_controls);
708SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm1_controls);
709SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm2_controls);
710SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_sprot_l0_controls);
711SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_media_l1_controls);
712SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_media_l2_controls);
713SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_voip_controls);
714SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_codec0_controls);
715SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_codec1_controls);
716
717/*
718 * sst_handle_vb_timer - Start/Stop the DSP scheduler
719 *
720 * The DSP expects first cmd to be SBA_VB_START, so at first startup send
721 * that.
722 * DSP expects last cmd to be SBA_VB_IDLE, so at last shutdown send that.
723 *
724 * Do refcount internally so that we send command only at first start
725 * and last end. Since SST driver does its own ref count, invoke sst's
726 * power ops always!
727 */
728int sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable)
729{
730 int ret = 0;
731 struct sst_cmd_generic cmd;
732 struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
733 static int timer_usage;
734
735 if (enable)
736 cmd.header.command_id = SBA_VB_START;
737 else
738 cmd.header.command_id = SBA_IDLE;
739 dev_dbg(dai->dev, "enable=%u, usage=%d\n", enable, timer_usage);
740
741 SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
742 cmd.header.length = 0;
743
744 if (enable) {
745 ret = sst->ops->power(sst->dev, true);
746 if (ret < 0)
747 return ret;
748 }
749
750 mutex_lock(&drv->lock);
751 if (enable)
752 timer_usage++;
753 else
754 timer_usage--;
755
756 /*
757 * Send the command only if this call is the first enable or last
758 * disable
759 */
760 if ((enable && (timer_usage == 1)) ||
761 (!enable && (timer_usage == 0))) {
762 ret = sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_CMD,
763 SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
764 sizeof(cmd.header) + cmd.header.length);
765 if (ret && enable) {
766 timer_usage--;
767 enable = false;
768 }
769 }
770 mutex_unlock(&drv->lock);
771
772 if (!enable)
773 sst->ops->power(sst->dev, false);
774 return ret;
775}
776
777/**
778 * sst_ssp_config - contains SSP configuration for media UC
779 */
780static const struct sst_ssp_config sst_ssp_configs = {
781 .ssp_id = SSP_CODEC,
782 .bits_per_slot = 24,
783 .slots = 4,
784 .ssp_mode = SSP_MODE_MASTER,
785 .pcm_mode = SSP_PCM_MODE_NETWORK,
786 .duplex = SSP_DUPLEX,
787 .ssp_protocol = SSP_MODE_PCM,
788 .fs_width = 1,
789 .fs_frequency = SSP_FS_48_KHZ,
790 .active_slot_map = 0xF,
791 .start_delay = 0,
792};
793
794int send_ssp_cmd(struct snd_soc_dai *dai, const char *id, bool enable)
795{
796 struct sst_cmd_sba_hw_set_ssp cmd;
797 struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
798 const struct sst_ssp_config *config;
799
800 dev_info(dai->dev, "Enter: enable=%d port_name=%s\n", enable, id);
801
802 SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
803 cmd.header.command_id = SBA_HW_SET_SSP;
804 cmd.header.length = sizeof(struct sst_cmd_sba_hw_set_ssp)
805 - sizeof(struct sst_dsp_header);
806
807 config = &sst_ssp_configs;
808 dev_dbg(dai->dev, "ssp_id: %u\n", config->ssp_id);
809
810 if (enable)
811 cmd.switch_state = SST_SWITCH_ON;
812 else
813 cmd.switch_state = SST_SWITCH_OFF;
814
815 cmd.selection = config->ssp_id;
816 cmd.nb_bits_per_slots = config->bits_per_slot;
817 cmd.nb_slots = config->slots;
818 cmd.mode = config->ssp_mode | (config->pcm_mode << 1);
819 cmd.duplex = config->duplex;
820 cmd.active_tx_slot_map = config->active_slot_map;
821 cmd.active_rx_slot_map = config->active_slot_map;
822 cmd.frame_sync_frequency = config->fs_frequency;
823 cmd.frame_sync_polarity = SSP_FS_ACTIVE_HIGH;
824 cmd.data_polarity = 1;
825 cmd.frame_sync_width = config->fs_width;
826 cmd.ssp_protocol = config->ssp_protocol;
827 cmd.start_delay = config->start_delay;
828 cmd.reserved1 = cmd.reserved2 = 0xFF;
829
830 return sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
831 SST_TASK_SBA, 0, &cmd,
832 sizeof(cmd.header) + cmd.header.length);
833}
834
835static int sst_set_be_modules(struct snd_soc_dapm_widget *w,
836 struct snd_kcontrol *k, int event)
837{
838 int ret = 0;
839 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
840 struct sst_data *drv = snd_soc_component_get_drvdata(c);
841
842 dev_dbg(c->dev, "Enter: widget=%s\n", w->name);
843
844 if (SND_SOC_DAPM_EVENT_ON(event)) {
845 ret = sst_send_slot_map(drv);
846 if (ret)
847 return ret;
848 ret = sst_send_pipe_module_params(w, k);
849 }
850 return ret;
851}
852
853static int sst_set_media_path(struct snd_soc_dapm_widget *w,
854 struct snd_kcontrol *k, int event)
855{
856 int ret = 0;
857 struct sst_cmd_set_media_path cmd;
858 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
859 struct sst_data *drv = snd_soc_component_get_drvdata(c);
860 struct sst_ids *ids = w->priv;
861
862 dev_dbg(c->dev, "widget=%s\n", w->name);
863 dev_dbg(c->dev, "task=%u, location=%#x\n",
864 ids->task_id, ids->location_id);
865
866 if (SND_SOC_DAPM_EVENT_ON(event))
867 cmd.switch_state = SST_PATH_ON;
868 else
869 cmd.switch_state = SST_PATH_OFF;
870
871 SST_FILL_DESTINATION(2, cmd.header.dst,
872 ids->location_id, SST_DEFAULT_MODULE_ID);
873
874 /* MMX_SET_MEDIA_PATH == SBA_SET_MEDIA_PATH */
875 cmd.header.command_id = MMX_SET_MEDIA_PATH;
876 cmd.header.length = sizeof(struct sst_cmd_set_media_path)
877 - sizeof(struct sst_dsp_header);
878
879 ret = sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
880 ids->task_id, 0, &cmd,
881 sizeof(cmd.header) + cmd.header.length);
882 if (ret)
883 return ret;
884
885 if (SND_SOC_DAPM_EVENT_ON(event))
886 ret = sst_send_pipe_module_params(w, k);
887 return ret;
888}
889
890static int sst_set_media_loop(struct snd_soc_dapm_widget *w,
891 struct snd_kcontrol *k, int event)
892{
893 int ret = 0;
894 struct sst_cmd_sba_set_media_loop_map cmd;
895 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
896 struct sst_data *drv = snd_soc_component_get_drvdata(c);
897 struct sst_ids *ids = w->priv;
898
899 dev_dbg(c->dev, "Enter:widget=%s\n", w->name);
900 if (SND_SOC_DAPM_EVENT_ON(event))
901 cmd.switch_state = SST_SWITCH_ON;
902 else
903 cmd.switch_state = SST_SWITCH_OFF;
904
905 SST_FILL_DESTINATION(2, cmd.header.dst,
906 ids->location_id, SST_DEFAULT_MODULE_ID);
907
908 cmd.header.command_id = SBA_SET_MEDIA_LOOP_MAP;
909 cmd.header.length = sizeof(struct sst_cmd_sba_set_media_loop_map)
910 - sizeof(struct sst_dsp_header);
911 cmd.param.part.cfg.rate = 2; /* 48khz */
912
913 cmd.param.part.cfg.format = ids->format; /* stereo/Mono */
914 cmd.param.part.cfg.s_length = 1; /* 24bit left justified */
915 cmd.map = 0; /* Algo sequence: Gain - DRP - FIR - IIR */
916
917 ret = sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
918 SST_TASK_SBA, 0, &cmd,
919 sizeof(cmd.header) + cmd.header.length);
920 if (ret)
921 return ret;
922
923 if (SND_SOC_DAPM_EVENT_ON(event))
924 ret = sst_send_pipe_module_params(w, k);
925 return ret;
926}
927
928static const struct snd_soc_dapm_widget sst_dapm_widgets[] = {
929 SST_AIF_IN("codec_in0", sst_set_be_modules),
930 SST_AIF_IN("codec_in1", sst_set_be_modules),
931 SST_AIF_OUT("codec_out0", sst_set_be_modules),
932 SST_AIF_OUT("codec_out1", sst_set_be_modules),
933
934 /* Media Paths */
935 /* MediaX IN paths are set via ALLOC, so no SET_MEDIA_PATH command */
936 SST_PATH_INPUT("media0_in", SST_TASK_MMX, SST_SWM_IN_MEDIA0, sst_generic_modules_event),
937 SST_PATH_INPUT("media1_in", SST_TASK_MMX, SST_SWM_IN_MEDIA1, NULL),
938 SST_PATH_INPUT("media2_in", SST_TASK_MMX, SST_SWM_IN_MEDIA2, sst_set_media_path),
939 SST_PATH_INPUT("media3_in", SST_TASK_MMX, SST_SWM_IN_MEDIA3, NULL),
940 SST_PATH_OUTPUT("media0_out", SST_TASK_MMX, SST_SWM_OUT_MEDIA0, sst_set_media_path),
941 SST_PATH_OUTPUT("media1_out", SST_TASK_MMX, SST_SWM_OUT_MEDIA1, sst_set_media_path),
942
943 /* SBA PCM Paths */
944 SST_PATH_INPUT("pcm0_in", SST_TASK_SBA, SST_SWM_IN_PCM0, sst_set_media_path),
945 SST_PATH_INPUT("pcm1_in", SST_TASK_SBA, SST_SWM_IN_PCM1, sst_set_media_path),
946 SST_PATH_OUTPUT("pcm0_out", SST_TASK_SBA, SST_SWM_OUT_PCM0, sst_set_media_path),
947 SST_PATH_OUTPUT("pcm1_out", SST_TASK_SBA, SST_SWM_OUT_PCM1, sst_set_media_path),
948 SST_PATH_OUTPUT("pcm2_out", SST_TASK_SBA, SST_SWM_OUT_PCM2, sst_set_media_path),
949
950 /* SBA Loops */
951 SST_PATH_INPUT("sprot_loop_in", SST_TASK_SBA, SST_SWM_IN_SPROT_LOOP, NULL),
952 SST_PATH_INPUT("media_loop1_in", SST_TASK_SBA, SST_SWM_IN_MEDIA_LOOP1, NULL),
953 SST_PATH_INPUT("media_loop2_in", SST_TASK_SBA, SST_SWM_IN_MEDIA_LOOP2, NULL),
954 SST_PATH_MEDIA_LOOP_OUTPUT("sprot_loop_out", SST_TASK_SBA, SST_SWM_OUT_SPROT_LOOP, SST_FMT_MONO, sst_set_media_loop),
955 SST_PATH_MEDIA_LOOP_OUTPUT("media_loop1_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP1, SST_FMT_MONO, sst_set_media_loop),
956 SST_PATH_MEDIA_LOOP_OUTPUT("media_loop2_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2, SST_FMT_STEREO, sst_set_media_loop),
957
958 /* Media Mixers */
959 SST_SWM_MIXER("media0_out mix 0", SND_SOC_NOPM, SST_TASK_MMX, SST_SWM_OUT_MEDIA0,
960 sst_mix_media0_controls, sst_swm_mixer_event),
961 SST_SWM_MIXER("media1_out mix 0", SND_SOC_NOPM, SST_TASK_MMX, SST_SWM_OUT_MEDIA1,
962 sst_mix_media1_controls, sst_swm_mixer_event),
963
964 /* SBA PCM mixers */
965 SST_SWM_MIXER("pcm0_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM0,
966 sst_mix_pcm0_controls, sst_swm_mixer_event),
967 SST_SWM_MIXER("pcm1_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM1,
968 sst_mix_pcm1_controls, sst_swm_mixer_event),
969 SST_SWM_MIXER("pcm2_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM2,
970 sst_mix_pcm2_controls, sst_swm_mixer_event),
971
972 /* SBA Loop mixers */
973 SST_SWM_MIXER("sprot_loop_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_SPROT_LOOP,
974 sst_mix_sprot_l0_controls, sst_swm_mixer_event),
975 SST_SWM_MIXER("media_loop1_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP1,
976 sst_mix_media_l1_controls, sst_swm_mixer_event),
977 SST_SWM_MIXER("media_loop2_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2,
978 sst_mix_media_l2_controls, sst_swm_mixer_event),
979
980 /* SBA Backend mixers */
981 SST_SWM_MIXER("codec_out0 mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_CODEC0,
982 sst_mix_codec0_controls, sst_swm_mixer_event),
983 SST_SWM_MIXER("codec_out1 mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_CODEC1,
984 sst_mix_codec1_controls, sst_swm_mixer_event),
985};
986
987static const struct snd_soc_dapm_route intercon[] = {
988 {"media0_in", NULL, "Compress Playback"},
989 {"media1_in", NULL, "Headset Playback"},
990 {"media2_in", NULL, "pcm0_out"},
991
992 {"media0_out mix 0", "media0_in Switch", "media0_in"},
993 {"media0_out mix 0", "media1_in Switch", "media1_in"},
994 {"media0_out mix 0", "media2_in Switch", "media2_in"},
995 {"media0_out mix 0", "media3_in Switch", "media3_in"},
996 {"media1_out mix 0", "media0_in Switch", "media0_in"},
997 {"media1_out mix 0", "media1_in Switch", "media1_in"},
998 {"media1_out mix 0", "media2_in Switch", "media2_in"},
999 {"media1_out mix 0", "media3_in Switch", "media3_in"},
1000
1001 {"media0_out", NULL, "media0_out mix 0"},
1002 {"media1_out", NULL, "media1_out mix 0"},
1003 {"pcm0_in", NULL, "media0_out"},
1004 {"pcm1_in", NULL, "media1_out"},
1005
1006 {"Headset Capture", NULL, "pcm1_out"},
1007 {"Headset Capture", NULL, "pcm2_out"},
1008 {"pcm0_out", NULL, "pcm0_out mix 0"},
1009 SST_SBA_MIXER_GRAPH_MAP("pcm0_out mix 0"),
1010 {"pcm1_out", NULL, "pcm1_out mix 0"},
1011 SST_SBA_MIXER_GRAPH_MAP("pcm1_out mix 0"),
1012 {"pcm2_out", NULL, "pcm2_out mix 0"},
1013 SST_SBA_MIXER_GRAPH_MAP("pcm2_out mix 0"),
1014
1015 {"media_loop1_in", NULL, "media_loop1_out"},
1016 {"media_loop1_out", NULL, "media_loop1_out mix 0"},
1017 SST_SBA_MIXER_GRAPH_MAP("media_loop1_out mix 0"),
1018 {"media_loop2_in", NULL, "media_loop2_out"},
1019 {"media_loop2_out", NULL, "media_loop2_out mix 0"},
1020 SST_SBA_MIXER_GRAPH_MAP("media_loop2_out mix 0"),
1021 {"sprot_loop_in", NULL, "sprot_loop_out"},
1022 {"sprot_loop_out", NULL, "sprot_loop_out mix 0"},
1023 SST_SBA_MIXER_GRAPH_MAP("sprot_loop_out mix 0"),
1024
1025 {"codec_out0", NULL, "codec_out0 mix 0"},
1026 SST_SBA_MIXER_GRAPH_MAP("codec_out0 mix 0"),
1027 {"codec_out1", NULL, "codec_out1 mix 0"},
1028 SST_SBA_MIXER_GRAPH_MAP("codec_out1 mix 0"),
1029
1030};
1031static const char * const slot_names[] = {
1032 "none",
1033 "slot 0", "slot 1", "slot 2", "slot 3",
1034 "slot 4", "slot 5", "slot 6", "slot 7", /* not supported by FW */
1035};
1036
1037static const char * const channel_names[] = {
1038 "none",
1039 "codec_out0_0", "codec_out0_1", "codec_out1_0", "codec_out1_1",
1040 "codec_out2_0", "codec_out2_1", "codec_out3_0", "codec_out3_1", /* not supported by FW */
1041};
1042
1043#define SST_INTERLEAVER(xpname, slot_name, slotno) \
1044 SST_SSP_SLOT_CTL(xpname, "tx interleaver", slot_name, slotno, true, \
1045 channel_names, sst_slot_get, sst_slot_put)
1046
1047#define SST_DEINTERLEAVER(xpname, channel_name, channel_no) \
1048 SST_SSP_SLOT_CTL(xpname, "rx deinterleaver", channel_name, channel_no, false, \
1049 slot_names, sst_slot_get, sst_slot_put)
1050
1051static const struct snd_kcontrol_new sst_slot_controls[] = {
1052 SST_INTERLEAVER("codec_out", "slot 0", 0),
1053 SST_INTERLEAVER("codec_out", "slot 1", 1),
1054 SST_INTERLEAVER("codec_out", "slot 2", 2),
1055 SST_INTERLEAVER("codec_out", "slot 3", 3),
1056 SST_DEINTERLEAVER("codec_in", "codec_in0_0", 0),
1057 SST_DEINTERLEAVER("codec_in", "codec_in0_1", 1),
1058 SST_DEINTERLEAVER("codec_in", "codec_in1_0", 2),
1059 SST_DEINTERLEAVER("codec_in", "codec_in1_1", 3),
1060};
1061
1062/* Gain helper with min/max set */
1063#define SST_GAIN(name, path_id, task_id, instance, gain_var) \
1064 SST_GAIN_KCONTROLS(name, "Gain", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE, \
1065 SST_GAIN_TC_MIN, SST_GAIN_TC_MAX, \
1066 sst_gain_get, sst_gain_put, \
1067 SST_MODULE_ID_GAIN_CELL, path_id, instance, task_id, \
1068 sst_gain_tlv_common, gain_var)
1069
1070#define SST_VOLUME(name, path_id, task_id, instance, gain_var) \
1071 SST_GAIN_KCONTROLS(name, "Volume", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE, \
1072 SST_GAIN_TC_MIN, SST_GAIN_TC_MAX, \
1073 sst_gain_get, sst_gain_put, \
1074 SST_MODULE_ID_VOLUME, path_id, instance, task_id, \
1075 sst_gain_tlv_common, gain_var)
1076
1077static struct sst_gain_value sst_gains[];
1078
1079static const struct snd_kcontrol_new sst_gain_controls[] = {
1080 SST_GAIN("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[0]),
1081 SST_GAIN("media1_in", SST_PATH_INDEX_MEDIA1_IN, SST_TASK_MMX, 0, &sst_gains[1]),
1082 SST_GAIN("media2_in", SST_PATH_INDEX_MEDIA2_IN, SST_TASK_MMX, 0, &sst_gains[2]),
1083 SST_GAIN("media3_in", SST_PATH_INDEX_MEDIA3_IN, SST_TASK_MMX, 0, &sst_gains[3]),
1084
1085 SST_GAIN("pcm0_in", SST_PATH_INDEX_PCM0_IN, SST_TASK_SBA, 0, &sst_gains[4]),
1086 SST_GAIN("pcm1_in", SST_PATH_INDEX_PCM1_IN, SST_TASK_SBA, 0, &sst_gains[5]),
1087 SST_GAIN("pcm1_out", SST_PATH_INDEX_PCM1_OUT, SST_TASK_SBA, 0, &sst_gains[6]),
1088 SST_GAIN("pcm2_out", SST_PATH_INDEX_PCM2_OUT, SST_TASK_SBA, 0, &sst_gains[7]),
1089
1090 SST_GAIN("codec_in0", SST_PATH_INDEX_CODEC_IN0, SST_TASK_SBA, 0, &sst_gains[8]),
1091 SST_GAIN("codec_in1", SST_PATH_INDEX_CODEC_IN1, SST_TASK_SBA, 0, &sst_gains[9]),
1092 SST_GAIN("codec_out0", SST_PATH_INDEX_CODEC_OUT0, SST_TASK_SBA, 0, &sst_gains[10]),
1093 SST_GAIN("codec_out1", SST_PATH_INDEX_CODEC_OUT1, SST_TASK_SBA, 0, &sst_gains[11]),
1094 SST_GAIN("media_loop1_out", SST_PATH_INDEX_MEDIA_LOOP1_OUT, SST_TASK_SBA, 0, &sst_gains[12]),
1095 SST_GAIN("media_loop2_out", SST_PATH_INDEX_MEDIA_LOOP2_OUT, SST_TASK_SBA, 0, &sst_gains[13]),
1096 SST_GAIN("sprot_loop_out", SST_PATH_INDEX_SPROT_LOOP_OUT, SST_TASK_SBA, 0, &sst_gains[14]),
1097 SST_VOLUME("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[15]),
1098};
1099
1100#define SST_GAIN_NUM_CONTROLS 3
1101/* the SST_GAIN macro above will create three alsa controls for each
1102 * instance invoked, gain, mute and ramp duration, which use the same gain
1103 * cell sst_gain to keep track of data
1104 * To calculate number of gain cell instances we need to device by 3 in
1105 * below caulcation for gain cell memory.
1106 * This gets rid of static number and issues while adding new controls
1107 */
1108static struct sst_gain_value sst_gains[ARRAY_SIZE(sst_gain_controls)/SST_GAIN_NUM_CONTROLS];
1109
165static const struct snd_kcontrol_new sst_algo_controls[] = { 1110static const struct snd_kcontrol_new sst_algo_controls[] = {
166 SST_ALGO_KCONTROL_BYTES("media_loop1_out", "fir", 272, SST_MODULE_ID_FIR_24, 1111 SST_ALGO_KCONTROL_BYTES("media_loop1_out", "fir", 272, SST_MODULE_ID_FIR_24,
167 SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR), 1112 SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
@@ -198,21 +1143,280 @@ static int sst_algo_control_init(struct device *dev)
198 return 0; 1143 return 0;
199} 1144}
200 1145
201int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform) 1146static bool is_sst_dapm_widget(struct snd_soc_dapm_widget *w)
1147{
1148 switch (w->id) {
1149 case snd_soc_dapm_pga:
1150 case snd_soc_dapm_aif_in:
1151 case snd_soc_dapm_aif_out:
1152 case snd_soc_dapm_input:
1153 case snd_soc_dapm_output:
1154 case snd_soc_dapm_mixer:
1155 return true;
1156 default:
1157 return false;
1158 }
1159}
1160
1161/**
1162 * sst_send_pipe_gains - send gains for the front-end DAIs
1163 *
1164 * The gains in the pipes connected to the front-ends are muted/unmuted
1165 * automatically via the digital_mute() DAPM callback. This function sends the
1166 * gains for the front-end pipes.
1167 */
1168int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute)
1169{
1170 struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
1171 struct snd_soc_dapm_widget *w;
1172 struct snd_soc_dapm_path *p = NULL;
1173
1174 dev_dbg(dai->dev, "enter, dai-name=%s dir=%d\n", dai->name, stream);
1175
1176 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
1177 dev_dbg(dai->dev, "Stream name=%s\n",
1178 dai->playback_widget->name);
1179 w = dai->playback_widget;
1180 list_for_each_entry(p, &w->sinks, list_source) {
1181 if (p->connected && !p->connected(w, p->sink))
1182 continue;
1183
1184 if (p->connect && p->sink->power &&
1185 is_sst_dapm_widget(p->sink)) {
1186 struct sst_ids *ids = p->sink->priv;
1187
1188 dev_dbg(dai->dev, "send gains for widget=%s\n",
1189 p->sink->name);
1190 mutex_lock(&drv->lock);
1191 sst_set_pipe_gain(ids, drv, mute);
1192 mutex_unlock(&drv->lock);
1193 }
1194 }
1195 } else {
1196 dev_dbg(dai->dev, "Stream name=%s\n",
1197 dai->capture_widget->name);
1198 w = dai->capture_widget;
1199 list_for_each_entry(p, &w->sources, list_sink) {
1200 if (p->connected && !p->connected(w, p->sink))
1201 continue;
1202
1203 if (p->connect && p->source->power &&
1204 is_sst_dapm_widget(p->source)) {
1205 struct sst_ids *ids = p->source->priv;
1206
1207 dev_dbg(dai->dev, "send gain for widget=%s\n",
1208 p->source->name);
1209 mutex_lock(&drv->lock);
1210 sst_set_pipe_gain(ids, drv, mute);
1211 mutex_unlock(&drv->lock);
1212 }
1213 }
1214 }
1215 return 0;
1216}
1217
1218/**
1219 * sst_fill_module_list - populate the list of modules/gains for a pipe
1220 *
1221 *
1222 * Fills the widget pointer in the kcontrol private data, and also fills the
1223 * kcontrol pointer in the widget private data.
1224 *
1225 * Widget pointer is used to send the algo/gain in the .put() handler if the
1226 * widget is powerd on.
1227 *
1228 * Kcontrol pointer is used to send the algo/gain in the widget power ON/OFF
1229 * event handler. Each widget (pipe) has multiple algos stored in the algo_list.
1230 */
1231static int sst_fill_module_list(struct snd_kcontrol *kctl,
1232 struct snd_soc_dapm_widget *w, int type)
202{ 1233{
1234 struct sst_module *module = NULL;
1235 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
1236 struct sst_ids *ids = w->priv;
203 int ret = 0; 1237 int ret = 0;
1238
1239 module = devm_kzalloc(c->dev, sizeof(*module), GFP_KERNEL);
1240 if (!module)
1241 return -ENOMEM;
1242
1243 if (type == SST_MODULE_GAIN) {
1244 struct sst_gain_mixer_control *mc = (void *)kctl->private_value;
1245
1246 mc->w = w;
1247 module->kctl = kctl;
1248 list_add_tail(&module->node, &ids->gain_list);
1249 } else if (type == SST_MODULE_ALGO) {
1250 struct sst_algo_control *bc = (void *)kctl->private_value;
1251
1252 bc->w = w;
1253 module->kctl = kctl;
1254 list_add_tail(&module->node, &ids->algo_list);
1255 } else {
1256 dev_err(c->dev, "invoked for unknown type %d module %s",
1257 type, kctl->id.name);
1258 ret = -EINVAL;
1259 }
1260
1261 return ret;
1262}
1263
1264/**
1265 * sst_fill_widget_module_info - fill list of gains/algos for the pipe
1266 * @widget: pipe modelled as a DAPM widget
1267 *
1268 * Fill the list of gains/algos for the widget by looking at all the card
1269 * controls and comparing the name of the widget with the first part of control
1270 * name. First part of control name contains the pipe name (widget name).
1271 */
1272static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w,
1273 struct snd_soc_platform *platform)
1274{
1275 struct snd_kcontrol *kctl;
1276 int index, ret = 0;
1277 struct snd_card *card = platform->component.card->snd_card;
1278 char *idx;
1279
1280 down_read(&card->controls_rwsem);
1281
1282 list_for_each_entry(kctl, &card->controls, list) {
1283 idx = strstr(kctl->id.name, " ");
1284 if (idx == NULL)
1285 continue;
1286 index = strlen(kctl->id.name) - strlen(idx);
1287
1288 if (strstr(kctl->id.name, "Volume") &&
1289 !strncmp(kctl->id.name, w->name, index))
1290 ret = sst_fill_module_list(kctl, w, SST_MODULE_GAIN);
1291
1292 else if (strstr(kctl->id.name, "params") &&
1293 !strncmp(kctl->id.name, w->name, index))
1294 ret = sst_fill_module_list(kctl, w, SST_MODULE_ALGO);
1295
1296 else if (strstr(kctl->id.name, "Switch") &&
1297 !strncmp(kctl->id.name, w->name, index) &&
1298 strstr(kctl->id.name, "Gain")) {
1299 struct sst_gain_mixer_control *mc =
1300 (void *)kctl->private_value;
1301
1302 mc->w = w;
1303
1304 } else if (strstr(kctl->id.name, "interleaver") &&
1305 !strncmp(kctl->id.name, w->name, index)) {
1306 struct sst_enum *e = (void *)kctl->private_value;
1307
1308 e->w = w;
1309
1310 } else if (strstr(kctl->id.name, "deinterleaver") &&
1311 !strncmp(kctl->id.name, w->name, index)) {
1312
1313 struct sst_enum *e = (void *)kctl->private_value;
1314
1315 e->w = w;
1316 }
1317
1318 if (ret < 0) {
1319 up_read(&card->controls_rwsem);
1320 return ret;
1321 }
1322 }
1323
1324 up_read(&card->controls_rwsem);
1325 return 0;
1326}
1327
1328/**
1329 * sst_fill_linked_widgets - fill the parent pointer for the linked widget
1330 */
1331static void sst_fill_linked_widgets(struct snd_soc_platform *platform,
1332 struct sst_ids *ids)
1333{
1334 struct snd_soc_dapm_widget *w;
1335 unsigned int len = strlen(ids->parent_wname);
1336
1337 list_for_each_entry(w, &platform->component.card->widgets, list) {
1338 if (!strncmp(ids->parent_wname, w->name, len)) {
1339 ids->parent_w = w;
1340 break;
1341 }
1342 }
1343}
1344
1345/**
1346 * sst_map_modules_to_pipe - fill algo/gains list for all pipes
1347 */
1348static int sst_map_modules_to_pipe(struct snd_soc_platform *platform)
1349{
1350 struct snd_soc_dapm_widget *w;
1351 int ret = 0;
1352
1353 list_for_each_entry(w, &platform->component.card->widgets, list) {
1354 if (is_sst_dapm_widget(w) && (w->priv)) {
1355 struct sst_ids *ids = w->priv;
1356
1357 dev_dbg(platform->dev, "widget type=%d name=%s\n",
1358 w->id, w->name);
1359 INIT_LIST_HEAD(&ids->algo_list);
1360 INIT_LIST_HEAD(&ids->gain_list);
1361 ret = sst_fill_widget_module_info(w, platform);
1362
1363 if (ret < 0)
1364 return ret;
1365
1366 /* fill linked widgets */
1367 if (ids->parent_wname != NULL)
1368 sst_fill_linked_widgets(platform, ids);
1369 }
1370 }
1371 return 0;
1372}
1373
1374int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
1375{
1376 int i, ret = 0;
1377 struct snd_soc_dapm_context *dapm =
1378 snd_soc_component_get_dapm(&platform->component);
204 struct sst_data *drv = snd_soc_platform_get_drvdata(platform); 1379 struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
1380 unsigned int gains = ARRAY_SIZE(sst_gain_controls)/3;
205 1381
206 drv->byte_stream = devm_kzalloc(platform->dev, 1382 drv->byte_stream = devm_kzalloc(platform->dev,
207 SST_MAX_BIN_BYTES, GFP_KERNEL); 1383 SST_MAX_BIN_BYTES, GFP_KERNEL);
208 if (!drv->byte_stream) 1384 if (!drv->byte_stream)
209 return -ENOMEM; 1385 return -ENOMEM;
210 1386
211 /*Initialize algo control params*/ 1387 snd_soc_dapm_new_controls(dapm, sst_dapm_widgets,
1388 ARRAY_SIZE(sst_dapm_widgets));
1389 snd_soc_dapm_add_routes(dapm, intercon,
1390 ARRAY_SIZE(intercon));
1391 snd_soc_dapm_new_widgets(dapm->card);
1392
1393 for (i = 0; i < gains; i++) {
1394 sst_gains[i].mute = SST_GAIN_MUTE_DEFAULT;
1395 sst_gains[i].l_gain = SST_GAIN_VOLUME_DEFAULT;
1396 sst_gains[i].r_gain = SST_GAIN_VOLUME_DEFAULT;
1397 sst_gains[i].ramp_duration = SST_GAIN_RAMP_DURATION_DEFAULT;
1398 }
1399
1400 ret = snd_soc_add_platform_controls(platform, sst_gain_controls,
1401 ARRAY_SIZE(sst_gain_controls));
1402 if (ret)
1403 return ret;
1404
1405 /* Initialize algo control params */
212 ret = sst_algo_control_init(platform->dev); 1406 ret = sst_algo_control_init(platform->dev);
213 if (ret) 1407 if (ret)
214 return ret; 1408 return ret;
215 ret = snd_soc_add_platform_controls(platform, sst_algo_controls, 1409 ret = snd_soc_add_platform_controls(platform, sst_algo_controls,
216 ARRAY_SIZE(sst_algo_controls)); 1410 ARRAY_SIZE(sst_algo_controls));
1411 if (ret)
1412 return ret;
1413
1414 ret = snd_soc_add_platform_controls(platform, sst_slot_controls,
1415 ARRAY_SIZE(sst_slot_controls));
1416 if (ret)
1417 return ret;
1418
1419 ret = sst_map_modules_to_pipe(platform);
1420
217 return ret; 1421 return ret;
218} 1422}
diff --git a/sound/soc/intel/sst-atom-controls.h b/sound/soc/intel/sst-atom-controls.h
index a73e894b175c..dfebfdd5eb2a 100644
--- a/sound/soc/intel/sst-atom-controls.h
+++ b/sound/soc/intel/sst-atom-controls.h
@@ -23,6 +23,9 @@
23#ifndef __SST_ATOM_CONTROLS_H__ 23#ifndef __SST_ATOM_CONTROLS_H__
24#define __SST_ATOM_CONTROLS_H__ 24#define __SST_ATOM_CONTROLS_H__
25 25
26#include <sound/soc.h>
27#include <sound/tlv.h>
28
26enum { 29enum {
27 MERR_DPCM_AUDIO = 0, 30 MERR_DPCM_AUDIO = 0,
28 MERR_DPCM_COMPR, 31 MERR_DPCM_COMPR,
@@ -360,16 +363,416 @@ struct sst_dsp_header {
360struct sst_cmd_generic { 363struct sst_cmd_generic {
361 struct sst_dsp_header header; 364 struct sst_dsp_header header;
362} __packed; 365} __packed;
366
367struct swm_input_ids {
368 struct sst_destination_id input_id;
369} __packed;
370
371struct sst_cmd_set_swm {
372 struct sst_dsp_header header;
373 struct sst_destination_id output_id;
374 u16 switch_state;
375 u16 nb_inputs;
376 struct swm_input_ids input[SST_CMD_SWM_MAX_INPUTS];
377} __packed;
378
379struct sst_cmd_set_media_path {
380 struct sst_dsp_header header;
381 u16 switch_state;
382} __packed;
383
384struct pcm_cfg {
385 u8 s_length:2;
386 u8 rate:3;
387 u8 format:3;
388} __packed;
389
390struct sst_cmd_set_speech_path {
391 struct sst_dsp_header header;
392 u16 switch_state;
393 struct {
394 u16 rsvd:8;
395 struct pcm_cfg cfg;
396 } config;
397} __packed;
398
399struct gain_cell {
400 struct sst_destination_id dest;
401 s16 cell_gain_left;
402 s16 cell_gain_right;
403 u16 gain_time_constant;
404} __packed;
405
406#define NUM_GAIN_CELLS 1
407struct sst_cmd_set_gain_dual {
408 struct sst_dsp_header header;
409 u16 gain_cell_num;
410 struct gain_cell cell_gains[NUM_GAIN_CELLS];
411} __packed;
363struct sst_cmd_set_params { 412struct sst_cmd_set_params {
364 struct sst_destination_id dst; 413 struct sst_destination_id dst;
365 u16 command_id; 414 u16 command_id;
366 char params[0]; 415 char params[0];
367} __packed; 416} __packed;
417
418
419struct sst_cmd_sba_vb_start {
420 struct sst_dsp_header header;
421} __packed;
422
423union sba_media_loop_params {
424 struct {
425 u16 rsvd:8;
426 struct pcm_cfg cfg;
427 } part;
428 u16 full;
429} __packed;
430
431struct sst_cmd_sba_set_media_loop_map {
432 struct sst_dsp_header header;
433 u16 switch_state;
434 union sba_media_loop_params param;
435 u16 map;
436} __packed;
437
438struct sst_cmd_tone_stop {
439 struct sst_dsp_header header;
440 u16 switch_state;
441} __packed;
442
443enum sst_ssp_mode {
444 SSP_MODE_MASTER = 0,
445 SSP_MODE_SLAVE = 1,
446};
447
448enum sst_ssp_pcm_mode {
449 SSP_PCM_MODE_NORMAL = 0,
450 SSP_PCM_MODE_NETWORK = 1,
451};
452
453enum sst_ssp_duplex {
454 SSP_DUPLEX = 0,
455 SSP_RX = 1,
456 SSP_TX = 2,
457};
458
459enum sst_ssp_fs_frequency {
460 SSP_FS_8_KHZ = 0,
461 SSP_FS_16_KHZ = 1,
462 SSP_FS_44_1_KHZ = 2,
463 SSP_FS_48_KHZ = 3,
464};
465
466enum sst_ssp_fs_polarity {
467 SSP_FS_ACTIVE_LOW = 0,
468 SSP_FS_ACTIVE_HIGH = 1,
469};
470
471enum sst_ssp_protocol {
472 SSP_MODE_PCM = 0,
473 SSP_MODE_I2S = 1,
474};
475
476enum sst_ssp_port_id {
477 SSP_MODEM = 0,
478 SSP_BT = 1,
479 SSP_FM = 2,
480 SSP_CODEC = 3,
481};
482
483struct sst_cmd_sba_hw_set_ssp {
484 struct sst_dsp_header header;
485 u16 selection; /* 0:SSP0(def), 1:SSP1, 2:SSP2 */
486
487 u16 switch_state;
488
489 u16 nb_bits_per_slots:6; /* 0-32 bits, 24 (def) */
490 u16 nb_slots:4; /* 0-8: slots per frame */
491 u16 mode:3; /* 0:Master, 1: Slave */
492 u16 duplex:3;
493
494 u16 active_tx_slot_map:8; /* Bit map, 0:off, 1:on */
495 u16 reserved1:8;
496
497 u16 active_rx_slot_map:8; /* Bit map 0: Off, 1:On */
498 u16 reserved2:8;
499
500 u16 frame_sync_frequency;
501
502 u16 frame_sync_polarity:8;
503 u16 data_polarity:8;
504
505 u16 frame_sync_width; /* 1 to N clocks */
506 u16 ssp_protocol:8;
507 u16 start_delay:8; /* Start delay in terms of clock ticks */
508} __packed;
509
510#define SST_MAX_TDM_SLOTS 8
511
512struct sst_param_sba_ssp_slot_map {
513 struct sst_dsp_header header;
514
515 u16 param_id;
516 u16 param_len;
517 u16 ssp_index;
518
519 u8 rx_slot_map[SST_MAX_TDM_SLOTS];
520 u8 tx_slot_map[SST_MAX_TDM_SLOTS];
521} __packed;
522
523enum {
524 SST_PROBE_EXTRACTOR = 0,
525 SST_PROBE_INJECTOR = 1,
526};
527
528/**** widget defines *****/
529
530#define SST_MODULE_GAIN 1
531#define SST_MODULE_ALGO 2
532
533#define SST_FMT_MONO 0
534#define SST_FMT_STEREO 3
535
536/* physical SSP numbers */
537enum {
538 SST_SSP0 = 0,
539 SST_SSP1,
540 SST_SSP2,
541 SST_SSP_LAST = SST_SSP2,
542};
543
544#define SST_NUM_SSPS (SST_SSP_LAST + 1) /* physical SSPs */
545#define SST_MAX_SSP_MUX 2 /* single SSP muxed between pipes */
546#define SST_MAX_SSP_DOMAINS 2 /* domains present in each pipe */
547
548struct sst_module {
549 struct snd_kcontrol *kctl;
550 struct list_head node;
551};
552
553struct sst_ssp_config {
554 u8 ssp_id;
555 u8 bits_per_slot;
556 u8 slots;
557 u8 ssp_mode;
558 u8 pcm_mode;
559 u8 duplex;
560 u8 ssp_protocol;
561 u8 fs_frequency;
562 u8 active_slot_map;
563 u8 start_delay;
564 u16 fs_width;
565};
566
567struct sst_ssp_cfg {
568 const u8 ssp_number;
569 const int *mux_shift;
570 const int (*domain_shift)[SST_MAX_SSP_MUX];
571 const struct sst_ssp_config (*ssp_config)[SST_MAX_SSP_MUX][SST_MAX_SSP_DOMAINS];
572};
573
574struct sst_ids {
575 u16 location_id;
576 u16 module_id;
577 u8 task_id;
578 u8 format;
579 u8 reg;
580 const char *parent_wname;
581 struct snd_soc_dapm_widget *parent_w;
582 struct list_head algo_list;
583 struct list_head gain_list;
584 const struct sst_pcm_format *pcm_fmt;
585};
586
587
588#define SST_AIF_IN(wname, wevent) \
589{ .id = snd_soc_dapm_aif_in, .name = wname, .sname = NULL, \
590 .reg = SND_SOC_NOPM, .shift = 0, \
591 .on_val = 1, .off_val = 0, \
592 .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
593 .priv = (void *)&(struct sst_ids) { .task_id = 0, .location_id = 0 } \
594}
595
596#define SST_AIF_OUT(wname, wevent) \
597{ .id = snd_soc_dapm_aif_out, .name = wname, .sname = NULL, \
598 .reg = SND_SOC_NOPM, .shift = 0, \
599 .on_val = 1, .off_val = 0, \
600 .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
601 .priv = (void *)&(struct sst_ids) { .task_id = 0, .location_id = 0 } \
602}
603
604#define SST_INPUT(wname, wevent) \
605{ .id = snd_soc_dapm_input, .name = wname, .sname = NULL, \
606 .reg = SND_SOC_NOPM, .shift = 0, \
607 .on_val = 1, .off_val = 0, \
608 .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
609 .priv = (void *)&(struct sst_ids) { .task_id = 0, .location_id = 0 } \
610}
611
612#define SST_OUTPUT(wname, wevent) \
613{ .id = snd_soc_dapm_output, .name = wname, .sname = NULL, \
614 .reg = SND_SOC_NOPM, .shift = 0, \
615 .on_val = 1, .off_val = 0, \
616 .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
617 .priv = (void *)&(struct sst_ids) { .task_id = 0, .location_id = 0 } \
618}
619
620#define SST_DAPM_OUTPUT(wname, wloc_id, wtask_id, wformat, wevent) \
621{ .id = snd_soc_dapm_output, .name = wname, .sname = NULL, \
622 .reg = SND_SOC_NOPM, .shift = 0, \
623 .on_val = 1, .off_val = 0, \
624 .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
625 .priv = (void *)&(struct sst_ids) { .location_id = wloc_id, .task_id = wtask_id,\
626 .pcm_fmt = wformat, } \
627}
628
629#define SST_PATH(wname, wtask, wloc_id, wevent, wflags) \
630{ .id = snd_soc_dapm_pga, .name = wname, .reg = SND_SOC_NOPM, .shift = 0, \
631 .kcontrol_news = NULL, .num_kcontrols = 0, \
632 .on_val = 1, .off_val = 0, \
633 .event = wevent, .event_flags = wflags, \
634 .priv = (void *)&(struct sst_ids) { .task_id = wtask, .location_id = wloc_id, } \
635}
636
637#define SST_LINKED_PATH(wname, wtask, wloc_id, linked_wname, wevent, wflags) \
638{ .id = snd_soc_dapm_pga, .name = wname, .reg = SND_SOC_NOPM, .shift = 0, \
639 .kcontrol_news = NULL, .num_kcontrols = 0, \
640 .on_val = 1, .off_val = 0, \
641 .event = wevent, .event_flags = wflags, \
642 .priv = (void *)&(struct sst_ids) { .task_id = wtask, .location_id = wloc_id, \
643 .parent_wname = linked_wname} \
644}
645
646#define SST_PATH_MEDIA_LOOP(wname, wtask, wloc_id, wformat, wevent, wflags) \
647{ .id = snd_soc_dapm_pga, .name = wname, .reg = SND_SOC_NOPM, .shift = 0, \
648 .kcontrol_news = NULL, .num_kcontrols = 0, \
649 .event = wevent, .event_flags = wflags, \
650 .priv = (void *)&(struct sst_ids) { .task_id = wtask, .location_id = wloc_id, \
651 .format = wformat,} \
652}
653
654/* output is triggered before input */
655#define SST_PATH_INPUT(name, task_id, loc_id, event) \
656 SST_PATH(name, task_id, loc_id, event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
657
658#define SST_PATH_LINKED_INPUT(name, task_id, loc_id, linked_wname, event) \
659 SST_LINKED_PATH(name, task_id, loc_id, linked_wname, event, \
660 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
661
662#define SST_PATH_OUTPUT(name, task_id, loc_id, event) \
663 SST_PATH(name, task_id, loc_id, event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)
664
665#define SST_PATH_LINKED_OUTPUT(name, task_id, loc_id, linked_wname, event) \
666 SST_LINKED_PATH(name, task_id, loc_id, linked_wname, event, \
667 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)
668
669#define SST_PATH_MEDIA_LOOP_OUTPUT(name, task_id, loc_id, format, event) \
670 SST_PATH_MEDIA_LOOP(name, task_id, loc_id, format, event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)
671
672
673#define SST_SWM_MIXER(wname, wreg, wtask, wloc_id, wcontrols, wevent) \
674{ .id = snd_soc_dapm_mixer, .name = wname, .reg = SND_SOC_NOPM, .shift = 0, \
675 .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols),\
676 .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD | \
677 SND_SOC_DAPM_POST_REG, \
678 .priv = (void *)&(struct sst_ids) { .task_id = wtask, .location_id = wloc_id, \
679 .reg = wreg } \
680}
681
682enum sst_gain_kcontrol_type {
683 SST_GAIN_TLV,
684 SST_GAIN_MUTE,
685 SST_GAIN_RAMP_DURATION,
686};
687
688struct sst_gain_mixer_control {
689 bool stereo;
690 enum sst_gain_kcontrol_type type;
691 struct sst_gain_value *gain_val;
692 int max;
693 int min;
694 u16 instance_id;
695 u16 module_id;
696 u16 pipe_id;
697 u16 task_id;
698 char pname[44];
699 struct snd_soc_dapm_widget *w;
700};
701
702struct sst_gain_value {
703 u16 ramp_duration;
704 s16 l_gain;
705 s16 r_gain;
706 bool mute;
707};
708#define SST_GAIN_VOLUME_DEFAULT (-1440)
709#define SST_GAIN_RAMP_DURATION_DEFAULT 5 /* timeconstant */
710#define SST_GAIN_MUTE_DEFAULT true
711
712#define SST_GAIN_KCONTROL_TLV(xname, xhandler_get, xhandler_put, \
713 xmod, xpipe, xinstance, xtask, tlv_array, xgain_val, \
714 xmin, xmax, xpname) \
715 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
716 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
717 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
718 .tlv.p = (tlv_array), \
719 .info = sst_gain_ctl_info,\
720 .get = xhandler_get, .put = xhandler_put, \
721 .private_value = (unsigned long)&(struct sst_gain_mixer_control) \
722 { .stereo = true, .max = xmax, .min = xmin, .type = SST_GAIN_TLV, \
723 .module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
724 .instance_id = xinstance, .gain_val = xgain_val, .pname = xpname}
725
726#define SST_GAIN_KCONTROL_INT(xname, xhandler_get, xhandler_put, \
727 xmod, xpipe, xinstance, xtask, xtype, xgain_val, \
728 xmin, xmax, xpname) \
729 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
730 .info = sst_gain_ctl_info, \
731 .get = xhandler_get, .put = xhandler_put, \
732 .private_value = (unsigned long)&(struct sst_gain_mixer_control) \
733 { .stereo = false, .max = xmax, .min = xmin, .type = xtype, \
734 .module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
735 .instance_id = xinstance, .gain_val = xgain_val, .pname = xpname}
736
737#define SST_GAIN_KCONTROL_BOOL(xname, xhandler_get, xhandler_put,\
738 xmod, xpipe, xinstance, xtask, xgain_val, xpname) \
739 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
740 .info = snd_soc_info_bool_ext, \
741 .get = xhandler_get, .put = xhandler_put, \
742 .private_value = (unsigned long)&(struct sst_gain_mixer_control) \
743 { .stereo = false, .type = SST_GAIN_MUTE, \
744 .module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
745 .instance_id = xinstance, .gain_val = xgain_val, .pname = xpname}
368#define SST_CONTROL_NAME(xpname, xmname, xinstance, xtype) \ 746#define SST_CONTROL_NAME(xpname, xmname, xinstance, xtype) \
369 xpname " " xmname " " #xinstance " " xtype 747 xpname " " xmname " " #xinstance " " xtype
370 748
371#define SST_COMBO_CONTROL_NAME(xpname, xmname, xinstance, xtype, xsubmodule) \ 749#define SST_COMBO_CONTROL_NAME(xpname, xmname, xinstance, xtype, xsubmodule) \
372 xpname " " xmname " " #xinstance " " xtype " " xsubmodule 750 xpname " " xmname " " #xinstance " " xtype " " xsubmodule
751
752/*
753 * 3 Controls for each Gain module
754 * e.g. - pcm0_in Gain 0 Volume
755 * - pcm0_in Gain 0 Ramp Delay
756 * - pcm0_in Gain 0 Switch
757 */
758#define SST_GAIN_KCONTROLS(xpname, xmname, xmin_gain, xmax_gain, xmin_tc, xmax_tc, \
759 xhandler_get, xhandler_put, \
760 xmod, xpipe, xinstance, xtask, tlv_array, xgain_val) \
761 { SST_GAIN_KCONTROL_INT(SST_CONTROL_NAME(xpname, xmname, xinstance, "Ramp Delay"), \
762 xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, SST_GAIN_RAMP_DURATION, \
763 xgain_val, xmin_tc, xmax_tc, xpname) }, \
764 { SST_GAIN_KCONTROL_BOOL(SST_CONTROL_NAME(xpname, xmname, xinstance, "Switch"), \
765 xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, \
766 xgain_val, xpname) } ,\
767 { SST_GAIN_KCONTROL_TLV(SST_CONTROL_NAME(xpname, xmname, xinstance, "Volume"), \
768 xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, tlv_array, \
769 xgain_val, xmin_gain, xmax_gain, xpname) }
770
771#define SST_GAIN_TC_MIN 5
772#define SST_GAIN_TC_MAX 5000
773#define SST_GAIN_MIN_VALUE -1440 /* in 0.1 DB units */
774#define SST_GAIN_MAX_VALUE 360
775
373enum sst_algo_kcontrol_type { 776enum sst_algo_kcontrol_type {
374 SST_ALGO_PARAMS, 777 SST_ALGO_PARAMS,
375 SST_ALGO_BYPASS, 778 SST_ALGO_BYPASS,
@@ -439,4 +842,29 @@ struct sst_enum {
439 struct snd_soc_dapm_widget *w; 842 struct snd_soc_dapm_widget *w;
440}; 843};
441 844
845/* only 4 slots/channels supported atm */
846#define SST_SSP_SLOT_ENUM(s_ch_no, is_tx, xtexts) \
847 (struct sst_enum){ .reg = s_ch_no, .tx = is_tx, .max = 4+1, .texts = xtexts, }
848
849#define SST_SLOT_CTL_NAME(xpname, xmname, s_ch_name) \
850 xpname " " xmname " " s_ch_name
851
852#define SST_SSP_SLOT_CTL(xpname, xmname, s_ch_name, s_ch_no, is_tx, xtexts, xget, xput) \
853{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
854 .name = SST_SLOT_CTL_NAME(xpname, xmname, s_ch_name), \
855 .info = sst_slot_enum_info, \
856 .get = xget, .put = xput, \
857 .private_value = (unsigned long)&SST_SSP_SLOT_ENUM(s_ch_no, is_tx, xtexts), \
858}
859
860#define SST_MUX_CTL_NAME(xpname, xinstance) \
861 xpname " " #xinstance
862
863#define SST_SSP_MUX_ENUM(xreg, xshift, xtexts) \
864 (struct soc_enum) SOC_ENUM_DOUBLE(xreg, xshift, xshift, ARRAY_SIZE(xtexts), xtexts)
865
866#define SST_SSP_MUX_CTL(xpname, xinstance, xreg, xshift, xtexts) \
867 SOC_DAPM_ENUM(SST_MUX_CTL_NAME(xpname, xinstance), \
868 SST_SSP_MUX_ENUM(xreg, xshift, xtexts))
869
442#endif 870#endif
diff --git a/sound/soc/intel/sst-baytrail-dsp.c b/sound/soc/intel/sst-baytrail-dsp.c
index fc588764ffa3..5a9e56700f31 100644
--- a/sound/soc/intel/sst-baytrail-dsp.c
+++ b/sound/soc/intel/sst-baytrail-dsp.c
@@ -67,17 +67,12 @@ static int sst_byt_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
67{ 67{
68 struct dma_block_info *block; 68 struct dma_block_info *block;
69 struct sst_module *mod; 69 struct sst_module *mod;
70 struct sst_module_data block_data;
71 struct sst_module_template template; 70 struct sst_module_template template;
72 int count; 71 int count;
73 72
74 memset(&template, 0, sizeof(template)); 73 memset(&template, 0, sizeof(template));
75 template.id = module->type; 74 template.id = module->type;
76 template.entry = module->entry_point; 75 template.entry = module->entry_point;
77 template.p.type = SST_MEM_DRAM;
78 template.p.data_type = SST_DATA_P;
79 template.s.type = SST_MEM_DRAM;
80 template.s.data_type = SST_DATA_S;
81 76
82 mod = sst_module_new(fw, &template, NULL); 77 mod = sst_module_new(fw, &template, NULL);
83 if (mod == NULL) 78 if (mod == NULL)
@@ -94,19 +89,19 @@ static int sst_byt_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
94 89
95 switch (block->type) { 90 switch (block->type) {
96 case SST_BYT_IRAM: 91 case SST_BYT_IRAM:
97 block_data.offset = block->ram_offset + 92 mod->offset = block->ram_offset +
98 dsp->addr.iram_offset; 93 dsp->addr.iram_offset;
99 block_data.type = SST_MEM_IRAM; 94 mod->type = SST_MEM_IRAM;
100 break; 95 break;
101 case SST_BYT_DRAM: 96 case SST_BYT_DRAM:
102 block_data.offset = block->ram_offset + 97 mod->offset = block->ram_offset +
103 dsp->addr.dram_offset; 98 dsp->addr.dram_offset;
104 block_data.type = SST_MEM_DRAM; 99 mod->type = SST_MEM_DRAM;
105 break; 100 break;
106 case SST_BYT_CACHE: 101 case SST_BYT_CACHE:
107 block_data.offset = block->ram_offset + 102 mod->offset = block->ram_offset +
108 (dsp->addr.fw_ext - dsp->addr.lpe); 103 (dsp->addr.fw_ext - dsp->addr.lpe);
109 block_data.type = SST_MEM_CACHE; 104 mod->type = SST_MEM_CACHE;
110 break; 105 break;
111 default: 106 default:
112 dev_err(dsp->dev, "wrong ram type 0x%x in block0x%x\n", 107 dev_err(dsp->dev, "wrong ram type 0x%x in block0x%x\n",
@@ -114,11 +109,10 @@ static int sst_byt_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
114 return -EINVAL; 109 return -EINVAL;
115 } 110 }
116 111
117 block_data.size = block->size; 112 mod->size = block->size;
118 block_data.data_type = SST_DATA_M; 113 mod->data = (void *)block + sizeof(*block);
119 block_data.data = (void *)block + sizeof(*block);
120 114
121 sst_module_insert_fixed_block(mod, &block_data); 115 sst_module_alloc_blocks(mod);
122 116
123 block = (void *)block + sizeof(*block) + block->size; 117 block = (void *)block + sizeof(*block) + block->size;
124 } 118 }
diff --git a/sound/soc/intel/sst-dsp-priv.h b/sound/soc/intel/sst-dsp-priv.h
index ffb308bd81ce..b9da030e312d 100644
--- a/sound/soc/intel/sst-dsp-priv.h
+++ b/sound/soc/intel/sst-dsp-priv.h
@@ -26,6 +26,9 @@ struct sst_mem_block;
26struct sst_module; 26struct sst_module;
27struct sst_fw; 27struct sst_fw;
28 28
29/* do we need to remove or keep */
30#define DSP_DRAM_ADDR_OFFSET 0x400000
31
29/* 32/*
30 * DSP Operations exported by platform Audio DSP driver. 33 * DSP Operations exported by platform Audio DSP driver.
31 */ 34 */
@@ -33,6 +36,9 @@ struct sst_ops {
33 /* DSP core boot / reset */ 36 /* DSP core boot / reset */
34 void (*boot)(struct sst_dsp *); 37 void (*boot)(struct sst_dsp *);
35 void (*reset)(struct sst_dsp *); 38 void (*reset)(struct sst_dsp *);
39 int (*wake)(struct sst_dsp *);
40 void (*sleep)(struct sst_dsp *);
41 void (*stall)(struct sst_dsp *);
36 42
37 /* Shim IO */ 43 /* Shim IO */
38 void (*write)(void __iomem *addr, u32 offset, u32 value); 44 void (*write)(void __iomem *addr, u32 offset, u32 value);
@@ -67,6 +73,8 @@ struct sst_addr {
67 u32 shim_offset; 73 u32 shim_offset;
68 u32 iram_offset; 74 u32 iram_offset;
69 u32 dram_offset; 75 u32 dram_offset;
76 u32 dsp_iram_offset;
77 u32 dsp_dram_offset;
70 void __iomem *lpe; 78 void __iomem *lpe;
71 void __iomem *shim; 79 void __iomem *shim;
72 void __iomem *pci_cfg; 80 void __iomem *pci_cfg;
@@ -84,15 +92,6 @@ struct sst_mailbox {
84}; 92};
85 93
86/* 94/*
87 * Audio DSP Firmware data types.
88 */
89enum sst_data_type {
90 SST_DATA_M = 0, /* module block data */
91 SST_DATA_P = 1, /* peristant data (text, data) */
92 SST_DATA_S = 2, /* scratch data (usually buffers) */
93};
94
95/*
96 * Audio DSP memory block types. 95 * Audio DSP memory block types.
97 */ 96 */
98enum sst_mem_type { 97enum sst_mem_type {
@@ -125,23 +124,6 @@ struct sst_fw {
125}; 124};
126 125
127/* 126/*
128 * Audio DSP Generic Module data.
129 *
130 * This is used to dsecribe any sections of persistent (text and data) and
131 * scratch (buffers) of module data in ADSP memory space.
132 */
133struct sst_module_data {
134
135 enum sst_mem_type type; /* destination memory type */
136 enum sst_data_type data_type; /* type of module data */
137
138 u32 size; /* size in bytes */
139 int32_t offset; /* offset in FW file */
140 u32 data_offset; /* offset in ADSP memory space */
141 void *data; /* module data */
142};
143
144/*
145 * Audio DSP Generic Module Template. 127 * Audio DSP Generic Module Template.
146 * 128 *
147 * Used to define and register a new FW module. This data is extracted from 129 * Used to define and register a new FW module. This data is extracted from
@@ -150,15 +132,52 @@ struct sst_module_data {
150struct sst_module_template { 132struct sst_module_template {
151 u32 id; 133 u32 id;
152 u32 entry; /* entry point */ 134 u32 entry; /* entry point */
153 struct sst_module_data s; /* scratch data */ 135 u32 scratch_size;
154 struct sst_module_data p; /* peristant data */ 136 u32 persistent_size;
137};
138
139/*
140 * Block Allocator - Used to allocate blocks of DSP memory.
141 */
142struct sst_block_allocator {
143 u32 id;
144 u32 offset;
145 int size;
146 enum sst_mem_type type;
147};
148
149/*
150 * Runtime Module Instance - A module object can be instanciated multiple
151 * times within the DSP FW.
152 */
153struct sst_module_runtime {
154 struct sst_dsp *dsp;
155 int id;
156 struct sst_module *module; /* parent module we belong too */
157
158 u32 persistent_offset; /* private memory offset */
159 void *private;
160
161 struct list_head list;
162 struct list_head block_list; /* list of blocks used */
163};
164
165/*
166 * Runtime Module Context - The runtime context must be manually stored by the
167 * driver prior to enter S3 and restored after leaving S3. This should really be
168 * part of the memory context saved by the enter D3 message IPC ???
169 */
170struct sst_module_runtime_context {
171 dma_addr_t dma_buffer;
172 u32 *buffer;
155}; 173};
156 174
157/* 175/*
158 * Audio DSP Generic Module. 176 * Audio DSP Generic Module.
159 * 177 *
160 * Each Firmware file can consist of 1..N modules. A module can span multiple 178 * Each Firmware file can consist of 1..N modules. A module can span multiple
161 * ADSP memory blocks. The simplest FW will be a file with 1 module. 179 * ADSP memory blocks. The simplest FW will be a file with 1 module. A module
180 * can be instanciated multiple times in the DSP.
162 */ 181 */
163struct sst_module { 182struct sst_module {
164 struct sst_dsp *dsp; 183 struct sst_dsp *dsp;
@@ -167,10 +186,13 @@ struct sst_module {
167 /* module configuration */ 186 /* module configuration */
168 u32 id; 187 u32 id;
169 u32 entry; /* module entry point */ 188 u32 entry; /* module entry point */
170 u32 offset; /* module offset in firmware file */ 189 s32 offset; /* module offset in firmware file */
171 u32 size; /* module size */ 190 u32 size; /* module size */
172 struct sst_module_data s; /* scratch data */ 191 u32 scratch_size; /* global scratch memory required */
173 struct sst_module_data p; /* peristant data */ 192 u32 persistent_size; /* private memory required */
193 enum sst_mem_type type; /* destination memory type */
194 u32 data_offset; /* offset in ADSP memory space */
195 void *data; /* module data */
174 196
175 /* runtime */ 197 /* runtime */
176 u32 usage_count; /* can be unloaded if count == 0 */ 198 u32 usage_count; /* can be unloaded if count == 0 */
@@ -180,6 +202,7 @@ struct sst_module {
180 struct list_head block_list; /* Module list of blocks in use */ 202 struct list_head block_list; /* Module list of blocks in use */
181 struct list_head list; /* DSP list of modules */ 203 struct list_head list; /* DSP list of modules */
182 struct list_head list_fw; /* FW list of modules */ 204 struct list_head list_fw; /* FW list of modules */
205 struct list_head runtime_list; /* list of runtime module objects*/
183}; 206};
184 207
185/* 208/*
@@ -208,7 +231,6 @@ struct sst_mem_block {
208 struct sst_block_ops *ops; /* block operations, if any */ 231 struct sst_block_ops *ops; /* block operations, if any */
209 232
210 /* block status */ 233 /* block status */
211 enum sst_data_type data_type; /* data type held in this block */
212 u32 bytes_used; /* bytes in use by modules */ 234 u32 bytes_used; /* bytes in use by modules */
213 void *private; /* generic core does not touch this */ 235 void *private; /* generic core does not touch this */
214 int users; /* number of modules using this block */ 236 int users; /* number of modules using this block */
@@ -253,6 +275,11 @@ struct sst_dsp {
253 struct list_head module_list; 275 struct list_head module_list;
254 struct list_head fw_list; 276 struct list_head fw_list;
255 277
278 /* scratch buffer */
279 struct list_head scratch_block_list;
280 u32 scratch_offset;
281 u32 scratch_size;
282
256 /* platform data */ 283 /* platform data */
257 struct sst_pdata *pdata; 284 struct sst_pdata *pdata;
258 285
@@ -290,18 +317,33 @@ void sst_fw_unload(struct sst_fw *sst_fw);
290/* Create/Free firmware modules */ 317/* Create/Free firmware modules */
291struct sst_module *sst_module_new(struct sst_fw *sst_fw, 318struct sst_module *sst_module_new(struct sst_fw *sst_fw,
292 struct sst_module_template *template, void *private); 319 struct sst_module_template *template, void *private);
293void sst_module_free(struct sst_module *sst_module); 320void sst_module_free(struct sst_module *module);
294int sst_module_insert(struct sst_module *sst_module);
295int sst_module_remove(struct sst_module *sst_module);
296int sst_module_insert_fixed_block(struct sst_module *module,
297 struct sst_module_data *data);
298struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id); 321struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id);
299 322int sst_module_alloc_blocks(struct sst_module *module);
300/* allocate/free pesistent/scratch memory regions managed by drv */ 323int sst_module_free_blocks(struct sst_module *module);
301struct sst_module *sst_mem_block_alloc_scratch(struct sst_dsp *dsp); 324
302void sst_mem_block_free_scratch(struct sst_dsp *dsp, 325/* Create/Free firmware module runtime instances */
303 struct sst_module *scratch); 326struct sst_module_runtime *sst_module_runtime_new(struct sst_module *module,
304int sst_block_module_remove(struct sst_module *module); 327 int id, void *private);
328void sst_module_runtime_free(struct sst_module_runtime *runtime);
329struct sst_module_runtime *sst_module_runtime_get_from_id(
330 struct sst_module *module, u32 id);
331int sst_module_runtime_alloc_blocks(struct sst_module_runtime *runtime,
332 int offset);
333int sst_module_runtime_free_blocks(struct sst_module_runtime *runtime);
334int sst_module_runtime_save(struct sst_module_runtime *runtime,
335 struct sst_module_runtime_context *context);
336int sst_module_runtime_restore(struct sst_module_runtime *runtime,
337 struct sst_module_runtime_context *context);
338
339/* generic block allocation */
340int sst_alloc_blocks(struct sst_dsp *dsp, struct sst_block_allocator *ba,
341 struct list_head *block_list);
342int sst_free_blocks(struct sst_dsp *dsp, struct list_head *block_list);
343
344/* scratch allocation */
345int sst_block_alloc_scratch(struct sst_dsp *dsp);
346void sst_block_free_scratch(struct sst_dsp *dsp);
305 347
306/* Register the DSPs memory blocks - would be nice to read from ACPI */ 348/* Register the DSPs memory blocks - would be nice to read from ACPI */
307struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset, 349struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
@@ -309,4 +351,10 @@ struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
309 void *private); 351 void *private);
310void sst_mem_block_unregister_all(struct sst_dsp *dsp); 352void sst_mem_block_unregister_all(struct sst_dsp *dsp);
311 353
354/* Create/Free DMA resources */
355int sst_dma_new(struct sst_dsp *sst);
356void sst_dma_free(struct sst_dma *dma);
357
358u32 sst_dsp_get_offset(struct sst_dsp *dsp, u32 offset,
359 enum sst_mem_type type);
312#endif 360#endif
diff --git a/sound/soc/intel/sst-dsp.c b/sound/soc/intel/sst-dsp.c
index cd23060a0d86..86e410845670 100644
--- a/sound/soc/intel/sst-dsp.c
+++ b/sound/soc/intel/sst-dsp.c
@@ -245,6 +245,29 @@ int sst_dsp_boot(struct sst_dsp *sst)
245} 245}
246EXPORT_SYMBOL_GPL(sst_dsp_boot); 246EXPORT_SYMBOL_GPL(sst_dsp_boot);
247 247
248int sst_dsp_wake(struct sst_dsp *sst)
249{
250 if (sst->ops->wake)
251 return sst->ops->wake(sst);
252
253 return 0;
254}
255EXPORT_SYMBOL_GPL(sst_dsp_wake);
256
257void sst_dsp_sleep(struct sst_dsp *sst)
258{
259 if (sst->ops->sleep)
260 sst->ops->sleep(sst);
261}
262EXPORT_SYMBOL_GPL(sst_dsp_sleep);
263
264void sst_dsp_stall(struct sst_dsp *sst)
265{
266 if (sst->ops->stall)
267 sst->ops->stall(sst);
268}
269EXPORT_SYMBOL_GPL(sst_dsp_stall);
270
248void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg) 271void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg)
249{ 272{
250 sst_dsp_shim_write_unlocked(dsp, SST_IPCX, msg | SST_IPCX_BUSY); 273 sst_dsp_shim_write_unlocked(dsp, SST_IPCX, msg | SST_IPCX_BUSY);
@@ -352,6 +375,7 @@ struct sst_dsp *sst_dsp_new(struct device *dev,
352 INIT_LIST_HEAD(&sst->free_block_list); 375 INIT_LIST_HEAD(&sst->free_block_list);
353 INIT_LIST_HEAD(&sst->module_list); 376 INIT_LIST_HEAD(&sst->module_list);
354 INIT_LIST_HEAD(&sst->fw_list); 377 INIT_LIST_HEAD(&sst->fw_list);
378 INIT_LIST_HEAD(&sst->scratch_block_list);
355 379
356 /* Initialise SST Audio DSP */ 380 /* Initialise SST Audio DSP */
357 if (sst->ops->init) { 381 if (sst->ops->init) {
@@ -366,6 +390,10 @@ struct sst_dsp *sst_dsp_new(struct device *dev,
366 if (err) 390 if (err)
367 goto irq_err; 391 goto irq_err;
368 392
393 err = sst_dma_new(sst);
394 if (err)
395 dev_warn(dev, "sst_dma_new failed %d\n", err);
396
369 return sst; 397 return sst;
370 398
371irq_err: 399irq_err:
@@ -381,6 +409,9 @@ void sst_dsp_free(struct sst_dsp *sst)
381 free_irq(sst->irq, sst); 409 free_irq(sst->irq, sst);
382 if (sst->ops->free) 410 if (sst->ops->free)
383 sst->ops->free(sst); 411 sst->ops->free(sst);
412
413 if (sst->dma)
414 sst_dma_free(sst->dma);
384} 415}
385EXPORT_SYMBOL_GPL(sst_dsp_free); 416EXPORT_SYMBOL_GPL(sst_dsp_free);
386 417
diff --git a/sound/soc/intel/sst-dsp.h b/sound/soc/intel/sst-dsp.h
index 3165dfa97408..f291e32f0077 100644
--- a/sound/soc/intel/sst-dsp.h
+++ b/sound/soc/intel/sst-dsp.h
@@ -30,6 +30,9 @@
30#define SST_DMA_TYPE_DW 1 30#define SST_DMA_TYPE_DW 1
31#define SST_DMA_TYPE_MID 2 31#define SST_DMA_TYPE_MID 2
32 32
33/* autosuspend delay 5s*/
34#define SST_RUNTIME_SUSPEND_DELAY (5 * 1000)
35
33/* SST Shim register map 36/* SST Shim register map
34 * The register naming can differ between products. Some products also 37 * The register naming can differ between products. Some products also
35 * contain extra functionality. 38 * contain extra functionality.
@@ -156,12 +159,18 @@
156#define SST_VDRTCTL3 0xaC 159#define SST_VDRTCTL3 0xaC
157 160
158/* VDRTCTL0 */ 161/* VDRTCTL0 */
159#define SST_VDRTCL0_APLLSE_MASK 1 162#define SST_VDRTCL0_D3PGD (1 << 0)
160#define SST_VDRTCL0_DSRAMPGE_SHIFT 16 163#define SST_VDRTCL0_D3SRAMPGD (1 << 1)
161#define SST_VDRTCL0_DSRAMPGE_MASK (0xffff << SST_VDRTCL0_DSRAMPGE_SHIFT) 164#define SST_VDRTCL0_DSRAMPGE_SHIFT 12
162#define SST_VDRTCL0_ISRAMPGE_SHIFT 6 165#define SST_VDRTCL0_DSRAMPGE_MASK (0xfffff << SST_VDRTCL0_DSRAMPGE_SHIFT)
166#define SST_VDRTCL0_ISRAMPGE_SHIFT 2
163#define SST_VDRTCL0_ISRAMPGE_MASK (0x3ff << SST_VDRTCL0_ISRAMPGE_SHIFT) 167#define SST_VDRTCL0_ISRAMPGE_MASK (0x3ff << SST_VDRTCL0_ISRAMPGE_SHIFT)
164 168
169/* VDRTCTL2 */
170#define SST_VDRTCL2_DCLCGE (1 << 1)
171#define SST_VDRTCL2_DTCGE (1 << 10)
172#define SST_VDRTCL2_APLLSE_MASK (1 << 31)
173
165/* PMCS */ 174/* PMCS */
166#define SST_PMCS 0x84 175#define SST_PMCS 0x84
167#define SST_PMCS_PS_MASK 0x3 176#define SST_PMCS_PS_MASK 0x3
@@ -245,6 +254,17 @@ void sst_memcpy_fromio_32(struct sst_dsp *sst,
245/* DSP reset & boot */ 254/* DSP reset & boot */
246void sst_dsp_reset(struct sst_dsp *sst); 255void sst_dsp_reset(struct sst_dsp *sst);
247int sst_dsp_boot(struct sst_dsp *sst); 256int sst_dsp_boot(struct sst_dsp *sst);
257int sst_dsp_wake(struct sst_dsp *sst);
258void sst_dsp_sleep(struct sst_dsp *sst);
259void sst_dsp_stall(struct sst_dsp *sst);
260
261/* DMA */
262int sst_dsp_dma_get_channel(struct sst_dsp *dsp, int chan_id);
263void sst_dsp_dma_put_channel(struct sst_dsp *dsp);
264int sst_dsp_dma_copyfrom(struct sst_dsp *sst, dma_addr_t dest_addr,
265 dma_addr_t src_addr, size_t size);
266int sst_dsp_dma_copyto(struct sst_dsp *sst, dma_addr_t dest_addr,
267 dma_addr_t src_addr, size_t size);
248 268
249/* Msg IO */ 269/* Msg IO */
250void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg); 270void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg);
diff --git a/sound/soc/intel/sst-firmware.c b/sound/soc/intel/sst-firmware.c
index 3bb43dac892d..4a5bde9c686b 100644
--- a/sound/soc/intel/sst-firmware.c
+++ b/sound/soc/intel/sst-firmware.c
@@ -23,6 +23,11 @@
23#include <linux/dma-mapping.h> 23#include <linux/dma-mapping.h>
24#include <linux/dmaengine.h> 24#include <linux/dmaengine.h>
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <linux/acpi.h>
27
28/* supported DMA engine drivers */
29#include <linux/platform_data/dma-dw.h>
30#include <linux/dma/dw.h>
26 31
27#include <asm/page.h> 32#include <asm/page.h>
28#include <asm/pgtable.h> 33#include <asm/pgtable.h>
@@ -30,16 +35,301 @@
30#include "sst-dsp.h" 35#include "sst-dsp.h"
31#include "sst-dsp-priv.h" 36#include "sst-dsp-priv.h"
32 37
33static void block_module_remove(struct sst_module *module); 38#define SST_DMA_RESOURCES 2
39#define SST_DSP_DMA_MAX_BURST 0x3
40#define SST_HSW_BLOCK_ANY 0xffffffff
41
42#define SST_HSW_MASK_DMA_ADDR_DSP 0xfff00000
43
44struct sst_dma {
45 struct sst_dsp *sst;
46
47 struct dw_dma_chip *chip;
48
49 struct dma_async_tx_descriptor *desc;
50 struct dma_chan *ch;
51};
52
53static inline void sst_memcpy32(volatile void __iomem *dest, void *src, u32 bytes)
54{
55 /* __iowrite32_copy use 32bit size values so divide by 4 */
56 __iowrite32_copy((void *)dest, src, bytes/4);
57}
58
59static void sst_dma_transfer_complete(void *arg)
60{
61 struct sst_dsp *sst = (struct sst_dsp *)arg;
62
63 dev_dbg(sst->dev, "DMA: callback\n");
64}
65
66static int sst_dsp_dma_copy(struct sst_dsp *sst, dma_addr_t dest_addr,
67 dma_addr_t src_addr, size_t size)
68{
69 struct dma_async_tx_descriptor *desc;
70 struct sst_dma *dma = sst->dma;
71
72 if (dma->ch == NULL) {
73 dev_err(sst->dev, "error: no DMA channel\n");
74 return -ENODEV;
75 }
76
77 dev_dbg(sst->dev, "DMA: src: 0x%lx dest 0x%lx size %zu\n",
78 (unsigned long)src_addr, (unsigned long)dest_addr, size);
79
80 desc = dma->ch->device->device_prep_dma_memcpy(dma->ch, dest_addr,
81 src_addr, size, DMA_CTRL_ACK);
82 if (!desc){
83 dev_err(sst->dev, "error: dma prep memcpy failed\n");
84 return -EINVAL;
85 }
86
87 desc->callback = sst_dma_transfer_complete;
88 desc->callback_param = sst;
89
90 desc->tx_submit(desc);
91 dma_wait_for_async_tx(desc);
92
93 return 0;
94}
95
96/* copy to DSP */
97int sst_dsp_dma_copyto(struct sst_dsp *sst, dma_addr_t dest_addr,
98 dma_addr_t src_addr, size_t size)
99{
100 return sst_dsp_dma_copy(sst, dest_addr | SST_HSW_MASK_DMA_ADDR_DSP,
101 src_addr, size);
102}
103EXPORT_SYMBOL_GPL(sst_dsp_dma_copyto);
104
105/* copy from DSP */
106int sst_dsp_dma_copyfrom(struct sst_dsp *sst, dma_addr_t dest_addr,
107 dma_addr_t src_addr, size_t size)
108{
109 return sst_dsp_dma_copy(sst, dest_addr,
110 src_addr | SST_HSW_MASK_DMA_ADDR_DSP, size);
111}
112EXPORT_SYMBOL_GPL(sst_dsp_dma_copyfrom);
113
114/* remove module from memory - callers hold locks */
115static void block_list_remove(struct sst_dsp *dsp,
116 struct list_head *block_list)
117{
118 struct sst_mem_block *block, *tmp;
119 int err;
120
121 /* disable each block */
122 list_for_each_entry(block, block_list, module_list) {
123
124 if (block->ops && block->ops->disable) {
125 err = block->ops->disable(block);
126 if (err < 0)
127 dev_err(dsp->dev,
128 "error: cant disable block %d:%d\n",
129 block->type, block->index);
130 }
131 }
132
133 /* mark each block as free */
134 list_for_each_entry_safe(block, tmp, block_list, module_list) {
135 list_del(&block->module_list);
136 list_move(&block->list, &dsp->free_block_list);
137 dev_dbg(dsp->dev, "block freed %d:%d at offset 0x%x\n",
138 block->type, block->index, block->offset);
139 }
140}
141
142/* prepare the memory block to receive data from host - callers hold locks */
143static int block_list_prepare(struct sst_dsp *dsp,
144 struct list_head *block_list)
145{
146 struct sst_mem_block *block;
147 int ret = 0;
148
149 /* enable each block so that's it'e ready for data */
150 list_for_each_entry(block, block_list, module_list) {
151
152 if (block->ops && block->ops->enable && !block->users) {
153 ret = block->ops->enable(block);
154 if (ret < 0) {
155 dev_err(dsp->dev,
156 "error: cant disable block %d:%d\n",
157 block->type, block->index);
158 goto err;
159 }
160 }
161 }
162 return ret;
163
164err:
165 list_for_each_entry(block, block_list, module_list) {
166 if (block->ops && block->ops->disable)
167 block->ops->disable(block);
168 }
169 return ret;
170}
171
172static struct dw_dma_platform_data dw_pdata = {
173 .is_private = 1,
174 .chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
175 .chan_priority = CHAN_PRIORITY_ASCENDING,
176};
177
178static struct dw_dma_chip *dw_probe(struct device *dev, struct resource *mem,
179 int irq)
180{
181 struct dw_dma_chip *chip;
182 int err;
183
184 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
185 if (!chip)
186 return ERR_PTR(-ENOMEM);
187
188 chip->irq = irq;
189 chip->regs = devm_ioremap_resource(dev, mem);
190 if (IS_ERR(chip->regs))
191 return ERR_CAST(chip->regs);
192
193 err = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(31));
194 if (err)
195 return ERR_PTR(err);
196
197 chip->dev = dev;
198 err = dw_dma_probe(chip, &dw_pdata);
199 if (err)
200 return ERR_PTR(err);
201
202 return chip;
203}
204
205static void dw_remove(struct dw_dma_chip *chip)
206{
207 dw_dma_remove(chip);
208}
209
210static bool dma_chan_filter(struct dma_chan *chan, void *param)
211{
212 struct sst_dsp *dsp = (struct sst_dsp *)param;
213
214 return chan->device->dev == dsp->dma_dev;
215}
34 216
35static void sst_memcpy32(volatile void __iomem *dest, void *src, u32 bytes) 217int sst_dsp_dma_get_channel(struct sst_dsp *dsp, int chan_id)
36{ 218{
37 u32 i; 219 struct sst_dma *dma = dsp->dma;
220 struct dma_slave_config slave;
221 dma_cap_mask_t mask;
222 int ret;
223
224 /* The Intel MID DMA engine driver needs the slave config set but
225 * Synopsis DMA engine driver safely ignores the slave config */
226 dma_cap_zero(mask);
227 dma_cap_set(DMA_SLAVE, mask);
228 dma_cap_set(DMA_MEMCPY, mask);
229
230 dma->ch = dma_request_channel(mask, dma_chan_filter, dsp);
231 if (dma->ch == NULL) {
232 dev_err(dsp->dev, "error: DMA request channel failed\n");
233 return -EIO;
234 }
235
236 memset(&slave, 0, sizeof(slave));
237 slave.direction = DMA_MEM_TO_DEV;
238 slave.src_addr_width =
239 slave.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
240 slave.src_maxburst = slave.dst_maxburst = SST_DSP_DMA_MAX_BURST;
241
242 ret = dmaengine_slave_config(dma->ch, &slave);
243 if (ret) {
244 dev_err(dsp->dev, "error: unable to set DMA slave config %d\n",
245 ret);
246 dma_release_channel(dma->ch);
247 dma->ch = NULL;
248 }
38 249
39 /* copy one 32 bit word at a time as 64 bit access is not supported */ 250 return ret;
40 for (i = 0; i < bytes; i += 4)
41 memcpy_toio(dest + i, src + i, 4);
42} 251}
252EXPORT_SYMBOL_GPL(sst_dsp_dma_get_channel);
253
254void sst_dsp_dma_put_channel(struct sst_dsp *dsp)
255{
256 struct sst_dma *dma = dsp->dma;
257
258 if (!dma->ch)
259 return;
260
261 dma_release_channel(dma->ch);
262 dma->ch = NULL;
263}
264EXPORT_SYMBOL_GPL(sst_dsp_dma_put_channel);
265
266int sst_dma_new(struct sst_dsp *sst)
267{
268 struct sst_pdata *sst_pdata = sst->pdata;
269 struct sst_dma *dma;
270 struct resource mem;
271 const char *dma_dev_name;
272 int ret = 0;
273
274 /* configure the correct platform data for whatever DMA engine
275 * is attached to the ADSP IP. */
276 switch (sst->pdata->dma_engine) {
277 case SST_DMA_TYPE_DW:
278 dma_dev_name = "dw_dmac";
279 break;
280 case SST_DMA_TYPE_MID:
281 dma_dev_name = "Intel MID DMA";
282 break;
283 default:
284 dev_err(sst->dev, "error: invalid DMA engine %d\n",
285 sst->pdata->dma_engine);
286 return -EINVAL;
287 }
288
289 dma = devm_kzalloc(sst->dev, sizeof(struct sst_dma), GFP_KERNEL);
290 if (!dma)
291 return -ENOMEM;
292
293 dma->sst = sst;
294
295 memset(&mem, 0, sizeof(mem));
296
297 mem.start = sst->addr.lpe_base + sst_pdata->dma_base;
298 mem.end = sst->addr.lpe_base + sst_pdata->dma_base + sst_pdata->dma_size - 1;
299 mem.flags = IORESOURCE_MEM;
300
301 /* now register DMA engine device */
302 dma->chip = dw_probe(sst->dma_dev, &mem, sst_pdata->irq);
303 if (IS_ERR(dma->chip)) {
304 dev_err(sst->dev, "error: DMA device register failed\n");
305 ret = PTR_ERR(dma->chip);
306 goto err_dma_dev;
307 }
308
309 sst->dma = dma;
310 sst->fw_use_dma = true;
311 return 0;
312
313err_dma_dev:
314 devm_kfree(sst->dev, dma);
315 return ret;
316}
317EXPORT_SYMBOL(sst_dma_new);
318
319void sst_dma_free(struct sst_dma *dma)
320{
321
322 if (dma == NULL)
323 return;
324
325 if (dma->ch)
326 dma_release_channel(dma->ch);
327
328 if (dma->chip)
329 dw_remove(dma->chip);
330
331}
332EXPORT_SYMBOL(sst_dma_free);
43 333
44/* create new generic firmware object */ 334/* create new generic firmware object */
45struct sst_fw *sst_fw_new(struct sst_dsp *dsp, 335struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
@@ -71,6 +361,12 @@ struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
71 /* copy FW data to DMA-able memory */ 361 /* copy FW data to DMA-able memory */
72 memcpy((void *)sst_fw->dma_buf, (void *)fw->data, fw->size); 362 memcpy((void *)sst_fw->dma_buf, (void *)fw->data, fw->size);
73 363
364 if (dsp->fw_use_dma) {
365 err = sst_dsp_dma_get_channel(dsp, 0);
366 if (err < 0)
367 goto chan_err;
368 }
369
74 /* call core specific FW paser to load FW data into DSP */ 370 /* call core specific FW paser to load FW data into DSP */
75 err = dsp->ops->parse_fw(sst_fw); 371 err = dsp->ops->parse_fw(sst_fw);
76 if (err < 0) { 372 if (err < 0) {
@@ -78,6 +374,9 @@ struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
78 goto parse_err; 374 goto parse_err;
79 } 375 }
80 376
377 if (dsp->fw_use_dma)
378 sst_dsp_dma_put_channel(dsp);
379
81 mutex_lock(&dsp->mutex); 380 mutex_lock(&dsp->mutex);
82 list_add(&sst_fw->list, &dsp->fw_list); 381 list_add(&sst_fw->list, &dsp->fw_list);
83 mutex_unlock(&dsp->mutex); 382 mutex_unlock(&dsp->mutex);
@@ -85,9 +384,13 @@ struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
85 return sst_fw; 384 return sst_fw;
86 385
87parse_err: 386parse_err:
88 dma_free_coherent(dsp->dev, sst_fw->size, 387 if (dsp->fw_use_dma)
388 sst_dsp_dma_put_channel(dsp);
389chan_err:
390 dma_free_coherent(dsp->dma_dev, sst_fw->size,
89 sst_fw->dma_buf, 391 sst_fw->dma_buf,
90 sst_fw->dmable_fw_paddr); 392 sst_fw->dmable_fw_paddr);
393 sst_fw->dma_buf = NULL;
91 kfree(sst_fw); 394 kfree(sst_fw);
92 return NULL; 395 return NULL;
93} 396}
@@ -111,21 +414,37 @@ EXPORT_SYMBOL_GPL(sst_fw_reload);
111 414
112void sst_fw_unload(struct sst_fw *sst_fw) 415void sst_fw_unload(struct sst_fw *sst_fw)
113{ 416{
114 struct sst_dsp *dsp = sst_fw->dsp; 417 struct sst_dsp *dsp = sst_fw->dsp;
115 struct sst_module *module, *tmp; 418 struct sst_module *module, *mtmp;
419 struct sst_module_runtime *runtime, *rtmp;
420
421 dev_dbg(dsp->dev, "unloading firmware\n");
422
423 mutex_lock(&dsp->mutex);
424
425 /* check module by module */
426 list_for_each_entry_safe(module, mtmp, &dsp->module_list, list) {
427 if (module->sst_fw == sst_fw) {
428
429 /* remove runtime modules */
430 list_for_each_entry_safe(runtime, rtmp, &module->runtime_list, list) {
116 431
117 dev_dbg(dsp->dev, "unloading firmware\n"); 432 block_list_remove(dsp, &runtime->block_list);
433 list_del(&runtime->list);
434 kfree(runtime);
435 }
436
437 /* now remove the module */
438 block_list_remove(dsp, &module->block_list);
439 list_del(&module->list);
440 kfree(module);
441 }
442 }
118 443
119 mutex_lock(&dsp->mutex); 444 /* remove all scratch blocks */
120 list_for_each_entry_safe(module, tmp, &dsp->module_list, list) { 445 block_list_remove(dsp, &dsp->scratch_block_list);
121 if (module->sst_fw == sst_fw) {
122 block_module_remove(module);
123 list_del(&module->list);
124 kfree(module);
125 }
126 }
127 446
128 mutex_unlock(&dsp->mutex); 447 mutex_unlock(&dsp->mutex);
129} 448}
130EXPORT_SYMBOL_GPL(sst_fw_unload); 449EXPORT_SYMBOL_GPL(sst_fw_unload);
131 450
@@ -138,7 +457,8 @@ void sst_fw_free(struct sst_fw *sst_fw)
138 list_del(&sst_fw->list); 457 list_del(&sst_fw->list);
139 mutex_unlock(&dsp->mutex); 458 mutex_unlock(&dsp->mutex);
140 459
141 dma_free_coherent(dsp->dma_dev, sst_fw->size, sst_fw->dma_buf, 460 if (sst_fw->dma_buf)
461 dma_free_coherent(dsp->dma_dev, sst_fw->size, sst_fw->dma_buf,
142 sst_fw->dmable_fw_paddr); 462 sst_fw->dmable_fw_paddr);
143 kfree(sst_fw); 463 kfree(sst_fw);
144} 464}
@@ -175,11 +495,11 @@ struct sst_module *sst_module_new(struct sst_fw *sst_fw,
175 sst_module->id = template->id; 495 sst_module->id = template->id;
176 sst_module->dsp = dsp; 496 sst_module->dsp = dsp;
177 sst_module->sst_fw = sst_fw; 497 sst_module->sst_fw = sst_fw;
178 498 sst_module->scratch_size = template->scratch_size;
179 memcpy(&sst_module->s, &template->s, sizeof(struct sst_module_data)); 499 sst_module->persistent_size = template->persistent_size;
180 memcpy(&sst_module->p, &template->p, sizeof(struct sst_module_data));
181 500
182 INIT_LIST_HEAD(&sst_module->block_list); 501 INIT_LIST_HEAD(&sst_module->block_list);
502 INIT_LIST_HEAD(&sst_module->runtime_list);
183 503
184 mutex_lock(&dsp->mutex); 504 mutex_lock(&dsp->mutex);
185 list_add(&sst_module->list, &dsp->module_list); 505 list_add(&sst_module->list, &dsp->module_list);
@@ -202,73 +522,122 @@ void sst_module_free(struct sst_module *sst_module)
202} 522}
203EXPORT_SYMBOL_GPL(sst_module_free); 523EXPORT_SYMBOL_GPL(sst_module_free);
204 524
205static struct sst_mem_block *find_block(struct sst_dsp *dsp, int type, 525struct sst_module_runtime *sst_module_runtime_new(struct sst_module *module,
206 u32 offset) 526 int id, void *private)
527{
528 struct sst_dsp *dsp = module->dsp;
529 struct sst_module_runtime *runtime;
530
531 runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
532 if (runtime == NULL)
533 return NULL;
534
535 runtime->id = id;
536 runtime->dsp = dsp;
537 runtime->module = module;
538 INIT_LIST_HEAD(&runtime->block_list);
539
540 mutex_lock(&dsp->mutex);
541 list_add(&runtime->list, &module->runtime_list);
542 mutex_unlock(&dsp->mutex);
543
544 return runtime;
545}
546EXPORT_SYMBOL_GPL(sst_module_runtime_new);
547
548void sst_module_runtime_free(struct sst_module_runtime *runtime)
549{
550 struct sst_dsp *dsp = runtime->dsp;
551
552 mutex_lock(&dsp->mutex);
553 list_del(&runtime->list);
554 mutex_unlock(&dsp->mutex);
555
556 kfree(runtime);
557}
558EXPORT_SYMBOL_GPL(sst_module_runtime_free);
559
560static struct sst_mem_block *find_block(struct sst_dsp *dsp,
561 struct sst_block_allocator *ba)
207{ 562{
208 struct sst_mem_block *block; 563 struct sst_mem_block *block;
209 564
210 list_for_each_entry(block, &dsp->free_block_list, list) { 565 list_for_each_entry(block, &dsp->free_block_list, list) {
211 if (block->type == type && block->offset == offset) 566 if (block->type == ba->type && block->offset == ba->offset)
212 return block; 567 return block;
213 } 568 }
214 569
215 return NULL; 570 return NULL;
216} 571}
217 572
218static int block_alloc_contiguous(struct sst_module *module, 573/* Block allocator must be on block boundary */
219 struct sst_module_data *data, u32 offset, int size) 574static int block_alloc_contiguous(struct sst_dsp *dsp,
575 struct sst_block_allocator *ba, struct list_head *block_list)
220{ 576{
221 struct list_head tmp = LIST_HEAD_INIT(tmp); 577 struct list_head tmp = LIST_HEAD_INIT(tmp);
222 struct sst_dsp *dsp = module->dsp;
223 struct sst_mem_block *block; 578 struct sst_mem_block *block;
579 u32 block_start = SST_HSW_BLOCK_ANY;
580 int size = ba->size, offset = ba->offset;
581
582 while (ba->size > 0) {
224 583
225 while (size > 0) { 584 block = find_block(dsp, ba);
226 block = find_block(dsp, data->type, offset);
227 if (!block) { 585 if (!block) {
228 list_splice(&tmp, &dsp->free_block_list); 586 list_splice(&tmp, &dsp->free_block_list);
587
588 ba->size = size;
589 ba->offset = offset;
229 return -ENOMEM; 590 return -ENOMEM;
230 } 591 }
231 592
232 list_move_tail(&block->list, &tmp); 593 list_move_tail(&block->list, &tmp);
233 offset += block->size; 594 ba->offset += block->size;
234 size -= block->size; 595 ba->size -= block->size;
235 } 596 }
597 ba->size = size;
598 ba->offset = offset;
599
600 list_for_each_entry(block, &tmp, list) {
601
602 if (block->offset < block_start)
603 block_start = block->offset;
236 604
237 list_for_each_entry(block, &tmp, list) 605 list_add(&block->module_list, block_list);
238 list_add(&block->module_list, &module->block_list); 606
607 dev_dbg(dsp->dev, "block allocated %d:%d at offset 0x%x\n",
608 block->type, block->index, block->offset);
609 }
239 610
240 list_splice(&tmp, &dsp->used_block_list); 611 list_splice(&tmp, &dsp->used_block_list);
241 return 0; 612 return 0;
242} 613}
243 614
244/* allocate free DSP blocks for module data - callers hold locks */ 615/* allocate first free DSP blocks for data - callers hold locks */
245static int block_alloc(struct sst_module *module, 616static int block_alloc(struct sst_dsp *dsp, struct sst_block_allocator *ba,
246 struct sst_module_data *data) 617 struct list_head *block_list)
247{ 618{
248 struct sst_dsp *dsp = module->dsp;
249 struct sst_mem_block *block, *tmp; 619 struct sst_mem_block *block, *tmp;
250 int ret = 0; 620 int ret = 0;
251 621
252 if (data->size == 0) 622 if (ba->size == 0)
253 return 0; 623 return 0;
254 624
255 /* find first free whole blocks that can hold module */ 625 /* find first free whole blocks that can hold module */
256 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) { 626 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) {
257 627
258 /* ignore blocks with wrong type */ 628 /* ignore blocks with wrong type */
259 if (block->type != data->type) 629 if (block->type != ba->type)
260 continue; 630 continue;
261 631
262 if (data->size > block->size) 632 if (ba->size > block->size)
263 continue; 633 continue;
264 634
265 data->offset = block->offset; 635 ba->offset = block->offset;
266 block->data_type = data->data_type; 636 block->bytes_used = ba->size % block->size;
267 block->bytes_used = data->size % block->size; 637 list_add(&block->module_list, block_list);
268 list_add(&block->module_list, &module->block_list);
269 list_move(&block->list, &dsp->used_block_list); 638 list_move(&block->list, &dsp->used_block_list);
270 dev_dbg(dsp->dev, " *module %d added block %d:%d\n", 639 dev_dbg(dsp->dev, "block allocated %d:%d at offset 0x%x\n",
271 module->id, block->type, block->index); 640 block->type, block->index, block->offset);
272 return 0; 641 return 0;
273 } 642 }
274 643
@@ -276,15 +645,19 @@ static int block_alloc(struct sst_module *module,
276 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) { 645 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) {
277 646
278 /* ignore blocks with wrong type */ 647 /* ignore blocks with wrong type */
279 if (block->type != data->type) 648 if (block->type != ba->type)
280 continue; 649 continue;
281 650
282 /* do we span > 1 blocks */ 651 /* do we span > 1 blocks */
283 if (data->size > block->size) { 652 if (ba->size > block->size) {
284 ret = block_alloc_contiguous(module, data, 653
285 block->offset, data->size); 654 /* align ba to block boundary */
655 ba->offset = block->offset;
656
657 ret = block_alloc_contiguous(dsp, ba, block_list);
286 if (ret == 0) 658 if (ret == 0)
287 return ret; 659 return ret;
660
288 } 661 }
289 } 662 }
290 663
@@ -292,93 +665,74 @@ static int block_alloc(struct sst_module *module,
292 return -ENOMEM; 665 return -ENOMEM;
293} 666}
294 667
295/* remove module from memory - callers hold locks */ 668int sst_alloc_blocks(struct sst_dsp *dsp, struct sst_block_allocator *ba,
296static void block_module_remove(struct sst_module *module) 669 struct list_head *block_list)
297{ 670{
298 struct sst_mem_block *block, *tmp; 671 int ret;
299 struct sst_dsp *dsp = module->dsp;
300 int err;
301 672
302 /* disable each block */ 673 dev_dbg(dsp->dev, "block request 0x%x bytes at offset 0x%x type %d\n",
303 list_for_each_entry(block, &module->block_list, module_list) { 674 ba->size, ba->offset, ba->type);
304 675
305 if (block->ops && block->ops->disable) { 676 mutex_lock(&dsp->mutex);
306 err = block->ops->disable(block);
307 if (err < 0)
308 dev_err(dsp->dev,
309 "error: cant disable block %d:%d\n",
310 block->type, block->index);
311 }
312 }
313 677
314 /* mark each block as free */ 678 ret = block_alloc(dsp, ba, block_list);
315 list_for_each_entry_safe(block, tmp, &module->block_list, module_list) { 679 if (ret < 0) {
316 list_del(&block->module_list); 680 dev_err(dsp->dev, "error: can't alloc blocks %d\n", ret);
317 list_move(&block->list, &dsp->free_block_list); 681 goto out;
318 } 682 }
319}
320
321/* prepare the memory block to receive data from host - callers hold locks */
322static int block_module_prepare(struct sst_module *module)
323{
324 struct sst_mem_block *block;
325 int ret = 0;
326 683
327 /* enable each block so that's it'e ready for module P/S data */ 684 /* prepare DSP blocks for module usage */
328 list_for_each_entry(block, &module->block_list, module_list) { 685 ret = block_list_prepare(dsp, block_list);
686 if (ret < 0)
687 dev_err(dsp->dev, "error: prepare failed\n");
329 688
330 if (block->ops && block->ops->enable) { 689out:
331 ret = block->ops->enable(block); 690 mutex_unlock(&dsp->mutex);
332 if (ret < 0) {
333 dev_err(module->dsp->dev,
334 "error: cant disable block %d:%d\n",
335 block->type, block->index);
336 goto err;
337 }
338 }
339 }
340 return ret; 691 return ret;
692}
693EXPORT_SYMBOL_GPL(sst_alloc_blocks);
341 694
342err: 695int sst_free_blocks(struct sst_dsp *dsp, struct list_head *block_list)
343 list_for_each_entry(block, &module->block_list, module_list) { 696{
344 if (block->ops && block->ops->disable) 697 mutex_lock(&dsp->mutex);
345 block->ops->disable(block); 698 block_list_remove(dsp, block_list);
346 } 699 mutex_unlock(&dsp->mutex);
347 return ret; 700 return 0;
348} 701}
702EXPORT_SYMBOL_GPL(sst_free_blocks);
349 703
350/* allocate memory blocks for static module addresses - callers hold locks */ 704/* allocate memory blocks for static module addresses - callers hold locks */
351static int block_alloc_fixed(struct sst_module *module, 705static int block_alloc_fixed(struct sst_dsp *dsp, struct sst_block_allocator *ba,
352 struct sst_module_data *data) 706 struct list_head *block_list)
353{ 707{
354 struct sst_dsp *dsp = module->dsp;
355 struct sst_mem_block *block, *tmp; 708 struct sst_mem_block *block, *tmp;
356 u32 end = data->offset + data->size, block_end; 709 u32 end = ba->offset + ba->size, block_end;
357 int err; 710 int err;
358 711
359 /* only IRAM/DRAM blocks are managed */ 712 /* only IRAM/DRAM blocks are managed */
360 if (data->type != SST_MEM_IRAM && data->type != SST_MEM_DRAM) 713 if (ba->type != SST_MEM_IRAM && ba->type != SST_MEM_DRAM)
361 return 0; 714 return 0;
362 715
363 /* are blocks already attached to this module */ 716 /* are blocks already attached to this module */
364 list_for_each_entry_safe(block, tmp, &module->block_list, module_list) { 717 list_for_each_entry_safe(block, tmp, block_list, module_list) {
365 718
366 /* force compacting mem blocks of the same data_type */ 719 /* ignore blocks with wrong type */
367 if (block->data_type != data->data_type) 720 if (block->type != ba->type)
368 continue; 721 continue;
369 722
370 block_end = block->offset + block->size; 723 block_end = block->offset + block->size;
371 724
372 /* find block that holds section */ 725 /* find block that holds section */
373 if (data->offset >= block->offset && end < block_end) 726 if (ba->offset >= block->offset && end <= block_end)
374 return 0; 727 return 0;
375 728
376 /* does block span more than 1 section */ 729 /* does block span more than 1 section */
377 if (data->offset >= block->offset && data->offset < block_end) { 730 if (ba->offset >= block->offset && ba->offset < block_end) {
378 731
379 err = block_alloc_contiguous(module, data, 732 /* align ba to block boundary */
380 block->offset + block->size, 733 ba->size -= block_end - ba->offset;
381 data->size - block->size); 734 ba->offset = block_end;
735 err = block_alloc_contiguous(dsp, ba, block_list);
382 if (err < 0) 736 if (err < 0)
383 return -ENOMEM; 737 return -ENOMEM;
384 738
@@ -391,82 +745,270 @@ static int block_alloc_fixed(struct sst_module *module,
391 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) { 745 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) {
392 block_end = block->offset + block->size; 746 block_end = block->offset + block->size;
393 747
748 /* ignore blocks with wrong type */
749 if (block->type != ba->type)
750 continue;
751
394 /* find block that holds section */ 752 /* find block that holds section */
395 if (data->offset >= block->offset && end < block_end) { 753 if (ba->offset >= block->offset && end <= block_end) {
396 754
397 /* add block */ 755 /* add block */
398 block->data_type = data->data_type;
399 list_move(&block->list, &dsp->used_block_list); 756 list_move(&block->list, &dsp->used_block_list);
400 list_add(&block->module_list, &module->block_list); 757 list_add(&block->module_list, block_list);
758 dev_dbg(dsp->dev, "block allocated %d:%d at offset 0x%x\n",
759 block->type, block->index, block->offset);
401 return 0; 760 return 0;
402 } 761 }
403 762
404 /* does block span more than 1 section */ 763 /* does block span more than 1 section */
405 if (data->offset >= block->offset && data->offset < block_end) { 764 if (ba->offset >= block->offset && ba->offset < block_end) {
406 765
407 err = block_alloc_contiguous(module, data, 766 /* align ba to block boundary */
408 block->offset, data->size); 767 ba->offset = block->offset;
768
769 err = block_alloc_contiguous(dsp, ba, block_list);
409 if (err < 0) 770 if (err < 0)
410 return -ENOMEM; 771 return -ENOMEM;
411 772
412 return 0; 773 return 0;
413 } 774 }
414
415 } 775 }
416 776
417 return -ENOMEM; 777 return -ENOMEM;
418} 778}
419 779
420/* Load fixed module data into DSP memory blocks */ 780/* Load fixed module data into DSP memory blocks */
421int sst_module_insert_fixed_block(struct sst_module *module, 781int sst_module_alloc_blocks(struct sst_module *module)
422 struct sst_module_data *data)
423{ 782{
424 struct sst_dsp *dsp = module->dsp; 783 struct sst_dsp *dsp = module->dsp;
784 struct sst_fw *sst_fw = module->sst_fw;
785 struct sst_block_allocator ba;
425 int ret; 786 int ret;
426 787
788 ba.size = module->size;
789 ba.type = module->type;
790 ba.offset = module->offset;
791
792 dev_dbg(dsp->dev, "block request 0x%x bytes at offset 0x%x type %d\n",
793 ba.size, ba.offset, ba.type);
794
427 mutex_lock(&dsp->mutex); 795 mutex_lock(&dsp->mutex);
428 796
429 /* alloc blocks that includes this section */ 797 /* alloc blocks that includes this section */
430 ret = block_alloc_fixed(module, data); 798 ret = block_alloc_fixed(dsp, &ba, &module->block_list);
431 if (ret < 0) { 799 if (ret < 0) {
432 dev_err(dsp->dev, 800 dev_err(dsp->dev,
433 "error: no free blocks for section at offset 0x%x size 0x%x\n", 801 "error: no free blocks for section at offset 0x%x size 0x%x\n",
434 data->offset, data->size); 802 module->offset, module->size);
435 mutex_unlock(&dsp->mutex); 803 mutex_unlock(&dsp->mutex);
436 return -ENOMEM; 804 return -ENOMEM;
437 } 805 }
438 806
439 /* prepare DSP blocks for module copy */ 807 /* prepare DSP blocks for module copy */
440 ret = block_module_prepare(module); 808 ret = block_list_prepare(dsp, &module->block_list);
441 if (ret < 0) { 809 if (ret < 0) {
442 dev_err(dsp->dev, "error: fw module prepare failed\n"); 810 dev_err(dsp->dev, "error: fw module prepare failed\n");
443 goto err; 811 goto err;
444 } 812 }
445 813
446 /* copy partial module data to blocks */ 814 /* copy partial module data to blocks */
447 sst_memcpy32(dsp->addr.lpe + data->offset, data->data, data->size); 815 if (dsp->fw_use_dma) {
816 ret = sst_dsp_dma_copyto(dsp,
817 dsp->addr.lpe_base + module->offset,
818 sst_fw->dmable_fw_paddr + module->data_offset,
819 module->size);
820 if (ret < 0) {
821 dev_err(dsp->dev, "error: module copy failed\n");
822 goto err;
823 }
824 } else
825 sst_memcpy32(dsp->addr.lpe + module->offset, module->data,
826 module->size);
448 827
449 mutex_unlock(&dsp->mutex); 828 mutex_unlock(&dsp->mutex);
450 return ret; 829 return ret;
451 830
452err: 831err:
453 block_module_remove(module); 832 block_list_remove(dsp, &module->block_list);
454 mutex_unlock(&dsp->mutex); 833 mutex_unlock(&dsp->mutex);
455 return ret; 834 return ret;
456} 835}
457EXPORT_SYMBOL_GPL(sst_module_insert_fixed_block); 836EXPORT_SYMBOL_GPL(sst_module_alloc_blocks);
458 837
459/* Unload entire module from DSP memory */ 838/* Unload entire module from DSP memory */
460int sst_block_module_remove(struct sst_module *module) 839int sst_module_free_blocks(struct sst_module *module)
461{ 840{
462 struct sst_dsp *dsp = module->dsp; 841 struct sst_dsp *dsp = module->dsp;
463 842
464 mutex_lock(&dsp->mutex); 843 mutex_lock(&dsp->mutex);
465 block_module_remove(module); 844 block_list_remove(dsp, &module->block_list);
466 mutex_unlock(&dsp->mutex); 845 mutex_unlock(&dsp->mutex);
467 return 0; 846 return 0;
468} 847}
469EXPORT_SYMBOL_GPL(sst_block_module_remove); 848EXPORT_SYMBOL_GPL(sst_module_free_blocks);
849
850int sst_module_runtime_alloc_blocks(struct sst_module_runtime *runtime,
851 int offset)
852{
853 struct sst_dsp *dsp = runtime->dsp;
854 struct sst_module *module = runtime->module;
855 struct sst_block_allocator ba;
856 int ret;
857
858 if (module->persistent_size == 0)
859 return 0;
860
861 ba.size = module->persistent_size;
862 ba.type = SST_MEM_DRAM;
863
864 mutex_lock(&dsp->mutex);
865
866 /* do we need to allocate at a fixed address ? */
867 if (offset != 0) {
868
869 ba.offset = offset;
870
871 dev_dbg(dsp->dev, "persistent fixed block request 0x%x bytes type %d offset 0x%x\n",
872 ba.size, ba.type, ba.offset);
873
874 /* alloc blocks that includes this section */
875 ret = block_alloc_fixed(dsp, &ba, &runtime->block_list);
876
877 } else {
878 dev_dbg(dsp->dev, "persistent block request 0x%x bytes type %d\n",
879 ba.size, ba.type);
880
881 /* alloc blocks that includes this section */
882 ret = block_alloc(dsp, &ba, &runtime->block_list);
883 }
884 if (ret < 0) {
885 dev_err(dsp->dev,
886 "error: no free blocks for runtime module size 0x%x\n",
887 module->persistent_size);
888 mutex_unlock(&dsp->mutex);
889 return -ENOMEM;
890 }
891 runtime->persistent_offset = ba.offset;
892
893 /* prepare DSP blocks for module copy */
894 ret = block_list_prepare(dsp, &runtime->block_list);
895 if (ret < 0) {
896 dev_err(dsp->dev, "error: runtime block prepare failed\n");
897 goto err;
898 }
899
900 mutex_unlock(&dsp->mutex);
901 return ret;
902
903err:
904 block_list_remove(dsp, &module->block_list);
905 mutex_unlock(&dsp->mutex);
906 return ret;
907}
908EXPORT_SYMBOL_GPL(sst_module_runtime_alloc_blocks);
909
910int sst_module_runtime_free_blocks(struct sst_module_runtime *runtime)
911{
912 struct sst_dsp *dsp = runtime->dsp;
913
914 mutex_lock(&dsp->mutex);
915 block_list_remove(dsp, &runtime->block_list);
916 mutex_unlock(&dsp->mutex);
917 return 0;
918}
919EXPORT_SYMBOL_GPL(sst_module_runtime_free_blocks);
920
921int sst_module_runtime_save(struct sst_module_runtime *runtime,
922 struct sst_module_runtime_context *context)
923{
924 struct sst_dsp *dsp = runtime->dsp;
925 struct sst_module *module = runtime->module;
926 int ret = 0;
927
928 dev_dbg(dsp->dev, "saving runtime %d memory at 0x%x size 0x%x\n",
929 runtime->id, runtime->persistent_offset,
930 module->persistent_size);
931
932 context->buffer = dma_alloc_coherent(dsp->dma_dev,
933 module->persistent_size,
934 &context->dma_buffer, GFP_DMA | GFP_KERNEL);
935 if (!context->buffer) {
936 dev_err(dsp->dev, "error: DMA context alloc failed\n");
937 return -ENOMEM;
938 }
939
940 mutex_lock(&dsp->mutex);
941
942 if (dsp->fw_use_dma) {
943
944 ret = sst_dsp_dma_get_channel(dsp, 0);
945 if (ret < 0)
946 goto err;
947
948 ret = sst_dsp_dma_copyfrom(dsp, context->dma_buffer,
949 dsp->addr.lpe_base + runtime->persistent_offset,
950 module->persistent_size);
951 sst_dsp_dma_put_channel(dsp);
952 if (ret < 0) {
953 dev_err(dsp->dev, "error: context copy failed\n");
954 goto err;
955 }
956 } else
957 sst_memcpy32(context->buffer, dsp->addr.lpe +
958 runtime->persistent_offset,
959 module->persistent_size);
960
961err:
962 mutex_unlock(&dsp->mutex);
963 return ret;
964}
965EXPORT_SYMBOL_GPL(sst_module_runtime_save);
966
967int sst_module_runtime_restore(struct sst_module_runtime *runtime,
968 struct sst_module_runtime_context *context)
969{
970 struct sst_dsp *dsp = runtime->dsp;
971 struct sst_module *module = runtime->module;
972 int ret = 0;
973
974 dev_dbg(dsp->dev, "restoring runtime %d memory at 0x%x size 0x%x\n",
975 runtime->id, runtime->persistent_offset,
976 module->persistent_size);
977
978 mutex_lock(&dsp->mutex);
979
980 if (!context->buffer) {
981 dev_info(dsp->dev, "no context buffer need to restore!\n");
982 goto err;
983 }
984
985 if (dsp->fw_use_dma) {
986
987 ret = sst_dsp_dma_get_channel(dsp, 0);
988 if (ret < 0)
989 goto err;
990
991 ret = sst_dsp_dma_copyto(dsp,
992 dsp->addr.lpe_base + runtime->persistent_offset,
993 context->dma_buffer, module->persistent_size);
994 sst_dsp_dma_put_channel(dsp);
995 if (ret < 0) {
996 dev_err(dsp->dev, "error: module copy failed\n");
997 goto err;
998 }
999 } else
1000 sst_memcpy32(dsp->addr.lpe + runtime->persistent_offset,
1001 context->buffer, module->persistent_size);
1002
1003 dma_free_coherent(dsp->dma_dev, module->persistent_size,
1004 context->buffer, context->dma_buffer);
1005 context->buffer = NULL;
1006
1007err:
1008 mutex_unlock(&dsp->mutex);
1009 return ret;
1010}
1011EXPORT_SYMBOL_GPL(sst_module_runtime_restore);
470 1012
471/* register a DSP memory block for use with FW based modules */ 1013/* register a DSP memory block for use with FW based modules */
472struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset, 1014struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
@@ -519,80 +1061,84 @@ void sst_mem_block_unregister_all(struct sst_dsp *dsp)
519EXPORT_SYMBOL_GPL(sst_mem_block_unregister_all); 1061EXPORT_SYMBOL_GPL(sst_mem_block_unregister_all);
520 1062
521/* allocate scratch buffer blocks */ 1063/* allocate scratch buffer blocks */
522struct sst_module *sst_mem_block_alloc_scratch(struct sst_dsp *dsp) 1064int sst_block_alloc_scratch(struct sst_dsp *dsp)
523{ 1065{
524 struct sst_module *sst_module, *scratch; 1066 struct sst_module *module;
525 struct sst_mem_block *block, *tmp; 1067 struct sst_block_allocator ba;
526 u32 block_size; 1068 int ret;
527 int ret = 0;
528
529 scratch = kzalloc(sizeof(struct sst_module), GFP_KERNEL);
530 if (scratch == NULL)
531 return NULL;
532 1069
533 mutex_lock(&dsp->mutex); 1070 mutex_lock(&dsp->mutex);
534 1071
535 /* calculate required scratch size */ 1072 /* calculate required scratch size */
536 list_for_each_entry(sst_module, &dsp->module_list, list) { 1073 dsp->scratch_size = 0;
537 if (scratch->s.size < sst_module->s.size) 1074 list_for_each_entry(module, &dsp->module_list, list) {
538 scratch->s.size = sst_module->s.size; 1075 dev_dbg(dsp->dev, "module %d scratch req 0x%x bytes\n",
1076 module->id, module->scratch_size);
1077 if (dsp->scratch_size < module->scratch_size)
1078 dsp->scratch_size = module->scratch_size;
539 } 1079 }
540 1080
541 dev_dbg(dsp->dev, "scratch buffer required is %d bytes\n", 1081 dev_dbg(dsp->dev, "scratch buffer required is 0x%x bytes\n",
542 scratch->s.size); 1082 dsp->scratch_size);
543
544 /* init scratch module */
545 scratch->dsp = dsp;
546 scratch->s.type = SST_MEM_DRAM;
547 scratch->s.data_type = SST_DATA_S;
548 INIT_LIST_HEAD(&scratch->block_list);
549 1083
550 /* check free blocks before looking at used blocks for space */ 1084 if (dsp->scratch_size == 0) {
551 if (!list_empty(&dsp->free_block_list)) 1085 dev_info(dsp->dev, "no modules need scratch buffer\n");
552 block = list_first_entry(&dsp->free_block_list, 1086 mutex_unlock(&dsp->mutex);
553 struct sst_mem_block, list); 1087 return 0;
554 else 1088 }
555 block = list_first_entry(&dsp->used_block_list,
556 struct sst_mem_block, list);
557 block_size = block->size;
558 1089
559 /* allocate blocks for module scratch buffers */ 1090 /* allocate blocks for module scratch buffers */
560 dev_dbg(dsp->dev, "allocating scratch blocks\n"); 1091 dev_dbg(dsp->dev, "allocating scratch blocks\n");
561 ret = block_alloc(scratch, &scratch->s); 1092
1093 ba.size = dsp->scratch_size;
1094 ba.type = SST_MEM_DRAM;
1095
1096 /* do we need to allocate at fixed offset */
1097 if (dsp->scratch_offset != 0) {
1098
1099 dev_dbg(dsp->dev, "block request 0x%x bytes type %d at 0x%x\n",
1100 ba.size, ba.type, ba.offset);
1101
1102 ba.offset = dsp->scratch_offset;
1103
1104 /* alloc blocks that includes this section */
1105 ret = block_alloc_fixed(dsp, &ba, &dsp->scratch_block_list);
1106
1107 } else {
1108 dev_dbg(dsp->dev, "block request 0x%x bytes type %d\n",
1109 ba.size, ba.type);
1110
1111 ba.offset = 0;
1112 ret = block_alloc(dsp, &ba, &dsp->scratch_block_list);
1113 }
562 if (ret < 0) { 1114 if (ret < 0) {
563 dev_err(dsp->dev, "error: can't alloc scratch blocks\n"); 1115 dev_err(dsp->dev, "error: can't alloc scratch blocks\n");
564 goto err; 1116 mutex_unlock(&dsp->mutex);
1117 return ret;
565 } 1118 }
566 1119
567 /* assign the same offset of scratch to each module */ 1120 ret = block_list_prepare(dsp, &dsp->scratch_block_list);
568 list_for_each_entry(sst_module, &dsp->module_list, list) 1121 if (ret < 0) {
569 sst_module->s.offset = scratch->s.offset; 1122 dev_err(dsp->dev, "error: scratch block prepare failed\n");
570 1123 mutex_unlock(&dsp->mutex);
571 mutex_unlock(&dsp->mutex); 1124 return ret;
572 return scratch; 1125 }
573 1126
574err: 1127 /* assign the same offset of scratch to each module */
575 list_for_each_entry_safe(block, tmp, &scratch->block_list, module_list) 1128 dsp->scratch_offset = ba.offset;
576 list_del(&block->module_list);
577 mutex_unlock(&dsp->mutex); 1129 mutex_unlock(&dsp->mutex);
578 return NULL; 1130 return dsp->scratch_size;
579} 1131}
580EXPORT_SYMBOL_GPL(sst_mem_block_alloc_scratch); 1132EXPORT_SYMBOL_GPL(sst_block_alloc_scratch);
581 1133
582/* free all scratch blocks */ 1134/* free all scratch blocks */
583void sst_mem_block_free_scratch(struct sst_dsp *dsp, 1135void sst_block_free_scratch(struct sst_dsp *dsp)
584 struct sst_module *scratch)
585{ 1136{
586 struct sst_mem_block *block, *tmp;
587
588 mutex_lock(&dsp->mutex); 1137 mutex_lock(&dsp->mutex);
589 1138 block_list_remove(dsp, &dsp->scratch_block_list);
590 list_for_each_entry_safe(block, tmp, &scratch->block_list, module_list)
591 list_del(&block->module_list);
592
593 mutex_unlock(&dsp->mutex); 1139 mutex_unlock(&dsp->mutex);
594} 1140}
595EXPORT_SYMBOL_GPL(sst_mem_block_free_scratch); 1141EXPORT_SYMBOL_GPL(sst_block_free_scratch);
596 1142
597/* get a module from it's unique ID */ 1143/* get a module from it's unique ID */
598struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id) 1144struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id)
@@ -612,3 +1158,40 @@ struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id)
612 return NULL; 1158 return NULL;
613} 1159}
614EXPORT_SYMBOL_GPL(sst_module_get_from_id); 1160EXPORT_SYMBOL_GPL(sst_module_get_from_id);
1161
1162struct sst_module_runtime *sst_module_runtime_get_from_id(
1163 struct sst_module *module, u32 id)
1164{
1165 struct sst_module_runtime *runtime;
1166 struct sst_dsp *dsp = module->dsp;
1167
1168 mutex_lock(&dsp->mutex);
1169
1170 list_for_each_entry(runtime, &module->runtime_list, list) {
1171 if (runtime->id == id) {
1172 mutex_unlock(&dsp->mutex);
1173 return runtime;
1174 }
1175 }
1176
1177 mutex_unlock(&dsp->mutex);
1178 return NULL;
1179}
1180EXPORT_SYMBOL_GPL(sst_module_runtime_get_from_id);
1181
1182/* returns block address in DSP address space */
1183u32 sst_dsp_get_offset(struct sst_dsp *dsp, u32 offset,
1184 enum sst_mem_type type)
1185{
1186 switch (type) {
1187 case SST_MEM_IRAM:
1188 return offset - dsp->addr.iram_offset +
1189 dsp->addr.dsp_iram_offset;
1190 case SST_MEM_DRAM:
1191 return offset - dsp->addr.dram_offset +
1192 dsp->addr.dsp_dram_offset;
1193 default:
1194 return 0;
1195 }
1196}
1197EXPORT_SYMBOL_GPL(sst_dsp_get_offset);
diff --git a/sound/soc/intel/sst-haswell-dsp.c b/sound/soc/intel/sst-haswell-dsp.c
index 4b6c163c10ff..57039b00efc2 100644
--- a/sound/soc/intel/sst-haswell-dsp.c
+++ b/sound/soc/intel/sst-haswell-dsp.c
@@ -42,6 +42,10 @@
42#define SST_LP_SHIM_OFFSET 0xE7000 42#define SST_LP_SHIM_OFFSET 0xE7000
43#define SST_WPT_IRAM_OFFSET 0xA0000 43#define SST_WPT_IRAM_OFFSET 0xA0000
44#define SST_LP_IRAM_OFFSET 0x80000 44#define SST_LP_IRAM_OFFSET 0x80000
45#define SST_WPT_DSP_DRAM_OFFSET 0x400000
46#define SST_WPT_DSP_IRAM_OFFSET 0x00000
47#define SST_LPT_DSP_DRAM_OFFSET 0x400000
48#define SST_LPT_DSP_IRAM_OFFSET 0x00000
45 49
46#define SST_SHIM_PM_REG 0x84 50#define SST_SHIM_PM_REG 0x84
47 51
@@ -86,9 +90,8 @@ static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
86{ 90{
87 struct dma_block_info *block; 91 struct dma_block_info *block;
88 struct sst_module *mod; 92 struct sst_module *mod;
89 struct sst_module_data block_data;
90 struct sst_module_template template; 93 struct sst_module_template template;
91 int count; 94 int count, ret;
92 void __iomem *ram; 95 void __iomem *ram;
93 96
94 /* TODO: allowed module types need to be configurable */ 97 /* TODO: allowed module types need to be configurable */
@@ -109,13 +112,9 @@ static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
109 112
110 memset(&template, 0, sizeof(template)); 113 memset(&template, 0, sizeof(template));
111 template.id = module->type; 114 template.id = module->type;
112 template.entry = module->entry_point; 115 template.entry = module->entry_point - 4;
113 template.p.size = module->info.persistent_size; 116 template.persistent_size = module->info.persistent_size;
114 template.p.type = SST_MEM_DRAM; 117 template.scratch_size = module->info.scratch_size;
115 template.p.data_type = SST_DATA_P;
116 template.s.size = module->info.scratch_size;
117 template.s.type = SST_MEM_DRAM;
118 template.s.data_type = SST_DATA_S;
119 118
120 mod = sst_module_new(fw, &template, NULL); 119 mod = sst_module_new(fw, &template, NULL);
121 if (mod == NULL) 120 if (mod == NULL)
@@ -135,14 +134,14 @@ static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
135 switch (block->type) { 134 switch (block->type) {
136 case SST_HSW_IRAM: 135 case SST_HSW_IRAM:
137 ram = dsp->addr.lpe; 136 ram = dsp->addr.lpe;
138 block_data.offset = 137 mod->offset =
139 block->ram_offset + dsp->addr.iram_offset; 138 block->ram_offset + dsp->addr.iram_offset;
140 block_data.type = SST_MEM_IRAM; 139 mod->type = SST_MEM_IRAM;
141 break; 140 break;
142 case SST_HSW_DRAM: 141 case SST_HSW_DRAM:
143 ram = dsp->addr.lpe; 142 ram = dsp->addr.lpe;
144 block_data.offset = block->ram_offset; 143 mod->offset = block->ram_offset;
145 block_data.type = SST_MEM_DRAM; 144 mod->type = SST_MEM_DRAM;
146 break; 145 break;
147 default: 146 default:
148 dev_err(dsp->dev, "error: bad type 0x%x for block 0x%x\n", 147 dev_err(dsp->dev, "error: bad type 0x%x for block 0x%x\n",
@@ -151,30 +150,34 @@ static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
151 return -EINVAL; 150 return -EINVAL;
152 } 151 }
153 152
154 block_data.size = block->size; 153 mod->size = block->size;
155 block_data.data_type = SST_DATA_M; 154 mod->data = (void *)block + sizeof(*block);
156 block_data.data = (void *)block + sizeof(*block); 155 mod->data_offset = mod->data - fw->dma_buf;
157 block_data.data_offset = block_data.data - fw->dma_buf;
158 156
159 dev_dbg(dsp->dev, "copy firmware block %d type 0x%x " 157 dev_dbg(dsp->dev, "module block %d type 0x%x "
160 "size 0x%x ==> ram %p offset 0x%x\n", 158 "size 0x%x ==> ram %p offset 0x%x\n",
161 count, block->type, block->size, ram, 159 count, mod->type, block->size, ram,
162 block->ram_offset); 160 block->ram_offset);
163 161
164 sst_module_insert_fixed_block(mod, &block_data); 162 ret = sst_module_alloc_blocks(mod);
163 if (ret < 0) {
164 dev_err(dsp->dev, "error: could not allocate blocks for module %d\n",
165 count);
166 sst_module_free(mod);
167 return ret;
168 }
165 169
166 block = (void *)block + sizeof(*block) + block->size; 170 block = (void *)block + sizeof(*block) + block->size;
167 } 171 }
172
168 return 0; 173 return 0;
169} 174}
170 175
171static int hsw_parse_fw_image(struct sst_fw *sst_fw) 176static int hsw_parse_fw_image(struct sst_fw *sst_fw)
172{ 177{
173 struct fw_header *header; 178 struct fw_header *header;
174 struct sst_module *scratch;
175 struct fw_module_header *module; 179 struct fw_module_header *module;
176 struct sst_dsp *dsp = sst_fw->dsp; 180 struct sst_dsp *dsp = sst_fw->dsp;
177 struct sst_hsw *hsw = sst_fw->private;
178 int ret, count; 181 int ret, count;
179 182
180 /* Read the header information from the data pointer */ 183 /* Read the header information from the data pointer */
@@ -204,12 +207,8 @@ static int hsw_parse_fw_image(struct sst_fw *sst_fw)
204 module = (void *)module + sizeof(*module) + module->mod_size; 207 module = (void *)module + sizeof(*module) + module->mod_size;
205 } 208 }
206 209
207 /* allocate persistent/scratch mem regions */ 210 /* allocate scratch mem regions */
208 scratch = sst_mem_block_alloc_scratch(dsp); 211 sst_block_alloc_scratch(dsp);
209 if (scratch == NULL)
210 return -ENOMEM;
211
212 sst_hsw_set_scratch_module(hsw, scratch);
213 212
214 return 0; 213 return 0;
215} 214}
@@ -248,8 +247,94 @@ static irqreturn_t hsw_irq(int irq, void *context)
248 return ret; 247 return ret;
249} 248}
250 249
251static void hsw_boot(struct sst_dsp *sst) 250static void hsw_set_dsp_D3(struct sst_dsp *sst)
251{
252 u32 val;
253 u32 reg;
254
255 /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
256 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
257 reg &= ~(SST_VDRTCL2_DCLCGE | SST_VDRTCL2_DTCGE);
258 writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
259
260 /* enable power gating and switch off DRAM & IRAM blocks */
261 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
262 val |= SST_VDRTCL0_DSRAMPGE_MASK |
263 SST_VDRTCL0_ISRAMPGE_MASK;
264 val &= ~(SST_VDRTCL0_D3PGD | SST_VDRTCL0_D3SRAMPGD);
265 writel(val, sst->addr.pci_cfg + SST_VDRTCTL0);
266
267 /* switch off audio PLL */
268 val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
269 val |= SST_VDRTCL2_APLLSE_MASK;
270 writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
271
272 /* disable MCLK(clkctl.smos = 0) */
273 sst_dsp_shim_update_bits_unlocked(sst, SST_CLKCTL,
274 SST_CLKCTL_MASK, 0);
275
276 /* Set D3 state, delay 50 us */
277 val = readl(sst->addr.pci_cfg + SST_PMCS);
278 val |= SST_PMCS_PS_MASK;
279 writel(val, sst->addr.pci_cfg + SST_PMCS);
280 udelay(50);
281
282 /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */
283 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
284 reg |= SST_VDRTCL2_DCLCGE | SST_VDRTCL2_DTCGE;
285 writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
286
287 udelay(50);
288
289}
290
291static void hsw_reset(struct sst_dsp *sst)
252{ 292{
293 /* put DSP into reset and stall */
294 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
295 SST_CSR_RST | SST_CSR_STALL,
296 SST_CSR_RST | SST_CSR_STALL);
297
298 /* keep in reset for 10ms */
299 mdelay(10);
300
301 /* take DSP out of reset and keep stalled for FW loading */
302 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
303 SST_CSR_RST | SST_CSR_STALL, SST_CSR_STALL);
304}
305
306static int hsw_set_dsp_D0(struct sst_dsp *sst)
307{
308 int tries = 10;
309 u32 reg;
310
311 /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
312 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
313 reg &= ~(SST_VDRTCL2_DCLCGE | SST_VDRTCL2_DTCGE);
314 writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
315
316 /* Disable D3PG (VDRTCTL0.D3PGD = 1) */
317 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
318 reg |= SST_VDRTCL0_D3PGD;
319 writel(reg, sst->addr.pci_cfg + SST_VDRTCTL0);
320
321 /* Set D0 state */
322 reg = readl(sst->addr.pci_cfg + SST_PMCS);
323 reg &= ~SST_PMCS_PS_MASK;
324 writel(reg, sst->addr.pci_cfg + SST_PMCS);
325
326 /* check that ADSP shim is enabled */
327 while (tries--) {
328 reg = readl(sst->addr.pci_cfg + SST_PMCS) & SST_PMCS_PS_MASK;
329 if (reg == 0)
330 goto finish;
331
332 msleep(1);
333 }
334
335 return -ENODEV;
336
337finish:
253 /* select SSP1 19.2MHz base clock, SSP clock 0, turn off Low Power Clock */ 338 /* select SSP1 19.2MHz base clock, SSP clock 0, turn off Low Power Clock */
254 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR, 339 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
255 SST_CSR_S1IOCS | SST_CSR_SBCS1 | SST_CSR_LPCS, 0x0); 340 SST_CSR_S1IOCS | SST_CSR_SBCS1 | SST_CSR_LPCS, 0x0);
@@ -264,34 +349,96 @@ static void hsw_boot(struct sst_dsp *sst)
264 SST_CLKCTL_MASK | SST_CLKCTL_DCPLCG | SST_CLKCTL_SCOE0, 349 SST_CLKCTL_MASK | SST_CLKCTL_DCPLCG | SST_CLKCTL_SCOE0,
265 SST_CLKCTL_MASK | SST_CLKCTL_DCPLCG | SST_CLKCTL_SCOE0); 350 SST_CLKCTL_MASK | SST_CLKCTL_DCPLCG | SST_CLKCTL_SCOE0);
266 351
352 /* Stall and reset core, set CSR */
353 hsw_reset(sst);
354
355 /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */
356 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
357 reg |= SST_VDRTCL2_DCLCGE | SST_VDRTCL2_DTCGE;
358 writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
359
360 udelay(50);
361
362 /* switch on audio PLL */
363 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
364 reg &= ~SST_VDRTCL2_APLLSE_MASK;
365 writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
366
367 /* set default power gating control, enable power gating control for all blocks. that is,
368 can't be accessed, please enable each block before accessing. */
369 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
370 reg |= SST_VDRTCL0_DSRAMPGE_MASK | SST_VDRTCL0_ISRAMPGE_MASK;
371 writel(reg, sst->addr.pci_cfg + SST_VDRTCTL0);
372
373
267 /* disable DMA finish function for SSP0 & SSP1 */ 374 /* disable DMA finish function for SSP0 & SSP1 */
268 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR2, SST_CSR2_SDFD_SSP1, 375 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR2, SST_CSR2_SDFD_SSP1,
269 SST_CSR2_SDFD_SSP1); 376 SST_CSR2_SDFD_SSP1);
270 377
271 /* enable DMA engine 0,1 all channels to access host memory */ 378 /* set on-demond mode on engine 0,1 for all channels */
272 sst_dsp_shim_update_bits_unlocked(sst, SST_HMDC, 379 sst_dsp_shim_update_bits(sst, SST_HMDC,
273 SST_HMDC_HDDA1(0xff) | SST_HMDC_HDDA0(0xff), 380 SST_HMDC_HDDA_E0_ALLCH | SST_HMDC_HDDA_E1_ALLCH,
274 SST_HMDC_HDDA1(0xff) | SST_HMDC_HDDA0(0xff)); 381 SST_HMDC_HDDA_E0_ALLCH | SST_HMDC_HDDA_E1_ALLCH);
382
383 /* Enable Interrupt from both sides */
384 sst_dsp_shim_update_bits(sst, SST_IMRX, (SST_IMRX_BUSY | SST_IMRX_DONE),
385 0x0);
386 sst_dsp_shim_update_bits(sst, SST_IMRD, (SST_IMRD_DONE | SST_IMRD_BUSY |
387 SST_IMRD_SSP0 | SST_IMRD_DMAC), 0x0);
388
389 /* clear IPC registers */
390 sst_dsp_shim_write(sst, SST_IPCX, 0x0);
391 sst_dsp_shim_write(sst, SST_IPCD, 0x0);
392 sst_dsp_shim_write(sst, 0x80, 0x6);
393 sst_dsp_shim_write(sst, 0xe0, 0x300a);
394
395 return 0;
396}
275 397
276 /* disable all clock gating */ 398static void hsw_boot(struct sst_dsp *sst)
277 writel(0x0, sst->addr.pci_cfg + SST_VDRTCTL2); 399{
400 /* set oportunistic mode on engine 0,1 for all channels */
401 sst_dsp_shim_update_bits(sst, SST_HMDC,
402 SST_HMDC_HDDA_E0_ALLCH | SST_HMDC_HDDA_E1_ALLCH, 0);
278 403
279 /* set DSP to RUN */ 404 /* set DSP to RUN */
280 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR, SST_CSR_STALL, 0x0); 405 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR, SST_CSR_STALL, 0x0);
281} 406}
282 407
283static void hsw_reset(struct sst_dsp *sst) 408static void hsw_stall(struct sst_dsp *sst)
409{
410 /* stall DSP */
411 sst_dsp_shim_update_bits(sst, SST_CSR,
412 SST_CSR_24MHZ_LPCS | SST_CSR_STALL,
413 SST_CSR_STALL | SST_CSR_24MHZ_LPCS);
414}
415
416static void hsw_sleep(struct sst_dsp *sst)
284{ 417{
418 dev_dbg(sst->dev, "HSW_PM dsp runtime suspend\n");
419
285 /* put DSP into reset and stall */ 420 /* put DSP into reset and stall */
286 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR, 421 sst_dsp_shim_update_bits(sst, SST_CSR,
287 SST_CSR_RST | SST_CSR_STALL, SST_CSR_RST | SST_CSR_STALL); 422 SST_CSR_24MHZ_LPCS | SST_CSR_RST | SST_CSR_STALL,
423 SST_CSR_RST | SST_CSR_STALL | SST_CSR_24MHZ_LPCS);
288 424
289 /* keep in reset for 10ms */ 425 hsw_set_dsp_D3(sst);
290 mdelay(10); 426 dev_dbg(sst->dev, "HSW_PM dsp runtime suspend exit\n");
427}
291 428
292 /* take DSP out of reset and keep stalled for FW loading */ 429static int hsw_wake(struct sst_dsp *sst)
293 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR, 430{
294 SST_CSR_RST | SST_CSR_STALL, SST_CSR_STALL); 431 int ret;
432
433 dev_dbg(sst->dev, "HSW_PM dsp runtime resume\n");
434
435 ret = hsw_set_dsp_D0(sst);
436 if (ret < 0)
437 return ret;
438
439 dev_dbg(sst->dev, "HSW_PM dsp runtime resume exit\n");
440
441 return 0;
295} 442}
296 443
297struct sst_adsp_memregion { 444struct sst_adsp_memregion {
@@ -396,6 +543,11 @@ static int hsw_block_enable(struct sst_mem_block *block)
396 dev_dbg(block->dsp->dev, " enabled block %d:%d at offset 0x%x\n", 543 dev_dbg(block->dsp->dev, " enabled block %d:%d at offset 0x%x\n",
397 block->type, block->index, block->offset); 544 block->type, block->index, block->offset);
398 545
546 /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
547 val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
548 val &= ~SST_VDRTCL2_DCLCGE;
549 writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
550
399 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0); 551 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
400 bit = hsw_block_get_bit(block); 552 bit = hsw_block_get_bit(block);
401 writel(val & ~bit, sst->addr.pci_cfg + SST_VDRTCTL0); 553 writel(val & ~bit, sst->addr.pci_cfg + SST_VDRTCTL0);
@@ -403,6 +555,13 @@ static int hsw_block_enable(struct sst_mem_block *block)
403 /* wait 18 DSP clock ticks */ 555 /* wait 18 DSP clock ticks */
404 udelay(10); 556 udelay(10);
405 557
558 /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */
559 val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
560 val |= SST_VDRTCL2_DCLCGE;
561 writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
562
563 udelay(50);
564
406 /*add a dummy read before the SRAM block is written, otherwise the writing may miss bytes sometimes.*/ 565 /*add a dummy read before the SRAM block is written, otherwise the writing may miss bytes sometimes.*/
407 sst_mem_block_dummy_read(block); 566 sst_mem_block_dummy_read(block);
408 return 0; 567 return 0;
@@ -420,10 +579,26 @@ static int hsw_block_disable(struct sst_mem_block *block)
420 dev_dbg(block->dsp->dev, " disabled block %d:%d at offset 0x%x\n", 579 dev_dbg(block->dsp->dev, " disabled block %d:%d at offset 0x%x\n",
421 block->type, block->index, block->offset); 580 block->type, block->index, block->offset);
422 581
582 /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
583 val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
584 val &= ~SST_VDRTCL2_DCLCGE;
585 writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
586
587
423 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0); 588 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
424 bit = hsw_block_get_bit(block); 589 bit = hsw_block_get_bit(block);
425 writel(val | bit, sst->addr.pci_cfg + SST_VDRTCTL0); 590 writel(val | bit, sst->addr.pci_cfg + SST_VDRTCTL0);
426 591
592 /* wait 18 DSP clock ticks */
593 udelay(10);
594
595 /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */
596 val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
597 val |= SST_VDRTCL2_DCLCGE;
598 writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
599
600 udelay(50);
601
427 return 0; 602 return 0;
428} 603}
429 604
@@ -432,27 +607,6 @@ static struct sst_block_ops sst_hsw_ops = {
432 .disable = hsw_block_disable, 607 .disable = hsw_block_disable,
433}; 608};
434 609
435static int hsw_enable_shim(struct sst_dsp *sst)
436{
437 int tries = 10;
438 u32 reg;
439
440 /* enable shim */
441 reg = readl(sst->addr.pci_cfg + SST_SHIM_PM_REG);
442 writel(reg & ~0x3, sst->addr.pci_cfg + SST_SHIM_PM_REG);
443
444 /* check that ADSP shim is enabled */
445 while (tries--) {
446 reg = sst_dsp_shim_read_unlocked(sst, SST_CSR);
447 if (reg != 0xffffffff)
448 return 0;
449
450 msleep(1);
451 }
452
453 return -ENODEV;
454}
455
456static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata) 610static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata)
457{ 611{
458 const struct sst_adsp_memregion *region; 612 const struct sst_adsp_memregion *region;
@@ -467,12 +621,16 @@ static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata)
467 region = lp_region; 621 region = lp_region;
468 region_count = ARRAY_SIZE(lp_region); 622 region_count = ARRAY_SIZE(lp_region);
469 sst->addr.iram_offset = SST_LP_IRAM_OFFSET; 623 sst->addr.iram_offset = SST_LP_IRAM_OFFSET;
624 sst->addr.dsp_iram_offset = SST_LPT_DSP_IRAM_OFFSET;
625 sst->addr.dsp_dram_offset = SST_LPT_DSP_DRAM_OFFSET;
470 sst->addr.shim_offset = SST_LP_SHIM_OFFSET; 626 sst->addr.shim_offset = SST_LP_SHIM_OFFSET;
471 break; 627 break;
472 case SST_DEV_ID_WILDCAT_POINT: 628 case SST_DEV_ID_WILDCAT_POINT:
473 region = wpt_region; 629 region = wpt_region;
474 region_count = ARRAY_SIZE(wpt_region); 630 region_count = ARRAY_SIZE(wpt_region);
475 sst->addr.iram_offset = SST_WPT_IRAM_OFFSET; 631 sst->addr.iram_offset = SST_WPT_IRAM_OFFSET;
632 sst->addr.dsp_iram_offset = SST_WPT_DSP_IRAM_OFFSET;
633 sst->addr.dsp_dram_offset = SST_WPT_DSP_DRAM_OFFSET;
476 sst->addr.shim_offset = SST_WPT_SHIM_OFFSET; 634 sst->addr.shim_offset = SST_WPT_SHIM_OFFSET;
477 break; 635 break;
478 default: 636 default:
@@ -487,7 +645,7 @@ static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata)
487 } 645 }
488 646
489 /* enable the DSP SHIM */ 647 /* enable the DSP SHIM */
490 ret = hsw_enable_shim(sst); 648 ret = hsw_set_dsp_D0(sst);
491 if (ret < 0) { 649 if (ret < 0) {
492 dev_err(dev, "error: failed to set DSP D0 and reset SHIM\n"); 650 dev_err(dev, "error: failed to set DSP D0 and reset SHIM\n");
493 return ret; 651 return ret;
@@ -497,10 +655,6 @@ static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata)
497 if (ret) 655 if (ret)
498 return ret; 656 return ret;
499 657
500 /* Enable Interrupt from both sides */
501 sst_dsp_shim_update_bits_unlocked(sst, SST_IMRX, 0x3, 0x0);
502 sst_dsp_shim_update_bits_unlocked(sst, SST_IMRD,
503 (0x3 | 0x1 << 16 | 0x3 << 21), 0x0);
504 658
505 /* register DSP memory blocks - ideally we should get this from ACPI */ 659 /* register DSP memory blocks - ideally we should get this from ACPI */
506 for (i = 0; i < region_count; i++) { 660 for (i = 0; i < region_count; i++) {
@@ -532,6 +686,9 @@ static void hsw_free(struct sst_dsp *sst)
532struct sst_ops haswell_ops = { 686struct sst_ops haswell_ops = {
533 .reset = hsw_reset, 687 .reset = hsw_reset,
534 .boot = hsw_boot, 688 .boot = hsw_boot,
689 .stall = hsw_stall,
690 .wake = hsw_wake,
691 .sleep = hsw_sleep,
535 .write = sst_shim32_write, 692 .write = sst_shim32_write,
536 .read = sst_shim32_read, 693 .read = sst_shim32_read,
537 .write64 = sst_shim32_write64, 694 .write64 = sst_shim32_write64,
diff --git a/sound/soc/intel/sst-haswell-ipc.c b/sound/soc/intel/sst-haswell-ipc.c
index b6291516dbbf..3f8c48231364 100644
--- a/sound/soc/intel/sst-haswell-ipc.c
+++ b/sound/soc/intel/sst-haswell-ipc.c
@@ -30,6 +30,7 @@
30#include <linux/firmware.h> 30#include <linux/firmware.h>
31#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
32#include <linux/debugfs.h> 32#include <linux/debugfs.h>
33#include <linux/pm_runtime.h>
33 34
34#include "sst-haswell-ipc.h" 35#include "sst-haswell-ipc.h"
35#include "sst-dsp.h" 36#include "sst-dsp.h"
@@ -276,6 +277,7 @@ struct sst_hsw {
276 struct sst_hsw_ipc_fw_version version; 277 struct sst_hsw_ipc_fw_version version;
277 struct sst_module *scratch; 278 struct sst_module *scratch;
278 bool fw_done; 279 bool fw_done;
280 struct sst_fw *sst_fw;
279 281
280 /* stream */ 282 /* stream */
281 struct list_head stream_list; 283 struct list_head stream_list;
@@ -289,6 +291,8 @@ struct sst_hsw {
289 291
290 /* DX */ 292 /* DX */
291 struct sst_hsw_ipc_dx_reply dx; 293 struct sst_hsw_ipc_dx_reply dx;
294 void *dx_context;
295 dma_addr_t dx_context_paddr;
292 296
293 /* boot */ 297 /* boot */
294 wait_queue_head_t boot_wait; 298 wait_queue_head_t boot_wait;
@@ -1038,14 +1042,9 @@ int sst_hsw_stream_set_volume(struct sst_hsw *hsw,
1038 1042
1039 trace_ipc_request("set stream volume", stream->reply.stream_hw_id); 1043 trace_ipc_request("set stream volume", stream->reply.stream_hw_id);
1040 1044
1041 if (channel > 1) 1045 if (channel >= 2 && channel != SST_HSW_CHANNELS_ALL)
1042 return -EINVAL; 1046 return -EINVAL;
1043 1047
1044 if (stream->mute[channel]) {
1045 stream->mute_volume[channel] = volume;
1046 return 0;
1047 }
1048
1049 header = IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE) | 1048 header = IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE) |
1050 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE); 1049 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE);
1051 header |= (stream->reply.stream_hw_id << IPC_STR_ID_SHIFT); 1050 header |= (stream->reply.stream_hw_id << IPC_STR_ID_SHIFT);
@@ -1053,9 +1052,28 @@ int sst_hsw_stream_set_volume(struct sst_hsw *hsw,
1053 header |= (stage_id << IPC_STG_ID_SHIFT); 1052 header |= (stage_id << IPC_STG_ID_SHIFT);
1054 1053
1055 req = &stream->vol_req; 1054 req = &stream->vol_req;
1056 req->channel = channel;
1057 req->target_volume = volume; 1055 req->target_volume = volume;
1058 1056
1057 /* set both at same time ? */
1058 if (channel == SST_HSW_CHANNELS_ALL) {
1059 if (hsw->mute[0] && hsw->mute[1]) {
1060 hsw->mute_volume[0] = hsw->mute_volume[1] = volume;
1061 return 0;
1062 } else if (hsw->mute[0])
1063 req->channel = 1;
1064 else if (hsw->mute[1])
1065 req->channel = 0;
1066 else
1067 req->channel = SST_HSW_CHANNELS_ALL;
1068 } else {
1069 /* set only 1 channel */
1070 if (hsw->mute[channel]) {
1071 hsw->mute_volume[channel] = volume;
1072 return 0;
1073 }
1074 req->channel = channel;
1075 }
1076
1059 ret = ipc_tx_message_wait(hsw, header, req, sizeof(*req), NULL, 0); 1077 ret = ipc_tx_message_wait(hsw, header, req, sizeof(*req), NULL, 0);
1060 if (ret < 0) { 1078 if (ret < 0) {
1061 dev_err(hsw->dev, "error: set stream volume failed\n"); 1079 dev_err(hsw->dev, "error: set stream volume failed\n");
@@ -1134,8 +1152,11 @@ int sst_hsw_mixer_set_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
1134 1152
1135 trace_ipc_request("set mixer volume", volume); 1153 trace_ipc_request("set mixer volume", volume);
1136 1154
1155 if (channel >= 2 && channel != SST_HSW_CHANNELS_ALL)
1156 return -EINVAL;
1157
1137 /* set both at same time ? */ 1158 /* set both at same time ? */
1138 if (channel == 2) { 1159 if (channel == SST_HSW_CHANNELS_ALL) {
1139 if (hsw->mute[0] && hsw->mute[1]) { 1160 if (hsw->mute[0] && hsw->mute[1]) {
1140 hsw->mute_volume[0] = hsw->mute_volume[1] = volume; 1161 hsw->mute_volume[0] = hsw->mute_volume[1] = volume;
1141 return 0; 1162 return 0;
@@ -1144,7 +1165,7 @@ int sst_hsw_mixer_set_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
1144 else if (hsw->mute[1]) 1165 else if (hsw->mute[1])
1145 req.channel = 0; 1166 req.channel = 0;
1146 else 1167 else
1147 req.channel = 0xffffffff; 1168 req.channel = SST_HSW_CHANNELS_ALL;
1148 } else { 1169 } else {
1149 /* set only 1 channel */ 1170 /* set only 1 channel */
1150 if (hsw->mute[channel]) { 1171 if (hsw->mute[channel]) {
@@ -1256,10 +1277,6 @@ int sst_hsw_stream_set_channels(struct sst_hsw *hsw,
1256 return -EINVAL; 1277 return -EINVAL;
1257 } 1278 }
1258 1279
1259 /* stereo is only supported atm */
1260 if (channels != 2)
1261 return -EINVAL;
1262
1263 stream->request.format.ch_num = channels; 1280 stream->request.format.ch_num = channels;
1264 return 0; 1281 return 0;
1265} 1282}
@@ -1355,10 +1372,11 @@ int sst_hsw_stream_buffer(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
1355} 1372}
1356 1373
1357int sst_hsw_stream_set_module_info(struct sst_hsw *hsw, 1374int sst_hsw_stream_set_module_info(struct sst_hsw *hsw,
1358 struct sst_hsw_stream *stream, enum sst_hsw_module_id module_id, 1375 struct sst_hsw_stream *stream, struct sst_module_runtime *runtime)
1359 u32 entry_point)
1360{ 1376{
1361 struct sst_hsw_module_map *map = &stream->request.map; 1377 struct sst_hsw_module_map *map = &stream->request.map;
1378 struct sst_dsp *dsp = sst_hsw_get_dsp(hsw);
1379 struct sst_module *module = runtime->module;
1362 1380
1363 if (stream->commited) { 1381 if (stream->commited) {
1364 dev_err(hsw->dev, "error: stream committed for set module\n"); 1382 dev_err(hsw->dev, "error: stream committed for set module\n");
@@ -1367,36 +1385,25 @@ int sst_hsw_stream_set_module_info(struct sst_hsw *hsw,
1367 1385
1368 /* only support initial module atm */ 1386 /* only support initial module atm */
1369 map->module_entries_count = 1; 1387 map->module_entries_count = 1;
1370 map->module_entries[0].module_id = module_id; 1388 map->module_entries[0].module_id = module->id;
1371 map->module_entries[0].entry_point = entry_point; 1389 map->module_entries[0].entry_point = module->entry;
1372 1390
1373 return 0; 1391 stream->request.persistent_mem.offset =
1374} 1392 sst_dsp_get_offset(dsp, runtime->persistent_offset, SST_MEM_DRAM);
1375 1393 stream->request.persistent_mem.size = module->persistent_size;
1376int sst_hsw_stream_set_pmemory_info(struct sst_hsw *hsw, 1394
1377 struct sst_hsw_stream *stream, u32 offset, u32 size) 1395 stream->request.scratch_mem.offset =
1378{ 1396 sst_dsp_get_offset(dsp, dsp->scratch_offset, SST_MEM_DRAM);
1379 if (stream->commited) { 1397 stream->request.scratch_mem.size = dsp->scratch_size;
1380 dev_err(hsw->dev, "error: stream committed for set pmem\n"); 1398
1381 return -EINVAL; 1399 dev_dbg(hsw->dev, "module %d runtime %d using:\n", module->id,
1382 } 1400 runtime->id);
1383 1401 dev_dbg(hsw->dev, " persistent offset 0x%x bytes 0x%x\n",
1384 stream->request.persistent_mem.offset = offset; 1402 stream->request.persistent_mem.offset,
1385 stream->request.persistent_mem.size = size; 1403 stream->request.persistent_mem.size);
1386 1404 dev_dbg(hsw->dev, " scratch offset 0x%x bytes 0x%x\n",
1387 return 0; 1405 stream->request.scratch_mem.offset,
1388} 1406 stream->request.scratch_mem.size);
1389
1390int sst_hsw_stream_set_smemory_info(struct sst_hsw *hsw,
1391 struct sst_hsw_stream *stream, u32 offset, u32 size)
1392{
1393 if (stream->commited) {
1394 dev_err(hsw->dev, "error: stream committed for set smem\n");
1395 return -EINVAL;
1396 }
1397
1398 stream->request.scratch_mem.offset = offset;
1399 stream->request.scratch_mem.size = size;
1400 1407
1401 return 0; 1408 return 0;
1402} 1409}
@@ -1630,6 +1637,10 @@ int sst_hsw_device_set_config(struct sst_hsw *hsw,
1630 config.clock_frequency = mclk; 1637 config.clock_frequency = mclk;
1631 config.mode = mode; 1638 config.mode = mode;
1632 config.clock_divider = clock_divider; 1639 config.clock_divider = clock_divider;
1640 if (mode == SST_HSW_DEVICE_TDM_CLOCK_MASTER)
1641 config.channels = 4;
1642 else
1643 config.channels = 2;
1633 1644
1634 trace_hsw_device_config_req(&config); 1645 trace_hsw_device_config_req(&config);
1635 1646
@@ -1673,34 +1684,283 @@ int sst_hsw_dx_set_state(struct sst_hsw *hsw,
1673 dev_dbg(hsw->dev, "ipc: got %d entry numbers for state %d\n", 1684 dev_dbg(hsw->dev, "ipc: got %d entry numbers for state %d\n",
1674 dx->entries_no, state); 1685 dx->entries_no, state);
1675 1686
1676 memcpy(&hsw->dx, dx, sizeof(*dx)); 1687 return ret;
1677 return 0;
1678} 1688}
1679 1689
1680/* Used to save state into hsw->dx_reply */ 1690struct sst_module_runtime *sst_hsw_runtime_module_create(struct sst_hsw *hsw,
1681int sst_hsw_dx_get_state(struct sst_hsw *hsw, u32 item, 1691 int mod_id, int offset)
1682 u32 *offset, u32 *size, u32 *source)
1683{ 1692{
1684 struct sst_hsw_ipc_dx_memory_item *dx_mem; 1693 struct sst_dsp *dsp = hsw->dsp;
1685 struct sst_hsw_ipc_dx_reply *dx_reply; 1694 struct sst_module *module;
1686 int entry_no; 1695 struct sst_module_runtime *runtime;
1696 int err;
1687 1697
1688 dx_reply = &hsw->dx; 1698 module = sst_module_get_from_id(dsp, mod_id);
1689 entry_no = dx_reply->entries_no; 1699 if (module == NULL) {
1700 dev_err(dsp->dev, "error: failed to get module %d for pcm\n",
1701 mod_id);
1702 return NULL;
1703 }
1704
1705 runtime = sst_module_runtime_new(module, mod_id, NULL);
1706 if (runtime == NULL) {
1707 dev_err(dsp->dev, "error: failed to create module %d runtime\n",
1708 mod_id);
1709 return NULL;
1710 }
1711
1712 err = sst_module_runtime_alloc_blocks(runtime, offset);
1713 if (err < 0) {
1714 dev_err(dsp->dev, "error: failed to alloc blocks for module %d runtime\n",
1715 mod_id);
1716 sst_module_runtime_free(runtime);
1717 return NULL;
1718 }
1719
1720 dev_dbg(dsp->dev, "runtime id %d created for module %d\n", runtime->id,
1721 mod_id);
1722 return runtime;
1723}
1724
1725void sst_hsw_runtime_module_free(struct sst_module_runtime *runtime)
1726{
1727 sst_module_runtime_free_blocks(runtime);
1728 sst_module_runtime_free(runtime);
1729}
1730
1731#ifdef CONFIG_PM
1732static int sst_hsw_dx_state_dump(struct sst_hsw *hsw)
1733{
1734 struct sst_dsp *sst = hsw->dsp;
1735 u32 item, offset, size;
1736 int ret = 0;
1690 1737
1691 trace_ipc_request("PM get Dx state", entry_no); 1738 trace_ipc_request("PM state dump. Items #", SST_HSW_MAX_DX_REGIONS);
1692 1739
1693 if (item >= entry_no) 1740 if (hsw->dx.entries_no > SST_HSW_MAX_DX_REGIONS) {
1741 dev_err(hsw->dev,
1742 "error: number of FW context regions greater than %d\n",
1743 SST_HSW_MAX_DX_REGIONS);
1744 memset(&hsw->dx, 0, sizeof(hsw->dx));
1694 return -EINVAL; 1745 return -EINVAL;
1746 }
1747
1748 ret = sst_dsp_dma_get_channel(sst, 0);
1749 if (ret < 0) {
1750 dev_err(hsw->dev, "error: cant allocate dma channel %d\n", ret);
1751 return ret;
1752 }
1753
1754 /* set on-demond mode on engine 0 channel 3 */
1755 sst_dsp_shim_update_bits(sst, SST_HMDC,
1756 SST_HMDC_HDDA_E0_ALLCH | SST_HMDC_HDDA_E1_ALLCH,
1757 SST_HMDC_HDDA_E0_ALLCH | SST_HMDC_HDDA_E1_ALLCH);
1758
1759 for (item = 0; item < hsw->dx.entries_no; item++) {
1760 if (hsw->dx.mem_info[item].source == SST_HSW_DX_TYPE_MEMORY_DUMP
1761 && hsw->dx.mem_info[item].offset > DSP_DRAM_ADDR_OFFSET
1762 && hsw->dx.mem_info[item].offset <
1763 DSP_DRAM_ADDR_OFFSET + SST_HSW_DX_CONTEXT_SIZE) {
1764
1765 offset = hsw->dx.mem_info[item].offset
1766 - DSP_DRAM_ADDR_OFFSET;
1767 size = (hsw->dx.mem_info[item].size + 3) & (~3);
1768
1769 ret = sst_dsp_dma_copyfrom(sst, hsw->dx_context_paddr + offset,
1770 sst->addr.lpe_base + offset, size);
1771 if (ret < 0) {
1772 dev_err(hsw->dev,
1773 "error: FW context dump failed\n");
1774 memset(&hsw->dx, 0, sizeof(hsw->dx));
1775 goto out;
1776 }
1777 }
1778 }
1779
1780out:
1781 sst_dsp_dma_put_channel(sst);
1782 return ret;
1783}
1784
1785static int sst_hsw_dx_state_restore(struct sst_hsw *hsw)
1786{
1787 struct sst_dsp *sst = hsw->dsp;
1788 u32 item, offset, size;
1789 int ret;
1790
1791 for (item = 0; item < hsw->dx.entries_no; item++) {
1792 if (hsw->dx.mem_info[item].source == SST_HSW_DX_TYPE_MEMORY_DUMP
1793 && hsw->dx.mem_info[item].offset > DSP_DRAM_ADDR_OFFSET
1794 && hsw->dx.mem_info[item].offset <
1795 DSP_DRAM_ADDR_OFFSET + SST_HSW_DX_CONTEXT_SIZE) {
1796
1797 offset = hsw->dx.mem_info[item].offset
1798 - DSP_DRAM_ADDR_OFFSET;
1799 size = (hsw->dx.mem_info[item].size + 3) & (~3);
1800
1801 ret = sst_dsp_dma_copyto(sst, sst->addr.lpe_base + offset,
1802 hsw->dx_context_paddr + offset, size);
1803 if (ret < 0) {
1804 dev_err(hsw->dev,
1805 "error: FW context restore failed\n");
1806 return ret;
1807 }
1808 }
1809 }
1810
1811 return 0;
1812}
1813
1814static void sst_hsw_drop_all(struct sst_hsw *hsw)
1815{
1816 struct ipc_message *msg, *tmp;
1817 unsigned long flags;
1818 int tx_drop_cnt = 0, rx_drop_cnt = 0;
1695 1819
1696 dx_mem = &dx_reply->mem_info[item]; 1820 /* drop all TX and Rx messages before we stall + reset DSP */
1697 *offset = dx_mem->offset; 1821 spin_lock_irqsave(&hsw->dsp->spinlock, flags);
1698 *size = dx_mem->size; 1822
1699 *source = dx_mem->source; 1823 list_for_each_entry_safe(msg, tmp, &hsw->tx_list, list) {
1824 list_move(&msg->list, &hsw->empty_list);
1825 tx_drop_cnt++;
1826 }
1827
1828 list_for_each_entry_safe(msg, tmp, &hsw->rx_list, list) {
1829 list_move(&msg->list, &hsw->empty_list);
1830 rx_drop_cnt++;
1831 }
1832
1833 spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
1834
1835 if (tx_drop_cnt || rx_drop_cnt)
1836 dev_err(hsw->dev, "dropped IPC msg RX=%d, TX=%d\n",
1837 tx_drop_cnt, rx_drop_cnt);
1838}
1839
1840int sst_hsw_dsp_load(struct sst_hsw *hsw)
1841{
1842 struct sst_dsp *dsp = hsw->dsp;
1843 int ret;
1844
1845 dev_dbg(hsw->dev, "loading audio DSP....");
1846
1847 ret = sst_dsp_wake(dsp);
1848 if (ret < 0) {
1849 dev_err(hsw->dev, "error: failed to wake audio DSP\n");
1850 return -ENODEV;
1851 }
1852
1853 ret = sst_dsp_dma_get_channel(dsp, 0);
1854 if (ret < 0) {
1855 dev_err(hsw->dev, "error: cant allocate dma channel %d\n", ret);
1856 return ret;
1857 }
1858
1859 ret = sst_fw_reload(hsw->sst_fw);
1860 if (ret < 0) {
1861 dev_err(hsw->dev, "error: SST FW reload failed\n");
1862 sst_dsp_dma_put_channel(dsp);
1863 return -ENOMEM;
1864 }
1700 1865
1866 sst_dsp_dma_put_channel(dsp);
1701 return 0; 1867 return 0;
1702} 1868}
1703 1869
1870static int sst_hsw_dsp_restore(struct sst_hsw *hsw)
1871{
1872 struct sst_dsp *dsp = hsw->dsp;
1873 int ret;
1874
1875 dev_dbg(hsw->dev, "restoring audio DSP....");
1876
1877 ret = sst_dsp_dma_get_channel(dsp, 0);
1878 if (ret < 0) {
1879 dev_err(hsw->dev, "error: cant allocate dma channel %d\n", ret);
1880 return ret;
1881 }
1882
1883 ret = sst_hsw_dx_state_restore(hsw);
1884 if (ret < 0) {
1885 dev_err(hsw->dev, "error: SST FW context restore failed\n");
1886 sst_dsp_dma_put_channel(dsp);
1887 return -ENOMEM;
1888 }
1889 sst_dsp_dma_put_channel(dsp);
1890
1891 /* wait for DSP boot completion */
1892 sst_dsp_boot(dsp);
1893
1894 return ret;
1895}
1896
1897int sst_hsw_dsp_runtime_suspend(struct sst_hsw *hsw)
1898{
1899 int ret;
1900
1901 dev_dbg(hsw->dev, "audio dsp runtime suspend\n");
1902
1903 ret = sst_hsw_dx_set_state(hsw, SST_HSW_DX_STATE_D3, &hsw->dx);
1904 if (ret < 0)
1905 return ret;
1906
1907 sst_dsp_stall(hsw->dsp);
1908
1909 ret = sst_hsw_dx_state_dump(hsw);
1910 if (ret < 0)
1911 return ret;
1912
1913 sst_hsw_drop_all(hsw);
1914
1915 return 0;
1916}
1917
1918int sst_hsw_dsp_runtime_sleep(struct sst_hsw *hsw)
1919{
1920 sst_fw_unload(hsw->sst_fw);
1921 sst_block_free_scratch(hsw->dsp);
1922
1923 hsw->boot_complete = false;
1924
1925 sst_dsp_sleep(hsw->dsp);
1926
1927 return 0;
1928}
1929
1930int sst_hsw_dsp_runtime_resume(struct sst_hsw *hsw)
1931{
1932 struct device *dev = hsw->dev;
1933 int ret;
1934
1935 dev_dbg(dev, "audio dsp runtime resume\n");
1936
1937 if (hsw->boot_complete)
1938 return 1; /* tell caller no action is required */
1939
1940 ret = sst_hsw_dsp_restore(hsw);
1941 if (ret < 0)
1942 dev_err(dev, "error: audio DSP boot failure\n");
1943
1944 ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete,
1945 msecs_to_jiffies(IPC_BOOT_MSECS));
1946 if (ret == 0) {
1947 dev_err(hsw->dev, "error: audio DSP boot timeout IPCD 0x%x IPCX 0x%x\n",
1948 sst_dsp_shim_read_unlocked(hsw->dsp, SST_IPCD),
1949 sst_dsp_shim_read_unlocked(hsw->dsp, SST_IPCX));
1950 return -EIO;
1951 }
1952
1953 /* Set ADSP SSP port settings */
1954 ret = sst_hsw_device_set_config(hsw, SST_HSW_DEVICE_SSP_0,
1955 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
1956 SST_HSW_DEVICE_CLOCK_MASTER, 9);
1957 if (ret < 0)
1958 dev_err(dev, "error: SSP re-initialization failed\n");
1959
1960 return ret;
1961}
1962#endif
1963
1704static int msg_empty_list_init(struct sst_hsw *hsw) 1964static int msg_empty_list_init(struct sst_hsw *hsw)
1705{ 1965{
1706 int i; 1966 int i;
@@ -1718,12 +1978,6 @@ static int msg_empty_list_init(struct sst_hsw *hsw)
1718 return 0; 1978 return 0;
1719} 1979}
1720 1980
1721void sst_hsw_set_scratch_module(struct sst_hsw *hsw,
1722 struct sst_module *scratch)
1723{
1724 hsw->scratch = scratch;
1725}
1726
1727struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw) 1981struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw)
1728{ 1982{
1729 return hsw->dsp; 1983 return hsw->dsp;
@@ -1738,7 +1992,6 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
1738{ 1992{
1739 struct sst_hsw_ipc_fw_version version; 1993 struct sst_hsw_ipc_fw_version version;
1740 struct sst_hsw *hsw; 1994 struct sst_hsw *hsw;
1741 struct sst_fw *hsw_sst_fw;
1742 int ret; 1995 int ret;
1743 1996
1744 dev_dbg(dev, "initialising Audio DSP IPC\n"); 1997 dev_dbg(dev, "initialising Audio DSP IPC\n");
@@ -1780,12 +2033,19 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
1780 goto dsp_err; 2033 goto dsp_err;
1781 } 2034 }
1782 2035
2036 /* allocate DMA buffer for context storage */
2037 hsw->dx_context = dma_alloc_coherent(hsw->dsp->dma_dev,
2038 SST_HSW_DX_CONTEXT_SIZE, &hsw->dx_context_paddr, GFP_KERNEL);
2039 if (hsw->dx_context == NULL) {
2040 ret = -ENOMEM;
2041 goto dma_err;
2042 }
2043
1783 /* keep the DSP in reset state for base FW loading */ 2044 /* keep the DSP in reset state for base FW loading */
1784 sst_dsp_reset(hsw->dsp); 2045 sst_dsp_reset(hsw->dsp);
1785 2046
1786 hsw_sst_fw = sst_fw_new(hsw->dsp, pdata->fw, hsw); 2047 hsw->sst_fw = sst_fw_new(hsw->dsp, pdata->fw, hsw);
1787 2048 if (hsw->sst_fw == NULL) {
1788 if (hsw_sst_fw == NULL) {
1789 ret = -ENODEV; 2049 ret = -ENODEV;
1790 dev_err(dev, "error: failed to load firmware\n"); 2050 dev_err(dev, "error: failed to load firmware\n");
1791 goto fw_err; 2051 goto fw_err;
@@ -1797,7 +2057,9 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
1797 msecs_to_jiffies(IPC_BOOT_MSECS)); 2057 msecs_to_jiffies(IPC_BOOT_MSECS));
1798 if (ret == 0) { 2058 if (ret == 0) {
1799 ret = -EIO; 2059 ret = -EIO;
1800 dev_err(hsw->dev, "error: ADSP boot timeout\n"); 2060 dev_err(hsw->dev, "error: audio DSP boot timeout IPCD 0x%x IPCX 0x%x\n",
2061 sst_dsp_shim_read_unlocked(hsw->dsp, SST_IPCD),
2062 sst_dsp_shim_read_unlocked(hsw->dsp, SST_IPCX));
1801 goto boot_err; 2063 goto boot_err;
1802 } 2064 }
1803 2065
@@ -1816,8 +2078,11 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
1816 2078
1817boot_err: 2079boot_err:
1818 sst_dsp_reset(hsw->dsp); 2080 sst_dsp_reset(hsw->dsp);
1819 sst_fw_free(hsw_sst_fw); 2081 sst_fw_free(hsw->sst_fw);
1820fw_err: 2082fw_err:
2083 dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE,
2084 hsw->dx_context, hsw->dx_context_paddr);
2085dma_err:
1821 sst_dsp_free(hsw->dsp); 2086 sst_dsp_free(hsw->dsp);
1822dsp_err: 2087dsp_err:
1823 kthread_stop(hsw->tx_thread); 2088 kthread_stop(hsw->tx_thread);
@@ -1834,6 +2099,8 @@ void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata)
1834 2099
1835 sst_dsp_reset(hsw->dsp); 2100 sst_dsp_reset(hsw->dsp);
1836 sst_fw_free_all(hsw->dsp); 2101 sst_fw_free_all(hsw->dsp);
2102 dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE,
2103 hsw->dx_context, hsw->dx_context_paddr);
1837 sst_dsp_free(hsw->dsp); 2104 sst_dsp_free(hsw->dsp);
1838 kfree(hsw->scratch); 2105 kfree(hsw->scratch);
1839 kthread_stop(hsw->tx_thread); 2106 kthread_stop(hsw->tx_thread);
diff --git a/sound/soc/intel/sst-haswell-ipc.h b/sound/soc/intel/sst-haswell-ipc.h
index 2ac194a6d04b..138e894ab413 100644
--- a/sound/soc/intel/sst-haswell-ipc.h
+++ b/sound/soc/intel/sst-haswell-ipc.h
@@ -21,8 +21,10 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23 23
24#define SST_HSW_NO_CHANNELS 2 24#define SST_HSW_NO_CHANNELS 4
25#define SST_HSW_MAX_DX_REGIONS 14 25#define SST_HSW_MAX_DX_REGIONS 14
26#define SST_HSW_DX_CONTEXT_SIZE (640 * 1024)
27#define SST_HSW_CHANNELS_ALL 0xffffffff
26 28
27#define SST_HSW_FW_LOG_CONFIG_DWORDS 12 29#define SST_HSW_FW_LOG_CONFIG_DWORDS 12
28#define SST_HSW_GLOBAL_LOG 15 30#define SST_HSW_GLOBAL_LOG 15
@@ -40,6 +42,7 @@ struct sst_hsw_stream;
40struct sst_hsw_log_stream; 42struct sst_hsw_log_stream;
41struct sst_pdata; 43struct sst_pdata;
42struct sst_module; 44struct sst_module;
45struct sst_module_runtime;
43extern struct sst_ops haswell_ops; 46extern struct sst_ops haswell_ops;
44 47
45/* Stream Allocate Path ID */ 48/* Stream Allocate Path ID */
@@ -84,6 +87,7 @@ enum sst_hsw_device_mclk {
84enum sst_hsw_device_mode { 87enum sst_hsw_device_mode {
85 SST_HSW_DEVICE_CLOCK_SLAVE = 0, 88 SST_HSW_DEVICE_CLOCK_SLAVE = 0,
86 SST_HSW_DEVICE_CLOCK_MASTER = 1, 89 SST_HSW_DEVICE_CLOCK_MASTER = 1,
90 SST_HSW_DEVICE_TDM_CLOCK_MASTER = 2,
87}; 91};
88 92
89/* DX Power State */ 93/* DX Power State */
@@ -295,7 +299,8 @@ struct sst_hsw_ipc_device_config_req {
295 u32 clock_frequency; 299 u32 clock_frequency;
296 u32 mode; 300 u32 mode;
297 u16 clock_divider; 301 u16 clock_divider;
298 u16 reserved; 302 u8 channels;
303 u8 reserved;
299} __attribute__((packed)); 304} __attribute__((packed));
300 305
301/* Audio Data formats */ 306/* Audio Data formats */
@@ -430,8 +435,7 @@ int sst_hsw_stream_set_map_config(struct sst_hsw *hsw,
430int sst_hsw_stream_set_style(struct sst_hsw *hsw, struct sst_hsw_stream *stream, 435int sst_hsw_stream_set_style(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
431 enum sst_hsw_interleaving style); 436 enum sst_hsw_interleaving style);
432int sst_hsw_stream_set_module_info(struct sst_hsw *hsw, 437int sst_hsw_stream_set_module_info(struct sst_hsw *hsw,
433 struct sst_hsw_stream *stream, enum sst_hsw_module_id module_id, 438 struct sst_hsw_stream *stream, struct sst_module_runtime *runtime);
434 u32 entry_point);
435int sst_hsw_stream_set_pmemory_info(struct sst_hsw *hsw, 439int sst_hsw_stream_set_pmemory_info(struct sst_hsw *hsw,
436 struct sst_hsw_stream *stream, u32 offset, u32 size); 440 struct sst_hsw_stream *stream, u32 offset, u32 size);
437int sst_hsw_stream_set_smemory_info(struct sst_hsw *hsw, 441int sst_hsw_stream_set_smemory_info(struct sst_hsw *hsw,
@@ -484,7 +488,16 @@ int sst_hsw_dx_get_state(struct sst_hsw *hsw, u32 item,
484int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata); 488int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata);
485void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata); 489void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata);
486struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw); 490struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw);
487void sst_hsw_set_scratch_module(struct sst_hsw *hsw, 491
488 struct sst_module *scratch); 492/* runtime module management */
493struct sst_module_runtime *sst_hsw_runtime_module_create(struct sst_hsw *hsw,
494 int mod_id, int offset);
495void sst_hsw_runtime_module_free(struct sst_module_runtime *runtime);
496
497/* PM */
498int sst_hsw_dsp_runtime_resume(struct sst_hsw *hsw);
499int sst_hsw_dsp_runtime_suspend(struct sst_hsw *hsw);
500int sst_hsw_dsp_load(struct sst_hsw *hsw);
501int sst_hsw_dsp_runtime_sleep(struct sst_hsw *hsw);
489 502
490#endif 503#endif
diff --git a/sound/soc/intel/sst-haswell-pcm.c b/sound/soc/intel/sst-haswell-pcm.c
index 4df867cbb92a..0180b386c421 100644
--- a/sound/soc/intel/sst-haswell-pcm.c
+++ b/sound/soc/intel/sst-haswell-pcm.c
@@ -18,6 +18,7 @@
18#include <linux/dma-mapping.h> 18#include <linux/dma-mapping.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/pm_runtime.h>
21#include <asm/page.h> 22#include <asm/page.h>
22#include <asm/pgtable.h> 23#include <asm/pgtable.h>
23#include <sound/core.h> 24#include <sound/core.h>
@@ -73,6 +74,13 @@ static const u32 volume_map[] = {
73#define HSW_PCM_PERIODS_MAX 64 74#define HSW_PCM_PERIODS_MAX 64
74#define HSW_PCM_PERIODS_MIN 2 75#define HSW_PCM_PERIODS_MIN 2
75 76
77#define HSW_PCM_DAI_ID_SYSTEM 0
78#define HSW_PCM_DAI_ID_OFFLOAD0 1
79#define HSW_PCM_DAI_ID_OFFLOAD1 2
80#define HSW_PCM_DAI_ID_LOOPBACK 3
81#define HSW_PCM_DAI_ID_CAPTURE 4
82
83
76static const struct snd_pcm_hardware hsw_pcm_hardware = { 84static const struct snd_pcm_hardware hsw_pcm_hardware = {
77 .info = SNDRV_PCM_INFO_MMAP | 85 .info = SNDRV_PCM_INFO_MMAP |
78 SNDRV_PCM_INFO_MMAP_VALID | 86 SNDRV_PCM_INFO_MMAP_VALID |
@@ -89,22 +97,39 @@ static const struct snd_pcm_hardware hsw_pcm_hardware = {
89 .buffer_bytes_max = HSW_PCM_PERIODS_MAX * PAGE_SIZE, 97 .buffer_bytes_max = HSW_PCM_PERIODS_MAX * PAGE_SIZE,
90}; 98};
91 99
100struct hsw_pcm_module_map {
101 int dai_id;
102 enum sst_hsw_module_id mod_id;
103};
104
92/* private data for each PCM DSP stream */ 105/* private data for each PCM DSP stream */
93struct hsw_pcm_data { 106struct hsw_pcm_data {
94 int dai_id; 107 int dai_id;
95 struct sst_hsw_stream *stream; 108 struct sst_hsw_stream *stream;
109 struct sst_module_runtime *runtime;
110 struct sst_module_runtime_context context;
111 struct snd_pcm *hsw_pcm;
96 u32 volume[2]; 112 u32 volume[2];
97 struct snd_pcm_substream *substream; 113 struct snd_pcm_substream *substream;
98 struct snd_compr_stream *cstream; 114 struct snd_compr_stream *cstream;
99 unsigned int wpos; 115 unsigned int wpos;
100 struct mutex mutex; 116 struct mutex mutex;
101 bool allocated; 117 bool allocated;
118 int persistent_offset;
119};
120
121enum hsw_pm_state {
122 HSW_PM_STATE_D3 = 0,
123 HSW_PM_STATE_D0 = 1,
102}; 124};
103 125
104/* private data for the driver */ 126/* private data for the driver */
105struct hsw_priv_data { 127struct hsw_priv_data {
106 /* runtime DSP */ 128 /* runtime DSP */
107 struct sst_hsw *hsw; 129 struct sst_hsw *hsw;
130 struct device *dev;
131 enum hsw_pm_state pm_state;
132 struct snd_soc_card *soc_card;
108 133
109 /* page tables */ 134 /* page tables */
110 struct snd_dma_buffer dmab[HSW_PCM_COUNT][2]; 135 struct snd_dma_buffer dmab[HSW_PCM_COUNT][2];
@@ -138,21 +163,25 @@ static inline unsigned int hsw_ipc_to_mixer(u32 value)
138static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol, 163static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol,
139 struct snd_ctl_elem_value *ucontrol) 164 struct snd_ctl_elem_value *ucontrol)
140{ 165{
141 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 166 struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol);
142 struct hsw_priv_data *pdata = snd_soc_component_get_drvdata(cmpnt);
143 struct soc_mixer_control *mc = 167 struct soc_mixer_control *mc =
144 (struct soc_mixer_control *)kcontrol->private_value; 168 (struct soc_mixer_control *)kcontrol->private_value;
169 struct hsw_priv_data *pdata =
170 snd_soc_platform_get_drvdata(platform);
145 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg]; 171 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg];
146 struct sst_hsw *hsw = pdata->hsw; 172 struct sst_hsw *hsw = pdata->hsw;
147 u32 volume; 173 u32 volume;
148 174
149 mutex_lock(&pcm_data->mutex); 175 mutex_lock(&pcm_data->mutex);
176 pm_runtime_get_sync(pdata->dev);
150 177
151 if (!pcm_data->stream) { 178 if (!pcm_data->stream) {
152 pcm_data->volume[0] = 179 pcm_data->volume[0] =
153 hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); 180 hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
154 pcm_data->volume[1] = 181 pcm_data->volume[1] =
155 hsw_mixer_to_ipc(ucontrol->value.integer.value[1]); 182 hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
183 pm_runtime_mark_last_busy(pdata->dev);
184 pm_runtime_put_autosuspend(pdata->dev);
156 mutex_unlock(&pcm_data->mutex); 185 mutex_unlock(&pcm_data->mutex);
157 return 0; 186 return 0;
158 } 187 }
@@ -160,7 +189,8 @@ static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol,
160 if (ucontrol->value.integer.value[0] == 189 if (ucontrol->value.integer.value[0] ==
161 ucontrol->value.integer.value[1]) { 190 ucontrol->value.integer.value[1]) {
162 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); 191 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
163 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 2, volume); 192 /* apply volume value to all channels */
193 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, SST_HSW_CHANNELS_ALL, volume);
164 } else { 194 } else {
165 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); 195 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
166 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 0, volume); 196 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 0, volume);
@@ -168,6 +198,8 @@ static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol,
168 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 1, volume); 198 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 1, volume);
169 } 199 }
170 200
201 pm_runtime_mark_last_busy(pdata->dev);
202 pm_runtime_put_autosuspend(pdata->dev);
171 mutex_unlock(&pcm_data->mutex); 203 mutex_unlock(&pcm_data->mutex);
172 return 0; 204 return 0;
173} 205}
@@ -175,21 +207,25 @@ static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol,
175static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol, 207static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol,
176 struct snd_ctl_elem_value *ucontrol) 208 struct snd_ctl_elem_value *ucontrol)
177{ 209{
178 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 210 struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol);
179 struct hsw_priv_data *pdata = snd_soc_component_get_drvdata(cmpnt);
180 struct soc_mixer_control *mc = 211 struct soc_mixer_control *mc =
181 (struct soc_mixer_control *)kcontrol->private_value; 212 (struct soc_mixer_control *)kcontrol->private_value;
213 struct hsw_priv_data *pdata =
214 snd_soc_platform_get_drvdata(platform);
182 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg]; 215 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg];
183 struct sst_hsw *hsw = pdata->hsw; 216 struct sst_hsw *hsw = pdata->hsw;
184 u32 volume; 217 u32 volume;
185 218
186 mutex_lock(&pcm_data->mutex); 219 mutex_lock(&pcm_data->mutex);
220 pm_runtime_get_sync(pdata->dev);
187 221
188 if (!pcm_data->stream) { 222 if (!pcm_data->stream) {
189 ucontrol->value.integer.value[0] = 223 ucontrol->value.integer.value[0] =
190 hsw_ipc_to_mixer(pcm_data->volume[0]); 224 hsw_ipc_to_mixer(pcm_data->volume[0]);
191 ucontrol->value.integer.value[1] = 225 ucontrol->value.integer.value[1] =
192 hsw_ipc_to_mixer(pcm_data->volume[1]); 226 hsw_ipc_to_mixer(pcm_data->volume[1]);
227 pm_runtime_mark_last_busy(pdata->dev);
228 pm_runtime_put_autosuspend(pdata->dev);
193 mutex_unlock(&pcm_data->mutex); 229 mutex_unlock(&pcm_data->mutex);
194 return 0; 230 return 0;
195 } 231 }
@@ -198,6 +234,9 @@ static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol,
198 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume); 234 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume);
199 sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 1, &volume); 235 sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 1, &volume);
200 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume); 236 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume);
237
238 pm_runtime_mark_last_busy(pdata->dev);
239 pm_runtime_put_autosuspend(pdata->dev);
201 mutex_unlock(&pcm_data->mutex); 240 mutex_unlock(&pcm_data->mutex);
202 241
203 return 0; 242 return 0;
@@ -206,16 +245,18 @@ static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol,
206static int hsw_volume_put(struct snd_kcontrol *kcontrol, 245static int hsw_volume_put(struct snd_kcontrol *kcontrol,
207 struct snd_ctl_elem_value *ucontrol) 246 struct snd_ctl_elem_value *ucontrol)
208{ 247{
209 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 248 struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol);
210 struct hsw_priv_data *pdata = snd_soc_component_get_drvdata(cmpnt); 249 struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform);
211 struct sst_hsw *hsw = pdata->hsw; 250 struct sst_hsw *hsw = pdata->hsw;
212 u32 volume; 251 u32 volume;
213 252
253 pm_runtime_get_sync(pdata->dev);
254
214 if (ucontrol->value.integer.value[0] == 255 if (ucontrol->value.integer.value[0] ==
215 ucontrol->value.integer.value[1]) { 256 ucontrol->value.integer.value[1]) {
216 257
217 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); 258 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
218 sst_hsw_mixer_set_volume(hsw, 0, 2, volume); 259 sst_hsw_mixer_set_volume(hsw, 0, SST_HSW_CHANNELS_ALL, volume);
219 260
220 } else { 261 } else {
221 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); 262 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
@@ -225,23 +266,28 @@ static int hsw_volume_put(struct snd_kcontrol *kcontrol,
225 sst_hsw_mixer_set_volume(hsw, 0, 1, volume); 266 sst_hsw_mixer_set_volume(hsw, 0, 1, volume);
226 } 267 }
227 268
269 pm_runtime_mark_last_busy(pdata->dev);
270 pm_runtime_put_autosuspend(pdata->dev);
228 return 0; 271 return 0;
229} 272}
230 273
231static int hsw_volume_get(struct snd_kcontrol *kcontrol, 274static int hsw_volume_get(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol) 275 struct snd_ctl_elem_value *ucontrol)
233{ 276{
234 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 277 struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol);
235 struct hsw_priv_data *pdata = snd_soc_component_get_drvdata(cmpnt); 278 struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform);
236 struct sst_hsw *hsw = pdata->hsw; 279 struct sst_hsw *hsw = pdata->hsw;
237 unsigned int volume = 0; 280 unsigned int volume = 0;
238 281
282 pm_runtime_get_sync(pdata->dev);
239 sst_hsw_mixer_get_volume(hsw, 0, 0, &volume); 283 sst_hsw_mixer_get_volume(hsw, 0, 0, &volume);
240 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume); 284 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume);
241 285
242 sst_hsw_mixer_get_volume(hsw, 0, 1, &volume); 286 sst_hsw_mixer_get_volume(hsw, 0, 1, &volume);
243 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume); 287 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume);
244 288
289 pm_runtime_mark_last_busy(pdata->dev);
290 pm_runtime_put_autosuspend(pdata->dev);
245 return 0; 291 return 0;
246} 292}
247 293
@@ -252,23 +298,19 @@ static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1);
252static const struct snd_kcontrol_new hsw_volume_controls[] = { 298static const struct snd_kcontrol_new hsw_volume_controls[] = {
253 /* Global DSP volume */ 299 /* Global DSP volume */
254 SOC_DOUBLE_EXT_TLV("Master Playback Volume", 0, 0, 8, 300 SOC_DOUBLE_EXT_TLV("Master Playback Volume", 0, 0, 8,
255 ARRAY_SIZE(volume_map) -1, 0, 301 ARRAY_SIZE(volume_map) - 1, 0,
256 hsw_volume_get, hsw_volume_put, hsw_vol_tlv), 302 hsw_volume_get, hsw_volume_put, hsw_vol_tlv),
257 /* Offload 0 volume */ 303 /* Offload 0 volume */
258 SOC_DOUBLE_EXT_TLV("Media0 Playback Volume", 1, 0, 8, 304 SOC_DOUBLE_EXT_TLV("Media0 Playback Volume", 1, 0, 8,
259 ARRAY_SIZE(volume_map), 0, 305 ARRAY_SIZE(volume_map) - 1, 0,
260 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), 306 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
261 /* Offload 1 volume */ 307 /* Offload 1 volume */
262 SOC_DOUBLE_EXT_TLV("Media1 Playback Volume", 2, 0, 8, 308 SOC_DOUBLE_EXT_TLV("Media1 Playback Volume", 2, 0, 8,
263 ARRAY_SIZE(volume_map), 0, 309 ARRAY_SIZE(volume_map) - 1, 0,
264 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
265 /* Loopback volume */
266 SOC_DOUBLE_EXT_TLV("Loopback Capture Volume", 3, 0, 8,
267 ARRAY_SIZE(volume_map), 0,
268 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), 310 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
269 /* Mic Capture volume */ 311 /* Mic Capture volume */
270 SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 4, 0, 8, 312 SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 0, 0, 8,
271 ARRAY_SIZE(volume_map), 0, 313 ARRAY_SIZE(volume_map) - 1, 0,
272 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), 314 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
273}; 315};
274 316
@@ -354,8 +396,14 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
354 /* DSP stream type depends on DAI ID */ 396 /* DSP stream type depends on DAI ID */
355 switch (rtd->cpu_dai->id) { 397 switch (rtd->cpu_dai->id) {
356 case 0: 398 case 0:
357 stream_type = SST_HSW_STREAM_TYPE_SYSTEM; 399 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
358 module_id = SST_HSW_MODULE_PCM_SYSTEM; 400 stream_type = SST_HSW_STREAM_TYPE_SYSTEM;
401 module_id = SST_HSW_MODULE_PCM_SYSTEM;
402 }
403 else {
404 stream_type = SST_HSW_STREAM_TYPE_CAPTURE;
405 module_id = SST_HSW_MODULE_PCM_CAPTURE;
406 }
359 break; 407 break;
360 case 1: 408 case 1:
361 case 2: 409 case 2:
@@ -368,10 +416,6 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
368 path_id = SST_HSW_STREAM_PATH_SSP0_OUT; 416 path_id = SST_HSW_STREAM_PATH_SSP0_OUT;
369 module_id = SST_HSW_MODULE_PCM_REFERENCE; 417 module_id = SST_HSW_MODULE_PCM_REFERENCE;
370 break; 418 break;
371 case 4:
372 stream_type = SST_HSW_STREAM_TYPE_CAPTURE;
373 module_id = SST_HSW_MODULE_PCM_CAPTURE;
374 break;
375 default: 419 default:
376 dev_err(rtd->dev, "error: invalid DAI ID %d\n", 420 dev_err(rtd->dev, "error: invalid DAI ID %d\n",
377 rtd->cpu_dai->id); 421 rtd->cpu_dai->id);
@@ -421,13 +465,7 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
421 return ret; 465 return ret;
422 } 466 }
423 467
424 /* we only support stereo atm */
425 channels = params_channels(params); 468 channels = params_channels(params);
426 if (channels != 2) {
427 dev_err(rtd->dev, "error: invalid channels %d\n", channels);
428 return -EINVAL;
429 }
430
431 map = create_channel_map(SST_HSW_CHANNEL_CONFIG_STEREO); 469 map = create_channel_map(SST_HSW_CHANNEL_CONFIG_STEREO);
432 sst_hsw_stream_set_map_config(hsw, pcm_data->stream, 470 sst_hsw_stream_set_map_config(hsw, pcm_data->stream,
433 map, SST_HSW_CHANNEL_CONFIG_STEREO); 471 map, SST_HSW_CHANNEL_CONFIG_STEREO);
@@ -478,35 +516,23 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
478 return -EINVAL; 516 return -EINVAL;
479 } 517 }
480 518
481 /* we use hardcoded memory offsets atm, will be updated for new FW */ 519 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
482 if (stream_type == SST_HSW_STREAM_TYPE_CAPTURE) { 520 pcm_data->runtime);
483 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
484 SST_HSW_MODULE_PCM_CAPTURE, module_data->entry);
485 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
486 0x449400, 0x4000);
487 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
488 0x400000, 0);
489 } else { /* stream_type == SST_HSW_STREAM_TYPE_SYSTEM */
490 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
491 SST_HSW_MODULE_PCM_SYSTEM, module_data->entry);
492
493 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
494 module_data->offset, module_data->size);
495 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
496 0x44d400, 0x3800);
497
498 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
499 module_data->offset, module_data->size);
500 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
501 0x400000, 0);
502 }
503 521
504 ret = sst_hsw_stream_commit(hsw, pcm_data->stream); 522 ret = sst_hsw_stream_commit(hsw, pcm_data->stream);
505 if (ret < 0) { 523 if (ret < 0) {
506 dev_err(rtd->dev, "error: failed to commit stream %d\n", ret); 524 dev_err(rtd->dev, "error: failed to commit stream %d\n", ret);
507 return ret; 525 return ret;
508 } 526 }
509 pcm_data->allocated = true; 527
528 if (!pcm_data->allocated) {
529 /* Set previous saved volume */
530 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
531 0, pcm_data->volume[0]);
532 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
533 1, pcm_data->volume[1]);
534 pcm_data->allocated = true;
535 }
510 536
511 ret = sst_hsw_stream_pause(hsw, pcm_data->stream, 1); 537 ret = sst_hsw_stream_pause(hsw, pcm_data->stream, 1);
512 if (ret < 0) 538 if (ret < 0)
@@ -558,7 +584,7 @@ static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data)
558 pos = frames_to_bytes(runtime, 584 pos = frames_to_bytes(runtime,
559 (runtime->control->appl_ptr % runtime->buffer_size)); 585 (runtime->control->appl_ptr % runtime->buffer_size));
560 586
561 dev_dbg(rtd->dev, "PCM: App pointer %d bytes\n", pos); 587 dev_vdbg(rtd->dev, "PCM: App pointer %d bytes\n", pos);
562 588
563 /* let alsa know we have play a period */ 589 /* let alsa know we have play a period */
564 snd_pcm_period_elapsed(substream); 590 snd_pcm_period_elapsed(substream);
@@ -580,7 +606,7 @@ static snd_pcm_uframes_t hsw_pcm_pointer(struct snd_pcm_substream *substream)
580 offset = bytes_to_frames(runtime, position); 606 offset = bytes_to_frames(runtime, position);
581 ppos = sst_hsw_get_dsp_presentation_position(hsw, pcm_data->stream); 607 ppos = sst_hsw_get_dsp_presentation_position(hsw, pcm_data->stream);
582 608
583 dev_dbg(rtd->dev, "PCM: DMA pointer %du bytes, pos %llu\n", 609 dev_vdbg(rtd->dev, "PCM: DMA pointer %du bytes, pos %llu\n",
584 position, ppos); 610 position, ppos);
585 return offset; 611 return offset;
586} 612}
@@ -596,6 +622,7 @@ static int hsw_pcm_open(struct snd_pcm_substream *substream)
596 pcm_data = &pdata->pcm[rtd->cpu_dai->id]; 622 pcm_data = &pdata->pcm[rtd->cpu_dai->id];
597 623
598 mutex_lock(&pcm_data->mutex); 624 mutex_lock(&pcm_data->mutex);
625 pm_runtime_get_sync(pdata->dev);
599 626
600 snd_soc_pcm_set_drvdata(rtd, pcm_data); 627 snd_soc_pcm_set_drvdata(rtd, pcm_data);
601 pcm_data->substream = substream; 628 pcm_data->substream = substream;
@@ -606,16 +633,12 @@ static int hsw_pcm_open(struct snd_pcm_substream *substream)
606 hsw_notify_pointer, pcm_data); 633 hsw_notify_pointer, pcm_data);
607 if (pcm_data->stream == NULL) { 634 if (pcm_data->stream == NULL) {
608 dev_err(rtd->dev, "error: failed to create stream\n"); 635 dev_err(rtd->dev, "error: failed to create stream\n");
636 pm_runtime_mark_last_busy(pdata->dev);
637 pm_runtime_put_autosuspend(pdata->dev);
609 mutex_unlock(&pcm_data->mutex); 638 mutex_unlock(&pcm_data->mutex);
610 return -EINVAL; 639 return -EINVAL;
611 } 640 }
612 641
613 /* Set previous saved volume */
614 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
615 0, pcm_data->volume[0]);
616 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
617 1, pcm_data->volume[1]);
618
619 mutex_unlock(&pcm_data->mutex); 642 mutex_unlock(&pcm_data->mutex);
620 return 0; 643 return 0;
621} 644}
@@ -645,6 +668,8 @@ static int hsw_pcm_close(struct snd_pcm_substream *substream)
645 pcm_data->stream = NULL; 668 pcm_data->stream = NULL;
646 669
647out: 670out:
671 pm_runtime_mark_last_busy(pdata->dev);
672 pm_runtime_put_autosuspend(pdata->dev);
648 mutex_unlock(&pcm_data->mutex); 673 mutex_unlock(&pcm_data->mutex);
649 return ret; 674 return ret;
650} 675}
@@ -660,6 +685,56 @@ static struct snd_pcm_ops hsw_pcm_ops = {
660 .page = snd_pcm_sgbuf_ops_page, 685 .page = snd_pcm_sgbuf_ops_page,
661}; 686};
662 687
688/* static mappings between PCMs and modules - may be dynamic in future */
689static struct hsw_pcm_module_map mod_map[] = {
690 {HSW_PCM_DAI_ID_SYSTEM, SST_HSW_MODULE_PCM_SYSTEM},
691 {HSW_PCM_DAI_ID_OFFLOAD0, SST_HSW_MODULE_PCM},
692 {HSW_PCM_DAI_ID_OFFLOAD1, SST_HSW_MODULE_PCM},
693 {HSW_PCM_DAI_ID_LOOPBACK, SST_HSW_MODULE_PCM_REFERENCE},
694 {HSW_PCM_DAI_ID_CAPTURE, SST_HSW_MODULE_PCM_CAPTURE},
695};
696
697static int hsw_pcm_create_modules(struct hsw_priv_data *pdata)
698{
699 struct sst_hsw *hsw = pdata->hsw;
700 struct hsw_pcm_data *pcm_data;
701 int i;
702
703 for (i = 0; i < ARRAY_SIZE(mod_map); i++) {
704 pcm_data = &pdata->pcm[i];
705
706 /* create new runtime module, use same offset if recreated */
707 pcm_data->runtime = sst_hsw_runtime_module_create(hsw,
708 mod_map[i].mod_id, pcm_data->persistent_offset);
709 if (pcm_data->runtime == NULL)
710 goto err;
711 pcm_data->persistent_offset =
712 pcm_data->runtime->persistent_offset;
713 }
714
715 return 0;
716
717err:
718 for (--i; i >= 0; i--) {
719 pcm_data = &pdata->pcm[i];
720 sst_hsw_runtime_module_free(pcm_data->runtime);
721 }
722
723 return -ENODEV;
724}
725
726static void hsw_pcm_free_modules(struct hsw_priv_data *pdata)
727{
728 struct hsw_pcm_data *pcm_data;
729 int i;
730
731 for (i = 0; i < ARRAY_SIZE(mod_map); i++) {
732 pcm_data = &pdata->pcm[i];
733
734 sst_hsw_runtime_module_free(pcm_data->runtime);
735 }
736}
737
663static void hsw_pcm_free(struct snd_pcm *pcm) 738static void hsw_pcm_free(struct snd_pcm *pcm)
664{ 739{
665 snd_pcm_lib_preallocate_free_for_all(pcm); 740 snd_pcm_lib_preallocate_free_for_all(pcm);
@@ -670,6 +745,7 @@ static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd)
670 struct snd_pcm *pcm = rtd->pcm; 745 struct snd_pcm *pcm = rtd->pcm;
671 struct snd_soc_platform *platform = rtd->platform; 746 struct snd_soc_platform *platform = rtd->platform;
672 struct sst_pdata *pdata = dev_get_platdata(platform->dev); 747 struct sst_pdata *pdata = dev_get_platdata(platform->dev);
748 struct hsw_priv_data *priv_data = dev_get_drvdata(platform->dev);
673 struct device *dev = pdata->dma_dev; 749 struct device *dev = pdata->dma_dev;
674 int ret = 0; 750 int ret = 0;
675 751
@@ -686,6 +762,7 @@ static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd)
686 return ret; 762 return ret;
687 } 763 }
688 } 764 }
765 priv_data->pcm[rtd->cpu_dai->id].hsw_pcm = pcm;
689 766
690 return ret; 767 return ret;
691} 768}
@@ -696,6 +773,7 @@ static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd)
696static struct snd_soc_dai_driver hsw_dais[] = { 773static struct snd_soc_dai_driver hsw_dais[] = {
697 { 774 {
698 .name = "System Pin", 775 .name = "System Pin",
776 .id = HSW_PCM_DAI_ID_SYSTEM,
699 .playback = { 777 .playback = {
700 .stream_name = "System Playback", 778 .stream_name = "System Playback",
701 .channels_min = 2, 779 .channels_min = 2,
@@ -703,10 +781,18 @@ static struct snd_soc_dai_driver hsw_dais[] = {
703 .rates = SNDRV_PCM_RATE_48000, 781 .rates = SNDRV_PCM_RATE_48000,
704 .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, 782 .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE,
705 }, 783 },
784 .capture = {
785 .stream_name = "Analog Capture",
786 .channels_min = 2,
787 .channels_max = 4,
788 .rates = SNDRV_PCM_RATE_48000,
789 .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE,
790 },
706 }, 791 },
707 { 792 {
708 /* PCM */ 793 /* PCM */
709 .name = "Offload0 Pin", 794 .name = "Offload0 Pin",
795 .id = HSW_PCM_DAI_ID_OFFLOAD0,
710 .playback = { 796 .playback = {
711 .stream_name = "Offload0 Playback", 797 .stream_name = "Offload0 Playback",
712 .channels_min = 2, 798 .channels_min = 2,
@@ -718,6 +804,7 @@ static struct snd_soc_dai_driver hsw_dais[] = {
718 { 804 {
719 /* PCM */ 805 /* PCM */
720 .name = "Offload1 Pin", 806 .name = "Offload1 Pin",
807 .id = HSW_PCM_DAI_ID_OFFLOAD1,
721 .playback = { 808 .playback = {
722 .stream_name = "Offload1 Playback", 809 .stream_name = "Offload1 Playback",
723 .channels_min = 2, 810 .channels_min = 2,
@@ -728,6 +815,7 @@ static struct snd_soc_dai_driver hsw_dais[] = {
728 }, 815 },
729 { 816 {
730 .name = "Loopback Pin", 817 .name = "Loopback Pin",
818 .id = HSW_PCM_DAI_ID_LOOPBACK,
731 .capture = { 819 .capture = {
732 .stream_name = "Loopback Capture", 820 .stream_name = "Loopback Capture",
733 .channels_min = 2, 821 .channels_min = 2,
@@ -736,16 +824,6 @@ static struct snd_soc_dai_driver hsw_dais[] = {
736 .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, 824 .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE,
737 }, 825 },
738 }, 826 },
739 {
740 .name = "Capture Pin",
741 .capture = {
742 .stream_name = "Analog Capture",
743 .channels_min = 2,
744 .channels_max = 2,
745 .rates = SNDRV_PCM_RATE_48000,
746 .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE,
747 },
748 },
749}; 827};
750 828
751static const struct snd_soc_dapm_widget widgets[] = { 829static const struct snd_soc_dapm_widget widgets[] = {
@@ -776,9 +854,20 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform)
776{ 854{
777 struct hsw_priv_data *priv_data = snd_soc_platform_get_drvdata(platform); 855 struct hsw_priv_data *priv_data = snd_soc_platform_get_drvdata(platform);
778 struct sst_pdata *pdata = dev_get_platdata(platform->dev); 856 struct sst_pdata *pdata = dev_get_platdata(platform->dev);
779 struct device *dma_dev = pdata->dma_dev; 857 struct device *dma_dev, *dev;
780 int i, ret = 0; 858 int i, ret = 0;
781 859
860 if (!pdata)
861 return -ENODEV;
862
863 dev = platform->dev;
864 dma_dev = pdata->dma_dev;
865
866 priv_data->hsw = pdata->dsp;
867 priv_data->dev = platform->dev;
868 priv_data->pm_state = HSW_PM_STATE_D0;
869 priv_data->soc_card = platform->component.card;
870
782 /* allocate DSP buffer page tables */ 871 /* allocate DSP buffer page tables */
783 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) { 872 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
784 873
@@ -801,6 +890,16 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform)
801 } 890 }
802 } 891 }
803 892
893 /* allocate runtime modules */
894 hsw_pcm_create_modules(priv_data);
895
896 /* enable runtime PM with auto suspend */
897 pm_runtime_set_autosuspend_delay(platform->dev,
898 SST_RUNTIME_SUSPEND_DELAY);
899 pm_runtime_use_autosuspend(platform->dev);
900 pm_runtime_enable(platform->dev);
901 pm_runtime_idle(platform->dev);
902
804 return 0; 903 return 0;
805 904
806err: 905err:
@@ -819,6 +918,9 @@ static int hsw_pcm_remove(struct snd_soc_platform *platform)
819 snd_soc_platform_get_drvdata(platform); 918 snd_soc_platform_get_drvdata(platform);
820 int i; 919 int i;
821 920
921 pm_runtime_disable(platform->dev);
922 hsw_pcm_free_modules(priv_data);
923
822 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) { 924 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
823 if (hsw_dais[i].playback.channels_min) 925 if (hsw_dais[i].playback.channels_min)
824 snd_dma_free_pages(&priv_data->dmab[i][0]); 926 snd_dma_free_pages(&priv_data->dmab[i][0]);
@@ -896,10 +998,181 @@ static int hsw_pcm_dev_remove(struct platform_device *pdev)
896 return 0; 998 return 0;
897} 999}
898 1000
1001#ifdef CONFIG_PM_RUNTIME
1002
1003static int hsw_pcm_runtime_idle(struct device *dev)
1004{
1005 return 0;
1006}
1007
1008static int hsw_pcm_runtime_suspend(struct device *dev)
1009{
1010 struct hsw_priv_data *pdata = dev_get_drvdata(dev);
1011 struct sst_hsw *hsw = pdata->hsw;
1012
1013 if (pdata->pm_state == HSW_PM_STATE_D3)
1014 return 0;
1015
1016 sst_hsw_dsp_runtime_suspend(hsw);
1017 sst_hsw_dsp_runtime_sleep(hsw);
1018 pdata->pm_state = HSW_PM_STATE_D3;
1019
1020 return 0;
1021}
1022
1023static int hsw_pcm_runtime_resume(struct device *dev)
1024{
1025 struct hsw_priv_data *pdata = dev_get_drvdata(dev);
1026 struct sst_hsw *hsw = pdata->hsw;
1027 int ret;
1028
1029 if (pdata->pm_state == HSW_PM_STATE_D0)
1030 return 0;
1031
1032 ret = sst_hsw_dsp_load(hsw);
1033 if (ret < 0) {
1034 dev_err(dev, "failed to reload %d\n", ret);
1035 return ret;
1036 }
1037
1038 ret = hsw_pcm_create_modules(pdata);
1039 if (ret < 0) {
1040 dev_err(dev, "failed to create modules %d\n", ret);
1041 return ret;
1042 }
1043
1044 ret = sst_hsw_dsp_runtime_resume(hsw);
1045 if (ret < 0)
1046 return ret;
1047 else if (ret == 1) /* no action required */
1048 return 0;
1049
1050 pdata->pm_state = HSW_PM_STATE_D0;
1051 return ret;
1052}
1053
1054#else
1055#define hsw_pcm_runtime_idle NULL
1056#define hsw_pcm_runtime_suspend NULL
1057#define hsw_pcm_runtime_resume NULL
1058#endif
1059
1060#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PM_RUNTIME)
1061
1062static void hsw_pcm_complete(struct device *dev)
1063{
1064 struct hsw_priv_data *pdata = dev_get_drvdata(dev);
1065 struct sst_hsw *hsw = pdata->hsw;
1066 struct hsw_pcm_data *pcm_data;
1067 int i, err;
1068
1069 if (pdata->pm_state == HSW_PM_STATE_D0)
1070 return;
1071
1072 err = sst_hsw_dsp_load(hsw);
1073 if (err < 0) {
1074 dev_err(dev, "failed to reload %d\n", err);
1075 return;
1076 }
1077
1078 err = hsw_pcm_create_modules(pdata);
1079 if (err < 0) {
1080 dev_err(dev, "failed to create modules %d\n", err);
1081 return;
1082 }
1083
1084 for (i = 0; i < HSW_PCM_DAI_ID_CAPTURE + 1; i++) {
1085 pcm_data = &pdata->pcm[i];
1086
1087 if (!pcm_data->substream)
1088 continue;
1089
1090 err = sst_module_runtime_restore(pcm_data->runtime,
1091 &pcm_data->context);
1092 if (err < 0)
1093 dev_err(dev, "failed to restore context for PCM %d\n", i);
1094 }
1095
1096 snd_soc_resume(pdata->soc_card->dev);
1097
1098 err = sst_hsw_dsp_runtime_resume(hsw);
1099 if (err < 0)
1100 return;
1101 else if (err == 1) /* no action required */
1102 return;
1103
1104 pdata->pm_state = HSW_PM_STATE_D0;
1105 return;
1106}
1107
1108static int hsw_pcm_prepare(struct device *dev)
1109{
1110 struct hsw_priv_data *pdata = dev_get_drvdata(dev);
1111 struct sst_hsw *hsw = pdata->hsw;
1112 struct hsw_pcm_data *pcm_data;
1113 int i, err;
1114
1115 if (pdata->pm_state == HSW_PM_STATE_D3)
1116 return 0;
1117 /* suspend all active streams */
1118 for (i = 0; i < HSW_PCM_DAI_ID_CAPTURE + 1; i++) {
1119 pcm_data = &pdata->pcm[i];
1120
1121 if (!pcm_data->substream)
1122 continue;
1123 dev_dbg(dev, "suspending pcm %d\n", i);
1124 snd_pcm_suspend_all(pcm_data->hsw_pcm);
1125
1126 /* We need to wait until the DSP FW stops the streams */
1127 msleep(2);
1128 }
1129
1130 snd_soc_suspend(pdata->soc_card->dev);
1131 snd_soc_poweroff(pdata->soc_card->dev);
1132
1133 /* enter D3 state and stall */
1134 sst_hsw_dsp_runtime_suspend(hsw);
1135
1136 /* preserve persistent memory */
1137 for (i = 0; i < HSW_PCM_DAI_ID_CAPTURE + 1; i++) {
1138 pcm_data = &pdata->pcm[i];
1139
1140 if (!pcm_data->substream)
1141 continue;
1142
1143 dev_dbg(dev, "saving context pcm %d\n", i);
1144 err = sst_module_runtime_save(pcm_data->runtime,
1145 &pcm_data->context);
1146 if (err < 0)
1147 dev_err(dev, "failed to save context for PCM %d\n", i);
1148 }
1149
1150 /* put the DSP to sleep */
1151 sst_hsw_dsp_runtime_sleep(hsw);
1152 pdata->pm_state = HSW_PM_STATE_D3;
1153
1154 return 0;
1155}
1156
1157#else
1158#define hsw_pcm_prepare NULL
1159#define hsw_pcm_complete NULL
1160#endif
1161
1162static const struct dev_pm_ops hsw_pcm_pm = {
1163 .runtime_idle = hsw_pcm_runtime_idle,
1164 .runtime_suspend = hsw_pcm_runtime_suspend,
1165 .runtime_resume = hsw_pcm_runtime_resume,
1166 .prepare = hsw_pcm_prepare,
1167 .complete = hsw_pcm_complete,
1168};
1169
899static struct platform_driver hsw_pcm_driver = { 1170static struct platform_driver hsw_pcm_driver = {
900 .driver = { 1171 .driver = {
901 .name = "haswell-pcm-audio", 1172 .name = "haswell-pcm-audio",
902 .owner = THIS_MODULE, 1173 .owner = THIS_MODULE,
1174 .pm = &hsw_pcm_pm,
1175
903 }, 1176 },
904 1177
905 .probe = hsw_pcm_dev_probe, 1178 .probe = hsw_pcm_dev_probe,
diff --git a/sound/soc/intel/sst-mfld-platform-compress.c b/sound/soc/intel/sst-mfld-platform-compress.c
index 59467775c9b8..395168986462 100644
--- a/sound/soc/intel/sst-mfld-platform-compress.c
+++ b/sound/soc/intel/sst-mfld-platform-compress.c
@@ -67,8 +67,11 @@ static int sst_platform_compr_open(struct snd_compr_stream *cstream)
67 goto out_ops; 67 goto out_ops;
68 } 68 }
69 stream->compr_ops = sst->compr_ops; 69 stream->compr_ops = sst->compr_ops;
70
71 stream->id = 0; 70 stream->id = 0;
71
72 /* Turn on LPE */
73 sst->compr_ops->power(sst->dev, true);
74
72 sst_set_stream_status(stream, SST_PLATFORM_INIT); 75 sst_set_stream_status(stream, SST_PLATFORM_INIT);
73 runtime->private_data = stream; 76 runtime->private_data = stream;
74 return 0; 77 return 0;
@@ -83,6 +86,9 @@ static int sst_platform_compr_free(struct snd_compr_stream *cstream)
83 int ret_val = 0, str_id; 86 int ret_val = 0, str_id;
84 87
85 stream = cstream->runtime->private_data; 88 stream = cstream->runtime->private_data;
89 /* Turn off LPE */
90 sst->compr_ops->power(sst->dev, false);
91
86 /*need to check*/ 92 /*need to check*/
87 str_id = stream->id; 93 str_id = stream->id;
88 if (str_id) 94 if (str_id)
diff --git a/sound/soc/intel/sst-mfld-platform-pcm.c b/sound/soc/intel/sst-mfld-platform-pcm.c
index aa9b600dfc9b..6032f18693be 100644
--- a/sound/soc/intel/sst-mfld-platform-pcm.c
+++ b/sound/soc/intel/sst-mfld-platform-pcm.c
@@ -101,35 +101,11 @@ static struct sst_dev_stream_map dpcm_strm_map[] = {
101 {MERR_DPCM_AUDIO, 0, SNDRV_PCM_STREAM_CAPTURE, PIPE_PCM1_OUT, SST_TASK_ID_MEDIA, 0}, 101 {MERR_DPCM_AUDIO, 0, SNDRV_PCM_STREAM_CAPTURE, PIPE_PCM1_OUT, SST_TASK_ID_MEDIA, 0},
102}; 102};
103 103
104/* MFLD - MSIC */ 104static int sst_media_digital_mute(struct snd_soc_dai *dai, int mute, int stream)
105static struct snd_soc_dai_driver sst_platform_dai[] = {
106{ 105{
107 .name = "Headset-cpu-dai", 106
108 .id = 0, 107 return sst_send_pipe_gains(dai, stream, mute);
109 .playback = { 108}
110 .channels_min = SST_STEREO,
111 .channels_max = SST_STEREO,
112 .rates = SNDRV_PCM_RATE_48000,
113 .formats = SNDRV_PCM_FMTBIT_S24_LE,
114 },
115 .capture = {
116 .channels_min = 1,
117 .channels_max = 5,
118 .rates = SNDRV_PCM_RATE_48000,
119 .formats = SNDRV_PCM_FMTBIT_S24_LE,
120 },
121},
122{
123 .name = "Compress-cpu-dai",
124 .compress_dai = 1,
125 .playback = {
126 .channels_min = SST_STEREO,
127 .channels_max = SST_STEREO,
128 .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
129 .formats = SNDRV_PCM_FMTBIT_S16_LE,
130 },
131},
132};
133 109
134/* helper functions */ 110/* helper functions */
135void sst_set_stream_status(struct sst_runtime_stream *stream, 111void sst_set_stream_status(struct sst_runtime_stream *stream,
@@ -451,12 +427,133 @@ static int sst_media_hw_free(struct snd_pcm_substream *substream,
451 return snd_pcm_lib_free_pages(substream); 427 return snd_pcm_lib_free_pages(substream);
452} 428}
453 429
430static int sst_enable_ssp(struct snd_pcm_substream *substream,
431 struct snd_soc_dai *dai)
432{
433 int ret = 0;
434
435 if (!dai->active) {
436 ret = sst_handle_vb_timer(dai, true);
437 if (ret)
438 return ret;
439 ret = send_ssp_cmd(dai, dai->name, 1);
440 }
441 return ret;
442}
443
444static void sst_disable_ssp(struct snd_pcm_substream *substream,
445 struct snd_soc_dai *dai)
446{
447 if (!dai->active) {
448 send_ssp_cmd(dai, dai->name, 0);
449 sst_handle_vb_timer(dai, false);
450 }
451}
452
454static struct snd_soc_dai_ops sst_media_dai_ops = { 453static struct snd_soc_dai_ops sst_media_dai_ops = {
455 .startup = sst_media_open, 454 .startup = sst_media_open,
456 .shutdown = sst_media_close, 455 .shutdown = sst_media_close,
457 .prepare = sst_media_prepare, 456 .prepare = sst_media_prepare,
458 .hw_params = sst_media_hw_params, 457 .hw_params = sst_media_hw_params,
459 .hw_free = sst_media_hw_free, 458 .hw_free = sst_media_hw_free,
459 .mute_stream = sst_media_digital_mute,
460};
461
462static struct snd_soc_dai_ops sst_compr_dai_ops = {
463 .mute_stream = sst_media_digital_mute,
464};
465
466static struct snd_soc_dai_ops sst_be_dai_ops = {
467 .startup = sst_enable_ssp,
468 .shutdown = sst_disable_ssp,
469};
470
471static struct snd_soc_dai_driver sst_platform_dai[] = {
472{
473 .name = "media-cpu-dai",
474 .ops = &sst_media_dai_ops,
475 .playback = {
476 .stream_name = "Headset Playback",
477 .channels_min = SST_STEREO,
478 .channels_max = SST_STEREO,
479 .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
480 .formats = SNDRV_PCM_FMTBIT_S16_LE,
481 },
482 .capture = {
483 .stream_name = "Headset Capture",
484 .channels_min = 1,
485 .channels_max = 2,
486 .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
487 .formats = SNDRV_PCM_FMTBIT_S16_LE,
488 },
489},
490{
491 .name = "compress-cpu-dai",
492 .compress_dai = 1,
493 .ops = &sst_compr_dai_ops,
494 .playback = {
495 .stream_name = "Compress Playback",
496 .channels_min = SST_STEREO,
497 .channels_max = SST_STEREO,
498 .rates = SNDRV_PCM_RATE_48000,
499 .formats = SNDRV_PCM_FMTBIT_S16_LE,
500 },
501},
502/* BE CPU Dais */
503{
504 .name = "ssp0-port",
505 .ops = &sst_be_dai_ops,
506 .playback = {
507 .stream_name = "ssp0 Tx",
508 .channels_min = SST_STEREO,
509 .channels_max = SST_STEREO,
510 .rates = SNDRV_PCM_RATE_48000,
511 .formats = SNDRV_PCM_FMTBIT_S16_LE,
512 },
513 .capture = {
514 .stream_name = "ssp0 Rx",
515 .channels_min = SST_STEREO,
516 .channels_max = SST_STEREO,
517 .rates = SNDRV_PCM_RATE_48000,
518 .formats = SNDRV_PCM_FMTBIT_S16_LE,
519 },
520},
521{
522 .name = "ssp1-port",
523 .ops = &sst_be_dai_ops,
524 .playback = {
525 .stream_name = "ssp1 Tx",
526 .channels_min = SST_STEREO,
527 .channels_max = SST_STEREO,
528 .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_48000,
529 .formats = SNDRV_PCM_FMTBIT_S16_LE,
530 },
531 .capture = {
532 .stream_name = "ssp1 Rx",
533 .channels_min = SST_STEREO,
534 .channels_max = SST_STEREO,
535 .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_48000,
536 .formats = SNDRV_PCM_FMTBIT_S16_LE,
537 },
538},
539{
540 .name = "ssp2-port",
541 .ops = &sst_be_dai_ops,
542 .playback = {
543 .stream_name = "ssp2 Tx",
544 .channels_min = SST_STEREO,
545 .channels_max = SST_STEREO,
546 .rates = SNDRV_PCM_RATE_48000,
547 .formats = SNDRV_PCM_FMTBIT_S16_LE,
548 },
549 .capture = {
550 .stream_name = "ssp2 Rx",
551 .channels_min = SST_STEREO,
552 .channels_max = SST_STEREO,
553 .rates = SNDRV_PCM_RATE_48000,
554 .formats = SNDRV_PCM_FMTBIT_S16_LE,
555 },
556},
460}; 557};
461 558
462static int sst_platform_open(struct snd_pcm_substream *substream) 559static int sst_platform_open(struct snd_pcm_substream *substream)
@@ -609,6 +706,7 @@ static int sst_platform_probe(struct platform_device *pdev)
609 pdata->pdev_strm_map = dpcm_strm_map; 706 pdata->pdev_strm_map = dpcm_strm_map;
610 pdata->strm_map_size = ARRAY_SIZE(dpcm_strm_map); 707 pdata->strm_map_size = ARRAY_SIZE(dpcm_strm_map);
611 drv->pdata = pdata; 708 drv->pdata = pdata;
709 drv->pdev = pdev;
612 mutex_init(&drv->lock); 710 mutex_init(&drv->lock);
613 dev_set_drvdata(&pdev->dev, drv); 711 dev_set_drvdata(&pdev->dev, drv);
614 712
diff --git a/sound/soc/intel/sst-mfld-platform.h b/sound/soc/intel/sst-mfld-platform.h
index 19f83ec51613..79c8d1246a8f 100644
--- a/sound/soc/intel/sst-mfld-platform.h
+++ b/sound/soc/intel/sst-mfld-platform.h
@@ -117,6 +117,7 @@ struct compress_sst_ops {
117 int (*get_codec_caps)(struct snd_compr_codec_caps *codec); 117 int (*get_codec_caps)(struct snd_compr_codec_caps *codec);
118 int (*set_metadata)(struct device *dev, unsigned int str_id, 118 int (*set_metadata)(struct device *dev, unsigned int str_id,
119 struct snd_compr_metadata *mdata); 119 struct snd_compr_metadata *mdata);
120 int (*power)(struct device *dev, bool state);
120}; 121};
121 122
122struct sst_ops { 123struct sst_ops {
@@ -153,6 +154,10 @@ struct sst_device {
153struct sst_data; 154struct sst_data;
154 155
155int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform); 156int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform);
157int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute);
158int send_ssp_cmd(struct snd_soc_dai *dai, const char *id, bool enable);
159int sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable);
160
156void sst_set_stream_status(struct sst_runtime_stream *stream, int state); 161void sst_set_stream_status(struct sst_runtime_stream *stream, int state);
157int sst_fill_stream_params(void *substream, const struct sst_data *ctx, 162int sst_fill_stream_params(void *substream, const struct sst_data *ctx,
158 struct snd_sst_params *str_params, bool is_compress); 163 struct snd_sst_params *str_params, bool is_compress);
diff --git a/sound/soc/intel/sst/Makefile b/sound/soc/intel/sst/Makefile
new file mode 100644
index 000000000000..fd21726361b5
--- /dev/null
+++ b/sound/soc/intel/sst/Makefile
@@ -0,0 +1,7 @@
1snd-intel-sst-core-objs := sst.o sst_ipc.o sst_stream.o sst_drv_interface.o sst_loader.o sst_pvt.o
2snd-intel-sst-pci-objs += sst_pci.o
3snd-intel-sst-acpi-objs += sst_acpi.o
4
5obj-$(CONFIG_SND_SST_IPC) += snd-intel-sst-core.o
6obj-$(CONFIG_SND_SST_IPC_PCI) += snd-intel-sst-pci.o
7obj-$(CONFIG_SND_SST_IPC_ACPI) += snd-intel-sst-acpi.o
diff --git a/sound/soc/intel/sst/sst.c b/sound/soc/intel/sst/sst.c
new file mode 100644
index 000000000000..8a8d56a146e7
--- /dev/null
+++ b/sound/soc/intel/sst/sst.c
@@ -0,0 +1,437 @@
1/*
2 * sst.c - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corp
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 */
22#include <linux/module.h>
23#include <linux/fs.h>
24#include <linux/interrupt.h>
25#include <linux/firmware.h>
26#include <linux/pm_runtime.h>
27#include <linux/pm_qos.h>
28#include <linux/async.h>
29#include <linux/acpi.h>
30#include <sound/core.h>
31#include <sound/soc.h>
32#include <asm/platform_sst_audio.h>
33#include "../sst-mfld-platform.h"
34#include "sst.h"
35#include "../sst-dsp.h"
36
37MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
38MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
39MODULE_DESCRIPTION("Intel (R) SST(R) Audio Engine Driver");
40MODULE_LICENSE("GPL v2");
41
42static inline bool sst_is_process_reply(u32 msg_id)
43{
44 return ((msg_id & PROCESS_MSG) ? true : false);
45}
46
47static inline bool sst_validate_mailbox_size(unsigned int size)
48{
49 return ((size <= SST_MAILBOX_SIZE) ? true : false);
50}
51
52static irqreturn_t intel_sst_interrupt_mrfld(int irq, void *context)
53{
54 union interrupt_reg_mrfld isr;
55 union ipc_header_mrfld header;
56 union sst_imr_reg_mrfld imr;
57 struct ipc_post *msg = NULL;
58 unsigned int size = 0;
59 struct intel_sst_drv *drv = (struct intel_sst_drv *) context;
60 irqreturn_t retval = IRQ_HANDLED;
61
62 /* Interrupt arrived, check src */
63 isr.full = sst_shim_read64(drv->shim, SST_ISRX);
64
65 if (isr.part.done_interrupt) {
66 /* Clear done bit */
67 spin_lock(&drv->ipc_spin_lock);
68 header.full = sst_shim_read64(drv->shim,
69 drv->ipc_reg.ipcx);
70 header.p.header_high.part.done = 0;
71 sst_shim_write64(drv->shim, drv->ipc_reg.ipcx, header.full);
72
73 /* write 1 to clear status register */;
74 isr.part.done_interrupt = 1;
75 sst_shim_write64(drv->shim, SST_ISRX, isr.full);
76 spin_unlock(&drv->ipc_spin_lock);
77
78 /* we can send more messages to DSP so trigger work */
79 queue_work(drv->post_msg_wq, &drv->ipc_post_msg_wq);
80 retval = IRQ_HANDLED;
81 }
82
83 if (isr.part.busy_interrupt) {
84 /* message from dsp so copy that */
85 spin_lock(&drv->ipc_spin_lock);
86 imr.full = sst_shim_read64(drv->shim, SST_IMRX);
87 imr.part.busy_interrupt = 1;
88 sst_shim_write64(drv->shim, SST_IMRX, imr.full);
89 spin_unlock(&drv->ipc_spin_lock);
90 header.full = sst_shim_read64(drv->shim, drv->ipc_reg.ipcd);
91
92 if (sst_create_ipc_msg(&msg, header.p.header_high.part.large)) {
93 drv->ops->clear_interrupt(drv);
94 return IRQ_HANDLED;
95 }
96
97 if (header.p.header_high.part.large) {
98 size = header.p.header_low_payload;
99 if (sst_validate_mailbox_size(size)) {
100 memcpy_fromio(msg->mailbox_data,
101 drv->mailbox + drv->mailbox_recv_offset, size);
102 } else {
103 dev_err(drv->dev,
104 "Mailbox not copied, payload size is: %u\n", size);
105 header.p.header_low_payload = 0;
106 }
107 }
108
109 msg->mrfld_header = header;
110 msg->is_process_reply =
111 sst_is_process_reply(header.p.header_high.part.msg_id);
112 spin_lock(&drv->rx_msg_lock);
113 list_add_tail(&msg->node, &drv->rx_list);
114 spin_unlock(&drv->rx_msg_lock);
115 drv->ops->clear_interrupt(drv);
116 retval = IRQ_WAKE_THREAD;
117 }
118 return retval;
119}
120
121static irqreturn_t intel_sst_irq_thread_mrfld(int irq, void *context)
122{
123 struct intel_sst_drv *drv = (struct intel_sst_drv *) context;
124 struct ipc_post *__msg, *msg = NULL;
125 unsigned long irq_flags;
126
127 spin_lock_irqsave(&drv->rx_msg_lock, irq_flags);
128 if (list_empty(&drv->rx_list)) {
129 spin_unlock_irqrestore(&drv->rx_msg_lock, irq_flags);
130 return IRQ_HANDLED;
131 }
132
133 list_for_each_entry_safe(msg, __msg, &drv->rx_list, node) {
134 list_del(&msg->node);
135 spin_unlock_irqrestore(&drv->rx_msg_lock, irq_flags);
136 if (msg->is_process_reply)
137 drv->ops->process_message(msg);
138 else
139 drv->ops->process_reply(drv, msg);
140
141 if (msg->is_large)
142 kfree(msg->mailbox_data);
143 kfree(msg);
144 spin_lock_irqsave(&drv->rx_msg_lock, irq_flags);
145 }
146 spin_unlock_irqrestore(&drv->rx_msg_lock, irq_flags);
147 return IRQ_HANDLED;
148}
149
150static int sst_save_dsp_context_v2(struct intel_sst_drv *sst)
151{
152 int ret = 0;
153
154 ret = sst_prepare_and_post_msg(sst, SST_TASK_ID_MEDIA, IPC_CMD,
155 IPC_PREP_D3, PIPE_RSVD, 0, NULL, NULL,
156 true, true, false, true);
157
158 if (ret < 0) {
159 dev_err(sst->dev, "not suspending FW!!, Err: %d\n", ret);
160 return -EIO;
161 }
162
163 return 0;
164}
165
166
167static struct intel_sst_ops mrfld_ops = {
168 .interrupt = intel_sst_interrupt_mrfld,
169 .irq_thread = intel_sst_irq_thread_mrfld,
170 .clear_interrupt = intel_sst_clear_intr_mrfld,
171 .start = sst_start_mrfld,
172 .reset = intel_sst_reset_dsp_mrfld,
173 .post_message = sst_post_message_mrfld,
174 .process_reply = sst_process_reply_mrfld,
175 .save_dsp_context = sst_save_dsp_context_v2,
176 .alloc_stream = sst_alloc_stream_mrfld,
177 .post_download = sst_post_download_mrfld,
178};
179
180int sst_driver_ops(struct intel_sst_drv *sst)
181{
182
183 switch (sst->dev_id) {
184 case SST_MRFLD_PCI_ID:
185 case SST_BYT_ACPI_ID:
186 case SST_CHV_ACPI_ID:
187 sst->tstamp = SST_TIME_STAMP_MRFLD;
188 sst->ops = &mrfld_ops;
189 return 0;
190
191 default:
192 dev_err(sst->dev,
193 "SST Driver capablities missing for dev_id: %x", sst->dev_id);
194 return -EINVAL;
195 };
196}
197
198void sst_process_pending_msg(struct work_struct *work)
199{
200 struct intel_sst_drv *ctx = container_of(work,
201 struct intel_sst_drv, ipc_post_msg_wq);
202
203 ctx->ops->post_message(ctx, NULL, false);
204}
205
206static int sst_workqueue_init(struct intel_sst_drv *ctx)
207{
208 INIT_LIST_HEAD(&ctx->memcpy_list);
209 INIT_LIST_HEAD(&ctx->rx_list);
210 INIT_LIST_HEAD(&ctx->ipc_dispatch_list);
211 INIT_LIST_HEAD(&ctx->block_list);
212 INIT_WORK(&ctx->ipc_post_msg_wq, sst_process_pending_msg);
213 init_waitqueue_head(&ctx->wait_queue);
214
215 ctx->post_msg_wq =
216 create_singlethread_workqueue("sst_post_msg_wq");
217 if (!ctx->post_msg_wq)
218 return -EBUSY;
219 return 0;
220}
221
222static void sst_init_locks(struct intel_sst_drv *ctx)
223{
224 mutex_init(&ctx->sst_lock);
225 spin_lock_init(&ctx->rx_msg_lock);
226 spin_lock_init(&ctx->ipc_spin_lock);
227 spin_lock_init(&ctx->block_lock);
228}
229
230int sst_alloc_drv_context(struct intel_sst_drv **ctx,
231 struct device *dev, unsigned int dev_id)
232{
233 *ctx = devm_kzalloc(dev, sizeof(struct intel_sst_drv), GFP_KERNEL);
234 if (!(*ctx))
235 return -ENOMEM;
236
237 (*ctx)->dev = dev;
238 (*ctx)->dev_id = dev_id;
239
240 return 0;
241}
242EXPORT_SYMBOL_GPL(sst_alloc_drv_context);
243
244int sst_context_init(struct intel_sst_drv *ctx)
245{
246 int ret = 0, i;
247
248 if (!ctx->pdata)
249 return -EINVAL;
250
251 if (!ctx->pdata->probe_data)
252 return -EINVAL;
253
254 memcpy(&ctx->info, ctx->pdata->probe_data, sizeof(ctx->info));
255
256 ret = sst_driver_ops(ctx);
257 if (ret != 0)
258 return -EINVAL;
259
260 sst_init_locks(ctx);
261 sst_set_fw_state_locked(ctx, SST_RESET);
262
263 /* pvt_id 0 reserved for async messages */
264 ctx->pvt_id = 1;
265 ctx->stream_cnt = 0;
266 ctx->fw_in_mem = NULL;
267 /* we use memcpy, so set to 0 */
268 ctx->use_dma = 0;
269 ctx->use_lli = 0;
270
271 if (sst_workqueue_init(ctx))
272 return -EINVAL;
273
274 ctx->mailbox_recv_offset = ctx->pdata->ipc_info->mbox_recv_off;
275 ctx->ipc_reg.ipcx = SST_IPCX + ctx->pdata->ipc_info->ipc_offset;
276 ctx->ipc_reg.ipcd = SST_IPCD + ctx->pdata->ipc_info->ipc_offset;
277
278 dev_info(ctx->dev, "Got drv data max stream %d\n",
279 ctx->info.max_streams);
280
281 for (i = 1; i <= ctx->info.max_streams; i++) {
282 struct stream_info *stream = &ctx->streams[i];
283
284 memset(stream, 0, sizeof(*stream));
285 stream->pipe_id = PIPE_RSVD;
286 mutex_init(&stream->lock);
287 }
288
289 /* Register the ISR */
290 ret = devm_request_threaded_irq(ctx->dev, ctx->irq_num, ctx->ops->interrupt,
291 ctx->ops->irq_thread, 0, SST_DRV_NAME,
292 ctx);
293 if (ret)
294 goto do_free_mem;
295
296 dev_dbg(ctx->dev, "Registered IRQ %#x\n", ctx->irq_num);
297
298 /* default intr are unmasked so set this as masked */
299 sst_shim_write64(ctx->shim, SST_IMRX, 0xFFFF0038);
300
301 ctx->qos = devm_kzalloc(ctx->dev,
302 sizeof(struct pm_qos_request), GFP_KERNEL);
303 if (!ctx->qos) {
304 ret = -ENOMEM;
305 goto do_free_mem;
306 }
307 pm_qos_add_request(ctx->qos, PM_QOS_CPU_DMA_LATENCY,
308 PM_QOS_DEFAULT_VALUE);
309
310 dev_dbg(ctx->dev, "Requesting FW %s now...\n", ctx->firmware_name);
311 ret = request_firmware_nowait(THIS_MODULE, true, ctx->firmware_name,
312 ctx->dev, GFP_KERNEL, ctx, sst_firmware_load_cb);
313 if (ret) {
314 dev_err(ctx->dev, "Firmware download failed:%d\n", ret);
315 goto do_free_mem;
316 }
317 sst_register(ctx->dev);
318 return 0;
319
320do_free_mem:
321 destroy_workqueue(ctx->post_msg_wq);
322 return ret;
323}
324EXPORT_SYMBOL_GPL(sst_context_init);
325
326void sst_context_cleanup(struct intel_sst_drv *ctx)
327{
328 pm_runtime_get_noresume(ctx->dev);
329 pm_runtime_disable(ctx->dev);
330 sst_unregister(ctx->dev);
331 sst_set_fw_state_locked(ctx, SST_SHUTDOWN);
332 flush_scheduled_work();
333 destroy_workqueue(ctx->post_msg_wq);
334 pm_qos_remove_request(ctx->qos);
335 kfree(ctx->fw_sg_list.src);
336 kfree(ctx->fw_sg_list.dst);
337 ctx->fw_sg_list.list_len = 0;
338 kfree(ctx->fw_in_mem);
339 ctx->fw_in_mem = NULL;
340 sst_memcpy_free_resources(ctx);
341 ctx = NULL;
342}
343EXPORT_SYMBOL_GPL(sst_context_cleanup);
344
345static inline void sst_save_shim64(struct intel_sst_drv *ctx,
346 void __iomem *shim,
347 struct sst_shim_regs64 *shim_regs)
348{
349 unsigned long irq_flags;
350
351 spin_lock_irqsave(&ctx->ipc_spin_lock, irq_flags);
352
353 shim_regs->imrx = sst_shim_read64(shim, SST_IMRX),
354
355 spin_unlock_irqrestore(&ctx->ipc_spin_lock, irq_flags);
356}
357
358static inline void sst_restore_shim64(struct intel_sst_drv *ctx,
359 void __iomem *shim,
360 struct sst_shim_regs64 *shim_regs)
361{
362 unsigned long irq_flags;
363
364 /*
365 * we only need to restore IMRX for this case, rest will be
366 * initialize by FW or driver when firmware is loaded
367 */
368 spin_lock_irqsave(&ctx->ipc_spin_lock, irq_flags);
369 sst_shim_write64(shim, SST_IMRX, shim_regs->imrx),
370 spin_unlock_irqrestore(&ctx->ipc_spin_lock, irq_flags);
371}
372
373void sst_configure_runtime_pm(struct intel_sst_drv *ctx)
374{
375 pm_runtime_set_autosuspend_delay(ctx->dev, SST_SUSPEND_DELAY);
376 pm_runtime_use_autosuspend(ctx->dev);
377 /*
378 * For acpi devices, the actual physical device state is
379 * initially active. So change the state to active before
380 * enabling the pm
381 */
382 pm_runtime_enable(ctx->dev);
383
384 if (acpi_disabled)
385 pm_runtime_set_active(ctx->dev);
386 else
387 pm_runtime_put_noidle(ctx->dev);
388
389 sst_save_shim64(ctx, ctx->shim, ctx->shim_regs64);
390}
391EXPORT_SYMBOL_GPL(sst_configure_runtime_pm);
392
393static int intel_sst_runtime_suspend(struct device *dev)
394{
395 int ret = 0;
396 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
397
398 if (ctx->sst_state == SST_RESET) {
399 dev_dbg(dev, "LPE is already in RESET state, No action\n");
400 return 0;
401 }
402 /* save fw context */
403 if (ctx->ops->save_dsp_context(ctx))
404 return -EBUSY;
405
406 /* Move the SST state to Reset */
407 sst_set_fw_state_locked(ctx, SST_RESET);
408
409 synchronize_irq(ctx->irq_num);
410 flush_workqueue(ctx->post_msg_wq);
411
412 /* save the shim registers because PMC doesn't save state */
413 sst_save_shim64(ctx, ctx->shim, ctx->shim_regs64);
414
415 return ret;
416}
417
418static int intel_sst_runtime_resume(struct device *dev)
419{
420 int ret = 0;
421 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
422
423 if (ctx->sst_state == SST_RESET) {
424 ret = sst_load_fw(ctx);
425 if (ret) {
426 dev_err(dev, "FW download fail %d\n", ret);
427 sst_set_fw_state_locked(ctx, SST_RESET);
428 }
429 }
430 return ret;
431}
432
433const struct dev_pm_ops intel_sst_pm = {
434 .runtime_suspend = intel_sst_runtime_suspend,
435 .runtime_resume = intel_sst_runtime_resume,
436};
437EXPORT_SYMBOL_GPL(intel_sst_pm);
diff --git a/sound/soc/intel/sst/sst.h b/sound/soc/intel/sst/sst.h
new file mode 100644
index 000000000000..7f4bbfcbc6f5
--- /dev/null
+++ b/sound/soc/intel/sst/sst.h
@@ -0,0 +1,546 @@
1/*
2 * sst.h - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corporation
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 *
22 * Common private declarations for SST
23 */
24#ifndef __SST_H__
25#define __SST_H__
26
27#include <linux/firmware.h>
28
29/* driver names */
30#define SST_DRV_NAME "intel_sst_driver"
31#define SST_MRFLD_PCI_ID 0x119A
32#define SST_BYT_ACPI_ID 0x80860F28
33#define SST_CHV_ACPI_ID 0x808622A8
34
35#define SST_SUSPEND_DELAY 2000
36#define FW_CONTEXT_MEM (64*1024)
37#define SST_ICCM_BOUNDARY 4
38#define SST_CONFIG_SSP_SIGN 0x7ffe8001
39
40#define MRFLD_FW_VIRTUAL_BASE 0xC0000000
41#define MRFLD_FW_DDR_BASE_OFFSET 0x0
42#define MRFLD_FW_FEATURE_BASE_OFFSET 0x4
43#define MRFLD_FW_BSS_RESET_BIT 0
44
45extern const struct dev_pm_ops intel_sst_pm;
46enum sst_states {
47 SST_FW_LOADING = 1,
48 SST_FW_RUNNING,
49 SST_RESET,
50 SST_SHUTDOWN,
51};
52
53enum sst_algo_ops {
54 SST_SET_ALGO = 0,
55 SST_GET_ALGO = 1,
56};
57
58#define SST_BLOCK_TIMEOUT 1000
59
60#define FW_SIGNATURE_SIZE 4
61
62/* stream states */
63enum sst_stream_states {
64 STREAM_UN_INIT = 0, /* Freed/Not used stream */
65 STREAM_RUNNING = 1, /* Running */
66 STREAM_PAUSED = 2, /* Paused stream */
67 STREAM_DECODE = 3, /* stream is in decoding only state */
68 STREAM_INIT = 4, /* stream init, waiting for data */
69 STREAM_RESET = 5, /* force reset on recovery */
70};
71
72enum sst_ram_type {
73 SST_IRAM = 1,
74 SST_DRAM = 2,
75 SST_DDR = 5,
76 SST_CUSTOM_INFO = 7, /* consists of FW binary information */
77};
78
79/* SST shim registers to structure mapping */
80union interrupt_reg {
81 struct {
82 u64 done_interrupt:1;
83 u64 busy_interrupt:1;
84 u64 rsvd:62;
85 } part;
86 u64 full;
87};
88
89union sst_pisr_reg {
90 struct {
91 u32 pssp0:1;
92 u32 pssp1:1;
93 u32 rsvd0:3;
94 u32 dmac:1;
95 u32 rsvd1:26;
96 } part;
97 u32 full;
98};
99
100union sst_pimr_reg {
101 struct {
102 u32 ssp0:1;
103 u32 ssp1:1;
104 u32 rsvd0:3;
105 u32 dmac:1;
106 u32 rsvd1:10;
107 u32 ssp0_sc:1;
108 u32 ssp1_sc:1;
109 u32 rsvd2:3;
110 u32 dmac_sc:1;
111 u32 rsvd3:10;
112 } part;
113 u32 full;
114};
115
116union config_status_reg_mrfld {
117 struct {
118 u64 lpe_reset:1;
119 u64 lpe_reset_vector:1;
120 u64 runstall:1;
121 u64 pwaitmode:1;
122 u64 clk_sel:3;
123 u64 rsvd2:1;
124 u64 sst_clk:3;
125 u64 xt_snoop:1;
126 u64 rsvd3:4;
127 u64 clk_sel1:6;
128 u64 clk_enable:3;
129 u64 rsvd4:6;
130 u64 slim0baseclk:1;
131 u64 rsvd:32;
132 } part;
133 u64 full;
134};
135
136union interrupt_reg_mrfld {
137 struct {
138 u64 done_interrupt:1;
139 u64 busy_interrupt:1;
140 u64 rsvd:62;
141 } part;
142 u64 full;
143};
144
145union sst_imr_reg_mrfld {
146 struct {
147 u64 done_interrupt:1;
148 u64 busy_interrupt:1;
149 u64 rsvd:62;
150 } part;
151 u64 full;
152};
153
154/**
155 * struct sst_block - This structure is used to block a user/fw data call to another
156 * fw/user call
157 *
158 * @condition: condition for blocking check
159 * @ret_code: ret code when block is released
160 * @data: data ptr
161 * @size: size of data
162 * @on: block condition
163 * @msg_id: msg_id = msgid in mfld/ctp, mrfld = NULL
164 * @drv_id: str_id in mfld/ctp, = drv_id in mrfld
165 * @node: list head node
166 */
167struct sst_block {
168 bool condition;
169 int ret_code;
170 void *data;
171 u32 size;
172 bool on;
173 u32 msg_id;
174 u32 drv_id;
175 struct list_head node;
176};
177
178/**
179 * struct stream_info - structure that holds the stream information
180 *
181 * @status : stream current state
182 * @prev : stream prev state
183 * @ops : stream operation pb/cp/drm...
184 * @bufs: stream buffer list
185 * @lock : stream mutex for protecting state
186 * @pcm_substream : PCM substream
187 * @period_elapsed : PCM period elapsed callback
188 * @sfreq : stream sampling freq
189 * @str_type : stream type
190 * @cumm_bytes : cummulative bytes decoded
191 * @str_type : stream type
192 * @src : stream source
193 */
194struct stream_info {
195 unsigned int status;
196 unsigned int prev;
197 unsigned int ops;
198 struct mutex lock;
199
200 void *pcm_substream;
201 void (*period_elapsed)(void *pcm_substream);
202
203 unsigned int sfreq;
204 u32 cumm_bytes;
205
206 void *compr_cb_param;
207 void (*compr_cb)(void *compr_cb_param);
208
209 void *drain_cb_param;
210 void (*drain_notify)(void *drain_cb_param);
211
212 unsigned int num_ch;
213 unsigned int pipe_id;
214 unsigned int str_id;
215 unsigned int task_id;
216};
217
218#define SST_FW_SIGN "$SST"
219#define SST_FW_LIB_SIGN "$LIB"
220
221/**
222 * struct sst_fw_header - FW file headers
223 *
224 * @signature : FW signature
225 * @file_size: size of fw image
226 * @modules : # of modules
227 * @file_format : version of header format
228 * @reserved : reserved fields
229 */
230struct sst_fw_header {
231 unsigned char signature[FW_SIGNATURE_SIZE];
232 u32 file_size;
233 u32 modules;
234 u32 file_format;
235 u32 reserved[4];
236};
237
238/**
239 * struct fw_module_header - module header in FW
240 *
241 * @signature: module signature
242 * @mod_size: size of module
243 * @blocks: block count
244 * @type: block type
245 * @entry_point: module netry point
246 */
247struct fw_module_header {
248 unsigned char signature[FW_SIGNATURE_SIZE];
249 u32 mod_size;
250 u32 blocks;
251 u32 type;
252 u32 entry_point;
253};
254
255/**
256 * struct fw_block_info - block header for FW
257 *
258 * @type: block ram type I/D
259 * @size: size of block
260 * @ram_offset: offset in ram
261 */
262struct fw_block_info {
263 enum sst_ram_type type;
264 u32 size;
265 u32 ram_offset;
266 u32 rsvd;
267};
268
269struct sst_runtime_param {
270 struct snd_sst_runtime_params param;
271};
272
273struct sst_sg_list {
274 struct scatterlist *src;
275 struct scatterlist *dst;
276 int list_len;
277 unsigned int sg_idx;
278};
279
280struct sst_memcpy_list {
281 struct list_head memcpylist;
282 void *dstn;
283 const void *src;
284 u32 size;
285 bool is_io;
286};
287
288/*Firmware Module Information*/
289enum sst_lib_dwnld_status {
290 SST_LIB_NOT_FOUND = 0,
291 SST_LIB_FOUND,
292 SST_LIB_DOWNLOADED,
293};
294
295struct sst_module_info {
296 const char *name; /*Library name*/
297 u32 id; /*Module ID*/
298 u32 entry_pt; /*Module entry point*/
299 u8 status; /*module status*/
300 u8 rsvd1;
301 u16 rsvd2;
302};
303
304/*
305 * Structure for managing the Library Region(1.5MB)
306 * in DDR in Merrifield
307 */
308struct sst_mem_mgr {
309 phys_addr_t current_base;
310 int avail;
311 unsigned int count;
312};
313
314struct sst_ipc_reg {
315 int ipcx;
316 int ipcd;
317};
318
319struct sst_shim_regs64 {
320 u64 csr;
321 u64 pisr;
322 u64 pimr;
323 u64 isrx;
324 u64 isrd;
325 u64 imrx;
326 u64 imrd;
327 u64 ipcx;
328 u64 ipcd;
329 u64 isrsc;
330 u64 isrlpesc;
331 u64 imrsc;
332 u64 imrlpesc;
333 u64 ipcsc;
334 u64 ipclpesc;
335 u64 clkctl;
336 u64 csr2;
337};
338
339/**
340 * struct intel_sst_drv - driver ops
341 *
342 * @sst_state : current sst device state
343 * @dev_id : device identifier, pci_id for pci devices and acpi_id for acpi
344 * devices
345 * @shim : SST shim pointer
346 * @mailbox : SST mailbox pointer
347 * @iram : SST IRAM pointer
348 * @dram : SST DRAM pointer
349 * @pdata : SST info passed as a part of pci platform data
350 * @shim_phy_add : SST shim phy addr
351 * @shim_regs64: Struct to save shim registers
352 * @ipc_dispatch_list : ipc messages dispatched
353 * @rx_list : to copy the process_reply/process_msg from DSP
354 * @ipc_post_msg_wq : wq to post IPC messages context
355 * @mad_ops : MAD driver operations registered
356 * @mad_wq : MAD driver wq
357 * @post_msg_wq : wq to post IPC messages
358 * @streams : sst stream contexts
359 * @list_lock : sst driver list lock (deprecated)
360 * @ipc_spin_lock : spin lock to handle audio shim access and ipc queue
361 * @block_lock : spin lock to add block to block_list and assign pvt_id
362 * @rx_msg_lock : spin lock to handle the rx messages from the DSP
363 * @scard_ops : sst card ops
364 * @pci : sst pci device struture
365 * @dev : pointer to current device struct
366 * @sst_lock : sst device lock
367 * @pvt_id : sst private id
368 * @stream_cnt : total sst active stream count
369 * @pb_streams : total active pb streams
370 * @cp_streams : total active cp streams
371 * @audio_start : audio status
372 * @qos : PM Qos struct
373 * firmware_name : Firmware / Library name
374 */
375struct intel_sst_drv {
376 int sst_state;
377 int irq_num;
378 unsigned int dev_id;
379 void __iomem *ddr;
380 void __iomem *shim;
381 void __iomem *mailbox;
382 void __iomem *iram;
383 void __iomem *dram;
384 unsigned int mailbox_add;
385 unsigned int iram_base;
386 unsigned int dram_base;
387 unsigned int shim_phy_add;
388 unsigned int iram_end;
389 unsigned int dram_end;
390 unsigned int ddr_end;
391 unsigned int ddr_base;
392 unsigned int mailbox_recv_offset;
393 struct sst_shim_regs64 *shim_regs64;
394 struct list_head block_list;
395 struct list_head ipc_dispatch_list;
396 struct sst_platform_info *pdata;
397 struct list_head rx_list;
398 struct work_struct ipc_post_msg_wq;
399 wait_queue_head_t wait_queue;
400 struct workqueue_struct *post_msg_wq;
401 unsigned int tstamp;
402 /* str_id 0 is not used */
403 struct stream_info streams[MAX_NUM_STREAMS+1];
404 spinlock_t ipc_spin_lock;
405 spinlock_t block_lock;
406 spinlock_t rx_msg_lock;
407 struct pci_dev *pci;
408 struct device *dev;
409 volatile long unsigned pvt_id;
410 struct mutex sst_lock;
411 unsigned int stream_cnt;
412 unsigned int csr_value;
413 void *fw_in_mem;
414 struct sst_sg_list fw_sg_list, library_list;
415 struct intel_sst_ops *ops;
416 struct sst_info info;
417 struct pm_qos_request *qos;
418 unsigned int use_dma;
419 unsigned int use_lli;
420 atomic_t fw_clear_context;
421 bool lib_dwnld_reqd;
422 struct list_head memcpy_list;
423 struct sst_ipc_reg ipc_reg;
424 struct sst_mem_mgr lib_mem_mgr;
425 /*
426 * Holder for firmware name. Due to async call it needs to be
427 * persistent till worker thread gets called
428 */
429 char firmware_name[20];
430};
431
432/* misc definitions */
433#define FW_DWNL_ID 0x01
434
435struct intel_sst_ops {
436 irqreturn_t (*interrupt)(int, void *);
437 irqreturn_t (*irq_thread)(int, void *);
438 void (*clear_interrupt)(struct intel_sst_drv *ctx);
439 int (*start)(struct intel_sst_drv *ctx);
440 int (*reset)(struct intel_sst_drv *ctx);
441 void (*process_reply)(struct intel_sst_drv *ctx, struct ipc_post *msg);
442 int (*post_message)(struct intel_sst_drv *ctx,
443 struct ipc_post *msg, bool sync);
444 void (*process_message)(struct ipc_post *msg);
445 void (*set_bypass)(bool set);
446 int (*save_dsp_context)(struct intel_sst_drv *sst);
447 void (*restore_dsp_context)(void);
448 int (*alloc_stream)(struct intel_sst_drv *ctx, void *params);
449 void (*post_download)(struct intel_sst_drv *sst);
450};
451
452int sst_pause_stream(struct intel_sst_drv *sst_drv_ctx, int id);
453int sst_resume_stream(struct intel_sst_drv *sst_drv_ctx, int id);
454int sst_drop_stream(struct intel_sst_drv *sst_drv_ctx, int id);
455int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int id);
456int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
457int sst_send_byte_stream_mrfld(struct intel_sst_drv *ctx,
458 struct snd_sst_bytes_v2 *sbytes);
459int sst_set_stream_param(int str_id, struct snd_sst_params *str_param);
460int sst_set_metadata(int str_id, char *params);
461int sst_get_stream(struct intel_sst_drv *sst_drv_ctx,
462 struct snd_sst_params *str_param);
463int sst_get_stream_allocated(struct intel_sst_drv *ctx,
464 struct snd_sst_params *str_param,
465 struct snd_sst_lib_download **lib_dnld);
466int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx,
467 int str_id, bool partial_drain);
468int sst_post_message_mrfld(struct intel_sst_drv *ctx,
469 struct ipc_post *msg, bool sync);
470void sst_process_reply_mrfld(struct intel_sst_drv *ctx, struct ipc_post *msg);
471int sst_start_mrfld(struct intel_sst_drv *ctx);
472int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *ctx);
473void intel_sst_clear_intr_mrfld(struct intel_sst_drv *ctx);
474
475int sst_load_fw(struct intel_sst_drv *ctx);
476int sst_load_library(struct snd_sst_lib_download *lib, u8 ops);
477void sst_post_download_mrfld(struct intel_sst_drv *ctx);
478int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx);
479void sst_memcpy_free_resources(struct intel_sst_drv *ctx);
480
481int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
482 struct sst_block *block);
483int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
484 struct sst_block *block);
485int sst_create_ipc_msg(struct ipc_post **arg, bool large);
486int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id);
487void sst_clean_stream(struct stream_info *stream);
488int intel_sst_register_compress(struct intel_sst_drv *sst);
489int intel_sst_remove_compress(struct intel_sst_drv *sst);
490void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id);
491int sst_send_sync_msg(int ipc, int str_id);
492int sst_get_num_channel(struct snd_sst_params *str_param);
493int sst_get_sfreq(struct snd_sst_params *str_param);
494int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params);
495void sst_restore_fw_context(void);
496struct sst_block *sst_create_block(struct intel_sst_drv *ctx,
497 u32 msg_id, u32 drv_id);
498int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large,
499 struct intel_sst_drv *sst_drv_ctx, struct sst_block **block,
500 u32 msg_id, u32 drv_id);
501int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed);
502int sst_wake_up_block(struct intel_sst_drv *ctx, int result,
503 u32 drv_id, u32 ipc, void *data, u32 size);
504int sst_request_firmware_async(struct intel_sst_drv *ctx);
505int sst_driver_ops(struct intel_sst_drv *sst);
506struct sst_platform_info *sst_get_acpi_driver_data(const char *hid);
507void sst_firmware_load_cb(const struct firmware *fw, void *context);
508int sst_prepare_and_post_msg(struct intel_sst_drv *sst,
509 int task_id, int ipc_msg, int cmd_id, int pipe_id,
510 size_t mbox_data_len, const void *mbox_data, void **data,
511 bool large, bool fill_dsp, bool sync, bool response);
512
513void sst_process_pending_msg(struct work_struct *work);
514int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx);
515void sst_init_stream(struct stream_info *stream,
516 int codec, int sst_id, int ops, u8 slot);
517int sst_validate_strid(struct intel_sst_drv *sst_drv_ctx, int str_id);
518struct stream_info *get_stream_info(struct intel_sst_drv *sst_drv_ctx,
519 int str_id);
520int get_stream_id_mrfld(struct intel_sst_drv *sst_drv_ctx,
521 u32 pipe_id);
522u32 relocate_imr_addr_mrfld(u32 base_addr);
523void sst_add_to_dispatch_list_and_post(struct intel_sst_drv *sst,
524 struct ipc_post *msg);
525int sst_pm_runtime_put(struct intel_sst_drv *sst_drv);
526int sst_shim_write(void __iomem *addr, int offset, int value);
527u32 sst_shim_read(void __iomem *addr, int offset);
528u64 sst_reg_read64(void __iomem *addr, int offset);
529int sst_shim_write64(void __iomem *addr, int offset, u64 value);
530u64 sst_shim_read64(void __iomem *addr, int offset);
531void sst_set_fw_state_locked(
532 struct intel_sst_drv *sst_drv_ctx, int sst_state);
533void sst_fill_header_mrfld(union ipc_header_mrfld *header,
534 int msg, int task_id, int large, int drv_id);
535void sst_fill_header_dsp(struct ipc_dsp_hdr *dsp, int msg,
536 int pipe_id, int len);
537
538int sst_register(struct device *);
539int sst_unregister(struct device *);
540
541int sst_alloc_drv_context(struct intel_sst_drv **ctx,
542 struct device *dev, unsigned int dev_id);
543int sst_context_init(struct intel_sst_drv *ctx);
544void sst_context_cleanup(struct intel_sst_drv *ctx);
545void sst_configure_runtime_pm(struct intel_sst_drv *ctx);
546#endif
diff --git a/sound/soc/intel/sst/sst_acpi.c b/sound/soc/intel/sst/sst_acpi.c
new file mode 100644
index 000000000000..31124aa4434e
--- /dev/null
+++ b/sound/soc/intel/sst/sst_acpi.c
@@ -0,0 +1,383 @@
1/*
2 * sst_acpi.c - SST (LPE) driver init file for ACPI enumeration.
3 *
4 * Copyright (c) 2013, Intel Corporation.
5 *
6 * Authors: Ramesh Babu K V <Ramesh.Babu@intel.com>
7 * Authors: Omair Mohammed Abdullah <omair.m.abdullah@intel.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 *
19 */
20
21#include <linux/module.h>
22#include <linux/fs.h>
23#include <linux/interrupt.h>
24#include <linux/slab.h>
25#include <linux/io.h>
26#include <linux/miscdevice.h>
27#include <linux/platform_device.h>
28#include <linux/firmware.h>
29#include <linux/pm_runtime.h>
30#include <linux/pm_qos.h>
31#include <linux/acpi.h>
32#include <asm/platform_sst_audio.h>
33#include <sound/core.h>
34#include <sound/soc.h>
35#include <sound/compress_driver.h>
36#include <acpi/acbuffer.h>
37#include <acpi/platform/acenv.h>
38#include <acpi/platform/aclinux.h>
39#include <acpi/actypes.h>
40#include <acpi/acpi_bus.h>
41#include "../sst-mfld-platform.h"
42#include "../sst-dsp.h"
43#include "sst.h"
44
45struct sst_machines {
46 char codec_id[32];
47 char board[32];
48 char machine[32];
49 void (*machine_quirk)(void);
50 char firmware[32];
51 struct sst_platform_info *pdata;
52
53};
54
55/* LPE viewpoint addresses */
56#define SST_BYT_IRAM_PHY_START 0xff2c0000
57#define SST_BYT_IRAM_PHY_END 0xff2d4000
58#define SST_BYT_DRAM_PHY_START 0xff300000
59#define SST_BYT_DRAM_PHY_END 0xff320000
60#define SST_BYT_IMR_VIRT_START 0xc0000000 /* virtual addr in LPE */
61#define SST_BYT_IMR_VIRT_END 0xc01fffff
62#define SST_BYT_SHIM_PHY_ADDR 0xff340000
63#define SST_BYT_MBOX_PHY_ADDR 0xff344000
64#define SST_BYT_DMA0_PHY_ADDR 0xff298000
65#define SST_BYT_DMA1_PHY_ADDR 0xff29c000
66#define SST_BYT_SSP0_PHY_ADDR 0xff2a0000
67#define SST_BYT_SSP2_PHY_ADDR 0xff2a2000
68
69#define BYT_FW_MOD_TABLE_OFFSET 0x80000
70#define BYT_FW_MOD_TABLE_SIZE 0x100
71#define BYT_FW_MOD_OFFSET (BYT_FW_MOD_TABLE_OFFSET + BYT_FW_MOD_TABLE_SIZE)
72
73static const struct sst_info byt_fwparse_info = {
74 .use_elf = false,
75 .max_streams = 25,
76 .iram_start = SST_BYT_IRAM_PHY_START,
77 .iram_end = SST_BYT_IRAM_PHY_END,
78 .iram_use = true,
79 .dram_start = SST_BYT_DRAM_PHY_START,
80 .dram_end = SST_BYT_DRAM_PHY_END,
81 .dram_use = true,
82 .imr_start = SST_BYT_IMR_VIRT_START,
83 .imr_end = SST_BYT_IMR_VIRT_END,
84 .imr_use = true,
85 .mailbox_start = SST_BYT_MBOX_PHY_ADDR,
86 .num_probes = 0,
87 .lpe_viewpt_rqd = true,
88};
89
90static const struct sst_ipc_info byt_ipc_info = {
91 .ipc_offset = 0,
92 .mbox_recv_off = 0x400,
93};
94
95static const struct sst_lib_dnld_info byt_lib_dnld_info = {
96 .mod_base = SST_BYT_IMR_VIRT_START,
97 .mod_end = SST_BYT_IMR_VIRT_END,
98 .mod_table_offset = BYT_FW_MOD_TABLE_OFFSET,
99 .mod_table_size = BYT_FW_MOD_TABLE_SIZE,
100 .mod_ddr_dnld = false,
101};
102
103static const struct sst_res_info byt_rvp_res_info = {
104 .shim_offset = 0x140000,
105 .shim_size = 0x000100,
106 .shim_phy_addr = SST_BYT_SHIM_PHY_ADDR,
107 .ssp0_offset = 0xa0000,
108 .ssp0_size = 0x1000,
109 .dma0_offset = 0x98000,
110 .dma0_size = 0x4000,
111 .dma1_offset = 0x9c000,
112 .dma1_size = 0x4000,
113 .iram_offset = 0x0c0000,
114 .iram_size = 0x14000,
115 .dram_offset = 0x100000,
116 .dram_size = 0x28000,
117 .mbox_offset = 0x144000,
118 .mbox_size = 0x1000,
119 .acpi_lpe_res_index = 0,
120 .acpi_ddr_index = 2,
121 .acpi_ipc_irq_index = 5,
122};
123
124static struct sst_platform_info byt_rvp_platform_data = {
125 .probe_data = &byt_fwparse_info,
126 .ipc_info = &byt_ipc_info,
127 .lib_info = &byt_lib_dnld_info,
128 .res_info = &byt_rvp_res_info,
129 .platform = "sst-mfld-platform",
130};
131
132/* Cherryview (Cherrytrail and Braswell) uses same mrfld dpcm fw as Baytrail,
133 * so pdata is same as Baytrail.
134 */
135static struct sst_platform_info chv_platform_data = {
136 .probe_data = &byt_fwparse_info,
137 .ipc_info = &byt_ipc_info,
138 .lib_info = &byt_lib_dnld_info,
139 .res_info = &byt_rvp_res_info,
140 .platform = "sst-mfld-platform",
141};
142
143static int sst_platform_get_resources(struct intel_sst_drv *ctx)
144{
145 struct resource *rsrc;
146 struct platform_device *pdev = to_platform_device(ctx->dev);
147
148 /* All ACPI resource request here */
149 /* Get Shim addr */
150 rsrc = platform_get_resource(pdev, IORESOURCE_MEM,
151 ctx->pdata->res_info->acpi_lpe_res_index);
152 if (!rsrc) {
153 dev_err(ctx->dev, "Invalid SHIM base from IFWI");
154 return -EIO;
155 }
156 dev_info(ctx->dev, "LPE base: %#x size:%#x", (unsigned int) rsrc->start,
157 (unsigned int)resource_size(rsrc));
158
159 ctx->iram_base = rsrc->start + ctx->pdata->res_info->iram_offset;
160 ctx->iram_end = ctx->iram_base + ctx->pdata->res_info->iram_size - 1;
161 dev_info(ctx->dev, "IRAM base: %#x", ctx->iram_base);
162 ctx->iram = devm_ioremap_nocache(ctx->dev, ctx->iram_base,
163 ctx->pdata->res_info->iram_size);
164 if (!ctx->iram) {
165 dev_err(ctx->dev, "unable to map IRAM");
166 return -EIO;
167 }
168
169 ctx->dram_base = rsrc->start + ctx->pdata->res_info->dram_offset;
170 ctx->dram_end = ctx->dram_base + ctx->pdata->res_info->dram_size - 1;
171 dev_info(ctx->dev, "DRAM base: %#x", ctx->dram_base);
172 ctx->dram = devm_ioremap_nocache(ctx->dev, ctx->dram_base,
173 ctx->pdata->res_info->dram_size);
174 if (!ctx->dram) {
175 dev_err(ctx->dev, "unable to map DRAM");
176 return -EIO;
177 }
178
179 ctx->shim_phy_add = rsrc->start + ctx->pdata->res_info->shim_offset;
180 dev_info(ctx->dev, "SHIM base: %#x", ctx->shim_phy_add);
181 ctx->shim = devm_ioremap_nocache(ctx->dev, ctx->shim_phy_add,
182 ctx->pdata->res_info->shim_size);
183 if (!ctx->shim) {
184 dev_err(ctx->dev, "unable to map SHIM");
185 return -EIO;
186 }
187
188 /* reassign physical address to LPE viewpoint address */
189 ctx->shim_phy_add = ctx->pdata->res_info->shim_phy_addr;
190
191 /* Get mailbox addr */
192 ctx->mailbox_add = rsrc->start + ctx->pdata->res_info->mbox_offset;
193 dev_info(ctx->dev, "Mailbox base: %#x", ctx->mailbox_add);
194 ctx->mailbox = devm_ioremap_nocache(ctx->dev, ctx->mailbox_add,
195 ctx->pdata->res_info->mbox_size);
196 if (!ctx->mailbox) {
197 dev_err(ctx->dev, "unable to map mailbox");
198 return -EIO;
199 }
200
201 /* reassign physical address to LPE viewpoint address */
202 ctx->mailbox_add = ctx->info.mailbox_start;
203
204 rsrc = platform_get_resource(pdev, IORESOURCE_MEM,
205 ctx->pdata->res_info->acpi_ddr_index);
206 if (!rsrc) {
207 dev_err(ctx->dev, "Invalid DDR base from IFWI");
208 return -EIO;
209 }
210 ctx->ddr_base = rsrc->start;
211 ctx->ddr_end = rsrc->end;
212 dev_info(ctx->dev, "DDR base: %#x", ctx->ddr_base);
213 ctx->ddr = devm_ioremap_nocache(ctx->dev, ctx->ddr_base,
214 resource_size(rsrc));
215 if (!ctx->ddr) {
216 dev_err(ctx->dev, "unable to map DDR");
217 return -EIO;
218 }
219
220 /* Find the IRQ */
221 ctx->irq_num = platform_get_irq(pdev,
222 ctx->pdata->res_info->acpi_ipc_irq_index);
223 return 0;
224}
225
226static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level,
227 void *context, void **ret)
228{
229 *(bool *)context = true;
230 return AE_OK;
231}
232
233static struct sst_machines *sst_acpi_find_machine(
234 struct sst_machines *machines)
235{
236 struct sst_machines *mach;
237 bool found = false;
238
239 for (mach = machines; mach->codec_id; mach++)
240 if (ACPI_SUCCESS(acpi_get_devices(mach->codec_id,
241 sst_acpi_mach_match,
242 &found, NULL)) && found)
243 return mach;
244
245 return NULL;
246}
247
248int sst_acpi_probe(struct platform_device *pdev)
249{
250 struct device *dev = &pdev->dev;
251 int ret = 0;
252 struct intel_sst_drv *ctx;
253 const struct acpi_device_id *id;
254 struct sst_machines *mach;
255 struct platform_device *mdev;
256 struct platform_device *plat_dev;
257 unsigned int dev_id;
258
259 id = acpi_match_device(dev->driver->acpi_match_table, dev);
260 if (!id)
261 return -ENODEV;
262 dev_dbg(dev, "for %s", id->id);
263
264 mach = (struct sst_machines *)id->driver_data;
265 mach = sst_acpi_find_machine(mach);
266 if (mach == NULL) {
267 dev_err(dev, "No matching machine driver found\n");
268 return -ENODEV;
269 }
270
271 ret = kstrtouint(id->id, 16, &dev_id);
272 if (ret < 0) {
273 dev_err(dev, "Unique device id conversion error: %d\n", ret);
274 return ret;
275 }
276
277 dev_dbg(dev, "ACPI device id: %x\n", dev_id);
278
279 plat_dev = platform_device_register_data(dev, mach->pdata->platform, -1, NULL, 0);
280 if (plat_dev == NULL) {
281 dev_err(dev, "Failed to create machine device: %s\n", mach->pdata->platform);
282 return -ENODEV;
283 }
284
285 /* Create platform device for sst machine driver */
286 mdev = platform_device_register_data(dev, mach->machine, -1, NULL, 0);
287 if (mdev == NULL) {
288 dev_err(dev, "Failed to create machine device: %s\n", mach->machine);
289 return -ENODEV;
290 }
291
292 ret = sst_alloc_drv_context(&ctx, dev, dev_id);
293 if (ret < 0)
294 return ret;
295
296 /* Fill sst platform data */
297 ctx->pdata = mach->pdata;
298 strcpy(ctx->firmware_name, mach->firmware);
299
300 ret = sst_platform_get_resources(ctx);
301 if (ret)
302 return ret;
303
304 ret = sst_context_init(ctx);
305 if (ret < 0)
306 return ret;
307
308 /* need to save shim registers in BYT */
309 ctx->shim_regs64 = devm_kzalloc(ctx->dev, sizeof(*ctx->shim_regs64),
310 GFP_KERNEL);
311 if (!ctx->shim_regs64) {
312 return -ENOMEM;
313 goto do_sst_cleanup;
314 }
315
316 sst_configure_runtime_pm(ctx);
317 platform_set_drvdata(pdev, ctx);
318 return ret;
319
320do_sst_cleanup:
321 sst_context_cleanup(ctx);
322 platform_set_drvdata(pdev, NULL);
323 dev_err(ctx->dev, "failed with %d\n", ret);
324 return ret;
325}
326
327/**
328* intel_sst_remove - remove function
329*
330* @pdev: platform device structure
331*
332* This function is called by OS when a device is unloaded
333* This frees the interrupt etc
334*/
335int sst_acpi_remove(struct platform_device *pdev)
336{
337 struct intel_sst_drv *ctx;
338
339 ctx = platform_get_drvdata(pdev);
340 sst_context_cleanup(ctx);
341 platform_set_drvdata(pdev, NULL);
342 return 0;
343}
344
345static struct sst_machines sst_acpi_bytcr[] = {
346 {"10EC5640", "T100", "bytt100_rt5640", NULL, "fw_sst_0f28.bin",
347 &byt_rvp_platform_data },
348 {},
349};
350
351/* Cherryview-based platforms: CherryTrail and Braswell */
352static struct sst_machines sst_acpi_chv[] = {
353 {"10EC5670", "cht-bsw", "cht-bsw-rt5672", NULL, "fw_sst_22a8.bin",
354 &chv_platform_data },
355 {},
356};
357
358static const struct acpi_device_id sst_acpi_ids[] = {
359 { "80860F28", (unsigned long)&sst_acpi_bytcr},
360 { "808622A8", (unsigned long) &sst_acpi_chv},
361 { },
362};
363
364MODULE_DEVICE_TABLE(acpi, sst_acpi_ids);
365
366static struct platform_driver sst_acpi_driver = {
367 .driver = {
368 .name = "intel_sst_acpi",
369 .owner = THIS_MODULE,
370 .acpi_match_table = ACPI_PTR(sst_acpi_ids),
371 .pm = &intel_sst_pm,
372 },
373 .probe = sst_acpi_probe,
374 .remove = sst_acpi_remove,
375};
376
377module_platform_driver(sst_acpi_driver);
378
379MODULE_DESCRIPTION("Intel (R) SST(R) Audio Engine ACPI Driver");
380MODULE_AUTHOR("Ramesh Babu K V");
381MODULE_AUTHOR("Omair Mohammed Abdullah");
382MODULE_LICENSE("GPL v2");
383MODULE_ALIAS("sst");
diff --git a/sound/soc/intel/sst/sst_drv_interface.c b/sound/soc/intel/sst/sst_drv_interface.c
new file mode 100644
index 000000000000..5f75ef3cdd22
--- /dev/null
+++ b/sound/soc/intel/sst/sst_drv_interface.c
@@ -0,0 +1,686 @@
1/*
2 * sst_drv_interface.c - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corp
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com)
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 as published by
12 * the Free Software Foundation; version 2 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; 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 */
21#include <linux/delay.h>
22#include <linux/pci.h>
23#include <linux/fs.h>
24#include <linux/firmware.h>
25#include <linux/pm_runtime.h>
26#include <linux/pm_qos.h>
27#include <linux/math64.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/soc.h>
31#include <sound/compress_driver.h>
32#include <asm/platform_sst_audio.h>
33#include "../sst-mfld-platform.h"
34#include "sst.h"
35#include "../sst-dsp.h"
36
37
38
39#define NUM_CODEC 2
40#define MIN_FRAGMENT 2
41#define MAX_FRAGMENT 4
42#define MIN_FRAGMENT_SIZE (50 * 1024)
43#define MAX_FRAGMENT_SIZE (1024 * 1024)
44#define SST_GET_BYTES_PER_SAMPLE(pcm_wd_sz) (((pcm_wd_sz + 15) >> 4) << 1)
45
46int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id)
47{
48 struct stream_info *stream;
49 int ret = 0;
50
51 stream = get_stream_info(ctx, str_id);
52 if (stream) {
53 /* str_id is valid, so stream is alloacted */
54 ret = sst_free_stream(ctx, str_id);
55 if (ret)
56 sst_clean_stream(&ctx->streams[str_id]);
57 return ret;
58 } else {
59 dev_err(ctx->dev, "we tried to free stream context %d which was freed!!!\n", str_id);
60 }
61 return ret;
62}
63
64int sst_get_stream_allocated(struct intel_sst_drv *ctx,
65 struct snd_sst_params *str_param,
66 struct snd_sst_lib_download **lib_dnld)
67{
68 int retval;
69
70 retval = ctx->ops->alloc_stream(ctx, str_param);
71 if (retval > 0)
72 dev_dbg(ctx->dev, "Stream allocated %d\n", retval);
73 return retval;
74
75}
76
77/*
78 * sst_get_sfreq - this function returns the frequency of the stream
79 *
80 * @str_param : stream params
81 */
82int sst_get_sfreq(struct snd_sst_params *str_param)
83{
84 switch (str_param->codec) {
85 case SST_CODEC_TYPE_PCM:
86 return str_param->sparams.uc.pcm_params.sfreq;
87 case SST_CODEC_TYPE_AAC:
88 return str_param->sparams.uc.aac_params.externalsr;
89 case SST_CODEC_TYPE_MP3:
90 return 0;
91 default:
92 return -EINVAL;
93 }
94}
95
96/*
97 * sst_get_num_channel - get number of channels for the stream
98 *
99 * @str_param : stream params
100 */
101int sst_get_num_channel(struct snd_sst_params *str_param)
102{
103 switch (str_param->codec) {
104 case SST_CODEC_TYPE_PCM:
105 return str_param->sparams.uc.pcm_params.num_chan;
106 case SST_CODEC_TYPE_MP3:
107 return str_param->sparams.uc.mp3_params.num_chan;
108 case SST_CODEC_TYPE_AAC:
109 return str_param->sparams.uc.aac_params.num_chan;
110 default:
111 return -EINVAL;
112 }
113}
114
115/*
116 * sst_get_stream - this function prepares for stream allocation
117 *
118 * @str_param : stream param
119 */
120int sst_get_stream(struct intel_sst_drv *ctx,
121 struct snd_sst_params *str_param)
122{
123 int retval;
124 struct stream_info *str_info;
125
126 /* stream is not allocated, we are allocating */
127 retval = ctx->ops->alloc_stream(ctx, str_param);
128 if (retval <= 0) {
129 return -EIO;
130 }
131 /* store sampling freq */
132 str_info = &ctx->streams[retval];
133 str_info->sfreq = sst_get_sfreq(str_param);
134
135 return retval;
136}
137
138static int sst_power_control(struct device *dev, bool state)
139{
140 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
141
142 dev_dbg(ctx->dev, "state:%d", state);
143 if (state == true)
144 return pm_runtime_get_sync(dev);
145 else
146 return sst_pm_runtime_put(ctx);
147}
148
149/*
150 * sst_open_pcm_stream - Open PCM interface
151 *
152 * @str_param: parameters of pcm stream
153 *
154 * This function is called by MID sound card driver to open
155 * a new pcm interface
156 */
157static int sst_open_pcm_stream(struct device *dev,
158 struct snd_sst_params *str_param)
159{
160 int retval;
161 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
162
163 if (!str_param)
164 return -EINVAL;
165
166 retval = sst_get_stream(ctx, str_param);
167 if (retval > 0)
168 ctx->stream_cnt++;
169 else
170 dev_err(ctx->dev, "sst_get_stream returned err %d\n", retval);
171
172 return retval;
173}
174
175static int sst_cdev_open(struct device *dev,
176 struct snd_sst_params *str_params, struct sst_compress_cb *cb)
177{
178 int str_id, retval;
179 struct stream_info *stream;
180 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
181
182 retval = pm_runtime_get_sync(ctx->dev);
183 if (retval < 0)
184 return retval;
185
186 str_id = sst_get_stream(ctx, str_params);
187 if (str_id > 0) {
188 dev_dbg(dev, "stream allocated in sst_cdev_open %d\n", str_id);
189 stream = &ctx->streams[str_id];
190 stream->compr_cb = cb->compr_cb;
191 stream->compr_cb_param = cb->param;
192 stream->drain_notify = cb->drain_notify;
193 stream->drain_cb_param = cb->drain_cb_param;
194 } else {
195 dev_err(dev, "stream encountered error during alloc %d\n", str_id);
196 str_id = -EINVAL;
197 sst_pm_runtime_put(ctx);
198 }
199 return str_id;
200}
201
202static int sst_cdev_close(struct device *dev, unsigned int str_id)
203{
204 int retval;
205 struct stream_info *stream;
206 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
207
208 stream = get_stream_info(ctx, str_id);
209 if (!stream) {
210 dev_err(dev, "stream info is NULL for str %d!!!\n", str_id);
211 return -EINVAL;
212 }
213
214 if (stream->status == STREAM_RESET) {
215 dev_dbg(dev, "stream in reset state...\n");
216 stream->status = STREAM_UN_INIT;
217
218 retval = 0;
219 goto put;
220 }
221
222 retval = sst_free_stream(ctx, str_id);
223put:
224 stream->compr_cb_param = NULL;
225 stream->compr_cb = NULL;
226
227 if (retval)
228 dev_err(dev, "free stream returned err %d\n", retval);
229
230 dev_dbg(dev, "End\n");
231 return retval;
232
233}
234
235static int sst_cdev_ack(struct device *dev, unsigned int str_id,
236 unsigned long bytes)
237{
238 struct stream_info *stream;
239 struct snd_sst_tstamp fw_tstamp = {0,};
240 int offset;
241 void __iomem *addr;
242 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
243
244 stream = get_stream_info(ctx, str_id);
245 if (!stream)
246 return -EINVAL;
247
248 /* update bytes sent */
249 stream->cumm_bytes += bytes;
250 dev_dbg(dev, "bytes copied %d inc by %ld\n", stream->cumm_bytes, bytes);
251
252 memcpy_fromio(&fw_tstamp,
253 ((void *)(ctx->mailbox + ctx->tstamp)
254 +(str_id * sizeof(fw_tstamp))),
255 sizeof(fw_tstamp));
256
257 fw_tstamp.bytes_copied = stream->cumm_bytes;
258 dev_dbg(dev, "bytes sent to fw %llu inc by %ld\n",
259 fw_tstamp.bytes_copied, bytes);
260
261 addr = ((void *)(ctx->mailbox + ctx->tstamp)) +
262 (str_id * sizeof(fw_tstamp));
263 offset = offsetof(struct snd_sst_tstamp, bytes_copied);
264 sst_shim_write(addr, offset, fw_tstamp.bytes_copied);
265 return 0;
266}
267
268static int sst_cdev_set_metadata(struct device *dev,
269 unsigned int str_id, struct snd_compr_metadata *metadata)
270{
271 int retval = 0;
272 struct stream_info *str_info;
273 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
274
275 dev_dbg(dev, "set metadata for stream %d\n", str_id);
276
277 str_info = get_stream_info(ctx, str_id);
278 if (!str_info)
279 return -EINVAL;
280
281 dev_dbg(dev, "pipe id = %d\n", str_info->pipe_id);
282 retval = sst_prepare_and_post_msg(ctx, str_info->task_id, IPC_CMD,
283 IPC_IA_SET_STREAM_PARAMS_MRFLD, str_info->pipe_id,
284 sizeof(*metadata), metadata, NULL,
285 true, true, true, false);
286
287 return retval;
288}
289
290static int sst_cdev_stream_pause(struct device *dev, unsigned int str_id)
291{
292 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
293
294 return sst_pause_stream(ctx, str_id);
295}
296
297static int sst_cdev_stream_pause_release(struct device *dev,
298 unsigned int str_id)
299{
300 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
301
302 return sst_resume_stream(ctx, str_id);
303}
304
305static int sst_cdev_stream_start(struct device *dev, unsigned int str_id)
306{
307 struct stream_info *str_info;
308 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
309
310 str_info = get_stream_info(ctx, str_id);
311 if (!str_info)
312 return -EINVAL;
313 str_info->prev = str_info->status;
314 str_info->status = STREAM_RUNNING;
315 return sst_start_stream(ctx, str_id);
316}
317
318static int sst_cdev_stream_drop(struct device *dev, unsigned int str_id)
319{
320 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
321
322 return sst_drop_stream(ctx, str_id);
323}
324
325static int sst_cdev_stream_drain(struct device *dev, unsigned int str_id)
326{
327 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
328
329 return sst_drain_stream(ctx, str_id, false);
330}
331
332static int sst_cdev_stream_partial_drain(struct device *dev,
333 unsigned int str_id)
334{
335 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
336
337 return sst_drain_stream(ctx, str_id, true);
338}
339
340static int sst_cdev_tstamp(struct device *dev, unsigned int str_id,
341 struct snd_compr_tstamp *tstamp)
342{
343 struct snd_sst_tstamp fw_tstamp = {0,};
344 struct stream_info *stream;
345 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
346
347 memcpy_fromio(&fw_tstamp,
348 ((void *)(ctx->mailbox + ctx->tstamp)
349 +(str_id * sizeof(fw_tstamp))),
350 sizeof(fw_tstamp));
351
352 stream = get_stream_info(ctx, str_id);
353 if (!stream)
354 return -EINVAL;
355 dev_dbg(dev, "rb_counter %llu in bytes\n", fw_tstamp.ring_buffer_counter);
356
357 tstamp->copied_total = fw_tstamp.ring_buffer_counter;
358 tstamp->pcm_frames = fw_tstamp.frames_decoded;
359 tstamp->pcm_io_frames = div_u64(fw_tstamp.hardware_counter,
360 (u64)((stream->num_ch) * SST_GET_BYTES_PER_SAMPLE(24)));
361 tstamp->sampling_rate = fw_tstamp.sampling_frequency;
362
363 dev_dbg(dev, "PCM = %u\n", tstamp->pcm_io_frames);
364 dev_dbg(dev, "Ptr Query on strid = %d copied_total %d, decodec %d\n",
365 str_id, tstamp->copied_total, tstamp->pcm_frames);
366 dev_dbg(dev, "rendered %d\n", tstamp->pcm_io_frames);
367
368 return 0;
369}
370
371static int sst_cdev_caps(struct snd_compr_caps *caps)
372{
373 caps->num_codecs = NUM_CODEC;
374 caps->min_fragment_size = MIN_FRAGMENT_SIZE; /* 50KB */
375 caps->max_fragment_size = MAX_FRAGMENT_SIZE; /* 1024KB */
376 caps->min_fragments = MIN_FRAGMENT;
377 caps->max_fragments = MAX_FRAGMENT;
378 caps->codecs[0] = SND_AUDIOCODEC_MP3;
379 caps->codecs[1] = SND_AUDIOCODEC_AAC;
380 return 0;
381}
382
383static struct snd_compr_codec_caps caps_mp3 = {
384 .num_descriptors = 1,
385 .descriptor[0].max_ch = 2,
386 .descriptor[0].sample_rates[0] = 48000,
387 .descriptor[0].sample_rates[1] = 44100,
388 .descriptor[0].sample_rates[2] = 32000,
389 .descriptor[0].sample_rates[3] = 16000,
390 .descriptor[0].sample_rates[4] = 8000,
391 .descriptor[0].num_sample_rates = 5,
392 .descriptor[0].bit_rate[0] = 320,
393 .descriptor[0].bit_rate[1] = 192,
394 .descriptor[0].num_bitrates = 2,
395 .descriptor[0].profiles = 0,
396 .descriptor[0].modes = SND_AUDIOCHANMODE_MP3_STEREO,
397 .descriptor[0].formats = 0,
398};
399
400static struct snd_compr_codec_caps caps_aac = {
401 .num_descriptors = 2,
402 .descriptor[1].max_ch = 2,
403 .descriptor[0].sample_rates[0] = 48000,
404 .descriptor[0].sample_rates[1] = 44100,
405 .descriptor[0].sample_rates[2] = 32000,
406 .descriptor[0].sample_rates[3] = 16000,
407 .descriptor[0].sample_rates[4] = 8000,
408 .descriptor[0].num_sample_rates = 5,
409 .descriptor[1].bit_rate[0] = 320,
410 .descriptor[1].bit_rate[1] = 192,
411 .descriptor[1].num_bitrates = 2,
412 .descriptor[1].profiles = 0,
413 .descriptor[1].modes = 0,
414 .descriptor[1].formats =
415 (SND_AUDIOSTREAMFORMAT_MP4ADTS |
416 SND_AUDIOSTREAMFORMAT_RAW),
417};
418
419static int sst_cdev_codec_caps(struct snd_compr_codec_caps *codec)
420{
421 if (codec->codec == SND_AUDIOCODEC_MP3)
422 *codec = caps_mp3;
423 else if (codec->codec == SND_AUDIOCODEC_AAC)
424 *codec = caps_aac;
425 else
426 return -EINVAL;
427
428 return 0;
429}
430
431void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id)
432{
433 struct stream_info *stream;
434
435 dev_dbg(ctx->dev, "fragment elapsed from firmware for str_id %d\n",
436 str_id);
437 stream = &ctx->streams[str_id];
438 if (stream->compr_cb)
439 stream->compr_cb(stream->compr_cb_param);
440}
441
442/*
443 * sst_close_pcm_stream - Close PCM interface
444 *
445 * @str_id: stream id to be closed
446 *
447 * This function is called by MID sound card driver to close
448 * an existing pcm interface
449 */
450static int sst_close_pcm_stream(struct device *dev, unsigned int str_id)
451{
452 struct stream_info *stream;
453 int retval = 0;
454 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
455
456 stream = get_stream_info(ctx, str_id);
457 if (!stream) {
458 dev_err(ctx->dev, "stream info is NULL for str %d!!!\n", str_id);
459 return -EINVAL;
460 }
461
462 if (stream->status == STREAM_RESET) {
463 /* silently fail here as we have cleaned the stream earlier */
464 dev_dbg(ctx->dev, "stream in reset state...\n");
465
466 retval = 0;
467 goto put;
468 }
469
470 retval = free_stream_context(ctx, str_id);
471put:
472 stream->pcm_substream = NULL;
473 stream->status = STREAM_UN_INIT;
474 stream->period_elapsed = NULL;
475 ctx->stream_cnt--;
476
477 if (retval)
478 dev_err(ctx->dev, "free stream returned err %d\n", retval);
479
480 dev_dbg(ctx->dev, "Exit\n");
481 return 0;
482}
483
484static inline int sst_calc_tstamp(struct intel_sst_drv *ctx,
485 struct pcm_stream_info *info,
486 struct snd_pcm_substream *substream,
487 struct snd_sst_tstamp *fw_tstamp)
488{
489 size_t delay_bytes, delay_frames;
490 size_t buffer_sz;
491 u32 pointer_bytes, pointer_samples;
492
493 dev_dbg(ctx->dev, "mrfld ring_buffer_counter %llu in bytes\n",
494 fw_tstamp->ring_buffer_counter);
495 dev_dbg(ctx->dev, "mrfld hardware_counter %llu in bytes\n",
496 fw_tstamp->hardware_counter);
497 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
498 delay_bytes = (size_t) (fw_tstamp->ring_buffer_counter -
499 fw_tstamp->hardware_counter);
500 else
501 delay_bytes = (size_t) (fw_tstamp->hardware_counter -
502 fw_tstamp->ring_buffer_counter);
503 delay_frames = bytes_to_frames(substream->runtime, delay_bytes);
504 buffer_sz = snd_pcm_lib_buffer_bytes(substream);
505 div_u64_rem(fw_tstamp->ring_buffer_counter, buffer_sz, &pointer_bytes);
506 pointer_samples = bytes_to_samples(substream->runtime, pointer_bytes);
507
508 dev_dbg(ctx->dev, "pcm delay %zu in bytes\n", delay_bytes);
509
510 info->buffer_ptr = pointer_samples / substream->runtime->channels;
511
512 info->pcm_delay = delay_frames / substream->runtime->channels;
513 dev_dbg(ctx->dev, "buffer ptr %llu pcm_delay rep: %llu\n",
514 info->buffer_ptr, info->pcm_delay);
515 return 0;
516}
517
518static int sst_read_timestamp(struct device *dev, struct pcm_stream_info *info)
519{
520 struct stream_info *stream;
521 struct snd_pcm_substream *substream;
522 struct snd_sst_tstamp fw_tstamp;
523 unsigned int str_id;
524 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
525
526 str_id = info->str_id;
527 stream = get_stream_info(ctx, str_id);
528 if (!stream)
529 return -EINVAL;
530
531 if (!stream->pcm_substream)
532 return -EINVAL;
533 substream = stream->pcm_substream;
534
535 memcpy_fromio(&fw_tstamp,
536 ((void *)(ctx->mailbox + ctx->tstamp)
537 + (str_id * sizeof(fw_tstamp))),
538 sizeof(fw_tstamp));
539 return sst_calc_tstamp(ctx, info, substream, &fw_tstamp);
540}
541
542static int sst_stream_start(struct device *dev, int str_id)
543{
544 struct stream_info *str_info;
545 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
546
547 if (ctx->sst_state != SST_FW_RUNNING)
548 return 0;
549 str_info = get_stream_info(ctx, str_id);
550 if (!str_info)
551 return -EINVAL;
552 str_info->prev = str_info->status;
553 str_info->status = STREAM_RUNNING;
554 sst_start_stream(ctx, str_id);
555
556 return 0;
557}
558
559static int sst_stream_drop(struct device *dev, int str_id)
560{
561 struct stream_info *str_info;
562 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
563
564 if (ctx->sst_state != SST_FW_RUNNING)
565 return 0;
566
567 str_info = get_stream_info(ctx, str_id);
568 if (!str_info)
569 return -EINVAL;
570 str_info->prev = STREAM_UN_INIT;
571 str_info->status = STREAM_INIT;
572 return sst_drop_stream(ctx, str_id);
573}
574
575static int sst_stream_init(struct device *dev, struct pcm_stream_info *str_info)
576{
577 int str_id = 0;
578 struct stream_info *stream;
579 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
580
581 str_id = str_info->str_id;
582
583 if (ctx->sst_state != SST_FW_RUNNING)
584 return 0;
585
586 stream = get_stream_info(ctx, str_id);
587 if (!stream)
588 return -EINVAL;
589
590 dev_dbg(ctx->dev, "setting the period ptrs\n");
591 stream->pcm_substream = str_info->arg;
592 stream->period_elapsed = str_info->period_elapsed;
593 stream->sfreq = str_info->sfreq;
594 stream->prev = stream->status;
595 stream->status = STREAM_INIT;
596 dev_dbg(ctx->dev,
597 "pcm_substream %p, period_elapsed %p, sfreq %d, status %d\n",
598 stream->pcm_substream, stream->period_elapsed,
599 stream->sfreq, stream->status);
600
601 return 0;
602}
603
604/*
605 * sst_set_byte_stream - Set generic params
606 *
607 * @cmd: control cmd to be set
608 * @arg: command argument
609 *
610 * This function is called by MID sound card driver to configure
611 * SST runtime params.
612 */
613static int sst_send_byte_stream(struct device *dev,
614 struct snd_sst_bytes_v2 *bytes)
615{
616 int ret_val = 0;
617 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
618
619 if (NULL == bytes)
620 return -EINVAL;
621 ret_val = pm_runtime_get_sync(ctx->dev);
622 if (ret_val < 0)
623 return ret_val;
624
625 ret_val = sst_send_byte_stream_mrfld(ctx, bytes);
626 sst_pm_runtime_put(ctx);
627
628 return ret_val;
629}
630
631static struct sst_ops pcm_ops = {
632 .open = sst_open_pcm_stream,
633 .stream_init = sst_stream_init,
634 .stream_start = sst_stream_start,
635 .stream_drop = sst_stream_drop,
636 .stream_read_tstamp = sst_read_timestamp,
637 .send_byte_stream = sst_send_byte_stream,
638 .close = sst_close_pcm_stream,
639 .power = sst_power_control,
640};
641
642static struct compress_sst_ops compr_ops = {
643 .open = sst_cdev_open,
644 .close = sst_cdev_close,
645 .stream_pause = sst_cdev_stream_pause,
646 .stream_pause_release = sst_cdev_stream_pause_release,
647 .stream_start = sst_cdev_stream_start,
648 .stream_drop = sst_cdev_stream_drop,
649 .stream_drain = sst_cdev_stream_drain,
650 .stream_partial_drain = sst_cdev_stream_partial_drain,
651 .tstamp = sst_cdev_tstamp,
652 .ack = sst_cdev_ack,
653 .get_caps = sst_cdev_caps,
654 .get_codec_caps = sst_cdev_codec_caps,
655 .set_metadata = sst_cdev_set_metadata,
656 .power = sst_power_control,
657};
658
659static struct sst_device sst_dsp_device = {
660 .name = "Intel(R) SST LPE",
661 .dev = NULL,
662 .ops = &pcm_ops,
663 .compr_ops = &compr_ops,
664};
665
666/*
667 * sst_register - function to register DSP
668 *
669 * This functions registers DSP with the platform driver
670 */
671int sst_register(struct device *dev)
672{
673 int ret_val;
674
675 sst_dsp_device.dev = dev;
676 ret_val = sst_register_dsp(&sst_dsp_device);
677 if (ret_val)
678 dev_err(dev, "Unable to register DSP with platform driver\n");
679
680 return ret_val;
681}
682
683int sst_unregister(struct device *dev)
684{
685 return sst_unregister_dsp(&sst_dsp_device);
686}
diff --git a/sound/soc/intel/sst/sst_ipc.c b/sound/soc/intel/sst/sst_ipc.c
new file mode 100644
index 000000000000..484e60978477
--- /dev/null
+++ b/sound/soc/intel/sst/sst_ipc.c
@@ -0,0 +1,373 @@
1/*
2 * sst_ipc.c - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corporation
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 */
22#include <linux/pci.h>
23#include <linux/firmware.h>
24#include <linux/sched.h>
25#include <linux/delay.h>
26#include <linux/pm_runtime.h>
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/soc.h>
30#include <sound/compress_driver.h>
31#include <asm/intel-mid.h>
32#include <asm/platform_sst_audio.h>
33#include "../sst-mfld-platform.h"
34#include "sst.h"
35#include "../sst-dsp.h"
36
37struct sst_block *sst_create_block(struct intel_sst_drv *ctx,
38 u32 msg_id, u32 drv_id)
39{
40 struct sst_block *msg = NULL;
41
42 dev_dbg(ctx->dev, "Enter\n");
43 msg = kzalloc(sizeof(*msg), GFP_KERNEL);
44 if (!msg)
45 return NULL;
46 msg->condition = false;
47 msg->on = true;
48 msg->msg_id = msg_id;
49 msg->drv_id = drv_id;
50 spin_lock_bh(&ctx->block_lock);
51 list_add_tail(&msg->node, &ctx->block_list);
52 spin_unlock_bh(&ctx->block_lock);
53
54 return msg;
55}
56
57/*
58 * while handling the interrupts, we need to check for message status and
59 * then if we are blocking for a message
60 *
61 * here we are unblocking the blocked ones, this is based on id we have
62 * passed and search that for block threads.
63 * We will not find block in two cases
64 * a) when its small message and block in not there, so silently ignore
65 * them
66 * b) when we are actually not able to find the block (bug perhaps)
67 *
68 * Since we have bit of small messages we can spam kernel log with err
69 * print on above so need to keep as debug prints which should be enabled
70 * via dynamic debug while debugging IPC issues
71 */
72int sst_wake_up_block(struct intel_sst_drv *ctx, int result,
73 u32 drv_id, u32 ipc, void *data, u32 size)
74{
75 struct sst_block *block = NULL;
76
77 dev_dbg(ctx->dev, "Enter\n");
78
79 spin_lock_bh(&ctx->block_lock);
80 list_for_each_entry(block, &ctx->block_list, node) {
81 dev_dbg(ctx->dev, "Block ipc %d, drv_id %d\n", block->msg_id,
82 block->drv_id);
83 if (block->msg_id == ipc && block->drv_id == drv_id) {
84 dev_dbg(ctx->dev, "free up the block\n");
85 block->ret_code = result;
86 block->data = data;
87 block->size = size;
88 block->condition = true;
89 spin_unlock_bh(&ctx->block_lock);
90 wake_up(&ctx->wait_queue);
91 return 0;
92 }
93 }
94 spin_unlock_bh(&ctx->block_lock);
95 dev_dbg(ctx->dev,
96 "Block not found or a response received for a short msg for ipc %d, drv_id %d\n",
97 ipc, drv_id);
98 return -EINVAL;
99}
100
101int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed)
102{
103 struct sst_block *block = NULL, *__block;
104
105 dev_dbg(ctx->dev, "Enter\n");
106 spin_lock_bh(&ctx->block_lock);
107 list_for_each_entry_safe(block, __block, &ctx->block_list, node) {
108 if (block == freed) {
109 pr_debug("pvt_id freed --> %d\n", freed->drv_id);
110 /* toggle the index position of pvt_id */
111 list_del(&freed->node);
112 spin_unlock_bh(&ctx->block_lock);
113 kfree(freed->data);
114 freed->data = NULL;
115 kfree(freed);
116 return 0;
117 }
118 }
119 spin_unlock_bh(&ctx->block_lock);
120 dev_err(ctx->dev, "block is already freed!!!\n");
121 return -EINVAL;
122}
123
124int sst_post_message_mrfld(struct intel_sst_drv *sst_drv_ctx,
125 struct ipc_post *ipc_msg, bool sync)
126{
127 struct ipc_post *msg = ipc_msg;
128 union ipc_header_mrfld header;
129 unsigned int loop_count = 0;
130 int retval = 0;
131 unsigned long irq_flags;
132
133 dev_dbg(sst_drv_ctx->dev, "Enter: sync: %d\n", sync);
134 spin_lock_irqsave(&sst_drv_ctx->ipc_spin_lock, irq_flags);
135 header.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCX);
136 if (sync) {
137 while (header.p.header_high.part.busy) {
138 if (loop_count > 25) {
139 dev_err(sst_drv_ctx->dev,
140 "sst: Busy wait failed, cant send this msg\n");
141 retval = -EBUSY;
142 goto out;
143 }
144 cpu_relax();
145 loop_count++;
146 header.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCX);
147 }
148 } else {
149 if (list_empty(&sst_drv_ctx->ipc_dispatch_list)) {
150 /* queue is empty, nothing to send */
151 spin_unlock_irqrestore(&sst_drv_ctx->ipc_spin_lock, irq_flags);
152 dev_dbg(sst_drv_ctx->dev,
153 "Empty msg queue... NO Action\n");
154 return 0;
155 }
156
157 if (header.p.header_high.part.busy) {
158 spin_unlock_irqrestore(&sst_drv_ctx->ipc_spin_lock, irq_flags);
159 dev_dbg(sst_drv_ctx->dev, "Busy not free... post later\n");
160 return 0;
161 }
162
163 /* copy msg from list */
164 msg = list_entry(sst_drv_ctx->ipc_dispatch_list.next,
165 struct ipc_post, node);
166 list_del(&msg->node);
167 }
168 dev_dbg(sst_drv_ctx->dev, "sst: Post message: header = %x\n",
169 msg->mrfld_header.p.header_high.full);
170 dev_dbg(sst_drv_ctx->dev, "sst: size = 0x%x\n",
171 msg->mrfld_header.p.header_low_payload);
172
173 if (msg->mrfld_header.p.header_high.part.large)
174 memcpy_toio(sst_drv_ctx->mailbox + SST_MAILBOX_SEND,
175 msg->mailbox_data,
176 msg->mrfld_header.p.header_low_payload);
177
178 sst_shim_write64(sst_drv_ctx->shim, SST_IPCX, msg->mrfld_header.full);
179
180out:
181 spin_unlock_irqrestore(&sst_drv_ctx->ipc_spin_lock, irq_flags);
182 kfree(msg->mailbox_data);
183 kfree(msg);
184 return retval;
185}
186
187void intel_sst_clear_intr_mrfld(struct intel_sst_drv *sst_drv_ctx)
188{
189 union interrupt_reg_mrfld isr;
190 union interrupt_reg_mrfld imr;
191 union ipc_header_mrfld clear_ipc;
192 unsigned long irq_flags;
193
194 spin_lock_irqsave(&sst_drv_ctx->ipc_spin_lock, irq_flags);
195 imr.full = sst_shim_read64(sst_drv_ctx->shim, SST_IMRX);
196 isr.full = sst_shim_read64(sst_drv_ctx->shim, SST_ISRX);
197
198 /* write 1 to clear*/
199 isr.part.busy_interrupt = 1;
200 sst_shim_write64(sst_drv_ctx->shim, SST_ISRX, isr.full);
201
202 /* Set IA done bit */
203 clear_ipc.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCD);
204
205 clear_ipc.p.header_high.part.busy = 0;
206 clear_ipc.p.header_high.part.done = 1;
207 clear_ipc.p.header_low_payload = IPC_ACK_SUCCESS;
208 sst_shim_write64(sst_drv_ctx->shim, SST_IPCD, clear_ipc.full);
209 /* un mask busy interrupt */
210 imr.part.busy_interrupt = 0;
211 sst_shim_write64(sst_drv_ctx->shim, SST_IMRX, imr.full);
212 spin_unlock_irqrestore(&sst_drv_ctx->ipc_spin_lock, irq_flags);
213}
214
215
216/*
217 * process_fw_init - process the FW init msg
218 *
219 * @msg: IPC message mailbox data from FW
220 *
221 * This function processes the FW init msg from FW
222 * marks FW state and prints debug info of loaded FW
223 */
224static void process_fw_init(struct intel_sst_drv *sst_drv_ctx,
225 void *msg)
226{
227 struct ipc_header_fw_init *init =
228 (struct ipc_header_fw_init *)msg;
229 int retval = 0;
230
231 dev_dbg(sst_drv_ctx->dev, "*** FW Init msg came***\n");
232 if (init->result) {
233 sst_set_fw_state_locked(sst_drv_ctx, SST_RESET);
234 dev_err(sst_drv_ctx->dev, "FW Init failed, Error %x\n",
235 init->result);
236 retval = init->result;
237 goto ret;
238 }
239
240ret:
241 sst_wake_up_block(sst_drv_ctx, retval, FW_DWNL_ID, 0 , NULL, 0);
242}
243
244static void process_fw_async_msg(struct intel_sst_drv *sst_drv_ctx,
245 struct ipc_post *msg)
246{
247 u32 msg_id;
248 int str_id;
249 u32 data_size, i;
250 void *data_offset;
251 struct stream_info *stream;
252 union ipc_header_high msg_high;
253 u32 msg_low, pipe_id;
254
255 msg_high = msg->mrfld_header.p.header_high;
256 msg_low = msg->mrfld_header.p.header_low_payload;
257 msg_id = ((struct ipc_dsp_hdr *)msg->mailbox_data)->cmd_id;
258 data_offset = (msg->mailbox_data + sizeof(struct ipc_dsp_hdr));
259 data_size = msg_low - (sizeof(struct ipc_dsp_hdr));
260
261 switch (msg_id) {
262 case IPC_SST_PERIOD_ELAPSED_MRFLD:
263 pipe_id = ((struct ipc_dsp_hdr *)msg->mailbox_data)->pipe_id;
264 str_id = get_stream_id_mrfld(sst_drv_ctx, pipe_id);
265 if (str_id > 0) {
266 dev_dbg(sst_drv_ctx->dev,
267 "Period elapsed rcvd for pipe id 0x%x\n",
268 pipe_id);
269 stream = &sst_drv_ctx->streams[str_id];
270 if (stream->period_elapsed)
271 stream->period_elapsed(stream->pcm_substream);
272 if (stream->compr_cb)
273 stream->compr_cb(stream->compr_cb_param);
274 }
275 break;
276
277 case IPC_IA_DRAIN_STREAM_MRFLD:
278 pipe_id = ((struct ipc_dsp_hdr *)msg->mailbox_data)->pipe_id;
279 str_id = get_stream_id_mrfld(sst_drv_ctx, pipe_id);
280 if (str_id > 0) {
281 stream = &sst_drv_ctx->streams[str_id];
282 if (stream->drain_notify)
283 stream->drain_notify(stream->drain_cb_param);
284 }
285 break;
286
287 case IPC_IA_FW_ASYNC_ERR_MRFLD:
288 dev_err(sst_drv_ctx->dev, "FW sent async error msg:\n");
289 for (i = 0; i < (data_size/4); i++)
290 print_hex_dump(KERN_DEBUG, NULL, DUMP_PREFIX_NONE,
291 16, 4, data_offset, data_size, false);
292 break;
293
294 case IPC_IA_FW_INIT_CMPLT_MRFLD:
295 process_fw_init(sst_drv_ctx, data_offset);
296 break;
297
298 case IPC_IA_BUF_UNDER_RUN_MRFLD:
299 pipe_id = ((struct ipc_dsp_hdr *)msg->mailbox_data)->pipe_id;
300 str_id = get_stream_id_mrfld(sst_drv_ctx, pipe_id);
301 if (str_id > 0)
302 dev_err(sst_drv_ctx->dev,
303 "Buffer under-run for pipe:%#x str_id:%d\n",
304 pipe_id, str_id);
305 break;
306
307 default:
308 dev_err(sst_drv_ctx->dev,
309 "Unrecognized async msg from FW msg_id %#x\n", msg_id);
310 }
311}
312
313void sst_process_reply_mrfld(struct intel_sst_drv *sst_drv_ctx,
314 struct ipc_post *msg)
315{
316 unsigned int drv_id;
317 void *data;
318 union ipc_header_high msg_high;
319 u32 msg_low;
320 struct ipc_dsp_hdr *dsp_hdr;
321 unsigned int cmd_id;
322
323 msg_high = msg->mrfld_header.p.header_high;
324 msg_low = msg->mrfld_header.p.header_low_payload;
325
326 dev_dbg(sst_drv_ctx->dev, "IPC process message header %x payload %x\n",
327 msg->mrfld_header.p.header_high.full,
328 msg->mrfld_header.p.header_low_payload);
329
330 drv_id = msg_high.part.drv_id;
331
332 /* Check for async messages first */
333 if (drv_id == SST_ASYNC_DRV_ID) {
334 /*FW sent async large message*/
335 process_fw_async_msg(sst_drv_ctx, msg);
336 return;
337 }
338
339 /* FW sent short error response for an IPC */
340 if (msg_high.part.result && drv_id && !msg_high.part.large) {
341 /* 32-bit FW error code in msg_low */
342 dev_err(sst_drv_ctx->dev, "FW sent error response 0x%x", msg_low);
343 sst_wake_up_block(sst_drv_ctx, msg_high.part.result,
344 msg_high.part.drv_id,
345 msg_high.part.msg_id, NULL, 0);
346 return;
347 }
348
349 /*
350 * Process all valid responses
351 * if it is a large message, the payload contains the size to
352 * copy from mailbox
353 **/
354 if (msg_high.part.large) {
355 data = kzalloc(msg_low, GFP_KERNEL);
356 if (!data)
357 return;
358 memcpy(data, (void *) msg->mailbox_data, msg_low);
359 /* Copy command id so that we can use to put sst to reset */
360 dsp_hdr = (struct ipc_dsp_hdr *)data;
361 cmd_id = dsp_hdr->cmd_id;
362 dev_dbg(sst_drv_ctx->dev, "cmd_id %d\n", dsp_hdr->cmd_id);
363 if (sst_wake_up_block(sst_drv_ctx, msg_high.part.result,
364 msg_high.part.drv_id,
365 msg_high.part.msg_id, data, msg_low))
366 kfree(data);
367 } else {
368 sst_wake_up_block(sst_drv_ctx, msg_high.part.result,
369 msg_high.part.drv_id,
370 msg_high.part.msg_id, NULL, 0);
371 }
372
373}
diff --git a/sound/soc/intel/sst/sst_loader.c b/sound/soc/intel/sst/sst_loader.c
new file mode 100644
index 000000000000..b580f96e25e5
--- /dev/null
+++ b/sound/soc/intel/sst/sst_loader.c
@@ -0,0 +1,456 @@
1/*
2 * sst_dsp.c - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corp
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 *
22 * This file contains all dsp controlling functions like firmware download,
23 * setting/resetting dsp cores, etc
24 */
25#include <linux/pci.h>
26#include <linux/delay.h>
27#include <linux/fs.h>
28#include <linux/sched.h>
29#include <linux/firmware.h>
30#include <linux/dmaengine.h>
31#include <linux/pm_runtime.h>
32#include <linux/pm_qos.h>
33#include <sound/core.h>
34#include <sound/pcm.h>
35#include <sound/soc.h>
36#include <sound/compress_driver.h>
37#include <asm/platform_sst_audio.h>
38#include "../sst-mfld-platform.h"
39#include "sst.h"
40#include "../sst-dsp.h"
41
42static inline void memcpy32_toio(void __iomem *dst, const void *src, int count)
43{
44 /* __iowrite32_copy uses 32-bit count values so divide by 4 for
45 * right count in words
46 */
47 __iowrite32_copy(dst, src, count/4);
48}
49
50/**
51 * intel_sst_reset_dsp_mrfld - Resetting SST DSP
52 *
53 * This resets DSP in case of MRFLD platfroms
54 */
55int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *sst_drv_ctx)
56{
57 union config_status_reg_mrfld csr;
58
59 dev_dbg(sst_drv_ctx->dev, "sst: Resetting the DSP in mrfld\n");
60 csr.full = sst_shim_read64(sst_drv_ctx->shim, SST_CSR);
61
62 dev_dbg(sst_drv_ctx->dev, "value:0x%llx\n", csr.full);
63
64 csr.full |= 0x7;
65 sst_shim_write64(sst_drv_ctx->shim, SST_CSR, csr.full);
66 csr.full = sst_shim_read64(sst_drv_ctx->shim, SST_CSR);
67
68 dev_dbg(sst_drv_ctx->dev, "value:0x%llx\n", csr.full);
69
70 csr.full &= ~(0x1);
71 sst_shim_write64(sst_drv_ctx->shim, SST_CSR, csr.full);
72
73 csr.full = sst_shim_read64(sst_drv_ctx->shim, SST_CSR);
74 dev_dbg(sst_drv_ctx->dev, "value:0x%llx\n", csr.full);
75 return 0;
76}
77
78/**
79 * sst_start_merrifield - Start the SST DSP processor
80 *
81 * This starts the DSP in MERRIFIELD platfroms
82 */
83int sst_start_mrfld(struct intel_sst_drv *sst_drv_ctx)
84{
85 union config_status_reg_mrfld csr;
86
87 dev_dbg(sst_drv_ctx->dev, "sst: Starting the DSP in mrfld LALALALA\n");
88 csr.full = sst_shim_read64(sst_drv_ctx->shim, SST_CSR);
89 dev_dbg(sst_drv_ctx->dev, "value:0x%llx\n", csr.full);
90
91 csr.full |= 0x7;
92 sst_shim_write64(sst_drv_ctx->shim, SST_CSR, csr.full);
93
94 csr.full = sst_shim_read64(sst_drv_ctx->shim, SST_CSR);
95 dev_dbg(sst_drv_ctx->dev, "value:0x%llx\n", csr.full);
96
97 csr.part.xt_snoop = 1;
98 csr.full &= ~(0x5);
99 sst_shim_write64(sst_drv_ctx->shim, SST_CSR, csr.full);
100
101 csr.full = sst_shim_read64(sst_drv_ctx->shim, SST_CSR);
102 dev_dbg(sst_drv_ctx->dev, "sst: Starting the DSP_merrifield:%llx\n",
103 csr.full);
104 return 0;
105}
106
107static int sst_validate_fw_image(struct intel_sst_drv *ctx, unsigned long size,
108 struct fw_module_header **module, u32 *num_modules)
109{
110 struct sst_fw_header *header;
111 const void *sst_fw_in_mem = ctx->fw_in_mem;
112
113 dev_dbg(ctx->dev, "Enter\n");
114
115 /* Read the header information from the data pointer */
116 header = (struct sst_fw_header *)sst_fw_in_mem;
117 dev_dbg(ctx->dev,
118 "header sign=%s size=%x modules=%x fmt=%x size=%zx\n",
119 header->signature, header->file_size, header->modules,
120 header->file_format, sizeof(*header));
121
122 /* verify FW */
123 if ((strncmp(header->signature, SST_FW_SIGN, 4) != 0) ||
124 (size != header->file_size + sizeof(*header))) {
125 /* Invalid FW signature */
126 dev_err(ctx->dev, "InvalidFW sign/filesize mismatch\n");
127 return -EINVAL;
128 }
129 *num_modules = header->modules;
130 *module = (void *)sst_fw_in_mem + sizeof(*header);
131
132 return 0;
133}
134
135/*
136 * sst_fill_memcpy_list - Fill the memcpy list
137 *
138 * @memcpy_list: List to be filled
139 * @destn: Destination addr to be filled in the list
140 * @src: Source addr to be filled in the list
141 * @size: Size to be filled in the list
142 *
143 * Adds the node to the list after required fields
144 * are populated in the node
145 */
146static int sst_fill_memcpy_list(struct list_head *memcpy_list,
147 void *destn, const void *src, u32 size, bool is_io)
148{
149 struct sst_memcpy_list *listnode;
150
151 listnode = kzalloc(sizeof(*listnode), GFP_KERNEL);
152 if (listnode == NULL)
153 return -ENOMEM;
154 listnode->dstn = destn;
155 listnode->src = src;
156 listnode->size = size;
157 listnode->is_io = is_io;
158 list_add_tail(&listnode->memcpylist, memcpy_list);
159
160 return 0;
161}
162
163/**
164 * sst_parse_module_memcpy - Parse audio FW modules and populate the memcpy list
165 *
166 * @sst_drv_ctx : driver context
167 * @module : FW module header
168 * @memcpy_list : Pointer to the list to be populated
169 * Create the memcpy list as the number of block to be copied
170 * returns error or 0 if module sizes are proper
171 */
172static int sst_parse_module_memcpy(struct intel_sst_drv *sst_drv_ctx,
173 struct fw_module_header *module, struct list_head *memcpy_list)
174{
175 struct fw_block_info *block;
176 u32 count;
177 int ret_val = 0;
178 void __iomem *ram_iomem;
179
180 dev_dbg(sst_drv_ctx->dev, "module sign %s size %x blocks %x type %x\n",
181 module->signature, module->mod_size,
182 module->blocks, module->type);
183 dev_dbg(sst_drv_ctx->dev, "module entrypoint 0x%x\n", module->entry_point);
184
185 block = (void *)module + sizeof(*module);
186
187 for (count = 0; count < module->blocks; count++) {
188 if (block->size <= 0) {
189 dev_err(sst_drv_ctx->dev, "block size invalid\n");
190 return -EINVAL;
191 }
192 switch (block->type) {
193 case SST_IRAM:
194 ram_iomem = sst_drv_ctx->iram;
195 break;
196 case SST_DRAM:
197 ram_iomem = sst_drv_ctx->dram;
198 break;
199 case SST_DDR:
200 ram_iomem = sst_drv_ctx->ddr;
201 break;
202 case SST_CUSTOM_INFO:
203 block = (void *)block + sizeof(*block) + block->size;
204 continue;
205 default:
206 dev_err(sst_drv_ctx->dev, "wrong ram type0x%x in block0x%x\n",
207 block->type, count);
208 return -EINVAL;
209 }
210
211 ret_val = sst_fill_memcpy_list(memcpy_list,
212 ram_iomem + block->ram_offset,
213 (void *)block + sizeof(*block), block->size, 1);
214 if (ret_val)
215 return ret_val;
216
217 block = (void *)block + sizeof(*block) + block->size;
218 }
219 return 0;
220}
221
222/**
223 * sst_parse_fw_memcpy - parse the firmware image & populate the list for memcpy
224 *
225 * @ctx : pointer to drv context
226 * @size : size of the firmware
227 * @fw_list : pointer to list_head to be populated
228 * This function parses the FW image and saves the parsed image in the list
229 * for memcpy
230 */
231static int sst_parse_fw_memcpy(struct intel_sst_drv *ctx, unsigned long size,
232 struct list_head *fw_list)
233{
234 struct fw_module_header *module;
235 u32 count, num_modules;
236 int ret_val;
237
238 ret_val = sst_validate_fw_image(ctx, size, &module, &num_modules);
239 if (ret_val)
240 return ret_val;
241
242 for (count = 0; count < num_modules; count++) {
243 ret_val = sst_parse_module_memcpy(ctx, module, fw_list);
244 if (ret_val)
245 return ret_val;
246 module = (void *)module + sizeof(*module) + module->mod_size;
247 }
248
249 return 0;
250}
251
252/**
253 * sst_do_memcpy - function initiates the memcpy
254 *
255 * @memcpy_list: Pter to memcpy list on which the memcpy needs to be initiated
256 *
257 * Triggers the memcpy
258 */
259static void sst_do_memcpy(struct list_head *memcpy_list)
260{
261 struct sst_memcpy_list *listnode;
262
263 list_for_each_entry(listnode, memcpy_list, memcpylist) {
264 if (listnode->is_io == true)
265 memcpy32_toio((void __iomem *)listnode->dstn,
266 listnode->src, listnode->size);
267 else
268 memcpy(listnode->dstn, listnode->src, listnode->size);
269 }
270}
271
272void sst_memcpy_free_resources(struct intel_sst_drv *sst_drv_ctx)
273{
274 struct sst_memcpy_list *listnode, *tmplistnode;
275
276 /* Free the list */
277 if (!list_empty(&sst_drv_ctx->memcpy_list)) {
278 list_for_each_entry_safe(listnode, tmplistnode,
279 &sst_drv_ctx->memcpy_list, memcpylist) {
280 list_del(&listnode->memcpylist);
281 kfree(listnode);
282 }
283 }
284}
285
286static int sst_cache_and_parse_fw(struct intel_sst_drv *sst,
287 const struct firmware *fw)
288{
289 int retval = 0;
290
291 sst->fw_in_mem = kzalloc(fw->size, GFP_KERNEL);
292 if (!sst->fw_in_mem) {
293 retval = -ENOMEM;
294 goto end_release;
295 }
296 dev_dbg(sst->dev, "copied fw to %p", sst->fw_in_mem);
297 dev_dbg(sst->dev, "phys: %lx", (unsigned long)virt_to_phys(sst->fw_in_mem));
298 memcpy(sst->fw_in_mem, fw->data, fw->size);
299 retval = sst_parse_fw_memcpy(sst, fw->size, &sst->memcpy_list);
300 if (retval) {
301 dev_err(sst->dev, "Failed to parse fw\n");
302 kfree(sst->fw_in_mem);
303 sst->fw_in_mem = NULL;
304 }
305
306end_release:
307 release_firmware(fw);
308 return retval;
309
310}
311
312void sst_firmware_load_cb(const struct firmware *fw, void *context)
313{
314 struct intel_sst_drv *ctx = context;
315
316 dev_dbg(ctx->dev, "Enter\n");
317
318 if (fw == NULL) {
319 dev_err(ctx->dev, "request fw failed\n");
320 return;
321 }
322
323 mutex_lock(&ctx->sst_lock);
324
325 if (ctx->sst_state != SST_RESET ||
326 ctx->fw_in_mem != NULL) {
327 if (fw != NULL)
328 release_firmware(fw);
329 mutex_unlock(&ctx->sst_lock);
330 return;
331 }
332
333 dev_dbg(ctx->dev, "Request Fw completed\n");
334 sst_cache_and_parse_fw(ctx, fw);
335 mutex_unlock(&ctx->sst_lock);
336}
337
338/*
339 * sst_request_fw - requests audio fw from kernel and saves a copy
340 *
341 * This function requests the SST FW from the kernel, parses it and
342 * saves a copy in the driver context
343 */
344static int sst_request_fw(struct intel_sst_drv *sst)
345{
346 int retval = 0;
347 const struct firmware *fw;
348
349 retval = request_firmware(&fw, sst->firmware_name, sst->dev);
350 if (fw == NULL) {
351 dev_err(sst->dev, "fw is returning as null\n");
352 return -EINVAL;
353 }
354 if (retval) {
355 dev_err(sst->dev, "request fw failed %d\n", retval);
356 return retval;
357 }
358 mutex_lock(&sst->sst_lock);
359 retval = sst_cache_and_parse_fw(sst, fw);
360 mutex_unlock(&sst->sst_lock);
361
362 return retval;
363}
364
365/*
366 * Writing the DDR physical base to DCCM offset
367 * so that FW can use it to setup TLB
368 */
369static void sst_dccm_config_write(void __iomem *dram_base,
370 unsigned int ddr_base)
371{
372 void __iomem *addr;
373 u32 bss_reset = 0;
374
375 addr = (void __iomem *)(dram_base + MRFLD_FW_DDR_BASE_OFFSET);
376 memcpy32_toio(addr, (void *)&ddr_base, sizeof(u32));
377 bss_reset |= (1 << MRFLD_FW_BSS_RESET_BIT);
378 addr = (void __iomem *)(dram_base + MRFLD_FW_FEATURE_BASE_OFFSET);
379 memcpy32_toio(addr, &bss_reset, sizeof(u32));
380
381}
382
383void sst_post_download_mrfld(struct intel_sst_drv *ctx)
384{
385 sst_dccm_config_write(ctx->dram, ctx->ddr_base);
386 dev_dbg(ctx->dev, "config written to DCCM\n");
387}
388
389/**
390 * sst_load_fw - function to load FW into DSP
391 * Transfers the FW to DSP using dma/memcpy
392 */
393int sst_load_fw(struct intel_sst_drv *sst_drv_ctx)
394{
395 int ret_val = 0;
396 struct sst_block *block;
397
398 dev_dbg(sst_drv_ctx->dev, "sst_load_fw\n");
399
400 if (sst_drv_ctx->sst_state != SST_RESET ||
401 sst_drv_ctx->sst_state == SST_SHUTDOWN)
402 return -EAGAIN;
403
404 if (!sst_drv_ctx->fw_in_mem) {
405 dev_dbg(sst_drv_ctx->dev, "sst: FW not in memory retry to download\n");
406 ret_val = sst_request_fw(sst_drv_ctx);
407 if (ret_val)
408 return ret_val;
409 }
410
411 BUG_ON(!sst_drv_ctx->fw_in_mem);
412 block = sst_create_block(sst_drv_ctx, 0, FW_DWNL_ID);
413 if (block == NULL)
414 return -ENOMEM;
415
416 /* Prevent C-states beyond C6 */
417 pm_qos_update_request(sst_drv_ctx->qos, 0);
418
419 sst_drv_ctx->sst_state = SST_FW_LOADING;
420
421 ret_val = sst_drv_ctx->ops->reset(sst_drv_ctx);
422 if (ret_val)
423 goto restore;
424
425 sst_do_memcpy(&sst_drv_ctx->memcpy_list);
426
427 /* Write the DRAM/DCCM config before enabling FW */
428 if (sst_drv_ctx->ops->post_download)
429 sst_drv_ctx->ops->post_download(sst_drv_ctx);
430
431 /* bring sst out of reset */
432 ret_val = sst_drv_ctx->ops->start(sst_drv_ctx);
433 if (ret_val)
434 goto restore;
435
436 ret_val = sst_wait_timeout(sst_drv_ctx, block);
437 if (ret_val) {
438 dev_err(sst_drv_ctx->dev, "fw download failed %d\n" , ret_val);
439 /* FW download failed due to timeout */
440 ret_val = -EBUSY;
441
442 }
443
444
445restore:
446 /* Re-enable Deeper C-states beyond C6 */
447 pm_qos_update_request(sst_drv_ctx->qos, PM_QOS_DEFAULT_VALUE);
448 sst_free_block(sst_drv_ctx, block);
449 dev_dbg(sst_drv_ctx->dev, "fw load successful!!!\n");
450
451 if (sst_drv_ctx->ops->restore_dsp_context)
452 sst_drv_ctx->ops->restore_dsp_context();
453 sst_drv_ctx->sst_state = SST_FW_RUNNING;
454 return ret_val;
455}
456
diff --git a/sound/soc/intel/sst/sst_pci.c b/sound/soc/intel/sst/sst_pci.c
new file mode 100644
index 000000000000..3a0b3bf0af97
--- /dev/null
+++ b/sound/soc/intel/sst/sst_pci.c
@@ -0,0 +1,209 @@
1/*
2 * sst_pci.c - SST (LPE) driver init file for pci enumeration.
3 *
4 * Copyright (C) 2008-14 Intel Corp
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 */
22#include <linux/module.h>
23#include <linux/pci.h>
24#include <linux/fs.h>
25#include <linux/firmware.h>
26#include <linux/pm_runtime.h>
27#include <sound/core.h>
28#include <sound/soc.h>
29#include <asm/platform_sst_audio.h>
30#include "../sst-mfld-platform.h"
31#include "sst.h"
32
33static int sst_platform_get_resources(struct intel_sst_drv *ctx)
34{
35 int ddr_base, ret = 0;
36 struct pci_dev *pci = ctx->pci;
37
38 ret = pci_request_regions(pci, SST_DRV_NAME);
39 if (ret)
40 return ret;
41
42 /* map registers */
43 /* DDR base */
44 if (ctx->dev_id == SST_MRFLD_PCI_ID) {
45 ctx->ddr_base = pci_resource_start(pci, 0);
46 /* check that the relocated IMR base matches with FW Binary */
47 ddr_base = relocate_imr_addr_mrfld(ctx->ddr_base);
48 if (!ctx->pdata->lib_info) {
49 dev_err(ctx->dev, "lib_info pointer NULL\n");
50 ret = -EINVAL;
51 goto do_release_regions;
52 }
53 if (ddr_base != ctx->pdata->lib_info->mod_base) {
54 dev_err(ctx->dev,
55 "FW LSP DDR BASE does not match with IFWI\n");
56 ret = -EINVAL;
57 goto do_release_regions;
58 }
59 ctx->ddr_end = pci_resource_end(pci, 0);
60
61 ctx->ddr = pcim_iomap(pci, 0,
62 pci_resource_len(pci, 0));
63 if (!ctx->ddr) {
64 ret = -EINVAL;
65 goto do_release_regions;
66 }
67 dev_dbg(ctx->dev, "sst: DDR Ptr %p\n", ctx->ddr);
68 } else {
69 ctx->ddr = NULL;
70 }
71 /* SHIM */
72 ctx->shim_phy_add = pci_resource_start(pci, 1);
73 ctx->shim = pcim_iomap(pci, 1, pci_resource_len(pci, 1));
74 if (!ctx->shim) {
75 ret = -EINVAL;
76 goto do_release_regions;
77 }
78 dev_dbg(ctx->dev, "SST Shim Ptr %p\n", ctx->shim);
79
80 /* Shared SRAM */
81 ctx->mailbox_add = pci_resource_start(pci, 2);
82 ctx->mailbox = pcim_iomap(pci, 2, pci_resource_len(pci, 2));
83 if (!ctx->mailbox) {
84 ret = -EINVAL;
85 goto do_release_regions;
86 }
87 dev_dbg(ctx->dev, "SRAM Ptr %p\n", ctx->mailbox);
88
89 /* IRAM */
90 ctx->iram_end = pci_resource_end(pci, 3);
91 ctx->iram_base = pci_resource_start(pci, 3);
92 ctx->iram = pcim_iomap(pci, 3, pci_resource_len(pci, 3));
93 if (!ctx->iram) {
94 ret = -EINVAL;
95 goto do_release_regions;
96 }
97 dev_dbg(ctx->dev, "IRAM Ptr %p\n", ctx->iram);
98
99 /* DRAM */
100 ctx->dram_end = pci_resource_end(pci, 4);
101 ctx->dram_base = pci_resource_start(pci, 4);
102 ctx->dram = pcim_iomap(pci, 4, pci_resource_len(pci, 4));
103 if (!ctx->dram) {
104 ret = -EINVAL;
105 goto do_release_regions;
106 }
107 dev_dbg(ctx->dev, "DRAM Ptr %p\n", ctx->dram);
108do_release_regions:
109 pci_release_regions(pci);
110 return 0;
111}
112
113/*
114 * intel_sst_probe - PCI probe function
115 *
116 * @pci: PCI device structure
117 * @pci_id: PCI device ID structure
118 *
119 */
120static int intel_sst_probe(struct pci_dev *pci,
121 const struct pci_device_id *pci_id)
122{
123 int ret = 0;
124 struct intel_sst_drv *sst_drv_ctx;
125 struct sst_platform_info *sst_pdata = pci->dev.platform_data;
126
127 dev_dbg(&pci->dev, "Probe for DID %x\n", pci->device);
128 ret = sst_alloc_drv_context(&sst_drv_ctx, &pci->dev, pci->device);
129 if (ret < 0)
130 return ret;
131
132 sst_drv_ctx->pdata = sst_pdata;
133 sst_drv_ctx->irq_num = pci->irq;
134 snprintf(sst_drv_ctx->firmware_name, sizeof(sst_drv_ctx->firmware_name),
135 "%s%04x%s", "fw_sst_",
136 sst_drv_ctx->dev_id, ".bin");
137
138 ret = sst_context_init(sst_drv_ctx);
139 if (ret < 0)
140 return ret;
141
142 /* Init the device */
143 ret = pcim_enable_device(pci);
144 if (ret) {
145 dev_err(sst_drv_ctx->dev,
146 "device can't be enabled. Returned err: %d\n", ret);
147 goto do_free_drv_ctx;
148 }
149 sst_drv_ctx->pci = pci_dev_get(pci);
150 ret = sst_platform_get_resources(sst_drv_ctx);
151 if (ret < 0)
152 goto do_free_drv_ctx;
153
154 pci_set_drvdata(pci, sst_drv_ctx);
155 sst_configure_runtime_pm(sst_drv_ctx);
156
157 return ret;
158
159do_free_drv_ctx:
160 sst_context_cleanup(sst_drv_ctx);
161 dev_err(sst_drv_ctx->dev, "Probe failed with %d\n", ret);
162 return ret;
163}
164
165/**
166 * intel_sst_remove - PCI remove function
167 *
168 * @pci: PCI device structure
169 *
170 * This function is called by OS when a device is unloaded
171 * This frees the interrupt etc
172 */
173static void intel_sst_remove(struct pci_dev *pci)
174{
175 struct intel_sst_drv *sst_drv_ctx = pci_get_drvdata(pci);
176
177 sst_context_cleanup(sst_drv_ctx);
178 pci_dev_put(sst_drv_ctx->pci);
179 pci_release_regions(pci);
180 pci_set_drvdata(pci, NULL);
181}
182
183/* PCI Routines */
184static struct pci_device_id intel_sst_ids[] = {
185 { PCI_VDEVICE(INTEL, SST_MRFLD_PCI_ID), 0},
186 { 0, }
187};
188
189static struct pci_driver sst_driver = {
190 .name = SST_DRV_NAME,
191 .id_table = intel_sst_ids,
192 .probe = intel_sst_probe,
193 .remove = intel_sst_remove,
194#ifdef CONFIG_PM
195 .driver = {
196 .pm = &intel_sst_pm,
197 },
198#endif
199};
200
201module_pci_driver(sst_driver);
202
203MODULE_DESCRIPTION("Intel (R) SST(R) Audio Engine PCI Driver");
204MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
205MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
206MODULE_AUTHOR("Dharageswari R <dharageswari.r@intel.com>");
207MODULE_AUTHOR("KP Jeeja <jeeja.kp@intel.com>");
208MODULE_LICENSE("GPL v2");
209MODULE_ALIAS("sst");
diff --git a/sound/soc/intel/sst/sst_pvt.c b/sound/soc/intel/sst/sst_pvt.c
new file mode 100644
index 000000000000..4b7720864492
--- /dev/null
+++ b/sound/soc/intel/sst/sst_pvt.c
@@ -0,0 +1,449 @@
1/*
2 * sst_pvt.c - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corp
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 */
22#include <linux/kobject.h>
23#include <linux/pci.h>
24#include <linux/fs.h>
25#include <linux/firmware.h>
26#include <linux/pm_runtime.h>
27#include <linux/sched.h>
28#include <linux/delay.h>
29#include <sound/asound.h>
30#include <sound/core.h>
31#include <sound/pcm.h>
32#include <sound/soc.h>
33#include <sound/compress_driver.h>
34#include <asm/platform_sst_audio.h>
35#include "../sst-mfld-platform.h"
36#include "sst.h"
37#include "../sst-dsp.h"
38
39int sst_shim_write(void __iomem *addr, int offset, int value)
40{
41 writel(value, addr + offset);
42 return 0;
43}
44
45u32 sst_shim_read(void __iomem *addr, int offset)
46{
47 return readl(addr + offset);
48}
49
50u64 sst_reg_read64(void __iomem *addr, int offset)
51{
52 u64 val = 0;
53
54 memcpy_fromio(&val, addr + offset, sizeof(val));
55
56 return val;
57}
58
59int sst_shim_write64(void __iomem *addr, int offset, u64 value)
60{
61 memcpy_toio(addr + offset, &value, sizeof(value));
62 return 0;
63}
64
65u64 sst_shim_read64(void __iomem *addr, int offset)
66{
67 u64 val = 0;
68
69 memcpy_fromio(&val, addr + offset, sizeof(val));
70 return val;
71}
72
73void sst_set_fw_state_locked(
74 struct intel_sst_drv *sst_drv_ctx, int sst_state)
75{
76 mutex_lock(&sst_drv_ctx->sst_lock);
77 sst_drv_ctx->sst_state = sst_state;
78 mutex_unlock(&sst_drv_ctx->sst_lock);
79}
80
81/*
82 * sst_wait_interruptible - wait on event
83 *
84 * @sst_drv_ctx: Driver context
85 * @block: Driver block to wait on
86 *
87 * This function waits without a timeout (and is interruptable) for a
88 * given block event
89 */
90int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
91 struct sst_block *block)
92{
93 int retval = 0;
94
95 if (!wait_event_interruptible(sst_drv_ctx->wait_queue,
96 block->condition)) {
97 /* event wake */
98 if (block->ret_code < 0) {
99 dev_err(sst_drv_ctx->dev,
100 "stream failed %d\n", block->ret_code);
101 retval = -EBUSY;
102 } else {
103 dev_dbg(sst_drv_ctx->dev, "event up\n");
104 retval = 0;
105 }
106 } else {
107 dev_err(sst_drv_ctx->dev, "signal interrupted\n");
108 retval = -EINTR;
109 }
110 return retval;
111
112}
113
114unsigned long long read_shim_data(struct intel_sst_drv *sst, int addr)
115{
116 unsigned long long val = 0;
117
118 switch (sst->dev_id) {
119 case SST_MRFLD_PCI_ID:
120 case SST_BYT_ACPI_ID:
121 val = sst_shim_read64(sst->shim, addr);
122 break;
123 }
124 return val;
125}
126
127void write_shim_data(struct intel_sst_drv *sst, int addr,
128 unsigned long long data)
129{
130 switch (sst->dev_id) {
131 case SST_MRFLD_PCI_ID:
132 case SST_BYT_ACPI_ID:
133 sst_shim_write64(sst->shim, addr, (u64) data);
134 break;
135 }
136}
137
138/*
139 * sst_wait_timeout - wait on event for timeout
140 *
141 * @sst_drv_ctx: Driver context
142 * @block: Driver block to wait on
143 *
144 * This function waits with a timeout value (and is not interruptible) on a
145 * given block event
146 */
147int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx, struct sst_block *block)
148{
149 int retval = 0;
150
151 /*
152 * NOTE:
153 * Observed that FW processes the alloc msg and replies even
154 * before the alloc thread has finished execution
155 */
156 dev_dbg(sst_drv_ctx->dev,
157 "waiting for condition %x ipc %d drv_id %d\n",
158 block->condition, block->msg_id, block->drv_id);
159 if (wait_event_timeout(sst_drv_ctx->wait_queue,
160 block->condition,
161 msecs_to_jiffies(SST_BLOCK_TIMEOUT))) {
162 /* event wake */
163 dev_dbg(sst_drv_ctx->dev, "Event wake %x\n",
164 block->condition);
165 dev_dbg(sst_drv_ctx->dev, "message ret: %d\n",
166 block->ret_code);
167 retval = -block->ret_code;
168 } else {
169 block->on = false;
170 dev_err(sst_drv_ctx->dev,
171 "Wait timed-out condition:%#x, msg_id:%#x fw_state %#x\n",
172 block->condition, block->msg_id, sst_drv_ctx->sst_state);
173 sst_drv_ctx->sst_state = SST_RESET;
174
175 retval = -EBUSY;
176 }
177 return retval;
178}
179
180/*
181 * sst_create_ipc_msg - create a IPC message
182 *
183 * @arg: ipc message
184 * @large: large or short message
185 *
186 * this function allocates structures to send a large or short
187 * message to the firmware
188 */
189int sst_create_ipc_msg(struct ipc_post **arg, bool large)
190{
191 struct ipc_post *msg;
192
193 msg = kzalloc(sizeof(struct ipc_post), GFP_ATOMIC);
194 if (!msg)
195 return -ENOMEM;
196 if (large) {
197 msg->mailbox_data = kzalloc(SST_MAILBOX_SIZE, GFP_ATOMIC);
198 if (!msg->mailbox_data) {
199 kfree(msg);
200 return -ENOMEM;
201 }
202 } else {
203 msg->mailbox_data = NULL;
204 }
205 msg->is_large = large;
206 *arg = msg;
207 return 0;
208}
209
210/*
211 * sst_create_block_and_ipc_msg - Creates IPC message and sst block
212 * @arg: passed to sst_create_ipc_message API
213 * @large: large or short message
214 * @sst_drv_ctx: sst driver context
215 * @block: return block allocated
216 * @msg_id: IPC
217 * @drv_id: stream id or private id
218 */
219int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large,
220 struct intel_sst_drv *sst_drv_ctx, struct sst_block **block,
221 u32 msg_id, u32 drv_id)
222{
223 int retval = 0;
224
225 retval = sst_create_ipc_msg(arg, large);
226 if (retval)
227 return retval;
228 *block = sst_create_block(sst_drv_ctx, msg_id, drv_id);
229 if (*block == NULL) {
230 kfree(*arg);
231 return -ENOMEM;
232 }
233 return retval;
234}
235
236/*
237 * sst_clean_stream - clean the stream context
238 *
239 * @stream: stream structure
240 *
241 * this function resets the stream contexts
242 * should be called in free
243 */
244void sst_clean_stream(struct stream_info *stream)
245{
246 stream->status = STREAM_UN_INIT;
247 stream->prev = STREAM_UN_INIT;
248 mutex_lock(&stream->lock);
249 stream->cumm_bytes = 0;
250 mutex_unlock(&stream->lock);
251}
252
253int sst_prepare_and_post_msg(struct intel_sst_drv *sst,
254 int task_id, int ipc_msg, int cmd_id, int pipe_id,
255 size_t mbox_data_len, const void *mbox_data, void **data,
256 bool large, bool fill_dsp, bool sync, bool response)
257{
258 struct ipc_post *msg = NULL;
259 struct ipc_dsp_hdr dsp_hdr;
260 struct sst_block *block;
261 int ret = 0, pvt_id;
262
263 pvt_id = sst_assign_pvt_id(sst);
264 if (pvt_id < 0)
265 return pvt_id;
266
267 if (response)
268 ret = sst_create_block_and_ipc_msg(
269 &msg, large, sst, &block, ipc_msg, pvt_id);
270 else
271 ret = sst_create_ipc_msg(&msg, large);
272
273 if (ret < 0) {
274 test_and_clear_bit(pvt_id, &sst->pvt_id);
275 return -ENOMEM;
276 }
277
278 dev_dbg(sst->dev, "pvt_id = %d, pipe id = %d, task = %d ipc_msg: %d\n",
279 pvt_id, pipe_id, task_id, ipc_msg);
280 sst_fill_header_mrfld(&msg->mrfld_header, ipc_msg,
281 task_id, large, pvt_id);
282 msg->mrfld_header.p.header_low_payload = sizeof(dsp_hdr) + mbox_data_len;
283 msg->mrfld_header.p.header_high.part.res_rqd = !sync;
284 dev_dbg(sst->dev, "header:%x\n",
285 msg->mrfld_header.p.header_high.full);
286 dev_dbg(sst->dev, "response rqd: %x",
287 msg->mrfld_header.p.header_high.part.res_rqd);
288 dev_dbg(sst->dev, "msg->mrfld_header.p.header_low_payload:%d",
289 msg->mrfld_header.p.header_low_payload);
290 if (fill_dsp) {
291 sst_fill_header_dsp(&dsp_hdr, cmd_id, pipe_id, mbox_data_len);
292 memcpy(msg->mailbox_data, &dsp_hdr, sizeof(dsp_hdr));
293 if (mbox_data_len) {
294 memcpy(msg->mailbox_data + sizeof(dsp_hdr),
295 mbox_data, mbox_data_len);
296 }
297 }
298
299 if (sync)
300 sst->ops->post_message(sst, msg, true);
301 else
302 sst_add_to_dispatch_list_and_post(sst, msg);
303
304 if (response) {
305 ret = sst_wait_timeout(sst, block);
306 if (ret < 0) {
307 goto out;
308 } else if(block->data) {
309 if (!data)
310 goto out;
311 *data = kzalloc(block->size, GFP_KERNEL);
312 if (!(*data)) {
313 ret = -ENOMEM;
314 goto out;
315 } else
316 memcpy(data, (void *) block->data, block->size);
317 }
318 }
319out:
320 if (response)
321 sst_free_block(sst, block);
322 test_and_clear_bit(pvt_id, &sst->pvt_id);
323 return ret;
324}
325
326int sst_pm_runtime_put(struct intel_sst_drv *sst_drv)
327{
328 int ret;
329
330 pm_runtime_mark_last_busy(sst_drv->dev);
331 ret = pm_runtime_put_autosuspend(sst_drv->dev);
332 if (ret < 0)
333 return ret;
334 return 0;
335}
336
337void sst_fill_header_mrfld(union ipc_header_mrfld *header,
338 int msg, int task_id, int large, int drv_id)
339{
340 header->full = 0;
341 header->p.header_high.part.msg_id = msg;
342 header->p.header_high.part.task_id = task_id;
343 header->p.header_high.part.large = large;
344 header->p.header_high.part.drv_id = drv_id;
345 header->p.header_high.part.done = 0;
346 header->p.header_high.part.busy = 1;
347 header->p.header_high.part.res_rqd = 1;
348}
349
350void sst_fill_header_dsp(struct ipc_dsp_hdr *dsp, int msg,
351 int pipe_id, int len)
352{
353 dsp->cmd_id = msg;
354 dsp->mod_index_id = 0xff;
355 dsp->pipe_id = pipe_id;
356 dsp->length = len;
357 dsp->mod_id = 0;
358}
359
360#define SST_MAX_BLOCKS 15
361/*
362 * sst_assign_pvt_id - assign a pvt id for stream
363 *
364 * @sst_drv_ctx : driver context
365 *
366 * this function assigns a private id for calls that dont have stream
367 * context yet, should be called with lock held
368 * uses bits for the id, and finds first free bits and assigns that
369 */
370int sst_assign_pvt_id(struct intel_sst_drv *drv)
371{
372 int local;
373
374 spin_lock(&drv->block_lock);
375 /* find first zero index from lsb */
376 local = ffz(drv->pvt_id);
377 dev_dbg(drv->dev, "pvt_id assigned --> %d\n", local);
378 if (local >= SST_MAX_BLOCKS){
379 spin_unlock(&drv->block_lock);
380 dev_err(drv->dev, "PVT _ID error: no free id blocks ");
381 return -EINVAL;
382 }
383 /* toggle the index */
384 change_bit(local, &drv->pvt_id);
385 spin_unlock(&drv->block_lock);
386 return local;
387}
388
389void sst_init_stream(struct stream_info *stream,
390 int codec, int sst_id, int ops, u8 slot)
391{
392 stream->status = STREAM_INIT;
393 stream->prev = STREAM_UN_INIT;
394 stream->ops = ops;
395}
396
397int sst_validate_strid(
398 struct intel_sst_drv *sst_drv_ctx, int str_id)
399{
400 if (str_id <= 0 || str_id > sst_drv_ctx->info.max_streams) {
401 dev_err(sst_drv_ctx->dev,
402 "SST ERR: invalid stream id : %d, max %d\n",
403 str_id, sst_drv_ctx->info.max_streams);
404 return -EINVAL;
405 }
406
407 return 0;
408}
409
410struct stream_info *get_stream_info(
411 struct intel_sst_drv *sst_drv_ctx, int str_id)
412{
413 if (sst_validate_strid(sst_drv_ctx, str_id))
414 return NULL;
415 return &sst_drv_ctx->streams[str_id];
416}
417
418int get_stream_id_mrfld(struct intel_sst_drv *sst_drv_ctx,
419 u32 pipe_id)
420{
421 int i;
422
423 for (i = 1; i <= sst_drv_ctx->info.max_streams; i++)
424 if (pipe_id == sst_drv_ctx->streams[i].pipe_id)
425 return i;
426
427 dev_dbg(sst_drv_ctx->dev, "no such pipe_id(%u)", pipe_id);
428 return -1;
429}
430
431u32 relocate_imr_addr_mrfld(u32 base_addr)
432{
433 /* Get the difference from 512MB aligned base addr */
434 /* relocate the base */
435 base_addr = MRFLD_FW_VIRTUAL_BASE + (base_addr % (512 * 1024 * 1024));
436 return base_addr;
437}
438EXPORT_SYMBOL_GPL(relocate_imr_addr_mrfld);
439
440void sst_add_to_dispatch_list_and_post(struct intel_sst_drv *sst,
441 struct ipc_post *msg)
442{
443 unsigned long irq_flags;
444
445 spin_lock_irqsave(&sst->ipc_spin_lock, irq_flags);
446 list_add_tail(&msg->node, &sst->ipc_dispatch_list);
447 spin_unlock_irqrestore(&sst->ipc_spin_lock, irq_flags);
448 sst->ops->post_message(sst, NULL, false);
449}
diff --git a/sound/soc/intel/sst/sst_stream.c b/sound/soc/intel/sst/sst_stream.c
new file mode 100644
index 000000000000..dae2a41997aa
--- /dev/null
+++ b/sound/soc/intel/sst/sst_stream.c
@@ -0,0 +1,437 @@
1/*
2 * sst_stream.c - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corp
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 */
22#include <linux/pci.h>
23#include <linux/firmware.h>
24#include <linux/sched.h>
25#include <linux/delay.h>
26#include <linux/pm_runtime.h>
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/soc.h>
30#include <sound/compress_driver.h>
31#include <asm/platform_sst_audio.h>
32#include "../sst-mfld-platform.h"
33#include "sst.h"
34#include "../sst-dsp.h"
35
36int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params)
37{
38 struct snd_sst_alloc_mrfld alloc_param;
39 struct snd_sst_params *str_params;
40 struct snd_sst_tstamp fw_tstamp;
41 struct stream_info *str_info;
42 struct snd_sst_alloc_response *response;
43 unsigned int str_id, pipe_id, task_id;
44 int i, num_ch, ret = 0;
45 void *data = NULL;
46
47 dev_dbg(sst_drv_ctx->dev, "Enter\n");
48 BUG_ON(!params);
49
50 str_params = (struct snd_sst_params *)params;
51 memset(&alloc_param, 0, sizeof(alloc_param));
52 alloc_param.operation = str_params->ops;
53 alloc_param.codec_type = str_params->codec;
54 alloc_param.sg_count = str_params->aparams.sg_count;
55 alloc_param.ring_buf_info[0].addr =
56 str_params->aparams.ring_buf_info[0].addr;
57 alloc_param.ring_buf_info[0].size =
58 str_params->aparams.ring_buf_info[0].size;
59 alloc_param.frag_size = str_params->aparams.frag_size;
60
61 memcpy(&alloc_param.codec_params, &str_params->sparams,
62 sizeof(struct snd_sst_stream_params));
63
64 /*
65 * fill channel map params for multichannel support.
66 * Ideally channel map should be received from upper layers
67 * for multichannel support.
68 * Currently hardcoding as per FW reqm.
69 */
70 num_ch = sst_get_num_channel(str_params);
71 for (i = 0; i < 8; i++) {
72 if (i < num_ch)
73 alloc_param.codec_params.uc.pcm_params.channel_map[i] = i;
74 else
75 alloc_param.codec_params.uc.pcm_params.channel_map[i] = 0xFF;
76 }
77
78 str_id = str_params->stream_id;
79 str_info = get_stream_info(sst_drv_ctx, str_id);
80 if (str_info == NULL) {
81 dev_err(sst_drv_ctx->dev, "get stream info returned null\n");
82 return -EINVAL;
83 }
84
85 pipe_id = str_params->device_type;
86 task_id = str_params->task;
87 sst_drv_ctx->streams[str_id].pipe_id = pipe_id;
88 sst_drv_ctx->streams[str_id].task_id = task_id;
89 sst_drv_ctx->streams[str_id].num_ch = num_ch;
90
91 if (sst_drv_ctx->info.lpe_viewpt_rqd)
92 alloc_param.ts = sst_drv_ctx->info.mailbox_start +
93 sst_drv_ctx->tstamp + (str_id * sizeof(fw_tstamp));
94 else
95 alloc_param.ts = sst_drv_ctx->mailbox_add +
96 sst_drv_ctx->tstamp + (str_id * sizeof(fw_tstamp));
97
98 dev_dbg(sst_drv_ctx->dev, "alloc tstamp location = 0x%x\n",
99 alloc_param.ts);
100 dev_dbg(sst_drv_ctx->dev, "assigned pipe id 0x%x to task %d\n",
101 pipe_id, task_id);
102
103 /* allocate device type context */
104 sst_init_stream(&sst_drv_ctx->streams[str_id], alloc_param.codec_type,
105 str_id, alloc_param.operation, 0);
106
107 dev_info(sst_drv_ctx->dev, "Alloc for str %d pipe %#x\n",
108 str_id, pipe_id);
109 ret = sst_prepare_and_post_msg(sst_drv_ctx, task_id, IPC_CMD,
110 IPC_IA_ALLOC_STREAM_MRFLD, pipe_id, sizeof(alloc_param),
111 &alloc_param, data, true, true, false, true);
112
113 if (ret < 0) {
114 dev_err(sst_drv_ctx->dev, "FW alloc failed ret %d\n", ret);
115 /* alloc failed, so reset the state to uninit */
116 str_info->status = STREAM_UN_INIT;
117 str_id = ret;
118 } else if (data) {
119 response = (struct snd_sst_alloc_response *)data;
120 ret = response->str_type.result;
121 if (!ret)
122 goto out;
123 dev_err(sst_drv_ctx->dev, "FW alloc failed ret %d\n", ret);
124 if (ret == SST_ERR_STREAM_IN_USE) {
125 dev_err(sst_drv_ctx->dev,
126 "FW not in clean state, send free for:%d\n", str_id);
127 sst_free_stream(sst_drv_ctx, str_id);
128 }
129 str_id = -ret;
130 }
131out:
132 kfree(data);
133 return str_id;
134}
135
136/**
137* sst_start_stream - Send msg for a starting stream
138* @str_id: stream ID
139*
140* This function is called by any function which wants to start
141* a stream.
142*/
143int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id)
144{
145 int retval = 0;
146 struct stream_info *str_info;
147 u16 data = 0;
148
149 dev_dbg(sst_drv_ctx->dev, "sst_start_stream for %d\n", str_id);
150 str_info = get_stream_info(sst_drv_ctx, str_id);
151 if (!str_info)
152 return -EINVAL;
153 if (str_info->status != STREAM_RUNNING)
154 return -EBADRQC;
155
156 retval = sst_prepare_and_post_msg(sst_drv_ctx, str_info->task_id,
157 IPC_CMD, IPC_IA_START_STREAM_MRFLD, str_info->pipe_id,
158 sizeof(u16), &data, NULL, true, true, true, false);
159
160 return retval;
161}
162
163int sst_send_byte_stream_mrfld(struct intel_sst_drv *sst_drv_ctx,
164 struct snd_sst_bytes_v2 *bytes)
165{ struct ipc_post *msg = NULL;
166 u32 length;
167 int pvt_id, ret = 0;
168 struct sst_block *block = NULL;
169
170 dev_dbg(sst_drv_ctx->dev,
171 "type:%u ipc_msg:%u block:%u task_id:%u pipe: %#x length:%#x\n",
172 bytes->type, bytes->ipc_msg, bytes->block, bytes->task_id,
173 bytes->pipe_id, bytes->len);
174
175 if (sst_create_ipc_msg(&msg, true))
176 return -ENOMEM;
177
178 pvt_id = sst_assign_pvt_id(sst_drv_ctx);
179 sst_fill_header_mrfld(&msg->mrfld_header, bytes->ipc_msg,
180 bytes->task_id, 1, pvt_id);
181 msg->mrfld_header.p.header_high.part.res_rqd = bytes->block;
182 length = bytes->len;
183 msg->mrfld_header.p.header_low_payload = length;
184 dev_dbg(sst_drv_ctx->dev, "length is %d\n", length);
185 memcpy(msg->mailbox_data, &bytes->bytes, bytes->len);
186 if (bytes->block) {
187 block = sst_create_block(sst_drv_ctx, bytes->ipc_msg, pvt_id);
188 if (block == NULL) {
189 kfree(msg);
190 ret = -ENOMEM;
191 goto out;
192 }
193 }
194
195 sst_add_to_dispatch_list_and_post(sst_drv_ctx, msg);
196 dev_dbg(sst_drv_ctx->dev, "msg->mrfld_header.p.header_low_payload:%d",
197 msg->mrfld_header.p.header_low_payload);
198
199 if (bytes->block) {
200 ret = sst_wait_timeout(sst_drv_ctx, block);
201 if (ret) {
202 dev_err(sst_drv_ctx->dev, "fw returned err %d\n", ret);
203 sst_free_block(sst_drv_ctx, block);
204 goto out;
205 }
206 }
207 if (bytes->type == SND_SST_BYTES_GET) {
208 /*
209 * copy the reply and send back
210 * we need to update only sz and payload
211 */
212 if (bytes->block) {
213 unsigned char *r = block->data;
214
215 dev_dbg(sst_drv_ctx->dev, "read back %d bytes",
216 bytes->len);
217 memcpy(bytes->bytes, r, bytes->len);
218 }
219 }
220 if (bytes->block)
221 sst_free_block(sst_drv_ctx, block);
222out:
223 test_and_clear_bit(pvt_id, &sst_drv_ctx->pvt_id);
224 return 0;
225}
226
227/*
228 * sst_pause_stream - Send msg for a pausing stream
229 * @str_id: stream ID
230 *
231 * This function is called by any function which wants to pause
232 * an already running stream.
233 */
234int sst_pause_stream(struct intel_sst_drv *sst_drv_ctx, int str_id)
235{
236 int retval = 0;
237 struct stream_info *str_info;
238
239 dev_dbg(sst_drv_ctx->dev, "SST DBG:sst_pause_stream for %d\n", str_id);
240 str_info = get_stream_info(sst_drv_ctx, str_id);
241 if (!str_info)
242 return -EINVAL;
243 if (str_info->status == STREAM_PAUSED)
244 return 0;
245 if (str_info->status == STREAM_RUNNING ||
246 str_info->status == STREAM_INIT) {
247 if (str_info->prev == STREAM_UN_INIT)
248 return -EBADRQC;
249
250 retval = sst_prepare_and_post_msg(sst_drv_ctx, str_info->task_id, IPC_CMD,
251 IPC_IA_PAUSE_STREAM_MRFLD, str_info->pipe_id,
252 0, NULL, NULL, true, true, false, true);
253
254 if (retval == 0) {
255 str_info->prev = str_info->status;
256 str_info->status = STREAM_PAUSED;
257 } else if (retval == SST_ERR_INVALID_STREAM_ID) {
258 retval = -EINVAL;
259 mutex_lock(&sst_drv_ctx->sst_lock);
260 sst_clean_stream(str_info);
261 mutex_unlock(&sst_drv_ctx->sst_lock);
262 }
263 } else {
264 retval = -EBADRQC;
265 dev_dbg(sst_drv_ctx->dev, "SST DBG:BADRQC for stream\n ");
266 }
267
268 return retval;
269}
270
271/**
272 * sst_resume_stream - Send msg for resuming stream
273 * @str_id: stream ID
274 *
275 * This function is called by any function which wants to resume
276 * an already paused stream.
277 */
278int sst_resume_stream(struct intel_sst_drv *sst_drv_ctx, int str_id)
279{
280 int retval = 0;
281 struct stream_info *str_info;
282
283 dev_dbg(sst_drv_ctx->dev, "SST DBG:sst_resume_stream for %d\n", str_id);
284 str_info = get_stream_info(sst_drv_ctx, str_id);
285 if (!str_info)
286 return -EINVAL;
287 if (str_info->status == STREAM_RUNNING)
288 return 0;
289 if (str_info->status == STREAM_PAUSED) {
290 retval = sst_prepare_and_post_msg(sst_drv_ctx, str_info->task_id,
291 IPC_CMD, IPC_IA_RESUME_STREAM_MRFLD,
292 str_info->pipe_id, 0, NULL, NULL,
293 true, true, false, true);
294
295 if (!retval) {
296 if (str_info->prev == STREAM_RUNNING)
297 str_info->status = STREAM_RUNNING;
298 else
299 str_info->status = STREAM_INIT;
300 str_info->prev = STREAM_PAUSED;
301 } else if (retval == -SST_ERR_INVALID_STREAM_ID) {
302 retval = -EINVAL;
303 mutex_lock(&sst_drv_ctx->sst_lock);
304 sst_clean_stream(str_info);
305 mutex_unlock(&sst_drv_ctx->sst_lock);
306 }
307 } else {
308 retval = -EBADRQC;
309 dev_err(sst_drv_ctx->dev, "SST ERR: BADQRC for stream\n");
310 }
311
312 return retval;
313}
314
315
316/**
317 * sst_drop_stream - Send msg for stopping stream
318 * @str_id: stream ID
319 *
320 * This function is called by any function which wants to stop
321 * a stream.
322 */
323int sst_drop_stream(struct intel_sst_drv *sst_drv_ctx, int str_id)
324{
325 int retval = 0;
326 struct stream_info *str_info;
327
328 dev_dbg(sst_drv_ctx->dev, "SST DBG:sst_drop_stream for %d\n", str_id);
329 str_info = get_stream_info(sst_drv_ctx, str_id);
330 if (!str_info)
331 return -EINVAL;
332
333 if (str_info->status != STREAM_UN_INIT) {
334 str_info->prev = STREAM_UN_INIT;
335 str_info->status = STREAM_INIT;
336 str_info->cumm_bytes = 0;
337 retval = sst_prepare_and_post_msg(sst_drv_ctx, str_info->task_id,
338 IPC_CMD, IPC_IA_DROP_STREAM_MRFLD,
339 str_info->pipe_id, 0, NULL, NULL,
340 true, true, true, false);
341 } else {
342 retval = -EBADRQC;
343 dev_dbg(sst_drv_ctx->dev, "BADQRC for stream, state %x\n",
344 str_info->status);
345 }
346 return retval;
347}
348
349/**
350* sst_drain_stream - Send msg for draining stream
351* @str_id: stream ID
352*
353* This function is called by any function which wants to drain
354* a stream.
355*/
356int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx,
357 int str_id, bool partial_drain)
358{
359 int retval = 0;
360 struct stream_info *str_info;
361
362 dev_dbg(sst_drv_ctx->dev, "SST DBG:sst_drain_stream for %d\n", str_id);
363 str_info = get_stream_info(sst_drv_ctx, str_id);
364 if (!str_info)
365 return -EINVAL;
366 if (str_info->status != STREAM_RUNNING &&
367 str_info->status != STREAM_INIT &&
368 str_info->status != STREAM_PAUSED) {
369 dev_err(sst_drv_ctx->dev, "SST ERR: BADQRC for stream = %d\n",
370 str_info->status);
371 return -EBADRQC;
372 }
373
374 retval = sst_prepare_and_post_msg(sst_drv_ctx, str_info->task_id, IPC_CMD,
375 IPC_IA_DRAIN_STREAM_MRFLD, str_info->pipe_id,
376 sizeof(u8), &partial_drain, NULL, true, true, false, false);
377 /*
378 * with new non blocked drain implementation in core we dont need to
379 * wait for respsonse, and need to only invoke callback for drain
380 * complete
381 */
382
383 return retval;
384}
385
386/**
387 * sst_free_stream - Frees a stream
388 * @str_id: stream ID
389 *
390 * This function is called by any function which wants to free
391 * a stream.
392 */
393int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int str_id)
394{
395 int retval = 0;
396 struct stream_info *str_info;
397 struct intel_sst_ops *ops;
398
399 dev_dbg(sst_drv_ctx->dev, "SST DBG:sst_free_stream for %d\n", str_id);
400
401 mutex_lock(&sst_drv_ctx->sst_lock);
402 if (sst_drv_ctx->sst_state == SST_RESET) {
403 mutex_unlock(&sst_drv_ctx->sst_lock);
404 return -ENODEV;
405 }
406 mutex_unlock(&sst_drv_ctx->sst_lock);
407 str_info = get_stream_info(sst_drv_ctx, str_id);
408 if (!str_info)
409 return -EINVAL;
410 ops = sst_drv_ctx->ops;
411
412 mutex_lock(&str_info->lock);
413 if (str_info->status != STREAM_UN_INIT) {
414 str_info->prev = str_info->status;
415 str_info->status = STREAM_UN_INIT;
416 mutex_unlock(&str_info->lock);
417
418 dev_info(sst_drv_ctx->dev, "Free for str %d pipe %#x\n",
419 str_id, str_info->pipe_id);
420 retval = sst_prepare_and_post_msg(sst_drv_ctx, str_info->task_id, IPC_CMD,
421 IPC_IA_FREE_STREAM_MRFLD, str_info->pipe_id, 0,
422 NULL, NULL, true, true, false, true);
423
424 dev_dbg(sst_drv_ctx->dev, "sst: wait for free returned %d\n",
425 retval);
426 mutex_lock(&sst_drv_ctx->sst_lock);
427 sst_clean_stream(str_info);
428 mutex_unlock(&sst_drv_ctx->sst_lock);
429 dev_dbg(sst_drv_ctx->dev, "SST DBG:Stream freed\n");
430 } else {
431 mutex_unlock(&str_info->lock);
432 retval = -EBADRQC;
433 dev_dbg(sst_drv_ctx->dev, "SST DBG:BADQRC for stream\n");
434 }
435
436 return retval;
437}
diff --git a/sound/soc/jz4740/qi_lb60.c b/sound/soc/jz4740/qi_lb60.c
index 5cb91f9e8626..0fb7d2a91c3a 100644
--- a/sound/soc/jz4740/qi_lb60.c
+++ b/sound/soc/jz4740/qi_lb60.c
@@ -77,25 +77,18 @@ static int qi_lb60_probe(struct platform_device *pdev)
77{ 77{
78 struct qi_lb60 *qi_lb60; 78 struct qi_lb60 *qi_lb60;
79 struct snd_soc_card *card = &qi_lb60_card; 79 struct snd_soc_card *card = &qi_lb60_card;
80 int ret;
81 80
82 qi_lb60 = devm_kzalloc(&pdev->dev, sizeof(*qi_lb60), GFP_KERNEL); 81 qi_lb60 = devm_kzalloc(&pdev->dev, sizeof(*qi_lb60), GFP_KERNEL);
83 if (!qi_lb60) 82 if (!qi_lb60)
84 return -ENOMEM; 83 return -ENOMEM;
85 84
86 qi_lb60->snd_gpio = devm_gpiod_get(&pdev->dev, "snd"); 85 qi_lb60->snd_gpio = devm_gpiod_get(&pdev->dev, "snd", GPIOD_OUT_LOW);
87 if (IS_ERR(qi_lb60->snd_gpio)) 86 if (IS_ERR(qi_lb60->snd_gpio))
88 return PTR_ERR(qi_lb60->snd_gpio); 87 return PTR_ERR(qi_lb60->snd_gpio);
89 ret = gpiod_direction_output(qi_lb60->snd_gpio, 0);
90 if (ret)
91 return ret;
92 88
93 qi_lb60->amp_gpio = devm_gpiod_get(&pdev->dev, "amp"); 89 qi_lb60->amp_gpio = devm_gpiod_get(&pdev->dev, "amp", GPIOD_OUT_LOW);
94 if (IS_ERR(qi_lb60->amp_gpio)) 90 if (IS_ERR(qi_lb60->amp_gpio))
95 return PTR_ERR(qi_lb60->amp_gpio); 91 return PTR_ERR(qi_lb60->amp_gpio);
96 ret = gpiod_direction_output(qi_lb60->amp_gpio, 0);
97 if (ret)
98 return ret;
99 92
100 card->dev = &pdev->dev; 93 card->dev = &pdev->dev;
101 94
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index 231d7e7b0711..83b2fea09219 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -773,7 +773,7 @@ static int mxs_saif_probe(struct platform_device *pdev)
773 773
774 saif->dev = &pdev->dev; 774 saif->dev = &pdev->dev;
775 ret = devm_request_irq(&pdev->dev, saif->irq, mxs_saif_irq, 0, 775 ret = devm_request_irq(&pdev->dev, saif->irq, mxs_saif_irq, 0,
776 "mxs-saif", saif); 776 dev_name(&pdev->dev), saif);
777 if (ret) { 777 if (ret) {
778 dev_err(&pdev->dev, "failed to request irq\n"); 778 dev_err(&pdev->dev, "failed to request irq\n");
779 return ret; 779 return ret;
diff --git a/sound/soc/mxs/mxs-sgtl5000.c b/sound/soc/mxs/mxs-sgtl5000.c
index 61822cc53bd3..3bba6cfe4f29 100644
--- a/sound/soc/mxs/mxs-sgtl5000.c
+++ b/sound/soc/mxs/mxs-sgtl5000.c
@@ -49,13 +49,6 @@ static int mxs_sgtl5000_hw_params(struct snd_pcm_substream *substream,
49 break; 49 break;
50 } 50 }
51 51
52 /* Sgtl5000 sysclk should be >= 8MHz and <= 27M */
53 if (mclk < 8000000 || mclk > 27000000) {
54 dev_err(codec_dai->dev, "Invalid mclk frequency: %u.%03uMHz\n",
55 mclk / 1000000, mclk / 1000 % 1000);
56 return -EINVAL;
57 }
58
59 /* Set SGTL5000's SYSCLK (provided by SAIF MCLK) */ 52 /* Set SGTL5000's SYSCLK (provided by SAIF MCLK) */
60 ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, mclk, 0); 53 ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, mclk, 0);
61 if (ret) { 54 if (ret) {
diff --git a/sound/soc/nuc900/nuc900-ac97.c b/sound/soc/nuc900/nuc900-ac97.c
index f2f67942b229..dff443e4b657 100644
--- a/sound/soc/nuc900/nuc900-ac97.c
+++ b/sound/soc/nuc900/nuc900-ac97.c
@@ -298,7 +298,7 @@ static const struct snd_soc_dai_ops nuc900_ac97_dai_ops = {
298static struct snd_soc_dai_driver nuc900_ac97_dai = { 298static struct snd_soc_dai_driver nuc900_ac97_dai = {
299 .probe = nuc900_ac97_probe, 299 .probe = nuc900_ac97_probe,
300 .remove = nuc900_ac97_remove, 300 .remove = nuc900_ac97_remove,
301 .ac97_control = 1, 301 .bus_control = true,
302 .playback = { 302 .playback = {
303 .rates = SNDRV_PCM_RATE_8000_48000, 303 .rates = SNDRV_PCM_RATE_8000_48000,
304 .formats = SNDRV_PCM_FMTBIT_S16_LE, 304 .formats = SNDRV_PCM_FMTBIT_S16_LE,
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index 3dfcadf00e55..a2cd3486ac55 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -37,15 +37,15 @@ config SND_OMAP_SOC_N810
37 Say Y if you want to add support for SoC audio on Nokia N810. 37 Say Y if you want to add support for SoC audio on Nokia N810.
38 38
39config SND_OMAP_SOC_RX51 39config SND_OMAP_SOC_RX51
40 tristate "SoC Audio support for Nokia RX-51" 40 tristate "SoC Audio support for Nokia N900 (RX-51)"
41 depends on SND_OMAP_SOC && ARM && (MACH_NOKIA_RX51 || COMPILE_TEST) && I2C 41 depends on SND_OMAP_SOC && ARM && I2C
42 select SND_OMAP_SOC_MCBSP 42 select SND_OMAP_SOC_MCBSP
43 select SND_SOC_TLV320AIC3X 43 select SND_SOC_TLV320AIC3X
44 select SND_SOC_TPA6130A2 44 select SND_SOC_TPA6130A2
45 depends on GPIOLIB 45 depends on GPIOLIB
46 help 46 help
47 Say Y if you want to add support for SoC audio on Nokia RX-51 47 Say Y if you want to add support for SoC audio on Nokia N900
48 hardware. This is also known as Nokia N900 product. 48 cellphone.
49 49
50config SND_OMAP_SOC_AMS_DELTA 50config SND_OMAP_SOC_AMS_DELTA
51 tristate "SoC Audio support for Amstrad E3 (Delta) videophone" 51 tristate "SoC Audio support for Amstrad E3 (Delta) videophone"
diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
index 86c75384c3c8..68a125205375 100644
--- a/sound/soc/omap/mcbsp.c
+++ b/sound/soc/omap/mcbsp.c
@@ -621,8 +621,7 @@ void omap_mcbsp_free(struct omap_mcbsp *mcbsp)
621 mcbsp->reg_cache = NULL; 621 mcbsp->reg_cache = NULL;
622 spin_unlock(&mcbsp->lock); 622 spin_unlock(&mcbsp->lock);
623 623
624 if (reg_cache) 624 kfree(reg_cache);
625 kfree(reg_cache);
626} 625}
627 626
628/* 627/*
diff --git a/sound/soc/pxa/mioa701_wm9713.c b/sound/soc/pxa/mioa701_wm9713.c
index 595eee341e90..a6b2be20cc0b 100644
--- a/sound/soc/pxa/mioa701_wm9713.c
+++ b/sound/soc/pxa/mioa701_wm9713.c
@@ -127,15 +127,12 @@ static const struct snd_soc_dapm_route audio_map[] = {
127static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd) 127static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
128{ 128{
129 struct snd_soc_codec *codec = rtd->codec; 129 struct snd_soc_codec *codec = rtd->codec;
130 unsigned short reg;
131 130
132 /* Prepare GPIO8 for rear speaker amplifier */ 131 /* Prepare GPIO8 for rear speaker amplifier */
133 reg = codec->driver->read(codec, AC97_GPIO_CFG); 132 snd_soc_update_bits(codec, AC97_GPIO_CFG, 0x100, 0x100);
134 codec->driver->write(codec, AC97_GPIO_CFG, reg | 0x0100);
135 133
136 /* Prepare MIC input */ 134 /* Prepare MIC input */
137 reg = codec->driver->read(codec, AC97_3D_CONTROL); 135 snd_soc_update_bits(codec, AC97_3D_CONTROL, 0xc000, 0xc000);
138 codec->driver->write(codec, AC97_3D_CONTROL, reg | 0xc000);
139 136
140 return 0; 137 return 0;
141} 138}
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c
index a8e097433074..cbba063a7210 100644
--- a/sound/soc/pxa/pxa-ssp.c
+++ b/sound/soc/pxa/pxa-ssp.c
@@ -97,7 +97,7 @@ static int pxa_ssp_startup(struct snd_pcm_substream *substream,
97 int ret = 0; 97 int ret = 0;
98 98
99 if (!cpu_dai->active) { 99 if (!cpu_dai->active) {
100 clk_enable(ssp->clk); 100 clk_prepare_enable(ssp->clk);
101 pxa_ssp_disable(ssp); 101 pxa_ssp_disable(ssp);
102 } 102 }
103 103
@@ -121,7 +121,7 @@ static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
121 121
122 if (!cpu_dai->active) { 122 if (!cpu_dai->active) {
123 pxa_ssp_disable(ssp); 123 pxa_ssp_disable(ssp);
124 clk_disable(ssp->clk); 124 clk_disable_unprepare(ssp->clk);
125 } 125 }
126 126
127 kfree(snd_soc_dai_get_dma_data(cpu_dai, substream)); 127 kfree(snd_soc_dai_get_dma_data(cpu_dai, substream));
@@ -136,7 +136,7 @@ static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai)
136 struct ssp_device *ssp = priv->ssp; 136 struct ssp_device *ssp = priv->ssp;
137 137
138 if (!cpu_dai->active) 138 if (!cpu_dai->active)
139 clk_enable(ssp->clk); 139 clk_prepare_enable(ssp->clk);
140 140
141 priv->cr0 = __raw_readl(ssp->mmio_base + SSCR0); 141 priv->cr0 = __raw_readl(ssp->mmio_base + SSCR0);
142 priv->cr1 = __raw_readl(ssp->mmio_base + SSCR1); 142 priv->cr1 = __raw_readl(ssp->mmio_base + SSCR1);
@@ -144,7 +144,7 @@ static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai)
144 priv->psp = __raw_readl(ssp->mmio_base + SSPSP); 144 priv->psp = __raw_readl(ssp->mmio_base + SSPSP);
145 145
146 pxa_ssp_disable(ssp); 146 pxa_ssp_disable(ssp);
147 clk_disable(ssp->clk); 147 clk_disable_unprepare(ssp->clk);
148 return 0; 148 return 0;
149} 149}
150 150
@@ -154,7 +154,7 @@ static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
154 struct ssp_device *ssp = priv->ssp; 154 struct ssp_device *ssp = priv->ssp;
155 uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE; 155 uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE;
156 156
157 clk_enable(ssp->clk); 157 clk_prepare_enable(ssp->clk);
158 158
159 __raw_writel(sssr, ssp->mmio_base + SSSR); 159 __raw_writel(sssr, ssp->mmio_base + SSSR);
160 __raw_writel(priv->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0); 160 __raw_writel(priv->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0);
@@ -165,7 +165,7 @@ static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
165 if (cpu_dai->active) 165 if (cpu_dai->active)
166 pxa_ssp_enable(ssp); 166 pxa_ssp_enable(ssp);
167 else 167 else
168 clk_disable(ssp->clk); 168 clk_disable_unprepare(ssp->clk);
169 169
170 return 0; 170 return 0;
171} 171}
@@ -256,11 +256,11 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
256 /* The SSP clock must be disabled when changing SSP clock mode 256 /* The SSP clock must be disabled when changing SSP clock mode
257 * on PXA2xx. On PXA3xx it must be enabled when doing so. */ 257 * on PXA2xx. On PXA3xx it must be enabled when doing so. */
258 if (ssp->type != PXA3xx_SSP) 258 if (ssp->type != PXA3xx_SSP)
259 clk_disable(ssp->clk); 259 clk_disable_unprepare(ssp->clk);
260 val = pxa_ssp_read_reg(ssp, SSCR0) | sscr0; 260 val = pxa_ssp_read_reg(ssp, SSCR0) | sscr0;
261 pxa_ssp_write_reg(ssp, SSCR0, val); 261 pxa_ssp_write_reg(ssp, SSCR0, val);
262 if (ssp->type != PXA3xx_SSP) 262 if (ssp->type != PXA3xx_SSP)
263 clk_enable(ssp->clk); 263 clk_prepare_enable(ssp->clk);
264 264
265 return 0; 265 return 0;
266} 266}
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index ae956e3f4b9d..73ca2820c08c 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -157,7 +157,7 @@ static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
157static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = { 157static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
158{ 158{
159 .name = "pxa2xx-ac97", 159 .name = "pxa2xx-ac97",
160 .ac97_control = 1, 160 .bus_control = true,
161 .playback = { 161 .playback = {
162 .stream_name = "AC97 Playback", 162 .stream_name = "AC97 Playback",
163 .channels_min = 2, 163 .channels_min = 2,
@@ -174,7 +174,7 @@ static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
174}, 174},
175{ 175{
176 .name = "pxa2xx-ac97-aux", 176 .name = "pxa2xx-ac97-aux",
177 .ac97_control = 1, 177 .bus_control = true,
178 .playback = { 178 .playback = {
179 .stream_name = "AC97 Aux Playback", 179 .stream_name = "AC97 Aux Playback",
180 .channels_min = 1, 180 .channels_min = 1,
@@ -191,7 +191,7 @@ static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
191}, 191},
192{ 192{
193 .name = "pxa2xx-ac97-mic", 193 .name = "pxa2xx-ac97-mic",
194 .ac97_control = 1, 194 .bus_control = true,
195 .capture = { 195 .capture = {
196 .stream_name = "AC97 Mic Capture", 196 .stream_name = "AC97 Mic Capture",
197 .channels_min = 1, 197 .channels_min = 1,
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index 1373b017a951..d7d5fb20ea6f 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -305,19 +305,15 @@ static struct snd_soc_card snd_soc_spitz = {
305 .num_dapm_routes = ARRAY_SIZE(spitz_audio_map), 305 .num_dapm_routes = ARRAY_SIZE(spitz_audio_map),
306}; 306};
307 307
308static struct platform_device *spitz_snd_device; 308static int spitz_probe(struct platform_device *pdev)
309
310static int __init spitz_init(void)
311{ 309{
310 struct snd_soc_card *card = &snd_soc_spitz;
312 int ret; 311 int ret;
313 312
314 if (!(machine_is_spitz() || machine_is_borzoi() || machine_is_akita())) 313 if (machine_is_akita())
315 return -ENODEV;
316
317 if (machine_is_borzoi() || machine_is_spitz())
318 spitz_mic_gpio = SPITZ_GPIO_MIC_BIAS;
319 else
320 spitz_mic_gpio = AKITA_GPIO_MIC_BIAS; 314 spitz_mic_gpio = AKITA_GPIO_MIC_BIAS;
315 else
316 spitz_mic_gpio = SPITZ_GPIO_MIC_BIAS;
321 317
322 ret = gpio_request(spitz_mic_gpio, "MIC GPIO"); 318 ret = gpio_request(spitz_mic_gpio, "MIC GPIO");
323 if (ret) 319 if (ret)
@@ -327,37 +323,45 @@ static int __init spitz_init(void)
327 if (ret) 323 if (ret)
328 goto err2; 324 goto err2;
329 325
330 spitz_snd_device = platform_device_alloc("soc-audio", -1); 326 card->dev = &pdev->dev;
331 if (!spitz_snd_device) { 327
332 ret = -ENOMEM; 328 ret = snd_soc_register_card(card);
329 if (ret) {
330 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
331 ret);
333 goto err2; 332 goto err2;
334 } 333 }
335 334
336 platform_set_drvdata(spitz_snd_device, &snd_soc_spitz);
337
338 ret = platform_device_add(spitz_snd_device);
339 if (ret)
340 goto err3;
341
342 return 0; 335 return 0;
343 336
344err3:
345 platform_device_put(spitz_snd_device);
346err2: 337err2:
347 gpio_free(spitz_mic_gpio); 338 gpio_free(spitz_mic_gpio);
348err1: 339err1:
349 return ret; 340 return ret;
350} 341}
351 342
352static void __exit spitz_exit(void) 343static int spitz_remove(struct platform_device *pdev)
353{ 344{
354 platform_device_unregister(spitz_snd_device); 345 struct snd_soc_card *card = platform_get_drvdata(pdev);
346
347 snd_soc_unregister_card(card);
355 gpio_free(spitz_mic_gpio); 348 gpio_free(spitz_mic_gpio);
349 return 0;
356} 350}
357 351
358module_init(spitz_init); 352static struct platform_driver spitz_driver = {
359module_exit(spitz_exit); 353 .driver = {
354 .name = "spitz-audio",
355 .owner = THIS_MODULE,
356 .pm = &snd_soc_pm_ops,
357 },
358 .probe = spitz_probe,
359 .remove = spitz_remove,
360};
361
362module_platform_driver(spitz_driver);
360 363
361MODULE_AUTHOR("Richard Purdie"); 364MODULE_AUTHOR("Richard Purdie");
362MODULE_DESCRIPTION("ALSA SoC Spitz"); 365MODULE_DESCRIPTION("ALSA SoC Spitz");
363MODULE_LICENSE("GPL"); 366MODULE_LICENSE("GPL");
367MODULE_ALIAS("platform:spitz-audio");
diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
index 78fc159559b0..e18182699d83 100644
--- a/sound/soc/rockchip/Kconfig
+++ b/sound/soc/rockchip/Kconfig
@@ -1,11 +1,16 @@
1config SND_SOC_ROCKCHIP 1config SND_SOC_ROCKCHIP
2 tristate "ASoC support for Rockchip" 2 tristate "ASoC support for Rockchip"
3 depends on COMPILE_TEST || ARCH_ROCKCHIP 3 depends on COMPILE_TEST || ARCH_ROCKCHIP
4 select SND_SOC_GENERIC_DMAENGINE_PCM
5 help 4 help
6 Say Y or M if you want to add support for codecs attached to 5 Say Y or M if you want to add support for codecs attached to
7 the Rockchip SoCs' Audio interfaces. You will also need to 6 the Rockchip SoCs' Audio interfaces. You will also need to
8 select the audio interfaces to support below. 7 select the audio interfaces to support below.
9 8
10config SND_SOC_ROCKCHIP_I2S 9config SND_SOC_ROCKCHIP_I2S
11 tristate 10 tristate "Rockchip I2S Device Driver"
11 depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP
12 select SND_SOC_GENERIC_DMAENGINE_PCM
13 help
14 Say Y or M if you want to add support for I2S driver for
15 Rockchip I2S device. The device supports upto maximum of
16 8 channels each for play and record.
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
index 55a38697443d..fc67f97f19f6 100644
--- a/sound/soc/samsung/Kconfig
+++ b/sound/soc/samsung/Kconfig
@@ -1,6 +1,6 @@
1config SND_SOC_SAMSUNG 1config SND_SOC_SAMSUNG
2 tristate "ASoC support for Samsung" 2 tristate "ASoC support for Samsung"
3 depends on PLAT_SAMSUNG 3 depends on (PLAT_SAMSUNG || ARCH_EXYNOS)
4 depends on S3C64XX_PL080 || !ARCH_S3C64XX 4 depends on S3C64XX_PL080 || !ARCH_S3C64XX
5 depends on S3C24XX_DMAC || !ARCH_S3C24XX 5 depends on S3C24XX_DMAC || !ARCH_S3C24XX
6 select SND_SOC_GENERIC_DMAENGINE_PCM 6 select SND_SOC_GENERIC_DMAENGINE_PCM
@@ -239,3 +239,9 @@ config SND_SOC_ODROIDX2
239 select SND_SAMSUNG_I2S 239 select SND_SAMSUNG_I2S
240 help 240 help
241 Say Y here to enable audio support for the Odroid-X2/U3. 241 Say Y here to enable audio support for the Odroid-X2/U3.
242
243config SND_SOC_ARNDALE_RT5631_ALC5631
244 tristate "Audio support for RT5631(ALC5631) on Arndale Board"
245 depends on SND_SOC_SAMSUNG
246 select SND_SAMSUNG_I2S
247 select SND_SOC_RT5631
diff --git a/sound/soc/samsung/Makefile b/sound/soc/samsung/Makefile
index 91505ddaaf95..31e3dba7e3b5 100644
--- a/sound/soc/samsung/Makefile
+++ b/sound/soc/samsung/Makefile
@@ -45,6 +45,7 @@ snd-soc-lowland-objs := lowland.o
45snd-soc-littlemill-objs := littlemill.o 45snd-soc-littlemill-objs := littlemill.o
46snd-soc-bells-objs := bells.o 46snd-soc-bells-objs := bells.o
47snd-soc-odroidx2-max98090-objs := odroidx2_max98090.o 47snd-soc-odroidx2-max98090-objs := odroidx2_max98090.o
48snd-soc-arndale-rt5631-objs := arndale_rt5631.o
48 49
49obj-$(CONFIG_SND_SOC_SAMSUNG_JIVE_WM8750) += snd-soc-jive-wm8750.o 50obj-$(CONFIG_SND_SOC_SAMSUNG_JIVE_WM8750) += snd-soc-jive-wm8750.o
50obj-$(CONFIG_SND_SOC_SAMSUNG_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o 51obj-$(CONFIG_SND_SOC_SAMSUNG_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o
@@ -71,3 +72,4 @@ obj-$(CONFIG_SND_SOC_LOWLAND) += snd-soc-lowland.o
71obj-$(CONFIG_SND_SOC_LITTLEMILL) += snd-soc-littlemill.o 72obj-$(CONFIG_SND_SOC_LITTLEMILL) += snd-soc-littlemill.o
72obj-$(CONFIG_SND_SOC_BELLS) += snd-soc-bells.o 73obj-$(CONFIG_SND_SOC_BELLS) += snd-soc-bells.o
73obj-$(CONFIG_SND_SOC_ODROIDX2) += snd-soc-odroidx2-max98090.o 74obj-$(CONFIG_SND_SOC_ODROIDX2) += snd-soc-odroidx2-max98090.o
75obj-$(CONFIG_SND_SOC_ARNDALE_RT5631_ALC5631) += snd-soc-arndale-rt5631.o
diff --git a/sound/soc/samsung/ac97.c b/sound/soc/samsung/ac97.c
index e1615113fd84..7952a625669d 100644
--- a/sound/soc/samsung/ac97.c
+++ b/sound/soc/samsung/ac97.c
@@ -288,7 +288,7 @@ static int s3c_ac97_mic_dai_probe(struct snd_soc_dai *dai)
288static struct snd_soc_dai_driver s3c_ac97_dai[] = { 288static struct snd_soc_dai_driver s3c_ac97_dai[] = {
289 [S3C_AC97_DAI_PCM] = { 289 [S3C_AC97_DAI_PCM] = {
290 .name = "samsung-ac97", 290 .name = "samsung-ac97",
291 .ac97_control = 1, 291 .bus_control = true,
292 .playback = { 292 .playback = {
293 .stream_name = "AC97 Playback", 293 .stream_name = "AC97 Playback",
294 .channels_min = 2, 294 .channels_min = 2,
@@ -306,7 +306,7 @@ static struct snd_soc_dai_driver s3c_ac97_dai[] = {
306 }, 306 },
307 [S3C_AC97_DAI_MIC] = { 307 [S3C_AC97_DAI_MIC] = {
308 .name = "samsung-ac97-mic", 308 .name = "samsung-ac97-mic",
309 .ac97_control = 1, 309 .bus_control = true,
310 .capture = { 310 .capture = {
311 .stream_name = "AC97 Mic Capture", 311 .stream_name = "AC97 Mic Capture",
312 .channels_min = 1, 312 .channels_min = 1,
diff --git a/sound/soc/samsung/arndale_rt5631.c b/sound/soc/samsung/arndale_rt5631.c
new file mode 100644
index 000000000000..1e2b61ca8db2
--- /dev/null
+++ b/sound/soc/samsung/arndale_rt5631.c
@@ -0,0 +1,150 @@
1/*
2 * arndale_rt5631.c
3 *
4 * Copyright (c) 2014, Insignal Co., Ltd.
5 *
6 * Author: Claude <claude@insginal.co.kr>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/clk.h>
17
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22
23#include "i2s.h"
24
25static int arndale_hw_params(struct snd_pcm_substream *substream,
26 struct snd_pcm_hw_params *params)
27{
28 struct snd_soc_pcm_runtime *rtd = substream->private_data;
29 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
30 struct snd_soc_dai *codec_dai = rtd->codec_dai;
31 int rfs, ret;
32 unsigned long rclk;
33
34 rfs = 256;
35
36 rclk = params_rate(params) * rfs;
37
38 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
39 0, SND_SOC_CLOCK_OUT);
40 if (ret < 0)
41 return ret;
42
43 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
44 0, SND_SOC_CLOCK_OUT);
45
46 if (ret < 0)
47 return ret;
48
49 ret = snd_soc_dai_set_sysclk(codec_dai, 0, rclk, SND_SOC_CLOCK_OUT);
50 if (ret < 0)
51 return ret;
52
53 return 0;
54}
55
56static struct snd_soc_ops arndale_ops = {
57 .hw_params = arndale_hw_params,
58};
59
60static struct snd_soc_dai_link arndale_rt5631_dai[] = {
61 {
62 .name = "RT5631 HiFi",
63 .stream_name = "Primary",
64 .codec_dai_name = "rt5631-hifi",
65 .dai_fmt = SND_SOC_DAIFMT_I2S
66 | SND_SOC_DAIFMT_NB_NF
67 | SND_SOC_DAIFMT_CBS_CFS,
68 .ops = &arndale_ops,
69 },
70};
71
72static struct snd_soc_card arndale_rt5631 = {
73 .name = "Arndale RT5631",
74 .dai_link = arndale_rt5631_dai,
75 .num_links = ARRAY_SIZE(arndale_rt5631_dai),
76};
77
78static int arndale_audio_probe(struct platform_device *pdev)
79{
80 int n, ret;
81 struct device_node *np = pdev->dev.of_node;
82 struct snd_soc_card *card = &arndale_rt5631;
83
84 card->dev = &pdev->dev;
85
86 for (n = 0; np && n < ARRAY_SIZE(arndale_rt5631_dai); n++) {
87 if (!arndale_rt5631_dai[n].cpu_dai_name) {
88 arndale_rt5631_dai[n].cpu_of_node = of_parse_phandle(np,
89 "samsung,audio-cpu", n);
90
91 if (!arndale_rt5631_dai[n].cpu_of_node) {
92 dev_err(&pdev->dev,
93 "Property 'samsung,audio-cpu' missing or invalid\n");
94 return -EINVAL;
95 }
96 }
97 if (!arndale_rt5631_dai[n].platform_name)
98 arndale_rt5631_dai[n].platform_of_node =
99 arndale_rt5631_dai[n].cpu_of_node;
100
101 arndale_rt5631_dai[n].codec_name = NULL;
102 arndale_rt5631_dai[n].codec_of_node = of_parse_phandle(np,
103 "samsung,audio-codec", n);
104 if (!arndale_rt5631_dai[0].codec_of_node) {
105 dev_err(&pdev->dev,
106 "Property 'samsung,audio-codec' missing or invalid\n");
107 return -EINVAL;
108 }
109 }
110
111 ret = devm_snd_soc_register_card(card->dev, card);
112
113 if (ret)
114 dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
115
116 return ret;
117}
118
119static int arndale_audio_remove(struct platform_device *pdev)
120{
121 struct snd_soc_card *card = platform_get_drvdata(pdev);
122
123 snd_soc_unregister_card(card);
124
125 return 0;
126}
127
128static const struct of_device_id samsung_arndale_rt5631_of_match[] __maybe_unused = {
129 { .compatible = "samsung,arndale-rt5631", },
130 { .compatible = "samsung,arndale-alc5631", },
131 {},
132};
133MODULE_DEVICE_TABLE(of, samsung_arndale_rt5631_of_match);
134
135static struct platform_driver arndale_audio_driver = {
136 .driver = {
137 .name = "arndale-audio",
138 .owner = THIS_MODULE,
139 .pm = &snd_soc_pm_ops,
140 .of_match_table = of_match_ptr(samsung_arndale_rt5631_of_match),
141 },
142 .probe = arndale_audio_probe,
143 .remove = arndale_audio_remove,
144};
145
146module_platform_driver(arndale_audio_driver);
147
148MODULE_AUTHOR("Claude <claude@insignal.co.kr>");
149MODULE_DESCRIPTION("ALSA SoC Driver for Arndale Board");
150MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/i2s-regs.h b/sound/soc/samsung/i2s-regs.h
index 821a50231002..9170c311d66e 100644
--- a/sound/soc/samsung/i2s-regs.h
+++ b/sound/soc/samsung/i2s-regs.h
@@ -33,8 +33,9 @@
33#define I2SLVL3ADDR 0x3c 33#define I2SLVL3ADDR 0x3c
34#define I2SSTR1 0x40 34#define I2SSTR1 0x40
35#define I2SVER 0x44 35#define I2SVER 0x44
36#define I2SFIC2 0x48 36#define I2SFIC1 0x48
37#define I2STDM 0x4c 37#define I2STDM 0x4c
38#define I2SFSTA 0x50
38 39
39#define CON_RSTCLR (1 << 31) 40#define CON_RSTCLR (1 << 31)
40#define CON_FRXOFSTATUS (1 << 26) 41#define CON_FRXOFSTATUS (1 << 26)
@@ -93,8 +94,6 @@
93#define MOD_BLC_24BIT (2 << 13) 94#define MOD_BLC_24BIT (2 << 13)
94#define MOD_BLC_MASK (3 << 13) 95#define MOD_BLC_MASK (3 << 13)
95 96
96#define MOD_IMS_SYSMUX (1 << 10)
97#define MOD_SLAVE (1 << 11)
98#define MOD_TXONLY (0 << 8) 97#define MOD_TXONLY (0 << 8)
99#define MOD_RXONLY (1 << 8) 98#define MOD_RXONLY (1 << 8)
100#define MOD_TXRX (2 << 8) 99#define MOD_TXRX (2 << 8)
@@ -132,7 +131,10 @@
132#define EXYNOS5420_MOD_BCLK_256FS 8 131#define EXYNOS5420_MOD_BCLK_256FS 8
133#define EXYNOS5420_MOD_BCLK_MASK 0xf 132#define EXYNOS5420_MOD_BCLK_MASK 0xf
134 133
135#define MOD_CDCLKCON (1 << 12) 134#define EXYNOS7_MOD_RCLK_64FS 4
135#define EXYNOS7_MOD_RCLK_128FS 5
136#define EXYNOS7_MOD_RCLK_96FS 6
137#define EXYNOS7_MOD_RCLK_192FS 7
136 138
137#define PSR_PSREN (1 << 15) 139#define PSR_PSREN (1 << 15)
138 140
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index 9d513473b300..c7aafcd95de3 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -36,9 +36,24 @@ enum samsung_dai_type {
36 TYPE_SEC, 36 TYPE_SEC,
37}; 37};
38 38
39struct samsung_i2s_variant_regs {
40 unsigned int bfs_off;
41 unsigned int rfs_off;
42 unsigned int sdf_off;
43 unsigned int txr_off;
44 unsigned int rclksrc_off;
45 unsigned int mss_off;
46 unsigned int cdclkcon_off;
47 unsigned int lrp_off;
48 unsigned int bfs_mask;
49 unsigned int rfs_mask;
50 unsigned int ftx0cnt_off;
51};
52
39struct samsung_i2s_dai_data { 53struct samsung_i2s_dai_data {
40 int dai_type; 54 int dai_type;
41 u32 quirks; 55 u32 quirks;
56 const struct samsung_i2s_variant_regs *i2s_variant_regs;
42}; 57};
43 58
44struct i2s_dai { 59struct i2s_dai {
@@ -81,6 +96,7 @@ struct i2s_dai {
81 u32 suspend_i2scon; 96 u32 suspend_i2scon;
82 u32 suspend_i2spsr; 97 u32 suspend_i2spsr;
83 unsigned long gpios[7]; /* i2s gpio line numbers */ 98 unsigned long gpios[7]; /* i2s gpio line numbers */
99 const struct samsung_i2s_variant_regs *variant_regs;
84}; 100};
85 101
86/* Lock for cross i/f checks */ 102/* Lock for cross i/f checks */
@@ -95,7 +111,8 @@ static inline bool is_secondary(struct i2s_dai *i2s)
95/* If operating in SoC-Slave mode */ 111/* If operating in SoC-Slave mode */
96static inline bool is_slave(struct i2s_dai *i2s) 112static inline bool is_slave(struct i2s_dai *i2s)
97{ 113{
98 return (readl(i2s->addr + I2SMOD) & MOD_SLAVE) ? true : false; 114 u32 mod = readl(i2s->addr + I2SMOD);
115 return (mod & (1 << i2s->variant_regs->mss_off)) ? true : false;
99} 116}
100 117
101/* If this interface of the controller is transmitting data */ 118/* If this interface of the controller is transmitting data */
@@ -200,14 +217,14 @@ static inline bool is_manager(struct i2s_dai *i2s)
200static inline unsigned get_rfs(struct i2s_dai *i2s) 217static inline unsigned get_rfs(struct i2s_dai *i2s)
201{ 218{
202 u32 rfs; 219 u32 rfs;
203 220 rfs = readl(i2s->addr + I2SMOD) >> i2s->variant_regs->rfs_off;
204 if (i2s->quirks & QUIRK_SUPPORTS_TDM) 221 rfs &= i2s->variant_regs->rfs_mask;
205 rfs = readl(i2s->addr + I2SMOD) >> EXYNOS5420_MOD_RCLK_SHIFT;
206 else
207 rfs = (readl(i2s->addr + I2SMOD) >> MOD_RCLK_SHIFT);
208 rfs &= MOD_RCLK_MASK;
209 222
210 switch (rfs) { 223 switch (rfs) {
224 case 7: return 192;
225 case 6: return 96;
226 case 5: return 128;
227 case 4: return 64;
211 case 3: return 768; 228 case 3: return 768;
212 case 2: return 384; 229 case 2: return 384;
213 case 1: return 512; 230 case 1: return 512;
@@ -219,15 +236,23 @@ static inline unsigned get_rfs(struct i2s_dai *i2s)
219static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs) 236static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs)
220{ 237{
221 u32 mod = readl(i2s->addr + I2SMOD); 238 u32 mod = readl(i2s->addr + I2SMOD);
222 int rfs_shift; 239 int rfs_shift = i2s->variant_regs->rfs_off;
223 240
224 if (i2s->quirks & QUIRK_SUPPORTS_TDM) 241 mod &= ~(i2s->variant_regs->rfs_mask << rfs_shift);
225 rfs_shift = EXYNOS5420_MOD_RCLK_SHIFT;
226 else
227 rfs_shift = MOD_RCLK_SHIFT;
228 mod &= ~(MOD_RCLK_MASK << rfs_shift);
229 242
230 switch (rfs) { 243 switch (rfs) {
244 case 192:
245 mod |= (EXYNOS7_MOD_RCLK_192FS << rfs_shift);
246 break;
247 case 96:
248 mod |= (EXYNOS7_MOD_RCLK_96FS << rfs_shift);
249 break;
250 case 128:
251 mod |= (EXYNOS7_MOD_RCLK_128FS << rfs_shift);
252 break;
253 case 64:
254 mod |= (EXYNOS7_MOD_RCLK_64FS << rfs_shift);
255 break;
231 case 768: 256 case 768:
232 mod |= (MOD_RCLK_768FS << rfs_shift); 257 mod |= (MOD_RCLK_768FS << rfs_shift);
233 break; 258 break;
@@ -249,14 +274,8 @@ static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs)
249static inline unsigned get_bfs(struct i2s_dai *i2s) 274static inline unsigned get_bfs(struct i2s_dai *i2s)
250{ 275{
251 u32 bfs; 276 u32 bfs;
252 277 bfs = readl(i2s->addr + I2SMOD) >> i2s->variant_regs->bfs_off;
253 if (i2s->quirks & QUIRK_SUPPORTS_TDM) { 278 bfs &= i2s->variant_regs->bfs_mask;
254 bfs = readl(i2s->addr + I2SMOD) >> EXYNOS5420_MOD_BCLK_SHIFT;
255 bfs &= EXYNOS5420_MOD_BCLK_MASK;
256 } else {
257 bfs = readl(i2s->addr + I2SMOD) >> MOD_BCLK_SHIFT;
258 bfs &= MOD_BCLK_MASK;
259 }
260 279
261 switch (bfs) { 280 switch (bfs) {
262 case 8: return 256; 281 case 8: return 256;
@@ -275,16 +294,8 @@ static inline unsigned get_bfs(struct i2s_dai *i2s)
275static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs) 294static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs)
276{ 295{
277 u32 mod = readl(i2s->addr + I2SMOD); 296 u32 mod = readl(i2s->addr + I2SMOD);
278 int bfs_shift;
279 int tdm = i2s->quirks & QUIRK_SUPPORTS_TDM; 297 int tdm = i2s->quirks & QUIRK_SUPPORTS_TDM;
280 298 int bfs_shift = i2s->variant_regs->bfs_off;
281 if (i2s->quirks & QUIRK_SUPPORTS_TDM) {
282 bfs_shift = EXYNOS5420_MOD_BCLK_SHIFT;
283 mod &= ~(EXYNOS5420_MOD_BCLK_MASK << bfs_shift);
284 } else {
285 bfs_shift = MOD_BCLK_SHIFT;
286 mod &= ~(MOD_BCLK_MASK << bfs_shift);
287 }
288 299
289 /* Non-TDM I2S controllers do not support BCLK > 48 * FS */ 300 /* Non-TDM I2S controllers do not support BCLK > 48 * FS */
290 if (!tdm && bfs > 48) { 301 if (!tdm && bfs > 48) {
@@ -292,6 +303,8 @@ static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs)
292 return; 303 return;
293 } 304 }
294 305
306 mod &= ~(i2s->variant_regs->bfs_mask << bfs_shift);
307
295 switch (bfs) { 308 switch (bfs) {
296 case 48: 309 case 48:
297 mod |= (MOD_BCLK_48FS << bfs_shift); 310 mod |= (MOD_BCLK_48FS << bfs_shift);
@@ -346,8 +359,9 @@ static inline int get_blc(struct i2s_dai *i2s)
346static void i2s_txctrl(struct i2s_dai *i2s, int on) 359static void i2s_txctrl(struct i2s_dai *i2s, int on)
347{ 360{
348 void __iomem *addr = i2s->addr; 361 void __iomem *addr = i2s->addr;
362 int txr_off = i2s->variant_regs->txr_off;
349 u32 con = readl(addr + I2SCON); 363 u32 con = readl(addr + I2SCON);
350 u32 mod = readl(addr + I2SMOD) & ~MOD_MASK; 364 u32 mod = readl(addr + I2SMOD) & ~(3 << txr_off);
351 365
352 if (on) { 366 if (on) {
353 con |= CON_ACTIVE; 367 con |= CON_ACTIVE;
@@ -362,9 +376,9 @@ static void i2s_txctrl(struct i2s_dai *i2s, int on)
362 } 376 }
363 377
364 if (any_rx_active(i2s)) 378 if (any_rx_active(i2s))
365 mod |= MOD_TXRX; 379 mod |= 2 << txr_off;
366 else 380 else
367 mod |= MOD_TXONLY; 381 mod |= 0 << txr_off;
368 } else { 382 } else {
369 if (is_secondary(i2s)) { 383 if (is_secondary(i2s)) {
370 con |= CON_TXSDMA_PAUSE; 384 con |= CON_TXSDMA_PAUSE;
@@ -382,7 +396,7 @@ static void i2s_txctrl(struct i2s_dai *i2s, int on)
382 con |= CON_TXCH_PAUSE; 396 con |= CON_TXCH_PAUSE;
383 397
384 if (any_rx_active(i2s)) 398 if (any_rx_active(i2s))
385 mod |= MOD_RXONLY; 399 mod |= 1 << txr_off;
386 else 400 else
387 con &= ~CON_ACTIVE; 401 con &= ~CON_ACTIVE;
388 } 402 }
@@ -395,23 +409,24 @@ static void i2s_txctrl(struct i2s_dai *i2s, int on)
395static void i2s_rxctrl(struct i2s_dai *i2s, int on) 409static void i2s_rxctrl(struct i2s_dai *i2s, int on)
396{ 410{
397 void __iomem *addr = i2s->addr; 411 void __iomem *addr = i2s->addr;
412 int txr_off = i2s->variant_regs->txr_off;
398 u32 con = readl(addr + I2SCON); 413 u32 con = readl(addr + I2SCON);
399 u32 mod = readl(addr + I2SMOD) & ~MOD_MASK; 414 u32 mod = readl(addr + I2SMOD) & ~(3 << txr_off);
400 415
401 if (on) { 416 if (on) {
402 con |= CON_RXDMA_ACTIVE | CON_ACTIVE; 417 con |= CON_RXDMA_ACTIVE | CON_ACTIVE;
403 con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE); 418 con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE);
404 419
405 if (any_tx_active(i2s)) 420 if (any_tx_active(i2s))
406 mod |= MOD_TXRX; 421 mod |= 2 << txr_off;
407 else 422 else
408 mod |= MOD_RXONLY; 423 mod |= 1 << txr_off;
409 } else { 424 } else {
410 con |= CON_RXDMA_PAUSE | CON_RXCH_PAUSE; 425 con |= CON_RXDMA_PAUSE | CON_RXCH_PAUSE;
411 con &= ~CON_RXDMA_ACTIVE; 426 con &= ~CON_RXDMA_ACTIVE;
412 427
413 if (any_tx_active(i2s)) 428 if (any_tx_active(i2s))
414 mod |= MOD_TXONLY; 429 mod |= 0 << txr_off;
415 else 430 else
416 con &= ~CON_ACTIVE; 431 con &= ~CON_ACTIVE;
417 } 432 }
@@ -451,6 +466,9 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
451 struct i2s_dai *i2s = to_info(dai); 466 struct i2s_dai *i2s = to_info(dai);
452 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 467 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
453 u32 mod = readl(i2s->addr + I2SMOD); 468 u32 mod = readl(i2s->addr + I2SMOD);
469 const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
470 unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off;
471 unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off;
454 472
455 switch (clk_id) { 473 switch (clk_id) {
456 case SAMSUNG_I2S_OPCLK: 474 case SAMSUNG_I2S_OPCLK:
@@ -465,18 +483,18 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
465 if ((rfs && other && other->rfs && (other->rfs != rfs)) || 483 if ((rfs && other && other->rfs && (other->rfs != rfs)) ||
466 (any_active(i2s) && 484 (any_active(i2s) &&
467 (((dir == SND_SOC_CLOCK_IN) 485 (((dir == SND_SOC_CLOCK_IN)
468 && !(mod & MOD_CDCLKCON)) || 486 && !(mod & cdcon_mask)) ||
469 ((dir == SND_SOC_CLOCK_OUT) 487 ((dir == SND_SOC_CLOCK_OUT)
470 && (mod & MOD_CDCLKCON))))) { 488 && (mod & cdcon_mask))))) {
471 dev_err(&i2s->pdev->dev, 489 dev_err(&i2s->pdev->dev,
472 "%s:%d Other DAI busy\n", __func__, __LINE__); 490 "%s:%d Other DAI busy\n", __func__, __LINE__);
473 return -EAGAIN; 491 return -EAGAIN;
474 } 492 }
475 493
476 if (dir == SND_SOC_CLOCK_IN) 494 if (dir == SND_SOC_CLOCK_IN)
477 mod |= MOD_CDCLKCON; 495 mod |= 1 << i2s_regs->cdclkcon_off;
478 else 496 else
479 mod &= ~MOD_CDCLKCON; 497 mod &= ~(1 << i2s_regs->cdclkcon_off);
480 498
481 i2s->rfs = rfs; 499 i2s->rfs = rfs;
482 break; 500 break;
@@ -491,8 +509,8 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
491 509
492 if (!any_active(i2s)) { 510 if (!any_active(i2s)) {
493 if (i2s->op_clk && !IS_ERR(i2s->op_clk)) { 511 if (i2s->op_clk && !IS_ERR(i2s->op_clk)) {
494 if ((clk_id && !(mod & MOD_IMS_SYSMUX)) || 512 if ((clk_id && !(mod & rsrc_mask)) ||
495 (!clk_id && (mod & MOD_IMS_SYSMUX))) { 513 (!clk_id && (mod & rsrc_mask))) {
496 clk_disable_unprepare(i2s->op_clk); 514 clk_disable_unprepare(i2s->op_clk);
497 clk_put(i2s->op_clk); 515 clk_put(i2s->op_clk);
498 } else { 516 } else {
@@ -520,8 +538,8 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
520 other->op_clk = i2s->op_clk; 538 other->op_clk = i2s->op_clk;
521 other->rclk_srcrate = i2s->rclk_srcrate; 539 other->rclk_srcrate = i2s->rclk_srcrate;
522 } 540 }
523 } else if ((!clk_id && (mod & MOD_IMS_SYSMUX)) 541 } else if ((!clk_id && (mod & rsrc_mask))
524 || (clk_id && !(mod & MOD_IMS_SYSMUX))) { 542 || (clk_id && !(mod & rsrc_mask))) {
525 dev_err(&i2s->pdev->dev, 543 dev_err(&i2s->pdev->dev,
526 "%s:%d Other DAI busy\n", __func__, __LINE__); 544 "%s:%d Other DAI busy\n", __func__, __LINE__);
527 return -EAGAIN; 545 return -EAGAIN;
@@ -533,11 +551,11 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
533 } 551 }
534 552
535 if (clk_id == 0) 553 if (clk_id == 0)
536 mod &= ~MOD_IMS_SYSMUX; 554 mod &= ~(1 << i2s_regs->rclksrc_off);
537 else 555 else
538 mod |= MOD_IMS_SYSMUX; 556 mod |= 1 << i2s_regs->rclksrc_off;
539 break;
540 557
558 break;
541 default: 559 default:
542 dev_err(&i2s->pdev->dev, "We don't serve that!\n"); 560 dev_err(&i2s->pdev->dev, "We don't serve that!\n");
543 return -EINVAL; 561 return -EINVAL;
@@ -553,16 +571,12 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
553{ 571{
554 struct i2s_dai *i2s = to_info(dai); 572 struct i2s_dai *i2s = to_info(dai);
555 u32 mod = readl(i2s->addr + I2SMOD); 573 u32 mod = readl(i2s->addr + I2SMOD);
556 int lrp_shift, sdf_shift, sdf_mask, lrp_rlow; 574 int lrp_shift, sdf_shift, sdf_mask, lrp_rlow, mod_slave;
557 u32 tmp = 0; 575 u32 tmp = 0;
558 576
559 if (i2s->quirks & QUIRK_SUPPORTS_TDM) { 577 lrp_shift = i2s->variant_regs->lrp_off;
560 lrp_shift = EXYNOS5420_MOD_LRP_SHIFT; 578 sdf_shift = i2s->variant_regs->sdf_off;
561 sdf_shift = EXYNOS5420_MOD_SDF_SHIFT; 579 mod_slave = 1 << i2s->variant_regs->mss_off;
562 } else {
563 lrp_shift = MOD_LRP_SHIFT;
564 sdf_shift = MOD_SDF_SHIFT;
565 }
566 580
567 sdf_mask = MOD_SDF_MASK << sdf_shift; 581 sdf_mask = MOD_SDF_MASK << sdf_shift;
568 lrp_rlow = MOD_LR_RLOW << lrp_shift; 582 lrp_rlow = MOD_LR_RLOW << lrp_shift;
@@ -605,7 +619,7 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
605 619
606 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 620 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
607 case SND_SOC_DAIFMT_CBM_CFM: 621 case SND_SOC_DAIFMT_CBM_CFM:
608 tmp |= MOD_SLAVE; 622 tmp |= mod_slave;
609 break; 623 break;
610 case SND_SOC_DAIFMT_CBS_CFS: 624 case SND_SOC_DAIFMT_CBS_CFS:
611 /* Set default source clock in Master mode */ 625 /* Set default source clock in Master mode */
@@ -623,13 +637,13 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
623 * channel. 637 * channel.
624 */ 638 */
625 if (any_active(i2s) && 639 if (any_active(i2s) &&
626 ((mod & (sdf_mask | lrp_rlow | MOD_SLAVE)) != tmp)) { 640 ((mod & (sdf_mask | lrp_rlow | mod_slave)) != tmp)) {
627 dev_err(&i2s->pdev->dev, 641 dev_err(&i2s->pdev->dev,
628 "%s:%d Other DAI busy\n", __func__, __LINE__); 642 "%s:%d Other DAI busy\n", __func__, __LINE__);
629 return -EAGAIN; 643 return -EAGAIN;
630 } 644 }
631 645
632 mod &= ~(sdf_mask | lrp_rlow | MOD_SLAVE); 646 mod &= ~(sdf_mask | lrp_rlow | mod_slave);
633 mod |= tmp; 647 mod |= tmp;
634 writel(mod, i2s->addr + I2SMOD); 648 writel(mod, i2s->addr + I2SMOD);
635 649
@@ -751,6 +765,7 @@ static void i2s_shutdown(struct snd_pcm_substream *substream,
751 struct i2s_dai *i2s = to_info(dai); 765 struct i2s_dai *i2s = to_info(dai);
752 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 766 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
753 unsigned long flags; 767 unsigned long flags;
768 const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
754 769
755 spin_lock_irqsave(&lock, flags); 770 spin_lock_irqsave(&lock, flags);
756 771
@@ -761,7 +776,7 @@ static void i2s_shutdown(struct snd_pcm_substream *substream,
761 other->mode |= DAI_MANAGER; 776 other->mode |= DAI_MANAGER;
762 } else { 777 } else {
763 u32 mod = readl(i2s->addr + I2SMOD); 778 u32 mod = readl(i2s->addr + I2SMOD);
764 i2s->cdclk_out = !(mod & MOD_CDCLKCON); 779 i2s->cdclk_out = !(mod & (1 << i2s_regs->cdclkcon_off));
765 if (other) 780 if (other)
766 other->cdclk_out = i2s->cdclk_out; 781 other->cdclk_out = i2s->cdclk_out;
767 } 782 }
@@ -914,13 +929,14 @@ i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
914 struct i2s_dai *i2s = to_info(dai); 929 struct i2s_dai *i2s = to_info(dai);
915 u32 reg = readl(i2s->addr + I2SFIC); 930 u32 reg = readl(i2s->addr + I2SFIC);
916 snd_pcm_sframes_t delay; 931 snd_pcm_sframes_t delay;
932 const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
917 933
918 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) 934 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
919 delay = FIC_RXCOUNT(reg); 935 delay = FIC_RXCOUNT(reg);
920 else if (is_secondary(i2s)) 936 else if (is_secondary(i2s))
921 delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS)); 937 delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
922 else 938 else
923 delay = FIC_TXCOUNT(reg); 939 delay = (reg >> i2s_regs->ftx0cnt_off) & 0x7f;
924 940
925 return delay; 941 return delay;
926} 942}
@@ -956,6 +972,7 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
956{ 972{
957 struct i2s_dai *i2s = to_info(dai); 973 struct i2s_dai *i2s = to_info(dai);
958 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 974 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
975 int ret;
959 976
960 if (other && other->clk) { /* If this is probe on secondary */ 977 if (other && other->clk) { /* If this is probe on secondary */
961 samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback, 978 samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback,
@@ -973,9 +990,14 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
973 if (IS_ERR(i2s->clk)) { 990 if (IS_ERR(i2s->clk)) {
974 dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n"); 991 dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n");
975 iounmap(i2s->addr); 992 iounmap(i2s->addr);
976 return -ENOENT; 993 return PTR_ERR(i2s->clk);
994 }
995
996 ret = clk_prepare_enable(i2s->clk);
997 if (ret != 0) {
998 dev_err(&i2s->pdev->dev, "failed to enable clock: %d\n", ret);
999 return ret;
977 } 1000 }
978 clk_prepare_enable(i2s->clk);
979 1001
980 samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture); 1002 samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
981 1003
@@ -987,7 +1009,7 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
987 if (i2s->quirks & QUIRK_NEED_RSTCLR) 1009 if (i2s->quirks & QUIRK_NEED_RSTCLR)
988 writel(CON_RSTCLR, i2s->addr + I2SCON); 1010 writel(CON_RSTCLR, i2s->addr + I2SCON);
989 1011
990 if (i2s->quirks & QUIRK_SEC_DAI) 1012 if (i2s->quirks & QUIRK_SUPPORTS_IDMA)
991 idma_reg_addr_init(i2s->addr, 1013 idma_reg_addr_init(i2s->addr,
992 i2s->sec_dai->idma_playback.dma_addr); 1014 i2s->sec_dai->idma_playback.dma_addr);
993 1015
@@ -1199,10 +1221,9 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1199 quirks = i2s_dai_data->quirks; 1221 quirks = i2s_dai_data->quirks;
1200 if (of_property_read_u32(np, "samsung,idma-addr", 1222 if (of_property_read_u32(np, "samsung,idma-addr",
1201 &idma_addr)) { 1223 &idma_addr)) {
1202 if (quirks & QUIRK_SEC_DAI) { 1224 if (quirks & QUIRK_SUPPORTS_IDMA) {
1203 dev_err(&pdev->dev, "idma address is not"\ 1225 dev_info(&pdev->dev, "idma address is not"\
1204 "specified"); 1226 "specified");
1205 return -EINVAL;
1206 } 1227 }
1207 } 1228 }
1208 } 1229 }
@@ -1228,6 +1249,7 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1228 pri_dai->dma_capture.dma_size = 4; 1249 pri_dai->dma_capture.dma_size = 4;
1229 pri_dai->base = regs_base; 1250 pri_dai->base = regs_base;
1230 pri_dai->quirks = quirks; 1251 pri_dai->quirks = quirks;
1252 pri_dai->variant_regs = i2s_dai_data->i2s_variant_regs;
1231 1253
1232 if (quirks & QUIRK_PRI_6CHAN) 1254 if (quirks & QUIRK_PRI_6CHAN)
1233 pri_dai->i2s_dai_drv.playback.channels_max = 6; 1255 pri_dai->i2s_dai_drv.playback.channels_max = 6;
@@ -1302,20 +1324,93 @@ static int samsung_i2s_remove(struct platform_device *pdev)
1302 return 0; 1324 return 0;
1303} 1325}
1304 1326
1327static const struct samsung_i2s_variant_regs i2sv3_regs = {
1328 .bfs_off = 1,
1329 .rfs_off = 3,
1330 .sdf_off = 5,
1331 .txr_off = 8,
1332 .rclksrc_off = 10,
1333 .mss_off = 11,
1334 .cdclkcon_off = 12,
1335 .lrp_off = 7,
1336 .bfs_mask = 0x3,
1337 .rfs_mask = 0x3,
1338 .ftx0cnt_off = 8,
1339};
1340
1341static const struct samsung_i2s_variant_regs i2sv6_regs = {
1342 .bfs_off = 0,
1343 .rfs_off = 4,
1344 .sdf_off = 6,
1345 .txr_off = 8,
1346 .rclksrc_off = 10,
1347 .mss_off = 11,
1348 .cdclkcon_off = 12,
1349 .lrp_off = 15,
1350 .bfs_mask = 0xf,
1351 .rfs_mask = 0x3,
1352 .ftx0cnt_off = 8,
1353};
1354
1355static const struct samsung_i2s_variant_regs i2sv7_regs = {
1356 .bfs_off = 0,
1357 .rfs_off = 4,
1358 .sdf_off = 7,
1359 .txr_off = 9,
1360 .rclksrc_off = 11,
1361 .mss_off = 12,
1362 .cdclkcon_off = 22,
1363 .lrp_off = 15,
1364 .bfs_mask = 0xf,
1365 .rfs_mask = 0x7,
1366 .ftx0cnt_off = 0,
1367};
1368
1369static const struct samsung_i2s_variant_regs i2sv5_i2s1_regs = {
1370 .bfs_off = 0,
1371 .rfs_off = 3,
1372 .sdf_off = 6,
1373 .txr_off = 8,
1374 .rclksrc_off = 10,
1375 .mss_off = 11,
1376 .cdclkcon_off = 12,
1377 .lrp_off = 15,
1378 .bfs_mask = 0x7,
1379 .rfs_mask = 0x7,
1380 .ftx0cnt_off = 8,
1381};
1382
1305static const struct samsung_i2s_dai_data i2sv3_dai_type = { 1383static const struct samsung_i2s_dai_data i2sv3_dai_type = {
1306 .dai_type = TYPE_PRI, 1384 .dai_type = TYPE_PRI,
1307 .quirks = QUIRK_NO_MUXPSR, 1385 .quirks = QUIRK_NO_MUXPSR,
1386 .i2s_variant_regs = &i2sv3_regs,
1308}; 1387};
1309 1388
1310static const struct samsung_i2s_dai_data i2sv5_dai_type = { 1389static const struct samsung_i2s_dai_data i2sv5_dai_type = {
1311 .dai_type = TYPE_PRI, 1390 .dai_type = TYPE_PRI,
1312 .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR, 1391 .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1392 QUIRK_SUPPORTS_IDMA,
1393 .i2s_variant_regs = &i2sv3_regs,
1313}; 1394};
1314 1395
1315static const struct samsung_i2s_dai_data i2sv6_dai_type = { 1396static const struct samsung_i2s_dai_data i2sv6_dai_type = {
1316 .dai_type = TYPE_PRI, 1397 .dai_type = TYPE_PRI,
1317 .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR | 1398 .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1399 QUIRK_SUPPORTS_TDM | QUIRK_SUPPORTS_IDMA,
1400 .i2s_variant_regs = &i2sv6_regs,
1401};
1402
1403static const struct samsung_i2s_dai_data i2sv7_dai_type = {
1404 .dai_type = TYPE_PRI,
1405 .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
1318 QUIRK_SUPPORTS_TDM, 1406 QUIRK_SUPPORTS_TDM,
1407 .i2s_variant_regs = &i2sv7_regs,
1408};
1409
1410static const struct samsung_i2s_dai_data i2sv5_dai_type_i2s1 = {
1411 .dai_type = TYPE_PRI,
1412 .quirks = QUIRK_PRI_6CHAN | QUIRK_NEED_RSTCLR,
1413 .i2s_variant_regs = &i2sv5_i2s1_regs,
1319}; 1414};
1320 1415
1321static const struct samsung_i2s_dai_data samsung_dai_type_pri = { 1416static const struct samsung_i2s_dai_data samsung_dai_type_pri = {
@@ -1329,10 +1424,13 @@ static const struct samsung_i2s_dai_data samsung_dai_type_sec = {
1329static struct platform_device_id samsung_i2s_driver_ids[] = { 1424static struct platform_device_id samsung_i2s_driver_ids[] = {
1330 { 1425 {
1331 .name = "samsung-i2s", 1426 .name = "samsung-i2s",
1332 .driver_data = (kernel_ulong_t)&samsung_dai_type_pri, 1427 .driver_data = (kernel_ulong_t)&i2sv3_dai_type,
1333 }, { 1428 }, {
1334 .name = "samsung-i2s-sec", 1429 .name = "samsung-i2s-sec",
1335 .driver_data = (kernel_ulong_t)&samsung_dai_type_sec, 1430 .driver_data = (kernel_ulong_t)&samsung_dai_type_sec,
1431 }, {
1432 .name = "samsung-i2sv4",
1433 .driver_data = (kernel_ulong_t)&i2sv5_dai_type,
1336 }, 1434 },
1337 {}, 1435 {},
1338}; 1436};
@@ -1349,6 +1447,12 @@ static const struct of_device_id exynos_i2s_match[] = {
1349 }, { 1447 }, {
1350 .compatible = "samsung,exynos5420-i2s", 1448 .compatible = "samsung,exynos5420-i2s",
1351 .data = &i2sv6_dai_type, 1449 .data = &i2sv6_dai_type,
1450 }, {
1451 .compatible = "samsung,exynos7-i2s",
1452 .data = &i2sv7_dai_type,
1453 }, {
1454 .compatible = "samsung,exynos7-i2s1",
1455 .data = &i2sv5_dai_type_i2s1,
1352 }, 1456 },
1353 {}, 1457 {},
1354}; 1458};
diff --git a/sound/soc/samsung/odroidx2_max98090.c b/sound/soc/samsung/odroidx2_max98090.c
index 3c8f60423e82..d7640e72cb1d 100644
--- a/sound/soc/samsung/odroidx2_max98090.c
+++ b/sound/soc/samsung/odroidx2_max98090.c
@@ -153,8 +153,8 @@ static int odroidx2_audio_remove(struct platform_device *pdev)
153 153
154 snd_soc_unregister_card(card); 154 snd_soc_unregister_card(card);
155 155
156 of_node_put((struct device_node *)odroidx2_dai[0].cpu_of_node); 156 of_node_put(odroidx2_dai[0].cpu_of_node);
157 of_node_put((struct device_node *)odroidx2_dai[0].codec_of_node); 157 of_node_put(odroidx2_dai[0].codec_of_node);
158 158
159 return 0; 159 return 0;
160} 160}
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 88e5df474ccf..8869971d7884 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -842,12 +842,9 @@ static int fsi_clk_disable(struct device *dev,
842 return -EINVAL; 842 return -EINVAL;
843 843
844 if (1 == clock->count--) { 844 if (1 == clock->count--) {
845 if (clock->xck) 845 clk_disable(clock->xck);
846 clk_disable(clock->xck); 846 clk_disable(clock->ick);
847 if (clock->ick) 847 clk_disable(clock->div);
848 clk_disable(clock->ick);
849 if (clock->div)
850 clk_disable(clock->div);
851 } 848 }
852 849
853 return 0; 850 return 0;
diff --git a/sound/soc/sh/hac.c b/sound/soc/sh/hac.c
index 0af2e4dfd139..d5f567e085ff 100644
--- a/sound/soc/sh/hac.c
+++ b/sound/soc/sh/hac.c
@@ -272,7 +272,7 @@ static const struct snd_soc_dai_ops hac_dai_ops = {
272static struct snd_soc_dai_driver sh4_hac_dai[] = { 272static struct snd_soc_dai_driver sh4_hac_dai[] = {
273{ 273{
274 .name = "hac-dai.0", 274 .name = "hac-dai.0",
275 .ac97_control = 1, 275 .bus_control = true,
276 .playback = { 276 .playback = {
277 .rates = AC97_RATES, 277 .rates = AC97_RATES,
278 .formats = AC97_FMTS, 278 .formats = AC97_FMTS,
diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c
index fc41a0e8b09f..14d1a7193469 100644
--- a/sound/soc/sh/rcar/adg.c
+++ b/sound/soc/sh/rcar/adg.c
@@ -430,7 +430,7 @@ int rsnd_adg_probe(struct platform_device *pdev,
430 adg->clk[CLKI] = devm_clk_get(dev, "clk_i"); 430 adg->clk[CLKI] = devm_clk_get(dev, "clk_i");
431 431
432 for_each_rsnd_clk(clk, adg, i) 432 for_each_rsnd_clk(clk, adg, i)
433 dev_dbg(dev, "clk %d : %p\n", i, clk); 433 dev_dbg(dev, "clk %d : %p : %ld\n", i, clk, clk_get_rate(clk));
434 434
435 rsnd_adg_ssi_clk_init(priv, adg); 435 rsnd_adg_ssi_clk_init(priv, adg);
436 436
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 70042197f9e2..75308bbc2ce8 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -349,7 +349,7 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
349 dma_name); 349 dma_name);
350 if (!dma->chan) { 350 if (!dma->chan) {
351 dev_err(dev, "can't get dma channel\n"); 351 dev_err(dev, "can't get dma channel\n");
352 return -EIO; 352 goto rsnd_dma_channel_err;
353 } 353 }
354 354
355 ret = dmaengine_slave_config(dma->chan, &cfg); 355 ret = dmaengine_slave_config(dma->chan, &cfg);
@@ -363,8 +363,15 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
363 363
364rsnd_dma_init_err: 364rsnd_dma_init_err:
365 rsnd_dma_quit(priv, dma); 365 rsnd_dma_quit(priv, dma);
366rsnd_dma_channel_err:
366 367
367 return ret; 368 /*
369 * DMA failed. try to PIO mode
370 * see
371 * rsnd_ssi_fallback()
372 * rsnd_rdai_continuance_probe()
373 */
374 return -EAGAIN;
368} 375}
369 376
370void rsnd_dma_quit(struct rsnd_priv *priv, 377void rsnd_dma_quit(struct rsnd_priv *priv,
@@ -409,9 +416,16 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod)
409({ \ 416({ \
410 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \ 417 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
411 struct device *dev = rsnd_priv_to_dev(priv); \ 418 struct device *dev = rsnd_priv_to_dev(priv); \
412 dev_dbg(dev, "%s [%d] %s\n", \ 419 u32 mask = 1 << __rsnd_mod_shift_##func; \
413 rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \ 420 u32 call = __rsnd_mod_call_##func << __rsnd_mod_shift_##func; \
414 (mod)->ops->func(mod, rdai); \ 421 int ret = 0; \
422 if ((mod->status & mask) == call) { \
423 dev_dbg(dev, "%s[%d] %s\n", \
424 rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \
425 ret = (mod)->ops->func(mod, rdai); \
426 mod->status = (mod->status & ~mask) | (~call & mask); \
427 } \
428 ret; \
415}) 429})
416 430
417#define rsnd_mod_call(mod, func, rdai...) \ 431#define rsnd_mod_call(mod, func, rdai...) \
@@ -456,6 +470,13 @@ static int rsnd_dai_connect(struct rsnd_mod *mod,
456 return 0; 470 return 0;
457} 471}
458 472
473static void rsnd_dai_disconnect(struct rsnd_mod *mod,
474 struct rsnd_dai_stream *io)
475{
476 mod->io = NULL;
477 io->mod[mod->type] = NULL;
478}
479
459int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai) 480int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
460{ 481{
461 int id = rdai - priv->rdai; 482 int id = rdai - priv->rdai;
@@ -686,6 +707,20 @@ static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
686 ret; \ 707 ret; \
687}) 708})
688 709
710#define rsnd_path_break(priv, io, type) \
711{ \
712 struct rsnd_mod *mod; \
713 int id = -1; \
714 \
715 if (rsnd_is_enable_path(io, type)) { \
716 id = rsnd_info_id(priv, io, type); \
717 if (id >= 0) { \
718 mod = rsnd_##type##_mod_get(priv, id); \
719 rsnd_dai_disconnect(mod, io); \
720 } \
721 } \
722}
723
689static int rsnd_path_init(struct rsnd_priv *priv, 724static int rsnd_path_init(struct rsnd_priv *priv,
690 struct rsnd_dai *rdai, 725 struct rsnd_dai *rdai,
691 struct rsnd_dai_stream *io) 726 struct rsnd_dai_stream *io)
@@ -934,6 +969,150 @@ static struct snd_pcm_ops rsnd_pcm_ops = {
934}; 969};
935 970
936/* 971/*
972 * snd_kcontrol
973 */
974#define kcontrol_to_cfg(kctrl) ((struct rsnd_kctrl_cfg *)kctrl->private_value)
975static int rsnd_kctrl_info(struct snd_kcontrol *kctrl,
976 struct snd_ctl_elem_info *uinfo)
977{
978 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
979
980 if (cfg->texts) {
981 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
982 uinfo->count = cfg->size;
983 uinfo->value.enumerated.items = cfg->max;
984 if (uinfo->value.enumerated.item >= cfg->max)
985 uinfo->value.enumerated.item = cfg->max - 1;
986 strlcpy(uinfo->value.enumerated.name,
987 cfg->texts[uinfo->value.enumerated.item],
988 sizeof(uinfo->value.enumerated.name));
989 } else {
990 uinfo->count = cfg->size;
991 uinfo->value.integer.min = 0;
992 uinfo->value.integer.max = cfg->max;
993 uinfo->type = (cfg->max == 1) ?
994 SNDRV_CTL_ELEM_TYPE_BOOLEAN :
995 SNDRV_CTL_ELEM_TYPE_INTEGER;
996 }
997
998 return 0;
999}
1000
1001static int rsnd_kctrl_get(struct snd_kcontrol *kctrl,
1002 struct snd_ctl_elem_value *uc)
1003{
1004 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
1005 int i;
1006
1007 for (i = 0; i < cfg->size; i++)
1008 if (cfg->texts)
1009 uc->value.enumerated.item[i] = cfg->val[i];
1010 else
1011 uc->value.integer.value[i] = cfg->val[i];
1012
1013 return 0;
1014}
1015
1016static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
1017 struct snd_ctl_elem_value *uc)
1018{
1019 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
1020 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
1021 int i, change = 0;
1022
1023 for (i = 0; i < cfg->size; i++) {
1024 if (cfg->texts) {
1025 change |= (uc->value.enumerated.item[i] != cfg->val[i]);
1026 cfg->val[i] = uc->value.enumerated.item[i];
1027 } else {
1028 change |= (uc->value.integer.value[i] != cfg->val[i]);
1029 cfg->val[i] = uc->value.integer.value[i];
1030 }
1031 }
1032
1033 if (change)
1034 cfg->update(mod);
1035
1036 return change;
1037}
1038
1039static int __rsnd_kctrl_new(struct rsnd_mod *mod,
1040 struct rsnd_dai *rdai,
1041 struct snd_soc_pcm_runtime *rtd,
1042 const unsigned char *name,
1043 struct rsnd_kctrl_cfg *cfg,
1044 void (*update)(struct rsnd_mod *mod))
1045{
1046 struct snd_card *card = rtd->card->snd_card;
1047 struct snd_kcontrol *kctrl;
1048 struct snd_kcontrol_new knew = {
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 .name = name,
1051 .info = rsnd_kctrl_info,
1052 .get = rsnd_kctrl_get,
1053 .put = rsnd_kctrl_put,
1054 .private_value = (unsigned long)cfg,
1055 };
1056 int ret;
1057
1058 kctrl = snd_ctl_new1(&knew, mod);
1059 if (!kctrl)
1060 return -ENOMEM;
1061
1062 ret = snd_ctl_add(card, kctrl);
1063 if (ret < 0)
1064 return ret;
1065
1066 cfg->update = update;
1067
1068 return 0;
1069}
1070
1071int rsnd_kctrl_new_m(struct rsnd_mod *mod,
1072 struct rsnd_dai *rdai,
1073 struct snd_soc_pcm_runtime *rtd,
1074 const unsigned char *name,
1075 void (*update)(struct rsnd_mod *mod),
1076 struct rsnd_kctrl_cfg_m *_cfg,
1077 u32 max)
1078{
1079 _cfg->cfg.max = max;
1080 _cfg->cfg.size = RSND_DVC_CHANNELS;
1081 _cfg->cfg.val = _cfg->val;
1082 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update);
1083}
1084
1085int rsnd_kctrl_new_s(struct rsnd_mod *mod,
1086 struct rsnd_dai *rdai,
1087 struct snd_soc_pcm_runtime *rtd,
1088 const unsigned char *name,
1089 void (*update)(struct rsnd_mod *mod),
1090 struct rsnd_kctrl_cfg_s *_cfg,
1091 u32 max)
1092{
1093 _cfg->cfg.max = max;
1094 _cfg->cfg.size = 1;
1095 _cfg->cfg.val = &_cfg->val;
1096 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update);
1097}
1098
1099int rsnd_kctrl_new_e(struct rsnd_mod *mod,
1100 struct rsnd_dai *rdai,
1101 struct snd_soc_pcm_runtime *rtd,
1102 const unsigned char *name,
1103 struct rsnd_kctrl_cfg_s *_cfg,
1104 void (*update)(struct rsnd_mod *mod),
1105 const char * const *texts,
1106 u32 max)
1107{
1108 _cfg->cfg.max = max;
1109 _cfg->cfg.size = 1;
1110 _cfg->cfg.val = &_cfg->val;
1111 _cfg->cfg.texts = texts;
1112 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update);
1113}
1114
1115/*
937 * snd_soc_platform 1116 * snd_soc_platform
938 */ 1117 */
939 1118
@@ -976,6 +1155,49 @@ static const struct snd_soc_component_driver rsnd_soc_component = {
976 .name = "rsnd", 1155 .name = "rsnd",
977}; 1156};
978 1157
1158static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
1159 struct rsnd_dai *rdai,
1160 int is_play)
1161{
1162 struct rsnd_dai_stream *io = is_play ? &rdai->playback : &rdai->capture;
1163 int ret;
1164
1165 ret = rsnd_dai_call(probe, io, rdai);
1166 if (ret == -EAGAIN) {
1167 /*
1168 * Fallback to PIO mode
1169 */
1170
1171 /*
1172 * call "remove" for SSI/SRC/DVC
1173 * SSI will be switch to PIO mode if it was DMA mode
1174 * see
1175 * rsnd_dma_init()
1176 * rsnd_ssi_fallback()
1177 */
1178 rsnd_dai_call(remove, io, rdai);
1179
1180 /*
1181 * remove SRC/DVC from DAI,
1182 */
1183 rsnd_path_break(priv, io, src);
1184 rsnd_path_break(priv, io, dvc);
1185
1186 /*
1187 * fallback
1188 */
1189 rsnd_dai_call(fallback, io, rdai);
1190
1191 /*
1192 * retry to "probe".
1193 * DAI has SSI which is PIO mode only now.
1194 */
1195 ret = rsnd_dai_call(probe, io, rdai);
1196 }
1197
1198 return ret;
1199}
1200
979/* 1201/*
980 * rsnd probe 1202 * rsnd probe
981 */ 1203 */
@@ -1037,11 +1259,11 @@ static int rsnd_probe(struct platform_device *pdev)
1037 } 1259 }
1038 1260
1039 for_each_rsnd_dai(rdai, priv, i) { 1261 for_each_rsnd_dai(rdai, priv, i) {
1040 ret = rsnd_dai_call(probe, &rdai->playback, rdai); 1262 ret = rsnd_rdai_continuance_probe(priv, rdai, 1);
1041 if (ret) 1263 if (ret)
1042 goto exit_snd_probe; 1264 goto exit_snd_probe;
1043 1265
1044 ret = rsnd_dai_call(probe, &rdai->capture, rdai); 1266 ret = rsnd_rdai_continuance_probe(priv, rdai, 0);
1045 if (ret) 1267 if (ret)
1046 goto exit_snd_probe; 1268 goto exit_snd_probe;
1047 } 1269 }
diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c
index 3f443930c2b1..5380a4827ba7 100644
--- a/sound/soc/sh/rcar/dvc.c
+++ b/sound/soc/sh/rcar/dvc.c
@@ -11,8 +11,6 @@
11#include "rsnd.h" 11#include "rsnd.h"
12 12
13#define RSND_DVC_NAME_SIZE 16 13#define RSND_DVC_NAME_SIZE 16
14#define RSND_DVC_VOLUME_MAX 100
15#define RSND_DVC_VOLUME_NUM 2
16 14
17#define DVC_NAME "dvc" 15#define DVC_NAME "dvc"
18 16
@@ -20,8 +18,11 @@ struct rsnd_dvc {
20 struct rsnd_dvc_platform_info *info; /* rcar_snd.h */ 18 struct rsnd_dvc_platform_info *info; /* rcar_snd.h */
21 struct rsnd_mod mod; 19 struct rsnd_mod mod;
22 struct clk *clk; 20 struct clk *clk;
23 u8 volume[RSND_DVC_VOLUME_NUM]; 21 struct rsnd_kctrl_cfg_m volume;
24 u8 mute[RSND_DVC_VOLUME_NUM]; 22 struct rsnd_kctrl_cfg_m mute;
23 struct rsnd_kctrl_cfg_s ren; /* Ramp Enable */
24 struct rsnd_kctrl_cfg_s rup; /* Ramp Rate Up */
25 struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */
25}; 26};
26 27
27#define rsnd_mod_to_dvc(_mod) \ 28#define rsnd_mod_to_dvc(_mod) \
@@ -33,23 +34,87 @@ struct rsnd_dvc {
33 ((pos) = (struct rsnd_dvc *)(priv)->dvc + i); \ 34 ((pos) = (struct rsnd_dvc *)(priv)->dvc + i); \
34 i++) 35 i++)
35 36
37static const char const *dvc_ramp_rate[] = {
38 "128 dB/1 step", /* 00000 */
39 "64 dB/1 step", /* 00001 */
40 "32 dB/1 step", /* 00010 */
41 "16 dB/1 step", /* 00011 */
42 "8 dB/1 step", /* 00100 */
43 "4 dB/1 step", /* 00101 */
44 "2 dB/1 step", /* 00110 */
45 "1 dB/1 step", /* 00111 */
46 "0.5 dB/1 step", /* 01000 */
47 "0.25 dB/1 step", /* 01001 */
48 "0.125 dB/1 step", /* 01010 */
49 "0.125 dB/2 steps", /* 01011 */
50 "0.125 dB/4 steps", /* 01100 */
51 "0.125 dB/8 steps", /* 01101 */
52 "0.125 dB/16 steps", /* 01110 */
53 "0.125 dB/32 steps", /* 01111 */
54 "0.125 dB/64 steps", /* 10000 */
55 "0.125 dB/128 steps", /* 10001 */
56 "0.125 dB/256 steps", /* 10010 */
57 "0.125 dB/512 steps", /* 10011 */
58 "0.125 dB/1024 steps", /* 10100 */
59 "0.125 dB/2048 steps", /* 10101 */
60 "0.125 dB/4096 steps", /* 10110 */
61 "0.125 dB/8192 steps", /* 10111 */
62};
63
36static void rsnd_dvc_volume_update(struct rsnd_mod *mod) 64static void rsnd_dvc_volume_update(struct rsnd_mod *mod)
37{ 65{
38 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); 66 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
39 u32 max = (0x00800000 - 1); 67 u32 val[RSND_DVC_CHANNELS];
40 u32 vol[RSND_DVC_VOLUME_NUM]; 68 u32 dvucr = 0;
41 u32 mute = 0; 69 u32 mute = 0;
42 int i; 70 int i;
43 71
44 for (i = 0; i < RSND_DVC_VOLUME_NUM; i++) { 72 for (i = 0; i < dvc->mute.cfg.size; i++)
45 vol[i] = max / RSND_DVC_VOLUME_MAX * dvc->volume[i]; 73 mute |= (!!dvc->mute.cfg.val[i]) << i;
46 mute |= (!!dvc->mute[i]) << i; 74
75 /* Disable DVC Register access */
76 rsnd_mod_write(mod, DVC_DVUER, 0);
77
78 /* Enable Ramp */
79 if (dvc->ren.val) {
80 dvucr |= 0x10;
81
82 /* Digital Volume Max */
83 for (i = 0; i < RSND_DVC_CHANNELS; i++)
84 val[i] = dvc->volume.cfg.max;
85
86 rsnd_mod_write(mod, DVC_VRCTR, 0xff);
87 rsnd_mod_write(mod, DVC_VRPDR, dvc->rup.val << 8 |
88 dvc->rdown.val);
89 /*
90 * FIXME !!
91 * use scale-downed Digital Volume
92 * as Volume Ramp
93 * 7F FFFF -> 3FF
94 */
95 rsnd_mod_write(mod, DVC_VRDBR,
96 0x3ff - (dvc->volume.val[0] >> 13));
97
98 } else {
99 for (i = 0; i < RSND_DVC_CHANNELS; i++)
100 val[i] = dvc->volume.val[i];
101 }
102
103 /* Enable Digital Volume */
104 dvucr |= 0x100;
105 rsnd_mod_write(mod, DVC_VOL0R, val[0]);
106 rsnd_mod_write(mod, DVC_VOL1R, val[1]);
107
108 /* Enable Mute */
109 if (mute) {
110 dvucr |= 0x1;
111 rsnd_mod_write(mod, DVC_ZCMCR, mute);
47 } 112 }
48 113
49 rsnd_mod_write(mod, DVC_VOL0R, vol[0]); 114 rsnd_mod_write(mod, DVC_DVUCR, dvucr);
50 rsnd_mod_write(mod, DVC_VOL1R, vol[1]);
51 115
52 rsnd_mod_write(mod, DVC_ZCMCR, mute); 116 /* Enable DVC Register access */
117 rsnd_mod_write(mod, DVC_DVUER, 1);
53} 118}
54 119
55static int rsnd_dvc_probe_gen2(struct rsnd_mod *mod, 120static int rsnd_dvc_probe_gen2(struct rsnd_mod *mod,
@@ -58,7 +123,8 @@ static int rsnd_dvc_probe_gen2(struct rsnd_mod *mod,
58 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 123 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
59 struct device *dev = rsnd_priv_to_dev(priv); 124 struct device *dev = rsnd_priv_to_dev(priv);
60 125
61 dev_dbg(dev, "%s (Gen2) is probed\n", rsnd_mod_name(mod)); 126 dev_dbg(dev, "%s[%d] (Gen2) is probed\n",
127 rsnd_mod_name(mod), rsnd_mod_id(mod));
62 128
63 return 0; 129 return 0;
64} 130}
@@ -102,16 +168,11 @@ static int rsnd_dvc_init(struct rsnd_mod *dvc_mod,
102 168
103 rsnd_mod_write(dvc_mod, DVC_ADINR, rsnd_get_adinr(dvc_mod)); 169 rsnd_mod_write(dvc_mod, DVC_ADINR, rsnd_get_adinr(dvc_mod));
104 170
105 /* enable Volume / Mute */
106 rsnd_mod_write(dvc_mod, DVC_DVUCR, 0x101);
107
108 /* ch0/ch1 Volume */ 171 /* ch0/ch1 Volume */
109 rsnd_dvc_volume_update(dvc_mod); 172 rsnd_dvc_volume_update(dvc_mod);
110 173
111 rsnd_mod_write(dvc_mod, DVC_DVUIR, 0); 174 rsnd_mod_write(dvc_mod, DVC_DVUIR, 0);
112 175
113 rsnd_mod_write(dvc_mod, DVC_DVUER, 1);
114
115 rsnd_adg_set_cmd_timsel_gen2(rdai, dvc_mod, io); 176 rsnd_adg_set_cmd_timsel_gen2(rdai, dvc_mod, io);
116 177
117 return 0; 178 return 0;
@@ -143,86 +204,6 @@ static int rsnd_dvc_stop(struct rsnd_mod *mod,
143 return 0; 204 return 0;
144} 205}
145 206
146static int rsnd_dvc_volume_info(struct snd_kcontrol *kctrl,
147 struct snd_ctl_elem_info *uinfo)
148{
149 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
150 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
151 u8 *val = (u8 *)kctrl->private_value;
152
153 uinfo->count = RSND_DVC_VOLUME_NUM;
154 uinfo->value.integer.min = 0;
155
156 if (val == dvc->volume) {
157 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
158 uinfo->value.integer.max = RSND_DVC_VOLUME_MAX;
159 } else {
160 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
161 uinfo->value.integer.max = 1;
162 }
163
164 return 0;
165}
166
167static int rsnd_dvc_volume_get(struct snd_kcontrol *kctrl,
168 struct snd_ctl_elem_value *ucontrol)
169{
170 u8 *val = (u8 *)kctrl->private_value;
171 int i;
172
173 for (i = 0; i < RSND_DVC_VOLUME_NUM; i++)
174 ucontrol->value.integer.value[i] = val[i];
175
176 return 0;
177}
178
179static int rsnd_dvc_volume_put(struct snd_kcontrol *kctrl,
180 struct snd_ctl_elem_value *ucontrol)
181{
182 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
183 u8 *val = (u8 *)kctrl->private_value;
184 int i, change = 0;
185
186 for (i = 0; i < RSND_DVC_VOLUME_NUM; i++) {
187 change |= (ucontrol->value.integer.value[i] != val[i]);
188 val[i] = ucontrol->value.integer.value[i];
189 }
190
191 if (change)
192 rsnd_dvc_volume_update(mod);
193
194 return change;
195}
196
197static int __rsnd_dvc_pcm_new(struct rsnd_mod *mod,
198 struct rsnd_dai *rdai,
199 struct snd_soc_pcm_runtime *rtd,
200 const unsigned char *name,
201 u8 *private)
202{
203 struct snd_card *card = rtd->card->snd_card;
204 struct snd_kcontrol *kctrl;
205 struct snd_kcontrol_new knew = {
206 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
207 .name = name,
208 .info = rsnd_dvc_volume_info,
209 .get = rsnd_dvc_volume_get,
210 .put = rsnd_dvc_volume_put,
211 .private_value = (unsigned long)private,
212 };
213 int ret;
214
215 kctrl = snd_ctl_new1(&knew, mod);
216 if (!kctrl)
217 return -ENOMEM;
218
219 ret = snd_ctl_add(card, kctrl);
220 if (ret < 0)
221 return ret;
222
223 return 0;
224}
225
226static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, 207static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
227 struct rsnd_dai *rdai, 208 struct rsnd_dai *rdai,
228 struct snd_soc_pcm_runtime *rtd) 209 struct snd_soc_pcm_runtime *rtd)
@@ -232,18 +213,48 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
232 int ret; 213 int ret;
233 214
234 /* Volume */ 215 /* Volume */
235 ret = __rsnd_dvc_pcm_new(mod, rdai, rtd, 216 ret = rsnd_kctrl_new_m(mod, rdai, rtd,
236 rsnd_dai_is_play(rdai, io) ? 217 rsnd_dai_is_play(rdai, io) ?
237 "DVC Out Playback Volume" : "DVC In Capture Volume", 218 "DVC Out Playback Volume" : "DVC In Capture Volume",
238 dvc->volume); 219 rsnd_dvc_volume_update,
220 &dvc->volume, 0x00800000 - 1);
239 if (ret < 0) 221 if (ret < 0)
240 return ret; 222 return ret;
241 223
242 /* Mute */ 224 /* Mute */
243 ret = __rsnd_dvc_pcm_new(mod, rdai, rtd, 225 ret = rsnd_kctrl_new_m(mod, rdai, rtd,
244 rsnd_dai_is_play(rdai, io) ? 226 rsnd_dai_is_play(rdai, io) ?
245 "DVC Out Mute Switch" : "DVC In Mute Switch", 227 "DVC Out Mute Switch" : "DVC In Mute Switch",
246 dvc->mute); 228 rsnd_dvc_volume_update,
229 &dvc->mute, 1);
230 if (ret < 0)
231 return ret;
232
233 /* Ramp */
234 ret = rsnd_kctrl_new_s(mod, rdai, rtd,
235 rsnd_dai_is_play(rdai, io) ?
236 "DVC Out Ramp Switch" : "DVC In Ramp Switch",
237 rsnd_dvc_volume_update,
238 &dvc->ren, 1);
239 if (ret < 0)
240 return ret;
241
242 ret = rsnd_kctrl_new_e(mod, rdai, rtd,
243 rsnd_dai_is_play(rdai, io) ?
244 "DVC Out Ramp Up Rate" : "DVC In Ramp Up Rate",
245 &dvc->rup,
246 rsnd_dvc_volume_update,
247 dvc_ramp_rate, ARRAY_SIZE(dvc_ramp_rate));
248 if (ret < 0)
249 return ret;
250
251 ret = rsnd_kctrl_new_e(mod, rdai, rtd,
252 rsnd_dai_is_play(rdai, io) ?
253 "DVC Out Ramp Down Rate" : "DVC In Ramp Down Rate",
254 &dvc->rdown,
255 rsnd_dvc_volume_update,
256 dvc_ramp_rate, ARRAY_SIZE(dvc_ramp_rate));
257
247 if (ret < 0) 258 if (ret < 0)
248 return ret; 259 return ret;
249 260
diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c
index f95e7ab135e8..87a6f2d62775 100644
--- a/sound/soc/sh/rcar/gen.c
+++ b/sound/soc/sh/rcar/gen.c
@@ -8,6 +8,17 @@
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
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11
12/*
13 * #define DEBUG
14 *
15 * you can also add below in
16 * ${LINUX}/drivers/base/regmap/regmap.c
17 * for regmap debug
18 *
19 * #define LOG_DEVICE "xxxx.rcar_sound"
20 */
21
11#include "rsnd.h" 22#include "rsnd.h"
12 23
13struct rsnd_gen { 24struct rsnd_gen {
@@ -67,9 +78,10 @@ u32 rsnd_read(struct rsnd_priv *priv,
67 if (!rsnd_is_accessible_reg(priv, gen, reg)) 78 if (!rsnd_is_accessible_reg(priv, gen, reg))
68 return 0; 79 return 0;
69 80
70 regmap_fields_read(gen->regs[reg], rsnd_mod_id(mod), &val); 81 dev_dbg(dev, "r %s[%d] - %4d : %08x\n",
82 rsnd_mod_name(mod), rsnd_mod_id(mod), reg, val);
71 83
72 dev_dbg(dev, "r %s - 0x%04d : %08x\n", rsnd_mod_name(mod), reg, val); 84 regmap_fields_read(gen->regs[reg], rsnd_mod_id(mod), &val);
73 85
74 return val; 86 return val;
75} 87}
@@ -84,9 +96,10 @@ void rsnd_write(struct rsnd_priv *priv,
84 if (!rsnd_is_accessible_reg(priv, gen, reg)) 96 if (!rsnd_is_accessible_reg(priv, gen, reg))
85 return; 97 return;
86 98
87 regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data); 99 dev_dbg(dev, "w %s[%d] - %4d : %08x\n",
100 rsnd_mod_name(mod), rsnd_mod_id(mod), reg, data);
88 101
89 dev_dbg(dev, "w %s - 0x%04d : %08x\n", rsnd_mod_name(mod), reg, data); 102 regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data);
90} 103}
91 104
92void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, 105void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod,
@@ -98,11 +111,11 @@ void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod,
98 if (!rsnd_is_accessible_reg(priv, gen, reg)) 111 if (!rsnd_is_accessible_reg(priv, gen, reg))
99 return; 112 return;
100 113
114 dev_dbg(dev, "b %s[%d] - %4d : %08x/%08x\n",
115 rsnd_mod_name(mod), rsnd_mod_id(mod), reg, data, mask);
116
101 regmap_fields_update_bits(gen->regs[reg], rsnd_mod_id(mod), 117 regmap_fields_update_bits(gen->regs[reg], rsnd_mod_id(mod),
102 mask, data); 118 mask, data);
103
104 dev_dbg(dev, "b %s - 0x%04d : %08x/%08x\n",
105 rsnd_mod_name(mod), reg, data, mask);
106} 119}
107 120
108#define rsnd_gen_regmap_init(priv, id_size, reg_id, conf) \ 121#define rsnd_gen_regmap_init(priv, id_size, reg_id, conf) \
@@ -311,6 +324,9 @@ static int rsnd_gen2_probe(struct platform_device *pdev,
311 RSND_GEN_M_REG(DVC_ADINR, 0xe08, 0x100), 324 RSND_GEN_M_REG(DVC_ADINR, 0xe08, 0x100),
312 RSND_GEN_M_REG(DVC_DVUCR, 0xe10, 0x100), 325 RSND_GEN_M_REG(DVC_DVUCR, 0xe10, 0x100),
313 RSND_GEN_M_REG(DVC_ZCMCR, 0xe14, 0x100), 326 RSND_GEN_M_REG(DVC_ZCMCR, 0xe14, 0x100),
327 RSND_GEN_M_REG(DVC_VRCTR, 0xe18, 0x100),
328 RSND_GEN_M_REG(DVC_VRPDR, 0xe1c, 0x100),
329 RSND_GEN_M_REG(DVC_VRDBR, 0xe20, 0x100),
314 RSND_GEN_M_REG(DVC_VOL0R, 0xe28, 0x100), 330 RSND_GEN_M_REG(DVC_VOL0R, 0xe28, 0x100),
315 RSND_GEN_M_REG(DVC_VOL1R, 0xe2c, 0x100), 331 RSND_GEN_M_REG(DVC_VOL1R, 0xe2c, 0x100),
316 RSND_GEN_M_REG(DVC_DVUER, 0xe48, 0x100), 332 RSND_GEN_M_REG(DVC_DVUER, 0xe48, 0x100),
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h
index d119adf97c9c..5826c8abf794 100644
--- a/sound/soc/sh/rcar/rsnd.h
+++ b/sound/soc/sh/rcar/rsnd.h
@@ -91,6 +91,9 @@ enum rsnd_reg {
91 RSND_REG_SHARE20, 91 RSND_REG_SHARE20,
92 RSND_REG_SHARE21, 92 RSND_REG_SHARE21,
93 RSND_REG_SHARE22, 93 RSND_REG_SHARE22,
94 RSND_REG_SHARE23,
95 RSND_REG_SHARE24,
96 RSND_REG_SHARE25,
94 97
95 RSND_REG_MAX, 98 RSND_REG_MAX,
96}; 99};
@@ -129,6 +132,9 @@ enum rsnd_reg {
129#define RSND_REG_CMD_CTRL RSND_REG_SHARE20 132#define RSND_REG_CMD_CTRL RSND_REG_SHARE20
130#define RSND_REG_CMDOUT_TIMSEL RSND_REG_SHARE21 133#define RSND_REG_CMDOUT_TIMSEL RSND_REG_SHARE21
131#define RSND_REG_BUSIF_DALIGN RSND_REG_SHARE22 134#define RSND_REG_BUSIF_DALIGN RSND_REG_SHARE22
135#define RSND_REG_DVC_VRCTR RSND_REG_SHARE23
136#define RSND_REG_DVC_VRPDR RSND_REG_SHARE24
137#define RSND_REG_DVC_VRDBR RSND_REG_SHARE25
132 138
133struct rsnd_of_data; 139struct rsnd_of_data;
134struct rsnd_priv; 140struct rsnd_priv;
@@ -200,6 +206,8 @@ struct rsnd_mod_ops {
200 int (*pcm_new)(struct rsnd_mod *mod, 206 int (*pcm_new)(struct rsnd_mod *mod,
201 struct rsnd_dai *rdai, 207 struct rsnd_dai *rdai,
202 struct snd_soc_pcm_runtime *rtd); 208 struct snd_soc_pcm_runtime *rtd);
209 int (*fallback)(struct rsnd_mod *mod,
210 struct rsnd_dai *rdai);
203}; 211};
204 212
205struct rsnd_dai_stream; 213struct rsnd_dai_stream;
@@ -210,7 +218,35 @@ struct rsnd_mod {
210 struct rsnd_mod_ops *ops; 218 struct rsnd_mod_ops *ops;
211 struct rsnd_dma dma; 219 struct rsnd_dma dma;
212 struct rsnd_dai_stream *io; 220 struct rsnd_dai_stream *io;
221 u32 status;
213}; 222};
223/*
224 * status
225 *
226 * bit
227 * 0 0: probe 1: remove
228 * 1 0: init 1: quit
229 * 2 0: start 1: stop
230 * 3 0: pcm_new
231 * 4 0: fallback
232 */
233#define __rsnd_mod_shift_probe 0
234#define __rsnd_mod_shift_remove 0
235#define __rsnd_mod_shift_init 1
236#define __rsnd_mod_shift_quit 1
237#define __rsnd_mod_shift_start 2
238#define __rsnd_mod_shift_stop 2
239#define __rsnd_mod_shift_pcm_new 3
240#define __rsnd_mod_shift_fallback 4
241
242#define __rsnd_mod_call_probe 0
243#define __rsnd_mod_call_remove 1
244#define __rsnd_mod_call_init 0
245#define __rsnd_mod_call_quit 1
246#define __rsnd_mod_call_start 0
247#define __rsnd_mod_call_stop 1
248#define __rsnd_mod_call_pcm_new 0
249#define __rsnd_mod_call_fallback 0
214 250
215#define rsnd_mod_to_priv(mod) ((mod)->priv) 251#define rsnd_mod_to_priv(mod) ((mod)->priv)
216#define rsnd_mod_to_dma(mod) (&(mod)->dma) 252#define rsnd_mod_to_dma(mod) (&(mod)->dma)
@@ -267,7 +303,8 @@ struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
267int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io); 303int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
268int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai); 304int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
269#define rsnd_dai_get_platform_info(rdai) ((rdai)->info) 305#define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
270#define rsnd_io_to_runtime(io) ((io)->substream->runtime) 306#define rsnd_io_to_runtime(io) ((io)->substream ? \
307 (io)->substream->runtime : NULL)
271 308
272void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt); 309void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
273int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional); 310int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
@@ -382,6 +419,51 @@ struct rsnd_priv {
382}) 419})
383 420
384/* 421/*
422 * rsnd_kctrl
423 */
424struct rsnd_kctrl_cfg {
425 unsigned int max;
426 unsigned int size;
427 u32 *val;
428 const char * const *texts;
429 void (*update)(struct rsnd_mod *mod);
430};
431
432#define RSND_DVC_CHANNELS 2
433struct rsnd_kctrl_cfg_m {
434 struct rsnd_kctrl_cfg cfg;
435 u32 val[RSND_DVC_CHANNELS];
436};
437
438struct rsnd_kctrl_cfg_s {
439 struct rsnd_kctrl_cfg cfg;
440 u32 val;
441};
442
443int rsnd_kctrl_new_m(struct rsnd_mod *mod,
444 struct rsnd_dai *rdai,
445 struct snd_soc_pcm_runtime *rtd,
446 const unsigned char *name,
447 void (*update)(struct rsnd_mod *mod),
448 struct rsnd_kctrl_cfg_m *_cfg,
449 u32 max);
450int rsnd_kctrl_new_s(struct rsnd_mod *mod,
451 struct rsnd_dai *rdai,
452 struct snd_soc_pcm_runtime *rtd,
453 const unsigned char *name,
454 void (*update)(struct rsnd_mod *mod),
455 struct rsnd_kctrl_cfg_s *_cfg,
456 u32 max);
457int rsnd_kctrl_new_e(struct rsnd_mod *mod,
458 struct rsnd_dai *rdai,
459 struct snd_soc_pcm_runtime *rtd,
460 const unsigned char *name,
461 struct rsnd_kctrl_cfg_s *_cfg,
462 void (*update)(struct rsnd_mod *mod),
463 const char * const *texts,
464 u32 max);
465
466/*
385 * R-Car SRC 467 * R-Car SRC
386 */ 468 */
387int rsnd_src_probe(struct platform_device *pdev, 469int rsnd_src_probe(struct platform_device *pdev,
@@ -395,10 +477,11 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
395 struct rsnd_dai *rdai, 477 struct rsnd_dai *rdai,
396 int use_busif); 478 int use_busif);
397int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod, 479int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
398 struct rsnd_dai *rdai, 480 struct rsnd_dai *rdai);
399 int use_busif); 481int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod,
400int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod,
401 struct rsnd_dai *rdai); 482 struct rsnd_dai *rdai);
483int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod,
484 struct rsnd_dai *rdai);
402 485
403#define rsnd_src_nr(priv) ((priv)->src_nr) 486#define rsnd_src_nr(priv) ((priv)->src_nr)
404 487
@@ -410,6 +493,7 @@ int rsnd_ssi_probe(struct platform_device *pdev,
410 struct rsnd_priv *priv); 493 struct rsnd_priv *priv);
411struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id); 494struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
412int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod); 495int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
496int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod);
413 497
414/* 498/*
415 * R-Car DVC 499 * R-Car DVC
diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c
index 9183e0145503..eede3ac6eed2 100644
--- a/sound/soc/sh/rcar/src.c
+++ b/sound/soc/sh/rcar/src.c
@@ -175,30 +175,47 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
175} 175}
176 176
177int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod, 177int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
178 struct rsnd_dai *rdai, 178 struct rsnd_dai *rdai)
179 int use_busif)
180{ 179{
181 /* 180 /*
182 * DMA settings for SSIU 181 * DMA settings for SSIU
183 */ 182 */
184 if (use_busif) 183 rsnd_mod_write(ssi_mod, SSI_CTRL, 0);
185 rsnd_mod_write(ssi_mod, SSI_CTRL, 0);
186 184
187 return 0; 185 return 0;
188} 186}
189 187
190int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod, 188int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod,
191 struct rsnd_dai *rdai) 189 struct rsnd_dai *rdai)
192{ 190{
193 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); 191 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
194 192
195 /* enable PIO interrupt if Gen2 */ 193 if (rsnd_is_gen1(priv))
196 if (rsnd_is_gen2(priv)) 194 return 0;
195
196 /* enable SSI interrupt if Gen2 */
197 if (rsnd_ssi_is_dma_mode(ssi_mod))
198 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0e000000);
199 else
197 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000); 200 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000);
198 201
199 return 0; 202 return 0;
200} 203}
201 204
205int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod,
206 struct rsnd_dai *rdai)
207{
208 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
209
210 if (rsnd_is_gen1(priv))
211 return 0;
212
213 /* disable SSI interrupt if Gen2 */
214 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x00000000);
215
216 return 0;
217}
218
202unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, 219unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
203 struct rsnd_dai_stream *io, 220 struct rsnd_dai_stream *io,
204 struct snd_pcm_runtime *runtime) 221 struct snd_pcm_runtime *runtime)
@@ -239,12 +256,6 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
239 rsnd_mod_write(mod, SRC_SWRSR, 0); 256 rsnd_mod_write(mod, SRC_SWRSR, 0);
240 rsnd_mod_write(mod, SRC_SWRSR, 1); 257 rsnd_mod_write(mod, SRC_SWRSR, 1);
241 258
242 /*
243 * Initialize the operation of the SRC internal circuits
244 * see rsnd_src_start()
245 */
246 rsnd_mod_write(mod, SRC_SRCIR, 1);
247
248 /* Set channel number and output bit length */ 259 /* Set channel number and output bit length */
249 rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod)); 260 rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod));
250 261
@@ -269,6 +280,12 @@ static int rsnd_src_init(struct rsnd_mod *mod,
269 280
270 clk_prepare_enable(src->clk); 281 clk_prepare_enable(src->clk);
271 282
283 /*
284 * Initialize the operation of the SRC internal circuits
285 * see rsnd_src_start()
286 */
287 rsnd_mod_write(mod, SRC_SRCIR, 1);
288
272 return 0; 289 return 0;
273} 290}
274 291
@@ -282,32 +299,20 @@ static int rsnd_src_quit(struct rsnd_mod *mod,
282 return 0; 299 return 0;
283} 300}
284 301
285static int rsnd_src_start(struct rsnd_mod *mod, 302static int rsnd_src_start(struct rsnd_mod *mod)
286 struct rsnd_dai *rdai)
287{ 303{
288 struct rsnd_src *src = rsnd_mod_to_src(mod);
289
290 /* 304 /*
291 * Cancel the initialization and operate the SRC function 305 * Cancel the initialization and operate the SRC function
292 * see rsnd_src_set_convert_rate() 306 * see rsnd_src_init()
293 */ 307 */
294 rsnd_mod_write(mod, SRC_SRCIR, 0); 308 rsnd_mod_write(mod, SRC_SRCIR, 0);
295 309
296 if (rsnd_src_convert_rate(src))
297 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
298
299 return 0; 310 return 0;
300} 311}
301 312
302 313static int rsnd_src_stop(struct rsnd_mod *mod)
303static int rsnd_src_stop(struct rsnd_mod *mod,
304 struct rsnd_dai *rdai)
305{ 314{
306 struct rsnd_src *src = rsnd_mod_to_src(mod); 315 /* nothing to do */
307
308 if (rsnd_src_convert_rate(src))
309 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0);
310
311 return 0; 316 return 0;
312} 317}
313 318
@@ -414,6 +419,7 @@ static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod,
414static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod, 419static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
415 struct rsnd_dai *rdai) 420 struct rsnd_dai *rdai)
416{ 421{
422 struct rsnd_src *src = rsnd_mod_to_src(mod);
417 int ret; 423 int ret;
418 424
419 ret = rsnd_src_set_convert_rate(mod, rdai); 425 ret = rsnd_src_set_convert_rate(mod, rdai);
@@ -427,6 +433,10 @@ static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
427 rsnd_mod_write(mod, SRC_MNFSR, 433 rsnd_mod_write(mod, SRC_MNFSR,
428 rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); 434 rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
429 435
436 /* Gen1/Gen2 are not compatible */
437 if (rsnd_src_convert_rate(src))
438 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
439
430 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ 440 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
431 441
432 return 0; 442 return 0;
@@ -438,7 +448,8 @@ static int rsnd_src_probe_gen1(struct rsnd_mod *mod,
438 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 448 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
439 struct device *dev = rsnd_priv_to_dev(priv); 449 struct device *dev = rsnd_priv_to_dev(priv);
440 450
441 dev_dbg(dev, "%s (Gen1) is probed\n", rsnd_mod_name(mod)); 451 dev_dbg(dev, "%s[%d] (Gen1) is probed\n",
452 rsnd_mod_name(mod), rsnd_mod_id(mod));
442 453
443 return 0; 454 return 0;
444} 455}
@@ -474,7 +485,7 @@ static int rsnd_src_start_gen1(struct rsnd_mod *mod,
474 485
475 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); 486 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id));
476 487
477 return rsnd_src_start(mod, rdai); 488 return rsnd_src_start(mod);
478} 489}
479 490
480static int rsnd_src_stop_gen1(struct rsnd_mod *mod, 491static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
@@ -484,7 +495,7 @@ static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
484 495
485 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); 496 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0);
486 497
487 return rsnd_src_stop(mod, rdai); 498 return rsnd_src_stop(mod);
488} 499}
489 500
490static struct rsnd_mod_ops rsnd_src_gen1_ops = { 501static struct rsnd_mod_ops rsnd_src_gen1_ops = {
@@ -507,16 +518,17 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
507 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 518 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
508 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 519 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
509 struct rsnd_src *src = rsnd_mod_to_src(mod); 520 struct rsnd_src *src = rsnd_mod_to_src(mod);
521 u32 convert_rate = rsnd_src_convert_rate(src);
510 uint ratio; 522 uint ratio;
511 int ret; 523 int ret;
512 524
513 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ 525 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */
514 if (!rsnd_src_convert_rate(src)) 526 if (!convert_rate)
515 ratio = 0; 527 ratio = 0;
516 else if (rsnd_src_convert_rate(src) > runtime->rate) 528 else if (convert_rate > runtime->rate)
517 ratio = 100 * rsnd_src_convert_rate(src) / runtime->rate; 529 ratio = 100 * convert_rate / runtime->rate;
518 else 530 else
519 ratio = 100 * runtime->rate / rsnd_src_convert_rate(src); 531 ratio = 100 * runtime->rate / convert_rate;
520 532
521 if (ratio > 600) { 533 if (ratio > 600) {
522 dev_err(dev, "FSO/FSI ratio error\n"); 534 dev_err(dev, "FSO/FSI ratio error\n");
@@ -529,6 +541,11 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
529 541
530 rsnd_mod_write(mod, SRC_SRCCR, 0x00011110); 542 rsnd_mod_write(mod, SRC_SRCCR, 0x00011110);
531 543
544 if (convert_rate) {
545 /* Gen1/Gen2 are not compatible */
546 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
547 }
548
532 switch (rsnd_mod_id(mod)) { 549 switch (rsnd_mod_id(mod)) {
533 case 5: 550 case 5:
534 case 6: 551 case 6:
@@ -578,9 +595,11 @@ static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
578 rsnd_info_is_playback(priv, src), 595 rsnd_info_is_playback(priv, src),
579 src->info->dma_id); 596 src->info->dma_id);
580 if (ret < 0) 597 if (ret < 0)
581 dev_err(dev, "SRC DMA failed\n"); 598 dev_err(dev, "%s[%d] (Gen2) failed\n",
582 599 rsnd_mod_name(mod), rsnd_mod_id(mod));
583 dev_dbg(dev, "%s (Gen2) is probed\n", rsnd_mod_name(mod)); 600 else
601 dev_dbg(dev, "%s[%d] (Gen2) is probed\n",
602 rsnd_mod_name(mod), rsnd_mod_id(mod));
584 603
585 return ret; 604 return ret;
586} 605}
@@ -624,7 +643,7 @@ static int rsnd_src_start_gen2(struct rsnd_mod *mod,
624 643
625 rsnd_mod_write(mod, SRC_CTRL, val); 644 rsnd_mod_write(mod, SRC_CTRL, val);
626 645
627 return rsnd_src_start(mod, rdai); 646 return rsnd_src_start(mod);
628} 647}
629 648
630static int rsnd_src_stop_gen2(struct rsnd_mod *mod, 649static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
@@ -636,7 +655,7 @@ static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
636 655
637 rsnd_dma_stop(rsnd_mod_to_dma(&src->mod)); 656 rsnd_dma_stop(rsnd_mod_to_dma(&src->mod));
638 657
639 return rsnd_src_stop(mod, rdai); 658 return rsnd_src_stop(mod);
640} 659}
641 660
642static struct rsnd_mod_ops rsnd_src_gen2_ops = { 661static struct rsnd_mod_ops rsnd_src_gen2_ops = {
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c
index 34e84009162b..3844fbef4664 100644
--- a/sound/soc/sh/rcar/ssi.c
+++ b/sound/soc/sh/rcar/ssi.c
@@ -68,7 +68,6 @@ struct rsnd_ssi {
68 struct rsnd_dai *rdai; 68 struct rsnd_dai *rdai;
69 u32 cr_own; 69 u32 cr_own;
70 u32 cr_clk; 70 u32 cr_clk;
71 u32 cr_etc;
72 int err; 71 int err;
73 unsigned int usrcnt; 72 unsigned int usrcnt;
74 unsigned int rate; 73 unsigned int rate;
@@ -83,7 +82,7 @@ struct rsnd_ssi {
83#define rsnd_ssi_nr(priv) ((priv)->ssi_nr) 82#define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
84#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod) 83#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
85#define rsnd_dma_to_ssi(dma) rsnd_mod_to_ssi(rsnd_dma_to_mod(dma)) 84#define rsnd_dma_to_ssi(dma) rsnd_mod_to_ssi(rsnd_dma_to_mod(dma))
86#define rsnd_ssi_pio_available(ssi) ((ssi)->info->pio_irq > 0) 85#define rsnd_ssi_pio_available(ssi) ((ssi)->info->irq > 0)
87#define rsnd_ssi_dma_available(ssi) \ 86#define rsnd_ssi_dma_available(ssi) \
88 rsnd_dma_available(rsnd_mod_to_dma(&(ssi)->mod)) 87 rsnd_dma_available(rsnd_mod_to_dma(&(ssi)->mod))
89#define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent) 88#define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent)
@@ -96,6 +95,9 @@ static int rsnd_ssi_use_busif(struct rsnd_mod *mod)
96 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 95 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
97 int use_busif = 0; 96 int use_busif = 0;
98 97
98 if (!rsnd_ssi_is_dma_mode(mod))
99 return 0;
100
99 if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF)) 101 if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF))
100 use_busif = 1; 102 use_busif = 1;
101 if (rsnd_io_to_mod_src(io)) 103 if (rsnd_io_to_mod_src(io))
@@ -159,7 +161,8 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
159 ssi->cr_clk = FORCE | SWL_32 | 161 ssi->cr_clk = FORCE | SWL_32 |
160 SCKD | SWSD | CKDV(j); 162 SCKD | SWSD | CKDV(j);
161 163
162 dev_dbg(dev, "ssi%d outputs %u Hz\n", 164 dev_dbg(dev, "%s[%d] outputs %u Hz\n",
165 rsnd_mod_name(&ssi->mod),
163 rsnd_mod_id(&ssi->mod), rate); 166 rsnd_mod_id(&ssi->mod), rate);
164 167
165 return 0; 168 return 0;
@@ -184,6 +187,7 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
184{ 187{
185 struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod); 188 struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
186 struct device *dev = rsnd_priv_to_dev(priv); 189 struct device *dev = rsnd_priv_to_dev(priv);
190 u32 cr_mode;
187 u32 cr; 191 u32 cr;
188 192
189 if (0 == ssi->usrcnt) { 193 if (0 == ssi->usrcnt) {
@@ -197,16 +201,29 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
197 } 201 }
198 } 202 }
199 203
204 cr_mode = rsnd_ssi_is_dma_mode(&ssi->mod) ?
205 DMEN : /* DMA : enable DMA */
206 DIEN; /* PIO : enable Data interrupt */
207
208
200 cr = ssi->cr_own | 209 cr = ssi->cr_own |
201 ssi->cr_clk | 210 ssi->cr_clk |
202 ssi->cr_etc | 211 cr_mode |
203 EN; 212 UIEN | OIEN | EN;
204 213
205 rsnd_mod_write(&ssi->mod, SSICR, cr); 214 rsnd_mod_write(&ssi->mod, SSICR, cr);
206 215
216 /* enable WS continue */
217 if (rsnd_dai_is_clk_master(rdai))
218 rsnd_mod_write(&ssi->mod, SSIWSR, CONT);
219
220 /* clear error status */
221 rsnd_mod_write(&ssi->mod, SSISR, 0);
222
207 ssi->usrcnt++; 223 ssi->usrcnt++;
208 224
209 dev_dbg(dev, "ssi%d hw started\n", rsnd_mod_id(&ssi->mod)); 225 dev_dbg(dev, "%s[%d] hw started\n",
226 rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod));
210} 227}
211 228
212static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi, 229static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi,
@@ -249,7 +266,8 @@ static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi,
249 clk_disable_unprepare(ssi->clk); 266 clk_disable_unprepare(ssi->clk);
250 } 267 }
251 268
252 dev_dbg(dev, "ssi%d hw stopped\n", rsnd_mod_id(&ssi->mod)); 269 dev_dbg(dev, "%s[%d] hw stopped\n",
270 rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod));
253} 271}
254 272
255/* 273/*
@@ -334,25 +352,54 @@ static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status)
334 } 352 }
335} 353}
336 354
337/* 355static int rsnd_ssi_start(struct rsnd_mod *mod,
338 * SSI PIO 356 struct rsnd_dai *rdai)
339 */ 357{
340static irqreturn_t rsnd_ssi_pio_interrupt(int irq, void *data) 358 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
359 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
360
361 rsnd_src_ssiu_start(mod, rdai, rsnd_ssi_use_busif(mod));
362
363 rsnd_ssi_hw_start(ssi, rdai, io);
364
365 rsnd_src_ssi_irq_enable(mod, rdai);
366
367 return 0;
368}
369
370static int rsnd_ssi_stop(struct rsnd_mod *mod,
371 struct rsnd_dai *rdai)
372{
373 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
374
375 rsnd_src_ssi_irq_disable(mod, rdai);
376
377 rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR));
378
379 rsnd_ssi_hw_stop(ssi, rdai);
380
381 rsnd_src_ssiu_stop(mod, rdai);
382
383 return 0;
384}
385
386static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
341{ 387{
342 struct rsnd_ssi *ssi = data; 388 struct rsnd_ssi *ssi = data;
389 struct rsnd_dai *rdai = ssi->rdai;
343 struct rsnd_mod *mod = &ssi->mod; 390 struct rsnd_mod *mod = &ssi->mod;
344 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 391 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
345 u32 status = rsnd_mod_read(mod, SSISR); 392 u32 status = rsnd_mod_read(mod, SSISR);
346 irqreturn_t ret = IRQ_NONE;
347 393
348 if (io && (status & DIRQ)) { 394 if (!io)
349 struct rsnd_dai *rdai = ssi->rdai; 395 return IRQ_NONE;
396
397 /* PIO only */
398 if (status & DIRQ) {
350 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 399 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
351 u32 *buf = (u32 *)(runtime->dma_area + 400 u32 *buf = (u32 *)(runtime->dma_area +
352 rsnd_dai_pointer_offset(io, 0)); 401 rsnd_dai_pointer_offset(io, 0));
353 402
354 rsnd_ssi_record_error(ssi, status);
355
356 /* 403 /*
357 * 8/16/32 data can be assesse to TDR/RDR register 404 * 8/16/32 data can be assesse to TDR/RDR register
358 * directly as 32bit data 405 * directly as 32bit data
@@ -364,73 +411,60 @@ static irqreturn_t rsnd_ssi_pio_interrupt(int irq, void *data)
364 *buf = rsnd_mod_read(mod, SSIRDR); 411 *buf = rsnd_mod_read(mod, SSIRDR);
365 412
366 rsnd_dai_pointer_update(io, sizeof(*buf)); 413 rsnd_dai_pointer_update(io, sizeof(*buf));
414 }
415
416 /* PIO / DMA */
417 if (status & (UIRQ | OIRQ)) {
418 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
419 struct device *dev = rsnd_priv_to_dev(priv);
420
421 /*
422 * restart SSI
423 */
424 rsnd_ssi_stop(mod, rdai);
425 rsnd_ssi_start(mod, rdai);
367 426
368 ret = IRQ_HANDLED; 427 dev_dbg(dev, "%s[%d] restart\n",
428 rsnd_mod_name(mod), rsnd_mod_id(mod));
369 } 429 }
370 430
371 return ret; 431 rsnd_ssi_record_error(ssi, status);
432
433 return IRQ_HANDLED;
372} 434}
373 435
436/*
437 * SSI PIO
438 */
374static int rsnd_ssi_pio_probe(struct rsnd_mod *mod, 439static int rsnd_ssi_pio_probe(struct rsnd_mod *mod,
375 struct rsnd_dai *rdai) 440 struct rsnd_dai *rdai)
376{ 441{
377 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 442 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
378 struct device *dev = rsnd_priv_to_dev(priv); 443 struct device *dev = rsnd_priv_to_dev(priv);
379 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 444 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
380 int irq = ssi->info->pio_irq;
381 int ret; 445 int ret;
382 446
383 ret = devm_request_irq(dev, irq, 447 ret = devm_request_irq(dev, ssi->info->irq,
384 rsnd_ssi_pio_interrupt, 448 rsnd_ssi_interrupt,
385 IRQF_SHARED, 449 IRQF_SHARED,
386 dev_name(dev), ssi); 450 dev_name(dev), ssi);
387 if (ret) 451 if (ret)
388 dev_err(dev, "SSI request interrupt failed\n"); 452 dev_err(dev, "%s[%d] (PIO) request interrupt failed\n",
389 453 rsnd_mod_name(mod), rsnd_mod_id(mod));
390 dev_dbg(dev, "%s (PIO) is probed\n", rsnd_mod_name(mod)); 454 else
455 dev_dbg(dev, "%s[%d] (PIO) is probed\n",
456 rsnd_mod_name(mod), rsnd_mod_id(mod));
391 457
392 return ret; 458 return ret;
393} 459}
394 460
395static int rsnd_ssi_pio_start(struct rsnd_mod *mod,
396 struct rsnd_dai *rdai)
397{
398 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
399 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
400
401 /* enable PIO IRQ */
402 ssi->cr_etc = UIEN | OIEN | DIEN;
403
404 rsnd_src_ssiu_start(mod, rdai, 0);
405
406 rsnd_src_enable_ssi_irq(mod, rdai);
407
408 rsnd_ssi_hw_start(ssi, rdai, io);
409
410 return 0;
411}
412
413static int rsnd_ssi_pio_stop(struct rsnd_mod *mod,
414 struct rsnd_dai *rdai)
415{
416 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
417
418 ssi->cr_etc = 0;
419
420 rsnd_ssi_hw_stop(ssi, rdai);
421
422 rsnd_src_ssiu_stop(mod, rdai, 0);
423
424 return 0;
425}
426
427static struct rsnd_mod_ops rsnd_ssi_pio_ops = { 461static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
428 .name = SSI_NAME, 462 .name = SSI_NAME,
429 .probe = rsnd_ssi_pio_probe, 463 .probe = rsnd_ssi_pio_probe,
430 .init = rsnd_ssi_init, 464 .init = rsnd_ssi_init,
431 .quit = rsnd_ssi_quit, 465 .quit = rsnd_ssi_quit,
432 .start = rsnd_ssi_pio_start, 466 .start = rsnd_ssi_start,
433 .stop = rsnd_ssi_pio_stop, 467 .stop = rsnd_ssi_stop,
434}; 468};
435 469
436static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, 470static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
@@ -442,15 +476,28 @@ static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
442 int dma_id = ssi->info->dma_id; 476 int dma_id = ssi->info->dma_id;
443 int ret; 477 int ret;
444 478
479 ret = devm_request_irq(dev, ssi->info->irq,
480 rsnd_ssi_interrupt,
481 IRQF_SHARED,
482 dev_name(dev), ssi);
483 if (ret)
484 goto rsnd_ssi_dma_probe_fail;
485
445 ret = rsnd_dma_init( 486 ret = rsnd_dma_init(
446 priv, rsnd_mod_to_dma(mod), 487 priv, rsnd_mod_to_dma(mod),
447 rsnd_info_is_playback(priv, ssi), 488 rsnd_info_is_playback(priv, ssi),
448 dma_id); 489 dma_id);
490 if (ret)
491 goto rsnd_ssi_dma_probe_fail;
449 492
450 if (ret < 0) 493 dev_dbg(dev, "%s[%d] (DMA) is probed\n",
451 dev_err(dev, "SSI DMA failed\n"); 494 rsnd_mod_name(mod), rsnd_mod_id(mod));
495
496 return ret;
452 497
453 dev_dbg(dev, "%s (DMA) is probed\n", rsnd_mod_name(mod)); 498rsnd_ssi_dma_probe_fail:
499 dev_err(dev, "%s[%d] (DMA) is failed\n",
500 rsnd_mod_name(mod), rsnd_mod_id(mod));
454 501
455 return ret; 502 return ret;
456} 503}
@@ -458,30 +505,48 @@ static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
458static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, 505static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
459 struct rsnd_dai *rdai) 506 struct rsnd_dai *rdai)
460{ 507{
508 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
509 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
510 struct device *dev = rsnd_priv_to_dev(priv);
511 int irq = ssi->info->irq;
512
461 rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod)); 513 rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod));
462 514
515 /* PIO will request IRQ again */
516 devm_free_irq(dev, irq, ssi);
517
463 return 0; 518 return 0;
464} 519}
465 520
466static int rsnd_ssi_dma_start(struct rsnd_mod *mod, 521static int rsnd_ssi_fallback(struct rsnd_mod *mod,
467 struct rsnd_dai *rdai) 522 struct rsnd_dai *rdai)
468{ 523{
469 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 524 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
470 struct rsnd_dma *dma = rsnd_mod_to_dma(&ssi->mod); 525 struct device *dev = rsnd_priv_to_dev(priv);
471 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
472 526
473 /* enable DMA transfer */ 527 /*
474 ssi->cr_etc = DMEN; 528 * fallback to PIO
529 *
530 * SSI .probe might be called again.
531 * see
532 * rsnd_rdai_continuance_probe()
533 */
534 mod->ops = &rsnd_ssi_pio_ops;
475 535
476 rsnd_src_ssiu_start(mod, rdai, rsnd_ssi_use_busif(mod)); 536 dev_info(dev, "%s[%d] fallback to PIO mode\n",
537 rsnd_mod_name(mod), rsnd_mod_id(mod));
477 538
478 rsnd_dma_start(dma); 539 return 0;
540}
479 541
480 rsnd_ssi_hw_start(ssi, ssi->rdai, io); 542static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
543 struct rsnd_dai *rdai)
544{
545 struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
481 546
482 /* enable WS continue */ 547 rsnd_ssi_start(mod, rdai);
483 if (rsnd_dai_is_clk_master(rdai)) 548
484 rsnd_mod_write(&ssi->mod, SSIWSR, CONT); 549 rsnd_dma_start(dma);
485 550
486 return 0; 551 return 0;
487} 552}
@@ -489,18 +554,11 @@ static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
489static int rsnd_ssi_dma_stop(struct rsnd_mod *mod, 554static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
490 struct rsnd_dai *rdai) 555 struct rsnd_dai *rdai)
491{ 556{
492 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 557 struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
493 struct rsnd_dma *dma = rsnd_mod_to_dma(&ssi->mod);
494
495 ssi->cr_etc = 0;
496
497 rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR));
498
499 rsnd_ssi_hw_stop(ssi, rdai);
500 558
501 rsnd_dma_stop(dma); 559 rsnd_dma_stop(dma);
502 560
503 rsnd_src_ssiu_stop(mod, rdai, 1); 561 rsnd_ssi_stop(mod, rdai);
504 562
505 return 0; 563 return 0;
506} 564}
@@ -519,8 +577,15 @@ static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
519 .quit = rsnd_ssi_quit, 577 .quit = rsnd_ssi_quit,
520 .start = rsnd_ssi_dma_start, 578 .start = rsnd_ssi_dma_start,
521 .stop = rsnd_ssi_dma_stop, 579 .stop = rsnd_ssi_dma_stop,
580 .fallback = rsnd_ssi_fallback,
522}; 581};
523 582
583int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
584{
585 return mod->ops == &rsnd_ssi_dma_ops;
586}
587
588
524/* 589/*
525 * Non SSI 590 * Non SSI
526 */ 591 */
@@ -614,7 +679,7 @@ static void rsnd_of_parse_ssi(struct platform_device *pdev,
614 /* 679 /*
615 * irq 680 * irq
616 */ 681 */
617 ssi_info->pio_irq = irq_of_parse_and_map(np, 0); 682 ssi_info->irq = irq_of_parse_and_map(np, 0);
618 683
619 /* 684 /*
620 * DMA 685 * DMA
diff --git a/sound/soc/soc-ac97.c b/sound/soc/soc-ac97.c
new file mode 100644
index 000000000000..2e10e9a38376
--- /dev/null
+++ b/sound/soc/soc-ac97.c
@@ -0,0 +1,256 @@
1/*
2 * soc-ac97.c -- ALSA SoC Audio Layer AC97 support
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
8 *
9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10 * with code, comments and ideas from :-
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/ctype.h>
20#include <linux/delay.h>
21#include <linux/export.h>
22#include <linux/gpio.h>
23#include <linux/init.h>
24#include <linux/of_gpio.h>
25#include <linux/of.h>
26#include <linux/pinctrl/consumer.h>
27#include <linux/slab.h>
28#include <sound/ac97_codec.h>
29#include <sound/soc.h>
30
31struct snd_ac97_reset_cfg {
32 struct pinctrl *pctl;
33 struct pinctrl_state *pstate_reset;
34 struct pinctrl_state *pstate_warm_reset;
35 struct pinctrl_state *pstate_run;
36 int gpio_sdata;
37 int gpio_sync;
38 int gpio_reset;
39};
40
41static struct snd_ac97_bus soc_ac97_bus = {
42 .ops = NULL, /* Gets initialized in snd_soc_set_ac97_ops() */
43};
44
45static void soc_ac97_device_release(struct device *dev)
46{
47 kfree(to_ac97_t(dev));
48}
49
50/**
51 * snd_soc_new_ac97_codec - initailise AC97 device
52 * @codec: audio codec
53 *
54 * Initialises AC97 codec resources for use by ad-hoc devices only.
55 */
56struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
57{
58 struct snd_ac97 *ac97;
59 int ret;
60
61 ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
62 if (ac97 == NULL)
63 return ERR_PTR(-ENOMEM);
64
65 ac97->bus = &soc_ac97_bus;
66 ac97->num = 0;
67
68 ac97->dev.bus = &ac97_bus_type;
69 ac97->dev.parent = codec->component.card->dev;
70 ac97->dev.release = soc_ac97_device_release;
71
72 dev_set_name(&ac97->dev, "%d-%d:%s",
73 codec->component.card->snd_card->number, 0,
74 codec->component.name);
75
76 ret = device_register(&ac97->dev);
77 if (ret) {
78 put_device(&ac97->dev);
79 return ERR_PTR(ret);
80 }
81
82 return ac97;
83}
84EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
85
86/**
87 * snd_soc_free_ac97_codec - free AC97 codec device
88 * @codec: audio codec
89 *
90 * Frees AC97 codec device resources.
91 */
92void snd_soc_free_ac97_codec(struct snd_ac97 *ac97)
93{
94 device_del(&ac97->dev);
95 ac97->bus = NULL;
96 put_device(&ac97->dev);
97}
98EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
99
100static struct snd_ac97_reset_cfg snd_ac97_rst_cfg;
101
102static void snd_soc_ac97_warm_reset(struct snd_ac97 *ac97)
103{
104 struct pinctrl *pctl = snd_ac97_rst_cfg.pctl;
105
106 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_warm_reset);
107
108 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 1);
109
110 udelay(10);
111
112 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0);
113
114 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run);
115 msleep(2);
116}
117
118static void snd_soc_ac97_reset(struct snd_ac97 *ac97)
119{
120 struct pinctrl *pctl = snd_ac97_rst_cfg.pctl;
121
122 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_reset);
123
124 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0);
125 gpio_direction_output(snd_ac97_rst_cfg.gpio_sdata, 0);
126 gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 0);
127
128 udelay(10);
129
130 gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 1);
131
132 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run);
133 msleep(2);
134}
135
136static int snd_soc_ac97_parse_pinctl(struct device *dev,
137 struct snd_ac97_reset_cfg *cfg)
138{
139 struct pinctrl *p;
140 struct pinctrl_state *state;
141 int gpio;
142 int ret;
143
144 p = devm_pinctrl_get(dev);
145 if (IS_ERR(p)) {
146 dev_err(dev, "Failed to get pinctrl\n");
147 return PTR_ERR(p);
148 }
149 cfg->pctl = p;
150
151 state = pinctrl_lookup_state(p, "ac97-reset");
152 if (IS_ERR(state)) {
153 dev_err(dev, "Can't find pinctrl state ac97-reset\n");
154 return PTR_ERR(state);
155 }
156 cfg->pstate_reset = state;
157
158 state = pinctrl_lookup_state(p, "ac97-warm-reset");
159 if (IS_ERR(state)) {
160 dev_err(dev, "Can't find pinctrl state ac97-warm-reset\n");
161 return PTR_ERR(state);
162 }
163 cfg->pstate_warm_reset = state;
164
165 state = pinctrl_lookup_state(p, "ac97-running");
166 if (IS_ERR(state)) {
167 dev_err(dev, "Can't find pinctrl state ac97-running\n");
168 return PTR_ERR(state);
169 }
170 cfg->pstate_run = state;
171
172 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 0);
173 if (gpio < 0) {
174 dev_err(dev, "Can't find ac97-sync gpio\n");
175 return gpio;
176 }
177 ret = devm_gpio_request(dev, gpio, "AC97 link sync");
178 if (ret) {
179 dev_err(dev, "Failed requesting ac97-sync gpio\n");
180 return ret;
181 }
182 cfg->gpio_sync = gpio;
183
184 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 1);
185 if (gpio < 0) {
186 dev_err(dev, "Can't find ac97-sdata gpio %d\n", gpio);
187 return gpio;
188 }
189 ret = devm_gpio_request(dev, gpio, "AC97 link sdata");
190 if (ret) {
191 dev_err(dev, "Failed requesting ac97-sdata gpio\n");
192 return ret;
193 }
194 cfg->gpio_sdata = gpio;
195
196 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 2);
197 if (gpio < 0) {
198 dev_err(dev, "Can't find ac97-reset gpio\n");
199 return gpio;
200 }
201 ret = devm_gpio_request(dev, gpio, "AC97 link reset");
202 if (ret) {
203 dev_err(dev, "Failed requesting ac97-reset gpio\n");
204 return ret;
205 }
206 cfg->gpio_reset = gpio;
207
208 return 0;
209}
210
211struct snd_ac97_bus_ops *soc_ac97_ops;
212EXPORT_SYMBOL_GPL(soc_ac97_ops);
213
214int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
215{
216 if (ops == soc_ac97_ops)
217 return 0;
218
219 if (soc_ac97_ops && ops)
220 return -EBUSY;
221
222 soc_ac97_ops = ops;
223 soc_ac97_bus.ops = ops;
224
225 return 0;
226}
227EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops);
228
229/**
230 * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions
231 *
232 * This function sets the reset and warm_reset properties of ops and parses
233 * the device node of pdev to get pinctrl states and gpio numbers to use.
234 */
235int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
236 struct platform_device *pdev)
237{
238 struct device *dev = &pdev->dev;
239 struct snd_ac97_reset_cfg cfg;
240 int ret;
241
242 ret = snd_soc_ac97_parse_pinctl(dev, &cfg);
243 if (ret)
244 return ret;
245
246 ret = snd_soc_set_ac97_ops(ops);
247 if (ret)
248 return ret;
249
250 ops->warm_reset = snd_soc_ac97_warm_reset;
251 ops->reset = snd_soc_ac97_reset;
252
253 snd_ac97_rst_cfg = cfg;
254 return 0;
255}
256EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset);
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index a9f82b5aba9d..07f43356f963 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -15,56 +15,6 @@
15#include <linux/export.h> 15#include <linux/export.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17 17
18#include <trace/events/asoc.h>
19
20static bool snd_soc_set_cache_val(void *base, unsigned int idx,
21 unsigned int val, unsigned int word_size)
22{
23 switch (word_size) {
24 case 1: {
25 u8 *cache = base;
26 if (cache[idx] == val)
27 return true;
28 cache[idx] = val;
29 break;
30 }
31 case 2: {
32 u16 *cache = base;
33 if (cache[idx] == val)
34 return true;
35 cache[idx] = val;
36 break;
37 }
38 default:
39 WARN(1, "Invalid word_size %d\n", word_size);
40 break;
41 }
42 return false;
43}
44
45static unsigned int snd_soc_get_cache_val(const void *base, unsigned int idx,
46 unsigned int word_size)
47{
48 if (!base)
49 return -1;
50
51 switch (word_size) {
52 case 1: {
53 const u8 *cache = base;
54 return cache[idx];
55 }
56 case 2: {
57 const u16 *cache = base;
58 return cache[idx];
59 }
60 default:
61 WARN(1, "Invalid word_size %d\n", word_size);
62 break;
63 }
64 /* unreachable */
65 return -1;
66}
67
68int snd_soc_cache_init(struct snd_soc_codec *codec) 18int snd_soc_cache_init(struct snd_soc_codec *codec)
69{ 19{
70 const struct snd_soc_codec_driver *codec_drv = codec->driver; 20 const struct snd_soc_codec_driver *codec_drv = codec->driver;
@@ -75,8 +25,6 @@ int snd_soc_cache_init(struct snd_soc_codec *codec)
75 if (!reg_size) 25 if (!reg_size)
76 return 0; 26 return 0;
77 27
78 mutex_init(&codec->cache_rw_mutex);
79
80 dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n", 28 dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n",
81 codec->component.name); 29 codec->component.name);
82 30
@@ -103,100 +51,3 @@ int snd_soc_cache_exit(struct snd_soc_codec *codec)
103 codec->reg_cache = NULL; 51 codec->reg_cache = NULL;
104 return 0; 52 return 0;
105} 53}
106
107/**
108 * snd_soc_cache_read: Fetch the value of a given register from the cache.
109 *
110 * @codec: CODEC to configure.
111 * @reg: The register index.
112 * @value: The value to be returned.
113 */
114int snd_soc_cache_read(struct snd_soc_codec *codec,
115 unsigned int reg, unsigned int *value)
116{
117 if (!value)
118 return -EINVAL;
119
120 mutex_lock(&codec->cache_rw_mutex);
121 if (!ZERO_OR_NULL_PTR(codec->reg_cache))
122 *value = snd_soc_get_cache_val(codec->reg_cache, reg,
123 codec->driver->reg_word_size);
124 mutex_unlock(&codec->cache_rw_mutex);
125
126 return 0;
127}
128EXPORT_SYMBOL_GPL(snd_soc_cache_read);
129
130/**
131 * snd_soc_cache_write: Set the value of a given register in the cache.
132 *
133 * @codec: CODEC to configure.
134 * @reg: The register index.
135 * @value: The new register value.
136 */
137int snd_soc_cache_write(struct snd_soc_codec *codec,
138 unsigned int reg, unsigned int value)
139{
140 mutex_lock(&codec->cache_rw_mutex);
141 if (!ZERO_OR_NULL_PTR(codec->reg_cache))
142 snd_soc_set_cache_val(codec->reg_cache, reg, value,
143 codec->driver->reg_word_size);
144 mutex_unlock(&codec->cache_rw_mutex);
145
146 return 0;
147}
148EXPORT_SYMBOL_GPL(snd_soc_cache_write);
149
150static int snd_soc_flat_cache_sync(struct snd_soc_codec *codec)
151{
152 int i;
153 int ret;
154 const struct snd_soc_codec_driver *codec_drv;
155 unsigned int val;
156
157 codec_drv = codec->driver;
158 for (i = 0; i < codec_drv->reg_cache_size; ++i) {
159 ret = snd_soc_cache_read(codec, i, &val);
160 if (ret)
161 return ret;
162 if (codec_drv->reg_cache_default)
163 if (snd_soc_get_cache_val(codec_drv->reg_cache_default,
164 i, codec_drv->reg_word_size) == val)
165 continue;
166
167 ret = snd_soc_write(codec, i, val);
168 if (ret)
169 return ret;
170 dev_dbg(codec->dev, "ASoC: Synced register %#x, value = %#x\n",
171 i, val);
172 }
173 return 0;
174}
175
176/**
177 * snd_soc_cache_sync: Sync the register cache with the hardware.
178 *
179 * @codec: CODEC to configure.
180 *
181 * Any registers that should not be synced should be marked as
182 * volatile. In general drivers can choose not to use the provided
183 * syncing functionality if they so require.
184 */
185int snd_soc_cache_sync(struct snd_soc_codec *codec)
186{
187 const char *name = "flat";
188 int ret;
189
190 if (!codec->cache_sync)
191 return 0;
192
193 dev_dbg(codec->dev, "ASoC: Syncing cache for %s codec\n",
194 codec->component.name);
195 trace_snd_soc_cache_sync(codec, name, "start");
196 ret = snd_soc_flat_cache_sync(codec);
197 if (!ret)
198 codec->cache_sync = 0;
199 trace_snd_soc_cache_sync(codec, name, "end");
200 return ret;
201}
202EXPORT_SYMBOL_GPL(snd_soc_cache_sync);
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index cecfab3cc948..590a82f01d0b 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -258,10 +258,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
258 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) 258 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
259 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; 259 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
260 260
261 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 261 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
262 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
263 else
264 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
265 262
266 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; 263 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
267 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 264 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
@@ -456,11 +453,7 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
456 if (ret < 0) 453 if (ret < 0)
457 goto out; 454 goto out;
458 455
459 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 456 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
460 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
461 else
462 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
463
464 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; 457 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
465 458
466out: 459out:
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index b60ff56ebc0f..935721062c21 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -34,9 +34,6 @@
34#include <linux/ctype.h> 34#include <linux/ctype.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/of.h> 36#include <linux/of.h>
37#include <linux/gpio.h>
38#include <linux/of_gpio.h>
39#include <sound/ac97_codec.h>
40#include <sound/core.h> 37#include <sound/core.h>
41#include <sound/jack.h> 38#include <sound/jack.h>
42#include <sound/pcm.h> 39#include <sound/pcm.h>
@@ -69,16 +66,6 @@ static int pmdown_time = 5000;
69module_param(pmdown_time, int, 0); 66module_param(pmdown_time, int, 0);
70MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); 67MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
71 68
72struct snd_ac97_reset_cfg {
73 struct pinctrl *pctl;
74 struct pinctrl_state *pstate_reset;
75 struct pinctrl_state *pstate_warm_reset;
76 struct pinctrl_state *pstate_run;
77 int gpio_sdata;
78 int gpio_sync;
79 int gpio_reset;
80};
81
82/* returns the minimum number of bytes needed to represent 69/* returns the minimum number of bytes needed to represent
83 * a particular given value */ 70 * a particular given value */
84static int min_bytes_needed(unsigned long val) 71static int min_bytes_needed(unsigned long val)
@@ -309,9 +296,6 @@ static void soc_init_codec_debugfs(struct snd_soc_component *component)
309{ 296{
310 struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 297 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
311 298
312 debugfs_create_bool("cache_sync", 0444, codec->component.debugfs_root,
313 &codec->cache_sync);
314
315 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, 299 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
316 codec->component.debugfs_root, 300 codec->component.debugfs_root,
317 codec, &codec_reg_fops); 301 codec, &codec_reg_fops);
@@ -499,40 +483,6 @@ struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
499} 483}
500EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); 484EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
501 485
502#ifdef CONFIG_SND_SOC_AC97_BUS
503/* unregister ac97 codec */
504static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
505{
506 if (codec->ac97->dev.bus)
507 device_unregister(&codec->ac97->dev);
508 return 0;
509}
510
511/* stop no dev release warning */
512static void soc_ac97_device_release(struct device *dev){}
513
514/* register ac97 codec to bus */
515static int soc_ac97_dev_register(struct snd_soc_codec *codec)
516{
517 int err;
518
519 codec->ac97->dev.bus = &ac97_bus_type;
520 codec->ac97->dev.parent = codec->component.card->dev;
521 codec->ac97->dev.release = soc_ac97_device_release;
522
523 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
524 codec->component.card->snd_card->number, 0,
525 codec->component.name);
526 err = device_register(&codec->ac97->dev);
527 if (err < 0) {
528 dev_err(codec->dev, "ASoC: Can't register ac97 bus\n");
529 codec->ac97->dev.bus = NULL;
530 return err;
531 }
532 return 0;
533}
534#endif
535
536static void codec2codec_close_delayed_work(struct work_struct *work) 486static void codec2codec_close_delayed_work(struct work_struct *work)
537{ 487{
538 /* Currently nothing to do for c2c links 488 /* Currently nothing to do for c2c links
@@ -592,17 +542,12 @@ int snd_soc_suspend(struct device *dev)
592 542
593 for (i = 0; i < card->num_rtd; i++) { 543 for (i = 0; i < card->num_rtd; i++) {
594 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 544 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
595 struct snd_soc_platform *platform = card->rtd[i].platform;
596 545
597 if (card->rtd[i].dai_link->ignore_suspend) 546 if (card->rtd[i].dai_link->ignore_suspend)
598 continue; 547 continue;
599 548
600 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control) 549 if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control)
601 cpu_dai->driver->suspend(cpu_dai); 550 cpu_dai->driver->suspend(cpu_dai);
602 if (platform->driver->suspend && !platform->suspended) {
603 platform->driver->suspend(cpu_dai);
604 platform->suspended = 1;
605 }
606 } 551 }
607 552
608 /* close any waiting streams and save state */ 553 /* close any waiting streams and save state */
@@ -629,8 +574,8 @@ int snd_soc_suspend(struct device *dev)
629 SND_SOC_DAPM_STREAM_SUSPEND); 574 SND_SOC_DAPM_STREAM_SUSPEND);
630 } 575 }
631 576
632 /* Recheck all analogue paths too */ 577 /* Recheck all endpoints too, their state is affected by suspend */
633 dapm_mark_io_dirty(&card->dapm); 578 dapm_mark_endpoints_dirty(card);
634 snd_soc_dapm_sync(&card->dapm); 579 snd_soc_dapm_sync(&card->dapm);
635 580
636 /* suspend all CODECs */ 581 /* suspend all CODECs */
@@ -656,7 +601,6 @@ int snd_soc_suspend(struct device *dev)
656 if (codec->driver->suspend) 601 if (codec->driver->suspend)
657 codec->driver->suspend(codec); 602 codec->driver->suspend(codec);
658 codec->suspended = 1; 603 codec->suspended = 1;
659 codec->cache_sync = 1;
660 if (codec->component.regmap) 604 if (codec->component.regmap)
661 regcache_mark_dirty(codec->component.regmap); 605 regcache_mark_dirty(codec->component.regmap);
662 /* deactivate pins to sleep state */ 606 /* deactivate pins to sleep state */
@@ -676,7 +620,7 @@ int snd_soc_suspend(struct device *dev)
676 if (card->rtd[i].dai_link->ignore_suspend) 620 if (card->rtd[i].dai_link->ignore_suspend)
677 continue; 621 continue;
678 622
679 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) 623 if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control)
680 cpu_dai->driver->suspend(cpu_dai); 624 cpu_dai->driver->suspend(cpu_dai);
681 625
682 /* deactivate pins to sleep state */ 626 /* deactivate pins to sleep state */
@@ -712,14 +656,14 @@ static void soc_resume_deferred(struct work_struct *work)
712 if (card->resume_pre) 656 if (card->resume_pre)
713 card->resume_pre(card); 657 card->resume_pre(card);
714 658
715 /* resume AC97 DAIs */ 659 /* resume control bus DAIs */
716 for (i = 0; i < card->num_rtd; i++) { 660 for (i = 0; i < card->num_rtd; i++) {
717 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 661 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
718 662
719 if (card->rtd[i].dai_link->ignore_suspend) 663 if (card->rtd[i].dai_link->ignore_suspend)
720 continue; 664 continue;
721 665
722 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) 666 if (cpu_dai->driver->resume && cpu_dai->driver->bus_control)
723 cpu_dai->driver->resume(cpu_dai); 667 cpu_dai->driver->resume(cpu_dai);
724 } 668 }
725 669
@@ -775,17 +719,12 @@ static void soc_resume_deferred(struct work_struct *work)
775 719
776 for (i = 0; i < card->num_rtd; i++) { 720 for (i = 0; i < card->num_rtd; i++) {
777 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 721 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
778 struct snd_soc_platform *platform = card->rtd[i].platform;
779 722
780 if (card->rtd[i].dai_link->ignore_suspend) 723 if (card->rtd[i].dai_link->ignore_suspend)
781 continue; 724 continue;
782 725
783 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) 726 if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control)
784 cpu_dai->driver->resume(cpu_dai); 727 cpu_dai->driver->resume(cpu_dai);
785 if (platform->driver->resume && platform->suspended) {
786 platform->driver->resume(cpu_dai);
787 platform->suspended = 0;
788 }
789 } 728 }
790 729
791 if (card->resume_post) 730 if (card->resume_post)
@@ -796,8 +735,8 @@ static void soc_resume_deferred(struct work_struct *work)
796 /* userspace can access us now we are back as we were before */ 735 /* userspace can access us now we are back as we were before */
797 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); 736 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
798 737
799 /* Recheck all analogue paths too */ 738 /* Recheck all endpoints too, their state is affected by suspend */
800 dapm_mark_io_dirty(&card->dapm); 739 dapm_mark_endpoints_dirty(card);
801 snd_soc_dapm_sync(&card->dapm); 740 snd_soc_dapm_sync(&card->dapm);
802} 741}
803 742
@@ -805,7 +744,8 @@ static void soc_resume_deferred(struct work_struct *work)
805int snd_soc_resume(struct device *dev) 744int snd_soc_resume(struct device *dev)
806{ 745{
807 struct snd_soc_card *card = dev_get_drvdata(dev); 746 struct snd_soc_card *card = dev_get_drvdata(dev);
808 int i, ac97_control = 0; 747 bool bus_control = false;
748 int i;
809 749
810 /* If the card is not initialized yet there is nothing to do */ 750 /* If the card is not initialized yet there is nothing to do */
811 if (!card->instantiated) 751 if (!card->instantiated)
@@ -828,17 +768,18 @@ int snd_soc_resume(struct device *dev)
828 } 768 }
829 } 769 }
830 770
831 /* AC97 devices might have other drivers hanging off them so 771 /*
832 * need to resume immediately. Other drivers don't have that 772 * DAIs that also act as the control bus master might have other drivers
833 * problem and may take a substantial amount of time to resume 773 * hanging off them so need to resume immediately. Other drivers don't
774 * have that problem and may take a substantial amount of time to resume
834 * due to I/O costs and anti-pop so handle them out of line. 775 * due to I/O costs and anti-pop so handle them out of line.
835 */ 776 */
836 for (i = 0; i < card->num_rtd; i++) { 777 for (i = 0; i < card->num_rtd; i++) {
837 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 778 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
838 ac97_control |= cpu_dai->driver->ac97_control; 779 bus_control |= cpu_dai->driver->bus_control;
839 } 780 }
840 if (ac97_control) { 781 if (bus_control) {
841 dev_dbg(dev, "ASoC: Resuming AC97 immediately\n"); 782 dev_dbg(dev, "ASoC: Resuming control bus master immediately\n");
842 soc_resume_deferred(&card->deferred_resume_work); 783 soc_resume_deferred(&card->deferred_resume_work);
843 } else { 784 } else {
844 dev_dbg(dev, "ASoC: Scheduling resume work\n"); 785 dev_dbg(dev, "ASoC: Scheduling resume work\n");
@@ -1251,25 +1192,22 @@ static int soc_probe_link_components(struct snd_soc_card *card, int num,
1251 return 0; 1192 return 0;
1252} 1193}
1253 1194
1254static int soc_probe_codec_dai(struct snd_soc_card *card, 1195static int soc_probe_dai(struct snd_soc_dai *dai, int order)
1255 struct snd_soc_dai *codec_dai,
1256 int order)
1257{ 1196{
1258 int ret; 1197 int ret;
1259 1198
1260 if (!codec_dai->probed && codec_dai->driver->probe_order == order) { 1199 if (!dai->probed && dai->driver->probe_order == order) {
1261 if (codec_dai->driver->probe) { 1200 if (dai->driver->probe) {
1262 ret = codec_dai->driver->probe(codec_dai); 1201 ret = dai->driver->probe(dai);
1263 if (ret < 0) { 1202 if (ret < 0) {
1264 dev_err(codec_dai->dev, 1203 dev_err(dai->dev,
1265 "ASoC: failed to probe CODEC DAI %s: %d\n", 1204 "ASoC: failed to probe DAI %s: %d\n",
1266 codec_dai->name, ret); 1205 dai->name, ret);
1267 return ret; 1206 return ret;
1268 } 1207 }
1269 } 1208 }
1270 1209
1271 /* mark codec_dai as probed and add to card dai list */ 1210 dai->probed = 1;
1272 codec_dai->probed = 1;
1273 } 1211 }
1274 1212
1275 return 0; 1213 return 0;
@@ -1319,40 +1257,22 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1319{ 1257{
1320 struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1258 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1321 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1259 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1322 struct snd_soc_platform *platform = rtd->platform;
1323 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1260 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1324 int i, ret; 1261 int i, ret;
1325 1262
1326 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", 1263 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
1327 card->name, num, order); 1264 card->name, num, order);
1328 1265
1329 /* config components */
1330 cpu_dai->platform = platform;
1331 cpu_dai->card = card;
1332 for (i = 0; i < rtd->num_codecs; i++)
1333 rtd->codec_dais[i]->card = card;
1334
1335 /* set default power off timeout */ 1266 /* set default power off timeout */
1336 rtd->pmdown_time = pmdown_time; 1267 rtd->pmdown_time = pmdown_time;
1337 1268
1338 /* probe the cpu_dai */ 1269 ret = soc_probe_dai(cpu_dai, order);
1339 if (!cpu_dai->probed && 1270 if (ret)
1340 cpu_dai->driver->probe_order == order) { 1271 return ret;
1341 if (cpu_dai->driver->probe) {
1342 ret = cpu_dai->driver->probe(cpu_dai);
1343 if (ret < 0) {
1344 dev_err(cpu_dai->dev,
1345 "ASoC: failed to probe CPU DAI %s: %d\n",
1346 cpu_dai->name, ret);
1347 return ret;
1348 }
1349 }
1350 cpu_dai->probed = 1;
1351 }
1352 1272
1353 /* probe the CODEC DAI */ 1273 /* probe the CODEC DAI */
1354 for (i = 0; i < rtd->num_codecs; i++) { 1274 for (i = 0; i < rtd->num_codecs; i++) {
1355 ret = soc_probe_codec_dai(card, rtd->codec_dais[i], order); 1275 ret = soc_probe_dai(rtd->codec_dais[i], order);
1356 if (ret) 1276 if (ret)
1357 return ret; 1277 return ret;
1358 } 1278 }
@@ -1422,84 +1342,9 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1422 } 1342 }
1423 } 1343 }
1424 1344
1425 /* add platform data for AC97 devices */
1426 for (i = 0; i < rtd->num_codecs; i++) {
1427 if (rtd->codec_dais[i]->driver->ac97_control)
1428 snd_ac97_dev_add_pdata(rtd->codec_dais[i]->codec->ac97,
1429 rtd->cpu_dai->ac97_pdata);
1430 }
1431
1432 return 0; 1345 return 0;
1433} 1346}
1434 1347
1435#ifdef CONFIG_SND_SOC_AC97_BUS
1436static int soc_register_ac97_codec(struct snd_soc_codec *codec,
1437 struct snd_soc_dai *codec_dai)
1438{
1439 int ret;
1440
1441 /* Only instantiate AC97 if not already done by the adaptor
1442 * for the generic AC97 subsystem.
1443 */
1444 if (codec_dai->driver->ac97_control && !codec->ac97_registered) {
1445 /*
1446 * It is possible that the AC97 device is already registered to
1447 * the device subsystem. This happens when the device is created
1448 * via snd_ac97_mixer(). Currently only SoC codec that does so
1449 * is the generic AC97 glue but others migh emerge.
1450 *
1451 * In those cases we don't try to register the device again.
1452 */
1453 if (!codec->ac97_created)
1454 return 0;
1455
1456 ret = soc_ac97_dev_register(codec);
1457 if (ret < 0) {
1458 dev_err(codec->dev,
1459 "ASoC: AC97 device register failed: %d\n", ret);
1460 return ret;
1461 }
1462
1463 codec->ac97_registered = 1;
1464 }
1465 return 0;
1466}
1467
1468static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
1469{
1470 if (codec->ac97_registered) {
1471 soc_ac97_dev_unregister(codec);
1472 codec->ac97_registered = 0;
1473 }
1474}
1475
1476static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1477{
1478 int i, ret;
1479
1480 for (i = 0; i < rtd->num_codecs; i++) {
1481 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
1482
1483 ret = soc_register_ac97_codec(codec_dai->codec, codec_dai);
1484 if (ret) {
1485 while (--i >= 0)
1486 soc_unregister_ac97_codec(codec_dai->codec);
1487 return ret;
1488 }
1489 }
1490
1491 return 0;
1492}
1493
1494static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1495{
1496 int i;
1497
1498 for (i = 0; i < rtd->num_codecs; i++)
1499 soc_unregister_ac97_codec(rtd->codec_dais[i]->codec);
1500}
1501#endif
1502
1503static int soc_bind_aux_dev(struct snd_soc_card *card, int num) 1348static int soc_bind_aux_dev(struct snd_soc_card *card, int num)
1504{ 1349{
1505 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 1350 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
@@ -1793,20 +1638,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1793 goto probe_aux_dev_err; 1638 goto probe_aux_dev_err;
1794 } 1639 }
1795 1640
1796#ifdef CONFIG_SND_SOC_AC97_BUS
1797 /* register any AC97 codecs */
1798 for (i = 0; i < card->num_rtd; i++) {
1799 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1800 if (ret < 0) {
1801 dev_err(card->dev,
1802 "ASoC: failed to register AC97: %d\n", ret);
1803 while (--i >= 0)
1804 soc_unregister_ac97_dai_link(&card->rtd[i]);
1805 goto probe_aux_dev_err;
1806 }
1807 }
1808#endif
1809
1810 card->instantiated = 1; 1641 card->instantiated = 1;
1811 snd_soc_dapm_sync(&card->dapm); 1642 snd_soc_dapm_sync(&card->dapm);
1812 mutex_unlock(&card->mutex); 1643 mutex_unlock(&card->mutex);
@@ -1949,216 +1780,6 @@ static struct platform_driver soc_driver = {
1949}; 1780};
1950 1781
1951/** 1782/**
1952 * snd_soc_new_ac97_codec - initailise AC97 device
1953 * @codec: audio codec
1954 * @ops: AC97 bus operations
1955 * @num: AC97 codec number
1956 *
1957 * Initialises AC97 codec resources for use by ad-hoc devices only.
1958 */
1959int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1960 struct snd_ac97_bus_ops *ops, int num)
1961{
1962 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1963 if (codec->ac97 == NULL)
1964 return -ENOMEM;
1965
1966 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1967 if (codec->ac97->bus == NULL) {
1968 kfree(codec->ac97);
1969 codec->ac97 = NULL;
1970 return -ENOMEM;
1971 }
1972
1973 codec->ac97->bus->ops = ops;
1974 codec->ac97->num = num;
1975
1976 /*
1977 * Mark the AC97 device to be created by us. This way we ensure that the
1978 * device will be registered with the device subsystem later on.
1979 */
1980 codec->ac97_created = 1;
1981
1982 return 0;
1983}
1984EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1985
1986static struct snd_ac97_reset_cfg snd_ac97_rst_cfg;
1987
1988static void snd_soc_ac97_warm_reset(struct snd_ac97 *ac97)
1989{
1990 struct pinctrl *pctl = snd_ac97_rst_cfg.pctl;
1991
1992 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_warm_reset);
1993
1994 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 1);
1995
1996 udelay(10);
1997
1998 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0);
1999
2000 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run);
2001 msleep(2);
2002}
2003
2004static void snd_soc_ac97_reset(struct snd_ac97 *ac97)
2005{
2006 struct pinctrl *pctl = snd_ac97_rst_cfg.pctl;
2007
2008 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_reset);
2009
2010 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0);
2011 gpio_direction_output(snd_ac97_rst_cfg.gpio_sdata, 0);
2012 gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 0);
2013
2014 udelay(10);
2015
2016 gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 1);
2017
2018 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run);
2019 msleep(2);
2020}
2021
2022static int snd_soc_ac97_parse_pinctl(struct device *dev,
2023 struct snd_ac97_reset_cfg *cfg)
2024{
2025 struct pinctrl *p;
2026 struct pinctrl_state *state;
2027 int gpio;
2028 int ret;
2029
2030 p = devm_pinctrl_get(dev);
2031 if (IS_ERR(p)) {
2032 dev_err(dev, "Failed to get pinctrl\n");
2033 return PTR_ERR(p);
2034 }
2035 cfg->pctl = p;
2036
2037 state = pinctrl_lookup_state(p, "ac97-reset");
2038 if (IS_ERR(state)) {
2039 dev_err(dev, "Can't find pinctrl state ac97-reset\n");
2040 return PTR_ERR(state);
2041 }
2042 cfg->pstate_reset = state;
2043
2044 state = pinctrl_lookup_state(p, "ac97-warm-reset");
2045 if (IS_ERR(state)) {
2046 dev_err(dev, "Can't find pinctrl state ac97-warm-reset\n");
2047 return PTR_ERR(state);
2048 }
2049 cfg->pstate_warm_reset = state;
2050
2051 state = pinctrl_lookup_state(p, "ac97-running");
2052 if (IS_ERR(state)) {
2053 dev_err(dev, "Can't find pinctrl state ac97-running\n");
2054 return PTR_ERR(state);
2055 }
2056 cfg->pstate_run = state;
2057
2058 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 0);
2059 if (gpio < 0) {
2060 dev_err(dev, "Can't find ac97-sync gpio\n");
2061 return gpio;
2062 }
2063 ret = devm_gpio_request(dev, gpio, "AC97 link sync");
2064 if (ret) {
2065 dev_err(dev, "Failed requesting ac97-sync gpio\n");
2066 return ret;
2067 }
2068 cfg->gpio_sync = gpio;
2069
2070 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 1);
2071 if (gpio < 0) {
2072 dev_err(dev, "Can't find ac97-sdata gpio %d\n", gpio);
2073 return gpio;
2074 }
2075 ret = devm_gpio_request(dev, gpio, "AC97 link sdata");
2076 if (ret) {
2077 dev_err(dev, "Failed requesting ac97-sdata gpio\n");
2078 return ret;
2079 }
2080 cfg->gpio_sdata = gpio;
2081
2082 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 2);
2083 if (gpio < 0) {
2084 dev_err(dev, "Can't find ac97-reset gpio\n");
2085 return gpio;
2086 }
2087 ret = devm_gpio_request(dev, gpio, "AC97 link reset");
2088 if (ret) {
2089 dev_err(dev, "Failed requesting ac97-reset gpio\n");
2090 return ret;
2091 }
2092 cfg->gpio_reset = gpio;
2093
2094 return 0;
2095}
2096
2097struct snd_ac97_bus_ops *soc_ac97_ops;
2098EXPORT_SYMBOL_GPL(soc_ac97_ops);
2099
2100int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
2101{
2102 if (ops == soc_ac97_ops)
2103 return 0;
2104
2105 if (soc_ac97_ops && ops)
2106 return -EBUSY;
2107
2108 soc_ac97_ops = ops;
2109
2110 return 0;
2111}
2112EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops);
2113
2114/**
2115 * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions
2116 *
2117 * This function sets the reset and warm_reset properties of ops and parses
2118 * the device node of pdev to get pinctrl states and gpio numbers to use.
2119 */
2120int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
2121 struct platform_device *pdev)
2122{
2123 struct device *dev = &pdev->dev;
2124 struct snd_ac97_reset_cfg cfg;
2125 int ret;
2126
2127 ret = snd_soc_ac97_parse_pinctl(dev, &cfg);
2128 if (ret)
2129 return ret;
2130
2131 ret = snd_soc_set_ac97_ops(ops);
2132 if (ret)
2133 return ret;
2134
2135 ops->warm_reset = snd_soc_ac97_warm_reset;
2136 ops->reset = snd_soc_ac97_reset;
2137
2138 snd_ac97_rst_cfg = cfg;
2139 return 0;
2140}
2141EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset);
2142
2143/**
2144 * snd_soc_free_ac97_codec - free AC97 codec device
2145 * @codec: audio codec
2146 *
2147 * Frees AC97 codec device resources.
2148 */
2149void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
2150{
2151#ifdef CONFIG_SND_SOC_AC97_BUS
2152 soc_unregister_ac97_codec(codec);
2153#endif
2154 kfree(codec->ac97->bus);
2155 kfree(codec->ac97);
2156 codec->ac97 = NULL;
2157 codec->ac97_created = 0;
2158}
2159EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
2160
2161/**
2162 * snd_soc_cnew - create new control 1783 * snd_soc_cnew - create new control
2163 * @_template: control template 1784 * @_template: control template
2164 * @data: control private data 1785 * @data: control private data
@@ -2326,7 +1947,7 @@ EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2326int snd_soc_add_dai_controls(struct snd_soc_dai *dai, 1947int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2327 const struct snd_kcontrol_new *controls, int num_controls) 1948 const struct snd_kcontrol_new *controls, int num_controls)
2328{ 1949{
2329 struct snd_card *card = dai->card->snd_card; 1950 struct snd_card *card = dai->component->card->snd_card;
2330 1951
2331 return snd_soc_add_controls(card, dai->dev, controls, num_controls, 1952 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2332 NULL, dai); 1953 NULL, dai);
@@ -2334,1020 +1955,6 @@ int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2334EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); 1955EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2335 1956
2336/** 1957/**
2337 * snd_soc_info_enum_double - enumerated double mixer info callback
2338 * @kcontrol: mixer control
2339 * @uinfo: control element information
2340 *
2341 * Callback to provide information about a double enumerated
2342 * mixer control.
2343 *
2344 * Returns 0 for success.
2345 */
2346int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2347 struct snd_ctl_elem_info *uinfo)
2348{
2349 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2350
2351 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2352 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2353 uinfo->value.enumerated.items = e->items;
2354
2355 if (uinfo->value.enumerated.item >= e->items)
2356 uinfo->value.enumerated.item = e->items - 1;
2357 strlcpy(uinfo->value.enumerated.name,
2358 e->texts[uinfo->value.enumerated.item],
2359 sizeof(uinfo->value.enumerated.name));
2360 return 0;
2361}
2362EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2363
2364/**
2365 * snd_soc_get_enum_double - enumerated double mixer get callback
2366 * @kcontrol: mixer control
2367 * @ucontrol: control element information
2368 *
2369 * Callback to get the value of a double enumerated mixer.
2370 *
2371 * Returns 0 for success.
2372 */
2373int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2374 struct snd_ctl_elem_value *ucontrol)
2375{
2376 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2377 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2378 unsigned int val, item;
2379 unsigned int reg_val;
2380 int ret;
2381
2382 ret = snd_soc_component_read(component, e->reg, &reg_val);
2383 if (ret)
2384 return ret;
2385 val = (reg_val >> e->shift_l) & e->mask;
2386 item = snd_soc_enum_val_to_item(e, val);
2387 ucontrol->value.enumerated.item[0] = item;
2388 if (e->shift_l != e->shift_r) {
2389 val = (reg_val >> e->shift_l) & e->mask;
2390 item = snd_soc_enum_val_to_item(e, val);
2391 ucontrol->value.enumerated.item[1] = item;
2392 }
2393
2394 return 0;
2395}
2396EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2397
2398/**
2399 * snd_soc_put_enum_double - enumerated double mixer put callback
2400 * @kcontrol: mixer control
2401 * @ucontrol: control element information
2402 *
2403 * Callback to set the value of a double enumerated mixer.
2404 *
2405 * Returns 0 for success.
2406 */
2407int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2408 struct snd_ctl_elem_value *ucontrol)
2409{
2410 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2411 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2412 unsigned int *item = ucontrol->value.enumerated.item;
2413 unsigned int val;
2414 unsigned int mask;
2415
2416 if (item[0] >= e->items)
2417 return -EINVAL;
2418 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
2419 mask = e->mask << e->shift_l;
2420 if (e->shift_l != e->shift_r) {
2421 if (item[1] >= e->items)
2422 return -EINVAL;
2423 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r;
2424 mask |= e->mask << e->shift_r;
2425 }
2426
2427 return snd_soc_component_update_bits(component, e->reg, mask, val);
2428}
2429EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2430
2431/**
2432 * snd_soc_read_signed - Read a codec register and interprete as signed value
2433 * @component: component
2434 * @reg: Register to read
2435 * @mask: Mask to use after shifting the register value
2436 * @shift: Right shift of register value
2437 * @sign_bit: Bit that describes if a number is negative or not.
2438 * @signed_val: Pointer to where the read value should be stored
2439 *
2440 * This functions reads a codec register. The register value is shifted right
2441 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
2442 * the given registervalue into a signed integer if sign_bit is non-zero.
2443 *
2444 * Returns 0 on sucess, otherwise an error value
2445 */
2446static int snd_soc_read_signed(struct snd_soc_component *component,
2447 unsigned int reg, unsigned int mask, unsigned int shift,
2448 unsigned int sign_bit, int *signed_val)
2449{
2450 int ret;
2451 unsigned int val;
2452
2453 ret = snd_soc_component_read(component, reg, &val);
2454 if (ret < 0)
2455 return ret;
2456
2457 val = (val >> shift) & mask;
2458
2459 if (!sign_bit) {
2460 *signed_val = val;
2461 return 0;
2462 }
2463
2464 /* non-negative number */
2465 if (!(val & BIT(sign_bit))) {
2466 *signed_val = val;
2467 return 0;
2468 }
2469
2470 ret = val;
2471
2472 /*
2473 * The register most probably does not contain a full-sized int.
2474 * Instead we have an arbitrary number of bits in a signed
2475 * representation which has to be translated into a full-sized int.
2476 * This is done by filling up all bits above the sign-bit.
2477 */
2478 ret |= ~((int)(BIT(sign_bit) - 1));
2479
2480 *signed_val = ret;
2481
2482 return 0;
2483}
2484
2485/**
2486 * snd_soc_info_volsw - single mixer info callback
2487 * @kcontrol: mixer control
2488 * @uinfo: control element information
2489 *
2490 * Callback to provide information about a single mixer control, or a double
2491 * mixer control that spans 2 registers.
2492 *
2493 * Returns 0 for success.
2494 */
2495int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2496 struct snd_ctl_elem_info *uinfo)
2497{
2498 struct soc_mixer_control *mc =
2499 (struct soc_mixer_control *)kcontrol->private_value;
2500 int platform_max;
2501
2502 if (!mc->platform_max)
2503 mc->platform_max = mc->max;
2504 platform_max = mc->platform_max;
2505
2506 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2507 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2508 else
2509 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2510
2511 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2512 uinfo->value.integer.min = 0;
2513 uinfo->value.integer.max = platform_max - mc->min;
2514 return 0;
2515}
2516EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2517
2518/**
2519 * snd_soc_get_volsw - single mixer get callback
2520 * @kcontrol: mixer control
2521 * @ucontrol: control element information
2522 *
2523 * Callback to get the value of a single mixer control, or a double mixer
2524 * control that spans 2 registers.
2525 *
2526 * Returns 0 for success.
2527 */
2528int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2529 struct snd_ctl_elem_value *ucontrol)
2530{
2531 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2532 struct soc_mixer_control *mc =
2533 (struct soc_mixer_control *)kcontrol->private_value;
2534 unsigned int reg = mc->reg;
2535 unsigned int reg2 = mc->rreg;
2536 unsigned int shift = mc->shift;
2537 unsigned int rshift = mc->rshift;
2538 int max = mc->max;
2539 int min = mc->min;
2540 int sign_bit = mc->sign_bit;
2541 unsigned int mask = (1 << fls(max)) - 1;
2542 unsigned int invert = mc->invert;
2543 int val;
2544 int ret;
2545
2546 if (sign_bit)
2547 mask = BIT(sign_bit + 1) - 1;
2548
2549 ret = snd_soc_read_signed(component, reg, mask, shift, sign_bit, &val);
2550 if (ret)
2551 return ret;
2552
2553 ucontrol->value.integer.value[0] = val - min;
2554 if (invert)
2555 ucontrol->value.integer.value[0] =
2556 max - ucontrol->value.integer.value[0];
2557
2558 if (snd_soc_volsw_is_stereo(mc)) {
2559 if (reg == reg2)
2560 ret = snd_soc_read_signed(component, reg, mask, rshift,
2561 sign_bit, &val);
2562 else
2563 ret = snd_soc_read_signed(component, reg2, mask, shift,
2564 sign_bit, &val);
2565 if (ret)
2566 return ret;
2567
2568 ucontrol->value.integer.value[1] = val - min;
2569 if (invert)
2570 ucontrol->value.integer.value[1] =
2571 max - ucontrol->value.integer.value[1];
2572 }
2573
2574 return 0;
2575}
2576EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2577
2578/**
2579 * snd_soc_put_volsw - single mixer put callback
2580 * @kcontrol: mixer control
2581 * @ucontrol: control element information
2582 *
2583 * Callback to set the value of a single mixer control, or a double mixer
2584 * control that spans 2 registers.
2585 *
2586 * Returns 0 for success.
2587 */
2588int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2589 struct snd_ctl_elem_value *ucontrol)
2590{
2591 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2592 struct soc_mixer_control *mc =
2593 (struct soc_mixer_control *)kcontrol->private_value;
2594 unsigned int reg = mc->reg;
2595 unsigned int reg2 = mc->rreg;
2596 unsigned int shift = mc->shift;
2597 unsigned int rshift = mc->rshift;
2598 int max = mc->max;
2599 int min = mc->min;
2600 unsigned int sign_bit = mc->sign_bit;
2601 unsigned int mask = (1 << fls(max)) - 1;
2602 unsigned int invert = mc->invert;
2603 int err;
2604 bool type_2r = false;
2605 unsigned int val2 = 0;
2606 unsigned int val, val_mask;
2607
2608 if (sign_bit)
2609 mask = BIT(sign_bit + 1) - 1;
2610
2611 val = ((ucontrol->value.integer.value[0] + min) & mask);
2612 if (invert)
2613 val = max - val;
2614 val_mask = mask << shift;
2615 val = val << shift;
2616 if (snd_soc_volsw_is_stereo(mc)) {
2617 val2 = ((ucontrol->value.integer.value[1] + min) & mask);
2618 if (invert)
2619 val2 = max - val2;
2620 if (reg == reg2) {
2621 val_mask |= mask << rshift;
2622 val |= val2 << rshift;
2623 } else {
2624 val2 = val2 << shift;
2625 type_2r = true;
2626 }
2627 }
2628 err = snd_soc_component_update_bits(component, reg, val_mask, val);
2629 if (err < 0)
2630 return err;
2631
2632 if (type_2r)
2633 err = snd_soc_component_update_bits(component, reg2, val_mask,
2634 val2);
2635
2636 return err;
2637}
2638EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2639
2640/**
2641 * snd_soc_get_volsw_sx - single mixer get callback
2642 * @kcontrol: mixer control
2643 * @ucontrol: control element information
2644 *
2645 * Callback to get the value of a single mixer control, or a double mixer
2646 * control that spans 2 registers.
2647 *
2648 * Returns 0 for success.
2649 */
2650int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
2651 struct snd_ctl_elem_value *ucontrol)
2652{
2653 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2654 struct soc_mixer_control *mc =
2655 (struct soc_mixer_control *)kcontrol->private_value;
2656 unsigned int reg = mc->reg;
2657 unsigned int reg2 = mc->rreg;
2658 unsigned int shift = mc->shift;
2659 unsigned int rshift = mc->rshift;
2660 int max = mc->max;
2661 int min = mc->min;
2662 int mask = (1 << (fls(min + max) - 1)) - 1;
2663 unsigned int val;
2664 int ret;
2665
2666 ret = snd_soc_component_read(component, reg, &val);
2667 if (ret < 0)
2668 return ret;
2669
2670 ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask;
2671
2672 if (snd_soc_volsw_is_stereo(mc)) {
2673 ret = snd_soc_component_read(component, reg2, &val);
2674 if (ret < 0)
2675 return ret;
2676
2677 val = ((val >> rshift) - min) & mask;
2678 ucontrol->value.integer.value[1] = val;
2679 }
2680
2681 return 0;
2682}
2683EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
2684
2685/**
2686 * snd_soc_put_volsw_sx - double mixer set callback
2687 * @kcontrol: mixer control
2688 * @uinfo: control element information
2689 *
2690 * Callback to set the value of a double mixer control that spans 2 registers.
2691 *
2692 * Returns 0 for success.
2693 */
2694int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2695 struct snd_ctl_elem_value *ucontrol)
2696{
2697 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2698 struct soc_mixer_control *mc =
2699 (struct soc_mixer_control *)kcontrol->private_value;
2700
2701 unsigned int reg = mc->reg;
2702 unsigned int reg2 = mc->rreg;
2703 unsigned int shift = mc->shift;
2704 unsigned int rshift = mc->rshift;
2705 int max = mc->max;
2706 int min = mc->min;
2707 int mask = (1 << (fls(min + max) - 1)) - 1;
2708 int err = 0;
2709 unsigned int val, val_mask, val2 = 0;
2710
2711 val_mask = mask << shift;
2712 val = (ucontrol->value.integer.value[0] + min) & mask;
2713 val = val << shift;
2714
2715 err = snd_soc_component_update_bits(component, reg, val_mask, val);
2716 if (err < 0)
2717 return err;
2718
2719 if (snd_soc_volsw_is_stereo(mc)) {
2720 val_mask = mask << rshift;
2721 val2 = (ucontrol->value.integer.value[1] + min) & mask;
2722 val2 = val2 << rshift;
2723
2724 err = snd_soc_component_update_bits(component, reg2, val_mask,
2725 val2);
2726 }
2727 return err;
2728}
2729EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
2730
2731/**
2732 * snd_soc_info_volsw_s8 - signed mixer info callback
2733 * @kcontrol: mixer control
2734 * @uinfo: control element information
2735 *
2736 * Callback to provide information about a signed mixer control.
2737 *
2738 * Returns 0 for success.
2739 */
2740int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2741 struct snd_ctl_elem_info *uinfo)
2742{
2743 struct soc_mixer_control *mc =
2744 (struct soc_mixer_control *)kcontrol->private_value;
2745 int platform_max;
2746 int min = mc->min;
2747
2748 if (!mc->platform_max)
2749 mc->platform_max = mc->max;
2750 platform_max = mc->platform_max;
2751
2752 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2753 uinfo->count = 2;
2754 uinfo->value.integer.min = 0;
2755 uinfo->value.integer.max = platform_max - min;
2756 return 0;
2757}
2758EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2759
2760/**
2761 * snd_soc_get_volsw_s8 - signed mixer get callback
2762 * @kcontrol: mixer control
2763 * @ucontrol: control element information
2764 *
2765 * Callback to get the value of a signed mixer control.
2766 *
2767 * Returns 0 for success.
2768 */
2769int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2770 struct snd_ctl_elem_value *ucontrol)
2771{
2772 struct soc_mixer_control *mc =
2773 (struct soc_mixer_control *)kcontrol->private_value;
2774 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2775 unsigned int reg = mc->reg;
2776 unsigned int val;
2777 int min = mc->min;
2778 int ret;
2779
2780 ret = snd_soc_component_read(component, reg, &val);
2781 if (ret)
2782 return ret;
2783
2784 ucontrol->value.integer.value[0] =
2785 ((signed char)(val & 0xff))-min;
2786 ucontrol->value.integer.value[1] =
2787 ((signed char)((val >> 8) & 0xff))-min;
2788 return 0;
2789}
2790EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2791
2792/**
2793 * snd_soc_put_volsw_sgn - signed mixer put callback
2794 * @kcontrol: mixer control
2795 * @ucontrol: control element information
2796 *
2797 * Callback to set the value of a signed mixer control.
2798 *
2799 * Returns 0 for success.
2800 */
2801int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2802 struct snd_ctl_elem_value *ucontrol)
2803{
2804 struct soc_mixer_control *mc =
2805 (struct soc_mixer_control *)kcontrol->private_value;
2806 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2807 unsigned int reg = mc->reg;
2808 int min = mc->min;
2809 unsigned int val;
2810
2811 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2812 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2813
2814 return snd_soc_component_update_bits(component, reg, 0xffff, val);
2815}
2816EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2817
2818/**
2819 * snd_soc_info_volsw_range - single mixer info callback with range.
2820 * @kcontrol: mixer control
2821 * @uinfo: control element information
2822 *
2823 * Callback to provide information, within a range, about a single
2824 * mixer control.
2825 *
2826 * returns 0 for success.
2827 */
2828int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
2829 struct snd_ctl_elem_info *uinfo)
2830{
2831 struct soc_mixer_control *mc =
2832 (struct soc_mixer_control *)kcontrol->private_value;
2833 int platform_max;
2834 int min = mc->min;
2835
2836 if (!mc->platform_max)
2837 mc->platform_max = mc->max;
2838 platform_max = mc->platform_max;
2839
2840 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2841 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2842 uinfo->value.integer.min = 0;
2843 uinfo->value.integer.max = platform_max - min;
2844
2845 return 0;
2846}
2847EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
2848
2849/**
2850 * snd_soc_put_volsw_range - single mixer put value callback with range.
2851 * @kcontrol: mixer control
2852 * @ucontrol: control element information
2853 *
2854 * Callback to set the value, within a range, for a single mixer control.
2855 *
2856 * Returns 0 for success.
2857 */
2858int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
2859 struct snd_ctl_elem_value *ucontrol)
2860{
2861 struct soc_mixer_control *mc =
2862 (struct soc_mixer_control *)kcontrol->private_value;
2863 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2864 unsigned int reg = mc->reg;
2865 unsigned int rreg = mc->rreg;
2866 unsigned int shift = mc->shift;
2867 int min = mc->min;
2868 int max = mc->max;
2869 unsigned int mask = (1 << fls(max)) - 1;
2870 unsigned int invert = mc->invert;
2871 unsigned int val, val_mask;
2872 int ret;
2873
2874 if (invert)
2875 val = (max - ucontrol->value.integer.value[0]) & mask;
2876 else
2877 val = ((ucontrol->value.integer.value[0] + min) & mask);
2878 val_mask = mask << shift;
2879 val = val << shift;
2880
2881 ret = snd_soc_component_update_bits(component, reg, val_mask, val);
2882 if (ret < 0)
2883 return ret;
2884
2885 if (snd_soc_volsw_is_stereo(mc)) {
2886 if (invert)
2887 val = (max - ucontrol->value.integer.value[1]) & mask;
2888 else
2889 val = ((ucontrol->value.integer.value[1] + min) & mask);
2890 val_mask = mask << shift;
2891 val = val << shift;
2892
2893 ret = snd_soc_component_update_bits(component, rreg, val_mask,
2894 val);
2895 }
2896
2897 return ret;
2898}
2899EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
2900
2901/**
2902 * snd_soc_get_volsw_range - single mixer get callback with range
2903 * @kcontrol: mixer control
2904 * @ucontrol: control element information
2905 *
2906 * Callback to get the value, within a range, of a single mixer control.
2907 *
2908 * Returns 0 for success.
2909 */
2910int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
2911 struct snd_ctl_elem_value *ucontrol)
2912{
2913 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2914 struct soc_mixer_control *mc =
2915 (struct soc_mixer_control *)kcontrol->private_value;
2916 unsigned int reg = mc->reg;
2917 unsigned int rreg = mc->rreg;
2918 unsigned int shift = mc->shift;
2919 int min = mc->min;
2920 int max = mc->max;
2921 unsigned int mask = (1 << fls(max)) - 1;
2922 unsigned int invert = mc->invert;
2923 unsigned int val;
2924 int ret;
2925
2926 ret = snd_soc_component_read(component, reg, &val);
2927 if (ret)
2928 return ret;
2929
2930 ucontrol->value.integer.value[0] = (val >> shift) & mask;
2931 if (invert)
2932 ucontrol->value.integer.value[0] =
2933 max - ucontrol->value.integer.value[0];
2934 else
2935 ucontrol->value.integer.value[0] =
2936 ucontrol->value.integer.value[0] - min;
2937
2938 if (snd_soc_volsw_is_stereo(mc)) {
2939 ret = snd_soc_component_read(component, rreg, &val);
2940 if (ret)
2941 return ret;
2942
2943 ucontrol->value.integer.value[1] = (val >> shift) & mask;
2944 if (invert)
2945 ucontrol->value.integer.value[1] =
2946 max - ucontrol->value.integer.value[1];
2947 else
2948 ucontrol->value.integer.value[1] =
2949 ucontrol->value.integer.value[1] - min;
2950 }
2951
2952 return 0;
2953}
2954EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
2955
2956/**
2957 * snd_soc_limit_volume - Set new limit to an existing volume control.
2958 *
2959 * @codec: where to look for the control
2960 * @name: Name of the control
2961 * @max: new maximum limit
2962 *
2963 * Return 0 for success, else error.
2964 */
2965int snd_soc_limit_volume(struct snd_soc_codec *codec,
2966 const char *name, int max)
2967{
2968 struct snd_card *card = codec->component.card->snd_card;
2969 struct snd_kcontrol *kctl;
2970 struct soc_mixer_control *mc;
2971 int found = 0;
2972 int ret = -EINVAL;
2973
2974 /* Sanity check for name and max */
2975 if (unlikely(!name || max <= 0))
2976 return -EINVAL;
2977
2978 list_for_each_entry(kctl, &card->controls, list) {
2979 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2980 found = 1;
2981 break;
2982 }
2983 }
2984 if (found) {
2985 mc = (struct soc_mixer_control *)kctl->private_value;
2986 if (max <= mc->max) {
2987 mc->platform_max = max;
2988 ret = 0;
2989 }
2990 }
2991 return ret;
2992}
2993EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2994
2995int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
2996 struct snd_ctl_elem_info *uinfo)
2997{
2998 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2999 struct soc_bytes *params = (void *)kcontrol->private_value;
3000
3001 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
3002 uinfo->count = params->num_regs * component->val_bytes;
3003
3004 return 0;
3005}
3006EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
3007
3008int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
3009 struct snd_ctl_elem_value *ucontrol)
3010{
3011 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3012 struct soc_bytes *params = (void *)kcontrol->private_value;
3013 int ret;
3014
3015 if (component->regmap)
3016 ret = regmap_raw_read(component->regmap, params->base,
3017 ucontrol->value.bytes.data,
3018 params->num_regs * component->val_bytes);
3019 else
3020 ret = -EINVAL;
3021
3022 /* Hide any masked bytes to ensure consistent data reporting */
3023 if (ret == 0 && params->mask) {
3024 switch (component->val_bytes) {
3025 case 1:
3026 ucontrol->value.bytes.data[0] &= ~params->mask;
3027 break;
3028 case 2:
3029 ((u16 *)(&ucontrol->value.bytes.data))[0]
3030 &= cpu_to_be16(~params->mask);
3031 break;
3032 case 4:
3033 ((u32 *)(&ucontrol->value.bytes.data))[0]
3034 &= cpu_to_be32(~params->mask);
3035 break;
3036 default:
3037 return -EINVAL;
3038 }
3039 }
3040
3041 return ret;
3042}
3043EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
3044
3045int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3046 struct snd_ctl_elem_value *ucontrol)
3047{
3048 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3049 struct soc_bytes *params = (void *)kcontrol->private_value;
3050 int ret, len;
3051 unsigned int val, mask;
3052 void *data;
3053
3054 if (!component->regmap || !params->num_regs)
3055 return -EINVAL;
3056
3057 len = params->num_regs * component->val_bytes;
3058
3059 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
3060 if (!data)
3061 return -ENOMEM;
3062
3063 /*
3064 * If we've got a mask then we need to preserve the register
3065 * bits. We shouldn't modify the incoming data so take a
3066 * copy.
3067 */
3068 if (params->mask) {
3069 ret = regmap_read(component->regmap, params->base, &val);
3070 if (ret != 0)
3071 goto out;
3072
3073 val &= params->mask;
3074
3075 switch (component->val_bytes) {
3076 case 1:
3077 ((u8 *)data)[0] &= ~params->mask;
3078 ((u8 *)data)[0] |= val;
3079 break;
3080 case 2:
3081 mask = ~params->mask;
3082 ret = regmap_parse_val(component->regmap,
3083 &mask, &mask);
3084 if (ret != 0)
3085 goto out;
3086
3087 ((u16 *)data)[0] &= mask;
3088
3089 ret = regmap_parse_val(component->regmap,
3090 &val, &val);
3091 if (ret != 0)
3092 goto out;
3093
3094 ((u16 *)data)[0] |= val;
3095 break;
3096 case 4:
3097 mask = ~params->mask;
3098 ret = regmap_parse_val(component->regmap,
3099 &mask, &mask);
3100 if (ret != 0)
3101 goto out;
3102
3103 ((u32 *)data)[0] &= mask;
3104
3105 ret = regmap_parse_val(component->regmap,
3106 &val, &val);
3107 if (ret != 0)
3108 goto out;
3109
3110 ((u32 *)data)[0] |= val;
3111 break;
3112 default:
3113 ret = -EINVAL;
3114 goto out;
3115 }
3116 }
3117
3118 ret = regmap_raw_write(component->regmap, params->base,
3119 data, len);
3120
3121out:
3122 kfree(data);
3123
3124 return ret;
3125}
3126EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
3127
3128int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
3129 struct snd_ctl_elem_info *ucontrol)
3130{
3131 struct soc_bytes_ext *params = (void *)kcontrol->private_value;
3132
3133 ucontrol->type = SNDRV_CTL_ELEM_TYPE_BYTES;
3134 ucontrol->count = params->max;
3135
3136 return 0;
3137}
3138EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext);
3139
3140int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
3141 unsigned int size, unsigned int __user *tlv)
3142{
3143 struct soc_bytes_ext *params = (void *)kcontrol->private_value;
3144 unsigned int count = size < params->max ? size : params->max;
3145 int ret = -ENXIO;
3146
3147 switch (op_flag) {
3148 case SNDRV_CTL_TLV_OP_READ:
3149 if (params->get)
3150 ret = params->get(tlv, count);
3151 break;
3152 case SNDRV_CTL_TLV_OP_WRITE:
3153 if (params->put)
3154 ret = params->put(tlv, count);
3155 break;
3156 }
3157 return ret;
3158}
3159EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback);
3160
3161/**
3162 * snd_soc_info_xr_sx - signed multi register info callback
3163 * @kcontrol: mreg control
3164 * @uinfo: control element information
3165 *
3166 * Callback to provide information of a control that can
3167 * span multiple codec registers which together
3168 * forms a single signed value in a MSB/LSB manner.
3169 *
3170 * Returns 0 for success.
3171 */
3172int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
3173 struct snd_ctl_elem_info *uinfo)
3174{
3175 struct soc_mreg_control *mc =
3176 (struct soc_mreg_control *)kcontrol->private_value;
3177 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3178 uinfo->count = 1;
3179 uinfo->value.integer.min = mc->min;
3180 uinfo->value.integer.max = mc->max;
3181
3182 return 0;
3183}
3184EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
3185
3186/**
3187 * snd_soc_get_xr_sx - signed multi register get callback
3188 * @kcontrol: mreg control
3189 * @ucontrol: control element information
3190 *
3191 * Callback to get the value of a control that can span
3192 * multiple codec registers which together forms a single
3193 * signed value in a MSB/LSB manner. The control supports
3194 * specifying total no of bits used to allow for bitfields
3195 * across the multiple codec registers.
3196 *
3197 * Returns 0 for success.
3198 */
3199int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
3200 struct snd_ctl_elem_value *ucontrol)
3201{
3202 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3203 struct soc_mreg_control *mc =
3204 (struct soc_mreg_control *)kcontrol->private_value;
3205 unsigned int regbase = mc->regbase;
3206 unsigned int regcount = mc->regcount;
3207 unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
3208 unsigned int regwmask = (1<<regwshift)-1;
3209 unsigned int invert = mc->invert;
3210 unsigned long mask = (1UL<<mc->nbits)-1;
3211 long min = mc->min;
3212 long max = mc->max;
3213 long val = 0;
3214 unsigned int regval;
3215 unsigned int i;
3216 int ret;
3217
3218 for (i = 0; i < regcount; i++) {
3219 ret = snd_soc_component_read(component, regbase+i, &regval);
3220 if (ret)
3221 return ret;
3222 val |= (regval & regwmask) << (regwshift*(regcount-i-1));
3223 }
3224 val &= mask;
3225 if (min < 0 && val > max)
3226 val |= ~mask;
3227 if (invert)
3228 val = max - val;
3229 ucontrol->value.integer.value[0] = val;
3230
3231 return 0;
3232}
3233EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
3234
3235/**
3236 * snd_soc_put_xr_sx - signed multi register get callback
3237 * @kcontrol: mreg control
3238 * @ucontrol: control element information
3239 *
3240 * Callback to set the value of a control that can span
3241 * multiple codec registers which together forms a single
3242 * signed value in a MSB/LSB manner. The control supports
3243 * specifying total no of bits used to allow for bitfields
3244 * across the multiple codec registers.
3245 *
3246 * Returns 0 for success.
3247 */
3248int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
3249 struct snd_ctl_elem_value *ucontrol)
3250{
3251 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3252 struct soc_mreg_control *mc =
3253 (struct soc_mreg_control *)kcontrol->private_value;
3254 unsigned int regbase = mc->regbase;
3255 unsigned int regcount = mc->regcount;
3256 unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
3257 unsigned int regwmask = (1<<regwshift)-1;
3258 unsigned int invert = mc->invert;
3259 unsigned long mask = (1UL<<mc->nbits)-1;
3260 long max = mc->max;
3261 long val = ucontrol->value.integer.value[0];
3262 unsigned int i, regval, regmask;
3263 int err;
3264
3265 if (invert)
3266 val = max - val;
3267 val &= mask;
3268 for (i = 0; i < regcount; i++) {
3269 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
3270 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
3271 err = snd_soc_component_update_bits(component, regbase+i,
3272 regmask, regval);
3273 if (err < 0)
3274 return err;
3275 }
3276
3277 return 0;
3278}
3279EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
3280
3281/**
3282 * snd_soc_get_strobe - strobe get callback
3283 * @kcontrol: mixer control
3284 * @ucontrol: control element information
3285 *
3286 * Callback get the value of a strobe mixer control.
3287 *
3288 * Returns 0 for success.
3289 */
3290int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
3291 struct snd_ctl_elem_value *ucontrol)
3292{
3293 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3294 struct soc_mixer_control *mc =
3295 (struct soc_mixer_control *)kcontrol->private_value;
3296 unsigned int reg = mc->reg;
3297 unsigned int shift = mc->shift;
3298 unsigned int mask = 1 << shift;
3299 unsigned int invert = mc->invert != 0;
3300 unsigned int val;
3301 int ret;
3302
3303 ret = snd_soc_component_read(component, reg, &val);
3304 if (ret)
3305 return ret;
3306
3307 val &= mask;
3308
3309 if (shift != 0 && val != 0)
3310 val = val >> shift;
3311 ucontrol->value.enumerated.item[0] = val ^ invert;
3312
3313 return 0;
3314}
3315EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
3316
3317/**
3318 * snd_soc_put_strobe - strobe put callback
3319 * @kcontrol: mixer control
3320 * @ucontrol: control element information
3321 *
3322 * Callback strobe a register bit to high then low (or the inverse)
3323 * in one pass of a single mixer enum control.
3324 *
3325 * Returns 1 for success.
3326 */
3327int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
3328 struct snd_ctl_elem_value *ucontrol)
3329{
3330 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3331 struct soc_mixer_control *mc =
3332 (struct soc_mixer_control *)kcontrol->private_value;
3333 unsigned int reg = mc->reg;
3334 unsigned int shift = mc->shift;
3335 unsigned int mask = 1 << shift;
3336 unsigned int invert = mc->invert != 0;
3337 unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
3338 unsigned int val1 = (strobe ^ invert) ? mask : 0;
3339 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
3340 int err;
3341
3342 err = snd_soc_component_update_bits(component, reg, mask, val1);
3343 if (err < 0)
3344 return err;
3345
3346 return snd_soc_component_update_bits(component, reg, mask, val2);
3347}
3348EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
3349
3350/**
3351 * snd_soc_dai_set_sysclk - configure DAI system or master clock. 1958 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3352 * @dai: DAI 1959 * @dai: DAI
3353 * @clk_id: DAI specific clock ID 1960 * @clk_id: DAI specific clock ID
@@ -3996,22 +2603,62 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
3996 return 0; 2603 return 0;
3997} 2604}
3998 2605
3999static void snd_soc_component_init_regmap(struct snd_soc_component *component) 2606static void snd_soc_component_setup_regmap(struct snd_soc_component *component)
4000{ 2607{
4001 if (!component->regmap) 2608 int val_bytes = regmap_get_val_bytes(component->regmap);
4002 component->regmap = dev_get_regmap(component->dev, NULL); 2609
4003 if (component->regmap) { 2610 /* Errors are legitimate for non-integer byte multiples */
4004 int val_bytes = regmap_get_val_bytes(component->regmap); 2611 if (val_bytes > 0)
4005 /* Errors are legitimate for non-integer byte multiples */ 2612 component->val_bytes = val_bytes;
4006 if (val_bytes > 0) 2613}
4007 component->val_bytes = val_bytes; 2614
4008 } 2615#ifdef CONFIG_REGMAP
2616
2617/**
2618 * snd_soc_component_init_regmap() - Initialize regmap instance for the component
2619 * @component: The component for which to initialize the regmap instance
2620 * @regmap: The regmap instance that should be used by the component
2621 *
2622 * This function allows deferred assignment of the regmap instance that is
2623 * associated with the component. Only use this if the regmap instance is not
2624 * yet ready when the component is registered. The function must also be called
2625 * before the first IO attempt of the component.
2626 */
2627void snd_soc_component_init_regmap(struct snd_soc_component *component,
2628 struct regmap *regmap)
2629{
2630 component->regmap = regmap;
2631 snd_soc_component_setup_regmap(component);
2632}
2633EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
2634
2635/**
2636 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component
2637 * @component: The component for which to de-initialize the regmap instance
2638 *
2639 * Calls regmap_exit() on the regmap instance associated to the component and
2640 * removes the regmap instance from the component.
2641 *
2642 * This function should only be used if snd_soc_component_init_regmap() was used
2643 * to initialize the regmap instance.
2644 */
2645void snd_soc_component_exit_regmap(struct snd_soc_component *component)
2646{
2647 regmap_exit(component->regmap);
2648 component->regmap = NULL;
4009} 2649}
2650EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
2651
2652#endif
4010 2653
4011static void snd_soc_component_add_unlocked(struct snd_soc_component *component) 2654static void snd_soc_component_add_unlocked(struct snd_soc_component *component)
4012{ 2655{
4013 if (!component->write && !component->read) 2656 if (!component->write && !component->read) {
4014 snd_soc_component_init_regmap(component); 2657 if (!component->regmap)
2658 component->regmap = dev_get_regmap(component->dev, NULL);
2659 if (component->regmap)
2660 snd_soc_component_setup_regmap(component);
2661 }
4015 2662
4016 list_add(&component->list, &component_list); 2663 list_add(&component->list, &component_list);
4017} 2664}
@@ -4362,7 +3009,6 @@ int snd_soc_register_codec(struct device *dev,
4362 codec->dev = dev; 3009 codec->dev = dev;
4363 codec->driver = codec_drv; 3010 codec->driver = codec_drv;
4364 codec->component.val_bytes = codec_drv->reg_word_size; 3011 codec->component.val_bytes = codec_drv->reg_word_size;
4365 mutex_init(&codec->mutex);
4366 3012
4367#ifdef CONFIG_DEBUG_FS 3013#ifdef CONFIG_DEBUG_FS
4368 codec->component.init_debugfs = soc_init_codec_debugfs; 3014 codec->component.init_debugfs = soc_init_codec_debugfs;
@@ -4585,7 +3231,7 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4585 const char *propname) 3231 const char *propname)
4586{ 3232{
4587 struct device_node *np = card->dev->of_node; 3233 struct device_node *np = card->dev->of_node;
4588 int num_routes; 3234 int num_routes, old_routes;
4589 struct snd_soc_dapm_route *routes; 3235 struct snd_soc_dapm_route *routes;
4590 int i, ret; 3236 int i, ret;
4591 3237
@@ -4603,7 +3249,9 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4603 return -EINVAL; 3249 return -EINVAL;
4604 } 3250 }
4605 3251
4606 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), 3252 old_routes = card->num_dapm_routes;
3253 routes = devm_kzalloc(card->dev,
3254 (old_routes + num_routes) * sizeof(*routes),
4607 GFP_KERNEL); 3255 GFP_KERNEL);
4608 if (!routes) { 3256 if (!routes) {
4609 dev_err(card->dev, 3257 dev_err(card->dev,
@@ -4611,9 +3259,11 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4611 return -EINVAL; 3259 return -EINVAL;
4612 } 3260 }
4613 3261
3262 memcpy(routes, card->dapm_routes, old_routes * sizeof(*routes));
3263
4614 for (i = 0; i < num_routes; i++) { 3264 for (i = 0; i < num_routes; i++) {
4615 ret = of_property_read_string_index(np, propname, 3265 ret = of_property_read_string_index(np, propname,
4616 2 * i, &routes[i].sink); 3266 2 * i, &routes[old_routes + i].sink);
4617 if (ret) { 3267 if (ret) {
4618 dev_err(card->dev, 3268 dev_err(card->dev,
4619 "ASoC: Property '%s' index %d could not be read: %d\n", 3269 "ASoC: Property '%s' index %d could not be read: %d\n",
@@ -4621,7 +3271,7 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4621 return -EINVAL; 3271 return -EINVAL;
4622 } 3272 }
4623 ret = of_property_read_string_index(np, propname, 3273 ret = of_property_read_string_index(np, propname,
4624 (2 * i) + 1, &routes[i].source); 3274 (2 * i) + 1, &routes[old_routes + i].source);
4625 if (ret) { 3275 if (ret) {
4626 dev_err(card->dev, 3276 dev_err(card->dev,
4627 "ASoC: Property '%s' index %d could not be read: %d\n", 3277 "ASoC: Property '%s' index %d could not be read: %d\n",
@@ -4630,7 +3280,7 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4630 } 3280 }
4631 } 3281 }
4632 3282
4633 card->num_dapm_routes = num_routes; 3283 card->num_dapm_routes += num_routes;
4634 card->dapm_routes = routes; 3284 card->dapm_routes = routes;
4635 3285
4636 return 0; 3286 return 0;
@@ -4750,36 +3400,30 @@ unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
4750} 3400}
4751EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); 3401EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
4752 3402
4753int snd_soc_of_get_dai_name(struct device_node *of_node, 3403static int snd_soc_get_dai_name(struct of_phandle_args *args,
4754 const char **dai_name) 3404 const char **dai_name)
4755{ 3405{
4756 struct snd_soc_component *pos; 3406 struct snd_soc_component *pos;
4757 struct of_phandle_args args; 3407 int ret = -EPROBE_DEFER;
4758 int ret;
4759
4760 ret = of_parse_phandle_with_args(of_node, "sound-dai",
4761 "#sound-dai-cells", 0, &args);
4762 if (ret)
4763 return ret;
4764
4765 ret = -EPROBE_DEFER;
4766 3408
4767 mutex_lock(&client_mutex); 3409 mutex_lock(&client_mutex);
4768 list_for_each_entry(pos, &component_list, list) { 3410 list_for_each_entry(pos, &component_list, list) {
4769 if (pos->dev->of_node != args.np) 3411 if (pos->dev->of_node != args->np)
4770 continue; 3412 continue;
4771 3413
4772 if (pos->driver->of_xlate_dai_name) { 3414 if (pos->driver->of_xlate_dai_name) {
4773 ret = pos->driver->of_xlate_dai_name(pos, &args, dai_name); 3415 ret = pos->driver->of_xlate_dai_name(pos,
3416 args,
3417 dai_name);
4774 } else { 3418 } else {
4775 int id = -1; 3419 int id = -1;
4776 3420
4777 switch (args.args_count) { 3421 switch (args->args_count) {
4778 case 0: 3422 case 0:
4779 id = 0; /* same as dai_drv[0] */ 3423 id = 0; /* same as dai_drv[0] */
4780 break; 3424 break;
4781 case 1: 3425 case 1:
4782 id = args.args[0]; 3426 id = args->args[0];
4783 break; 3427 break;
4784 default: 3428 default:
4785 /* not supported */ 3429 /* not supported */
@@ -4801,6 +3445,21 @@ int snd_soc_of_get_dai_name(struct device_node *of_node,
4801 break; 3445 break;
4802 } 3446 }
4803 mutex_unlock(&client_mutex); 3447 mutex_unlock(&client_mutex);
3448 return ret;
3449}
3450
3451int snd_soc_of_get_dai_name(struct device_node *of_node,
3452 const char **dai_name)
3453{
3454 struct of_phandle_args args;
3455 int ret;
3456
3457 ret = of_parse_phandle_with_args(of_node, "sound-dai",
3458 "#sound-dai-cells", 0, &args);
3459 if (ret)
3460 return ret;
3461
3462 ret = snd_soc_get_dai_name(&args, dai_name);
4804 3463
4805 of_node_put(args.np); 3464 of_node_put(args.np);
4806 3465
@@ -4808,6 +3467,77 @@ int snd_soc_of_get_dai_name(struct device_node *of_node,
4808} 3467}
4809EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name); 3468EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
4810 3469
3470/*
3471 * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
3472 * @dev: Card device
3473 * @of_node: Device node
3474 * @dai_link: DAI link
3475 *
3476 * Builds an array of CODEC DAI components from the DAI link property
3477 * 'sound-dai'.
3478 * The array is set in the DAI link and the number of DAIs is set accordingly.
3479 * The device nodes in the array (of_node) must be dereferenced by the caller.
3480 *
3481 * Returns 0 for success
3482 */
3483int snd_soc_of_get_dai_link_codecs(struct device *dev,
3484 struct device_node *of_node,
3485 struct snd_soc_dai_link *dai_link)
3486{
3487 struct of_phandle_args args;
3488 struct snd_soc_dai_link_component *component;
3489 char *name;
3490 int index, num_codecs, ret;
3491
3492 /* Count the number of CODECs */
3493 name = "sound-dai";
3494 num_codecs = of_count_phandle_with_args(of_node, name,
3495 "#sound-dai-cells");
3496 if (num_codecs <= 0) {
3497 if (num_codecs == -ENOENT)
3498 dev_err(dev, "No 'sound-dai' property\n");
3499 else
3500 dev_err(dev, "Bad phandle in 'sound-dai'\n");
3501 return num_codecs;
3502 }
3503 component = devm_kzalloc(dev,
3504 sizeof *component * num_codecs,
3505 GFP_KERNEL);
3506 if (!component)
3507 return -ENOMEM;
3508 dai_link->codecs = component;
3509 dai_link->num_codecs = num_codecs;
3510
3511 /* Parse the list */
3512 for (index = 0, component = dai_link->codecs;
3513 index < dai_link->num_codecs;
3514 index++, component++) {
3515 ret = of_parse_phandle_with_args(of_node, name,
3516 "#sound-dai-cells",
3517 index, &args);
3518 if (ret)
3519 goto err;
3520 component->of_node = args.np;
3521 ret = snd_soc_get_dai_name(&args, &component->dai_name);
3522 if (ret < 0)
3523 goto err;
3524 }
3525 return 0;
3526err:
3527 for (index = 0, component = dai_link->codecs;
3528 index < dai_link->num_codecs;
3529 index++, component++) {
3530 if (!component->of_node)
3531 break;
3532 of_node_put(component->of_node);
3533 component->of_node = NULL;
3534 }
3535 dai_link->codecs = NULL;
3536 dai_link->num_codecs = 0;
3537 return ret;
3538}
3539EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
3540
4811static int __init snd_soc_init(void) 3541static int __init snd_soc_init(void)
4812{ 3542{
4813#ifdef CONFIG_DEBUG_FS 3543#ifdef CONFIG_DEBUG_FS
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index c61cb9cedbcd..c5136bb1f982 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -159,27 +159,135 @@ static void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
159 } 159 }
160} 160}
161 161
162void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm) 162/*
163 * dapm_widget_invalidate_input_paths() - Invalidate the cached number of input
164 * paths
165 * @w: The widget for which to invalidate the cached number of input paths
166 *
167 * The function resets the cached number of inputs for the specified widget and
168 * all widgets that can be reached via outgoing paths from the widget.
169 *
170 * This function must be called if the number of input paths for a widget might
171 * have changed. E.g. if the source state of a widget changes or a path is added
172 * or activated with the widget as the sink.
173 */
174static void dapm_widget_invalidate_input_paths(struct snd_soc_dapm_widget *w)
175{
176 struct snd_soc_dapm_widget *sink;
177 struct snd_soc_dapm_path *p;
178 LIST_HEAD(list);
179
180 dapm_assert_locked(w->dapm);
181
182 if (w->inputs == -1)
183 return;
184
185 w->inputs = -1;
186 list_add_tail(&w->work_list, &list);
187
188 list_for_each_entry(w, &list, work_list) {
189 list_for_each_entry(p, &w->sinks, list_source) {
190 if (p->is_supply || p->weak || !p->connect)
191 continue;
192 sink = p->sink;
193 if (sink->inputs != -1) {
194 sink->inputs = -1;
195 list_add_tail(&sink->work_list, &list);
196 }
197 }
198 }
199}
200
201/*
202 * dapm_widget_invalidate_output_paths() - Invalidate the cached number of
203 * output paths
204 * @w: The widget for which to invalidate the cached number of output paths
205 *
206 * Resets the cached number of outputs for the specified widget and all widgets
207 * that can be reached via incoming paths from the widget.
208 *
209 * This function must be called if the number of output paths for a widget might
210 * have changed. E.g. if the sink state of a widget changes or a path is added
211 * or activated with the widget as the source.
212 */
213static void dapm_widget_invalidate_output_paths(struct snd_soc_dapm_widget *w)
214{
215 struct snd_soc_dapm_widget *source;
216 struct snd_soc_dapm_path *p;
217 LIST_HEAD(list);
218
219 dapm_assert_locked(w->dapm);
220
221 if (w->outputs == -1)
222 return;
223
224 w->outputs = -1;
225 list_add_tail(&w->work_list, &list);
226
227 list_for_each_entry(w, &list, work_list) {
228 list_for_each_entry(p, &w->sources, list_sink) {
229 if (p->is_supply || p->weak || !p->connect)
230 continue;
231 source = p->source;
232 if (source->outputs != -1) {
233 source->outputs = -1;
234 list_add_tail(&source->work_list, &list);
235 }
236 }
237 }
238}
239
240/*
241 * dapm_path_invalidate() - Invalidates the cached number of inputs and outputs
242 * for the widgets connected to a path
243 * @p: The path to invalidate
244 *
245 * Resets the cached number of inputs for the sink of the path and the cached
246 * number of outputs for the source of the path.
247 *
248 * This function must be called when a path is added, removed or the connected
249 * state changes.
250 */
251static void dapm_path_invalidate(struct snd_soc_dapm_path *p)
252{
253 /*
254 * Weak paths or supply paths do not influence the number of input or
255 * output paths of their neighbors.
256 */
257 if (p->weak || p->is_supply)
258 return;
259
260 /*
261 * The number of connected endpoints is the sum of the number of
262 * connected endpoints of all neighbors. If a node with 0 connected
263 * endpoints is either connected or disconnected that sum won't change,
264 * so there is no need to re-check the path.
265 */
266 if (p->source->inputs != 0)
267 dapm_widget_invalidate_input_paths(p->sink);
268 if (p->sink->outputs != 0)
269 dapm_widget_invalidate_output_paths(p->source);
270}
271
272void dapm_mark_endpoints_dirty(struct snd_soc_card *card)
163{ 273{
164 struct snd_soc_card *card = dapm->card;
165 struct snd_soc_dapm_widget *w; 274 struct snd_soc_dapm_widget *w;
166 275
167 mutex_lock(&card->dapm_mutex); 276 mutex_lock(&card->dapm_mutex);
168 277
169 list_for_each_entry(w, &card->widgets, list) { 278 list_for_each_entry(w, &card->widgets, list) {
170 switch (w->id) { 279 if (w->is_sink || w->is_source) {
171 case snd_soc_dapm_input: 280 dapm_mark_dirty(w, "Rechecking endpoints");
172 case snd_soc_dapm_output: 281 if (w->is_sink)
173 dapm_mark_dirty(w, "Rechecking inputs and outputs"); 282 dapm_widget_invalidate_output_paths(w);
174 break; 283 if (w->is_source)
175 default: 284 dapm_widget_invalidate_input_paths(w);
176 break;
177 } 285 }
178 } 286 }
179 287
180 mutex_unlock(&card->dapm_mutex); 288 mutex_unlock(&card->dapm_mutex);
181} 289}
182EXPORT_SYMBOL_GPL(dapm_mark_io_dirty); 290EXPORT_SYMBOL_GPL(dapm_mark_endpoints_dirty);
183 291
184/* create a new dapm widget */ 292/* create a new dapm widget */
185static inline struct snd_soc_dapm_widget *dapm_cnew_widget( 293static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
@@ -386,8 +494,6 @@ static void dapm_reset(struct snd_soc_card *card)
386 list_for_each_entry(w, &card->widgets, list) { 494 list_for_each_entry(w, &card->widgets, list) {
387 w->new_power = w->power; 495 w->new_power = w->power;
388 w->power_checked = false; 496 w->power_checked = false;
389 w->inputs = -1;
390 w->outputs = -1;
391 } 497 }
392} 498}
393 499
@@ -469,10 +575,9 @@ out:
469 575
470/* connect mux widget to its interconnecting audio paths */ 576/* connect mux widget to its interconnecting audio paths */
471static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, 577static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
472 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, 578 struct snd_soc_dapm_path *path, const char *control_name)
473 struct snd_soc_dapm_path *path, const char *control_name,
474 const struct snd_kcontrol_new *kcontrol)
475{ 579{
580 const struct snd_kcontrol_new *kcontrol = &path->sink->kcontrol_news[0];
476 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 581 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
477 unsigned int val, item; 582 unsigned int val, item;
478 int i; 583 int i;
@@ -493,10 +598,7 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
493 598
494 for (i = 0; i < e->items; i++) { 599 for (i = 0; i < e->items; i++) {
495 if (!(strcmp(control_name, e->texts[i]))) { 600 if (!(strcmp(control_name, e->texts[i]))) {
496 list_add(&path->list, &dapm->card->paths); 601 path->name = e->texts[i];
497 list_add(&path->list_sink, &dest->sources);
498 list_add(&path->list_source, &src->sinks);
499 path->name = (char*)e->texts[i];
500 if (i == item) 602 if (i == item)
501 path->connect = 1; 603 path->connect = 1;
502 else 604 else
@@ -509,11 +611,10 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
509} 611}
510 612
511/* set up initial codec paths */ 613/* set up initial codec paths */
512static void dapm_set_mixer_path_status(struct snd_soc_dapm_widget *w, 614static void dapm_set_mixer_path_status(struct snd_soc_dapm_path *p, int i)
513 struct snd_soc_dapm_path *p, int i)
514{ 615{
515 struct soc_mixer_control *mc = (struct soc_mixer_control *) 616 struct soc_mixer_control *mc = (struct soc_mixer_control *)
516 w->kcontrol_news[i].private_value; 617 p->sink->kcontrol_news[i].private_value;
517 unsigned int reg = mc->reg; 618 unsigned int reg = mc->reg;
518 unsigned int shift = mc->shift; 619 unsigned int shift = mc->shift;
519 unsigned int max = mc->max; 620 unsigned int max = mc->max;
@@ -522,7 +623,7 @@ static void dapm_set_mixer_path_status(struct snd_soc_dapm_widget *w,
522 unsigned int val; 623 unsigned int val;
523 624
524 if (reg != SND_SOC_NOPM) { 625 if (reg != SND_SOC_NOPM) {
525 soc_dapm_read(w->dapm, reg, &val); 626 soc_dapm_read(p->sink->dapm, reg, &val);
526 val = (val >> shift) & mask; 627 val = (val >> shift) & mask;
527 if (invert) 628 if (invert)
528 val = max - val; 629 val = max - val;
@@ -534,19 +635,15 @@ static void dapm_set_mixer_path_status(struct snd_soc_dapm_widget *w,
534 635
535/* connect mixer widget to its interconnecting audio paths */ 636/* connect mixer widget to its interconnecting audio paths */
536static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm, 637static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
537 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
538 struct snd_soc_dapm_path *path, const char *control_name) 638 struct snd_soc_dapm_path *path, const char *control_name)
539{ 639{
540 int i; 640 int i;
541 641
542 /* search for mixer kcontrol */ 642 /* search for mixer kcontrol */
543 for (i = 0; i < dest->num_kcontrols; i++) { 643 for (i = 0; i < path->sink->num_kcontrols; i++) {
544 if (!strcmp(control_name, dest->kcontrol_news[i].name)) { 644 if (!strcmp(control_name, path->sink->kcontrol_news[i].name)) {
545 list_add(&path->list, &dapm->card->paths); 645 path->name = path->sink->kcontrol_news[i].name;
546 list_add(&path->list_sink, &dest->sources); 646 dapm_set_mixer_path_status(path, i);
547 list_add(&path->list_source, &src->sinks);
548 path->name = dest->kcontrol_news[i].name;
549 dapm_set_mixer_path_status(dest, path, i);
550 return 0; 647 return 0;
551 } 648 }
552 } 649 }
@@ -738,8 +835,10 @@ static int dapm_new_mux(struct snd_soc_dapm_widget *w)
738 if (ret < 0) 835 if (ret < 0)
739 return ret; 836 return ret;
740 837
741 list_for_each_entry(path, &w->sources, list_sink) 838 list_for_each_entry(path, &w->sources, list_sink) {
742 dapm_kcontrol_add_path(w->kcontrols[0], path); 839 if (path->name)
840 dapm_kcontrol_add_path(w->kcontrols[0], path);
841 }
743 842
744 return 0; 843 return 0;
745} 844}
@@ -754,34 +853,6 @@ static int dapm_new_pga(struct snd_soc_dapm_widget *w)
754 return 0; 853 return 0;
755} 854}
756 855
757/* reset 'walked' bit for each dapm path */
758static void dapm_clear_walk_output(struct snd_soc_dapm_context *dapm,
759 struct list_head *sink)
760{
761 struct snd_soc_dapm_path *p;
762
763 list_for_each_entry(p, sink, list_source) {
764 if (p->walked) {
765 p->walked = 0;
766 dapm_clear_walk_output(dapm, &p->sink->sinks);
767 }
768 }
769}
770
771static void dapm_clear_walk_input(struct snd_soc_dapm_context *dapm,
772 struct list_head *source)
773{
774 struct snd_soc_dapm_path *p;
775
776 list_for_each_entry(p, source, list_sink) {
777 if (p->walked) {
778 p->walked = 0;
779 dapm_clear_walk_input(dapm, &p->source->sources);
780 }
781 }
782}
783
784
785/* We implement power down on suspend by checking the power state of 856/* We implement power down on suspend by checking the power state of
786 * the ALSA card - when we are suspending the ALSA state for the card 857 * the ALSA card - when we are suspending the ALSA state for the card
787 * is set to D3. 858 * is set to D3.
@@ -856,61 +927,23 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
856 927
857 DAPM_UPDATE_STAT(widget, path_checks); 928 DAPM_UPDATE_STAT(widget, path_checks);
858 929
859 switch (widget->id) { 930 if (widget->is_sink && widget->connected) {
860 case snd_soc_dapm_supply: 931 widget->outputs = snd_soc_dapm_suspend_check(widget);
861 case snd_soc_dapm_regulator_supply: 932 return widget->outputs;
862 case snd_soc_dapm_clock_supply:
863 case snd_soc_dapm_kcontrol:
864 return 0;
865 default:
866 break;
867 }
868
869 switch (widget->id) {
870 case snd_soc_dapm_adc:
871 case snd_soc_dapm_aif_out:
872 case snd_soc_dapm_dai_out:
873 if (widget->active) {
874 widget->outputs = snd_soc_dapm_suspend_check(widget);
875 return widget->outputs;
876 }
877 default:
878 break;
879 }
880
881 if (widget->connected) {
882 /* connected pin ? */
883 if (widget->id == snd_soc_dapm_output && !widget->ext) {
884 widget->outputs = snd_soc_dapm_suspend_check(widget);
885 return widget->outputs;
886 }
887
888 /* connected jack or spk ? */
889 if (widget->id == snd_soc_dapm_hp ||
890 widget->id == snd_soc_dapm_spk ||
891 (widget->id == snd_soc_dapm_line &&
892 !list_empty(&widget->sources))) {
893 widget->outputs = snd_soc_dapm_suspend_check(widget);
894 return widget->outputs;
895 }
896 } 933 }
897 934
898 list_for_each_entry(path, &widget->sinks, list_source) { 935 list_for_each_entry(path, &widget->sinks, list_source) {
899 DAPM_UPDATE_STAT(widget, neighbour_checks); 936 DAPM_UPDATE_STAT(widget, neighbour_checks);
900 937
901 if (path->weak) 938 if (path->weak || path->is_supply)
902 continue; 939 continue;
903 940
904 if (path->walking) 941 if (path->walking)
905 return 1; 942 return 1;
906 943
907 if (path->walked)
908 continue;
909
910 trace_snd_soc_dapm_output_path(widget, path); 944 trace_snd_soc_dapm_output_path(widget, path);
911 945
912 if (path->sink && path->connect) { 946 if (path->connect) {
913 path->walked = 1;
914 path->walking = 1; 947 path->walking = 1;
915 948
916 /* do we need to add this widget to the list ? */ 949 /* do we need to add this widget to the list ? */
@@ -952,73 +985,23 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
952 985
953 DAPM_UPDATE_STAT(widget, path_checks); 986 DAPM_UPDATE_STAT(widget, path_checks);
954 987
955 switch (widget->id) { 988 if (widget->is_source && widget->connected) {
956 case snd_soc_dapm_supply: 989 widget->inputs = snd_soc_dapm_suspend_check(widget);
957 case snd_soc_dapm_regulator_supply: 990 return widget->inputs;
958 case snd_soc_dapm_clock_supply:
959 case snd_soc_dapm_kcontrol:
960 return 0;
961 default:
962 break;
963 }
964
965 /* active stream ? */
966 switch (widget->id) {
967 case snd_soc_dapm_dac:
968 case snd_soc_dapm_aif_in:
969 case snd_soc_dapm_dai_in:
970 if (widget->active) {
971 widget->inputs = snd_soc_dapm_suspend_check(widget);
972 return widget->inputs;
973 }
974 default:
975 break;
976 }
977
978 if (widget->connected) {
979 /* connected pin ? */
980 if (widget->id == snd_soc_dapm_input && !widget->ext) {
981 widget->inputs = snd_soc_dapm_suspend_check(widget);
982 return widget->inputs;
983 }
984
985 /* connected VMID/Bias for lower pops */
986 if (widget->id == snd_soc_dapm_vmid) {
987 widget->inputs = snd_soc_dapm_suspend_check(widget);
988 return widget->inputs;
989 }
990
991 /* connected jack ? */
992 if (widget->id == snd_soc_dapm_mic ||
993 (widget->id == snd_soc_dapm_line &&
994 !list_empty(&widget->sinks))) {
995 widget->inputs = snd_soc_dapm_suspend_check(widget);
996 return widget->inputs;
997 }
998
999 /* signal generator */
1000 if (widget->id == snd_soc_dapm_siggen) {
1001 widget->inputs = snd_soc_dapm_suspend_check(widget);
1002 return widget->inputs;
1003 }
1004 } 991 }
1005 992
1006 list_for_each_entry(path, &widget->sources, list_sink) { 993 list_for_each_entry(path, &widget->sources, list_sink) {
1007 DAPM_UPDATE_STAT(widget, neighbour_checks); 994 DAPM_UPDATE_STAT(widget, neighbour_checks);
1008 995
1009 if (path->weak) 996 if (path->weak || path->is_supply)
1010 continue; 997 continue;
1011 998
1012 if (path->walking) 999 if (path->walking)
1013 return 1; 1000 return 1;
1014 1001
1015 if (path->walked)
1016 continue;
1017
1018 trace_snd_soc_dapm_input_path(widget, path); 1002 trace_snd_soc_dapm_input_path(widget, path);
1019 1003
1020 if (path->source && path->connect) { 1004 if (path->connect) {
1021 path->walked = 1;
1022 path->walking = 1; 1005 path->walking = 1;
1023 1006
1024 /* do we need to add this widget to the list ? */ 1007 /* do we need to add this widget to the list ? */
@@ -1060,21 +1043,25 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
1060int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, 1043int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
1061 struct snd_soc_dapm_widget_list **list) 1044 struct snd_soc_dapm_widget_list **list)
1062{ 1045{
1063 struct snd_soc_card *card = dai->card; 1046 struct snd_soc_card *card = dai->component->card;
1047 struct snd_soc_dapm_widget *w;
1064 int paths; 1048 int paths;
1065 1049
1066 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 1050 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1067 dapm_reset(card);
1068 1051
1069 if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 1052 /*
1053 * For is_connected_{output,input}_ep fully discover the graph we need
1054 * to reset the cached number of inputs and outputs.
1055 */
1056 list_for_each_entry(w, &card->widgets, list) {
1057 w->inputs = -1;
1058 w->outputs = -1;
1059 }
1060
1061 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1070 paths = is_connected_output_ep(dai->playback_widget, list); 1062 paths = is_connected_output_ep(dai->playback_widget, list);
1071 dapm_clear_walk_output(&card->dapm, 1063 else
1072 &dai->playback_widget->sinks);
1073 } else {
1074 paths = is_connected_input_ep(dai->capture_widget, list); 1064 paths = is_connected_input_ep(dai->capture_widget, list);
1075 dapm_clear_walk_input(&card->dapm,
1076 &dai->capture_widget->sources);
1077 }
1078 1065
1079 trace_snd_soc_dapm_connected(paths, stream); 1066 trace_snd_soc_dapm_connected(paths, stream);
1080 mutex_unlock(&card->dapm_mutex); 1067 mutex_unlock(&card->dapm_mutex);
@@ -1163,44 +1150,10 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
1163 DAPM_UPDATE_STAT(w, power_checks); 1150 DAPM_UPDATE_STAT(w, power_checks);
1164 1151
1165 in = is_connected_input_ep(w, NULL); 1152 in = is_connected_input_ep(w, NULL);
1166 dapm_clear_walk_input(w->dapm, &w->sources);
1167 out = is_connected_output_ep(w, NULL); 1153 out = is_connected_output_ep(w, NULL);
1168 dapm_clear_walk_output(w->dapm, &w->sinks);
1169 return out != 0 && in != 0; 1154 return out != 0 && in != 0;
1170} 1155}
1171 1156
1172/* Check to see if an ADC has power */
1173static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
1174{
1175 int in;
1176
1177 DAPM_UPDATE_STAT(w, power_checks);
1178
1179 if (w->active) {
1180 in = is_connected_input_ep(w, NULL);
1181 dapm_clear_walk_input(w->dapm, &w->sources);
1182 return in != 0;
1183 } else {
1184 return dapm_generic_check_power(w);
1185 }
1186}
1187
1188/* Check to see if a DAC has power */
1189static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
1190{
1191 int out;
1192
1193 DAPM_UPDATE_STAT(w, power_checks);
1194
1195 if (w->active) {
1196 out = is_connected_output_ep(w, NULL);
1197 dapm_clear_walk_output(w->dapm, &w->sinks);
1198 return out != 0;
1199 } else {
1200 return dapm_generic_check_power(w);
1201 }
1202}
1203
1204/* Check to see if a power supply is needed */ 1157/* Check to see if a power supply is needed */
1205static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) 1158static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
1206{ 1159{
@@ -1219,9 +1172,6 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
1219 !path->connected(path->source, path->sink)) 1172 !path->connected(path->source, path->sink))
1220 continue; 1173 continue;
1221 1174
1222 if (!path->sink)
1223 continue;
1224
1225 if (dapm_widget_power_check(path->sink)) 1175 if (dapm_widget_power_check(path->sink))
1226 return 1; 1176 return 1;
1227 } 1177 }
@@ -1636,27 +1586,14 @@ static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1636 /* If we changed our power state perhaps our neigbours changed 1586 /* If we changed our power state perhaps our neigbours changed
1637 * also. 1587 * also.
1638 */ 1588 */
1639 list_for_each_entry(path, &w->sources, list_sink) { 1589 list_for_each_entry(path, &w->sources, list_sink)
1640 if (path->source) { 1590 dapm_widget_set_peer_power(path->source, power, path->connect);
1641 dapm_widget_set_peer_power(path->source, power, 1591
1592 /* Supplies can't affect their outputs, only their inputs */
1593 if (!w->is_supply) {
1594 list_for_each_entry(path, &w->sinks, list_source)
1595 dapm_widget_set_peer_power(path->sink, power,
1642 path->connect); 1596 path->connect);
1643 }
1644 }
1645 switch (w->id) {
1646 case snd_soc_dapm_supply:
1647 case snd_soc_dapm_regulator_supply:
1648 case snd_soc_dapm_clock_supply:
1649 case snd_soc_dapm_kcontrol:
1650 /* Supplies can't affect their outputs, only their inputs */
1651 break;
1652 default:
1653 list_for_each_entry(path, &w->sinks, list_source) {
1654 if (path->sink) {
1655 dapm_widget_set_peer_power(path->sink, power,
1656 path->connect);
1657 }
1658 }
1659 break;
1660 } 1597 }
1661 1598
1662 if (power) 1599 if (power)
@@ -1863,10 +1800,14 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1863 if (!buf) 1800 if (!buf)
1864 return -ENOMEM; 1801 return -ENOMEM;
1865 1802
1866 in = is_connected_input_ep(w, NULL); 1803 /* Supply widgets are not handled by is_connected_{input,output}_ep() */
1867 dapm_clear_walk_input(w->dapm, &w->sources); 1804 if (w->is_supply) {
1868 out = is_connected_output_ep(w, NULL); 1805 in = 0;
1869 dapm_clear_walk_output(w->dapm, &w->sinks); 1806 out = 0;
1807 } else {
1808 in = is_connected_input_ep(w, NULL);
1809 out = is_connected_output_ep(w, NULL);
1810 }
1870 1811
1871 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", 1812 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
1872 w->name, w->power ? "On" : "Off", 1813 w->name, w->power ? "On" : "Off",
@@ -2011,32 +1952,45 @@ static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
2011 1952
2012#endif 1953#endif
2013 1954
1955/*
1956 * soc_dapm_connect_path() - Connects or disconnects a path
1957 * @path: The path to update
1958 * @connect: The new connect state of the path. True if the path is connected,
1959 * false if it is disconneted.
1960 * @reason: The reason why the path changed (for debugging only)
1961 */
1962static void soc_dapm_connect_path(struct snd_soc_dapm_path *path,
1963 bool connect, const char *reason)
1964{
1965 if (path->connect == connect)
1966 return;
1967
1968 path->connect = connect;
1969 dapm_mark_dirty(path->source, reason);
1970 dapm_mark_dirty(path->sink, reason);
1971 dapm_path_invalidate(path);
1972}
1973
2014/* test and update the power status of a mux widget */ 1974/* test and update the power status of a mux widget */
2015static int soc_dapm_mux_update_power(struct snd_soc_card *card, 1975static int soc_dapm_mux_update_power(struct snd_soc_card *card,
2016 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e) 1976 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
2017{ 1977{
2018 struct snd_soc_dapm_path *path; 1978 struct snd_soc_dapm_path *path;
2019 int found = 0; 1979 int found = 0;
1980 bool connect;
2020 1981
2021 lockdep_assert_held(&card->dapm_mutex); 1982 lockdep_assert_held(&card->dapm_mutex);
2022 1983
2023 /* find dapm widget path assoc with kcontrol */ 1984 /* find dapm widget path assoc with kcontrol */
2024 dapm_kcontrol_for_each_path(path, kcontrol) { 1985 dapm_kcontrol_for_each_path(path, kcontrol) {
2025 if (!path->name || !e->texts[mux])
2026 continue;
2027
2028 found = 1; 1986 found = 1;
2029 /* we now need to match the string in the enum to the path */ 1987 /* we now need to match the string in the enum to the path */
2030 if (!(strcmp(path->name, e->texts[mux]))) { 1988 if (!(strcmp(path->name, e->texts[mux])))
2031 path->connect = 1; /* new connection */ 1989 connect = true;
2032 dapm_mark_dirty(path->source, "mux connection"); 1990 else
2033 } else { 1991 connect = false;
2034 if (path->connect) 1992
2035 dapm_mark_dirty(path->source, 1993 soc_dapm_connect_path(path, connect, "mux update");
2036 "mux disconnection");
2037 path->connect = 0; /* old connection must be powered down */
2038 }
2039 dapm_mark_dirty(path->sink, "mux change");
2040 } 1994 }
2041 1995
2042 if (found) 1996 if (found)
@@ -2075,9 +2029,7 @@ static int soc_dapm_mixer_update_power(struct snd_soc_card *card,
2075 /* find dapm widget path assoc with kcontrol */ 2029 /* find dapm widget path assoc with kcontrol */
2076 dapm_kcontrol_for_each_path(path, kcontrol) { 2030 dapm_kcontrol_for_each_path(path, kcontrol) {
2077 found = 1; 2031 found = 1;
2078 path->connect = connect; 2032 soc_dapm_connect_path(path, connect, "mixer update");
2079 dapm_mark_dirty(path->source, "mixer connection");
2080 dapm_mark_dirty(path->sink, "mixer update");
2081 } 2033 }
2082 2034
2083 if (found) 2035 if (found)
@@ -2255,8 +2207,11 @@ static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2255 return -EINVAL; 2207 return -EINVAL;
2256 } 2208 }
2257 2209
2258 if (w->connected != status) 2210 if (w->connected != status) {
2259 dapm_mark_dirty(w, "pin configuration"); 2211 dapm_mark_dirty(w, "pin configuration");
2212 dapm_widget_invalidate_input_paths(w);
2213 dapm_widget_invalidate_output_paths(w);
2214 }
2260 2215
2261 w->connected = status; 2216 w->connected = status;
2262 if (status == 0) 2217 if (status == 0)
@@ -2309,6 +2264,53 @@ int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2309} 2264}
2310EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); 2265EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
2311 2266
2267/*
2268 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2269 * @w: The widget for which to update the flags
2270 *
2271 * Some widgets have a dynamic category which depends on which neighbors they
2272 * are connected to. This function update the category for these widgets.
2273 *
2274 * This function must be called whenever a path is added or removed to a widget.
2275 */
2276static void dapm_update_widget_flags(struct snd_soc_dapm_widget *w)
2277{
2278 struct snd_soc_dapm_path *p;
2279
2280 switch (w->id) {
2281 case snd_soc_dapm_input:
2282 w->is_source = 1;
2283 list_for_each_entry(p, &w->sources, list_sink) {
2284 if (p->source->id == snd_soc_dapm_micbias ||
2285 p->source->id == snd_soc_dapm_mic ||
2286 p->source->id == snd_soc_dapm_line ||
2287 p->source->id == snd_soc_dapm_output) {
2288 w->is_source = 0;
2289 break;
2290 }
2291 }
2292 break;
2293 case snd_soc_dapm_output:
2294 w->is_sink = 1;
2295 list_for_each_entry(p, &w->sinks, list_source) {
2296 if (p->sink->id == snd_soc_dapm_spk ||
2297 p->sink->id == snd_soc_dapm_hp ||
2298 p->sink->id == snd_soc_dapm_line ||
2299 p->sink->id == snd_soc_dapm_input) {
2300 w->is_sink = 0;
2301 break;
2302 }
2303 }
2304 break;
2305 case snd_soc_dapm_line:
2306 w->is_sink = !list_empty(&w->sources);
2307 w->is_source = !list_empty(&w->sinks);
2308 break;
2309 default:
2310 break;
2311 }
2312}
2313
2312static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm, 2314static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2313 struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink, 2315 struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink,
2314 const char *control, 2316 const char *control,
@@ -2318,6 +2320,27 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2318 struct snd_soc_dapm_path *path; 2320 struct snd_soc_dapm_path *path;
2319 int ret; 2321 int ret;
2320 2322
2323 if (wsink->is_supply && !wsource->is_supply) {
2324 dev_err(dapm->dev,
2325 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n",
2326 wsource->name, wsink->name);
2327 return -EINVAL;
2328 }
2329
2330 if (connected && !wsource->is_supply) {
2331 dev_err(dapm->dev,
2332 "connected() callback only supported for supply widgets (%s -> %s)\n",
2333 wsource->name, wsink->name);
2334 return -EINVAL;
2335 }
2336
2337 if (wsource->is_supply && control) {
2338 dev_err(dapm->dev,
2339 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n",
2340 wsource->name, control, wsink->name);
2341 return -EINVAL;
2342 }
2343
2321 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); 2344 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2322 if (!path) 2345 if (!path)
2323 return -ENOMEM; 2346 return -ENOMEM;
@@ -2330,85 +2353,49 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2330 INIT_LIST_HEAD(&path->list_source); 2353 INIT_LIST_HEAD(&path->list_source);
2331 INIT_LIST_HEAD(&path->list_sink); 2354 INIT_LIST_HEAD(&path->list_sink);
2332 2355
2333 /* check for external widgets */ 2356 if (wsource->is_supply || wsink->is_supply)
2334 if (wsink->id == snd_soc_dapm_input) { 2357 path->is_supply = 1;
2335 if (wsource->id == snd_soc_dapm_micbias ||
2336 wsource->id == snd_soc_dapm_mic ||
2337 wsource->id == snd_soc_dapm_line ||
2338 wsource->id == snd_soc_dapm_output)
2339 wsink->ext = 1;
2340 }
2341 if (wsource->id == snd_soc_dapm_output) {
2342 if (wsink->id == snd_soc_dapm_spk ||
2343 wsink->id == snd_soc_dapm_hp ||
2344 wsink->id == snd_soc_dapm_line ||
2345 wsink->id == snd_soc_dapm_input)
2346 wsource->ext = 1;
2347 }
2348
2349 dapm_mark_dirty(wsource, "Route added");
2350 dapm_mark_dirty(wsink, "Route added");
2351 2358
2352 /* connect static paths */ 2359 /* connect static paths */
2353 if (control == NULL) { 2360 if (control == NULL) {
2354 list_add(&path->list, &dapm->card->paths);
2355 list_add(&path->list_sink, &wsink->sources);
2356 list_add(&path->list_source, &wsource->sinks);
2357 path->connect = 1; 2361 path->connect = 1;
2358 return 0; 2362 } else {
2359 } 2363 /* connect dynamic paths */
2360 2364 switch (wsink->id) {
2361 /* connect dynamic paths */ 2365 case snd_soc_dapm_mux:
2362 switch (wsink->id) { 2366 ret = dapm_connect_mux(dapm, path, control);
2363 case snd_soc_dapm_adc: 2367 if (ret != 0)
2364 case snd_soc_dapm_dac: 2368 goto err;
2365 case snd_soc_dapm_pga: 2369 break;
2366 case snd_soc_dapm_out_drv: 2370 case snd_soc_dapm_switch:
2367 case snd_soc_dapm_input: 2371 case snd_soc_dapm_mixer:
2368 case snd_soc_dapm_output: 2372 case snd_soc_dapm_mixer_named_ctl:
2369 case snd_soc_dapm_siggen: 2373 ret = dapm_connect_mixer(dapm, path, control);
2370 case snd_soc_dapm_micbias: 2374 if (ret != 0)
2371 case snd_soc_dapm_vmid: 2375 goto err;
2372 case snd_soc_dapm_pre: 2376 break;
2373 case snd_soc_dapm_post: 2377 default:
2374 case snd_soc_dapm_supply: 2378 dev_err(dapm->dev,
2375 case snd_soc_dapm_regulator_supply: 2379 "Control not supported for path %s -> [%s] -> %s\n",
2376 case snd_soc_dapm_clock_supply: 2380 wsource->name, control, wsink->name);
2377 case snd_soc_dapm_aif_in: 2381 ret = -EINVAL;
2378 case snd_soc_dapm_aif_out:
2379 case snd_soc_dapm_dai_in:
2380 case snd_soc_dapm_dai_out:
2381 case snd_soc_dapm_dai_link:
2382 case snd_soc_dapm_kcontrol:
2383 list_add(&path->list, &dapm->card->paths);
2384 list_add(&path->list_sink, &wsink->sources);
2385 list_add(&path->list_source, &wsource->sinks);
2386 path->connect = 1;
2387 return 0;
2388 case snd_soc_dapm_mux:
2389 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2390 &wsink->kcontrol_news[0]);
2391 if (ret != 0)
2392 goto err;
2393 break;
2394 case snd_soc_dapm_switch:
2395 case snd_soc_dapm_mixer:
2396 case snd_soc_dapm_mixer_named_ctl:
2397 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
2398 if (ret != 0)
2399 goto err; 2382 goto err;
2400 break; 2383 }
2401 case snd_soc_dapm_hp:
2402 case snd_soc_dapm_mic:
2403 case snd_soc_dapm_line:
2404 case snd_soc_dapm_spk:
2405 list_add(&path->list, &dapm->card->paths);
2406 list_add(&path->list_sink, &wsink->sources);
2407 list_add(&path->list_source, &wsource->sinks);
2408 path->connect = 0;
2409 return 0;
2410 } 2384 }
2411 2385
2386 list_add(&path->list, &dapm->card->paths);
2387 list_add(&path->list_sink, &wsink->sources);
2388 list_add(&path->list_source, &wsource->sinks);
2389
2390 dapm_update_widget_flags(wsource);
2391 dapm_update_widget_flags(wsink);
2392
2393 dapm_mark_dirty(wsource, "Route added");
2394 dapm_mark_dirty(wsink, "Route added");
2395
2396 if (dapm->card->instantiated && path->connect)
2397 dapm_path_invalidate(path);
2398
2412 return 0; 2399 return 0;
2413err: 2400err:
2414 kfree(path); 2401 kfree(path);
@@ -2489,6 +2476,7 @@ err:
2489static int snd_soc_dapm_del_route(struct snd_soc_dapm_context *dapm, 2476static int snd_soc_dapm_del_route(struct snd_soc_dapm_context *dapm,
2490 const struct snd_soc_dapm_route *route) 2477 const struct snd_soc_dapm_route *route)
2491{ 2478{
2479 struct snd_soc_dapm_widget *wsource, *wsink;
2492 struct snd_soc_dapm_path *path, *p; 2480 struct snd_soc_dapm_path *path, *p;
2493 const char *sink; 2481 const char *sink;
2494 const char *source; 2482 const char *source;
@@ -2526,10 +2514,19 @@ static int snd_soc_dapm_del_route(struct snd_soc_dapm_context *dapm,
2526 } 2514 }
2527 2515
2528 if (path) { 2516 if (path) {
2529 dapm_mark_dirty(path->source, "Route removed"); 2517 wsource = path->source;
2530 dapm_mark_dirty(path->sink, "Route removed"); 2518 wsink = path->sink;
2519
2520 dapm_mark_dirty(wsource, "Route removed");
2521 dapm_mark_dirty(wsink, "Route removed");
2522 if (path->connect)
2523 dapm_path_invalidate(path);
2531 2524
2532 dapm_free_path(path); 2525 dapm_free_path(path);
2526
2527 /* Update any path related flags */
2528 dapm_update_widget_flags(wsource);
2529 dapm_update_widget_flags(wsink);
2533 } else { 2530 } else {
2534 dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n", 2531 dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n",
2535 source, sink); 2532 source, sink);
@@ -3087,40 +3084,44 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3087 } 3084 }
3088 3085
3089 switch (w->id) { 3086 switch (w->id) {
3090 case snd_soc_dapm_switch: 3087 case snd_soc_dapm_mic:
3091 case snd_soc_dapm_mixer: 3088 case snd_soc_dapm_input:
3092 case snd_soc_dapm_mixer_named_ctl: 3089 w->is_source = 1;
3093 w->power_check = dapm_generic_check_power; 3090 w->power_check = dapm_generic_check_power;
3094 break; 3091 break;
3095 case snd_soc_dapm_mux: 3092 case snd_soc_dapm_spk:
3093 case snd_soc_dapm_hp:
3094 case snd_soc_dapm_output:
3095 w->is_sink = 1;
3096 w->power_check = dapm_generic_check_power; 3096 w->power_check = dapm_generic_check_power;
3097 break; 3097 break;
3098 case snd_soc_dapm_dai_out: 3098 case snd_soc_dapm_vmid:
3099 w->power_check = dapm_adc_check_power; 3099 case snd_soc_dapm_siggen:
3100 break; 3100 w->is_source = 1;
3101 case snd_soc_dapm_dai_in: 3101 w->power_check = dapm_always_on_check_power;
3102 w->power_check = dapm_dac_check_power;
3103 break; 3102 break;
3103 case snd_soc_dapm_mux:
3104 case snd_soc_dapm_switch:
3105 case snd_soc_dapm_mixer:
3106 case snd_soc_dapm_mixer_named_ctl:
3104 case snd_soc_dapm_adc: 3107 case snd_soc_dapm_adc:
3105 case snd_soc_dapm_aif_out: 3108 case snd_soc_dapm_aif_out:
3106 case snd_soc_dapm_dac: 3109 case snd_soc_dapm_dac:
3107 case snd_soc_dapm_aif_in: 3110 case snd_soc_dapm_aif_in:
3108 case snd_soc_dapm_pga: 3111 case snd_soc_dapm_pga:
3109 case snd_soc_dapm_out_drv: 3112 case snd_soc_dapm_out_drv:
3110 case snd_soc_dapm_input:
3111 case snd_soc_dapm_output:
3112 case snd_soc_dapm_micbias: 3113 case snd_soc_dapm_micbias:
3113 case snd_soc_dapm_spk:
3114 case snd_soc_dapm_hp:
3115 case snd_soc_dapm_mic:
3116 case snd_soc_dapm_line: 3114 case snd_soc_dapm_line:
3117 case snd_soc_dapm_dai_link: 3115 case snd_soc_dapm_dai_link:
3116 case snd_soc_dapm_dai_out:
3117 case snd_soc_dapm_dai_in:
3118 w->power_check = dapm_generic_check_power; 3118 w->power_check = dapm_generic_check_power;
3119 break; 3119 break;
3120 case snd_soc_dapm_supply: 3120 case snd_soc_dapm_supply:
3121 case snd_soc_dapm_regulator_supply: 3121 case snd_soc_dapm_regulator_supply:
3122 case snd_soc_dapm_clock_supply: 3122 case snd_soc_dapm_clock_supply:
3123 case snd_soc_dapm_kcontrol: 3123 case snd_soc_dapm_kcontrol:
3124 w->is_supply = 1;
3124 w->power_check = dapm_supply_check_power; 3125 w->power_check = dapm_supply_check_power;
3125 break; 3126 break;
3126 default: 3127 default:
@@ -3137,6 +3138,9 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3137 INIT_LIST_HEAD(&w->dirty); 3138 INIT_LIST_HEAD(&w->dirty);
3138 list_add(&w->list, &dapm->card->widgets); 3139 list_add(&w->list, &dapm->card->widgets);
3139 3140
3141 w->inputs = -1;
3142 w->outputs = -1;
3143
3140 /* machine layer set ups unconnected pins and insertions */ 3144 /* machine layer set ups unconnected pins and insertions */
3141 w->connected = 1; 3145 w->connected = 1;
3142 return w; 3146 return w;
@@ -3484,6 +3488,14 @@ static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream,
3484 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: 3488 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3485 break; 3489 break;
3486 } 3490 }
3491
3492 if (w->id == snd_soc_dapm_dai_in) {
3493 w->is_source = w->active;
3494 dapm_widget_invalidate_input_paths(w);
3495 } else {
3496 w->is_sink = w->active;
3497 dapm_widget_invalidate_output_paths(w);
3498 }
3487 } 3499 }
3488} 3500}
3489 3501
@@ -3610,7 +3622,15 @@ int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
3610 } 3622 }
3611 3623
3612 dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin); 3624 dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin);
3613 w->connected = 1; 3625 if (!w->connected) {
3626 /*
3627 * w->force does not affect the number of input or output paths,
3628 * so we only have to recheck if w->connected is changed
3629 */
3630 dapm_widget_invalidate_input_paths(w);
3631 dapm_widget_invalidate_output_paths(w);
3632 w->connected = 1;
3633 }
3614 w->force = 1; 3634 w->force = 1;
3615 dapm_mark_dirty(w, "force enable"); 3635 dapm_mark_dirty(w, "force enable");
3616 3636
@@ -3788,35 +3808,54 @@ int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
3788} 3808}
3789EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); 3809EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
3790 3810
3811/**
3812 * dapm_is_external_path() - Checks if a path is a external path
3813 * @card: The card the path belongs to
3814 * @path: The path to check
3815 *
3816 * Returns true if the path is either between two different DAPM contexts or
3817 * between two external pins of the same DAPM context. Otherwise returns
3818 * false.
3819 */
3820static bool dapm_is_external_path(struct snd_soc_card *card,
3821 struct snd_soc_dapm_path *path)
3822{
3823 dev_dbg(card->dev,
3824 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3825 path->source->name, path->source->id, path->source->dapm,
3826 path->sink->name, path->sink->id, path->sink->dapm);
3827
3828 /* Connection between two different DAPM contexts */
3829 if (path->source->dapm != path->sink->dapm)
3830 return true;
3831
3832 /* Loopback connection from external pin to external pin */
3833 if (path->sink->id == snd_soc_dapm_input) {
3834 switch (path->source->id) {
3835 case snd_soc_dapm_output:
3836 case snd_soc_dapm_micbias:
3837 return true;
3838 default:
3839 break;
3840 }
3841 }
3842
3843 return false;
3844}
3845
3791static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card, 3846static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
3792 struct snd_soc_dapm_widget *w) 3847 struct snd_soc_dapm_widget *w)
3793{ 3848{
3794 struct snd_soc_dapm_path *p; 3849 struct snd_soc_dapm_path *p;
3795 3850
3796 list_for_each_entry(p, &card->paths, list) { 3851 list_for_each_entry(p, &w->sources, list_sink) {
3797 if ((p->source == w) || (p->sink == w)) { 3852 if (dapm_is_external_path(card, p))
3798 dev_dbg(card->dev, 3853 return true;
3799 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n", 3854 }
3800 p->source->name, p->source->id, p->source->dapm,
3801 p->sink->name, p->sink->id, p->sink->dapm);
3802 3855
3803 /* Connected to something other than the codec */ 3856 list_for_each_entry(p, &w->sinks, list_source) {
3804 if (p->source->dapm != p->sink->dapm) 3857 if (dapm_is_external_path(card, p))
3805 return true; 3858 return true;
3806 /*
3807 * Loopback connection from codec external pin to
3808 * codec external pin
3809 */
3810 if (p->sink->id == snd_soc_dapm_input) {
3811 switch (p->source->id) {
3812 case snd_soc_dapm_output:
3813 case snd_soc_dapm_micbias:
3814 return true;
3815 default:
3816 break;
3817 }
3818 }
3819 }
3820 } 3859 }
3821 3860
3822 return false; 3861 return false;
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index ab47fea997a3..4380dcc064a5 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -116,7 +116,7 @@ EXPORT_SYMBOL_GPL(snd_soc_jack_report);
116 * 116 *
117 * @jack: ASoC jack 117 * @jack: ASoC jack
118 * @count: Number of zones 118 * @count: Number of zones
119 * @zone: Array of zones 119 * @zones: Array of zones
120 * 120 *
121 * After this function has been called the zones specified in the 121 * After this function has been called the zones specified in the
122 * array will be associated with the jack. 122 * array will be associated with the jack.
@@ -309,7 +309,7 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
309 /* GPIO descriptor */ 309 /* GPIO descriptor */
310 gpios[i].desc = gpiod_get_index(gpios[i].gpiod_dev, 310 gpios[i].desc = gpiod_get_index(gpios[i].gpiod_dev,
311 gpios[i].name, 311 gpios[i].name,
312 gpios[i].idx); 312 gpios[i].idx, GPIOD_IN);
313 if (IS_ERR(gpios[i].desc)) { 313 if (IS_ERR(gpios[i].desc)) {
314 ret = PTR_ERR(gpios[i].desc); 314 ret = PTR_ERR(gpios[i].desc);
315 dev_err(gpios[i].gpiod_dev, 315 dev_err(gpios[i].gpiod_dev,
@@ -327,17 +327,14 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
327 goto undo; 327 goto undo;
328 } 328 }
329 329
330 ret = gpio_request(gpios[i].gpio, gpios[i].name); 330 ret = gpio_request_one(gpios[i].gpio, GPIOF_IN,
331 gpios[i].name);
331 if (ret) 332 if (ret)
332 goto undo; 333 goto undo;
333 334
334 gpios[i].desc = gpio_to_desc(gpios[i].gpio); 335 gpios[i].desc = gpio_to_desc(gpios[i].gpio);
335 } 336 }
336 337
337 ret = gpiod_direction_input(gpios[i].desc);
338 if (ret)
339 goto err;
340
341 INIT_DELAYED_WORK(&gpios[i].work, gpio_work); 338 INIT_DELAYED_WORK(&gpios[i].work, gpio_work);
342 gpios[i].jack = jack; 339 gpios[i].jack = jack;
343 340
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
new file mode 100644
index 000000000000..100d92b5b77e
--- /dev/null
+++ b/sound/soc/soc-ops.c
@@ -0,0 +1,952 @@
1/*
2 * soc-ops.c -- Generic ASoC operations
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
8 *
9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10 * with code, comments and ideas from :-
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/moduleparam.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/pm.h>
24#include <linux/bitops.h>
25#include <linux/ctype.h>
26#include <linux/slab.h>
27#include <sound/core.h>
28#include <sound/jack.h>
29#include <sound/pcm.h>
30#include <sound/pcm_params.h>
31#include <sound/soc.h>
32#include <sound/soc-dpcm.h>
33#include <sound/initval.h>
34
35/**
36 * snd_soc_info_enum_double - enumerated double mixer info callback
37 * @kcontrol: mixer control
38 * @uinfo: control element information
39 *
40 * Callback to provide information about a double enumerated
41 * mixer control.
42 *
43 * Returns 0 for success.
44 */
45int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
46 struct snd_ctl_elem_info *uinfo)
47{
48 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
49
50 return snd_ctl_enum_info(uinfo, e->shift_l == e->shift_r ? 1 : 2,
51 e->items, e->texts);
52}
53EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
54
55/**
56 * snd_soc_get_enum_double - enumerated double mixer get callback
57 * @kcontrol: mixer control
58 * @ucontrol: control element information
59 *
60 * Callback to get the value of a double enumerated mixer.
61 *
62 * Returns 0 for success.
63 */
64int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
65 struct snd_ctl_elem_value *ucontrol)
66{
67 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
68 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
69 unsigned int val, item;
70 unsigned int reg_val;
71 int ret;
72
73 ret = snd_soc_component_read(component, e->reg, &reg_val);
74 if (ret)
75 return ret;
76 val = (reg_val >> e->shift_l) & e->mask;
77 item = snd_soc_enum_val_to_item(e, val);
78 ucontrol->value.enumerated.item[0] = item;
79 if (e->shift_l != e->shift_r) {
80 val = (reg_val >> e->shift_l) & e->mask;
81 item = snd_soc_enum_val_to_item(e, val);
82 ucontrol->value.enumerated.item[1] = item;
83 }
84
85 return 0;
86}
87EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
88
89/**
90 * snd_soc_put_enum_double - enumerated double mixer put callback
91 * @kcontrol: mixer control
92 * @ucontrol: control element information
93 *
94 * Callback to set the value of a double enumerated mixer.
95 *
96 * Returns 0 for success.
97 */
98int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
99 struct snd_ctl_elem_value *ucontrol)
100{
101 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
102 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
103 unsigned int *item = ucontrol->value.enumerated.item;
104 unsigned int val;
105 unsigned int mask;
106
107 if (item[0] >= e->items)
108 return -EINVAL;
109 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
110 mask = e->mask << e->shift_l;
111 if (e->shift_l != e->shift_r) {
112 if (item[1] >= e->items)
113 return -EINVAL;
114 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r;
115 mask |= e->mask << e->shift_r;
116 }
117
118 return snd_soc_component_update_bits(component, e->reg, mask, val);
119}
120EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
121
122/**
123 * snd_soc_read_signed - Read a codec register and interprete as signed value
124 * @component: component
125 * @reg: Register to read
126 * @mask: Mask to use after shifting the register value
127 * @shift: Right shift of register value
128 * @sign_bit: Bit that describes if a number is negative or not.
129 * @signed_val: Pointer to where the read value should be stored
130 *
131 * This functions reads a codec register. The register value is shifted right
132 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
133 * the given registervalue into a signed integer if sign_bit is non-zero.
134 *
135 * Returns 0 on sucess, otherwise an error value
136 */
137static int snd_soc_read_signed(struct snd_soc_component *component,
138 unsigned int reg, unsigned int mask, unsigned int shift,
139 unsigned int sign_bit, int *signed_val)
140{
141 int ret;
142 unsigned int val;
143
144 ret = snd_soc_component_read(component, reg, &val);
145 if (ret < 0)
146 return ret;
147
148 val = (val >> shift) & mask;
149
150 if (!sign_bit) {
151 *signed_val = val;
152 return 0;
153 }
154
155 /* non-negative number */
156 if (!(val & BIT(sign_bit))) {
157 *signed_val = val;
158 return 0;
159 }
160
161 ret = val;
162
163 /*
164 * The register most probably does not contain a full-sized int.
165 * Instead we have an arbitrary number of bits in a signed
166 * representation which has to be translated into a full-sized int.
167 * This is done by filling up all bits above the sign-bit.
168 */
169 ret |= ~((int)(BIT(sign_bit) - 1));
170
171 *signed_val = ret;
172
173 return 0;
174}
175
176/**
177 * snd_soc_info_volsw - single mixer info callback
178 * @kcontrol: mixer control
179 * @uinfo: control element information
180 *
181 * Callback to provide information about a single mixer control, or a double
182 * mixer control that spans 2 registers.
183 *
184 * Returns 0 for success.
185 */
186int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
187 struct snd_ctl_elem_info *uinfo)
188{
189 struct soc_mixer_control *mc =
190 (struct soc_mixer_control *)kcontrol->private_value;
191 int platform_max;
192
193 if (!mc->platform_max)
194 mc->platform_max = mc->max;
195 platform_max = mc->platform_max;
196
197 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
198 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
199 else
200 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
201
202 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
203 uinfo->value.integer.min = 0;
204 uinfo->value.integer.max = platform_max - mc->min;
205 return 0;
206}
207EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
208
209/**
210 * snd_soc_get_volsw - single mixer get callback
211 * @kcontrol: mixer control
212 * @ucontrol: control element information
213 *
214 * Callback to get the value of a single mixer control, or a double mixer
215 * control that spans 2 registers.
216 *
217 * Returns 0 for success.
218 */
219int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
220 struct snd_ctl_elem_value *ucontrol)
221{
222 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
223 struct soc_mixer_control *mc =
224 (struct soc_mixer_control *)kcontrol->private_value;
225 unsigned int reg = mc->reg;
226 unsigned int reg2 = mc->rreg;
227 unsigned int shift = mc->shift;
228 unsigned int rshift = mc->rshift;
229 int max = mc->max;
230 int min = mc->min;
231 int sign_bit = mc->sign_bit;
232 unsigned int mask = (1 << fls(max)) - 1;
233 unsigned int invert = mc->invert;
234 int val;
235 int ret;
236
237 if (sign_bit)
238 mask = BIT(sign_bit + 1) - 1;
239
240 ret = snd_soc_read_signed(component, reg, mask, shift, sign_bit, &val);
241 if (ret)
242 return ret;
243
244 ucontrol->value.integer.value[0] = val - min;
245 if (invert)
246 ucontrol->value.integer.value[0] =
247 max - ucontrol->value.integer.value[0];
248
249 if (snd_soc_volsw_is_stereo(mc)) {
250 if (reg == reg2)
251 ret = snd_soc_read_signed(component, reg, mask, rshift,
252 sign_bit, &val);
253 else
254 ret = snd_soc_read_signed(component, reg2, mask, shift,
255 sign_bit, &val);
256 if (ret)
257 return ret;
258
259 ucontrol->value.integer.value[1] = val - min;
260 if (invert)
261 ucontrol->value.integer.value[1] =
262 max - ucontrol->value.integer.value[1];
263 }
264
265 return 0;
266}
267EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
268
269/**
270 * snd_soc_put_volsw - single mixer put callback
271 * @kcontrol: mixer control
272 * @ucontrol: control element information
273 *
274 * Callback to set the value of a single mixer control, or a double mixer
275 * control that spans 2 registers.
276 *
277 * Returns 0 for success.
278 */
279int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_value *ucontrol)
281{
282 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
283 struct soc_mixer_control *mc =
284 (struct soc_mixer_control *)kcontrol->private_value;
285 unsigned int reg = mc->reg;
286 unsigned int reg2 = mc->rreg;
287 unsigned int shift = mc->shift;
288 unsigned int rshift = mc->rshift;
289 int max = mc->max;
290 int min = mc->min;
291 unsigned int sign_bit = mc->sign_bit;
292 unsigned int mask = (1 << fls(max)) - 1;
293 unsigned int invert = mc->invert;
294 int err;
295 bool type_2r = false;
296 unsigned int val2 = 0;
297 unsigned int val, val_mask;
298
299 if (sign_bit)
300 mask = BIT(sign_bit + 1) - 1;
301
302 val = ((ucontrol->value.integer.value[0] + min) & mask);
303 if (invert)
304 val = max - val;
305 val_mask = mask << shift;
306 val = val << shift;
307 if (snd_soc_volsw_is_stereo(mc)) {
308 val2 = ((ucontrol->value.integer.value[1] + min) & mask);
309 if (invert)
310 val2 = max - val2;
311 if (reg == reg2) {
312 val_mask |= mask << rshift;
313 val |= val2 << rshift;
314 } else {
315 val2 = val2 << shift;
316 type_2r = true;
317 }
318 }
319 err = snd_soc_component_update_bits(component, reg, val_mask, val);
320 if (err < 0)
321 return err;
322
323 if (type_2r)
324 err = snd_soc_component_update_bits(component, reg2, val_mask,
325 val2);
326
327 return err;
328}
329EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
330
331/**
332 * snd_soc_get_volsw_sx - single mixer get callback
333 * @kcontrol: mixer control
334 * @ucontrol: control element information
335 *
336 * Callback to get the value of a single mixer control, or a double mixer
337 * control that spans 2 registers.
338 *
339 * Returns 0 for success.
340 */
341int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_value *ucontrol)
343{
344 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
345 struct soc_mixer_control *mc =
346 (struct soc_mixer_control *)kcontrol->private_value;
347 unsigned int reg = mc->reg;
348 unsigned int reg2 = mc->rreg;
349 unsigned int shift = mc->shift;
350 unsigned int rshift = mc->rshift;
351 int max = mc->max;
352 int min = mc->min;
353 int mask = (1 << (fls(min + max) - 1)) - 1;
354 unsigned int val;
355 int ret;
356
357 ret = snd_soc_component_read(component, reg, &val);
358 if (ret < 0)
359 return ret;
360
361 ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask;
362
363 if (snd_soc_volsw_is_stereo(mc)) {
364 ret = snd_soc_component_read(component, reg2, &val);
365 if (ret < 0)
366 return ret;
367
368 val = ((val >> rshift) - min) & mask;
369 ucontrol->value.integer.value[1] = val;
370 }
371
372 return 0;
373}
374EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
375
376/**
377 * snd_soc_put_volsw_sx - double mixer set callback
378 * @kcontrol: mixer control
379 * @uinfo: control element information
380 *
381 * Callback to set the value of a double mixer control that spans 2 registers.
382 *
383 * Returns 0 for success.
384 */
385int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_value *ucontrol)
387{
388 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
389 struct soc_mixer_control *mc =
390 (struct soc_mixer_control *)kcontrol->private_value;
391
392 unsigned int reg = mc->reg;
393 unsigned int reg2 = mc->rreg;
394 unsigned int shift = mc->shift;
395 unsigned int rshift = mc->rshift;
396 int max = mc->max;
397 int min = mc->min;
398 int mask = (1 << (fls(min + max) - 1)) - 1;
399 int err = 0;
400 unsigned int val, val_mask, val2 = 0;
401
402 val_mask = mask << shift;
403 val = (ucontrol->value.integer.value[0] + min) & mask;
404 val = val << shift;
405
406 err = snd_soc_component_update_bits(component, reg, val_mask, val);
407 if (err < 0)
408 return err;
409
410 if (snd_soc_volsw_is_stereo(mc)) {
411 val_mask = mask << rshift;
412 val2 = (ucontrol->value.integer.value[1] + min) & mask;
413 val2 = val2 << rshift;
414
415 err = snd_soc_component_update_bits(component, reg2, val_mask,
416 val2);
417 }
418 return err;
419}
420EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
421
422/**
423 * snd_soc_info_volsw_range - single mixer info callback with range.
424 * @kcontrol: mixer control
425 * @uinfo: control element information
426 *
427 * Callback to provide information, within a range, about a single
428 * mixer control.
429 *
430 * returns 0 for success.
431 */
432int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
433 struct snd_ctl_elem_info *uinfo)
434{
435 struct soc_mixer_control *mc =
436 (struct soc_mixer_control *)kcontrol->private_value;
437 int platform_max;
438 int min = mc->min;
439
440 if (!mc->platform_max)
441 mc->platform_max = mc->max;
442 platform_max = mc->platform_max;
443
444 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
445 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
446 uinfo->value.integer.min = 0;
447 uinfo->value.integer.max = platform_max - min;
448
449 return 0;
450}
451EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
452
453/**
454 * snd_soc_put_volsw_range - single mixer put value callback with range.
455 * @kcontrol: mixer control
456 * @ucontrol: control element information
457 *
458 * Callback to set the value, within a range, for a single mixer control.
459 *
460 * Returns 0 for success.
461 */
462int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
463 struct snd_ctl_elem_value *ucontrol)
464{
465 struct soc_mixer_control *mc =
466 (struct soc_mixer_control *)kcontrol->private_value;
467 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
468 unsigned int reg = mc->reg;
469 unsigned int rreg = mc->rreg;
470 unsigned int shift = mc->shift;
471 int min = mc->min;
472 int max = mc->max;
473 unsigned int mask = (1 << fls(max)) - 1;
474 unsigned int invert = mc->invert;
475 unsigned int val, val_mask;
476 int ret;
477
478 if (invert)
479 val = (max - ucontrol->value.integer.value[0]) & mask;
480 else
481 val = ((ucontrol->value.integer.value[0] + min) & mask);
482 val_mask = mask << shift;
483 val = val << shift;
484
485 ret = snd_soc_component_update_bits(component, reg, val_mask, val);
486 if (ret < 0)
487 return ret;
488
489 if (snd_soc_volsw_is_stereo(mc)) {
490 if (invert)
491 val = (max - ucontrol->value.integer.value[1]) & mask;
492 else
493 val = ((ucontrol->value.integer.value[1] + min) & mask);
494 val_mask = mask << shift;
495 val = val << shift;
496
497 ret = snd_soc_component_update_bits(component, rreg, val_mask,
498 val);
499 }
500
501 return ret;
502}
503EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
504
505/**
506 * snd_soc_get_volsw_range - single mixer get callback with range
507 * @kcontrol: mixer control
508 * @ucontrol: control element information
509 *
510 * Callback to get the value, within a range, of a single mixer control.
511 *
512 * Returns 0 for success.
513 */
514int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
515 struct snd_ctl_elem_value *ucontrol)
516{
517 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
518 struct soc_mixer_control *mc =
519 (struct soc_mixer_control *)kcontrol->private_value;
520 unsigned int reg = mc->reg;
521 unsigned int rreg = mc->rreg;
522 unsigned int shift = mc->shift;
523 int min = mc->min;
524 int max = mc->max;
525 unsigned int mask = (1 << fls(max)) - 1;
526 unsigned int invert = mc->invert;
527 unsigned int val;
528 int ret;
529
530 ret = snd_soc_component_read(component, reg, &val);
531 if (ret)
532 return ret;
533
534 ucontrol->value.integer.value[0] = (val >> shift) & mask;
535 if (invert)
536 ucontrol->value.integer.value[0] =
537 max - ucontrol->value.integer.value[0];
538 else
539 ucontrol->value.integer.value[0] =
540 ucontrol->value.integer.value[0] - min;
541
542 if (snd_soc_volsw_is_stereo(mc)) {
543 ret = snd_soc_component_read(component, rreg, &val);
544 if (ret)
545 return ret;
546
547 ucontrol->value.integer.value[1] = (val >> shift) & mask;
548 if (invert)
549 ucontrol->value.integer.value[1] =
550 max - ucontrol->value.integer.value[1];
551 else
552 ucontrol->value.integer.value[1] =
553 ucontrol->value.integer.value[1] - min;
554 }
555
556 return 0;
557}
558EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
559
560/**
561 * snd_soc_limit_volume - Set new limit to an existing volume control.
562 *
563 * @codec: where to look for the control
564 * @name: Name of the control
565 * @max: new maximum limit
566 *
567 * Return 0 for success, else error.
568 */
569int snd_soc_limit_volume(struct snd_soc_codec *codec,
570 const char *name, int max)
571{
572 struct snd_card *card = codec->component.card->snd_card;
573 struct snd_kcontrol *kctl;
574 struct soc_mixer_control *mc;
575 int found = 0;
576 int ret = -EINVAL;
577
578 /* Sanity check for name and max */
579 if (unlikely(!name || max <= 0))
580 return -EINVAL;
581
582 list_for_each_entry(kctl, &card->controls, list) {
583 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
584 found = 1;
585 break;
586 }
587 }
588 if (found) {
589 mc = (struct soc_mixer_control *)kctl->private_value;
590 if (max <= mc->max) {
591 mc->platform_max = max;
592 ret = 0;
593 }
594 }
595 return ret;
596}
597EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
598
599int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
600 struct snd_ctl_elem_info *uinfo)
601{
602 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
603 struct soc_bytes *params = (void *)kcontrol->private_value;
604
605 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
606 uinfo->count = params->num_regs * component->val_bytes;
607
608 return 0;
609}
610EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
611
612int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
614{
615 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
616 struct soc_bytes *params = (void *)kcontrol->private_value;
617 int ret;
618
619 if (component->regmap)
620 ret = regmap_raw_read(component->regmap, params->base,
621 ucontrol->value.bytes.data,
622 params->num_regs * component->val_bytes);
623 else
624 ret = -EINVAL;
625
626 /* Hide any masked bytes to ensure consistent data reporting */
627 if (ret == 0 && params->mask) {
628 switch (component->val_bytes) {
629 case 1:
630 ucontrol->value.bytes.data[0] &= ~params->mask;
631 break;
632 case 2:
633 ((u16 *)(&ucontrol->value.bytes.data))[0]
634 &= cpu_to_be16(~params->mask);
635 break;
636 case 4:
637 ((u32 *)(&ucontrol->value.bytes.data))[0]
638 &= cpu_to_be32(~params->mask);
639 break;
640 default:
641 return -EINVAL;
642 }
643 }
644
645 return ret;
646}
647EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
648
649int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_value *ucontrol)
651{
652 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
653 struct soc_bytes *params = (void *)kcontrol->private_value;
654 int ret, len;
655 unsigned int val, mask;
656 void *data;
657
658 if (!component->regmap || !params->num_regs)
659 return -EINVAL;
660
661 len = params->num_regs * component->val_bytes;
662
663 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
664 if (!data)
665 return -ENOMEM;
666
667 /*
668 * If we've got a mask then we need to preserve the register
669 * bits. We shouldn't modify the incoming data so take a
670 * copy.
671 */
672 if (params->mask) {
673 ret = regmap_read(component->regmap, params->base, &val);
674 if (ret != 0)
675 goto out;
676
677 val &= params->mask;
678
679 switch (component->val_bytes) {
680 case 1:
681 ((u8 *)data)[0] &= ~params->mask;
682 ((u8 *)data)[0] |= val;
683 break;
684 case 2:
685 mask = ~params->mask;
686 ret = regmap_parse_val(component->regmap,
687 &mask, &mask);
688 if (ret != 0)
689 goto out;
690
691 ((u16 *)data)[0] &= mask;
692
693 ret = regmap_parse_val(component->regmap,
694 &val, &val);
695 if (ret != 0)
696 goto out;
697
698 ((u16 *)data)[0] |= val;
699 break;
700 case 4:
701 mask = ~params->mask;
702 ret = regmap_parse_val(component->regmap,
703 &mask, &mask);
704 if (ret != 0)
705 goto out;
706
707 ((u32 *)data)[0] &= mask;
708
709 ret = regmap_parse_val(component->regmap,
710 &val, &val);
711 if (ret != 0)
712 goto out;
713
714 ((u32 *)data)[0] |= val;
715 break;
716 default:
717 ret = -EINVAL;
718 goto out;
719 }
720 }
721
722 ret = regmap_raw_write(component->regmap, params->base,
723 data, len);
724
725out:
726 kfree(data);
727
728 return ret;
729}
730EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
731
732int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
733 struct snd_ctl_elem_info *ucontrol)
734{
735 struct soc_bytes_ext *params = (void *)kcontrol->private_value;
736
737 ucontrol->type = SNDRV_CTL_ELEM_TYPE_BYTES;
738 ucontrol->count = params->max;
739
740 return 0;
741}
742EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext);
743
744int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
745 unsigned int size, unsigned int __user *tlv)
746{
747 struct soc_bytes_ext *params = (void *)kcontrol->private_value;
748 unsigned int count = size < params->max ? size : params->max;
749 int ret = -ENXIO;
750
751 switch (op_flag) {
752 case SNDRV_CTL_TLV_OP_READ:
753 if (params->get)
754 ret = params->get(tlv, count);
755 break;
756 case SNDRV_CTL_TLV_OP_WRITE:
757 if (params->put)
758 ret = params->put(tlv, count);
759 break;
760 }
761 return ret;
762}
763EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback);
764
765/**
766 * snd_soc_info_xr_sx - signed multi register info callback
767 * @kcontrol: mreg control
768 * @uinfo: control element information
769 *
770 * Callback to provide information of a control that can
771 * span multiple codec registers which together
772 * forms a single signed value in a MSB/LSB manner.
773 *
774 * Returns 0 for success.
775 */
776int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_info *uinfo)
778{
779 struct soc_mreg_control *mc =
780 (struct soc_mreg_control *)kcontrol->private_value;
781 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
782 uinfo->count = 1;
783 uinfo->value.integer.min = mc->min;
784 uinfo->value.integer.max = mc->max;
785
786 return 0;
787}
788EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
789
790/**
791 * snd_soc_get_xr_sx - signed multi register get callback
792 * @kcontrol: mreg control
793 * @ucontrol: control element information
794 *
795 * Callback to get the value of a control that can span
796 * multiple codec registers which together forms a single
797 * signed value in a MSB/LSB manner. The control supports
798 * specifying total no of bits used to allow for bitfields
799 * across the multiple codec registers.
800 *
801 * Returns 0 for success.
802 */
803int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
804 struct snd_ctl_elem_value *ucontrol)
805{
806 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
807 struct soc_mreg_control *mc =
808 (struct soc_mreg_control *)kcontrol->private_value;
809 unsigned int regbase = mc->regbase;
810 unsigned int regcount = mc->regcount;
811 unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
812 unsigned int regwmask = (1<<regwshift)-1;
813 unsigned int invert = mc->invert;
814 unsigned long mask = (1UL<<mc->nbits)-1;
815 long min = mc->min;
816 long max = mc->max;
817 long val = 0;
818 unsigned int regval;
819 unsigned int i;
820 int ret;
821
822 for (i = 0; i < regcount; i++) {
823 ret = snd_soc_component_read(component, regbase+i, &regval);
824 if (ret)
825 return ret;
826 val |= (regval & regwmask) << (regwshift*(regcount-i-1));
827 }
828 val &= mask;
829 if (min < 0 && val > max)
830 val |= ~mask;
831 if (invert)
832 val = max - val;
833 ucontrol->value.integer.value[0] = val;
834
835 return 0;
836}
837EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
838
839/**
840 * snd_soc_put_xr_sx - signed multi register get callback
841 * @kcontrol: mreg control
842 * @ucontrol: control element information
843 *
844 * Callback to set the value of a control that can span
845 * multiple codec registers which together forms a single
846 * signed value in a MSB/LSB manner. The control supports
847 * specifying total no of bits used to allow for bitfields
848 * across the multiple codec registers.
849 *
850 * Returns 0 for success.
851 */
852int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
853 struct snd_ctl_elem_value *ucontrol)
854{
855 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
856 struct soc_mreg_control *mc =
857 (struct soc_mreg_control *)kcontrol->private_value;
858 unsigned int regbase = mc->regbase;
859 unsigned int regcount = mc->regcount;
860 unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
861 unsigned int regwmask = (1<<regwshift)-1;
862 unsigned int invert = mc->invert;
863 unsigned long mask = (1UL<<mc->nbits)-1;
864 long max = mc->max;
865 long val = ucontrol->value.integer.value[0];
866 unsigned int i, regval, regmask;
867 int err;
868
869 if (invert)
870 val = max - val;
871 val &= mask;
872 for (i = 0; i < regcount; i++) {
873 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
874 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
875 err = snd_soc_component_update_bits(component, regbase+i,
876 regmask, regval);
877 if (err < 0)
878 return err;
879 }
880
881 return 0;
882}
883EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
884
885/**
886 * snd_soc_get_strobe - strobe get callback
887 * @kcontrol: mixer control
888 * @ucontrol: control element information
889 *
890 * Callback get the value of a strobe mixer control.
891 *
892 * Returns 0 for success.
893 */
894int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
895 struct snd_ctl_elem_value *ucontrol)
896{
897 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
898 struct soc_mixer_control *mc =
899 (struct soc_mixer_control *)kcontrol->private_value;
900 unsigned int reg = mc->reg;
901 unsigned int shift = mc->shift;
902 unsigned int mask = 1 << shift;
903 unsigned int invert = mc->invert != 0;
904 unsigned int val;
905 int ret;
906
907 ret = snd_soc_component_read(component, reg, &val);
908 if (ret)
909 return ret;
910
911 val &= mask;
912
913 if (shift != 0 && val != 0)
914 val = val >> shift;
915 ucontrol->value.enumerated.item[0] = val ^ invert;
916
917 return 0;
918}
919EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
920
921/**
922 * snd_soc_put_strobe - strobe put callback
923 * @kcontrol: mixer control
924 * @ucontrol: control element information
925 *
926 * Callback strobe a register bit to high then low (or the inverse)
927 * in one pass of a single mixer enum control.
928 *
929 * Returns 1 for success.
930 */
931int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
932 struct snd_ctl_elem_value *ucontrol)
933{
934 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
935 struct soc_mixer_control *mc =
936 (struct soc_mixer_control *)kcontrol->private_value;
937 unsigned int reg = mc->reg;
938 unsigned int shift = mc->shift;
939 unsigned int mask = 1 << shift;
940 unsigned int invert = mc->invert != 0;
941 unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
942 unsigned int val1 = (strobe ^ invert) ? mask : 0;
943 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
944 int err;
945
946 err = snd_soc_component_update_bits(component, reg, mask, val1);
947 if (err < 0)
948 return err;
949
950 return snd_soc_component_update_bits(component, reg, mask, val2);
951}
952EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 57277dd79e11..eb87d96e2cf0 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -654,6 +654,8 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
654 codec_dai->rate = 0; 654 codec_dai->rate = 0;
655 } 655 }
656 656
657 snd_soc_dai_digital_mute(cpu_dai, 1, substream->stream);
658
657 if (cpu_dai->driver->ops->shutdown) 659 if (cpu_dai->driver->ops->shutdown)
658 cpu_dai->driver->ops->shutdown(substream, cpu_dai); 660 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
659 661
@@ -772,6 +774,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
772 for (i = 0; i < rtd->num_codecs; i++) 774 for (i = 0; i < rtd->num_codecs; i++)
773 snd_soc_dai_digital_mute(rtd->codec_dais[i], 0, 775 snd_soc_dai_digital_mute(rtd->codec_dais[i], 0,
774 substream->stream); 776 substream->stream);
777 snd_soc_dai_digital_mute(cpu_dai, 0, substream->stream);
775 778
776out: 779out:
777 mutex_unlock(&rtd->pcm_mutex); 780 mutex_unlock(&rtd->pcm_mutex);
@@ -1664,6 +1667,10 @@ int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
1664 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) 1667 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1665 continue; 1668 continue;
1666 1669
1670 /* do not free hw if this BE is used by other FE */
1671 if (be->dpcm[stream].users > 1)
1672 continue;
1673
1667 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && 1674 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1668 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) && 1675 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1669 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) && 1676 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
@@ -2288,7 +2295,13 @@ int soc_dpcm_runtime_update(struct snd_soc_card *card)
2288 fe->dai_link->name); 2295 fe->dai_link->name);
2289 2296
2290 /* skip if FE doesn't have playback capability */ 2297 /* skip if FE doesn't have playback capability */
2291 if (!fe->cpu_dai->driver->playback.channels_min) 2298 if (!fe->cpu_dai->driver->playback.channels_min
2299 || !fe->codec_dai->driver->playback.channels_min)
2300 goto capture;
2301
2302 /* skip if FE isn't currently playing */
2303 if (!fe->cpu_dai->playback_active
2304 || !fe->codec_dai->playback_active)
2292 goto capture; 2305 goto capture;
2293 2306
2294 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list); 2307 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
@@ -2318,7 +2331,13 @@ int soc_dpcm_runtime_update(struct snd_soc_card *card)
2318 dpcm_path_put(&list); 2331 dpcm_path_put(&list);
2319capture: 2332capture:
2320 /* skip if FE doesn't have capture capability */ 2333 /* skip if FE doesn't have capture capability */
2321 if (!fe->cpu_dai->driver->capture.channels_min) 2334 if (!fe->cpu_dai->driver->capture.channels_min
2335 || !fe->codec_dai->driver->capture.channels_min)
2336 continue;
2337
2338 /* skip if FE isn't currently capturing */
2339 if (!fe->cpu_dai->capture_active
2340 || !fe->codec_dai->capture_active)
2322 continue; 2341 continue;
2323 2342
2324 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list); 2343 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
diff --git a/sound/soc/tegra/tegra20_ac97.c b/sound/soc/tegra/tegra20_ac97.c
index 3b0fa12dbff7..29a9957d335a 100644
--- a/sound/soc/tegra/tegra20_ac97.c
+++ b/sound/soc/tegra/tegra20_ac97.c
@@ -228,7 +228,7 @@ static int tegra20_ac97_probe(struct snd_soc_dai *dai)
228 228
229static struct snd_soc_dai_driver tegra20_ac97_dai = { 229static struct snd_soc_dai_driver tegra20_ac97_dai = {
230 .name = "tegra-ac97-pcm", 230 .name = "tegra-ac97-pcm",
231 .ac97_control = 1, 231 .bus_control = true,
232 .probe = tegra20_ac97_probe, 232 .probe = tegra20_ac97_probe,
233 .playback = { 233 .playback = {
234 .stream_name = "PCM Playback", 234 .stream_name = "PCM Playback",
diff --git a/sound/soc/tegra/tegra_rt5640.c b/sound/soc/tegra/tegra_rt5640.c
index a6898831fb9f..4ebe3871e610 100644
--- a/sound/soc/tegra/tegra_rt5640.c
+++ b/sound/soc/tegra/tegra_rt5640.c
@@ -44,6 +44,7 @@
44struct tegra_rt5640 { 44struct tegra_rt5640 {
45 struct tegra_asoc_utils_data util_data; 45 struct tegra_asoc_utils_data util_data;
46 int gpio_hp_det; 46 int gpio_hp_det;
47 enum of_gpio_flags gpio_hp_det_flags;
47}; 48};
48 49
49static int tegra_rt5640_asoc_hw_params(struct snd_pcm_substream *substream, 50static int tegra_rt5640_asoc_hw_params(struct snd_pcm_substream *substream,
@@ -119,6 +120,8 @@ static int tegra_rt5640_asoc_init(struct snd_soc_pcm_runtime *rtd)
119 120
120 if (gpio_is_valid(machine->gpio_hp_det)) { 121 if (gpio_is_valid(machine->gpio_hp_det)) {
121 tegra_rt5640_hp_jack_gpio.gpio = machine->gpio_hp_det; 122 tegra_rt5640_hp_jack_gpio.gpio = machine->gpio_hp_det;
123 tegra_rt5640_hp_jack_gpio.invert =
124 !!(machine->gpio_hp_det_flags & OF_GPIO_ACTIVE_LOW);
122 snd_soc_jack_add_gpios(&tegra_rt5640_hp_jack, 125 snd_soc_jack_add_gpios(&tegra_rt5640_hp_jack,
123 1, 126 1,
124 &tegra_rt5640_hp_jack_gpio); 127 &tegra_rt5640_hp_jack_gpio);
@@ -180,7 +183,8 @@ static int tegra_rt5640_probe(struct platform_device *pdev)
180 platform_set_drvdata(pdev, card); 183 platform_set_drvdata(pdev, card);
181 snd_soc_card_set_drvdata(card, machine); 184 snd_soc_card_set_drvdata(card, machine);
182 185
183 machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0); 186 machine->gpio_hp_det = of_get_named_gpio_flags(
187 np, "nvidia,hp-det-gpios", 0, &machine->gpio_hp_det_flags);
184 if (machine->gpio_hp_det == -EPROBE_DEFER) 188 if (machine->gpio_hp_det == -EPROBE_DEFER)
185 return -EPROBE_DEFER; 189 return -EPROBE_DEFER;
186 190
diff --git a/sound/soc/txx9/txx9aclc-ac97.c b/sound/soc/txx9/txx9aclc-ac97.c
index 9edd68db9f48..f7135cdaa2ca 100644
--- a/sound/soc/txx9/txx9aclc-ac97.c
+++ b/sound/soc/txx9/txx9aclc-ac97.c
@@ -152,7 +152,7 @@ static int txx9aclc_ac97_remove(struct snd_soc_dai *dai)
152} 152}
153 153
154static struct snd_soc_dai_driver txx9aclc_ac97_dai = { 154static struct snd_soc_dai_driver txx9aclc_ac97_dai = {
155 .ac97_control = 1, 155 .bus_control = true,
156 .probe = txx9aclc_ac97_probe, 156 .probe = txx9aclc_ac97_probe,
157 .remove = txx9aclc_ac97_remove, 157 .remove = txx9aclc_ac97_remove,
158 .playback = { 158 .playback = {
diff --git a/sound/soc/txx9/txx9aclc.c b/sound/soc/txx9/txx9aclc.c
index cd71fd889d8b..00b7e2d02690 100644
--- a/sound/soc/txx9/txx9aclc.c
+++ b/sound/soc/txx9/txx9aclc.c
@@ -292,7 +292,7 @@ static int txx9aclc_pcm_new(struct snd_soc_pcm_runtime *rtd)
292 struct snd_card *card = rtd->card->snd_card; 292 struct snd_card *card = rtd->card->snd_card;
293 struct snd_soc_dai *dai = rtd->cpu_dai; 293 struct snd_soc_dai *dai = rtd->cpu_dai;
294 struct snd_pcm *pcm = rtd->pcm; 294 struct snd_pcm *pcm = rtd->pcm;
295 struct platform_device *pdev = to_platform_device(dai->platform->dev); 295 struct platform_device *pdev = to_platform_device(rtd->platform->dev);
296 struct txx9aclc_soc_device *dev; 296 struct txx9aclc_soc_device *dev;
297 struct resource *r; 297 struct resource *r;
298 int i; 298 int i;
diff --git a/sound/soc/ux500/mop500.c b/sound/soc/ux500/mop500.c
index b3b66aa98dce..9f2d045ee118 100644
--- a/sound/soc/ux500/mop500.c
+++ b/sound/soc/ux500/mop500.c
@@ -63,12 +63,8 @@ static void mop500_of_node_put(void)
63 int i; 63 int i;
64 64
65 for (i = 0; i < 2; i++) { 65 for (i = 0; i < 2; i++) {
66 if (mop500_dai_links[i].cpu_of_node) 66 of_node_put(mop500_dai_links[i].cpu_of_node);
67 of_node_put((struct device_node *) 67 of_node_put(mop500_dai_links[i].codec_of_node);
68 mop500_dai_links[i].cpu_of_node);
69 if (mop500_dai_links[i].codec_of_node)
70 of_node_put((struct device_node *)
71 mop500_dai_links[i].codec_of_node);
72 } 68 }
73} 69}
74 70
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index 4e91bcaa3664..06606f9bbf78 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -1285,19 +1285,11 @@ static int snd_cs4231_timer(struct snd_card *card)
1285static int snd_cs4231_info_mux(struct snd_kcontrol *kcontrol, 1285static int snd_cs4231_info_mux(struct snd_kcontrol *kcontrol,
1286 struct snd_ctl_elem_info *uinfo) 1286 struct snd_ctl_elem_info *uinfo)
1287{ 1287{
1288 static char *texts[4] = { 1288 static const char * const texts[4] = {
1289 "Line", "CD", "Mic", "Mix" 1289 "Line", "CD", "Mic", "Mix"
1290 }; 1290 };
1291 1291
1292 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1292 return snd_ctl_enum_info(uinfo, 2, 4, texts);
1293 uinfo->count = 2;
1294 uinfo->value.enumerated.items = 4;
1295 if (uinfo->value.enumerated.item > 3)
1296 uinfo->value.enumerated.item = 3;
1297 strcpy(uinfo->value.enumerated.name,
1298 texts[uinfo->value.enumerated.item]);
1299
1300 return 0;
1301} 1293}
1302 1294
1303static int snd_cs4231_get_mux(struct snd_kcontrol *kcontrol, 1295static int snd_cs4231_get_mux(struct snd_kcontrol *kcontrol,
diff --git a/sound/usb/6fire/control.c b/sound/usb/6fire/control.c
index 184e3987ac24..54656eed6e2e 100644
--- a/sound/usb/6fire/control.c
+++ b/sound/usb/6fire/control.c
@@ -25,8 +25,8 @@
25#include "comm.h" 25#include "comm.h"
26#include "chip.h" 26#include "chip.h"
27 27
28static char *opt_coax_texts[2] = { "Optical", "Coax" }; 28static const char * const opt_coax_texts[2] = { "Optical", "Coax" };
29static char *line_phono_texts[2] = { "Line", "Phono" }; 29static const char * const line_phono_texts[2] = { "Line", "Phono" };
30 30
31/* 31/*
32 * data that needs to be sent to device. sets up card internal stuff. 32 * data that needs to be sent to device. sets up card internal stuff.
@@ -327,14 +327,7 @@ static int usb6fire_control_input_vol_get(struct snd_kcontrol *kcontrol,
327static int usb6fire_control_line_phono_info(struct snd_kcontrol *kcontrol, 327static int usb6fire_control_line_phono_info(struct snd_kcontrol *kcontrol,
328 struct snd_ctl_elem_info *uinfo) 328 struct snd_ctl_elem_info *uinfo)
329{ 329{
330 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 330 return snd_ctl_enum_info(uinfo, 1, 2, line_phono_texts);
331 uinfo->count = 1;
332 uinfo->value.enumerated.items = 2;
333 if (uinfo->value.enumerated.item > 1)
334 uinfo->value.enumerated.item = 1;
335 strcpy(uinfo->value.enumerated.name,
336 line_phono_texts[uinfo->value.enumerated.item]);
337 return 0;
338} 331}
339 332
340static int usb6fire_control_line_phono_put(struct snd_kcontrol *kcontrol, 333static int usb6fire_control_line_phono_put(struct snd_kcontrol *kcontrol,
@@ -361,14 +354,7 @@ static int usb6fire_control_line_phono_get(struct snd_kcontrol *kcontrol,
361static int usb6fire_control_opt_coax_info(struct snd_kcontrol *kcontrol, 354static int usb6fire_control_opt_coax_info(struct snd_kcontrol *kcontrol,
362 struct snd_ctl_elem_info *uinfo) 355 struct snd_ctl_elem_info *uinfo)
363{ 356{
364 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 357 return snd_ctl_enum_info(uinfo, 1, 2, opt_coax_texts);
365 uinfo->count = 1;
366 uinfo->value.enumerated.items = 2;
367 if (uinfo->value.enumerated.item > 1)
368 uinfo->value.enumerated.item = 1;
369 strcpy(uinfo->value.enumerated.name,
370 opt_coax_texts[uinfo->value.enumerated.item]);
371 return 0;
372} 358}
373 359
374static int usb6fire_control_opt_coax_put(struct snd_kcontrol *kcontrol, 360static int usb6fire_control_opt_coax_put(struct snd_kcontrol *kcontrol,
diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c
index 3b02e54b8f6d..62c25e74f0e5 100644
--- a/sound/usb/6fire/firmware.c
+++ b/sound/usb/6fire/firmware.c
@@ -316,7 +316,7 @@ static int usb6fire_fw_fpga_upload(
316 316
317 while (c != end) { 317 while (c != end) {
318 for (i = 0; c != end && i < FPGA_BUFSIZE; i++, c++) 318 for (i = 0; c != end && i < FPGA_BUFSIZE; i++, c++)
319 buffer[i] = byte_rev_table[(u8) *c]; 319 buffer[i] = bitrev8((u8)*c);
320 320
321 ret = usb6fire_fw_fpga_write(device, buffer, i); 321 ret = usb6fire_fw_fpga_write(device, buffer, i);
322 if (ret < 0) { 322 if (ret < 0) {
diff --git a/sound/usb/6fire/pcm.c b/sound/usb/6fire/pcm.c
index ba40489b2de4..36f4115eb1cd 100644
--- a/sound/usb/6fire/pcm.c
+++ b/sound/usb/6fire/pcm.c
@@ -679,25 +679,16 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
679void usb6fire_pcm_abort(struct sfire_chip *chip) 679void usb6fire_pcm_abort(struct sfire_chip *chip)
680{ 680{
681 struct pcm_runtime *rt = chip->pcm; 681 struct pcm_runtime *rt = chip->pcm;
682 unsigned long flags;
683 int i; 682 int i;
684 683
685 if (rt) { 684 if (rt) {
686 rt->panic = true; 685 rt->panic = true;
687 686
688 if (rt->playback.instance) { 687 if (rt->playback.instance)
689 snd_pcm_stream_lock_irqsave(rt->playback.instance, flags); 688 snd_pcm_stop_xrun(rt->playback.instance);
690 snd_pcm_stop(rt->playback.instance,
691 SNDRV_PCM_STATE_XRUN);
692 snd_pcm_stream_unlock_irqrestore(rt->playback.instance, flags);
693 }
694 689
695 if (rt->capture.instance) { 690 if (rt->capture.instance)
696 snd_pcm_stream_lock_irqsave(rt->capture.instance, flags); 691 snd_pcm_stop_xrun(rt->capture.instance);
697 snd_pcm_stop(rt->capture.instance,
698 SNDRV_PCM_STATE_XRUN);
699 snd_pcm_stream_unlock_irqrestore(rt->capture.instance, flags);
700 }
701 692
702 for (i = 0; i < PCM_N_URBS; i++) { 693 for (i = 0; i < PCM_N_URBS; i++) {
703 usb_poison_urb(&rt->in_urbs[i].instance); 694 usb_poison_urb(&rt->in_urbs[i].instance);
diff --git a/sound/usb/Makefile b/sound/usb/Makefile
index 2b92f0dcbc4c..bcee4060fd18 100644
--- a/sound/usb/Makefile
+++ b/sound/usb/Makefile
@@ -9,6 +9,7 @@ snd-usb-audio-objs := card.o \
9 helper.o \ 9 helper.o \
10 mixer.o \ 10 mixer.o \
11 mixer_quirks.o \ 11 mixer_quirks.o \
12 mixer_scarlett.o \
12 pcm.o \ 13 pcm.o \
13 proc.o \ 14 proc.o \
14 quirks.o \ 15 quirks.o \
diff --git a/sound/usb/card.c b/sound/usb/card.c
index f61ebb17cc64..1fab9778807a 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -112,15 +112,13 @@ static struct usb_driver usb_audio_driver;
112 112
113/* 113/*
114 * disconnect streams 114 * disconnect streams
115 * called from snd_usb_audio_disconnect() 115 * called from usb_audio_disconnect()
116 */ 116 */
117static void snd_usb_stream_disconnect(struct list_head *head) 117static void snd_usb_stream_disconnect(struct snd_usb_stream *as)
118{ 118{
119 int idx; 119 int idx;
120 struct snd_usb_stream *as;
121 struct snd_usb_substream *subs; 120 struct snd_usb_substream *subs;
122 121
123 as = list_entry(head, struct snd_usb_stream, list);
124 for (idx = 0; idx < 2; idx++) { 122 for (idx = 0; idx < 2; idx++) {
125 subs = &as->substream[idx]; 123 subs = &as->substream[idx];
126 if (!subs->num_formats) 124 if (!subs->num_formats)
@@ -307,10 +305,10 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
307 305
308static int snd_usb_audio_free(struct snd_usb_audio *chip) 306static int snd_usb_audio_free(struct snd_usb_audio *chip)
309{ 307{
310 struct list_head *p, *n; 308 struct snd_usb_endpoint *ep, *n;
311 309
312 list_for_each_safe(p, n, &chip->ep_list) 310 list_for_each_entry_safe(ep, n, &chip->ep_list, list)
313 snd_usb_endpoint_free(p); 311 snd_usb_endpoint_free(ep);
314 312
315 mutex_destroy(&chip->mutex); 313 mutex_destroy(&chip->mutex);
316 kfree(chip); 314 kfree(chip);
@@ -323,16 +321,6 @@ static int snd_usb_audio_dev_free(struct snd_device *device)
323 return snd_usb_audio_free(chip); 321 return snd_usb_audio_free(chip);
324} 322}
325 323
326static void remove_trailing_spaces(char *str)
327{
328 char *p;
329
330 if (!*str)
331 return;
332 for (p = str + strlen(str) - 1; p >= str && isspace(*p); p--)
333 *p = 0;
334}
335
336/* 324/*
337 * create a chip instance and set its names. 325 * create a chip instance and set its names.
338 */ 326 */
@@ -416,7 +404,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,
416 USB_ID_PRODUCT(chip->usb_id)); 404 USB_ID_PRODUCT(chip->usb_id));
417 } 405 }
418 } 406 }
419 remove_trailing_spaces(card->shortname); 407 strim(card->shortname);
420 408
421 /* retrieve the vendor and device strings as longname */ 409 /* retrieve the vendor and device strings as longname */
422 if (quirk && quirk->vendor_name && *quirk->vendor_name) { 410 if (quirk && quirk->vendor_name && *quirk->vendor_name) {
@@ -430,7 +418,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,
430 /* we don't really care if there isn't any vendor string */ 418 /* we don't really care if there isn't any vendor string */
431 } 419 }
432 if (len > 0) { 420 if (len > 0) {
433 remove_trailing_spaces(card->longname); 421 strim(card->longname);
434 if (*card->longname) 422 if (*card->longname)
435 strlcat(card->longname, " ", sizeof(card->longname)); 423 strlcat(card->longname, " ", sizeof(card->longname));
436 } 424 }
@@ -475,14 +463,14 @@ static int snd_usb_audio_create(struct usb_interface *intf,
475 * only at the first time. the successive calls of this function will 463 * only at the first time. the successive calls of this function will
476 * append the pcm interface to the corresponding card. 464 * append the pcm interface to the corresponding card.
477 */ 465 */
478static struct snd_usb_audio * 466static int usb_audio_probe(struct usb_interface *intf,
479snd_usb_audio_probe(struct usb_device *dev, 467 const struct usb_device_id *usb_id)
480 struct usb_interface *intf,
481 const struct usb_device_id *usb_id)
482{ 468{
483 const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info; 469 struct usb_device *dev = interface_to_usbdev(intf);
484 int i, err; 470 const struct snd_usb_audio_quirk *quirk =
471 (const struct snd_usb_audio_quirk *)usb_id->driver_info;
485 struct snd_usb_audio *chip; 472 struct snd_usb_audio *chip;
473 int i, err;
486 struct usb_host_interface *alts; 474 struct usb_host_interface *alts;
487 int ifnum; 475 int ifnum;
488 u32 id; 476 u32 id;
@@ -492,10 +480,11 @@ snd_usb_audio_probe(struct usb_device *dev,
492 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 480 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
493 le16_to_cpu(dev->descriptor.idProduct)); 481 le16_to_cpu(dev->descriptor.idProduct));
494 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum) 482 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
495 goto __err_val; 483 return -ENXIO;
496 484
497 if (snd_usb_apply_boot_quirk(dev, intf, quirk) < 0) 485 err = snd_usb_apply_boot_quirk(dev, intf, quirk);
498 goto __err_val; 486 if (err < 0)
487 return err;
499 488
500 /* 489 /*
501 * found a config. now register to ALSA 490 * found a config. now register to ALSA
@@ -508,6 +497,7 @@ snd_usb_audio_probe(struct usb_device *dev,
508 if (usb_chip[i] && usb_chip[i]->dev == dev) { 497 if (usb_chip[i] && usb_chip[i]->dev == dev) {
509 if (usb_chip[i]->shutdown) { 498 if (usb_chip[i]->shutdown) {
510 dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n"); 499 dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n");
500 err = -EIO;
511 goto __error; 501 goto __error;
512 } 502 }
513 chip = usb_chip[i]; 503 chip = usb_chip[i];
@@ -523,15 +513,16 @@ snd_usb_audio_probe(struct usb_device *dev,
523 if (enable[i] && ! usb_chip[i] && 513 if (enable[i] && ! usb_chip[i] &&
524 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) && 514 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
525 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) { 515 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
526 if (snd_usb_audio_create(intf, dev, i, quirk, 516 err = snd_usb_audio_create(intf, dev, i, quirk,
527 &chip) < 0) { 517 &chip);
518 if (err < 0)
528 goto __error; 519 goto __error;
529 }
530 chip->pm_intf = intf; 520 chip->pm_intf = intf;
531 break; 521 break;
532 } 522 }
533 if (!chip) { 523 if (!chip) {
534 dev_err(&dev->dev, "no available usb audio device\n"); 524 dev_err(&dev->dev, "no available usb audio device\n");
525 err = -ENODEV;
535 goto __error; 526 goto __error;
536 } 527 }
537 } 528 }
@@ -548,28 +539,32 @@ snd_usb_audio_probe(struct usb_device *dev,
548 err = 1; /* continue */ 539 err = 1; /* continue */
549 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { 540 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
550 /* need some special handlings */ 541 /* need some special handlings */
551 if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0) 542 err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk);
543 if (err < 0)
552 goto __error; 544 goto __error;
553 } 545 }
554 546
555 if (err > 0) { 547 if (err > 0) {
556 /* create normal USB audio interfaces */ 548 /* create normal USB audio interfaces */
557 if (snd_usb_create_streams(chip, ifnum) < 0 || 549 err = snd_usb_create_streams(chip, ifnum);
558 snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) { 550 if (err < 0)
551 goto __error;
552 err = snd_usb_create_mixer(chip, ifnum, ignore_ctl_error);
553 if (err < 0)
559 goto __error; 554 goto __error;
560 }
561 } 555 }
562 556
563 /* we are allowed to call snd_card_register() many times */ 557 /* we are allowed to call snd_card_register() many times */
564 if (snd_card_register(chip->card) < 0) { 558 err = snd_card_register(chip->card);
559 if (err < 0)
565 goto __error; 560 goto __error;
566 }
567 561
568 usb_chip[chip->index] = chip; 562 usb_chip[chip->index] = chip;
569 chip->num_interfaces++; 563 chip->num_interfaces++;
570 chip->probing = 0; 564 chip->probing = 0;
565 usb_set_intfdata(intf, chip);
571 mutex_unlock(&register_mutex); 566 mutex_unlock(&register_mutex);
572 return chip; 567 return 0;
573 568
574 __error: 569 __error:
575 if (chip) { 570 if (chip) {
@@ -578,17 +573,16 @@ snd_usb_audio_probe(struct usb_device *dev,
578 chip->probing = 0; 573 chip->probing = 0;
579 } 574 }
580 mutex_unlock(&register_mutex); 575 mutex_unlock(&register_mutex);
581 __err_val: 576 return err;
582 return NULL;
583} 577}
584 578
585/* 579/*
586 * we need to take care of counter, since disconnection can be called also 580 * we need to take care of counter, since disconnection can be called also
587 * many times as well as usb_audio_probe(). 581 * many times as well as usb_audio_probe().
588 */ 582 */
589static void snd_usb_audio_disconnect(struct usb_device *dev, 583static void usb_audio_disconnect(struct usb_interface *intf)
590 struct snd_usb_audio *chip)
591{ 584{
585 struct snd_usb_audio *chip = usb_get_intfdata(intf);
592 struct snd_card *card; 586 struct snd_card *card;
593 struct list_head *p; 587 struct list_head *p;
594 bool was_shutdown; 588 bool was_shutdown;
@@ -604,12 +598,14 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
604 598
605 mutex_lock(&register_mutex); 599 mutex_lock(&register_mutex);
606 if (!was_shutdown) { 600 if (!was_shutdown) {
601 struct snd_usb_stream *as;
607 struct snd_usb_endpoint *ep; 602 struct snd_usb_endpoint *ep;
603 struct usb_mixer_interface *mixer;
608 604
609 snd_card_disconnect(card); 605 snd_card_disconnect(card);
610 /* release the pcm resources */ 606 /* release the pcm resources */
611 list_for_each(p, &chip->pcm_list) { 607 list_for_each_entry(as, &chip->pcm_list, list) {
612 snd_usb_stream_disconnect(p); 608 snd_usb_stream_disconnect(as);
613 } 609 }
614 /* release the endpoint resources */ 610 /* release the endpoint resources */
615 list_for_each_entry(ep, &chip->ep_list, list) { 611 list_for_each_entry(ep, &chip->ep_list, list) {
@@ -620,8 +616,8 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
620 snd_usbmidi_disconnect(p); 616 snd_usbmidi_disconnect(p);
621 } 617 }
622 /* release mixer resources */ 618 /* release mixer resources */
623 list_for_each(p, &chip->mixer_list) { 619 list_for_each_entry(mixer, &chip->mixer_list, list) {
624 snd_usb_mixer_disconnect(p); 620 snd_usb_mixer_disconnect(mixer);
625 } 621 }
626 } 622 }
627 623
@@ -635,27 +631,6 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
635 } 631 }
636} 632}
637 633
638/*
639 * new 2.5 USB kernel API
640 */
641static int usb_audio_probe(struct usb_interface *intf,
642 const struct usb_device_id *id)
643{
644 struct snd_usb_audio *chip;
645 chip = snd_usb_audio_probe(interface_to_usbdev(intf), intf, id);
646 if (chip) {
647 usb_set_intfdata(intf, chip);
648 return 0;
649 } else
650 return -EIO;
651}
652
653static void usb_audio_disconnect(struct usb_interface *intf)
654{
655 snd_usb_audio_disconnect(interface_to_usbdev(intf),
656 usb_get_intfdata(intf));
657}
658
659#ifdef CONFIG_PM 634#ifdef CONFIG_PM
660 635
661int snd_usb_autoresume(struct snd_usb_audio *chip) 636int snd_usb_autoresume(struct snd_usb_audio *chip)
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 114e3e7ff511..03b074419964 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -348,6 +348,8 @@ static void snd_complete_urb(struct urb *urb)
348{ 348{
349 struct snd_urb_ctx *ctx = urb->context; 349 struct snd_urb_ctx *ctx = urb->context;
350 struct snd_usb_endpoint *ep = ctx->ep; 350 struct snd_usb_endpoint *ep = ctx->ep;
351 struct snd_pcm_substream *substream;
352 unsigned long flags;
351 int err; 353 int err;
352 354
353 if (unlikely(urb->status == -ENOENT || /* unlinked */ 355 if (unlikely(urb->status == -ENOENT || /* unlinked */
@@ -364,8 +366,6 @@ static void snd_complete_urb(struct urb *urb)
364 goto exit_clear; 366 goto exit_clear;
365 367
366 if (snd_usb_endpoint_implicit_feedback_sink(ep)) { 368 if (snd_usb_endpoint_implicit_feedback_sink(ep)) {
367 unsigned long flags;
368
369 spin_lock_irqsave(&ep->lock, flags); 369 spin_lock_irqsave(&ep->lock, flags);
370 list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs); 370 list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs);
371 spin_unlock_irqrestore(&ep->lock, flags); 371 spin_unlock_irqrestore(&ep->lock, flags);
@@ -389,7 +389,10 @@ static void snd_complete_urb(struct urb *urb)
389 return; 389 return;
390 390
391 usb_audio_err(ep->chip, "cannot submit urb (err = %d)\n", err); 391 usb_audio_err(ep->chip, "cannot submit urb (err = %d)\n", err);
392 //snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 392 if (ep->data_subs && ep->data_subs->pcm_substream) {
393 substream = ep->data_subs->pcm_substream;
394 snd_pcm_stop_xrun(substream);
395 }
393 396
394exit_clear: 397exit_clear:
395 clear_bit(ctx->index, &ep->active_mask); 398 clear_bit(ctx->index, &ep->active_mask);
@@ -1002,15 +1005,12 @@ void snd_usb_endpoint_release(struct snd_usb_endpoint *ep)
1002/** 1005/**
1003 * snd_usb_endpoint_free: Free the resources of an snd_usb_endpoint 1006 * snd_usb_endpoint_free: Free the resources of an snd_usb_endpoint
1004 * 1007 *
1005 * @ep: the list header of the endpoint to free 1008 * @ep: the endpoint to free
1006 * 1009 *
1007 * This free all resources of the given ep. 1010 * This free all resources of the given ep.
1008 */ 1011 */
1009void snd_usb_endpoint_free(struct list_head *head) 1012void snd_usb_endpoint_free(struct snd_usb_endpoint *ep)
1010{ 1013{
1011 struct snd_usb_endpoint *ep;
1012
1013 ep = list_entry(head, struct snd_usb_endpoint, list);
1014 kfree(ep); 1014 kfree(ep);
1015} 1015}
1016 1016
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
index e61ee5c356a3..6428392d8f62 100644
--- a/sound/usb/endpoint.h
+++ b/sound/usb/endpoint.h
@@ -24,7 +24,7 @@ void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep);
24int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep); 24int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
25void snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep); 25void snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep);
26void snd_usb_endpoint_release(struct snd_usb_endpoint *ep); 26void snd_usb_endpoint_release(struct snd_usb_endpoint *ep);
27void snd_usb_endpoint_free(struct list_head *head); 27void snd_usb_endpoint_free(struct snd_usb_endpoint *ep);
28 28
29int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep); 29int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep);
30int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep); 30int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep);
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index d3d49525a16b..5bfb695547f8 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -365,6 +365,8 @@ static void snd_usbmidi_error_timer(unsigned long data)
365 if (in && in->error_resubmit) { 365 if (in && in->error_resubmit) {
366 in->error_resubmit = 0; 366 in->error_resubmit = 0;
367 for (j = 0; j < INPUT_URBS; ++j) { 367 for (j = 0; j < INPUT_URBS; ++j) {
368 if (atomic_read(&in->urbs[j]->use_count))
369 continue;
368 in->urbs[j]->dev = umidi->dev; 370 in->urbs[j]->dev = umidi->dev;
369 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC); 371 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC);
370 } 372 }
diff --git a/sound/usb/misc/ua101.c b/sound/usb/misc/ua101.c
index a1bab149df4d..9581089c28c5 100644
--- a/sound/usb/misc/ua101.c
+++ b/sound/usb/misc/ua101.c
@@ -613,24 +613,14 @@ static int start_usb_playback(struct ua101 *ua)
613 613
614static void abort_alsa_capture(struct ua101 *ua) 614static void abort_alsa_capture(struct ua101 *ua)
615{ 615{
616 unsigned long flags; 616 if (test_bit(ALSA_CAPTURE_RUNNING, &ua->states))
617 617 snd_pcm_stop_xrun(ua->capture.substream);
618 if (test_bit(ALSA_CAPTURE_RUNNING, &ua->states)) {
619 snd_pcm_stream_lock_irqsave(ua->capture.substream, flags);
620 snd_pcm_stop(ua->capture.substream, SNDRV_PCM_STATE_XRUN);
621 snd_pcm_stream_unlock_irqrestore(ua->capture.substream, flags);
622 }
623} 618}
624 619
625static void abort_alsa_playback(struct ua101 *ua) 620static void abort_alsa_playback(struct ua101 *ua)
626{ 621{
627 unsigned long flags; 622 if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
628 623 snd_pcm_stop_xrun(ua->playback.substream);
629 if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states)) {
630 snd_pcm_stream_lock_irqsave(ua->playback.substream, flags);
631 snd_pcm_stop(ua->playback.substream, SNDRV_PCM_STATE_XRUN);
632 snd_pcm_stream_unlock_irqrestore(ua->playback.substream, flags);
633 }
634} 624}
635 625
636static int set_stream_hw(struct ua101 *ua, struct snd_pcm_substream *substream, 626static int set_stream_hw(struct ua101 *ua, struct snd_pcm_substream *substream,
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 6e354d326858..41650d5b93b7 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -136,6 +136,10 @@ check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen)
136 return strlcpy(buf, p->name, buflen); 136 return strlcpy(buf, p->name, buflen);
137} 137}
138 138
139/* ignore the error value if ignore_ctl_error flag is set */
140#define filter_error(cval, err) \
141 ((cval)->head.mixer->ignore_ctl_error ? 0 : (err))
142
139/* check whether the control should be ignored */ 143/* check whether the control should be ignored */
140static inline int 144static inline int
141check_ignored_ctl(const struct usbmix_name_map *p) 145check_ignored_ctl(const struct usbmix_name_map *p)
@@ -286,13 +290,13 @@ static int get_abs_value(struct usb_mixer_elem_info *cval, int val)
286static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, 290static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request,
287 int validx, int *value_ret) 291 int validx, int *value_ret)
288{ 292{
289 struct snd_usb_audio *chip = cval->mixer->chip; 293 struct snd_usb_audio *chip = cval->head.mixer->chip;
290 unsigned char buf[2]; 294 unsigned char buf[2];
291 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 295 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
292 int timeout = 10; 296 int timeout = 10;
293 int idx = 0, err; 297 int idx = 0, err;
294 298
295 err = snd_usb_autoresume(cval->mixer->chip); 299 err = snd_usb_autoresume(chip);
296 if (err < 0) 300 if (err < 0)
297 return -EIO; 301 return -EIO;
298 302
@@ -300,7 +304,7 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request,
300 while (timeout-- > 0) { 304 while (timeout-- > 0) {
301 if (chip->shutdown) 305 if (chip->shutdown)
302 break; 306 break;
303 idx = snd_usb_ctrl_intf(chip) | (cval->id << 8); 307 idx = snd_usb_ctrl_intf(chip) | (cval->head.id << 8);
304 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request, 308 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request,
305 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 309 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
306 validx, idx, buf, val_len) >= val_len) { 310 validx, idx, buf, val_len) >= val_len) {
@@ -316,14 +320,14 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request,
316 320
317 out: 321 out:
318 up_read(&chip->shutdown_rwsem); 322 up_read(&chip->shutdown_rwsem);
319 snd_usb_autosuspend(cval->mixer->chip); 323 snd_usb_autosuspend(chip);
320 return err; 324 return err;
321} 325}
322 326
323static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, 327static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request,
324 int validx, int *value_ret) 328 int validx, int *value_ret)
325{ 329{
326 struct snd_usb_audio *chip = cval->mixer->chip; 330 struct snd_usb_audio *chip = cval->head.mixer->chip;
327 unsigned char buf[2 + 3 * sizeof(__u16)]; /* enough space for one range */ 331 unsigned char buf[2 + 3 * sizeof(__u16)]; /* enough space for one range */
328 unsigned char *val; 332 unsigned char *val;
329 int idx = 0, ret, size; 333 int idx = 0, ret, size;
@@ -347,7 +351,7 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request,
347 if (chip->shutdown) { 351 if (chip->shutdown) {
348 ret = -ENODEV; 352 ret = -ENODEV;
349 } else { 353 } else {
350 idx = snd_usb_ctrl_intf(chip) | (cval->id << 8); 354 idx = snd_usb_ctrl_intf(chip) | (cval->head.id << 8);
351 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest, 355 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest,
352 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 356 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
353 validx, idx, buf, size); 357 validx, idx, buf, size);
@@ -392,7 +396,7 @@ static int get_ctl_value(struct usb_mixer_elem_info *cval, int request,
392{ 396{
393 validx += cval->idx_off; 397 validx += cval->idx_off;
394 398
395 return (cval->mixer->protocol == UAC_VERSION_1) ? 399 return (cval->head.mixer->protocol == UAC_VERSION_1) ?
396 get_ctl_value_v1(cval, request, validx, value_ret) : 400 get_ctl_value_v1(cval, request, validx, value_ret) :
397 get_ctl_value_v2(cval, request, validx, value_ret); 401 get_ctl_value_v2(cval, request, validx, value_ret);
398} 402}
@@ -412,7 +416,7 @@ static inline int get_cur_mix_raw(struct usb_mixer_elem_info *cval,
412 value); 416 value);
413} 417}
414 418
415static int get_cur_mix_value(struct usb_mixer_elem_info *cval, 419int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval,
416 int channel, int index, int *value) 420 int channel, int index, int *value)
417{ 421{
418 int err; 422 int err;
@@ -423,8 +427,8 @@ static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
423 } 427 }
424 err = get_cur_mix_raw(cval, channel, value); 428 err = get_cur_mix_raw(cval, channel, value);
425 if (err < 0) { 429 if (err < 0) {
426 if (!cval->mixer->ignore_ctl_error) 430 if (!cval->head.mixer->ignore_ctl_error)
427 usb_audio_dbg(cval->mixer->chip, 431 usb_audio_dbg(cval->head.mixer->chip,
428 "cannot get current value for control %d ch %d: err = %d\n", 432 "cannot get current value for control %d ch %d: err = %d\n",
429 cval->control, channel, err); 433 cval->control, channel, err);
430 return err; 434 return err;
@@ -441,13 +445,13 @@ static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
441int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval, 445int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
442 int request, int validx, int value_set) 446 int request, int validx, int value_set)
443{ 447{
444 struct snd_usb_audio *chip = cval->mixer->chip; 448 struct snd_usb_audio *chip = cval->head.mixer->chip;
445 unsigned char buf[2]; 449 unsigned char buf[2];
446 int idx = 0, val_len, err, timeout = 10; 450 int idx = 0, val_len, err, timeout = 10;
447 451
448 validx += cval->idx_off; 452 validx += cval->idx_off;
449 453
450 if (cval->mixer->protocol == UAC_VERSION_1) { 454 if (cval->head.mixer->protocol == UAC_VERSION_1) {
451 val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 455 val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
452 } else { /* UAC_VERSION_2 */ 456 } else { /* UAC_VERSION_2 */
453 /* audio class v2 controls are always 2 bytes in size */ 457 /* audio class v2 controls are always 2 bytes in size */
@@ -472,7 +476,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
472 while (timeout-- > 0) { 476 while (timeout-- > 0) {
473 if (chip->shutdown) 477 if (chip->shutdown)
474 break; 478 break;
475 idx = snd_usb_ctrl_intf(chip) | (cval->id << 8); 479 idx = snd_usb_ctrl_intf(chip) | (cval->head.id << 8);
476 if (snd_usb_ctl_msg(chip->dev, 480 if (snd_usb_ctl_msg(chip->dev,
477 usb_sndctrlpipe(chip->dev, 0), request, 481 usb_sndctrlpipe(chip->dev, 0), request,
478 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 482 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
@@ -497,7 +501,7 @@ static int set_cur_ctl_value(struct usb_mixer_elem_info *cval,
497 return snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, validx, value); 501 return snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, validx, value);
498} 502}
499 503
500static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, 504int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
501 int index, int value) 505 int index, int value)
502{ 506{
503 int err; 507 int err;
@@ -506,7 +510,7 @@ static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
506 cval->ch_readonly & (1 << (channel - 1)); 510 cval->ch_readonly & (1 << (channel - 1));
507 511
508 if (read_only) { 512 if (read_only) {
509 usb_audio_dbg(cval->mixer->chip, 513 usb_audio_dbg(cval->head.mixer->chip,
510 "%s(): channel %d of control %d is read_only\n", 514 "%s(): channel %d of control %d is read_only\n",
511 __func__, channel, cval->control); 515 __func__, channel, cval->control);
512 return 0; 516 return 0;
@@ -565,10 +569,10 @@ static int check_matrix_bitmap(unsigned char *bmap,
565 * if failed, give up and free the control instance. 569 * if failed, give up and free the control instance.
566 */ 570 */
567 571
568int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer, 572int snd_usb_mixer_add_control(struct usb_mixer_elem_list *list,
569 struct snd_kcontrol *kctl) 573 struct snd_kcontrol *kctl)
570{ 574{
571 struct usb_mixer_elem_info *cval = kctl->private_data; 575 struct usb_mixer_interface *mixer = list->mixer;
572 int err; 576 int err;
573 577
574 while (snd_ctl_find_id(mixer->chip->card, &kctl->id)) 578 while (snd_ctl_find_id(mixer->chip->card, &kctl->id))
@@ -578,9 +582,9 @@ int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer,
578 err); 582 err);
579 return err; 583 return err;
580 } 584 }
581 cval->elem_id = &kctl->id; 585 list->kctl = kctl;
582 cval->next_id_elem = mixer->id_elems[cval->id]; 586 list->next_id_elem = mixer->id_elems[list->id];
583 mixer->id_elems[cval->id] = cval; 587 mixer->id_elems[list->id] = list;
584 return 0; 588 return 0;
585} 589}
586 590
@@ -815,7 +819,7 @@ static struct usb_feature_control_info audio_feature_info[] = {
815}; 819};
816 820
817/* private_free callback */ 821/* private_free callback */
818static void usb_mixer_elem_free(struct snd_kcontrol *kctl) 822void snd_usb_mixer_elem_free(struct snd_kcontrol *kctl)
819{ 823{
820 kfree(kctl->private_data); 824 kfree(kctl->private_data);
821 kctl->private_data = NULL; 825 kctl->private_data = NULL;
@@ -829,7 +833,7 @@ static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
829static void volume_control_quirks(struct usb_mixer_elem_info *cval, 833static void volume_control_quirks(struct usb_mixer_elem_info *cval,
830 struct snd_kcontrol *kctl) 834 struct snd_kcontrol *kctl)
831{ 835{
832 struct snd_usb_audio *chip = cval->mixer->chip; 836 struct snd_usb_audio *chip = cval->head.mixer->chip;
833 switch (chip->usb_id) { 837 switch (chip->usb_id) {
834 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ 838 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
835 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */ 839 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */
@@ -954,10 +958,10 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
954 } 958 }
955 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 || 959 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 ||
956 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) { 960 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) {
957 usb_audio_err(cval->mixer->chip, 961 usb_audio_err(cval->head.mixer->chip,
958 "%d:%d: cannot get min/max values for control %d (id %d)\n", 962 "%d:%d: cannot get min/max values for control %d (id %d)\n",
959 cval->id, snd_usb_ctrl_intf(cval->mixer->chip), 963 cval->head.id, snd_usb_ctrl_intf(cval->head.mixer->chip),
960 cval->control, cval->id); 964 cval->control, cval->head.id);
961 return -EINVAL; 965 return -EINVAL;
962 } 966 }
963 if (get_ctl_value(cval, UAC_GET_RES, 967 if (get_ctl_value(cval, UAC_GET_RES,
@@ -998,7 +1002,7 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
998 else 1002 else
999 test -= cval->res; 1003 test -= cval->res;
1000 if (test < cval->min || test > cval->max || 1004 if (test < cval->min || test > cval->max ||
1001 set_cur_mix_value(cval, minchn, 0, test) || 1005 snd_usb_set_cur_mix_value(cval, minchn, 0, test) ||
1002 get_cur_mix_raw(cval, minchn, &check)) { 1006 get_cur_mix_raw(cval, minchn, &check)) {
1003 cval->res = last_valid_res; 1007 cval->res = last_valid_res;
1004 break; 1008 break;
@@ -1007,7 +1011,7 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
1007 break; 1011 break;
1008 cval->res *= 2; 1012 cval->res *= 2;
1009 } 1013 }
1010 set_cur_mix_value(cval, minchn, 0, saved); 1014 snd_usb_set_cur_mix_value(cval, minchn, 0, saved);
1011 } 1015 }
1012 1016
1013 cval->initialized = 1; 1017 cval->initialized = 1;
@@ -1061,7 +1065,7 @@ static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol,
1061 kcontrol->vd[0].access &= 1065 kcontrol->vd[0].access &=
1062 ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ | 1066 ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ |
1063 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK); 1067 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK);
1064 snd_ctl_notify(cval->mixer->chip->card, 1068 snd_ctl_notify(cval->head.mixer->chip->card,
1065 SNDRV_CTL_EVENT_MASK_INFO, 1069 SNDRV_CTL_EVENT_MASK_INFO,
1066 &kcontrol->id); 1070 &kcontrol->id);
1067 } 1071 }
@@ -1086,9 +1090,9 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol,
1086 for (c = 0; c < MAX_CHANNELS; c++) { 1090 for (c = 0; c < MAX_CHANNELS; c++) {
1087 if (!(cval->cmask & (1 << c))) 1091 if (!(cval->cmask & (1 << c)))
1088 continue; 1092 continue;
1089 err = get_cur_mix_value(cval, c + 1, cnt, &val); 1093 err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &val);
1090 if (err < 0) 1094 if (err < 0)
1091 return cval->mixer->ignore_ctl_error ? 0 : err; 1095 return filter_error(cval, err);
1092 val = get_relative_value(cval, val); 1096 val = get_relative_value(cval, val);
1093 ucontrol->value.integer.value[cnt] = val; 1097 ucontrol->value.integer.value[cnt] = val;
1094 cnt++; 1098 cnt++;
@@ -1096,9 +1100,9 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol,
1096 return 0; 1100 return 0;
1097 } else { 1101 } else {
1098 /* master channel */ 1102 /* master channel */
1099 err = get_cur_mix_value(cval, 0, 0, &val); 1103 err = snd_usb_get_cur_mix_value(cval, 0, 0, &val);
1100 if (err < 0) 1104 if (err < 0)
1101 return cval->mixer->ignore_ctl_error ? 0 : err; 1105 return filter_error(cval, err);
1102 val = get_relative_value(cval, val); 1106 val = get_relative_value(cval, val);
1103 ucontrol->value.integer.value[0] = val; 1107 ucontrol->value.integer.value[0] = val;
1104 } 1108 }
@@ -1118,26 +1122,26 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol,
1118 for (c = 0; c < MAX_CHANNELS; c++) { 1122 for (c = 0; c < MAX_CHANNELS; c++) {
1119 if (!(cval->cmask & (1 << c))) 1123 if (!(cval->cmask & (1 << c)))
1120 continue; 1124 continue;
1121 err = get_cur_mix_value(cval, c + 1, cnt, &oval); 1125 err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
1122 if (err < 0) 1126 if (err < 0)
1123 return cval->mixer->ignore_ctl_error ? 0 : err; 1127 return filter_error(cval, err);
1124 val = ucontrol->value.integer.value[cnt]; 1128 val = ucontrol->value.integer.value[cnt];
1125 val = get_abs_value(cval, val); 1129 val = get_abs_value(cval, val);
1126 if (oval != val) { 1130 if (oval != val) {
1127 set_cur_mix_value(cval, c + 1, cnt, val); 1131 snd_usb_set_cur_mix_value(cval, c + 1, cnt, val);
1128 changed = 1; 1132 changed = 1;
1129 } 1133 }
1130 cnt++; 1134 cnt++;
1131 } 1135 }
1132 } else { 1136 } else {
1133 /* master channel */ 1137 /* master channel */
1134 err = get_cur_mix_value(cval, 0, 0, &oval); 1138 err = snd_usb_get_cur_mix_value(cval, 0, 0, &oval);
1135 if (err < 0) 1139 if (err < 0)
1136 return cval->mixer->ignore_ctl_error ? 0 : err; 1140 return filter_error(cval, err);
1137 val = ucontrol->value.integer.value[0]; 1141 val = ucontrol->value.integer.value[0];
1138 val = get_abs_value(cval, val); 1142 val = get_abs_value(cval, val);
1139 if (val != oval) { 1143 if (val != oval) {
1140 set_cur_mix_value(cval, 0, 0, val); 1144 snd_usb_set_cur_mix_value(cval, 0, 0, val);
1141 changed = 1; 1145 changed = 1;
1142 } 1146 }
1143 } 1147 }
@@ -1231,8 +1235,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1231 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1235 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1232 if (!cval) 1236 if (!cval)
1233 return; 1237 return;
1234 cval->mixer = state->mixer; 1238 snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid);
1235 cval->id = unitid;
1236 cval->control = control; 1239 cval->control = control;
1237 cval->cmask = ctl_mask; 1240 cval->cmask = ctl_mask;
1238 cval->val_type = audio_feature_info[control-1].type; 1241 cval->val_type = audio_feature_info[control-1].type;
@@ -1250,7 +1253,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1250 1253
1251 /* 1254 /*
1252 * If all channels in the mask are marked read-only, make the control 1255 * If all channels in the mask are marked read-only, make the control
1253 * read-only. set_cur_mix_value() will check the mask again and won't 1256 * read-only. snd_usb_set_cur_mix_value() will check the mask again and won't
1254 * issue write commands to read-only channels. 1257 * issue write commands to read-only channels.
1255 */ 1258 */
1256 if (cval->channels == readonly_mask) 1259 if (cval->channels == readonly_mask)
@@ -1263,7 +1266,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1263 kfree(cval); 1266 kfree(cval);
1264 return; 1267 return;
1265 } 1268 }
1266 kctl->private_free = usb_mixer_elem_free; 1269 kctl->private_free = snd_usb_mixer_elem_free;
1267 1270
1268 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); 1271 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
1269 mapped_name = len != 0; 1272 mapped_name = len != 0;
@@ -1290,9 +1293,8 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1290 kctl->id.name, 1293 kctl->id.name,
1291 sizeof(kctl->id.name), 1); 1294 sizeof(kctl->id.name), 1);
1292 if (!len) 1295 if (!len)
1293 len = snprintf(kctl->id.name, 1296 snprintf(kctl->id.name, sizeof(kctl->id.name),
1294 sizeof(kctl->id.name), 1297 "Feature %d", unitid);
1295 "Feature %d", unitid);
1296 } 1298 }
1297 1299
1298 if (!mapped_name) 1300 if (!mapped_name)
@@ -1305,9 +1307,9 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1305 */ 1307 */
1306 if (!mapped_name && !(state->oterm.type >> 16)) { 1308 if (!mapped_name && !(state->oterm.type >> 16)) {
1307 if ((state->oterm.type & 0xff00) == 0x0100) 1309 if ((state->oterm.type & 0xff00) == 0x0100)
1308 len = append_ctl_name(kctl, " Capture"); 1310 append_ctl_name(kctl, " Capture");
1309 else 1311 else
1310 len = append_ctl_name(kctl, " Playback"); 1312 append_ctl_name(kctl, " Playback");
1311 } 1313 }
1312 append_ctl_name(kctl, control == UAC_FU_MUTE ? 1314 append_ctl_name(kctl, control == UAC_FU_MUTE ?
1313 " Switch" : " Volume"); 1315 " Switch" : " Volume");
@@ -1344,14 +1346,14 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1344 range); 1346 range);
1345 usb_audio_warn(state->chip, 1347 usb_audio_warn(state->chip,
1346 "[%d] FU [%s] ch = %d, val = %d/%d/%d", 1348 "[%d] FU [%s] ch = %d, val = %d/%d/%d",
1347 cval->id, kctl->id.name, cval->channels, 1349 cval->head.id, kctl->id.name, cval->channels,
1348 cval->min, cval->max, cval->res); 1350 cval->min, cval->max, cval->res);
1349 } 1351 }
1350 1352
1351 usb_audio_dbg(state->chip, "[%d] FU [%s] ch = %d, val = %d/%d/%d\n", 1353 usb_audio_dbg(state->chip, "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
1352 cval->id, kctl->id.name, cval->channels, 1354 cval->head.id, kctl->id.name, cval->channels,
1353 cval->min, cval->max, cval->res); 1355 cval->min, cval->max, cval->res);
1354 snd_usb_mixer_add_control(state->mixer, kctl); 1356 snd_usb_mixer_add_control(&cval->head, kctl);
1355} 1357}
1356 1358
1357/* 1359/*
@@ -1525,8 +1527,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
1525 if (!cval) 1527 if (!cval)
1526 return; 1528 return;
1527 1529
1528 cval->mixer = state->mixer; 1530 snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid);
1529 cval->id = unitid;
1530 cval->control = in_ch + 1; /* based on 1 */ 1531 cval->control = in_ch + 1; /* based on 1 */
1531 cval->val_type = USB_MIXER_S16; 1532 cval->val_type = USB_MIXER_S16;
1532 for (i = 0; i < num_outs; i++) { 1533 for (i = 0; i < num_outs; i++) {
@@ -1547,7 +1548,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
1547 kfree(cval); 1548 kfree(cval);
1548 return; 1549 return;
1549 } 1550 }
1550 kctl->private_free = usb_mixer_elem_free; 1551 kctl->private_free = snd_usb_mixer_elem_free;
1551 1552
1552 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); 1553 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
1553 if (!len) 1554 if (!len)
@@ -1558,8 +1559,8 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
1558 append_ctl_name(kctl, " Volume"); 1559 append_ctl_name(kctl, " Volume");
1559 1560
1560 usb_audio_dbg(state->chip, "[%d] MU [%s] ch = %d, val = %d/%d\n", 1561 usb_audio_dbg(state->chip, "[%d] MU [%s] ch = %d, val = %d/%d\n",
1561 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1562 cval->head.id, kctl->id.name, cval->channels, cval->min, cval->max);
1562 snd_usb_mixer_add_control(state->mixer, kctl); 1563 snd_usb_mixer_add_control(&cval->head, kctl);
1563} 1564}
1564 1565
1565/* 1566/*
@@ -1629,12 +1630,10 @@ static int mixer_ctl_procunit_get(struct snd_kcontrol *kcontrol,
1629 int err, val; 1630 int err, val;
1630 1631
1631 err = get_cur_ctl_value(cval, cval->control << 8, &val); 1632 err = get_cur_ctl_value(cval, cval->control << 8, &val);
1632 if (err < 0 && cval->mixer->ignore_ctl_error) { 1633 if (err < 0) {
1633 ucontrol->value.integer.value[0] = cval->min; 1634 ucontrol->value.integer.value[0] = cval->min;
1634 return 0; 1635 return filter_error(cval, err);
1635 } 1636 }
1636 if (err < 0)
1637 return err;
1638 val = get_relative_value(cval, val); 1637 val = get_relative_value(cval, val);
1639 ucontrol->value.integer.value[0] = val; 1638 ucontrol->value.integer.value[0] = val;
1640 return 0; 1639 return 0;
@@ -1648,11 +1647,8 @@ static int mixer_ctl_procunit_put(struct snd_kcontrol *kcontrol,
1648 int val, oval, err; 1647 int val, oval, err;
1649 1648
1650 err = get_cur_ctl_value(cval, cval->control << 8, &oval); 1649 err = get_cur_ctl_value(cval, cval->control << 8, &oval);
1651 if (err < 0) { 1650 if (err < 0)
1652 if (cval->mixer->ignore_ctl_error) 1651 return filter_error(cval, err);
1653 return 0;
1654 return err;
1655 }
1656 val = ucontrol->value.integer.value[0]; 1652 val = ucontrol->value.integer.value[0];
1657 val = get_abs_value(cval, val); 1653 val = get_abs_value(cval, val);
1658 if (val != oval) { 1654 if (val != oval) {
@@ -1814,8 +1810,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
1814 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1810 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1815 if (!cval) 1811 if (!cval)
1816 return -ENOMEM; 1812 return -ENOMEM;
1817 cval->mixer = state->mixer; 1813 snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid);
1818 cval->id = unitid;
1819 cval->control = valinfo->control; 1814 cval->control = valinfo->control;
1820 cval->val_type = valinfo->val_type; 1815 cval->val_type = valinfo->val_type;
1821 cval->channels = 1; 1816 cval->channels = 1;
@@ -1847,7 +1842,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
1847 kfree(cval); 1842 kfree(cval);
1848 return -ENOMEM; 1843 return -ENOMEM;
1849 } 1844 }
1850 kctl->private_free = usb_mixer_elem_free; 1845 kctl->private_free = snd_usb_mixer_elem_free;
1851 1846
1852 if (check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name))) { 1847 if (check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name))) {
1853 /* nothing */ ; 1848 /* nothing */ ;
@@ -1868,10 +1863,10 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
1868 1863
1869 usb_audio_dbg(state->chip, 1864 usb_audio_dbg(state->chip,
1870 "[%d] PU [%s] ch = %d, val = %d/%d\n", 1865 "[%d] PU [%s] ch = %d, val = %d/%d\n",
1871 cval->id, kctl->id.name, cval->channels, 1866 cval->head.id, kctl->id.name, cval->channels,
1872 cval->min, cval->max); 1867 cval->min, cval->max);
1873 1868
1874 err = snd_usb_mixer_add_control(state->mixer, kctl); 1869 err = snd_usb_mixer_add_control(&cval->head, kctl);
1875 if (err < 0) 1870 if (err < 0)
1876 return err; 1871 return err;
1877 } 1872 }
@@ -1924,11 +1919,8 @@ static int mixer_ctl_selector_get(struct snd_kcontrol *kcontrol,
1924 1919
1925 err = get_cur_ctl_value(cval, cval->control << 8, &val); 1920 err = get_cur_ctl_value(cval, cval->control << 8, &val);
1926 if (err < 0) { 1921 if (err < 0) {
1927 if (cval->mixer->ignore_ctl_error) { 1922 ucontrol->value.enumerated.item[0] = 0;
1928 ucontrol->value.enumerated.item[0] = 0; 1923 return filter_error(cval, err);
1929 return 0;
1930 }
1931 return err;
1932 } 1924 }
1933 val = get_relative_value(cval, val); 1925 val = get_relative_value(cval, val);
1934 ucontrol->value.enumerated.item[0] = val; 1926 ucontrol->value.enumerated.item[0] = val;
@@ -1943,11 +1935,8 @@ static int mixer_ctl_selector_put(struct snd_kcontrol *kcontrol,
1943 int val, oval, err; 1935 int val, oval, err;
1944 1936
1945 err = get_cur_ctl_value(cval, cval->control << 8, &oval); 1937 err = get_cur_ctl_value(cval, cval->control << 8, &oval);
1946 if (err < 0) { 1938 if (err < 0)
1947 if (cval->mixer->ignore_ctl_error) 1939 return filter_error(cval, err);
1948 return 0;
1949 return err;
1950 }
1951 val = ucontrol->value.enumerated.item[0]; 1940 val = ucontrol->value.enumerated.item[0];
1952 val = get_abs_value(cval, val); 1941 val = get_abs_value(cval, val);
1953 if (val != oval) { 1942 if (val != oval) {
@@ -2024,8 +2013,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid,
2024 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 2013 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
2025 if (!cval) 2014 if (!cval)
2026 return -ENOMEM; 2015 return -ENOMEM;
2027 cval->mixer = state->mixer; 2016 snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid);
2028 cval->id = unitid;
2029 cval->val_type = USB_MIXER_U8; 2017 cval->val_type = USB_MIXER_U8;
2030 cval->channels = 1; 2018 cval->channels = 1;
2031 cval->min = 1; 2019 cval->min = 1;
@@ -2096,11 +2084,8 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid,
2096 } 2084 }
2097 2085
2098 usb_audio_dbg(state->chip, "[%d] SU [%s] items = %d\n", 2086 usb_audio_dbg(state->chip, "[%d] SU [%s] items = %d\n",
2099 cval->id, kctl->id.name, desc->bNrInPins); 2087 cval->head.id, kctl->id.name, desc->bNrInPins);
2100 if ((err = snd_usb_mixer_add_control(state->mixer, kctl)) < 0) 2088 return snd_usb_mixer_add_control(&cval->head, kctl);
2101 return err;
2102
2103 return 0;
2104} 2089}
2105 2090
2106/* 2091/*
@@ -2245,25 +2230,21 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
2245 2230
2246void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid) 2231void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid)
2247{ 2232{
2248 struct usb_mixer_elem_info *info; 2233 struct usb_mixer_elem_list *list;
2249 2234
2250 for (info = mixer->id_elems[unitid]; info; info = info->next_id_elem) 2235 for (list = mixer->id_elems[unitid]; list; list = list->next_id_elem)
2251 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 2236 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
2252 info->elem_id); 2237 &list->kctl->id);
2253} 2238}
2254 2239
2255static void snd_usb_mixer_dump_cval(struct snd_info_buffer *buffer, 2240static void snd_usb_mixer_dump_cval(struct snd_info_buffer *buffer,
2256 int unitid, 2241 struct usb_mixer_elem_list *list)
2257 struct usb_mixer_elem_info *cval)
2258{ 2242{
2243 struct usb_mixer_elem_info *cval = (struct usb_mixer_elem_info *)list;
2259 static char *val_types[] = {"BOOLEAN", "INV_BOOLEAN", 2244 static char *val_types[] = {"BOOLEAN", "INV_BOOLEAN",
2260 "S8", "U8", "S16", "U16"}; 2245 "S8", "U8", "S16", "U16"};
2261 snd_iprintf(buffer, " Unit: %i\n", unitid);
2262 if (cval->elem_id)
2263 snd_iprintf(buffer, " Control: name=\"%s\", index=%i\n",
2264 cval->elem_id->name, cval->elem_id->index);
2265 snd_iprintf(buffer, " Info: id=%i, control=%i, cmask=0x%x, " 2246 snd_iprintf(buffer, " Info: id=%i, control=%i, cmask=0x%x, "
2266 "channels=%i, type=\"%s\"\n", cval->id, 2247 "channels=%i, type=\"%s\"\n", cval->head.id,
2267 cval->control, cval->cmask, cval->channels, 2248 cval->control, cval->cmask, cval->channels,
2268 val_types[cval->val_type]); 2249 val_types[cval->val_type]);
2269 snd_iprintf(buffer, " Volume: min=%i, max=%i, dBmin=%i, dBmax=%i\n", 2250 snd_iprintf(buffer, " Volume: min=%i, max=%i, dBmin=%i, dBmax=%i\n",
@@ -2275,7 +2256,7 @@ static void snd_usb_mixer_proc_read(struct snd_info_entry *entry,
2275{ 2256{
2276 struct snd_usb_audio *chip = entry->private_data; 2257 struct snd_usb_audio *chip = entry->private_data;
2277 struct usb_mixer_interface *mixer; 2258 struct usb_mixer_interface *mixer;
2278 struct usb_mixer_elem_info *cval; 2259 struct usb_mixer_elem_list *list;
2279 int unitid; 2260 int unitid;
2280 2261
2281 list_for_each_entry(mixer, &chip->mixer_list, list) { 2262 list_for_each_entry(mixer, &chip->mixer_list, list) {
@@ -2285,9 +2266,17 @@ static void snd_usb_mixer_proc_read(struct snd_info_entry *entry,
2285 mixer->ignore_ctl_error); 2266 mixer->ignore_ctl_error);
2286 snd_iprintf(buffer, "Card: %s\n", chip->card->longname); 2267 snd_iprintf(buffer, "Card: %s\n", chip->card->longname);
2287 for (unitid = 0; unitid < MAX_ID_ELEMS; unitid++) { 2268 for (unitid = 0; unitid < MAX_ID_ELEMS; unitid++) {
2288 for (cval = mixer->id_elems[unitid]; cval; 2269 for (list = mixer->id_elems[unitid]; list;
2289 cval = cval->next_id_elem) 2270 list = list->next_id_elem) {
2290 snd_usb_mixer_dump_cval(buffer, unitid, cval); 2271 snd_iprintf(buffer, " Unit: %i\n", list->id);
2272 if (list->kctl)
2273 snd_iprintf(buffer,
2274 " Control: name=\"%s\", index=%i\n",
2275 list->kctl->id.name,
2276 list->kctl->id.index);
2277 if (list->dump)
2278 list->dump(buffer, list);
2279 }
2291 } 2280 }
2292 } 2281 }
2293} 2282}
@@ -2295,7 +2284,7 @@ static void snd_usb_mixer_proc_read(struct snd_info_entry *entry,
2295static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer, 2284static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
2296 int attribute, int value, int index) 2285 int attribute, int value, int index)
2297{ 2286{
2298 struct usb_mixer_elem_info *info; 2287 struct usb_mixer_elem_list *list;
2299 __u8 unitid = (index >> 8) & 0xff; 2288 __u8 unitid = (index >> 8) & 0xff;
2300 __u8 control = (value >> 8) & 0xff; 2289 __u8 control = (value >> 8) & 0xff;
2301 __u8 channel = value & 0xff; 2290 __u8 channel = value & 0xff;
@@ -2307,7 +2296,13 @@ static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
2307 return; 2296 return;
2308 } 2297 }
2309 2298
2310 for (info = mixer->id_elems[unitid]; info; info = info->next_id_elem) { 2299 for (list = mixer->id_elems[unitid]; list; list = list->next_id_elem) {
2300 struct usb_mixer_elem_info *info;
2301
2302 if (!list->kctl)
2303 continue;
2304
2305 info = (struct usb_mixer_elem_info *)list;
2311 if (info->control != control) 2306 if (info->control != control)
2312 continue; 2307 continue;
2313 2308
@@ -2320,7 +2315,7 @@ static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
2320 info->cached = 0; 2315 info->cached = 0;
2321 2316
2322 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 2317 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
2323 info->elem_id); 2318 &info->head.kctl->id);
2324 break; 2319 break;
2325 2320
2326 case UAC2_CS_RANGE: 2321 case UAC2_CS_RANGE:
@@ -2485,11 +2480,8 @@ _error:
2485 return err; 2480 return err;
2486} 2481}
2487 2482
2488void snd_usb_mixer_disconnect(struct list_head *p) 2483void snd_usb_mixer_disconnect(struct usb_mixer_interface *mixer)
2489{ 2484{
2490 struct usb_mixer_interface *mixer;
2491
2492 mixer = list_entry(p, struct usb_mixer_interface, list);
2493 usb_kill_urb(mixer->urb); 2485 usb_kill_urb(mixer->urb);
2494 usb_kill_urb(mixer->rc_urb); 2486 usb_kill_urb(mixer->rc_urb);
2495} 2487}
@@ -2521,8 +2513,9 @@ int snd_usb_mixer_suspend(struct usb_mixer_interface *mixer)
2521 return 0; 2513 return 0;
2522} 2514}
2523 2515
2524static int restore_mixer_value(struct usb_mixer_elem_info *cval) 2516static int restore_mixer_value(struct usb_mixer_elem_list *list)
2525{ 2517{
2518 struct usb_mixer_elem_info *cval = (struct usb_mixer_elem_info *)list;
2526 int c, err, idx; 2519 int c, err, idx;
2527 2520
2528 if (cval->cmask) { 2521 if (cval->cmask) {
@@ -2531,7 +2524,7 @@ static int restore_mixer_value(struct usb_mixer_elem_info *cval)
2531 if (!(cval->cmask & (1 << c))) 2524 if (!(cval->cmask & (1 << c)))
2532 continue; 2525 continue;
2533 if (cval->cached & (1 << c)) { 2526 if (cval->cached & (1 << c)) {
2534 err = set_cur_mix_value(cval, c + 1, idx, 2527 err = snd_usb_set_cur_mix_value(cval, c + 1, idx,
2535 cval->cache_val[idx]); 2528 cval->cache_val[idx]);
2536 if (err < 0) 2529 if (err < 0)
2537 return err; 2530 return err;
@@ -2541,7 +2534,7 @@ static int restore_mixer_value(struct usb_mixer_elem_info *cval)
2541 } else { 2534 } else {
2542 /* master */ 2535 /* master */
2543 if (cval->cached) { 2536 if (cval->cached) {
2544 err = set_cur_mix_value(cval, 0, 0, *cval->cache_val); 2537 err = snd_usb_set_cur_mix_value(cval, 0, 0, *cval->cache_val);
2545 if (err < 0) 2538 if (err < 0)
2546 return err; 2539 return err;
2547 } 2540 }
@@ -2552,19 +2545,19 @@ static int restore_mixer_value(struct usb_mixer_elem_info *cval)
2552 2545
2553int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume) 2546int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume)
2554{ 2547{
2555 struct usb_mixer_elem_info *cval; 2548 struct usb_mixer_elem_list *list;
2556 int id, err; 2549 int id, err;
2557 2550
2558 /* FIXME: any mixer quirks? */
2559
2560 if (reset_resume) { 2551 if (reset_resume) {
2561 /* restore cached mixer values */ 2552 /* restore cached mixer values */
2562 for (id = 0; id < MAX_ID_ELEMS; id++) { 2553 for (id = 0; id < MAX_ID_ELEMS; id++) {
2563 for (cval = mixer->id_elems[id]; cval; 2554 for (list = mixer->id_elems[id]; list;
2564 cval = cval->next_id_elem) { 2555 list = list->next_id_elem) {
2565 err = restore_mixer_value(cval); 2556 if (list->resume) {
2566 if (err < 0) 2557 err = list->resume(list);
2567 return err; 2558 if (err < 0)
2559 return err;
2560 }
2568 } 2561 }
2569 } 2562 }
2570 } 2563 }
@@ -2572,3 +2565,15 @@ int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume)
2572 return snd_usb_mixer_activate(mixer); 2565 return snd_usb_mixer_activate(mixer);
2573} 2566}
2574#endif 2567#endif
2568
2569void snd_usb_mixer_elem_init_std(struct usb_mixer_elem_list *list,
2570 struct usb_mixer_interface *mixer,
2571 int unitid)
2572{
2573 list->mixer = mixer;
2574 list->id = unitid;
2575 list->dump = snd_usb_mixer_dump_cval;
2576#ifdef CONFIG_PM
2577 list->resume = restore_mixer_value;
2578#endif
2579}
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index 73b1f649447b..d3268f0ee2b3 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -1,6 +1,8 @@
1#ifndef __USBMIXER_H 1#ifndef __USBMIXER_H
2#define __USBMIXER_H 2#define __USBMIXER_H
3 3
4#include <sound/info.h>
5
4struct usb_mixer_interface { 6struct usb_mixer_interface {
5 struct snd_usb_audio *chip; 7 struct snd_usb_audio *chip;
6 struct usb_host_interface *hostif; 8 struct usb_host_interface *hostif;
@@ -8,7 +10,7 @@ struct usb_mixer_interface {
8 unsigned int ignore_ctl_error; 10 unsigned int ignore_ctl_error;
9 struct urb *urb; 11 struct urb *urb;
10 /* array[MAX_ID_ELEMS], indexed by unit id */ 12 /* array[MAX_ID_ELEMS], indexed by unit id */
11 struct usb_mixer_elem_info **id_elems; 13 struct usb_mixer_elem_list **id_elems;
12 14
13 /* the usb audio specification version this interface complies to */ 15 /* the usb audio specification version this interface complies to */
14 int protocol; 16 int protocol;
@@ -20,9 +22,6 @@ struct usb_mixer_interface {
20 struct urb *rc_urb; 22 struct urb *rc_urb;
21 struct usb_ctrlrequest *rc_setup_packet; 23 struct usb_ctrlrequest *rc_setup_packet;
22 u8 rc_buffer[6]; 24 u8 rc_buffer[6];
23
24 u8 audigy2nx_leds[3];
25 u8 xonar_u1_status;
26}; 25};
27 26
28#define MAX_CHANNELS 16 /* max logical channels */ 27#define MAX_CHANNELS 16 /* max logical channels */
@@ -36,11 +35,21 @@ enum {
36 USB_MIXER_U16, 35 USB_MIXER_U16,
37}; 36};
38 37
39struct usb_mixer_elem_info { 38typedef void (*usb_mixer_elem_dump_func_t)(struct snd_info_buffer *buffer,
39 struct usb_mixer_elem_list *list);
40typedef int (*usb_mixer_elem_resume_func_t)(struct usb_mixer_elem_list *elem);
41
42struct usb_mixer_elem_list {
40 struct usb_mixer_interface *mixer; 43 struct usb_mixer_interface *mixer;
41 struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */ 44 struct usb_mixer_elem_list *next_id_elem; /* list of controls with same id */
42 struct snd_ctl_elem_id *elem_id; 45 struct snd_kcontrol *kctl;
43 unsigned int id; 46 unsigned int id;
47 usb_mixer_elem_dump_func_t dump;
48 usb_mixer_elem_resume_func_t resume;
49};
50
51struct usb_mixer_elem_info {
52 struct usb_mixer_elem_list head;
44 unsigned int control; /* CS or ICN (high byte) */ 53 unsigned int control; /* CS or ICN (high byte) */
45 unsigned int cmask; /* channel mask bitmap: 0 = master */ 54 unsigned int cmask; /* channel mask bitmap: 0 = master */
46 unsigned int idx_off; /* Control index offset */ 55 unsigned int idx_off; /* Control index offset */
@@ -53,20 +62,25 @@ struct usb_mixer_elem_info {
53 int cached; 62 int cached;
54 int cache_val[MAX_CHANNELS]; 63 int cache_val[MAX_CHANNELS];
55 u8 initialized; 64 u8 initialized;
65 void *private_data;
56}; 66};
57 67
58int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, 68int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
59 int ignore_error); 69 int ignore_error);
60void snd_usb_mixer_disconnect(struct list_head *p); 70void snd_usb_mixer_disconnect(struct usb_mixer_interface *mixer);
61 71
62void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid); 72void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid);
63 73
64int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval, 74int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
65 int request, int validx, int value_set); 75 int request, int validx, int value_set);
66 76
67int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer, 77int snd_usb_mixer_add_control(struct usb_mixer_elem_list *list,
68 struct snd_kcontrol *kctl); 78 struct snd_kcontrol *kctl);
69 79
80void snd_usb_mixer_elem_init_std(struct usb_mixer_elem_list *list,
81 struct usb_mixer_interface *mixer,
82 int unitid);
83
70int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, 84int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
71 unsigned int size, unsigned int __user *_tlv); 85 unsigned int size, unsigned int __user *_tlv);
72 86
@@ -75,4 +89,12 @@ int snd_usb_mixer_suspend(struct usb_mixer_interface *mixer);
75int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume); 89int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume);
76#endif 90#endif
77 91
92int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
93 int index, int value);
94
95int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval,
96 int channel, int index, int *value);
97
98extern void snd_usb_mixer_elem_free(struct snd_kcontrol *kctl);
99
78#endif /* __USBMIXER_H */ 100#endif /* __USBMIXER_H */
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index d1d72ff50347..1994d41348f8 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -179,6 +179,11 @@ static struct usbmix_name_map audigy2nx_map[] = {
179 { 0 } /* terminator */ 179 { 0 } /* terminator */
180}; 180};
181 181
182static struct usbmix_name_map mbox1_map[] = {
183 { 1, "Clock" },
184 { 0 } /* terminator */
185};
186
182static struct usbmix_selector_map c400_selectors[] = { 187static struct usbmix_selector_map c400_selectors[] = {
183 { 188 {
184 .id = 0x80, 189 .id = 0x80,
@@ -416,6 +421,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
416 .map = aureon_51_2_map, 421 .map = aureon_51_2_map,
417 }, 422 },
418 { 423 {
424 .id = USB_ID(0x0dba, 0x1000),
425 .map = mbox1_map,
426 },
427 {
419 .id = USB_ID(0x13e5, 0x0001), 428 .id = USB_ID(0x13e5, 0x0001),
420 .map = scratch_live_map, 429 .map = scratch_live_map,
421 .ignore_ctl_error = 1, 430 .ignore_ctl_error = 1,
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 8c9bf4b7aaf0..dc9df007d3e3 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -41,6 +41,7 @@
41#include "usbaudio.h" 41#include "usbaudio.h"
42#include "mixer.h" 42#include "mixer.h"
43#include "mixer_quirks.h" 43#include "mixer_quirks.h"
44#include "mixer_scarlett.h"
44#include "helper.h" 45#include "helper.h"
45 46
46extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl; 47extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
@@ -52,13 +53,6 @@ struct std_mono_table {
52 snd_kcontrol_tlv_rw_t *tlv_callback; 53 snd_kcontrol_tlv_rw_t *tlv_callback;
53}; 54};
54 55
55/* private_free callback */
56static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
57{
58 kfree(kctl->private_data);
59 kctl->private_data = NULL;
60}
61
62/* This function allows for the creation of standard UAC controls. 56/* This function allows for the creation of standard UAC controls.
63 * See the quirks for M-Audio FTUs or Ebox-44. 57 * See the quirks for M-Audio FTUs or Ebox-44.
64 * If you don't want to set a TLV callback pass NULL. 58 * If you don't want to set a TLV callback pass NULL.
@@ -75,7 +69,6 @@ static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
75 const char *name, 69 const char *name,
76 snd_kcontrol_tlv_rw_t *tlv_callback) 70 snd_kcontrol_tlv_rw_t *tlv_callback)
77{ 71{
78 int err;
79 struct usb_mixer_elem_info *cval; 72 struct usb_mixer_elem_info *cval;
80 struct snd_kcontrol *kctl; 73 struct snd_kcontrol *kctl;
81 74
@@ -83,8 +76,7 @@ static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
83 if (!cval) 76 if (!cval)
84 return -ENOMEM; 77 return -ENOMEM;
85 78
86 cval->id = unitid; 79 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
87 cval->mixer = mixer;
88 cval->val_type = val_type; 80 cval->val_type = val_type;
89 cval->channels = 1; 81 cval->channels = 1;
90 cval->control = control; 82 cval->control = control;
@@ -108,7 +100,7 @@ static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
108 100
109 /* Set name */ 101 /* Set name */
110 snprintf(kctl->id.name, sizeof(kctl->id.name), name); 102 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
111 kctl->private_free = usb_mixer_elem_free; 103 kctl->private_free = snd_usb_mixer_elem_free;
112 104
113 /* set TLV */ 105 /* set TLV */
114 if (tlv_callback) { 106 if (tlv_callback) {
@@ -118,11 +110,7 @@ static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
118 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 110 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
119 } 111 }
120 /* Add control to mixer */ 112 /* Add control to mixer */
121 err = snd_usb_mixer_add_control(mixer, kctl); 113 return snd_usb_mixer_add_control(&cval->head, kctl);
122 if (err < 0)
123 return err;
124
125 return 0;
126} 114}
127 115
128static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, 116static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
@@ -156,6 +144,32 @@ static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
156 return 0; 144 return 0;
157} 145}
158 146
147static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
148 int id,
149 usb_mixer_elem_resume_func_t resume,
150 const struct snd_kcontrol_new *knew,
151 struct usb_mixer_elem_list **listp)
152{
153 struct usb_mixer_elem_list *list;
154 struct snd_kcontrol *kctl;
155
156 list = kzalloc(sizeof(*list), GFP_KERNEL);
157 if (!list)
158 return -ENOMEM;
159 if (listp)
160 *listp = list;
161 list->mixer = mixer;
162 list->id = id;
163 list->resume = resume;
164 kctl = snd_ctl_new1(knew, list);
165 if (!kctl) {
166 kfree(list);
167 return -ENOMEM;
168 }
169 kctl->private_free = snd_usb_mixer_elem_free;
170 return snd_usb_mixer_add_control(list, kctl);
171}
172
159/* 173/*
160 * Sound Blaster remote control configuration 174 * Sound Blaster remote control configuration
161 * 175 *
@@ -283,84 +297,90 @@ static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
283 297
284static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 298static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
285{ 299{
286 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 300 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
287 int index = kcontrol->private_value;
288
289 ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
290 return 0; 301 return 0;
291} 302}
292 303
293static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 304static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
305 int value, int index)
294{ 306{
295 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 307 struct snd_usb_audio *chip = mixer->chip;
296 int index = kcontrol->private_value; 308 int err;
297 int value = ucontrol->value.integer.value[0];
298 int err, changed;
299 309
300 if (value > 1) 310 down_read(&chip->shutdown_rwsem);
301 return -EINVAL; 311 if (chip->shutdown) {
302 changed = value != mixer->audigy2nx_leds[index];
303 down_read(&mixer->chip->shutdown_rwsem);
304 if (mixer->chip->shutdown) {
305 err = -ENODEV; 312 err = -ENODEV;
306 goto out; 313 goto out;
307 } 314 }
308 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) 315 if (chip->usb_id == USB_ID(0x041e, 0x3042))
309 err = snd_usb_ctl_msg(mixer->chip->dev, 316 err = snd_usb_ctl_msg(chip->dev,
310 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 317 usb_sndctrlpipe(chip->dev, 0), 0x24,
311 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 318 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
312 !value, 0, NULL, 0); 319 !value, 0, NULL, 0);
313 /* USB X-Fi S51 Pro */ 320 /* USB X-Fi S51 Pro */
314 if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) 321 if (chip->usb_id == USB_ID(0x041e, 0x30df))
315 err = snd_usb_ctl_msg(mixer->chip->dev, 322 err = snd_usb_ctl_msg(chip->dev,
316 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 323 usb_sndctrlpipe(chip->dev, 0), 0x24,
317 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 324 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
318 !value, 0, NULL, 0); 325 !value, 0, NULL, 0);
319 else 326 else
320 err = snd_usb_ctl_msg(mixer->chip->dev, 327 err = snd_usb_ctl_msg(chip->dev,
321 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 328 usb_sndctrlpipe(chip->dev, 0), 0x24,
322 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 329 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
323 value, index + 2, NULL, 0); 330 value, index + 2, NULL, 0);
324 out: 331 out:
325 up_read(&mixer->chip->shutdown_rwsem); 332 up_read(&chip->shutdown_rwsem);
326 if (err < 0) 333 return err;
327 return err;
328 mixer->audigy2nx_leds[index] = value;
329 return changed;
330} 334}
331 335
332static struct snd_kcontrol_new snd_audigy2nx_controls[] = { 336static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
333 { 337 struct snd_ctl_elem_value *ucontrol)
334 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 338{
335 .name = "CMSS LED Switch", 339 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
336 .info = snd_audigy2nx_led_info, 340 struct usb_mixer_interface *mixer = list->mixer;
337 .get = snd_audigy2nx_led_get, 341 int index = kcontrol->private_value & 0xff;
338 .put = snd_audigy2nx_led_put, 342 int value = ucontrol->value.integer.value[0];
339 .private_value = 0, 343 int old_value = kcontrol->private_value >> 8;
340 }, 344 int err;
341 { 345
342 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 346 if (value > 1)
343 .name = "Power LED Switch", 347 return -EINVAL;
344 .info = snd_audigy2nx_led_info, 348 if (value == old_value)
345 .get = snd_audigy2nx_led_get, 349 return 0;
346 .put = snd_audigy2nx_led_put, 350 kcontrol->private_value = (value << 8) | index;
347 .private_value = 1, 351 err = snd_audigy2nx_led_update(mixer, value, index);
348 }, 352 return err < 0 ? err : 1;
349 { 353}
350 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 354
351 .name = "Dolby Digital LED Switch", 355static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
352 .info = snd_audigy2nx_led_info, 356{
353 .get = snd_audigy2nx_led_get, 357 int priv_value = list->kctl->private_value;
354 .put = snd_audigy2nx_led_put, 358
355 .private_value = 2, 359 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
356 }, 360 priv_value & 0xff);
361}
362
363/* name and private_value are set dynamically */
364static struct snd_kcontrol_new snd_audigy2nx_control = {
365 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
366 .info = snd_audigy2nx_led_info,
367 .get = snd_audigy2nx_led_get,
368 .put = snd_audigy2nx_led_put,
369};
370
371static const char * const snd_audigy2nx_led_names[] = {
372 "CMSS LED Switch",
373 "Power LED Switch",
374 "Dolby Digital LED Switch",
357}; 375};
358 376
359static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) 377static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
360{ 378{
361 int i, err; 379 int i, err;
362 380
363 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { 381 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
382 struct snd_kcontrol_new knew;
383
364 /* USB X-Fi S51 doesn't have a CMSS LED */ 384 /* USB X-Fi S51 doesn't have a CMSS LED */
365 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0) 385 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
366 continue; 386 continue;
@@ -373,12 +393,16 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
373 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) || 393 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
374 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) 394 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
375 break; 395 break;
376 err = snd_ctl_add(mixer->chip->card, 396
377 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer)); 397 knew = snd_audigy2nx_control;
398 knew.name = snd_audigy2nx_led_names[i];
399 knew.private_value = (1 << 8) | i; /* LED on as default */
400 err = add_single_ctl_with_resume(mixer, 0,
401 snd_audigy2nx_led_resume,
402 &knew, NULL);
378 if (err < 0) 403 if (err < 0)
379 return err; 404 return err;
380 } 405 }
381 mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
382 return 0; 406 return 0;
383} 407}
384 408
@@ -437,19 +461,9 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
437static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol, 461static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
438 struct snd_ctl_elem_info *uinfo) 462 struct snd_ctl_elem_info *uinfo)
439{ 463{
440 static const char *texts[2] = {"1/2", 464 static const char * const texts[2] = {"1/2", "3/4"};
441 "3/4"
442 };
443 465
444 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 466 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
445 uinfo->count = 1;
446 uinfo->value.enumerated.items = 2;
447 if (uinfo->value.enumerated.item > 1)
448 uinfo->value.enumerated.item = 1;
449 strcpy(uinfo->value.enumerated.name,
450 texts[uinfo->value.enumerated.item]);
451
452 return 0;
453} 467}
454 468
455static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol, 469static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
@@ -459,100 +473,122 @@ static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
459 return 0; 473 return 0;
460} 474}
461 475
462static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol, 476static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
463 struct snd_ctl_elem_value *ucontrol) 477 int value)
464{ 478{
465 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 479 struct snd_usb_audio *chip = mixer->chip;
466 unsigned int value = ucontrol->value.enumerated.item[0]; 480 int err;
467 int err, changed;
468 unsigned char buf[2]; 481 unsigned char buf[2];
469 482
470 if (value > 1) 483 down_read(&chip->shutdown_rwsem);
471 return -EINVAL;
472
473 buf[0] = 0x01;
474 buf[1] = value ? 0x02 : 0x01;
475
476 changed = value != kcontrol->private_value;
477 down_read(&mixer->chip->shutdown_rwsem);
478 if (mixer->chip->shutdown) { 484 if (mixer->chip->shutdown) {
479 err = -ENODEV; 485 err = -ENODEV;
480 goto out; 486 goto out;
481 } 487 }
482 err = snd_usb_ctl_msg(mixer->chip->dev, 488
483 usb_sndctrlpipe(mixer->chip->dev, 0), UAC_SET_CUR, 489 buf[0] = 0x01;
490 buf[1] = value ? 0x02 : 0x01;
491 err = snd_usb_ctl_msg(chip->dev,
492 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
484 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 493 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
485 0x0400, 0x0e00, buf, 2); 494 0x0400, 0x0e00, buf, 2);
486 out: 495 out:
487 up_read(&mixer->chip->shutdown_rwsem); 496 up_read(&chip->shutdown_rwsem);
488 if (err < 0) 497 return err;
489 return err; 498}
499
500static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
501 struct snd_ctl_elem_value *ucontrol)
502{
503 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
504 struct usb_mixer_interface *mixer = list->mixer;
505 unsigned int value = ucontrol->value.enumerated.item[0];
506 int err;
507
508 if (value > 1)
509 return -EINVAL;
510
511 if (value == kcontrol->private_value)
512 return 0;
513
490 kcontrol->private_value = value; 514 kcontrol->private_value = value;
491 return changed; 515 err = snd_emu0204_ch_switch_update(mixer, value);
516 return err < 0 ? err : 1;
492} 517}
493 518
519static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
520{
521 return snd_emu0204_ch_switch_update(list->mixer,
522 list->kctl->private_value);
523}
494 524
495static struct snd_kcontrol_new snd_emu0204_controls[] = { 525static struct snd_kcontrol_new snd_emu0204_control = {
496 { 526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 527 .name = "Front Jack Channels",
498 .name = "Front Jack Channels", 528 .info = snd_emu0204_ch_switch_info,
499 .info = snd_emu0204_ch_switch_info, 529 .get = snd_emu0204_ch_switch_get,
500 .get = snd_emu0204_ch_switch_get, 530 .put = snd_emu0204_ch_switch_put,
501 .put = snd_emu0204_ch_switch_put, 531 .private_value = 0,
502 .private_value = 0,
503 },
504}; 532};
505 533
506static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer) 534static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
507{ 535{
508 int i, err; 536 return add_single_ctl_with_resume(mixer, 0,
509 537 snd_emu0204_ch_switch_resume,
510 for (i = 0; i < ARRAY_SIZE(snd_emu0204_controls); ++i) { 538 &snd_emu0204_control, NULL);
511 err = snd_ctl_add(mixer->chip->card,
512 snd_ctl_new1(&snd_emu0204_controls[i], mixer));
513 if (err < 0)
514 return err;
515 }
516
517 return 0;
518} 539}
540
519/* ASUS Xonar U1 / U3 controls */ 541/* ASUS Xonar U1 / U3 controls */
520 542
521static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, 543static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
522 struct snd_ctl_elem_value *ucontrol) 544 struct snd_ctl_elem_value *ucontrol)
523{ 545{
524 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 546 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
525
526 ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
527 return 0; 547 return 0;
528} 548}
529 549
550static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
551 unsigned char status)
552{
553 struct snd_usb_audio *chip = mixer->chip;
554 int err;
555
556 down_read(&chip->shutdown_rwsem);
557 if (chip->shutdown)
558 err = -ENODEV;
559 else
560 err = snd_usb_ctl_msg(chip->dev,
561 usb_sndctrlpipe(chip->dev, 0), 0x08,
562 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
563 50, 0, &status, 1);
564 up_read(&chip->shutdown_rwsem);
565 return err;
566}
567
530static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, 568static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
531 struct snd_ctl_elem_value *ucontrol) 569 struct snd_ctl_elem_value *ucontrol)
532{ 570{
533 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 571 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
534 u8 old_status, new_status; 572 u8 old_status, new_status;
535 int err, changed; 573 int err;
536 574
537 old_status = mixer->xonar_u1_status; 575 old_status = kcontrol->private_value;
538 if (ucontrol->value.integer.value[0]) 576 if (ucontrol->value.integer.value[0])
539 new_status = old_status | 0x02; 577 new_status = old_status | 0x02;
540 else 578 else
541 new_status = old_status & ~0x02; 579 new_status = old_status & ~0x02;
542 changed = new_status != old_status; 580 if (new_status == old_status)
543 down_read(&mixer->chip->shutdown_rwsem); 581 return 0;
544 if (mixer->chip->shutdown) 582
545 err = -ENODEV; 583 kcontrol->private_value = new_status;
546 else 584 err = snd_xonar_u1_switch_update(list->mixer, new_status);
547 err = snd_usb_ctl_msg(mixer->chip->dev, 585 return err < 0 ? err : 1;
548 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, 586}
549 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 587
550 50, 0, &new_status, 1); 588static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
551 up_read(&mixer->chip->shutdown_rwsem); 589{
552 if (err < 0) 590 return snd_xonar_u1_switch_update(list->mixer,
553 return err; 591 list->kctl->private_value);
554 mixer->xonar_u1_status = new_status;
555 return changed;
556} 592}
557 593
558static struct snd_kcontrol_new snd_xonar_u1_output_switch = { 594static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
@@ -561,82 +597,213 @@ static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
561 .info = snd_ctl_boolean_mono_info, 597 .info = snd_ctl_boolean_mono_info,
562 .get = snd_xonar_u1_switch_get, 598 .get = snd_xonar_u1_switch_get,
563 .put = snd_xonar_u1_switch_put, 599 .put = snd_xonar_u1_switch_put,
600 .private_value = 0x05,
564}; 601};
565 602
566static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) 603static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
567{ 604{
605 return add_single_ctl_with_resume(mixer, 0,
606 snd_xonar_u1_switch_resume,
607 &snd_xonar_u1_output_switch, NULL);
608}
609
610/* Digidesign Mbox 1 clock source switch (internal/spdif) */
611
612static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
613 struct snd_ctl_elem_value *ucontrol)
614{
615 ucontrol->value.enumerated.item[0] = kctl->private_value;
616 return 0;
617}
618
619static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
620{
621 struct snd_usb_audio *chip = mixer->chip;
568 int err; 622 int err;
623 unsigned char buff[3];
624
625 down_read(&chip->shutdown_rwsem);
626 if (chip->shutdown) {
627 err = -ENODEV;
628 goto err;
629 }
569 630
570 err = snd_ctl_add(mixer->chip->card, 631 /* Prepare for magic command to toggle clock source */
571 snd_ctl_new1(&snd_xonar_u1_output_switch, mixer)); 632 err = snd_usb_ctl_msg(chip->dev,
633 usb_rcvctrlpipe(chip->dev, 0), 0x81,
634 USB_DIR_IN |
635 USB_TYPE_CLASS |
636 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
572 if (err < 0) 637 if (err < 0)
573 return err; 638 goto err;
574 mixer->xonar_u1_status = 0x05; 639 err = snd_usb_ctl_msg(chip->dev,
575 return 0; 640 usb_rcvctrlpipe(chip->dev, 0), 0x81,
641 USB_DIR_IN |
642 USB_TYPE_CLASS |
643 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
644 if (err < 0)
645 goto err;
646
647 /* 2 possibilities: Internal -> send sample rate
648 * S/PDIF sync -> send zeroes
649 * NB: Sample rate locked to 48kHz on purpose to
650 * prevent user from resetting the sample rate
651 * while S/PDIF sync is enabled and confusing
652 * this configuration.
653 */
654 if (val == 0) {
655 buff[0] = 0x80;
656 buff[1] = 0xbb;
657 buff[2] = 0x00;
658 } else {
659 buff[0] = buff[1] = buff[2] = 0x00;
660 }
661
662 /* Send the magic command to toggle the clock source */
663 err = snd_usb_ctl_msg(chip->dev,
664 usb_sndctrlpipe(chip->dev, 0), 0x1,
665 USB_TYPE_CLASS |
666 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
667 if (err < 0)
668 goto err;
669 err = snd_usb_ctl_msg(chip->dev,
670 usb_rcvctrlpipe(chip->dev, 0), 0x81,
671 USB_DIR_IN |
672 USB_TYPE_CLASS |
673 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
674 if (err < 0)
675 goto err;
676 err = snd_usb_ctl_msg(chip->dev,
677 usb_rcvctrlpipe(chip->dev, 0), 0x81,
678 USB_DIR_IN |
679 USB_TYPE_CLASS |
680 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
681 if (err < 0)
682 goto err;
683
684err:
685 up_read(&chip->shutdown_rwsem);
686 return err;
687}
688
689static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
690 struct snd_ctl_elem_value *ucontrol)
691{
692 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
693 struct usb_mixer_interface *mixer = list->mixer;
694 int err;
695 bool cur_val, new_val;
696
697 cur_val = kctl->private_value;
698 new_val = ucontrol->value.enumerated.item[0];
699 if (cur_val == new_val)
700 return 0;
701
702 kctl->private_value = new_val;
703 err = snd_mbox1_switch_update(mixer, new_val);
704 return err < 0 ? err : 1;
705}
706
707static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
708 struct snd_ctl_elem_info *uinfo)
709{
710 static const char *const texts[2] = {
711 "Internal",
712 "S/PDIF"
713 };
714
715 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
716}
717
718static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
719{
720 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
721}
722
723static struct snd_kcontrol_new snd_mbox1_switch = {
724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
725 .name = "Clock Source",
726 .index = 0,
727 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
728 .info = snd_mbox1_switch_info,
729 .get = snd_mbox1_switch_get,
730 .put = snd_mbox1_switch_put,
731 .private_value = 0
732};
733
734static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
735{
736 return add_single_ctl_with_resume(mixer, 0,
737 snd_mbox1_switch_resume,
738 &snd_mbox1_switch, NULL);
576} 739}
577 740
578/* Native Instruments device quirks */ 741/* Native Instruments device quirks */
579 742
580#define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex)) 743#define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
581 744
582static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol, 745static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
583 struct snd_ctl_elem_value *ucontrol) 746 struct snd_kcontrol *kctl)
584{ 747{
585 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
586 struct usb_device *dev = mixer->chip->dev; 748 struct usb_device *dev = mixer->chip->dev;
587 u8 bRequest = (kcontrol->private_value >> 16) & 0xff; 749 unsigned int pval = kctl->private_value;
588 u16 wIndex = kcontrol->private_value & 0xffff; 750 u8 value;
589 u8 tmp; 751 int err;
590 int ret;
591
592 down_read(&mixer->chip->shutdown_rwsem);
593 if (mixer->chip->shutdown)
594 ret = -ENODEV;
595 else
596 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
597 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
598 0, wIndex,
599 &tmp, sizeof(tmp));
600 up_read(&mixer->chip->shutdown_rwsem);
601 752
602 if (ret < 0) { 753 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
754 (pval >> 16) & 0xff,
755 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
756 0, pval & 0xffff, &value, 1);
757 if (err < 0) {
603 dev_err(&dev->dev, 758 dev_err(&dev->dev,
604 "unable to issue vendor read request (ret = %d)", ret); 759 "unable to issue vendor read request (ret = %d)", err);
605 return ret; 760 return err;
606 } 761 }
607 762
608 ucontrol->value.integer.value[0] = tmp; 763 kctl->private_value |= (value << 24);
764 return 0;
765}
609 766
767static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
768 struct snd_ctl_elem_value *ucontrol)
769{
770 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
610 return 0; 771 return 0;
611} 772}
612 773
774static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
775{
776 struct snd_usb_audio *chip = list->mixer->chip;
777 unsigned int pval = list->kctl->private_value;
778 int err;
779
780 down_read(&chip->shutdown_rwsem);
781 if (chip->shutdown)
782 err = -ENODEV;
783 else
784 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
785 (pval >> 16) & 0xff,
786 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
787 pval >> 24, pval & 0xffff, NULL, 0, 1000);
788 up_read(&chip->shutdown_rwsem);
789 return err;
790}
791
613static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol, 792static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
614 struct snd_ctl_elem_value *ucontrol) 793 struct snd_ctl_elem_value *ucontrol)
615{ 794{
616 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 795 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
617 struct usb_device *dev = mixer->chip->dev; 796 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
618 u8 bRequest = (kcontrol->private_value >> 16) & 0xff; 797 u8 newval = ucontrol->value.integer.value[0];
619 u16 wIndex = kcontrol->private_value & 0xffff; 798 int err;
620 u16 wValue = ucontrol->value.integer.value[0];
621 int ret;
622
623 down_read(&mixer->chip->shutdown_rwsem);
624 if (mixer->chip->shutdown)
625 ret = -ENODEV;
626 else
627 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
628 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
629 wValue, wIndex,
630 NULL, 0, 1000);
631 up_read(&mixer->chip->shutdown_rwsem);
632 799
633 if (ret < 0) { 800 if (oldval == newval)
634 dev_err(&dev->dev, 801 return 0;
635 "unable to issue vendor write request (ret = %d)", ret);
636 return ret;
637 }
638 802
639 return 0; 803 kcontrol->private_value &= ~(0xff << 24);
804 kcontrol->private_value |= newval;
805 err = snd_ni_update_cur_val(list);
806 return err < 0 ? err : 1;
640} 807}
641 808
642static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = { 809static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
@@ -707,16 +874,17 @@ static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
707 }; 874 };
708 875
709 for (i = 0; i < count; i++) { 876 for (i = 0; i < count; i++) {
710 struct snd_kcontrol *c; 877 struct usb_mixer_elem_list *list;
711 878
712 template.name = kc[i].name; 879 template.name = kc[i].name;
713 template.private_value = kc[i].private_value; 880 template.private_value = kc[i].private_value;
714 881
715 c = snd_ctl_new1(&template, mixer); 882 err = add_single_ctl_with_resume(mixer, 0,
716 err = snd_ctl_add(mixer->chip->card, c); 883 snd_ni_update_cur_val,
717 884 &template, &list);
718 if (err < 0) 885 if (err < 0)
719 break; 886 break;
887 snd_ni_control_init_val(mixer, list->kctl);
720 } 888 }
721 889
722 return err; 890 return err;
@@ -724,170 +892,88 @@ static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
724 892
725/* M-Audio FastTrack Ultra quirks */ 893/* M-Audio FastTrack Ultra quirks */
726/* FTU Effect switch (also used by C400/C600) */ 894/* FTU Effect switch (also used by C400/C600) */
727struct snd_ftu_eff_switch_priv_val {
728 struct usb_mixer_interface *mixer;
729 int cached_value;
730 int is_cached;
731 int bUnitID;
732 int validx;
733};
734
735static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol, 895static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
736 struct snd_ctl_elem_info *uinfo) 896 struct snd_ctl_elem_info *uinfo)
737{ 897{
738 static const char *texts[8] = {"Room 1", 898 static const char *const texts[8] = {
739 "Room 2", 899 "Room 1", "Room 2", "Room 3", "Hall 1",
740 "Room 3", 900 "Hall 2", "Plate", "Delay", "Echo"
741 "Hall 1",
742 "Hall 2",
743 "Plate",
744 "Delay",
745 "Echo"
746 }; 901 };
747 902
748 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 903 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
749 uinfo->count = 1;
750 uinfo->value.enumerated.items = 8;
751 if (uinfo->value.enumerated.item > 7)
752 uinfo->value.enumerated.item = 7;
753 strcpy(uinfo->value.enumerated.name,
754 texts[uinfo->value.enumerated.item]);
755
756 return 0;
757} 904}
758 905
759static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl, 906static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
760 struct snd_ctl_elem_value *ucontrol) 907 struct snd_kcontrol *kctl)
761{ 908{
762 struct snd_usb_audio *chip; 909 struct usb_device *dev = mixer->chip->dev;
763 struct usb_mixer_interface *mixer; 910 unsigned int pval = kctl->private_value;
764 struct snd_ftu_eff_switch_priv_val *pval;
765 int err; 911 int err;
766 unsigned char value[2]; 912 unsigned char value[2];
767 int id, validx;
768
769 const int val_len = 2;
770 913
771 value[0] = 0x00; 914 value[0] = 0x00;
772 value[1] = 0x00; 915 value[1] = 0x00;
773 916
774 pval = (struct snd_ftu_eff_switch_priv_val *) 917 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
775 kctl->private_value; 918 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
919 pval & 0xff00,
920 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
921 value, 2);
922 if (err < 0)
923 return err;
776 924
777 if (pval->is_cached) { 925 kctl->private_value |= value[0] << 24;
778 ucontrol->value.enumerated.item[0] = pval->cached_value; 926 return 0;
779 return 0; 927}
780 }
781 928
782 mixer = (struct usb_mixer_interface *) pval->mixer; 929static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
783 if (snd_BUG_ON(!mixer)) 930 struct snd_ctl_elem_value *ucontrol)
784 return -EINVAL; 931{
932 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
933 return 0;
934}
785 935
786 chip = (struct snd_usb_audio *) mixer->chip; 936static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
787 if (snd_BUG_ON(!chip)) 937{
788 return -EINVAL; 938 struct snd_usb_audio *chip = list->mixer->chip;
939 unsigned int pval = list->kctl->private_value;
940 unsigned char value[2];
941 int err;
789 942
790 id = pval->bUnitID; 943 value[0] = pval >> 24;
791 validx = pval->validx; 944 value[1] = 0;
792 945
793 down_read(&mixer->chip->shutdown_rwsem); 946 down_read(&chip->shutdown_rwsem);
794 if (mixer->chip->shutdown) 947 if (chip->shutdown)
795 err = -ENODEV; 948 err = -ENODEV;
796 else 949 else
797 err = snd_usb_ctl_msg(chip->dev, 950 err = snd_usb_ctl_msg(chip->dev,
798 usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, 951 usb_sndctrlpipe(chip->dev, 0),
799 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 952 UAC_SET_CUR,
800 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), 953 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
801 value, val_len); 954 pval & 0xff00,
802 up_read(&mixer->chip->shutdown_rwsem); 955 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
803 if (err < 0) 956 value, 2);
804 return err; 957 up_read(&chip->shutdown_rwsem);
805 958 return err;
806 ucontrol->value.enumerated.item[0] = value[0];
807 pval->cached_value = value[0];
808 pval->is_cached = 1;
809
810 return 0;
811} 959}
812 960
813static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl, 961static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
814 struct snd_ctl_elem_value *ucontrol) 962 struct snd_ctl_elem_value *ucontrol)
815{ 963{
816 struct snd_usb_audio *chip; 964 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
817 struct snd_ftu_eff_switch_priv_val *pval; 965 unsigned int pval = list->kctl->private_value;
966 int cur_val, err, new_val;
818 967
819 struct usb_mixer_interface *mixer; 968 cur_val = pval >> 24;
820 int changed, cur_val, err, new_val;
821 unsigned char value[2];
822 int id, validx;
823
824 const int val_len = 2;
825
826 changed = 0;
827
828 pval = (struct snd_ftu_eff_switch_priv_val *)
829 kctl->private_value;
830 cur_val = pval->cached_value;
831 new_val = ucontrol->value.enumerated.item[0]; 969 new_val = ucontrol->value.enumerated.item[0];
970 if (cur_val == new_val)
971 return 0;
832 972
833 mixer = (struct usb_mixer_interface *) pval->mixer; 973 kctl->private_value &= ~(0xff << 24);
834 if (snd_BUG_ON(!mixer)) 974 kctl->private_value |= new_val << 24;
835 return -EINVAL; 975 err = snd_ftu_eff_switch_update(list);
836 976 return err < 0 ? err : 1;
837 chip = (struct snd_usb_audio *) mixer->chip;
838 if (snd_BUG_ON(!chip))
839 return -EINVAL;
840
841 id = pval->bUnitID;
842 validx = pval->validx;
843
844 if (!pval->is_cached) {
845 /* Read current value */
846 down_read(&mixer->chip->shutdown_rwsem);
847 if (mixer->chip->shutdown)
848 err = -ENODEV;
849 else
850 err = snd_usb_ctl_msg(chip->dev,
851 usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
852 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
853 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
854 value, val_len);
855 up_read(&mixer->chip->shutdown_rwsem);
856 if (err < 0)
857 return err;
858
859 cur_val = value[0];
860 pval->cached_value = cur_val;
861 pval->is_cached = 1;
862 }
863 /* update value if needed */
864 if (cur_val != new_val) {
865 value[0] = new_val;
866 value[1] = 0;
867 down_read(&mixer->chip->shutdown_rwsem);
868 if (mixer->chip->shutdown)
869 err = -ENODEV;
870 else
871 err = snd_usb_ctl_msg(chip->dev,
872 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
873 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
874 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
875 value, val_len);
876 up_read(&mixer->chip->shutdown_rwsem);
877 if (err < 0)
878 return err;
879
880 pval->cached_value = new_val;
881 pval->is_cached = 1;
882 changed = 1;
883 }
884
885 return changed;
886}
887
888static void kctl_private_value_free(struct snd_kcontrol *kctl)
889{
890 kfree((void *)kctl->private_value);
891} 977}
892 978
893static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer, 979static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
@@ -902,33 +988,16 @@ static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
902 .get = snd_ftu_eff_switch_get, 988 .get = snd_ftu_eff_switch_get,
903 .put = snd_ftu_eff_switch_put 989 .put = snd_ftu_eff_switch_put
904 }; 990 };
905 991 struct usb_mixer_elem_list *list;
906 int err; 992 int err;
907 struct snd_kcontrol *kctl;
908 struct snd_ftu_eff_switch_priv_val *pval;
909
910 pval = kzalloc(sizeof(*pval), GFP_KERNEL);
911 if (!pval)
912 return -ENOMEM;
913
914 pval->cached_value = 0;
915 pval->is_cached = 0;
916 pval->mixer = mixer;
917 pval->bUnitID = bUnitID;
918 pval->validx = validx;
919
920 template.private_value = (unsigned long) pval;
921 kctl = snd_ctl_new1(&template, mixer->chip);
922 if (!kctl) {
923 kfree(pval);
924 return -ENOMEM;
925 }
926 993
927 kctl->private_free = kctl_private_value_free; 994 err = add_single_ctl_with_resume(mixer, bUnitID,
928 err = snd_ctl_add(mixer->chip->card, kctl); 995 snd_ftu_eff_switch_update,
996 &template, &list);
929 if (err < 0) 997 if (err < 0)
930 return err; 998 return err;
931 999 list->kctl->private_value = (validx << 8) | bUnitID;
1000 snd_ftu_eff_switch_init(mixer, list->kctl);
932 return 0; 1001 return 0;
933} 1002}
934 1003
@@ -1110,7 +1179,7 @@ void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1110 int unitid = 12; /* SamleRate ExtensionUnit ID */ 1179 int unitid = 12; /* SamleRate ExtensionUnit ID */
1111 1180
1112 list_for_each_entry(mixer, &chip->mixer_list, list) { 1181 list_for_each_entry(mixer, &chip->mixer_list, list) {
1113 cval = mixer->id_elems[unitid]; 1182 cval = (struct usb_mixer_elem_info *)mixer->id_elems[unitid];
1114 if (cval) { 1183 if (cval) {
1115 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, 1184 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1116 cval->control << 8, 1185 cval->control << 8,
@@ -1440,7 +1509,8 @@ static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1440static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol, 1509static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1441 struct snd_ctl_elem_value *ucontrol) 1510 struct snd_ctl_elem_value *ucontrol)
1442{ 1511{
1443 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 1512 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1513 struct snd_usb_audio *chip = list->mixer->chip;
1444 int err; 1514 int err;
1445 struct usb_interface *iface; 1515 struct usb_interface *iface;
1446 struct usb_host_interface *alts; 1516 struct usb_host_interface *alts;
@@ -1448,17 +1518,23 @@ static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1448 unsigned char data[3]; 1518 unsigned char data[3];
1449 int rate; 1519 int rate;
1450 1520
1521 down_read(&chip->shutdown_rwsem);
1522 if (chip->shutdown) {
1523 err = -ENODEV;
1524 goto end;
1525 }
1526
1451 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff; 1527 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1452 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff; 1528 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1453 ucontrol->value.iec958.status[2] = 0x00; 1529 ucontrol->value.iec958.status[2] = 0x00;
1454 1530
1455 /* use known values for that card: interface#1 altsetting#1 */ 1531 /* use known values for that card: interface#1 altsetting#1 */
1456 iface = usb_ifnum_to_if(mixer->chip->dev, 1); 1532 iface = usb_ifnum_to_if(chip->dev, 1);
1457 alts = &iface->altsetting[1]; 1533 alts = &iface->altsetting[1];
1458 ep = get_endpoint(alts, 0)->bEndpointAddress; 1534 ep = get_endpoint(alts, 0)->bEndpointAddress;
1459 1535
1460 err = snd_usb_ctl_msg(mixer->chip->dev, 1536 err = snd_usb_ctl_msg(chip->dev,
1461 usb_rcvctrlpipe(mixer->chip->dev, 0), 1537 usb_rcvctrlpipe(chip->dev, 0),
1462 UAC_GET_CUR, 1538 UAC_GET_CUR,
1463 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, 1539 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1464 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, 1540 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
@@ -1473,22 +1549,27 @@ static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1473 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100; 1549 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1474 1550
1475 err = 0; 1551 err = 0;
1476end: 1552 end:
1553 up_read(&chip->shutdown_rwsem);
1477 return err; 1554 return err;
1478} 1555}
1479 1556
1480static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol, 1557static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1481 struct snd_ctl_elem_value *ucontrol)
1482{ 1558{
1483 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 1559 struct snd_usb_audio *chip = list->mixer->chip;
1484 int err; 1560 unsigned int pval = list->kctl->private_value;
1485 u8 reg; 1561 u8 reg;
1486 unsigned long priv_backup = kcontrol->private_value; 1562 int err;
1487 1563
1488 reg = ((ucontrol->value.iec958.status[1] & 0x0f) << 4) | 1564 down_read(&chip->shutdown_rwsem);
1489 (ucontrol->value.iec958.status[0] & 0x0f); 1565 if (chip->shutdown) {
1490 err = snd_usb_ctl_msg(mixer->chip->dev, 1566 err = -ENODEV;
1491 usb_sndctrlpipe(mixer->chip->dev, 0), 1567 goto end;
1568 }
1569
1570 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1571 err = snd_usb_ctl_msg(chip->dev,
1572 usb_sndctrlpipe(chip->dev, 0),
1492 UAC_SET_CUR, 1573 UAC_SET_CUR,
1493 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 1574 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1494 reg, 1575 reg,
@@ -1498,15 +1579,10 @@ static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1498 if (err < 0) 1579 if (err < 0)
1499 goto end; 1580 goto end;
1500 1581
1501 kcontrol->private_value &= 0xfffff0f0; 1582 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1502 kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0x0f) << 8; 1583 reg |= (pval >> 12) & 0x0f;
1503 kcontrol->private_value |= (ucontrol->value.iec958.status[0] & 0x0f); 1584 err = snd_usb_ctl_msg(chip->dev,
1504 1585 usb_sndctrlpipe(chip->dev, 0),
1505 reg = (ucontrol->value.iec958.status[0] & IEC958_AES0_NONAUDIO) ?
1506 0xa0 : 0x20;
1507 reg |= (ucontrol->value.iec958.status[1] >> 4) & 0x0f;
1508 err = snd_usb_ctl_msg(mixer->chip->dev,
1509 usb_sndctrlpipe(mixer->chip->dev, 0),
1510 UAC_SET_CUR, 1586 UAC_SET_CUR,
1511 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 1587 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1512 reg, 1588 reg,
@@ -1516,16 +1592,36 @@ static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1516 if (err < 0) 1592 if (err < 0)
1517 goto end; 1593 goto end;
1518 1594
1519 kcontrol->private_value &= 0xffff0fff; 1595 end:
1520 kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0xf0) << 8; 1596 up_read(&chip->shutdown_rwsem);
1597 return err;
1598}
1599
1600static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1601 struct snd_ctl_elem_value *ucontrol)
1602{
1603 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1604 unsigned int pval, pval_old;
1605 int err;
1606
1607 pval = pval_old = kcontrol->private_value;
1608 pval &= 0xfffff0f0;
1609 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1610 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1611
1612 pval &= 0xffff0fff;
1613 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1521 1614
1522 /* The frequency bits in AES3 cannot be set via register access. */ 1615 /* The frequency bits in AES3 cannot be set via register access. */
1523 1616
1524 /* Silently ignore any bits from the request that cannot be set. */ 1617 /* Silently ignore any bits from the request that cannot be set. */
1525 1618
1526 err = (priv_backup != kcontrol->private_value); 1619 if (pval == pval_old)
1527end: 1620 return 0;
1528 return err; 1621
1622 kcontrol->private_value = pval;
1623 err = snd_microii_spdif_default_update(list);
1624 return err < 0 ? err : 1;
1529} 1625}
1530 1626
1531static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol, 1627static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
@@ -1547,15 +1643,20 @@ static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1547 return 0; 1643 return 0;
1548} 1644}
1549 1645
1550static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol, 1646static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1551 struct snd_ctl_elem_value *ucontrol)
1552{ 1647{
1553 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 1648 struct snd_usb_audio *chip = list->mixer->chip;
1649 u8 reg = list->kctl->private_value;
1554 int err; 1650 int err;
1555 u8 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1556 1651
1557 err = snd_usb_ctl_msg(mixer->chip->dev, 1652 down_read(&chip->shutdown_rwsem);
1558 usb_sndctrlpipe(mixer->chip->dev, 0), 1653 if (chip->shutdown) {
1654 err = -ENODEV;
1655 goto end;
1656 }
1657
1658 err = snd_usb_ctl_msg(chip->dev,
1659 usb_sndctrlpipe(chip->dev, 0),
1559 UAC_SET_CUR, 1660 UAC_SET_CUR,
1560 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 1661 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1561 reg, 1662 reg,
@@ -1563,15 +1664,27 @@ static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1563 NULL, 1664 NULL,
1564 0); 1665 0);
1565 1666
1566 if (!err) { 1667 end:
1567 err = (reg != (kcontrol->private_value & 0x0ff)); 1668 up_read(&chip->shutdown_rwsem);
1568 if (err)
1569 kcontrol->private_value = reg;
1570 }
1571
1572 return err; 1669 return err;
1573} 1670}
1574 1671
1672static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1673 struct snd_ctl_elem_value *ucontrol)
1674{
1675 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1676 u8 reg;
1677 int err;
1678
1679 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1680 if (reg != list->kctl->private_value)
1681 return 0;
1682
1683 kcontrol->private_value = reg;
1684 err = snd_microii_spdif_switch_update(list);
1685 return err < 0 ? err : 1;
1686}
1687
1575static struct snd_kcontrol_new snd_microii_mixer_spdif[] = { 1688static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1576 { 1689 {
1577 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1690 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
@@ -1601,10 +1714,17 @@ static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1601static int snd_microii_controls_create(struct usb_mixer_interface *mixer) 1714static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1602{ 1715{
1603 int err, i; 1716 int err, i;
1717 static usb_mixer_elem_resume_func_t resume_funcs[] = {
1718 snd_microii_spdif_default_update,
1719 NULL,
1720 snd_microii_spdif_switch_update
1721 };
1604 1722
1605 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) { 1723 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1606 err = snd_ctl_add(mixer->chip->card, 1724 err = add_single_ctl_with_resume(mixer, 0,
1607 snd_ctl_new1(&snd_microii_mixer_spdif[i], mixer)); 1725 resume_funcs[i],
1726 &snd_microii_mixer_spdif[i],
1727 NULL);
1608 if (err < 0) 1728 if (err < 0)
1609 return err; 1729 return err;
1610 } 1730 }
@@ -1661,6 +1781,10 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1661 err = snd_microii_controls_create(mixer); 1781 err = snd_microii_controls_create(mixer);
1662 break; 1782 break;
1663 1783
1784 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1785 err = snd_mbox1_create_sync_switch(mixer);
1786 break;
1787
1664 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */ 1788 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1665 err = snd_nativeinstruments_create_mixer(mixer, 1789 err = snd_nativeinstruments_create_mixer(mixer,
1666 snd_nativeinstruments_ta6_mixers, 1790 snd_nativeinstruments_ta6_mixers,
@@ -1677,6 +1801,14 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1677 /* detection is disabled in mixer_maps.c */ 1801 /* detection is disabled in mixer_maps.c */
1678 err = snd_create_std_mono_table(mixer, ebox44_table); 1802 err = snd_create_std_mono_table(mixer, ebox44_table);
1679 break; 1803 break;
1804
1805 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
1806 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
1807 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
1808 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
1809 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
1810 err = snd_scarlett_controls_create(mixer);
1811 break;
1680 } 1812 }
1681 1813
1682 return err; 1814 return err;
diff --git a/sound/usb/mixer_scarlett.c b/sound/usb/mixer_scarlett.c
new file mode 100644
index 000000000000..9109652b88b9
--- /dev/null
+++ b/sound/usb/mixer_scarlett.c
@@ -0,0 +1,1004 @@
1/*
2 * Scarlett Driver for ALSA
3 *
4 * Copyright (c) 2013 by Tobias Hoffmann
5 * Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
6 * Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
7 * Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
8 *
9 * Many codes borrowed from audio.c by
10 * Alan Cox (alan at lxorguk.ukuu.org.uk)
11 * Thomas Sailer (sailer at ife.ee.ethz.ch)
12 *
13 * Code cleanup:
14 * David Henningsson <david.henningsson at canonical.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 */
27
28/*
29 * Rewritten and extended to support more models, e.g. Scarlett 18i8.
30 *
31 * Auto-detection via UAC2 is not feasible to properly discover the vast
32 * majority of features. It's related to both Linux/ALSA's UAC2 as well as
33 * Focusrite's implementation of it. Eventually quirks may be sufficient but
34 * right now it's a major headache to work arount these things.
35 *
36 * NB. Neither the OSX nor the win driver provided by Focusrite performs
37 * discovery, they seem to operate the same as this driver.
38 */
39
40/* Mixer Interface for the Focusrite Scarlett 18i6 audio interface.
41 *
42 * The protocol was reverse engineered by looking at communication between
43 * Scarlett MixControl (v 1.2.128.0) and the Focusrite(R) Scarlett 18i6
44 * (firmware v305) using wireshark and usbmon in January 2013.
45 * Extended in July 2013.
46 *
47 * this mixer gives complete access to all features of the device:
48 * - change Impedance of inputs (Line-in, Mic / Instrument, Hi-Z)
49 * - select clock source
50 * - dynamic input to mixer-matrix assignment
51 * - 18 x 6 mixer-matrix gain stages
52 * - bus routing & volume control
53 * - automatic re-initialization on connect if device was power-cycled
54 *
55 * USB URB commands overview (bRequest = 0x01 = UAC2_CS_CUR)
56 * wIndex
57 * 0x01 Analog Input line/instrument impedance switch, wValue=0x0901 +
58 * channel, data=Line/Inst (2bytes)
59 * pad (-10dB) switch, wValue=0x0b01 + channel, data=Off/On (2bytes)
60 * ?? wValue=0x0803/04, ?? (2bytes)
61 * 0x0a Master Volume, wValue=0x0200+bus[0:all + only 1..4?] data(2bytes)
62 * Bus Mute/Unmute wValue=0x0100+bus[0:all + only 1..4?], data(2bytes)
63 * 0x28 Clock source, wValue=0x0100, data={1:int,2:spdif,3:adat} (1byte)
64 * 0x29 Set Sample-rate, wValue=0x0100, data=sample-rate(4bytes)
65 * 0x32 Mixer mux, wValue=0x0600 + mixer-channel, data=input-to-connect(2bytes)
66 * 0x33 Output mux, wValue=bus, data=input-to-connect(2bytes)
67 * 0x34 Capture mux, wValue=0...18, data=input-to-connect(2bytes)
68 * 0x3c Matrix Mixer gains, wValue=mixer-node data=gain(2bytes)
69 * ?? [sometimes](4bytes, e.g 0x000003be 0x000003bf ...03ff)
70 *
71 * USB reads: (i.e. actually issued by original software)
72 * 0x01 wValue=0x0901+channel (1byte!!), wValue=0x0b01+channed (1byte!!)
73 * 0x29 wValue=0x0100 sample-rate(4bytes)
74 * wValue=0x0200 ?? 1byte (only once)
75 * 0x2a wValue=0x0100 ?? 4bytes, sample-rate2 ??
76 *
77 * USB reads with bRequest = 0x03 = UAC2_CS_MEM
78 * 0x3c wValue=0x0002 1byte: sync status (locked=1)
79 * wValue=0x0000 18*2byte: peak meter (inputs)
80 * wValue=0x0001 8(?)*2byte: peak meter (mix)
81 * wValue=0x0003 6*2byte: peak meter (pcm/daw)
82 *
83 * USB write with bRequest = 0x03
84 * 0x3c Save settings to hardware: wValue=0x005a, data=0xa5
85 *
86 *
87 * <ditaa>
88 * /--------------\ 18chn 6chn /--------------\
89 * | Hardware in +--+-------\ /------+--+ ALSA PCM out |
90 * \--------------/ | | | | \--------------/
91 * | | | |
92 * | v v |
93 * | +---------------+ |
94 * | \ Matrix Mux / |
95 * | +-----+-----+ |
96 * | | |
97 * | | 18chn |
98 * | v |
99 * | +-----------+ |
100 * | | Mixer | |
101 * | | Matrix | |
102 * | | | |
103 * | | 18x6 Gain | |
104 * | | stages | |
105 * | +-----+-----+ |
106 * | | |
107 * | | |
108 * | 18chn | 6chn | 6chn
109 * v v v
110 * =========================
111 * +---------------+ +--—------------+
112 * \ Output Mux / \ Capture Mux /
113 * +-----+-----+ +-----+-----+
114 * | |
115 * | 6chn |
116 * v |
117 * +-------------+ |
118 * | Master Gain | |
119 * +------+------+ |
120 * | |
121 * | 6chn | 18chn
122 * | (3 stereo pairs) |
123 * /--------------\ | | /--------------\
124 * | Hardware out |<--/ \-->| ALSA PCM in |
125 * \--------------/ \--------------/
126 * </ditaa>
127 *
128 */
129
130#include <linux/slab.h>
131#include <linux/usb.h>
132#include <linux/usb/audio-v2.h>
133
134#include <sound/core.h>
135#include <sound/control.h>
136#include <sound/tlv.h>
137
138#include "usbaudio.h"
139#include "mixer.h"
140#include "helper.h"
141#include "power.h"
142
143#include "mixer_scarlett.h"
144
145/* some gui mixers can't handle negative ctl values */
146#define SND_SCARLETT_LEVEL_BIAS 128
147#define SND_SCARLETT_MATRIX_IN_MAX 18
148#define SND_SCARLETT_CONTROLS_MAX 10
149#define SND_SCARLETT_OFFSETS_MAX 5
150
151enum {
152 SCARLETT_OUTPUTS,
153 SCARLETT_SWITCH_IMPEDANCE,
154 SCARLETT_SWITCH_PAD,
155};
156
157enum {
158 SCARLETT_OFFSET_PCM = 0,
159 SCARLETT_OFFSET_ANALOG = 1,
160 SCARLETT_OFFSET_SPDIF = 2,
161 SCARLETT_OFFSET_ADAT = 3,
162 SCARLETT_OFFSET_MIX = 4,
163};
164
165struct scarlett_mixer_elem_enum_info {
166 int start;
167 int len;
168 int offsets[SND_SCARLETT_OFFSETS_MAX];
169 char const * const *names;
170};
171
172struct scarlett_mixer_control {
173 unsigned char num;
174 unsigned char type;
175 const char *name;
176};
177
178struct scarlett_device_info {
179 int matrix_in;
180 int matrix_out;
181 int input_len;
182 int output_len;
183
184 struct scarlett_mixer_elem_enum_info opt_master;
185 struct scarlett_mixer_elem_enum_info opt_matrix;
186
187 /* initial values for matrix mux */
188 int matrix_mux_init[SND_SCARLETT_MATRIX_IN_MAX];
189
190 int num_controls; /* number of items in controls */
191 const struct scarlett_mixer_control controls[SND_SCARLETT_CONTROLS_MAX];
192};
193
194/********************** Enum Strings *************************/
195
196static const struct scarlett_mixer_elem_enum_info opt_pad = {
197 .start = 0,
198 .len = 2,
199 .offsets = {},
200 .names = (char const * const []){
201 "0dB", "-10dB"
202 }
203};
204
205static const struct scarlett_mixer_elem_enum_info opt_impedance = {
206 .start = 0,
207 .len = 2,
208 .offsets = {},
209 .names = (char const * const []){
210 "Line", "Hi-Z"
211 }
212};
213
214static const struct scarlett_mixer_elem_enum_info opt_clock = {
215 .start = 1,
216 .len = 3,
217 .offsets = {},
218 .names = (char const * const []){
219 "Internal", "SPDIF", "ADAT"
220 }
221};
222
223static const struct scarlett_mixer_elem_enum_info opt_sync = {
224 .start = 0,
225 .len = 2,
226 .offsets = {},
227 .names = (char const * const []){
228 "No Lock", "Locked"
229 }
230};
231
232static int scarlett_ctl_switch_info(struct snd_kcontrol *kctl,
233 struct snd_ctl_elem_info *uinfo)
234{
235 struct usb_mixer_elem_info *elem = kctl->private_data;
236
237 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
238 uinfo->count = elem->channels;
239 uinfo->value.integer.min = 0;
240 uinfo->value.integer.max = 1;
241 return 0;
242}
243
244static int scarlett_ctl_switch_get(struct snd_kcontrol *kctl,
245 struct snd_ctl_elem_value *ucontrol)
246{
247 struct usb_mixer_elem_info *elem = kctl->private_data;
248 int i, err, val;
249
250 for (i = 0; i < elem->channels; i++) {
251 err = snd_usb_get_cur_mix_value(elem, i, i, &val);
252 if (err < 0)
253 return err;
254
255 val = !val; /* invert mute logic for mixer */
256 ucontrol->value.integer.value[i] = val;
257 }
258
259 return 0;
260}
261
262static int scarlett_ctl_switch_put(struct snd_kcontrol *kctl,
263 struct snd_ctl_elem_value *ucontrol)
264{
265 struct usb_mixer_elem_info *elem = kctl->private_data;
266 int i, changed = 0;
267 int err, oval, val;
268
269 for (i = 0; i < elem->channels; i++) {
270 err = snd_usb_get_cur_mix_value(elem, i, i, &oval);
271 if (err < 0)
272 return err;
273
274 val = ucontrol->value.integer.value[i];
275 val = !val;
276 if (oval != val) {
277 err = snd_usb_set_cur_mix_value(elem, i, i, val);
278 if (err < 0)
279 return err;
280
281 changed = 1;
282 }
283 }
284
285 return changed;
286}
287
288static int scarlett_ctl_resume(struct usb_mixer_elem_list *list)
289{
290 struct usb_mixer_elem_info *elem =
291 container_of(list, struct usb_mixer_elem_info, head);
292 int i;
293
294 for (i = 0; i < elem->channels; i++)
295 if (elem->cached & (1 << i))
296 snd_usb_set_cur_mix_value(elem, i, i,
297 elem->cache_val[i]);
298 return 0;
299}
300
301static int scarlett_ctl_info(struct snd_kcontrol *kctl,
302 struct snd_ctl_elem_info *uinfo)
303{
304 struct usb_mixer_elem_info *elem = kctl->private_data;
305
306 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
307 uinfo->count = elem->channels;
308 uinfo->value.integer.min = 0;
309 uinfo->value.integer.max = (int)kctl->private_value +
310 SND_SCARLETT_LEVEL_BIAS;
311 uinfo->value.integer.step = 1;
312 return 0;
313}
314
315static int scarlett_ctl_get(struct snd_kcontrol *kctl,
316 struct snd_ctl_elem_value *ucontrol)
317{
318 struct usb_mixer_elem_info *elem = kctl->private_data;
319 int i, err, val;
320
321 for (i = 0; i < elem->channels; i++) {
322 err = snd_usb_get_cur_mix_value(elem, i, i, &val);
323 if (err < 0)
324 return err;
325
326 val = clamp(val / 256, -128, (int)kctl->private_value) +
327 SND_SCARLETT_LEVEL_BIAS;
328 ucontrol->value.integer.value[i] = val;
329 }
330
331 return 0;
332}
333
334static int scarlett_ctl_put(struct snd_kcontrol *kctl,
335 struct snd_ctl_elem_value *ucontrol)
336{
337 struct usb_mixer_elem_info *elem = kctl->private_data;
338 int i, changed = 0;
339 int err, oval, val;
340
341 for (i = 0; i < elem->channels; i++) {
342 err = snd_usb_get_cur_mix_value(elem, i, i, &oval);
343 if (err < 0)
344 return err;
345
346 val = ucontrol->value.integer.value[i] -
347 SND_SCARLETT_LEVEL_BIAS;
348 val = val * 256;
349 if (oval != val) {
350 err = snd_usb_set_cur_mix_value(elem, i, i, val);
351 if (err < 0)
352 return err;
353
354 changed = 1;
355 }
356 }
357
358 return changed;
359}
360
361static void scarlett_generate_name(int i, char *dst, int offsets[])
362{
363 if (i > offsets[SCARLETT_OFFSET_MIX])
364 sprintf(dst, "Mix %c",
365 'A'+(i - offsets[SCARLETT_OFFSET_MIX] - 1));
366 else if (i > offsets[SCARLETT_OFFSET_ADAT])
367 sprintf(dst, "ADAT %d", i - offsets[SCARLETT_OFFSET_ADAT]);
368 else if (i > offsets[SCARLETT_OFFSET_SPDIF])
369 sprintf(dst, "SPDIF %d", i - offsets[SCARLETT_OFFSET_SPDIF]);
370 else if (i > offsets[SCARLETT_OFFSET_ANALOG])
371 sprintf(dst, "Analog %d", i - offsets[SCARLETT_OFFSET_ANALOG]);
372 else if (i > offsets[SCARLETT_OFFSET_PCM])
373 sprintf(dst, "PCM %d", i - offsets[SCARLETT_OFFSET_PCM]);
374 else
375 sprintf(dst, "Off");
376}
377
378static int scarlett_ctl_enum_dynamic_info(struct snd_kcontrol *kctl,
379 struct snd_ctl_elem_info *uinfo)
380{
381 struct usb_mixer_elem_info *elem = kctl->private_data;
382 struct scarlett_mixer_elem_enum_info *opt = elem->private_data;
383 unsigned int items = opt->len;
384
385 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
386 uinfo->count = elem->channels;
387 uinfo->value.enumerated.items = items;
388
389 if (uinfo->value.enumerated.item >= items)
390 uinfo->value.enumerated.item = items - 1;
391
392 /* generate name dynamically based on item number and offset info */
393 scarlett_generate_name(uinfo->value.enumerated.item,
394 uinfo->value.enumerated.name,
395 opt->offsets);
396
397 return 0;
398}
399
400static int scarlett_ctl_enum_info(struct snd_kcontrol *kctl,
401 struct snd_ctl_elem_info *uinfo)
402{
403 struct usb_mixer_elem_info *elem = kctl->private_data;
404 struct scarlett_mixer_elem_enum_info *opt = elem->private_data;
405
406 return snd_ctl_enum_info(uinfo, elem->channels, opt->len,
407 (const char * const *)opt->names);
408}
409
410static int scarlett_ctl_enum_get(struct snd_kcontrol *kctl,
411 struct snd_ctl_elem_value *ucontrol)
412{
413 struct usb_mixer_elem_info *elem = kctl->private_data;
414 struct scarlett_mixer_elem_enum_info *opt = elem->private_data;
415 int err, val;
416
417 err = snd_usb_get_cur_mix_value(elem, 0, 0, &val);
418 if (err < 0)
419 return err;
420
421 val = clamp(val - opt->start, 0, opt->len-1);
422
423 ucontrol->value.enumerated.item[0] = val;
424
425 return 0;
426}
427
428static int scarlett_ctl_enum_put(struct snd_kcontrol *kctl,
429 struct snd_ctl_elem_value *ucontrol)
430{
431 struct usb_mixer_elem_info *elem = kctl->private_data;
432 struct scarlett_mixer_elem_enum_info *opt = elem->private_data;
433 int err, oval, val;
434
435 err = snd_usb_get_cur_mix_value(elem, 0, 0, &oval);
436 if (err < 0)
437 return err;
438
439 val = ucontrol->value.integer.value[0];
440 val = val + opt->start;
441 if (val != oval) {
442 snd_usb_set_cur_mix_value(elem, 0, 0, val);
443 return 1;
444 }
445 return 0;
446}
447
448static int scarlett_ctl_enum_resume(struct usb_mixer_elem_list *list)
449{
450 struct usb_mixer_elem_info *elem =
451 container_of(list, struct usb_mixer_elem_info, head);
452
453 if (elem->cached)
454 snd_usb_set_cur_mix_value(elem, 0, 0, *elem->cache_val);
455 return 0;
456}
457
458static int scarlett_ctl_meter_get(struct snd_kcontrol *kctl,
459 struct snd_ctl_elem_value *ucontrol)
460{
461 struct usb_mixer_elem_info *elem = kctl->private_data;
462 struct snd_usb_audio *chip = elem->head.mixer->chip;
463 unsigned char buf[2 * MAX_CHANNELS] = {0, };
464 int wValue = (elem->control << 8) | elem->idx_off;
465 int idx = snd_usb_ctrl_intf(chip) | (elem->head.id << 8);
466 int err;
467
468 err = snd_usb_ctl_msg(chip->dev,
469 usb_rcvctrlpipe(chip->dev, 0),
470 UAC2_CS_MEM,
471 USB_RECIP_INTERFACE | USB_TYPE_CLASS |
472 USB_DIR_IN, wValue, idx, buf, elem->channels);
473 if (err < 0)
474 return err;
475
476 ucontrol->value.enumerated.item[0] = clamp((int)buf[0], 0, 1);
477 return 0;
478}
479
480static struct snd_kcontrol_new usb_scarlett_ctl_switch = {
481 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
482 .name = "",
483 .info = scarlett_ctl_switch_info,
484 .get = scarlett_ctl_switch_get,
485 .put = scarlett_ctl_switch_put,
486};
487
488static const DECLARE_TLV_DB_SCALE(db_scale_scarlett_gain, -12800, 100, 0);
489
490static struct snd_kcontrol_new usb_scarlett_ctl = {
491 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
492 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
493 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
494 .name = "",
495 .info = scarlett_ctl_info,
496 .get = scarlett_ctl_get,
497 .put = scarlett_ctl_put,
498 .private_value = 6, /* max value */
499 .tlv = { .p = db_scale_scarlett_gain }
500};
501
502static struct snd_kcontrol_new usb_scarlett_ctl_master = {
503 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
504 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
505 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
506 .name = "",
507 .info = scarlett_ctl_info,
508 .get = scarlett_ctl_get,
509 .put = scarlett_ctl_put,
510 .private_value = 6, /* max value */
511 .tlv = { .p = db_scale_scarlett_gain }
512};
513
514static struct snd_kcontrol_new usb_scarlett_ctl_enum = {
515 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
516 .name = "",
517 .info = scarlett_ctl_enum_info,
518 .get = scarlett_ctl_enum_get,
519 .put = scarlett_ctl_enum_put,
520};
521
522static struct snd_kcontrol_new usb_scarlett_ctl_dynamic_enum = {
523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
524 .name = "",
525 .info = scarlett_ctl_enum_dynamic_info,
526 .get = scarlett_ctl_enum_get,
527 .put = scarlett_ctl_enum_put,
528};
529
530static struct snd_kcontrol_new usb_scarlett_ctl_sync = {
531 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
532 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
533 .name = "",
534 .info = scarlett_ctl_enum_info,
535 .get = scarlett_ctl_meter_get,
536};
537
538static int add_new_ctl(struct usb_mixer_interface *mixer,
539 const struct snd_kcontrol_new *ncontrol,
540 usb_mixer_elem_resume_func_t resume,
541 int index, int offset, int num,
542 int val_type, int channels, const char *name,
543 const struct scarlett_mixer_elem_enum_info *opt,
544 struct usb_mixer_elem_info **elem_ret
545)
546{
547 struct snd_kcontrol *kctl;
548 struct usb_mixer_elem_info *elem;
549 int err;
550
551 elem = kzalloc(sizeof(*elem), GFP_KERNEL);
552 if (!elem)
553 return -ENOMEM;
554
555 elem->head.mixer = mixer;
556 elem->head.resume = resume;
557 elem->control = offset;
558 elem->idx_off = num;
559 elem->head.id = index;
560 elem->val_type = val_type;
561
562 elem->channels = channels;
563
564 /* add scarlett_mixer_elem_enum_info struct */
565 elem->private_data = (void *)opt;
566
567 kctl = snd_ctl_new1(ncontrol, elem);
568 if (!kctl) {
569 kfree(elem);
570 return -ENOMEM;
571 }
572 kctl->private_free = snd_usb_mixer_elem_free;
573
574 strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
575
576 err = snd_usb_mixer_add_control(&elem->head, kctl);
577 if (err < 0)
578 return err;
579
580 if (elem_ret)
581 *elem_ret = elem;
582
583 return 0;
584}
585
586static int add_output_ctls(struct usb_mixer_interface *mixer,
587 int index, const char *name,
588 const struct scarlett_device_info *info)
589{
590 int err;
591 char mx[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
592 struct usb_mixer_elem_info *elem;
593
594 /* Add mute switch */
595 snprintf(mx, sizeof(mx), "Master %d (%s) Playback Switch",
596 index + 1, name);
597 err = add_new_ctl(mixer, &usb_scarlett_ctl_switch,
598 scarlett_ctl_resume, 0x0a, 0x01,
599 2*index+1, USB_MIXER_S16, 2, mx, NULL, &elem);
600 if (err < 0)
601 return err;
602
603 /* Add volume control and initialize to 0 */
604 snprintf(mx, sizeof(mx), "Master %d (%s) Playback Volume",
605 index + 1, name);
606 err = add_new_ctl(mixer, &usb_scarlett_ctl_master,
607 scarlett_ctl_resume, 0x0a, 0x02,
608 2*index+1, USB_MIXER_S16, 2, mx, NULL, &elem);
609 if (err < 0)
610 return err;
611
612 /* Add L channel source playback enumeration */
613 snprintf(mx, sizeof(mx), "Master %dL (%s) Source Playback Enum",
614 index + 1, name);
615 err = add_new_ctl(mixer, &usb_scarlett_ctl_dynamic_enum,
616 scarlett_ctl_enum_resume, 0x33, 0x00,
617 2*index, USB_MIXER_S16, 1, mx, &info->opt_master,
618 &elem);
619 if (err < 0)
620 return err;
621
622 /* Add R channel source playback enumeration */
623 snprintf(mx, sizeof(mx), "Master %dR (%s) Source Playback Enum",
624 index + 1, name);
625 err = add_new_ctl(mixer, &usb_scarlett_ctl_dynamic_enum,
626 scarlett_ctl_enum_resume, 0x33, 0x00,
627 2*index+1, USB_MIXER_S16, 1, mx, &info->opt_master,
628 &elem);
629 if (err < 0)
630 return err;
631
632 return 0;
633}
634
635/********************** device-specific config *************************/
636
637/* untested... */
638static struct scarlett_device_info s6i6_info = {
639 .matrix_in = 18,
640 .matrix_out = 8,
641 .input_len = 6,
642 .output_len = 6,
643
644 .opt_master = {
645 .start = -1,
646 .len = 27,
647 .offsets = {0, 12, 16, 18, 18},
648 .names = NULL
649 },
650
651 .opt_matrix = {
652 .start = -1,
653 .len = 19,
654 .offsets = {0, 12, 16, 18, 18},
655 .names = NULL
656 },
657
658 .num_controls = 0,
659 .controls = {
660 { .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
661 { .num = 1, .type = SCARLETT_OUTPUTS, .name = "Headphone" },
662 { .num = 2, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
663 { .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
664 { .num = 1, .type = SCARLETT_SWITCH_PAD, .name = NULL},
665 { .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
666 { .num = 2, .type = SCARLETT_SWITCH_PAD, .name = NULL},
667 { .num = 3, .type = SCARLETT_SWITCH_PAD, .name = NULL},
668 { .num = 4, .type = SCARLETT_SWITCH_PAD, .name = NULL},
669 },
670
671 .matrix_mux_init = {
672 12, 13, 14, 15, /* Analog -> 1..4 */
673 16, 17, /* SPDIF -> 5,6 */
674 0, 1, 2, 3, 4, 5, 6, 7, /* PCM[1..12] -> 7..18 */
675 8, 9, 10, 11
676 }
677};
678
679/* untested... */
680static struct scarlett_device_info s8i6_info = {
681 .matrix_in = 18,
682 .matrix_out = 6,
683 .input_len = 8,
684 .output_len = 6,
685
686 .opt_master = {
687 .start = -1,
688 .len = 25,
689 .offsets = {0, 12, 16, 18, 18},
690 .names = NULL
691 },
692
693 .opt_matrix = {
694 .start = -1,
695 .len = 19,
696 .offsets = {0, 12, 16, 18, 18},
697 .names = NULL
698 },
699
700 .num_controls = 7,
701 .controls = {
702 { .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
703 { .num = 1, .type = SCARLETT_OUTPUTS, .name = "Headphone" },
704 { .num = 2, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
705 { .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
706 { .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
707 { .num = 3, .type = SCARLETT_SWITCH_PAD, .name = NULL},
708 { .num = 4, .type = SCARLETT_SWITCH_PAD, .name = NULL},
709 },
710
711 .matrix_mux_init = {
712 12, 13, 14, 15, /* Analog -> 1..4 */
713 16, 17, /* SPDIF -> 5,6 */
714 0, 1, 2, 3, 4, 5, 6, 7, /* PCM[1..12] -> 7..18 */
715 8, 9, 10, 11
716 }
717};
718
719static struct scarlett_device_info s18i6_info = {
720 .matrix_in = 18,
721 .matrix_out = 6,
722 .input_len = 18,
723 .output_len = 6,
724
725 .opt_master = {
726 .start = -1,
727 .len = 31,
728 .offsets = {0, 6, 14, 16, 24},
729 .names = NULL,
730 },
731
732 .opt_matrix = {
733 .start = -1,
734 .len = 25,
735 .offsets = {0, 6, 14, 16, 24},
736 .names = NULL,
737 },
738
739 .num_controls = 5,
740 .controls = {
741 { .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
742 { .num = 1, .type = SCARLETT_OUTPUTS, .name = "Headphone" },
743 { .num = 2, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
744 { .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
745 { .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
746 },
747
748 .matrix_mux_init = {
749 6, 7, 8, 9, 10, 11, 12, 13, /* Analog -> 1..8 */
750 16, 17, 18, 19, 20, 21, /* ADAT[1..6] -> 9..14 */
751 14, 15, /* SPDIF -> 15,16 */
752 0, 1 /* PCM[1,2] -> 17,18 */
753 }
754};
755
756static struct scarlett_device_info s18i8_info = {
757 .matrix_in = 18,
758 .matrix_out = 8,
759 .input_len = 18,
760 .output_len = 8,
761
762 .opt_master = {
763 .start = -1,
764 .len = 35,
765 .offsets = {0, 8, 16, 18, 26},
766 .names = NULL
767 },
768
769 .opt_matrix = {
770 .start = -1,
771 .len = 27,
772 .offsets = {0, 8, 16, 18, 26},
773 .names = NULL
774 },
775
776 .num_controls = 10,
777 .controls = {
778 { .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
779 { .num = 1, .type = SCARLETT_OUTPUTS, .name = "Headphone 1" },
780 { .num = 2, .type = SCARLETT_OUTPUTS, .name = "Headphone 2" },
781 { .num = 3, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
782 { .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
783 { .num = 1, .type = SCARLETT_SWITCH_PAD, .name = NULL},
784 { .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
785 { .num = 2, .type = SCARLETT_SWITCH_PAD, .name = NULL},
786 { .num = 3, .type = SCARLETT_SWITCH_PAD, .name = NULL},
787 { .num = 4, .type = SCARLETT_SWITCH_PAD, .name = NULL},
788 },
789
790 .matrix_mux_init = {
791 8, 9, 10, 11, 12, 13, 14, 15, /* Analog -> 1..8 */
792 18, 19, 20, 21, 22, 23, /* ADAT[1..6] -> 9..14 */
793 16, 17, /* SPDIF -> 15,16 */
794 0, 1 /* PCM[1,2] -> 17,18 */
795 }
796};
797
798static struct scarlett_device_info s18i20_info = {
799 .matrix_in = 18,
800 .matrix_out = 8,
801 .input_len = 18,
802 .output_len = 20,
803
804 .opt_master = {
805 .start = -1,
806 .len = 47,
807 .offsets = {0, 20, 28, 30, 38},
808 .names = NULL
809 },
810
811 .opt_matrix = {
812 .start = -1,
813 .len = 39,
814 .offsets = {0, 20, 28, 30, 38},
815 .names = NULL
816 },
817
818 .num_controls = 10,
819 .controls = {
820 { .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
821 { .num = 1, .type = SCARLETT_OUTPUTS, .name = "Line 3/4" },
822 { .num = 2, .type = SCARLETT_OUTPUTS, .name = "Line 5/6" },
823 { .num = 3, .type = SCARLETT_OUTPUTS, .name = "Line 7/8" },
824 { .num = 4, .type = SCARLETT_OUTPUTS, .name = "Line 9/10" },
825 { .num = 5, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
826 { .num = 6, .type = SCARLETT_OUTPUTS, .name = "ADAT 1/2" },
827 { .num = 7, .type = SCARLETT_OUTPUTS, .name = "ADAT 3/4" },
828 { .num = 8, .type = SCARLETT_OUTPUTS, .name = "ADAT 5/6" },
829 { .num = 9, .type = SCARLETT_OUTPUTS, .name = "ADAT 7/8" },
830 /*{ .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
831 { .num = 1, .type = SCARLETT_SWITCH_PAD, .name = NULL},
832 { .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
833 { .num = 2, .type = SCARLETT_SWITCH_PAD, .name = NULL},
834 { .num = 3, .type = SCARLETT_SWITCH_PAD, .name = NULL},
835 { .num = 4, .type = SCARLETT_SWITCH_PAD, .name = NULL},*/
836 },
837
838 .matrix_mux_init = {
839 20, 21, 22, 23, 24, 25, 26, 27, /* Analog -> 1..8 */
840 30, 31, 32, 33, 34, 35, /* ADAT[1..6] -> 9..14 */
841 28, 29, /* SPDIF -> 15,16 */
842 0, 1 /* PCM[1,2] -> 17,18 */
843 }
844};
845
846
847static int scarlett_controls_create_generic(struct usb_mixer_interface *mixer,
848 struct scarlett_device_info *info)
849{
850 int i, err;
851 char mx[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
852 const struct scarlett_mixer_control *ctl;
853 struct usb_mixer_elem_info *elem;
854
855 /* create master switch and playback volume */
856 err = add_new_ctl(mixer, &usb_scarlett_ctl_switch,
857 scarlett_ctl_resume, 0x0a, 0x01, 0,
858 USB_MIXER_S16, 1, "Master Playback Switch", NULL,
859 &elem);
860 if (err < 0)
861 return err;
862
863 err = add_new_ctl(mixer, &usb_scarlett_ctl_master,
864 scarlett_ctl_resume, 0x0a, 0x02, 0,
865 USB_MIXER_S16, 1, "Master Playback Volume", NULL,
866 &elem);
867 if (err < 0)
868 return err;
869
870 /* iterate through controls in info struct and create each one */
871 for (i = 0; i < info->num_controls; i++) {
872 ctl = &info->controls[i];
873
874 switch (ctl->type) {
875 case SCARLETT_OUTPUTS:
876 err = add_output_ctls(mixer, ctl->num, ctl->name, info);
877 if (err < 0)
878 return err;
879 break;
880 case SCARLETT_SWITCH_IMPEDANCE:
881 sprintf(mx, "Input %d Impedance Switch", ctl->num);
882 err = add_new_ctl(mixer, &usb_scarlett_ctl_enum,
883 scarlett_ctl_enum_resume, 0x01,
884 0x09, ctl->num, USB_MIXER_S16, 1, mx,
885 &opt_impedance, &elem);
886 if (err < 0)
887 return err;
888 break;
889 case SCARLETT_SWITCH_PAD:
890 sprintf(mx, "Input %d Pad Switch", ctl->num);
891 err = add_new_ctl(mixer, &usb_scarlett_ctl_enum,
892 scarlett_ctl_enum_resume, 0x01,
893 0x0b, ctl->num, USB_MIXER_S16, 1, mx,
894 &opt_pad, &elem);
895 if (err < 0)
896 return err;
897 break;
898 }
899 }
900
901 return 0;
902}
903
904/*
905 * Create and initialize a mixer for the Focusrite(R) Scarlett
906 */
907int snd_scarlett_controls_create(struct usb_mixer_interface *mixer)
908{
909 int err, i, o;
910 char mx[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
911 struct scarlett_device_info *info;
912 struct usb_mixer_elem_info *elem;
913 static char sample_rate_buffer[4] = { '\x80', '\xbb', '\x00', '\x00' };
914
915 /* only use UAC_VERSION_2 */
916 if (!mixer->protocol)
917 return 0;
918
919 switch (mixer->chip->usb_id) {
920 case USB_ID(0x1235, 0x8012):
921 info = &s6i6_info;
922 break;
923 case USB_ID(0x1235, 0x8002):
924 info = &s8i6_info;
925 break;
926 case USB_ID(0x1235, 0x8004):
927 info = &s18i6_info;
928 break;
929 case USB_ID(0x1235, 0x8014):
930 info = &s18i8_info;
931 break;
932 case USB_ID(0x1235, 0x800c):
933 info = &s18i20_info;
934 break;
935 default: /* device not (yet) supported */
936 return -EINVAL;
937 }
938
939 /* generic function to create controls */
940 err = scarlett_controls_create_generic(mixer, info);
941 if (err < 0)
942 return err;
943
944 /* setup matrix controls */
945 for (i = 0; i < info->matrix_in; i++) {
946 snprintf(mx, sizeof(mx), "Matrix %02d Input Playback Route",
947 i+1);
948 err = add_new_ctl(mixer, &usb_scarlett_ctl_dynamic_enum,
949 scarlett_ctl_enum_resume, 0x32,
950 0x06, i, USB_MIXER_S16, 1, mx,
951 &info->opt_matrix, &elem);
952 if (err < 0)
953 return err;
954
955 for (o = 0; o < info->matrix_out; o++) {
956 sprintf(mx, "Matrix %02d Mix %c Playback Volume", i+1,
957 o+'A');
958 err = add_new_ctl(mixer, &usb_scarlett_ctl,
959 scarlett_ctl_resume, 0x3c, 0x00,
960 (i << 3) + (o & 0x07), USB_MIXER_S16,
961 1, mx, NULL, &elem);
962 if (err < 0)
963 return err;
964
965 }
966 }
967
968 for (i = 0; i < info->input_len; i++) {
969 snprintf(mx, sizeof(mx), "Input Source %02d Capture Route",
970 i+1);
971 err = add_new_ctl(mixer, &usb_scarlett_ctl_dynamic_enum,
972 scarlett_ctl_enum_resume, 0x34,
973 0x00, i, USB_MIXER_S16, 1, mx,
974 &info->opt_master, &elem);
975 if (err < 0)
976 return err;
977 }
978
979 /* val_len == 1 needed here */
980 err = add_new_ctl(mixer, &usb_scarlett_ctl_enum,
981 scarlett_ctl_enum_resume, 0x28, 0x01, 0,
982 USB_MIXER_U8, 1, "Sample Clock Source",
983 &opt_clock, &elem);
984 if (err < 0)
985 return err;
986
987 /* val_len == 1 and UAC2_CS_MEM */
988 err = add_new_ctl(mixer, &usb_scarlett_ctl_sync, NULL, 0x3c, 0x00, 2,
989 USB_MIXER_U8, 1, "Sample Clock Sync Status",
990 &opt_sync, &elem);
991 if (err < 0)
992 return err;
993
994 /* initialize sampling rate to 48000 */
995 err = snd_usb_ctl_msg(mixer->chip->dev,
996 usb_sndctrlpipe(mixer->chip->dev, 0), UAC2_CS_CUR,
997 USB_RECIP_INTERFACE | USB_TYPE_CLASS |
998 USB_DIR_OUT, 0x0100, snd_usb_ctrl_intf(mixer->chip) |
999 (0x29 << 8), sample_rate_buffer, 4);
1000 if (err < 0)
1001 return err;
1002
1003 return err;
1004}
diff --git a/sound/usb/mixer_scarlett.h b/sound/usb/mixer_scarlett.h
new file mode 100644
index 000000000000..19c592ab0332
--- /dev/null
+++ b/sound/usb/mixer_scarlett.h
@@ -0,0 +1,6 @@
1#ifndef __USB_MIXER_SCARLETT_H
2#define __USB_MIXER_SCARLETT_H
3
4int snd_scarlett_controls_create(struct usb_mixer_interface *mixer);
5
6#endif /* __USB_MIXER_SCARLETT_H */
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index c62a1659106d..0d8aba5fe1a8 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -482,6 +482,11 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
482 /* set interface */ 482 /* set interface */
483 if (subs->interface != fmt->iface || 483 if (subs->interface != fmt->iface ||
484 subs->altset_idx != fmt->altset_idx) { 484 subs->altset_idx != fmt->altset_idx) {
485
486 err = snd_usb_select_mode_quirk(subs, fmt);
487 if (err < 0)
488 return -EIO;
489
485 err = usb_set_interface(dev, fmt->iface, fmt->altsetting); 490 err = usb_set_interface(dev, fmt->iface, fmt->altsetting);
486 if (err < 0) { 491 if (err < 0) {
487 dev_err(&dev->dev, 492 dev_err(&dev->dev,
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index 83bddbdb90e9..0a598af9b38b 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -2667,57 +2667,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2667 .type = QUIRK_MIDI_NOVATION 2667 .type = QUIRK_MIDI_NOVATION
2668 } 2668 }
2669}, 2669},
2670{
2671 /*
2672 * Focusrite Scarlett 18i6
2673 *
2674 * Avoid mixer creation, which otherwise fails because some of
2675 * the interface descriptor subtypes for interface 0 are
2676 * unknown. That should be fixed or worked-around but this at
2677 * least allows the device to be used successfully with a DAW
2678 * and an external mixer. See comments below about other
2679 * ignored interfaces.
2680 */
2681 USB_DEVICE(0x1235, 0x8004),
2682 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2683 .vendor_name = "Focusrite",
2684 .product_name = "Scarlett 18i6",
2685 .ifnum = QUIRK_ANY_INTERFACE,
2686 .type = QUIRK_COMPOSITE,
2687 .data = & (const struct snd_usb_audio_quirk[]) {
2688 {
2689 /* InterfaceSubClass 1 (Control Device) */
2690 .ifnum = 0,
2691 .type = QUIRK_IGNORE_INTERFACE
2692 },
2693 {
2694 .ifnum = 1,
2695 .type = QUIRK_AUDIO_STANDARD_INTERFACE
2696 },
2697 {
2698 .ifnum = 2,
2699 .type = QUIRK_AUDIO_STANDARD_INTERFACE
2700 },
2701 {
2702 /* InterfaceSubClass 1 (Control Device) */
2703 .ifnum = 3,
2704 .type = QUIRK_IGNORE_INTERFACE
2705 },
2706 {
2707 .ifnum = 4,
2708 .type = QUIRK_MIDI_STANDARD_INTERFACE
2709 },
2710 {
2711 /* InterfaceSubClass 1 (Device Firmware Update) */
2712 .ifnum = 5,
2713 .type = QUIRK_IGNORE_INTERFACE
2714 },
2715 {
2716 .ifnum = -1
2717 }
2718 }
2719 }
2720},
2721 2670
2722/* Access Music devices */ 2671/* Access Music devices */
2723{ 2672{
@@ -2856,7 +2805,7 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
2856 .data = (const struct snd_usb_audio_quirk[]){ 2805 .data = (const struct snd_usb_audio_quirk[]){
2857 { 2806 {
2858 .ifnum = 0, 2807 .ifnum = 0,
2859 .type = QUIRK_IGNORE_INTERFACE, 2808 .type = QUIRK_AUDIO_STANDARD_MIXER,
2860 }, 2809 },
2861 { 2810 {
2862 .ifnum = 1, 2811 .ifnum = 1,
@@ -2867,16 +2816,40 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
2867 .iface = 1, 2816 .iface = 1,
2868 .altsetting = 1, 2817 .altsetting = 1,
2869 .altset_idx = 1, 2818 .altset_idx = 1,
2870 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE, 2819 .attributes = 0x4,
2871 .endpoint = 0x02, 2820 .endpoint = 0x02,
2872 .ep_attr = 0x01, 2821 .ep_attr = USB_ENDPOINT_XFER_ISOC |
2873 .rates = SNDRV_PCM_RATE_44100 | 2822 USB_ENDPOINT_SYNC_SYNC,
2874 SNDRV_PCM_RATE_48000, 2823 .maxpacksize = 0x130,
2875 .rate_min = 44100, 2824 .rates = SNDRV_PCM_RATE_48000,
2825 .rate_min = 48000,
2876 .rate_max = 48000, 2826 .rate_max = 48000,
2877 .nr_rates = 2, 2827 .nr_rates = 1,
2878 .rate_table = (unsigned int[]) { 2828 .rate_table = (unsigned int[]) {
2879 44100, 48000 2829 48000
2830 }
2831 }
2832 },
2833 {
2834 .ifnum = 1,
2835 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
2836 .data = &(const struct audioformat) {
2837 .formats = SNDRV_PCM_FMTBIT_S24_3BE,
2838 .channels = 2,
2839 .iface = 1,
2840 .altsetting = 1,
2841 .altset_idx = 1,
2842 .attributes = 0x4,
2843 .endpoint = 0x81,
2844 .ep_attr = USB_ENDPOINT_XFER_ISOC |
2845 USB_ENDPOINT_SYNC_ASYNC,
2846 .maxpacksize = 0x130,
2847 .rates = SNDRV_PCM_RATE_48000,
2848 .rate_min = 48000,
2849 .rate_max = 48000,
2850 .nr_rates = 1,
2851 .rate_table = (unsigned int[]) {
2852 48000
2880 } 2853 }
2881 } 2854 }
2882 }, 2855 },
@@ -2884,7 +2857,6 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
2884 .ifnum = -1 2857 .ifnum = -1
2885 } 2858 }
2886 } 2859 }
2887
2888 } 2860 }
2889}, 2861},
2890 2862
@@ -3115,6 +3087,46 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
3115 3087
3116{ 3088{
3117 /* 3089 /*
3090 * ZOOM R16/24 in audio interface mode.
3091 * Mixer descriptors are garbage, further quirks will be needed
3092 * to make any of it functional, thus disabled for now.
3093 * Playback stream appears to start and run fine but no sound
3094 * is produced, so also disabled for now.
3095 */
3096 USB_DEVICE(0x1686, 0x00dd),
3097 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
3098 .ifnum = QUIRK_ANY_INTERFACE,
3099 .type = QUIRK_COMPOSITE,
3100 .data = (const struct snd_usb_audio_quirk[]) {
3101 {
3102 /* Mixer */
3103 .ifnum = 0,
3104 .type = QUIRK_IGNORE_INTERFACE,
3105 },
3106 {
3107 /* Playback */
3108 .ifnum = 1,
3109 .type = QUIRK_IGNORE_INTERFACE,
3110 },
3111 {
3112 /* Capture */
3113 .ifnum = 2,
3114 .type = QUIRK_AUDIO_STANDARD_INTERFACE,
3115 },
3116 {
3117 /* Midi */
3118 .ifnum = 3,
3119 .type = QUIRK_MIDI_STANDARD_INTERFACE
3120 },
3121 {
3122 .ifnum = -1
3123 },
3124 }
3125 }
3126},
3127
3128{
3129 /*
3118 * Some USB MIDI devices don't have an audio control interface, 3130 * Some USB MIDI devices don't have an audio control interface,
3119 * so we have to grab MIDI streaming interfaces here. 3131 * so we have to grab MIDI streaming interfaces here.
3120 */ 3132 */
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 60dfe0d28771..4dbfb3d18ee2 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -43,12 +43,13 @@
43static int create_composite_quirk(struct snd_usb_audio *chip, 43static int create_composite_quirk(struct snd_usb_audio *chip,
44 struct usb_interface *iface, 44 struct usb_interface *iface,
45 struct usb_driver *driver, 45 struct usb_driver *driver,
46 const struct snd_usb_audio_quirk *quirk) 46 const struct snd_usb_audio_quirk *quirk_comp)
47{ 47{
48 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber; 48 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
49 const struct snd_usb_audio_quirk *quirk;
49 int err; 50 int err;
50 51
51 for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) { 52 for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
52 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum); 53 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
53 if (!iface) 54 if (!iface)
54 continue; 55 continue;
@@ -58,9 +59,17 @@ static int create_composite_quirk(struct snd_usb_audio *chip,
58 err = snd_usb_create_quirk(chip, iface, driver, quirk); 59 err = snd_usb_create_quirk(chip, iface, driver, quirk);
59 if (err < 0) 60 if (err < 0)
60 return err; 61 return err;
61 if (quirk->ifnum != probed_ifnum) 62 }
63
64 for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
65 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
66 if (!iface)
67 continue;
68 if (quirk->ifnum != probed_ifnum &&
69 !usb_interface_claimed(iface))
62 usb_driver_claim_interface(driver, iface, (void *)-1L); 70 usb_driver_claim_interface(driver, iface, (void *)-1L);
63 } 71 }
72
64 return 0; 73 return 0;
65} 74}
66 75
@@ -1102,6 +1111,44 @@ void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
1102 } 1111 }
1103} 1112}
1104 1113
1114
1115/* Marantz/Denon USB DACs need a vendor cmd to switch
1116 * between PCM and native DSD mode
1117 */
1118int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
1119 struct audioformat *fmt)
1120{
1121 struct usb_device *dev = subs->dev;
1122 int err;
1123
1124 switch (subs->stream->chip->usb_id) {
1125 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1126 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1127
1128 /* First switch to alt set 0, otherwise the mode switch cmd
1129 * will not be accepted by the DAC
1130 */
1131 err = usb_set_interface(dev, fmt->iface, 0);
1132 if (err < 0)
1133 return err;
1134
1135 mdelay(20); /* Delay needed after setting the interface */
1136
1137 switch (fmt->altsetting) {
1138 case 2: /* DSD mode requested */
1139 case 1: /* PCM mode requested */
1140 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
1141 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
1142 fmt->altsetting - 1, 1, NULL, 0);
1143 if (err < 0)
1144 return err;
1145 break;
1146 }
1147 mdelay(20);
1148 }
1149 return 0;
1150}
1151
1105void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep) 1152void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
1106{ 1153{
1107 /* 1154 /*
@@ -1160,6 +1207,14 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
1160 break; 1207 break;
1161 } 1208 }
1162 } 1209 }
1210
1211 /* Zoom R16/24 needs a tiny delay here, otherwise requests like
1212 * get/set frequency return as failed despite actually succeeding.
1213 */
1214 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1686) &&
1215 (le16_to_cpu(dev->descriptor.idProduct) == 0x00dd) &&
1216 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1217 mdelay(1);
1163} 1218}
1164 1219
1165/* 1220/*
@@ -1204,5 +1259,16 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1204 break; 1259 break;
1205 } 1260 }
1206 1261
1262 /* Denon/Marantz devices with USB DAC functionality */
1263 switch (chip->usb_id) {
1264 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1265 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1266 if (fp->altsetting == 2)
1267 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1268 break;
1269 default:
1270 break;
1271 }
1272
1207 return 0; 1273 return 0;
1208} 1274}
diff --git a/sound/usb/quirks.h b/sound/usb/quirks.h
index 665e972a1b40..1b862386577d 100644
--- a/sound/usb/quirks.h
+++ b/sound/usb/quirks.h
@@ -31,6 +31,9 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
31 __u8 request, __u8 requesttype, __u16 value, 31 __u8 request, __u8 requesttype, __u16 value,
32 __u16 index, void *data, __u16 size); 32 __u16 index, void *data, __u16 size);
33 33
34int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
35 struct audioformat *fmt);
36
34u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, 37u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
35 struct audioformat *fp, 38 struct audioformat *fp,
36 unsigned int sample_bytes); 39 unsigned int sample_bytes);
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index a63330dd1407..61d5dc2a3421 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -272,13 +272,8 @@ static void usX2Y_clients_stop(struct usX2Ydev *usX2Y)
272 for (s = 0; s < 4; s++) { 272 for (s = 0; s < 4; s++) {
273 struct snd_usX2Y_substream *subs = usX2Y->subs[s]; 273 struct snd_usX2Y_substream *subs = usX2Y->subs[s];
274 if (subs) { 274 if (subs) {
275 if (atomic_read(&subs->state) >= state_PRERUNNING) { 275 if (atomic_read(&subs->state) >= state_PRERUNNING)
276 unsigned long flags; 276 snd_pcm_stop_xrun(subs->pcm_substream);
277
278 snd_pcm_stream_lock_irqsave(subs->pcm_substream, flags);
279 snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
280 snd_pcm_stream_unlock_irqrestore(subs->pcm_substream, flags);
281 }
282 for (u = 0; u < NRURBS; u++) { 277 for (u = 0; u < NRURBS; u++) {
283 struct urb *urb = subs->urb[u]; 278 struct urb *urb = subs->urb[u];
284 if (NULL != urb) 279 if (NULL != urb)